Add options to session.fromPartition
This commit is contained in:
parent
00804e5f98
commit
e213e09c3e
4 changed files with 19 additions and 9 deletions
|
@ -21,6 +21,7 @@
|
||||||
#include "atom/common/native_mate_converters/gurl_converter.h"
|
#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/file_path_converter.h"
|
||||||
#include "atom/common/native_mate_converters/net_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 "atom/common/node_includes.h"
|
||||||
#include "base/files/file_path.h"
|
#include "base/files/file_path.h"
|
||||||
#include "base/guid.h"
|
#include "base/guid.h"
|
||||||
|
@ -536,16 +537,17 @@ mate::Handle<Session> Session::CreateFrom(
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::Handle<Session> Session::FromPartition(
|
mate::Handle<Session> Session::FromPartition(
|
||||||
v8::Isolate* isolate, const std::string& partition) {
|
v8::Isolate* isolate, const std::string& partition,
|
||||||
|
const base::DictionaryValue& options) {
|
||||||
scoped_refptr<AtomBrowserContext> browser_context;
|
scoped_refptr<AtomBrowserContext> browser_context;
|
||||||
if (partition.empty()) {
|
if (partition.empty()) {
|
||||||
browser_context = AtomBrowserContext::From("", false);
|
browser_context = AtomBrowserContext::From("", false, options);
|
||||||
} else if (base::StartsWith(partition, kPersistPrefix,
|
} else if (base::StartsWith(partition, kPersistPrefix,
|
||||||
base::CompareCase::SENSITIVE)) {
|
base::CompareCase::SENSITIVE)) {
|
||||||
std::string name = partition.substr(8);
|
std::string name = partition.substr(8);
|
||||||
browser_context = AtomBrowserContext::From(name, false);
|
browser_context = AtomBrowserContext::From(name, false, options);
|
||||||
} else {
|
} else {
|
||||||
browser_context = AtomBrowserContext::From(partition, true);
|
browser_context = AtomBrowserContext::From(partition, true, options);
|
||||||
}
|
}
|
||||||
return CreateFrom(isolate, browser_context.get());
|
return CreateFrom(isolate, browser_context.get());
|
||||||
}
|
}
|
||||||
|
@ -593,7 +595,10 @@ v8::Local<v8::Value> FromPartition(
|
||||||
args->ThrowError("Session can only be received when app is ready");
|
args->ThrowError("Session can only be received when app is ready");
|
||||||
return v8::Null(args->isolate());
|
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<v8::Object> exports, v8::Local<v8::Value> unused,
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "atom/browser/api/trackable_object.h"
|
#include "atom/browser/api/trackable_object.h"
|
||||||
|
#include "base/values.h"
|
||||||
#include "content/public/browser/download_manager.h"
|
#include "content/public/browser/download_manager.h"
|
||||||
#include "native_mate/handle.h"
|
#include "native_mate/handle.h"
|
||||||
#include "net/base/completion_callback.h"
|
#include "net/base/completion_callback.h"
|
||||||
|
@ -49,7 +50,8 @@ class Session: public mate::TrackableObject<Session>,
|
||||||
|
|
||||||
// Gets the Session of |partition|.
|
// Gets the Session of |partition|.
|
||||||
static mate::Handle<Session> FromPartition(
|
static mate::Handle<Session> 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(); }
|
AtomBrowserContext* browser_context() const { return browser_context_.get(); }
|
||||||
|
|
||||||
|
|
|
@ -192,7 +192,8 @@ void AtomBrowserContext::RegisterPrefs(PrefRegistrySimple* pref_registry) {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
scoped_refptr<AtomBrowserContext> AtomBrowserContext::From(
|
scoped_refptr<AtomBrowserContext> 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);
|
auto browser_context = brightray::BrowserContext::Get(partition, in_memory);
|
||||||
if (browser_context)
|
if (browser_context)
|
||||||
return static_cast<AtomBrowserContext*>(browser_context.get());
|
return static_cast<AtomBrowserContext*>(browser_context.get());
|
||||||
|
|
|
@ -19,9 +19,11 @@ class WebViewManager;
|
||||||
class AtomBrowserContext : public brightray::BrowserContext {
|
class AtomBrowserContext : public brightray::BrowserContext {
|
||||||
public:
|
public:
|
||||||
// Get or create the BrowserContext according to its |partition| and
|
// 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<AtomBrowserContext> From(
|
static scoped_refptr<AtomBrowserContext> 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);
|
void SetUserAgent(const std::string& user_agent);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue