Bug 1576455 - Initialize the flash plugin row in Page Info. r=frg
authorIan Neal <iann_cvs@blueyonder.co.uk>
Tue, 01 Oct 2019 16:39:56 +0200
changeset 27806 ba2b990c337c39e1f4e74f732e140983177d4bac
parent 27805 d09c38b4a740dc580c3d6c5b8fb8af399e372d9d
child 27807 80b647910ff0037cf2b7022a705491b4dbdbf2e7
push id16496
push userfrgrahl@gmx.net
push dateTue, 01 Oct 2019 14:52:03 +0000
treeherdercomm-central@0e49bcfec167 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrg
bugs1576455
Bug 1576455 - Initialize the flash plugin row in Page Info. r=frg
suite/browser/pageinfo/permissions.js
suite/locales/en-US/chrome/common/sitePermissions.properties
suite/modules/SitePermissions.jsm
--- a/suite/browser/pageinfo/permissions.js
+++ b/suite/browser/pageinfo/permissions.js
@@ -72,16 +72,23 @@ function initRow(aPartId)
     command.setAttribute("disabled", "true");
     document.getElementById(aPartId + "RadioGroup").selectedItem = null;
     return;
   }
   checkbox.removeAttribute("disabled");
   var {state} = SitePermissions.get(gPermURI, aPartId);
   let defaultState = SitePermissions.getDefault(aPartId);
 
+  // When flash permission state is "Hide", we show it as "Always Ask"
+  // in page info.
+  if (aPartId.startsWith("plugin") && state == SitePermissions.PROMPT_HIDE) {
+    defaultState == SitePermissions.UNKNOWN ? state = defaultState :
+                                              state = SitePermissions.PROMPT;
+  }
+
   if (state != defaultState) {
     checkbox.checked = false;
     command.removeAttribute("disabled");
   }
   else {
     checkbox.checked = true;
     command.setAttribute("disabled", "true");
   }
--- a/suite/locales/en-US/chrome/common/sitePermissions.properties
+++ b/suite/locales/en-US/chrome/common/sitePermissions.properties
@@ -1,25 +1,27 @@
 # 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/.
 
 # LOCALIZATION NOTE (state.current.allowed,
 #                    state.current.allowedForSession,
 #                    state.current.allowedTemporarily,
 #                    state.current.blockedTemporarily,
-#                    state.current.blocked):
+#                    state.current.blocked,
+#                    state.current.hide):
 # This label is used to display active permission states in the site
 # identity popup (which does not have a lot of screen space).
 state.current.allowed = Allowed
 state.current.allowedForSession = Allowed for Session
 state.current.allowedTemporarily = Allowed Temporarily
 state.current.blockedTemporarily = Blocked Temporarily
 state.current.blocked = Blocked
 state.current.prompt = Always Ask
+state.current.hide = Hide Prompt
 
 # LOCALIZATION NOTE (state.multichoice.alwaysAsk,
 #                    state.multichoice.allow,
 #                    state.multichoice.allowForSameDomain,
 #                    state.multichoice.allowForSession,
 #                    state.multichoice.block):
 # Used to label permission state checkboxes in the page info dialog.
 state.multichoice.alwaysAsk = Always Ask
@@ -35,8 +37,9 @@ permission.camera.label = Use the Camera
 permission.microphone.label = Use the Microphone
 permission.screen.label = Share the Screen
 permission.install.label = Install Add-ons
 permission.popup.label = Open Pop-up Windows
 permission.geo.label = Access Your Location
 permission.indexedDB.label = Maintain Offline Storage
 permission.focus-tab-by-prompt.label = Switch to this Tab
 permission.persistent-storage.label = Store Data in Persistent Storage
