toolkit/mozapps/handling/nsContentDispatchChooser.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
     7 ////////////////////////////////////////////////////////////////////////////////
     8 //// Constants
    10 const Cc = Components.classes;
    11 const Ci = Components.interfaces;
    12 const Cr = Components.results;
    14 const CONTENT_HANDLING_URL = "chrome://mozapps/content/handling/dialog.xul";
    15 const STRINGBUNDLE_URL = "chrome://mozapps/locale/handling/handling.properties";
    17 ////////////////////////////////////////////////////////////////////////////////
    18 //// nsContentDispatchChooser class
    20 function nsContentDispatchChooser()
    21 {
    22 }
    24 nsContentDispatchChooser.prototype =
    25 {
    26   classID: Components.ID("e35d5067-95bc-4029-8432-e8f1e431148d"),
    28   //////////////////////////////////////////////////////////////////////////////
    29   //// nsIContentDispatchChooser
    31   ask: function ask(aHandler, aWindowContext, aURI, aReason)
    32   {
    33     var window = null;
    34     try {
    35       if (aWindowContext)
    36         window = aWindowContext.getInterface(Ci.nsIDOMWindow);
    37     } catch (e) { /* it's OK to not have a window */ }
    39     var sbs = Cc["@mozilla.org/intl/stringbundle;1"].
    40               getService(Ci.nsIStringBundleService);
    41     var bundle = sbs.createBundle(STRINGBUNDLE_URL);
    43     var xai = Cc["@mozilla.org/xre/app-info;1"].
    44               getService(Ci.nsIXULAppInfo);
    45     // TODO when this is hooked up for content, we will need different strings
    46     //      for most of these
    47     var arr = [bundle.GetStringFromName("protocol.title"),
    48                "",
    49                bundle.GetStringFromName("protocol.description"),
    50                bundle.GetStringFromName("protocol.choices.label"),
    51                bundle.formatStringFromName("protocol.checkbox.label",
    52                                            [aURI.scheme], 1),
    53                bundle.GetStringFromName("protocol.checkbox.accesskey"),
    54                bundle.formatStringFromName("protocol.checkbox.extra",
    55                                            [xai.name], 1)];
    57     var params = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
    58     let SupportsString = Components.Constructor(
    59                            "@mozilla.org/supports-string;1",
    60                            "nsISupportsString");
    61     for each (let text in arr) {
    62       let string = new SupportsString;
    63       string.data = text;
    64       params.appendElement(string, false);
    65     }
    66     params.appendElement(aHandler, false);
    67     params.appendElement(aURI, false);
    68     params.appendElement(aWindowContext, false);
    70     var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
    71              getService(Ci.nsIWindowWatcher);
    72     ww.openWindow(window,
    73                   CONTENT_HANDLING_URL,
    74                   null,
    75                   "chrome,dialog=yes,resizable,centerscreen",
    76                   params);
    77   },
    79   //////////////////////////////////////////////////////////////////////////////
    80   //// nsISupports
    82   QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentDispatchChooser])
    83 };
    85 ////////////////////////////////////////////////////////////////////////////////
    86 //// Module
    88 let components = [nsContentDispatchChooser];
    90 this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);

mercurial