Remove AtomBrowserContext::SetCookieableSchemes

The standard schemes are already stored, we don't have to duplicate the
list for every session.
This commit is contained in:
Cheng Zhao 2016-08-05 16:35:37 +09:00
Родитель 6cd1aa21af
Коммит a14b2c1cf8
4 изменённых файлов: 28 добавлений и 25 удалений

Просмотреть файл

@ -42,10 +42,26 @@ void ClearJobFactoryInIO(
} // namespace
std::vector<std::string> GetStandardSchemes() {
return g_standard_schemes;
}
void RegisterStandardSchemes(const std::vector<std::string>& 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<v8::Object> exports, v8::Local<v8::Value> unused,
@ -222,6 +228,7 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.SetMethod("registerStandardSchemes", &RegisterStandardSchemes);
dict.SetMethod("getStandardSchemes", &atom::api::GetStandardSchemes);
}
} // namespace

Просмотреть файл

@ -28,6 +28,9 @@ namespace atom {
namespace api {
std::vector<std::string> GetStandardSchemes();
void RegisterStandardSchemes(const std::vector<std::string>& schemes);
class Protocol : public mate::TrackableObject<Protocol> {
public:
using Handler =

Просмотреть файл

@ -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<std::string>& 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<std::string> 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) {

Просмотреть файл

@ -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<std::string>& schemes);
// brightray::URLRequestContextGetter::Delegate:
net::NetworkDelegate* CreateNetworkDelegate() override;
@ -59,7 +58,6 @@ class AtomBrowserContext : public brightray::BrowserContext {
std::unique_ptr<AtomDownloadManagerDelegate> download_manager_delegate_;
std::unique_ptr<WebViewManager> guest_manager_;
std::unique_ptr<AtomPermissionManager> permission_manager_;
std::vector<std::string> cookieable_schemes_;
std::string user_agent_;
bool use_cache_;