From 75fa7297bc26310364a3319ad807dfe74b2b9203 Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Tue, 20 Dec 2016 17:54:30 +0000 Subject: [PATCH] Adding in extension experiment for API changes --- webextension-experiment/.schema.json.swp | Bin 0 -> 16384 bytes webextension-experiment/LICENSE | 27 ++++++ webextension-experiment/README.md | 7 ++ webextension-experiment/api.js | 113 +++++++++++++++++++++++ webextension-experiment/install.rdf | 31 +++++++ webextension-experiment/schema.json | 105 +++++++++++++++++++++ webextension/manifest.json | 2 + 7 files changed, 285 insertions(+) create mode 100644 webextension-experiment/.schema.json.swp create mode 100644 webextension-experiment/LICENSE create mode 100644 webextension-experiment/README.md create mode 100644 webextension-experiment/api.js create mode 100644 webextension-experiment/install.rdf create mode 100644 webextension-experiment/schema.json diff --git a/webextension-experiment/.schema.json.swp b/webextension-experiment/.schema.json.swp new file mode 100644 index 0000000000000000000000000000000000000000..584e55918188c02df0dccd474daaefff83ecd58d GIT binary patch literal 16384 zcmeI2O^6&t6vxZxYNAF>jDk6potx~=#zd1SQ4BjK3_;LMHn_y#)^ykG)~2UxQeCsV z!?Nl{gdlqGpa($&LHq!3Dj4G-;5pv>I(g8OXGL`JUp3v+J#Fu->ts>fYWOkz`Rdib zt6sh8srvpiwI}G|$^!)39fXWroPIibZ##MBBq8%MVtS56=F*_;yohFFEu*T4M>tNnu&<3czlu9`I6>QEMzpsms(tjCXe)Z?9cHg ztIWr8U6)GBcPE_!TULR#Zj2q-Ne&*kf4|XSpLZ|4bNAGimBUrsDc}@v3OEIv0!{&^ zfK$LJuoV^1t!?CaRD4@f`I+SRy29`E$?=ZlmldujhwjHI;1qBQI0c*nP64NYQ@|!1c60SCc-zymwL&o>kD5qJZ< z05muQ4uh}pG2#+94vv6P;DLLydzhZh&a=1^`8cIjn~!Fv10MTI zv^17h;G$RMA)bvXqh|dD*KHP35n!=}&>dRuP@!X7k>>@cr?ga@)~XdRXHIuo+}LTf zBj4K0U5ntCxu$qiF7Vz{sqZV=3FQM!`bFCJ0q3HS-4%U)V?tQD4@c%#&lwpJ{} zWm{?L6)Jmrj#KkIl?|$~Z>zl2SLcdXZ~#U6GL&kVGOdAi3eCizcJmVT{&7Xk^BXGD z!=fB4wb6o`mXyAw#G8VWRgSefA(~BHw)I+C(mKbRp}yiw^B~`BjM21$cuCe)uYDvX zrteqQ%}SxZt9jpYt;kv}IBH&btvW!5v~^?slHwKWk#6yc6KNCfb^+T1YC)ebs7UH* z+7fdnGEax>r&Fx}BKG=ef1{;~LeJT^Fe?^#L~$$2%iZ&EP%mxU5_)w@JY4->nOi_i?_YX{X1HRdZ` z|3JBs=v|8%QZ<SDoHN8;XZz5$*pl3S}ybTodXh0gT2N?ZY*)stsyC%d-)`t9&oR%+lO*snM(_ zWP3JmGkI$|XqV@VB|}e=?%IT4aPH9G2M6YfrR5;49FUp7dRjq~jSR|sORTRufc6_7 z5V1;(uRCPrjIR}#ihX2~w-k>t^N49#<0{S7GktnJ`Y-9CCjz9i-h`Rn*tDsZOm7NZ z+givPmxoliDPpq(-JZnTO${XTBNI}RCRnV?RLpHSJ?hJVKU!CEG3Kh0Sx8)fg`?y4 z7JBT-nhC`==1>*|v?&A8=#)gV&L~1$EUAw`#{ { + if (details.name && + ContextualIdentityService.getUserContextLabel(identity.userContextId) != details.name) { + return; + } + + identities.push(convert(identity)); + }); + + return Promise.resolve(identities); + }, + + create(details) { + let identity = ContextualIdentityService.create(details.name, + details.icon, + details.color); + return Promise.resolve(convert(identity)); + }, + + update(cookieStoreId, details) { + let containerId = getContainerForCookieStoreId(cookieStoreId); + if (!containerId) { + return Promise.resolve(null); + } + + let identity = ContextualIdentityService.getIdentityFromId(containerId); + if (!identity) { + return Promise.resolve(null); + } + + if (details.name !== null) { + identity.name = details.name; + } + + if (details.color !== null) { + identity.color = details.color; + } + + if (details.icon !== null) { + identity.icon = details.icon; + } + + if (!ContextualIdentityService.update(identity.userContextId, + identity.name, identity.icon, + identity.color)) { + return Promise.resolve(null); + } + + return Promise.resolve(convert(identity)); + }, + + remove(cookieStoreId) { + let containerId = getContainerForCookieStoreId(cookieStoreId); + if (!containerId) { + return Promise.resolve(null); + } + + let identity = ContextualIdentityService.getIdentityFromId(containerId); + if (!identity) { + return Promise.resolve(null); + } + + // We have to create the identity object before removing it. + let convertedIdentity = convert(identity); + + if (!ContextualIdentityService.remove(identity.userContextId)) { + return Promise.resolve(null); + } + + return Promise.resolve(convertedIdentity); + }, + }, + }; + + return self; + } +} diff --git a/webextension-experiment/install.rdf b/webextension-experiment/install.rdf new file mode 100644 index 0000000..e1d4e0b --- /dev/null +++ b/webextension-experiment/install.rdf @@ -0,0 +1,31 @@ + + + + contextualidentities@experiments.addons.mozilla.org + Experimental Contextual Identites API + 256 + 0.1 + Experimental Contextual Identities API + groovecoder, baku and jkt + true + + + + + {ec8030f7-c20a-464f-9b0e-13a3a9e97384} + 51.0 + * + + + + + + + xpcshell@tests.mozilla.org + 1 + 2 + + + + + diff --git a/webextension-experiment/schema.json b/webextension-experiment/schema.json new file mode 100644 index 0000000..562ad7d --- /dev/null +++ b/webextension-experiment/schema.json @@ -0,0 +1,105 @@ +[ + { + "namespace": "contextualIdentities", + "description": "Use the browser.contextualIdentities API to query and modify contextual identity, also called as containers.", + "permissions": ["contextualidentities"], + "types": [ + { + "id": "ContextualIdentity", + "type": "object", + "description": "Represents information about a contextual identity.", + "properties": { + "name": {"type": "string", "description": "The name of the contextual identity."}, + "icon": {"type": "string", "description": "The icon of the contextual identity."}, + "color": {"type": "string", "description": "The color of the contextual identity."}, + "cookieStoreId": {"type": "string", "description": "The cookie store ID of the contextual identity."} + } + } + ], + "functions": [ + { + "name": "get", + "type": "function", + "description": "Retrieves information about a single contextual identity.", + "async": true, + "parameters": [ + { + "type": "string", + "name": "cookieStoreId", + "description": "The ID of the contextual identity cookie store. " + } + ] + }, + { + "name": "query", + "type": "function", + "description": "Retrieves all contextual identities", + "async": true, + "parameters": [ + { + "type": "object", + "name": "details", + "description": "Information to filter the contextual identities being retrieved.", + "properties": { + "name": {"type": "string", "optional": true, "description": "Filters the contextual identity by name."} + } + } + ] + }, + { + "name": "create", + "type": "function", + "description": "Creates a contextual identity with the given data.", + "async": true, + "parameters": [ + { + "type": "object", + "name": "details", + "description": "Details about the contextual identity being created.", + "properties": { + "name": {"type": "string", "optional": false, "description": "The name of the contextual identity." }, + "color": {"type": "string", "optional": false, "description": "The color of the contextual identity." }, + "icon": {"type": "string", "optional": false, "description": "The icon of the contextual identity." } + } + } + ] + }, + { + "name": "update", + "type": "function", + "description": "Updates a contextual identity with the given data.", + "async": true, + "parameters": [ + { + "type": "string", + "name": "cookieStoreId", + "description": "The ID of the contextual identity cookie store. " + }, + { + "type": "object", + "name": "details", + "description": "Details about the contextual identity being created.", + "properties": { + "name": {"type": "string", "optional": true, "description": "The name of the contextual identity." }, + "color": {"type": "string", "optional": true, "description": "The color of the contextual identity." }, + "icon": {"type": "string", "optional": true, "description": "The icon of the contextual identity." } + } + } + ] + }, + { + "name": "remove", + "type": "function", + "description": "Deletes a contetual identity by its cookie Store ID.", + "async": true, + "parameters": [ + { + "type": "string", + "name": "cookieStoreId", + "description": "The ID of the contextual identity cookie store. " + } + ] + } + ] + } +] diff --git a/webextension/manifest.json b/webextension/manifest.json index 3eaede1..3205c33 100644 --- a/webextension/manifest.json +++ b/webextension/manifest.json @@ -20,6 +20,8 @@ "homepage_url": "https://testpilot.firefox.com/", "permissions": [ + "experiments.contextualidentities", + "contextualidentities" ], "browser_action": {