changes for plugin support.

This commit is contained in:
michaelp%netscape.com 1998-08-01 05:46:47 +00:00
parent b8343322aa
commit 942e5214f9
26 changed files with 2296 additions and 472 deletions

View File

@ -31,6 +31,9 @@ CPPSRCS = \
nsPluginHostImpl.cpp \
nsPluginFactory.cpp \
ns4xPlugin.cpp \
ns4xPluginInstance.cpp \
ns4xPluginStream.cpp \
nsPluginInstancePeer.cpp \
$(NULL)
REQUIRES = raptor plugin java xpcom

View File

@ -35,6 +35,9 @@ OBJS = \
.\$(OBJDIR)\nsPluginHostImpl.obj \
.\$(OBJDIR)\nsPluginFactory.obj \
.\$(OBJDIR)\ns4xPlugin.obj \
.\$(OBJDIR)\ns4xPluginInstance.obj \
.\$(OBJDIR)\ns4xPluginStream.obj \
.\$(OBJDIR)\nsPluginInstancePeer.obj \
$(NULL)
LINCS= \

View File

@ -21,7 +21,8 @@
#include "xp_core.h"
#include "nsplugin.h"
#include "ns4xPlugin.h"
//#include "ns4xPluginInstance.h"
#include "nsIPluginStream.h"
#include "ns4xPluginInstance.h"
////////////////////////////////////////////////////////////////////////
@ -34,7 +35,9 @@ typedef NPError (*NP_PLUGINSHUTDOWN)();
////////////////////////////////////////////////////////////////////////
NPNetscapeFuncs ns4xPlugin::CALLBACKS;
nsIPluginManager * ns4xPlugin::mManager;
nsIPluginManager * ns4xPlugin::mPluginManager;
nsINetworkManager * ns4xPlugin::mNetworkManager;
nsIMalloc * ns4xPlugin::mMalloc;
void
ns4xPlugin::CheckClassInitialized(void)
@ -44,7 +47,9 @@ ns4xPlugin::CheckClassInitialized(void)
if (initialized)
return;
mManager = nsnull;
mPluginManager = nsnull;
mNetworkManager = nsnull;
mMalloc = nsnull;
// XXX It'd be nice to make this const and initialize it
// statically...
@ -53,25 +58,25 @@ ns4xPlugin::CheckClassInitialized(void)
CALLBACKS.geturl = NewNPN_GetURLProc(_geturl);
CALLBACKS.posturl = NewNPN_PostURLProc(_posturl);
// CALLBACKS.requestread = NewNPN_RequestReadProc(_requestread);
// CALLBACKS.newstream = NewNPN_NewStreamProc(_newstream);
// CALLBACKS.write = NewNPN_WriteProc(_write);
// CALLBACKS.destroystream = NewNPN_DestroyStreamProc(_destroystream);
// CALLBACKS.status = NewNPN_StatusProc(_status);
// CALLBACKS.uagent = NewNPN_UserAgentProc(_useragent);
// CALLBACKS.memalloc = NewNPN_MemAllocProc(_memalloc);
// CALLBACKS.memfree = NewNPN_MemFreeProc(_memfree);
// CALLBACKS.memflush = NewNPN_MemFlushProc(_memflush);
// CALLBACKS.reloadplugins = NewNPN_ReloadPluginsProc(_reloadplugins);
// CALLBACKS.getJavaEnv = NewNPN_GetJavaEnvProc(_getJavaEnv);
CALLBACKS.requestread = NewNPN_RequestReadProc(_requestread);
CALLBACKS.newstream = NewNPN_NewStreamProc(_newstream);
CALLBACKS.write = NewNPN_WriteProc(_write);
CALLBACKS.destroystream = NewNPN_DestroyStreamProc(_destroystream);
CALLBACKS.status = NewNPN_StatusProc(_status);
CALLBACKS.uagent = NewNPN_UserAgentProc(_useragent);
CALLBACKS.memalloc = NewNPN_MemAllocProc(_memalloc);
CALLBACKS.memfree = NewNPN_MemFreeProc(_memfree);
CALLBACKS.memflush = NewNPN_MemFlushProc(_memflush);
CALLBACKS.reloadplugins = NewNPN_ReloadPluginsProc(_reloadplugins);
CALLBACKS.getJavaEnv = NewNPN_GetJavaEnvProc(_getJavaEnv);
// CALLBACKS.getJavaPeer = NewNPN_GetJavaPeerProc(_getJavaPeer);
CALLBACKS.geturlnotify = NewNPN_GetURLNotifyProc(_geturlnotify);
CALLBACKS.posturlnotify = NewNPN_PostURLNotifyProc(_posturlnotify);
// CALLBACKS.getvalue = NewNPN_GetValueProc(_getvalue);
// CALLBACKS.setvalue = NewNPN_SetValueProc(_setvalue);
// CALLBACKS.invalidaterect = NewNPN_InvalidateRectProc(_invalidaterect);
// CALLBACKS.invalidateregion = NewNPN_InvalidateRegionProc(_invalidateregion);
// CALLBACKS.forceredraw = NewNPN_ForceRedrawProc(_forceredraw);
CALLBACKS.getvalue = NewNPN_GetValueProc(_getvalue);
CALLBACKS.setvalue = NewNPN_SetValueProc(_setvalue);
CALLBACKS.invalidaterect = NewNPN_InvalidateRectProc(_invalidaterect);
CALLBACKS.invalidateregion = NewNPN_InvalidateRegionProc(_invalidateregion);
CALLBACKS.forceredraw = NewNPN_ForceRedrawProc(_forceredraw);
initialized = TRUE;
};
@ -83,13 +88,14 @@ ns4xPlugin::ns4xPlugin(NPPluginFuncs* callbacks)
{
NS_INIT_REFCNT();
memcpy((void*) &fCallbacks, (void*) callbacks, sizeof(fCallbacks));
mManager = nsnull;
}
ns4xPlugin::~ns4xPlugin(void)
{
NS_IF_RELEASE(mManager);
NS_IF_RELEASE(mPluginManager);
NS_IF_RELEASE(mNetworkManager);
NS_IF_RELEASE(mMalloc);
}
@ -102,6 +108,8 @@ NS_IMPL_RELEASE(ns4xPlugin);
static NS_DEFINE_IID(kILiveConnectPluginIID, NS_ILIVECONNECTPLUGIN_IID);
static NS_DEFINE_IID(kIPluginIID, NS_IPLUGIN_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIWindowlessPluginInstancePeerIID, NS_IWINDOWLESSPLUGININSTANCEPEER_IID);
static NS_DEFINE_IID(kISeekablePluginStreamPeerIID, NS_ISEEKABLEPLUGINSTREAMPEER_IID);
nsresult
ns4xPlugin::QueryInterface(const nsIID& iid, void** instance)
@ -109,20 +117,28 @@ ns4xPlugin::QueryInterface(const nsIID& iid, void** instance)
if (instance == NULL)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIPluginIID) ||
iid.Equals(kISupportsIID)) {
*instance = (void*) this;
if (iid.Equals(kIPluginIID))
{
*instance = (void *)(nsIPlugin *)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kILiveConnectPluginIID)) {
if (iid.Equals(kILiveConnectPluginIID))
{
// Check the 4.x plugin callbacks to see if it supports
// LiveConnect...
if (fCallbacks.javaClass == NULL)
return NS_NOINTERFACE;
*instance = (void*) this;
*instance = (void *)(nsILiveConnectPlugin *)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kISupportsIID))
{
*instance = (void *)(nsISupports *)this;
AddRef();
return NS_OK;
}
@ -200,7 +216,7 @@ nsresult ns4xPlugin :: CreateInstance(nsISupports *aOuter,
nsISupports *inst;
inst = nsnull;
// inst = (nsISupports *)(nsIPluginInstance *)new ns4xPluginInstance();
inst = (nsISupports *)(nsIPluginInstance *)new ns4xPluginInstance(&fCallbacks);
if (inst == NULL) {
return NS_ERROR_OUT_OF_MEMORY;
@ -223,20 +239,33 @@ nsresult ns4xPlugin :: LockFactory(PRBool aLock)
}
static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID);
static NS_DEFINE_IID(kINetworkManagerIID, NS_INETWORKMANAGER_IID);
static NS_DEFINE_IID(kIMallocIID, NS_IMALLOC_IID);
nsresult
ns4xPlugin::Initialize(nsISupports* browserInterfaces)
{
if (nsnull == mManager)
return browserInterfaces->QueryInterface(kIPluginManagerIID, (void **)&mManager);
else
return NS_OK;
nsresult rv = NS_OK;
if (nsnull == mPluginManager)
rv = browserInterfaces->QueryInterface(kIPluginManagerIID, (void **)&mPluginManager);
if (nsnull == mNetworkManager)
rv = browserInterfaces->QueryInterface(kINetworkManagerIID, (void **)&mNetworkManager);
if (nsnull == mMalloc)
rv = browserInterfaces->QueryInterface(kIMallocIID, (void **)&mMalloc);
return rv;
}
nsresult
ns4xPlugin::Shutdown(void)
{
NS_IF_RELEASE(mManager);
NS_IF_RELEASE(mPluginManager);
NS_IF_RELEASE(mNetworkManager);
NS_IF_RELEASE(mMalloc);
return NS_OK;
}
@ -262,7 +291,7 @@ ns4xPlugin::SetValue(nsPluginVariable variable, void *value)
nsresult
ns4xPlugin::GetJavaClass(jclass *resultingClass)
{
*resultingClass = fCallbacks.javaClass;
*resultingClass = (jclass)fCallbacks.javaClass;
return NS_OK;
}
@ -277,29 +306,12 @@ ns4xPlugin::_geturl(NPP npp, const char* relativeURL, const char* target)
nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata;
NS_ASSERTION(peer != NULL, "null peer");
NS_ASSERTION(mManager != NULL, "null manager");
NS_ASSERTION(mNetworkManager != NULL, "null manager");
if (peer == NULL)
return NS_ERROR_UNEXPECTED; // XXX
#if 0
nsURLInfo urlinfo;
urlinfo.version = nsURLInfo_Version;
urlinfo.url = relativeURL;
urlinfo.target = target;
urlinfo.notifyData = nsnull;
urlinfo.altHost = nsnull;
urlinfo.referrer = nsnull;
urlinfo.forceJSEnabled = PR_FALSE;
urlinfo.postData = nsnull;
urlinfo.postDataLength = 0;
urlinfo.postHeaders = nsnull;
urlinfo.postHeadersLength = 0;
urlinfo.postFile = PR_FALSE;
return mManager->FetchURL(peer, &urlinfo);
#endif
return NS_OK;
return mNetworkManager->GetURL(peer, relativeURL, target);
}
nsresult NP_EXPORT
@ -309,29 +321,13 @@ ns4xPlugin::_geturlnotify(NPP npp, const char* relativeURL, const char* target,
nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata;
NS_ASSERTION(peer != NULL, "null peer");
NS_ASSERTION(mManager != NULL, "null manager");
NS_ASSERTION(mNetworkManager != NULL, "null manager");
if (peer == NULL)
return NS_ERROR_UNEXPECTED; // XXX
#if 0
nsURLInfo urlinfo;
urlinfo.version = nsURLInfo_Version;
urlinfo.url = relativeURL;
urlinfo.target = target;
urlinfo.notifyData = notifyData;
urlinfo.altHost = nsnull;
urlinfo.referrer = nsnull;
urlinfo.forceJSEnabled = PR_FALSE;
urlinfo.postData = nsnull;
urlinfo.postDataLength = 0;
urlinfo.postHeaders = nsnull;
urlinfo.postHeadersLength = 0;
urlinfo.postFile = PR_FALSE;
return mManager->FetchURL(peer, &urlinfo);
#endif
return NS_OK;
return mNetworkManager->GetURL(peer, relativeURL, target,
notifyData);
}
@ -343,29 +339,13 @@ ns4xPlugin::_posturlnotify(NPP npp, const char* relativeURL, const char *target,
nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata;
NS_ASSERTION(peer != NULL, "null peer");
NS_ASSERTION(mManager != NULL, "null manager");
NS_ASSERTION(mNetworkManager != NULL, "null manager");
if (peer == NULL)
return NS_ERROR_UNEXPECTED; // XXX
#if 0
nsURLInfo urlinfo;
urlinfo.version = nsURLInfo_Version;
urlinfo.url = relativeURL;
urlinfo.target = target;
urlinfo.notifyData = notifyData;
urlinfo.altHost = nsnull;
urlinfo.referrer = nsnull;
urlinfo.forceJSEnabled = PR_FALSE;
urlinfo.postData = buf;
urlinfo.postDataLength = len;
urlinfo.postHeaders = nsnull;
urlinfo.postHeadersLength = 0;
urlinfo.postFile = file;
return mManager->FetchURL(peer, &urlinfo);
#endif
return NS_OK;
return mNetworkManager->PostURL(peer, relativeURL, target,
len, buf, file, notifyData);
}
@ -376,49 +356,32 @@ ns4xPlugin::_posturl(NPP npp, const char* relativeURL, const char *target, uint3
nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata;
NS_ASSERTION(peer != NULL, "null peer");
NS_ASSERTION(mManager != NULL, "null manager");
NS_ASSERTION(mNetworkManager != NULL, "null manager");
if (peer == NULL)
return NS_ERROR_UNEXPECTED; // XXX
#if 0
nsURLInfo urlinfo;
urlinfo.version = nsURLInfo_Version;
urlinfo.url = relativeURL;
urlinfo.target = target;
urlinfo.notifyData = nsnull;
urlinfo.altHost = nsnull;
urlinfo.referrer = nsnull;
urlinfo.forceJSEnabled = PR_FALSE;
urlinfo.postData = buf;
urlinfo.postDataLength = len;
urlinfo.postHeaders = nsnull;
urlinfo.postHeadersLength = 0;
urlinfo.postFile = file;
return mManager->FetchURL(peer, &urlinfo);
#endif
return NS_OK;
return mNetworkManager->PostURL(peer, relativeURL, target,
len, buf, file);
}
#if 0
////////////////////////////////////////////////////////////////////////
/**
* A little helper class used to wrap up plugin manager streams (that is,
* streams from the plugin to the browser).
*/
class ns4xStreamWrapper {
class ns4xStreamWrapper
{
protected:
NPIPluginManagerStream* fStream;
NPStream fNPStream;
nsIOutputStream *fStream;
NPStream fNPStream;
public:
ns4xStreamWrapper(NPIPluginManagerStream* stream);
ns4xStreamWrapper(nsIOutputStream* stream);
~ns4xStreamWrapper();
NPIPluginManagerStream*
nsIOutputStream*
GetStream(void);
NPStream*
@ -427,11 +390,12 @@ public:
};
};
ns4xStreamWrapper::ns4xStreamWrapper(NPIPluginManagerStream* stream)
ns4xStreamWrapper::ns4xStreamWrapper(nsIOutputStream* stream)
: fStream(stream)
{
PR_ASSERT(stream != NULL);
fStream->AddRef();
NS_ASSERTION(stream != NULL, "bad stream");
NS_ADDREF(fStream);
memset(&fNPStream, 0, sizeof(fNPStream));
fNPStream.ndata = (void*) this;
@ -439,15 +403,13 @@ ns4xStreamWrapper::ns4xStreamWrapper(NPIPluginManagerStream* stream)
ns4xStreamWrapper::~ns4xStreamWrapper(void)
{
if (fStream != NULL)
fStream->Release();
NS_IF_RELEASE(fStream);
}
NPIPluginManagerStream*
nsIOutputStream*
ns4xStreamWrapper::GetStream(void)
{
if (fStream != NULL)
fStream->AddRef();
NS_IF_ADDREF(fStream);
return fStream;
}
@ -466,194 +428,205 @@ ns4xPlugin::_newstream(NPP npp, NPMIMEType type, const char* window, NPStream* *
return NS_ERROR_UNEXPECTED; // XXX
nsresult error;
nsIPluginStream* stream;
nsIOutputStream* stream;
if ((error = peer->NewStream((const char*) type, window, &stream))
!= NPPluginError_NoError)
return (NPError) error;
!= NS_OK)
return error;
ns4xStreamWrapper* wrapper = new ns4xStreamWrapper(stream);
if (wrapper == NULL) {
stream->Release();
return NPERR_OUT_OF_MEMORY_ERROR;
if (wrapper == NULL)
{
NS_RELEASE(stream);
return NS_ERROR_OUT_OF_MEMORY;
}
(*result) = wrapper->GetNPStream();
return NPERR_NO_ERROR;
return NS_OK;
}
int32 NP_EXPORT
ns4xPlugin::_write(NPP npp, NPStream *pstream, int32 len, void *buffer)
{
ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) npp->ndata;
PR_ASSERT(wrapper != NULL);
NS_ASSERTION(wrapper != NULL, "null wrapper");
if (wrapper == NULL)
return 0;
NPIPluginManagerStream* stream = wrapper->GetStream();
PRUint32 count = 0;
while (count < ((PRUint32) len)) {
PRUint32 ready = stream->WriteReady();
ready = (ready > ((PRUint32) len)) ? ((PRUint32) len) : ready;
nsIOutputStream* stream = wrapper->GetStream();
PRUint32 written = stream->Write(ready, ((const char*) buffer) + count);
count += written;
}
PRInt32 count = 0;
nsresult rv = stream->Write((char *)buffer, 0, len, &count);
stream->Release();
NS_RELEASE(stream);
return count;
}
NPError NP_EXPORT
nsresult NP_EXPORT
ns4xPlugin::_destroystream(NPP npp, NPStream *pstream, NPError reason)
{
ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) npp->ndata;
PR_ASSERT(wrapper != NULL);
NS_ASSERTION(wrapper != NULL, "null wrapper");
if (wrapper == NULL)
return 0;
// This will release the wrapped NPIPluginManagerStream.
// This will release the wrapped nsIOutputStream.
delete wrapper;
return NPERR_NO_ERROR;
return NS_OK;
}
void NP_EXPORT
ns4xPlugin::_status(NPP npp, const char *message)
{
NPIPluginInstancePeer* peer = (NPIPluginInstancePeer*) npp->ndata;
PR_ASSERT(peer != NULL);
nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata;
NS_ASSERTION(peer != NULL, "null peer");
if (peer == NULL)
return;
peer->ShowStatus(message);
}
void NP_EXPORT
ns4xPlugin::_memfree (void *ptr)
{
thePluginManager->MemFree(ptr);
mMalloc->Free(ptr);
}
uint32 NP_EXPORT
ns4xPlugin::_memflush(uint32 size)
{
return thePluginManager->MemFlush(size);
mMalloc->HeapMinimize();
return 0;
}
void NP_EXPORT
ns4xPlugin::_reloadplugins(NPBool reloadPages)
{
thePluginManager->ReloadPlugins(reloadPages);
mPluginManager->ReloadPlugins(reloadPages);
}
void NP_EXPORT
ns4xPlugin::_invalidaterect(NPP npp, NPRect *invalidRect)
{
NPIPluginInstancePeer* peer = (NPIPluginInstancePeer*) npp->ndata;
PR_ASSERT(peer != NULL);
nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata;
NS_ASSERTION(peer != NULL, "null peer");
if (peer == NULL)
return;
// XXX nsRect & NPRect are structurally equivalent
peer->InvalidateRect((nsRect*) invalidRect);
nsIWindowlessPluginInstancePeer *wpeer;
if (NS_OK == peer->QueryInterface(kIWindowlessPluginInstancePeerIID, (void **)&wpeer))
{
// XXX nsRect & NPRect are structurally equivalent
wpeer->InvalidateRect((nsPluginRect *)invalidRect);
NS_RELEASE(wpeer);
}
}
void NP_EXPORT
ns4xPlugin::_invalidateregion(NPP npp, NPRegion invalidRegion)
{
NPIPluginInstancePeer* peer = (NPIPluginInstancePeer*) npp->ndata;
PR_ASSERT(peer != NULL);
nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata;
NS_ASSERTION(peer != NULL, "null peer");
if (peer == NULL)
return;
// XXX nsRegion & NPRegion are typedef'd to the same thing
peer->InvalidateRegion((nsRegion*) invalidRegion);
nsIWindowlessPluginInstancePeer *wpeer;
if (NS_OK == peer->QueryInterface(kIWindowlessPluginInstancePeerIID, (void **)&wpeer))
{
// XXX nsRegion & NPRegion are typedef'd to the same thing
wpeer->InvalidateRegion((nsPluginRegion*) invalidRegion);
NS_RELEASE(wpeer);
}
}
void NP_EXPORT
ns4xPlugin::_forceredraw(NPP npp)
{
NPIPluginInstancePeer* peer = (NPIPluginInstancePeer*) npp->ndata;
PR_ASSERT(peer != NULL);
nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata;
NS_ASSERTION(peer != NULL, "null peer");
if (peer == NULL)
return;
peer->ForceRedraw();
nsIWindowlessPluginInstancePeer *wpeer;
if (NS_OK == peer->QueryInterface(kIWindowlessPluginInstancePeerIID, (void **)&wpeer))
{
wpeer->ForceRedraw();
NS_RELEASE(wpeer);
}
}
NPError NP_EXPORT
nsresult NP_EXPORT
ns4xPlugin::_getvalue(NPP npp, NPNVariable variable, void *result)
{
NPIPluginInstancePeer* peer = (NPIPluginInstancePeer*) npp->ndata;
PR_ASSERT(peer != NULL);
nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata;
NS_ASSERTION(peer != NULL, "null peer");
if (peer == NULL)
return NPERR_INVALID_PLUGIN_ERROR; // XXX
return NS_ERROR_FAILURE; // XXX
// XXX Note that for backwards compatibility, the old NPNVariables
// map correctly to NPPluginManagerVariables.
return (NPError) peer->GetValue((NPPluginManagerVariable) variable, result);
return peer->GetValue((nsPluginInstancePeerVariable)variable, result);
}
NPError NP_EXPORT
nsresult NP_EXPORT
ns4xPlugin::_setvalue(NPP npp, NPPVariable variable, void *result)
{
NPIPluginInstancePeer* peer = (NPIPluginInstancePeer*) npp->ndata;
PR_ASSERT(peer != NULL);
nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata;
NS_ASSERTION(peer != NULL, "null peer");
if (peer == NULL)
return NPERR_INVALID_PLUGIN_ERROR; // XXX
return NS_ERROR_FAILURE; // XXX
// XXX Note that for backwards compatibility, the old NPPVariables
// map correctly to NPPluginVariables.
return (NPError) peer->SetValue((NPPluginVariable) variable, result);
return peer->SetValue((nsPluginInstancePeerVariable)variable, result);
}
NPError NP_EXPORT
nsresult NP_EXPORT
ns4xPlugin::_requestread(NPStream *pstream, NPByteRange *rangeList)
{
NPIPluginStreamPeer* streamPeer = (NPIPluginStreamPeer*) pstream->ndata;
PR_ASSERT(streamPeer != NULL);
if (streamPeer == NULL)
return NPERR_INVALID_PLUGIN_ERROR; // XXX
nsIPluginStreamPeer* streamPeer = (nsIPluginStreamPeer*) pstream->ndata;
NS_ASSERTION(streamPeer != NULL, "null streampeer");
if (streamPeer == NULL)
return NS_ERROR_FAILURE; // XXX
nsISeekablePluginStreamPeer* seekablePeer = NULL;
NPISeekablePluginStreamPeer* seekablePeer = NULL;
static NS_DEFINE_IID(kISeekablePluginStreamPeerIID, NP_ISEEKABLEPLUGINSTREAMPEER_IID);
if (streamPeer->QueryInterface(kISeekablePluginStreamPeerIID,
(void**) seekablePeer) == NS_OK) {
NPError error;
(void**)seekablePeer) == NS_OK)
{
nsresult error;
// XXX nsByteRange & NPByteRange are structurally equivalent.
error = (NPError) seekablePeer->RequestRead((nsByteRange*) rangeList);
seekablePeer->Release();
error = seekablePeer->RequestRead((nsByteRange *)rangeList);
NS_RELEASE(seekablePeer);
return error;
}
return NPERR_STREAM_NOT_SEEKABLE;
return NS_ERROR_UNEXPECTED;
}
@ -674,25 +647,28 @@ ns4xPlugin::_getJavaEnv(void)
return NULL;
}
const char * NP_EXPORT
ns4xPlugin::_useragent(NPP npp)
{
NPIPluginInstancePeer* peer = (NPIPluginInstancePeer*) npp->ndata;
PR_ASSERT(peer != NULL);
if (peer == NULL)
NS_ASSERTION(mPluginManager != NULL, "null pluginmanager");
if (mPluginManager == NULL)
return NULL;
return peer->UserAgent();
}
char *retstr;
mPluginManager->UserAgent((const char **)&retstr);
return retstr;
}
void * NP_EXPORT
ns4xPlugin::_memalloc (uint32 size)
{
return thePluginManager->MemAlloc(size);
return mMalloc->Alloc(size);
}
#if 0
#ifdef JAVA
java_lang_Class* NP_EXPORT
@ -727,11 +703,11 @@ ns4xPlugin::_getJavaPeer(NPP npp)
return NULL;
}
#endif
#if defined(XP_MAC) && !defined(powerc)
#pragma pointers_in_A0
#endif
//
////////////////////////////////////////////////////////////////////////
#endif

