Bug 1391994 Part 1: Define Element::setAttributeSystem and ::setAttributeSystemNS to allow Chrome callers to set attributes using the System Principal.
MozReview-Commit-ID: 8pn0D1E3Xp8
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -1440,16 +1440,43 @@ Element::SetAttributeNS(const nsAString&
return;
}
aError = SetAttr(ni->NamespaceID(), ni->NameAtom(), ni->GetPrefixAtom(),
aValue, aTriggeringPrincipal, true);
}
void
+Element::SetAttributeSystem(const nsAString& aName,
+ const nsAString& aValue,
+ ErrorResult& aError)
+{
+ // Run this through SetAttribute with the System Principal.
+ nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
+ nsCOMPtr<nsIPrincipal> sysPrincipal;
+ ssm->GetSystemPrincipal(getter_AddRefs(sysPrincipal));
+
+ SetAttribute(aName, aValue, sysPrincipal, aError);
+}
+
+void
+Element::SetAttributeSystemNS(const nsAString& aNamespaceURI,
+ const nsAString& aLocalName,
+ const nsAString& aValue,
+ ErrorResult& aError)
+{
+ // Run this through SetAttributeNS with the System Principal.
+ nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
+ nsCOMPtr<nsIPrincipal> sysPrincipal;
+ ssm->GetSystemPrincipal(getter_AddRefs(sysPrincipal));
+
+ SetAttributeNS(aNamespaceURI, aLocalName, aValue, sysPrincipal, aError);
+}
+
+void
Element::RemoveAttributeNS(const nsAString& aNamespaceURI,
const nsAString& aLocalName,
ErrorResult& aError)
{
RefPtr<nsAtom> name = NS_AtomizeMainThread(aLocalName);
int32_t nsid =
nsContentUtils::NameSpaceManager()->GetNameSpaceID(aNamespaceURI,
nsContentUtils::IsChromeDoc(OwnerDoc()));
--- a/dom/base/Element.h
+++ b/dom/base/Element.h
@@ -1135,16 +1135,23 @@ public:
const nsAString& aValue,
nsIPrincipal* aTriggeringPrincipal,
ErrorResult& aError);
void SetAttribute(const nsAString& aName, const nsAString& aValue,
ErrorResult& aError)
{
SetAttribute(aName, aValue, nullptr, aError);
}
+ void SetAttributeSystem(const nsAString& aName,
+ const nsAString& aValue,
+ ErrorResult& aError);
+ void SetAttributeSystemNS(const nsAString& aNamespaceURI,
+ const nsAString& aLocalName,
+ const nsAString& aValue,
+ ErrorResult& aError);
void RemoveAttribute(const nsAString& aName,
ErrorResult& aError);
void RemoveAttributeNS(const nsAString& aNamespaceURI,
const nsAString& aLocalName,
ErrorResult& aError);
bool HasAttribute(const nsAString& aName) const
{
--- a/dom/webidl/Element.webidl
+++ b/dom/webidl/Element.webidl
@@ -39,16 +39,20 @@ interface Element : Node {
[Pure]
DOMString? getAttribute(DOMString name);
[Pure]
DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
[CEReactions, NeedsSubjectPrincipal=NonSystem, Throws]
void setAttribute(DOMString name, DOMString value);
[CEReactions, NeedsSubjectPrincipal=NonSystem, Throws]
void setAttributeNS(DOMString? namespace, DOMString name, DOMString value);
+ [ChromeOnly, CEReactions, Throws]
+ void setAttributeSystem(DOMString name, DOMString value);
+ [ChromeOnly, CEReactions, Throws]
+ void setAttributeSystemNS(DOMString? namespace, DOMString name, DOMString value);
[CEReactions, Throws]
void removeAttribute(DOMString name);
[CEReactions, Throws]
void removeAttributeNS(DOMString? namespace, DOMString localName);
[Pure]
boolean hasAttribute(DOMString name);
[Pure]
boolean hasAttributeNS(DOMString? namespace, DOMString localName);