Bug 1415352: Part 4b - Capture the subject principal in textContent setters. r?bz
This is necessary in order to capture the correct triggering principal for
inline <style> nodes.
MozReview-Commit-ID: 7g1n3bdHVi4
--- a/dom/base/Attr.cpp
+++ b/dom/base/Attr.cpp
@@ -277,16 +277,17 @@ void
Attr::GetTextContentInternal(nsAString& aTextContent,
OOMReporter& aError)
{
GetValue(aTextContent);
}
void
Attr::SetTextContentInternal(const nsAString& aTextContent,
+ nsIPrincipal* aSubjectPrincipal,
ErrorResult& aError)
{
SetNodeValueInternal(aTextContent, aError);
}
NS_IMETHODIMP
Attr::GetIsId(bool* aReturn)
{
--- a/dom/base/Attr.h
+++ b/dom/base/Attr.h
@@ -41,16 +41,17 @@ public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
// nsIDOMNode interface
NS_FORWARD_NSIDOMNODE_TO_NSINODE
virtual void GetTextContentInternal(nsAString& aTextContent,
OOMReporter& aError) override;
virtual void SetTextContentInternal(const nsAString& aTextContent,
+ nsIPrincipal* aSubjectPrincipal,
ErrorResult& aError) override;
virtual void GetNodeValueInternal(nsAString& aNodeValue) override;
virtual void SetNodeValueInternal(const nsAString& aNodeValue,
ErrorResult& aError) override;
// nsIDOMAttr interface
NS_DECL_NSIDOMATTR
--- a/dom/base/FragmentOrElement.cpp
+++ b/dom/base/FragmentOrElement.cpp
@@ -1349,16 +1349,17 @@ FragmentOrElement::GetTextContentInterna
{
if (!nsContentUtils::GetNodeTextContent(this, true, aTextContent, fallible)) {
aError.ReportOOM();
}
}
void
FragmentOrElement::SetTextContentInternal(const nsAString& aTextContent,
+ nsIPrincipal* aSubjectPrincipal,
ErrorResult& aError)
{
aError = nsContentUtils::SetNodeTextContent(this, aTextContent, false);
}
void
FragmentOrElement::DestroyContent()
{
--- a/dom/base/FragmentOrElement.h
+++ b/dom/base/FragmentOrElement.h
@@ -121,16 +121,17 @@ public:
virtual nsIContent *GetChildAt(uint32_t aIndex) const override;
virtual int32_t IndexOf(const nsINode* aPossibleChild) const override;
virtual nsresult InsertChildAt(nsIContent* aKid, uint32_t aIndex,
bool aNotify) override;
virtual void RemoveChildAt(uint32_t aIndex, bool aNotify) override;
virtual void GetTextContentInternal(nsAString& aTextContent,
mozilla::OOMReporter& aError) override;
virtual void SetTextContentInternal(const nsAString& aTextContent,
+ nsIPrincipal* aSubjectPrincipal,
mozilla::ErrorResult& aError) override;
// nsIContent interface methods
virtual already_AddRefed<nsINodeList> GetChildren(uint32_t aFilter) override;
virtual const nsTextFragment *GetText() override;
virtual uint32_t TextLength() const override;
virtual nsresult SetText(const char16_t* aBuffer, uint32_t aLength,
bool aNotify) override;
--- a/dom/base/nsGenericDOMDataNode.h
+++ b/dom/base/nsGenericDOMDataNode.h
@@ -111,16 +111,17 @@ public:
bool aNotify) override;
virtual void RemoveChildAt(uint32_t aIndex, bool aNotify) override;
virtual void GetTextContentInternal(nsAString& aTextContent,
mozilla::OOMReporter& aError) override
{
GetNodeValue(aTextContent);
}
virtual void SetTextContentInternal(const nsAString& aTextContent,
+ nsIPrincipal* aSubjectPrincipal,
mozilla::ErrorResult& aError) override
{
// Batch possible DOMSubtreeModified events.
mozAutoSubtreeModified subtree(OwnerDoc(), nullptr);
return SetNodeValue(aTextContent, aError);
}
// Implementation for nsIContent
--- a/dom/base/nsINode.h
+++ b/dom/base/nsINode.h
@@ -1330,24 +1330,36 @@ public:
// a way to ask an element whether it's an HTMLShadowElement.
virtual bool IsHTMLShadowElement() const { return false; }
// Elements named <content> may or may not be HTMLContentElement. This is a
// way to ask an element whether it's an HTMLContentElement.
virtual bool IsHTMLContentElement() const { return false; }
void GetTextContent(nsAString& aTextContent,
+ nsIPrincipal& aSubjectPrincipal,
+ mozilla::OOMReporter& aError)
+ {
+ GetTextContentInternal(aTextContent, aError);
+ }
+ void GetTextContent(nsAString& aTextContent,
mozilla::OOMReporter& aError)
{
GetTextContentInternal(aTextContent, aError);
}
void SetTextContent(const nsAString& aTextContent,
+ nsIPrincipal& aSubjectPrincipal,
mozilla::ErrorResult& aError)
{
- SetTextContentInternal(aTextContent, aError);
+ SetTextContentInternal(aTextContent, &aSubjectPrincipal, aError);
+ }
+ void SetTextContent(const nsAString& aTextContent,
+ mozilla::ErrorResult& aError)
+ {
+ SetTextContentInternal(aTextContent, nullptr, aError);
}
mozilla::dom::Element* QuerySelector(const nsAString& aSelector,
mozilla::ErrorResult& aResult);
already_AddRefed<nsINodeList> QuerySelectorAll(const nsAString& aSelector,
mozilla::ErrorResult& aResult);
protected:
@@ -1988,16 +2000,17 @@ protected:
virtual bool IsEditableExternal() const
{
return IsEditableInternal();
}
virtual void GetTextContentInternal(nsAString& aTextContent,
mozilla::OOMReporter& aError);
virtual void SetTextContentInternal(const nsAString& aTextContent,
+ nsIPrincipal* aSubjectPrincipal,
mozilla::ErrorResult& aError)
{
}
#ifdef DEBUG
// Note: virtual so that IsInNativeAnonymousSubtree can be called accross
// module boundaries.
virtual void CheckNotNativeAnonymous() const;
--- a/dom/webidl/Node.webidl
+++ b/dom/webidl/Node.webidl
@@ -54,17 +54,17 @@ interface Node : EventTarget {
readonly attribute Node? lastChild;
[Pure]
readonly attribute Node? previousSibling;
[Pure]
readonly attribute Node? nextSibling;
[CEReactions, SetterThrows, Pure]
attribute DOMString? nodeValue;
- [CEReactions, SetterThrows, GetterCanOOM, Pure]
+ [CEReactions, SetterThrows, GetterCanOOM, NeedsSubjectPrincipal, Pure]
attribute DOMString? textContent;
[CEReactions, Throws]
Node insertBefore(Node node, Node? child);
[CEReactions, Throws]
Node appendChild(Node node);
[CEReactions, Throws]
Node replaceChild(Node node, Node child);
[CEReactions, Throws]