Bug 1655575 - Add enterprise policy for xr permission. r=emalysz, a=jcristau
authorMichael Kaply <mozilla@kaply.com>
Tue, 28 Jul 2020 21:19:06 +0000
changeset 599986 89bd47656f3d849c2be15c87f8d4afae756c48e9
parent 599985 34006a2e14797314fc30b4d99eb881bb35ea7734
child 599987 e21bf8670b749d1dbe7e8aaede34668685d91f0e
push id54
push userjcristau@mozilla.com
push dateThu, 06 Aug 2020 10:31:36 +0000
treeherdermozilla-esr78@89bd47656f3d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemalysz, jcristau
bugs1655575
milestone78.2.0
Bug 1655575 - Add enterprise policy for xr permission. r=emalysz, a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D85200
browser/base/content/pageinfo/permissions.js
browser/components/enterprisepolicies/Policies.jsm
browser/components/enterprisepolicies/schemas/policies-schema.json
browser/components/enterprisepolicies/tests/browser/browser_policy_pageinfo_permissions.js
browser/components/enterprisepolicies/tests/xpcshell/test_permissions.js
--- a/browser/base/content/pageinfo/permissions.js
+++ b/browser/base/content/pageinfo/permissions.js
@@ -123,16 +123,17 @@ function initRow(aPartId) {
       break;
     case "autoplay-media":
       checkbox.disabled = Services.prefs.prefIsLocked("media.autoplay.default");
       break;
     case "geo":
     case "desktop-notification":
     case "camera":
     case "microphone":
+    case "xr":
       checkbox.disabled = Services.prefs.prefIsLocked(
         "permissions.default." + aPartId
       );
       break;
   }
 }
 
 function createRow(aPartId) {
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -1381,16 +1381,25 @@ var Policies = {
       if (param.Notifications) {
         addAllowDenyPermissions(
           "desktop-notification",
           param.Notifications.Allow,
           param.Notifications.Block
         );
         setDefaultPermission("desktop-notification", param.Notifications);
       }
+
+      if ("VirtualReality" in param) {
+        addAllowDenyPermissions(
+          "xr",
+          param.VirtualReality.Allow,
+          param.VirtualReality.Block
+        );
+        setDefaultPermission("xr", param.VirtualReality);
+      }
     },
   },
 
   PictureInPicture: {
     onBeforeAddons(manager, param) {
       if ("Enabled" in param) {
         setDefaultPref(
           "media.videocontrols.picture-in-picture.video-toggle.enabled",
--- a/browser/components/enterprisepolicies/schemas/policies-schema.json
+++ b/browser/components/enterprisepolicies/schemas/policies-schema.json
@@ -831,16 +831,45 @@
             "BlockNewRequests": {
               "type": "boolean"
             },
 
             "Locked": {
               "type": "boolean"
             }
           }
+        },
+
+        "VirtualReality": {
+          "type": "object",
+          "properties": {
+            "Allow": {
+              "type": "array",
+              "strict": false,
+              "items": {
+                "type": "origin"
+              }
+            },
+
+            "Block": {
+              "type": "array",
+              "strict": false,
+              "items": {
+                "type": "origin"
+              }
+            },
+
+            "BlockNewRequests": {
+              "type": "boolean"
+            },
+
+            "Locked": {
+              "type": "boolean"
+            }
+          }
         }
       }
     },
 
     "PictureInPicture": {
       "type": "object",
       "properties": {
         "Enabled": {
--- a/browser/components/enterprisepolicies/tests/browser/browser_policy_pageinfo_permissions.js
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_pageinfo_permissions.js
@@ -20,16 +20,20 @@ add_task(async function test_pageinfo_pe
         Location: {
           BlockNewRequests: true,
           Locked: true,
         },
         Notifications: {
           BlockNewRequests: true,
           Locked: true,
         },
+        VirtualReality: {
+          BlockNewRequests: true,
+          Locked: true,
+        },
         Autoplay: {
           Default: "block-audio",
           Locked: true,
         },
       },
       InstallAddonsPermission: {
         Default: false,
       },
@@ -46,16 +50,17 @@ add_task(async function test_pageinfo_pe
     "geo",
     "autoplay-media",
     "install",
     "popup",
     "desktop-notification",
     "cookie",
     "camera",
     "microphone",
+    "xr",
   ];
 
   await BrowserTestUtils.withNewTab(TEST_ORIGIN, async function(browser) {
     let pageInfo = BrowserPageInfo(TEST_ORIGIN, "permTab");
     await BrowserTestUtils.waitForEvent(pageInfo, "load");
 
     for (let i = 0; i < permissions.length; i++) {
       let permission = permissions[i];
--- a/browser/components/enterprisepolicies/tests/xpcshell/test_permissions.js
+++ b/browser/components/enterprisepolicies/tests/xpcshell/test_permissions.js
@@ -39,16 +39,22 @@ add_task(async function test_setup_preex
     Ci.nsIPermissionManager.EXPIRE_SESSION
   );
   PermissionTestUtils.add(
     "https://www.pre-existing-allow.com",
     "autoplay-media",
     Ci.nsIPermissionManager.ALLOW_ACTION,
     Ci.nsIPermissionManager.EXPIRE_SESSION
   );
+  PermissionTestUtils.add(
+    "https://www.pre-existing-allow.com",
+    "xr",
+    Ci.nsIPermissionManager.ALLOW_ACTION,
+    Ci.nsIPermissionManager.EXPIRE_SESSION
+  );
 
   // Pre-existing DENY permissions that should be overridden
   // with ALLOW.
 
   PermissionTestUtils.add(
     "https://www.pre-existing-deny.com",
     "camera",
     Ci.nsIPermissionManager.DENY_ACTION,
@@ -73,16 +79,22 @@ add_task(async function test_setup_preex
     Ci.nsIPermissionManager.EXPIRE_SESSION
   );
   PermissionTestUtils.add(
     "https://www.pre-existing-deny.com",
     "autoplay-media",
     Ci.nsIPermissionManager.DENY_ACTION,
     Ci.nsIPermissionManager.EXPIRE_SESSION
   );
+  PermissionTestUtils.add(
+    "https://www.pre-existing-deny.com",
+    "xr",
+    Ci.nsIPermissionManager.DENY_ACTION,
+    Ci.nsIPermissionManager.EXPIRE_SESSION
+  );
 });
 
 add_task(async function test_setup_activate_policies() {
   await setupPolicyEngineWithJson({
     policies: {
       Permissions: {
         Camera: {
           Allow: ["https://www.allow.com", "https://www.pre-existing-deny.com"],
@@ -99,16 +111,20 @@ add_task(async function test_setup_activ
         Notifications: {
           Allow: ["https://www.allow.com", "https://www.pre-existing-deny.com"],
           Block: ["https://www.deny.com", "https://www.pre-existing-allow.com"],
         },
         Autoplay: {
           Allow: ["https://www.allow.com", "https://www.pre-existing-deny.com"],
           Block: ["https://www.deny.com", "https://www.pre-existing-allow.com"],
         },
+        VirtualReality: {
+          Allow: ["https://www.allow.com", "https://www.pre-existing-deny.com"],
+          Block: ["https://www.deny.com", "https://www.pre-existing-allow.com"],
+        },
       },
     },
   });
   equal(
     Services.policies.status,
     Ci.nsIEnterprisePolicies.ACTIVE,
     "Engine is active"
   );
@@ -165,16 +181,20 @@ add_task(async function test_location_po
 add_task(async function test_notifications_policy() {
   checkAllPermissionsForType("desktop-notification");
 });
 
 add_task(async function test_autoplay_policy() {
   checkAllPermissionsForType("autoplay-media");
 });
 
+add_task(async function test_xr_policy() {
+  checkAllPermissionsForType("xr");
+});
+
 add_task(async function test_change_permission() {
   // Checks that changing a permission will still retain the
   // value set through the engine.
   PermissionTestUtils.add(
     "https://www.allow.com",
     "camera",
     Ci.nsIPermissionManager.DENY_ACTION,
     Ci.nsIPermissionManager.EXPIRE_SESSION
@@ -198,22 +218,29 @@ add_task(async function test_change_perm
     Ci.nsIPermissionManager.EXPIRE_SESSION
   );
   PermissionTestUtils.add(
     "https://www.allow.com",
     "autoplay-media",
     Ci.nsIPermissionManager.DENY_ACTION,
     Ci.nsIPermissionManager.EXPIRE_SESSION
   );
+  PermissionTestUtils.add(
+    "https://www.allow.com",
+    "xr",
+    Ci.nsIPermissionManager.DENY_ACTION,
+    Ci.nsIPermissionManager.EXPIRE_SESSION
+  );
 
   checkPermission("allow.com", "ALLOW", "camera");
   checkPermission("allow.com", "ALLOW", "microphone");
   checkPermission("allow.com", "ALLOW", "geo");
   checkPermission("allow.com", "ALLOW", "desktop-notification");
   checkPermission("allow.com", "ALLOW", "autoplay-media");
+  checkPermission("allow.com", "ALLOW", "xr");
 
   // Also change one un-managed permission to make sure it doesn't
   // cause any problems to the policy engine or the permission manager.
   PermissionTestUtils.add(
     "https://www.unmanaged.com",
     "camera",
     Ci.nsIPermissionManager.DENY_ACTION,
     Ci.nsIPermissionManager.EXPIRE_SESSION
@@ -237,16 +264,22 @@ add_task(async function test_change_perm
     Ci.nsIPermissionManager.EXPIRE_SESSION
   );
   PermissionTestUtils.add(
     "https://www.unmanaged.com",
     "autoplay-media",
     Ci.nsIPermissionManager.DENY_ACTION,
     Ci.nsIPermissionManager.EXPIRE_SESSION
   );
+  PermissionTestUtils.add(
+    "https://www.unmanaged.com",
+    "xr",
+    Ci.nsIPermissionManager.DENY_ACTION,
+    Ci.nsIPermissionManager.EXPIRE_SESSION
+  );
 });
 
 add_task(async function test_setup_trackingprotection() {
   await setupPolicyEngineWithJson({
     policies: {
       EnableTrackingProtection: {
         Exceptions: ["https://www.allow.com"],
       },