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