diff --git a/browser/components/enterprisepolicies/Policies.jsm b/browser/components/enterprisepolicies/Policies.jsm index 210ac088f68e..041400da0114 100644 --- a/browser/components/enterprisepolicies/Policies.jsm +++ b/browser/components/enterprisepolicies/Policies.jsm @@ -181,6 +181,14 @@ var Policies = { } }, + "DisableBuiltinPDFViewer": { + onBeforeUIStartup(manager, param) { + if (param) { + manager.disallowFeature("PDFjs"); + } + } + }, + "DisablePocket": { onBeforeAddons(manager, param) { if (param) { diff --git a/browser/components/enterprisepolicies/schemas/policies-schema.json b/browser/components/enterprisepolicies/schemas/policies-schema.json index c00b2d44bd9f..c20f8a047793 100644 --- a/browser/components/enterprisepolicies/schemas/policies-schema.json +++ b/browser/components/enterprisepolicies/schemas/policies-schema.json @@ -142,6 +142,13 @@ "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", diff --git a/browser/components/enterprisepolicies/tests/browser/browser.ini b/browser/components/enterprisepolicies/tests/browser/browser.ini index 626b693f5cd2..8ef7e76e1570 100644 --- a/browser/components/enterprisepolicies/tests/browser/browser.ini +++ b/browser/components/enterprisepolicies/tests/browser/browser.ini @@ -28,6 +28,7 @@ support-files = [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] diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_pdfjs.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_pdfjs.js new file mode 100644 index 000000000000..bb63775b9572 --- /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"); +}); diff --git a/browser/extensions/pdfjs/content/PdfJs.jsm b/browser/extensions/pdfjs/content/PdfJs.jsm index 1a3ef5a1267b..f3d849ce573e 100644 --- a/browser/extensions/pdfjs/content/PdfJs.jsm +++ b/browser/extensions/pdfjs/content/PdfJs.jsm @@ -337,6 +337,10 @@ var PdfJs = { * @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