Bug 1641345 - Relationship among <browser>, tabmail tab, and web-ext tabId is broken for shared messagepane tabs. r=darktrojan

This commit is contained in:
alta88@fixall.com 2020-06-02 13:37:26 +03:00
Родитель 0268148857
Коммит 72d1cce056
2 изменённых файлов: 45 добавлений и 9 удалений

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

@ -468,6 +468,10 @@
* open when we received the call to openTab.
*/
this._mostRecentTabInfo = null;
/**
* Tab id, incremented on each openTab() and set on the browser.
*/
this.tabId = 0;
this.tabTypes = {};
this.tabModes = {};
this.defaultTabMode = null;
@ -860,12 +864,20 @@
},
};
firstTab.tabNode = this.tabContainer.arrowScrollbox.firstElementChild;
firstTab.tabId = this.tabId++;
firstTab.mode.tabs.push(firstTab);
this.tabInfo[0] = this.currentTabInfo = firstTab;
let tabOpenFirstFunc =
firstTab.mode.openFirstTab || firstTab.mode.tabType.openFirstTab;
tabOpenFirstFunc.call(firstTab.mode.tabType, firstTab);
this.setTabTitle(null);
// Set the tabId after defining a <browser> and before notifications.
firstTab.browser = this.getBrowserForTab(firstTab);
firstTab.browser._activeTabId = firstTab.tabId;
for (let tabMonitor of this.tabMonitors) {
if ("onTabOpened" in tabMonitor) {
tabMonitor.onTabOpened(firstTab, true);
@ -934,6 +946,7 @@
_ext: {},
};
tab.tabId = this.tabId++;
tabMode.tabs.push(tab);
var t = document.createXULElement("tab", { is: "tabmail-tab" });
tab.tabNode = t;
@ -1019,6 +1032,18 @@
t.linkedPanel = tab.panel.id;
}
// Set the tabId after defining a <browser> and before notifications.
let browser = this.getBrowserForTab(tab);
if (browser && !tab.browser) {
tab.browser = browser;
if (!tab.linkedBrowser) {
tab.linkedBrowser = browser;
}
}
if (tab.browser && !background) {
tab.browser._activeTabId = tab.tabId;
}
let restoreState = this._restoringTabState;
for (let tabMonitor of this.tabMonitors) {
if (
@ -1063,9 +1088,8 @@
});
t.dispatchEvent(evt);
delete tab.beforeTabOpen;
// Register browser progress listeners
let browser = this.getBrowserForTab(tab);
// Register browser progress listeners
if (browser && !browser._progressListenerAdded) {
// It would probably be better to have the tabs register this listener, since the
// browser can change. This wasn't trivial to do while implementing basic WebExtension
@ -1677,6 +1701,17 @@
let showTabFunc = tab.mode.showTab || tab.mode.tabType.showTab;
showTabFunc.call(tab.mode.tabType, tab);
let browser = this.getBrowserForTab(tab);
if (browser && !tab.browser) {
tab.browser = browser;
if (!tab.linkedBrowser) {
tab.linkedBrowser = browser;
}
}
if (tab.browser) {
tab.browser._activeTabId = tab.tabId;
}
for (let tabMonitor of this.tabMonitors) {
tabMonitor.onTabSwitched(tab, oldTab);
}

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

@ -399,7 +399,7 @@ class TabTracker extends TabTrackerBase {
super();
this._tabs = new WeakMap();
this._browsers = new WeakMap();
this._browsers = new Map();
this._tabIds = new Map();
this._nextId = 1;
this._movingTabs = new Map();
@ -457,18 +457,19 @@ class TabTracker extends TabTrackerBase {
* @return {Integer} The tab's numeric ID
*/
getBrowserTabId(browser) {
let id = this._browsers.get(browser);
let id = this._browsers.get(`${browser.id}#${browser._activeTabId}`);
if (id) {
return id;
}
let tabmail = browser.ownerDocument.getElementById("tabmail");
let tab =
tabmail && tabmail.tabInfo.find(info => getTabBrowser(info) == browser);
tabmail &&
tabmail.tabInfo.find(info => info.tabId == browser._activeTabId);
if (tab) {
id = this.getId(tab);
this._browsers.set(browser, id);
this._browsers.set(`${browser.id}#${tab.tabId}`, id);
return id;
}
return -1;
@ -484,7 +485,7 @@ class TabTracker extends TabTrackerBase {
this._tabs.set(nativeTabInfo, id);
let browser = getTabBrowser(nativeTabInfo);
if (browser) {
this._browsers.set(browser, id);
this._browsers.set(`${browser.id}#${nativeTabInfo.tabId}`, id);
}
this._tabIds.set(id, nativeTabInfo);
}
@ -499,6 +500,7 @@ class TabTracker extends TabTrackerBase {
let id = this._tabs.get(nativeTabInfo);
if (id) {
this._tabs.delete(nativeTabInfo);
this._browsers.delete(`${nativeTabInfo.browser.id}#${nativeTabInfo.tabId}`);
if (this._tabIds.get(id) === nativeTabInfo) {
this._tabIds.delete(id);
}
@ -539,7 +541,6 @@ class TabTracker extends TabTrackerBase {
// dispatched.
let tabmail = event.target.ownerDocument.getElementById("tabmail");
let currentTab = tabmail.selectedTab;
// We need to delay sending this event until the next tick, since the
// tab does not have its final index when the TabOpen event is dispatched.
Promise.resolve().then(() => {
@ -969,7 +970,7 @@ class TabmailTab extends Tab {
/** Returns the favIcon, without permission checks. */
get _favIconUrl() {
return this.browser.mIconURL;
return this.browser?.mIconURL;
}
/** Returns the tabmail element for the tab. */