Bug 1429160 - Create enterprise policy to disable PDFjs
MozReview-Commit-ID: 4Ir407Qjdoq
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -176,16 +176,24 @@ var Policies = {
"DisableFormHistory": {
onBeforeUIStartup(manager, param) {
if (param) {
setAndLockPref("browser.formfill.enable", false);
}
}
},
+ "DisableBuiltinPDFViewer": {
+ onBeforeUIStartup(manager, param) {
+ if (param) {
+ manager.disallowFeature("PDFjs");
+ }
+ }
+ },
+
"DisablePocket": {
onBeforeAddons(manager, param) {
if (param) {
setAndLockPref("extensions.pocket.enabled", false);
}
}
},
--- a/browser/components/enterprisepolicies/schemas/policies-schema.json
+++ b/browser/components/enterprisepolicies/schemas/policies-schema.json
@@ -137,16 +137,23 @@
"DisableFormHistory": {
"description": "Don't remember search and form history.",
"first_available": "60.0",
"type": "boolean"
},
+ "DisableBuiltinPDFViewer": {
+ "description": "Disables PDF.js, which displays PDFs within Firefox.",
+ "first_available": "60.0",
+
+ "type": "boolean"
+ },
+
"DisablePocket": {
"description": "Prevents ability to save webpages to Pocket.",
"first_available": "60.0",
"type": "boolean"
},
"DisablePrivateBrowsing": {
--- a/browser/components/enterprisepolicies/tests/browser/browser.ini
+++ b/browser/components/enterprisepolicies/tests/browser/browser.ini
@@ -23,15 +23,16 @@ support-files =
[browser_policy_block_set_desktop_background.js]
[browser_policy_bookmarks.js]
[browser_policy_clear_blocked_cookies.js]
[browser_policy_default_browser_check.js]
[browser_policy_disable_formhistory.js]
[browser_policy_disable_fxaccounts.js]
[browser_policy_disable_fxscreenshots.js]
[browser_policy_disable_masterpassword.js]
+[browser_policy_disable_pdfjs.js]
[browser_policy_disable_pocket.js]
[browser_policy_disable_privatebrowsing.js]
[browser_policy_disable_shield.js]
[browser_policy_display_bookmarks.js]
[browser_policy_display_menu.js]
[browser_policy_remember_passwords.js]
[browser_policy_set_homepage.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_pdfjs.js
@@ -0,0 +1,17 @@
+/* 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/extensions/pdfjs/content/PdfJs.jsm
+++ b/browser/extensions/pdfjs/content/PdfJs.jsm
@@ -332,16 +332,20 @@ 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 && !Services.policies.isAllowed("PDFjs")) {
+ 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();
}