diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /toolkit/mozapps/extensions/amContentHandler.jsm | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/mozapps/extensions/amContentHandler.jsm')
-rw-r--r-- | toolkit/mozapps/extensions/amContentHandler.jsm | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/amContentHandler.jsm b/toolkit/mozapps/extensions/amContentHandler.jsm new file mode 100644 index 0000000000..b655409850 --- /dev/null +++ b/toolkit/mozapps/extensions/amContentHandler.jsm @@ -0,0 +1,81 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const XPI_CONTENT_TYPE = "application/x-xpinstall"; +const MSG_INSTALL_ADDON = "WebInstallerInstallAddonFromWebpage"; + +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); + +function amContentHandler() {} + +amContentHandler.prototype = { + /** + * Handles a new request for an application/x-xpinstall file. + * + * @param aMimetype + * The mimetype of the file + * @param aContext + * The context passed to nsIChannel.asyncOpen + * @param aRequest + * The nsIRequest dealing with the content + */ + handleContent(aMimetype, aContext, aRequest) { + if (aMimetype != XPI_CONTENT_TYPE) { + throw Components.Exception("", Cr.NS_ERROR_WONT_HANDLE_CONTENT); + } + + if (!(aRequest instanceof Ci.nsIChannel)) { + throw Components.Exception("", Cr.NS_ERROR_WONT_HANDLE_CONTENT); + } + + let uri = aRequest.URI; + + aRequest.cancel(Cr.NS_BINDING_ABORTED); + + let { loadInfo } = aRequest; + const { triggeringPrincipal } = loadInfo; + let browsingContext = loadInfo.targetBrowsingContext; + + let sourceHost; + let sourceURL; + + try { + sourceURL = + triggeringPrincipal.spec != "" ? triggeringPrincipal.spec : undefined; + sourceHost = triggeringPrincipal.host; + } catch (error) { + // Ignore errors when retrieving the host for the principal (e.g. data URIs return + // an NS_ERROR_FAILURE when principal.host is accessed). + } + + let install = { + uri: uri.spec, + hash: null, + name: null, + icon: null, + mimetype: XPI_CONTENT_TYPE, + triggeringPrincipal, + callbackID: -1, + method: "link", + sourceHost, + sourceURL, + browsingContext, + }; + + Services.cpmm.sendAsyncMessage(MSG_INSTALL_ADDON, install); + }, + + classID: Components.ID("{7beb3ba8-6ec3-41b4-b67c-da89b8518922}"), + QueryInterface: ChromeUtils.generateQI(["nsIContentHandler"]), + + log(aMsg) { + let msg = "amContentHandler.js: " + (aMsg.join ? aMsg.join("") : aMsg); + Services.console.logStringMessage(msg); + dump(msg + "\n"); + }, +}; + +var EXPORTED_SYMBOLS = ["amContentHandler"]; |