Cleanup the JavaScript code of session
This commit is contained in:
parent
18f005092b
commit
d105524135
2 changed files with 12 additions and 14 deletions
|
@ -1,14 +1,12 @@
|
||||||
|
const {EventEmitter} = require('events')
|
||||||
const bindings = process.atomBinding('session')
|
const bindings = process.atomBinding('session')
|
||||||
|
|
||||||
const PERSIST_PREFIX = 'persist:'
|
const PERSIST_PREFIX = 'persist:'
|
||||||
|
|
||||||
// Returns the Session from |partition| string.
|
// Returns the Session from |partition| string.
|
||||||
exports.fromPartition = function (partition) {
|
exports.fromPartition = function (partition = '') {
|
||||||
if (partition == null) {
|
if (partition === '') return exports.defaultSession
|
||||||
partition = ''
|
|
||||||
}
|
|
||||||
if (partition === '') {
|
|
||||||
return exports.defaultSession
|
|
||||||
}
|
|
||||||
if (partition.startsWith(PERSIST_PREFIX)) {
|
if (partition.startsWith(PERSIST_PREFIX)) {
|
||||||
return bindings.fromPartition(partition.substr(PERSIST_PREFIX.length), false)
|
return bindings.fromPartition(partition.substr(PERSIST_PREFIX.length), false)
|
||||||
} else {
|
} else {
|
||||||
|
@ -23,3 +21,10 @@ Object.defineProperty(exports, 'defaultSession', {
|
||||||
return bindings.fromPartition('', false)
|
return bindings.fromPartition('', false)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const wrapSession = function (session) {
|
||||||
|
// Session is an EventEmitter.
|
||||||
|
Object.setPrototypeOf(session, EventEmitter.prototype)
|
||||||
|
}
|
||||||
|
|
||||||
|
bindings._setWrapSession(wrapSession)
|
||||||
|
|
|
@ -5,7 +5,6 @@ const {ipcMain, Menu, NavigationController} = require('electron')
|
||||||
|
|
||||||
const binding = process.atomBinding('web_contents')
|
const binding = process.atomBinding('web_contents')
|
||||||
const debuggerBinding = process.atomBinding('debugger')
|
const debuggerBinding = process.atomBinding('debugger')
|
||||||
const sessionBinding = process.atomBinding('session')
|
|
||||||
|
|
||||||
let nextId = 0
|
let nextId = 0
|
||||||
|
|
||||||
|
@ -212,14 +211,8 @@ let wrapDebugger = function (webContentsDebugger) {
|
||||||
Object.setPrototypeOf(webContentsDebugger, EventEmitter.prototype)
|
Object.setPrototypeOf(webContentsDebugger, EventEmitter.prototype)
|
||||||
}
|
}
|
||||||
|
|
||||||
var wrapSession = function (session) {
|
|
||||||
// session is an EventEmitter.
|
|
||||||
Object.setPrototypeOf(session, EventEmitter.prototype)
|
|
||||||
}
|
|
||||||
|
|
||||||
binding._setWrapWebContents(wrapWebContents)
|
binding._setWrapWebContents(wrapWebContents)
|
||||||
debuggerBinding._setWrapDebugger(wrapDebugger)
|
debuggerBinding._setWrapDebugger(wrapDebugger)
|
||||||
sessionBinding._setWrapSession(wrapSession)
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
create (options = {}) {
|
create (options = {}) {
|
||||||
|
|
Loading…
Reference in a new issue