Bug 1594232 support isolated_world alias in extension manifest r=robwu
authorShane Caraveo <scaraveo@mozilla.com>
Thu, 16 Jan 2020 03:46:18 +0000
changeset 510442 22135e7e31430e6cc90872111a0d7a6b5100bef1
parent 510441 76d2813008374a2e1cfc4443de4b3c12d9ef2c3f
child 510443 75b2943f6e6ab284629f0997e7d99e3e2adb396f
push id37021
push userrmaries@mozilla.com
push dateThu, 16 Jan 2020 09:46:51 +0000
treeherdermozilla-central@7541d616ff87 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrobwu
bugs1594232
milestone74.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1594232 support isolated_world alias in extension manifest r=robwu Differential Revision: https://phabricator.services.mozilla.com/D59969
toolkit/components/extensions/Extension.jsm
toolkit/components/extensions/schemas/manifest.json
toolkit/components/extensions/test/xpcshell/test_csp_custom_policies.js
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -1929,17 +1929,20 @@ class Extension extends ExtensionData {
   }
 
   get contentScriptCSP() {
     let { content_security_policy } = this.manifest;
     if (
       content_security_policy &&
       typeof content_security_policy === "object"
     ) {
-      return content_security_policy.content_scripts;
+      return (
+        content_security_policy.content_scripts ||
+        content_security_policy.isolated_world
+      );
     }
   }
 
   get backgroundScripts() {
     return this.manifest.background && this.manifest.background.scripts;
   }
 
   get optionalPermissions() {
--- a/toolkit/components/extensions/schemas/manifest.json
+++ b/toolkit/components/extensions/schemas/manifest.json
@@ -182,26 +182,37 @@
             "onError": "warn",
             "choices": [
               {
                 "type": "string",
                 "format": "contentSecurityPolicy"
               },
               {
                 "type": "object",
+                "additionalProperties": {
+                  "$ref": "UnrecognizedProperty"
+                },
                 "properties": {
                   "extension_pages": {
                     "type": "string",
                     "optional": true,
-                    "format": "contentSecurityPolicy"
+                    "format": "contentSecurityPolicy",
+                    "description": "The Content Security Policy used for extension pages."
                   },
                   "content_scripts": {
                     "type": "string",
                     "optional": true,
-                    "format": "contentSecurityPolicy"
+                    "format": "contentSecurityPolicy",
+                    "description": "The Content Security Policy used for content scripts."
+                  },
+                  "isolated_world": {
+                    "type": "string",
+                    "optional": true,
+                    "format": "contentSecurityPolicy",
+                    "description": "An alias for content_scripts to support Chrome compatibility.  Content Security Policy implementations may differ between Firefox and Chrome.  If both isolated_world and content_scripts exist, the value from content_scripts will be used."
                   }
                 }
               }
             ]
           },
 
           "permissions": {
             "type": "array",
--- a/toolkit/components/extensions/test/xpcshell/test_csp_custom_policies.js
+++ b/toolkit/components/extensions/test/xpcshell/test_csp_custom_policies.js
@@ -106,8 +106,49 @@ add_task(async function test_invalid_csp
   equal(
     policy.contentScriptCSP,
     defaultPolicy,
     "csp is default when invalid csp is provided."
   );
   await extension.unload();
   ExtensionTestUtils.failOnSchemaWarnings(true);
 });
+
+add_task(async function test_isolated_world() {
+  const test_policy = "script-src 'self'; object-src 'none'; img-src 'none'";
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      content_security_policy: {
+        isolated_world: test_policy,
+      },
+    },
+  });
+  await extension.startup();
+  let policy = WebExtensionPolicy.getByID(extension.id);
+  equal(
+    policy.contentScriptCSP,
+    test_policy,
+    "csp is is correct when using isolated_world."
+  );
+  await extension.unload();
+});
+
+// If both isolated_world and content_scripts is provided, content_scripts is used.
+add_task(async function test_isolated_world_overridden() {
+  const test_policy =
+    "script-src 'self'; object-src 'none'; img-src https://xpcshell.test.custom.csp";
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      content_security_policy: {
+        content_scripts: test_policy,
+        isolated_world: "script-src 'self'; object-src 'none'; img-src 'none'",
+      },
+    },
+  });
+  await extension.startup();
+  let policy = WebExtensionPolicy.getByID(extension.id);
+  equal(
+    policy.contentScriptCSP,
+    test_policy,
+    "csp is is correct when using isolated_world and content_scripts."
+  );
+  await extension.unload();
+});