Browse Source

allow additional schemes that should support cookies

deepak1556 8 years ago
parent
commit
826fbf3e21

+ 32 - 62
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<net::CookieStore> cookie_store = nullptr;
+    std::vector<std::string> 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<net::HostResolver> host_resolver(net::HostResolver::CreateDefaultResolver(nullptr));
 
     // --host-resolver-rules
-    if (command_line.HasSwitch(switches::kHostResolverRules)) {
+    if (command_line.HasSwitch(::switches::kHostResolverRules)) {
       std::unique_ptr<net::MappedHostResolver> 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();
     }
 

+ 57 - 0
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

+ 26 - 0
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_

+ 2 - 0
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',
     ],
   },
 }