Merge pull request #6708 from deepak1556/cookieable_schemes_patch
protocol: custom standard schemes should support cookies
This commit is contained in:
commit
6cd1aa21af
4 changed files with 50 additions and 0 deletions
|
@ -29,6 +29,9 @@ namespace api {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
// List of registered custom standard schemes.
|
||||||
|
std::vector<std::string> g_standard_schemes;
|
||||||
|
|
||||||
// Clear protocol handlers in IO thread.
|
// Clear protocol handlers in IO thread.
|
||||||
void ClearJobFactoryInIO(
|
void ClearJobFactoryInIO(
|
||||||
scoped_refptr<brightray::URLRequestContextGetter> request_context_getter) {
|
scoped_refptr<brightray::URLRequestContextGetter> request_context_getter) {
|
||||||
|
@ -42,6 +45,7 @@ void ClearJobFactoryInIO(
|
||||||
Protocol::Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context)
|
Protocol::Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context)
|
||||||
: request_context_getter_(browser_context->GetRequestContext()),
|
: request_context_getter_(browser_context->GetRequestContext()),
|
||||||
weak_factory_(this) {
|
weak_factory_(this) {
|
||||||
|
browser_context->SetCookieableSchemes(g_standard_schemes);
|
||||||
Init(isolate);
|
Init(isolate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,6 +213,8 @@ void RegisterStandardSchemes(
|
||||||
auto command_line = base::CommandLine::ForCurrentProcess();
|
auto command_line = base::CommandLine::ForCurrentProcess();
|
||||||
command_line->AppendSwitchASCII(atom::switches::kStandardSchemes,
|
command_line->AppendSwitchASCII(atom::switches::kStandardSchemes,
|
||||||
base::JoinString(schemes, ","));
|
base::JoinString(schemes, ","));
|
||||||
|
|
||||||
|
atom::api::g_standard_schemes = schemes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
|
|
|
@ -88,6 +88,9 @@ AtomBrowserContext::AtomBrowserContext(
|
||||||
use_cache_ = true;
|
use_cache_ = true;
|
||||||
options.GetBoolean("cache", &use_cache_);
|
options.GetBoolean("cache", &use_cache_);
|
||||||
|
|
||||||
|
// Default schemes that should support cookies.
|
||||||
|
cookieable_schemes_ = {"http", "https", "ws", "wss"};
|
||||||
|
|
||||||
// Initialize Pref Registry in brightray.
|
// Initialize Pref Registry in brightray.
|
||||||
InitPrefs();
|
InitPrefs();
|
||||||
}
|
}
|
||||||
|
@ -99,6 +102,13 @@ void AtomBrowserContext::SetUserAgent(const std::string& user_agent) {
|
||||||
user_agent_ = 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() {
|
net::NetworkDelegate* AtomBrowserContext::CreateNetworkDelegate() {
|
||||||
return network_delegate_;
|
return network_delegate_;
|
||||||
}
|
}
|
||||||
|
@ -188,6 +198,10 @@ net::SSLConfigService* AtomBrowserContext::CreateSSLConfigService() {
|
||||||
return new AtomSSLConfigService;
|
return new AtomSSLConfigService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> AtomBrowserContext::GetCookieableSchemes() {
|
||||||
|
return cookieable_schemes_;
|
||||||
|
}
|
||||||
|
|
||||||
void AtomBrowserContext::RegisterPrefs(PrefRegistrySimple* pref_registry) {
|
void AtomBrowserContext::RegisterPrefs(PrefRegistrySimple* pref_registry) {
|
||||||
pref_registry->RegisterFilePathPref(prefs::kSelectFileLastDirectory,
|
pref_registry->RegisterFilePathPref(prefs::kSelectFileLastDirectory,
|
||||||
base::FilePath());
|
base::FilePath());
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#define ATOM_BROWSER_ATOM_BROWSER_CONTEXT_H_
|
#define ATOM_BROWSER_ATOM_BROWSER_CONTEXT_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "brightray/browser/browser_context.h"
|
#include "brightray/browser/browser_context.h"
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ class AtomBrowserContext : public brightray::BrowserContext {
|
||||||
const base::DictionaryValue& options = base::DictionaryValue());
|
const base::DictionaryValue& options = base::DictionaryValue());
|
||||||
|
|
||||||
void SetUserAgent(const std::string& user_agent);
|
void SetUserAgent(const std::string& user_agent);
|
||||||
|
void SetCookieableSchemes(const std::vector<std::string>& schemes);
|
||||||
|
|
||||||
// brightray::URLRequestContextGetter::Delegate:
|
// brightray::URLRequestContextGetter::Delegate:
|
||||||
net::NetworkDelegate* CreateNetworkDelegate() override;
|
net::NetworkDelegate* CreateNetworkDelegate() override;
|
||||||
|
@ -36,6 +38,7 @@ class AtomBrowserContext : public brightray::BrowserContext {
|
||||||
const base::FilePath& base_path) override;
|
const base::FilePath& base_path) override;
|
||||||
std::unique_ptr<net::CertVerifier> CreateCertVerifier() override;
|
std::unique_ptr<net::CertVerifier> CreateCertVerifier() override;
|
||||||
net::SSLConfigService* CreateSSLConfigService() override;
|
net::SSLConfigService* CreateSSLConfigService() override;
|
||||||
|
std::vector<std::string> GetCookieableSchemes() override;
|
||||||
|
|
||||||
// content::BrowserContext:
|
// content::BrowserContext:
|
||||||
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
|
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
|
||||||
|
@ -56,6 +59,7 @@ class AtomBrowserContext : public brightray::BrowserContext {
|
||||||
std::unique_ptr<AtomDownloadManagerDelegate> download_manager_delegate_;
|
std::unique_ptr<AtomDownloadManagerDelegate> download_manager_delegate_;
|
||||||
std::unique_ptr<WebViewManager> guest_manager_;
|
std::unique_ptr<WebViewManager> guest_manager_;
|
||||||
std::unique_ptr<AtomPermissionManager> permission_manager_;
|
std::unique_ptr<AtomPermissionManager> permission_manager_;
|
||||||
|
std::vector<std::string> cookieable_schemes_;
|
||||||
std::string user_agent_;
|
std::string user_agent_;
|
||||||
bool use_cache_;
|
bool use_cache_;
|
||||||
|
|
||||||
|
|
|
@ -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 () {
|
describe('ses.clearStorageData(options)', function () {
|
||||||
|
|
Loading…
Reference in a new issue