From d10552413578e24c4d4087268a3712767235761f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 1 Jun 2016 10:42:24 +0900 Subject: [PATCH] Cleanup the JavaScript code of session --- lib/browser/api/session.js | 19 ++++++++++++------- lib/browser/api/web-contents.js | 7 ------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/browser/api/session.js b/lib/browser/api/session.js index 9c42f3645603..49b169bd3ac5 100644 --- a/lib/browser/api/session.js +++ b/lib/browser/api/session.js @@ -1,14 +1,12 @@ +const {EventEmitter} = require('events') const bindings = process.atomBinding('session') + const PERSIST_PREFIX = 'persist:' // Returns the Session from |partition| string. -exports.fromPartition = function (partition) { - if (partition == null) { - partition = '' - } - if (partition === '') { - return exports.defaultSession - } +exports.fromPartition = function (partition = '') { + if (partition === '') return exports.defaultSession + if (partition.startsWith(PERSIST_PREFIX)) { return bindings.fromPartition(partition.substr(PERSIST_PREFIX.length), false) } else { @@ -23,3 +21,10 @@ Object.defineProperty(exports, 'defaultSession', { return bindings.fromPartition('', false) } }) + +const wrapSession = function (session) { + // Session is an EventEmitter. + Object.setPrototypeOf(session, EventEmitter.prototype) +} + +bindings._setWrapSession(wrapSession) diff --git a/lib/browser/api/web-contents.js b/lib/browser/api/web-contents.js index 0f79a185ffc9..fbb91879f80c 100644 --- a/lib/browser/api/web-contents.js +++ b/lib/browser/api/web-contents.js @@ -5,7 +5,6 @@ const {ipcMain, Menu, NavigationController} = require('electron') const binding = process.atomBinding('web_contents') const debuggerBinding = process.atomBinding('debugger') -const sessionBinding = process.atomBinding('session') let nextId = 0 @@ -212,14 +211,8 @@ let wrapDebugger = function (webContentsDebugger) { Object.setPrototypeOf(webContentsDebugger, EventEmitter.prototype) } -var wrapSession = function (session) { - // session is an EventEmitter. - Object.setPrototypeOf(session, EventEmitter.prototype) -} - binding._setWrapWebContents(wrapWebContents) debuggerBinding._setWrapDebugger(wrapDebugger) -sessionBinding._setWrapSession(wrapSession) module.exports = { create (options = {}) {