Bug 1261536 - Create a synthetic document after the window is set - r?bz
MozReview-Commit-ID: 7SBC2dFZAkP
--- a/dom/html/VideoDocument.cpp
+++ b/dom/html/VideoDocument.cpp
@@ -28,18 +28,17 @@ public:
nsIContentSink* aSink = nullptr);
virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject);
protected:
// Sets document <title> to reflect the file name and description.
void UpdateTitle(nsIChannel* aChannel);
- nsresult CreateSyntheticVideoDocument(nsIChannel* aChannel,
- nsIStreamListener** aListener);
+ nsresult CreateSyntheticVideoDocument();
RefPtr<MediaDocumentStreamListener> mStreamListener;
};
nsresult
VideoDocument::StartDocumentLoad(const char* aCommand,
nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
@@ -49,47 +48,49 @@ 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);
-
- // 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) {
+ if (!GetRootElement()) {
+ // Create synthetic document
+#ifdef DEBUG
+ nsresult rv =
+#endif
+ CreateSyntheticVideoDocument();
+ NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create synthetic video document");
+ }
+
if (!nsContentUtils::IsChildOfSameType(this) &&
GetReadyStateEnum() != nsIDocument::READYSTATE_COMPLETE) {
LinkStylesheet(NS_LITERAL_STRING("resource://gre/res/TopLevelVideoDocument.css"));
LinkStylesheet(NS_LITERAL_STRING("chrome://global/skin/media/TopLevelVideoDocument.css"));
LinkScript(NS_LITERAL_STRING("chrome://global/content/TopLevelVideoDocument.js"));
}
BecomeInteractive();
}
}
nsresult
-VideoDocument::CreateSyntheticVideoDocument(nsIChannel* aChannel,
- nsIStreamListener** aListener)
+VideoDocument::CreateSyntheticVideoDocument()
{
// make our generic document
nsresult rv = MediaDocument::CreateSyntheticDocument();
NS_ENSURE_SUCCESS(rv, rv);
Element* body = GetBodyElement();
if (!body) {
NS_WARNING("no body on video document!");
@@ -104,18 +105,19 @@ VideoDocument::CreateSyntheticVideoDocum
RefPtr<HTMLMediaElement> element =
static_cast<HTMLMediaElement*>(NS_NewHTMLVideoElement(nodeInfo.forget(),
NOT_FROM_PARSER));
if (!element)
return NS_ERROR_OUT_OF_MEMORY;
element->SetAutoplay(true);
element->SetControls(true);
- element->LoadWithChannel(aChannel, aListener);
- UpdateTitle(aChannel);
+ element->LoadWithChannel(mChannel,
+ getter_AddRefs(mStreamListener->mNextStream));
+ UpdateTitle(mChannel);
if (nsContentUtils::IsChildOfSameType(this)) {
// Video documents that aren't toplevel should fill their frames and
// not have margins
element->SetAttr(kNameSpaceID_None, nsGkAtoms::style,
NS_LITERAL_STRING("position:absolute; top:0; left:0; width:100%; height:100%"),
true);
}