From e213e09c3e04c00217898f76ab98399a2bfc5328 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 12 Jul 2016 21:53:19 +0900 Subject: [PATCH] Add options to session.fromPartition --- atom/browser/api/atom_api_session.cc | 15 ++++++++++----- atom/browser/api/atom_api_session.h | 4 +++- atom/browser/atom_browser_context.cc | 3 ++- atom/browser/atom_browser_context.h | 6 ++++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/atom/browser/api/atom_api_session.cc b/atom/browser/api/atom_api_session.cc index a9447392f25e..c1f4a1934ffd 100644 --- a/atom/browser/api/atom_api_session.cc +++ b/atom/browser/api/atom_api_session.cc @@ -21,6 +21,7 @@ #include "atom/common/native_mate_converters/gurl_converter.h" #include "atom/common/native_mate_converters/file_path_converter.h" #include "atom/common/native_mate_converters/net_converter.h" +#include "atom/common/native_mate_converters/value_converter.h" #include "atom/common/node_includes.h" #include "base/files/file_path.h" #include "base/guid.h" @@ -536,16 +537,17 @@ mate::Handle Session::CreateFrom( // static mate::Handle Session::FromPartition( - v8::Isolate* isolate, const std::string& partition) { + v8::Isolate* isolate, const std::string& partition, + const base::DictionaryValue& options) { scoped_refptr browser_context; if (partition.empty()) { - browser_context = AtomBrowserContext::From("", false); + browser_context = AtomBrowserContext::From("", false, options); } else if (base::StartsWith(partition, kPersistPrefix, base::CompareCase::SENSITIVE)) { std::string name = partition.substr(8); - browser_context = AtomBrowserContext::From(name, false); + browser_context = AtomBrowserContext::From(name, false, options); } else { - browser_context = AtomBrowserContext::From(partition, true); + browser_context = AtomBrowserContext::From(partition, true, options); } return CreateFrom(isolate, browser_context.get()); } @@ -593,7 +595,10 @@ v8::Local FromPartition( args->ThrowError("Session can only be received when app is ready"); return v8::Null(args->isolate()); } - return atom::api::Session::FromPartition(args->isolate(), partition).ToV8(); + base::DictionaryValue options; + args->GetNext(&options); + return atom::api::Session::FromPartition( + args->isolate(), partition, options).ToV8(); } void Initialize(v8::Local exports, v8::Local unused, diff --git a/atom/browser/api/atom_api_session.h b/atom/browser/api/atom_api_session.h index d1943ba6ed1e..c3bb82eebaf4 100644 --- a/atom/browser/api/atom_api_session.h +++ b/atom/browser/api/atom_api_session.h @@ -8,6 +8,7 @@ #include #include "atom/browser/api/trackable_object.h" +#include "base/values.h" #include "content/public/browser/download_manager.h" #include "native_mate/handle.h" #include "net/base/completion_callback.h" @@ -49,7 +50,8 @@ class Session: public mate::TrackableObject, // Gets the Session of |partition|. static mate::Handle FromPartition( - v8::Isolate* isolate, const std::string& partition); + v8::Isolate* isolate, const std::string& partition, + const base::DictionaryValue& options = base::DictionaryValue()); AtomBrowserContext* browser_context() const { return browser_context_.get(); } diff --git a/atom/browser/atom_browser_context.cc b/atom/browser/atom_browser_context.cc index 9bb3f6455e60..1853f931b5e5 100644 --- a/atom/browser/atom_browser_context.cc +++ b/atom/browser/atom_browser_context.cc @@ -192,7 +192,8 @@ void AtomBrowserContext::RegisterPrefs(PrefRegistrySimple* pref_registry) { // static scoped_refptr AtomBrowserContext::From( - const std::string& partition, bool in_memory) { + const std::string& partition, bool in_memory, + const base::DictionaryValue& options) { auto browser_context = brightray::BrowserContext::Get(partition, in_memory); if (browser_context) return static_cast(browser_context.get()); diff --git a/atom/browser/atom_browser_context.h b/atom/browser/atom_browser_context.h index 47c05a00cf4a..5e83b69808d3 100644 --- a/atom/browser/atom_browser_context.h +++ b/atom/browser/atom_browser_context.h @@ -19,9 +19,11 @@ class WebViewManager; class AtomBrowserContext : public brightray::BrowserContext { public: // Get or create the BrowserContext according to its |partition| and - // |in_memory|. + // |in_memory|. The |options| will be passed to constructor when there is no + // existing BrowserContext. static scoped_refptr From( - const std::string& partition, bool in_memory); + const std::string& partition, bool in_memory, + const base::DictionaryValue& options = base::DictionaryValue()); void SetUserAgent(const std::string& user_agent);