From 826fbf3e21f6e43918ad2690c1b87f38be4438c6 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Wed, 3 Aug 2016 15:52:09 +0530 Subject: [PATCH 1/2] allow additional schemes that should support cookies --- .../browser/url_request_context_getter.cc | 94 +++++++------------ brightray/common/switches.cc | 57 +++++++++++ brightray/common/switches.h | 26 +++++ brightray/filenames.gypi | 2 + 4 files changed, 117 insertions(+), 62 deletions(-) create mode 100644 brightray/common/switches.cc create mode 100644 brightray/common/switches.h diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 41b570cd7cf8..b07fe88d663d 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -10,9 +10,11 @@ #include "browser/net/devtools_network_transaction_factory.h" #include "browser/net_log.h" #include "browser/network_delegate.h" +#include "common/switches.h" #include "base/command_line.h" #include "base/memory/ptr_util.h" +#include "base/strings/string_split.h" #include "base/strings/string_util.h" #include "base/threading/sequenced_worker_pool.h" #include "base/threading/worker_pool.h" @@ -56,51 +58,6 @@ using content::BrowserThread; namespace brightray { -namespace { - -// Comma-separated list of rules that control how hostnames are mapped. -// -// For example: -// "MAP * 127.0.0.1" --> Forces all hostnames to be mapped to 127.0.0.1 -// "MAP *.google.com proxy" --> Forces all google.com subdomains to be -// resolved to "proxy". -// "MAP test.com [::1]:77 --> Forces "test.com" to resolve to IPv6 loopback. -// Will also force the port of the resulting -// socket address to be 77. -// "MAP * baz, EXCLUDE www.google.com" --> Remaps everything to "baz", -// except for "www.google.com". -// -// These mappings apply to the endpoint host in a net::URLRequest (the TCP -// connect and host resolver in a direct connection, and the CONNECT in an http -// proxy connection, and the endpoint host in a SOCKS proxy connection). -const char kHostRules[] = "host-rules"; - -// Don't use a proxy server, always make direct connections. Overrides any -// other proxy server flags that are passed. -const char kNoProxyServer[] = "no-proxy-server"; - -// Uses a specified proxy server, overrides system settings. This switch only -// affects HTTP and HTTPS requests. -const char kProxyServer[] = "proxy-server"; - -// Bypass specified proxy for the given semi-colon-separated list of hosts. This -// flag has an effect only when --proxy-server is set. -const char kProxyBypassList[] = "proxy-bypass-list"; - -// Uses the pac script at the given URL. -const char kProxyPacUrl[] = "proxy-pac-url"; - -// Disable HTTP/2 and SPDY/3.1 protocols. -const char kDisableHttp2[] = "disable-http2"; - -// Whitelist containing servers for which Integrated Authentication is enabled. -const char kAuthServerWhitelist[] = "auth-server-whitelist"; - -// Whitelist containing servers for which Kerberos delegation is allowed. -const char kAuthNegotiateDelegateWhitelist[] = "auth-negotiate-delegate-whitelist"; - -} // namespace - std::string URLRequestContextGetter::Delegate::GetUserAgent() { return base::EmptyString(); } @@ -215,13 +172,26 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { storage_.reset(new net::URLRequestContextStorage(url_request_context_.get())); std::unique_ptr cookie_store = nullptr; + std::vector default_cookieable_schemes = {"http", "https", "ws", "wss"}; + auto schemes_string = command_line.GetSwitchValueASCII(switches::kCookieableSchemes); + if (!schemes_string.empty()) { + auto additional_cookieable_schemes = base::SplitString(schemes_string, ",", + base::TRIM_WHITESPACE, + base::SPLIT_WANT_NONEMPTY); + default_cookieable_schemes.insert(default_cookieable_schemes.end(), + additional_cookieable_schemes.begin(), + additional_cookieable_schemes.end()); + } if (in_memory_) { - cookie_store = content::CreateCookieStore(content::CookieStoreConfig()); + auto cookie_config = content::CookieStoreConfig(); + cookie_config.cookieable_schemes = default_cookieable_schemes; + cookie_store = content::CreateCookieStore(cookie_config); } else { auto cookie_config = content::CookieStoreConfig( base_path_.Append(FILE_PATH_LITERAL("Cookies")), content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, nullptr, nullptr); + cookie_config.cookieable_schemes = default_cookieable_schemes; cookie_store = content::CreateCookieStore(cookie_config); } storage_->set_cookie_store(std::move(cookie_store)); @@ -238,28 +208,28 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { std::unique_ptr host_resolver(net::HostResolver::CreateDefaultResolver(nullptr)); // --host-resolver-rules - if (command_line.HasSwitch(switches::kHostResolverRules)) { + if (command_line.HasSwitch(::switches::kHostResolverRules)) { std::unique_ptr remapped_resolver( new net::MappedHostResolver(std::move(host_resolver))); remapped_resolver->SetRulesFromString( - command_line.GetSwitchValueASCII(switches::kHostResolverRules)); + command_line.GetSwitchValueASCII(::switches::kHostResolverRules)); host_resolver = std::move(remapped_resolver); } // --proxy-server net::DhcpProxyScriptFetcherFactory dhcp_factory; - if (command_line.HasSwitch(kNoProxyServer)) { + if (command_line.HasSwitch(switches::kNoProxyServer)) { storage_->set_proxy_service(net::ProxyService::CreateDirect()); - } else if (command_line.HasSwitch(kProxyServer)) { + } else if (command_line.HasSwitch(switches::kProxyServer)) { net::ProxyConfig proxy_config; proxy_config.proxy_rules().ParseFromString( - command_line.GetSwitchValueASCII(kProxyServer)); + command_line.GetSwitchValueASCII(switches::kProxyServer)); proxy_config.proxy_rules().bypass_rules.ParseFromString( - command_line.GetSwitchValueASCII(kProxyBypassList)); + command_line.GetSwitchValueASCII(switches::kProxyBypassList)); storage_->set_proxy_service(net::ProxyService::CreateFixed(proxy_config)); - } else if (command_line.HasSwitch(kProxyPacUrl)) { + } else if (command_line.HasSwitch(switches::kProxyPacUrl)) { auto proxy_config = net::ProxyConfig::CreateFromCustomPacURL( - GURL(command_line.GetSwitchValueASCII(kProxyPacUrl))); + GURL(command_line.GetSwitchValueASCII(switches::kProxyPacUrl))); proxy_config.set_pac_mandatory(true); storage_->set_proxy_service(net::ProxyService::CreateFixed( proxy_config)); @@ -287,15 +257,15 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { #endif // --auth-server-whitelist - if (command_line.HasSwitch(kAuthServerWhitelist)) { + if (command_line.HasSwitch(switches::kAuthServerWhitelist)) { http_auth_preferences_->set_server_whitelist( - command_line.GetSwitchValueASCII(kAuthServerWhitelist)); + command_line.GetSwitchValueASCII(switches::kAuthServerWhitelist)); } // --auth-negotiate-delegate-whitelist - if (command_line.HasSwitch(kAuthNegotiateDelegateWhitelist)) { + if (command_line.HasSwitch(switches::kAuthNegotiateDelegateWhitelist)) { http_auth_preferences_->set_delegate_whitelist( - command_line.GetSwitchValueASCII(kAuthNegotiateDelegateWhitelist)); + command_line.GetSwitchValueASCII(switches::kAuthNegotiateDelegateWhitelist)); } auto auth_handler_factory = @@ -326,19 +296,19 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { network_session_params.net_log = url_request_context_->net_log(); // --disable-http2 - if (command_line.HasSwitch(kDisableHttp2)) { + if (command_line.HasSwitch(switches::kDisableHttp2)) { network_session_params.enable_spdy31 = false; network_session_params.enable_http2 = false; } // --ignore-certificate-errors - if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) + if (command_line.HasSwitch(::switches::kIgnoreCertificateErrors)) network_session_params.ignore_certificate_errors = true; // --host-rules - if (command_line.HasSwitch(kHostRules)) { + if (command_line.HasSwitch(switches::kHostRules)) { host_mapping_rules_.reset(new net::HostMappingRules); - host_mapping_rules_->SetRulesFromString(command_line.GetSwitchValueASCII(kHostRules)); + host_mapping_rules_->SetRulesFromString(command_line.GetSwitchValueASCII(switches::kHostRules)); network_session_params.host_mapping_rules = host_mapping_rules_.get(); } diff --git a/brightray/common/switches.cc b/brightray/common/switches.cc new file mode 100644 index 000000000000..3fc6d3125919 --- /dev/null +++ b/brightray/common/switches.cc @@ -0,0 +1,57 @@ +// Copyright (c) 2016 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "common/switches.h" + +namespace brightray { + +namespace switches { + +// Comma-separated list of rules that control how hostnames are mapped. +// +// For example: +// "MAP * 127.0.0.1" --> Forces all hostnames to be mapped to 127.0.0.1 +// "MAP *.google.com proxy" --> Forces all google.com subdomains to be +// resolved to "proxy". +// "MAP test.com [::1]:77 --> Forces "test.com" to resolve to IPv6 loopback. +// Will also force the port of the resulting +// socket address to be 77. +// "MAP * baz, EXCLUDE www.google.com" --> Remaps everything to "baz", +// except for "www.google.com". +// +// These mappings apply to the endpoint host in a net::URLRequest (the TCP +// connect and host resolver in a direct connection, and the CONNECT in an http +// proxy connection, and the endpoint host in a SOCKS proxy connection). +const char kHostRules[] = "host-rules"; + +// Don't use a proxy server, always make direct connections. Overrides any +// other proxy server flags that are passed. +const char kNoProxyServer[] = "no-proxy-server"; + +// Uses a specified proxy server, overrides system settings. This switch only +// affects HTTP and HTTPS requests. +const char kProxyServer[] = "proxy-server"; + +// Bypass specified proxy for the given semi-colon-separated list of hosts. This +// flag has an effect only when --proxy-server is set. +const char kProxyBypassList[] = "proxy-bypass-list"; + +// Uses the pac script at the given URL. +const char kProxyPacUrl[] = "proxy-pac-url"; + +// Disable HTTP/2 and SPDY/3.1 protocols. +const char kDisableHttp2[] = "disable-http2"; + +// Whitelist containing servers for which Integrated Authentication is enabled. +const char kAuthServerWhitelist[] = "auth-server-whitelist"; + +// Whitelist containing servers for which Kerberos delegation is allowed. +const char kAuthNegotiateDelegateWhitelist[] = "auth-negotiate-delegate-whitelist"; + +// Comma separated list of schemes that should support cookies. +const char kCookieableSchemes[] = "cookieable-schemes"; + +} // namespace switches + +} // namespace brightray diff --git a/brightray/common/switches.h b/brightray/common/switches.h new file mode 100644 index 000000000000..962e4149e339 --- /dev/null +++ b/brightray/common/switches.h @@ -0,0 +1,26 @@ +// Copyright (c) 2016 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef BRIGHTRAY_COMMON_SWITCHES_H_ +#define BRIGHTRAY_COMMON_SWITCHES_H_ + +namespace brightray { + +namespace switches { + +extern const char kHostRules[]; +extern const char kNoProxyServer[]; +extern const char kProxyServer[]; +extern const char kProxyBypassList[]; +extern const char kProxyPacUrl[]; +extern const char kDisableHttp2[]; +extern const char kAuthServerWhitelist[]; +extern const char kAuthNegotiateDelegateWhitelist[]; +extern const char kCookieableSchemes[]; + +} // namespace switches + +} // namespace brightray + +#endif // BRIGHTRAY_COMMON_SWITCHES_H_ diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index 944b8824da04..c36bddea5d85 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -109,6 +109,8 @@ 'common/main_delegate.cc', 'common/main_delegate.h', 'common/main_delegate_mac.mm', + 'common/switches.cc', + 'common/switches.h', ], }, } From e96b22430765d9fb7fef4d3e2bd8550d269a59cc Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Thu, 4 Aug 2016 12:20:19 +0530 Subject: [PATCH 2/2] allow delegate to provide cookieable schemes --- brightray/browser/url_request_context_getter.cc | 15 ++------------- brightray/browser/url_request_context_getter.h | 3 +++ brightray/common/switches.cc | 3 --- brightray/common/switches.h | 1 - 4 files changed, 5 insertions(+), 17 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index b07fe88d663d..46860d791983 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -14,7 +14,6 @@ #include "base/command_line.h" #include "base/memory/ptr_util.h" -#include "base/strings/string_split.h" #include "base/strings/string_util.h" #include "base/threading/sequenced_worker_pool.h" #include "base/threading/worker_pool.h" @@ -172,26 +171,16 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { storage_.reset(new net::URLRequestContextStorage(url_request_context_.get())); std::unique_ptr cookie_store = nullptr; - std::vector default_cookieable_schemes = {"http", "https", "ws", "wss"}; - auto schemes_string = command_line.GetSwitchValueASCII(switches::kCookieableSchemes); - if (!schemes_string.empty()) { - auto additional_cookieable_schemes = base::SplitString(schemes_string, ",", - base::TRIM_WHITESPACE, - base::SPLIT_WANT_NONEMPTY); - default_cookieable_schemes.insert(default_cookieable_schemes.end(), - additional_cookieable_schemes.begin(), - additional_cookieable_schemes.end()); - } if (in_memory_) { auto cookie_config = content::CookieStoreConfig(); - cookie_config.cookieable_schemes = default_cookieable_schemes; + cookie_config.cookieable_schemes = delegate_->GetCookieableSchemes(); cookie_store = content::CreateCookieStore(cookie_config); } else { auto cookie_config = content::CookieStoreConfig( base_path_.Append(FILE_PATH_LITERAL("Cookies")), content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, nullptr, nullptr); - cookie_config.cookieable_schemes = default_cookieable_schemes; + cookie_config.cookieable_schemes = delegate_->GetCookieableSchemes(); cookie_store = content::CreateCookieStore(cookie_config); } storage_->set_cookie_store(std::move(cookie_store)); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index aef0e96fe6f4..dfe233f28311 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -47,6 +47,9 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { const base::FilePath& base_path); virtual std::unique_ptr CreateCertVerifier(); virtual net::SSLConfigService* CreateSSLConfigService(); + virtual std::vector GetCookieableSchemes() { + return std::vector(); + } }; URLRequestContextGetter( diff --git a/brightray/common/switches.cc b/brightray/common/switches.cc index 3fc6d3125919..7ca869ae98f9 100644 --- a/brightray/common/switches.cc +++ b/brightray/common/switches.cc @@ -49,9 +49,6 @@ const char kAuthServerWhitelist[] = "auth-server-whitelist"; // Whitelist containing servers for which Kerberos delegation is allowed. const char kAuthNegotiateDelegateWhitelist[] = "auth-negotiate-delegate-whitelist"; -// Comma separated list of schemes that should support cookies. -const char kCookieableSchemes[] = "cookieable-schemes"; - } // namespace switches } // namespace brightray diff --git a/brightray/common/switches.h b/brightray/common/switches.h index 962e4149e339..3af00813830f 100644 --- a/brightray/common/switches.h +++ b/brightray/common/switches.h @@ -17,7 +17,6 @@ extern const char kProxyPacUrl[]; extern const char kDisableHttp2[]; extern const char kAuthServerWhitelist[]; extern const char kAuthNegotiateDelegateWhitelist[]; -extern const char kCookieableSchemes[]; } // namespace switches