Bug 1370832 - Remove PluginProvider Hash calculation for plugin name/desc; r=bsmedberg
PluginProvider used NSS to create an MD5 hash for plugin
identification. This would bring NSS up on startup, causing a
noticable slowdown. Since we're down to only allowing one plugin, we
can concatenate the description and name and call that good enough.
MozReview-Commit-ID: 5XmeyYktvNC
--- a/toolkit/mozapps/extensions/internal/PluginProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/PluginProvider.jsm
@@ -23,39 +23,16 @@ const FLASH_MIME_TYPE = "applicat
Cu.import("resource://gre/modules/Log.jsm");
const LOGGER_ID = "addons.plugins";
// Create a new logger for use by the Addons Plugin Provider
// (Requires AddonManager.jsm)
var logger = Log.repository.getLogger(LOGGER_ID);
-function getIDHashForString(aStr) {
- // return the two-digit hexadecimal code for a byte
- let toHexString = charCode => ("0" + charCode.toString(16)).slice(-2);
-
- let hasher = Cc["@mozilla.org/security/hash;1"].
- createInstance(Ci.nsICryptoHash);
- hasher.init(Ci.nsICryptoHash.MD5);
- let stringStream = Cc["@mozilla.org/io/string-input-stream;1"].
- createInstance(Ci.nsIStringInputStream);
- stringStream.data = aStr ? aStr : "null";
- hasher.updateFromStream(stringStream, -1);
-
- // convert the binary hash data to a hex string.
- let binary = hasher.finish(false);
- let hash = Array.from(binary, c => toHexString(c.charCodeAt(0)));
- hash = hash.join("").toLowerCase();
- return "{" + hash.substr(0, 8) + "-" +
- hash.substr(8, 4) + "-" +
- hash.substr(12, 4) + "-" +
- hash.substr(16, 4) + "-" +
- hash.substr(20) + "}";
-}
-
var PluginProvider = {
get name() {
return "PluginProvider";
},
// A dictionary mapping IDs to names and descriptions
plugins: null,
@@ -192,17 +169,17 @@ var PluginProvider = {
let list = {};
let seenPlugins = {};
for (let tag of tags) {
if (!(tag.name in seenPlugins))
seenPlugins[tag.name] = {};
if (!(tag.description in seenPlugins[tag.name])) {
let plugin = {
- id: getIDHashForString(tag.name + tag.description),
+ id: tag.name + tag.description,
name: tag.name,
description: tag.description,
tags: [tag]
};
seenPlugins[tag.name][tag.description] = plugin;
list[plugin.id] = plugin;
} else {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_pluginchange.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_pluginchange.js
@@ -1,16 +1,14 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
const LIST_UPDATED_TOPIC = "plugins-list-updated";
-// We need to use the same algorithm for generating IDs for plugins
-var { getIDHashForString } = Components.utils.import("resource://gre/modules/addons/PluginProvider.jsm", {});
var { MockRegistrar } = Components.utils.import("resource://testing-common/MockRegistrar.jsm", {});
function PluginTag(name, description) {
this.name = name;
this.description = description;
}
PluginTag.prototype = {
@@ -116,17 +114,17 @@ function run_test_2() {
run_test_3();
});
}
// Tests that a newly detected plugin shows up in the API and sends out events
function run_test_3() {
let tag = new PluginTag("Quicktime", "A mock Quicktime plugin");
PLUGINS.push(tag);
- let id = getIDHashForString(tag.name + tag.description);
+ let id = tag.name + tag.description;
let test_params = {};
test_params[id] = [
["onInstalling", false],
"onInstalled"
];
prepare_test(test_params, [
@@ -151,17 +149,17 @@ function run_test_3() {
run_test_4();
});
}
// Tests that a removed plugin disappears from in the API and sends out events
function run_test_4() {
let tag = PLUGINS.splice(1, 1)[0];
- let id = getIDHashForString(tag.name + tag.description);
+ let id = tag.name + tag.description;
let test_params = {};
test_params[id] = [
["onUninstalling", false],
"onUninstalled"
];
prepare_test(test_params);
@@ -209,21 +207,21 @@ function run_test_5() {
// Replacing flash should be detected
function run_test_6() {
let oldTag = PLUGINS.splice(0, 1)[0];
let newTag = new PluginTag("Flash 2", "A new crash-free Flash!");
newTag.disabled = true;
PLUGINS.push(newTag);
let test_params = {};
- test_params[getIDHashForString(oldTag.name + oldTag.description)] = [
+ test_params[oldTag.name + oldTag.description] = [
["onUninstalling", false],
"onUninstalled"
];
- test_params[getIDHashForString(newTag.name + newTag.description)] = [
+ test_params[newTag.name + newTag.description] = [
["onInstalling", false],
"onInstalled"
];
prepare_test(test_params, [
"onExternalInstall"
]);
@@ -248,21 +246,21 @@ function run_test_6() {
// If new tags are detected and the disabled state changes then we should send
// out appropriate notifications
function run_test_7() {
PLUGINS[0] = new PluginTag("Quicktime", "A mock Quicktime plugin");
PLUGINS[0].disabled = true;
PLUGINS[1] = new PluginTag("Flash 2", "A new crash-free Flash!");
let test_params = {};
- test_params[getIDHashForString(PLUGINS[0].name + PLUGINS[0].description)] = [
+ test_params[PLUGINS[0].name + PLUGINS[0].description] = [
["onDisabling", false],
"onDisabled"
];
- test_params[getIDHashForString(PLUGINS[1].name + PLUGINS[1].description)] = [
+ test_params[PLUGINS[1].name + PLUGINS[1].description] = [
["onEnabling", false],
"onEnabled"
];
prepare_test(test_params);
Services.obs.notifyObservers(null, LIST_UPDATED_TOPIC);