From 207c4dd3bdec33cd86c4eeb8abe27721a0f2ccd3 Mon Sep 17 00:00:00 2001 From: David Keeler Date: Thu, 3 Jan 2013 11:31:04 -0800 Subject: [PATCH] bug 820303 - scripted click-to-play plugins: handle deny permission r=jaws --- browser/base/content/browser-plugins.js | 11 +++++--- .../browser_clickToPlayPluginScriptAccessPopup.js | 31 +++++++++++++++++++++- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/browser/base/content/browser-plugins.js b/browser/base/content/browser-plugins.js index 54740321d9ba..ad8be8ad39e0 100644 --- a/browser/base/content/browser-plugins.js +++ b/browser/base/content/browser-plugins.js @@ -256,8 +256,12 @@ var gPluginHandler = { let cwu = contentWindow.QueryInterface(Ci.nsIInterfaceRequestor) .getInterface(Ci.nsIDOMWindowUtils); - let haveVisibleCTPPlugin = cwu.plugins.some(function(plugin) { + let plugins = cwu.plugins.filter(function(plugin) { let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); + return gPluginHandler.canActivatePlugin(objLoadingContent); + }); + + let haveVisibleCTPPlugin = plugins.some(function(plugin) { let doc = plugin.ownerDocument; let overlay = doc.getAnonymousElementByAttribute(plugin, "class", "mainBox"); if (!overlay) @@ -271,12 +275,11 @@ var gPluginHandler = { let isInvisible = ((computedStyle.width == "240px" && computedStyle.height == "200px") || gPluginHandler.isTooSmall(plugin, overlay)); - return (!isInvisible && - gPluginHandler.canActivatePlugin(objLoadingContent)); + return !isInvisible; }); let notification = PopupNotifications.getNotification("click-to-play-plugins", aBrowser); - if (notification && !haveVisibleCTPPlugin && !this._notificationDisplayedOnce) { + if (notification && plugins.length > 0 && !haveVisibleCTPPlugin && !this._notificationDisplayedOnce) { notification.dismissed = false; PopupNotifications._update(notification.anchorElement); this._notificationDisplayedOnce = true; diff --git a/browser/base/content/test/browser_clickToPlayPluginScriptAccessPopup.js b/browser/base/content/test/browser_clickToPlayPluginScriptAccessPopup.js index b80e2909d6ab..02967edd2e02 100644 --- a/browser/base/content/test/browser_clickToPlayPluginScriptAccessPopup.js +++ b/browser/base/content/test/browser_clickToPlayPluginScriptAccessPopup.js @@ -1,5 +1,5 @@ const gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/"); -const EXPECTED_PLUGINSCRIPTED_EVENT_COUNT = 6; +const EXPECTED_PLUGINSCRIPTED_EVENT_COUNT = 7; var gTestBrowser = null; var gNextTestList = []; @@ -90,6 +90,35 @@ function testNoEventFired() { ok(notification.dismissed, "notification should not be showing (" + getCurrentTestLocation() + ")"); ok(!gPluginScriptedFired, "PluginScripted should not have fired (" + getCurrentTestLocation() + ")"); + prepareTest(testDenyPermissionPart1, gHttpTestRoot + "plugin_test_noScriptNoPopup.html"); +} + +function testDenyPermissionPart1() { + var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); + ok(notification, "test deny permission: should have a click-to-play notification"); + // Simulate clicking the "Deny Always" button. + notification.secondaryActions[1].callback(); + gPluginScriptedFired = false; + prepareTest(testDenyPermissionPart2, gHttpTestRoot + "plugin_test_scriptedPopup1.html"); +} + +function testDenyPermissionPart2() { + var condition = function() gPluginScriptedFired; + waitForCondition(condition, testDenyPermissionPart3, "test deny permission: waited too long for PluginScripted event"); +} + +function testDenyPermissionPart3() { + var condition = function() gTestBrowser._pluginScriptedState == gPluginHandler.PLUGIN_SCRIPTED_STATE_DONE; + waitForCondition(condition, testDenyPermissionPart4, "test deny permission: waited too long for PluginScripted event handling"); +} + +function testDenyPermissionPart4() { + var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); + ok(!notification, "test deny permission: should not have a click-to-play notification"); + + var pluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost); + Services.perms.remove("127.0.0.1:8888", pluginHost.getPermissionStringForType("application/x-test")); + runNextTest(); } -- 2.11.4.GIT