Bug 1074976 - Move function makeNicePluginName() into BroswerUtils.jsm module. r=felipe
authorMike Quested <bruteforks@gmail.com>
Mon, 06 Oct 2014 11:40:00 -0400
changeset 209989 a86a4468774af87c4c8a8e4627ef9b961880af6e
parent 209988 412cf5315d9f37d7bed210d5b30423de8efb07f9
child 209990 bc2f5abcf051f1bb649e62d1aade3a3049836646
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersfelipe
bugs1074976
milestone35.0a1
Bug 1074976 - Move function makeNicePluginName() into BroswerUtils.jsm module. r=felipe
browser/base/content/pageinfo/permissions.js
browser/modules/PluginContent.jsm
toolkit/modules/BrowserUtils.jsm
--- a/browser/base/content/pageinfo/permissions.js
+++ b/browser/base/content/pageinfo/permissions.js
@@ -1,13 +1,14 @@
 /* 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/. */
 
 Components.utils.import("resource:///modules/SitePermissions.jsm");
+Components.utils.import("resource://gre/modules/BrowserUtils.jsm");
 
 const nsIQuotaManager = Components.interfaces.nsIQuotaManager;
 
 var gPermURI;
 var gUsageRequest;
 
 var gPermissions = SitePermissions.listPermissions();
 gPermissions.push("plugins");
@@ -226,30 +227,16 @@ function onIndexedDBUsageCallback(uri, u
     status.value =
       gBundle.getFormattedString("indexedDBUsage",
                                  DownloadUtils.convertByteUnits(usage));
     status.removeAttribute("hidden");
     button.removeAttribute("hidden");
   }
 }
 
