diff --git a/shell/app/electron_content_client.cc b/shell/app/electron_content_client.cc index 530637ac4d..fe00e251f4 100644 --- a/shell/app/electron_content_client.cc +++ b/shell/app/electron_content_client.cc @@ -187,13 +187,9 @@ void ElectronContentClient::AddAdditionalSchemes(Schemes* schemes) { auto* command_line = base::CommandLine::ForCurrentProcess(); std::string process_type = command_line->GetSwitchValueASCII(::switches::kProcessType); - // Browser Process registration happens in - // `api::Protocol::RegisterSchemesAsPrivileged` - // - // Renderer Process registration happens in `RendererClientBase` - // - // We use this for registration to network utility process - if (process_type == ::switches::kUtilityProcess) { + // Register schemes for browser process and network utility process, the + // registration for renderer process happens in `RendererClientBase`. + if (process_type.empty() || process_type == ::switches::kUtilityProcess) { AppendDelimitedSwitchToVector(switches::kServiceWorkerSchemes, &schemes->service_worker_schemes); AppendDelimitedSwitchToVector(switches::kStandardSchemes, diff --git a/shell/browser/api/electron_api_protocol.cc b/shell/browser/api/electron_api_protocol.cc index 8e4329b523..8d9b7d2c34 100644 --- a/shell/browser/api/electron_api_protocol.cc +++ b/shell/browser/api/electron_api_protocol.cc @@ -10,6 +10,7 @@ #include "base/command_line.h" #include "base/stl_util.h" +#include "content/common/url_schemes.h" #include "content/public/browser/child_process_security_policy.h" #include "gin/object_template_builder.h" #include "shell/browser/browser.h" @@ -149,6 +150,14 @@ void RegisterSchemesAsPrivileged(gin_helper::ErrorThrower thrower, g_standard_schemes); AppendSchemesToCmdLine(electron::switches::kStreamingSchemes, g_streaming_schemes); + + // The scheme registration happens before user's main script is executed, so + // we have to explicitly do a re-registration to make the new scheme + // effective. + // Note that while the API is marked as ForTests, it is safe to call in this + // use case, and it has DCHECK to ensure we are not making changes to schemes + // _after_ any code has read the scheme registry. + content::ReRegisterContentSchemesForTests(); } namespace {