-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathbootstrap.js
139 lines (133 loc) · 4.56 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
129
130
131
132
133
134
135
136
137
138
139
/* This is part of Pterosaur.
*
* Copyright (c) 2015 James Kolb <jck1089@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Components.utils.import("resource://gre/modules/Services.jsm");
var scopes = {};
function require(module)
{
if (!(module in scopes))
{
let url = "chrome://pterosaur/content/" + module + ".js";
scopes[module] = {
require: require,
exports: {}
};
Services.scriptloader.loadSubScript(url, scopes[module]);
}
return scopes[module].exports;
}
var pterosaur;
function startup(data, reason) {
/// <summary>
/// Bootstrap data structure @see https://developer.mozilla.org/en-US/docs/Extensions/Bootstrapped_extensions#Bootstrap_data
/// string id
/// string version
/// nsIFile installPath
/// nsIURI resourceURI
///
/// Reason types:
/// APP_STARTUP
/// ADDON_ENABLE
/// ADDON_INSTALL
/// ADDON_UPGRADE
/// ADDON_DOWNGRADE
/// </summary>
pterosaur = require("pterosaur");
forEachOpenWindow(pterosaur.setup);
Services.wm.addListener(WindowListener);
}
var WindowListener =
{
onOpenWindow: function(xulWindow)
{
var window = xulWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow);
function onWindowLoad()
{
window.removeEventListener("load", onWindowLoad);
if (window.document.documentElement.getAttribute("windowtype") == "navigator:browser")
pterosaur.setup(window);
}
window.addEventListener("load", onWindowLoad);
},
onCloseWindow: function(xulWindow) {
var window = xulWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow);
function onWindowUnload()
{
window.removeEventListener("unload", onWindowUnload);
if (window.document.documentElement.getAttribute("windowtype") == "navigator:browser")
{
pterosaur.shutdown(window);
}
}
window.addEventListener("unload", onWindowUnload);
},
onWindowTitleChange: function(xulWindow, newTitle) { }
}
function shutdown(data, reason) {
/// <summary>
/// Bootstrap data structure @see https://developer.mozilla.org/en-US/docs/Extensions/Bootstrapped_extensions#Bootstrap_data
/// string id
/// string version
/// nsIFile installPath
/// nsIURI resourceURI
///
/// Reason types:
/// APP_SHUTDOWN
/// ADDON_DISABLE
/// ADDON_UNINSTALL
/// ADDON_UPGRADE
/// ADDON_DOWNGRADE
/// </summary>
forEachOpenWindow(pterosaur.shutdown);
Services.wm.removeListener(WindowListener);
}
function install(data, reason) {
/// <summary>
/// Bootstrap data structure @see https://developer.mozilla.org/en-US/docs/Extensions/Bootstrapped_extensions#Bootstrap_data
/// string id
/// string version
/// nsIFile installPath
/// nsIURI resourceURI
///
/// Reason types:
/// ADDON_INSTALL
/// ADDON_UPGRADE
/// ADDON_DOWNGRADE
/// </summary>
}
function uninstall(data, reason) {
/// <summary>
/// Bootstrap data structure @see https://developer.mozilla.org/en-US/docs/Extensions/Bootstrapped_extensions#Bootstrap_data
/// string id
/// string version
/// nsIFile installPath
/// nsIURI resourceURI
///
/// Reason types:
/// ADDON_UNINSTALL
/// ADDON_UPGRADE
/// ADDON_DOWNGRADE
/// </summary>
}
function forEachOpenWindow(todo) {
var windows = Services.wm.getEnumerator("navigator:browser")
while (windows.hasMoreElements()) {
todo(windows.getNext().QueryInterface(Components.interfaces.nsIDOMWindow));
}
}