Bug 1306241 - Use NeedsSubjectPrincipal in dom/html/* - part 2, r=ehsan
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 03 Oct 2016 10:34:29 +0200
changeset 316222 98bcafb5ec2ca852a40430fa87cf840852903b36
parent 316221 dffc1cba16ebb105bd6e3d8a6aea04ec698e7dbe
child 316223 a99817b61d70c8ae47fdd60993d16638536f000f
push id30766
push userphilringnalda@gmail.com
push dateTue, 04 Oct 2016 03:09:34 +0000
treeherdermozilla-central@c8a660c5f105 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1306241
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1306241 - Use NeedsSubjectPrincipal in dom/html/* - part 2, r=ehsan
dom/base/nsObjectLoadingContent.cpp
dom/base/nsObjectLoadingContent.h
dom/html/HTMLObjectElement.cpp
dom/html/HTMLObjectElement.h
dom/html/HTMLSharedObjectElement.h
dom/webidl/HTMLEmbedElement.webidl
dom/webidl/HTMLObjectElement.webidl
--- a/dom/base/nsObjectLoadingContent.cpp
+++ b/dom/base/nsObjectLoadingContent.cpp
@@ -3532,32 +3532,34 @@ nsObjectLoadingContent::ShouldPlay(Fallb
     return true;
   case nsIPluginTag::STATE_CLICKTOPLAY:
     return false;
   }
   MOZ_CRASH("Unexpected enabledState");
 }
 
 nsIDocument*
-nsObjectLoadingContent::GetContentDocument()
+nsObjectLoadingContent::GetContentDocument(const mozilla::Maybe<nsIPrincipal*>& aSubjectPrincipal)
 {
+  MOZ_ASSERT(aSubjectPrincipal.isSome());
+
   nsCOMPtr<nsIContent> thisContent =
     do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
 
   if (!thisContent->IsInComposedDoc()) {
     return nullptr;
   }
 
   nsIDocument *sub_doc = thisContent->OwnerDoc()->GetSubDocumentFor(thisContent);
   if (!sub_doc) {
     return nullptr;
   }
 
   // Return null for cross-origin contentDocument.
-  if (!nsContentUtils::SubjectPrincipal()->SubsumesConsideringDomain(sub_doc->NodePrincipal())) {
+  if (!aSubjectPrincipal.value()->SubsumesConsideringDomain(sub_doc->NodePrincipal())) {
     return nullptr;
   }
 
   return sub_doc;
 }
 
 void
 nsObjectLoadingContent::LegacyCall(JSContext* aCx,
--- a/dom/base/nsObjectLoadingContent.h
+++ b/dom/base/nsObjectLoadingContent.h
@@ -22,16 +22,17 @@
 #include "nsIRunnable.h"
 #include "nsIThreadInternal.h"
 #include "nsIFrame.h"
 #include "nsIFrameLoader.h"
 
 class nsAsyncInstantiateEvent;
 class nsStopPluginRunnable;
 class AutoSetInstantiatingToFalse;
+class nsIPrincipal;
 class nsFrameLoader;
 class nsPluginFrame;
 class nsXULElement;
 class nsPluginInstanceOwner;
 
 namespace mozilla {
 namespace dom {
 template<typename T> class Sequence;
@@ -174,17 +175,17 @@ class nsObjectLoadingContent : public ns
     // id.  If in doubt, return true.
     static bool MayResolve(jsid aId);
 
     // Helper for WebIDL enumeration
     void GetOwnPropertyNames(JSContext* aCx, nsTArray<nsString>& /* unused */,
                              mozilla::ErrorResult& aRv);
 
     // WebIDL API
-    nsIDocument* GetContentDocument();
+    nsIDocument* GetContentDocument(const mozilla::Maybe<nsIPrincipal*>& aSubjectPrincipal);
     void GetActualType(nsAString& aType) const
     {
       CopyUTF8toUTF16(mContentType, aType);
     }
     uint32_t DisplayedType() const
     {
       return mType;
     }
--- a/dom/html/HTMLObjectElement.cpp
+++ b/dom/html/HTMLObjectElement.cpp
@@ -460,25 +460,26 @@ HTMLObjectElement::TabIndexDefault()
   return IsFocusableForTabIndex() ? 0 : -1;
 }
 
 NS_IMETHODIMP
 HTMLObjectElement::GetContentDocument(nsIDOMDocument **aContentDocument)
 {
   NS_ENSURE_ARG_POINTER(aContentDocument);
 
-  nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(GetContentDocument());
+  nsCOMPtr<nsIDOMDocument> domDoc =
+    do_QueryInterface(GetContentDocument(Some(nsContentUtils::SubjectPrincipal())));
   domDoc.forget(aContentDocument);
   return NS_OK;
 }
 
 nsPIDOMWindowOuter*
-HTMLObjectElement::GetContentWindow()
+HTMLObjectElement::GetContentWindow(const mozilla::Maybe<nsIPrincipal*>& aSubjectPrincipal)
 {
-  nsIDocument* doc = GetContentDocument();
+  nsIDocument* doc = GetContentDocument(aSubjectPrincipal);
   if (doc) {
     return doc->GetWindow();
   }
 
   return nullptr;
 }
 
 bool