View File

@ -21,7 +21,8 @@
#include "nsplugin.h"
#include "prlink.h" // for PRLibrary
#include "../src/npupp.h"
#include "npupp.h"
#include "nsIMalloc.h"
////////////////////////////////////////////////////////////////////////
@ -128,8 +129,6 @@ protected:
_posturl(NPP npp, const char* relativeURL, const char *target, uint32 len,
const char *buf, NPBool file);
#if 0
static nsresult NP_EXPORT
_newstream(NPP npp, NPMIMEType type, const char* window, NPStream** pstream);
@ -142,6 +141,8 @@ protected:
static void NP_EXPORT
_status(NPP npp, const char *message);
#if 0
static void NP_EXPORT
_registerwindow(NPP npp, void* window);
@ -151,6 +152,8 @@ protected:
static int16 NP_EXPORT
_allocateMenuID(NPP npp, NPBool isSubmenu);
#endif
static void NP_EXPORT
_memfree (void *ptr);
@ -187,13 +190,15 @@ protected:
static JRIEnv* NP_EXPORT
_getJavaEnv(void);
#if 0
static jref NP_EXPORT
_getJavaPeer(NPP npp);
#if defined(XP_MAC) && !defined(powerc)
#pragma pointers_in_A0
#endif
#if defined(XP_MAC) && !defined(powerc)
#pragma pointers_in_A0
#endif
/**
@ -207,7 +212,9 @@ protected:
*/
static NPNetscapeFuncs CALLBACKS;
static nsIPluginManager *mManager;
static nsIPluginManager *mPluginManager;
static nsINetworkManager *mNetworkManager;
static nsIMalloc *mMalloc;
};
#endif // ns4xPlugin_h__

