From 0905b54ccc5ad5c9936398bf0b1635f6096b18dd Mon Sep 17 00:00:00 2001 From: Margaret Leibovic Date: Tue, 22 May 2012 21:29:19 -0400 Subject: [PATCH] Bug 755062 - Make sure there are no visible plugins on the page before deciding to show the plugin doorhanger. r=mfinkle --- mobile/android/chrome/content/browser.js | 27 ++++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index 507096bd21e..84bcf319216 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -1510,7 +1510,8 @@ function Tab(aURL, aParams) { this._drawZoom = 1.0; this.userScrollPos = { x: 0, y: 0 }; this.contentDocumentIsDisplayed = true; - this.clickToPlayPluginDoorhangerShown = false; + this.pluginDoorhangerTimeout = null; + this.shouldShowPluginDoorhanger = true; this.clickToPlayPluginsActivated = false; } @@ -2111,11 +2112,22 @@ Tab.prototype = { // If the plugin is hidden, or if the overlay is too small, show a doorhanger notification let overlay = plugin.ownerDocument.getAnonymousElementByAttribute(plugin, "class", "mainBox"); if (!overlay || PluginHelper.isTooSmall(plugin, overlay)) { - if (!this.clickToPlayPluginDoorhangerShown) - PluginHelper.showDoorHanger(this); + // To avoid showing the doorhanger if there are also visible plugin overlays on the page, + // delay showing the doorhanger to check if visible plugins get added in the near future. + if (!this.pluginDoorhangerTimeout) { + this.pluginDoorhangerTimeout = setTimeout(function() { + if (this.shouldShowPluginDoorhanger) + PluginHelper.showDoorHanger(this); + }.bind(this), 500); + } + // No overlay? We're done here. if (!overlay) return; + + } else { + // There's a large enough visible overlay that we don't need to show the doorhanger. + this.shouldShowPluginDoorhanger = false; } // Add click to play listener to the overlay @@ -2130,8 +2142,7 @@ Tab.prototype = { tab.clickToPlayPluginsActivated = true; PluginHelper.playAllPlugins(win); - if (tab.clickToPlayPluginDoorhangerShown) - NativeWindow.doorhanger.hide("ask-to-play-plugins", tab.id); + NativeWindow.doorhanger.hide("ask-to-play-plugins", tab.id); }, true); break; } @@ -2209,7 +2220,9 @@ Tab.prototype = { let sameDocument = (aFlags & Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT) != 0; // Reset state of click-to-play plugin notifications. - this.clickToPlayPluginDoorhangerShown = false; + clearTimeout(this.pluginDoorhangerTimeout); + this.pluginDoorhangerTimeout = null; + this.shouldShowPluginDoorhanger = true; this.clickToPlayPluginsActivated = false; let message = { @@ -4215,7 +4228,7 @@ var PluginHelper = { // Even though we may not end up showing a doorhanger, this flag // lets us know that we've tried to show a doorhanger. - aTab.clickToPlayPluginDoorhangerShown = true; + aTab.shouldShowPluginDoorhanger = false; let uri = aTab.browser.currentURI;