Bug 1402944: Part 6 - Optimize getBrowserInfo some more. r=mixedpuppy

MozReview-Commit-ID: 8kdeVqKb889

--HG--
extra : rebase_source : 63282fc295a50ef9743b3e6192e2b1ac726af022
This commit is contained in:
Kris Maglione 2017-09-23 00:50:46 -07:00
Родитель 89ae1721a0
Коммит 32f579d0e3
1 изменённых файлов: 39 добавлений и 22 удалений

Просмотреть файл

@ -207,6 +207,7 @@ class TabTracker extends TabTrackerBase {
super();
this._tabs = new WeakMap();
this._browsers = new WeakMap();
this._tabIds = new Map();
this._nextId = 1;
@ -239,19 +240,38 @@ class TabTracker extends TabTrackerBase {
}
getId(nativeTab) {
if (this._tabs.has(nativeTab)) {
return this._tabs.get(nativeTab);
let id = this._tabs.get(nativeTab);
if (id) {
return id;
}
this.init();
let id = this._nextId++;
id = this._nextId++;
this.setId(nativeTab, id);
return id;
}
getBrowserTabId(browser) {
let id = this._browsers.get(browser);
if (id) {
return id;
}
let tab = browser.ownerGlobal.gBrowser.getTabForBrowser(browser);
if (tab) {
id = this.getId(tab);
this._browsers.set(browser, id);
return id;
}
return -1;
}
setId(nativeTab, id) {
this._tabs.set(nativeTab, id);
if (nativeTab.linkedBrowser) {
this._browsers.set(nativeTab.linkedBrowser, id);
}
this._tabIds.set(id, nativeTab);
}
@ -522,30 +542,27 @@ class TabTracker extends TabTrackerBase {
}
getBrowserData(browser) {
if (browser.ownerDocument.documentURI === "about:addons") {
// When we're loaded into a <browser> inside about:addons, we need to go up
// one more level.
browser = browser.ownerDocument.docShell.chromeEventHandler;
}
let result = {
tabId: -1,
windowId: -1,
};
let {gBrowser} = browser.ownerGlobal;
// Some non-browser windows have gBrowser but not
// getTabForBrowser!
if (gBrowser && gBrowser.getTabForBrowser) {
result.windowId = windowTracker.getId(browser.ownerGlobal);
// Some non-browser windows have gBrowser but not getTabForBrowser!
if (!gBrowser || !gBrowser.getTabForBrowser) {
if (browser.ownerDocument.documentURI === "about:addons") {
// When we're loaded into a <browser> inside about:addons, we need to go up
// one more level.
browser = browser.ownerDocument.docShell.chromeEventHandler;
let nativeTab = gBrowser.getTabForBrowser(browser);
if (nativeTab) {
result.tabId = this.getId(nativeTab);
({gBrowser} = browser.ownerGlobal);
} else {
return {
tabId: -1,
windowId: -1,
};
}
}
return result;
return {
tabId: this.getBrowserTabId(browser),
windowId: windowTracker.getId(browser.ownerGlobal),
};
}
get activeTab() {