Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 const Cc = Components.classes;
8 const Ci = Components.interfaces;
9 const Cr = Components.results;
11 const XPI_CONTENT_TYPE = "application/x-xpinstall";
13 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
15 function amContentHandler() {
16 }
18 amContentHandler.prototype = {
19 /**
20 * Handles a new request for an application/x-xpinstall file.
21 *
22 * @param aMimetype
23 * The mimetype of the file
24 * @param aContext
25 * The context passed to nsIChannel.asyncOpen
26 * @param aRequest
27 * The nsIRequest dealing with the content
28 */
29 handleContent: function XCH_handleContent(aMimetype, aContext, aRequest) {
30 if (aMimetype != XPI_CONTENT_TYPE)
31 throw Cr.NS_ERROR_WONT_HANDLE_CONTENT;
33 if (!(aRequest instanceof Ci.nsIChannel))
34 throw Cr.NS_ERROR_WONT_HANDLE_CONTENT;
36 let uri = aRequest.URI;
38 let window = null;
39 let callbacks = aRequest.notificationCallbacks ?
40 aRequest.notificationCallbacks :
41 aRequest.loadGroup.notificationCallbacks;
42 if (callbacks)
43 window = callbacks.getInterface(Ci.nsIDOMWindow);
45 aRequest.cancel(Cr.NS_BINDING_ABORTED);
47 let appinfo = Cc["@mozilla.org/xre/app-info;1"].
48 getService(Ci.nsIXULRuntime);
49 if (appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT) {
50 try {
51 if (!window.InstallTrigger)
52 window = window.wrappedJSObject;
54 if (window.InstallTrigger)
55 window.InstallTrigger.startSoftwareUpdate(uri.spec);
56 else
57 this.log("Window does not have an InstallTrigger");
58 } catch(ex) {
59 this.log(ex);
60 }
61 }
62 else {
63 let referer = null;
64 if (aRequest instanceof Ci.nsIPropertyBag2) {
65 referer = aRequest.getPropertyAsInterface("docshell.internalReferrer",
66 Ci.nsIURI);
67 }
69 let manager = Cc["@mozilla.org/addons/integration;1"].
70 getService(Ci.amIWebInstaller);
71 manager.installAddonsFromWebpage(aMimetype, window, referer, [uri.spec],
72 [null], [null], [null], null, 1);
73 }
74 },
76 classID: Components.ID("{7beb3ba8-6ec3-41b4-b67c-da89b8518922}"),
77 QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentHandler]),
79 log : function XCH_log(aMsg) {
80 let msg = "amContentHandler.js: " + (aMsg.join ? aMsg.join("") : aMsg);
81 Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).
82 logStringMessage(msg);
83 dump(msg + "\n");
84 }
85 };
87 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([amContentHandler]);