Bug 1511276 - Add UserAgentStyleSheetList.h and use it to simplify nsLayoutStylesheetCache. r=emilio
authorCameron McCormack <cam@mcc.id.au>
Wed, 05 Dec 2018 20:08:35 +0000
changeset 449469 48eb1f0778e6ea78ef272b1a7103d8f227f16d5e
parent 449468 3f5a132b7e4f7579209ca906f9ec79059e426f26
child 449470 e743bb11887dd30522a13ca6b04b1cd0040beedd
push id35164
push usershindli@mozilla.com
push dateThu, 06 Dec 2018 04:02:49 +0000
treeherdermozilla-central@d932537fec3b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1511276
milestone65.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 1511276 - Add UserAgentStyleSheetList.h and use it to simplify nsLayoutStylesheetCache. r=emilio Differential Revision: https://phabricator.services.mozilla.com/D13585
layout/style/UserAgentStyleSheetList.h
layout/style/moz.build
layout/style/nsLayoutStylesheetCache.cpp
layout/style/nsLayoutStylesheetCache.h
new file mode 100644
--- /dev/null
+++ b/layout/style/UserAgentStyleSheetList.h
@@ -0,0 +1,35 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* list of user agent style sheets that nsLayoutStylesheetCache manages */
+
+/*
+ * STYLE_SHEET(identifier_, url_, lazy_)
+ *
+ * identifier_
+ *   An identifier for the style sheet, suitable for use as an enum class value.
+ *
+ * url_
+ *   The URL of the style sheet.
+ *
+ * lazy_
+ *   A boolean indicating whether the sheet is loaded lazily.
+ */
+
+STYLE_SHEET(ContentEditable, "resource://gre/res/contenteditable.css", true)
+STYLE_SHEET(CounterStyles, "resource://gre-resources/counterstyles.css", false)
+STYLE_SHEET(DesignMode, "resource://gre/res/designmode.css", true)
+STYLE_SHEET(Forms, "resource://gre-resources/forms.css", true)
+STYLE_SHEET(HTML, "resource://gre-resources/html.css", false)
+STYLE_SHEET(MathML, "resource://gre-resources/mathml.css", true)
+STYLE_SHEET(MinimalXUL, "chrome://global/content/minimal-xul.css", false)
+STYLE_SHEET(NoFrames, "resource://gre-resources/noframes.css", true)
+STYLE_SHEET(NoScript, "resource://gre-resources/noscript.css", true)
+STYLE_SHEET(Quirk, "resource://gre-resources/quirk.css", false)
+STYLE_SHEET(Scrollbars, "chrome://global/skin/scrollbars.css", true)
+STYLE_SHEET(SVG, "resource://gre/res/svg.css", false)
+STYLE_SHEET(UA, "resource://gre-resources/ua.css", true)
+STYLE_SHEET(XUL, "chrome://global/content/xul.css", true)
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -107,16 +107,17 @@ EXPORTS.mozilla += [
     'ServoUtils.h',
     'SheetType.h',
     'StyleAnimationValue.h',
     'StyleComplexColor.h',
     'StyleSheet.h',
     'StyleSheetInfo.h',
     'StyleSheetInlines.h',
     'URLExtraData.h',
+    'UserAgentStyleSheetList.h',
 ]
 
 EXPORTS.mozilla.dom += [
     'CSS.h',
     'CSSCounterStyleRule.h',
     'CSSFontFaceRule.h',
     'CSSFontFeatureValuesRule.h',
     'CSSImportRule.h',
--- a/layout/style/nsLayoutStylesheetCache.cpp
+++ b/layout/style/nsLayoutStylesheetCache.cpp
@@ -54,103 +54,34 @@ nsresult nsLayoutStylesheetCache::Observ
     mScrollbarsSheet = nullptr;
     mFormsSheet = nullptr;
   } else {
     MOZ_ASSERT_UNREACHABLE("Unexpected observer topic.");
   }
   return NS_OK;
 }
 
