Bug 736278 - Add always/never permissions for click-to-play plugins. r=mfinkle
☠☠ backed out by 591720c6e345 ☠ ☠
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Tue, 27 Mar 2012 14:36:25 -0700
changeset 93769 3a4ed2b028ad63845bb6324a6556d8864616c356
parent 93768 6e5e460230945d1f113c1a9360c02b243dbf0c65
child 93770 97157235087fbed4b2110cc04be83b479058ae55
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs736278
milestone14.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 736278 - Add always/never permissions for click-to-play plugins. r=mfinkle
mobile/android/chrome/content/browser.js
mobile/android/locales/en-US/chrome/browser.properties
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -3920,33 +3920,63 @@ var ClipboardHelper = {
       }
       return false;
     }
   }
 };
 
 var PluginHelper = {
   showDoorHanger: function(aTab) {
+    if (!aTab.browser)
+      return;
+
+    // Even though we may not end up showing a doorhanger, this flag
+    // lets us know that we've tried to show a doorhanger.
     aTab.clickToPlayPluginDoorhangerShown = true;
-    let message = Strings.browser.GetStringFromName("clickToPlayPlugins.message");
+
+    let uri = aTab.browser.currentURI;
+
+    // If the user has previously set a plugins permission for this website,
+    // either play or don't play the plugins instead of showing a doorhanger.
+    let permValue = Services.perms.testPermission(uri, "plugins");
+    if (permValue != Services.perms.UNKNOWN_ACTION) {
+      if (permValue == Services.perms.ALLOW_ACTION)
+        PluginHelper.playAllPlugins(aTab.browser.contentWindow);
+
+      return;
+    }
+
+    let message = Strings.browser.formatStringFromName("clickToPlayPlugins.message1",
+                                                       [uri.host], 1);
     let buttons = [
       {
         label: Strings.browser.GetStringFromName("clickToPlayPlugins.yes"),
-        callback: function() {
+        callback: function(aChecked) {
+          // If the user checked "Don't ask again", make a permanent exception
+          if (aChecked)
+            Services.perms.add(uri, "plugins", Ci.nsIPermissionManager.ALLOW_ACTION);
+
           PluginHelper.playAllPlugins(aTab.browser.contentWindow);
         }
       },
       {
         label: Strings.browser.GetStringFromName("clickToPlayPlugins.no"),
-        callback: function() {
-          // Do nothing
-        }
+        callback: function(aChecked) {
+          // If the user checked "Don't ask again", make a permanent exception
+          if (aChecked)
+            Services.perms.add(uri, "plugins", Ci.nsIPermissionManager.DENY_ACTION);
+
+          // Other than that, do nothing
       }
-    ]
-    NativeWindow.doorhanger.show(message, "ask-to-play-plugins", buttons, aTab.id);
+    ];
+
+    // Add a checkbox with a "Don't ask again" message
+    let options = { checkbox: Strings.browser.GetStringFromName("clickToPlayPlugins.dontAskAgain") };
+
+    NativeWindow.doorhanger.show(message, "ask-to-play-plugins", buttons, aTab.id, options);
   },
 
   playAllPlugins: function(aContentWindow) {
     let cwu = aContentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
                             .getInterface(Ci.nsIDOMWindowUtils);
     // XXX not sure if we should enable plugins for the parent documents...
     let plugins = cwu.plugins;
     if (!plugins || !plugins.length)
@@ -3998,17 +4028,17 @@ var PluginHelper = {
 
     return overflows;
   }
 };
 
 var PermissionsHelper = {
 
   _permissonTypes: ["password", "geolocation", "popup", "indexedDB",
-                    "offline-app", "desktop-notification"],
+                    "offline-app", "desktop-notification", "plugins"],
   _permissionStrings: {
     "password": {
       label: "password.rememberPassword",
       allowed: "password.remember",
       denied: "password.never"
     },
     "geolocation": {
       label: "geolocation.shareLocation",
@@ -4029,16 +4059,21 @@ var PermissionsHelper = {
       label: "offlineApps.storeOfflineData",
       allowed: "offlineApps.allow",
       denied: "offlineApps.never"
     },
     "desktop-notification": {
       label: "desktopNotification.useNotifications",
       allowed: "desktopNotification.allow",
       denied: "desktopNotification.dontAllow"
+    },
+    "plugins": {
+      label: "clickToPlayPlugins.playPlugins",
+      allowed: "clickToPlayPlugins.yes",
+      denied: "clickToPlayPlugins.no"
     }
   },
 
   init: function init() {
     Services.obs.addObserver(this, "Permissions:Get", false);
     Services.obs.addObserver(this, "Permissions:Clear", false);
   },
 
--- a/mobile/android/locales/en-US/chrome/browser.properties
+++ b/mobile/android/locales/en-US/chrome/browser.properties
@@ -221,19 +221,25 @@ stacktrace.outputMessage=Stack trace fro
 timer.start=%S: timer started
 
 # LOCALIZATION NOTE (timer.end):
 # This string is used to display the result of the console.timeEnd() call.
 # %1$S=name of timer, %2$S=number of milliseconds
 timer.end=%1$S: %2$Sms
 
 # Click to play plugins
-clickToPlayPlugins.message=This page contains plugin content. Would you like to play it?
+clickToPlayPlugins.message1=%S contains plugin content. Would you like to play it?
 clickToPlayPlugins.yes=Yes
 clickToPlayPlugins.no=No
+# LOCALIZATION NOTE (clickToPlayPlugins.dontAskAgain): This label appears next to a
+# checkbox to indicate whether or not the user wants to make a permanent decision.
+clickToPlayPlugins.dontAskAgain=Don't ask again for this site
+# LOCALIZATION NOTE (clickToPlayPlugins.playPlugins): Label that
+# will be used in site settings dialog.
+clickToPlayPlugins.playPlugins=Play Plugins
 
 # Site settings dialog
 # LOCALIZATION NOTE (siteSettings.labelToValue): This string will be used to
 # dislay a list of current permissions settings for a site.
 # Example: "Store Offline Data: Allow"
 siteSettings.labelToValue=%S: %S
 
 masterPassword.incorrect=Incorrect password