aboutsummaryrefslogtreecommitdiffstats
path: root/js/vapi-window.js
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2022-04-06 10:38:06 +0800
committerJesús <heckyel@hyperbola.info>2022-04-06 10:38:06 +0800
commit8aeb670be1d252807252ee2bfe99b15b81c3e28d (patch)
treeced0973165449d620c5c40876c37ab16b17655f9 /js/vapi-window.js
parent5aa99a2ea2b683ba35eb36dfc54efd79f3cfcb85 (diff)
downloadematrix-8aeb670be1d252807252ee2bfe99b15b81c3e28d.tar.lz
ematrix-8aeb670be1d252807252ee2bfe99b15b81c3e28d.tar.xz
ematrix-8aeb670be1d252807252ee2bfe99b15b81c3e28d.zip
update from upstream
Diffstat (limited to 'js/vapi-window.js')
-rw-r--r--js/vapi-window.js170
1 files changed, 85 insertions, 85 deletions
diff --git a/js/vapi-window.js b/js/vapi-window.js
index 9e35db8..c7baede 100644
--- a/js/vapi-window.js
+++ b/js/vapi-window.js
@@ -2,7 +2,7 @@
ηMatrix - a browser extension to black/white list requests.
Copyright (C) 2014-2019 The uMatrix/uBlock Origin authors
- Copyright (C) 2019-2020 Alessio Vanni
+ Copyright (C) 2019-2022 Alessio Vanni
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see {http://www.gnu.org/licenses/}.
- Home: https://libregit.spks.xyz/heckyel/ematrix
+ Home: https://gitlab.com/vannilla/ematrix
uMatrix Home: https://github.com/gorhill/uMatrix
*/
@@ -27,157 +27,157 @@
(function () {
vAPI.window = (function () {
- let windowToIdMap = new Map();
- let windowIdGenerator = 1;
- let api = {
+ let windowToIdMap = new Map();
+ let windowIdGenerator = 1;
+ let api = {
onOpenWindow: null,
onCloseWindow: null
- };
-
- // https://github.com/gorhill/uMatrix/issues/586 This is
- // necessary hack because on SeaMonkey 2.40, for unknown
- // reasons private windows do not have the attribute
- // `windowtype` set to `navigator:browser`. As a fallback, the
- // code here will also test whether the id attribute is
- // `main-window`.
- api.toBrowserWindow = function (win) {
+ };
+
+ // https://github.com/gorhill/uMatrix/issues/586 This is
+ // necessary hack because on SeaMonkey 2.40, for unknown
+ // reasons private windows do not have the attribute
+ // `windowtype` set to `navigator:browser`. As a fallback, the
+ // code here will also test whether the id attribute is
+ // `main-window`.
+ api.toBrowserWindow = function (win) {
let docElement = win && win.document
- && win.document.documentElement;
+ && win.document.documentElement;
if (!docElement) {
- return null;
+ return null;
}
if (vAPI.thunderbird) {
- return docElement.getAttribute('windowtype') === 'mail:3pane'
- ? win
- : null;
+ return docElement.getAttribute('windowtype') === 'mail:3pane'
+ ? win
+ : null;
}
return docElement.getAttribute('windowtype') === 'navigator:browser'
- || docElement.getAttribute('id') === 'main-window'
- ? win
- : null;
- };
+ || docElement.getAttribute('id') === 'main-window'
+ ? win
+ : null;
+ };
- api.getWindows = function () {
+ api.getWindows = function () {
return windowToIdMap.keys();
- };
+ };
- api.idFromWindow = function (win) {
+ api.idFromWindow = function (win) {
return windowToIdMap.get(win) || 0;
- };
+ };
- api.getCurrentWindow = function () {
+ api.getCurrentWindow = function () {
return this.toBrowserWindow(Services.wm.getMostRecentWindow(null));
- };
+ };
- let addWindow = function (win) {
+ let addWindow = function (win) {
if (!win || windowToIdMap.has(win)) {
- return;
+ return;
}
windowToIdMap.set(win, windowIdGenerator++);
if (typeof api.onOpenWindow === 'function') {
- api.onOpenWindow(win);
+ api.onOpenWindow(win);
}
- };
+ };
- let removeWindow = function (win) {
+ let removeWindow = function (win) {
if (!win || windowToIdMap.delete(win) !== true) {
- return;
+ return;
}
if (typeof api.onCloseWindow === 'function') {
- api.onCloseWindow(win);
+ api.onCloseWindow(win);
}
- };
+ };
- // https://github.com/gorhill/uMatrix/issues/357
- // Use nsIWindowMediator for being notified of opened/closed windows.
- let listeners = {
+ // https://github.com/gorhill/uMatrix/issues/357
+ // Use nsIWindowMediator for being notified of opened/closed windows.
+ let listeners = {
onOpenWindow: function (aWindow) {
- let win;
- try {
+ let win;
+ try {
win = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
- } catch (e) {
- // Ignore
- }
+ } catch (e) {
+ // Ignore
+ }
- addWindow(win);
+ addWindow(win);
},
onCloseWindow: function (aWindow) {
- let win;
- try {
+ let win;
+ try {
win = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
- } catch (e) {
- // Ignore
- }
+ } catch (e) {
+ // Ignore
+ }
- removeWindow(win);
+ removeWindow(win);
},
observe: function (aSubject, topic) {
- let win;
- try {
+ let win;
+ try {
win = aSubject.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
- } catch (e) {
- // Ignore
- }
-
- if (!win) {
- return;
- }
-
- switch (topic) {
- case 'domwindowopened':
- addWindow(win);
- break;
- case 'domwindowclosed':
- removeWindow(win);
- break;
- default:
- console.error('unknown observer topic');
- break;
- }
+ } catch (e) {
+ // Ignore
+ }
+
+ if (!win) {
+ return;
+ }
+
+ switch (topic) {
+ case 'domwindowopened':
+ addWindow(win);
+ break;
+ case 'domwindowclosed':
+ removeWindow(win);
+ break;
+ default:
+ console.error('unknown observer topic');
+ break;
+ }
}
- };
+ };
- (function() {
+ (function() {
let winumerator;
winumerator = Services.wm.getEnumerator(null);
while (winumerator.hasMoreElements()) {
- let win = winumerator.getNext();
+ let win = winumerator.getNext();
- if (!win.closed) {
+ if (!win.closed) {
windowToIdMap.set(win, windowIdGenerator++);
- }
+ }
}
winumerator = Services.ww.getWindowEnumerator();
while (winumerator.hasMoreElements()) {
- let win = winumerator.getNext()
+ let win = winumerator.getNext()
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
- if (!win.closed) {
+ if (!win.closed) {
windowToIdMap.set(win, windowIdGenerator++);
- }
+ }
}
Services.wm.addListener(listeners);
Services.ww.registerNotification(listeners);
- })();
+ })();
- vAPI.addCleanUpTask(function() {
+ vAPI.addCleanUpTask(function() {
Services.wm.removeListener(listeners);
Services.ww.unregisterNotification(listeners);
windowToIdMap.clear();
- });
+ });
- return api;
+ return api;
})();
})();