--- a/dom/html/HTMLObjectElement.h
+++ b/dom/html/HTMLObjectElement.h
@@ -151,17 +151,20 @@ public:
   {
     GetHTMLAttr(nsGkAtoms::height, aValue);
   }
   void SetHeight(const nsAString& aValue, ErrorResult& aRv)
   {
     SetHTMLAttr(nsGkAtoms::height, aValue, aRv);
   }
   using nsObjectLoadingContent::GetContentDocument;
-  nsPIDOMWindowOuter* GetContentWindow();
+
+  nsPIDOMWindowOuter*
+  GetContentWindow(const mozilla::Maybe<nsIPrincipal*>& aSubjectPrincipal);
+
   using nsIConstraintValidation::CheckValidity;
   using nsIConstraintValidation::ReportValidity;
   using nsIConstraintValidation::GetValidationMessage;
   void GetAlign(DOMString& aValue)
   {
     GetHTMLAttr(nsGkAtoms::align, aValue);
   }
   void SetAlign(const nsAString& aValue, ErrorResult& aRv)
@@ -229,19 +232,21 @@ public:
   void GetBorder(DOMString& aValue)
   {
     GetHTMLAttr(nsGkAtoms::border, aValue);
   }
   void SetBorder(const nsAString& aValue, ErrorResult& aRv)
   {
     SetHTMLAttr(nsGkAtoms::border, aValue, aRv);
   }
-  nsIDocument* GetSVGDocument()
+
+  nsIDocument*
+  GetSVGDocument(const mozilla::Maybe<nsIPrincipal*>& aSubjectPrincipal)
   {
-    return GetContentDocument();
+    return GetContentDocument(aSubjectPrincipal);
   }
 
 private:
   /**
    * Calls LoadObject with the correct arguments to start the plugin load.
    */
   void StartObjectLoad(bool aNotify);
 
--- a/dom/html/HTMLSharedObjectElement.h
+++ b/dom/html/HTMLSharedObjectElement.h
@@ -182,19 +182,20 @@ public:
   void SetType(const nsAString& aValue, ErrorResult& aRv)
   {
     SetHTMLAttr(nsGkAtoms::type, aValue, aRv);
   }
   // width covered by <applet>
   // height covered by <applet>
   // align covered by <applet>
   // name covered by <applet>
-  nsIDocument* GetSVGDocument()
+  nsIDocument*
+  GetSVGDocument(const mozilla::Maybe<nsIPrincipal*>& aSubjectPrincipal)
   {
-    return GetContentDocument();
+    return GetContentDocument(aSubjectPrincipal);
   }
 
   /**
    * Calls LoadObject with the correct arguments to start the plugin load.
    */
   void StartObjectLoad(bool aNotify, bool aForceLoad);
 private:
   virtual ~HTMLSharedObjectElement();
--- a/dom/webidl/HTMLEmbedElement.webidl
+++ b/dom/webidl/HTMLEmbedElement.webidl
@@ -32,14 +32,15 @@ partial interface HTMLEmbedElement {
   [Pure, SetterThrows]
            attribute DOMString align;
   [Pure, SetterThrows]
            attribute DOMString name;
 };
 
 partial interface HTMLEmbedElement {
   // GetSVGDocument
+  [NeedsSubjectPrincipal]
   Document? getSVGDocument();
 };
 
 HTMLEmbedElement implements MozImageLoadingContent;
 HTMLEmbedElement implements MozFrameLoaderOwner;
 HTMLEmbedElement implements MozObjectLoadingContent;
--- a/dom/webidl/HTMLObjectElement.webidl
+++ b/dom/webidl/HTMLObjectElement.webidl
@@ -27,18 +27,20 @@ interface HTMLObjectElement : HTMLElemen
            attribute DOMString useMap;
   [Pure]
   readonly attribute HTMLFormElement? form;
   [Pure, SetterThrows]
            attribute DOMString width;
   [Pure, SetterThrows]
            attribute DOMString height;
   // Not pure: can trigger about:blank instantiation
+  [NeedsSubjectPrincipal]
   readonly attribute Document? contentDocument;
   // Not pure: can trigger about:blank instantiation
+  [NeedsSubjectPrincipal]
   readonly attribute WindowProxy? contentWindow;
 
   readonly attribute boolean willValidate;
   readonly attribute ValidityState validity;
   readonly attribute DOMString validationMessage;
   boolean checkValidity();
   boolean reportValidity();
   void setCustomValidity(DOMString error);
@@ -69,16 +71,17 @@ partial interface HTMLObjectElement {
            attribute DOMString codeType;
 
   [TreatNullAs=EmptyString, Pure, SetterThrows]
            attribute DOMString border;
 };
 
 partial interface HTMLObjectElement {
   // GetSVGDocument
+  [NeedsSubjectPrincipal]
   Document? getSVGDocument();
 };
 
 [NoInterfaceObject]
 interface MozObjectLoadingContent {
   // Mirrored chrome-only scriptable nsIObjectLoadingContent methods.  Please
   // make sure to update this list if nsIObjectLoadingContent changes.  Also,
   // make sure everything on here is [ChromeOnly].