implements nsIPluginStreamListener, to handle javascript: URLs.

This commit is contained in:
beard%netscape.com 1999-03-02 04:42:35 +00:00
Родитель fcf7f5153e
Коммит 5180d7830e
2 изменённых файлов: 143 добавлений и 9 удалений

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

@ -459,7 +459,7 @@ MRJPluginInstance::MRJPluginInstance(MRJPlugin* plugin)
: SupportsMixin(this, sInterfaces, kInterfaceCount),
mPeer(NULL), mWindowlessPeer(NULL),
mPlugin(plugin), mSession(plugin->getSession()),
mContext(NULL), mApplet(NULL),
mContext(NULL), mApplet(NULL), mPluginWindow(NULL),
mNext(NULL)
{
// add this instance to the instance list.
@ -474,6 +474,7 @@ MRJPluginInstance::~MRJPluginInstance()
// Remove this instance from the global list.
popInstance();
#if 0
if (mContext != NULL) {
delete mContext;
mContext = NULL;
@ -499,8 +500,11 @@ MRJPluginInstance::~MRJPluginInstance()
env->DeleteGlobalRef(mApplet);
mApplet = NULL;
}
#endif
}
static const char* kGetCodeBaseScriptURL = "javascript:var href = window.location.href; href.substring(0, href.lastIndexOf('/') + 1)";
NS_METHOD MRJPluginInstance::Initialize(nsIPluginInstancePeer* peer)
{
// Tell the peer we are retaining a reference.
@ -514,12 +518,43 @@ NS_METHOD MRJPluginInstance::Initialize(nsIPluginInstancePeer* peer)
// create a context for the applet we will run.
mContext = new MRJContext(mSession, this);
mContext->processAppletTag();
mContext->createContext();
if (mWindowlessPeer != NULL) {
mContext->processAppletTag();
mContext->createContext();
} else {
// we'll be using JavaScript to create windows.
// fire up a JavaScript URL to get the current document's location.
nsIPluginInstance* pluginInstance = this;
nsIPluginStreamListener* listener = this;
result = thePluginManager->GetURL(pluginInstance, kGetCodeBaseScriptURL, NULL, listener);
}
return NS_OK;
}
NS_METHOD MRJPluginInstance::OnDataAvailable(const char* url, nsIInputStream* input,
PRUint32 offset, PRUint32 length, nsIPluginStreamInfo* pluginInfo)
{
// hopefully all our data is available.
char* codeBase = new char[length + 1];
if (codeBase != NULL) {
if (input->Read(codeBase, 0, length, &length) == NS_OK) {
// We've delayed processing the applet tag, because we
// don't know the location of the curren document yet.
codeBase[length] = '\0';
mContext->setCodeBase(codeBase);
mContext->processAppletTag();
mContext->createContext();
// SetWindow is called at an inopportune time.
if (mPluginWindow != NULL)
mContext->setWindow(mPluginWindow);
}
}
return NS_OK;
}
NS_METHOD MRJPluginInstance::GetPeer(nsIPluginInstancePeer* *result)
{
mPeer->AddRef();
@ -549,7 +584,34 @@ NS_METHOD MRJPluginInstance::Stop()
NS_METHOD MRJPluginInstance::Destroy()
{
// Release();
// Use this opportunity to break any cycles that might exist, and reduce
// reference counts to their minimum values.
if (mContext != NULL) {
delete mContext;
mContext = NULL;
}
if (mPlugin != NULL) {
mPlugin->Release();
mPlugin = NULL;
}
if (mWindowlessPeer != NULL) {
mWindowlessPeer->Release();
mWindowlessPeer = NULL;
}
if (mPeer != NULL) {
mPeer->Release();
mPeer = NULL;
}
if (mApplet != NULL) {
JNIEnv* env = mSession->getCurrentEnv();
env->DeleteGlobalRef(mApplet);
mApplet = NULL;
}
return NS_OK;
}
@ -557,6 +619,8 @@ NS_METHOD MRJPluginInstance::Destroy()
NS_METHOD MRJPluginInstance::SetWindow(nsPluginWindow* pluginWindow)
{
mPluginWindow = pluginWindow;
mContext->setWindow(pluginWindow);
return NS_OK;

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

@ -32,6 +32,7 @@
#include "nsIPluginInstance.h"
#include "nsIJVMPluginInstance.h"
#include "nsIEventHandler.h"
#include "nsIPluginStreamListener.h"
#include "SupportsMixin.h"
class MRJPlugin;
@ -237,9 +238,8 @@ private:
static const UInt32 kInterfaceCount;
};
class MRJPluginInstance : public nsIPluginInstance,
public nsIJVMPluginInstance,
public nsIEventHandler,
class MRJPluginInstance : public nsIPluginInstance, public nsIJVMPluginInstance,
public nsIEventHandler, public nsIPluginStreamListener,
private SupportsMixin {
public:
MRJPluginInstance(MRJPlugin* plugin);
@ -331,8 +331,9 @@ public:
NS_IMETHOD
NewStream(nsIPluginStreamListener** listener)
{
*listener = NULL;
return NS_ERROR_NOT_IMPLEMENTED;
*listener = this;
AddRef();
return NS_OK;
}
#else
/**
@ -396,6 +397,74 @@ public:
return NS_OK;
}
// nsIPluginStreamListener implementation.
/**
* Notify the observer that the URL has started to load. This method is
* called only once, at the beginning of a URL load.<BR><BR>
*
* @return The return value is currently ignored. In the future it may be
* used to cancel the URL load..
*/
NS_IMETHOD
OnStartBinding(const char* url, nsIPluginStreamInfo* pluginInfo)
{
return NS_OK;
}
/**
* Notify the client that data is available in the input stream. This
* method is called whenver data is written into the input stream by the
* networking library...<BR><BR>
*
* @param aIStream The input stream containing the data. This stream can
* be either a blocking or non-blocking stream.
* @param length The amount of data that was just pushed into the stream.
* @return The return value is currently ignored.
*/
NS_IMETHOD
OnDataAvailable(const char* url, nsIInputStream* input,
PRUint32 offset, PRUint32 length, nsIPluginStreamInfo* pluginInfo);
NS_IMETHOD
OnFileAvailable(const char* url, const char* fileName)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/**
* Notify the observer that the URL has finished loading. This method is
* called once when the networking library has finished processing the
* URL transaction initiatied via the nsINetService::Open(...) call.<BR><BR>
*
* This method is called regardless of whether the URL loaded successfully.<BR><BR>
*
* @param status Status code for the URL load.
* @param msg A text string describing the error.
* @return The return value is currently ignored.
*/
NS_IMETHOD
OnStopBinding(const char* url, nsresult status, nsIPluginStreamInfo* pluginInfo)
{
return NS_OK;
}
NS_IMETHOD
OnNotify(const char* url, nsresult status)
{
return NS_OK;
}
/**
* What is this method supposed to do?
*/
NS_IMETHOD
GetStreamType(nsPluginStreamType *result)
{
*result = nsPluginStreamType_Normal;
return NS_OK;
}
// Accessing the list of instances.
static MRJPluginInstance* getInstances(void);
MRJPluginInstance* getNextInstance(void);
@ -414,6 +483,7 @@ private:
MRJSession* mSession;
MRJContext* mContext;
jobject mApplet;
nsPluginWindow* mPluginWindow;
// maintain a list of instances.
MRJPluginInstance* mNext;