Bug 1362224: Cached normalized object for simple icon URLs. r?aswan
MozReview-Commit-ID: ErFFdfKAtuz
--- a/toolkit/components/extensions/ExtensionUtils.jsm
+++ b/toolkit/components/extensions/ExtensionUtils.jsm
@@ -318,26 +318,46 @@ class SpreadArgs extends Array {
super();
this.push(...args);
}
}
// Manages icon details for toolbar buttons in the |pageAction| and
// |browserAction| APIs.
let IconDetails = {
+ iconCache: new DefaultWeakMap(() => new Map()),
+
// Normalizes the various acceptable input formats into an object
// with icon size as key and icon URL as value.
//
// If a context is specified (function is called from an extension):
// Throws an error if an invalid icon size was provided or the
// extension is not allowed to load the specified resources.
//
// If no context is specified, instead of throwing an error, this
// function simply logs a warning message.
normalize(details, extension, context = null) {
+ if (!details.imageData && typeof details.path === "string") {
+ let icons = this.iconCache.get(extension);
+
+ let baseURI = context ? context.uri : extension.baseURI;
+ let url = baseURI.resolve(details.path);
+
+ let icon = icons.get(url);
+ if (!icon) {
+ icon = this._normalize(details, extension, context);
+ icons.set(url, icon);
+ }
+ return icon;
+ }
+
+ return this._normalize(details, extension, context);
+ },
+
+ _normalize(details, extension, context = null) {
let result = {};
try {
if (details.imageData) {
let imageData = details.imageData;
if (typeof imageData == "string") {
imageData = {"19": imageData};