Bug 1482809 - Move non-browser-specific parts of browser/components/enterprisepolicies to toolkit r=mkaply,Felipe
authorGeoff Lankow <geoff@thunderbird.net>
Tue, 30 Apr 2019 16:01:06 +0000
changeset 530797 0f5b654fe33f69c20f3c4fe3d18a5511813a79b7
parent 530796 40dcf4f4a5159f4372107d32219e7351a5ebe908
child 530798 11b4d70a2b5d6373f5ec8fa01ca48a1c7bc1829e
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkaply, Felipe
bugs1482809
milestone68.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 1482809 - Move non-browser-specific parts of browser/components/enterprisepolicies to toolkit r=mkaply,Felipe Differential Revision: https://phabricator.services.mozilla.com/D28309
browser/components/enterprisepolicies/EnterprisePolicies.js
browser/components/enterprisepolicies/EnterprisePolicies.manifest
browser/components/enterprisepolicies/EnterprisePoliciesContent.js
browser/components/enterprisepolicies/WindowsGPOParser.jsm
browser/components/enterprisepolicies/macOSPoliciesParser.jsm
browser/components/enterprisepolicies/moz.build
browser/components/enterprisepolicies/tests/EnterprisePolicyTesting.jsm
browser/components/enterprisepolicies/tests/browser/browser.ini
browser/components/enterprisepolicies/tests/browser/browser_policies_basic_tests.js
browser/components/enterprisepolicies/tests/browser/browser_policies_broken_json.js
browser/components/enterprisepolicies/tests/browser/browser_policies_enterprise_only.js
browser/components/enterprisepolicies/tests/browser/browser_policies_macosparser_unflatten.js
browser/components/enterprisepolicies/tests/browser/browser_policies_mistyped_json.js
browser/components/enterprisepolicies/tests/browser/config_broken_json.json
browser/components/enterprisepolicies/tests/moz.build
browser/installer/package-manifest.in
netwerk/protocol/about/nsAboutProtocolHandler.cpp
toolkit/components/enterprisepolicies/EnterprisePolicies.js
toolkit/components/enterprisepolicies/EnterprisePolicies.manifest
toolkit/components/enterprisepolicies/EnterprisePoliciesContent.js
toolkit/components/enterprisepolicies/WindowsGPOParser.jsm
toolkit/components/enterprisepolicies/macOSPoliciesParser.jsm
toolkit/components/enterprisepolicies/moz.build
toolkit/components/enterprisepolicies/tests/EnterprisePolicyTesting.jsm
toolkit/components/enterprisepolicies/tests/browser/browser.ini
toolkit/components/enterprisepolicies/tests/browser/browser_policies_basic_tests.js
toolkit/components/enterprisepolicies/tests/browser/browser_policies_broken_json.js
toolkit/components/enterprisepolicies/tests/browser/browser_policies_enterprise_only.js
toolkit/components/enterprisepolicies/tests/browser/browser_policies_mistyped_json.js
toolkit/components/enterprisepolicies/tests/browser/config_broken_json.json
toolkit/components/enterprisepolicies/tests/browser/head.js
toolkit/components/enterprisepolicies/tests/moz.build
toolkit/modules/Services.jsm
toolkit/modules/tests/xpcshell/test_Services.js
toolkit/xre/nsXREDirProvider.cpp
--- a/browser/components/enterprisepolicies/moz.build
+++ b/browser/components/enterprisepolicies/moz.build
@@ -11,31 +11,15 @@ DIRS += [
     'helpers',
     'schemas',
 ]
 
 TEST_DIRS += [
 	'tests'
 ]
 
-EXTRA_COMPONENTS += [
-    'EnterprisePolicies.js',
-    'EnterprisePolicies.manifest',
-    'EnterprisePoliciesContent.js',
-]
-
 EXTRA_JS_MODULES.policies += [
     'Policies.jsm',
 ]
 
-if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
-    EXTRA_JS_MODULES.policies += [
-        'WindowsGPOParser.jsm',
-]
-
-if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
-    EXTRA_JS_MODULES.policies += [
-        'macOSPoliciesParser.jsm',
-]
-
 FINAL_LIBRARY = 'browsercomps'
 
 JAR_MANIFESTS += ['jar.mn']
