Implementation of 'openTab' method
This commit is contained in:
parent
679d8b9fbb
commit
a9eb39dfba
2 changed files with 30 additions and 4 deletions
25
index.js
25
index.js
|
@ -1,5 +1,8 @@
|
|||
/* global require */
|
||||
const {ContextualIdentityService} = require('resource://gre/modules/ContextualIdentityService.jsm');
|
||||
const { Cc, Ci, Cu, Cr } = require('chrome');
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const tabs = require('sdk/tabs');
|
||||
const webExtension = require('sdk/webextension');
|
||||
|
@ -167,6 +170,25 @@ const contextualIdentities = {
|
|||
remove: removeContainer
|
||||
};
|
||||
|
||||
function openTab(args) {
|
||||
let browserWin = Services.wm.getMostRecentWindow('navigator:browser');
|
||||
|
||||
// This should not really happen.
|
||||
if (!browserWin || !browserWin.gBrowser) {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
let userContextId = 0;
|
||||
if ('cookieStoreId' in args) {
|
||||
userContextId = getContainerForCookieStoreId(args.cookieStoreId);
|
||||
}
|
||||
|
||||
let tab = browserWin.gBrowser.addTab(args.url || null,
|
||||
{ userContextId: userContextId })
|
||||
browserWin.gBrowser.selectedTab = tab;
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
function handleWebExtensionMessage(message, sender, sendReply) {
|
||||
switch (message.method) {
|
||||
case 'query':
|
||||
|
@ -198,6 +220,9 @@ function handleWebExtensionMessage(message, sender, sendReply) {
|
|||
tabs.open('about:preferences#containers');
|
||||
sendReply({content: 'opened'});
|
||||
break;
|
||||
case 'openTab':
|
||||
sendReply(openTab(message));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,9 +31,10 @@ function showContainerTabs(containerId) {
|
|||
cookieStoreId: containerId
|
||||
}).then(hiddenTabUrls=> {
|
||||
hiddenTabUrls.forEach(url=> {
|
||||
browser.tabs.create({
|
||||
url: url,
|
||||
cookieStoreId: containerId
|
||||
browser.runtime.sendMessage({
|
||||
method: 'openTab',
|
||||
cookieStoreId: containerId,
|
||||
url: url
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -121,7 +122,7 @@ browser.runtime.sendMessage({method: 'query'}).then(identities=> {
|
|||
}
|
||||
});
|
||||
} else if (e.target.matches('.newtab-icon')) {
|
||||
browser.tabs.create({cookieStoreId: containerId});
|
||||
browser.runtime.sendMessage({method: 'openTab', cookieStoreId: containerId});
|
||||
window.close();
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue