bug 820497 - update popup notification for click-to-play more often r=jaws
authorDavid Keeler <dkeeler@mozilla.com>
Mon, 17 Dec 2012 16:12:14 -0800
changeset 125459 3aa1bed744bb4663204609d9ba75269df418be91
parent 125458 ab307f02af0cd3ab8ff2463f546862e5130353ce
child 125460 e1a57065f541c449b4618dc9875ba536729394e7
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs820497
milestone20.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 820497 - update popup notification for click-to-play more often r=jaws
browser/base/content/browser-plugins.js
browser/base/content/browser.js
browser/base/content/test/Makefile.in
browser/base/content/test/browser_bug820497.js
browser/base/content/test/plugin_bug820497.html
--- a/browser/base/content/browser-plugins.js
+++ b/browser/base/content/browser-plugins.js
@@ -331,17 +331,16 @@ var gPluginHandler = {
       objLoadingContent.playPlugin();
 
     let cwu = aContentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
                             .getInterface(Ci.nsIDOMWindowUtils);
     let pluginNeedsActivation = gPluginHandler._pluginNeedsActivationExceptThese([aPlugin]);
     let browser = gBrowser.getBrowserForDocument(aContentWindow.document);
     let notification = PopupNotifications.getNotification("click-to-play-plugins", browser);
     if (notification) {
-      browser._clickToPlayDoorhangerShown = false;
       notification.remove();
     }
     if (pluginNeedsActivation) {
       gPluginHandler._showClickToPlayNotification(browser);
     }
   },
 
   stopPlayPreview: function PH_stopPlayPreview(aPlugin, aPlayPlugin) {
@@ -447,18 +446,17 @@ var gPluginHandler = {
             aEvent.button == 0 && aEvent.isTrusted) {
           gPluginHandler.activateSinglePlugin(aEvent.target.ownerDocument.defaultView.top, aPlugin);
           aEvent.stopPropagation();
           aEvent.preventDefault();
         }
       }, true);
     }
 
