Skip to content

Commit

Permalink
feat: Use default URLLoaderFactory if protocal handler was callbacked…
Browse files Browse the repository at this point in the history
… without argument.
  • Loading branch information
mrchaofan committed Apr 23, 2024
1 parent b428315 commit 7867b60
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
15 changes: 12 additions & 3 deletions shell/browser/net/electron_url_loader_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,18 @@ void ElectronURLLoaderFactory::StartLoading(
// Note that we should not throw JS error in the callback no matter what is
// passed, to keep compatibility with old code.
v8::Local<v8::Value> response;
if (!args->GetNext(&response)) {
OnComplete(std::move(client), request_id,
network::URLLoaderCompletionStatus(net::ERR_NOT_IMPLEMENTED));
if (!args->GetNext(&response) || response->IsNullOrUndefined() ||
(response->IsObject() &&
response.As<v8::Object>()
->GetOwnPropertyNames(args->isolate()->GetCurrentContext())
.ToLocalChecked()
->Length() == 0)) {
mojo::Remote<network::mojom::URLLoaderFactory> target_factory_remote(
std::move(target_factory));
// Pass-through to the original factory.
target_factory_remote->CreateLoaderAndStart(
std::move(loader), request_id, options | kBypassCustomProtocolHandlers,
request, std::move(client), traffic_annotation);
return;
}

Expand Down
2 changes: 2 additions & 0 deletions shell/browser/net/electron_url_loader_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

namespace electron {

const uint32_t kBypassCustomProtocolHandlers = 1 << 30;

// Old Protocol API can only serve one type of response for one scheme.
enum class ProtocolType {
kBuffer,
Expand Down
2 changes: 0 additions & 2 deletions shell/browser/net/proxying_url_loader_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@

namespace electron {

const uint32_t kBypassCustomProtocolHandlers = 1 << 30;

// This class is responsible for following tasks when NetworkService is enabled:
// 1. handling intercepted protocols;
// 2. implementing webRequest module;
Expand Down

0 comments on commit 7867b60

Please sign in to comment.