mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-26 19:55:39 +00:00
29414a264f
Also changed some function names to attempt to guarantee uniqueness across API files. MozReview-Commit-ID: GnwWwTADF3a --HG-- extra : rebase_source : 2d51f3de2958089de97ce98ed1f01c68ec0ed74a
74 lines
2.6 KiB
JavaScript
74 lines
2.6 KiB
JavaScript
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
/* vim: set sts=2 sw=2 et tw=80: */
|
|
"use strict";
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "handlerService",
|
|
"@mozilla.org/uriloader/handler-service;1",
|
|
"nsIHandlerService");
|
|
XPCOMUtils.defineLazyServiceGetter(this, "protocolService",
|
|
"@mozilla.org/uriloader/external-protocol-service;1",
|
|
"nsIExternalProtocolService");
|
|
Cu.importGlobalProperties(["URL"]);
|
|
|
|
const hasHandlerApp = handlerConfig => {
|
|
let protoInfo = protocolService.getProtocolHandlerInfo(handlerConfig.protocol);
|
|
let appHandlers = protoInfo.possibleApplicationHandlers;
|
|
for (let i = 0; i < appHandlers.length; i++) {
|
|
let handler = appHandlers.queryElementAt(i, Ci.nsISupports);
|
|
if (handler instanceof Ci.nsIWebHandlerApp &&
|
|
handler.uriTemplate === handlerConfig.uriTemplate) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
|
|
this.protocolHandlers = class extends ExtensionAPI {
|
|
onManifestEntry(entryName) {
|
|
let {extension} = this;
|
|
let {manifest} = extension;
|
|
|
|
for (let handlerConfig of manifest.protocol_handlers) {
|
|
if (hasHandlerApp(handlerConfig)) {
|
|
continue;
|
|
}
|
|
|
|
let handler = Cc["@mozilla.org/uriloader/web-handler-app;1"]
|
|
.createInstance(Ci.nsIWebHandlerApp);
|
|
handler.name = handlerConfig.name;
|
|
handler.uriTemplate = handlerConfig.uriTemplate;
|
|
|
|
let protoInfo = protocolService.getProtocolHandlerInfo(handlerConfig.protocol);
|
|
protoInfo.possibleApplicationHandlers.appendElement(handler);
|
|
handlerService.store(protoInfo);
|
|
}
|
|
}
|
|
|
|
onShutdown(shutdownReason) {
|
|
let {extension} = this;
|
|
let {manifest} = extension;
|
|
|
|
if (shutdownReason === "APP_SHUTDOWN") {
|
|
return;
|
|
}
|
|
|
|
for (let handlerConfig of manifest.protocol_handlers) {
|
|
let protoInfo = protocolService.getProtocolHandlerInfo(handlerConfig.protocol);
|
|
let appHandlers = protoInfo.possibleApplicationHandlers;
|
|
for (let i = 0; i < appHandlers.length; i++) {
|
|
let handler = appHandlers.queryElementAt(i, Ci.nsISupports);
|
|
if (handler instanceof Ci.nsIWebHandlerApp &&
|
|
handler.uriTemplate === handlerConfig.uriTemplate) {
|
|
appHandlers.removeElementAt(i);
|
|
if (protoInfo.preferredApplicationHandler === handler) {
|
|
protoInfo.preferredApplicationHandler = null;
|
|
protoInfo.alwaysAskBeforeHandling = true;
|
|
}
|
|
handlerService.store(protoInfo);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|