Bug 1096808 - Reload ua.css when ruby pref changes. r=bzbarsky
authorCameron McCormack <cam@mcc.id.au>
Fri, 14 Nov 2014 09:11:20 +1100
changeset 215644 5922f13f84397b5a8bc39254ff8506796e37571a
parent 215643 ba794ec8a0f070fe81b752ce0c6367f2269a6733
child 215645 9832aa5cb89bbb125e77557690f3213aac67a6c1
push id51809
push usercmccormack@mozilla.com
push dateThu, 13 Nov 2014 22:14:26 +0000
treeherdermozilla-inbound@5922f13f8439 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1096808
milestone36.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 1096808 - Reload ua.css when ruby pref changes. r=bzbarsky
layout/style/nsLayoutStylesheetCache.cpp
modules/libpref/init/all.js
--- a/layout/style/nsLayoutStylesheetCache.cpp
+++ b/layout/style/nsLayoutStylesheetCache.cpp
@@ -109,16 +109,22 @@ nsLayoutStylesheetCache::UserChromeSheet
   EnsureGlobal();
   return gStyleCache->mUserChromeSheet;
 }
 
 CSSStyleSheet*
 nsLayoutStylesheetCache::UASheet()
 {
   EnsureGlobal();
+
+  if (!gStyleCache->mUASheet) {
+    LoadSheetURL("resource://gre-resources/ua.css",
+                 gStyleCache->mUASheet, true);
+  }
+
   return gStyleCache->mUASheet;
 }
 
 CSSStyleSheet*
 nsLayoutStylesheetCache::HTMLSheet()
 {
   EnsureGlobal();
   return gStyleCache->mHTMLSheet;
@@ -253,23 +259,22 @@ nsLayoutStylesheetCache::nsLayoutStylesh
   LoadSheetURL("resource://gre-resources/html.css",
                mHTMLSheet, true);
   LoadSheetURL("chrome://global/content/minimal-xul.css",
                mMinimalXULSheet, true);
   LoadSheetURL("resource://gre-resources/quirk.css",
                mQuirkSheet, true);
   LoadSheetURL("resource://gre/res/svg.css",
                mSVGSheet, true);
-  LoadSheetURL("resource://gre-resources/ua.css",
-               mUASheet, true);
   LoadSheetURL("chrome://global/content/xul.css",
                mXULSheet, true);
 
-  // The remaining sheets are created on-demand since their use is rarer. This
-  // helps save memory for Firefox OS apps.
+  // The remaining sheets are created on-demand do to their use being rarer
+  // (which helps save memory for Firefox OS apps) or because they need to
+  // be re-loadable in DependentPrefChanged.
 }
 
 nsLayoutStylesheetCache::~nsLayoutStylesheetCache()
 {
   mozilla::UnregisterWeakMemoryReporter(this);
   MOZ_ASSERT(!gStyleCache);
 }
 
@@ -292,18 +297,18 @@ nsLayoutStylesheetCache::EnsureGlobal()
 
   Preferences::AddBoolVarCache(&sNumberControlEnabled, NUMBER_CONTROL_PREF,
                                true);
 
   // For each pref that controls a CSS feature that a UA style sheet depends
   // on (such as a pref that enables a property that a UA style sheet uses),
   // register DependentPrefChanged as a callback to ensure that the relevant
   // style sheets will be re-parsed.
-  // Preferences::RegisterCallback(&DependentPrefChanged,
-  //                               "layout.css.example-pref.enabled");
+  Preferences::RegisterCallback(&DependentPrefChanged,
+                                "layout.css.ruby.enabled");
 }
 
 void
 nsLayoutStylesheetCache::InitFromProfile()
 {
   nsCOMPtr<nsIXULRuntime> appInfo = do_GetService("@mozilla.org/xre/app-info;1");
   if (appInfo) {
     bool inSafeMode = false;
@@ -412,16 +417,18 @@ nsLayoutStylesheetCache::InvalidateSheet
 nsLayoutStylesheetCache::DependentPrefChanged(const char* aPref, void* aData)
 {
   MOZ_ASSERT(gStyleCache, "pref changed after shutdown?");
 
   // Cause any UA style sheets whose parsing depends on the value of prefs
   // to be re-parsed by dropping the sheet from gCSSLoader's cache then
   // setting our cached sheet pointer to null.  This will only work for sheets
   // that are loaded lazily.
-  // InvalidateSheet(gStyleCache->mSomeLazilyLoadedSheet);
+
+  // for layout.css.ruby.enabled
+  InvalidateSheet(gStyleCache->mUASheet);
 }
 
 mozilla::StaticRefPtr<nsLayoutStylesheetCache>
 nsLayoutStylesheetCache::gStyleCache;
 
 mozilla::css::Loader*
 nsLayoutStylesheetCache::gCSSLoader = nullptr;
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -2145,16 +2145,21 @@ pref("layout.css.variables.enabled", tru
 
 // Is support for CSS overflow-clip-box enabled for non-UA sheets?
 pref("layout.css.overflow-clip-box.enabled", false);
 
 // Is support for CSS grid enabled?
 pref("layout.css.grid.enabled", false);
 
 // Is support for CSS Ruby enabled?
+//
+// When this pref is removed, make sure that the pref callback registration
+// in nsLayoutStylesheetCache::EnsureGlobal and the invalidation of
+// mUASheet in nsLayoutStylesheetCache::DependentPrefChanged (if it's not
+// otherwise needed) are removed.
 pref("layout.css.ruby.enabled", false);
 
 // Is support for CSS box-decoration-break enabled?
 pref("layout.css.box-decoration-break.enabled", true);
 
 // Is layout of CSS outline-style:auto enabled?
 pref("layout.css.outline-style-auto.enabled", false);