Bug 1429169 - Add enterprise policy for disabling the Flash plugin r=Felipe,jaws
☠☠ backed out by deee0d19a090 ☠ ☠
authorKirk Steuber <ksteuber@mozilla.com>
Wed, 21 Mar 2018 11:04:28 -0700
changeset 410721 437f677d38080a3045a29370ed6dd6e136ffc916
parent 410720 2f744fd3d77c9329cb23eee8a795ecd2316ea095
child 410722 a49df97d2ad98b4bfd97e60000b2b2cc1c1663cf
push id33735
push usershindli@mozilla.com
push dateFri, 30 Mar 2018 09:55:46 +0000
treeherdermozilla-central@3f37287132bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe, jaws
bugs1429169
milestone61.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 1429169 - Add enterprise policy for disabling the Flash plugin r=Felipe,jaws MozReview-Commit-ID: AEZZbaYwTLT
browser/components/enterprisepolicies/Policies.jsm
browser/components/enterprisepolicies/schemas/policies-schema.json
browser/components/enterprisepolicies/tests/browser/browser.ini
browser/components/enterprisepolicies/tests/browser/browser_policy_disable_flash_plugin.js
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -386,16 +386,34 @@ var Policies = {
         }
       }
     }
   },
 
   "FlashPlugin": {
     onBeforeUIStartup(manager, param) {
       addAllowDenyPermissions("plugin:flash", param.Allow, param.Block);
+
+      const FLASH_NEVER_ACTIVATE = 0;
+      const FLASH_ASK_TO_ACTIVATE = 1;
+      const FLASH_ALWAYS_ACTIVATE = 2;
+
+      let flashPrefVal;
+      if (param.Default === undefined) {
+        flashPrefVal = FLASH_ASK_TO_ACTIVATE;
+      } else if (param.Default) {
+        flashPrefVal = FLASH_ALWAYS_ACTIVATE;
+      } else {
+        flashPrefVal = FLASH_NEVER_ACTIVATE;
+      }
+      if (param.Locked) {
+        setAndLockPref("plugin.state.flash", flashPrefVal);
+      } else if (param.Default !== undefined) {
+        setDefaultPref("plugin.state.flash", flashPrefVal);
+      }
     }
   },
 
   "Homepage": {
     onBeforeUIStartup(manager, param) {
       // |homepages| will be a string containing a pipe-separated ('|') list of
       // URLs because that is what the "Home page" section of about:preferences
       // (and therefore what the pref |browser.startup.homepage|) accepts.
--- a/browser/components/enterprisepolicies/schemas/policies-schema.json
+++ b/browser/components/enterprisepolicies/schemas/policies-schema.json
@@ -288,16 +288,24 @@
           }
         },
 
         "Block": {
           "type": "array",
           "items": {
             "type": "origin"
           }
+        },
+
+        "Default": {
+          "type": "boolean"
+        },
+
+        "Locked": {
+          "type": "boolean"
         }
       }
     },
 
     "Homepage": {
       "description": "Set and optionally lock the homepage.",
       "first_available": "60.0",
       "enterprise_only": true,
--- a/browser/components/enterprisepolicies/tests/browser/browser.ini
+++ b/browser/components/enterprisepolicies/tests/browser/browser.ini
@@ -23,16 +23,17 @@ support-files =
 [browser_policy_block_about_profiles.js]
 [browser_policy_block_about_support.js]
 [browser_policy_block_set_desktop_background.js]
 [browser_policy_bookmarks.js]
 [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]
 [browser_policy_disable_masterpassword.js]
 [browser_policy_disable_pdfjs.js]
 [browser_policy_disable_pocket.js]
 [browser_policy_disable_privatebrowsing.js]
 [browser_policy_disable_safemode.js]
 [browser_policy_disable_shield.js]
 [browser_policy_disable_telemetry.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_flash_plugin.js
@@ -0,0 +1,134 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+const labelTextAlwaysActivate = "Always Activate";
+const labelTextAskToActivate = "Ask to Activate";
+const labelTextNeverActivate = "Never Activate";
+
+function restore_prefs() {
+  Services.prefs.clearUserPref("plugin.state.flash");
+}
+registerCleanupFunction(restore_prefs);
+
+async function test_flash_status({expectedLabelText, locked}) {
+  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
+  await BrowserOpenAddonsMgr("addons://list/plugin");
+  await ContentTask.spawn(tab.linkedBrowser, {aExpectedLabelText: expectedLabelText, aLocked: locked}, async function({aExpectedLabelText, aLocked}) {
+    let list = content.document.getElementById("addon-list");
+    let flashEntry = list.getElementsByAttribute("name", "Shockwave Flash")[0];
+    let dropDown = content.document.getAnonymousElementByAttribute(flashEntry, "anonid", "state-menulist");
+
+    is(dropDown.label, aExpectedLabelText,
+       "Flash setting text should match the expected value");
+    is(dropDown.disabled, aLocked,
+       "Flash controls disabled state should match policy locked state");
+  });
+  BrowserTestUtils.removeTab(tab);
+
+  is(Services.prefs.prefIsLocked("plugin.state.flash"), locked,
+     "Flash pref lock state should match policy lock state");
+}
+
+add_task(async function test_enabled() {
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "FlashPlugin": {
+        "Default": true
+      }
+    }
+  });
+
+  await test_flash_status({
+    expectedLabelText: labelTextAlwaysActivate,
+    locked: false
+  });
+
+  restore_prefs();
+});
+
+add_task(async function test_enabled_locked() {
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "FlashPlugin": {
+        "Default": true,
+        "Locked": true
+      }
+    }
+  });
+
+  await test_flash_status({
+    expectedLabelText: labelTextAlwaysActivate,
+    locked: true
+  });
+
+  restore_prefs();
+});
+
+add_task(async function test_disabled() {
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "FlashPlugin": {
+        "Default": false
+      }
+    }
+  });
+
+  await test_flash_status({
+    expectedLabelText: labelTextNeverActivate,
+    locked: false
+  });
+
+  restore_prefs();
+});
+
+add_task(async function test_disabled_locked() {
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "FlashPlugin": {
+        "Default": false,
+        "Locked": true
+      }
+    }
+  });
+
+  await test_flash_status({
+    expectedLabelText: labelTextNeverActivate,
+    locked: true
+  });
+
+  restore_prefs();
+});
+
+add_task(async function test_ask() {
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "FlashPlugin": {
+      }
+    }
+  });
+
+  await test_flash_status({
+    expectedLabelText: labelTextAskToActivate,
+    locked: false
+  });
+
+  restore_prefs();
+});
+
+add_task(async function test_ask_locked() {
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "FlashPlugin": {
+        "Locked": true
+      }
+    }
+  });
+
+  await test_flash_status({
+    expectedLabelText: labelTextAskToActivate,
+    locked: true
+  });
+
+  restore_prefs();
+});