add docs
This commit is contained in:
parent
85800256de
commit
bdfc19ad20
3 changed files with 29 additions and 9 deletions
|
@ -19,10 +19,6 @@ var logAndThrow = function(callback, message) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
protocol.fromPartition = function(partition) {
|
|
||||||
return session.fromPartition(partition).protocol;
|
|
||||||
};
|
|
||||||
|
|
||||||
protocol.registerProtocol = function(scheme, handler, callback) {
|
protocol.registerProtocol = function(scheme, handler, callback) {
|
||||||
return logAndThrow(callback, 'registerProtocol API has been replaced by the register[File/Http/Buffer/String]Protocol API family, please switch to the new APIs.');
|
return logAndThrow(callback, 'registerProtocol API has been replaced by the register[File/Http/Buffer/String]Protocol API family, please switch to the new APIs.');
|
||||||
};
|
};
|
||||||
|
|
|
@ -523,3 +523,25 @@ The `listener` will be called with `listener(details)` when an error occurs.
|
||||||
* `timestamp` Double
|
* `timestamp` Double
|
||||||
* `fromCache` Boolean
|
* `fromCache` Boolean
|
||||||
* `error` String - The error description.
|
* `error` String - The error description.
|
||||||
|
|
||||||
|
#### `ses.protocol`
|
||||||
|
|
||||||
|
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)});
|
||||||
|
}, function (error) {
|
||||||
|
if (error)
|
||||||
|
console.error('Failed to register protocol')
|
||||||
|
});
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
|
@ -5,6 +5,7 @@ const qs = require('querystring');
|
||||||
const remote = require('electron').remote;
|
const remote = require('electron').remote;
|
||||||
const BrowserWindow = remote.require('electron').BrowserWindow;
|
const BrowserWindow = remote.require('electron').BrowserWindow;
|
||||||
const protocol = remote.require('electron').protocol;
|
const protocol = remote.require('electron').protocol;
|
||||||
|
const session = remote.require('electron').session;
|
||||||
|
|
||||||
describe('protocol module', function() {
|
describe('protocol module', function() {
|
||||||
var protocolName = 'sp';
|
var protocolName = 'sp';
|
||||||
|
@ -818,7 +819,7 @@ describe('protocol module', function() {
|
||||||
|
|
||||||
describe('protocol.fromPartition', function() {
|
describe('protocol.fromPartition', function() {
|
||||||
var partitionName = 'temp';
|
var partitionName = 'temp';
|
||||||
var tempProtocol = protocol.fromPartition(partitionName);
|
var tempProtocol = session.fromPartition(partitionName).protocol;
|
||||||
var w = null;
|
var w = null;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
|
@ -852,13 +853,12 @@ describe('protocol module', function() {
|
||||||
if (error) {
|
if (error) {
|
||||||
return done(error);
|
return done(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol.isProtocolHandled(protocolName, function(result) {
|
protocol.isProtocolHandled(protocolName, function(result) {
|
||||||
assert.equal(result, false);
|
assert.equal(result, false);
|
||||||
});
|
});
|
||||||
tempProtocol.isProtocolHandled(protocolName, function(result) {
|
tempProtocol.isProtocolHandled(protocolName, function(result) {
|
||||||
assert.equal(result, true);
|
assert.equal(result, true);
|
||||||
});
|
|
||||||
});
|
|
||||||
w.webContents.on('did-finish-load', function() {
|
w.webContents.on('did-finish-load', function() {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -866,3 +866,5 @@ describe('protocol module', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue