mobile/android/components/ContentDispatchChooser.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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

mercurial