Bug 1384162 part 3 - Move document container setting into nsContentDLF::CreateBlankDocument before adding any nodes. r?bz draft
authorXidorn Quan <me@upsuper.org>
Wed, 26 Jul 2017 20:02:58 +1000
changeset 616305 f6b2f32fb4e7b3cb1022d1fef0722435d25d0d46
parent 615801 caef389697d2574703670b693297ad4c4c66b2ec
child 616306 0fab994aaebb13f3f1cf86d6b390536656a111ff
push id70642
push userxquan@mozilla.com
push dateWed, 26 Jul 2017 22:23:16 +0000
reviewersbz
bugs1384162
milestone56.0a1
Bug 1384162 part 3 - Move document container setting into nsContentDLF::CreateBlankDocument before adding any nodes. r?bz MozReview-Commit-ID: KdXQH5eRD7a
docshell/base/nsDocShell.cpp
layout/build/nsContentDLF.cpp
layout/build/nsContentDLF.h
testing/web-platform/meta/cssom-view/matchMedia.xht.ini
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -8182,24 +8182,22 @@ nsDocShell::CreateAboutBlankContentViewe
         principal = NullPrincipal::CreateWithInheritedAttributes(aPrincipal);
       } else {
         principal = NullPrincipal::CreateWithInheritedAttributes(this);
       }
     } else {
       principal = aPrincipal;
     }
     // generate (about:blank) document to load
-    blankDoc = nsContentDLF::CreateBlankDocument(mLoadGroup, principal);
+    blankDoc = nsContentDLF::CreateBlankDocument(mLoadGroup, principal, this);
     if (blankDoc) {
       // Hack: set the base URI manually, since this document never
       // got Reset() with a channel.
       blankDoc->SetBaseURI(aBaseURI);
 
-      blankDoc->SetContainer(this);
-
       // Copy our sandbox flags to the document. These are immutable
       // after being set here.
       blankDoc->SetSandboxFlags(mSandboxFlags);
 
       // create a content viewer for us and the new document
       docFactory->CreateInstanceForDocument(
         NS_ISUPPORTS_CAST(nsIDocShell*, this), blankDoc, "view",
         getter_AddRefs(viewer));
--- a/layout/build/nsContentDLF.cpp
+++ b/layout/build/nsContentDLF.cpp
@@ -260,32 +260,34 @@ nsContentDLF::CreateInstanceForDocument(
   // Bind the document to the Content Viewer
   contentViewer->LoadStart(aDocument);
   contentViewer.forget(aContentViewer);
   return NS_OK;
 }
 
 /* static */ already_AddRefed<nsIDocument>
 nsContentDLF::CreateBlankDocument(nsILoadGroup* aLoadGroup,
-                                  nsIPrincipal* aPrincipal)
+                                  nsIPrincipal* aPrincipal,
+                                  nsDocShell* aContainer)
 {
   // create a new blank HTML document
   nsCOMPtr<nsIDocument> blankDoc(do_CreateInstance(kHTMLDocumentCID));
 
   if (!blankDoc) {
     return nullptr;
   }
 
   // initialize
   nsCOMPtr<nsIURI> uri;
   NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING("about:blank"));
   if (!uri) {
     return nullptr;
   }
   blankDoc->ResetToURI(uri, aLoadGroup, aPrincipal);
+  blankDoc->SetContainer(aContainer);
 
   // add some simple content structure
   nsNodeInfoManager *nim = blankDoc->NodeInfoManager();
 
   RefPtr<mozilla::dom::NodeInfo> htmlNodeInfo;
 
   // generate an html html element
   htmlNodeInfo = nim->GetNodeInfo(nsGkAtoms::html, 0, kNameSpaceID_XHTML,
--- a/layout/build/nsContentDLF.h
+++ b/layout/build/nsContentDLF.h
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsContentDLF_h__
 #define nsContentDLF_h__
 
 #include "nsIDocumentLoaderFactory.h"
 #include "nsMimeTypes.h"
 
+class nsDocShell;
 class nsIChannel;
 class nsIContentViewer;
 class nsILoadGroup;
 class nsIStreamListener;
 
 #define CONTENT_DLF_CONTRACTID "@mozilla.org/content/document-loader-factory;1"
 #define PLUGIN_DLF_CONTRACTID "@mozilla.org/content/plugin/document-loader-factory;1"
 
@@ -47,17 +48,19 @@ public:
                              nsIContentViewer** aContentViewer);
 
   /**
    * Create a blank document using the given loadgroup and given
    * principal.  aPrincipal is allowed to be null, in which case the
    * new document will get the about:blank codebase principal.
    */
   static already_AddRefed<nsIDocument>
-  CreateBlankDocument(nsILoadGroup* aLoadGroup, nsIPrincipal* aPrincipal);
+  CreateBlankDocument(nsILoadGroup* aLoadGroup,
+                      nsIPrincipal* aPrincipal,
+                      nsDocShell* aContainer);
 
 private:
   static nsresult EnsureUAStyleSheet();
   static bool IsImageContentType(const char* aContentType);
 };
 
 nsresult
 NS_NewContentDocumentLoaderFactory(nsIDocumentLoaderFactory** aResult);
--- a/testing/web-platform/meta/cssom-view/matchMedia.xht.ini
+++ b/testing/web-platform/meta/cssom-view/matchMedia.xht.ini
@@ -1,16 +1,18 @@
 [matchMedia.xht]
   type: testharness
   expected: TIMEOUT
   [window.matchMedia exists]
     expected: FAIL
 
   [MediaQueryList.matches for "(max-width: 199px), all and (min-width: 200px)"]
-    expected: FAIL
+    expected:
+      if stylo: PASS
+      FAIL
 
   [Resize iframe from 200x100 to 200x50, then to 100x50]
     expected: NOTRUN
 
   [Listeners are called in the order which they have been added]
     expected: NOTRUN
 
   [Listener added twice is only called once.]