fixed crashing bug when frames are destroyed

This commit is contained in:
beard%netscape.com 1999-03-14 22:51:41 +00:00
Родитель 9047f78053
Коммит dd56a01163
4 изменённых файлов: 40 добавлений и 12 удалений

Просмотреть файл

@ -27,12 +27,13 @@
#include <Controls.h>
#include <Events.h>
#include "EmbeddedFrame.h"
#include "EmbeddedFramePluginInstance.h"
#include "MRJPlugin.h"
#include "MRJSession.h"
#include "nsIPluginInstancePeer.h"
#include "nsIOutputStream.h"
#include "EmbeddedFrame.h"
#include "JSEvaluator.h"
#include "LocalPort.h"
#include "StringUtils.h"
@ -43,7 +44,7 @@ static short getModifiers();
EmbeddedFrame::EmbeddedFrame(MRJPluginInstance* pluginInstance, JMFrameRef frameRef, JMFrameKind kind,
const Rect* initialBounds, Boolean resizeable)
: MRJFrame(frameRef),
mPluginInstance(pluginInstance), mEvaluator(NULL), mWindow(NULL), mBounds(*initialBounds)
mPluginInstance(NULL), mEvaluator(NULL), mWindow(NULL), mBounds(*initialBounds)
{
Boolean hasGoAway = true;
SInt16 windowProc = documentProc;
@ -117,9 +118,14 @@ EmbeddedFrame::EmbeddedFrame(MRJPluginInstance* pluginInstance, JMFrameRef frame
#else
// Use JavaScript to create a window with an <EMBED TYPE="application/x-java-frame"> tag.
const char* kEmbeddedFrameScript = "javascript:var w = window.open('', '', 'resizable=yes,status=no,width=400,height=400'); "
"var d = w.document; d.write('<HTML><HEAD></HEAD><BODY><EMBED TYPE=\"application/x-java-frame\""
"BORDER=5 WIDTH=400 HEIGHT=400 FRAME=XXXXXXXX></EMBED></BODY></HTML>'); d.close();";
const char* kEmbeddedFrameScript = "var w = window.open('','_new','resizable=no,status=no,width=200,height=200');"
"var d = w.document; d.write('"
// "<BODY MARGINWIDTH=0 MARGINHEIGHT=0>" // this doesn't work, don't know why
"<HTML><BODY>"
"<EMBED TYPE=\"application/x-java-frame\""
"WIDTH=200 HEIGHT=200 FRAME=XXXXXXXX></EMBED>"
"</BODY></HTML>'); d.close();";
char* script = strdup(kEmbeddedFrameScript);
char* address = strchr(script, 'X');
sprintf(address, "%08X", this);
@ -132,6 +138,7 @@ EmbeddedFrame::EmbeddedFrame(MRJPluginInstance* pluginInstance, JMFrameRef frame
const char* result = evaluator->eval(script);
delete[] script;
#endif
#endif
@ -144,6 +151,9 @@ EmbeddedFrame::EmbeddedFrame(MRJPluginInstance* pluginInstance, JMFrameRef frame
EmbeddedFrame::~EmbeddedFrame()
{
if (mPluginInstance != NULL)
mPluginInstance->setFrame(NULL);
// make sure the window is hidden (and unregistered with the browser).
showHide(false);
@ -283,6 +293,11 @@ void EmbeddedFrame::click(const EventRecord* event)
}
}
void EmbeddedFrame::setPluginInstance(EmbeddedFramePluginInstance* embeddedInstance)
{
mPluginInstance = embeddedInstance;
}
void EmbeddedFrame::setWindow(WindowRef window)
{
mWindow = window;

Просмотреть файл

@ -33,6 +33,7 @@
#endif
class MRJPluginInstance;
class EmbeddedFramePluginInstance;
class JSEvaluator;
class EmbeddedFrame : public MRJFrame {
@ -51,6 +52,8 @@ public:
virtual void activate(Boolean active);
virtual void click(const EventRecord* event);
void setPluginInstance(EmbeddedFramePluginInstance* embeddedInstance);
void setWindow(WindowRef window);
WindowRef getWindow();
@ -58,7 +61,7 @@ protected:
virtual GrafPtr getPort();
private:
MRJPluginInstance* mPluginInstance;
EmbeddedFramePluginInstance* mPluginInstance;
JSEvaluator* mEvaluator;
WindowRef mWindow;
Rect mBounds;

Просмотреть файл

@ -29,7 +29,7 @@
#include <stdio.h>
EmbeddedFramePluginInstance::EmbeddedFramePluginInstance()
: mPeer(NULL), mParentInstance(NULL), mFrame(NULL)
: mPeer(NULL), mFrame(NULL)
{
NS_INIT_REFCNT();
}
@ -53,6 +53,8 @@ NS_METHOD EmbeddedFramePluginInstance::Initialize(nsIPluginInstancePeer* peer)
if (tagInfo->GetAttribute("FRAME", &frameValue) == NS_OK) {
sscanf(frameValue, "%X", &mFrame);
}
if (mFrame != NULL)
mFrame->setPluginInstance(this);
NS_RELEASE(tagInfo);
}
@ -71,7 +73,6 @@ NS_METHOD EmbeddedFramePluginInstance::GetPeer(nsIPluginInstancePeer* *resulting
NS_METHOD EmbeddedFramePluginInstance::Destroy()
{
NS_IF_RELEASE(mPeer);
NS_IF_RELEASE(mParentInstance);
if (mFrame != NULL) {
delete mFrame;
mFrame = NULL;
@ -81,10 +82,12 @@ NS_METHOD EmbeddedFramePluginInstance::Destroy()
NS_METHOD EmbeddedFramePluginInstance::SetWindow(nsPluginWindow* pluginWindow)
{
if (pluginWindow != NULL)
mFrame->setWindow(WindowRef(pluginWindow->window->port));
else
mFrame->setWindow(NULL);
if (mFrame != NULL) {
if (pluginWindow != NULL)
mFrame->setWindow(WindowRef(pluginWindow->window->port));
else
mFrame->setWindow(NULL);
}
return NS_OK;
}
@ -94,3 +97,8 @@ NS_METHOD EmbeddedFramePluginInstance::HandleEvent(nsPluginEvent* pluginEvent, P
*eventHandled = mFrame->handleEvent(pluginEvent->event);
return NS_OK;
}
void EmbeddedFramePluginInstance::setFrame(EmbeddedFrame* frame)
{
mFrame = frame;
}

Просмотреть файл

@ -168,6 +168,8 @@ public:
NS_IMETHOD
HandleEvent(nsPluginEvent* event, PRBool* handled);
void setFrame(EmbeddedFrame* frame);
private:
nsIPluginInstancePeer* mPeer;
MRJPluginInstance* mParentInstance;