Browse Source

fix spec and docs

deepak1556 8 years ago
parent
commit
4749e18fc0
4 changed files with 19 additions and 25 deletions
  1. 10 12
      docs/api/session.md
  2. 6 3
      lib/browser/api/session.js
  3. 3 3
      lib/browser/chrome-extension.js
  4. 0 7
      spec/api-session-spec.js

+ 10 - 12
docs/api/session.md

@@ -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.
 
 ```javascript
-const electron = require('electron');
-const app = electron.app;
-const session = electron.session;
-const path = require('path');
-
-app.on('ready', function() {
-  const protocol = session.fromPartition(partitionName).protocol;
-  protocol.registerFileProtocol('atom', function(request, callback) {
-    var url = request.url.substr(7);
-    callback({path: path.normalize(__dirname + '/' + url)});
+const {app, session} = require('electron')
+const path = require('path')
+
+app.on('ready', function () {
+  const protocol = session.fromPartition(partitionName).protocol
+  protocol.registerFileProtocol('atom', function (request, callback) {
+    var url = request.url.substr(7)
+    callback({path: path.normalize(__dirname + '/' + url)})
   }, function (error) {
     if (error)
       console.error('Failed to register protocol')
-  });
-});
+  })
+})

+ 6 - 3
lib/browser/api/session.js

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

+ 3 - 3
lib/browser/chrome-extension.js

@@ -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 renderProcessPreferences = process.atomBinding('render_process_preferences').forAllBrowserWindow()
 
@@ -280,8 +280,8 @@ app.once('ready', function () {
       }
     })
   }
-  process.on('session-created', function (session) {
-    session.protocol.registerBufferProtocol('chrome-extension', chromeExtensionHandler, function (error) {
+  session.on('session-created', function (ses) {
+    ses.protocol.registerBufferProtocol('chrome-extension', chromeExtensionHandler, function (error) {
       if (error) {
         console.error(`Unable to register chrome-extension protocol: ${error}`)
       }

+ 0 - 7
spec/api-session-spec.js

@@ -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) {
       var handler = function (error, callback) {
         callback({