Skip to content

Commit

Permalink
fix: ensure standard schemes are registered in nw service process
Browse files Browse the repository at this point in the history
Refs #20546
  • Loading branch information
deepak1556 authored and electron-bot committed Apr 1, 2020
1 parent b4675ce commit 8fee5d7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
30 changes: 22 additions & 8 deletions shell/app/electron_content_client.cc
Expand Up @@ -15,6 +15,7 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_switches.h"
#include "electron/buildflags/buildflags.h"
#include "extensions/common/constants.h"
#include "ppapi/buildflags/buildflags.h"
Expand Down Expand Up @@ -231,14 +232,27 @@ base::RefCountedMemory* ElectronContentClient::GetDataResourceBytes(
}

void ElectronContentClient::AddAdditionalSchemes(Schemes* schemes) {
AppendDelimitedSwitchToVector(switches::kServiceWorkerSchemes,
&schemes->service_worker_schemes);
AppendDelimitedSwitchToVector(switches::kSecureSchemes,
&schemes->secure_schemes);
AppendDelimitedSwitchToVector(switches::kBypassCSPSchemes,
&schemes->csp_bypassing_schemes);
AppendDelimitedSwitchToVector(switches::kCORSSchemes,
&schemes->cors_enabled_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) {
AppendDelimitedSwitchToVector(switches::kServiceWorkerSchemes,
&schemes->service_worker_schemes);
AppendDelimitedSwitchToVector(switches::kStandardSchemes,
&schemes->standard_schemes);
AppendDelimitedSwitchToVector(switches::kSecureSchemes,
&schemes->secure_schemes);
AppendDelimitedSwitchToVector(switches::kBypassCSPSchemes,
&schemes->csp_bypassing_schemes);
AppendDelimitedSwitchToVector(switches::kCORSSchemes,
&schemes->cors_enabled_schemes);
}

schemes->service_worker_schemes.emplace_back(url::kFileScheme);
schemes->standard_schemes.emplace_back(extensions::kExtensionScheme);
Expand Down
5 changes: 5 additions & 0 deletions shell/renderer/renderer_client_base.cc
Expand Up @@ -101,6 +101,11 @@ RendererClientBase::RendererClientBase() {
ParseSchemesCLISwitch(command_line, switches::kStandardSchemes);
for (const std::string& scheme : standard_schemes_list)
url::AddStandardScheme(scheme.c_str(), url::SCHEME_WITH_HOST);
// Parse --cors-schemes=scheme1,scheme2
std::vector<std::string> cors_schemes_list =
ParseSchemesCLISwitch(command_line, switches::kCORSSchemes);
for (const std::string& scheme : cors_schemes_list)
url::AddCorsEnabledScheme(scheme.c_str());
isolated_world_ = base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kContextIsolation);
// We rely on the unique process host id which is notified to the
Expand Down

0 comments on commit 8fee5d7

Please sign in to comment.