forked from Woundorf/foxreplace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.js
More file actions
99 lines (74 loc) · 2.92 KB
/
Copy pathbootstrap.js
File metadata and controls
99 lines (74 loc) · 2.92 KB
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
/** ***** BEGIN LICENSE BLOCK *****
*
* Copyright (C) 2016 Marc Ruiz Altisent. All rights reserved.
*
* This file is part of FoxReplace.
*
* FoxReplace is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* FoxReplace 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with FoxReplace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LICENSE BLOCK ***** */
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
function startup(aData, aReason) {
Cu.import("chrome://foxreplace/content/foxreplace.js");
foxreplace.startup();
forEachOpenWindow(loadIntoWindow);
Services.wm.addListener(WindowListener);
aData.webExtension.startup().then(api => {
const {browser} = api;
browser.runtime.onConnect.addListener(port => {
foxreplace.webExtensionPort = port;
});
browser.runtime.onMessage.addListener(foxreplace.webExtensionMessageListener);
});
}
function shutdown(aData, aReason) {
if (aReason == APP_SHUTDOWN) return;
forEachOpenWindow(unloadFromWindow);
Services.wm.removeListener(WindowListener);
foxreplace.shutdown();
Cu.unload("chrome://foxreplace/content/foxreplace.js");
// HACK WARNING: The Addon Manager does not properly clear all addon related caches on update;
// in order to fully update images and locales, their caches need clearing here
Services.obs.notifyObservers(null, "chrome-flush-caches", null);
}
function install(aData, aReason) {
}
function uninstall(aData, aReason) {
}
let windows = {};
function loadIntoWindow(aWindow) {
windows[aWindow] = new FoxReplace(aWindow);
}
function unloadFromWindow(aWindow) {
windows[aWindow].onUnload();
delete windows[aWindow];
}
// Apply a function to all open browser windows
function forEachOpenWindow(aFunction) {
let windows = Services.wm.getEnumerator("navigator:browser");
while (windows.hasMoreElements())
aFunction(windows.getNext().QueryInterface(Ci.nsIDOMWindow));
}
let WindowListener = {
onOpenWindow: function(aXulWindow) {
let window = aXulWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow);
function onWindowLoad() {
window.removeEventListener("load", onWindowLoad);
if (window.document.documentElement.getAttribute("windowtype") == "navigator:browser")
loadIntoWindow(window);
}
window.addEventListener("load", onWindowLoad);
},
onCloseWindow: function(aXulWindow) {
},
onWindowTitleChange: function(aXulWindow, aNewTitle) {
}
};