Bug 1431255 - Part XIV, Move the creation of video element in synthetic media document draft
authorTimothy Guan-tin Chien <timdream@gmail.com>
Wed, 08 Aug 2018 15:55:29 -0700
changeset 828980 617e1f613946023e1cfa678d94866bad05e614b0
parent 828979 a5aa591ae040c1c56491f17397de867c9b098f01
push id118738
push usertimdream@gmail.com
push dateTue, 14 Aug 2018 17:19:06 +0000
bugs1431255, 448603
milestone63.0a1
Bug 1431255 - Part XIV, Move the creation of video element in synthetic media document This patch moves the call into CreateSyntheticVideoDocument() from VideoDocument::StartDocumentLoad() to VideoDocument::SetScriptGlobalObject() because there isn't a inner window at the time of document load, thus the UAWidgetBindToTree event will not be dispatched (see EventDispatcher::Dispatch()). This is modeled after where ImageDocument::CreateSyntheticDocument() is called. Although it is unclear to me why it was being done differently in bug 448603. MozReview-Commit-ID: F3IJo4Ewe6d
dom/html/VideoDocument.cpp
--- a/dom/html/VideoDocument.cpp
+++ b/dom/html/VideoDocument.cpp
@@ -62,34 +62,34 @@ VideoDocument::StartDocumentLoad(const c
                                  nsIContentSink*     aSink)
 {
   nsresult rv =
     MediaDocument::StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer,
                                      aDocListener, aReset, aSink);
   NS_ENSURE_SUCCESS(rv, rv);
 
   mStreamListener = new MediaDocumentStreamListener(this);
+  NS_ADDREF(*aDocListener = mStreamListener);
 
-  // Create synthetic document
-  rv = CreateSyntheticVideoDocument(aChannel,
-      getter_AddRefs(mStreamListener->mNextStream));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  NS_ADDREF(*aDocListener = mStreamListener);
   return rv;
 }
 
 void
 VideoDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject)
 {
   // Set the script global object on the superclass before doing
   // anything that might require it....
   MediaDocument::SetScriptGlobalObject(aScriptGlobalObject);
 
   if (aScriptGlobalObject && !InitialSetupHasBeenDone()) {
+    // Create synthetic document
+    DebugOnly<nsresult> rv = CreateSyntheticVideoDocument(mChannel,
+        getter_AddRefs(mStreamListener->mNextStream));
+    NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create synthetic document");
+
     if (!nsContentUtils::IsChildOfSameType(this)) {
       LinkStylesheet(NS_LITERAL_STRING("resource://content-accessible/TopLevelVideoDocument.css"));
       LinkStylesheet(NS_LITERAL_STRING("chrome://global/skin/media/TopLevelVideoDocument.css"));
       LinkScript(NS_LITERAL_STRING("chrome://global/content/TopLevelVideoDocument.js"));
     }
     InitialSetupDone();
   }
 }