]> khamidou — GitHub mirrors - electron.git/commitdiff
Add session.defaultSession and remove app.defaultSession
authorCheng Zhao <zcbenz@gmail.com>
Thu, 19 Nov 2015 13:03:42 +0000 (21:03 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 19 Nov 2015 13:03:42 +0000 (21:03 +0800)
The latter has never been a public API, no need to keep it.

atom/browser/api/atom_api_app.cc
atom/browser/api/atom_api_app.h
atom/browser/api/lib/app.coffee
atom/browser/api/lib/browser-window.coffee
atom/browser/api/lib/session.coffee

index 28c3b4c1598349c09d3afa05bf9515fcc7426d9c..697d6eca6aabe30b968fc865fc70b2b189f8d4f1 100644 (file)
@@ -206,14 +206,6 @@ void App::OnWillFinishLaunching() {
 }
 
 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");
 }
 
@@ -325,13 +317,6 @@ std::string App::GetLocale() {
   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(
     const ProcessSingleton::NotificationCallback& callback) {
   if (process_singleton_.get())
@@ -382,8 +367,7 @@ mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
       .SetMethod("allowNTLMCredentialsForAllDomains",
                  &App::AllowNTLMCredentialsForAllDomains)
       .SetMethod("getLocale", &App::GetLocale)
-      .SetMethod("makeSingleInstance", &App::MakeSingleInstance)
-      .SetProperty("defaultSession", &App::DefaultSession);
+      .SetMethod("makeSingleInstance", &App::MakeSingleInstance);
 }
 
 // static
index ee7e020791255bddd92d8a2daa80c4fb45ed495d..a6f99d65e0af1963c64f6ee29fb493a7a2b87c22 100644 (file)
@@ -87,9 +87,6 @@ class App : public AtomBrowserClient::Delegate,
   bool MakeSingleInstance(
       const ProcessSingleton::NotificationCallback& callback);
   std::string GetLocale();
-  v8::Local<v8::Value> DefaultSession(v8::Isolate* isolate);
-
-  v8::Global<v8::Value> default_session_;
 
   scoped_ptr<ProcessSingleton> process_singleton_;
 
index 9f9f5811d76ac9946251aa29e2f2201c7fb99a4f..c2116fb7bca4a05d9b80f3eeabd81c6f080182ce 100644 (file)
@@ -1,4 +1,4 @@
-electron = require 'electron'
+{deprecate, session, Menu} = require 'electron'
 {EventEmitter} = require 'events'
 
 bindings = process.atomBinding 'app'
@@ -8,10 +8,10 @@ app = bindings.app
 app.__proto__ = EventEmitter.prototype
 
 app.setApplicationMenu = (menu) ->
-  electron.Menu.setApplicationMenu menu
+  Menu.setApplicationMenu menu
 
 app.getApplicationMenu = ->
-  electron.Menu.getApplicationMenu()
+  Menu.getApplicationMenu()
 
 app.commandLine =
   appendSwitch: bindings.appendSwitch,
@@ -35,7 +35,8 @@ app.getAppPath = ->
   appPath
 
 # Helpers.
-app.resolveProxy = (url, callback) -> @defaultSession.resolveProxy url, callback
+app.resolveProxy = (url, callback) ->
+  session.defaultSession.resolveProxy url, callback
 
 # Routes the events to webContents.
 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...
 
 # Deprecated.
-{deprecate} = electron
 app.getHomeDir = deprecate 'app.getHomeDir', 'app.getPath', ->
   @getPath 'home'
 app.getDataPath = deprecate 'app.getDataPath', 'app.getPath', ->
index 99921372f14c74a142e3e3ebcdebbb9f02ae2f35..4cdffae87a6097154a42ef4b5d6cf5efd48da77b 100644 (file)
@@ -1,10 +1,12 @@
-{app, ipcMain, deprecate} = require 'electron'
+{ipcMain, deprecate} = require 'electron'
 {EventEmitter} = require 'events'
 
 {BrowserWindow} = process.atomBinding 'window'
 BrowserWindow::__proto__ = EventEmitter.prototype
 
 BrowserWindow::_init = ->
+  {app} = require 'electron'  # avoid recursive require.
+
   # Simulate the application menu on platforms other than OS X.
   if process.platform isnt 'darwin'
     menu = app.getApplicationMenu()
index e0fc7b6e0bca3cc72d54839575b3993b25567119..6abfe7925e695d0847cf314ca2375a2351ee0e62 100644 (file)
@@ -4,12 +4,18 @@ bindings = process.atomBinding 'session'
 
 PERSIST_PERFIX = 'persist:'
 
+# Returns the Session from |partition| string.
 exports.fromPartition = (partition='') ->
   if partition.startsWith PERSIST_PERFIX
     bindings.fromPartition partition.substr(PERSIST_PERFIX.length), false
   else
     bindings.fromPartition partition, true
 
+# Returns the default session.
+Object.defineProperty exports, 'defaultSession',
+  enumerable: true
+  get: -> exports.fromPartition ''
+
 wrapSession = (session) ->
   # session is an EventEmitter.
   session.__proto__ = EventEmitter.prototype