-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.js
80 lines (68 loc) · 2.4 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
var SDK = {
Cc: Components.classes,
Ci: Components.interfaces,
utils: Components.utils
}
var extension;
function loadIntoWindow(window) {
if (!window) return;
// MoWA modules are loaded
SDK.utils.import("resource://gre/modules/Services.jsm");
var charset = "ISO-8859-1";
Services.scriptloader.loadSubScript("chrome://MoWA/content/ExtensionManager.js",
window, charset);
//Instantiating the ExtensionManager
extension = new window["ExtensionManager"](window,charset);
};
function unloadFromWindow(window) {
if (!window)
return;
try{
// Removing UI elements and cleanup
extension.unloadModules();
window.NativeWindow.menu.remove(extension.getMainMenu());
}catch(err){window.NativeWindow.toast.show(err.message, "long");}
};
// Generic methods for extension installation and initialization
var windowListener = {
onOpenWindow: function(aWindow) {
// Wait for the window to finish loading
let domWindow = aWindow.QueryInterface(SDK.Ci.nsIInterfaceRequestor).getInterface(SDK.Ci.nsIDOMWindowInternal || SDK.Ci.nsIDOMWindow);
domWindow.addEventListener("load", function() {
domWindow.removeEventListener("load", arguments.callee, false);
loadIntoWindow(domWindow);
}, false);
},
onCloseWindow: function(aWindow) {
unloadFromWindow();
},
onWindowTitleChange: function(aWindow, aTitle) {}
};
function startup(aData, aReason) {
let wm = SDK.Cc["@mozilla.org/appshell/window-mediator;1"].getService(SDK.Ci.nsIWindowMediator);
// Load into any existing windows
let windows = wm.getEnumerator("navigator:browser");
while (windows.hasMoreElements()) {
let domWindow = windows.getNext().QueryInterface(SDK.Ci.nsIDOMWindow);
loadIntoWindow(domWindow);
}
// Load into any new windows
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;
let wm = SDK.Cc["@mozilla.org/appshell/window-mediator;1"].getService(SDK.Ci.nsIWindowMediator);
// Stop listening for new windows
wm.removeListener(windowListener);
// Unload from any existing windows
let windows = wm.getEnumerator("navigator:browser");
while (windows.hasMoreElements()) {
let domWindow = windows.getNext().QueryInterface(SDK.Ci.nsIDOMWindow);
unloadFromWindow(domWindow);
}
};
function install(aData, aReason) {};
function uninstall(aData, aReason) {};