Bug 854867 - "Click-to-play no longer respects per-site permissions" r=IanN a=Callek RELEASE_20_END
authorneil@parkwaycc.co.uk <neil@httl.net>
Thu, 04 Apr 2013 16:21:00 -0400
changeset 30973 9ee1b229d0fb0ecf85c889a7e016f7be8fdcc349
parent 30969 832b035c68d546e0a862cd79bffbd4eb7116e174
child 30974 e7d562d9d11c4b5bbbdcdaed786f291f265d0b8f
child 30977 7125b153ce1e202cdf7cba533f449a553e68bc2a
push id1
push userclokep@gmail.com
push dateMon, 07 May 2018 22:45:56 +0000
treeherdercomm-esr60@57eacde5ef40 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersIanN, Callek
bugs854867
Bug 854867 - "Click-to-play no longer respects per-site permissions" r=IanN a=Callek
suite/common/bindings/notification.xml
--- a/suite/common/bindings/notification.xml
+++ b/suite/common/bindings/notification.xml
@@ -554,19 +554,53 @@
           ]]>
         </body>
       </method>
 
       <method name="canActivatePlugin">
         <parameter name="objLoadingContent"/>
         <body>
           <![CDATA[
-            var nsIObjectLoadingContent = Components.interfaces.nsIObjectLoadingContent;
-            return !objLoadingContent.activated &&
-                   objLoadingContent.pluginFallbackType !== nsIObjectLoadingContent.PLUGIN_PLAY_PREVIEW;
+            const nsIObjectLoadingContent = Components.interfaces.nsIObjectLoadingContent;
+            var actualType = objLoadingContent.actualType;
+            if (objLoadingContent.getContentTypeForMIMEType(actualType) != nsIObjectLoadingContent.TYPE_PLUGIN ||
+                objLoadingContent.activated ||
+                objLoadingContent.pluginFallbackType < nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY ||
+                objLoadingContent.pluginFallbackType > nsIObjectLoadingContent.PLUGIN_VULNERABLE_NO_UPDATE)
+              return false;
+
+            var ph = Components.classes["@mozilla.org/plugin/host;1"]
+                               .getService(Components.interfaces.nsIPluginHost);
+            var permissionString = ph.getPermissionStringForType(actualType);
+            const nsIPermissionManager = Components.interfaces.nsIPermissionManager;
+            var pm = Components.classes["@mozilla.org/permissionmanager;1"]
+                               .getService(nsIPermissionManager);
+            var pluginPermission = pm.testPermission(this.activeBrowser.currentURI, permissionString);
+            return pluginPermission != nsIPermissionManager.DENY_ACTION;
+          ]]>
+        </body>
+      </method>
+
+      <method name="setPermissionForPlugins">
+        <parameter name="aPermission"/>
+        <body>
+          <![CDATA[
+            var ph = Components.classes["@mozilla.org/plugin/host;1"]
+                               .getService(Components.interfaces.nsIPluginHost);
+            const nsIPermissionManager = Components.interfaces.nsIPermissionManager;
+            var pm = Components.classes["@mozilla.org/permissionmanager;1"]
+                               .getService(nsIPermissionManager);
+            var plugins = this.contentWindowUtils.plugins;
+            for (var plugin of plugins) {
+              var objLoadingContent = plugin.QueryInterface(Components.interfaces.nsIObjectLoadingContent);
+              if (this.canActivatePlugin(objLoadingContent)) {
+                var permissionString = ph.getPermissionStringForType(objLoadingContent.actualType);
+                pm.add(this.activeBrowser.currentURI, permissionString, aPermission);
+              }
+            }
           ]]>
         </body>
       </method>
 
       <method name="activatePlugins">
         <body>
           <![CDATA[
             this.clickToPlayPluginsActivated = true;
@@ -1175,35 +1209,31 @@
           <![CDATA[
             this.clickToPlayPromptShown = true;
 
             var checkbox = document.createElement("checkbox");
             checkbox.className = "rememberChoice";
             checkbox.setAttribute("label", this._stringBundle.GetStringFromName("activatepluginsMessage.remember"));
 
             const nsIPermissionManager = Components.interfaces.nsIPermissionManager;
-            var pm = Components.classes["@mozilla.org/permissionmanager;1"]
-                               .getService(nsIPermissionManager);
             var messageString = this._stringBundle.GetStringFromName("activatepluginsMessage.title");
             var buttons = [{
               label: this._stringBundle.GetStringFromName("activatepluginsMessage.activate.label"),
               accessKey: this._stringBundle.GetStringFromName("activatepluginsMessage.activate.accesskey"),
               callback: (function () {
                 if (checkbox.checked)
-                  pm.add(this.activeBrowser.currentURI, "plugins",
-                         nsIPermissionManager.ALLOW_ACTION);
+                  this.setPermissionForPlugins(nsIPermissionManager.ALLOW_ACTION);
                 this.activatePlugins();
               }).bind(this)
             }, {
               label: this._stringBundle.GetStringFromName("activatepluginsMessage.dismiss.label"),
               accessKey: this._stringBundle.GetStringFromName("activatepluginsMessage.dismiss.accesskey"),
               callback: (function () {
                 if (checkbox.checked)
-                  pm.add(this.activeBrowser.currentURI, "plugins",
-                         nsIPermissionManager.DENY_ACTION);
+                  this.setPermissionForPlugins(nsIPermissionManager.DENY_ACTION);
               }).bind(this)
             }];
             var box = this.appendNotification(messageString,
                                               "click-to-play-plugins",
                                               null,
                                               this.PRIORITY_INFO_HIGH,
                                               buttons);
             // Force a style flush, so that we ensure the binding is attached.
@@ -1212,42 +1242,37 @@
           ]]>
         </body>
       </method>
 
       <method name="setupPluginClickToPlay">
         <parameter name="pluginElement"/>
         <body>
           <![CDATA[
-            if (this.clickToPlayPluginsActivated) {
-              let objLoadingContent = pluginElement.QueryInterface(Components.interfaces.nsIObjectLoadingContent);
-              objLoadingContent.playPlugin();
-              return;
-            }
-
             // Force a style flush, so that we ensure our binding is attached.
             pluginElement.clientTop;
             var doc = pluginElement.ownerDocument;
             var overlay = doc.getAnonymousElementByAttribute(pluginElement, "class", "mainBox");
 
-            const nsIPermissionManager = Components.interfaces.nsIPermissionManager;
-            var pm = Components.classes["@mozilla.org/permissionmanager;1"]
-                               .getService(nsIPermissionManager);
-            var pluginPermission = pm.testPermission(this.activeBrowser.currentURI, "plugins");
-            if (pluginPermission == nsIPermissionManager.DENY_ACTION) {
+            var objLoadingContent = pluginElement.QueryInterface(Components.interfaces.nsIObjectLoadingContent);
+            if (!this.canActivatePlugin(objLoadingContent)) {
               overlay.style.visibility = "hidden";
               return;
             }
 
+            if (this.clickToPlayPluginsActivated) {
+              objLoadingContent.playPlugin();
+              return;
+            }
+
             this.addLinkClickCallback(overlay, this.activateSinglePlugin, pluginElement);
 
             if (!this.clickToPlayPromptShown)
               this.showPluginClickToPlayPrompt();
 
-            let overlay = doc.getAnonymousElementByAttribute(pluginElement, "class", "mainBox");
             if (this.isTooSmall(pluginElement, overlay))
               overlay.style.visibility = "hidden";
           ]]>
         </body>
       </method>
 
       <method name="handlePlayPreviewEvent">
         <parameter name="pluginElement"/>
@@ -2128,23 +2153,16 @@
       <handler event="pageshow" phase="capturing">
         <![CDATA[
           // The PluginClickToPlay events are not fired when navigating using the
           // BF cache. |event.persisted| is true when the page is loaded from the
           // BF cache, so this code reshows the notification if necessary.
           if (!event.persisted || !this._prefs.getBoolPref("plugins.click_to_play"))
             return;
 
-          const nsIPermissionManager = Components.interfaces.nsIPermissionManager;
-          var pm = Components.classes["@mozilla.org/permissionmanager;1"]
-                             .getService(nsIPermissionManager);
-          var pluginPermission = pm.testPermission(this.activeBrowser.currentURI, "plugins");
-          if (pluginPermission == nsIPermissionManager.DENY_ACTION)
-            return;
-
           var pluginNeedsActivation = this.contentWindowUtils.plugins.some(function(aPlugin) {
             var objLoadingContent = aPlugin.QueryInterface(Components.interfaces.nsIObjectLoadingContent);
             return this.canActivatePlugin(objLoadingContent);
           }, this);
           if (pluginNeedsActivation)
             this.showPluginClickToPlayPrompt();
         ]]>
       </handler>
@@ -2247,38 +2265,34 @@
         </body>
       </method>
 
       <method name="showPluginClickToPlayPrompt">
         <body>
           <![CDATA[
             this.clickToPlayPromptShown = true;
             const nsIPermissionManager = Components.interfaces.nsIPermissionManager;
-            var pm = Components.classes["@mozilla.org/permissionmanager;1"]
-                               .getService(nsIPermissionManager);
             var messageString = this._stringBundle.GetStringFromName("activatepluginsMessage.title");
             var mainAction = {
               label: this._stringBundle.GetStringFromName("activatepluginsMessage.activate.label"),
               accessKey: this._stringBundle.GetStringFromName("activatepluginsMessage.activate.accesskey"),
               callback: this.activatePlugins.bind(this)
             };
             var secondaryActions = [{
               label: this._stringBundle.GetStringFromName("activatepluginsMessage.always.label"),
               accessKey: this._stringBundle.GetStringFromName("activatepluginsMessage.always.accesskey"),
               callback: (function () {
-                pm.add(this.activeBrowser.currentURI, "plugins",
-                       nsIPermissionManager.ALLOW_ACTION);
+                this.setPermissionForPlugins(nsIPermissionManager.ALLOW_ACTION);
                 this.activatePlugins();
               }).bind(this)
             }, {
               label: this._stringBundle.GetStringFromName("activatepluginsMessage.never.label"),
               accessKey: this._stringBundle.GetStringFromName("activatepluginsMessage.never.accesskey"),
               callback: (function () {
-                pm.add(this.activeBrowser.currentURI, "plugins",
-                       nsIPermissionManager.DENY_ACTION);
+                this.setPermissionForPlugins(nsIPermissionManager.DENY_ACTION);
                 var notification = PopupNotifications.getNotification("click-to-play-plugins",
                                                                       this.activeBrowser);
                 if (notification)
                   notification.remove();
               }).bind(this)
             }];
             var options = {
               dismissed: true