bug 820497 - update popup notification for click-to-play more often (beta) r=jaws a=lsblakk
authorDavid Keeler <dkeeler@mozilla.com>
Mon, 17 Dec 2012 16:12:14 -0800
changeset 122682 5b312c4d8130c2b816df283a9ae9c8ab6b25f5d7
parent 122681 d8a545b0cb29b141d7ac251dc46d778fcd7e7af7
child 122683 5932391eb74a537f6a3bef96c4aef2a958896e1e
push id2088
push userdkeeler@mozilla.com
push dateSat, 26 Jan 2013 00:23:12 +0000
treeherdermozilla-beta@5932391eb74a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, lsblakk
bugs820497
milestone19.0
bug 820497 - update popup notification for click-to-play more often (beta) 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
@@ -316,17 +316,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) {
@@ -423,18 +422,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
@@ -567,19 +565,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("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
@@ -4561,17 +4561,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
@@ -247,16 +247,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 \
                  browser_tabMatchesInAwesomebar.js \
                  file_bug550565_popup.html \
                  file_bug550565_favicon.ico \
@@ -274,16 +275,17 @@ endif
                  browser_minimize.js \
                  browser_aboutSyncProgress.js \
                  browser_middleMouse_inherit.js \
                  redirect_bug623155.sjs \
                  browser_tabDrop.js \
                  browser_lastAccessedTab.js \
                  browser_bug734076.js \
                  browser_bug818009.js \
+                 browser_bug820497.js \
                  browser_utilityOverlay.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 \
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>