Bug 532751 - Stop cacheing the nsNPAPIPlugin when it crashes, so that refreshing the page immediately reloads the plugin, r=bent pending r?joshmoz

This commit is contained in:
Benjamin Smedberg 2009-12-04 13:24:57 -05:00
parent 3bcd07af0a
commit 87941a941e
8 changed files with 53 additions and 4 deletions

View File

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=4 ts=4 et :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
@ -43,6 +43,8 @@
#include "npapi.h"
#include "nscore.h"
class nsNPAPIPlugin;
namespace mozilla {
class PluginLibrary
@ -50,6 +52,12 @@ class PluginLibrary
public:
virtual ~PluginLibrary() { }
/**
* Inform this library about the nsNPAPIPlugin which owns it. This
* object will hold a weak pointer to the plugin.
*/
virtual void SetPlugin(nsNPAPIPlugin* plugin) = 0;
virtual bool HasRequiredFunctions() = 0;
#if defined(XP_UNIX) && !defined(XP_MACOSX)

View File

@ -69,6 +69,7 @@ PluginModuleParent::PluginModuleParent(const char* aFilePath)
: mSubprocess(new PluginProcessParent(aFilePath))
, mShutdown(false)
, mNPNIface(NULL)
, mPlugin(NULL)
{
NS_ASSERTION(mSubprocess, "Out of memory!");
@ -97,8 +98,8 @@ PluginModuleParent::ActorDestroy(ActorDestroyReason why)
{
switch (why) {
case AbnormalShutdown:
// TODObsmedberg: notify the plugin host to forget this plugin module
// and instantiate us again.
if (mPlugin)
mPlugin->PluginCrashed();
// FALL THROUGH
case NormalShutdown:

View File

@ -97,9 +97,13 @@ protected:
public:
PluginModuleParent(const char* aFilePath);
virtual ~PluginModuleParent();
NS_OVERRIDE virtual void SetPlugin(nsNPAPIPlugin* plugin)
{
mPlugin = plugin;
}
NS_OVERRIDE virtual void ActorDestroy(ActorDestroyReason why);
/**
@ -213,6 +217,7 @@ private:
bool mShutdown;
const NPNetscapeFuncs* mNPNIface;
nsTHashtable<nsVoidPtrHashKey> mValidIdentifiers;
nsNPAPIPlugin* mPlugin;
};
} // namespace plugins

View File

@ -83,6 +83,8 @@ public:
// unref here??
}
virtual void SetPlugin(nsNPAPIPlugin*) { }
virtual bool HasRequiredFunctions() {
mNP_Initialize = (NP_InitializeFunc)
PR_FindFunctionSymbol(mLibrary, "NP_Initialize");

View File

@ -281,6 +281,7 @@ nsNPAPIPlugin::nsNPAPIPlugin(NPPluginFuncs* callbacks,
#endif
fLibrary = aLibrary;
fLibrary->SetPlugin(this);
}
nsNPAPIPlugin::~nsNPAPIPlugin()
@ -300,6 +301,15 @@ nsNPAPIPlugin::SetPluginRefNum(short aRefNum)
}
#endif
void
nsNPAPIPlugin::PluginCrashed()
{
nsPluginTag* tag = nsPluginHost::GetInst()->FindPluginTag(this);
if (tag) {
NS_RELEASE(tag->mEntryPoint);
}
}
namespace {
#ifdef MOZ_IPC

View File

@ -94,6 +94,11 @@ public:
void SetPluginRefNum(short aRefNum);
#endif
#ifdef MOZ_IPC
// The IPC mechanism will notify us if a plugin crashed and is no longer usable.
void PluginCrashed();
#endif
protected:
friend class nsNPAPIPluginInstance;
friend class nsNPAPIPluginStreamListener;

View File

@ -3917,6 +3917,19 @@ nsPluginHost::FindPluginEnabledForExtension(const char* aExtension,
return nsnull;
}
nsPluginTag*
nsPluginHost::FindPluginTag(nsIPlugin* plugin)
{
nsPluginTag* plugins = mPlugins;
while (plugins) {
if (plugins->mEntryPoint == plugin)
return plugins;
plugins = plugins->mNext;
}
return nsnull;
}
static nsresult ConvertToNative(nsIUnicodeEncoder *aEncoder,
const nsACString& aUTF8String,
nsACString& aNativeString)

View File

@ -266,6 +266,8 @@ public:
static nsresult GetPrompt(nsIPluginInstanceOwner *aOwner, nsIPrompt **aPrompt);
private:
friend class nsNPAPIPlugin;
nsresult
TrySetUpPluginInstance(const char *aMimeType, nsIURI *aURL, nsIPluginInstanceOwner *aOwner);
@ -288,6 +290,9 @@ private:
nsPluginTag*
FindPluginEnabledForExtension(const char* aExtension, const char* &aMimeType);
nsPluginTag*
FindPluginTag(nsIPlugin* plugin);
nsresult
FindStoppedPluginForURL(nsIURI* aURL, nsIPluginInstanceOwner *aOwner);