diff options
Diffstat (limited to 'js/vapi-tabs.js')
-rw-r--r-- | js/vapi-tabs.js | 666 |
1 files changed, 333 insertions, 333 deletions
diff --git a/js/vapi-tabs.js b/js/vapi-tabs.js index 02c3644..e5eab6b 100644 --- a/js/vapi-tabs.js +++ b/js/vapi-tabs.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 */ @@ -29,548 +29,548 @@ vAPI.tabs = {}; vAPI.tabs.registerListeners = function() { - vAPI.tabs.manager.start(); + vAPI.tabs.manager.start(); }; vAPI.tabs.get = function (tabId, callback) { - // eMatrix: the following might be obsoleted (though probably - // still relevant at least for Pale Moon.) - // - // Firefox: - // - // browser -> ownerDocument -> defaultView -> gBrowser -> browsers --+ - // ^ | - // | | - // +--------------------------------------------------------------+ - // - // browser (browser) - // contentTitle - // currentURI - // ownerDocument (XULDocument) - // defaultView (ChromeWindow) - // gBrowser (tabbrowser OR browser) - // browsers (browser) - // selectedBrowser - // selectedTab - // tabs (tab.tabbrowser-tab) - // - // Fennec: (what I figured so far) - // - // tab -> browser windows -> window -> BrowserApp -> tabs --+ - // ^ window | - // | | - // +-----------------------------------------------------------+ - // - // tab - // browser - // [manual search to go back to tab from list of windows] - let browser; - - if (tabId === null) { + // eMatrix: the following might be obsoleted (though probably + // still relevant at least for Pale Moon.) + // + // Firefox: + // + // browser -> ownerDocument -> defaultView -> gBrowser -> browsers --+ + // ^ | + // | | + // +--------------------------------------------------------------+ + // + // browser (browser) + // contentTitle + // currentURI + // ownerDocument (XULDocument) + // defaultView (ChromeWindow) + // gBrowser (tabbrowser OR browser) + // browsers (browser) + // selectedBrowser + // selectedTab + // tabs (tab.tabbrowser-tab) + // + // Fennec: (what I figured so far) + // + // tab -> browser windows -> window -> BrowserApp -> tabs --+ + // ^ window | + // | | + // +-----------------------------------------------------------+ + // + // tab + // browser + // [manual search to go back to tab from list of windows] + let browser; + + if (tabId === null) { browser = vAPI.tabs.manager.currentBrowser(); tabId = vAPI.tabs.manager.tabIdFromTarget(browser); - } else { + } else { browser = vAPI.tabs.manager.browserFromTabId(tabId); - } + } - // For internal use - if (typeof callback !== 'function') { + // For internal use + if (typeof callback !== 'function') { return browser; - } + } - if (!browser || !browser.currentURI) { + if (!browser || !browser.currentURI) { callback(); return; - } + } - let win = vAPI.browser.getOwnerWindow(browser); - let tabBrowser = vAPI.browser.getTabBrowser(win); + let win = vAPI.browser.getOwnerWindow(browser); + let tabBrowser = vAPI.browser.getTabBrowser(win); - callback({ + callback({ id: tabId, windowId: vAPI.window.idFromWindow(win), active: tabBrowser !== null - && browser === tabBrowser.selectedBrowser, + && browser === tabBrowser.selectedBrowser, url: browser.currentURI.asciiSpec, title: browser.contentTitle - }); + }); }; vAPI.tabs.getAllSync = function (window) { - let win; - let tabs = []; + let win; + let tabs = []; - for (let win of vAPI.window.getWindows()) { + for (let win of vAPI.window.getWindows()) { if (window && window !== win) { - continue; + continue; } let tabBrowser = vAPI.browser.getTabBrowser(win); if (tabBrowser === null) { - continue; + continue; } // This can happens if a tab-less window is currently opened. // Example of a tab-less window: one opened from clicking // "View Page Source". if (!tabBrowser.tabs) { - continue; + continue; } for (let tab of tabBrowser.tabs) { - tabs.push(tab); + tabs.push(tab); } - } + } - return tabs; + return tabs; }; vAPI.tabs.getAll = function (callback) { - let tabs = []; + let tabs = []; - for (let browser of vAPI.tabs.manager.browsers()) { + for (let browser of vAPI.tabs.manager.browsers()) { let tab = vAPI.tabs.manager.tabFromBrowser(browser); if (tab === null) { - continue; + continue; } if (tab.hasAttribute('pending')) { - continue; + continue; } tabs.push({ - id: vAPI.tabs.manager.tabIdFromTarget(browser), - url: browser.currentURI.asciiSpec + id: vAPI.tabs.manager.tabIdFromTarget(browser), + url: browser.currentURI.asciiSpec }); - } + } - callback(tabs); + callback(tabs); }; vAPI.tabs.open = function (details) { - // properties of the details object: - // + url - the address that will be opened - // + tabId:- the tab is used if set, instead of creating a new one - // + index: - undefined: end of the list, -1: following tab, or - // after index - // + active: - opens the tab in background - true and undefined: - // foreground - // + select: - if a tab is already opened with that url, then - // select it instead of opening a new one - if (!details.url) { + // properties of the details object: + // + url - the address that will be opened + // + tabId:- the tab is used if set, instead of creating a new one + // + index: - undefined: end of the list, -1: following tab, or + // after index + // + active: - opens the tab in background - true and undefined: + // foreground + // + select: - if a tab is already opened with that url, then + // select it instead of opening a new one + if (!details.url) { return null; - } + } - // extension pages - if (/^[\w-]{2,}:/.test(details.url) === false) { + // extension pages + if (/^[\w-]{2,}:/.test(details.url) === false) { details.url = vAPI.getURL(details.url); - } + } - if (details.select) { + if (details.select) { let URI = Services.io.newURI(details.url, null, null); for (let tab of this.getAllSync()) { - let browser = vAPI.tabs.manager.browserFromTarget(tab); + let browser = vAPI.tabs.manager.browserFromTarget(tab); - // https://github.com/gorhill/uBlock/issues/2558 - if (browser === null) { - continue; - } + // https://github.com/gorhill/uBlock/issues/2558 + if (browser === null) { + continue; + } - // Or simply .equals if we care about the fragment - if (URI.equalsExceptRef(browser.currentURI) === false) { + // Or simply .equals if we care about the fragment + if (URI.equalsExceptRef(browser.currentURI) === false) { continue; - } + } - this.select(tab); + this.select(tab); - // Update URL if fragment is different - if (URI.equals(browser.currentURI) === false) { + // Update URL if fragment is different + if (URI.equals(browser.currentURI) === false) { browser.loadURI(URI.asciiSpec); - } + } - return; + return; } - } + } - if (details.active === undefined) { + if (details.active === undefined) { details.active = true; - } + } - if (details.tabId) { + if (details.tabId) { let tab = vAPI.tabs.manager.browserFromTabId(details.tabId); if (tab) { - vAPI.tabs.manager.browserFromTarget(tab).loadURI(details.url); - return; + vAPI.tabs.manager.browserFromTarget(tab).loadURI(details.url); + return; } - } + } - // Open in a standalone window - if (details.popup === true) { + // Open in a standalone window + if (details.popup === true) { Services.ww.openWindow(self, - details.url, - null, - 'location=1,menubar=1,personalbar=1,' - +'resizable=1,toolbar=1', - null); + details.url, + null, + 'location=1,menubar=1,personalbar=1,' + +'resizable=1,toolbar=1', + null); return; - } + } - let win = vAPI.window.getCurrentWindow(); - let tabBrowser = vAPI.browser.getTabBrowser(win); + let win = vAPI.window.getCurrentWindow(); + let tabBrowser = vAPI.browser.getTabBrowser(win); - if (tabBrowser === null) { + if (tabBrowser === null) { return; - } + } - if (details.index === -1) { + if (details.index === -1) { details.index = - tabBrowser.browsers.indexOf(tabBrowser.selectedBrowser) + 1; - } + tabBrowser.browsers.indexOf(tabBrowser.selectedBrowser) + 1; + } - let tab = tabBrowser.loadOneTab(details.url, { - inBackground: !details.active - }); + let tab = tabBrowser.loadOneTab(details.url, { + inBackground: !details.active + }); - if (details.index !== undefined) { + if (details.index !== undefined) { tabBrowser.moveTabTo(tab, details.index); - } + } }; vAPI.tabs.replace = function (tabId, url) { - // Replace the URL of a tab. Noop if the tab does not exist. - let targetURL = url; + // Replace the URL of a tab. Noop if the tab does not exist. + let targetURL = url; - // extension pages - if (/^[\w-]{2,}:/.test(targetURL) !== true) { + // extension pages + if (/^[\w-]{2,}:/.test(targetURL) !== true) { targetURL = vAPI.getURL(targetURL); - } + } - let browser = vAPI.tabs.manager.browserFromTabId(tabId); - if (browser) { + let browser = vAPI.tabs.manager.browserFromTabId(tabId); + if (browser) { browser.loadURI(targetURL); - } + } }; function removeInternal(tab, tabBrowser) { - if (tabBrowser) { - tabBrowser.removeTab(tab); - } + if (tabBrowser) { + tabBrowser.removeTab(tab); + } } vAPI.tabs.remove = function (tabId) { - let browser = vAPI.tabs.manager.browserFromTabId(tabId); - if (!browser) { + let browser = vAPI.tabs.manager.browserFromTabId(tabId); + if (!browser) { return; - } + } - let tab = vAPI.tabs.manager.tabFromBrowser(browser); - if (!tab) { + let tab = vAPI.tabs.manager.tabFromBrowser(browser); + if (!tab) { return; - } + } - removeInternal(tab, - vAPI.browser.getTabBrowser - (vAPI.browser.getOwnerWindow(browser))); + removeInternal(tab, + vAPI.browser.getTabBrowser + (vAPI.browser.getOwnerWindow(browser))); }; vAPI.tabs.reload = function (tabId) { - let browser = vAPI.tabs.manager.browserFromTabId(tabId); - if (!browser) { + let browser = vAPI.tabs.manager.browserFromTabId(tabId); + if (!browser) { return; - } + } - browser.webNavigation.reload(Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE); + browser.webNavigation.reload(Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE); }; vAPI.tabs.select = function (tab) { - if (typeof tab !== 'object') { + if (typeof tab !== 'object') { tab = vAPI.tabs.manager - .tabFromBrowser(vAPI.tabs.manager.browserFromTabId(tab)); - } - if (!tab) { + .tabFromBrowser(vAPI.tabs.manager.browserFromTabId(tab)); + } + if (!tab) { return; - } + } - // https://github.com/gorhill/uBlock/issues/470 - let win = vAPI.browser.getOwnerWindow(tab); - win.focus(); + // https://github.com/gorhill/uBlock/issues/470 + let win = vAPI.browser.getOwnerWindow(tab); + win.focus(); - let tabBrowser = vAPI.browser.getTabBrowser(win); - if (tabBrowser) { + let tabBrowser = vAPI.browser.getTabBrowser(win); + if (tabBrowser) { tabBrowser.selectedTab = tab; - } + } }; vAPI.tabs.injectScript = function (tabId, details, callback) { - let browser = vAPI.tabs.manager.browserFromTabId(tabId); - if (!browser) { + let browser = vAPI.tabs.manager.browserFromTabId(tabId); + if (!browser) { return; - } + } - if (typeof details.file !== 'string') { + if (typeof details.file !== 'string') { return; - } - - details.file = vAPI.getURL(details.file); - browser.messageManager.sendAsyncMessage(location.host + ':broadcast', - JSON.stringify({ - broadcast: true, - channelName: 'vAPI', - msg: { - cmd: 'injectScript', - details: details - } - })); - - if (typeof callback === 'function') { + } + + details.file = vAPI.getURL(details.file); + browser.messageManager.sendAsyncMessage(location.host + ':broadcast', + JSON.stringify({ + broadcast: true, + channelName: 'vAPI', + msg: { + cmd: 'injectScript', + details: details + } + })); + + if (typeof callback === 'function') { vAPI.setTimeout(callback, 13); - } + } }; vAPI.tabs.manager = (function () { - // TODO: find out whether we need a janitor to take care of stale entries. + // TODO: find out whether we need a janitor to take care of stale entries. - // https://github.com/gorhill/uMatrix/issues/540 - // Use only weak references to hold onto browser references. - let browserToTabIdMap = new WeakMap(); - let tabIdToBrowserMap = new Map(); - let tabIdGenerator = 1; + // https://github.com/gorhill/uMatrix/issues/540 + // Use only weak references to hold onto browser references. + let browserToTabIdMap = new WeakMap(); + let tabIdToBrowserMap = new Map(); + let tabIdGenerator = 1; - let indexFromBrowser = function (browser) { + let indexFromBrowser = function (browser) { if (!browser) { - return -1; + return -1; } - let win = vAPI.browser.getOwnerWindow(browser); + let win = vAPI.browser.getOwnerWindow(browser); if (!win) { - return -1; + return -1; } let tabBrowser = vAPI.browser.getTabBrowser(win); if (tabBrowser === null) { - return -1; + return -1; } // This can happen, for example, the `view-source:` // window, there is no tabbrowser object, the browser // object sits directly in the window. if (tabBrowser === browser) { - return 0; + return 0; } return tabBrowser.browsers.indexOf(browser); - }; + }; - let indexFromTarget = function (target) { + let indexFromTarget = function (target) { return indexFromBrowser(browserFromTarget(target)); - }; + }; - let tabFromBrowser = function (browser) { + let tabFromBrowser = function (browser) { let i = indexFromBrowser(browser); if (i === -1) { - return null; + return null; } let win = vAPI.browser.getOwnerWindow(browser); if (!win) { - return null; + return null; } let tabBrowser = vAPI.browser.getTabBrowser(win); if (tabBrowser === null) { - return null; + return null; } if (!tabBrowser.tabs || i >= tabBrowser.tabs.length) { - return null; + return null; } return tabBrowser.tabs[i]; - }; + }; - let browserFromTarget = function (target) { + let browserFromTarget = function (target) { if (!target) { - return null; + return null; } if (target.linkedPanel) { - // target is a tab - target = target.linkedBrowser; + // target is a tab + target = target.linkedBrowser; } if (target.localName !== 'browser') { - return null; + return null; } return target; - }; + }; - let tabIdFromTarget = function (target) { + let tabIdFromTarget = function (target) { let browser = browserFromTarget(target); if (browser === null) { - return vAPI.noTabId; + return vAPI.noTabId; } let tabId = browserToTabIdMap.get(browser); if (tabId === undefined) { - tabId = '' + tabIdGenerator++; - browserToTabIdMap.set(browser, tabId); - tabIdToBrowserMap.set(tabId, Cu.getWeakReference(browser)); + tabId = '' + tabIdGenerator++; + browserToTabIdMap.set(browser, tabId); + tabIdToBrowserMap.set(tabId, Cu.getWeakReference(browser)); } return tabId; - }; + }; - let browserFromTabId = function (tabId) { + let browserFromTabId = function (tabId) { let weakref = tabIdToBrowserMap.get(tabId); let browser = weakref && weakref.get(); return browser || null; - }; + }; - let currentBrowser = function () { + let currentBrowser = function () { let win = vAPI.window.getCurrentWindow(); // https://github.com/gorhill/uBlock/issues/399 // getTabBrowser() can return null at browser launch time. let tabBrowser = vAPI.browser.getTabBrowser(win); if (tabBrowser === null) { - return null; + return null; } return browserFromTarget(tabBrowser.selectedTab); - }; + }; - let removeBrowserEntry = function (tabId, browser) { + let removeBrowserEntry = function (tabId, browser) { if (tabId && tabId !== vAPI.noTabId) { - vAPI.tabs.onClosed(tabId); - delete vAPI.toolbarButton.tabs[tabId]; - tabIdToBrowserMap.delete(tabId); + vAPI.tabs.onClosed(tabId); + delete vAPI.toolbarButton.tabs[tabId]; + tabIdToBrowserMap.delete(tabId); } if (browser) { - browserToTabIdMap.delete(browser); + browserToTabIdMap.delete(browser); } - }; + }; - let removeTarget = function (target) { + let removeTarget = function (target) { onClose({ - target: target - }); - }; + target: target + }); + }; - let getAllBrowsers = function () { + let getAllBrowsers = function () { let browsers = []; - for (let [tabId, weakref] of tabIdToBrowserMap) { - let browser = weakref.get(); + for (let [tabId, weakref] of tabIdToBrowserMap) { + let browser = weakref.get(); - // TODO: Maybe call removeBrowserEntry() if the - // browser no longer exists? - if (browser) { + // TODO: Maybe call removeBrowserEntry() if the + // browser no longer exists? + if (browser) { browsers.push(browser); - } + } } return browsers; - }; - - // var onOpen = function (target) { - // var tabId = tabIdFromTarget(target); - // var browser = browserFromTabId(tabId); - // vAPI.tabs.onNavigation({ - // frameId: 0, - // tabId: tabId, - // url: browser.currentURI.asciiSpec, - // }); - // }; - - var onShow = function ({target}) { + }; + + // var onOpen = function (target) { + // var tabId = tabIdFromTarget(target); + // var browser = browserFromTabId(tabId); + // vAPI.tabs.onNavigation({ + // frameId: 0, + // tabId: tabId, + // url: browser.currentURI.asciiSpec, + // }); + // }; + + var onShow = function ({target}) { tabIdFromTarget(target); - }; + }; - var onClose = function ({target}) { + var onClose = function ({target}) { // target is tab in Firefox, browser in Fennec let browser = browserFromTarget(target); let tabId = browserToTabIdMap.get(browser); removeBrowserEntry(tabId, browser); - }; + }; - var onSelect = function ({target}) { - // This is an entry point: when creating a new tab, it is - // not always reported through onLocationChanged... - // Sigh. It is "reported" here however. + var onSelect = function ({target}) { + // This is an entry point: when creating a new tab, it is + // not always reported through onLocationChanged... + // Sigh. It is "reported" here however. let browser = browserFromTarget(target); let tabId = browserToTabIdMap.get(browser); - if (tabId === undefined) { - tabId = tabIdFromTarget(target); - vAPI.tabs.onNavigation({ + if (tabId === undefined) { + tabId = tabIdFromTarget(target); + vAPI.tabs.onNavigation({ frameId: 0, tabId: tabId, url: browser.currentURI.asciiSpec - }); + }); } vAPI.setIcon(tabId, vAPI.browser.getOwnerWindow(target)); - }; + }; - let locationChangedMessageName = location.host + ':locationChanged'; + let locationChangedMessageName = location.host + ':locationChanged'; - let onLocationChanged = function (e) { + let onLocationChanged = function (e) { let details = e.data; // Ignore notifications related to our popup if (details.url.lastIndexOf(vAPI.getURL('popup.html'), 0) === 0) { - return; + return; } let browser = e.target; let tabId = tabIdFromTarget(browser); if (tabId === vAPI.noTabId) { - return; + return; } // LOCATION_CHANGE_SAME_DOCUMENT = "did not load a new document" if (details.flags - & Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT) { - vAPI.tabs.onUpdated(tabId, {url: details.url}, { + & Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT) { + vAPI.tabs.onUpdated(tabId, {url: details.url}, { frameId: 0, tabId: tabId, url: browser.currentURI.asciiSpec - }); - return; + }); + return; } // https://github.com/chrisaljoudi/uBlock/issues/105 // Allow any kind of pages vAPI.tabs.onNavigation({ - frameId: 0, - tabId: tabId, - url: details.url + frameId: 0, + tabId: tabId, + url: details.url }); - }; + }; - let attachToTabBrowser = function (window) { + let attachToTabBrowser = function (window) { if (typeof vAPI.toolbarButton.attachToNewWindow === 'function') { - vAPI.toolbarButton.attachToNewWindow(window); + vAPI.toolbarButton.attachToNewWindow(window); } let tabBrowser = vAPI.browser.getTabBrowser(window); if (tabBrowser === null) { - return; + return; } let tabContainer; if (tabBrowser.deck) { // Fennec - tabContainer = tabBrowser.deck; + tabContainer = tabBrowser.deck; } else if (tabBrowser.tabContainer) { - // Firefox - tabContainer = tabBrowser.tabContainer; + // Firefox + tabContainer = tabBrowser.tabContainer; } // https://github.com/gorhill/uBlock/issues/697 @@ -579,20 +579,20 @@ // of session restore -- it is set *after* the event is // fired in such case. if (tabContainer) { - tabContainer.addEventListener('TabShow', onShow); - tabContainer.addEventListener('TabClose', onClose); - // when new window is opened TabSelect doesn't run on - // the selected tab? - tabContainer.addEventListener('TabSelect', onSelect); + tabContainer.addEventListener('TabShow', onShow); + tabContainer.addEventListener('TabClose', onClose); + // when new window is opened TabSelect doesn't run on + // the selected tab? + tabContainer.addEventListener('TabSelect', onSelect); } - }; + }; - var canAttachToTabBrowser = function (window) { - // https://github.com/gorhill/uBlock/issues/906 - // Ensure the environment is ready before trying to attaching. + var canAttachToTabBrowser = function (window) { + // https://github.com/gorhill/uBlock/issues/906 + // Ensure the environment is ready before trying to attaching. let document = window && window.document; if (!document || document.readyState !== 'complete') { - return false; + return false; } // On some platforms, the tab browser isn't immediately @@ -602,28 +602,28 @@ // attaching ourself to the window. let tabBrowser = vAPI.browser.getTabBrowser(window); if (tabBrowser === null) { - return false; + return false; } return vAPI.window.toBrowserWindow(window) !== null; - }; + }; - let onWindowLoad = function (win) { + let onWindowLoad = function (win) { vAPI.deferUntil(canAttachToTabBrowser.bind(null, win), - attachToTabBrowser.bind(null, win)); - }; + attachToTabBrowser.bind(null, win)); + }; - let onWindowUnload = function (win) { + let onWindowUnload = function (win) { let tabBrowser = vAPI.browser.getTabBrowser(win); if (tabBrowser === null) { - return; + return; } let tabContainer = tabBrowser.tabContainer; if (tabContainer) { - tabContainer.removeEventListener('TabShow', onShow); - tabContainer.removeEventListener('TabClose', onClose); - tabContainer.removeEventListener('TabSelect', onSelect); + tabContainer.removeEventListener('TabShow', onShow); + tabContainer.removeEventListener('TabClose', onClose); + tabContainer.removeEventListener('TabSelect', onSelect); } // https://github.com/gorhill/uBlock/issues/574 @@ -631,85 +631,85 @@ // sometimes the window IS the tab. let tabs; if (tabBrowser.tabs) { - tabs = tabBrowser.tabs; + tabs = tabBrowser.tabs; } else if (tabBrowser.localName === 'browser') { - tabs = [tabBrowser]; + tabs = [tabBrowser]; } else { - tabs = []; + tabs = []; } let browser; - let URI; - let tabId; - for (let i=tabs.length-1; i>=0; --i) { - let tab = tabs[i]; - browser = browserFromTarget(tab); - if (browser === null) { + let URI; + let tabId; + for (let i=tabs.length-1; i>=0; --i) { + let tab = tabs[i]; + browser = browserFromTarget(tab); + if (browser === null) { continue; - } + } - URI = browser.currentURI; - // Close extension tabs - if (URI.schemeIs('chrome') && URI.host === location.host) { + URI = browser.currentURI; + // Close extension tabs + if (URI.schemeIs('chrome') && URI.host === location.host) { removeInternal(tab, vAPI.browser.getTabBrowser(win)); - } + } - tabId = browserToTabIdMap.get(browser); - if (tabId !== undefined) { + tabId = browserToTabIdMap.get(browser); + if (tabId !== undefined) { removeBrowserEntry(tabId, browser); tabIdToBrowserMap.delete(tabId); - } - browserToTabIdMap.delete(browser); + } + browserToTabIdMap.delete(browser); } - }; + }; - var start = function () { - // Initialize map with existing active tabs + var start = function () { + // Initialize map with existing active tabs let tabBrowser; - let tabs; + let tabs; for (let win of vAPI.window.getWindows()) { - onWindowLoad(win); + onWindowLoad(win); - tabBrowser = vAPI.browser.getTabBrowser(win); - if (tabBrowser === null) { + tabBrowser = vAPI.browser.getTabBrowser(win); + if (tabBrowser === null) { continue; - } + } - for (let tab of tabBrowser.tabs) { + for (let tab of tabBrowser.tabs) { if (!tab.hasAttribute('pending')) { - tabIdFromTarget(tab); + tabIdFromTarget(tab); } - } + } } vAPI.window.onOpenWindow = onWindowLoad; vAPI.window.onCloseWindow = onWindowUnload; vAPI.messaging.globalMessageManager - .addMessageListener(locationChangedMessageName, - onLocationChanged); - }; + .addMessageListener(locationChangedMessageName, + onLocationChanged); + }; - let stop = function () { + let stop = function () { vAPI.window.onOpenWindow = null; vAPI.window.onCloseWindow = null; vAPI.messaging.globalMessageManager - .removeMessageListener(locationChangedMessageName, - onLocationChanged); + .removeMessageListener(locationChangedMessageName, + onLocationChanged); for (let win of vAPI.window.getWindows()) { - onWindowUnload(win); + onWindowUnload(win); } browserToTabIdMap = new WeakMap(); tabIdToBrowserMap.clear(); - }; + }; - vAPI.addCleanUpTask(stop); + vAPI.addCleanUpTask(stop); - return { + return { browsers: getAllBrowsers, browserFromTabId: browserFromTabId, browserFromTarget: browserFromTarget, @@ -719,6 +719,6 @@ start: start, tabFromBrowser: tabFromBrowser, tabIdFromTarget: tabIdFromTarget - }; + }; })(); })(); |