-
Notifications
You must be signed in to change notification settings - Fork 54
/
ContentDispatchChooser.jsm
78 lines (63 loc) · 2.35 KB
/
ContentDispatchChooser.jsm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Constants
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const CONTENT_HANDLING_URL = "chrome://mozapps/content/handling/dialog.xhtml";
const STRINGBUNDLE_URL = "chrome://mozapps/locale/handling/handling.properties";
// nsContentDispatchChooser class
function nsContentDispatchChooser() {}
nsContentDispatchChooser.prototype = {
classID: Components.ID("e35d5067-95bc-4029-8432-e8f1e431148d"),
// nsIContentDispatchChooser
ask: function ask(aHandler, aWindowContext, aURI, aReason) {
var window = null;
try {
if (aWindowContext) {
window = aWindowContext.getInterface(Ci.nsIDOMWindow);
if (window) {
window = window.docShell.rootTreeItem.domWindow;
}
}
} catch (e) {
/* it's OK to not have a window */
}
var bundle = Services.strings.createBundle(STRINGBUNDLE_URL);
// TODO when this is hooked up for content, we will need different strings
// for most of these
var arr = [
bundle.GetStringFromName("protocol.title"),
"",
bundle.GetStringFromName("protocol.description"),
bundle.GetStringFromName("protocol.choices.label"),
bundle.formatStringFromName("protocol.checkbox.label", [aURI.scheme]),
bundle.GetStringFromName("protocol.checkbox.accesskey"),
bundle.formatStringFromName("protocol.checkbox.extra", [
Services.appinfo.name,
]),
];
var params = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
let SupportsString = Components.Constructor(
"@mozilla.org/supports-string;1",
"nsISupportsString"
);
for (let text of arr) {
let string = new SupportsString();
string.data = text;
params.appendElement(string);
}
params.appendElement(aHandler);
params.appendElement(aURI);
params.appendElement(aWindowContext);
Services.ww.openWindow(
window,
CONTENT_HANDLING_URL,
null,
"chrome,dialog=yes,resizable,centerscreen",
params
);
},
// nsISupports
QueryInterface: ChromeUtils.generateQI([Ci.nsIContentDispatchChooser]),
};
var EXPORTED_SYMBOLS = ["nsContentDispatchChooser"];