mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:47:44 +00:00
ProtocolServer+LibProtocol: Reject unhandled URLs instead of asserting
StartDownload requests for unhandled protocols (or invalid URLs) will now refuse to load instead of asserting. A failure code is sent back to LibProtocol and Protocol::Client::start_download() returns nullptr. Fixes #1604.
This commit is contained in:
parent
53d0ca2ad8
commit
fc5067afd2
4 changed files with 15 additions and 2 deletions
|
@ -50,6 +50,8 @@ bool Client::is_supported_protocol(const String& protocol)
|
|||
RefPtr<Download> Client::start_download(const String& url)
|
||||
{
|
||||
i32 download_id = send_sync<Messages::ProtocolServer::StartDownload>(url)->download_id();
|
||||
if (download_id < 0)
|
||||
return nullptr;
|
||||
auto download = Download::create_from_id({}, *this, download_id);
|
||||
m_downloads.set(download_id, download);
|
||||
return download;
|
||||
|
|
|
@ -86,6 +86,11 @@ void ResourceLoader::load(const URL& url, Function<void(const ByteBuffer&)> succ
|
|||
|
||||
if (url.protocol() == "http") {
|
||||
auto download = protocol_client().start_download(url.to_string());
|
||||
if (!download) {
|
||||
if (error_callback)
|
||||
error_callback("Failed to initiate load");
|
||||
return;
|
||||
}
|
||||
download->on_finish = [this, success_callback = move(success_callback), error_callback = move(error_callback)](bool success, const ByteBuffer& payload, auto) {
|
||||
--m_pending_loads;
|
||||
if (on_load_counter_change)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue