From 52431506ba8a76c19d796e94944493ea3c0d29d8 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Wed, 3 Aug 2016 16:09:03 +0530 Subject: [PATCH 1/2] protocol: custom standard schemes should support cookies --- atom/browser/api/atom_api_protocol.cc | 3 +++ spec/api-session-spec.js | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/atom/browser/api/atom_api_protocol.cc b/atom/browser/api/atom_api_protocol.cc index eaed0c6dca3e..17182d2b6c1f 100644 --- a/atom/browser/api/atom_api_protocol.cc +++ b/atom/browser/api/atom_api_protocol.cc @@ -17,6 +17,7 @@ #include "atom/common/options_switches.h" #include "base/command_line.h" #include "base/strings/string_util.h" +#include "brightray/common/switches.h" #include "content/public/browser/child_process_security_policy.h" #include "native_mate/dictionary.h" #include "url/url_util.h" @@ -209,6 +210,8 @@ void RegisterStandardSchemes( auto command_line = base::CommandLine::ForCurrentProcess(); command_line->AppendSwitchASCII(atom::switches::kStandardSchemes, base::JoinString(schemes, ",")); + command_line->AppendSwitchASCII(brightray::switches::kCookieableSchemes, + base::JoinString(schemes, ",")); } void Initialize(v8::Local exports, v8::Local unused, diff --git a/spec/api-session-spec.js b/spec/api-session-spec.js index 52da23ce5254..5440ff29b844 100644 --- a/spec/api-session-spec.js +++ b/spec/api-session-spec.js @@ -153,6 +153,32 @@ describe('session module', function () { }) }) }) + + it('should set cookie for standard scheme', function (done) { + const standardScheme = remote.getGlobal('standardScheme') + const origin = standardScheme + '://fake-host' + session.defaultSession.cookies.set({ + url: origin, + name: 'custom', + value: '1' + }, function (error) { + if (error) { + return done(error) + } + session.defaultSession.cookies.get({ + url: origin + }, function (error, list) { + if (error) { + return done(error) + } + assert.equal(list.length, 1) + assert.equal(list[0].name, 'custom') + assert.equal(list[0].value, '1') + assert.equal(list[0].domain, 'fake-host') + done() + }) + }) + }) }) describe('ses.clearStorageData(options)', function () { From 2aa1c9e556dfa1195f81b27c60c7a02ecc481e40 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Thu, 4 Aug 2016 12:15:45 +0530 Subject: [PATCH 2/2] register cookieable schemes with browser context --- atom/browser/api/atom_api_protocol.cc | 9 ++++++--- atom/browser/atom_browser_context.cc | 14 ++++++++++++++ atom/browser/atom_browser_context.h | 4 ++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/atom/browser/api/atom_api_protocol.cc b/atom/browser/api/atom_api_protocol.cc index 17182d2b6c1f..dbd668f4210f 100644 --- a/atom/browser/api/atom_api_protocol.cc +++ b/atom/browser/api/atom_api_protocol.cc @@ -17,7 +17,6 @@ #include "atom/common/options_switches.h" #include "base/command_line.h" #include "base/strings/string_util.h" -#include "brightray/common/switches.h" #include "content/public/browser/child_process_security_policy.h" #include "native_mate/dictionary.h" #include "url/url_util.h" @@ -30,6 +29,9 @@ namespace api { namespace { +// List of registered custom standard schemes. +std::vector g_standard_schemes; + // Clear protocol handlers in IO thread. void ClearJobFactoryInIO( scoped_refptr request_context_getter) { @@ -43,6 +45,7 @@ void ClearJobFactoryInIO( 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); } @@ -210,8 +213,8 @@ void RegisterStandardSchemes( auto command_line = base::CommandLine::ForCurrentProcess(); command_line->AppendSwitchASCII(atom::switches::kStandardSchemes, base::JoinString(schemes, ",")); - command_line->AppendSwitchASCII(brightray::switches::kCookieableSchemes, - base::JoinString(schemes, ",")); + + atom::api::g_standard_schemes = schemes; } void Initialize(v8::Local exports, v8::Local unused, diff --git a/atom/browser/atom_browser_context.cc b/atom/browser/atom_browser_context.cc index 7ac5dde4ef21..dc158a0a5f12 100644 --- a/atom/browser/atom_browser_context.cc +++ b/atom/browser/atom_browser_context.cc @@ -88,6 +88,9 @@ 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(); } @@ -99,6 +102,13 @@ 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_; } @@ -188,6 +198,10 @@ net::SSLConfigService* AtomBrowserContext::CreateSSLConfigService() { return new AtomSSLConfigService; } +std::vector AtomBrowserContext::GetCookieableSchemes() { + return cookieable_schemes_; +} + void AtomBrowserContext::RegisterPrefs(PrefRegistrySimple* pref_registry) { pref_registry->RegisterFilePathPref(prefs::kSelectFileLastDirectory, base::FilePath()); diff --git a/atom/browser/atom_browser_context.h b/atom/browser/atom_browser_context.h index ed3817da6033..c19f4672a0a8 100644 --- a/atom/browser/atom_browser_context.h +++ b/atom/browser/atom_browser_context.h @@ -6,6 +6,7 @@ #define ATOM_BROWSER_ATOM_BROWSER_CONTEXT_H_ #include +#include #include "brightray/browser/browser_context.h" @@ -26,6 +27,7 @@ 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; @@ -36,6 +38,7 @@ class AtomBrowserContext : public brightray::BrowserContext { const base::FilePath& base_path) override; std::unique_ptr CreateCertVerifier() override; net::SSLConfigService* CreateSSLConfigService() override; + std::vector GetCookieableSchemes() override; // content::BrowserContext: content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; @@ -56,6 +59,7 @@ 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_;