Add session.defaultSession and remove app.defaultSession

The latter has never been a public API, no need to keep it.
This commit is contained in:
Cheng Zhao 2015-11-19 21:03:42 +08:00
parent 47d7d49d19
commit 1392873cbc
5 changed files with 15 additions and 26 deletions

View file

@ -206,14 +206,6 @@ void App::OnWillFinishLaunching() {
} }
void App::OnFinishLaunching() { void App::OnFinishLaunching() {
// Create the defaultSession.
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
auto browser_context = static_cast<AtomBrowserContext*>(
AtomBrowserMainParts::Get()->browser_context());
auto handle = Session::CreateFrom(isolate(), browser_context);
default_session_.Reset(isolate(), handle.ToV8());
Emit("ready"); Emit("ready");
} }
@ -325,13 +317,6 @@ std::string App::GetLocale() {
return l10n_util::GetApplicationLocale(""); return l10n_util::GetApplicationLocale("");
} }
v8::Local<v8::Value> App::DefaultSession(v8::Isolate* isolate) {
if (default_session_.IsEmpty())
return v8::Null(isolate);
else
return v8::Local<v8::Value>::New(isolate, default_session_);
}
bool App::MakeSingleInstance( bool App::MakeSingleInstance(
const ProcessSingleton::NotificationCallback& callback) { const ProcessSingleton::NotificationCallback& callback) {
if (process_singleton_.get()) if (process_singleton_.get())
@ -382,8 +367,7 @@ mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
.SetMethod("allowNTLMCredentialsForAllDomains", .SetMethod("allowNTLMCredentialsForAllDomains",
&App::AllowNTLMCredentialsForAllDomains) &App::AllowNTLMCredentialsForAllDomains)
.SetMethod("getLocale", &App::GetLocale) .SetMethod("getLocale", &App::GetLocale)
.SetMethod("makeSingleInstance", &App::MakeSingleInstance) .SetMethod("makeSingleInstance", &App::MakeSingleInstance);
.SetProperty("defaultSession", &App::DefaultSession);
} }
// static // static

View file

@ -87,9 +87,6 @@ class App : public AtomBrowserClient::Delegate,
bool MakeSingleInstance( bool MakeSingleInstance(
const ProcessSingleton::NotificationCallback& callback); const ProcessSingleton::NotificationCallback& callback);
std::string GetLocale(); std::string GetLocale();
v8::Local<v8::Value> DefaultSession(v8::Isolate* isolate);
v8::Global<v8::Value> default_session_;
scoped_ptr<ProcessSingleton> process_singleton_; scoped_ptr<ProcessSingleton> process_singleton_;

View file

@ -1,4 +1,4 @@
electron = require 'electron' {deprecate, session, Menu} = require 'electron'
{EventEmitter} = require 'events' {EventEmitter} = require 'events'
bindings = process.atomBinding 'app' bindings = process.atomBinding 'app'
@ -8,10 +8,10 @@ app = bindings.app
app.__proto__ = EventEmitter.prototype app.__proto__ = EventEmitter.prototype
app.setApplicationMenu = (menu) -> app.setApplicationMenu = (menu) ->
electron.Menu.setApplicationMenu menu Menu.setApplicationMenu menu
app.getApplicationMenu = -> app.getApplicationMenu = ->
electron.Menu.getApplicationMenu() Menu.getApplicationMenu()
app.commandLine = app.commandLine =
appendSwitch: bindings.appendSwitch, appendSwitch: bindings.appendSwitch,
@ -35,7 +35,8 @@ app.getAppPath = ->
appPath appPath
# Helpers. # Helpers.
app.resolveProxy = (url, callback) -> @defaultSession.resolveProxy url, callback app.resolveProxy = (url, callback) ->
session.defaultSession.resolveProxy url, callback
# Routes the events to webContents. # Routes the events to webContents.
for name in ['login', 'certificate-error', 'select-client-certificate'] for name in ['login', 'certificate-error', 'select-client-certificate']
@ -44,7 +45,6 @@ for name in ['login', 'certificate-error', 'select-client-certificate']
webContents.emit name, event, args... webContents.emit name, event, args...
# Deprecated. # Deprecated.
{deprecate} = electron
app.getHomeDir = deprecate 'app.getHomeDir', 'app.getPath', -> app.getHomeDir = deprecate 'app.getHomeDir', 'app.getPath', ->
@getPath 'home' @getPath 'home'
app.getDataPath = deprecate 'app.getDataPath', 'app.getPath', -> app.getDataPath = deprecate 'app.getDataPath', 'app.getPath', ->

View file

@ -1,10 +1,12 @@
{app, ipcMain, deprecate} = require 'electron' {ipcMain, deprecate} = require 'electron'
{EventEmitter} = require 'events' {EventEmitter} = require 'events'
{BrowserWindow} = process.atomBinding 'window' {BrowserWindow} = process.atomBinding 'window'
BrowserWindow::__proto__ = EventEmitter.prototype BrowserWindow::__proto__ = EventEmitter.prototype
BrowserWindow::_init = -> BrowserWindow::_init = ->
{app} = require 'electron' # avoid recursive require.
# Simulate the application menu on platforms other than OS X. # Simulate the application menu on platforms other than OS X.
if process.platform isnt 'darwin' if process.platform isnt 'darwin'
menu = app.getApplicationMenu() menu = app.getApplicationMenu()

View file

@ -4,12 +4,18 @@ bindings = process.atomBinding 'session'
PERSIST_PERFIX = 'persist:' PERSIST_PERFIX = 'persist:'
# Returns the Session from |partition| string.
exports.fromPartition = (partition='') -> exports.fromPartition = (partition='') ->
if partition.startsWith PERSIST_PERFIX if partition.startsWith PERSIST_PERFIX
bindings.fromPartition partition.substr(PERSIST_PERFIX.length), false bindings.fromPartition partition.substr(PERSIST_PERFIX.length), false
else else
bindings.fromPartition partition, true bindings.fromPartition partition, true
# Returns the default session.
Object.defineProperty exports, 'defaultSession',
enumerable: true
get: -> exports.fromPartition ''
wrapSession = (session) -> wrapSession = (session) ->
# session is an EventEmitter. # session is an EventEmitter.
session.__proto__ = EventEmitter.prototype session.__proto__ = EventEmitter.prototype