Bug 1496855 - Switch PDF policy to use pdfjs.disabled. r=Felipe, a=pascalc
authorMichael Kaply <mozilla@kaply.com>
Wed, 10 Oct 2018 21:57:34 +0000
changeset 490271 818b81b2177e
parent 490270 dc0694bc87c1
child 490272 39d6cdbcbf64
push id9970
push userryanvm@gmail.com
push date2018-10-11 18:08 +0000
treeherdermozilla-beta@491779804da9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe, pascalc
bugs1496855
milestone63.0
Bug 1496855 - Switch PDF policy to use pdfjs.disabled. r=Felipe, a=pascalc pdfjs.disabled now works from policy, so use it Differential Revision: https://phabricator.services.mozilla.com/D8237
browser/components/enterprisepolicies/Policies.jsm
browser/components/enterprisepolicies/tests/browser/browser.ini
browser/components/enterprisepolicies/tests/browser/browser_policies_simple_pref_policies.js
browser/components/enterprisepolicies/tests/browser/browser_policy_disable_pdfjs.js
browser/components/preferences/in-content/main.js
browser/extensions/pdfjs/content/PdfJs.jsm
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -222,19 +222,19 @@ var Policies = {
     onBeforeAddons(manager, param) {
       if (param) {
         manager.disallowFeature("appUpdate");
       }
     },
   },
 
   "DisableBuiltinPDFViewer": {
-    onBeforeUIStartup(manager, param) {
+    onBeforeAddons(manager, param) {
       if (param) {
-        manager.disallowFeature("PDF.js");
+        setAndLockPref("pdfjs.disabled", true);
       }
     },
   },
 
   "DisableDeveloperTools": {
     onBeforeAddons(manager, param) {
       if (param) {
         setAndLockPref("devtools.policy.disabled", true);
--- a/browser/components/enterprisepolicies/tests/browser/browser.ini
+++ b/browser/components/enterprisepolicies/tests/browser/browser.ini
@@ -32,17 +32,16 @@ support-files =
 [browser_policy_clear_blocked_cookies.js]
 [browser_policy_cookie_settings.js]
 [browser_policy_default_browser_check.js]
 [browser_policy_disable_feedback_commands.js]
 [browser_policy_disable_flash_plugin.js]
 [browser_policy_disable_fxaccounts.js]
 skip-if = (verify && debug && (os == 'mac'))
 [browser_policy_disable_masterpassword.js]
-[browser_policy_disable_pdfjs.js]
 [browser_policy_disable_pocket.js]
 [browser_policy_disable_popup_blocker.js]
 [browser_policy_disable_privatebrowsing.js]
 [browser_policy_disable_profile_reset.js]
 [browser_policy_disable_profile_import.js]
 [browser_policy_disable_safemode.js]
 [browser_policy_disable_shield.js]
 [browser_policy_disable_telemetry.js]
--- a/browser/components/enterprisepolicies/tests/browser/browser_policies_simple_pref_policies.js
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policies_simple_pref_policies.js
@@ -48,16 +48,21 @@ const POLICIES_TESTS = [
       },
     },
     lockedPrefs: {
       "security.certerror.hideAddException": true,
       "browser.safebrowsing.allowOverride": false,
     },
   },
 
+  // POLICY: DisableBuiltinPDFViewer
+  {
+    policies: { "DisableBuiltinPDFViewer": true },
+    lockedPrefs: { "pdfjs.disabled": true },
+  },
 
   // POLICY: DisableFormHistory
   {
     policies: { "DisableFormHistory": true },
     lockedPrefs: { "browser.formfill.enable": false },
   },
 
   // POLICY: EnableTrackingProtection
deleted file mode 100644
--- a/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_pdfjs.js
+++ /dev/null
@@ -1,17 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
-"use strict";
-
-const {PdfJs} = ChromeUtils.import("resource://pdf.js/PdfJs.jsm", {});
-
-add_task(async function test_disable_pdfjs() {
-  is(PdfJs.enabled, true, "PDFjs should be enabled before policy runs");
-
-  await setupPolicyEngineWithJson({
-    "policies": {
-      "DisableBuiltinPDFViewer": true,
-    },
-  });
-
-  is(PdfJs.enabled, false, "PDFjs should be disabled after policy runs");
-});
--- a/browser/components/preferences/in-content/main.js
+++ b/browser/components/preferences/in-content/main.js
@@ -3244,12 +3244,11 @@ class PDFHandlerInfoWrapper extends Inte
     return TOPIC_PDFJS_HANDLER_CHANGED;
   }
 
   get _appPrefLabel() {
     return "portableDocumentFormat";
   }
 
   get enabled() {
-    return !Services.prefs.getBoolPref(PREF_PDFJS_DISABLED) &&
-           Services.policies.isAllowed("PDF.js");
+    return !Services.prefs.getBoolPref(PREF_PDFJS_DISABLED);
   }
 }
--- a/browser/extensions/pdfjs/content/PdfJs.jsm
+++ b/browser/extensions/pdfjs/content/PdfJs.jsm
@@ -257,20 +257,16 @@ var PdfJs = {
   },
 
   /**
    * pdf.js is only enabled if it is both selected as the pdf viewer and if the
    * global switch enabling it is true.
    * @return {boolean} Whether or not it's enabled.
    */
   get enabled() {
-    if (!Services.policies.isAllowed("PDF.js")) {
-      return false;
-    }
-
     if (!Services.prefs.getBoolPref(PREF_ENABLED_CACHE_INITIALIZED, false)) {
       // If we just updated, and the cache hasn't been initialized, then we
       // can't assume a default state, and need to synchronously initialize
       // PdfJs
       if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_POSTUPDATE)) {
         this.checkEnabled();
       }