Bug 159646 -- taking care of stale pointer in the plugin sample code, not part of the build

This commit is contained in:
av%netscape.com 2002-08-07 02:46:43 +00:00
parent 95ef8b41ef
commit ce05ae57b4
14 changed files with 53 additions and 20 deletions

View File

@ -107,6 +107,11 @@ NS_IMETHODIMP nsScriptablePeer::QueryInterface(const nsIID& aIID, void** aInstan
return NS_NOINTERFACE;
}
void nsScriptablePeer::SetInstance(nsPluginInstance* plugin)
{
mPlugin = plugin;
}
//
// the following methods will be callable from JavaScript
//

View File

@ -98,6 +98,8 @@ public:
// native methods callable from JavaScript
NS_DECL_NSISCRIPTABLEPLUGIN
void SetInstance(nsPluginInstance* plugin);
protected:
nsPluginInstance* mPlugin;
};

View File

@ -91,6 +91,11 @@ nsPluginInstance::nsPluginInstance(NPP aInstance) : nsPluginInstanceBase(),
nsPluginInstance::~nsPluginInstance()
{
// mScriptablePeer may be also held by the browser
// so releasing it here does not guarantee that it is over
// we should take precaution in case it will be called later
// and zero its mPlugin member
mScriptablePeer->SetInstance(NULL);
NS_IF_RELEASE(mScriptablePeer);
}
@ -356,7 +361,7 @@ NPError nsPluginInstance::GetValue(NPPVariable aVariable, void *aValue)
// ==============================
//
// this method will return the scriptable object (and create it if necessary)
nsIScriptablePlugin* nsPluginInstance::getScriptablePeer()
nsScriptablePeer* nsPluginInstance::getScriptablePeer()
{
if (!mScriptablePeer) {
mScriptablePeer = new nsScriptablePeer(this);
@ -369,6 +374,4 @@ nsIScriptablePlugin* nsPluginInstance::getScriptablePeer()
// add reference for the caller requesting the object
NS_ADDREF(mScriptablePeer);
return mScriptablePeer;
return NULL;
}

View File

@ -56,7 +56,7 @@ public:
void showVersion();
void clear();
nsIScriptablePlugin* getScriptablePeer();
nsScriptablePeer* getScriptablePeer();
char mString[128];
@ -67,7 +67,7 @@ private:
void EndDraw(NPWindow* window);
void DrawString(const unsigned char* text, short width, short height, short centerX, Rect drawRect);
nsIScriptablePlugin * mScriptablePeer;
nsScriptablePeer * mScriptablePeer;
NPWindow * mWindow;
NPP mInstance;

View File

@ -99,6 +99,11 @@ nsPluginInstance::nsPluginInstance(NPP aInstance) : nsPluginInstanceBase(),
nsPluginInstance::~nsPluginInstance()
{
// mScriptablePeer may be also held by the browser
// so releasing it here does not guarantee that it is over
// we should take precaution in case it will be called later
// and zero its mPlugin member
mScriptablePeer->SetInstance(NULL);
NS_IF_RELEASE(mScriptablePeer);
}
@ -246,7 +251,7 @@ NPError nsPluginInstance::GetValue(NPPVariable aVariable, void *aValue)
// ==============================
//
// this method will return the scriptable object (and create it if necessary)
nsIScriptablePlugin* nsPluginInstance::getScriptablePeer()
nsScriptablePeer* nsPluginInstance::getScriptablePeer()
{
if (!mScriptablePeer) {
mScriptablePeer = new nsScriptablePeer(this);
@ -259,6 +264,4 @@ nsIScriptablePlugin* nsPluginInstance::getScriptablePeer()
// add reference for the caller requesting the object
NS_ADDREF(mScriptablePeer);
return mScriptablePeer;
return NULL;
}

View File

@ -58,7 +58,7 @@ public:
void clear();
void draw();
nsIScriptablePlugin* getScriptablePeer();
nsScriptablePeer* getScriptablePeer();
private:
NPP mInstance;
@ -73,7 +73,7 @@ private:
XFontStruct *mFontInfo;
GC mGC;
nsIScriptablePlugin * mScriptablePeer;
nsScriptablePeer* mScriptablePeer;
public:
char mString[128];

View File

@ -107,6 +107,11 @@ NS_IMETHODIMP nsScriptablePeer::QueryInterface(const nsIID& aIID, void** aInstan
return NS_NOINTERFACE;
}
void nsScriptablePeer::SetInstance(nsPluginInstance* plugin)
{
mPlugin = plugin;
}
//
// the following methods will be callable from JavaScript
//

View File

@ -98,6 +98,8 @@ public:
// native methods callable from JavaScript
NS_DECL_NSISCRIPTABLEPLUGIN
void SetInstance(nsPluginInstance* plugin);
protected:
nsPluginInstance* mPlugin;
};

View File

@ -88,6 +88,11 @@ nsPluginInstance::nsPluginInstance(NPP aInstance) : nsPluginInstanceBase(),
nsPluginInstance::~nsPluginInstance()
{
// mScriptablePeer may be also held by the browser
// so releasing it here does not guarantee that it is over
// we should take precaution in case it will be called later
// and zero its mPlugin member
mScriptablePeer->SetInstance(NULL);
NS_IF_RELEASE(mScriptablePeer);
}
@ -184,7 +189,7 @@ NPError nsPluginInstance::GetValue(NPPVariable aVariable, void *aValue)
// ==============================
//
// this method will return the scriptable object (and create it if necessary)
nsIScriptablePlugin* nsPluginInstance::getScriptablePeer()
nsScriptablePeer* nsPluginInstance::getScriptablePeer()
{
if (!mScriptablePeer) {
mScriptablePeer = new nsScriptablePeer(this);
@ -197,8 +202,6 @@ nsIScriptablePlugin* nsPluginInstance::getScriptablePeer()
// add reference for the caller requesting the object
NS_ADDREF(mScriptablePeer);
return mScriptablePeer;
return NULL;
}
static LRESULT CALLBACK PluginWinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)

View File

@ -59,13 +59,13 @@ public:
void showVersion();
void clear();
nsIScriptablePlugin* getScriptablePeer();
nsScriptablePeer* getScriptablePeer();
private:
NPP mInstance;
NPBool mInitialized;
HWND mhWnd;
nsIScriptablePlugin * mScriptablePeer;
nsScriptablePeer * mScriptablePeer;
public:
char mString[128];

View File

@ -107,6 +107,11 @@ NS_IMETHODIMP nsScriptablePeer::QueryInterface(const nsIID& aIID, void** aInstan
return NS_NOINTERFACE;
}
void nsScriptablePeer::SetInstance(nsPluginInstance* plugin)
{
mPlugin = plugin;
}
//
// the following method will be callable from JavaScript
//

View File

@ -98,6 +98,8 @@ public:
// native methods callable from JavaScript
NS_DECL_NSISIMPLEPLUGIN
void SetInstance(nsPluginInstance* plugin);
protected:
nsPluginInstance* mPlugin;
};