View File

@ -0,0 +1,239 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "ns4xPluginInstance.h"
#include "ns4xPluginStream.h"
#include "prlog.h"
////////////////////////////////////////////////////////////////////////
ns4xPluginInstance :: ns4xPluginInstance(NPPluginFuncs* callbacks)
: fCallbacks(callbacks)
{
NS_INIT_REFCNT();
NS_ASSERTION(fCallbacks != NULL, "null callbacks");
// Initialize the NPP structure.
fNPP.pdata = NULL;
fNPP.ndata = this;
fPeer = nsnull;
}
ns4xPluginInstance :: ~ns4xPluginInstance(void)
{
NS_RELEASE(fPeer);
}
////////////////////////////////////////////////////////////////////////
NS_IMPL_ADDREF(ns4xPluginInstance);
NS_IMPL_RELEASE(ns4xPluginInstance);
static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID);
static NS_DEFINE_IID(kIEventHandlerIID, NS_IEVENTHANDLER_IID);
static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
NS_IMETHODIMP ns4xPluginInstance :: QueryInterface(const nsIID& iid, void** instance)
{
if (instance == NULL)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIPluginInstanceIID))
{
*instance = (void *)(nsIPluginInstance *)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kIEventHandlerIID))
{
*instance = (void *)(nsIEventHandler *)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kISupportsIID))
{
*instance = (void *)(nsISupports *)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP ns4xPluginInstance :: Initialize(nsIPluginInstancePeer* peer)
{
PRUint16 count;
const char* const* names;
const char* const* values;
NS_ASSERTION(peer != NULL, "null peer");
fPeer = peer;
NS_ADDREF(fPeer);
nsresult error;
nsIPluginTagInfo *taginfo;
error = fPeer->QueryInterface(kIPluginTagInfoIID, (void **)&taginfo);
if (NS_OK == error)
{
if ((error = taginfo->GetAttributes(count, names, values)) != NS_OK)
return error;
if (fCallbacks->newp == NULL)
return NS_ERROR_FAILURE; // XXX right error?
// XXX Note that the NPPluginType_* enums were crafted to be
// backward compatible...
nsPluginMode mode;
nsMIMEType mimetype;
fPeer->GetMode(&mode);
fPeer->GetMIMEType(&mimetype);
error = (nsresult)
CallNPP_NewProc(fCallbacks->newp,
(char *)mimetype,
&fNPP,
(PRUint16)mode,
count,
(char**)names,
(char**)values,
NULL); // saved data
NS_RELEASE(taginfo);
}
return error;
}
NS_IMETHODIMP ns4xPluginInstance :: GetPeer(nsIPluginInstancePeer* *resultingPeer)
{
NS_ADDREF(fPeer);
*resultingPeer = fPeer;
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::Start(void)
{
// XXX At some point, we maybe should implement start and stop to
// load/unload the 4.x plugin, just in case there are some plugins
// that rely on that behavior...
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::Stop(void)
{
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::Destroy(void)
{
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::SetWindow(nsPluginWindow* window)
{
// XXX 4.x plugins don't want a SetWindow(NULL).
if (window == NULL)
return NS_OK;
nsresult error = NS_OK;
if (fCallbacks->setwindow) {
// XXX Turns out that NPPluginWindow and NPWindow are structurally
// identical (on purpose!), so there's no need to make a copy.
error = (nsresult) CallNPP_SetWindowProc(fCallbacks->setwindow,
&fNPP,
(NPWindow*) window);
// XXX In the old code, we'd just ignore any errors coming
// back from the plugin's SetWindow(). Is this the correct
// behavior?!?
NS_ASSERTION(error == NS_OK, "error in setwindow");
}
return error;
}
NS_IMETHODIMP ns4xPluginInstance::NewStream(nsIPluginStreamPeer* peer, nsIPluginStream* *result)
{
(*result) = NULL;
ns4xPluginStream* stream = new ns4xPluginStream();
if (stream == NULL)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(stream);
nsresult error;
// does it need the peer?
if ((error = stream->Initialize(this, peer)) != NS_OK)
{
NS_RELEASE(stream);
return error;
}
(*result) = stream;
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::Print(nsPluginPrint* platformPrint)
{
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::HandleEvent(nsPluginEvent* event, PRBool* handled)
{
*handled = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::URLNotify(const char* url, const char* target,
nsPluginReason reason, void* notifyData)
{
if (fCallbacks->urlnotify != NULL)
{
CallNPP_URLNotifyProc(fCallbacks->urlnotify,
&fNPP,
url,
reason,
notifyData);
}
return NS_OK; //XXX this seems bad...
}

View File

@ -0,0 +1,127 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef ns4xPluginInstance_h__
#define ns4xPluginInstance_h__
#include "nsplugin.h"
#include "npupp.h"
#include "jri.h"
////////////////////////////////////////////////////////////////////////
class ns4xPluginInstance : public nsIPluginInstance
{
public:
/**
* Construct a new 4.x plugin instance with the specified peer
* and callbacks.
*/
ns4xPluginInstance(NPPluginFuncs* callbacks);
// Use Release() to destroy this
~ns4xPluginInstance(void);
NS_DECL_ISUPPORTS
////////////////////////////////////////////////////////////////////////
// nsIPluginInstance methods
/**
* Actually initialize the plugin instance. This calls the 4.x <b>newp</b>
* callback, and may return an error (which is why it is distinct from the
* constructor.) If an error is returned, the caller should <i>not</i>
* continue to use the <b>ns4xPluginInstance</b> object.
*/
NS_METHOD
Initialize(nsIPluginInstancePeer* peer);
NS_IMETHOD
GetPeer(nsIPluginInstancePeer* *resultingPeer);
NS_IMETHOD
Start(void);
NS_IMETHOD
Stop(void);
NS_IMETHOD
Destroy(void);
NS_IMETHOD
SetWindow(nsPluginWindow* window);
NS_IMETHOD
NewStream(nsIPluginStreamPeer* peer, nsIPluginStream* *result);
NS_IMETHOD
Print(nsPluginPrint* platformPrint);
NS_IMETHOD
HandleEvent(nsPluginEvent* event, PRBool* handled);
NS_IMETHOD
URLNotify(const char* url, const char* target,
nsPluginReason reason, void* notifyData);
////////////////////////////////////////////////////////////////////////
// ns4xPluginInstance-specific methods
/**
* Return the 4.x-style interface object.
*/
NS_IMETHOD
GetNPP(NPP * aNPP) {
*aNPP = &fNPP;
return NS_OK;
};
/**
* Return the callbacks for the plugin instance.
*/
NS_IMETHOD
GetCallbacks(const NPPluginFuncs ** aCallbacks) {
*aCallbacks = fCallbacks;
return NS_OK;
};
protected:
/**
* The plugin instance peer for this instance.
*/
nsIPluginInstancePeer* fPeer;
/**
* A pointer to the plugin's callback functions. This information
* is actually stored in the plugin class (<b>nsPluginClass</b>),
* and is common for all plugins of the class.
*/
NPPluginFuncs* fCallbacks;
/**
* The 4.x-style structure used to communicate between the plugin
* instance and the browser.
*/
NPP_t fNPP;
};
#endif // ns4xPluginInstance_h__

View File

@ -0,0 +1,210 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "ns4xPluginStream.h"
#include "prlog.h" // for PR_ASSERT
////////////////////////////////////////////////////////////////////////
ns4xPluginStream::ns4xPluginStream(void)
: fStreamType(nsPluginStreamType_Normal), fSeekable(PR_FALSE), fPosition(0)
{
NS_INIT_REFCNT();
// Initialize the 4.x interface structure
memset(&fNPStream, 0, sizeof(fNPStream));
}
ns4xPluginStream::~ns4xPluginStream(void)
{
const NPPluginFuncs *callbacks;
NPP npp;
nsPluginReason reason;
fInstance->GetCallbacks(&callbacks);
fInstance->GetNPP(&npp);
fPeer->GetReason(&reason);
if (callbacks->destroystream != NULL)
{
CallNPP_DestroyStreamProc(callbacks->destroystream,
npp,
&fNPStream,
reason);
}
NS_IF_RELEASE(fPeer);
NS_IF_RELEASE(fInstance);
}
////////////////////////////////////////////////////////////////////////
NS_IMPL_ADDREF(ns4xPluginStream);
NS_IMPL_RELEASE(ns4xPluginStream);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIPluginStreamIID, NS_IPLUGINSTREAM_IID);
static NS_DEFINE_IID(kISeekablePluginStreamPeerIID, NS_ISEEKABLEPLUGINSTREAMPEER_IID);
NS_IMETHODIMP ns4xPluginStream::QueryInterface(const nsIID& iid, void** instance)
{
if (instance == NULL)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIPluginStreamIID))
{
*instance = (void *)(nsIPluginStream *)this;
AddRef();
return NS_OK;
}
else if (iid.Equals(kISupportsIID))
{
*instance = (void *)(nsISupports *)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP ns4xPluginStream::Initialize(ns4xPluginInstance* instance,
nsIPluginStreamPeer* peer)
{
fInstance = instance;
fPeer = peer;
NS_ASSERTION(fInstance != NULL, "null instance");
fInstance->AddRef();
NS_ASSERTION(fPeer != NULL, "null peer");
NS_ADDREF(fPeer);
const char *url;
PRUint32 length, modified;
fPeer->GetURL(&url);
fPeer->GetEnd(&length);
fPeer->GetLastModified(&modified);
fNPStream.ndata = (void*) fPeer;
fNPStream.url = url;
fNPStream.end = length;
fNPStream.lastmodified = modified;
// Are we seekable?
nsISupports* seekablePeer;
if (fPeer->QueryInterface(kISeekablePluginStreamPeerIID,
(void**) &seekablePeer) == NS_OK)
{
fSeekable = TRUE;
NS_RELEASE(seekablePeer);
}
const NPPluginFuncs *callbacks;
NPP npp;
nsMIMEType mimetype;
fInstance->GetCallbacks(&callbacks);
fInstance->GetNPP(&npp);
fPeer->GetMIMEType(&mimetype);
if (callbacks->newstream == NULL)
return NS_ERROR_FAILURE;
PRUint16 streamType = (PRUint16) fStreamType;
nsresult error
= (nsresult)CallNPP_NewStreamProc(callbacks->newstream,
npp,
(char *)mimetype,
&fNPStream,
fSeekable,
&streamType);
fStreamType = (nsPluginStreamType) streamType;
return error;
}
NS_IMETHODIMP ns4xPluginStream::Write(const char* buffer, PRInt32 offset, PRInt32 len, PRInt32 *aWriteCount)
{
const NPPluginFuncs *callbacks;
NPP npp;
fInstance->GetCallbacks(&callbacks);
fInstance->GetNPP(&npp);
if (callbacks->write == NULL)
return NS_OK;
*aWriteCount = CallNPP_WriteProc(callbacks->write,
npp,
&fNPStream,
fPosition,
len,
(void *)buffer);
fPosition += len;
return NS_OK; //XXX this seems bad...
}
NS_IMETHODIMP ns4xPluginStream::GetStreamType(nsPluginStreamType *result)
{
*result = fStreamType;
return NS_OK;
}
NS_IMETHODIMP ns4xPluginStream::AsFile(const char* filename)
{
const NPPluginFuncs *callbacks;
NPP npp;
fInstance->GetCallbacks(&callbacks);
fInstance->GetNPP(&npp);
if (callbacks->asfile == NULL)
return NS_OK;
CallNPP_StreamAsFileProc(callbacks->asfile,
npp,
&fNPStream,
filename);
return NS_OK;
}
NS_IMETHODIMP ns4xPluginStream :: Close(void)
{
return NS_OK;
}
////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,112 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef ns4xPluginStream_h__
#define ns4xPluginStream_h__
#include "jri.h" // XXX should be jni.h
#include "nsplugin.h"
#include "ns4xPluginInstance.h"
////////////////////////////////////////////////////////////////////////
/**
* A 5.0 wrapper for a 4.x plugin stream.
*/
class ns4xPluginStream : public nsIPluginStream
{
public:
/**
* Construct a new 4.x plugin stream associated with the specified
* instance and stream peer.
*/
ns4xPluginStream();
~ns4xPluginStream();
NS_DECL_ISUPPORTS
/**
* Do internal initialization. This actually calls into the 4.x plugin
* to create the stream, and may fail (which is why it's separate from
* the constructor).
*/
NS_METHOD
Initialize(ns4xPluginInstance* instance, nsIPluginStreamPeer* peer);
////////////////////////////////////////////////////////////////////////
// nsIPluginStream methods
// (Corresponds to NPP_Write and NPN_Write.)
NS_IMETHOD
Write(const char* buffer, PRInt32 offset, PRInt32 len, PRInt32 *aWriteCount);
// (Corresponds to NPP_NewStream's stype return parameter.)
NS_IMETHOD
GetStreamType(nsPluginStreamType *result);
// (Corresponds to NPP_StreamAsFile.)
NS_IMETHOD
AsFile(const char* fname);
NS_IMETHOD
Close(void);
////////////////////////////////////////////////////////////////////////
// Methods specific to ns4xPluginStream
protected:
/**
* The plugin instance to which this stream belongs.
*/
ns4xPluginInstance* fInstance;
/**
* The peer associated with this stream.
*/
nsIPluginStreamPeer* fPeer;
/**
* The type of stream, for the peer's use.
*/
nsPluginStreamType fStreamType;
/**
* The 4.x-style structure used to contain stream information.
* This is what actually gets used to communicate with the plugin.
*/
NPStream fNPStream;
/**
* Set to <b>TRUE</b> if the peer implements
* <b>NPISeekablPluginStreamPeer</b>.
*/
PRBool fSeekable;
/**
* Tracks the position in the content that is being
* read. 4.x-style plugins expect to be told the offset in the
* buffer that they should read <i>to</i>, even though it's always
* done serially.
*/
PRUint32 fPosition;
};
#endif // ns4xPluginStream_h__

View File

@ -36,7 +36,7 @@ public:
LoadPlugins(void) = 0;
NS_IMETHOD
InstantiatePlugin(char *aMimeType, nsISupports ** aPluginInst) = 0;
InstantiatePlugin(char *aMimeType, nsIPluginInstance ** aPluginInst) = 0;
};
#endif

View File

@ -21,11 +21,15 @@
#include "prio.h"
#include "prmem.h"
#include "ns4xPlugin.h"
#include "nsMalloc.h" //this is evil...
#include "nsPluginInstancePeer.h"
#ifdef XP_PC
#include "windows.h"
#endif
static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID);
nsPluginTag :: nsPluginTag()
{
mNext = nsnull;
@ -104,6 +108,7 @@ nsPluginTag :: ~nsPluginTag()
static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID);
static NS_DEFINE_IID(kIPluginHostIID, NS_IPLUGINHOST_IID);
static NS_DEFINE_IID(kIMallocIID, NS_IMALLOC_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
nsPluginHostImpl :: nsPluginHostImpl()
@ -124,6 +129,8 @@ nsPluginHostImpl :: ~nsPluginHostImpl()
delete mPlugins;
mPlugins = temp;
}
NS_IF_RELEASE(mMalloc);
}
NS_IMPL_ADDREF(nsPluginHostImpl)
@ -151,6 +158,13 @@ nsresult nsPluginHostImpl :: QueryInterface(const nsIID& aIID,
return NS_OK;
}
if (aIID.Equals(kIMallocIID))
{
*aInstancePtrResult = mMalloc;
NS_IF_ADDREF(mMalloc);
return NS_OK;
}
if (aIID.Equals(kISupportsIID))
{
*aInstancePtrResult = (void *)((nsISupports *)((nsIPluginHost *)this));
@ -183,14 +197,32 @@ nsresult nsPluginHostImpl :: SetValue(nsPluginManagerVariable variable, void *va
return NS_OK;
}
//nsresult nsPluginHostImpl :: FetchURL(nsISupports* peer, nsURLInfo* urlInfo)
//{
// return NS_OK;
//}
NS_IMETHODIMP nsPluginHostImpl :: GetURL(nsISupports* peer, const char* url,
const char* target,
void* notifyData, const char* altHost,
const char* referrer, PRBool forceJSEnabled)
{
return NS_OK;
}
NS_IMETHODIMP nsPluginHostImpl :: PostURL(nsISupports* peer,
const char* url, const char* target,
PRUint32 postDataLen, const char* postData,
PRBool isFile, void* notifyData,
const char* altHost, const char* referrer,
PRBool forceJSEnabled,
PRUint32 postHeadersLength, const char* postHeaders)
{
return NS_OK;
}
nsresult nsPluginHostImpl :: Init(void)
{
return NS_OK;
nsresult rv;
rv = nsMalloc::Create(nsnull, kIMallocIID, (void **)&mMalloc);
return rv;
}
nsresult nsPluginHostImpl :: LoadPlugins(void)
@ -520,7 +552,7 @@ printf("plugin %s added to list %s\n", plugintag->mName, (plugintag->mFlags & NS
return NS_OK;
}
nsresult nsPluginHostImpl :: InstantiatePlugin(char *aMimeType, nsISupports ** aPluginInst)
nsresult nsPluginHostImpl :: InstantiatePlugin(char *aMimeType, nsIPluginInstance ** aPluginInst)
{
nsPluginTag *plugins = mPlugins;
PRInt32 variants, cnt;
@ -558,10 +590,32 @@ printf("loaded plugin %s for mime type %s\n", plugins->mName, aMimeType);
{
if (nsnull == plugins->mEntryPoint)
{
//create the plugin object
if (plugins->mFlags & NS_PLUGIN_FLAG_OLDSCHOOL)
plugins->mEntryPoint = PR_FindSymbol(plugins->mLibrary, "NP_Initialize");
{
nsresult rv = ns4xPlugin::CreatePlugin(plugins->mLibrary, (nsIPlugin **)&plugins->mEntryPoint);
printf("result of creating plugin adapter: %d\n", rv);
}
else
plugins->mEntryPoint = PR_FindSymbol(plugins->mLibrary, "NSGetFactory");
plugins->mEntryPoint = (nsIPlugin *)PR_FindSymbol(plugins->mLibrary, "NSGetFactory");
if (nsnull != plugins->mEntryPoint)
plugins->mEntryPoint->Initialize((nsISupports *)(nsIPluginManager *)this);
}
if (nsnull != plugins->mEntryPoint)
{
//create an instance
if (NS_OK == plugins->mEntryPoint->CreateInstance(nsnull, kIPluginInstanceIID, (void **)aPluginInst))
{
printf("successfully created plugin instance\n");
nsIPluginInstancePeer *peer = new nsPluginInstancePeerImpl();
(*aPluginInst)->Initialize(peer);
}
}
}
else

View File

@ -22,8 +22,10 @@
#include "xp_core.h"
#include "nsIPluginManager.h"
#include "nsIPluginHost.h"
#include "nsINetworkManager.h"
#include "nsCRT.h"
#include "prlink.h"
#include "nsIMalloc.h"
class ns4xPlugin;
@ -44,7 +46,7 @@ public:
char **mMimeDescriptionArray;
char **mExtensionsArray;
PRLibrary *mLibrary;
void *mEntryPoint;
nsIPlugin *mEntryPoint;
ns4xPlugin *mAdapter;
PRUint32 mFlags;
};
@ -52,7 +54,8 @@ public:
#define NS_PLUGIN_FLAG_ENABLED 0x0001 //is this plugin enabled?
#define NS_PLUGIN_FLAG_OLDSCHOOL 0x0002 //is this a pre-xpcom plugin?
class nsPluginHostImpl : public nsIPluginManager, public nsIPluginHost
class nsPluginHostImpl : public nsIPluginManager, public nsIPluginHost,
public nsINetworkManager
{
public:
nsPluginHostImpl();
@ -80,8 +83,20 @@ public:
NS_IMETHOD
SetValue(nsPluginManagerVariable variable, void *value);
// NS_IMETHOD
// FetchURL(nsISupports* peer, nsURLInfo* urlInfo);
//nsINetworkManager interface
NS_IMETHOD
GetURL(nsISupports* peer, const char* url, const char* target,
void* notifyData = NULL, const char* altHost = NULL,
const char* referrer = NULL, PRBool forceJSEnabled = PR_FALSE);
NS_IMETHOD
PostURL(nsISupports* peer, const char* url, const char* target,
PRUint32 postDataLen, const char* postData,
PRBool isFile = PR_FALSE, void* notifyData = NULL,
const char* altHost = NULL, const char* referrer = NULL,
PRBool forceJSEnabled = PR_FALSE,
PRUint32 postHeadersLength = 0, const char* postHeaders = NULL);
//nsIPluginHost interface
@ -92,11 +107,12 @@ public:
LoadPlugins(void);
NS_IMETHOD
InstantiatePlugin(char *aMimeType, nsISupports ** aPluginInst);
InstantiatePlugin(char *aMimeType, nsIPluginInstance ** aPluginInst);
private:
char *mPluginPath;
nsPluginTag *mPlugins;
nsIMalloc *mMalloc;
};
#endif

View File

@ -0,0 +1,103 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsPluginInstancePeer.h"
nsPluginInstancePeerImpl :: nsPluginInstancePeerImpl()
{
}
nsPluginInstancePeerImpl :: ~nsPluginInstancePeerImpl()
{
}
NS_IMPL_ADDREF(nsPluginInstancePeerImpl);
NS_IMPL_RELEASE(nsPluginInstancePeerImpl);
static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID);
static NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
nsresult nsPluginInstancePeerImpl :: QueryInterface(const nsIID& iid, void** instance)
{
if (instance == NULL)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIPluginInstancePeerIID))
{
*instance = (void *)(nsISupports *)(nsIPluginInstancePeer *)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kIPluginTagInfoIID))
{
*instance = (void *)(nsISupports *)(nsIPluginTagInfo *)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kISupportsIID))
{
*instance = (void *)(nsISupports *)(nsIPluginTagInfo *)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP nsPluginInstancePeerImpl :: GetValue(nsPluginInstancePeerVariable variable, void *value)
{
return NS_OK;
}
NS_IMETHODIMP nsPluginInstancePeerImpl :: SetValue(nsPluginInstancePeerVariable variable, void *value)
{
return NS_OK;
}
NS_IMETHODIMP nsPluginInstancePeerImpl :: GetMIMEType(nsMIMEType *result)
{
return NS_OK;
}
NS_IMETHODIMP nsPluginInstancePeerImpl :: GetMode(nsPluginMode *result)
{
return NS_OK;
}
NS_IMETHODIMP nsPluginInstancePeerImpl :: NewStream(nsMIMEType type, const char* target, nsIOutputStream* *result)
{
return NS_OK;
}
NS_IMETHODIMP nsPluginInstancePeerImpl :: ShowStatus(const char* message)
{
return NS_OK;
}
NS_IMETHODIMP nsPluginInstancePeerImpl :: GetAttributes(PRUint16& n, const char*const*& names, const char*const*& values)
{
return NS_OK;
}
NS_IMETHODIMP nsPluginInstancePeerImpl :: GetAttribute(const char* name, const char* *result)
{
return NS_OK;
}

View File

@ -0,0 +1,62 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsPluginInstancePeer_h___
#define nsPluginInstancePeer_h___
#include "nsIPluginInstancePeer.h"
#include "nsIPluginTagInfo.h"
class nsPluginInstancePeerImpl : public nsIPluginInstancePeer, public nsIPluginTagInfo
{
public:
nsPluginInstancePeerImpl();
~nsPluginInstancePeerImpl();
NS_DECL_ISUPPORTS
//nsIPluginInstancePeer interface
NS_IMETHOD
GetValue(nsPluginInstancePeerVariable variable, void *value);
NS_IMETHOD
SetValue(nsPluginInstancePeerVariable variable, void *value);
NS_IMETHOD
GetMIMEType(nsMIMEType *result);
NS_IMETHOD
GetMode(nsPluginMode *result);
NS_IMETHOD
NewStream(nsMIMEType type, const char* target, nsIOutputStream* *result);
NS_IMETHOD
ShowStatus(const char* message);
//nsIPluginTagInfo interface
NS_IMETHOD
GetAttributes(PRUint16& n, const char*const*& names, const char*const*& values);
NS_IMETHOD
GetAttribute(const char* name, const char* *result);
};
#endif

View File

@ -31,6 +31,9 @@ CPPSRCS = \
nsPluginHostImpl.cpp \
nsPluginFactory.cpp \
ns4xPlugin.cpp \
ns4xPluginInstance.cpp \
ns4xPluginStream.cpp \
nsPluginInstancePeer.cpp \
$(NULL)
REQUIRES = raptor plugin java xpcom

View File

@ -35,6 +35,9 @@ OBJS = \
.\$(OBJDIR)\nsPluginHostImpl.obj \
.\$(OBJDIR)\nsPluginFactory.obj \
.\$(OBJDIR)\ns4xPlugin.obj \
.\$(OBJDIR)\ns4xPluginInstance.obj \
.\$(OBJDIR)\ns4xPluginStream.obj \
.\$(OBJDIR)\nsPluginInstancePeer.obj \
$(NULL)
LINCS= \

View File

@ -21,7 +21,8 @@
#include "xp_core.h"
#include "nsplugin.h"
#include "ns4xPlugin.h"
//#include "ns4xPluginInstance.h"
#include "nsIPluginStream.h"
#include "ns4xPluginInstance.h"
////////////////////////////////////////////////////////////////////////
@ -34,7 +35,9 @@ typedef NPError (*NP_PLUGINSHUTDOWN)();
////////////////////////////////////////////////////////////////////////
NPNetscapeFuncs ns4xPlugin::CALLBACKS;
nsIPluginManager * ns4xPlugin::mManager;
nsIPluginManager * ns4xPlugin::mPluginManager;
nsINetworkManager * ns4xPlugin::mNetworkManager;
nsIMalloc * ns4xPlugin::mMalloc;
void
ns4xPlugin::CheckClassInitialized(void)
@ -44,7 +47,9 @@ ns4xPlugin::CheckClassInitialized(void)
if (initialized)
return;
mManager = nsnull;
mPluginManager = nsnull;
mNetworkManager = nsnull;
mMalloc = nsnull;
// XXX It'd be nice to make this const and initialize it
// statically...
@ -53,25 +58,25 @@ ns4xPlugin::CheckClassInitialized(void)
CALLBACKS.geturl = NewNPN_GetURLProc(_geturl);
CALLBACKS.posturl = NewNPN_PostURLProc(_posturl);
// CALLBACKS.requestread = NewNPN_RequestReadProc(_requestread);
// CALLBACKS.newstream = NewNPN_NewStreamProc(_newstream);
// CALLBACKS.write = NewNPN_WriteProc(_write);
// CALLBACKS.destroystream = NewNPN_DestroyStreamProc(_destroystream);
// CALLBACKS.status = NewNPN_StatusProc(_status);
// CALLBACKS.uagent = NewNPN_UserAgentProc(_useragent);
// CALLBACKS.memalloc = NewNPN_MemAllocProc(_memalloc);
// CALLBACKS.memfree = NewNPN_MemFreeProc(_memfree);
// CALLBACKS.memflush = NewNPN_MemFlushProc(_memflush);
// CALLBACKS.reloadplugins = NewNPN_ReloadPluginsProc(_reloadplugins);
// CALLBACKS.getJavaEnv = NewNPN_GetJavaEnvProc(_getJavaEnv);
CALLBACKS.requestread = NewNPN_RequestReadProc(_requestread);
CALLBACKS.newstream = NewNPN_NewStreamProc(_newstream);
CALLBACKS.write = NewNPN_WriteProc(_write);
CALLBACKS.destroystream = NewNPN_DestroyStreamProc(_destroystream);
CALLBACKS.status = NewNPN_StatusProc(_status);
CALLBACKS.uagent = NewNPN_UserAgentProc(_useragent);
CALLBACKS.memalloc = NewNPN_MemAllocProc(_memalloc);
CALLBACKS.memfree = NewNPN_MemFreeProc(_memfree);
CALLBACKS.memflush = NewNPN_MemFlushProc(_memflush);
CALLBACKS.reloadplugins = NewNPN_ReloadPluginsProc(_reloadplugins);
CALLBACKS.getJavaEnv = NewNPN_GetJavaEnvProc(_getJavaEnv);
// CALLBACKS.getJavaPeer = NewNPN_GetJavaPeerProc(_getJavaPeer);
CALLBACKS.geturlnotify = NewNPN_GetURLNotifyProc(_geturlnotify);
CALLBACKS.posturlnotify = NewNPN_PostURLNotifyProc(_posturlnotify);
// CALLBACKS.getvalue = NewNPN_GetValueProc(_getvalue);
// CALLBACKS.setvalue = NewNPN_SetValueProc(_setvalue);
// CALLBACKS.invalidaterect = NewNPN_InvalidateRectProc(_invalidaterect);
// CALLBACKS.invalidateregion = NewNPN_InvalidateRegionProc(_invalidateregion);
// CALLBACKS.forceredraw = NewNPN_ForceRedrawProc(_forceredraw);
CALLBACKS.getvalue = NewNPN_GetValueProc(_getvalue);
CALLBACKS.setvalue = NewNPN_SetValueProc(_setvalue);
CALLBACKS.invalidaterect = NewNPN_InvalidateRectProc(_invalidaterect);
CALLBACKS.invalidateregion = NewNPN_InvalidateRegionProc(_invalidateregion);
CALLBACKS.forceredraw = NewNPN_ForceRedrawProc(_forceredraw);
initialized = TRUE;
};
@ -83,13 +88,14 @@ ns4xPlugin::ns4xPlugin(NPPluginFuncs* callbacks)
{
NS_INIT_REFCNT();
memcpy((void*) &fCallbacks, (void*) callbacks, sizeof(fCallbacks));
mManager = nsnull;
}
ns4xPlugin::~ns4xPlugin(void)
{
NS_IF_RELEASE(mManager);
NS_IF_RELEASE(mPluginManager);
NS_IF_RELEASE(mNetworkManager);
NS_IF_RELEASE(mMalloc);
}
@ -102,6 +108,8 @@ NS_IMPL_RELEASE(ns4xPlugin);
static NS_DEFINE_IID(kILiveConnectPluginIID, NS_ILIVECONNECTPLUGIN_IID);
static NS_DEFINE_IID(kIPluginIID, NS_IPLUGIN_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIWindowlessPluginInstancePeerIID, NS_IWINDOWLESSPLUGININSTANCEPEER_IID);
static NS_DEFINE_IID(kISeekablePluginStreamPeerIID, NS_ISEEKABLEPLUGINSTREAMPEER_IID);
nsresult
ns4xPlugin::QueryInterface(const nsIID& iid, void** instance)
@ -109,20 +117,28 @@ ns4xPlugin::QueryInterface(const nsIID& iid, void** instance)
if (instance == NULL)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIPluginIID) ||
iid.Equals(kISupportsIID)) {
*instance = (void*) this;
if (iid.Equals(kIPluginIID))
{
*instance = (void *)(nsIPlugin *)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kILiveConnectPluginIID)) {
if (iid.Equals(kILiveConnectPluginIID))
{
// Check the 4.x plugin callbacks to see if it supports
// LiveConnect...
if (fCallbacks.javaClass == NULL)
return NS_NOINTERFACE;
*instance = (void*) this;
*instance = (void *)(nsILiveConnectPlugin *)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kISupportsIID))
{
*instance = (void *)(nsISupports *)this;
AddRef();
return NS_OK;
}
@ -200,7 +216,7 @@ nsresult ns4xPlugin :: CreateInstance(nsISupports *aOuter,
nsISupports *inst;
inst = nsnull;
// inst = (nsISupports *)(nsIPluginInstance *)new ns4xPluginInstance();
inst = (nsISupports *)(nsIPluginInstance *)new ns4xPluginInstance(&fCallbacks);
if (inst == NULL) {
return NS_ERROR_OUT_OF_MEMORY;
@ -223,20 +239,33 @@ nsresult ns4xPlugin :: LockFactory(PRBool aLock)
}
static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID);
static NS_DEFINE_IID(kINetworkManagerIID, NS_INETWORKMANAGER_IID);
static NS_DEFINE_IID(kIMallocIID, NS_IMALLOC_IID);
nsresult
ns4xPlugin::Initialize(nsISupports* browserInterfaces)
{
if (nsnull == mManager)
return browserInterfaces->QueryInterface(kIPluginManagerIID, (void **)&mManager);
else
return NS_OK;
nsresult rv = NS_OK;
if (nsnull == mPluginManager)
rv = browserInterfaces->QueryInterface(kIPluginManagerIID, (void **)&mPluginManager);
if (nsnull == mNetworkManager)
rv = browserInterfaces->QueryInterface(kINetworkManagerIID, (void **)&mNetworkManager);
if (nsnull == mMalloc)
rv = browserInterfaces->QueryInterface(kIMallocIID, (void **)&mMalloc);
return rv;
}
nsresult
ns4xPlugin::Shutdown(void)
{
NS_IF_RELEASE(mManager);
NS_IF_RELEASE(mPluginManager);
NS_IF_RELEASE(mNetworkManager);
NS_IF_RELEASE(mMalloc);
return NS_OK;
}
@ -262,7 +291,7 @@ ns4xPlugin::SetValue(nsPluginVariable variable, void *value)
nsresult
ns4xPlugin::GetJavaClass(jclass *resultingClass)
{
*resultingClass = fCallbacks.javaClass;
*resultingClass = (jclass)fCallbacks.javaClass;
return NS_OK;
}
@ -277,29 +306,12 @@ ns4xPlugin::_geturl(NPP npp, const char* relativeURL, const char* target)
nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata;
NS_ASSERTION(peer != NULL, "null peer");
NS_ASSERTION(mManager != NULL, "null manager");
NS_ASSERTION(mNetworkManager != NULL, "null manager");
if (peer == NULL)
return NS_ERROR_UNEXPECTED; // XXX
#if 0
nsURLInfo urlinfo;
urlinfo.version = nsURLInfo_Version;
urlinfo.url = relativeURL;
urlinfo.target = target;
urlinfo.notifyData = nsnull;
urlinfo.altHost = nsnull;
urlinfo.referrer = nsnull;
urlinfo.forceJSEnabled = PR_FALSE;
urlinfo.postData = nsnull;
urlinfo.postDataLength = 0;
urlinfo.postHeaders = nsnull;
urlinfo.postHeadersLength = 0;
urlinfo.postFile = PR_FALSE;
return mManager->FetchURL(peer, &urlinfo);
#endif
return NS_OK;
return mNetworkManager->GetURL(peer, relativeURL, target);
}
nsresult NP_EXPORT
@ -309,29 +321,13 @@ ns4xPlugin::_geturlnotify(NPP npp, const char* relativeURL, const char* target,
nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata;
NS_ASSERTION(peer != NULL, "null peer");
NS_ASSERTION(mManager != NULL, "null manager");
NS_ASSERTION(mNetworkManager != NULL, "null manager");
if (peer == NULL)
return NS_ERROR_UNEXPECTED; // XXX
#if 0
nsURLInfo urlinfo;
urlinfo.version = nsURLInfo_Version;
urlinfo.url = relativeURL;
urlinfo.target = target;
urlinfo.notifyData = notifyData;
urlinfo.altHost = nsnull;
urlinfo.referrer = nsnull;
urlinfo.forceJSEnabled = PR_FALSE;
urlinfo.postData = nsnull;
urlinfo.postDataLength = 0;
urlinfo.postHeaders = nsnull;
urlinfo.postHeadersLength = 0;
urlinfo.postFile = PR_FALSE;
return mManager->FetchURL(peer, &urlinfo);
#endif
return NS_OK;
return mNetworkManager->GetURL(peer, relativeURL, target,
notifyData);
}
@ -343,29 +339,13 @@ ns4xPlugin::_posturlnotify(NPP npp, const char* relativeURL, const char *target,
nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata;
NS_ASSERTION(peer != NULL, "null peer");
NS_ASSERTION(mManager != NULL, "null manager");
NS_ASSERTION(mNetworkManager != NULL, "null manager");
if (peer == NULL)
return NS_ERROR_UNEXPECTED; // XXX
#if 0
nsURLInfo urlinfo;
urlinfo.version = nsURLInfo_Version;
urlinfo.url = relativeURL;
urlinfo.target = target;
urlinfo.notifyData = notifyData;
urlinfo.altHost = nsnull;
urlinfo.referrer = nsnull;
urlinfo.forceJSEnabled = PR_FALSE;
urlinfo.postData = buf;
urlinfo.postDataLength = len;
urlinfo.postHeaders = nsnull;
urlinfo.postHeadersLength = 0;
urlinfo.postFile = file;
return mManager->FetchURL(peer, &urlinfo);
#endif
return NS_OK;
return mNetworkManager->PostURL(peer, relativeURL, target,
len, buf, file, notifyData);
}
@ -376,49 +356,32 @@ ns4xPlugin::_posturl(NPP npp, const char* relativeURL, const char *target, uint3
nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata;
NS_ASSERTION(peer != NULL, "null peer");
NS_ASSERTION(mManager != NULL, "null manager");
NS_ASSERTION(mNetworkManager != NULL, "null manager");
if (peer == NULL)
return NS_ERROR_UNEXPECTED; // XXX
#if 0
nsURLInfo urlinfo;
urlinfo.version = nsURLInfo_Version;
urlinfo.url = relativeURL;
urlinfo.target = target;
urlinfo.notifyData = nsnull;
urlinfo.altHost = nsnull;
urlinfo.referrer = nsnull;
urlinfo.forceJSEnabled = PR_FALSE;
urlinfo.postData = buf;
urlinfo.postDataLength = len;
urlinfo.postHeaders = nsnull;
urlinfo.postHeadersLength = 0;
urlinfo.postFile = file;
return mManager->FetchURL(peer, &urlinfo);
#endif
return NS_OK;
return mNetworkManager->PostURL(peer, relativeURL, target,
len, buf, file);
}
#if 0
////////////////////////////////////////////////////////////////////////
/**
* A little helper class used to wrap up plugin manager streams (that is,
* streams from the plugin to the browser).
*/
class ns4xStreamWrapper {
class ns4xStreamWrapper
{
protected:
NPIPluginManagerStream* fStream;
NPStream fNPStream;
nsIOutputStream *fStream;
NPStream fNPStream;
public:
ns4xStreamWrapper(NPIPluginManagerStream* stream);
ns4xStreamWrapper(nsIOutputStream* stream);
~ns4xStreamWrapper();
NPIPluginManagerStream*
nsIOutputStream*
GetStream(void);
NPStream*
@ -427,11 +390,12 @@ public:
};
};
ns4xStreamWrapper::ns4xStreamWrapper(NPIPluginManagerStream* stream)
ns4xStreamWrapper::ns4xStreamWrapper(nsIOutputStream* stream)
: fStream(stream)
{
PR_ASSERT(stream != NULL);
fStream->AddRef();
NS_ASSERTION(stream != NULL, "bad stream");
NS_ADDREF(fStream);
memset(&fNPStream, 0, sizeof(fNPStream));
fNPStream.ndata = (void*) this;
@ -439,15 +403,13 @@ ns4xStreamWrapper::ns4xStreamWrapper(NPIPluginManagerStream* stream)
ns4xStreamWrapper::~ns4xStreamWrapper(void)
{
if (fStream != NULL)
fStream->Release();
NS_IF_RELEASE(fStream);
}
NPIPluginManagerStream*
nsIOutputStream*
ns4xStreamWrapper::GetStream(void)
{
if (fStream != NULL)
fStream->AddRef();
NS_IF_ADDREF(fStream);
return fStream;
}
@ -466,194 +428,205 @@ ns4xPlugin::_newstream(NPP npp, NPMIMEType type, const char* window, NPStream* *
return NS_ERROR_UNEXPECTED; // XXX
nsresult error;
nsIPluginStream* stream;
nsIOutputStream* stream;
if ((error = peer->NewStream((const char*) type, window, &stream))
!= NPPluginError_NoError)
return (NPError) error;
!= NS_OK)
return error;
ns4xStreamWrapper* wrapper = new ns4xStreamWrapper(stream);
if (wrapper == NULL) {
stream->Release();
return NPERR_OUT_OF_MEMORY_ERROR;
if (wrapper == NULL)
{
NS_RELEASE(stream);
return NS_ERROR_OUT_OF_MEMORY;
}
(*result) = wrapper->GetNPStream();
return NPERR_NO_ERROR;
return NS_OK;
}
int32 NP_EXPORT
ns4xPlugin::_write(NPP npp, NPStream *pstream, int32 len, void *buffer)
{
ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) npp->ndata;
PR_ASSERT(wrapper != NULL);
NS_ASSERTION(wrapper != NULL, "null wrapper");
if (wrapper == NULL)
return 0;
NPIPluginManagerStream* stream = wrapper->GetStream();
PRUint32 count = 0;
while (count < ((PRUint32) len)) {
PRUint32 ready = stream->WriteReady();
ready = (ready > ((PRUint32) len)) ? ((PRUint32) len) : ready;
nsIOutputStream* stream = wrapper->GetStream();
PRUint32 written = stream->Write(ready, ((const char*) buffer) + count);
count += written;
}
PRInt32 count = 0;
nsresult rv = stream->Write((char *)buffer, 0, len, &count);
stream->Release();
NS_RELEASE(stream);
return count;
}
NPError NP_EXPORT
nsresult NP_EXPORT
ns4xPlugin::_destroystream(NPP npp, NPStream *pstream, NPError reason)
{
ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) npp->ndata;
PR_ASSERT(wrapper != NULL);
NS_ASSERTION(wrapper != NULL, "null wrapper");
if (wrapper == NULL)
return 0;
// This will release the wrapped NPIPluginManagerStream.
// This will release the wrapped nsIOutputStream.
delete wrapper;
return NPERR_NO_ERROR;
return NS_OK;
}
void NP_EXPORT
ns4xPlugin::_status(NPP npp, const char *message)
{
NPIPluginInstancePeer* peer = (NPIPluginInstancePeer*) npp->ndata;
PR_ASSERT(peer != NULL);
nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata;
NS_ASSERTION(peer != NULL, "null peer");
if (peer == NULL)
return;
peer->ShowStatus(message);
}
void NP_EXPORT
ns4xPlugin::_memfree (void *ptr)
{
thePluginManager->MemFree(ptr);
mMalloc->Free(ptr);
}
uint32 NP_EXPORT
ns4xPlugin::_memflush(uint32 size)
{
return thePluginManager->MemFlush(size);
mMalloc->HeapMinimize();
return 0;
}
void NP_EXPORT
ns4xPlugin::_reloadplugins(NPBool reloadPages)
{
thePluginManager->ReloadPlugins(reloadPages);
mPluginManager->ReloadPlugins(reloadPages);
}
void NP_EXPORT
ns4xPlugin::_invalidaterect(NPP npp, NPRect *invalidRect)
{
NPIPluginInstancePeer* peer = (NPIPluginInstancePeer*) npp->ndata;
PR_ASSERT(peer != NULL);
nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata;
NS_ASSERTION(peer != NULL, "null peer");
if (peer == NULL)
return;
// XXX nsRect & NPRect are structurally equivalent
peer->InvalidateRect((nsRect*) invalidRect);
nsIWindowlessPluginInstancePeer *wpeer;
if (NS_OK == peer->QueryInterface(kIWindowlessPluginInstancePeerIID, (void **)&wpeer))
{
// XXX nsRect & NPRect are structurally equivalent
wpeer->InvalidateRect((nsPluginRect *)invalidRect);
NS_RELEASE(wpeer);
}
}
void NP_EXPORT
ns4xPlugin::_invalidateregion(NPP npp, NPRegion invalidRegion)
{
NPIPluginInstancePeer* peer = (NPIPluginInstancePeer*) npp->ndata;
PR_ASSERT(peer != NULL);
nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata;
NS_ASSERTION(peer != NULL, "null peer");
if (peer == NULL)
return;
// XXX nsRegion & NPRegion are typedef'd to the same thing
peer->InvalidateRegion((nsRegion*) invalidRegion);
nsIWindowlessPluginInstancePeer *wpeer;
if (NS_OK == peer->QueryInterface(kIWindowlessPluginInstancePeerIID, (void **)&wpeer))
{
// XXX nsRegion & NPRegion are typedef'd to the same thing
wpeer->InvalidateRegion((nsPluginRegion*) invalidRegion);
NS_RELEASE(wpeer);
}
}
void NP_EXPORT
ns4xPlugin::_forceredraw(NPP npp)
{
NPIPluginInstancePeer* peer = (NPIPluginInstancePeer*) npp->ndata;
PR_ASSERT(peer != NULL);
nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata;
NS_ASSERTION(peer != NULL, "null peer");
if (peer == NULL)
return;
peer->ForceRedraw();
nsIWindowlessPluginInstancePeer *wpeer;
if (NS_OK == peer->QueryInterface(kIWindowlessPluginInstancePeerIID, (void **)&wpeer))
{
wpeer->ForceRedraw();
NS_RELEASE(wpeer);
}
}
NPError NP_EXPORT
nsresult NP_EXPORT
ns4xPlugin::_getvalue(NPP npp, NPNVariable variable, void *result)
{
NPIPluginInstancePeer* peer = (NPIPluginInstancePeer*) npp->ndata;
PR_ASSERT(peer != NULL);
nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata;
NS_ASSERTION(peer != NULL, "null peer");
if (peer == NULL)
return NPERR_INVALID_PLUGIN_ERROR; // XXX
return NS_ERROR_FAILURE; // XXX
// XXX Note that for backwards compatibility, the old NPNVariables
// map correctly to NPPluginManagerVariables.
return (NPError) peer->GetValue((NPPluginManagerVariable) variable, result);
return peer->GetValue((nsPluginInstancePeerVariable)variable, result);
}
NPError NP_EXPORT
nsresult NP_EXPORT
ns4xPlugin::_setvalue(NPP npp, NPPVariable variable, void *result)
{
NPIPluginInstancePeer* peer = (NPIPluginInstancePeer*) npp->ndata;
PR_ASSERT(peer != NULL);
nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata;
NS_ASSERTION(peer != NULL, "null peer");
if (peer == NULL)
return NPERR_INVALID_PLUGIN_ERROR; // XXX
return NS_ERROR_FAILURE; // XXX
// XXX Note that for backwards compatibility, the old NPPVariables
// map correctly to NPPluginVariables.
return (NPError) peer->SetValue((NPPluginVariable) variable, result);
return peer->SetValue((nsPluginInstancePeerVariable)variable, result);
}
NPError NP_EXPORT
nsresult NP_EXPORT
ns4xPlugin::_requestread(NPStream *pstream, NPByteRange *rangeList)
{
NPIPluginStreamPeer* streamPeer = (NPIPluginStreamPeer*) pstream->ndata;
PR_ASSERT(streamPeer != NULL);
if (streamPeer == NULL)
return NPERR_INVALID_PLUGIN_ERROR; // XXX
nsIPluginStreamPeer* streamPeer = (nsIPluginStreamPeer*) pstream->ndata;
NS_ASSERTION(streamPeer != NULL, "null streampeer");
if (streamPeer == NULL)
return NS_ERROR_FAILURE; // XXX
nsISeekablePluginStreamPeer* seekablePeer = NULL;
NPISeekablePluginStreamPeer* seekablePeer = NULL;
static NS_DEFINE_IID(kISeekablePluginStreamPeerIID, NP_ISEEKABLEPLUGINSTREAMPEER_IID);
if (streamPeer->QueryInterface(kISeekablePluginStreamPeerIID,
(void**) seekablePeer) == NS_OK) {
NPError error;
(void**)seekablePeer) == NS_OK)
{
nsresult error;
// XXX nsByteRange & NPByteRange are structurally equivalent.
error = (NPError) seekablePeer->RequestRead((nsByteRange*) rangeList);
seekablePeer->Release();
error = seekablePeer->RequestRead((nsByteRange *)rangeList);
NS_RELEASE(seekablePeer);
return error;
}
return NPERR_STREAM_NOT_SEEKABLE;
return NS_ERROR_UNEXPECTED;
}
@ -674,25 +647,28 @@ ns4xPlugin::_getJavaEnv(void)
return NULL;
}
const char * NP_EXPORT
ns4xPlugin::_useragent(NPP npp)
{
NPIPluginInstancePeer* peer = (NPIPluginInstancePeer*) npp->ndata;
PR_ASSERT(peer != NULL);
if (peer == NULL)
NS_ASSERTION(mPluginManager != NULL, "null pluginmanager");
if (mPluginManager == NULL)
return NULL;
return peer->UserAgent();
}
char *retstr;
mPluginManager->UserAgent((const char **)&retstr);
return retstr;
}
void * NP_EXPORT
ns4xPlugin::_memalloc (uint32 size)
{
return thePluginManager->MemAlloc(size);
return mMalloc->Alloc(size);
}
#if 0
#ifdef JAVA
java_lang_Class* NP_EXPORT
@ -727,11 +703,11 @@ ns4xPlugin::_getJavaPeer(NPP npp)
return NULL;
}
#endif
#if defined(XP_MAC) && !defined(powerc)
#pragma pointers_in_A0
#endif
//
////////////////////////////////////////////////////////////////////////
#endif