+permission.flash-plugin.label = Run Adobe Flash
--- a/suite/modules/SitePermissions.jsm
+++ b/suite/modules/SitePermissions.jsm
@@ -133,21 +133,24 @@ var TemporaryBlockedPermissions = {
  * A module to manage permanent and temporary permissions
  * by URI and browser.
  *
  * Some methods have the side effect of dispatching a "PermissionStateChange"
  * event on changes to temporary permissions, as mentioned in the respective docs.
  */
 var SitePermissions = {
   // Permission states.
+  // PROMPT_HIDE state is only used to show the "Hide Prompt" state in the
+  // identity panel for the "plugin:flash" permission and not in pageinfo.
   UNKNOWN: Services.perms.UNKNOWN_ACTION,
   ALLOW: Services.perms.ALLOW_ACTION,
   BLOCK: Services.perms.DENY_ACTION,
   PROMPT: Services.perms.PROMPT_ACTION,
   ALLOW_COOKIES_FOR_SESSION: Ci.nsICookiePermission.ACCESS_SESSION,
+  PROMPT_HIDE: Ci.nsIObjectLoadingContent.PLUGIN_PERMISSION_PROMPT_ACTION_QUIET,
 
   // Permission scopes.
   SCOPE_REQUEST: "{SitePermissions.SCOPE_REQUEST}",
   SCOPE_TEMPORARY: "{SitePermissions.SCOPE_TEMPORARY}",
   SCOPE_SESSION: "{SitePermissions.SCOPE_SESSION}",
   SCOPE_PERSISTENT: "{SitePermissions.SCOPE_PERSISTENT}",
 
   _defaultPrefBranch: Services.prefs.getBranch("permissions.default."),
@@ -538,23 +541,31 @@ var SitePermissions = {
     }
   },
 
   /**
    * Returns the localized label for a permission's current state.
    *
    * @param {SitePermissions state} state
    *        The state to get the label for.
+   * @param {string} id
+   *        The permission to get the state label for.
    * @param {SitePermissions scope} scope (optional)
    *        The scope to get the label for.
    *
    * @return {String|null} the localized label or null if an
    *         unknown state was passed.
    */
-  getCurrentStateLabel(state, scope = null) {
+  getCurrentStateLabel(state, id, scope = null) {
+    // We try to avoid a collision between SitePermissions.PROMPT_HIDE and
+    // SitePermissions.ALLOW_COOKIES_FOR_SESSION which share the same const
+    // value.
+    if (id.startsWith("plugin") && state == SitePermissions.PROMPT_HIDE) {
+      return gStringBundle.GetStringFromName("state.current.hide");
+    }
     switch (state) {
       case this.PROMPT:
         return gStringBundle.GetStringFromName("state.current.prompt");
       case this.ALLOW:
         if (scope && scope != this.SCOPE_PERSISTENT)
           return gStringBundle.GetStringFromName("state.current.allowedTemporarily");
         return gStringBundle.GetStringFromName("state.current.allowed");
       case this.ALLOW_COOKIES_FOR_SESSION:
@@ -585,16 +596,19 @@ var gPermissionObject = {
    *
    *  - labelID
    *    Use the given ID instead of the permission name for looking up strings.
    *    e.g. "desktop-notification2" to use permission.desktop-notification2.label
    *
    *  - states
    *    Array of permission states to be exposed to the user.
    *    Defaults to ALLOW, BLOCK and the default state (see getDefault).
+   *    The PROMPT_HIDE state is deliberately excluded from "plugin:flash"
+   *    since we don't want to expose a "Hide Prompt" button to the user
+   *    through pageinfo.
    *
    *  - getMultichoiceStateLabel
    *    Allows for custom logic for getting its default value
    */
 
   "image": {
     states: [
       SitePermissions.ALLOW,
@@ -665,18 +679,24 @@ var gPermissionObject = {
   "geo": {
     exactHostMatch: true
   },
 
   "focus-tab-by-prompt": {
     exactHostMatch: true,
     states: [ SitePermissions.UNKNOWN, SitePermissions.ALLOW ],
   },
+
   "persistent-storage": {
     exactHostMatch: true
+  },
+
+  "plugin:flash": {
+    labelID: "flash-plugin",
+    states: [ SitePermissions.UNKNOWN, SitePermissions.ALLOW, SitePermissions.BLOCK ],
   }
 };
 
 // Delete this entry while being pre-off
 // or the persistent-storage permission would appear in Page info's Permission section
 if (!Services.prefs.getBoolPref("browser.storageManager.enabled")) {
   delete gPermissionObject["persistent-storage"];
 }