Merge pull request #5406 from deepak1556/protocol_standard_scheme_patch

protocol: fix registerStandardSchemes api
This commit is contained in:
Cheng Zhao 2016-05-09 09:12:35 +09:00
commit af0afecb45
13 changed files with 136 additions and 66 deletions

View file

@ -1,10 +1,6 @@
const app = require('electron').app
if (!app.isReady()) {
throw new Error('Can not initialize protocol module before app is ready')
}
const protocol = process.atomBinding('protocol').protocol
const {createProtocolObject, registerStandardSchemes} = process.atomBinding('protocol')
let protocol = null
// Warn about removed APIs.
var logAndThrow = function (callback, message) {
@ -16,16 +12,29 @@ var logAndThrow = function (callback, message) {
}
}
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.')
exports.registerStandardSchemes = function (schemes) {
if (app.isReady()) {
throw new Error('protocol.registerStandardSchemes should be called before app is ready')
}
registerStandardSchemes(schemes)
}
protocol.isHandledProtocol = function (scheme, callback) {
return logAndThrow(callback, 'isHandledProtocol API has been replaced by isProtocolHandled.')
}
app.once('ready', function () {
protocol = createProtocolObject()
// Be compatible with old APIs.
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.')
}
protocol.interceptProtocol = function (scheme, handler, callback) {
return logAndThrow(callback, 'interceptProtocol API has been replaced by the intercept[File/Http/Buffer/String]Protocol API family, please switch to the new APIs.')
}
protocol.isHandledProtocol = function (scheme, callback) {
return logAndThrow(callback, 'isHandledProtocol API has been replaced by isProtocolHandled.')
}
module.exports = protocol
protocol.interceptProtocol = function (scheme, handler, callback) {
return logAndThrow(callback, 'interceptProtocol API has been replaced by the intercept[File/Http/Buffer/String]Protocol API family, please switch to the new APIs.')
}
for (let method in protocol) {
exports[method] = protocol[method].bind(protocol)
}
})