Skip to content

Commit bdfc19a

Browse files
committed
add docs
1 parent 8580025 commit bdfc19a

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

atom/browser/api/lib/protocol.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ var logAndThrow = function(callback, message) {
1919
}
2020
};
2121

22-
protocol.fromPartition = function(partition) {
23-
return session.fromPartition(partition).protocol;
24-
};
25-
2622
protocol.registerProtocol = function(scheme, handler, callback) {
2723
return logAndThrow(callback, 'registerProtocol API has been replaced by the register[File/Http/Buffer/String]Protocol API family, please switch to the new APIs.');
2824
};

docs/api/session.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,3 +523,25 @@ The `listener` will be called with `listener(details)` when an error occurs.
523523
* `timestamp` Double
524524
* `fromCache` Boolean
525525
* `error` String - The error description.
526+
527+
#### `ses.protocol`
528+
529+
Returns an instance of [protocol](protocol.md) module for this session.
530+
531+
```javascript
532+
const electron = require('electron');
533+
const app = electron.app;
534+
const session = electron.session;
535+
const path = require('path');
536+
537+
app.on('ready', function() {
538+
const protocol = session.fromPartition(partitionName).protocol;
539+
protocol.registerFileProtocol('atom', function(request, callback) {
540+
var url = request.url.substr(7);
541+
callback({path: path.normalize(__dirname + '/' + url)});
542+
}, function (error) {
543+
if (error)
544+
console.error('Failed to register protocol')
545+
});
546+
});
547+
```

spec/api-protocol-spec.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const qs = require('querystring');
55
const remote = require('electron').remote;
66
const BrowserWindow = remote.require('electron').BrowserWindow;
77
const protocol = remote.require('electron').protocol;
8+
const session = remote.require('electron').session;
89

910
describe('protocol module', function() {
1011
var protocolName = 'sp';
@@ -818,7 +819,7 @@ describe('protocol module', function() {
818819

819820
describe('protocol.fromPartition', function() {
820821
var partitionName = 'temp';
821-
var tempProtocol = protocol.fromPartition(partitionName);
822+
var tempProtocol = session.fromPartition(partitionName).protocol;
822823
var w = null;
823824

824825
beforeEach(function() {
@@ -852,17 +853,18 @@ describe('protocol module', function() {
852853
if (error) {
853854
return done(error);
854855
}
856+
855857
protocol.isProtocolHandled(protocolName, function(result) {
856858
assert.equal(result, false);
857859
});
858860
tempProtocol.isProtocolHandled(protocolName, function(result) {
859861
assert.equal(result, true);
862+
w.webContents.on('did-finish-load', function() {
863+
done();
864+
});
865+
w.loadURL(protocolName + "://fake-host");
860866
});
861867
});
862-
w.webContents.on('did-finish-load', function() {
863-
done();
864-
});
865-
w.loadURL(protocolName + "://fake-host");
866868
});
867869
});
868870
});

0 commit comments

Comments
 (0)