diff --git a/atom/browser/api/atom_api_protocol.cc b/atom/browser/api/atom_api_protocol.cc index dbd668f421..e4f27b54fb 100644 --- a/atom/browser/api/atom_api_protocol.cc +++ b/atom/browser/api/atom_api_protocol.cc @@ -42,10 +42,26 @@ void ClearJobFactoryInIO( } // namespace +std::vector GetStandardSchemes() { + return g_standard_schemes; +} + +void RegisterStandardSchemes(const std::vector& schemes) { + g_standard_schemes = schemes; + + auto* policy = content::ChildProcessSecurityPolicy::GetInstance(); + for (const std::string& scheme : schemes) { + url::AddStandardScheme(scheme.c_str(), url::SCHEME_WITHOUT_PORT); + policy->RegisterWebSafeScheme(scheme); + } + + base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( + atom::switches::kStandardSchemes, base::JoinString(schemes, ",")); +} + Protocol::Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context) : request_context_getter_(browser_context->GetRequestContext()), weak_factory_(this) { - browser_context->SetCookieableSchemes(g_standard_schemes); Init(isolate); } @@ -204,17 +220,7 @@ void RegisterStandardSchemes( return; } - auto policy = content::ChildProcessSecurityPolicy::GetInstance(); - for (const auto& scheme : schemes) { - url::AddStandardScheme(scheme.c_str(), url::SCHEME_WITHOUT_PORT); - policy->RegisterWebSafeScheme(scheme); - } - - auto command_line = base::CommandLine::ForCurrentProcess(); - command_line->AppendSwitchASCII(atom::switches::kStandardSchemes, - base::JoinString(schemes, ",")); - - atom::api::g_standard_schemes = schemes; + atom::api::RegisterStandardSchemes(schemes); } void Initialize(v8::Local exports, v8::Local unused, @@ -222,6 +228,7 @@ void Initialize(v8::Local exports, v8::Local unused, v8::Isolate* isolate = context->GetIsolate(); mate::Dictionary dict(isolate, exports); dict.SetMethod("registerStandardSchemes", &RegisterStandardSchemes); + dict.SetMethod("getStandardSchemes", &atom::api::GetStandardSchemes); } } // namespace diff --git a/atom/browser/api/atom_api_protocol.h b/atom/browser/api/atom_api_protocol.h index 969fe7f665..2e69e781c7 100644 --- a/atom/browser/api/atom_api_protocol.h +++ b/atom/browser/api/atom_api_protocol.h @@ -28,6 +28,9 @@ namespace atom { namespace api { +std::vector GetStandardSchemes(); +void RegisterStandardSchemes(const std::vector& schemes); + class Protocol : public mate::TrackableObject { public: using Handler = diff --git a/atom/browser/atom_browser_context.cc b/atom/browser/atom_browser_context.cc index dc158a0a5f..f9bfe1a94c 100644 --- a/atom/browser/atom_browser_context.cc +++ b/atom/browser/atom_browser_context.cc @@ -4,6 +4,7 @@ #include "atom/browser/atom_browser_context.h" +#include "atom/browser/api/atom_api_protocol.h" #include "atom/browser/atom_browser_main_parts.h" #include "atom/browser/atom_download_manager_delegate.h" #include "atom/browser/browser.h" @@ -88,9 +89,6 @@ AtomBrowserContext::AtomBrowserContext( use_cache_ = true; options.GetBoolean("cache", &use_cache_); - // Default schemes that should support cookies. - cookieable_schemes_ = {"http", "https", "ws", "wss"}; - // Initialize Pref Registry in brightray. InitPrefs(); } @@ -102,13 +100,6 @@ void AtomBrowserContext::SetUserAgent(const std::string& user_agent) { user_agent_ = user_agent; } -void AtomBrowserContext::SetCookieableSchemes( - const std::vector& schemes) { - if (!schemes.empty()) - cookieable_schemes_.insert(cookieable_schemes_.end(), - schemes.begin(), schemes.end()); -} - net::NetworkDelegate* AtomBrowserContext::CreateNetworkDelegate() { return network_delegate_; } @@ -199,7 +190,11 @@ net::SSLConfigService* AtomBrowserContext::CreateSSLConfigService() { } std::vector AtomBrowserContext::GetCookieableSchemes() { - return cookieable_schemes_; + auto default_schemes = brightray::BrowserContext::GetCookieableSchemes(); + const auto& standard_schemes = atom::api::GetStandardSchemes(); + default_schemes.insert(default_schemes.end(), + standard_schemes.begin(), standard_schemes.end()); + return default_schemes; } void AtomBrowserContext::RegisterPrefs(PrefRegistrySimple* pref_registry) { diff --git a/atom/browser/atom_browser_context.h b/atom/browser/atom_browser_context.h index c19f4672a0..fa3186396c 100644 --- a/atom/browser/atom_browser_context.h +++ b/atom/browser/atom_browser_context.h @@ -27,7 +27,6 @@ class AtomBrowserContext : public brightray::BrowserContext { const base::DictionaryValue& options = base::DictionaryValue()); void SetUserAgent(const std::string& user_agent); - void SetCookieableSchemes(const std::vector& schemes); // brightray::URLRequestContextGetter::Delegate: net::NetworkDelegate* CreateNetworkDelegate() override; @@ -59,7 +58,6 @@ class AtomBrowserContext : public brightray::BrowserContext { std::unique_ptr download_manager_delegate_; std::unique_ptr guest_manager_; std::unique_ptr permission_manager_; - std::vector cookieable_schemes_; std::string user_agent_; bool use_cache_;