-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathbootstrap.js
128 lines (104 loc) · 3.73 KB
/
bootstrap.js
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
// An example of how to create a string bundle for localization.
XPCOMUtils.defineLazyGetter(this, "Strings", function() {
return Services.strings.createBundle("chrome://skeleton/locale/skeleton.properties");
});
// An example of how to import a helper module.
XPCOMUtils.defineLazyGetter(this, "Helper", function() {
let sandbox = {};
Services.scriptloader.loadSubScript("chrome://skeleton/content/helper.js", sandbox);
return sandbox["Helper"];
});
function isNativeUI() {
return (Services.appinfo.ID == "{aa3c5121-dab2-40e2-81ca-7ea25febc110}");
}
function showToast(aWindow) {
aWindow.NativeWindow.toast.show(Strings.GetStringFromName("toast.message"), "short");
}
function showDoorhanger(aWindow) {
let buttons = [
{
label: "Button 1",
callback: function() {
aWindow.NativeWindow.toast.show("Button 1 was tapped", "short");
}
} , {
label: "Button 2",
callback: function() {
aWindow.NativeWindow.toast.show("Button 2 was tapped", "short");
}
}];
aWindow.NativeWindow.doorhanger.show("Showing a doorhanger with two button choices.", "doorhanger-test", buttons);
}
function copyLink(aWindow, aTarget) {
let url = aWindow.NativeWindow.contextmenus._getLinkURL(aTarget);
aWindow.NativeWindow.toast.show("Todo: copy > " + url, "short");
}
var gToastMenuId = null;
var gDoorhangerMenuId = null;
var gContextMenuId = null;
function loadIntoWindow(window) {
if (!window)
return;
if (isNativeUI()) {
gToastMenuId = window.NativeWindow.menu.add("Show Toast", null, function() { showToast(window); });
gDoorhangerMenuId = window.NativeWindow.menu.add("Show Doorhanger", null, function() { showDoorhanger(window); });
gContextMenuId = window.NativeWindow.contextmenus.add("Copy Link", window.NativeWindow.contextmenus.linkOpenableContext, function(aTarget) { copyLink(window, aTarget); });
}
}
function unloadFromWindow(window) {
if (!window)
return;
if (isNativeUI()) {
window.NativeWindow.menu.remove(gToastMenuId);
window.NativeWindow.menu.remove(gDoorhangerMenuId);
window.NativeWindow.contextmenus.remove(gContextMenuId);
}
}
/**
* bootstrap.js API
*/
var windowListener = {
onOpenWindow: function(aWindow) {
// Wait for the window to finish loading
let domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
domWindow.addEventListener("load", function() {
domWindow.removeEventListener("load", arguments.callee, false);
loadIntoWindow(domWindow);
}, false);
},
onCloseWindow: function(aWindow) {
},
onWindowTitleChange: function(aWindow, aTitle) {
}
};
function startup(aData, aReason) {
// Load into any existing windows
let windows = Services.wm.getEnumerator("navigator:browser");
while (windows.hasMoreElements()) {
let domWindow = windows.getNext().QueryInterface(Ci.nsIDOMWindow);
loadIntoWindow(domWindow);
}
// Load into any new windows
Services.wm.addListener(windowListener);
}
function shutdown(aData, aReason) {
// When the application is shutting down we normally don't have to clean
// up any UI changes made
if (aReason == APP_SHUTDOWN)
return;
// Stop listening for new windows
Services.wm.removeListener(windowListener);
// Unload from any existing windows
let windows = Services.wm.getEnumerator("navigator:browser");
while (windows.hasMoreElements()) {
let domWindow = windows.getNext().QueryInterface(Ci.nsIDOMWindow);
unloadFromWindow(domWindow);
}
}
function install(aData, aReason) {
}
function uninstall(aData, aReason) {
}