fix spec and docs

This commit is contained in:
deepak1556 2016-06-09 10:38:45 +05:30
parent b91217f29e
commit 4749e18fc0
4 changed files with 18 additions and 24 deletions

View file

@ -553,18 +553,16 @@ The `listener` will be called with `listener(details)` when an error occurs.
Returns an instance of [protocol](protocol.md) module for this session. Returns an instance of [protocol](protocol.md) module for this session.
```javascript ```javascript
const electron = require('electron'); const {app, session} = require('electron')
const app = electron.app; const path = require('path')
const session = electron.session;
const path = require('path');
app.on('ready', function() { app.on('ready', function () {
const protocol = session.fromPartition(partitionName).protocol; const protocol = session.fromPartition(partitionName).protocol
protocol.registerFileProtocol('atom', function(request, callback) { protocol.registerFileProtocol('atom', function (request, callback) {
var url = request.url.substr(7); var url = request.url.substr(7)
callback({path: path.normalize(__dirname + '/' + url)}); callback({path: path.normalize(__dirname + '/' + url)})
}, function (error) { }, function (error) {
if (error) if (error)
console.error('Failed to register protocol') console.error('Failed to register protocol')
}); })
}); })

View file

@ -3,6 +3,7 @@ const electron = require('electron')
const bindings = process.atomBinding('session') const bindings = process.atomBinding('session')
const PERSIST_PREFIX = 'persist:' const PERSIST_PREFIX = 'persist:'
const Session = new EventEmitter()
// Wrapper of binding.fromPartition that checks for ready event. // Wrapper of binding.fromPartition that checks for ready event.
const fromPartition = function (partition, persist) { const fromPartition = function (partition, persist) {
@ -14,7 +15,7 @@ const fromPartition = function (partition, persist) {
} }
// Returns the Session from |partition| string. // Returns the Session from |partition| string.
exports.fromPartition = function (partition = '') { Session.fromPartition = function (partition = '') {
if (partition === '') return exports.defaultSession if (partition === '') return exports.defaultSession
if (partition.startsWith(PERSIST_PREFIX)) { if (partition.startsWith(PERSIST_PREFIX)) {
@ -25,7 +26,7 @@ exports.fromPartition = function (partition = '') {
} }
// Returns the default session. // Returns the default session.
Object.defineProperty(exports, 'defaultSession', { Object.defineProperty(Session, 'defaultSession', {
enumerable: true, enumerable: true,
get: function () { get: function () {
return fromPartition('', false) return fromPartition('', false)
@ -35,7 +36,9 @@ Object.defineProperty(exports, 'defaultSession', {
const wrapSession = function (session) { const wrapSession = function (session) {
// Session is an EventEmitter. // Session is an EventEmitter.
Object.setPrototypeOf(session, EventEmitter.prototype) Object.setPrototypeOf(session, EventEmitter.prototype)
process.emit('session-created', session) Session.emit('session-created', session)
} }
bindings._setWrapSession(wrapSession) bindings._setWrapSession(wrapSession)
module.exports = Session

View file

@ -1,4 +1,4 @@
const {app, ipcMain, protocol, webContents, BrowserWindow} = require('electron') const {app, ipcMain, session, webContents, BrowserWindow} = require('electron')
const {getAllWebContents} = process.atomBinding('web_contents') const {getAllWebContents} = process.atomBinding('web_contents')
const renderProcessPreferences = process.atomBinding('render_process_preferences').forAllBrowserWindow() const renderProcessPreferences = process.atomBinding('render_process_preferences').forAllBrowserWindow()
@ -280,8 +280,8 @@ app.once('ready', function () {
} }
}) })
} }
process.on('session-created', function (session) { session.on('session-created', function (ses) {
session.protocol.registerBufferProtocol('chrome-extension', chromeExtensionHandler, function (error) { ses.protocol.registerBufferProtocol('chrome-extension', chromeExtensionHandler, function (error) {
if (error) { if (error) {
console.error(`Unable to register chrome-extension protocol: ${error}`) console.error(`Unable to register chrome-extension protocol: ${error}`)
} }

View file

@ -288,13 +288,6 @@ describe('session module', function () {
}) })
}) })
afterEach(function () {
if (w != null) {
w.destroy()
}
w = null
})
it('handles requests from a partition', function (done) { it('handles requests from a partition', function (done) {
var handler = function (error, callback) { var handler = function (error, callback) {
callback({ callback({