-StyleSheet* nsLayoutStylesheetCache::ScrollbarsSheet() {
-  if (!mScrollbarsSheet) {
-    // Scrollbars don't need access to unsafe rules
-    LoadSheetURL("chrome://global/skin/scrollbars.css", &mScrollbarsSheet,
-                 eSafeAgentSheetFeatures, eCrash);
+#define STYLE_SHEET(identifier_, url_, lazy_)                                  \
+  StyleSheet* nsLayoutStylesheetCache::identifier_##Sheet() {                  \
+    if (lazy_ && !m##identifier_##Sheet) {                                     \
+      LoadSheetURL(url_, &m##identifier_##Sheet, eAgentSheetFeatures, eCrash); \
+    }                                                                          \
+    return m##identifier_##Sheet;                                              \
   }
-
-  return mScrollbarsSheet;
-}
-
-StyleSheet* nsLayoutStylesheetCache::FormsSheet() {
-  if (!mFormsSheet) {
-    // forms.css needs access to unsafe rules
-    LoadSheetURL("resource://gre-resources/forms.css", &mFormsSheet,
-                 eAgentSheetFeatures, eCrash);
-  }
-
-  return mFormsSheet;
-}
+#include "mozilla/UserAgentStyleSheetList.h"
+#undef STYLE_SHEET
 
 StyleSheet* nsLayoutStylesheetCache::UserContentSheet() {
   return mUserContentSheet;
 }
 
 StyleSheet* nsLayoutStylesheetCache::UserChromeSheet() {
   return mUserChromeSheet;
 }
 
-StyleSheet* nsLayoutStylesheetCache::UASheet() {
-  if (!mUASheet) {
-    LoadSheetURL("resource://gre-resources/ua.css", &mUASheet,
-                 eAgentSheetFeatures, eCrash);
-  }
-
-  return mUASheet;
-}
-
-StyleSheet* nsLayoutStylesheetCache::HTMLSheet() { return mHTMLSheet; }
-
-StyleSheet* nsLayoutStylesheetCache::MinimalXULSheet() {
-  return mMinimalXULSheet;
-}
-
-StyleSheet* nsLayoutStylesheetCache::XULSheet() {
-  if (!mXULSheet) {
-    LoadSheetURL("chrome://global/content/xul.css", &mXULSheet,
-                 eAgentSheetFeatures, eCrash);
-  }
-
-  return mXULSheet;
-}
-
-StyleSheet* nsLayoutStylesheetCache::QuirkSheet() { return mQuirkSheet; }
-
-StyleSheet* nsLayoutStylesheetCache::SVGSheet() { return mSVGSheet; }
-
-StyleSheet* nsLayoutStylesheetCache::MathMLSheet() {
-  if (!mMathMLSheet) {
-    LoadSheetURL("resource://gre-resources/mathml.css", &mMathMLSheet,
-                 eAgentSheetFeatures, eCrash);
-  }
-
-  return mMathMLSheet;
-}
-
-StyleSheet* nsLayoutStylesheetCache::CounterStylesSheet() {
-  return mCounterStylesSheet;
-}
-
-StyleSheet* nsLayoutStylesheetCache::NoScriptSheet() {
-  if (!mNoScriptSheet) {
-    LoadSheetURL("resource://gre-resources/noscript.css", &mNoScriptSheet,
-                 eAgentSheetFeatures, eCrash);
-  }
-
-  return mNoScriptSheet;
-}
-
-StyleSheet* nsLayoutStylesheetCache::NoFramesSheet() {
-  if (!mNoFramesSheet) {
-    LoadSheetURL("resource://gre-resources/noframes.css", &mNoFramesSheet,
-                 eAgentSheetFeatures, eCrash);
-  }
-
-  return mNoFramesSheet;
-}
-
 StyleSheet* nsLayoutStylesheetCache::ChromePreferenceSheet(
     nsPresContext* aPresContext) {
   if (!mChromePreferenceSheet) {
     BuildPreferenceSheet(&mChromePreferenceSheet, aPresContext);
   }
 
   return mChromePreferenceSheet;
 }
@@ -159,34 +90,16 @@ StyleSheet* nsLayoutStylesheetCache::Con
     nsPresContext* aPresContext) {
   if (!mContentPreferenceSheet) {
     BuildPreferenceSheet(&mContentPreferenceSheet, aPresContext);
   }
 
   return mContentPreferenceSheet;
 }
 
-StyleSheet* nsLayoutStylesheetCache::ContentEditableSheet() {
-  if (!mContentEditableSheet) {
-    LoadSheetURL("resource://gre/res/contenteditable.css",
-                 &mContentEditableSheet, eAgentSheetFeatures, eCrash);
-  }
-
-  return mContentEditableSheet;
-}
-
-StyleSheet* nsLayoutStylesheetCache::DesignModeSheet() {
-  if (!mDesignModeSheet) {
-    LoadSheetURL("resource://gre/res/designmode.css", &mDesignModeSheet,
-                 eAgentSheetFeatures, eCrash);
-  }
-
-  return mDesignModeSheet;
-}
-
 void nsLayoutStylesheetCache::Shutdown() {
   gCSSLoader = nullptr;
   NS_WARNING_ASSERTION(!gStyleCache || !gUserContentSheetURL,
                        "Got the URL but never used?");
   gStyleCache = nullptr;
   gUserContentSheetURL = nullptr;
 }
 
