aboutsummaryrefslogtreecommitdiffstats
path: root/js/vapi-background.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/vapi-background.js')
-rw-r--r--js/vapi-background.js46
1 files changed, 27 insertions, 19 deletions
diff --git a/js/vapi-background.js b/js/vapi-background.js
index 10f7b2b..109a06b 100644
--- a/js/vapi-background.js
+++ b/js/vapi-background.js
@@ -764,11 +764,14 @@
vAPI.window = winWatcher;
- let getTabBrowser = function (win) {
+ // browser-handling utilities
+ vAPI.browser = {};
+
+ vAPI.browser.getTabBrowser = function (win) {
return win && win.gBrowser || null;
};
- let getOwnerWindow = function (target) {
+ vAPI.browser.getOwnerWindow = function (target) {
if (target.ownerDocument) {
return target.ownerDocument.defaultView;
}
@@ -776,6 +779,8 @@
return null;
};
+ vAPI.noTabId = '-1';
+
vAPI.isBehindTheSceneTabId = function (tabId) {
return tabId.toString() === '-1';
};
@@ -791,12 +796,12 @@
win = winWatcher.getCurrentWindow();
}
- let tabBrowser = getTabBrowser(win);
+ let tabBrowser = vAPI.browser.getTabBrowser(win);
if (tabBrowser === null) {
return;
}
- let curTabId = tabWatcher.tabIdFromTarget(tabBrowser.selectedTab);
+ let curTabId = vAPI.tabs.manager.tabIdFromTarget(tabBrowser.selectedTab);
let tb = vAPI.toolbarButton;
// from 'TabSelect' event
@@ -857,7 +862,7 @@
let sender = {
tab: {
- id: tabWatcher.tabIdFromTarget(target)
+ id: vAPI.tabs.manager.tabIdFromTarget(target)
}
};
@@ -1325,7 +1330,7 @@
}
if (lc.topFrameElement) {
- return tabWatcher.tabIdFromTarget(lc.topFrameElement);
+ return vAPI.tabs.manager.tabIdFromTarget(lc.topFrameElement);
}
let win;
@@ -1346,11 +1351,12 @@
let tabBrowser;
try {
tabBrowser =
- getTabBrowser(win.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIWebNavigation)
- .QueryInterface(Ci.nsIDocShell).rootTreeItem
- .QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDOMWindow));
+ vAPI.browser.getTabBrowser
+ (win.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIWebNavigation)
+ .QueryInterface(Ci.nsIDocShell).rootTreeItem
+ .QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindow));
} catch (ex) {
// Ignore
}
@@ -1360,14 +1366,15 @@
}
if (tabBrowser.getBrowserForContentWindow) {
- return tabWatcher.tabIdFromTarget(tabBrowser.getBrowserForContentWindow(win));
+ return vAPI.tabs.manager
+ .tabIdFromTarget(tabBrowser.getBrowserForContentWindow(win));
}
// Falling back onto _getTabForContentWindow to ensure older
// versions of Firefox work well.
return tabBrowser._getTabForContentWindow
- ? tabWatcher.tabIdFromTarget(tabBrowser
- ._getTabForContentWindow(win))
+ ? vAPI.tabs.manager
+ .tabIdFromTarget(tabBrowser._getTabForContentWindow(win))
: vAPI.noTabId;
},
rawtypeFromContentType: function (channel) {
@@ -1539,7 +1546,7 @@
let details = e.data;
let pendingReq = httpObserver.createPendingRequest(details.url);
pendingReq.rawType = details.rawType;
- pendingReq.tabId = tabWatcher.tabIdFromTarget(e.target);
+ pendingReq.tabId = vAPI.tabs.manager.tabIdFromTarget(e.target);
};
// https://github.com/gorhill/uMatrix/issues/200
@@ -2479,7 +2486,7 @@
}
callback(details, {
- id: tabWatcher.tabIdFromTarget(gContextMenu.browser),
+ id: vAPI.tabs.manager.tabIdFromTarget(gContextMenu.browser),
url: gContextMenu.browser.currentURI.asciiSpec
});
};
@@ -2551,7 +2558,7 @@
// Older versions of Firefox can throw here when looking
// up `currentURI`.
try {
- let tabBrowser = tabWatcher.currentBrowser();
+ let tabBrowser = vAPI.tabs.manager.currentBrowser();
return tabBrowser
&& tabBrowser.currentURI
&& tabBrowser.currentURI.spec === 'about:addons'
@@ -2566,7 +2573,8 @@
// already opened.
let init = function () {
if (canInit()) {
- setupOptionsButtons(tabWatcher.currentBrowser().contentDocument);
+ setupOptionsButtons(vAPI.tabs.manager
+ .currentBrowser().contentDocument);
}
};
@@ -2600,7 +2608,7 @@
// to inject content scripts in already opened web pages, to
// remove whatever nuisance could make it to the web pages
// before uBlock was ready.
- for (let browser of tabWatcher.browsers()) {
+ for (let browser of vAPI.tabs.manager.browsers()) {
browser.messageManager
.sendAsyncMessage(location.host + '-load-completed');
}