1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/handling/nsContentDispatchChooser.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); 1.9 + 1.10 +//////////////////////////////////////////////////////////////////////////////// 1.11 +//// Constants 1.12 + 1.13 +const Cc = Components.classes; 1.14 +const Ci = Components.interfaces; 1.15 +const Cr = Components.results; 1.16 + 1.17 +const CONTENT_HANDLING_URL = "chrome://mozapps/content/handling/dialog.xul"; 1.18 +const STRINGBUNDLE_URL = "chrome://mozapps/locale/handling/handling.properties"; 1.19 + 1.20 +//////////////////////////////////////////////////////////////////////////////// 1.21 +//// nsContentDispatchChooser class 1.22 + 1.23 +function nsContentDispatchChooser() 1.24 +{ 1.25 +} 1.26 + 1.27 +nsContentDispatchChooser.prototype = 1.28 +{ 1.29 + classID: Components.ID("e35d5067-95bc-4029-8432-e8f1e431148d"), 1.30 + 1.31 + ////////////////////////////////////////////////////////////////////////////// 1.32 + //// nsIContentDispatchChooser 1.33 + 1.34 + ask: function ask(aHandler, aWindowContext, aURI, aReason) 1.35 + { 1.36 + var window = null; 1.37 + try { 1.38 + if (aWindowContext) 1.39 + window = aWindowContext.getInterface(Ci.nsIDOMWindow); 1.40 + } catch (e) { /* it's OK to not have a window */ } 1.41 + 1.42 + var sbs = Cc["@mozilla.org/intl/stringbundle;1"]. 1.43 + getService(Ci.nsIStringBundleService); 1.44 + var bundle = sbs.createBundle(STRINGBUNDLE_URL); 1.45 + 1.46 + var xai = Cc["@mozilla.org/xre/app-info;1"]. 1.47 + getService(Ci.nsIXULAppInfo); 1.48 + // TODO when this is hooked up for content, we will need different strings 1.49 + // for most of these 1.50 + var arr = [bundle.GetStringFromName("protocol.title"), 1.51 + "", 1.52 + bundle.GetStringFromName("protocol.description"), 1.53 + bundle.GetStringFromName("protocol.choices.label"), 1.54 + bundle.formatStringFromName("protocol.checkbox.label", 1.55 + [aURI.scheme], 1), 1.56 + bundle.GetStringFromName("protocol.checkbox.accesskey"), 1.57 + bundle.formatStringFromName("protocol.checkbox.extra", 1.58 + [xai.name], 1)]; 1.59 + 1.60 + var params = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray); 1.61 + let SupportsString = Components.Constructor( 1.62 + "@mozilla.org/supports-string;1", 1.63 + "nsISupportsString"); 1.64 + for each (let text in arr) { 1.65 + let string = new SupportsString; 1.66 + string.data = text; 1.67 + params.appendElement(string, false); 1.68 + } 1.69 + params.appendElement(aHandler, false); 1.70 + params.appendElement(aURI, false); 1.71 + params.appendElement(aWindowContext, false); 1.72 + 1.73 + var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"]. 1.74 + getService(Ci.nsIWindowWatcher); 1.75 + ww.openWindow(window, 1.76 + CONTENT_HANDLING_URL, 1.77 + null, 1.78 + "chrome,dialog=yes,resizable,centerscreen", 1.79 + params); 1.80 + }, 1.81 + 1.82 + ////////////////////////////////////////////////////////////////////////////// 1.83 + //// nsISupports 1.84 + 1.85 + QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentDispatchChooser]) 1.86 +}; 1.87 + 1.88 +//////////////////////////////////////////////////////////////////////////////// 1.89 +//// Module 1.90 + 1.91 +let components = [nsContentDispatchChooser]; 1.92 + 1.93 +this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);