code review

This commit is contained in:
gorhill 2015-10-12 17:06:25 -04:00
parent b0fcfaca7d
commit ceb9800eb1
1 changed files with 31 additions and 24 deletions

View File

@ -964,29 +964,36 @@ var tabWatcher = (function() {
return tabbrowser.tabs[i]; return tabbrowser.tabs[i];
}; };
var browserFromTarget = function(target) { var browserFromTarget = (function() {
if ( !target ) {
return null;
}
if ( vAPI.fennec ) { if ( vAPI.fennec ) {
if ( target.browser ) { // target is a tab return function(target) {
target = target.browser; if ( !target ) { return null; }
} if ( target.browser ) { // target is a tab
} else if ( vAPI.thunderbird ) { target = target.browser;
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;
};
}
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 function(target) {
if ( !target ) { return null; }
if ( target.linkedPanel ) { // target is a tab
target = target.linkedBrowser;
} }
} else if ( target.linkedPanel ) { // target is a tab return target.localName === 'browser' ? target : null;
target = target.linkedBrowser; };
} })();
if ( target.localName !== 'browser' ) {
return null;
}
return target;
};
var tabIdFromTarget = function(target) { var tabIdFromTarget = function(target) {
var browser = browserFromTarget(target); var browser = browserFromTarget(target);
@ -1161,9 +1168,10 @@ var tabWatcher = (function() {
} }
var browser, URI, tabId; var browser, URI, tabId;
for ( var tabindex = tabs.length - 1; tabindex >= 0; tabindex-- ) { var tabindex = tabs.length, tab;
var tab = tabs[tabindex]; while ( tabindex-- ) {
browser = tabWatcher.browserFromTarget(tab); tab = tabs[tabindex];
browser = browserFromTarget(tab);
if ( browser === null ) { if ( browser === null ) {
continue; continue;
} }
@ -1172,7 +1180,6 @@ var tabWatcher = (function() {
if ( URI.schemeIs('chrome') && URI.host === location.host ) { if ( URI.schemeIs('chrome') && URI.host === location.host ) {
vAPI.tabs._remove(tab, getTabBrowser(this)); vAPI.tabs._remove(tab, getTabBrowser(this));
} }
browser = browserFromTarget(tab);
tabId = browserToTabIdMap.get(browser); tabId = browserToTabIdMap.get(browser);
if ( tabId !== undefined ) { if ( tabId !== undefined ) {
removeBrowserEntry(tabId, browser); removeBrowserEntry(tabId, browser);