Bug 1068477 - Add pref callback to style sheet cache to handle UA style sheet reloads. r=bzbarsky

This commit is contained in:
Cameron McCormack 2014-11-14 09:11:19 +11:00
parent fa8ad881b8
commit 5b29892f54
2 changed files with 32 additions and 0 deletions

View File

@ -292,6 +292,13 @@ 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");
}
void
@ -390,6 +397,29 @@ nsLayoutStylesheetCache::LoadSheet(nsIURI* aURI,
}
}
/* static */ void
nsLayoutStylesheetCache::InvalidateSheet(nsRefPtr<CSSStyleSheet>& aSheet)
{
MOZ_ASSERT(gCSSLoader, "pref changed before we loaded a sheet?");
if (aSheet) {
gCSSLoader->ObsoleteSheet(aSheet->GetSheetURI());
aSheet = nullptr;
}
}
/* static */ void
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);
}
mozilla::StaticRefPtr<nsLayoutStylesheetCache>
nsLayoutStylesheetCache::gStyleCache;

View File

@ -67,6 +67,8 @@ private:
nsRefPtr<mozilla::CSSStyleSheet>& aSheet);
static void LoadSheet(nsIURI* aURI, nsRefPtr<mozilla::CSSStyleSheet>& aSheet,
bool aEnableUnsafeRules);
static void InvalidateSheet(nsRefPtr<mozilla::CSSStyleSheet>& aSheet);
static void DependentPrefChanged(const char* aPref, void* aData);
static mozilla::StaticRefPtr<nsLayoutStylesheetCache> gStyleCache;
static mozilla::css::Loader* gCSSLoader;