Query() moved to the parent process
This commit is contained in:
parent
0f95126092
commit
094f4fc107
2 changed files with 55 additions and 3 deletions
46
index.js
46
index.js
|
@ -6,6 +6,7 @@ Cu.import("resource://gre/modules/Services.jsm");
|
|||
|
||||
const tabs = require('sdk/tabs');
|
||||
const webExtension = require('sdk/webextension');
|
||||
const { viewFor } = require("sdk/view/core");
|
||||
|
||||
/* Let's start enabling Containers */
|
||||
var prefs = [
|
||||
|
@ -26,6 +27,10 @@ const identitiesState = {
|
|||
};
|
||||
|
||||
function getCookieStoreIdForContainer(containerId) {
|
||||
if (containerId == 0) {
|
||||
return 'firefox-default';
|
||||
}
|
||||
|
||||
return CONTAINER_STORE + containerId;
|
||||
}
|
||||
|
||||
|
@ -189,11 +194,48 @@ function openTab(args) {
|
|||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
function queryTabs(args) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let tabList = [];
|
||||
|
||||
for (let tab of tabs) {
|
||||
let xulTab = viewFor(tab);
|
||||
let userContextId = xulTab.getAttribute('usercontextid') || 0;
|
||||
let cookieStoreId = getCookieStoreIdForContainer(userContextId);
|
||||
|
||||
if ("cookieStoreId" in args && args.cookieStoreId != cookieStoreId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tabList.push({
|
||||
id: tab.id,
|
||||
url: tab.url,
|
||||
cookieStoreId: cookieStoreId,
|
||||
});
|
||||
}
|
||||
|
||||
resolve(tabList);
|
||||
});
|
||||
}
|
||||
|
||||
function removeTabs(ids) {
|
||||
for (let tab of tabs) {
|
||||
if (ids.indexOf(tab.id) != -1) {
|
||||
tab.close();
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
function handleWebExtensionMessage(message, sender, sendReply) {
|
||||
switch (message.method) {
|
||||
case 'queryIdentities':
|
||||
sendReply(contextualIdentities.query(message.arguments));
|
||||
break;
|
||||
case 'queryTabs':
|
||||
sendReply(queryTabs(message));
|
||||
break;
|
||||
case 'hideTab':
|
||||
identitiesState[message.cookieStoreId].hiddenTabUrls = message.tabUrlsToSave;
|
||||
break;
|
||||
|
@ -201,6 +243,10 @@ function handleWebExtensionMessage(message, sender, sendReply) {
|
|||
sendReply(identitiesState[message.cookieStoreId].hiddenTabUrls);
|
||||
identitiesState[message.cookieStoreId].hiddenTabUrls = [];
|
||||
break;
|
||||
case 'removeTabs':
|
||||
sendReply(removeTabs(message.tabIds));
|
||||
identitiesState[message.cookieStoreId].hiddenTabUrls = [];
|
||||
break;
|
||||
case 'getTab':
|
||||
sendReply(contextualIdentities.get(message.arguments));
|
||||
break;
|
||||
|
|
|
@ -7,7 +7,10 @@ function hideContainerTabs(containerId) {
|
|||
const tabUrlsToSave = [];
|
||||
const hideorshowIcon = document.querySelector(`#${containerId}-hideorshow-icon`);
|
||||
|
||||
browser.tabs.query({cookieStoreId: containerId}).then(tabs=> {
|
||||
browser.runtime.sendMessage({
|
||||
method: 'queryTabs',
|
||||
cookieStoreId: containerId
|
||||
}).then(tabs=> {
|
||||
tabs.forEach(tab=> {
|
||||
tabIdsToRemove.push(tab.id);
|
||||
tabUrlsToSave.push(tab.url);
|
||||
|
@ -17,7 +20,10 @@ function hideContainerTabs(containerId) {
|
|||
cookieStoreId: containerId,
|
||||
tabUrlsToSave: tabUrlsToSave
|
||||
}).then(()=> {
|
||||
browser.tabs.remove(tabIdsToRemove);
|
||||
browser.runtime.sendMessage({
|
||||
method: 'removeTabs',
|
||||
tabIds: tabIdsToRemove
|
||||
});
|
||||
hideorshowIcon.src = CONTAINER_UNHIDE_SRC;
|
||||
});
|
||||
});
|
||||
|
@ -122,7 +128,7 @@ document.querySelector('#sort-containers-link').addEventListener('click', ()=> {
|
|||
browser.runtime.sendMessage({method: 'queryIdentities'}).then(identities=> {
|
||||
identities.unshift({cookieStoreId: 'firefox-default'});
|
||||
|
||||
browser.tabs.query({}).then(tabsArray=> {
|
||||
browser.runtime.sendMessage({method: 'queryTabs'}).then(tabsArray=> {
|
||||
const sortedTabsArray = [];
|
||||
|
||||
identities.forEach(identity=> {
|
||||
|
|
Loading…
Add table
Reference in a new issue