-// XXX copied this from browser-plugins.js - is there a way to share?
-function makeNicePluginName(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
-  // removing "Plugin" (and then trimming to get rid of any whitespace).
-  // (Otherwise, something like "Java(TM) Plug-in 1.7.0_07" gets mangled)
-  let newName = aName.replace(/[\s\d\.\-\_\(\)]+$/, "").replace(/\bplug-?in\b/i, "").trim();
-  return newName;
-}
-
 function fillInPluginPermissionTemplate(aPluginName, aPermissionString) {
   let permPluginTemplate = document.getElementById("permPluginTemplate").cloneNode(true);
   permPluginTemplate.setAttribute("permString", aPermissionString);
   let attrs = [
     [ ".permPluginTemplateLabel", "value", aPluginName ],
     [ ".permPluginTemplateRadioGroup", "id", aPermissionString + "RadioGroup" ],
     [ ".permPluginTemplateRadioDefault", "id", aPermissionString + "#0" ],
     [ ".permPluginTemplateRadioAsk", "id", aPermissionString + "#3" ],
@@ -283,17 +270,17 @@ function initPluginsRow() {
 
   for (let plugin of pluginHost.getPluginTags()) {
     if (plugin.disabled) {
       continue;
     }
     for (let mimeType of plugin.getMimeTypes()) {
       let permString = pluginHost.getPermissionStringForType(mimeType);
       if (!permissionMap.has(permString)) {
-        var name = makeNicePluginName(plugin.name);
+        let name = BrowserUtils.makeNicePluginName(plugin.name);
         if (permString.startsWith("plugin-vulnerable:")) {
           name += " \u2014 " + vulnerableLabel;
         }
         permissionMap.set(permString, name);
       }
     }
   }
 
--- a/browser/modules/PluginContent.jsm
+++ b/browser/modules/PluginContent.jsm
@@ -9,16 +9,17 @@ let Cc = Components.classes;
 let Ci = Components.interfaces;
 let Cu = Components.utils;
 
 this.EXPORTED_SYMBOLS = [ "PluginContent" ];
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/Timer.jsm");
+Cu.import("resource://gre/modules/BrowserUtils.jsm");
 
 XPCOMUtils.defineLazyGetter(this, "gNavigatorBundle", function() {
   const url = "chrome://browser/locale/browser.properties";
   return Services.strings.createBundle(url);
 });
 
 this.PluginContent = function (global) {
   this.init(global);
@@ -114,17 +115,17 @@ PluginContent.prototype = {
 
     tagMimetype = pluginElement.actualType;
     if (tagMimetype == "") {
       tagMimetype = pluginElement.type;
     }
 
     if (this.isKnownPlugin(pluginElement)) {
       pluginTag = pluginHost.getPluginTagForType(pluginElement.actualType);
-      pluginName = this.makeNicePluginName(pluginTag.name);
+      pluginName = BrowserUtils.makeNicePluginName(pluginTag.name);
 
       permissionString = pluginHost.getPermissionStringForType(pluginElement.actualType);
       fallbackType = pluginElement.defaultFallbackType;
       blocklistState = pluginHost.getBlocklistStateForType(pluginElement.actualType);
       // Make state-softblocked == state-notblocked for our purposes,
       // they have the same UI. STATE_OUTDATED should not exist for plugin
       // items, but let's alias it anyway, just in case.
       if (blocklistState == Ci.nsIBlocklistService.STATE_SOFTBLOCKED ||
@@ -137,36 +138,16 @@ PluginContent.prototype = {
              pluginName: pluginName,
              pluginTag: pluginTag,
              permissionString: permissionString,
              fallbackType: fallbackType,
              blocklistState: blocklistState,
            };
   },
 
-  // Map the plugin's name to a filtered version more suitable for user UI.
-  makeNicePluginName : function (aName) {
-    if (aName == "Shockwave Flash")
-      return "Adobe Flash";
-    // Regex checks if aName begins with "Java" + non-letter char
-    if (/^Java\W/.exec(aName))
-      return "Java";
-
-    // Clean up the plugin name by stripping off parenthetical clauses,
-    // trailing version numbers or "plugin".
-    // EG, "Foo Bar (Linux) Plugin 1.23_02" --> "Foo Bar"
-    // Do this by first stripping the numbers, etc. off the end, and then
-    // removing "Plugin" (and then trimming to get rid of any whitespace).
-    // (Otherwise, something like "Java(TM) Plug-in 1.7.0_07" gets mangled)
-    let newName = aName.replace(/\(.*?\)/g, "").
-                        replace(/[\s\d\.\-\_\(\)]+$/, "").
-                        replace(/\bplug-?in\b/i, "").trim();
-    return newName;
-  },
-
   /**
    * Update the visibility of the plugin overlay.
    */
   setVisibility : function (plugin, overlay, shouldShow) {
     overlay.classList.toggle("visible", shouldShow);
   },
 
   /**
@@ -838,17 +819,17 @@ PluginContent.prototype = {
     try {
       gmpPlugin = propBag.getPropertyAsBool("gmpPlugin");
     } catch (e) {
       // This property is only set for GMP plugins.
     }
 
     // For non-GMP plugins, remap the plugin name to a more user-presentable form.
     if (!gmpPlugin) {
-      pluginName = this.makeNicePluginName(pluginName);
+      pluginName = BrowserUtils.makeNicePluginName(pluginName);
     }
 
     let messageString = gNavigatorBundle.formatStringFromName("crashedpluginsMessage.title", [pluginName], 1);
 
     let plugin = null, doc;
     if (target instanceof Ci.nsIObjectLoadingContent) {
       plugin = target;
       doc = plugin.ownerDocument;
--- a/toolkit/modules/BrowserUtils.jsm
+++ b/toolkit/modules/BrowserUtils.jsm
@@ -174,9 +174,34 @@ this.BrowserUtils = {
     // Special case: ignore "www" prefix if it is part of host string
     let [longHost, shortHost] =
       linkHost.length > docHost.length ? [linkHost, docHost] : [docHost, linkHost];
     if (longHost == "www." + shortHost)
       return originalTarget;
 
     return "_blank";
   },
+
+  /**
+   * Map the plugin's name to a filtered version more suitable for UI.
+   *
+   * @param aName The full-length name string of the plugin.
+   * @return the simplified name string.
+   */
+  makeNicePluginName: function (aName) {
+    if (aName == "Shockwave Flash")
+      return "Adobe Flash";
+    // Regex checks if aName begins with "Java" + non-letter char
+    if (/^Java\W/.exec(aName))
+      return "Java";
+
+    // Clean up the plugin name by stripping off parenthetical clauses,
+    // trailing version numbers or "plugin".
+    // EG, "Foo Bar (Linux) Plugin 1.23_02" --> "Foo Bar"
+    // Do this by first stripping the numbers, etc. off the end, and then
+    // removing "Plugin" (and then trimming to get rid of any whitespace).
+    // (Otherwise, something like "Java(TM) Plug-in 1.7.0_07" gets mangled)
+    let newName = aName.replace(/\(.*?\)/g, "").
+                        replace(/[\s\d\.\-\_\(\)]+$/, "").
+                        replace(/\bplug-?in\b/i, "").trim();
+    return newName;
+  },
 };