Bug 822435 - Undo global-scope pollution from browser-plugins.js. r=jaws
authorDão Gottwald <dao@mozilla.com>
Tue, 18 Dec 2012 01:05:00 +0100
changeset 116352 0bec05537ea564b878f548fd540222fd878fea3d
parent 116351 84a620ecdf7230c34fa7e23ec28625a73e6d721d
child 116353 eb8734ce0dc2a98ba885bfd5fed9dc5f8177b683
push id24046
push useremorley@mozilla.com
push dateTue, 18 Dec 2012 09:32:10 +0000
treeherdermozilla-central@dd277d439d31 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs822435
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 822435 - Undo global-scope pollution from browser-plugins.js. r=jaws
browser/base/content/browser-plugins.js
browser/base/content/browser.js
browser/base/content/test/browser_clickToPlayPluginScriptAccessPopup.js
--- a/browser/base/content/browser-plugins.js
+++ b/browser/base/content/browser-plugins.js
@@ -1,73 +1,71 @@
 # -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 # 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/.
 
-const PLUGIN_SCRIPTED_STATE_NONE = 0;
-const PLUGIN_SCRIPTED_STATE_FIRED = 1;
-const PLUGIN_SCRIPTED_STATE_DONE = 2;
-
-function getPluginInfo(pluginElement)
-{
-  var tagMimetype;
-  var pluginsPage;
-  var pluginName = gNavigatorBundle.getString("pluginInfo.unknownPlugin");
-  if (pluginElement instanceof HTMLAppletElement) {
-    tagMimetype = "application/x-java-vm";
-  } else {
-    if (pluginElement instanceof HTMLObjectElement) {
-      pluginsPage = pluginElement.getAttribute("codebase");
-    } else {
-      pluginsPage = pluginElement.getAttribute("pluginspage");
-    }
-
-    // only attempt if a pluginsPage is defined.
-    if (pluginsPage) {
-      var doc = pluginElement.ownerDocument;
-      var docShell = findChildShell(doc, gBrowser.docShell, null);
-      try {
-        pluginsPage = makeURI(pluginsPage, doc.characterSet, docShell.currentURI).spec;
-      } catch (ex) {
-        pluginsPage = "";
-      }
-    }
-
-    tagMimetype = pluginElement.QueryInterface(Components.interfaces.nsIObjectLoadingContent)
-                               .actualType;
-
-    if (tagMimetype == "") {
-      tagMimetype = pluginElement.type;
-    }
-  }
-
-  if (tagMimetype) {
-    let navMimeType = navigator.mimeTypes.namedItem(tagMimetype);
-    if (navMimeType && navMimeType.enabledPlugin) {
-      pluginName = navMimeType.enabledPlugin.name;
-      pluginName = gPluginHandler.makeNicePluginName(pluginName);
-    }
-  }
-
-  return { mimetype: tagMimetype,
-           pluginsPage: pluginsPage,
-           pluginName: pluginName };
-}
-
 var gPluginHandler = {
+  PLUGIN_SCRIPTED_STATE_NONE: 0,
+  PLUGIN_SCRIPTED_STATE_FIRED: 1,
+  PLUGIN_SCRIPTED_STATE_DONE: 2,
 
 #ifdef MOZ_CRASHREPORTER
   get CrashSubmit() {
     delete this.CrashSubmit;
     Cu.import("resource://gre/modules/CrashSubmit.jsm", this);
     return this.CrashSubmit;
   },
 #endif
 
+  _getPluginInfo: function (pluginElement) {
+    let tagMimetype;
+    let pluginsPage;
+    let pluginName = gNavigatorBundle.getString("pluginInfo.unknownPlugin");
+    if (pluginElement instanceof HTMLAppletElement) {
+      tagMimetype = "application/x-java-vm";
+    } else {
+      if (pluginElement instanceof HTMLObjectElement) {
+        pluginsPage = pluginElement.getAttribute("codebase");
+      } else {
+        pluginsPage = pluginElement.getAttribute("pluginspage");
+      }
+
+      // only attempt if a pluginsPage is defined.
+      if (pluginsPage) {
+        let doc = pluginElement.ownerDocument;
+        let docShell = findChildShell(doc, gBrowser.docShell, null);
+        try {
+          pluginsPage = makeURI(pluginsPage, doc.characterSet, docShell.currentURI).spec;
+        } catch (ex) {
+          pluginsPage = "";
+        }
+      }
+
+      tagMimetype = pluginElement.QueryInterface(Ci.nsIObjectLoadingContent)
+                                 .actualType;
+
+      if (tagMimetype == "") {
+        tagMimetype = pluginElement.type;
+      }
+    }
+
+    if (tagMimetype) {
+      let navMimeType = navigator.mimeTypes.namedItem(tagMimetype);
+      if (navMimeType && navMimeType.enabledPlugin) {
+        pluginName = navMimeType.enabledPlugin.name;
+        pluginName = gPluginHandler.makeNicePluginName(pluginName);
+      }
+    }
+
+    return { mimetype: tagMimetype,
+             pluginsPage: pluginsPage,
+             pluginName: pluginName };
+  },
+
   // Map the plugin's name to a filtered version more suitable for user UI.
   makeNicePluginName : function (aName) {
     if (aName == "Shockwave Flash")
       return "Adobe Flash";
 
     // Clean up the plugin name by stripping off any trailing version numbers
     // or "plugin". EG, "Foo Bar Plugin 1.23_02" --> "Foo Bar"
     // Do this by first stripping the numbers, etc. off the end, and then
@@ -206,17 +204,17 @@ var gPluginHandler = {
         let updateLink = doc.getAnonymousElementByAttribute(plugin, "class", "checkForUpdatesLink");
         self.addLinkClickCallback(updateLink, "openPluginUpdatePage");
         /* FALLTHRU */
 
       case "PluginVulnerableNoUpdate":
       case "PluginClickToPlay":
         self._handleClickToPlayEvent(plugin);
         let overlay = doc.getAnonymousElementByAttribute(plugin, "class", "mainBox");
-        let pluginName = getPluginInfo(plugin).pluginName;
+        let pluginName = self._getPluginInfo(plugin).pluginName;
         let messageString = gNavigatorBundle.getFormattedString("PluginClickToPlay", [pluginName]);
         let overlayText = doc.getAnonymousElementByAttribute(plugin, "class", "msg msgClickToPlay");
         overlayText.textContent = messageString;
         if (eventType == "PluginVulnerableUpdatable" ||
             eventType == "PluginVulnerableNoUpdate") {
           let vulnerabilityString = gNavigatorBundle.getString(eventType);
           let vulnerabilityText = doc.getAnonymousElementByAttribute(plugin, "anonid", "vulnerabilityStatus");
           vulnerabilityText.textContent = vulnerabilityString;
@@ -229,18 +227,18 @@ var gPluginHandler = {
 
       case "PluginDisabled":
         let manageLink = doc.getAnonymousElementByAttribute(plugin, "class", "managePluginsLink");
         self.addLinkClickCallback(manageLink, "managePlugins");
         break;
 
       case "PluginScripted":
         let browser = gBrowser.getBrowserForDocument(doc.defaultView.top.document);
-        if (browser._pluginScriptedState == PLUGIN_SCRIPTED_STATE_NONE) {
-          browser._pluginScriptedState = PLUGIN_SCRIPTED_STATE_FIRED;
+        if (browser._pluginScriptedState == this.PLUGIN_SCRIPTED_STATE_NONE) {
+          browser._pluginScriptedState = this.PLUGIN_SCRIPTED_STATE_FIRED;
           setTimeout(function() {
             gPluginHandler.handlePluginScripted(this);
           }.bind(browser), 500);
         }
         break;
     }
 
     // Hide the in-content UI if it's too big. The crashed plugin handler already did this.
@@ -280,17 +278,17 @@ var gPluginHandler = {
 
     let notification = PopupNotifications.getNotification("click-to-play-plugins", aBrowser);
     if (notification && !haveVisibleCTPPlugin && !this._notificationDisplayedOnce) {
       notification.dismissed = false;
       PopupNotifications._update(notification.anchorElement);
       this._notificationDisplayedOnce = true;
     }
 
-    aBrowser._pluginScriptedState = PLUGIN_SCRIPTED_STATE_DONE;
+    aBrowser._pluginScriptedState = this.PLUGIN_SCRIPTED_STATE_DONE;
   },
 
   isKnownPlugin: function PH_isKnownPlugin(objLoadingContent) {
     return (objLoadingContent.getContentTypeForMIMEType(objLoadingContent.actualType) ==
             Ci.nsIObjectLoadingContent.TYPE_PLUGIN);
   },
 
   canActivatePlugin: function PH_canActivatePlugin(objLoadingContent) {
@@ -371,17 +369,17 @@ var gPluginHandler = {
     // reload the browser to make the new plugin show.
     browser.reload();
   },
 
   // Callback for user clicking on a missing (unsupported) plugin.
   installSinglePlugin: function (plugin) {
     var missingPlugins = new Map();
 
-    var pluginInfo = getPluginInfo(plugin);
+    var pluginInfo = this._getPluginInfo(plugin);
     missingPlugins.set(pluginInfo.mimetype, pluginInfo);
 
     openDialog("chrome://mozapps/content/plugins/pluginInstallerWizard.xul",
                "PFSWindow", "chrome,centerscreen,resizable=yes",
                {plugins: missingPlugins, browser: gBrowser.selectedBrowser});
   },
 
   // Callback for user clicking on a disabled plugin
@@ -466,17 +464,17 @@ var gPluginHandler = {
       // lazy initialization of the iframe
       iframe = doc.createElementNS("http://www.w3.org/1999/xhtml", "iframe");
       iframe.className = "previewPluginContentFrame";
       previewContent.appendChild(iframe);
 
       // Force a style flush, so that we ensure our binding is attached.
       aPlugin.clientTop;
     }
-    let pluginInfo = getPluginInfo(aPlugin);
+    let pluginInfo = this._getPluginInfo(aPlugin);
     let playPreviewUri = "data:application/x-moz-playpreview;," + pluginInfo.mimetype;
     iframe.src = playPreviewUri;
 
     // MozPlayPlugin event can be dispatched from the extension chrome
     // code to replace the preview content with the native plugin
     previewContent.addEventListener("MozPlayPlugin", function playPluginHandler(aEvent) {
       if (!aEvent.isTrusted)
         return;
@@ -515,34 +513,34 @@ var gPluginHandler = {
   },
 
   /* Gets all plugins currently in the page of the given name */
   _getPluginsByName: function PH_getPluginsByName(aDOMWindowUtils, aName) {
     let plugins = [];
     for (let plugin of aDOMWindowUtils.plugins) {
       let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
       if (gPluginHandler.canActivatePlugin(objLoadingContent)) {
-        let pluginName = getPluginInfo(plugin).pluginName;
+        let pluginName = this._getPluginInfo(plugin).pluginName;
         if (aName == pluginName) {
           plugins.push(objLoadingContent);
         }
       }
     }
     return plugins;
   },
 
   _makeCenterActions: function PH_makeCenterActions(aBrowser) {
     let contentWindow = aBrowser.contentWindow;
     let cwu = contentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
                            .getInterface(Ci.nsIDOMWindowUtils);
     let pluginsDictionary = new Map();
     for (let plugin of cwu.plugins) {
       let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
       if (gPluginHandler.canActivatePlugin(objLoadingContent)) {
-        let pluginName = getPluginInfo(plugin).pluginName;
+        let pluginName = this._getPluginInfo(plugin).pluginName;
         if (!pluginsDictionary.has(pluginName))
           pluginsDictionary.set(pluginName, []);
         pluginsDictionary.get(pluginName).push(objLoadingContent);
       }
     }
 
     let centerActions = [];
     for (let [pluginName, namedPluginArray] of pluginsDictionary) {
@@ -665,17 +663,17 @@ var gPluginHandler = {
 
   // event listener for missing/blocklisted/outdated/carbonFailure plugins.
   pluginUnavailable: function (plugin, eventType) {
     let browser = gBrowser.getBrowserForDocument(plugin.ownerDocument
                                                        .defaultView.top.document);
     if (!browser.missingPlugins)
       browser.missingPlugins = new Map();
 
-    var pluginInfo = getPluginInfo(plugin);
+    var pluginInfo = this._getPluginInfo(plugin);
     browser.missingPlugins.set(pluginInfo.mimetype, pluginInfo);
 
     var notificationBox = gBrowser.getNotificationBox(browser);
 
     // Should only display one of these warnings per page.
     // In order of priority, they are: outdated > missing > blocklisted
     let outdatedNotification = notificationBox.getNotificationWithValue("outdated-plugins");
     let blockedNotification  = notificationBox.getNotificationWithValue("blocked-plugins");
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -4515,17 +4515,17 @@ var TabsProgressListener = {
     // 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;
+        aBrowser._pluginScriptedState = gPluginHandler.PLUGIN_SCRIPTED_STATE_NONE;
       }
       FullZoom.onLocationChange(aLocationURI, false, aBrowser);
     }
   },
 
   onRefreshAttempted: function (aBrowser, aWebProgress, aURI, aDelay, aSameURI) {
     if (gPrefService.getBoolPref("accessibility.blockautorefresh")) {
       let brandBundle = document.getElementById("bundle_brand");
--- a/browser/base/content/test/browser_clickToPlayPluginScriptAccessPopup.js
+++ b/browser/base/content/test/browser_clickToPlayPluginScriptAccessPopup.js
@@ -94,17 +94,17 @@ function testNoEventFired() {
 }
 
 function testExpectNoPopupPart1() {
   var condition = function() gPluginScriptedFired;
   waitForCondition(condition, testExpectNoPopupPart2, "waited too long for PluginScripted event (" + getCurrentTestLocation() + ")");
 }
 
 function testExpectNoPopupPart2() {
-  var condition = function() gTestBrowser._pluginScriptedState == PLUGIN_SCRIPTED_STATE_DONE;
+  var condition = function() gTestBrowser._pluginScriptedState == gPluginHandler.PLUGIN_SCRIPTED_STATE_DONE;
   waitForCondition(condition, testExpectNoPopupPart3, "waited too long for PluginScripted event handling (" + getCurrentTestLocation() + ")");
 }
 
 function testExpectNoPopupPart3() {
   var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
   ok(notification, "should have a click-to-play notification (" + getCurrentTestLocation() + ")");
   ok(notification.dismissed, "notification should not be showing (" + getCurrentTestLocation() + ")");