Bug 1470163: Load mathml.css upfront, and remove the concept of on-demand builtin UA sheets. r=heycam

On top of the two depending bugs.

Funny how there's a comment referencing bug 77999.

Differential Revision: https://phabricator.services.mozilla.com/D1750

MozReview-Commit-ID: LCuJROu92bo
This commit is contained in:
Emilio Cobos Álvarez 2018-06-21 16:53:12 +02:00
parent 6a2e3606ae
commit 71d364bdd1
4 changed files with 9 additions and 120 deletions

View File

@ -1632,7 +1632,7 @@ nsDocument::~nsDocument()
Accumulate(Telemetry::CSP_UNSAFE_EVAL_DOCUMENTS_COUNT, 1);
}
if (MOZ_UNLIKELY(GetMathMLEnabled())) {
if (MOZ_UNLIKELY(mMathMLEnabled)) {
ScalarAdd(Telemetry::ScalarID::MATHML_DOC_COUNT, 1);
}
}
@ -1695,7 +1695,6 @@ nsDocument::~nsDocument()
if (mAttrStyleSheet) {
mAttrStyleSheet->SetOwningDocument(nullptr);
}
// We don't own the mOnDemandBuiltInUASheets, so we don't need to reset them.
if (mListenerManager) {
mListenerManager->Disconnect();
@ -1918,7 +1917,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument)
// Traverse all our nsCOMArrays.
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStyleSheets)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOnDemandBuiltInUASheets)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPreloadingImages)
for (uint32_t i = 0; i < tmp->mFrameRequestCallbacks.Length(); ++i) {
@ -2457,7 +2455,6 @@ nsIDocument::ResetStylesheetsToURI(nsIURI* aURI)
// filled the style set. (This allows us to avoid calling
// GetStyleBackendType() too early.)
RemoveDocStyleSheetsFromStyleSets();
RemoveStyleSheetsFromStyleSets(mOnDemandBuiltInUASheets, SheetType::Agent);
RemoveStyleSheetsFromStyleSets(mAdditionalSheets[eAgentSheet], SheetType::Agent);
RemoveStyleSheetsFromStyleSets(mAdditionalSheets[eUserSheet], SheetType::User);
RemoveStyleSheetsFromStyleSets(mAdditionalSheets[eAuthorSheet], SheetType::Doc);
@ -2472,7 +2469,6 @@ nsIDocument::ResetStylesheetsToURI(nsIURI* aURI)
// Release all the sheets
mStyleSheets.Clear();
mOnDemandBuiltInUASheets.Clear();
for (auto& sheets : mAdditionalSheets) {
sheets.Clear();
}
@ -2536,13 +2532,6 @@ nsIDocument::FillStyleSet(ServoStyleSet* aStyleSet)
}
}
// Iterate backwards to maintain order
for (StyleSheet* sheet : Reversed(mOnDemandBuiltInUASheets)) {
if (sheet->IsApplicable()) {
aStyleSet->PrependStyleSheet(SheetType::Agent, sheet);
}
}
AppendSheetsToStyleSet(aStyleSet, mAdditionalSheets[eAgentSheet],
SheetType::Agent);
AppendSheetsToStyleSet(aStyleSet, mAdditionalSheets[eUserSheet],
@ -4131,43 +4120,6 @@ nsIDocument::RemoveChildNode(nsIContent* aKid, bool aNotify)
"(maybe somebody called GetRootElement() too early?)");
}
void
nsIDocument::EnsureOnDemandBuiltInUASheet(StyleSheet* aSheet)
{
if (mOnDemandBuiltInUASheets.Contains(aSheet)) {
return;
}
AddOnDemandBuiltInUASheet(aSheet);
}
void
nsIDocument::AddOnDemandBuiltInUASheet(StyleSheet* aSheet)
{
MOZ_ASSERT(!mOnDemandBuiltInUASheets.Contains(aSheet));
// Prepend here so that we store the sheets in mOnDemandBuiltInUASheets in
// the same order that they should end up in the style set.
mOnDemandBuiltInUASheets.InsertElementAt(0, aSheet);
if (aSheet->IsApplicable()) {
// This is like |AddStyleSheetToStyleSets|, but for an agent sheet.
if (nsIPresShell* shell = GetShell()) {
// Note that prepending here is necessary to make sure that html.css etc.
// does not override Firefox OS/Mobile's content.css sheet.
//
// Maybe we should have an insertion point to match the order of
// nsDocumentViewer::CreateStyleSet though?
//
// FIXME(emilio): We probably should, randomly prepending stuff here is
// very prone to subtle bugs, behavior differences...
shell->StyleSet()->PrependStyleSheet(SheetType::Agent, aSheet);
shell->ApplicableStylesChanged();
}
}
NotifyStyleSheetAdded(aSheet, false);
}
void
nsIDocument::AddStyleSheetToStyleSets(StyleSheet* aSheet)
{
@ -9542,21 +9494,6 @@ nsIDocument::CreateStaticClone(nsIDocShell* aCloneContainer)
}
}
}
// Iterate backwards to maintain order
for (StyleSheet* sheet : Reversed(thisAsDoc->mOnDemandBuiltInUASheets)) {
if (sheet) {
if (sheet->IsApplicable()) {
RefPtr<StyleSheet> clonedSheet =
sheet->Clone(nullptr, nullptr, clonedDoc, nullptr);
NS_WARNING_ASSERTION(clonedSheet,
"Cloning a stylesheet didn't work!");
if (clonedSheet) {
clonedDoc->AddOnDemandBuiltInUASheet(clonedSheet);
}
}
}
}
}
}
mCreatingStaticClone = false;
@ -11761,11 +11698,6 @@ nsDocument::DocAddSizeOfExcludingThis(nsWindowSizes& aWindowSizes) const
aWindowSizes.mLayoutStyleSheetsSize +=
SizeOfOwnedSheetArrayExcludingThis(mStyleSheets,
aWindowSizes.mState.mMallocSizeOf);
// Note that we do not own the sheets pointed to by mOnDemandBuiltInUASheets
// (the nsLayoutStyleSheetCache singleton does).
aWindowSizes.mLayoutStyleSheetsSize +=
mOnDemandBuiltInUASheets.ShallowSizeOfExcludingThis(
aWindowSizes.mState.mMallocSizeOf);
for (auto& sheetArray : mAdditionalSheets) {
aWindowSizes.mLayoutStyleSheetsSize +=
SizeOfOwnedSheetArrayExcludingThis(sheetArray,

View File

@ -836,14 +836,6 @@ public:
mBidiEnabled = true;
}
/**
* Check if the document contains (or has contained) any MathML elements.
*/
bool GetMathMLEnabled() const
{
return mMathMLEnabled;
}
void SetMathMLEnabled()
{
mMathMLEnabled = true;
@ -1468,28 +1460,6 @@ public:
* Style sheets are ordered, most significant last.
*/
/**
* These exists to allow us to on-demand load user-agent style sheets that
* would otherwise be loaded by nsDocumentViewer::CreateStyleSet. This allows
* us to keep the memory used by a document's rule cascade data (the stuff in
* its nsStyleSet's nsCSSRuleProcessors) - which can be considerable - lower
* than it would be if we loaded all built-in user-agent style sheets up
* front.
*
* By "built-in" user-agent style sheets we mean the user-agent style sheets
* that gecko itself supplies (such as html.css and svg.css) as opposed to
* user-agent level style sheets inserted by add-ons or the like.
*
* This function prepends the given style sheet to the document's style set
* in order to make sure that it does not override user-agent style sheets
* supplied by add-ons or by the app (Firefox OS or Firefox Mobile, for
* example), since their sheets should override built-in sheets.
*
* TODO We can get rid of the whole concept of delayed loading if we fix
* bug 77999.
*/
void EnsureOnDemandBuiltInUASheet(mozilla::StyleSheet* aSheet);
mozilla::dom::StyleSheetList* StyleSheets()
{
return &DocumentOrShadowRoot::EnsureDOMStyleSheets();
@ -3616,7 +3586,6 @@ protected:
void UpdateDocumentStates(mozilla::EventStates);
void AddOnDemandBuiltInUASheet(mozilla::StyleSheet* aSheet);
void RemoveDocStyleSheetsFromStyleSets();
void RemoveStyleSheetsFromStyleSets(
const nsTArray<RefPtr<mozilla::StyleSheet>>& aSheets,
@ -4418,7 +4387,6 @@ protected:
nsCOMPtr<nsIRunnable> mMaybeEndOutermostXBLUpdateRunner;
nsCOMPtr<nsIRequest> mOnloadBlocker;
nsTArray<RefPtr<mozilla::StyleSheet>> mOnDemandBuiltInUASheets;
nsTArray<RefPtr<mozilla::StyleSheet>> mAdditionalSheets[AdditionalSheetTypeCount];
// Member to store out last-selected stylesheet set.

View File

@ -106,25 +106,9 @@ nsMathMLElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
aDocument->RegisterPendingLinkUpdate(this);
}
nsIDocument* doc = GetComposedDoc();
if (doc) {
if (!doc->GetMathMLEnabled()) {
// Enable MathML and setup the style sheet during binding, not element
// construction, because we could move a MathML element from the document
// that created it to another document.
auto cache = nsLayoutStylesheetCache::Singleton();
doc->SetMathMLEnabled();
doc->EnsureOnDemandBuiltInUASheet(cache->MathMLSheet());
// Rebuild style data for the presshell, because style system
// optimizations may have taken place assuming MathML was disabled.
// (See nsRuleNode::CheckSpecifiedProperties.)
RefPtr<nsPresContext> presContext = doc->GetPresContext();
if (presContext) {
presContext->
PostRebuildAllStyleDataEvent(nsChangeHint(0), eRestyle_Subtree);
}
}
// Set the bit in the document for telemetry.
if (nsIDocument* doc = GetComposedDoc()) {
doc->SetMathMLEnabled();
}
return rv;

View File

@ -2517,6 +2517,11 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument)
styleSet->PrependStyleSheet(SheetType::Agent, sheet);
}
sheet = cache->MathMLSheet();
if (sheet) {
styleSet->PrependStyleSheet(SheetType::Agent, sheet);
}
styleSet->PrependStyleSheet(SheetType::Agent, cache->UASheet());
if (nsStyleSheetService* sheetService = nsStyleSheetService::GetInstance()) {