From 5c7541d07638d10e814d18012ea4a6b6d50c0943 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 7 Oct 2008 14:53:23 -0400 Subject: [PATCH] Bug 458100. Make sure that we'll also instantiate the plug-in even if the nsPluginDocument has no presshell yet at OnStartRequest time. Thanks to Evgeny for pointing out the problem. r+sr=jst --- content/base/src/nsObjectLoadingContent.cpp | 6 +++++- .../html/document/src/nsPluginDocument.cpp | 20 +++++++++++++++++++ layout/generic/nsObjectFrame.cpp | 6 +++++- .../plugin/base/public/nsIPluginDocument.idl | 9 ++++++++- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/content/base/src/nsObjectLoadingContent.cpp b/content/base/src/nsObjectLoadingContent.cpp index cb55dbcbb0f1..1cd018dcdbb6 100644 --- a/content/base/src/nsObjectLoadingContent.cpp +++ b/content/base/src/nsObjectLoadingContent.cpp @@ -798,7 +798,11 @@ nsObjectLoadingContent::HasNewFrame(nsIObjectFrame* aFrame) // instantiate nsCOMPtr pDoc (do_QueryInterface(GetOurDocument())); if (pDoc) { - return NS_OK; + PRBool willHandleInstantiation; + pDoc->GetWillHandleInstantiation(&willHandleInstantiation); + if (willHandleInstantiation) { + return NS_OK; + } } nsCOMPtr event = diff --git a/content/html/document/src/nsPluginDocument.cpp b/content/html/document/src/nsPluginDocument.cpp index 148957c8f840..527657ac46e6 100644 --- a/content/html/document/src/nsPluginDocument.cpp +++ b/content/html/document/src/nsPluginDocument.cpp @@ -71,12 +71,21 @@ public: const nsCString& GetType() const { return mMimeType; } nsIContent* GetPluginContent() { return mPluginContent; } + void SkippedInstantiation() { + mWillHandleInstantiation = PR_FALSE; + } + protected: nsresult CreateSyntheticPluginDocument(); nsCOMPtr mPluginContent; nsRefPtr mStreamListener; nsCString mMimeType; + + // Hack to handle the fact that plug-in loading lives in frames and that the + // frames may not be around when we need to instantiate. Once plug-in + // loading moves to content, this can all go away. + PRBool mWillHandleInstantiation; }; class nsPluginStreamListener : public nsMediaDocumentStreamListener @@ -104,6 +113,7 @@ nsPluginStreamListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt) nsIPresShell* shell = mDocument->GetPrimaryShell(); if (!shell) { // Can't instantiate w/o a shell + mPluginDoc->SkippedInstantiation(); return NS_BINDING_ABORTED; } @@ -114,12 +124,14 @@ nsPluginStreamListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt) nsIFrame* frame = shell->GetPrimaryFrameFor(embed); if (!frame) { + mPluginDoc->SkippedInstantiation(); return rv; } nsIObjectFrame* objFrame; CallQueryInterface(frame, &objFrame); if (!objFrame) { + mPluginDoc->SkippedInstantiation(); return NS_ERROR_UNEXPECTED; } @@ -138,6 +150,7 @@ nsPluginStreamListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt) // bother initializing members to 0. nsPluginDocument::nsPluginDocument() + : mWillHandleInstantiation(PR_TRUE) { } @@ -323,6 +336,13 @@ nsPluginDocument::Print() return NS_OK; } +NS_IMETHODIMP +nsPluginDocument::GetWillHandleInstantiation(PRBool* aWillHandle) +{ + *aWillHandle = mWillHandleInstantiation; + return NS_OK; +} + nsresult NS_NewPluginDocument(nsIDocument** aResult) { diff --git a/layout/generic/nsObjectFrame.cpp b/layout/generic/nsObjectFrame.cpp index ea38bd85a942..082a835e6dbd 100644 --- a/layout/generic/nsObjectFrame.cpp +++ b/layout/generic/nsObjectFrame.cpp @@ -878,9 +878,13 @@ nsObjectFrame::InstantiatePlugin(nsIPluginHost* aPluginHost, nsIDocument* doc = mContent->GetOwnerDoc(); nsCOMPtr pDoc (do_QueryInterface(doc)); + PRBool fullPageMode = PR_FALSE; + if (pDoc) { + pDoc->GetWillHandleInstantiation(&fullPageMode); + } nsresult rv; - if (pDoc) { /* full-page mode */ + if (fullPageMode) { /* full-page mode */ nsCOMPtr stream; rv = aPluginHost->InstantiateFullPagePlugin(aMimeType, aURI, /* resulting stream listener */ *getter_AddRefs(stream), diff --git a/modules/plugin/base/public/nsIPluginDocument.idl b/modules/plugin/base/public/nsIPluginDocument.idl index 7e7b309f79f2..9d9d2acb4a79 100644 --- a/modules/plugin/base/public/nsIPluginDocument.idl +++ b/modules/plugin/base/public/nsIPluginDocument.idl @@ -38,7 +38,7 @@ #include "nsISupports.idl" #include "nsIStreamListener.idl" -[uuid(0d8129f1-5a55-4eaa-851f-15e43ce3d183)] +[uuid(e4be1d0a-9f24-4d69-bec5-245726ab85fb)] interface nsIPluginDocument : nsISupports { /** @@ -51,4 +51,11 @@ interface nsIPluginDocument : nsISupports * Causes the plugin to print in full-page mode */ void print(); + + /** + * Check whether the document is planning to handle plug-in instantiation + * itself. If not, then the plugin content node should do it. + */ + // XXXbz once we move plug-in loading to content, this can go away. + readonly attribute boolean willHandleInstantiation; };