diff --git a/index.js b/index.js index 5a45c07..a751559 100644 --- a/index.js +++ b/index.js @@ -43,7 +43,10 @@ let ContainerService = { "openTab", "moveTabsToWindow", "queryIdentities", - "getIdentity" + "getIdentity", + "createIdentity", + "removeIdentity", + "updateIdentity", ]; // Map of identities. @@ -164,10 +167,14 @@ let ContainerService = { // Tabs management hideTabs(args) { - return new Promise(resolve => { + return new Promise((resolve, reject) => { + if (!("userContextId" in args)) { + reject("hideTabs must be called with userContextId argument."); + return; + } + for (const tab of tabs) { - const userContextId = this._getUserContextIdFromTab(tab); - if ("userContextId" in args && args.userContextId !== userContextId) { + if (args.userContextId !== this._getUserContextIdFromTab(tab)) { continue; } @@ -180,6 +187,11 @@ let ContainerService = { }, showTabs(args) { + if (!("userContextId" in args)) { + Promise.reject("showTabs must be called with userContextId argument."); + return; + } + let promises = []; for (let url of this._identitiesState[args.userContextId].hiddenTabUrls) { @@ -367,10 +379,57 @@ let ContainerService = { }, getIdentity(args) { + if (!("userContextId" in args)) { + Promise.reject("getIdentity must be called with userContextId argument."); + return; + } + let identity = ContextualIdentityService.getIdentityFromId(args.userContextId); return Promise.resolve(identity ? this._convert(identity) : null); }, + createIdentity(args) { + for (const arg of [ "name", "color", "icon"]) { + if (!(arg in args)) { + Promise.reject("createIdentity must be called with " + arg + " argument."); + return; + } + } + + // FIXME: icon and color conversion based on FF version. + const identity = ContextualIdentityService.create(args.name, args.icon, args.color); + return Promise.resolve(this._convert(identity)); + }, + + updateIdentity(args) { + if (!("userContextId" in args)) { + Promise.reject("updateIdentity must be called with userContextId argument."); + return; + } + + let identity = ContextualIdentityService.getIdentityFromId(args.userContextId); + for (const arg of [ "name", "color", "icon"]) { + if ((arg in args)) { + identity[arg] = args[arg]; + } + } + + // FIXME: icon and color conversion based on FF version. + // FIXME: color/name update propagation + return Promise.resolve(ContextualIdentityService.update(args.userContextId, + identity.name, + identity.icon, + identity.color)); + }, + + removeIdentity(args) { + if (!("userContextId" in args)) { + Promise.reject("removeIdentity must be called with userContextId argument."); + return; + } + return Promise.resolve(ContextualIdentityService.remove(args.userContextId)); + }, + // Styling the window configureWindow(window) {