@@ -209,34 +122,24 @@ nsLayoutStylesheetCache::CollectReports(
 }
 
 size_t nsLayoutStylesheetCache::SizeOfIncludingThis(
     mozilla::MallocSizeOf aMallocSizeOf) const {
   size_t n = aMallocSizeOf(this);
 
 #define MEASURE(s) n += s ? s->SizeOfIncludingThis(aMallocSizeOf) : 0;
 
+#define STYLE_SHEET(identifier_, url_, lazy_) MEASURE(m##identifier_##Sheet);
+#include "mozilla/UserAgentStyleSheetList.h"
+#undef STYLE_SHEET
+
   MEASURE(mChromePreferenceSheet);
-  MEASURE(mContentEditableSheet);
   MEASURE(mContentPreferenceSheet);
-  MEASURE(mCounterStylesSheet);
-  MEASURE(mDesignModeSheet);
-  MEASURE(mFormsSheet);
-  MEASURE(mHTMLSheet);
-  MEASURE(mMathMLSheet);
-  MEASURE(mMinimalXULSheet);
-  MEASURE(mNoFramesSheet);
-  MEASURE(mNoScriptSheet);
-  MEASURE(mQuirkSheet);
-  MEASURE(mSVGSheet);
-  MEASURE(mScrollbarsSheet);
-  MEASURE(mUASheet);
   MEASURE(mUserChromeSheet);
   MEASURE(mUserContentSheet);
-  MEASURE(mXULSheet);
 
   // Measurement of the following members may be added later if DMD finds it is
   // worthwhile:
   // - gCSSLoader
 
   return n;
 }
 
@@ -250,26 +153,23 @@ nsLayoutStylesheetCache::nsLayoutStylesh
     obsSvc->AddObserver(this, "chrome-flush-skin-caches", false);
     obsSvc->AddObserver(this, "chrome-flush-caches", false);
   }
 
   InitFromProfile();
 
   // And make sure that we load our UA sheets.  No need to do this
   // per-profile, since they're profile-invariant.
-  LoadSheetURL("resource://gre-resources/counterstyles.css",
-               &mCounterStylesSheet, eAgentSheetFeatures, eCrash);
-  LoadSheetURL("resource://gre-resources/html.css", &mHTMLSheet,
-               eAgentSheetFeatures, eCrash);
-  LoadSheetURL("chrome://global/content/minimal-xul.css", &mMinimalXULSheet,
-               eAgentSheetFeatures, eCrash);
-  LoadSheetURL("resource://gre-resources/quirk.css", &mQuirkSheet,
-               eAgentSheetFeatures, eCrash);
-  LoadSheetURL("resource://gre/res/svg.css", &mSVGSheet, eAgentSheetFeatures,
-               eCrash);
+#define STYLE_SHEET(identifier_, url_, lazy_)                                \
+  if (!lazy_) {                                                              \
+    LoadSheetURL(url_, &m##identifier_##Sheet, eAgentSheetFeatures, eCrash); \
+  }
+#include "mozilla/UserAgentStyleSheetList.h"
+#undef STYLE_SHEET
+
   if (XRE_IsParentProcess()) {
     // We know we need xul.css for the UI, so load that now too:
     XULSheet();
   }
 
   if (gUserContentSheetURL) {
     MOZ_ASSERT(XRE_IsContentProcess(), "Only used in content processes.");
     LoadSheet(gUserContentSheetURL, &mUserContentSheet, eUserSheetFeatures,
--- a/layout/style/nsLayoutStylesheetCache.h
+++ b/layout/style/nsLayoutStylesheetCache.h
@@ -33,34 +33,25 @@ enum FailureAction { eCrash = 0, eLogToC
 class nsLayoutStylesheetCache final : public nsIObserver,
                                       public nsIMemoryReporter {
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVER
   NS_DECL_NSIMEMORYREPORTER
 
   static nsLayoutStylesheetCache* Singleton();
 
-  mozilla::StyleSheet* ScrollbarsSheet();
-  mozilla::StyleSheet* FormsSheet();
+#define STYLE_SHEET(identifier_, url_, lazy_) \
+  mozilla::StyleSheet* identifier_##Sheet();
+#include "mozilla/UserAgentStyleSheetList.h"
+#undef STYLE_SHEET
+
   mozilla::StyleSheet* UserContentSheet();
   mozilla::StyleSheet* UserChromeSheet();
-  mozilla::StyleSheet* UASheet();
-  mozilla::StyleSheet* HTMLSheet();
-  mozilla::StyleSheet* MinimalXULSheet();
-  mozilla::StyleSheet* XULSheet();
-  mozilla::StyleSheet* QuirkSheet();
-  mozilla::StyleSheet* SVGSheet();
-  mozilla::StyleSheet* MathMLSheet();
-  mozilla::StyleSheet* CounterStylesSheet();
-  mozilla::StyleSheet* NoScriptSheet();
-  mozilla::StyleSheet* NoFramesSheet();
   mozilla::StyleSheet* ChromePreferenceSheet(nsPresContext* aPresContext);
   mozilla::StyleSheet* ContentPreferenceSheet(nsPresContext* aPresContext);
-  mozilla::StyleSheet* ContentEditableSheet();
-  mozilla::StyleSheet* DesignModeSheet();
 
   static void InvalidatePreferenceSheets();
 
   static void Shutdown();
 
   static void SetUserContentCSSURL(nsIURI* aURI);
 
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;