Bug 1507291 - Remove concept of machine_only policies. r=Felipe,flod, a=jcristau
authorMichael Kaply <mozilla@kaply.com>
Thu, 15 Nov 2018 20:30:03 +0000
changeset 501297 27727035c0de45862af6d6fd140c962f8bd5e483
parent 501296 88649b8165f06f85195acbac78619ab97ee3de33
child 501298 571a146f0732aeab505743a97ad176e5d7e673dc
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe, flod, jcristau
bugs1507291
milestone64.0
Bug 1507291 - Remove concept of machine_only policies. r=Felipe,flod, a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D11942
browser/components/enterprisepolicies/EnterprisePolicies.js
browser/components/enterprisepolicies/WindowsGPOParser.jsm
browser/components/enterprisepolicies/content/aboutPolicies.css
browser/components/enterprisepolicies/content/aboutPolicies.js
browser/components/enterprisepolicies/schemas/policies-schema.json
--- a/browser/components/enterprisepolicies/EnterprisePolicies.js
+++ b/browser/components/enterprisepolicies/EnterprisePolicies.js
@@ -402,17 +402,19 @@ class JSONPoliciesProvider {
 class WindowsGPOPoliciesProvider {
   constructor() {
     this._policies = null;
 
     let wrk = Cc["@mozilla.org/windows-registry-key;1"].createInstance(Ci.nsIWindowsRegKey);
 
     // Machine policies override user policies, so we read
     // user policies first and then replace them if necessary.
+    log.debug("root = HKEY_CURRENT_USER");
     this._readData(wrk, wrk.ROOT_KEY_CURRENT_USER);
+    log.debug("root = HKEY_LOCAL_MACHINE");
     this._readData(wrk, wrk.ROOT_KEY_LOCAL_MACHINE);
   }
 
   get hasPolicies() {
     return this._policies !== null;
   }
 
   get policies() {
@@ -421,18 +423,17 @@ class WindowsGPOPoliciesProvider {
 
   get failed() {
     return this._failed;
   }
 
   _readData(wrk, root) {
     wrk.open(root, "SOFTWARE\\Policies", wrk.ACCESS_READ);
     if (wrk.hasChild("Mozilla\\Firefox")) {
-      let isMachineRoot = (root == wrk.ROOT_KEY_LOCAL_MACHINE);
-      this._policies = WindowsGPOParser.readPolicies(wrk, this._policies, isMachineRoot);
+      this._policies = WindowsGPOParser.readPolicies(wrk, this._policies);
     }
     wrk.close();
   }
 }
 
 class macOSPoliciesProvider {
   constructor() {
     this._policies = null;
--- a/browser/components/enterprisepolicies/WindowsGPOParser.jsm
+++ b/browser/components/enterprisepolicies/WindowsGPOParser.jsm
@@ -14,89 +14,75 @@ XPCOMUtils.defineLazyGetter(this, "log",
     prefix: "GPOParser.jsm",
     // tip: set maxLogLevel to "debug" and use log.debug() to create detailed
     // messages during development. See LOG_LEVELS in Console.jsm for details.
     maxLogLevel: "error",
     maxLogLevelPref: PREF_LOGLEVEL,
   });
 });
 
-XPCOMUtils.defineLazyModuleGetters(this, {
-  schema: "resource:///modules/policies/schema.jsm",
-});
-
 var EXPORTED_SYMBOLS = ["WindowsGPOParser"];
 
 var WindowsGPOParser = {
-  readPolicies(wrk, policies, isMachineRoot) {
+  readPolicies(wrk, policies) {
     let childWrk = wrk.openChild("Mozilla\\Firefox", wrk.ACCESS_READ);
     if (!policies) {
       policies = {};
     }
     try {
-      policies = registryToObject(childWrk, policies, isMachineRoot);
+      policies = registryToObject(childWrk, policies);
     } catch (e) {
       log.error(e);
     } finally {
       childWrk.close();
     }
     // Need an extra check here so we don't
     // JSON.stringify if we aren't in debug mode
     if (log._maxLogLevel == "debug") {
-      log.debug("root = " + isMachineRoot ? "HKEY_LOCAL_MACHINE" : "HKEY_CURRENT_USER");
       log.debug(JSON.stringify(policies, null, 2));
     }
     return policies;
   },
 };
 
-function registryToObject(wrk, policies, isMachineRoot) {
+function registryToObject(wrk, policies) {
   if (!policies) {
     policies = {};
   }
   if (wrk.valueCount > 0) {
     if (wrk.getValueName(0) == "1") {
       // If the first item is 1, just assume it is an array
       let array = [];
       for (let i = 0; i < wrk.valueCount; i++) {
         array.push(readRegistryValue(wrk, wrk.getValueName(i)));
       }
       // If it's an array, it shouldn't have any children
       return array;
     }
     for (let i = 0; i < wrk.valueCount; i++) {
       let name = wrk.getValueName(i);
-      if (!isMachineRoot && isMachineOnlyPolicy(name)) {
-        continue;
-      }
       let value = readRegistryValue(wrk, name);
       policies[name] = value;
     }
   }
   if (wrk.childCount > 0) {
     if (wrk.getChildName(0) == "1") {
       // If the first item is 1, it's an array of objects
       let array = [];
       for (let i = 0; i < wrk.childCount; i++) {
         let name = wrk.getChildName(i);
-        if (!isMachineRoot && isMachineOnlyPolicy(name)) {
-          continue;
-        }
         let childWrk = wrk.openChild(name, wrk.ACCESS_READ);
         array.push(registryToObject(childWrk));
         childWrk.close();
       }
       // If it's an array, it shouldn't have any children
       return array;
     }
     for (let i = 0; i < wrk.childCount; i++) {
       let name = wrk.getChildName(i);
-        if (!isMachineRoot && isMachineOnlyPolicy(name)) {
-        continue;
-      }
       let childWrk = wrk.openChild(name, wrk.ACCESS_READ);
       policies[name] = registryToObject(childWrk);
       childWrk.close();
     }
   }
   return policies;
 }
 
@@ -109,17 +95,8 @@ function readRegistryValue(wrk, value) {
     case wrk.TYPE_INT:
       return wrk.readIntValue(value);
     case wrk.TYPE_INT64:
       return wrk.readInt64Value(value);
   }
   // unknown type
   return null;
 }
-
-function isMachineOnlyPolicy(name) {
-  if (schema.properties[name] &&
-      schema.properties[name].machine_only) {
-    log.error(`Policy ${name} is only allowed under the HKEY_LOCAL_MACHINE root`);
-    return true;
-  }
-  return false;
-}
--- a/browser/components/enterprisepolicies/content/aboutPolicies.css
+++ b/browser/components/enterprisepolicies/content/aboutPolicies.css
@@ -109,20 +109,16 @@ tbody:nth-child(4n + 1) {
   fill: var(--newtab-icon-primary-color);
   height: 14px;
   vertical-align: middle;
   width: 14px;
   margin-top: -.125rem;
   margin-left: .5rem;
 }
 
-.icon.machine-only {
-  background-image: url("chrome://browser/skin/developer.svg");
-}
-
 .collapsible {
   cursor: pointer;
   border: none;
   outline: none;
 }
 
 .content {
   display: none;
--- a/browser/components/enterprisepolicies/content/aboutPolicies.js
+++ b/browser/components/enterprisepolicies/content/aboutPolicies.js
@@ -17,28 +17,16 @@ function col(text, className) {
   if (className) {
     column.classList.add(className);
   }
   let content = document.createTextNode(text);
   column.appendChild(content);
   return column;
 }
 
-function machine_only_col(text) {
-  let icon = document.createElement("span");
-  icon.classList.add("icon");
-  icon.classList.add("machine-only");
-  icon.setAttribute("data-l10n-id", "gpo-machine-only");
-  let column = document.createElement("td");
-  let content = document.createTextNode(text);
-  column.appendChild(content);
-  column.appendChild(icon);
-  return column;
-}
-
 function addMissingColumns() {
   const table = document.getElementById("activeContent");
   let maxColumns = 0;
 
   // count the number of columns per row and set the max number of columns
   for (let i = 0, length = table.rows.length; i < length; i++) {
     if (maxColumns < table.rows[i].cells.length) {
       maxColumns = table.rows[i].cells.length;
@@ -241,22 +229,17 @@ function generateDocumentation() {
   for (let policyName in schema.properties) {
     let main_tbody = document.createElement("tbody");
     main_tbody.classList.add("collapsible");
     main_tbody.addEventListener("click", function() {
       let content = this.nextElementSibling;
       content.classList.toggle("content");
     });
     let row = document.createElement("tr");
-    if (AppConstants.platform == "win" &&
-        schema.properties[policyName].machine_only) {
-      row.appendChild(machine_only_col(policyName));
-    } else {
-      row.appendChild(col(policyName));
-    }
+    row.appendChild(col(policyName));
     let descriptionColumn = col("");
     let stringID = string_mapping[policyName] || policyName;
     descriptionColumn.setAttribute("data-l10n-id", `policy-${stringID}`);
     row.appendChild(descriptionColumn);
     main_tbody.appendChild(row);
     let sec_tbody = document.createElement("tbody");
     sec_tbody.classList.add("content");
     sec_tbody.classList.add("content-style");
--- a/browser/components/enterprisepolicies/schemas/policies-schema.json
+++ b/browser/components/enterprisepolicies/schemas/policies-schema.json
@@ -1,15 +1,13 @@
 {
   "$schema": "http://json-schema.org/draft-04/schema#",
   "type": "object",
   "properties": {
     "AppUpdateURL": {
-      "machine_only": true,
-
       "type": "URL"
     },
 
     "Authentication": {
       "type": "object",
       "properties": {
         "SPNEGO" : {
           "type": "array",
@@ -158,18 +156,16 @@
         },
         "Locked": {
           "type": "boolean"
         }
       }
     },
 
     "DisableAppUpdate": {
-      "machine_only": true,
-
       "type": "boolean"
     },
 
     "DisableBuiltinPDFViewer": {
       "type": "boolean"
     },
 
     "DisableDeveloperTools": {
@@ -237,24 +233,20 @@
       }
     },
 
     "DisableSetDesktopBackground": {
       "type": "boolean"
     },
 
     "DisableSystemAddonUpdate": {
-      "machine_only": true,
-
       "type": "boolean"
     },
 
     "DisableTelemetry": {
-      "machine_only": true,
-
       "type": "boolean"
     },
 
     "DisplayBookmarksToolbar": {
       "type": "boolean"
     },
 
     "DisplayMenuBar": {
@@ -274,18 +266,16 @@
         "Locked": {
           "type": "boolean"
         }
       },
       "required": ["Value"]
     },
 
     "Extensions": {
-      "machine_only": true,
-
       "type": "object",
       "properties": {
         "Install" : {
           "type": "array",
           "items": {
             "type": "string"
           }
         },
@@ -333,18 +323,16 @@
       }
     },
 
     "HardwareAcceleration": {
       "type": "boolean"
     },
 
     "Homepage": {
-      "machine_only": true,
-
       "type": "object",
       "properties": {
         "URL": {
           "type": "URL"
         },
         "Locked": {
           "type": "boolean"
         },
@@ -382,24 +370,20 @@
       "type": "boolean"
     },
 
     "OfferToSaveLogins": {
       "type": "boolean"
     },
 
     "OverrideFirstRunPage": {
-      "machine_only": true,
-
       "type": "URLorEmpty"
     },
 
     "OverridePostUpdatePage": {
-      "machine_only": true,
-
       "type": "URLorEmpty"
     },
 
     "Permissions": {
       "type": "object",
       "properties": {
         "Camera": {
           "type": "object",
@@ -666,18 +650,16 @@
     "SecurityDevices": {
       "type": "object",
       "patternProperties": {
         "^.*$": { "type": "string" }
       }
     },
 
     "WebsiteFilter": {
-      "machine_only": "true",
-
       "type": "object",
       "properties": {
         "Block": {
           "type": "array",
           "items": {
             "type": "string"
           }
         },