1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-16 23:42:39 +01:00

Fix for #1437 - support for browsers which don't support getTabForBrowser

This commit is contained in:
AlexVallat 2015-06-07 19:30:31 +01:00
parent 6d942dc424
commit eb264c6b87

View File

@ -383,9 +383,25 @@ var getTabForBrowser = function(browser) {
return null;
}
var win = browser.ownerGlobal;
return vAPI.fennec && win.BrowserApp && win.BrowserApp.getTabForBrowser(browser) ||
win.gBrowser && (win.gBrowser.getTabForBrowser && win.gBrowser.getTabForBrowser(browser) ||
win.gBrowser._getTabForBrowser && win.gBrowser._getTabForBrowser(browser));
if (vAPI.fennec) {
return win.BrowserApp && win.BrowserApp.getTabForBrowser(browser);
} else {
var gBrowser = win.gBrowser;
if (gBrowser) {
if (typeof gBrowser.getTabForBrowser === 'function') {
return gBrowser.getTabForBrowser(browser);
} else if (gBrowser.browsers && gBrowser.tabs) {
// Fallback to manual searching if the browser doesn't support getTabForBrowser
for (var i = 0; i < gBrowser.browsers.length; i++) {
if (gBrowser.browsers[i] === browser) {
return gBrowser.tabs[i];
}
}
}
}
}
return null;
};
@ -477,7 +493,7 @@ vAPI.tabs.getTabId = function(target) {
return vAPI.noTabId;
}
var tab;
var tab = null;
var browser;
if ( vAPI.fennec ) {
@ -505,13 +521,7 @@ vAPI.tabs.getTabId = function(target) {
tabId = '' + this.stackId++;
this.stack.set(browser, tabId);
if (!tab) {
tab = getTabForBrowser(browser);
}
if (tab) {
this.tabLookup.set(tabId, tab);
}
this.tabLookup.set(tabId, tab || browser); // If the tab is not know, record the browser instead and find the tab later
}
return tabId;
};
@ -519,7 +529,24 @@ vAPI.tabs.getTabId = function(target) {
/******************************************************************************/
vAPI.tabs.tabFromTabId = function(tabId) {
return this.tabLookup.get(tabId);
var target = this.tabLookup.get(tabId);
if (!target) {
return null;
}
// Check if this is actually a tab
if (vAPI.fennec && target.browser ||
target.linkedPanel) {
return target;
}
// This isn't a tab. No tab for this browser is yet known.
var tab = getTabForBrowser(target);
if (tab) {
// Found the tab now, so record it
this.tabLookup.set(tabId, tab);
}
return tab;
};
/******************************************************************************/