diff options
author | gorhill <rhill@raymondhill.net> | 2015-10-12 17:06:25 -0400 |
---|---|---|
committer | gorhill <rhill@raymondhill.net> | 2015-10-12 17:06:25 -0400 |
commit | ceb9800eb16591459d3293d4d07cbcffe61fdf46 (patch) | |
tree | 6c91445af82ff18afcb6f378e791419cc9a947e5 /platform | |
parent | b0fcfaca7dad641ee92542bc8a84dd0d1275d061 (diff) | |
download | uBlock-ceb9800eb16591459d3293d4d07cbcffe61fdf46.zip uBlock-ceb9800eb16591459d3293d4d07cbcffe61fdf46.tar.gz uBlock-ceb9800eb16591459d3293d4d07cbcffe61fdf46.tar.bz2 |
code review
Diffstat (limited to 'platform')
-rw-r--r-- | platform/firefox/vapi-background.js | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index cff89ba..e21afdf 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -964,29 +964,36 @@ var tabWatcher = (function() { return tabbrowser.tabs[i]; }; - var browserFromTarget = function(target) { - if ( !target ) { - return null; - } + var browserFromTarget = (function() { if ( vAPI.fennec ) { - if ( target.browser ) { // target is a tab - target = target.browser; - } - } else if ( vAPI.thunderbird ) { - if ( target.mode ) { // target is object with tab info - var browserFunc = target.mode.getBrowser || target.mode.tabType.getBrowser; - if (browserFunc) { - return browserFunc.call(target.mode.tabType, target); + return function(target) { + if ( !target ) { return null; } + if ( target.browser ) { // target is a tab + target = target.browser; } - } - } else if ( target.linkedPanel ) { // target is a tab - target = target.linkedBrowser; + return target.localName === 'browser' ? target : null; + }; } - if ( target.localName !== 'browser' ) { - return null; + if ( vAPI.thunderbird ) { + return function(target) { + if ( !target ) { return null; } + if ( target.mode ) { // target is object with tab info + var browserFunc = target.mode.getBrowser || target.mode.tabType.getBrowser; + if ( browserFunc ) { + return browserFunc.call(target.mode.tabType, target); + } + } + return target.localName === 'browser' ? target : null; + }; } - return target; - }; + return function(target) { + if ( !target ) { return null; } + if ( target.linkedPanel ) { // target is a tab + target = target.linkedBrowser; + } + return target.localName === 'browser' ? target : null; + }; + })(); var tabIdFromTarget = function(target) { var browser = browserFromTarget(target); @@ -1161,9 +1168,10 @@ var tabWatcher = (function() { } var browser, URI, tabId; - for ( var tabindex = tabs.length - 1; tabindex >= 0; tabindex-- ) { - var tab = tabs[tabindex]; - browser = tabWatcher.browserFromTarget(tab); + var tabindex = tabs.length, tab; + while ( tabindex-- ) { + tab = tabs[tabindex]; + browser = browserFromTarget(tab); if ( browser === null ) { continue; } @@ -1172,7 +1180,6 @@ var tabWatcher = (function() { if ( URI.schemeIs('chrome') && URI.host === location.host ) { vAPI.tabs._remove(tab, getTabBrowser(this)); } - browser = browserFromTarget(tab); tabId = browserToTabIdMap.get(browser); if ( tabId !== undefined ) { removeBrowserEntry(tabId, browser); |