!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is nsContentDispatchChooser.
15 *
16 * The Initial Developer of the Original Code is
17 * Mozilla Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2007
19 * the Initial Developer. All Rights Reserved.
20 *
21 * Contributor(s):
22 * Shawn Wilsher <me@shawnwilsher.com> (Original Author)
23 * Dan Mosedale <dmose@mozilla.org>
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
39 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
40
41 ////////////////////////////////////////////////////////////////////////////////
42 //// Constants
43
44 const Cc = Components.classes;
45 const Ci = Components.interfaces;
46 const Cr = Components.results;
47
48 const CONTENT_HANDLING_URL = "chrome://mozapps/content/handling/dialog.xul";
49 const STRINGBUNDLE_URL = "chrome://mozapps/locale/handling/handling.properties";
50
51 ////////////////////////////////////////////////////////////////////////////////
52 //// nsContentDispatchChooser class
53
nsContentDispatchChooser
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
54 function nsContentDispatchChooser()
55 {
56 }
57
58 nsContentDispatchChooser.prototype =
59 {
60 classDescription: "Used to handle different types of content",
61 classID: Components.ID("e35d5067-95bc-4029-8432-e8f1e431148d"),
62 contractID: "@mozilla.org/content-dispatch-chooser;1",
63
64 //////////////////////////////////////////////////////////////////////////////
65 //// nsIContentDispatchChooser
66
ask
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
67 ask: function ask(aHandler, aWindowContext, aURI, aReason)
68 {
69 var window = null;
70 try {
71 if (aWindowContext)
72 window = aWindowContext.getInterface(Ci.nsIDOMWindow);
73 } catch (e) { /* it's OK to not have a window */ }
74
75 var sbs = Cc["@mozilla.org/intl/stringbundle;1"].
76 getService(Ci.nsIStringBundleService);
77 var bundle = sbs.createBundle(STRINGBUNDLE_URL);
78
79 var xai = Cc["@mozilla.org/xre/app-info;1"].
80 getService(Ci.nsIXULAppInfo);
81 // TODO when this is hooked up for content, we will need different strings
82 // for most of these
83 var arr = [bundle.GetStringFromName("protocol.title"),
84 "",
85 bundle.GetStringFromName("protocol.description"),
86 bundle.GetStringFromName("protocol.choices.label"),
87 bundle.formatStringFromName("protocol.checkbox.label",
88 [aURI.scheme], 1),
89 bundle.GetStringFromName("protocol.checkbox.accesskey"),
90 bundle.formatStringFromName("protocol.checkbox.extra",
91 [xai.name], 1)];
92
93 var params = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
94 for each (let text in arr) {
95 let string = Cc["@mozilla.org/supports-string;1"].
96 createInstance(Ci.nsISupportsString);
97 string.data = text;
98 params.appendElement(string, false);
99 }
100 params.appendElement(aHandler, false);
101 params.appendElement(aURI, false);
102 params.appendElement(aWindowContext, false);
103
104 var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
105 getService(Ci.nsIWindowWatcher);
106 ww.openWindow(window,
107 CONTENT_HANDLING_URL,
108 null,
109 "chrome,dialog=yes,resizable,centerscreen",
110 params);
111 },
112
113 //////////////////////////////////////////////////////////////////////////////
114 //// nsISupports
115
116 QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentDispatchChooser])
117 };
118
119 ////////////////////////////////////////////////////////////////////////////////
120 //// Module
121
122 let components = [nsContentDispatchChooser];
123
NSGetModule
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
124 function NSGetModule(compMgr, fileSpec)
125 {
126 return XPCOMUtils.generateModule(components);
127 }