From 233b384467ca7835ad4de23a606528eaf42078cf Mon Sep 17 00:00:00 2001 From: David Keeler Date: Wed, 5 Dec 2012 13:00:52 -0800 Subject: [PATCH] bug 818009 - canActivate: only click-to-play-type plugins are valid r=jaws --- browser/base/content/browser-plugins.js | 3 +- browser/base/content/test/Makefile.in | 2 + .../base/content/test/browser_bug818009.js | 47 +++++++++++++++++++ .../base/content/test/plugin_bug818009.html | 8 ++++ .../base/public/nsIObjectLoadingContent.idl | 2 + content/base/src/nsObjectLoadingContent.h | 2 + 6 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 browser/base/content/test/browser_bug818009.js create mode 100644 browser/base/content/test/plugin_bug818009.html diff --git a/browser/base/content/browser-plugins.js b/browser/base/content/browser-plugins.js index 2212f4096f52..aeea152d3ed9 100644 --- a/browser/base/content/browser-plugins.js +++ b/browser/base/content/browser-plugins.js @@ -248,7 +248,8 @@ var gPluginHandler = { return !objLoadingContent.activated && pluginPermission != Ci.nsIPermissionManager.DENY_ACTION && - objLoadingContent.pluginFallbackType !== Ci.nsIObjectLoadingContent.PLUGIN_PLAY_PREVIEW; + objLoadingContent.pluginFallbackType >= Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY && + objLoadingContent.pluginFallbackType <= Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_NO_UPDATE; }, activatePlugins: function PH_activatePlugins(aContentWindow) { diff --git a/browser/base/content/test/Makefile.in b/browser/base/content/test/Makefile.in index aaaf041e33b1..9382393f7b52 100644 --- a/browser/base/content/test/Makefile.in +++ b/browser/base/content/test/Makefile.in @@ -246,6 +246,7 @@ _BROWSER_FILES = \ plugin_clickToPlayDeny.html \ plugin_bug749455.html \ plugin_bug797677.html \ + plugin_bug818009.html \ plugin_hidden_to_visible.html \ plugin_two_types.html \ alltabslistener.html \ @@ -272,6 +273,7 @@ _BROWSER_FILES = \ browser_lastAccessedTab.js \ browser_bug734076.js \ browser_bug812562.js \ + browser_bug818009.js \ blockPluginVulnerableUpdatable.xml \ blockPluginVulnerableNoUpdate.xml \ blockNoPlugins.xml \ diff --git a/browser/base/content/test/browser_bug818009.js b/browser/base/content/test/browser_bug818009.js new file mode 100644 index 000000000000..50d43a2d4a32 --- /dev/null +++ b/browser/base/content/test/browser_bug818009.js @@ -0,0 +1,47 @@ +var gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/"); +var gTestBrowser = null; + +Components.utils.import("resource://gre/modules/Services.jsm"); + +function test() { + waitForExplicitFinish(); + registerCleanupFunction(function() { + Services.prefs.clearUserPref("plugins.click_to_play"); + gTestBrowser.removeEventListener("load", pageLoad, true); + }); + Services.prefs.setBoolPref("plugins.click_to_play", true); + + gBrowser.selectedTab = gBrowser.addTab(); + gTestBrowser = gBrowser.selectedBrowser; + gTestBrowser.addEventListener("load", pageLoad, true); + gTestBrowser.contentWindow.location = gHttpTestRoot + "plugin_bug818009.html"; +} + +function pageLoad() { + // The plugin events are async dispatched and can come after the load event + // This just allows the events to fire before we then go on to test the states + executeSoon(actualTest); +} + +function actualTest() { + var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); + ok(notification, "should have a click-to-play notification"); + is(notification.options.centerActions.length, 1, "should have only one type of plugin in the notification"); + is(notification.options.centerActions[0].message, "Test", "the one type of plugin should be the 'Test' plugin"); + + var doc = gTestBrowser.contentDocument; + var inner = doc.getElementById("inner"); + ok(inner, "should have 'inner' plugin"); + var innerObjLC = inner.QueryInterface(Ci.nsIObjectLoadingContent); + ok(!innerObjLC.activated, "inner plugin shouldn't be activated"); + is(innerObjLC.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, "inner plugin fallback type should be PLUGIN_CLICK_TO_PLAY"); + var outer = doc.getElementById("outer"); + ok(outer, "should have 'outer' plugin"); + var outerObjLC = outer.QueryInterface(Ci.nsIObjectLoadingContent); + ok(!outerObjLC.activated, "outer plugin shouldn't be activated"); + is(outerObjLC.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_ALTERNATE, "outer plugin fallback type should be PLUGIN_ALTERNATE"); + + gBrowser.removeCurrentTab(); + window.focus(); + finish(); +} diff --git a/browser/base/content/test/plugin_bug818009.html b/browser/base/content/test/plugin_bug818009.html new file mode 100644 index 000000000000..48f3b921ef0a --- /dev/null +++ b/browser/base/content/test/plugin_bug818009.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/content/base/public/nsIObjectLoadingContent.idl b/content/base/public/nsIObjectLoadingContent.idl index 1a343c53f48a..f8feb847087a 100644 --- a/content/base/public/nsIObjectLoadingContent.idl +++ b/content/base/public/nsIObjectLoadingContent.idl @@ -51,6 +51,8 @@ interface nsIObjectLoadingContent : nsISupports const unsigned long PLUGIN_USER_DISABLED = 7; /// ** All values >= PLUGIN_CLICK_TO_PLAY are plugin placeholder types that /// would be replaced by a real plugin if activated (playPlugin()) + /// ** Furthermore, values >= PLUGIN_CLICK_TO_PLAY and + /// <= PLUGIN_VULNERABLE_NO_UPDATE are click-to-play types. // The plugin is disabled until the user clicks on it const unsigned long PLUGIN_CLICK_TO_PLAY = 8; // The plugin is vulnerable (update available) diff --git a/content/base/src/nsObjectLoadingContent.h b/content/base/src/nsObjectLoadingContent.h index bfdbc8c35ea4..2f449cb74990 100644 --- a/content/base/src/nsObjectLoadingContent.h +++ b/content/base/src/nsObjectLoadingContent.h @@ -79,6 +79,8 @@ class nsObjectLoadingContent : public nsImageLoadingContent eFallbackUserDisabled = nsIObjectLoadingContent::PLUGIN_USER_DISABLED, /// ** All values >= eFallbackClickToPlay are plugin placeholder types /// that would be replaced by a real plugin if activated (PlayPlugin()) + /// ** Furthermore, values >= eFallbackClickToPlay and + /// <= eFallbackVulnerableNoUpdate are click-to-play types. // The plugin is disabled until the user clicks on it eFallbackClickToPlay = nsIObjectLoadingContent::PLUGIN_CLICK_TO_PLAY, // The plugin is vulnerable (update available)