bug 820497 - update popup notification for click-to-play more often (esr17) r=jaws a=lsblakk
authorDavid Keeler <dkeeler@mozilla.com>
Mon, 17 Dec 2012 16:12:14 -0800
changeset 110018 c732d17352f56c758bda7b9460be19bec68b8dfa
parent 110017 2ea34ecded8ea6d7155795f70b88c03b853965bb
child 110019 0f66b61edee6fb9cdf145e56d4a8120a25d27f98
push id121
push userdkeeler@mozilla.com
push dateSat, 26 Jan 2013 00:33:00 +0000
reviewersjaws, lsblakk
bugs820497
milestone17.0.2esrpre
bug 820497 - update popup notification for click-to-play more often (esr17) r=jaws a=lsblakk
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
@@ -315,17 +315,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) {
@@ -422,18 +421,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
@@ -565,19 +563,17 @@ var gPluginHandler = {
       };
       centerActions.push(action);
     }
 
     return centerActions;
    },
 
   _showClickToPlayNotification: function PH_showClickToPlayNotification(aBrowser) {
-    aBrowser._clickToPlayDoorhangerShown = true;
     let contentWindow = aBrowser.contentWindow;
-
     let messageString = gNavigatorBundle.getString("activatePluginsMessage.message");
     let mainAction = {
       label: gNavigatorBundle.getString("activatePluginsMessage.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
@@ -4506,17 +4506,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 = 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
@@ -240,16 +240,17 @@ endif
                  plugin_test_scriptedNoPopup3.html \
                  plugin_alternate_content.html \
                  plugin_both.html \
                  plugin_both2.html \
                  plugin_bug743421.html \
                  plugin_clickToPlayAllow.html \
                  plugin_clickToPlayDeny.html \
                  plugin_bug749455.html \
+                 plugin_bug820497.html \
                  plugin_hidden_to_visible.html \
                  plugin_two_types.html \
                  alltabslistener.html \
                  zoom_test.html \
                  dummy_page.html \
                  browser_tabMatchesInAwesomebar.js \
                  file_bug550565_popup.html \
                  file_bug550565_favicon.ico \
@@ -266,16 +267,17 @@ endif
                  authenticate.sjs \
                  browser_minimize.js \
                  browser_aboutSyncProgress.js \
                  browser_middleMouse_inherit.js \
                  redirect_bug623155.sjs \
                  browser_tabDrop.js \
                  browser_lastAccessedTab.js \
                  browser_bug734076.js \
+                 browser_bug820497.js \
                  browser_social.js \
                  browser_social_toolbar.js \
                  browser_social_shareButton.js \
                  browser_social_sidebar.js \
                  browser_social_flyout.js \
                  browser_social_mozSocial_API.js \
                  browser_social_isVisible.js \
                  browser_social_chatwindow.js \
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>