michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// Constants michael@0: michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: const Cr = Components.results; michael@0: michael@0: const CONTENT_HANDLING_URL = "chrome://mozapps/content/handling/dialog.xul"; michael@0: const STRINGBUNDLE_URL = "chrome://mozapps/locale/handling/handling.properties"; michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// nsContentDispatchChooser class michael@0: michael@0: function nsContentDispatchChooser() michael@0: { michael@0: } michael@0: michael@0: nsContentDispatchChooser.prototype = michael@0: { michael@0: classID: Components.ID("e35d5067-95bc-4029-8432-e8f1e431148d"), michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //// nsIContentDispatchChooser michael@0: michael@0: ask: function ask(aHandler, aWindowContext, aURI, aReason) michael@0: { michael@0: var window = null; michael@0: try { michael@0: if (aWindowContext) michael@0: window = aWindowContext.getInterface(Ci.nsIDOMWindow); michael@0: } catch (e) { /* it's OK to not have a window */ } michael@0: michael@0: var sbs = Cc["@mozilla.org/intl/stringbundle;1"]. michael@0: getService(Ci.nsIStringBundleService); michael@0: var bundle = sbs.createBundle(STRINGBUNDLE_URL); michael@0: michael@0: var xai = Cc["@mozilla.org/xre/app-info;1"]. michael@0: getService(Ci.nsIXULAppInfo); michael@0: // TODO when this is hooked up for content, we will need different strings michael@0: // for most of these michael@0: var arr = [bundle.GetStringFromName("protocol.title"), michael@0: "", michael@0: bundle.GetStringFromName("protocol.description"), michael@0: bundle.GetStringFromName("protocol.choices.label"), michael@0: bundle.formatStringFromName("protocol.checkbox.label", michael@0: [aURI.scheme], 1), michael@0: bundle.GetStringFromName("protocol.checkbox.accesskey"), michael@0: bundle.formatStringFromName("protocol.checkbox.extra", michael@0: [xai.name], 1)]; michael@0: michael@0: var params = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray); michael@0: let SupportsString = Components.Constructor( michael@0: "@mozilla.org/supports-string;1", michael@0: "nsISupportsString"); michael@0: for each (let text in arr) { michael@0: let string = new SupportsString; michael@0: string.data = text; michael@0: params.appendElement(string, false); michael@0: } michael@0: params.appendElement(aHandler, false); michael@0: params.appendElement(aURI, false); michael@0: params.appendElement(aWindowContext, false); michael@0: michael@0: var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"]. michael@0: getService(Ci.nsIWindowWatcher); michael@0: ww.openWindow(window, michael@0: CONTENT_HANDLING_URL, michael@0: null, michael@0: "chrome,dialog=yes,resizable,centerscreen", michael@0: params); michael@0: }, michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //// nsISupports michael@0: michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentDispatchChooser]) michael@0: }; michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// Module michael@0: michael@0: let components = [nsContentDispatchChooser]; michael@0: michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);