Bug 1391994 Part 1: Define Element::setAttributeSystem and ::setAttributeSystemNS to allow Chrome callers to set attributes using the System Principal. draft
authorBrad Werth <bwerth@mozilla.com>
Mon, 08 Jan 2018 16:15:58 -0800
changeset 718849 4e8c696c41c0475ee9be182ba646b9a4c2ab57a1
parent 718505 d5f42a23909eb181274731b07e4984bfbd18557d
child 718850 68b0967cd2db7ee426a88aa7e38eb2ac8c0adccc
push id95059
push userbwerth@mozilla.com
push dateWed, 10 Jan 2018 22:45:04 +0000
bugs1391994
milestone59.0a1
Bug 1391994 Part 1: Define Element::setAttributeSystem and ::setAttributeSystemNS to allow Chrome callers to set attributes using the System Principal. MozReview-Commit-ID: 8pn0D1E3Xp8
dom/base/Element.cpp
dom/base/Element.h
dom/webidl/Element.webidl
--- 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);