Bug 937616 Click-to-play notifications should track plugins that are no longer present in the page r=mcsmurf f=Ratty a=IanN
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Mon, 03 Feb 2014 00:37:30 +0000
changeset 17007 70d35117ff596e963cf02e4131d8b9f8163d9c38
parent 17006 b03561ae7689b9187ba45573fad4ca953e4a890c
child 17008 0c0348549dd424bafd5cead0cf6a1ef891be6261
push id1074
push userbugzilla@standard8.plus.com
push dateMon, 03 Feb 2014 22:47:23 +0000
treeherdercomm-beta@6b791b5369ed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcsmurf, IanN
bugs937616
Bug 937616 Click-to-play notifications should track plugins that are no longer present in the page r=mcsmurf f=Ratty a=IanN a=Callek for checkin to a CLOSED TREE
suite/common/bindings/notification.xml
--- a/suite/common/bindings/notification.xml
+++ b/suite/common/bindings/notification.xml
@@ -88,16 +88,17 @@
       </field>
 
       <method name="onDocumentChange">
         <body>
           <![CDATA[
             this.missingPlugins = null;
             this.crashNotified = false;
             this.clickToPlayPluginsActivated = false;
+            this.clickToPlayTypes = Set();
             if (this.popupCount) {
               this.popupCount = 0;
               this.notifyPopupCountChanged();
             }
             this.removeTransientNotifications();
           ]]>
         </body>
       </method>
@@ -513,16 +514,18 @@
                 onset="return this._missingPlugins = val;"/>
 
       <field name="CrashSubmit">null</field>
 
       <field name="crashNotified">false</field>
 
       <field name="clickToPlayPluginsActivated">false</field>
 
+      <field name="clickToPlayTypes">Set()</field>
+
       <method name="getPluginInfo">
         <parameter name="pluginElement"/>
         <body>
           <![CDATA[
             var mimetype;
             var pluginsPage;
             var pluginName = this._stringBundle.GetStringFromName("pluginInfo.unknownPlugin");
             if (pluginElement instanceof HTMLAppletElement) {
@@ -645,37 +648,44 @@
         <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) {
-              if (this.canActivatePlugin(plugin)) {
-                var permissionString = ph.getPermissionStringForType(plugin.actualType);
-                pm.add(this.activeBrowser.currentURI, permissionString, aPermission);
-              }
+            for (var type of this.clickToPlayTypes) {
+              var permissionString = ph.getPermissionStringForType(type);
+              pm.add(this.activeBrowser.currentURI, permissionString, aPermission);
             }
           ]]>
         </body>
       </method>
 
       <method name="activatePlugins">
+        <parameter name="aCheckForReload"/>
         <body>
           <![CDATA[
             this.clickToPlayPluginsActivated = true;
             var plugins = this.contentWindowUtils.plugins;
             for (let plugin of plugins) {
               if (this.canActivatePlugin(plugin))
-                plugin.playPlugin();
+                this.clickToPlayTypes.delete(plugin.actualType);
             }
-            this.removePluginClickToPlayPrompt();
+            if (aCheckForReload && this.clickToPlayTypes.size)
+              this.reloadPage();
+            else {
+              for (let plugin of plugins) {
+                if (this.canActivatePlugin(plugin))
+                  plugin.playPlugin();
+              }
+              if (!this.clickToPlayTypes.size)
+                this.removePluginClickToPlayPrompt();
+            }
           ]]>
         </body>
       </method>
 
       <method name="activateSinglePlugin">
         <parameter name="aPlugin"/>
         <body>
           <![CDATA[
@@ -1350,17 +1360,17 @@
             const nsIPermissionManager = Components.interfaces.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)
                   this.setPermissionForPlugins(nsIPermissionManager.ALLOW_ACTION);
-                this.activatePlugins();
+                this.activatePlugins(checkbox.checked);
               }).bind(this)
             }, {
               label: this._stringBundle.GetStringFromName("activatepluginsMessage.dismiss.label"),
               accessKey: this._stringBundle.GetStringFromName("activatepluginsMessage.dismiss.accesskey"),
               callback: (function () {
                 if (checkbox.checked)
                   this.setPermissionForPlugins(nsIPermissionManager.DENY_ACTION);
                 this.removeClickToPlayOverlays();
@@ -1426,16 +1436,17 @@
               return;
             }
 
             if (this.clickToPlayPluginsActivated) {
               pluginElement.playPlugin();
               return;
             }
 
+            this.clickToPlayTypes.add(pluginElement.actualType);
             this.showPluginClickToPlayPrompt(aTriggeredByNewPlugin);
 
             // Show the in-content UI if it's not too big. The crashed plugin handler already does this.
             pluginElement.addEventListener("overflow", this);
             pluginElement.addEventListener("underflow", this);
             overlay.style.visibility =
               this.isTooSmall(pluginElement, overlay) ? "hidden" : "visible";
 
@@ -2678,17 +2689,17 @@
             var messageString = this._stringBundle.GetStringFromName(haveVulnerablePlugin ?
                                                                      "vulnerablePluginsMessage" :
                                                                      "activatepluginsMessage.title");
             var secondaryActions = [{
               label: this._stringBundle.GetStringFromName("activatepluginsMessage.always.label"),
               accessKey: this._stringBundle.GetStringFromName("activatepluginsMessage.always.accesskey"),
               callback: (function () {
                 this.setPermissionForPlugins(nsIPermissionManager.ALLOW_ACTION);
-                this.activatePlugins();
+                this.activatePlugins(true);
               }).bind(this)
             }, {
               label: this._stringBundle.GetStringFromName("activatepluginsMessage.never.label"),
               accessKey: this._stringBundle.GetStringFromName("activatepluginsMessage.never.accesskey"),
               callback: (function () {
                 this.setPermissionForPlugins(nsIPermissionManager.DENY_ACTION);
                 var notification = PopupNotifications.getNotification("click-to-play-plugins",
                                                                       this.activeBrowser);