From f049147c23cdb12127300b8cb326cc52f68592f7 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 9 Jan 2009 12:54:23 -0500 Subject: [PATCH] Bug 472239. Make sure to set up our listener before trying to call OnStartRequest on it. r+sr=jst --- .../html/document/src/nsPluginDocument.cpp | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/content/html/document/src/nsPluginDocument.cpp b/content/html/document/src/nsPluginDocument.cpp index a95c52d5a3ed..44be07650ccf 100644 --- a/content/html/document/src/nsPluginDocument.cpp +++ b/content/html/document/src/nsPluginDocument.cpp @@ -75,6 +75,8 @@ public: mWillHandleInstantiation = PR_FALSE; } + void StartLayout() { nsMediaDocument::StartLayout(); } + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsPluginDocument, nsMediaDocument) protected: nsresult CreateSyntheticPluginDocument(); @@ -91,22 +93,35 @@ protected: class nsPluginStreamListener : public nsMediaDocumentStreamListener { - public: - nsPluginStreamListener(nsPluginDocument* doc) : - nsMediaDocumentStreamListener(doc), mPluginDoc(doc) {} - NS_IMETHOD OnStartRequest(nsIRequest* request, nsISupports *ctxt); - private: - nsRefPtr mPluginDoc; +public: + nsPluginStreamListener(nsPluginDocument* doc) : + nsMediaDocumentStreamListener(doc), mPluginDoc(doc) {} + NS_IMETHOD OnStartRequest(nsIRequest* request, nsISupports *ctxt); +private: + nsresult SetupPlugin(); + + nsRefPtr mPluginDoc; }; NS_IMETHODIMP nsPluginStreamListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt) { - nsresult rv = nsMediaDocumentStreamListener::OnStartRequest(request, ctxt); - if (NS_FAILED(rv)) { - return rv; - } + // Have to set up our plugin stuff before we call OnStartRequest, so + // that the plugin listener can get that call. + nsresult rv = SetupPlugin(); + + NS_ASSERTION(NS_FAILED(rv) || mNextStream, + "We should have a listener by now"); + nsresult rv2 = nsMediaDocumentStreamListener::OnStartRequest(request, ctxt); + return NS_SUCCEEDED(rv) ? rv2 : rv; +} + +nsresult +nsPluginStreamListener::SetupPlugin() +{ + NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE); + mPluginDoc->StartLayout(); nsCOMPtr embed = mPluginDoc->GetPluginContent(); @@ -126,7 +141,7 @@ nsPluginStreamListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt) nsIFrame* frame = shell->GetPrimaryFrameFor(embed); if (!frame) { mPluginDoc->AllowNormalInstantiation(); - return rv; + return NS_OK; } nsIObjectFrame* objFrame; @@ -136,8 +151,8 @@ nsPluginStreamListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt) return NS_ERROR_UNEXPECTED; } - rv = objFrame->Instantiate(mPluginDoc->GetType().get(), - mDocument->nsIDocument::GetDocumentURI()); + nsresult rv = objFrame->Instantiate(mPluginDoc->GetType().get(), + mDocument->nsIDocument::GetDocumentURI()); if (NS_FAILED(rv)) { return rv; } @@ -146,8 +161,7 @@ nsPluginStreamListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt) // (say if there's a reframe of this entire presentation). mPluginDoc->AllowNormalInstantiation(); - NS_ASSERTION(mNextStream, "We should have a listener by now"); - return mNextStream->OnStartRequest(request, ctxt); + return NS_OK; }