diff --git a/mozilla/modules/plugin/base/src/Makefile b/mozilla/modules/plugin/base/src/Makefile index 2ee5ad906fe..6f646653e67 100644 --- a/mozilla/modules/plugin/base/src/Makefile +++ b/mozilla/modules/plugin/base/src/Makefile @@ -37,7 +37,7 @@ CPPSRCS = \ nsPluginStreamPeer.cpp \ $(NULL) -REQUIRES = raptor plugin java xpcom +REQUIRES = raptor plugin java xpcom netlib LCFLAGS =-D_IMPL_NS_PLUGIN diff --git a/mozilla/modules/plugin/base/src/makefile.win b/mozilla/modules/plugin/base/src/makefile.win index 6de3c26fbf1..2d1f7a51e09 100644 --- a/mozilla/modules/plugin/base/src/makefile.win +++ b/mozilla/modules/plugin/base/src/makefile.win @@ -46,6 +46,7 @@ LINCS= \ -I$(PUBLIC)\xpcom \ -I$(PUBLIC)\plugin \ -I$(PUBLIC)\java \ + -I$(PUBLIC)\netlib \ $(NULL) @@ -57,6 +58,7 @@ LCFLAGS = \ OURLIBS= \ $(DIST)\lib\xpcom32.lib \ $(DIST)\lib\raptorbase.lib \ + $(DIST)\lib\netlib.lib \ $(LIBNSPR) LLIBS= \ diff --git a/mozilla/modules/plugin/base/src/ns4xPlugin.cpp b/mozilla/modules/plugin/base/src/ns4xPlugin.cpp index fc9bf695725..cb9ef64369e 100644 --- a/mozilla/modules/plugin/base/src/ns4xPlugin.cpp +++ b/mozilla/modules/plugin/base/src/ns4xPlugin.cpp @@ -303,30 +303,30 @@ ns4xPlugin::GetJavaClass(jclass *resultingClass) nsresult NP_EXPORT ns4xPlugin::_geturl(NPP npp, const char* relativeURL, const char* target) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); NS_ASSERTION(mNetworkManager != NULL, "null manager"); - if (peer == NULL) + if (inst == NULL) return NS_ERROR_UNEXPECTED; // XXX - return mNetworkManager->GetURL(peer, relativeURL, target); + return mNetworkManager->GetURL(inst, relativeURL, target); } nsresult NP_EXPORT ns4xPlugin::_geturlnotify(NPP npp, const char* relativeURL, const char* target, void* notifyData) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); NS_ASSERTION(mNetworkManager != NULL, "null manager"); - if (peer == NULL) + if (inst == NULL) return NS_ERROR_UNEXPECTED; // XXX - return mNetworkManager->GetURL(peer, relativeURL, target, + return mNetworkManager->GetURL(inst, relativeURL, target, notifyData); } @@ -336,15 +336,15 @@ ns4xPlugin::_posturlnotify(NPP npp, const char* relativeURL, const char *target, uint32 len, const char *buf, NPBool file, void* notifyData) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); NS_ASSERTION(mNetworkManager != NULL, "null manager"); - if (peer == NULL) + if (inst == NULL) return NS_ERROR_UNEXPECTED; // XXX - return mNetworkManager->PostURL(peer, relativeURL, target, + return mNetworkManager->PostURL(inst, relativeURL, target, len, buf, file, notifyData); } @@ -353,15 +353,15 @@ nsresult NP_EXPORT ns4xPlugin::_posturl(NPP npp, const char* relativeURL, const char *target, uint32 len, const char *buf, NPBool file) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); NS_ASSERTION(mNetworkManager != NULL, "null manager"); - if (peer == NULL) + if (inst == NULL) return NS_ERROR_UNEXPECTED; // XXX - return mNetworkManager->PostURL(peer, relativeURL, target, + return mNetworkManager->PostURL(inst, relativeURL, target, len, buf, file); } @@ -420,29 +420,42 @@ ns4xStreamWrapper::GetStream(void) nsresult NP_EXPORT ns4xPlugin::_newstream(NPP npp, NPMIMEType type, const char* window, NPStream* *result) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); - if (peer == NULL) + if (inst == NULL) return NS_ERROR_UNEXPECTED; // XXX nsresult error; nsIOutputStream* stream; - if ((error = peer->NewStream((const char*) type, window, &stream)) - != NS_OK) - return error; + nsIPluginInstancePeer *peer; - ns4xStreamWrapper* wrapper = new ns4xStreamWrapper(stream); - - if (wrapper == NULL) + if (NS_OK == inst->GetPeer(&peer)) { + if ((error = peer->NewStream((const char*) type, window, &stream)) != NS_OK) + { + NS_RELEASE(peer); + return error; + } + + ns4xStreamWrapper* wrapper = new ns4xStreamWrapper(stream); + + if (wrapper == NULL) + { + NS_RELEASE(peer); NS_RELEASE(stream); return NS_ERROR_OUT_OF_MEMORY; - } + } - (*result) = wrapper->GetNPStream(); - return NS_OK; + (*result) = wrapper->GetNPStream(); + + NS_RELEASE(peer); + + return error; + } + else + return NS_ERROR_UNEXPECTED; } int32 NP_EXPORT @@ -484,14 +497,20 @@ ns4xPlugin::_destroystream(NPP npp, NPStream *pstream, NPError reason) void NP_EXPORT ns4xPlugin::_status(NPP npp, const char *message) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); - if (peer == NULL) + if (inst == NULL) return; - peer->ShowStatus(message); + nsIPluginInstancePeer *peer; + + if (NS_OK == inst->GetPeer(&peer)) + { + peer->ShowStatus(message); + NS_RELEASE(peer); + } } void NP_EXPORT @@ -517,90 +536,130 @@ ns4xPlugin::_reloadplugins(NPBool reloadPages) void NP_EXPORT ns4xPlugin::_invalidaterect(NPP npp, NPRect *invalidRect) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); - if (peer == NULL) + if (inst == NULL) return; + nsIPluginInstancePeer *peer; nsIWindowlessPluginInstancePeer *wpeer; - if (NS_OK == peer->QueryInterface(kIWindowlessPluginInstancePeerIID, (void **)&wpeer)) + if (NS_OK == inst->GetPeer(&peer)) { - // XXX nsRect & NPRect are structurally equivalent - wpeer->InvalidateRect((nsPluginRect *)invalidRect); - NS_RELEASE(wpeer); + if (NS_OK == peer->QueryInterface(kIWindowlessPluginInstancePeerIID, (void **)&wpeer)) + { + // XXX nsRect & NPRect are structurally equivalent + wpeer->InvalidateRect((nsPluginRect *)invalidRect); + NS_RELEASE(wpeer); + } + + NS_RELEASE(peer); } } void NP_EXPORT ns4xPlugin::_invalidateregion(NPP npp, NPRegion invalidRegion) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); - if (peer == NULL) + if (inst == NULL) return; + nsIPluginInstancePeer *peer; nsIWindowlessPluginInstancePeer *wpeer; - if (NS_OK == peer->QueryInterface(kIWindowlessPluginInstancePeerIID, (void **)&wpeer)) + if (NS_OK == inst->GetPeer(&peer)) { - // XXX nsRegion & NPRegion are typedef'd to the same thing - wpeer->InvalidateRegion((nsPluginRegion)invalidRegion); - NS_RELEASE(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); + } + + NS_RELEASE(peer); } } void NP_EXPORT ns4xPlugin::_forceredraw(NPP npp) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); - if (peer == NULL) + if (inst == NULL) return; + nsIPluginInstancePeer *peer; nsIWindowlessPluginInstancePeer *wpeer; - if (NS_OK == peer->QueryInterface(kIWindowlessPluginInstancePeerIID, (void **)&wpeer)) + if (NS_OK == inst->GetPeer(&peer)) { - wpeer->ForceRedraw(); - NS_RELEASE(wpeer); + if (NS_OK == peer->QueryInterface(kIWindowlessPluginInstancePeerIID, (void **)&wpeer)) + { + wpeer->ForceRedraw(); + NS_RELEASE(wpeer); + } + + NS_RELEASE(peer); } } nsresult NP_EXPORT ns4xPlugin::_getvalue(NPP npp, NPNVariable variable, void *result) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); - if (peer == NULL) + if (inst == NULL) return NS_ERROR_FAILURE; // XXX - // XXX Note that for backwards compatibility, the old NPNVariables - // map correctly to NPPluginManagerVariables. - return peer->GetValue((nsPluginInstancePeerVariable)variable, result); + nsIPluginInstancePeer *peer; + + if (NS_OK == inst->GetPeer(&peer)) + { + nsresult rv; + + // XXX Note that for backwards compatibility, the old NPNVariables + // map correctly to NPPluginManagerVariables. + rv = peer->GetValue((nsPluginInstancePeerVariable)variable, result); + NS_RELEASE(peer); + return rv; + } + else + return NS_ERROR_UNEXPECTED; } nsresult NP_EXPORT ns4xPlugin::_setvalue(NPP npp, NPPVariable variable, void *result) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); - if (peer == NULL) + if (inst == NULL) return NS_ERROR_FAILURE; // XXX - // XXX Note that for backwards compatibility, the old NPPVariables - // map correctly to NPPluginVariables. - return peer->SetValue((nsPluginInstancePeerVariable)variable, result); + nsIPluginInstancePeer *peer; + + if (NS_OK == inst->GetPeer(&peer)) + { + nsresult rv; + + // XXX Note that for backwards compatibility, the old NPPVariables + // map correctly to NPPluginVariables. + rv = peer->SetValue((nsPluginInstancePeerVariable)variable, result); + NS_RELEASE(peer); + return rv; + } + else + return NS_ERROR_UNEXPECTED; } nsresult NP_EXPORT diff --git a/mozilla/modules/plugin/base/src/ns4xPluginInstance.cpp b/mozilla/modules/plugin/base/src/ns4xPluginInstance.cpp index 2c262607097..d01e5bfe0d9 100644 --- a/mozilla/modules/plugin/base/src/ns4xPluginInstance.cpp +++ b/mozilla/modules/plugin/base/src/ns4xPluginInstance.cpp @@ -183,7 +183,8 @@ NS_IMETHODIMP ns4xPluginInstance::SetWindow(nsPluginWindow* window) // back from the plugin's SetWindow(). Is this the correct // behavior?!? - NS_ASSERTION(error == NS_OK, "error in setwindow"); + if (error != NS_OK) + printf("error in setwindow %d\n", error); } return error; diff --git a/mozilla/modules/plugin/base/src/ns4xPluginStream.cpp b/mozilla/modules/plugin/base/src/ns4xPluginStream.cpp index 8fbac3b5e44..434a662e62a 100644 --- a/mozilla/modules/plugin/base/src/ns4xPluginStream.cpp +++ b/mozilla/modules/plugin/base/src/ns4xPluginStream.cpp @@ -203,7 +203,45 @@ NS_IMETHODIMP ns4xPluginStream::AsFile(const char* filename) NS_IMETHODIMP ns4xPluginStream :: Close(void) { - return NS_OK; + const NPPluginFuncs *callbacks; + NPP npp; + nsresult rv; + void *notifydata; + + fInstance->GetCallbacks(&callbacks); + fInstance->GetNPP(&npp); + + fPeer->GetNotifyData(¬ifydata); + + nsPluginReason reason; + + fPeer->GetReason(&reason); + + if (nsnull != notifydata) + { + if (callbacks->urlnotify == NULL) + return NS_OK; + + const char *url; + + fPeer->GetURL(&url); + + CallNPP_URLNotifyProc(callbacks->urlnotify, + npp, + url, + (NPReason)reason, + notifydata); + } + + if (callbacks->destroystream == NULL) + return NS_OK; + + rv = (nsresult)CallNPP_DestroyStreamProc(callbacks->destroystream, + npp, + &fNPStream, + (NPReason)reason); + + return rv; } //////////////////////////////////////////////////////////////////////// diff --git a/mozilla/modules/plugin/base/src/nsIPluginHost.h b/mozilla/modules/plugin/base/src/nsIPluginHost.h index 7b503f27adf..650bf516da1 100644 --- a/mozilla/modules/plugin/base/src/nsIPluginHost.h +++ b/mozilla/modules/plugin/base/src/nsIPluginHost.h @@ -22,6 +22,7 @@ #include "xp_core.h" #include "nsplugindefs.h" #include "nsIFactory.h" +#include "nsString.h" #define NS_IPLUGINHOST_IID \ { 0x264c0640, 0x1c31, 0x11d2, \ @@ -38,7 +39,17 @@ public: LoadPlugins(void) = 0; NS_IMETHOD - InstantiatePlugin(char *aMimeType, nsIPluginInstance ** aPluginInst) = 0; + InstantiatePlugin(const char *aMimeType, nsIPluginInstance ** aPluginInst) = 0; + + NS_IMETHOD + InstantiatePlugin(const char *aMimeType, nsIPluginInstance ** aPluginInst, + nsPluginWindow *aWindow, nsString& aURL) = 0; + + NS_IMETHOD + NewPluginStream(const nsString& aURL, nsIPluginInstance *aInstance, void *aNotifyData) = 0; + + NS_IMETHOD + NewPluginStream(const nsString& aURL, nsIPluginInstance **aInstance, nsPluginWindow *aWindow) = 0; }; #endif diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp index 53b068e43fa..7238f1ec5d2 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -24,12 +24,25 @@ #include "nsMalloc.h" //this is evil... #include "nsPluginInstancePeer.h" #include "nsPluginStreamPeer.h" +#include "nsIStreamListener.h" +#include "nsIURL.h" +#include "nsIInputStream.h" #ifdef XP_PC #include "windows.h" #endif static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID); +static NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID); +static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID); +static NS_DEFINE_IID(kINetworkManagerIID, NS_INETWORKMANAGER_IID); +static NS_DEFINE_IID(kIPluginHostIID, NS_IPLUGINHOST_IID); +static NS_DEFINE_IID(kIPluginStreamPeerIID, NS_IPLUGINSTREAMPEER_IID); +static NS_DEFINE_IID(kIMallocIID, NS_IMALLOC_IID); +static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID); +static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID); nsPluginTag :: nsPluginTag() { @@ -107,12 +120,254 @@ nsPluginTag :: ~nsPluginTag() mEntryPoint = nsnull; } -static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID); -static NS_DEFINE_IID(kIPluginHostIID, NS_IPLUGINHOST_IID); -static NS_DEFINE_IID(kIPluginStreamPeerIID, NS_IPLUGINSTREAMPEER_IID); -static NS_DEFINE_IID(kIMallocIID, NS_IMALLOC_IID); -static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +class nsPluginStreamListener : public nsIStreamListener +{ +public: + nsPluginStreamListener(); + ~nsPluginStreamListener(); + + NS_DECL_ISUPPORTS + + //nsIStreamObserver interface + + NS_IMETHOD OnStartBinding(nsIURL* aURL, const char *aContentType); + + NS_IMETHOD OnProgress(nsIURL* aURL, PRInt32 aProgress, PRInt32 aProgressMax); + + NS_IMETHOD OnStatus(nsIURL* aURL, const nsString &aMsg); + + NS_IMETHOD OnStopBinding(nsIURL* aURL, PRInt32 aStatus, const nsString &aMsg); + + //nsIStreamListener interface + + NS_IMETHOD GetBindInfo(nsIURL* aURL); + + NS_IMETHOD OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream, + PRInt32 aLength); + + //locals + + nsresult Initialize(nsIURL *aURL, nsIPluginInstance *aInstance, void *aNotifyData); + nsresult Initialize(nsIURL *aURL, nsIPluginInstance **aInstance, + nsPluginWindow *aWindow, nsIPluginHost *aHost); + +private: + nsIURL *mURL; + nsPluginStreamPeer *mPeer; + nsIPluginInstance *mInstance; + nsIPluginInstance **mFarInstance; + PRBool mBound; + nsIPluginStream *mStream; + char *mMIMEType; + PRUint8 *mBuffer; + PRUint32 mBufSize; + void *mNotifyData; + nsPluginWindow *mWindow; + nsIPluginHost *mHost; +}; + +nsPluginStreamListener :: nsPluginStreamListener() +{ + mURL = nsnull; + mPeer = nsnull; + mInstance = nsnull; + mFarInstance = nsnull; + mBound = PR_FALSE; + mStream = nsnull; + mMIMEType = nsnull; + mBuffer = nsnull; + mBufSize = 0; + mNotifyData = nsnull; + mWindow = nsnull; + mHost = nsnull; +} + +nsPluginStreamListener :: ~nsPluginStreamListener() +{ + NS_IF_RELEASE(mURL); + NS_IF_RELEASE(mPeer); + NS_IF_RELEASE(mInstance); + NS_IF_RELEASE(mStream); + + if (nsnull != mMIMEType) + { + PR_Free(mMIMEType); + mMIMEType = nsnull; + } + + if (nsnull != mBuffer) + { + PR_Free(mBuffer); + mBuffer = nsnull; + } + + mNotifyData = nsnull; + mWindow = nsnull; + mFarInstance = nsnull; + + NS_IF_RELEASE(mHost); +} + +NS_IMPL_ADDREF(nsPluginStreamListener) +NS_IMPL_RELEASE(nsPluginStreamListener) + +nsresult nsPluginStreamListener :: QueryInterface(const nsIID& aIID, + void** aInstancePtrResult) +{ + NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer"); + + if (nsnull == aInstancePtrResult) + return NS_ERROR_NULL_POINTER; + + if (aIID.Equals(kIStreamListenerIID)) + { + *aInstancePtrResult = (void *)((nsIStreamListener *)this); + AddRef(); + return NS_OK; + } + + if (aIID.Equals(kIStreamObserverIID)) + { + *aInstancePtrResult = (void *)((nsIStreamObserver *)this); + AddRef(); + return NS_OK; + } + + if (aIID.Equals(kISupportsIID)) + { + *aInstancePtrResult = (void *)((nsISupports *)((nsIStreamListener *)this)); + AddRef(); + return NS_OK; + } + + return NS_NOINTERFACE; +} + +nsresult nsPluginStreamListener :: Initialize(nsIURL *aURL, nsIPluginInstance *aInstance, void *aNotifyData) +{ + mURL = aURL; + NS_ADDREF(mURL); + + mInstance = aInstance; + NS_ADDREF(mInstance); + + mNotifyData = aNotifyData; + + return NS_OK; +} + +nsresult nsPluginStreamListener :: Initialize(nsIURL *aURL, nsIPluginInstance **aInstance, + nsPluginWindow *aWindow, nsIPluginHost *aHost) +{ + mURL = aURL; + NS_ADDREF(mURL); + + mFarInstance = aInstance; + + mWindow = aWindow; + + mHost = aHost; + NS_IF_ADDREF(mHost); + + return NS_OK; +} + +NS_IMETHODIMP nsPluginStreamListener :: OnStartBinding(nsIURL* aURL, const char *aContentType) +{ + nsresult rv = NS_OK; + + if (nsnull != aContentType) + { + PRInt32 len = strlen(aContentType); + mMIMEType = (char *)PR_Malloc(len + 1); + + if (nsnull != mMIMEType) + strcpy(mMIMEType, aContentType); + else + rv = NS_ERROR_OUT_OF_MEMORY; + } + + //now that we have the mime type, see if we need + //to load a plugin... + + if ((nsnull == mInstance) && (nsnull != mFarInstance) && + (nsnull != mHost) && (nsnull != mWindow) && (nsnull != mMIMEType)) + { + rv = mHost->InstantiatePlugin(mMIMEType, mFarInstance); + + if (NS_OK == rv) + { + mInstance = *mFarInstance; + NS_ADDREF(mInstance); + + (*mFarInstance)->Start(); + (*mFarInstance)->SetWindow(mWindow); + } + } + + mBound = PR_TRUE; + + return rv; +} + +NS_IMETHODIMP nsPluginStreamListener :: OnProgress(nsIURL* aURL, PRInt32 aProgress, PRInt32 aProgressMax) +{ + NS_ASSERTION(!(mBound == PR_FALSE), "ack, got progress without start binding"); + + if ((PR_TRUE == mBound) && (nsnull == mPeer)) + { + //need to create new peer and and tell plugin that we have new stream... + + mPeer = (nsPluginStreamPeer *)new nsPluginStreamPeer(); + + NS_ADDREF(mPeer); + + mPeer->Initialize(aURL, aProgressMax, 0, mMIMEType, mNotifyData); + mInstance->NewStream(mPeer, &mStream); + } + + return NS_OK; +} + +NS_IMETHODIMP nsPluginStreamListener :: OnStatus(nsIURL* aURL, const nsString &aMsg) +{ + return NS_OK; +} + +NS_IMETHODIMP nsPluginStreamListener :: OnStopBinding(nsIURL* aURL, PRInt32 aStatus, const nsString &aMsg) +{ + if (nsnull != mStream) + mStream->Close(); + + return NS_OK; +} + +NS_IMETHODIMP nsPluginStreamListener :: GetBindInfo(nsIURL* aURL) +{ + return NS_OK; +} + +NS_IMETHODIMP nsPluginStreamListener :: OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream, + PRInt32 aLength) +{ + if ((PRUint32)aLength > mBufSize) + { + if (nsnull != mBuffer) + PR_Free((void *)mBuffer); + + mBuffer = (PRUint8 *)PR_Malloc(aLength); + mBufSize = aLength; + } + + if ((nsnull != mBuffer) && (nsnull != mStream)) + { + PRInt32 readlen; + aIStream->Read((char *)mBuffer, 0, aLength, &readlen); + mStream->Write((char *)mBuffer, 0, aLength, &readlen); + } + + return NS_OK; +} nsPluginHostImpl :: nsPluginHostImpl() { @@ -161,6 +416,13 @@ nsresult nsPluginHostImpl :: QueryInterface(const nsIID& aIID, return NS_OK; } + if (aIID.Equals(kINetworkManagerIID)) + { + *aInstancePtrResult = (void *)((nsINetworkManager *)this); + AddRef(); + return NS_OK; + } + if (aIID.Equals(kIFactoryIID)) { *aInstancePtrResult = (void *)((nsIFactory *)this); @@ -212,7 +474,19 @@ NS_IMETHODIMP nsPluginHostImpl :: GetURL(nsISupports* peer, const char* url, void* notifyData, const char* altHost, const char* referrer, PRBool forceJSEnabled) { - return NS_OK; + nsAutoString string = nsAutoString(url); + nsIPluginInstance *inst; + nsresult rv; + + rv = peer->QueryInterface(kIPluginInstanceIID, (void **)&inst); + + if (NS_OK == rv) + { + NewPluginStream(string, inst, notifyData); + NS_RELEASE(inst); + } + + return rv; } NS_IMETHODIMP nsPluginHostImpl :: PostURL(nsISupports* peer, @@ -562,7 +836,7 @@ printf("plugin %s added to list %s\n", plugintag->mName, (plugintag->mFlags & NS return NS_OK; } -nsresult nsPluginHostImpl :: InstantiatePlugin(char *aMimeType, nsIPluginInstance ** aPluginInst) +nsresult nsPluginHostImpl :: InstantiatePlugin(const char *aMimeType, nsIPluginInstance ** aPluginInst) { nsPluginTag *plugins = mPlugins; PRInt32 variants, cnt; @@ -622,8 +896,9 @@ printf("result of creating plugin adapter: %d\n", rv); { printf("successfully created plugin instance\n"); - nsIPluginInstancePeer *peer = new nsPluginInstancePeerImpl(); + nsPluginInstancePeerImpl *peer = new nsPluginInstancePeerImpl(); + peer->Initialize(*aPluginInst); //this will not add a ref to the instance. MMP (*aPluginInst)->Initialize(peer); } } @@ -641,6 +916,65 @@ printf("unable to find plugin to handle %s\n", aMimeType); } } +nsresult nsPluginHostImpl :: InstantiatePlugin(const char *aMimeType, nsIPluginInstance ** aPluginInst, + nsPluginWindow *aWindow, nsString& aURL) +{ + nsresult rv; + + if (nsnull == aMimeType) + { + if (aURL.Length() > 0) + { + //we need to stream in enough to get the mime type... + + rv = NewPluginStream(aURL, aPluginInst, aWindow); + } + else + rv = NS_ERROR_FAILURE; + } + else + { + rv = InstantiatePlugin(aMimeType, aPluginInst); + + if (NS_OK == rv) + { + (*aPluginInst)->Start(); + (*aPluginInst)->SetWindow(aWindow); + NewPluginStream(aURL, *aPluginInst, nsnull); + } + } + + return rv; +} + +NS_IMETHODIMP nsPluginHostImpl :: NewPluginStream(const nsString& aURL, nsIPluginInstance *aInstance, void *aNotifyData) +{ + nsIURL *mURL; + nsPluginStreamListener *mListener = (nsPluginStreamListener *)new nsPluginStreamListener(); + + if (NS_OK == NS_NewURL(&mURL, aURL)) + { + mListener->Initialize(mURL, aInstance, aNotifyData); + mURL->Open(mListener); + } + + return NS_OK; +} + +NS_IMETHODIMP nsPluginHostImpl :: NewPluginStream(const nsString& aURL, nsIPluginInstance **aInstance, nsPluginWindow *aWindow) +{ + nsIURL *mURL; + nsPluginStreamListener *mListener = (nsPluginStreamListener *)new nsPluginStreamListener(); + + if (NS_OK == NS_NewURL(&mURL, aURL)) + { + mListener->Initialize(mURL, aInstance, aWindow, (nsIPluginHost *)this); + mURL->Open(mListener); + } + + return NS_OK; +} + nsresult nsPluginHostImpl :: CreateInstance(nsISupports *aOuter, const nsIID &aIID, void **aResult) diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.h b/mozilla/modules/plugin/base/src/nsPluginHostImpl.h index ee14d3a33f4..71d5d99d00c 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.h +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.h @@ -107,7 +107,17 @@ public: LoadPlugins(void); NS_IMETHOD - InstantiatePlugin(char *aMimeType, nsIPluginInstance ** aPluginInst); + InstantiatePlugin(const char *aMimeType, nsIPluginInstance ** aPluginInst); + + NS_IMETHOD + InstantiatePlugin(const char *aMimeType, nsIPluginInstance ** aPluginInst, + nsPluginWindow *aWindow, nsString& aURL); + + NS_IMETHOD + NewPluginStream(const nsString& aURL, nsIPluginInstance *aInstance, void *aNotifyData); + + NS_IMETHOD + NewPluginStream(const nsString& aURL, nsIPluginInstance **aInstance, nsPluginWindow *aWindow); //nsIFactory interface diff --git a/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp b/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp index 53f07f5ffe0..611a50fd737 100644 --- a/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp @@ -16,14 +16,18 @@ * Reserved. */ +#include "nscore.h" #include "nsPluginInstancePeer.h" +#include "nsIPluginInstance.h" nsPluginInstancePeerImpl :: nsPluginInstancePeerImpl() { + mInstance = nsnull; } nsPluginInstancePeerImpl :: ~nsPluginInstancePeerImpl() { + mInstance = nsnull; } NS_IMPL_ADDREF(nsPluginInstancePeerImpl); @@ -64,7 +68,7 @@ nsresult nsPluginInstancePeerImpl :: QueryInterface(const nsIID& iid, void** ins NS_IMETHODIMP nsPluginInstancePeerImpl :: GetValue(nsPluginInstancePeerVariable variable, void *value) { - return NS_OK; + return NS_ERROR_FAILURE; } NS_IMETHODIMP nsPluginInstancePeerImpl :: SetValue(nsPluginInstancePeerVariable variable, void *value) @@ -94,10 +98,20 @@ NS_IMETHODIMP nsPluginInstancePeerImpl :: ShowStatus(const char* message) NS_IMETHODIMP nsPluginInstancePeerImpl :: GetAttributes(PRUint16& n, const char*const*& names, const char*const*& values) { + n = 0; return NS_OK; } NS_IMETHODIMP nsPluginInstancePeerImpl :: GetAttribute(const char* name, const char* *result) { + *result = 0; + return NS_OK; +} + +nsresult nsPluginInstancePeerImpl :: Initialize(nsIPluginInstance *aInstance) +{ + //don't add a ref to precent circular references... MMP + mInstance = aInstance; + return NS_OK; } diff --git a/mozilla/modules/plugin/base/src/nsPluginInstancePeer.h b/mozilla/modules/plugin/base/src/nsPluginInstancePeer.h index a208d050444..aed1996112b 100644 --- a/mozilla/modules/plugin/base/src/nsPluginInstancePeer.h +++ b/mozilla/modules/plugin/base/src/nsPluginInstancePeer.h @@ -57,6 +57,13 @@ public: NS_IMETHOD GetAttribute(const char* name, const char* *result); + + //locals + + nsresult Initialize(nsIPluginInstance *aInstance); + +private: + nsIPluginInstance *mInstance; //we don't add a ref to this }; #endif diff --git a/mozilla/modules/plugin/base/src/nsPluginStreamPeer.cpp b/mozilla/modules/plugin/base/src/nsPluginStreamPeer.cpp index 222fcc4cefe..e1f2cd711fe 100644 --- a/mozilla/modules/plugin/base/src/nsPluginStreamPeer.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginStreamPeer.cpp @@ -17,13 +17,35 @@ */ #include "nsPluginStreamPeer.h" +#include "nsIURL.h" +#include "prmem.h" +#include "nsString.h" nsPluginStreamPeer :: nsPluginStreamPeer() { + mURL = nsnull; + mLength = 0; + mLastMod = 0; + mNotifyData = nsnull; + mMIMEType = nsnull; + mURLSpec = nsnull; } nsPluginStreamPeer :: ~nsPluginStreamPeer() { + NS_IF_RELEASE(mURL); + + if (nsnull != mMIMEType) + { + PR_Free((void *)mMIMEType); + mMIMEType = nsnull; + } + + if (nsnull != mURLSpec) + { + PR_Free((void *)mURLSpec); + mURLSpec = nsnull; + } } NS_IMPL_ADDREF(nsPluginStreamPeer); @@ -56,35 +78,82 @@ NS_IMETHODIMP nsPluginStreamPeer :: QueryInterface(const nsIID& iid, void** inst NS_IMETHODIMP nsPluginStreamPeer :: GetURL(const char* *result) { - return NS_OK; + if (nsnull != mURL) + { + if (nsnull == mURLSpec) + { + nsString string; + + mURL->ToString(string); + + mURLSpec = (char *)PR_Malloc(string.Length() + 1); + + if (nsnull != mURLSpec) + string.ToCString(mURLSpec, string.Length() + 1); + else + return NS_ERROR_OUT_OF_MEMORY; + } + + *result = mURLSpec; + + return NS_OK; + } + else + return NS_ERROR_UNEXPECTED; } NS_IMETHODIMP nsPluginStreamPeer :: GetEnd(PRUint32 *result) { + *result = mLength; return NS_OK; } NS_IMETHODIMP nsPluginStreamPeer :: GetLastModified(PRUint32 *result) { + *result = mLastMod; return NS_OK; } NS_IMETHODIMP nsPluginStreamPeer :: GetNotifyData(void* *result) { + *result = mNotifyData; return NS_OK; } NS_IMETHODIMP nsPluginStreamPeer :: GetReason(nsPluginReason *result) { + *result = nsPluginReason_NoReason; return NS_OK; } NS_IMETHODIMP nsPluginStreamPeer :: GetMIMEType(nsMIMEType *result) { + *result = mMIMEType; return NS_OK; } -NS_IMETHODIMP nsPluginStreamPeer :: Initialize(void) +nsresult nsPluginStreamPeer :: Initialize(nsIURL *aURL, PRUint32 aLength, + PRUint32 aLastMod, nsMIMEType aMIMEType, + void *aNotifyData) { + mURL = aURL; + NS_ADDREF(mURL); + + mLength = aLength; + mLastMod = aLastMod; + + if (nsnull != aMIMEType) + { + PRInt32 len = strlen(aMIMEType); + mMIMEType = (char *)PR_Malloc(len + 1); + + if (nsnull != mMIMEType) + strcpy((char *)mMIMEType, (char *)aMIMEType); + else + return NS_ERROR_OUT_OF_MEMORY; + } + + mNotifyData = aNotifyData; + return NS_OK; } diff --git a/mozilla/modules/plugin/base/src/nsPluginStreamPeer.h b/mozilla/modules/plugin/base/src/nsPluginStreamPeer.h index c2c90788ebd..be7822fe88b 100644 --- a/mozilla/modules/plugin/base/src/nsPluginStreamPeer.h +++ b/mozilla/modules/plugin/base/src/nsPluginStreamPeer.h @@ -19,8 +19,11 @@ #ifndef nsPluginStreamPeer_h___ #define nsPluginStreamPeer_h___ +#include "nscore.h" #include "nsIPluginStreamPeer.h" +class nsIURL; + class nsPluginStreamPeer : public nsIPluginStreamPeer { public: @@ -47,8 +50,19 @@ public: NS_IMETHOD GetMIMEType(nsMIMEType *result); - NS_IMETHOD - Initialize(void); + //locals + + nsresult Initialize(nsIURL *aURL, PRUint32 aLength, + PRUint32 aLastMod, nsMIMEType aMIMEType, + void *aNotifyData); + +private: + nsIURL *mURL; + PRUint32 mLength; + PRUint32 mLastMod; + void *mNotifyData; + nsMIMEType mMIMEType; + char *mURLSpec; }; #endif diff --git a/mozilla/modules/plugin/nglsrc/Makefile b/mozilla/modules/plugin/nglsrc/Makefile index 2ee5ad906fe..6f646653e67 100644 --- a/mozilla/modules/plugin/nglsrc/Makefile +++ b/mozilla/modules/plugin/nglsrc/Makefile @@ -37,7 +37,7 @@ CPPSRCS = \ nsPluginStreamPeer.cpp \ $(NULL) -REQUIRES = raptor plugin java xpcom +REQUIRES = raptor plugin java xpcom netlib LCFLAGS =-D_IMPL_NS_PLUGIN diff --git a/mozilla/modules/plugin/nglsrc/makefile.win b/mozilla/modules/plugin/nglsrc/makefile.win index 6de3c26fbf1..2d1f7a51e09 100644 --- a/mozilla/modules/plugin/nglsrc/makefile.win +++ b/mozilla/modules/plugin/nglsrc/makefile.win @@ -46,6 +46,7 @@ LINCS= \ -I$(PUBLIC)\xpcom \ -I$(PUBLIC)\plugin \ -I$(PUBLIC)\java \ + -I$(PUBLIC)\netlib \ $(NULL) @@ -57,6 +58,7 @@ LCFLAGS = \ OURLIBS= \ $(DIST)\lib\xpcom32.lib \ $(DIST)\lib\raptorbase.lib \ + $(DIST)\lib\netlib.lib \ $(LIBNSPR) LLIBS= \ diff --git a/mozilla/modules/plugin/nglsrc/ns4xPlugin.cpp b/mozilla/modules/plugin/nglsrc/ns4xPlugin.cpp index fc9bf695725..cb9ef64369e 100644 --- a/mozilla/modules/plugin/nglsrc/ns4xPlugin.cpp +++ b/mozilla/modules/plugin/nglsrc/ns4xPlugin.cpp @@ -303,30 +303,30 @@ ns4xPlugin::GetJavaClass(jclass *resultingClass) nsresult NP_EXPORT ns4xPlugin::_geturl(NPP npp, const char* relativeURL, const char* target) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); NS_ASSERTION(mNetworkManager != NULL, "null manager"); - if (peer == NULL) + if (inst == NULL) return NS_ERROR_UNEXPECTED; // XXX - return mNetworkManager->GetURL(peer, relativeURL, target); + return mNetworkManager->GetURL(inst, relativeURL, target); } nsresult NP_EXPORT ns4xPlugin::_geturlnotify(NPP npp, const char* relativeURL, const char* target, void* notifyData) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); NS_ASSERTION(mNetworkManager != NULL, "null manager"); - if (peer == NULL) + if (inst == NULL) return NS_ERROR_UNEXPECTED; // XXX - return mNetworkManager->GetURL(peer, relativeURL, target, + return mNetworkManager->GetURL(inst, relativeURL, target, notifyData); } @@ -336,15 +336,15 @@ ns4xPlugin::_posturlnotify(NPP npp, const char* relativeURL, const char *target, uint32 len, const char *buf, NPBool file, void* notifyData) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); NS_ASSERTION(mNetworkManager != NULL, "null manager"); - if (peer == NULL) + if (inst == NULL) return NS_ERROR_UNEXPECTED; // XXX - return mNetworkManager->PostURL(peer, relativeURL, target, + return mNetworkManager->PostURL(inst, relativeURL, target, len, buf, file, notifyData); } @@ -353,15 +353,15 @@ nsresult NP_EXPORT ns4xPlugin::_posturl(NPP npp, const char* relativeURL, const char *target, uint32 len, const char *buf, NPBool file) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); NS_ASSERTION(mNetworkManager != NULL, "null manager"); - if (peer == NULL) + if (inst == NULL) return NS_ERROR_UNEXPECTED; // XXX - return mNetworkManager->PostURL(peer, relativeURL, target, + return mNetworkManager->PostURL(inst, relativeURL, target, len, buf, file); } @@ -420,29 +420,42 @@ ns4xStreamWrapper::GetStream(void) nsresult NP_EXPORT ns4xPlugin::_newstream(NPP npp, NPMIMEType type, const char* window, NPStream* *result) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); - if (peer == NULL) + if (inst == NULL) return NS_ERROR_UNEXPECTED; // XXX nsresult error; nsIOutputStream* stream; - if ((error = peer->NewStream((const char*) type, window, &stream)) - != NS_OK) - return error; + nsIPluginInstancePeer *peer; - ns4xStreamWrapper* wrapper = new ns4xStreamWrapper(stream); - - if (wrapper == NULL) + if (NS_OK == inst->GetPeer(&peer)) { + if ((error = peer->NewStream((const char*) type, window, &stream)) != NS_OK) + { + NS_RELEASE(peer); + return error; + } + + ns4xStreamWrapper* wrapper = new ns4xStreamWrapper(stream); + + if (wrapper == NULL) + { + NS_RELEASE(peer); NS_RELEASE(stream); return NS_ERROR_OUT_OF_MEMORY; - } + } - (*result) = wrapper->GetNPStream(); - return NS_OK; + (*result) = wrapper->GetNPStream(); + + NS_RELEASE(peer); + + return error; + } + else + return NS_ERROR_UNEXPECTED; } int32 NP_EXPORT @@ -484,14 +497,20 @@ ns4xPlugin::_destroystream(NPP npp, NPStream *pstream, NPError reason) void NP_EXPORT ns4xPlugin::_status(NPP npp, const char *message) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); - if (peer == NULL) + if (inst == NULL) return; - peer->ShowStatus(message); + nsIPluginInstancePeer *peer; + + if (NS_OK == inst->GetPeer(&peer)) + { + peer->ShowStatus(message); + NS_RELEASE(peer); + } } void NP_EXPORT @@ -517,90 +536,130 @@ ns4xPlugin::_reloadplugins(NPBool reloadPages) void NP_EXPORT ns4xPlugin::_invalidaterect(NPP npp, NPRect *invalidRect) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); - if (peer == NULL) + if (inst == NULL) return; + nsIPluginInstancePeer *peer; nsIWindowlessPluginInstancePeer *wpeer; - if (NS_OK == peer->QueryInterface(kIWindowlessPluginInstancePeerIID, (void **)&wpeer)) + if (NS_OK == inst->GetPeer(&peer)) { - // XXX nsRect & NPRect are structurally equivalent - wpeer->InvalidateRect((nsPluginRect *)invalidRect); - NS_RELEASE(wpeer); + if (NS_OK == peer->QueryInterface(kIWindowlessPluginInstancePeerIID, (void **)&wpeer)) + { + // XXX nsRect & NPRect are structurally equivalent + wpeer->InvalidateRect((nsPluginRect *)invalidRect); + NS_RELEASE(wpeer); + } + + NS_RELEASE(peer); } } void NP_EXPORT ns4xPlugin::_invalidateregion(NPP npp, NPRegion invalidRegion) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); - if (peer == NULL) + if (inst == NULL) return; + nsIPluginInstancePeer *peer; nsIWindowlessPluginInstancePeer *wpeer; - if (NS_OK == peer->QueryInterface(kIWindowlessPluginInstancePeerIID, (void **)&wpeer)) + if (NS_OK == inst->GetPeer(&peer)) { - // XXX nsRegion & NPRegion are typedef'd to the same thing - wpeer->InvalidateRegion((nsPluginRegion)invalidRegion); - NS_RELEASE(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); + } + + NS_RELEASE(peer); } } void NP_EXPORT ns4xPlugin::_forceredraw(NPP npp) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); - if (peer == NULL) + if (inst == NULL) return; + nsIPluginInstancePeer *peer; nsIWindowlessPluginInstancePeer *wpeer; - if (NS_OK == peer->QueryInterface(kIWindowlessPluginInstancePeerIID, (void **)&wpeer)) + if (NS_OK == inst->GetPeer(&peer)) { - wpeer->ForceRedraw(); - NS_RELEASE(wpeer); + if (NS_OK == peer->QueryInterface(kIWindowlessPluginInstancePeerIID, (void **)&wpeer)) + { + wpeer->ForceRedraw(); + NS_RELEASE(wpeer); + } + + NS_RELEASE(peer); } } nsresult NP_EXPORT ns4xPlugin::_getvalue(NPP npp, NPNVariable variable, void *result) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); - if (peer == NULL) + if (inst == NULL) return NS_ERROR_FAILURE; // XXX - // XXX Note that for backwards compatibility, the old NPNVariables - // map correctly to NPPluginManagerVariables. - return peer->GetValue((nsPluginInstancePeerVariable)variable, result); + nsIPluginInstancePeer *peer; + + if (NS_OK == inst->GetPeer(&peer)) + { + nsresult rv; + + // XXX Note that for backwards compatibility, the old NPNVariables + // map correctly to NPPluginManagerVariables. + rv = peer->GetValue((nsPluginInstancePeerVariable)variable, result); + NS_RELEASE(peer); + return rv; + } + else + return NS_ERROR_UNEXPECTED; } nsresult NP_EXPORT ns4xPlugin::_setvalue(NPP npp, NPPVariable variable, void *result) { - nsIPluginInstancePeer* peer = (nsIPluginInstancePeer*) npp->ndata; + nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata; - NS_ASSERTION(peer != NULL, "null peer"); + NS_ASSERTION(inst != NULL, "null instance"); - if (peer == NULL) + if (inst == NULL) return NS_ERROR_FAILURE; // XXX - // XXX Note that for backwards compatibility, the old NPPVariables - // map correctly to NPPluginVariables. - return peer->SetValue((nsPluginInstancePeerVariable)variable, result); + nsIPluginInstancePeer *peer; + + if (NS_OK == inst->GetPeer(&peer)) + { + nsresult rv; + + // XXX Note that for backwards compatibility, the old NPPVariables + // map correctly to NPPluginVariables. + rv = peer->SetValue((nsPluginInstancePeerVariable)variable, result); + NS_RELEASE(peer); + return rv; + } + else + return NS_ERROR_UNEXPECTED; } nsresult NP_EXPORT diff --git a/mozilla/modules/plugin/nglsrc/ns4xPluginInstance.cpp b/mozilla/modules/plugin/nglsrc/ns4xPluginInstance.cpp index 2c262607097..d01e5bfe0d9 100644 --- a/mozilla/modules/plugin/nglsrc/ns4xPluginInstance.cpp +++ b/mozilla/modules/plugin/nglsrc/ns4xPluginInstance.cpp @@ -183,7 +183,8 @@ NS_IMETHODIMP ns4xPluginInstance::SetWindow(nsPluginWindow* window) // back from the plugin's SetWindow(). Is this the correct // behavior?!? - NS_ASSERTION(error == NS_OK, "error in setwindow"); + if (error != NS_OK) + printf("error in setwindow %d\n", error); } return error; diff --git a/mozilla/modules/plugin/nglsrc/ns4xPluginStream.cpp b/mozilla/modules/plugin/nglsrc/ns4xPluginStream.cpp index 8fbac3b5e44..434a662e62a 100644 --- a/mozilla/modules/plugin/nglsrc/ns4xPluginStream.cpp +++ b/mozilla/modules/plugin/nglsrc/ns4xPluginStream.cpp @@ -203,7 +203,45 @@ NS_IMETHODIMP ns4xPluginStream::AsFile(const char* filename) NS_IMETHODIMP ns4xPluginStream :: Close(void) { - return NS_OK; + const NPPluginFuncs *callbacks; + NPP npp; + nsresult rv; + void *notifydata; + + fInstance->GetCallbacks(&callbacks); + fInstance->GetNPP(&npp); + + fPeer->GetNotifyData(¬ifydata); + + nsPluginReason reason; + + fPeer->GetReason(&reason); + + if (nsnull != notifydata) + { + if (callbacks->urlnotify == NULL) + return NS_OK; + + const char *url; + + fPeer->GetURL(&url); + + CallNPP_URLNotifyProc(callbacks->urlnotify, + npp, + url, + (NPReason)reason, + notifydata); + } + + if (callbacks->destroystream == NULL) + return NS_OK; + + rv = (nsresult)CallNPP_DestroyStreamProc(callbacks->destroystream, + npp, + &fNPStream, + (NPReason)reason); + + return rv; } //////////////////////////////////////////////////////////////////////// diff --git a/mozilla/modules/plugin/nglsrc/nsIPluginHost.h b/mozilla/modules/plugin/nglsrc/nsIPluginHost.h index 7b503f27adf..650bf516da1 100644 --- a/mozilla/modules/plugin/nglsrc/nsIPluginHost.h +++ b/mozilla/modules/plugin/nglsrc/nsIPluginHost.h @@ -22,6 +22,7 @@ #include "xp_core.h" #include "nsplugindefs.h" #include "nsIFactory.h" +#include "nsString.h" #define NS_IPLUGINHOST_IID \ { 0x264c0640, 0x1c31, 0x11d2, \ @@ -38,7 +39,17 @@ public: LoadPlugins(void) = 0; NS_IMETHOD - InstantiatePlugin(char *aMimeType, nsIPluginInstance ** aPluginInst) = 0; + InstantiatePlugin(const char *aMimeType, nsIPluginInstance ** aPluginInst) = 0; + + NS_IMETHOD + InstantiatePlugin(const char *aMimeType, nsIPluginInstance ** aPluginInst, + nsPluginWindow *aWindow, nsString& aURL) = 0; + + NS_IMETHOD + NewPluginStream(const nsString& aURL, nsIPluginInstance *aInstance, void *aNotifyData) = 0; + + NS_IMETHOD + NewPluginStream(const nsString& aURL, nsIPluginInstance **aInstance, nsPluginWindow *aWindow) = 0; }; #endif diff --git a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp index 53b068e43fa..7238f1ec5d2 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp @@ -24,12 +24,25 @@ #include "nsMalloc.h" //this is evil... #include "nsPluginInstancePeer.h" #include "nsPluginStreamPeer.h" +#include "nsIStreamListener.h" +#include "nsIURL.h" +#include "nsIInputStream.h" #ifdef XP_PC #include "windows.h" #endif static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID); +static NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID); +static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID); +static NS_DEFINE_IID(kINetworkManagerIID, NS_INETWORKMANAGER_IID); +static NS_DEFINE_IID(kIPluginHostIID, NS_IPLUGINHOST_IID); +static NS_DEFINE_IID(kIPluginStreamPeerIID, NS_IPLUGINSTREAMPEER_IID); +static NS_DEFINE_IID(kIMallocIID, NS_IMALLOC_IID); +static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID); +static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID); nsPluginTag :: nsPluginTag() { @@ -107,12 +120,254 @@ nsPluginTag :: ~nsPluginTag() mEntryPoint = nsnull; } -static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID); -static NS_DEFINE_IID(kIPluginHostIID, NS_IPLUGINHOST_IID); -static NS_DEFINE_IID(kIPluginStreamPeerIID, NS_IPLUGINSTREAMPEER_IID); -static NS_DEFINE_IID(kIMallocIID, NS_IMALLOC_IID); -static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +class nsPluginStreamListener : public nsIStreamListener +{ +public: + nsPluginStreamListener(); + ~nsPluginStreamListener(); + + NS_DECL_ISUPPORTS + + //nsIStreamObserver interface + + NS_IMETHOD OnStartBinding(nsIURL* aURL, const char *aContentType); + + NS_IMETHOD OnProgress(nsIURL* aURL, PRInt32 aProgress, PRInt32 aProgressMax); + + NS_IMETHOD OnStatus(nsIURL* aURL, const nsString &aMsg); + + NS_IMETHOD OnStopBinding(nsIURL* aURL, PRInt32 aStatus, const nsString &aMsg); + + //nsIStreamListener interface + + NS_IMETHOD GetBindInfo(nsIURL* aURL); + + NS_IMETHOD OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream, + PRInt32 aLength); + + //locals + + nsresult Initialize(nsIURL *aURL, nsIPluginInstance *aInstance, void *aNotifyData); + nsresult Initialize(nsIURL *aURL, nsIPluginInstance **aInstance, + nsPluginWindow *aWindow, nsIPluginHost *aHost); + +private: + nsIURL *mURL; + nsPluginStreamPeer *mPeer; + nsIPluginInstance *mInstance; + nsIPluginInstance **mFarInstance; + PRBool mBound; + nsIPluginStream *mStream; + char *mMIMEType; + PRUint8 *mBuffer; + PRUint32 mBufSize; + void *mNotifyData; + nsPluginWindow *mWindow; + nsIPluginHost *mHost; +}; + +nsPluginStreamListener :: nsPluginStreamListener() +{ + mURL = nsnull; + mPeer = nsnull; + mInstance = nsnull; + mFarInstance = nsnull; + mBound = PR_FALSE; + mStream = nsnull; + mMIMEType = nsnull; + mBuffer = nsnull; + mBufSize = 0; + mNotifyData = nsnull; + mWindow = nsnull; + mHost = nsnull; +} + +nsPluginStreamListener :: ~nsPluginStreamListener() +{ + NS_IF_RELEASE(mURL); + NS_IF_RELEASE(mPeer); + NS_IF_RELEASE(mInstance); + NS_IF_RELEASE(mStream); + + if (nsnull != mMIMEType) + { + PR_Free(mMIMEType); + mMIMEType = nsnull; + } + + if (nsnull != mBuffer) + { + PR_Free(mBuffer); + mBuffer = nsnull; + } + + mNotifyData = nsnull; + mWindow = nsnull; + mFarInstance = nsnull; + + NS_IF_RELEASE(mHost); +} + +NS_IMPL_ADDREF(nsPluginStreamListener) +NS_IMPL_RELEASE(nsPluginStreamListener) + +nsresult nsPluginStreamListener :: QueryInterface(const nsIID& aIID, + void** aInstancePtrResult) +{ + NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer"); + + if (nsnull == aInstancePtrResult) + return NS_ERROR_NULL_POINTER; + + if (aIID.Equals(kIStreamListenerIID)) + { + *aInstancePtrResult = (void *)((nsIStreamListener *)this); + AddRef(); + return NS_OK; + } + + if (aIID.Equals(kIStreamObserverIID)) + { + *aInstancePtrResult = (void *)((nsIStreamObserver *)this); + AddRef(); + return NS_OK; + } + + if (aIID.Equals(kISupportsIID)) + { + *aInstancePtrResult = (void *)((nsISupports *)((nsIStreamListener *)this)); + AddRef(); + return NS_OK; + } + + return NS_NOINTERFACE; +} + +nsresult nsPluginStreamListener :: Initialize(nsIURL *aURL, nsIPluginInstance *aInstance, void *aNotifyData) +{ + mURL = aURL; + NS_ADDREF(mURL); + + mInstance = aInstance; + NS_ADDREF(mInstance); + + mNotifyData = aNotifyData; + + return NS_OK; +} + +nsresult nsPluginStreamListener :: Initialize(nsIURL *aURL, nsIPluginInstance **aInstance, + nsPluginWindow *aWindow, nsIPluginHost *aHost) +{ + mURL = aURL; + NS_ADDREF(mURL); + + mFarInstance = aInstance; + + mWindow = aWindow; + + mHost = aHost; + NS_IF_ADDREF(mHost); + + return NS_OK; +} + +NS_IMETHODIMP nsPluginStreamListener :: OnStartBinding(nsIURL* aURL, const char *aContentType) +{ + nsresult rv = NS_OK; + + if (nsnull != aContentType) + { + PRInt32 len = strlen(aContentType); + mMIMEType = (char *)PR_Malloc(len + 1); + + if (nsnull != mMIMEType) + strcpy(mMIMEType, aContentType); + else + rv = NS_ERROR_OUT_OF_MEMORY; + } + + //now that we have the mime type, see if we need + //to load a plugin... + + if ((nsnull == mInstance) && (nsnull != mFarInstance) && + (nsnull != mHost) && (nsnull != mWindow) && (nsnull != mMIMEType)) + { + rv = mHost->InstantiatePlugin(mMIMEType, mFarInstance); + + if (NS_OK == rv) + { + mInstance = *mFarInstance; + NS_ADDREF(mInstance); + + (*mFarInstance)->Start(); + (*mFarInstance)->SetWindow(mWindow); + } + } + + mBound = PR_TRUE; + + return rv; +} + +NS_IMETHODIMP nsPluginStreamListener :: OnProgress(nsIURL* aURL, PRInt32 aProgress, PRInt32 aProgressMax) +{ + NS_ASSERTION(!(mBound == PR_FALSE), "ack, got progress without start binding"); + + if ((PR_TRUE == mBound) && (nsnull == mPeer)) + { + //need to create new peer and and tell plugin that we have new stream... + + mPeer = (nsPluginStreamPeer *)new nsPluginStreamPeer(); + + NS_ADDREF(mPeer); + + mPeer->Initialize(aURL, aProgressMax, 0, mMIMEType, mNotifyData); + mInstance->NewStream(mPeer, &mStream); + } + + return NS_OK; +} + +NS_IMETHODIMP nsPluginStreamListener :: OnStatus(nsIURL* aURL, const nsString &aMsg) +{ + return NS_OK; +} + +NS_IMETHODIMP nsPluginStreamListener :: OnStopBinding(nsIURL* aURL, PRInt32 aStatus, const nsString &aMsg) +{ + if (nsnull != mStream) + mStream->Close(); + + return NS_OK; +} + +NS_IMETHODIMP nsPluginStreamListener :: GetBindInfo(nsIURL* aURL) +{ + return NS_OK; +} + +NS_IMETHODIMP nsPluginStreamListener :: OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream, + PRInt32 aLength) +{ + if ((PRUint32)aLength > mBufSize) + { + if (nsnull != mBuffer) + PR_Free((void *)mBuffer); + + mBuffer = (PRUint8 *)PR_Malloc(aLength); + mBufSize = aLength; + } + + if ((nsnull != mBuffer) && (nsnull != mStream)) + { + PRInt32 readlen; + aIStream->Read((char *)mBuffer, 0, aLength, &readlen); + mStream->Write((char *)mBuffer, 0, aLength, &readlen); + } + + return NS_OK; +} nsPluginHostImpl :: nsPluginHostImpl() { @@ -161,6 +416,13 @@ nsresult nsPluginHostImpl :: QueryInterface(const nsIID& aIID, return NS_OK; } + if (aIID.Equals(kINetworkManagerIID)) + { + *aInstancePtrResult = (void *)((nsINetworkManager *)this); + AddRef(); + return NS_OK; + } + if (aIID.Equals(kIFactoryIID)) { *aInstancePtrResult = (void *)((nsIFactory *)this); @@ -212,7 +474,19 @@ NS_IMETHODIMP nsPluginHostImpl :: GetURL(nsISupports* peer, const char* url, void* notifyData, const char* altHost, const char* referrer, PRBool forceJSEnabled) { - return NS_OK; + nsAutoString string = nsAutoString(url); + nsIPluginInstance *inst; + nsresult rv; + + rv = peer->QueryInterface(kIPluginInstanceIID, (void **)&inst); + + if (NS_OK == rv) + { + NewPluginStream(string, inst, notifyData); + NS_RELEASE(inst); + } + + return rv; } NS_IMETHODIMP nsPluginHostImpl :: PostURL(nsISupports* peer, @@ -562,7 +836,7 @@ printf("plugin %s added to list %s\n", plugintag->mName, (plugintag->mFlags & NS return NS_OK; } -nsresult nsPluginHostImpl :: InstantiatePlugin(char *aMimeType, nsIPluginInstance ** aPluginInst) +nsresult nsPluginHostImpl :: InstantiatePlugin(const char *aMimeType, nsIPluginInstance ** aPluginInst) { nsPluginTag *plugins = mPlugins; PRInt32 variants, cnt; @@ -622,8 +896,9 @@ printf("result of creating plugin adapter: %d\n", rv); { printf("successfully created plugin instance\n"); - nsIPluginInstancePeer *peer = new nsPluginInstancePeerImpl(); + nsPluginInstancePeerImpl *peer = new nsPluginInstancePeerImpl(); + peer->Initialize(*aPluginInst); //this will not add a ref to the instance. MMP (*aPluginInst)->Initialize(peer); } } @@ -641,6 +916,65 @@ printf("unable to find plugin to handle %s\n", aMimeType); } } +nsresult nsPluginHostImpl :: InstantiatePlugin(const char *aMimeType, nsIPluginInstance ** aPluginInst, + nsPluginWindow *aWindow, nsString& aURL) +{ + nsresult rv; + + if (nsnull == aMimeType) + { + if (aURL.Length() > 0) + { + //we need to stream in enough to get the mime type... + + rv = NewPluginStream(aURL, aPluginInst, aWindow); + } + else + rv = NS_ERROR_FAILURE; + } + else + { + rv = InstantiatePlugin(aMimeType, aPluginInst); + + if (NS_OK == rv) + { + (*aPluginInst)->Start(); + (*aPluginInst)->SetWindow(aWindow); + NewPluginStream(aURL, *aPluginInst, nsnull); + } + } + + return rv; +} + +NS_IMETHODIMP nsPluginHostImpl :: NewPluginStream(const nsString& aURL, nsIPluginInstance *aInstance, void *aNotifyData) +{ + nsIURL *mURL; + nsPluginStreamListener *mListener = (nsPluginStreamListener *)new nsPluginStreamListener(); + + if (NS_OK == NS_NewURL(&mURL, aURL)) + { + mListener->Initialize(mURL, aInstance, aNotifyData); + mURL->Open(mListener); + } + + return NS_OK; +} + +NS_IMETHODIMP nsPluginHostImpl :: NewPluginStream(const nsString& aURL, nsIPluginInstance **aInstance, nsPluginWindow *aWindow) +{ + nsIURL *mURL; + nsPluginStreamListener *mListener = (nsPluginStreamListener *)new nsPluginStreamListener(); + + if (NS_OK == NS_NewURL(&mURL, aURL)) + { + mListener->Initialize(mURL, aInstance, aWindow, (nsIPluginHost *)this); + mURL->Open(mListener); + } + + return NS_OK; +} + nsresult nsPluginHostImpl :: CreateInstance(nsISupports *aOuter, const nsIID &aIID, void **aResult) diff --git a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h index ee14d3a33f4..71d5d99d00c 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h +++ b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h @@ -107,7 +107,17 @@ public: LoadPlugins(void); NS_IMETHOD - InstantiatePlugin(char *aMimeType, nsIPluginInstance ** aPluginInst); + InstantiatePlugin(const char *aMimeType, nsIPluginInstance ** aPluginInst); + + NS_IMETHOD + InstantiatePlugin(const char *aMimeType, nsIPluginInstance ** aPluginInst, + nsPluginWindow *aWindow, nsString& aURL); + + NS_IMETHOD + NewPluginStream(const nsString& aURL, nsIPluginInstance *aInstance, void *aNotifyData); + + NS_IMETHOD + NewPluginStream(const nsString& aURL, nsIPluginInstance **aInstance, nsPluginWindow *aWindow); //nsIFactory interface diff --git a/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp b/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp index 53f07f5ffe0..611a50fd737 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp +++ b/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp @@ -16,14 +16,18 @@ * Reserved. */ +#include "nscore.h" #include "nsPluginInstancePeer.h" +#include "nsIPluginInstance.h" nsPluginInstancePeerImpl :: nsPluginInstancePeerImpl() { + mInstance = nsnull; } nsPluginInstancePeerImpl :: ~nsPluginInstancePeerImpl() { + mInstance = nsnull; } NS_IMPL_ADDREF(nsPluginInstancePeerImpl); @@ -64,7 +68,7 @@ nsresult nsPluginInstancePeerImpl :: QueryInterface(const nsIID& iid, void** ins NS_IMETHODIMP nsPluginInstancePeerImpl :: GetValue(nsPluginInstancePeerVariable variable, void *value) { - return NS_OK; + return NS_ERROR_FAILURE; } NS_IMETHODIMP nsPluginInstancePeerImpl :: SetValue(nsPluginInstancePeerVariable variable, void *value) @@ -94,10 +98,20 @@ NS_IMETHODIMP nsPluginInstancePeerImpl :: ShowStatus(const char* message) NS_IMETHODIMP nsPluginInstancePeerImpl :: GetAttributes(PRUint16& n, const char*const*& names, const char*const*& values) { + n = 0; return NS_OK; } NS_IMETHODIMP nsPluginInstancePeerImpl :: GetAttribute(const char* name, const char* *result) { + *result = 0; + return NS_OK; +} + +nsresult nsPluginInstancePeerImpl :: Initialize(nsIPluginInstance *aInstance) +{ + //don't add a ref to precent circular references... MMP + mInstance = aInstance; + return NS_OK; } diff --git a/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.h b/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.h index a208d050444..aed1996112b 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.h +++ b/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.h @@ -57,6 +57,13 @@ public: NS_IMETHOD GetAttribute(const char* name, const char* *result); + + //locals + + nsresult Initialize(nsIPluginInstance *aInstance); + +private: + nsIPluginInstance *mInstance; //we don't add a ref to this }; #endif diff --git a/mozilla/modules/plugin/nglsrc/nsPluginStreamPeer.cpp b/mozilla/modules/plugin/nglsrc/nsPluginStreamPeer.cpp index 222fcc4cefe..e1f2cd711fe 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginStreamPeer.cpp +++ b/mozilla/modules/plugin/nglsrc/nsPluginStreamPeer.cpp @@ -17,13 +17,35 @@ */ #include "nsPluginStreamPeer.h" +#include "nsIURL.h" +#include "prmem.h" +#include "nsString.h" nsPluginStreamPeer :: nsPluginStreamPeer() { + mURL = nsnull; + mLength = 0; + mLastMod = 0; + mNotifyData = nsnull; + mMIMEType = nsnull; + mURLSpec = nsnull; } nsPluginStreamPeer :: ~nsPluginStreamPeer() { + NS_IF_RELEASE(mURL); + + if (nsnull != mMIMEType) + { + PR_Free((void *)mMIMEType); + mMIMEType = nsnull; + } + + if (nsnull != mURLSpec) + { + PR_Free((void *)mURLSpec); + mURLSpec = nsnull; + } } NS_IMPL_ADDREF(nsPluginStreamPeer); @@ -56,35 +78,82 @@ NS_IMETHODIMP nsPluginStreamPeer :: QueryInterface(const nsIID& iid, void** inst NS_IMETHODIMP nsPluginStreamPeer :: GetURL(const char* *result) { - return NS_OK; + if (nsnull != mURL) + { + if (nsnull == mURLSpec) + { + nsString string; + + mURL->ToString(string); + + mURLSpec = (char *)PR_Malloc(string.Length() + 1); + + if (nsnull != mURLSpec) + string.ToCString(mURLSpec, string.Length() + 1); + else + return NS_ERROR_OUT_OF_MEMORY; + } + + *result = mURLSpec; + + return NS_OK; + } + else + return NS_ERROR_UNEXPECTED; } NS_IMETHODIMP nsPluginStreamPeer :: GetEnd(PRUint32 *result) { + *result = mLength; return NS_OK; } NS_IMETHODIMP nsPluginStreamPeer :: GetLastModified(PRUint32 *result) { + *result = mLastMod; return NS_OK; } NS_IMETHODIMP nsPluginStreamPeer :: GetNotifyData(void* *result) { + *result = mNotifyData; return NS_OK; } NS_IMETHODIMP nsPluginStreamPeer :: GetReason(nsPluginReason *result) { + *result = nsPluginReason_NoReason; return NS_OK; } NS_IMETHODIMP nsPluginStreamPeer :: GetMIMEType(nsMIMEType *result) { + *result = mMIMEType; return NS_OK; } -NS_IMETHODIMP nsPluginStreamPeer :: Initialize(void) +nsresult nsPluginStreamPeer :: Initialize(nsIURL *aURL, PRUint32 aLength, + PRUint32 aLastMod, nsMIMEType aMIMEType, + void *aNotifyData) { + mURL = aURL; + NS_ADDREF(mURL); + + mLength = aLength; + mLastMod = aLastMod; + + if (nsnull != aMIMEType) + { + PRInt32 len = strlen(aMIMEType); + mMIMEType = (char *)PR_Malloc(len + 1); + + if (nsnull != mMIMEType) + strcpy((char *)mMIMEType, (char *)aMIMEType); + else + return NS_ERROR_OUT_OF_MEMORY; + } + + mNotifyData = aNotifyData; + return NS_OK; } diff --git a/mozilla/modules/plugin/nglsrc/nsPluginStreamPeer.h b/mozilla/modules/plugin/nglsrc/nsPluginStreamPeer.h index c2c90788ebd..be7822fe88b 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginStreamPeer.h +++ b/mozilla/modules/plugin/nglsrc/nsPluginStreamPeer.h @@ -19,8 +19,11 @@ #ifndef nsPluginStreamPeer_h___ #define nsPluginStreamPeer_h___ +#include "nscore.h" #include "nsIPluginStreamPeer.h" +class nsIURL; + class nsPluginStreamPeer : public nsIPluginStreamPeer { public: @@ -47,8 +50,19 @@ public: NS_IMETHOD GetMIMEType(nsMIMEType *result); - NS_IMETHOD - Initialize(void); + //locals + + nsresult Initialize(nsIURL *aURL, PRUint32 aLength, + PRUint32 aLastMod, nsMIMEType aMIMEType, + void *aNotifyData); + +private: + nsIURL *mURL; + PRUint32 mLength; + PRUint32 mLastMod; + void *mNotifyData; + nsMIMEType mMIMEType; + char *mURLSpec; }; #endif