Add session module

This commit is contained in:
Cheng Zhao 2015-11-19 20:47:11 +08:00
parent b9ddb0c268
commit 47d7d49d19
5 changed files with 22 additions and 7 deletions

View file

@ -2,7 +2,6 @@ electron = require 'electron'
{EventEmitter} = require 'events'
bindings = process.atomBinding 'app'
sessionBindings = process.atomBinding 'session'
downloadItemBindings = process.atomBinding 'download_item'
app = bindings.app
@ -61,11 +60,6 @@ deprecate.event app, 'activate-with-no-open-windows', 'activate', (event, hasVis
deprecate.event app, 'select-certificate', 'select-client-certificate'
# Wrappers for native classes.
wrapSession = (session) ->
# session is an EventEmitter.
session.__proto__ = EventEmitter.prototype
sessionBindings._setWrapSession wrapSession
wrapDownloadItem = (downloadItem) ->
# downloadItem is an EventEmitter.
downloadItem.__proto__ = EventEmitter.prototype

View file

@ -42,6 +42,9 @@ Object.defineProperties module.exports,
screen:
enumerable: true
get: -> require '../screen'
session:
enumerable: true
get: -> require '../session'
Tray:
enumerable: true
get: -> require '../tray'

View file

@ -0,0 +1,17 @@
{EventEmitter} = require 'events'
bindings = process.atomBinding 'session'
PERSIST_PERFIX = 'persist:'
exports.fromPartition = (partition='') ->
if partition.startsWith PERSIST_PERFIX
bindings.fromPartition partition.substr(PERSIST_PERFIX.length), false
else
bindings.fromPartition partition, true
wrapSession = (session) ->
# session is an EventEmitter.
session.__proto__ = EventEmitter.prototype
bindings._setWrapSession wrapSession

View file

@ -1,5 +1,5 @@
{EventEmitter} = require 'events'
{deprecate, ipcMain, NavigationController, Menu} = require 'electron'
{deprecate, ipcMain, session, NavigationController, Menu} = require 'electron'
binding = process.atomBinding 'web_contents'

View file

@ -26,6 +26,7 @@
'atom/browser/api/lib/power-monitor.coffee',
'atom/browser/api/lib/power-save-blocker.coffee',
'atom/browser/api/lib/protocol.coffee',
'atom/browser/api/lib/session.coffee',
'atom/browser/api/lib/screen.coffee',
'atom/browser/api/lib/tray.coffee',
'atom/browser/api/lib/web-contents.coffee',