diff --git a/content/base/src/nsObjectLoadingContent.cpp b/content/base/src/nsObjectLoadingContent.cpp index d59a898ef8c..0ddb4e55df2 100644 --- a/content/base/src/nsObjectLoadingContent.cpp +++ b/content/base/src/nsObjectLoadingContent.cpp @@ -687,21 +687,29 @@ nsObjectLoadingContent::~nsObjectLoadingContent() nsresult nsObjectLoadingContent::InstantiatePluginInstance() { - if (mType != eType_Plugin || mIsLoading) { - LOG(("OBJLC [%p]: Not instantiating loading or non-plugin object, type %u", - this, mType)); + if (mInstanceOwner || mType != eType_Plugin || mIsLoading || mInstantiating) { + return NS_OK; + } + + nsCOMPtr thisContent = + do_QueryInterface(static_cast(this)); + + // Flush layout so that the frame is created if possible and the plugin is + // initialized with the latest information. + nsIDocument* doc = thisContent->GetCurrentDoc(); + + if (!doc || !InActiveDocument(thisContent)) { + NS_ERROR("Shouldn't be calling " + "InstantiatePluginInstance without an active document"); + return NS_ERROR_FAILURE; + } + doc->FlushPendingNotifications(Flush_Layout); + + if (!thisContent->GetPrimaryFrame()) { + LOG(("OBJLC [%p]: Not instantiating plugin with no frame", this)); return NS_OK; } - // Don't do anything if we already have an active instance. - if (mInstanceOwner) { - return NS_OK; - } - - // Don't allow re-entry into initialization code. - if (mInstantiating) { - return NS_OK; - } mInstantiating = true; AutoSetInstantiatingToFalse autoInstantiating(this); @@ -710,20 +718,6 @@ nsObjectLoadingContent::InstantiatePluginInstance() // of this method. nsCOMPtr kungFuDeathGrip = this; - nsCOMPtr thisContent = - do_QueryInterface(static_cast(this)); - // Flush layout so that the plugin is initialized with the latest information. - nsIDocument* doc = thisContent->GetCurrentDoc(); - if (!doc) { - return NS_ERROR_FAILURE; - } - if (!InActiveDocument(thisContent)) { - NS_ERROR("Shouldn't be calling " - "InstantiatePluginInstance in an inactive document"); - return NS_ERROR_FAILURE; - } - doc->FlushPendingNotifications(Flush_Layout); - nsresult rv = NS_ERROR_FAILURE; nsRefPtr pluginHost = already_AddRefed(nsPluginHost::GetInst()); @@ -1729,6 +1723,14 @@ nsObjectLoadingContent::LoadObject(bool aNotify, oldType = mType; oldState = ObjectState(); + if (!thisContent->GetPrimaryFrame()) { + // We're un-rendered, and can't instantiate a plugin. HasNewFrame will + // re-start us when we can proceed. + LOG(("OBJLC [%p]: Aborting load - plugin-type, but no frame", this)); + CloseChannel(); + break; + } + rv = pluginHost->NewEmbeddedPluginStreamListener(mURI, this, nullptr, getter_AddRefs(mFinalListener)); if (NS_SUCCEEDED(rv)) { diff --git a/dom/plugins/base/nsPluginInstanceOwner.cpp b/dom/plugins/base/nsPluginInstanceOwner.cpp index 302f6a05af0..0e3d052476c 100644 --- a/dom/plugins/base/nsPluginInstanceOwner.cpp +++ b/dom/plugins/base/nsPluginInstanceOwner.cpp @@ -3224,6 +3224,7 @@ nsresult nsPluginInstanceOwner::Init(nsIContent* aContent) // document is destroyed before we try to create the new one. objFrame->PresContext()->EnsureVisible(); } else { + NS_NOTREACHED("Should not be initializing plugin without a frame"); return NS_ERROR_FAILURE; }