Bug 1685801: Part 11 - Move makeNicePluginName out of BrowserUtils. r=handyman

It will mostly not be used. This patch just duplicates it in the two modules
that use it since it's not long for this world, anyway.

Differential Revision: https://phabricator.services.mozilla.com/D101491
This commit is contained in:
Kris Maglione 2021-01-28 03:33:07 +00:00
Родитель bde014e0c3
Коммит de80dda2f5
3 изменённых файлов: 65 добавлений и 40 удалений

Просмотреть файл

@ -9,9 +9,6 @@ var EXPORTED_SYMBOLS = ["PluginChild"];
const { AppConstants } = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);
const { BrowserUtils } = ChromeUtils.import(
"resource://gre/modules/BrowserUtils.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
@ -44,6 +41,37 @@ const OVERLAY_DISPLAY = {
// definition.
const kSubmitMsg = "PluginParent:NPAPIPluginCrashReportSubmitted";
/**
* Map the plugin's name to a filtered version more suitable for UI.
*
* N.B. This should be completely dead code at this point.
*
* @param aName The full-length name string of the plugin.
* @return the simplified name string.
*/
function makeNicePluginName(aName) {
if (aName == "Shockwave Flash") {
return "Adobe Flash";
}
// Regex checks if aName begins with "Java" + non-letter char
if (/^Java\W/.test(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;
}
class PluginChild extends JSWindowActorChild {
constructor() {
super();
@ -139,7 +167,7 @@ class PluginChild extends JSWindowActorChild {
_getPluginInfo(pluginElement) {
if (this.isKnownPlugin(pluginElement)) {
let pluginTag = gPluginHost.getPluginTagForType(pluginElement.actualType);
let pluginName = BrowserUtils.makeNicePluginName(pluginTag.name);
let pluginName = makeNicePluginName(pluginTag.name);
let fallbackType = pluginElement.defaultFallbackType;
let permissionString = gPluginHost.getPermissionStringForType(
pluginElement.actualType
@ -169,7 +197,7 @@ class PluginChild extends JSWindowActorChild {
// nsIObjectLoadingContent to check.
let fallbackType = Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY;
if (pluginTag) {
let pluginName = BrowserUtils.makeNicePluginName(pluginTag.name);
let pluginName = makeNicePluginName(pluginTag.name);
let permissionString = gPluginHost.getPermissionStringForTag(pluginTag);
return { pluginTag, pluginName, permissionString, fallbackType };
}

Просмотреть файл

@ -22,11 +22,6 @@ XPCOMUtils.defineLazyServiceGetter(
"nsIPluginHost"
);
ChromeUtils.defineModuleGetter(
this,
"BrowserUtils",
"resource://gre/modules/BrowserUtils.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"CrashSubmit",
@ -47,6 +42,37 @@ const {
PLUGIN_CLICK_TO_PLAY_QUIET,
} = Ci.nsIObjectLoadingContent;
/**
* Map the plugin's name to a filtered version more suitable for UI.
*
* N.B. This should be completely dead code at this point.
*
* @param aName The full-length name string of the plugin.
* @return the simplified name string.
*/
function makeNicePluginName(aName) {
if (aName == "Shockwave Flash") {
return "Adobe Flash";
}
// Regex checks if aName begins with "Java" + non-letter char
if (/^Java\W/.test(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;
}
const PluginManager = {
_initialized: false,
@ -129,7 +155,7 @@ const PluginManager = {
let runID = propertyBag.getPropertyAsUint32("runID");
let uglyPluginName = propertyBag.getPropertyAsAString("pluginName");
let pluginName = BrowserUtils.makeNicePluginName(uglyPluginName);
let pluginName = makeNicePluginName(uglyPluginName);
let pluginDumpID = propertyBag.getPropertyAsAString("pluginDumpID");
let state;

Просмотреть файл

@ -127,35 +127,6 @@ var BrowserUtils = {
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(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;
},
/**
* Returns true if |mimeType| is text-based, or false otherwise.
*