Add a tab observer to show hidden tabs as there are many tab creation routes. Uses a queue to prevent multiple triggers. Fixes #765

This commit is contained in:
Jonathan Kingston 2017-08-28 16:40:14 -07:00
parent 3cc40344af
commit a762b5eca2
2 changed files with 17 additions and 23 deletions

View file

@ -52,12 +52,6 @@ const backgroundLogic = {
},
async openTab(options) {
const userContextId = ("userContextId" in options) ? options.userContextId : 0;
const cookieStoreId = backgroundLogic.cookieStoreId(userContextId);
// Unhide all hidden tabs
this.showTabs({
cookieStoreId
});
return this.openNewTab(options);
},

View file

@ -3,6 +3,7 @@ const messageHandler = {
// We use this to catch redirected tabs that have just opened
// If this were in platform we would change how the tab opens based on "new tab" link navigations such as ctrl+click
LAST_CREATED_TAB_TIMER: 2000,
unhideQueue: [],
init() {
// Handles messages from webextension code
@ -87,20 +88,6 @@ const messageHandler = {
}
});
browser.tabs.onCreated.addListener((tab) => {
// This works at capturing the tabs as they are created
// However we need onFocusChanged and onActivated to capture the initial tab
if (tab.id === -1) {
return {};
}
});
browser.tabs.onRemoved.addListener((tabId) => {
if (tabId === -1) {
return {};
}
});
browser.tabs.onActivated.addListener((info) => {
assignManager.removeContextMenu();
browser.tabs.get(info.tabId).then((tab) => {
@ -127,14 +114,27 @@ const messageHandler = {
});
}, {urls: ["<all_urls>"], types: ["main_frame"]});
// lets remember the last tab created so we can close it if it looks like a redirect
browser.tabs.onCreated.addListener((details) => {
this.lastCreatedTab = details;
browser.tabs.onCreated.addListener((tab) => {
// lets remember the last tab created so we can close it if it looks like a redirect
this.lastCreatedTab = tab;
if (tab.cookieStoreId) {
this.unhideContainer(tab.cookieStoreId);
}
setTimeout(() => {
this.lastCreatedTab = null;
}, this.LAST_CREATED_TAB_TIMER);
});
},
async unhideContainer(cookieStoreId) {
if (!this.unhideQueue.includes(cookieStoreId)) {
this.unhideQueue.push(cookieStoreId);
// Unhide all hidden tabs
await backgroundLogic.showTabs({
cookieStoreId
});
this.unhideQueue.splice(this.unhideQueue.indexOf(cookieStoreId), 1);
}
},
async onFocusChangedCallback(windowId) {