2020-05-06 00:58:22 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
2022-02-10 22:28:48 +03:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-05-06 00:58:22 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-05-06 00:58:22 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/URL.h>
|
|
|
|
#include <LibCore/ElapsedTimer.h>
|
2021-05-31 19:20:50 +03:00
|
|
|
#include <LibGUI/ImageWidget.h>
|
2021-04-13 17:18:20 +03:00
|
|
|
#include <LibGUI/Progressbar.h>
|
2020-05-06 00:58:22 +03:00
|
|
|
#include <LibGUI/Widget.h>
|
2022-04-30 13:06:30 +03:00
|
|
|
#include <LibWeb/Loader/ResourceLoader.h>
|
2020-05-06 00:58:22 +03:00
|
|
|
|
|
|
|
namespace Browser {
|
|
|
|
|
|
|
|
class DownloadWidget final : public GUI::Widget {
|
|
|
|
C_OBJECT(DownloadWidget);
|
|
|
|
|
|
|
|
public:
|
2022-02-10 22:28:48 +03:00
|
|
|
virtual ~DownloadWidget() override = default;
|
2020-05-06 00:58:22 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
explicit DownloadWidget(const URL&);
|
|
|
|
|
2023-06-11 02:56:35 +03:00
|
|
|
void did_progress(Optional<u64> total_size, u64 downloaded_size);
|
ProtocolServer: Stream the downloaded data if possible
This patchset makes ProtocolServer stream the downloads to its client
(LibProtocol), and as such changes the download API; a possible
download lifecycle could be as such:
notation = client->server:'>', server->client:'<', pipe activity:'*'
```
> StartDownload(GET, url, headers, {})
< Response(0, fd 8)
* {data, 1024b}
< HeadersBecameAvailable(0, response_headers, 200)
< DownloadProgress(0, 4K, 1024)
* {data, 1024b}
* {data, 1024b}
< DownloadProgress(0, 4K, 2048)
* {data, 1024b}
< DownloadProgress(0, 4K, 1024)
< DownloadFinished(0, true, 4K)
```
Since managing the received file descriptor is a pain, LibProtocol
implements `Download::stream_into(OutputStream)`, which can be used to
stream the download into any given output stream (be it a file, or
memory, or writing stuff with a delay, etc.).
Also, as some of the users of this API require all the downloaded data
upfront, LibProtocol also implements `set_should_buffer_all_input()`,
which causes the download instance to buffer all the data until the
download is complete, and to call the `on_buffered_download_finish`
hook.
2020-12-26 16:44:12 +03:00
|
|
|
void did_finish(bool success);
|
2020-05-06 00:58:22 +03:00
|
|
|
|
|
|
|
URL m_url;
|
2022-12-04 21:02:33 +03:00
|
|
|
DeprecatedString m_destination_path;
|
2022-04-30 13:06:30 +03:00
|
|
|
RefPtr<Web::ResourceLoaderConnectorRequest> m_download;
|
2021-04-13 17:18:20 +03:00
|
|
|
RefPtr<GUI::Progressbar> m_progressbar;
|
2020-05-06 00:58:22 +03:00
|
|
|
RefPtr<GUI::Label> m_progress_label;
|
|
|
|
RefPtr<GUI::Button> m_cancel_button;
|
|
|
|
RefPtr<GUI::Button> m_close_button;
|
2021-05-31 19:19:13 +03:00
|
|
|
RefPtr<GUI::CheckBox> m_close_on_finish_checkbox;
|
2021-05-31 19:20:50 +03:00
|
|
|
RefPtr<GUI::ImageWidget> m_browser_image;
|
2023-02-09 05:02:46 +03:00
|
|
|
OwnPtr<Core::File> m_output_file_stream;
|
2020-05-06 00:58:22 +03:00
|
|
|
Core::ElapsedTimer m_elapsed_timer;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|