-    if (!browser._clickToPlayDoorhangerShown)
-      gPluginHandler._showClickToPlayNotification(browser);
+    gPluginHandler._showClickToPlayNotification(browser);
   },
 
   _handlePlayPreviewEvent: function PH_handlePlayPreviewEvent(aPlugin) {
     let doc = aPlugin.ownerDocument;
     let previewContent = doc.getAnonymousElementByAttribute(aPlugin, "class", "previewPluginContent");
     let iframe = previewContent.getElementsByClassName("previewPluginContentFrame")[0];
     if (!iframe) {
       // lazy initialization of the iframe
@@ -596,19 +594,17 @@ var gPluginHandler = {
       if (gPluginHandler.canActivatePlugin(objLoadingContent)) {
         let permissionString = pluginHost.getPermissionStringForType(objLoadingContent.actualType);
         Services.perms.add(aBrowser.currentURI, permissionString, aPermission);
       }
     }
   },
 
   _showClickToPlayNotification: function PH_showClickToPlayNotification(aBrowser) {
-    aBrowser._clickToPlayDoorhangerShown = true;
     let contentWindow = aBrowser.contentWindow;
-
     let messageString = gNavigatorBundle.getString("activatePluginsMessage.message");
     let mainAction = {
       label: gNavigatorBundle.getString("activateAllPluginsMessage.label"),
       accessKey: gNavigatorBundle.getString("activatePluginsMessage.accesskey"),
       callback: function() { gPluginHandler.activatePlugins(contentWindow); }
     };
     let centerActions = gPluginHandler._makeCenterActions(aBrowser);
     let cwu = contentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -4513,17 +4513,16 @@ var TabsProgressListener = {
   onLocationChange: function (aBrowser, aWebProgress, aRequest, aLocationURI,
                               aFlags) {
     // Filter out any sub-frame loads
     if (aBrowser.contentWindow == aWebProgress.DOMWindow) {
       // Filter out any onLocationChanges triggered by anchor navigation
       // or history.push/pop/replaceState.
       if (aRequest) {
         // Initialize the click-to-play state.
-        aBrowser._clickToPlayDoorhangerShown = false;
         aBrowser._clickToPlayPluginsActivated = false;
         aBrowser._pluginScriptedState = gPluginHandler.PLUGIN_SCRIPTED_STATE_NONE;
       }
       FullZoom.onLocationChange(aLocationURI, false, aBrowser);
     }
   },
 
   onRefreshAttempted: function (aBrowser, aWebProgress, aURI, aDelay, aSameURI) {
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -250,16 +250,17 @@ endif
                  plugin_both.html \
                  plugin_both2.html \
                  plugin_bug743421.html \
                  plugin_clickToPlayAllow.html \
                  plugin_clickToPlayDeny.html \
                  plugin_bug749455.html \
                  plugin_bug797677.html \
                  plugin_bug818009.html \
+                 plugin_bug820497.html \
                  plugin_hidden_to_visible.html \
                  plugin_two_types.html \
                  alltabslistener.html \
                  zoom_test.html \
                  dummy_page.html \
                  file_bug550565_popup.html \
                  file_bug550565_favicon.ico \
                  browser_aboutHome.js \
@@ -278,16 +279,17 @@ endif
                  browser_middleMouse_inherit.js \
                  redirect_bug623155.sjs \
                  browser_tabDrop.js \
                  browser_lastAccessedTab.js \
                  browser_bug734076.js \
                  browser_bug812562.js \
                  browser_bug818009.js \
                  browser_bug818118.js \
+                 browser_bug820497.js \
                  blockPluginVulnerableUpdatable.xml \
                  blockPluginVulnerableNoUpdate.xml \
                  blockNoPlugins.xml \
                  browser_utilityOverlay.js \
                  browser_bug676619.js \
                  download_page.html \
                  browser_URLBarSetURI.js \
                  $(NULL)
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/browser_bug820497.js
@@ -0,0 +1,53 @@
+/* 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/. */
+
+var gTestBrowser = null;
+var gNumPluginBindingsAttached = 0;
+
+Components.utils.import("resource://gre/modules/Services.jsm");
+
+function test() {
+  waitForExplicitFinish();
+  registerCleanupFunction(function() {
+    Services.prefs.clearUserPref("plugins.click_to_play");
+    gTestBrowser.removeEventListener("PluginBindingAttached", pluginBindingAttached, true, true);
+    gBrowser.removeCurrentTab();
+    window.focus();
+  });
+
+  Services.prefs.setBoolPref("plugins.click_to_play", true);
+
+  gBrowser.selectedTab = gBrowser.addTab();
+  gTestBrowser = gBrowser.selectedBrowser;
+  gTestBrowser.addEventListener("PluginBindingAttached", pluginBindingAttached, true, true);
+  var gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
+  gTestBrowser.contentWindow.location = gHttpTestRoot + "plugin_bug820497.html";
+}
+
+function pluginBindingAttached() {
+  gNumPluginBindingsAttached++;
+
+  if (gNumPluginBindingsAttached == 1) {
+    var doc = gTestBrowser.contentDocument;
+    var testplugin = doc.getElementById("test");
+    ok(testplugin, "should have test plugin");
+    var secondtestplugin = doc.getElementById("secondtest");
+    ok(!secondtestplugin, "should not yet have second test plugin");
+    var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
+    ok(notification, "should have popup notification");
+    is(notification.options.centerActions.length, 1, "should be 1 type of plugin in the popup notification");
+  } else if (gNumPluginBindingsAttached == 2) {
+    var doc = gTestBrowser.contentDocument;
+    var testplugin = doc.getElementById("test");
+    ok(testplugin, "should have test plugin");
+    var secondtestplugin = doc.getElementById("secondtest");
+    ok(secondtestplugin, "should have second test plugin");
+    var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
+    ok(notification, "should have popup notification");
+    is(notification.options.centerActions.length, 2, "should be 2 types of plugin in the popup notification");
+    finish();
+  } else {
+    ok(false, "if we've gotten here, something is quite wrong");
+  }
+}
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/plugin_bug820497.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+<head><meta charset="utf-8"/></head>
+<body onload="addSecondPlugin()">
+<object id="test" type="application/x-test" width=200 height=200></object>
+<script>
+  function addSecondPlugin() {
+    var object = document.createElement("object");
+    object.type = "application/x-second-test";
+    object.width = 200;
+    object.height = 200;
+    object.id = "secondtest";
+    document.body.appendChild(object);
+  }
+</script>
+</body>
+</html>