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 {
|
||||
|
||||
const char kPersistPrefix[] = "persist:";
|
||||
|
||||
// The wrapSession funtion which is implemented in JavaScript
|
||||
using WrapSessionCallback = base::Callback<void(v8::Local<v8::Value>)>;
|
||||
WrapSessionCallback g_wrap_session;
|
||||
|
@ -534,10 +536,19 @@ mate::Handle<Session> Session::CreateFrom(
|
|||
|
||||
// static
|
||||
mate::Handle<Session> Session::FromPartition(
|
||||
v8::Isolate* isolate, const std::string& partition, bool in_memory) {
|
||||
auto browser_context = brightray::BrowserContext::From(partition, in_memory);
|
||||
return CreateFrom(isolate,
|
||||
static_cast<AtomBrowserContext*>(browser_context.get()));
|
||||
v8::Isolate* isolate, const std::string& partition) {
|
||||
scoped_refptr<brightray::BrowserContext> browser_context;
|
||||
if (partition.empty()) {
|
||||
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
|
||||
|
@ -578,13 +589,12 @@ void SetWrapSession(const WrapSessionCallback& callback) {
|
|||
namespace {
|
||||
|
||||
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()) {
|
||||
args->ThrowError("Session can only be received when app is ready");
|
||||
return v8::Null(args->isolate());
|
||||
}
|
||||
return atom::api::Session::FromPartition(
|
||||
args->isolate(), partition, in_memory).ToV8();
|
||||
return atom::api::Session::FromPartition(args->isolate(), partition).ToV8();
|
||||
}
|
||||
|
||||
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(
|
||||
v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
||||
|
||||
// Gets the Session of |partition| and |in_memory|.
|
||||
// Gets the Session of |partition|.
|
||||
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(); }
|
||||
|
||||
|
|
|
@ -285,16 +285,11 @@ WebContents::WebContents(v8::Isolate* isolate,
|
|||
std::string partition;
|
||||
mate::Handle<api::Session> session;
|
||||
if (options.Get("session", &session)) {
|
||||
} else if (options.Get("partition", &partition) && !partition.empty()) {
|
||||
bool in_memory = true;
|
||||
if (base::StartsWith(partition, "persist:", base::CompareCase::SENSITIVE)) {
|
||||
in_memory = false;
|
||||
partition = partition.substr(8);
|
||||
}
|
||||
session = Session::FromPartition(isolate, partition, in_memory);
|
||||
} else if (options.Get("partition", &partition)) {
|
||||
session = Session::FromPartition(isolate, partition);
|
||||
} else {
|
||||
// Use the default session if not specified.
|
||||
session = Session::FromPartition(isolate, "", false);
|
||||
session = Session::FromPartition(isolate, "");
|
||||
}
|
||||
session_.Reset(isolate, session.ToV8());
|
||||
|
||||
|
|
|
@ -2,24 +2,15 @@ const {EventEmitter} = require('events')
|
|||
const {app} = require('electron')
|
||||
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.
|
||||
Object.defineProperty(exports, 'defaultSession', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return fromPartition('', false)
|
||||
Object.defineProperties(exports, {
|
||||
defaultSession: {
|
||||
enumerable: true,
|
||||
get () { return fromPartition('') }
|
||||
},
|
||||
fromPartition: {
|
||||
enumerable: true,
|
||||
value: fromPartition
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue