Bug 1350151 Part 2: Use requireUserInput for permissions.request() r=kmag
authorAndrew Swan <aswan@mozilla.com>
Tue, 25 Jul 2017 22:43:34 -0700
changeset 420829 3facbb92e28bd61778e50d9dace21f6ccc4dbe83
parent 420828 1cf8b34f618eab61e33d1d4331db057522462ae3
child 420830 86ed29aded3267dfa24df213ee1a82e50575a7e4
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1350151
milestone56.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 1350151 Part 2: Use requireUserInput for permissions.request() r=kmag MozReview-Commit-ID: ALRlk7ZZ7LR
toolkit/components/extensions/ext-c-permissions.js
toolkit/components/extensions/ext-c-toolkit.js
toolkit/components/extensions/ext-permissions.js
toolkit/components/extensions/jar.mn
toolkit/components/extensions/schemas/permissions.json
toolkit/components/extensions/test/xpcshell/test_ext_permissions.js
deleted file mode 100644
--- a/toolkit/components/extensions/ext-c-permissions.js
+++ /dev/null
@@ -1,22 +0,0 @@
-"use strict";
-
-var {
-  ExtensionError,
-} = ExtensionUtils;
-
-this.permissions = class extends ExtensionAPI {
-  getAPI(context) {
-    return {
-      permissions: {
-        async request(perms) {
-          let winUtils = context.contentWindow.getInterface(Ci.nsIDOMWindowUtils);
-          if (!winUtils.isHandlingUserInput) {
-            throw new ExtensionError("May only request permissions from a user input handler");
-          }
-
-          return context.childManager.callParentAsyncFunction("permissions.request_parent", [perms]);
-        },
-      },
-    };
-  }
-};
--- a/toolkit/components/extensions/ext-c-toolkit.js
+++ b/toolkit/components/extensions/ext-c-toolkit.js
@@ -57,23 +57,16 @@ extensions.registerModules({
   },
   i18n: {
     url: "chrome://extensions/content/ext-i18n.js",
     scopes: ["addon_child", "content_child", "devtools_child", "proxy_script"],
     paths: [
       ["i18n"],
     ],
   },
-  permissions: {
-    url: "chrome://extensions/content/ext-c-permissions.js",
-    scopes: ["addon_child", "content_child", "devtools_child", "proxy_script"],
-    paths: [
-      ["permissions"],
-    ],
-  },
   runtime: {
     url: "chrome://extensions/content/ext-c-runtime.js",
     scopes: ["addon_child", "content_child", "devtools_child", "proxy_script"],
     paths: [
       ["runtime"],
     ],
   },
   storage: {
--- a/toolkit/components/extensions/ext-permissions.js
+++ b/toolkit/components/extensions/ext-permissions.js
@@ -13,17 +13,17 @@ var {
 
 XPCOMUtils.defineLazyPreferenceGetter(this, "promptsEnabled",
                                       "extensions.webextOptionalPermissionPrompts");
 
 this.permissions = class extends ExtensionAPI {
   getAPI(context) {
     return {
       permissions: {
-        async request_parent(perms) {
+        async request(perms) {
           let {permissions, origins} = perms;
 
           let manifestPermissions = context.extension.manifest.optional_permissions;
           for (let perm of permissions) {
             if (!manifestPermissions.includes(perm)) {
               throw new ExtensionError(`Cannot request permission ${perm} since it was not declared in optional_permissions`);
             }
           }
--- a/toolkit/components/extensions/jar.mn
+++ b/toolkit/components/extensions/jar.mn
@@ -32,13 +32,12 @@ toolkit.jar:
     # Below is a separate group using the naming convention ext-c-*.js that run
     # in the child process.
     content/extensions/ext-c-backgroundPage.js
     content/extensions/ext-c-downloads.js
     content/extensions/ext-c-extension.js
 #ifndef ANDROID
     content/extensions/ext-c-identity.js
 #endif
-    content/extensions/ext-c-permissions.js
     content/extensions/ext-c-runtime.js
     content/extensions/ext-c-storage.js
     content/extensions/ext-c-test.js
     content/extensions/ext-c-toolkit.js
--- a/toolkit/components/extensions/schemas/permissions.json
+++ b/toolkit/components/extensions/schemas/permissions.json
@@ -81,16 +81,17 @@
           }
         ]
       },
       {
         "name": "request",
         "type": "function",
         "allowedContexts": ["content"],
         "async": "callback",
+        "requireUserInput": true,
         "description": "Request the given permissions.",
         "parameters": [
           {
             "name": "permissions",
             "$ref": "Permissions"
           },
           {
             "name": "callback",
--- a/toolkit/components/extensions/test/xpcshell/test_ext_permissions.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_permissions.js
@@ -125,17 +125,17 @@ add_task(async function test_permissions
   result = await call("contains", {
     permissions: [...REQUIRED_PERMISSIONS, ...OPTIONAL_PERMISSIONS],
   });
   equal(result, false, "contains() returns false for a mix of available and unavailable permissions");
 
   let perm = OPTIONAL_PERMISSIONS[0];
   result = await call("request", {permissions: [perm]});
   equal(result.status, "error", "request() fails if not called from an event handler");
-  ok(/May only request permissions from a user input handler/.test(result.message),
+  ok(/request may only be called from a user input handler/.test(result.message),
      "error message for calling request() outside an event handler is reasonable");
   result = await call("contains", {permissions: [perm]});
   equal(result, false, "Permission requested outside an event handler was not granted");
 
   let userInputHandle = winUtils.setHandlingUserInput(true);
 
   result = await call("request", {permissions: ["notifications"]});
   equal(result.status, "error", "request() for permission not in optional_permissions should fail");