Bug 1436450 - Fix <all_urls> as an optional API permission. r=aswan, a=RyanVM
authorTomislav Jovanovic <tomica@gmail.com>
Tue, 27 Mar 2018 00:40:23 +0200
changeset 463143 5dc2bed05d2ac1525dc9a4a146cbff0b84611cce
parent 463142 345eb838f7866a6d4cfd87c92a77f1f674064850
child 463144 57318d4d7ca9f00ad4fa688516b43b4a39cadcf0
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan, RyanVM
bugs1436450
milestone60.0
Bug 1436450 - Fix <all_urls> as an optional API permission. r=aswan, a=RyanVM MozReview-Commit-ID: FXiUuNgPlRo
toolkit/components/extensions/ext-permissions.js
toolkit/components/extensions/test/xpcshell/test_ext_permissions.js
--- a/toolkit/components/extensions/ext-permissions.js
+++ b/toolkit/components/extensions/ext-permissions.js
@@ -54,16 +54,21 @@ this.permissions = class extends Extensi
               };
               Services.obs.notifyObservers(subject, "webextension-optional-permission-prompt");
             });
             if (!allow) {
               return false;
             }
           }
 
+          // Unfortunatelly, we treat <all_urls> as an API permission as well.
+          if (origins.includes("<all_urls>")) {
+            perms.permissions.push("<all_urls>");
+          }
+
           await ExtensionPermissions.add(context.extension, perms);
           return true;
         },
 
         async getAll() {
           let perms = context.extension.activePermissions;
           delete perms.apis;
           return perms;
--- a/toolkit/components/extensions/test/xpcshell/test_ext_permissions.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_permissions.js
@@ -433,16 +433,48 @@ add_task(function test_permissions_have_
       } catch (e) {
         ok(GRANTED_WITHOUT_USER_PROMPT.includes(perm),
            `Permission '${perm}' intentionally granted without prompting the user`);
       }
     }
   }
 });
 
+// Check <all_urls> used as an optional API permission.
+add_task(async function test_optional_all_urls() {
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      optional_permissions: ["<all_urls>"],
+    },
+
+    background() {
+      browser.test.onMessage.addListener(async () => {
+        let before = !!browser.tabs.captureVisibleTab;
+        let granted = await browser.permissions.request({origins: ["<all_urls>"]});
+        let after = !!browser.tabs.captureVisibleTab;
+
+        browser.test.sendMessage("results", [before, granted, after]);
+      });
+    },
+  });
+
+  await extension.startup();
+
+  await withHandlingUserInput(extension, async () => {
+    extension.sendMessage("request");
+    let [before, granted, after] = await extension.awaitMessage("results");
+
+    equal(before, false, "captureVisibleTab() unavailable before optional permission request()");
+    equal(granted, true, "request() for optional permissions granted");
+    equal(after, true, "captureVisibleTab() avaiable after optional permission request()");
+  });
+
+  await extension.unload();
+});
+
 // Check that optional permissions are not included in update prompts
 add_task(async function test_permissions_prompt() {
   function background() {
     browser.test.onMessage.addListener(async (msg, arg) => {
       if (msg == "request") {
         let result = await browser.permissions.request(arg);
         browser.test.sendMessage("result", result);
       }