diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 4e742fc11779..0ac8662ad90c 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -6580,21 +6580,6 @@ void Document::RemoveStyleSheetFromStyleSets(StyleSheet& aSheet) { } } -void Document::RemoveStyleSheet(StyleSheet& aSheet) { - RefPtr sheet = DocumentOrShadowRoot::RemoveSheet(aSheet); - - if (!sheet) { - NS_ASSERTION(mInUnlinkOrDeletion, "stylesheet not found"); - return; - } - - if (!mIsGoingAway && sheet->IsApplicable()) { - RemoveStyleSheetFromStyleSets(*sheet); - } - - sheet->ClearAssociatedDocumentOrShadowRoot(); -} - void Document::InsertSheetAt(size_t aIndex, StyleSheet& aSheet) { DocumentOrShadowRoot::InsertSheetAt(aIndex, aSheet); diff --git a/dom/base/Document.h b/dom/base/Document.h index 38c6b0c4cd5b..ad448d4658af 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -1715,11 +1715,6 @@ class Document : public nsINode, InsertSheetAt(SheetCount(), *aSheet); } - /** - * Remove a stylesheet from the document - */ - void RemoveStyleSheet(StyleSheet&); - /** * Notify the document that the applicable state of the sheet changed * and that observers should be notified and style sets updated diff --git a/dom/base/DocumentOrShadowRoot.cpp b/dom/base/DocumentOrShadowRoot.cpp index a283f43417b3..d22250d421d4 100644 --- a/dom/base/DocumentOrShadowRoot.cpp +++ b/dom/base/DocumentOrShadowRoot.cpp @@ -78,16 +78,20 @@ void DocumentOrShadowRoot::InsertSheetAt(size_t aIndex, StyleSheet& aSheet) { mStyleSheets.InsertElementAt(aIndex, &aSheet); } -already_AddRefed DocumentOrShadowRoot::RemoveSheet( - StyleSheet& aSheet) { +void DocumentOrShadowRoot::RemoveStyleSheet(StyleSheet& aSheet) { auto index = mStyleSheets.IndexOf(&aSheet); if (index == mStyleSheets.NoIndex) { - return nullptr; + // We should only hit this case if we are unlinking + // in which case mStyleSheets should be cleared. + MOZ_ASSERT(mKind != Kind::Document || + AsNode().AsDocument()->InUnlinkOrDeletion()); + MOZ_ASSERT(mStyleSheets.IsEmpty()); + return; } RefPtr sheet = std::move(mStyleSheets[index]); mStyleSheets.RemoveElementAt(index); + RemoveSheetFromStylesIfApplicable(*sheet); sheet->ClearAssociatedDocumentOrShadowRoot(); - return sheet.forget(); } void DocumentOrShadowRoot::RemoveSheetFromStylesIfApplicable( diff --git a/dom/base/DocumentOrShadowRoot.h b/dom/base/DocumentOrShadowRoot.h index a730a608125e..1bfa3cac49d4 100644 --- a/dom/base/DocumentOrShadowRoot.h +++ b/dom/base/DocumentOrShadowRoot.h @@ -88,6 +88,8 @@ class DocumentOrShadowRoot { void GetAdoptedStyleSheets(nsTArray>&) const; + void RemoveStyleSheet(StyleSheet&); + Element* GetElementById(const nsAString& aElementId); /** @@ -251,8 +253,6 @@ class DocumentOrShadowRoot { */ void CloneAdoptedSheetsFrom(const DocumentOrShadowRoot&); - // Returns the reference to the sheet, if found in mStyleSheets. - already_AddRefed RemoveSheet(StyleSheet& aSheet); void InsertSheetAt(size_t aIndex, StyleSheet& aSheet); void AddSizeOfExcludingThis(nsWindowSizes&) const; diff --git a/dom/base/ShadowRoot.cpp b/dom/base/ShadowRoot.cpp index cedca7e1b71c..7d7072f0a89f 100644 --- a/dom/base/ShadowRoot.cpp +++ b/dom/base/ShadowRoot.cpp @@ -477,16 +477,6 @@ void ShadowRoot::RemoveSheetFromStyles(StyleSheet& aSheet) { ApplicableRulesChanged(); } -void ShadowRoot::RemoveSheet(StyleSheet& aSheet) { - RefPtr sheet = DocumentOrShadowRoot::RemoveSheet(aSheet); - MOZ_ASSERT(sheet || mStyleSheets.IsEmpty(), - "sheet should always be found, except after unlink, where we " - "should've cleared all stylesheets"); - if (sheet && sheet->IsApplicable()) { - RemoveSheetFromStyles(*sheet); - } -} - void ShadowRoot::AddToIdTable(Element* aElement, nsAtom* aId) { IdentifierMapEntry* entry = mIdentifierMap.PutEntry(aId); if (entry) { diff --git a/dom/base/ShadowRoot.h b/dom/base/ShadowRoot.h index 6e8a263fe4d1..945e5460fc7a 100644 --- a/dom/base/ShadowRoot.h +++ b/dom/base/ShadowRoot.h @@ -74,7 +74,6 @@ class ShadowRoot final : public DocumentFragment, ShadowRootMode Mode() const { return mMode; } bool IsClosed() const { return mMode == ShadowRootMode::Closed; } - void RemoveSheet(StyleSheet&); void RemoveSheetFromStyles(StyleSheet&); void RuleAdded(StyleSheet&, css::Rule&); void RuleRemoved(StyleSheet&, css::Rule&); diff --git a/dom/base/nsStyleLinkElement.cpp b/dom/base/nsStyleLinkElement.cpp index cea272e9a360..1b5062fa6cf3 100644 --- a/dom/base/nsStyleLinkElement.cpp +++ b/dom/base/nsStyleLinkElement.cpp @@ -260,7 +260,7 @@ nsStyleLinkElement::DoUpdateStyleSheet(Document* aOldDocument, // disabled, since otherwise a sheet with a stale linking element pointer // will be hanging around -- not good! if (aOldShadowRoot) { - aOldShadowRoot->RemoveSheet(*mStyleSheet); + aOldShadowRoot->RemoveStyleSheet(*mStyleSheet); } else { aOldDocument->RemoveStyleSheet(*mStyleSheet); } @@ -297,7 +297,7 @@ nsStyleLinkElement::DoUpdateStyleSheet(Document* aOldDocument, ShadowRoot* containingShadow = thisContent->GetContainingShadow(); // Could be null only during unlink. if (MOZ_LIKELY(containingShadow)) { - containingShadow->RemoveSheet(*mStyleSheet); + containingShadow->RemoveStyleSheet(*mStyleSheet); } } else { doc->RemoveStyleSheet(*mStyleSheet);