Bug 1330369 - Part 1 - Share the extension stylesheets between sidebar, popups, and options r=mixedpuppy
authorMatthew Wein <mwein@mozilla.com>
Fri, 19 May 2017 15:48:44 -0400
changeset 409111 163ef155b600a49c1799275d415eda74bdf5d3d2
parent 409110 9fcbe35118f1b3afdc97e1781a376411ef45fff4
child 409112 a766850786e747f8e1495992b07c8212c1ab3306
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1330369
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1330369 - Part 1 - Share the extension stylesheets between sidebar, popups, and options r=mixedpuppy MozReview-Commit-ID: EquM6hSQ8pH
browser/components/extensions/ExtensionPopups.jsm
toolkit/components/extensions/ExtensionUtils.jsm
toolkit/mozapps/extensions/content/extensions.js
--- 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);
     });
   },