summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dom/base/nsDOMWindowUtils.cpp2
-rw-r--r--dom/base/nsDocument.cpp22
-rw-r--r--editor/libeditor/HTMLEditor.cpp4
-rw-r--r--layout/style/CSSStyleSheet.cpp20
-rw-r--r--layout/style/CSSStyleSheet.h3
-rw-r--r--layout/style/Loader.cpp6
-rw-r--r--layout/style/ServoStyleSheet.cpp10
-rw-r--r--layout/style/ServoStyleSheet.h3
-rw-r--r--layout/style/StyleRule.cpp10
-rw-r--r--layout/style/StyleSheet.cpp4
-rw-r--r--layout/style/StyleSheet.h23
-rw-r--r--layout/style/StyleSheetInlines.h12
-rw-r--r--layout/style/nsDOMCSSDeclaration.cpp2
13 files changed, 83 insertions, 38 deletions
diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp
index 3f5b54c94..a923e8f70 100644
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -3473,7 +3473,7 @@ nsDOMWindowUtils::AddSheet(nsIDOMStyleSheet *aSheet, uint32_t aSheetType)
nsIDocument::additionalSheetType type = convertSheetType(aSheetType);
RefPtr<CSSStyleSheet> sheet = do_QueryObject(aSheet);
NS_ENSURE_TRUE(sheet, NS_ERROR_FAILURE);
- if (sheet->GetOwningDocument()) {
+ if (sheet->GetAssociatedDocument()) {
return NS_ERROR_INVALID_ARG;
}
return doc->AddAdditionalStyleSheet(type, sheet);
diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp
index e16c1831c..130580fad 100644
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -1452,11 +1452,11 @@ nsDocument::~nsDocument()
// Let the stylesheets know we're going away
for (StyleSheet* sheet : mStyleSheets) {
- sheet->SetOwningDocument(nullptr);
+ sheet->ClearAssociatedDocument();
}
for (auto& sheets : mAdditionalSheets) {
for (StyleSheet* sheet : sheets) {
- sheet->SetOwningDocument(nullptr);
+ sheet->ClearAssociatedDocument();
}
}
if (mAttrStyleSheet) {
@@ -2113,7 +2113,7 @@ nsDocument::RemoveDocStyleSheetsFromStyleSets()
{
// The stylesheets should forget us
for (StyleSheet* sheet : Reversed(mStyleSheets)) {
- sheet->SetOwningDocument(nullptr);
+ sheet->ClearAssociatedDocument();
if (sheet->IsApplicable()) {
nsCOMPtr<nsIPresShell> shell = GetShell();
@@ -2132,7 +2132,7 @@ nsDocument::RemoveStyleSheetsFromStyleSets(
{
// The stylesheets should forget us
for (StyleSheet* sheet : Reversed(aSheets)) {
- sheet->SetOwningDocument(nullptr);
+ sheet->ClearAssociatedDocument();
if (sheet->IsApplicable()) {
nsCOMPtr<nsIPresShell> shell = GetShell();
@@ -4007,7 +4007,7 @@ nsDocument::AddStyleSheet(StyleSheet* aSheet)
{
NS_PRECONDITION(aSheet, "null arg");
mStyleSheets.AppendElement(aSheet);
- aSheet->SetOwningDocument(this);
+ aSheet->SetAssociatedDocument(this, StyleSheet::OwnedByDocument);
if (aSheet->IsApplicable()) {
AddStyleSheetToStyleSets(aSheet);
@@ -4044,7 +4044,7 @@ nsDocument::RemoveStyleSheet(StyleSheet* aSheet)
NotifyStyleSheetRemoved(aSheet, true);
}
- aSheet->SetOwningDocument(nullptr);
+ aSheet->ClearAssociatedDocument();
}
void
@@ -4072,7 +4072,7 @@ nsDocument::UpdateStyleSheets(nsTArray<RefPtr<StyleSheet>>& aOldSheets,
StyleSheet* newSheet = aNewSheets[i];
if (newSheet) {
mStyleSheets.InsertElementAt(oldIndex, newSheet);
- newSheet->SetOwningDocument(this);
+ newSheet->SetAssociatedDocument(this, StyleSheet::OwnedByDocument);
if (newSheet->IsApplicable()) {
AddStyleSheetToStyleSets(newSheet);
}
@@ -4091,7 +4091,7 @@ nsDocument::InsertStyleSheetAt(StyleSheet* aSheet, int32_t aIndex)
mStyleSheets.InsertElementAt(aIndex, aSheet);
- aSheet->SetOwningDocument(this);
+ aSheet->SetAssociatedDocument(this, StyleSheet::OwnedByDocument);
if (aSheet->IsApplicable()) {
AddStyleSheetToStyleSets(aSheet);
@@ -4216,7 +4216,7 @@ nsDocument::LoadAdditionalStyleSheet(additionalSheetType aType,
nsresult rv = loader->LoadSheetSync(aSheetURI, parsingMode, true, &sheet);
NS_ENSURE_SUCCESS(rv, rv);
- sheet->SetOwningDocument(this);
+ sheet->SetAssociatedDocument(this, StyleSheet::OwnedByDocument);
MOZ_ASSERT(sheet->IsApplicable());
return AddAdditionalStyleSheet(aType, sheet);
@@ -4274,7 +4274,7 @@ nsDocument::RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheet
NotifyStyleSheetRemoved(sheetRef, false);
EndUpdate(UPDATE_STYLE);
- sheetRef->SetOwningDocument(nullptr);
+ sheetRef->ClearAssociatedDocument();
}
}
@@ -12126,7 +12126,7 @@ SizeOfOwnedSheetArrayExcludingThis(const nsTArray<RefPtr<StyleSheet>>& aSheets,
size_t n = 0;
n += aSheets.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (StyleSheet* sheet : aSheets) {
- if (!sheet->GetOwningDocument()) {
+ if (!sheet->GetAssociatedDocument()) {
// Avoid over-reporting shared sheets.
continue;
}
diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp
index 56e607200..3c43ade3b 100644
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -2961,7 +2961,7 @@ HTMLEditor::EnableStyleSheet(const nsAString& aURL,
// Ensure the style sheet is owned by our document.
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
- sheet->SetOwningDocument(doc);
+ sheet->SetAssociatedDocument(doc, StyleSheet::NotOwnedByDocument);
if (sheet->IsServo()) {
// XXXheycam ServoStyleSheets don't support being enabled/disabled yet.
@@ -2983,7 +2983,7 @@ HTMLEditor::EnableExistingStyleSheet(const nsAString& aURL)
// Ensure the style sheet is owned by our document.
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
- sheet->SetOwningDocument(doc);
+ sheet->SetAssociatedDocument(doc, StyleSheet::NotOwnedByDocument);
if (sheet->IsServo()) {
// XXXheycam ServoStyleSheets don't support being enabled/disabled yet.
diff --git a/layout/style/CSSStyleSheet.cpp b/layout/style/CSSStyleSheet.cpp
index 71ca6e3f2..43d47100d 100644
--- a/layout/style/CSSStyleSheet.cpp
+++ b/layout/style/CSSStyleSheet.cpp
@@ -694,7 +694,7 @@ nsMediaList::GetMediaText(nsAString& aMediaText)
// nsCOMPtr<nsIDocument>
#define BEGIN_MEDIA_CHANGE(sheet, doc) \
if (sheet) { \
- doc = sheet->GetOwningDocument(); \
+ doc = sheet->GetAssociatedDocument(); \
} \
mozAutoDocUpdate updateBatch(doc, UPDATE_STYLE, true); \
if (sheet) { \
@@ -864,7 +864,8 @@ struct ChildSheetListBuilder {
void SetParentLinks(CSSStyleSheet* aSheet) {
aSheet->mParent = parent;
- aSheet->SetOwningDocument(parent->mDocument);
+ aSheet->SetAssociatedDocument(parent->mDocument,
+ parent->mDocumentAssociationMode);
}
static void ReparentChildList(CSSStyleSheet* aPrimarySheet,
@@ -872,7 +873,8 @@ struct ChildSheetListBuilder {
{
for (CSSStyleSheet *child = aFirstChild; child; child = child->mNext) {
child->mParent = aPrimarySheet;
- child->SetOwningDocument(aPrimarySheet->mDocument);
+ child->SetAssociatedDocument(aPrimarySheet->mDocument,
+ aPrimarySheet->mDocumentAssociationMode);
}
}
};
@@ -1359,16 +1361,22 @@ CSSStyleSheet::GetParentSheet() const
}
void
-CSSStyleSheet::SetOwningDocument(nsIDocument* aDocument)
-{ // not ref counted
+CSSStyleSheet::SetAssociatedDocument(nsIDocument* aDocument,
+ DocumentAssociationMode aAssociationMode)
+{
+ MOZ_ASSERT_IF(!aDocument, aAssociationMode == NotOwnedByDocument);
+
+ // not ref counted
mDocument = aDocument;
+ mDocumentAssociationMode = aAssociationMode;
+
// Now set the same document on all our child sheets....
// XXXbz this is a little bogus; see the XXX comment where we
// declare mFirstChild.
for (CSSStyleSheet* child = mInner->mFirstChild;
child; child = child->mNext) {
if (child->mParent == this) {
- child->SetOwningDocument(aDocument);
+ child->SetAssociatedDocument(aDocument, aAssociationMode);
}
}
}
diff --git a/layout/style/CSSStyleSheet.h b/layout/style/CSSStyleSheet.h
index 74e12291e..89189d781 100644
--- a/layout/style/CSSStyleSheet.h
+++ b/layout/style/CSSStyleSheet.h
@@ -129,7 +129,8 @@ public:
// style sheet owner info
CSSStyleSheet* GetParentSheet() const; // may be null
- void SetOwningDocument(nsIDocument* aDocument);
+ void SetAssociatedDocument(nsIDocument* aDocument,
+ DocumentAssociationMode aAssociationMode);
// Find the ID of the owner inner window.
uint64_t FindOwningWindowInnerID() const;
diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp
index 0ce337e29..d4edfe81d 100644
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -2209,9 +2209,9 @@ Loader::LoadChildSheet(StyleSheet* aParentSheet,
nsCOMPtr<nsINode> owningNode;
- // check for an owning document: if none, don't bother walking up the parent
- // sheets
- if (aParentSheet->GetOwningDocument()) {
+ // check for an associated document: if none, don't bother walking up the
+ // parent sheets
+ if (aParentSheet->GetAssociatedDocument()) {
StyleSheet* topSheet = aParentSheet;
while (StyleSheet* parent = topSheet->GetParentSheet()) {
topSheet = parent;
diff --git a/layout/style/ServoStyleSheet.cpp b/layout/style/ServoStyleSheet.cpp
index cfeae20d2..5f2a925b5 100644
--- a/layout/style/ServoStyleSheet.cpp
+++ b/layout/style/ServoStyleSheet.cpp
@@ -30,19 +30,23 @@ ServoStyleSheet::HasRules() const
}
void
-ServoStyleSheet::SetOwningDocument(nsIDocument* aDocument)
+ServoStyleSheet::SetAssociatedDocument(nsIDocument* aDocument,
+ DocumentAssociationMode aAssociationMode)
{
+ MOZ_ASSERT_IF(!aDocument, aAssociationMode == NotOwnedByDocument);
+
// XXXheycam: Traverse to child ServoStyleSheets to set this, like
- // CSSStyleSheet::SetOwningDocument does.
+ // CSSStyleSheet::SetAssociatedDocument does.
mDocument = aDocument;
+ mDocumentAssociationMode = aAssociationMode;
}
ServoStyleSheet*
ServoStyleSheet::GetParentSheet() const
{
// XXXheycam: When we implement support for child sheets, we'll have
- // to fix SetOwningDocument to propagate the owning document down
+ // to fix SetAssociatedDocument to propagate the associated document down
// to the children.
MOZ_CRASH("stylo: not implemented");
}
diff --git a/layout/style/ServoStyleSheet.h b/layout/style/ServoStyleSheet.h
index 079f196eb..c54c15e7d 100644
--- a/layout/style/ServoStyleSheet.h
+++ b/layout/style/ServoStyleSheet.h
@@ -29,7 +29,8 @@ public:
bool HasRules() const;
- void SetOwningDocument(nsIDocument* aDocument);
+ void SetAssociatedDocument(nsIDocument* aDocument,
+ DocumentAssociationMode aAssociationMode);
ServoStyleSheet* GetParentSheet() const;
void AppendStyleSheet(ServoStyleSheet* aSheet);
diff --git a/layout/style/StyleRule.cpp b/layout/style/StyleRule.cpp
index 598cb7c74..622f498dd 100644
--- a/layout/style/StyleRule.cpp
+++ b/layout/style/StyleRule.cpp
@@ -1209,13 +1209,13 @@ DOMCSSDeclarationImpl::SetCSSDeclaration(DeclarationBlock* aDecl)
NS_PRECONDITION(mRule,
"can only be called when |GetCSSDeclaration| returned a declaration");
- nsCOMPtr<nsIDocument> owningDoc;
+ nsCOMPtr<nsIDocument> doc;
RefPtr<CSSStyleSheet> sheet = mRule->GetStyleSheet();
if (sheet) {
- owningDoc = sheet->GetOwningDocument();
+ doc = sheet->GetAssociatedDocument();
}
- mozAutoDocUpdate updateBatch(owningDoc, UPDATE_STYLE, true);
+ mozAutoDocUpdate updateBatch(doc, UPDATE_STYLE, true);
mRule->SetDeclaration(aDecl->AsGecko());
@@ -1223,8 +1223,8 @@ DOMCSSDeclarationImpl::SetCSSDeclaration(DeclarationBlock* aDecl)
sheet->DidDirty();
}
- if (owningDoc) {
- owningDoc->StyleRuleChanged(sheet, mRule);
+ if (doc) {
+ doc->StyleRuleChanged(sheet, mRule);
}
return NS_OK;
}
diff --git a/layout/style/StyleSheet.cpp b/layout/style/StyleSheet.cpp
index fa4beeb36..f125cf97e 100644
--- a/layout/style/StyleSheet.cpp
+++ b/layout/style/StyleSheet.cpp
@@ -24,6 +24,7 @@ StyleSheet::StyleSheet(StyleBackendType aType, css::SheetParsingMode aParsingMod
, mParsingMode(aParsingMode)
, mType(aType)
, mDisabled(false)
+ , mDocumentAssociationMode(NotOwnedByDocument)
{
}
@@ -36,6 +37,9 @@ StyleSheet::StyleSheet(const StyleSheet& aCopy,
, mParsingMode(aCopy.mParsingMode)
, mType(aCopy.mType)
, mDisabled(aCopy.mDisabled)
+ // 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.
+ , mDocumentAssociationMode(NotOwnedByDocument)
{
}
diff --git a/layout/style/StyleSheet.h b/layout/style/StyleSheet.h
index 863f6d22f..7a1a71466 100644
--- a/layout/style/StyleSheet.h
+++ b/layout/style/StyleSheet.h
@@ -95,8 +95,22 @@ public:
inline bool HasRules() const;
// style sheet owner info
- nsIDocument* GetOwningDocument() const { return mDocument; }
- inline void SetOwningDocument(nsIDocument* aDocument);
+ enum DocumentAssociationMode {
+ // OwnedByDocument means mDocument owns us (possibly via a chain of other
+ // stylesheets).
+ OwnedByDocument,
+ // NotOwnedByDocument means we're owned by something that might have a
+ // different lifetime than mDocument.
+ NotOwnedByDocument
+ };
+ nsIDocument* GetAssociatedDocument() const { return mDocument; }
+ bool IsOwnedByDocument() const {
+ return mDocumentAssociationMode == OwnedByDocument;
+ }
+ // aDocument must not be null.
+ inline void SetAssociatedDocument(nsIDocument* aDocument,
+ DocumentAssociationMode aMode);
+ inline void ClearAssociatedDocument();
nsINode* GetOwnerNode() const { return mOwningNode; }
inline StyleSheet* GetParentSheet() const;
@@ -206,6 +220,11 @@ protected:
const StyleBackendType mType;
bool mDisabled;
+
+ // mDocumentAssociationMode determines whether mDocument directly owns us (in
+ // the sense that if it's known-live then we're known-live). Always
+ // NotOwnedByDocument when mDocument is null.
+ DocumentAssociationMode mDocumentAssociationMode;
};
} // namespace mozilla
diff --git a/layout/style/StyleSheetInlines.h b/layout/style/StyleSheetInlines.h
index d03a3741b..c0b8495f8 100644
--- a/layout/style/StyleSheetInlines.h
+++ b/layout/style/StyleSheetInlines.h
@@ -83,9 +83,17 @@ StyleSheet::HasRules() const
}
void
-StyleSheet::SetOwningDocument(nsIDocument* aDocument)
+StyleSheet::SetAssociatedDocument(nsIDocument* aDocument,
+ DocumentAssociationMode aAssociationMode)
{
- MOZ_STYLO_FORWARD(SetOwningDocument, (aDocument))
+ MOZ_ASSERT(aDocument);
+ MOZ_STYLO_FORWARD(SetAssociatedDocument, (aDocument, aAssociationMode))
+}
+
+void
+StyleSheet::ClearAssociatedDocument()
+{
+ MOZ_STYLO_FORWARD(SetAssociatedDocument, (nullptr, NotOwnedByDocument));
}
StyleSheet*
diff --git a/layout/style/nsDOMCSSDeclaration.cpp b/layout/style/nsDOMCSSDeclaration.cpp
index bd6c6069d..51ce8c335 100644
--- a/layout/style/nsDOMCSSDeclaration.cpp
+++ b/layout/style/nsDOMCSSDeclaration.cpp
@@ -267,7 +267,7 @@ nsDOMCSSDeclaration::GetCSSParsingEnvironmentForRule(css::Rule* aRule,
return;
}
- nsIDocument* document = sheet->GetOwningDocument();
+ nsIDocument* document = sheet->GetAssociatedDocument();
aCSSParseEnv.mSheetURI = sheet->GetSheetURI();
aCSSParseEnv.mBaseURI = sheet->GetBaseURI();
aCSSParseEnv.mPrincipal = sheet->Principal();