View File

@ -21,7 +21,8 @@
#include "nsplugin.h"
#include "prlink.h" // for PRLibrary
#include "../src/npupp.h"
#include "npupp.h"
#include "nsIMalloc.h"
////////////////////////////////////////////////////////////////////////
@ -128,8 +129,6 @@ protected:
_posturl(NPP npp, const char* relativeURL, const char *target, uint32 len,
const char *buf, NPBool file);
#if 0
static nsresult NP_EXPORT
_newstream(NPP npp, NPMIMEType type, const char* window, NPStream** pstream);
@ -142,6 +141,8 @@ protected:
static void NP_EXPORT
_status(NPP npp, const char *message);
#if 0
static void NP_EXPORT
_registerwindow(NPP npp, void* window);
@ -151,6 +152,8 @@ protected:
static int16 NP_EXPORT
_allocateMenuID(NPP npp, NPBool isSubmenu);
#endif
static void NP_EXPORT
_memfree (void *ptr);
@ -187,13 +190,15 @@ protected:
static JRIEnv* NP_EXPORT
_getJavaEnv(void);
#if 0
static jref NP_EXPORT
_getJavaPeer(NPP npp);
#if defined(XP_MAC) && !defined(powerc)
#pragma pointers_in_A0
#endif
#if defined(XP_MAC) && !defined(powerc)
#pragma pointers_in_A0
#endif
/**
@ -207,7 +212,9 @@ protected:
*/
static NPNetscapeFuncs CALLBACKS;
static nsIPluginManager *mManager;
static nsIPluginManager *mPluginManager;
static nsINetworkManager *mNetworkManager;
static nsIMalloc *mMalloc;
};
#endif // ns4xPlugin_h__

