diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index df81ade49f0f..92761b0b0aea 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -6692,8 +6692,7 @@ nsresult Document::LoadAdditionalStyleSheet(additionalSheetType aType, RefPtr sheet = result.unwrap(); - sheet->SetAssociatedDocumentOrShadowRoot( - this, StyleSheet::OwnedByDocumentOrShadowRoot); + sheet->SetAssociatedDocumentOrShadowRoot(this); MOZ_ASSERT(sheet->IsApplicable()); return AddAdditionalStyleSheet(aType, sheet); diff --git a/dom/base/DocumentOrShadowRoot.cpp b/dom/base/DocumentOrShadowRoot.cpp index 910e01183bd5..0719b23842bb 100644 --- a/dom/base/DocumentOrShadowRoot.cpp +++ b/dom/base/DocumentOrShadowRoot.cpp @@ -73,8 +73,7 @@ StyleSheetList* DocumentOrShadowRoot::StyleSheets() { } void DocumentOrShadowRoot::InsertSheetAt(size_t aIndex, StyleSheet& aSheet) { - aSheet.SetAssociatedDocumentOrShadowRoot( - this, StyleSheet::OwnedByDocumentOrShadowRoot); + aSheet.SetAssociatedDocumentOrShadowRoot(this); mStyleSheets.InsertElementAt(aIndex, &aSheet); } diff --git a/layout/style/StyleSheet.cpp b/layout/style/StyleSheet.cpp index c23dc1a5efac..5d0c3063d3df 100644 --- a/layout/style/StyleSheet.cpp +++ b/layout/style/StyleSheet.cpp @@ -40,7 +40,6 @@ StyleSheet::StyleSheet(css::SheetParsingMode aParsingMode, CORSMode aCORSMode, mOwnerRule(nullptr), mParsingMode(aParsingMode), mState(static_cast(0)), - mAssociationMode(NotOwnedByDocumentOrShadowRoot), mInner(new StyleSheetInfo(aCORSMode, aIntegrity, aParsingMode)) { mInner->AddSheet(this); } @@ -58,9 +57,6 @@ StyleSheet::StyleSheet(const StyleSheet& aCopy, StyleSheet* aParentSheetToUse, mOwnerRule(aOwnerRuleToUse), mParsingMode(aCopy.mParsingMode), mState(aCopy.mState), - // We only use this constructor during cloning. It's the cloner's - // responsibility to notify us if we end up being owned by a document. - mAssociationMode(NotOwnedByDocumentOrShadowRoot), // Shallow copy, but concrete subclasses will fix up. mInner(aCopy.mInner) { MOZ_ASSERT(!aConstructorDocToUse || aCopy.IsConstructed()); @@ -176,8 +172,7 @@ dom::DocumentOrShadowRoot* StyleSheet::GetAssociatedDocumentOrShadowRoot() Document* StyleSheet::GetKeptAliveByDocument() const { for (const auto* sheet = this; sheet; sheet = sheet->mParentSheet) { - if (sheet->mAssociationMode == OwnedByDocumentOrShadowRoot) { - MOZ_ASSERT(sheet->mDocumentOrShadowRoot); + if (sheet->mDocumentOrShadowRoot) { return sheet->mDocumentOrShadowRoot->AsNode().GetComposedDoc(); } if (sheet->IsConstructed()) { @@ -884,7 +879,7 @@ void StyleSheet::RemoveFromParent() { } void StyleSheet::UnparentChildren() { - MOZ_ASSERT(mAssociationMode == NotOwnedByDocumentOrShadowRoot, + MOZ_ASSERT(!mDocumentOrShadowRoot, "How did we get to the destructor, exactly, if we're owned " "by a document?"); // XXXbz this is a little bogus; see the comment where we @@ -951,16 +946,12 @@ bool StyleSheet::AreRulesAvailable(nsIPrincipal& aSubjectPrincipal, } void StyleSheet::SetAssociatedDocumentOrShadowRoot( - DocumentOrShadowRoot* aDocOrShadowRoot, AssociationMode aAssociationMode) { + DocumentOrShadowRoot* aDocOrShadowRoot) { MOZ_ASSERT(!IsConstructed()); - MOZ_ASSERT(aDocOrShadowRoot || - aAssociationMode == NotOwnedByDocumentOrShadowRoot); MOZ_ASSERT(!mParentSheet || !aDocOrShadowRoot, "Shouldn't be set on child sheets"); - // not ref counted mDocumentOrShadowRoot = aDocOrShadowRoot; - mAssociationMode = aAssociationMode; } void StyleSheet::AppendStyleSheet(StyleSheet& aSheet) { diff --git a/layout/style/StyleSheet.h b/layout/style/StyleSheet.h index b63fa73afa25..e5ab7a1491d9 100644 --- a/layout/style/StyleSheet.h +++ b/layout/style/StyleSheet.h @@ -244,15 +244,10 @@ class StyleSheet final : public nsICSSLoaderObserver, public nsWrapperCache { void EnsureUniqueInner(); - // style sheet owner info - enum AssociationMode : uint8_t { - // OwnedByDocumentOrShadowRoot means mDocumentOrShadowRoot owns us (possibly - // via a chain of other stylesheets). - OwnedByDocumentOrShadowRoot, - // NotOwnedByDocument means we're owned by something that might have a - // different lifetime than mDocument. - NotOwnedByDocumentOrShadowRoot - }; + // Returns the DocumentOrShadowRoot* that owns us, if any. + // + // TODO(emilio): Maybe rename to GetOwner*() or such? Might be + // confusing with nsINode::OwnerDoc and such. dom::DocumentOrShadowRoot* GetAssociatedDocumentOrShadowRoot() const; // Whether this stylesheet is kept alive by the associated or constructor @@ -267,10 +262,9 @@ class StyleSheet final : public nsICSSLoaderObserver, public nsWrapperCache { // Non-null iff GetAssociatedDocumentOrShadowRoot is non-null. dom::Document* GetAssociatedDocument() const; - void SetAssociatedDocumentOrShadowRoot(dom::DocumentOrShadowRoot*, - AssociationMode); + void SetAssociatedDocumentOrShadowRoot(dom::DocumentOrShadowRoot*); void ClearAssociatedDocumentOrShadowRoot() { - SetAssociatedDocumentOrShadowRoot(nullptr, NotOwnedByDocumentOrShadowRoot); + SetAssociatedDocumentOrShadowRoot(nullptr); } nsINode* GetOwnerNode() const { return mOwningNode; } @@ -577,12 +571,6 @@ class StyleSheet final : public nsICSSLoaderObserver, public nsWrapperCache { State mState; - // mAssociationMode determines whether mDocumentOrShadowRoot directly owns us - // (in the sense that if it's known-live then we're known-live). - // - // Always NotOwnedByDocumentOrShadowRoot when mDocumentOrShadowRoot is null. - AssociationMode mAssociationMode; - // Core information we get from parsed sheets, which are shared amongst // StyleSheet clones. //