--- a/browser/components/enterprisepolicies/tests/browser/browser.ini
+++ b/browser/components/enterprisepolicies/tests/browser/browser.ini
@@ -1,29 +1,24 @@
 [DEFAULT]
 support-files =
   head.js
   config_popups_cookies_addons_flash.json
-  config_broken_json.json
   opensearch.html
   opensearchEngine.xml
   policytest_v0.1.xpi
   policytest_v0.2.xpi
   policy_websitefilter_block.html
   policy_websitefilter_exception.html
   ../../../../../toolkit/components/antitracking/test/browser/page.html
   ../../../../../toolkit/components/antitracking/test/browser/subResources.sjs
 
-[browser_policies_basic_tests.js]
-[browser_policies_broken_json.js]
-[browser_policies_enterprise_only.js]
 [browser_policies_getActivePolicies.js]
 [browser_policies_macosparser_unflatten.js]
 skip-if = os != 'mac'
-[browser_policies_mistyped_json.js]
 [browser_policies_notice_in_aboutpreferences.js]
 [browser_policies_popups_cookies_addons_flash.js]
 [browser_policies_runOnce_helper.js]
 [browser_policies_setAndLockPref_API.js]
 [browser_policies_simple_pref_policies.js]
 [browser_policies_sorted_alphabetically.js]
 [browser_policy_3rdparty.js]
 [browser_policy_app_update.js]
