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 | const Ci = Components.interfaces; |
michael@0 | 6 | const Cu = Components.utils; |
michael@0 | 7 | const Cc = Components.classes; |
michael@0 | 8 | |
michael@0 | 9 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 10 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 11 | Cu.import("resource://gre/modules/Messaging.jsm"); |
michael@0 | 12 | |
michael@0 | 13 | function ContentDispatchChooser() {} |
michael@0 | 14 | |
michael@0 | 15 | ContentDispatchChooser.prototype = |
michael@0 | 16 | { |
michael@0 | 17 | classID: Components.ID("5a072a22-1e66-4100-afc1-07aed8b62fc5"), |
michael@0 | 18 | |
michael@0 | 19 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentDispatchChooser]), |
michael@0 | 20 | |
michael@0 | 21 | get protoSvc() { |
michael@0 | 22 | delete this.protoSvc; |
michael@0 | 23 | return this.protoSvc = Cc["@mozilla.org/uriloader/external-protocol-service;1"].getService(Ci.nsIExternalProtocolService); |
michael@0 | 24 | }, |
michael@0 | 25 | |
michael@0 | 26 | _getChromeWin: function getChromeWin() { |
michael@0 | 27 | try { |
michael@0 | 28 | return Services.wm.getMostRecentWindow("navigator:browser"); |
michael@0 | 29 | } catch (e) { |
michael@0 | 30 | throw Cr.NS_ERROR_FAILURE; |
michael@0 | 31 | } |
michael@0 | 32 | }, |
michael@0 | 33 | |
michael@0 | 34 | ask: function ask(aHandler, aWindowContext, aURI, aReason) { |
michael@0 | 35 | let window = null; |
michael@0 | 36 | try { |
michael@0 | 37 | if (aWindowContext) |
michael@0 | 38 | window = aWindowContext.getInterface(Ci.nsIDOMWindow); |
michael@0 | 39 | } catch (e) { /* it's OK to not have a window */ } |
michael@0 | 40 | |
michael@0 | 41 | // The current list is based purely on the scheme. Redo the query using the url to get more |
michael@0 | 42 | // specific results. |
michael@0 | 43 | aHandler = this.protoSvc.getProtocolHandlerInfoFromOS(aURI.spec, {}); |
michael@0 | 44 | |
michael@0 | 45 | // The first handler in the set is the Android Application Chooser (which will fall back to a default if one is set) |
michael@0 | 46 | // If we have more than one option, let the OS handle showing a list (if needed). |
michael@0 | 47 | if (aHandler.possibleApplicationHandlers.length > 1) { |
michael@0 | 48 | aHandler.launchWithURI(aURI, aWindowContext); |
michael@0 | 49 | } else { |
michael@0 | 50 | let win = this._getChromeWin(); |
michael@0 | 51 | if (win && win.NativeWindow) { |
michael@0 | 52 | let bundle = Services.strings.createBundle("chrome://browser/locale/handling.properties"); |
michael@0 | 53 | let failedText = bundle.GetStringFromName("protocol.failed"); |
michael@0 | 54 | let searchText = bundle.GetStringFromName("protocol.toast.search"); |
michael@0 | 55 | |
michael@0 | 56 | win.NativeWindow.toast.show(failedText, "long", { |
michael@0 | 57 | button: { |
michael@0 | 58 | label: searchText, |
michael@0 | 59 | callback: function() { |
michael@0 | 60 | let message = { |
michael@0 | 61 | type: "Intent:Open", |
michael@0 | 62 | url: "market://search?q=" + aURI.scheme, |
michael@0 | 63 | }; |
michael@0 | 64 | |
michael@0 | 65 | sendMessageToJava(message); |
michael@0 | 66 | } |
michael@0 | 67 | } |
michael@0 | 68 | }); |
michael@0 | 69 | } |
michael@0 | 70 | } |
michael@0 | 71 | }, |
michael@0 | 72 | }; |
michael@0 | 73 | |
michael@0 | 74 | this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ContentDispatchChooser]); |