Bug 1330369 - Part 1 - Share the extension stylesheets between sidebar, popups, and options r?mixedpuppy
MozReview-Commit-ID: EquM6hSQ8pH
--- a/browser/components/extensions/ExtensionPopups.jsm
+++ b/browser/components/extensions/ExtensionPopups.jsm
@@ -19,16 +19,17 @@ XPCOMUtils.defineLazyModuleGetter(this,
XPCOMUtils.defineLazyModuleGetter(this, "setTimeout",
"resource://gre/modules/Timer.jsm");
Cu.import("resource://gre/modules/AppConstants.jsm");
Cu.import("resource://gre/modules/ExtensionUtils.jsm");
var {
DefaultWeakMap,
+ extensionStylesheets,
promiseEvent,
} = ExtensionUtils;
const POPUP_LOAD_TIMEOUT_MS = 200;
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
@@ -45,25 +46,16 @@ function promisePopupShown(popup) {
} else {
popup.addEventListener("popupshown", function(event) {
resolve();
}, {once: true});
}
});
}
-XPCOMUtils.defineLazyGetter(this, "popupStylesheets", () => {
- let stylesheets = ["chrome://browser/content/extension.css"];
-
- if (AppConstants.platform === "macosx") {
- stylesheets.push("chrome://browser/content/extension-mac.css");
- }
- return stylesheets;
-});
-
XPCOMUtils.defineLazyGetter(this, "standaloneStylesheets", () => {
let stylesheets = [];
if (AppConstants.platform === "macosx") {
stylesheets.push("chrome://browser/content/extension-mac-panel.css");
}
if (AppConstants.platform === "win") {
stylesheets.push("chrome://browser/content/extension-win-panel.css");
@@ -163,17 +155,17 @@ class BasePopup {
get DESTROY_EVENT() {
throw new Error("Not implemented");
}
get STYLESHEETS() {
let sheets = [];
if (this.browserStyle) {
- sheets.push(...popupStylesheets);
+ sheets.push(...extensionStylesheets);
}
if (!this.fixedWidth) {
sheets.push(...standaloneStylesheets);
}
return sheets;
}
--- a/toolkit/components/extensions/ExtensionUtils.jsm
+++ b/toolkit/components/extensions/ExtensionUtils.jsm
@@ -788,16 +788,30 @@ function normalizeTime(date) {
}
const stylesheetMap = new DefaultMap(url => {
let uri = Services.io.newURI(url);
return styleSheetService.preloadSheet(uri, styleSheetService.AGENT_SHEET);
});
/**
+ * Retreives the browser_style stylesheets needed for extension popups and sidebars.
+ * @returns {Array<string>} an array of stylesheets needed for the current platform.
+ */
+function extensionStylesheets() {
+ let stylesheets = ["chrome://browser/content/extension.css"];
+
+ if (AppConstants.platform === "macosx") {
+ stylesheets.push("chrome://browser/content/extension-mac.css");
+ }
+
+ return stylesheets;
+}
+
+/**
* Defines a lazy getter for the given property on the given object. The
* first time the property is accessed, the return value of the getter
* is defined on the current `this` object with the given property name.
* Importantly, this means that a lazy getter defined on an object
* prototype will be invoked separately for each object instance that
* it's accessed on.
*
* @param {object} object
@@ -1084,9 +1098,10 @@ this.ExtensionUtils = {
ExtensionError,
IconDetails,
LimitedSet,
MessageManagerProxy,
SpreadArgs,
StartupCache,
};
+XPCOMUtils.defineLazyGetter(this.ExtensionUtils, "extensionStylesheets", extensionStylesheets);
XPCOMUtils.defineLazyGetter(this.ExtensionUtils, "PlatformInfo", PlatformInfo);
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -68,16 +68,21 @@ const SEARCH_SCORE_MATCH_SUBSTRING = 3;
const UPDATES_RECENT_TIMESPAN = 2 * 24 * 3600000; // 2 days (in milliseconds)
const UPDATES_RELEASENOTES_TRANSFORMFILE = "chrome://mozapps/content/extensions/updateinfo.xsl";
const XMLURI_PARSE_ERROR = "http://www.mozilla.org/newlayout/xml/parsererror.xml"
var gViewDefault = "addons://discover/";
+XPCOMUtils.defineLazyGetter(this, "extensionStylesheets", () => {
+ const {ExtensionUtils} = Cu.import("resource://gre/modules/ExtensionUtils.jsm", {});
+ return ExtensionUtils.extensionStylesheets;
+});
+
var gStrings = {};
XPCOMUtils.defineLazyServiceGetter(gStrings, "bundleSvc",
"@mozilla.org/intl/stringbundle;1",
"nsIStringBundleService");
XPCOMUtils.defineLazyGetter(gStrings, "brand", function() {
return this.bundleSvc.createBundle("chrome://branding/locale/brand.properties");
});
@@ -90,23 +95,16 @@ XPCOMUtils.defineLazyGetter(gStrings, "d
XPCOMUtils.defineLazyGetter(gStrings, "brandShortName", function() {
return this.brand.GetStringFromName("brandShortName");
});
XPCOMUtils.defineLazyGetter(gStrings, "appVersion", function() {
return Services.appinfo.version;
});
-XPCOMUtils.defineLazyGetter(this, "gInlineOptionsStylesheets", () => {
- let stylesheets = ["chrome://browser/content/extension.css"];
- if (AppConstants.platform === "macosx") {
- stylesheets.push("chrome://browser/content/extension-mac.css");
- }
- return stylesheets;
-});
XPCOMUtils.defineLazyPreferenceGetter(this, "legacyWarningExceptions",
PREF_LEGACY_EXCEPTIONS, "",
raw => raw.split(","));
document.addEventListener("load", initialize, true);
window.addEventListener("unload", shutdown);
@@ -3704,17 +3702,17 @@ var gDetailView = {
mm.addMessageListener("Extension:BrowserResized", messageListener);
let browserOptions = {
fixedWidth: true,
isInline: true,
};
if (this._addon.optionsBrowserStyle) {
- browserOptions.stylesheets = gInlineOptionsStylesheets;
+ browserOptions.stylesheets = extensionStylesheets;
}
mm.sendAsyncMessage("Extension:InitBrowser", browserOptions);
browser.loadURI(optionsURL);
});
},