This commit is contained in:
gorhill 2015-06-01 08:49:41 -04:00
parent 10740a28ff
commit d724fb23bd

View file

@ -609,13 +609,15 @@ vAPI.tabs._remove = function(tab, tabBrowser) {
/******************************************************************************/
vAPI.tabs.remove = function(tabId) {
var tabs = tabWatcher.browserFromTabId(tabId);
if ( tabs.length === 0 ) {
var browser = tabWatcher.browserFromTabId(tabId);
if ( !browser ) {
return;
}
for ( var tab of tabs ) {
this._remove(tab, getTabBrowser(getOwnerWindow(tab)));
var tab = tabWatcher.tabFromBrowser(browser);
if ( !tab ) {
return;
}
this._remove(tab, getTabBrowser(getOwnerWindow(browser)));
};
/******************************************************************************/
@ -713,6 +715,25 @@ var tabWatcher = (function() {
return indexFromBrowser(browserFromTarget(target));
};
var tabFromBrowser = function(browser) {
var i = indexFromBrowser(browser);
if ( i === -1 ) {
return null;
}
var win = getOwnerWindow(browser);
if ( !win ) {
return null;
}
var tabbrowser = getTabBrowser(win);
if ( !tabbrowser ) {
return null;
}
if ( !tabbrowser.tabs || i >= tabbrowser.tabs.length ) {
return null;
}
return tabbrowser.tabs[i];
};
var browserFromTarget = function(target) {
if ( !target ) {
return null;
@ -921,7 +942,8 @@ var tabWatcher = (function() {
tabs: function() { return browserToTabIdMap.keys(); },
tabIdFromTarget: tabIdFromTarget,
browserFromTabId: browserFromTabId,
indexFromTarget: indexFromTarget
indexFromTarget: indexFromTarget,
tabFromBrowser: tabFromBrowser
};
})();