--- a/browser/components/enterprisepolicies/tests/browser/browser_policies_macosparser_unflatten.js
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policies_macosparser_unflatten.js
@@ -1,14 +1,14 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
-let { macOSPoliciesParser } = ChromeUtils.import("resource:///modules/policies/macOSPoliciesParser.jsm");
+let { macOSPoliciesParser } = ChromeUtils.import("resource://gre/modules/policies/macOSPoliciesParser.jsm");
 
 add_task(async function test_object_unflatten() {
   // Note: these policies are just examples and they won't actually
   // run through the policy engine on this test. We're just testing
   // that the unflattening algorithm produces the correct output.
   let input = {
     "DisplayBookmarksToolbar": true,
 
--- a/browser/components/enterprisepolicies/tests/moz.build
+++ b/browser/components/enterprisepolicies/tests/moz.build
@@ -8,12 +8,8 @@ BROWSER_CHROME_MANIFESTS += [
     'browser/browser.ini',
     'browser/disable_app_update/browser.ini',
     'browser/disable_default_bookmarks/browser.ini',
     'browser/disable_developer_tools/browser.ini',
     'browser/disable_forget_button/browser.ini',
     'browser/disable_fxscreenshots/browser.ini',
     'browser/hardware_acceleration/browser.ini',
 ]
-
-TESTING_JS_MODULES += [
-    'EnterprisePolicyTesting.jsm',
-]
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -160,19 +160,19 @@
 @BINPATH@/AccessibleHandler.dll
 @BINPATH@/AccessibleMarshal.dll
 @BINPATH@/IA2Marshal.dll
 #endif
 #endif
 
 ; JavaScript components
 @RESPATH@/browser/components/BrowserComponents.manifest
-@RESPATH@/browser/components/EnterprisePolicies.js
-@RESPATH@/browser/components/EnterprisePoliciesContent.js
-@RESPATH@/browser/components/EnterprisePolicies.manifest
+@RESPATH@/components/EnterprisePolicies.js
+@RESPATH@/components/EnterprisePoliciesContent.js
+@RESPATH@/components/EnterprisePolicies.manifest
 @RESPATH@/components/toolkitsearch.manifest
 @RESPATH@/components/extensions.manifest
 #ifdef MOZ_UPDATER
 @RESPATH@/components/nsUpdateService.manifest
 #endif
 @RESPATH@/components/ProcessSingleton.manifest
 @RESPATH@/components/HandlerService.manifest
 @RESPATH@/components/HandlerService.js
--- a/netwerk/protocol/about/nsAboutProtocolHandler.cpp
+++ b/netwerk/protocol/about/nsAboutProtocolHandler.cpp
@@ -178,17 +178,17 @@ nsAboutProtocolHandler::NewChannel(nsIUR
       // that it doesn't exist.
       rv = NS_ERROR_FACTORY_NOT_REGISTERED;
     } else if (!path.EqualsLiteral("blank") &&
                !path.EqualsLiteral("neterror") && !path.EqualsLiteral("home") &&
                !path.EqualsLiteral("welcome") &&
                !path.EqualsLiteral("newtab") &&
                !path.EqualsLiteral("certerror")) {
       nsCOMPtr<nsIEnterprisePolicies> policyManager =
-          do_GetService("@mozilla.org/browser/enterprisepolicies;1", &rv2);
+          do_GetService("@mozilla.org/enterprisepolicies;1", &rv2);
       if (NS_SUCCEEDED(rv2)) {
         nsAutoCString normalizedURL;
         normalizedURL.AssignLiteral("about:");
         normalizedURL.Append(path);
         rv2 = policyManager->IsAllowed(normalizedURL, &aboutPageAllowed);
         if (NS_FAILED(rv2)) {
           aboutPageAllowed = false;
         }
rename from browser/components/enterprisepolicies/EnterprisePolicies.js
rename to toolkit/components/enterprisepolicies/EnterprisePolicies.js
--- a/browser/components/enterprisepolicies/EnterprisePolicies.js
+++ b/toolkit/components/enterprisepolicies/EnterprisePolicies.js
@@ -2,18 +2,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 
 XPCOMUtils.defineLazyModuleGetters(this, {
-  WindowsGPOParser: "resource:///modules/policies/WindowsGPOParser.jsm",
-  macOSPoliciesParser: "resource:///modules/policies/macOSPoliciesParser.jsm",
+  WindowsGPOParser: "resource://gre/modules/policies/WindowsGPOParser.jsm",
+  macOSPoliciesParser: "resource://gre/modules/policies/macOSPoliciesParser.jsm",
   Policies: "resource:///modules/policies/Policies.jsm",
   JsonSchemaValidator: "resource://gre/modules/components-utils/JsonSchemaValidator.jsm",
 });
 
 // This is the file that will be searched for in the
 // ${InstallDir}/distribution folder.
 const POLICIES_FILENAME = "policies.json";
 
@@ -463,17 +463,17 @@ class WindowsGPOPoliciesProvider {
   }
 
   get failed() {
     return this._failed;
   }
 
   _readData(wrk, root) {
     wrk.open(root, "SOFTWARE\\Policies", wrk.ACCESS_READ);
-    if (wrk.hasChild("Mozilla\\Firefox")) {
+    if (wrk.hasChild("Mozilla\\" + Services.appinfo.name)) {
       this._policies = WindowsGPOParser.readPolicies(wrk, this._policies);
     }
     wrk.close();
   }
 }
 
 class macOSPoliciesProvider {
   constructor() {
rename from browser/components/enterprisepolicies/EnterprisePolicies.manifest
rename to toolkit/components/enterprisepolicies/EnterprisePolicies.manifest
--- a/browser/components/enterprisepolicies/EnterprisePolicies.manifest
+++ b/toolkit/components/enterprisepolicies/EnterprisePolicies.manifest
@@ -1,5 +1,5 @@
 component {ea4e1414-779b-458b-9d1f-d18e8efbc145} EnterprisePolicies.js process=main
-contract @mozilla.org/browser/enterprisepolicies;1 {ea4e1414-779b-458b-9d1f-d18e8efbc145} process=main
+contract @mozilla.org/enterprisepolicies;1 {ea4e1414-779b-458b-9d1f-d18e8efbc145} process=main
 
 component {dc6358f8-d167-4566-bf5b-4350b5e6a7a2} EnterprisePoliciesContent.js process=content
-contract @mozilla.org/browser/enterprisepolicies;1 {dc6358f8-d167-4566-bf5b-4350b5e6a7a2} process=content
+contract @mozilla.org/enterprisepolicies;1 {dc6358f8-d167-4566-bf5b-4350b5e6a7a2} process=content
rename from browser/components/enterprisepolicies/EnterprisePoliciesContent.js
rename to toolkit/components/enterprisepolicies/EnterprisePoliciesContent.js
rename from browser/components/enterprisepolicies/WindowsGPOParser.jsm
rename to toolkit/components/enterprisepolicies/WindowsGPOParser.jsm
--- a/browser/components/enterprisepolicies/WindowsGPOParser.jsm
+++ b/toolkit/components/enterprisepolicies/WindowsGPOParser.jsm
@@ -1,14 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
+const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 const PREF_LOGLEVEL = "browser.policies.loglevel";
 
 XPCOMUtils.defineLazyGetter(this, "log", () => {
   let { ConsoleAPI } = ChromeUtils.import("resource://gre/modules/Console.jsm");
   return new ConsoleAPI({
     prefix: "GPOParser.jsm",
@@ -18,17 +19,17 @@ XPCOMUtils.defineLazyGetter(this, "log",
     maxLogLevelPref: PREF_LOGLEVEL,
   });
 });
 
 var EXPORTED_SYMBOLS = ["WindowsGPOParser"];
 
 var WindowsGPOParser = {
   readPolicies(wrk, policies) {
-    let childWrk = wrk.openChild("Mozilla\\Firefox", wrk.ACCESS_READ);
+    let childWrk = wrk.openChild("Mozilla\\" + Services.appinfo.name, wrk.ACCESS_READ);
     if (!policies) {
       policies = {};
     }
     try {
       policies = registryToObject(childWrk, policies);
     } catch (e) {
       log.error(e);
     } finally {
rename from browser/components/enterprisepolicies/macOSPoliciesParser.jsm
rename to toolkit/components/enterprisepolicies/macOSPoliciesParser.jsm
--- a/toolkit/components/enterprisepolicies/moz.build
+++ b/toolkit/components/enterprisepolicies/moz.build
@@ -7,8 +7,29 @@
 with Files("**"):
     BUG_COMPONENT = ("Firefox", "Enterprise Policies")
 
 XPIDL_SOURCES += [
     'nsIEnterprisePolicies.idl',
 ]
 
 XPIDL_MODULE = 'enterprisepolicies'
+
+TEST_DIRS += [
+    'tests'
+]
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] != "android":
+    EXTRA_COMPONENTS += [
+        'EnterprisePolicies.js',
+        'EnterprisePolicies.manifest',
+        'EnterprisePoliciesContent.js',
+    ]
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
+    EXTRA_JS_MODULES.policies += [
+        'WindowsGPOParser.jsm',
+]
+
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
+    EXTRA_JS_MODULES.policies += [
+        'macOSPoliciesParser.jsm',
+]
rename from browser/components/enterprisepolicies/tests/EnterprisePolicyTesting.jsm
rename to toolkit/components/enterprisepolicies/tests/EnterprisePolicyTesting.jsm
new file mode 100644
--- /dev/null
+++ b/toolkit/components/enterprisepolicies/tests/browser/browser.ini
@@ -0,0 +1,9 @@
+[DEFAULT]
+head = head.js
+support-files =
+  config_broken_json.json
+
+[browser_policies_basic_tests.js]
+[browser_policies_broken_json.js]
+[browser_policies_enterprise_only.js]
+[browser_policies_mistyped_json.js]
rename from browser/components/enterprisepolicies/tests/browser/browser_policies_basic_tests.js
rename to toolkit/components/enterprisepolicies/tests/browser/browser_policies_basic_tests.js
rename from browser/components/enterprisepolicies/tests/browser/browser_policies_broken_json.js
rename to toolkit/components/enterprisepolicies/tests/browser/browser_policies_broken_json.js
rename from browser/components/enterprisepolicies/tests/browser/browser_policies_enterprise_only.js
rename to toolkit/components/enterprisepolicies/tests/browser/browser_policies_enterprise_only.js
rename from browser/components/enterprisepolicies/tests/browser/browser_policies_mistyped_json.js
rename to toolkit/components/enterprisepolicies/tests/browser/browser_policies_mistyped_json.js
rename from browser/components/enterprisepolicies/tests/browser/config_broken_json.json
rename to toolkit/components/enterprisepolicies/tests/browser/config_broken_json.json
new file mode 100644
--- /dev/null
+++ b/toolkit/components/enterprisepolicies/tests/browser/head.js
@@ -0,0 +1,22 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {
+  EnterprisePolicyTesting,
+  PoliciesPrefTracker,
+} = ChromeUtils.import("resource://testing-common/EnterprisePolicyTesting.jsm", null);
+const {TestUtils} = ChromeUtils.import("resource://testing-common/TestUtils.jsm", null);
+
+PoliciesPrefTracker.start();
+
+async function setupPolicyEngineWithJson(json, customSchema) {
+  PoliciesPrefTracker.restoreDefaultValues();
+  if (typeof(json) != "object") {
+    let filePath = getTestFilePath(json ? json : "non-existing-file.json");
+    return EnterprisePolicyTesting.setupPolicyEngineWithJson(filePath, customSchema);
+  }
+  return EnterprisePolicyTesting.setupPolicyEngineWithJson(json, customSchema);
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/components/enterprisepolicies/tests/moz.build
@@ -0,0 +1,13 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+BROWSER_CHROME_MANIFESTS += [
+    'browser/browser.ini',
+]
+
+TESTING_JS_MODULES += [
+    'EnterprisePolicyTesting.jsm',
+]
--- a/toolkit/modules/Services.jsm
+++ b/toolkit/modules/Services.jsm
@@ -108,15 +108,15 @@ var initTable = {
 };
 
 if (AppConstants.platform == "android") {
   initTable.androidBridge = ["@mozilla.org/android/bridge;1", "nsIAndroidBridge"];
 }
 if (AppConstants.MOZ_GECKO_PROFILER) {
   initTable.profiler = ["@mozilla.org/tools/profiler;1", "nsIProfiler"];
 }
-if ("@mozilla.org/browser/enterprisepolicies;1" in Cc) {
-  initTable.policies = ["@mozilla.org/browser/enterprisepolicies;1", "nsIEnterprisePolicies"];
+if ("@mozilla.org/enterprisepolicies;1" in Cc) {
+  initTable.policies = ["@mozilla.org/enterprisepolicies;1", "nsIEnterprisePolicies"];
 }
 
 XPCOMUtils.defineLazyServiceGetters(Services, initTable);
 
 initTable = undefined;
--- a/toolkit/modules/tests/xpcshell/test_Services.js
+++ b/toolkit/modules/tests/xpcshell/test_Services.js
@@ -54,17 +54,17 @@ function run_test() {
   checkService("wm", Ci.nsIWindowMediator);
   checkService("ww", Ci.nsIWindowWatcher);
   if ("nsISearchService" in Ci) {
     checkService("search", Ci.nsISearchService);
   }
   if ("nsIAndroidBridge" in Ci) {
     checkService("androidBridge", Ci.nsIAndroidBridge);
   }
-  if ("@mozilla.org/browser/enterprisepolicies;1" in Cc) {
+  if ("@mozilla.org/enterprisepolicies;1" in Cc) {
     checkService("policies", Ci.nsIEnterprisePolicies);
   }
 
 
   // In xpcshell tests, the "@mozilla.org/xre/app-info;1" component implements
   // only the nsIXULRuntime interface, but not nsIXULAppInfo.  To test the
   // service getter for the latter interface, load mock app-info.
   let tmp = {};
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -981,17 +981,17 @@ nsXREDirProvider::DoStartup() {
     static const char16_t kStartup[] = {'s', 't', 'a', 'r',
                                         't', 'u', 'p', '\0'};
     obsSvc->NotifyObservers(nullptr, "profile-do-change", kStartup);
 
     // Initialize the Enterprise Policies service in the parent process
     // In the content process it's loaded on demand when needed
     if (XRE_IsParentProcess()) {
       nsCOMPtr<nsIObserver> policies(
-          do_GetService("@mozilla.org/browser/enterprisepolicies;1"));
+          do_GetService("@mozilla.org/enterprisepolicies;1"));
       if (policies) {
         policies->Observe(nullptr, "policies-startup", nullptr);
       }
     }
 
 #if defined(MOZ_SANDBOX) && defined(XP_WIN)
     // Call SandboxBroker to initialize things that depend on Gecko machinery
     // like the directory provider. We insert this initialization code here