Bug 1376497 - Put XHR docs in a DocGroup. draft
authorHenri Sivonen <hsivonen@hsivonen.fi>
Thu, 14 Sep 2017 13:28:00 +0300
changeset 664786 19ba80920ec67239a565c6b3f9863c21dd940fd7
parent 664785 bc3d643c49739f2576a5f94eb53a13d3d3b4ebaf
child 731542 967b5e755cf1583043f69344b34568e1bd0cb11b
push id79802
push userbmo:hsivonen@hsivonen.fi
push dateThu, 14 Sep 2017 10:54:17 +0000
bugs1376497
milestone57.0a1
Bug 1376497 - Put XHR docs in a DocGroup. MozReview-Commit-ID: 5aMgfIvMfJI
dom/base/nsDocument.cpp
dom/base/nsDocument.h
dom/base/nsIDocument.h
dom/xhr/XMLHttpRequestMainThread.cpp
parser/html/nsHtml5StreamParser.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -4886,16 +4886,28 @@ nsDocument::SetScopeObject(nsIGlobalObje
       } else {
         mDocGroup = tabgroup->AddDocument(docGroupKey, this);
         MOZ_ASSERT(mDocGroup);
       }
     }
   }
 }
 
+void
+nsDocument::SetDocGroupWithoutScopeObject(mozilla::dom::DocGroup* aDocGroup)
+{
+  MOZ_ASSERT(!mHasHadScriptHandlingObject);
+  nsAutoCString docGroupKey;
+  nsresult rv =
+    mozilla::dom::DocGroup::GetKey(NodePrincipal(), docGroupKey);
+  MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv), "How come getting the doc group key failed for XHR?");
+  mDocGroup = aDocGroup->GetTabGroup()->AddDocument(docGroupKey, this);
+  MOZ_ASSERT(mDocGroup);
+}
+
 static void
 CheckIfContainsEMEContent(nsISupports* aSupports, void* aContainsEME)
 {
   nsCOMPtr<nsIDOMHTMLMediaElement> domMediaElem(do_QueryInterface(aSupports));
   if (domMediaElem) {
     nsCOMPtr<nsIContent> content(do_QueryInterface(domMediaElem));
     MOZ_ASSERT(content, "aSupports is not a content");
     HTMLMediaElement* mediaElem = static_cast<HTMLMediaElement*>(content.get());
--- a/dom/base/nsDocument.h
+++ b/dom/base/nsDocument.h
@@ -530,16 +530,19 @@ public:
   }
 
   virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject) override;
 
   virtual void SetScriptHandlingObject(nsIScriptGlobalObject* aScriptObject) override;
 
   virtual nsIGlobalObject* GetScopeObject() const override;
   void SetScopeObject(nsIGlobalObject* aGlobal) override;
+
+  void SetDocGroupWithoutScopeObject(mozilla::dom::DocGroup* aDocGroup) override;
+
   /**
    * Get the script loader for this document
    */
   virtual mozilla::dom::ScriptLoader* ScriptLoader() override;
 
   /**
    * Add/Remove an element to the document's id and name hashes
    */
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -1401,16 +1401,18 @@ public:
    * wrappers whose owner document is this document. Unlike the script global
    * object, this will only return null when the global object for this
    * document is truly gone. Use this object when you're trying to find a
    * content wrapper in XPConnect.
    */
   virtual nsIGlobalObject* GetScopeObject() const = 0;
   virtual void SetScopeObject(nsIGlobalObject* aGlobal) = 0;
 
+  virtual void SetDocGroupWithoutScopeObject(mozilla::dom::DocGroup* aDocGroup) = 0;
+
   /**
    * Return the window containing the document (the outer window).
    */
   nsPIDOMWindowOuter *GetWindow() const
   {
     return mWindow ? mWindow->GetOuterWindow() : GetWindowInternal();
   }
 
--- a/dom/xhr/XMLHttpRequestMainThread.cpp
+++ b/dom/xhr/XMLHttpRequestMainThread.cpp
@@ -2162,20 +2162,23 @@ XMLHttpRequestMainThread::OnStartRequest
 
     rv = NS_NewDOMDocument(getter_AddRefs(responseDoc),
                            emptyStr, emptyStr, nullptr, docURI,
                            baseURI, requestingPrincipal, true, global,
                            mIsHtml ? DocumentFlavorHTML :
                                      DocumentFlavorLegacyGuess,
                            mStyleBackend);
     NS_ENSURE_SUCCESS(rv, rv);
+
     mResponseXML = do_QueryInterface(responseDoc);
     mResponseXML->SetChromeXHRDocURI(chromeXHRDocURI);
     mResponseXML->SetChromeXHRDocBaseURI(chromeXHRDocBaseURI);
 
+    mResponseXML->SetDocGroupWithoutScopeObject(doc->GetDocGroup());
+
     // suppress parsing failure messages to console for statuses which
     // can have empty bodies (see bug 884693).
     uint32_t responseStatus;
     if (NS_SUCCEEDED(GetStatus(&responseStatus)) &&
         (responseStatus == 201 || responseStatus == 202 ||
          responseStatus == 204 || responseStatus == 205 ||
          responseStatus == 304)) {
       mResponseXML->SetSuppressParserErrorConsoleMessages(true);
--- a/parser/html/nsHtml5StreamParser.cpp
+++ b/parser/html/nsHtml5StreamParser.cpp
@@ -961,23 +961,20 @@ nsHtml5StreamParser::OnStartRequest(nsIR
   rv = NS_OK;
 
   // The line below means that the encoding can end up being wrong if
   // a view-source URL is loaded without having the encoding hint from a
   // previous normal load in the history.
   mReparseForbidden = !(mMode == NORMAL || mMode == PLAIN_TEXT);
 
   mDocGroup = mExecutor->GetDocument()->GetDocGroup();
+  MOZ_ASSERT(mDocGroup, "How come the doc group is still null?");
 
   nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mRequest, &rv));
   if (NS_SUCCEEDED(rv)) {
-    // Non-HTTP channels are bogus enough that we let them work with unlabeled
-    // runnables for now. Asserting for HTTP channels only.
-    MOZ_ASSERT(mDocGroup || mMode == LOAD_AS_DATA, "How come the doc group is still null?");
-
     nsAutoCString method;
     Unused << httpChannel->GetRequestMethod(method);
     // XXX does Necko have a way to renavigate POST, etc. without hitting
     // the network?
     if (!method.EqualsLiteral("GET")) {
       // This is the old Gecko behavior but the HTML5 spec disagrees.
       // Don't reparse on POST.
       mReparseForbidden = true;