Skip to content

Commit da11b10

Browse files
committed
Bug 1928932 - Part 1 - Add an mIsTrusted flag on script elements. r=smaug,credential-management-reviewers,dimi
This flag can be modified when notifying for character data change, content appending, content insertion and content removal by specifying a MutationEffectOnScript flag. By default callers other than the HTML5 parsers always specify "drop trustworthiness" but mIsTrusted flag is not used anyway, so there is no behavior change. Spec: https://w3c.github.io/trusted-types/dist/spec/#enforcement-in-scripts PR: w3c/trusted-types#579 Differential Revision: https://phabricator.services.mozilla.com/D252020 UltraBlame original commit: bb51e4ab08008c6f6920e651994b59de56d19383
1 parent e0e9657 commit da11b10

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+329
-175
lines changed

accessible/generic/DocAccessible.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,8 @@ void DocAccessible::ARIAActiveDescendantChanged(LocalAccessible* aAccessible) {
999999
}
10001000
}
10011001

1002-
void DocAccessible::ContentAppended(nsIContent* aFirstNewContent) {
1002+
void DocAccessible::ContentAppended(nsIContent* aFirstNewContent,
1003+
const ContentAppendInfo&) {
10031004
MaybeHandleChangeToHiddenNameOrDescription(aFirstNewContent);
10041005
}
10051006

@@ -1118,12 +1119,13 @@ void DocAccessible::CharacterDataChanged(nsIContent* aContent,
11181119
MaybeHandleChangeToHiddenNameOrDescription(aContent);
11191120
}
11201121

1121-
void DocAccessible::ContentInserted(nsIContent* aChild) {
1122+
void DocAccessible::ContentInserted(nsIContent* aChild,
1123+
const ContentInsertInfo&) {
11221124
MaybeHandleChangeToHiddenNameOrDescription(aChild);
11231125
}
11241126

11251127
void DocAccessible::ContentWillBeRemoved(nsIContent* aChildNode,
1126-
const BatchRemovalState*) {
1128+
const ContentRemoveInfo&) {
11271129
#ifdef A11Y_LOG
11281130
if (logging::IsEnabled(logging::eTree)) {
11291131
logging::MsgBegin("TREE", "DOM content removed; doc: %p", this);

docshell/shistory/nsSHEntryShared.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,20 +346,22 @@ void nsSHEntryShared::AttributeChanged(dom::Element* aElement,
346346
}
347347
}
348348

349-
void nsSHEntryShared::ContentAppended(nsIContent* aFirstNewContent) {
349+
void nsSHEntryShared::ContentAppended(nsIContent* aFirstNewContent,
350+
const ContentAppendInfo&) {
350351
if (!IgnoreMutationForBfCache(*aFirstNewContent)) {
351352
RemoveFromBFCacheAsync();
352353
}
353354
}
354355

355-
void nsSHEntryShared::ContentInserted(nsIContent* aChild) {
356+
void nsSHEntryShared::ContentInserted(nsIContent* aChild,
357+
const ContentInsertInfo&) {
356358
if (!IgnoreMutationForBfCache(*aChild)) {
357359
RemoveFromBFCacheAsync();
358360
}
359361
}
360362

361363
void nsSHEntryShared::ContentWillBeRemoved(nsIContent* aChild,
362-
const BatchRemovalState*) {
364+
const ContentRemoveInfo&) {
363365
if (!IgnoreMutationForBfCache(*aChild)) {
364366
RemoveFromBFCacheAsync();
365367
}

dom/base/CharacterData.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,12 @@ nsresult CharacterData::SetTextInternal(
243243
}
244244

245245
if (aNotify) {
246-
CharacterDataChangeInfo info = {aOffset == textLength, aOffset, endOffset,
247-
aLength, aDetails};
246+
CharacterDataChangeInfo info = {aOffset == textLength,
247+
aOffset,
248+
endOffset,
249+
aLength,
250+
MutationEffectOnScript::DropTrustWorthiness,
251+
aDetails};
248252
MutationObservers::NotifyCharacterDataWillChange(this, info);
249253
}
250254

@@ -317,8 +321,12 @@ nsresult CharacterData::SetTextInternal(
317321

318322

319323
if (aNotify) {
320-
CharacterDataChangeInfo info = {aOffset == textLength, aOffset, endOffset,
321-
aLength, aDetails};
324+
CharacterDataChangeInfo info = {aOffset == textLength,
325+
aOffset,
326+
endOffset,
327+
aLength,
328+
MutationEffectOnScript::DropTrustWorthiness,
329+
aDetails};
322330
MutationObservers::NotifyCharacterDataChanged(this, info);
323331

324332
if (haveMutationListeners) {

dom/base/CrossShadowBoundaryRange.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void CrossShadowBoundaryRange::DoSetRange(
139139
}
140140
}
141141
void CrossShadowBoundaryRange::ContentWillBeRemoved(nsIContent* aChild,
142-
const BatchRemovalState*) {
142+
const ContentRemoveInfo&) {
143143

144144

145145

dom/base/Document.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,7 +3028,7 @@ void Document::DisconnectNodeTree() {
30283028

30293029
while (nsCOMPtr<nsIContent> content = GetLastChild()) {
30303030
nsMutationGuard::DidMutate();
3031-
MutationObservers::NotifyContentWillBeRemoved(this, content, nullptr);
3031+
MutationObservers::NotifyContentWillBeRemoved(this, content, {});
30323032
DisconnectChild(content);
30333033
if (content == mCachedRootElement) {
30343034

@@ -7769,7 +7769,7 @@ void Document::RemoveChildNode(nsIContent* aKid, bool aNotify,
77697769

77707770

77717771
if (aNotify) {
7772-
MutationObservers::NotifyContentWillBeRemoved(this, aKid, aState);
7772+
MutationObservers::NotifyContentWillBeRemoved(this, aKid, {aState});
77737773
aNotify = false;
77747774
}
77757775

@@ -8760,7 +8760,7 @@ void Document::RemoveCustomContentContainer() {
87608760
container->QueueDevtoolsAnonymousEvent( true);
87618761
}
87628762
if (PresShell* ps = GetPresShell()) {
8763-
ps->ContentWillBeRemoved(container, nullptr);
8763+
ps->ContentWillBeRemoved(container, {});
87648764
}
87658765
container->UnbindFromTree();
87668766
}
@@ -8807,7 +8807,7 @@ void Document::CreateCustomContentContainerIfNeeded() {
88078807
container->QueueDevtoolsAnonymousEvent( false);
88088808
}
88098809
if (PresShell* ps = GetPresShell()) {
8810-
ps->ContentAppended(container);
8810+
ps->ContentAppended(container, {});
88118811
}
88128812
for (auto& anonContent : mAnonymousContents) {
88138813
BindAnonymousContent(*anonContent, *container);
@@ -14784,13 +14784,15 @@ void DevToolsMutationObserver::AttributeChanged(Element* aElement,
1478414784
FireEvent(aElement, u"devtoolsattrmodified"_ns);
1478514785
}
1478614786

14787-
void DevToolsMutationObserver::ContentAppended(nsIContent* aFirstNewContent) {
14787+
void DevToolsMutationObserver::ContentAppended(nsIContent* aFirstNewContent,
14788+
const ContentAppendInfo& aInfo) {
1478814789
for (nsIContent* c = aFirstNewContent; c; c = c->GetNextSibling()) {
14789-
ContentInserted(c);
14790+
ContentInserted(c, aInfo);
1479014791
}
1479114792
}
1479214793

14793-
void DevToolsMutationObserver::ContentInserted(nsIContent* aChild) {
14794+
void DevToolsMutationObserver::ContentInserted(nsIContent* aChild,
14795+
const ContentInsertInfo&) {
1479414796
FireEvent(aChild, u"devtoolschildinserted"_ns);
1479514797
}
1479614798

dom/base/FragmentOrElement.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE_AND_DESTROY(nsIContent,
140140
LastRelease(),
141141
Destroy())
142142

143-
nsIContent*
144-
nsIContent::FindFirstNonChromeOnlyAccessContent() const {
143+
nsIContent* nsIContent::FindFirstNonChromeOnlyAccessContent() const {
145144

146145

147146

@@ -2011,7 +2010,8 @@ void FragmentOrElement::SetInnerHTMLInternal(const nsAString& aInnerHTML,
20112010
doc->GetCompatibilityMode() == eCompatibility_NavQuirks, true);
20122011
doc->ResumeDOMNotifications();
20132012
if (target->GetFirstChild()) {
2014-
MutationObservers::NotifyContentAppended(target, target->GetFirstChild());
2013+
MutationObservers::NotifyContentAppended(target, target->GetFirstChild(),
2014+
{});
20152015
}
20162016
mb.NodesAdded();
20172017

dom/base/MutationObservers.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,31 +161,33 @@ void MutationObservers::NotifyAttributeSetToCurrentValue(Element* aElement,
161161
}
162162

163163
void MutationObservers::NotifyContentAppended(nsIContent* aContainer,
164-
nsIContent* aFirstNewContent) {
164+
nsIContent* aFirstNewContent,
165+
const ContentAppendInfo& aInfo) {
165166
aContainer->OwnerDoc()->Changed();
166-
Notify(aContainer, NOTIFIER(ContentAppended, aFirstNewContent),
167+
Notify(aContainer, NOTIFIER(ContentAppended, aFirstNewContent, aInfo),
167168
nsIMutationObserver::kContentAppended);
168169
}
169170

170171
void MutationObservers::NotifyContentInserted(nsINode* aContainer,
171-
nsIContent* aChild) {
172+
nsIContent* aChild,
173+
const ContentInsertInfo& aInfo) {
172174
MOZ_ASSERT(aContainer->IsContent() || aContainer->IsDocument(),
173175
"container must be an nsIContent or an Document");
174176
aContainer->OwnerDoc()->Changed();
175-
Notify(aContainer, NOTIFIER(ContentInserted, aChild),
177+
Notify(aContainer, NOTIFIER(ContentInserted, aChild, aInfo),
176178
nsIMutationObserver::kContentInserted);
177179
}
178180

179181
void MutationObservers::NotifyContentWillBeRemoved(
180-
nsINode* aContainer, nsIContent* aChild, const BatchRemovalState* aState) {
182+
nsINode* aContainer, nsIContent* aChild, const ContentRemoveInfo& aInfo) {
181183
MOZ_ASSERT(aContainer->IsContent() || aContainer->IsDocument(),
182184
"container must be an nsIContent or an Document");
183185
MOZ_ASSERT(aChild->GetParentNode() == aContainer,
184186
"We expect the parent link to be still around at this point");
185187
aContainer->OwnerDoc()->Changed();
186-
Notify<NotifyPresShell::Before>(
187-
aContainer, NOTIFIER(ContentWillBeRemoved, aChild, aState),
188-
nsIMutationObserver::kContentWillBeRemoved);
188+
Notify<NotifyPresShell::Before>(aContainer,
189+
NOTIFIER(ContentWillBeRemoved, aChild, aInfo),
190+
nsIMutationObserver::kContentWillBeRemoved);
189191
}
190192

191193
void MutationObservers::NotifyARIAAttributeDefaultWillChange(

dom/base/MutationObservers.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,22 @@ class MutationObservers {
8484

8585

8686

87+
88+
8789
static void NotifyContentAppended(nsIContent* aContainer,
88-
nsIContent* aFirstNewContent);
90+
nsIContent* aFirstNewContent,
91+
const ContentAppendInfo&);
8992

9093

9194

9295

9396

9497

9598

96-
static void NotifyContentInserted(nsINode* aContainer, nsIContent* aChild);
97-
9899

100+
static void NotifyContentInserted(nsINode* aContainer, nsIContent* aChild,
101+
const ContentInsertInfo&);
102+
99103

100104

101105

@@ -104,7 +108,7 @@ class MutationObservers {
104108

105109
static void NotifyContentWillBeRemoved(nsINode* aContainer,
106110
nsIContent* aChild,
107-
const BatchRemovalState*);
111+
const ContentRemoveInfo&);
108112

109113

110114

dom/base/NodeIterator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void NodeIterator::Detach() {
202202

203203

204204
void NodeIterator::ContentWillBeRemoved(nsIContent* aChild,
205-
const BatchRemovalState*) {
205+
const ContentRemoveInfo&) {
206206
nsINode* container = aChild->GetParentNode();
207207
mPointer.AdjustForRemoval(mRoot, container, aChild);
208208
mWorkingPointer.AdjustForRemoval(mRoot, container, aChild);

dom/base/nsContentList.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,8 @@ void nsContentList::AttributeChanged(Element* aElement, int32_t aNameSpaceID,
706706
}
707707
}
708708

709-
void nsContentList::ContentAppended(nsIContent* aFirstNewContent) {
709+
void nsContentList::ContentAppended(nsIContent* aFirstNewContent,
710+
const ContentAppendInfo&) {
710711
nsIContent* container = aFirstNewContent->GetParent();
711712
MOZ_ASSERT(container, "Can't get at the new content if no container!");
712713

@@ -800,7 +801,8 @@ void nsContentList::ContentAppended(nsIContent* aFirstNewContent) {
800801
ASSERT_IN_SYNC;
801802
}
802803

803-
void nsContentList::ContentInserted(nsIContent* aChild) {
804+
void nsContentList::ContentInserted(nsIContent* aChild,
805+
const ContentInsertInfo&) {
804806

805807

806808

@@ -815,7 +817,7 @@ void nsContentList::ContentInserted(nsIContent* aChild) {
815817
}
816818

817819
void nsContentList::ContentWillBeRemoved(nsIContent* aChild,
818-
const BatchRemovalState*) {
820+
const ContentRemoveInfo&) {
819821
if (mState != State::Dirty &&
820822
MayContainRelevantNodes(aChild->GetParentNode()) &&
821823
nsContentUtils::IsInSameAnonymousTree(mRootNode, aChild) &&
@@ -1115,7 +1117,8 @@ void nsLabelsNodeList::AttributeChanged(Element* aElement, int32_t aNameSpaceID,
11151117
}
11161118
}
11171119

1118-
void nsLabelsNodeList::ContentAppended(nsIContent* aFirstNewContent) {
1120+
void nsLabelsNodeList::ContentAppended(nsIContent* aFirstNewContent,
1121+
const ContentAppendInfo&) {
11191122
nsIContent* container = aFirstNewContent->GetParent();
11201123

11211124

@@ -1127,7 +1130,8 @@ void nsLabelsNodeList::ContentAppended(nsIContent* aFirstNewContent) {
11271130
}
11281131
}
11291132

1130-
void nsLabelsNodeList::ContentInserted(nsIContent* aChild) {
1133+
void nsLabelsNodeList::ContentInserted(nsIContent* aChild,
1134+
const ContentInsertInfo&) {
11311135

11321136

11331137

@@ -1139,7 +1143,7 @@ void nsLabelsNodeList::ContentInserted(nsIContent* aChild) {
11391143
}
11401144

11411145
void nsLabelsNodeList::ContentWillBeRemoved(nsIContent* aChild,
1142-
const BatchRemovalState* aState) {
1146+
const ContentRemoveInfo&) {
11431147

11441148

11451149
if (mState != State::Dirty &&

0 commit comments

Comments
 (0)