View File

@ -0,0 +1,239 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "ns4xPluginInstance.h"
#include "ns4xPluginStream.h"
#include "prlog.h"
////////////////////////////////////////////////////////////////////////
ns4xPluginInstance :: ns4xPluginInstance(NPPluginFuncs* callbacks)
: fCallbacks(callbacks)
{
NS_INIT_REFCNT();
NS_ASSERTION(fCallbacks != NULL, "null callbacks");
// Initialize the NPP structure.
fNPP.pdata = NULL;
fNPP.ndata = this;
fPeer = nsnull;
}
ns4xPluginInstance :: ~ns4xPluginInstance(void)
{
NS_RELEASE(fPeer);
}
////////////////////////////////////////////////////////////////////////
NS_IMPL_ADDREF(ns4xPluginInstance);
NS_IMPL_RELEASE(ns4xPluginInstance);
static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID);
static NS_DEFINE_IID(kIEventHandlerIID, NS_IEVENTHANDLER_IID);
static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
NS_IMETHODIMP ns4xPluginInstance :: QueryInterface(const nsIID& iid, void** instance)
{
if (instance == NULL)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIPluginInstanceIID))
{
*instance = (void *)(nsIPluginInstance *)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kIEventHandlerIID))
{
*instance = (void *)(nsIEventHandler *)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kISupportsIID))
{
*instance = (void *)(nsISupports *)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP ns4xPluginInstance :: Initialize(nsIPluginInstancePeer* peer)
{
PRUint16 count;
const char* const* names;
const char* const* values;
NS_ASSERTION(peer != NULL, "null peer");
fPeer = peer;
NS_ADDREF(fPeer);
nsresult error;
nsIPluginTagInfo *taginfo;
error = fPeer->QueryInterface(kIPluginTagInfoIID, (void **)&taginfo);
if (NS_OK == error)
{
if ((error = taginfo->GetAttributes(count, names, values)) != NS_OK)
return error;
if (fCallbacks->newp == NULL)
return NS_ERROR_FAILURE; // XXX right error?
// XXX Note that the NPPluginType_* enums were crafted to be
// backward compatible...
nsPluginMode mode;
nsMIMEType mimetype;
fPeer->GetMode(&mode);
fPeer->GetMIMEType(&mimetype);
error = (nsresult)
CallNPP_NewProc(fCallbacks->newp,
(char *)mimetype,
&fNPP,
(PRUint16)mode,
count,
(char**)names,
(char**)values,
NULL); // saved data
NS_RELEASE(taginfo);
}
return error;
}
NS_IMETHODIMP ns4xPluginInstance :: GetPeer(nsIPluginInstancePeer* *resultingPeer)
{
NS_ADDREF(fPeer);
*resultingPeer = fPeer;
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::Start(void)
{
// XXX At some point, we maybe should implement start and stop to
// load/unload the 4.x plugin, just in case there are some plugins
// that rely on that behavior...
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::Stop(void)
{
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::Destroy(void)
{
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::SetWindow(nsPluginWindow* window)
{
// XXX 4.x plugins don't want a SetWindow(NULL).
if (window == NULL)
return NS_OK;
nsresult error = NS_OK;
if (fCallbacks->setwindow) {
// XXX Turns out that NPPluginWindow and NPWindow are structurally
// identical (on purpose!), so there's no need to make a copy.
error = (nsresult) CallNPP_SetWindowProc(fCallbacks->setwindow,
&fNPP,
(NPWindow*) window);
// XXX In the old code, we'd just ignore any errors coming
// back from the plugin's SetWindow(). Is this the correct
// behavior?!?
NS_ASSERTION(error == NS_OK, "error in setwindow");
}
return error;
}
NS_IMETHODIMP ns4xPluginInstance::NewStream(nsIPluginStreamPeer* peer, nsIPluginStream* *result)
{
(*result) = NULL;
ns4xPluginStream* stream = new ns4xPluginStream();
if (stream == NULL)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(stream);
nsresult error;
// does it need the peer?
if ((error = stream->Initialize(this, peer)) != NS_OK)
{
NS_RELEASE(stream);
return error;
}
(*result) = stream;
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::Print(nsPluginPrint* platformPrint)
{
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::HandleEvent(nsPluginEvent* event, PRBool* handled)
{
*handled = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::URLNotify(const char* url, const char* target,
nsPluginReason reason, void* notifyData)
{
if (fCallbacks->urlnotify != NULL)
{
CallNPP_URLNotifyProc(fCallbacks->urlnotify,
&fNPP,
url,
reason,
notifyData);
}
return NS_OK; //XXX this seems bad...
}

View File

@ -0,0 +1,127 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef ns4xPluginInstance_h__
#define ns4xPluginInstance_h__
#include "nsplugin.h"
#include "npupp.h"
#include "jri.h"
////////////////////////////////////////////////////////////////////////
class ns4xPluginInstance : public nsIPluginInstance
{
public:
/**
* Construct a new 4.x plugin instance with the specified peer
* and callbacks.
*/
ns4xPluginInstance(NPPluginFuncs* callbacks);
// Use Release() to destroy this
~ns4xPluginInstance(void);
NS_DECL_ISUPPORTS
////////////////////////////////////////////////////////////////////////
// nsIPluginInstance methods
/**
* Actually initialize the plugin instance. This calls the 4.x <b>newp</b>
* callback, and may return an error (which is why it is distinct from the
* constructor.) If an error is returned, the caller should <i>not</i>
* continue to use the <b>ns4xPluginInstance</b> object.
*/
NS_METHOD
Initialize(nsIPluginInstancePeer* peer);
NS_IMETHOD
GetPeer(nsIPluginInstancePeer* *resultingPeer);
NS_IMETHOD
Start(void);
NS_IMETHOD
Stop(void);
NS_IMETHOD
Destroy(void);
NS_IMETHOD
SetWindow(nsPluginWindow* window);
NS_IMETHOD
NewStream(nsIPluginStreamPeer* peer, nsIPluginStream* *result);
NS_IMETHOD
Print(nsPluginPrint* platformPrint);
NS_IMETHOD
HandleEvent(nsPluginEvent* event, PRBool* handled);
NS_IMETHOD
URLNotify(const char* url, const char* target,
nsPluginReason reason, void* notifyData);
////////////////////////////////////////////////////////////////////////
// ns4xPluginInstance-specific methods
/**
* Return the 4.x-style interface object.
*/
NS_IMETHOD
GetNPP(NPP * aNPP) {
*aNPP = &fNPP;
return NS_OK;
};
/**
* Return the callbacks for the plugin instance.
*/
NS_IMETHOD
GetCallbacks(const NPPluginFuncs ** aCallbacks) {
*aCallbacks = fCallbacks;
return NS_OK;
};
protected:
/**
* The plugin instance peer for this instance.
*/
nsIPluginInstancePeer* fPeer;
/**
* A pointer to the plugin's callback functions. This information
* is actually stored in the plugin class (<b>nsPluginClass</b>),
* and is common for all plugins of the class.
*/
NPPluginFuncs* fCallbacks;
/**
* The 4.x-style structure used to communicate between the plugin
* instance and the browser.
*/
NPP_t fNPP;
};
#endif // ns4xPluginInstance_h__

View File

@ -0,0 +1,210 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "ns4xPluginStream.h"
#include "prlog.h" // for PR_ASSERT
////////////////////////////////////////////////////////////////////////
ns4xPluginStream::ns4xPluginStream(void)
: fStreamType(nsPluginStreamType_Normal), fSeekable(PR_FALSE), fPosition(0)
{
NS_INIT_REFCNT();
// Initialize the 4.x interface structure
memset(&fNPStream, 0, sizeof(fNPStream));
}
ns4xPluginStream::~ns4xPluginStream(void)
{
const NPPluginFuncs *callbacks;
NPP npp;
nsPluginReason reason;
fInstance->GetCallbacks(&callbacks);
fInstance->GetNPP(&npp);
fPeer->GetReason(&reason);
if (callbacks->destroystream != NULL)
{
CallNPP_DestroyStreamProc(callbacks->destroystream,
npp,
&fNPStream,
reason);
}
NS_IF_RELEASE(fPeer);
NS_IF_RELEASE(fInstance);
}
////////////////////////////////////////////////////////////////////////
NS_IMPL_ADDREF(ns4xPluginStream);
NS_IMPL_RELEASE(ns4xPluginStream);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIPluginStreamIID, NS_IPLUGINSTREAM_IID);
static NS_DEFINE_IID(kISeekablePluginStreamPeerIID, NS_ISEEKABLEPLUGINSTREAMPEER_IID);
NS_IMETHODIMP ns4xPluginStream::QueryInterface(const nsIID& iid, void** instance)
{
if (instance == NULL)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIPluginStreamIID))
{
*instance = (void *)(nsIPluginStream *)this;
AddRef();
return NS_OK;
}
else if (iid.Equals(kISupportsIID))
{
*instance = (void *)(nsISupports *)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP ns4xPluginStream::Initialize(ns4xPluginInstance* instance,
nsIPluginStreamPeer* peer)
{
fInstance = instance;
fPeer = peer;
NS_ASSERTION(fInstance != NULL, "null instance");
fInstance->AddRef();
NS_ASSERTION(fPeer != NULL, "null peer");
NS_ADDREF(fPeer);
const char *url;
PRUint32 length, modified;
fPeer->GetURL(&url);
fPeer->GetEnd(&length);
fPeer->GetLastModified(&modified);
fNPStream.ndata = (void*) fPeer;
fNPStream.url = url;
fNPStream.end = length;
fNPStream.lastmodified = modified;
// Are we seekable?
nsISupports* seekablePeer;
if (fPeer->QueryInterface(kISeekablePluginStreamPeerIID,
(void**) &seekablePeer) == NS_OK)
{
fSeekable = TRUE;
NS_RELEASE(seekablePeer);
}
const NPPluginFuncs *callbacks;
NPP npp;
nsMIMEType mimetype;
fInstance->GetCallbacks(&callbacks);
fInstance->GetNPP(&npp);
fPeer->GetMIMEType(&mimetype);
if (callbacks->newstream == NULL)
return NS_ERROR_FAILURE;
PRUint16 streamType = (PRUint16) fStreamType;
nsresult error
= (nsresult)CallNPP_NewStreamProc(callbacks->newstream,
npp,
(char *)mimetype,
&fNPStream,
fSeekable,
&streamType);
fStreamType = (nsPluginStreamType) streamType;
return error;
}
NS_IMETHODIMP ns4xPluginStream::Write(const char* buffer, PRInt32 offset, PRInt32 len, PRInt32 *aWriteCount)
{
const NPPluginFuncs *callbacks;
NPP npp;
fInstance->GetCallbacks(&callbacks);
fInstance->GetNPP(&npp);
if (callbacks->write == NULL)
return NS_OK;
*aWriteCount = CallNPP_WriteProc(callbacks->write,
npp,
&fNPStream,
fPosition,
len,
(void *)buffer);
fPosition += len;
return NS_OK; //XXX this seems bad...
}
NS_IMETHODIMP ns4xPluginStream::GetStreamType(nsPluginStreamType *result)
{
*result = fStreamType;
return NS_OK;
}
NS_IMETHODIMP ns4xPluginStream::AsFile(const char* filename)
{
const NPPluginFuncs *callbacks;
NPP npp;
fInstance->GetCallbacks(&callbacks);
fInstance->GetNPP(&npp);
if (callbacks->asfile == NULL)
return NS_OK;
CallNPP_StreamAsFileProc(callbacks->asfile,
npp,
&fNPStream,
filename);
return NS_OK;
}
NS_IMETHODIMP ns4xPluginStream :: Close(void)
{
return NS_OK;
}
////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,112 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef ns4xPluginStream_h__
#define ns4xPluginStream_h__
#include "jri.h" // XXX should be jni.h
#include "nsplugin.h"
#include "ns4xPluginInstance.h"
////////////////////////////////////////////////////////////////////////
/**
* A 5.0 wrapper for a 4.x plugin stream.
*/
class ns4xPluginStream : public nsIPluginStream
{
public:
/**
* Construct a new 4.x plugin stream associated with the specified
* instance and stream peer.
*/
ns4xPluginStream();
~ns4xPluginStream();
NS_DECL_ISUPPORTS
/**
* Do internal initialization. This actually calls into the 4.x plugin
* to create the stream, and may fail (which is why it's separate from
* the constructor).
*/
NS_METHOD
Initialize(ns4xPluginInstance* instance, nsIPluginStreamPeer* peer);
////////////////////////////////////////////////////////////////////////
// nsIPluginStream methods
// (Corresponds to NPP_Write and NPN_Write.)
NS_IMETHOD
Write(const char* buffer, PRInt32 offset, PRInt32 len, PRInt32 *aWriteCount);
// (Corresponds to NPP_NewStream's stype return parameter.)
NS_IMETHOD
GetStreamType(nsPluginStreamType *result);
// (Corresponds to NPP_StreamAsFile.)
NS_IMETHOD
AsFile(const char* fname);
NS_IMETHOD
Close(void);
////////////////////////////////////////////////////////////////////////
// Methods specific to ns4xPluginStream
protected:
/**
* The plugin instance to which this stream belongs.
*/
ns4xPluginInstance* fInstance;
/**
* The peer associated with this stream.
*/
nsIPluginStreamPeer* fPeer;
/**
* The type of stream, for the peer's use.
*/
nsPluginStreamType fStreamType;
/**
* The 4.x-style structure used to contain stream information.
* This is what actually gets used to communicate with the plugin.
*/
NPStream fNPStream;
/**
* Set to <b>TRUE</b> if the peer implements
* <b>NPISeekablPluginStreamPeer</b>.
*/
PRBool fSeekable;
/**
* Tracks the position in the content that is being
* read. 4.x-style plugins expect to be told the offset in the
* buffer that they should read <i>to</i>, even though it's always
* done serially.
*/
PRUint32 fPosition;
};
#endif // ns4xPluginStream_h__

View File

@ -36,7 +36,7 @@ public:
LoadPlugins(void) = 0;
NS_IMETHOD
InstantiatePlugin(char *aMimeType, nsISupports ** aPluginInst) = 0;
InstantiatePlugin(char *aMimeType, nsIPluginInstance ** aPluginInst) = 0;
};
#endif

View File

@ -21,11 +21,15 @@
#include "prio.h"
#include "prmem.h"
#include "ns4xPlugin.h"
#include "nsMalloc.h" //this is evil...
#include "nsPluginInstancePeer.h"
#ifdef XP_PC
#include "windows.h"
#endif
static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID);
nsPluginTag :: nsPluginTag()
{
mNext = nsnull;
@ -104,6 +108,7 @@ nsPluginTag :: ~nsPluginTag()
static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID);
static NS_DEFINE_IID(kIPluginHostIID, NS_IPLUGINHOST_IID);
static NS_DEFINE_IID(kIMallocIID, NS_IMALLOC_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
nsPluginHostImpl :: nsPluginHostImpl()
@ -124,6 +129,8 @@ nsPluginHostImpl :: ~nsPluginHostImpl()
delete mPlugins;
mPlugins = temp;
}
NS_IF_RELEASE(mMalloc);
}
NS_IMPL_ADDREF(nsPluginHostImpl)
@ -151,6 +158,13 @@ nsresult nsPluginHostImpl :: QueryInterface(const nsIID& aIID,
return NS_OK;
}
if (aIID.Equals(kIMallocIID))
{
*aInstancePtrResult = mMalloc;
NS_IF_ADDREF(mMalloc);
return NS_OK;
}
if (aIID.Equals(kISupportsIID))
{
*aInstancePtrResult = (void *)((nsISupports *)((nsIPluginHost *)this));
@ -183,14 +197,32 @@ nsresult nsPluginHostImpl :: SetValue(nsPluginManagerVariable variable, void *va
return NS_OK;
}
//nsresult nsPluginHostImpl :: FetchURL(nsISupports* peer, nsURLInfo* urlInfo)
//{
// return NS_OK;
//}
NS_IMETHODIMP nsPluginHostImpl :: GetURL(nsISupports* peer, const char* url,
const char* target,
void* notifyData, const char* altHost,
const char* referrer, PRBool forceJSEnabled)
{
return NS_OK;
}
NS_IMETHODIMP nsPluginHostImpl :: PostURL(nsISupports* peer,
const char* url, const char* target,
PRUint32 postDataLen, const char* postData,
PRBool isFile, void* notifyData,
const char* altHost, const char* referrer,
PRBool forceJSEnabled,
PRUint32 postHeadersLength, const char* postHeaders)
{
return NS_OK;
}
nsresult nsPluginHostImpl :: Init(void)
{
return NS_OK;
nsresult rv;
rv = nsMalloc::Create(nsnull, kIMallocIID, (void **)&mMalloc);
return rv;
}
nsresult nsPluginHostImpl :: LoadPlugins(void)
@ -520,7 +552,7 @@ printf("plugin %s added to list %s\n", plugintag->mName, (plugintag->mFlags & NS
return NS_OK;
}
nsresult nsPluginHostImpl :: InstantiatePlugin(char *aMimeType, nsISupports ** aPluginInst)
nsresult nsPluginHostImpl :: InstantiatePlugin(char *aMimeType, nsIPluginInstance ** aPluginInst)
{
nsPluginTag *plugins = mPlugins;
PRInt32 variants, cnt;
@ -558,10 +590,32 @@ printf("loaded plugin %s for mime type %s\n", plugins->mName, aMimeType);
{
if (nsnull == plugins->mEntryPoint)
{
//create the plugin object
if (plugins->mFlags & NS_PLUGIN_FLAG_OLDSCHOOL)
plugins->mEntryPoint = PR_FindSymbol(plugins->mLibrary, "NP_Initialize");
{
nsresult rv = ns4xPlugin::CreatePlugin(plugins->mLibrary, (nsIPlugin **)&plugins->mEntryPoint);
printf("result of creating plugin adapter: %d\n", rv);
}
else
plugins->mEntryPoint = PR_FindSymbol(plugins->mLibrary, "NSGetFactory");
plugins->mEntryPoint = (nsIPlugin *)PR_FindSymbol(plugins->mLibrary, "NSGetFactory");
if (nsnull != plugins->mEntryPoint)
plugins->mEntryPoint->Initialize((nsISupports *)(nsIPluginManager *)this);
}
if (nsnull != plugins->mEntryPoint)
{
//create an instance
if (NS_OK == plugins->mEntryPoint->CreateInstance(nsnull, kIPluginInstanceIID, (void **)aPluginInst))
{
printf("successfully created plugin instance\n");
nsIPluginInstancePeer *peer = new nsPluginInstancePeerImpl();
(*aPluginInst)->Initialize(peer);
}
}
}
else

View File

@ -22,8 +22,10 @@
#include "xp_core.h"
#include "nsIPluginManager.h"
#include "nsIPluginHost.h"
#include "nsINetworkManager.h"
#include "nsCRT.h"
#include "prlink.h"
#include "nsIMalloc.h"
class ns4xPlugin;
@ -44,7 +46,7 @@ public:
char **mMimeDescriptionArray;
char **mExtensionsArray;
PRLibrary *mLibrary;
void *mEntryPoint;
nsIPlugin *mEntryPoint;
ns4xPlugin *mAdapter;
PRUint32 mFlags;
};
@ -52,7 +54,8 @@ public:
#define NS_PLUGIN_FLAG_ENABLED 0x0001 //is this plugin enabled?
#define NS_PLUGIN_FLAG_OLDSCHOOL 0x0002 //is this a pre-xpcom plugin?
class nsPluginHostImpl : public nsIPluginManager, public nsIPluginHost
class nsPluginHostImpl : public nsIPluginManager, public nsIPluginHost,
public nsINetworkManager
{
public:
nsPluginHostImpl();
@ -80,8 +83,20 @@ public:
NS_IMETHOD
SetValue(nsPluginManagerVariable variable, void *value);
// NS_IMETHOD
// FetchURL(nsISupports* peer, nsURLInfo* urlInfo);
//nsINetworkManager interface
NS_IMETHOD
GetURL(nsISupports* peer, const char* url, const char* target,
void* notifyData = NULL, const char* altHost = NULL,
const char* referrer = NULL, PRBool forceJSEnabled = PR_FALSE);
NS_IMETHOD
PostURL(nsISupports* peer, const char* url, const char* target,
PRUint32 postDataLen, const char* postData,
PRBool isFile = PR_FALSE, void* notifyData = NULL,
const char* altHost = NULL, const char* referrer = NULL,
PRBool forceJSEnabled = PR_FALSE,
PRUint32 postHeadersLength = 0, const char* postHeaders = NULL);
//nsIPluginHost interface
@ -92,11 +107,12 @@ public:
LoadPlugins(void);
NS_IMETHOD
InstantiatePlugin(char *aMimeType, nsISupports ** aPluginInst);
InstantiatePlugin(char *aMimeType, nsIPluginInstance ** aPluginInst);
private:
char *mPluginPath;
nsPluginTag *mPlugins;
nsIMalloc *mMalloc;
};
#endif

View File

@ -0,0 +1,103 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsPluginInstancePeer.h"
nsPluginInstancePeerImpl :: nsPluginInstancePeerImpl()
{
}
nsPluginInstancePeerImpl :: ~nsPluginInstancePeerImpl()
{
}
NS_IMPL_ADDREF(nsPluginInstancePeerImpl);
NS_IMPL_RELEASE(nsPluginInstancePeerImpl);
static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID);
static NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
nsresult nsPluginInstancePeerImpl :: QueryInterface(const nsIID& iid, void** instance)
{
if (instance == NULL)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIPluginInstancePeerIID))
{
*instance = (void *)(nsISupports *)(nsIPluginInstancePeer *)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kIPluginTagInfoIID))
{
*instance = (void *)(nsISupports *)(nsIPluginTagInfo *)this;
AddRef();
return NS_OK;
}
if (iid.Equals(kISupportsIID))
{
*instance = (void *)(nsISupports *)(nsIPluginTagInfo *)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP nsPluginInstancePeerImpl :: GetValue(nsPluginInstancePeerVariable variable, void *value)
{
return NS_OK;
}
NS_IMETHODIMP nsPluginInstancePeerImpl :: SetValue(nsPluginInstancePeerVariable variable, void *value)
{
return NS_OK;
}
NS_IMETHODIMP nsPluginInstancePeerImpl :: GetMIMEType(nsMIMEType *result)
{
return NS_OK;
}
NS_IMETHODIMP nsPluginInstancePeerImpl :: GetMode(nsPluginMode *result)
{
return NS_OK;
}
NS_IMETHODIMP nsPluginInstancePeerImpl :: NewStream(nsMIMEType type, const char* target, nsIOutputStream* *result)
{
return NS_OK;
}
NS_IMETHODIMP nsPluginInstancePeerImpl :: ShowStatus(const char* message)
{
return NS_OK;
}
NS_IMETHODIMP nsPluginInstancePeerImpl :: GetAttributes(PRUint16& n, const char*const*& names, const char*const*& values)
{
return NS_OK;
}
NS_IMETHODIMP nsPluginInstancePeerImpl :: GetAttribute(const char* name, const char* *result)
{
return NS_OK;
}

View File

@ -0,0 +1,62 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsPluginInstancePeer_h___
#define nsPluginInstancePeer_h___
#include "nsIPluginInstancePeer.h"
#include "nsIPluginTagInfo.h"
class nsPluginInstancePeerImpl : public nsIPluginInstancePeer, public nsIPluginTagInfo
{
public:
nsPluginInstancePeerImpl();
~nsPluginInstancePeerImpl();
NS_DECL_ISUPPORTS
//nsIPluginInstancePeer interface
NS_IMETHOD
GetValue(nsPluginInstancePeerVariable variable, void *value);
NS_IMETHOD
SetValue(nsPluginInstancePeerVariable variable, void *value);
NS_IMETHOD
GetMIMEType(nsMIMEType *result);
NS_IMETHOD
GetMode(nsPluginMode *result);
NS_IMETHOD
NewStream(nsMIMEType type, const char* target, nsIOutputStream* *result);
NS_IMETHOD
ShowStatus(const char* message);
//nsIPluginTagInfo interface
NS_IMETHOD
GetAttributes(PRUint16& n, const char*const*& names, const char*const*& values);
NS_IMETHOD
GetAttribute(const char* name, const char* *result);
};
#endif