|
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/. */ |
|
4 |
|
5 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
6 |
|
7 //////////////////////////////////////////////////////////////////////////////// |
|
8 //// Constants |
|
9 |
|
10 const Cc = Components.classes; |
|
11 const Ci = Components.interfaces; |
|
12 const Cr = Components.results; |
|
13 |
|
14 const CONTENT_HANDLING_URL = "chrome://mozapps/content/handling/dialog.xul"; |
|
15 const STRINGBUNDLE_URL = "chrome://mozapps/locale/handling/handling.properties"; |
|
16 |
|
17 //////////////////////////////////////////////////////////////////////////////// |
|
18 //// nsContentDispatchChooser class |
|
19 |
|
20 function nsContentDispatchChooser() |
|
21 { |
|
22 } |
|
23 |
|
24 nsContentDispatchChooser.prototype = |
|
25 { |
|
26 classID: Components.ID("e35d5067-95bc-4029-8432-e8f1e431148d"), |
|
27 |
|
28 ////////////////////////////////////////////////////////////////////////////// |
|
29 //// nsIContentDispatchChooser |
|
30 |
|
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 */ } |
|
38 |
|
39 var sbs = Cc["@mozilla.org/intl/stringbundle;1"]. |
|
40 getService(Ci.nsIStringBundleService); |
|
41 var bundle = sbs.createBundle(STRINGBUNDLE_URL); |
|
42 |
|
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)]; |
|
56 |
|
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); |
|
69 |
|
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 }, |
|
78 |
|
79 ////////////////////////////////////////////////////////////////////////////// |
|
80 //// nsISupports |
|
81 |
|
82 QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentDispatchChooser]) |
|
83 }; |
|
84 |
|
85 //////////////////////////////////////////////////////////////////////////////// |
|
86 //// Module |
|
87 |
|
88 let components = [nsContentDispatchChooser]; |
|
89 |
|
90 this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components); |