View File

@ -118,6 +118,11 @@ nsPluginInstance::nsPluginInstance(NPP aInstance) : nsPluginInstanceBase(),
nsPluginInstance::~nsPluginInstance()
{
// mScriptablePeer may be also held by the browser
// so releasing it here does not guarantee that it is over
// we should take precaution in case it will be called later
// and zero its mPlugin member
mScriptablePeer->SetInstance(NULL);
NS_IF_RELEASE(mScriptablePeer);
}
@ -222,7 +227,7 @@ NPError nsPluginInstance::GetValue(NPPVariable aVariable, void *aValue)
// ==============================
//
// this method will return the scriptable object (and create it if necessary)
nsISimplePlugin* nsPluginInstance::getScriptablePeer()
nsScriptablePeer* nsPluginInstance::getScriptablePeer()
{
if (!mScriptablePeer) {
mScriptablePeer = new nsScriptablePeer(this);
@ -235,6 +240,4 @@ nsISimplePlugin* nsPluginInstance::getScriptablePeer()
// add reference for the caller requesting the object
NS_ADDREF(mScriptablePeer);
return mScriptablePeer;
return NULL;
}

View File

@ -59,12 +59,12 @@ public:
// locals
void getVersion(char* *aVersion);
nsISimplePlugin* getScriptablePeer();
nsScriptablePeer* getScriptablePeer();
private:
NPP mInstance;
NPBool mInitialized;
nsISimplePlugin * mScriptablePeer;
nsScriptablePeer * mScriptablePeer;
public:
char mString[128];