Hide in_memory parameter in native interface
This commit is contained in:
parent
06a41cedab
commit
400bb8d0f3
4 changed files with 30 additions and 34 deletions
|
@ -164,6 +164,8 @@ namespace api {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
const char kPersistPrefix[] = "persist:";
|
||||||
|
|
||||||
// The wrapSession funtion which is implemented in JavaScript
|
// The wrapSession funtion which is implemented in JavaScript
|
||||||
using WrapSessionCallback = base::Callback<void(v8::Local<v8::Value>)>;
|
using WrapSessionCallback = base::Callback<void(v8::Local<v8::Value>)>;
|
||||||
WrapSessionCallback g_wrap_session;
|
WrapSessionCallback g_wrap_session;
|
||||||
|
@ -534,10 +536,19 @@ mate::Handle<Session> Session::CreateFrom(
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::Handle<Session> Session::FromPartition(
|
mate::Handle<Session> Session::FromPartition(
|
||||||
v8::Isolate* isolate, const std::string& partition, bool in_memory) {
|
v8::Isolate* isolate, const std::string& partition) {
|
||||||
auto browser_context = brightray::BrowserContext::From(partition, in_memory);
|
scoped_refptr<brightray::BrowserContext> browser_context;
|
||||||
return CreateFrom(isolate,
|
if (partition.empty()) {
|
||||||
static_cast<AtomBrowserContext*>(browser_context.get()));
|
browser_context = brightray::BrowserContext::From("", false);
|
||||||
|
} else if (base::StartsWith(partition, kPersistPrefix,
|
||||||
|
base::CompareCase::SENSITIVE)) {
|
||||||
|
std::string name = partition.substr(8);
|
||||||
|
browser_context = brightray::BrowserContext::From(name, false);
|
||||||
|
} else {
|
||||||
|
browser_context = brightray::BrowserContext::From(partition, true);
|
||||||
|
}
|
||||||
|
return CreateFrom(
|
||||||
|
isolate, static_cast<AtomBrowserContext*>(browser_context.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
@ -578,13 +589,12 @@ void SetWrapSession(const WrapSessionCallback& callback) {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
v8::Local<v8::Value> FromPartition(
|
v8::Local<v8::Value> FromPartition(
|
||||||
const std::string& partition, bool in_memory, mate::Arguments* args) {
|
const std::string& partition, mate::Arguments* args) {
|
||||||
if (!atom::Browser::Get()->is_ready()) {
|
if (!atom::Browser::Get()->is_ready()) {
|
||||||
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(
|
return atom::api::Session::FromPartition(args->isolate(), partition).ToV8();
|
||||||
args->isolate(), partition, in_memory).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,
|
||||||
|
|
|
@ -47,9 +47,9 @@ class Session: public mate::TrackableObject<Session>,
|
||||||
static mate::Handle<Session> CreateFrom(
|
static mate::Handle<Session> CreateFrom(
|
||||||
v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
||||||
|
|
||||||
// Gets the Session of |partition| and |in_memory|.
|
// Gets the Session of |partition|.
|
||||||
static mate::Handle<Session> FromPartition(
|
static mate::Handle<Session> FromPartition(
|
||||||
v8::Isolate* isolate, const std::string& partition, bool in_memory);
|
v8::Isolate* isolate, const std::string& partition);
|
||||||
|
|
||||||
AtomBrowserContext* browser_context() const { return browser_context_.get(); }
|
AtomBrowserContext* browser_context() const { return browser_context_.get(); }
|
||||||
|
|
||||||
|
|
|
@ -285,16 +285,11 @@ WebContents::WebContents(v8::Isolate* isolate,
|
||||||
std::string partition;
|
std::string partition;
|
||||||
mate::Handle<api::Session> session;
|
mate::Handle<api::Session> session;
|
||||||
if (options.Get("session", &session)) {
|
if (options.Get("session", &session)) {
|
||||||
} else if (options.Get("partition", &partition) && !partition.empty()) {
|
} else if (options.Get("partition", &partition)) {
|
||||||
bool in_memory = true;
|
session = Session::FromPartition(isolate, partition);
|
||||||
if (base::StartsWith(partition, "persist:", base::CompareCase::SENSITIVE)) {
|
|
||||||
in_memory = false;
|
|
||||||
partition = partition.substr(8);
|
|
||||||
}
|
|
||||||
session = Session::FromPartition(isolate, partition, in_memory);
|
|
||||||
} else {
|
} else {
|
||||||
// Use the default session if not specified.
|
// Use the default session if not specified.
|
||||||
session = Session::FromPartition(isolate, "", false);
|
session = Session::FromPartition(isolate, "");
|
||||||
}
|
}
|
||||||
session_.Reset(isolate, session.ToV8());
|
session_.Reset(isolate, session.ToV8());
|
||||||
|
|
||||||
|
|
|
@ -2,24 +2,15 @@ const {EventEmitter} = require('events')
|
||||||
const {app} = require('electron')
|
const {app} = require('electron')
|
||||||
const {fromPartition, _setWrapSession} = process.atomBinding('session')
|
const {fromPartition, _setWrapSession} = process.atomBinding('session')
|
||||||
|
|
||||||
const PERSIST_PREFIX = 'persist:'
|
|
||||||
|
|
||||||
// Returns the Session from |partition| string.
|
|
||||||
exports.fromPartition = function (partition = '') {
|
|
||||||
if (partition === '') return exports.defaultSession
|
|
||||||
|
|
||||||
if (partition.startsWith(PERSIST_PREFIX)) {
|
|
||||||
return fromPartition(partition.substr(PERSIST_PREFIX.length), false)
|
|
||||||
} else {
|
|
||||||
return fromPartition(partition, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the default session.
|
// Returns the default session.
|
||||||
Object.defineProperty(exports, 'defaultSession', {
|
Object.defineProperties(exports, {
|
||||||
enumerable: true,
|
defaultSession: {
|
||||||
get: function () {
|
enumerable: true,
|
||||||
return fromPartition('', false)
|
get () { return fromPartition('') }
|
||||||
|
},
|
||||||
|
fromPartition: {
|
||||||
|
enumerable: true,
|
||||||
|
value: fromPartition
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue