diff --git a/mozilla/modules/plugin/base/public/nsIPluginInstance.h b/mozilla/modules/plugin/base/public/nsIPluginInstance.h
index e7822176edc..39d2fb211bb 100644
--- a/mozilla/modules/plugin/base/public/nsIPluginInstance.h
+++ b/mozilla/modules/plugin/base/public/nsIPluginInstance.h
@@ -36,10 +36,7 @@
#include "nsplugindefs.h"
#include "nsISupports.h"
-
-#ifdef NEW_PLUGIN_STREAM_API
#include "nsIPluginStreamListener.h"
-#endif
#define NS_IPLUGININSTANCE_IID \
{ /* ebe00f40-0199-11d2-815b-006008119d7a */ \
@@ -140,7 +137,6 @@ public:
NS_IMETHOD
SetWindow(nsPluginWindow* window) = 0;
-#ifdef NEW_PLUGIN_STREAM_API
/**
* Called to tell the plugin that the initial src/data stream is
* ready. Expects the plugin to return a nsIPluginStreamListener.
@@ -152,21 +148,6 @@ public:
*/
NS_IMETHOD
NewStream(nsIPluginStreamListener** listener) = 0;
-#else
- /**
- * Called when a new plugin stream must be constructed in order for the plugin
- * instance to receive a stream of data from the browser.
- *
- * (Corresponds to NPP_NewStream.)
- *
- * @param peer - the plugin stream peer, representing information about the
- * incoming stream, and stream-specific callbacks into the browser
- * @param result - the resulting plugin stream
- * @result - NS_OK if this operation was successful
- */
- NS_IMETHOD
- NewStream(nsIPluginStreamPeer* peer, nsIPluginStream* *result) = 0;
-#endif
/**
* Called to instruct the plugin instance to print itself to a printer.
@@ -179,24 +160,6 @@ public:
NS_IMETHOD
Print(nsPluginPrint* platformPrint) = 0;
-#ifndef NEW_PLUGIN_STREAM_API
- /**
- * Called to notify the plugin instance that a URL request has been
- * completed. (See nsIPluginManager::GetURL and nsIPluginManager::PostURL).
- *
- * (Corresponds to NPP_URLNotify.)
- *
- * @param url - the requested URL
- * @param target - the target window name
- * @param reason - the reason for completion
- * @param notifyData - the notify data supplied to GetURL or PostURL
- * @result - NS_OK if this operation was successful
- */
- NS_IMETHOD
- URLNotify(const char* url, const char* target,
- nsPluginReason reason, void* notifyData) = 0;
-#endif
-
/**
* Returns the value of a variable associated with the plugin instance.
*
diff --git a/mozilla/modules/plugin/base/public/nsIPluginManager.h b/mozilla/modules/plugin/base/public/nsIPluginManager.h
index 36951cc1793..615b9bd9751 100644
--- a/mozilla/modules/plugin/base/public/nsIPluginManager.h
+++ b/mozilla/modules/plugin/base/public/nsIPluginManager.h
@@ -102,32 +102,6 @@ public:
NS_IMETHOD
UserAgent(const char* *resultingAgentString) = 0;
-#ifdef NEW_PLUGIN_STREAM_API
-
- NS_IMETHOD
- GetURL(nsISupports* pluginInst,
- const char* url,
- const char* target = NULL,
- nsIPluginStreamListener* streamListener = NULL,
- const char* altHost = NULL,
- const char* referrer = NULL,
- PRBool forceJSEnabled = PR_FALSE) = 0;
-
- NS_IMETHOD
- PostURL(nsISupports* pluginInst,
- const char* url,
- PRUint32 postDataLen,
- const char* postData,
- PRBool isFile = PR_FALSE,
- const char* target = NULL,
- nsIPluginStreamListener* streamListener = NULL,
- const char* altHost = NULL,
- const char* referrer = NULL,
- PRBool forceJSEnabled = PR_FALSE,
- PRUint32 postHeadersLength = 0,
- const char* postHeaders = NULL) = 0;
-
-#else // !NEW_PLUGIN_STREAM_API
/**
* Fetches a URL.
*
@@ -149,10 +123,15 @@ public:
* specify PR_FALSE)
* @result - NS_OK if this operation was successful
*/
+
NS_IMETHOD
- GetURL(nsISupports* pluginInst, const char* url, const char* target,
- void* notifyData = NULL, const char* altHost = NULL,
- const char* referrer = NULL, PRBool forceJSEnabled = PR_FALSE) = 0;
+ GetURL(nsISupports* pluginInst,
+ const char* url,
+ const char* target = NULL,
+ nsIPluginStreamListener* streamListener = NULL,
+ const char* altHost = NULL,
+ const char* referrer = NULL,
+ PRBool forceJSEnabled = PR_FALSE) = 0;
/**
* Posts to a URL with post data and/or post headers.
@@ -183,14 +162,20 @@ public:
* are no post headers
* @result - NS_OK if this operation was successful
*/
+
NS_IMETHOD
- PostURL(nsISupports* pluginInst, 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,
+ PostURL(nsISupports* pluginInst,
+ const char* url,
+ PRUint32 postDataLen,
+ const char* postData,
+ PRBool isFile = PR_FALSE,
+ const char* target = NULL,
+ nsIPluginStreamListener* streamListener = NULL,
+ const char* altHost = NULL,
+ const char* referrer = NULL,
PRBool forceJSEnabled = PR_FALSE,
- PRUint32 postHeadersLength = 0, const char* postHeaders = NULL) = 0;
-#endif // !NEW_PLUGIN_STREAM_API
+ PRUint32 postHeadersLength = 0,
+ const char* postHeaders = NULL) = 0;
};
diff --git a/mozilla/modules/plugin/base/public/nsIPluginStreamInfo.h b/mozilla/modules/plugin/base/public/nsIPluginStreamInfo.h
index fc874022bce..62d9898403a 100644
--- a/mozilla/modules/plugin/base/public/nsIPluginStreamInfo.h
+++ b/mozilla/modules/plugin/base/public/nsIPluginStreamInfo.h
@@ -38,6 +38,9 @@ public:
NS_IMETHOD
GetLastModified(PRUint32* result) = 0;
+ NS_IMETHOD
+ GetURL(const char** result) = 0;
+
NS_IMETHOD
RequestRead(nsByteRange* rangeList) = 0;
};
diff --git a/mozilla/modules/plugin/base/public/nsIPluginStreamListener.h b/mozilla/modules/plugin/base/public/nsIPluginStreamListener.h
index 8e22c7a4637..591f0526d61 100644
--- a/mozilla/modules/plugin/base/public/nsIPluginStreamListener.h
+++ b/mozilla/modules/plugin/base/public/nsIPluginStreamListener.h
@@ -56,7 +56,7 @@ public:
* used to cancel the URL load..
*/
NS_IMETHOD
- OnStartBinding(const char* url, nsIPluginStreamInfo* pluginInfo) = 0;
+ OnStartBinding(nsIPluginStreamInfo* pluginInfo) = 0;
/**
* Notify the client that data is available in the input stream. This
@@ -69,12 +69,12 @@ public:
* @return The return value is currently ignored.
*/
NS_IMETHOD
- OnDataAvailable(const char* url, nsIInputStream* input,
- PRUint32 offset, PRUint32 length, nsIPluginStreamInfo* pluginInfo) = 0;
+ OnDataAvailable(nsIPluginStreamInfo* pluginInfo, nsIInputStream* input, PRUint32 length) = 0;
NS_IMETHOD
- OnFileAvailable(const char* url, const char* fileName) = 0;
- /**
+ OnFileAvailable(nsIPluginStreamInfo* pluginInfo, const char* fileName) = 0;
+
+ /**
* Notify the observer that the URL has finished loading. This method is
* called once when the networking library has finished processing the
* URL transaction initiatied via the nsINetService::Open(...) call.
@@ -86,10 +86,8 @@ public:
* @return The return value is currently ignored.
*/
NS_IMETHOD
- OnStopBinding(const char* url, nsresult status, nsIPluginStreamInfo* pluginInfo) = 0;
+ OnStopBinding(nsIPluginStreamInfo* pluginInfo, nsresult status) = 0;
- NS_IMETHOD
- OnNotify(const char* url, nsresult status) = 0;
NS_IMETHOD
GetStreamType(nsPluginStreamType *result) = 0;
diff --git a/mozilla/modules/plugin/base/public/nsplugin.h b/mozilla/modules/plugin/base/public/nsplugin.h
index 181a01500e3..dc9f9c702ee 100644
--- a/mozilla/modules/plugin/base/public/nsplugin.h
+++ b/mozilla/modules/plugin/base/public/nsplugin.h
@@ -79,8 +79,7 @@
#ifndef nsplugins_h___
#define nsplugins_h___
-#define NEW_PLUGIN_STREAM_API
-
+#include "nsRepository.h" // for NSGetFactory
#include "nsIComponentManager.h" // for NSGetFactory
////////////////////////////////////////////////////////////////////////////////
@@ -114,23 +113,11 @@
*/
#include "nsIPluginInstance.h"
-#ifdef NEW_PLUGIN_STREAM_API
-
/**
* A plugin stream listener ...
*/
#include "nsIPluginStreamListener.h"
-#else // !NEW_PLUGIN_STREAM_API
-
-/**
- * A plugin stream gets instantiated when a plugin instance receives data from
- * the browser.
- */
-#include "nsIPluginStream.h"
-
-#endif // !NEW_PLUGIN_STREAM_API
-
/**
* The nsILiveConnectPlugin interface provides additional operations that a
* plugin must implement if it is to be controlled by JavaScript through
@@ -177,32 +164,11 @@
*/
#include "nsIWindowlessPlugInstPeer.h"
-#ifdef NEW_PLUGIN_STREAM_API
-
/**
*
*/
#include "nsIPluginInputStream.h"
-#else // !NEW_PLUGIN_STREAM_API
-
-/**
- * A plugin stream peer gets create by the browser and associated with each
- * plugin stream to represent stream and URL information, and provides
- * other callbacks needed by the plugin stream.
- */
-#include "nsIPluginStreamPeer.h"
-
-/**
- * The nsISeekablePluginStreamPeer provides additional operations for seekable
- * plugin streams.
- *
- * To obtain: QueryInterface on nsIPluginStreamPeer
- */
-#include "nsISeekablePluginStreamPeer.h"
-
-#endif // !NEW_PLUGIN_STREAM_API
-
////////////////////////////////////////////////////////////////////////////////
/**
* Interfaces implemented by the browser (new for 5.0):
@@ -236,25 +202,11 @@
*/
//#include "nsILiveConnectPlugInstPeer.h"
-#ifdef NEW_PLUGIN_STREAM_API
-
/**
*
*/
#include "nsIPluginInputStream2.h"
-#else // !NEW_PLUGIN_STREAM_API
-
-/**
- * The nsIPluginStreamPeer2 interface provides additional plugin stream
- * peer features only available in Communicator 5.0.
- *
- * To obtain: QueryInterface on nsIPluginStreamPeer
- */
-#include "nsIPluginStreamPeer2.h"
-
-#endif // !NEW_PLUGIN_STREAM_API
-
/**
* The nsIPluginTagInfo2 interface provides additional html tag information
* only available in Communicator 5.0.
diff --git a/mozilla/modules/plugin/base/public/nsplugindefs.h b/mozilla/modules/plugin/base/public/nsplugindefs.h
index 3c70aa12d03..60de04887eb 100644
--- a/mozilla/modules/plugin/base/public/nsplugindefs.h
+++ b/mozilla/modules/plugin/base/public/nsplugindefs.h
@@ -34,8 +34,6 @@
#ifndef nsplugindefs_h___
#define nsplugindefs_h___
-#define NEW_PLUGIN_STREAM_API
-
#ifndef prtypes_h___
#include "prtypes.h"
#endif
diff --git a/mozilla/modules/plugin/base/src/Makefile.in b/mozilla/modules/plugin/base/src/Makefile.in
index 8bd676ef362..baadc115123 100644
--- a/mozilla/modules/plugin/base/src/Makefile.in
+++ b/mozilla/modules/plugin/base/src/Makefile.in
@@ -41,7 +41,6 @@ CPPSRCS = \
ns4xPlugin.cpp \
ns4xPluginInstance.cpp \
nsPluginInstancePeer.cpp \
- nsMalloc.cpp \
$(NULL)
REQUIRES = raptor plugin java xpcom netlib libplc21 oji
diff --git a/mozilla/modules/plugin/base/src/makefile.win b/mozilla/modules/plugin/base/src/makefile.win
index c563abda4ac..9411e87a1db 100644
--- a/mozilla/modules/plugin/base/src/makefile.win
+++ b/mozilla/modules/plugin/base/src/makefile.win
@@ -37,10 +37,7 @@ OBJS = \
.\$(OBJDIR)\nsPluginFactory.obj \
.\$(OBJDIR)\ns4xPlugin.obj \
.\$(OBJDIR)\ns4xPluginInstance.obj \
-# .\$(OBJDIR)\ns4xPluginStream.obj \
.\$(OBJDIR)\nsPluginInstancePeer.obj \
-# .\$(OBJDIR)\nsPluginStreamPeer.obj \
- .\$(OBJDIR)\nsMalloc.obj \
$(NULL)
LINCS = \
diff --git a/mozilla/modules/plugin/base/src/ns4xPlugin.cpp b/mozilla/modules/plugin/base/src/ns4xPlugin.cpp
index 5e487c4e257..b72d5d15b28 100644
--- a/mozilla/modules/plugin/base/src/ns4xPlugin.cpp
+++ b/mozilla/modules/plugin/base/src/ns4xPlugin.cpp
@@ -24,12 +24,13 @@
#include "ns4xPluginInstance.h"
#include "nsIServiceManager.h"
#include "nsIAllocator.h"
+#include "nsIPluginStreamListener.h"
////////////////////////////////////////////////////////////////////////
NPNetscapeFuncs ns4xPlugin::CALLBACKS;
nsIPluginManager * ns4xPlugin::mPluginManager;
-nsIAllocator * ns4xPlugin::mMalloc;
+nsIAllocator * ns4xPlugin::mMalloc;
void
ns4xPlugin::CheckClassInitialized(void)
@@ -87,32 +88,23 @@ static NS_DEFINE_IID(kPluginManagerCID, NS_PLUGINMANAGER_CID);
static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID);
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID);
-
-#ifndef NEW_PLUGIN_STREAM_API
-static NS_DEFINE_IID(kISeekablePluginStreamPeerIID, NS_ISEEKABLEPLUGINSTREAMPEER_IID);
-#endif
+static NS_DEFINE_IID(kIPluginStreamListenerIID, NS_IPLUGINSTREAMLISTENER_IID);
////////////////////////////////////////////////////////////////////////
-#ifdef NEW_PLUGIN_STREAM_API
ns4xPlugin::ns4xPlugin(NPPluginFuncs* callbacks, NP_PLUGINSHUTDOWN aShutdown, nsIServiceManager* serviceMgr)
-#else
-ns4xPlugin::ns4xPlugin(NPPluginFuncs* callbacks, NP_PLUGINSHUTDOWN aShutdown)
-#endif
{
NS_INIT_REFCNT();
memcpy((void*) &fCallbacks, (void*) callbacks, sizeof(fCallbacks));
fShutdownEntry = aShutdown;
-#ifdef NEW_PLUGIN_STREAM_API
- // set up the connections to the plugin manager
+ // set up the connections to the plugin manager
if (nsnull == mPluginManager)
serviceMgr->GetService(kPluginManagerCID, kIPluginManagerIID, (nsISupports**)&mPluginManager);
- if (nsnull == mMalloc)
+ if (nsnull == mMalloc)
serviceMgr->GetService(kAllocatorCID, kIAllocatorIID, (nsISupports**)&mMalloc);
-#endif
}
@@ -165,7 +157,8 @@ ns4xPlugin::QueryInterface(const nsIID& iid, void** instance)
nsresult
ns4xPlugin::CreatePlugin(PRLibrary *library,
- nsIPlugin **result, nsIServiceManager* serviceMgr)
+ nsIPlugin **result,
+ nsIServiceManager* serviceMgr)
{
CheckClassInitialized();
@@ -203,11 +196,7 @@ ns4xPlugin::CreatePlugin(PRLibrary *library,
// we must init here because the plugin may call NPN functions
// when we call into the NP_Initialize entry point - NPN functions
// require that mBrowserManager be set up
-#ifdef NEW_PLUGIN_STREAM_API
(*result)->Initialize();
-#else
- (*result)->Initialize(browserInterfaces);
-#endif
// the NP_Initialize entry point was misnamed as NP_PluginInit,
// early in plugin project development. Its correct name is
@@ -273,30 +262,11 @@ nsresult ns4xPlugin :: LockFactory(PRBool aLock)
return NS_OK;
}
-#ifndef NEW_PLUGIN_STREAM_API
-nsresult
-ns4xPlugin::Initialize(nsISupports* browserInterfaces)
-{
- nsresult rv = NS_OK;
-
- // set up the connections to the plugin manager
- if (nsnull == mPluginManager)
- if((rv = browserInterfaces->QueryInterface(kIPluginManagerIID, (void **)&mPluginManager)) != NS_OK)
- return rv;
- if (nsnull == mMalloc)
- if((rv = browserInterfaces->QueryInterface(kIMallocIID, (void **)&mMalloc)) != NS_OK)
- return rv;
-
- return rv;
-}
-#else
nsresult
ns4xPlugin::Initialize(void)
{
return NS_OK;
}
-#endif
-
nsresult
ns4xPlugin::Shutdown(void)
@@ -336,101 +306,106 @@ printf("plugin getvalue %d called\n", variable);
// Static callbacks that get routed back through the new C++ API
//
-nsresult NP_EXPORT
+NPError NP_EXPORT
ns4xPlugin::_geturl(NPP npp, const char* relativeURL, const char* target)
{
+ if(!npp)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
NS_ASSERTION(mPluginManager != NULL, "null manager");
if (inst == NULL)
- return NS_ERROR_UNEXPECTED; // XXX
+ return NPERR_INVALID_INSTANCE_ERROR;
-#ifdef NEW_PLUGIN_STREAM_API
nsIPluginStreamListener* listener = nsnull;
if(target == nsnull)
inst->NewStream(&listener);
- return mPluginManager->GetURL(inst, relativeURL, target, listener);
-#else
- return mPluginManager->GetURL(inst, relativeURL, target);
-#endif
+ if(mPluginManager->GetURL(inst, relativeURL, target, listener) != NS_OK)
+ return NPERR_GENERIC_ERROR;
+
+ return NPERR_NO_ERROR;
}
-nsresult NP_EXPORT
+NPError NP_EXPORT
ns4xPlugin::_geturlnotify(NPP npp, const char* relativeURL, const char* target,
void* notifyData)
{
+ if(!npp)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
NS_ASSERTION(mPluginManager != NULL, "null manager");
if (inst == NULL)
- return NS_ERROR_UNEXPECTED; // XXX
+ return NPERR_INVALID_INSTANCE_ERROR;
-#ifdef NEW_PLUGIN_STREAM_API
nsIPluginStreamListener* listener = nsnull;
if(target == nsnull)
((ns4xPluginInstance*)inst)->NewNotifyStream(&listener, notifyData);
- return mPluginManager->GetURL(inst, relativeURL, target, listener);
-#else
- return mPluginManager->GetURL(inst, relativeURL, target,
- notifyData);
-#endif
+ if(mPluginManager->GetURL(inst, relativeURL, target, listener) != NS_OK)
+ return NPERR_GENERIC_ERROR;
+
+ return NPERR_NO_ERROR;
}
-nsresult NP_EXPORT
+NPError NP_EXPORT
ns4xPlugin::_posturlnotify(NPP npp, const char* relativeURL, const char *target,
uint32 len, const char *buf, NPBool file,
void* notifyData)
{
+ if(!npp)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
NS_ASSERTION(mPluginManager != NULL, "null manager");
if (inst == NULL)
- return NS_ERROR_UNEXPECTED; // XXX
+ return NPERR_INVALID_INSTANCE_ERROR;
-#ifdef NEW_PLUGIN_STREAM_API
nsIPluginStreamListener* listener = nsnull;
if(target == nsnull)
((ns4xPluginInstance*)inst)->NewNotifyStream(&listener, notifyData);
- return mPluginManager->PostURL(inst, relativeURL, len, buf, file, target, listener);
-#else
- return mPluginManager->PostURL(inst, relativeURL, target,
- len, buf, file, notifyData);
-#endif
+ if(mPluginManager->PostURL(inst, relativeURL, len, buf, file, target, listener) != NS_OK)
+ return NPERR_GENERIC_ERROR;
+
+ return NPERR_NO_ERROR;
}
-nsresult NP_EXPORT
+NPError NP_EXPORT
ns4xPlugin::_posturl(NPP npp, const char* relativeURL, const char *target, uint32 len,
const char *buf, NPBool file)
{
+ if(!npp)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
NS_ASSERTION(mPluginManager != NULL, "null manager");
if (inst == NULL)
- return NS_ERROR_UNEXPECTED; // XXX
+ return NPERR_INVALID_INSTANCE_ERROR;
-#ifdef NEW_PLUGIN_STREAM_API
nsIPluginStreamListener* listener = nsnull;
if(target == nsnull)
inst->NewStream(&listener);
- return mPluginManager->PostURL(inst, relativeURL, len, buf, file, target, listener);
-#else
- return mPluginManager->PostURL(inst, relativeURL, target,
- len, buf, file);
-#endif
+ if(mPluginManager->PostURL(inst, relativeURL, len, buf, file, target, listener) != NS_OK)
+ return NPERR_GENERIC_ERROR;
+
+ return NPERR_NO_ERROR;
}
////////////////////////////////////////////////////////////////////////
@@ -449,8 +424,7 @@ public:
ns4xStreamWrapper(nsIOutputStream* stream);
~ns4xStreamWrapper();
- nsIOutputStream*
- GetStream(void);
+ void GetStream(nsIOutputStream* &result);
NPStream*
GetNPStream(void) {
@@ -464,7 +438,6 @@ ns4xStreamWrapper::ns4xStreamWrapper(nsIOutputStream* stream)
NS_ASSERTION(stream != NULL, "bad stream");
fStream = stream;
-
NS_ADDREF(fStream);
memset(&fNPStream, 0, sizeof(fNPStream));
@@ -474,41 +447,42 @@ ns4xStreamWrapper::ns4xStreamWrapper(nsIOutputStream* stream)
ns4xStreamWrapper::~ns4xStreamWrapper(void)
{
fStream->Close();
-
NS_IF_RELEASE(fStream);
}
-nsIOutputStream*
-ns4xStreamWrapper::GetStream(void)
-{
- NS_IF_ADDREF(fStream);
- return fStream;
+void
+ns4xStreamWrapper::GetStream(nsIOutputStream* &result)
+{
+ result = fStream;
+ NS_IF_ADDREF(fStream);
}
////////////////////////////////////////////////////////////////////////
-nsresult NP_EXPORT
+NPError NP_EXPORT
ns4xPlugin::_newstream(NPP npp, NPMIMEType type, const char* window, NPStream* *result)
{
+ if(!npp)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
if (inst == NULL)
- return NS_ERROR_UNEXPECTED; // XXX
+ return NPERR_INVALID_INSTANCE_ERROR;
- nsresult error;
nsIOutputStream* stream;
nsIPluginInstancePeer *peer;
if (NS_OK == inst->GetPeer(&peer))
{
- if ((error = peer->NewStream((const char*) type, window, &stream)) != NS_OK)
+ if (peer->NewStream((const char*) type, window, &stream) != NS_OK)
{
NS_RELEASE(peer);
- return error;
+ return NPERR_GENERIC_ERROR;
}
ns4xStreamWrapper* wrapper = new ns4xStreamWrapper(stream);
@@ -517,58 +491,83 @@ ns4xPlugin::_newstream(NPP npp, NPMIMEType type, const char* window, NPStream* *
{
NS_RELEASE(peer);
NS_RELEASE(stream);
- return NS_ERROR_OUT_OF_MEMORY;
+ return NPERR_OUT_OF_MEMORY_ERROR;
}
(*result) = wrapper->GetNPStream();
NS_RELEASE(peer);
- return error;
+ return NPERR_NO_ERROR;
}
else
- return NS_ERROR_UNEXPECTED;
+ return NPERR_GENERIC_ERROR;
}
int32 NP_EXPORT
ns4xPlugin::_write(NPP npp, NPStream *pstream, int32 len, void *buffer)
{
- ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) pstream->ndata;
+ // negative return indicates failure to the plugin
+ if(!npp)
+ return -1;
- NS_ASSERTION(wrapper != NULL, "null wrapper");
+ ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) pstream->ndata;
+ NS_ASSERTION(wrapper != NULL, "null stream");
if (wrapper == NULL)
- return 0;
+ return -1;
- nsIOutputStream* stream = wrapper->GetStream();
+ nsIOutputStream* stream;
+ wrapper->GetStream(stream);
PRUint32 count = 0;
nsresult rv = stream->Write((char *)buffer, len, &count);
-
NS_RELEASE(stream);
+ if(rv != NS_OK)
+ return -1;
+
return (int32)count;
}
-nsresult NP_EXPORT
+NPError NP_EXPORT
ns4xPlugin::_destroystream(NPP npp, NPStream *pstream, NPError reason)
{
+ if(!npp)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ nsISupports* stream = (nsISupports*) pstream->ndata;
+ nsIPluginStreamListener* listener;
+
+ // DestroyStream can kill two kinds of streams: NPP derived and
+ // NPN derived.
+ // check to see if they're trying to kill a NPP stream
+ if(stream->QueryInterface(kIPluginStreamListenerIID, (void**)&listener) == NS_OK)
+ {
+ // XXX we should try to kill this listener here somehow
+ NS_RELEASE(listener);
+ return NPERR_NO_ERROR;
+ }
+
ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) pstream->ndata;
NS_ASSERTION(wrapper != NULL, "null wrapper");
if (wrapper == NULL)
- return 0;
+ return NPERR_INVALID_PARAM;
// This will release the wrapped nsIOutputStream.
delete wrapper;
- return NS_OK;
+ return NPERR_NO_ERROR;
}
void NP_EXPORT
ns4xPlugin::_status(NPP npp, const char *message)
{
+ if(!npp)
+ return;
+
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
@@ -588,7 +587,8 @@ ns4xPlugin::_status(NPP npp, const char *message)
void NP_EXPORT
ns4xPlugin::_memfree (void *ptr)
{
- mMalloc->Free(ptr);
+ if(ptr)
+ mMalloc->Free(ptr);
}
uint32 NP_EXPORT
@@ -608,6 +608,9 @@ ns4xPlugin::_reloadplugins(NPBool reloadPages)
void NP_EXPORT
ns4xPlugin::_invalidaterect(NPP npp, NPRect *invalidRect)
{
+ if(!npp)
+ return;
+
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
@@ -634,6 +637,9 @@ ns4xPlugin::_invalidaterect(NPP npp, NPRect *invalidRect)
void NP_EXPORT
ns4xPlugin::_invalidateregion(NPP npp, NPRegion invalidRegion)
{
+ if(!npp)
+ return;
+
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
@@ -660,6 +666,9 @@ ns4xPlugin::_invalidateregion(NPP npp, NPRegion invalidRegion)
void NP_EXPORT
ns4xPlugin::_forceredraw(NPP npp)
{
+ if(!npp)
+ return;
+
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
@@ -682,15 +691,18 @@ ns4xPlugin::_forceredraw(NPP npp)
}
}
-nsresult NP_EXPORT
+NPError NP_EXPORT
ns4xPlugin::_getvalue(NPP npp, NPNVariable variable, void *result)
{
+ if(!npp)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
if (inst == NULL)
- return NS_ERROR_FAILURE; // XXX
+ return NPERR_INVALID_INSTANCE_ERROR;
nsIPluginInstancePeer *peer;
@@ -705,18 +717,21 @@ ns4xPlugin::_getvalue(NPP npp, NPNVariable variable, void *result)
return rv;
}
else
- return NS_ERROR_UNEXPECTED;
+ return NPERR_GENERIC_ERROR;
}
-nsresult NP_EXPORT
+NPError NP_EXPORT
ns4xPlugin::_setvalue(NPP npp, NPPVariable variable, void *result)
{
+ if(!npp)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
ns4xPluginInstance *inst = (ns4xPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
if (inst == NULL)
- return NS_ERROR_FAILURE; // XXX
+ return NPERR_INVALID_INSTANCE_ERROR;
switch (variable)
{
@@ -727,7 +742,7 @@ ns4xPlugin::_setvalue(NPP npp, NPPVariable variable, void *result)
return inst->SetTransparent(*((NPBool *)result));
default:
- return NS_OK;
+ return NPERR_NO_ERROR;
}
#if 0
@@ -748,31 +763,10 @@ ns4xPlugin::_setvalue(NPP npp, NPPVariable variable, void *result)
#endif
}
-nsresult NP_EXPORT
+NPError NP_EXPORT
ns4xPlugin::_requestread(NPStream *pstream, NPByteRange *rangeList)
{
-#ifndef NEW_PLUGIN_STREAM_API
- nsIPluginStreamPeer* streamPeer = (nsIPluginStreamPeer*) pstream->ndata;
-
- NS_ASSERTION(streamPeer != NULL, "null streampeer");
-
- if (streamPeer == NULL)
- return NS_ERROR_FAILURE; // XXX
-
- nsISeekablePluginStreamPeer* seekablePeer = NULL;
-
- if (streamPeer->QueryInterface(kISeekablePluginStreamPeerIID,
- (void**)seekablePeer) == NS_OK)
- {
- nsresult error;
-
- // XXX nsByteRange & NPByteRange are structurally equivalent.
- error = seekablePeer->RequestRead((nsByteRange *)rangeList);
- NS_RELEASE(seekablePeer);
- return error;
- }
-#endif
- return NS_ERROR_UNEXPECTED;
+ return NPERR_STREAM_NOT_SEEKABLE;
}
diff --git a/mozilla/modules/plugin/base/src/ns4xPlugin.h b/mozilla/modules/plugin/base/src/ns4xPlugin.h
index 99466b0fda4..3f78a3b3588 100644
--- a/mozilla/modules/plugin/base/src/ns4xPlugin.h
+++ b/mozilla/modules/plugin/base/src/ns4xPlugin.h
@@ -54,6 +54,7 @@ class nsIAllocator;
class ns4xPlugin : public nsIPlugin
{
public:
+
ns4xPlugin(NPPluginFuncs* callbacks, NP_PLUGINSHUTDOWN aShutdown, nsIServiceManager* serviceMgr);
~ns4xPlugin(void);
@@ -69,13 +70,8 @@ public:
//nsIPlugin interface
-#ifndef NEW_PLUGIN_STREAM_API
- NS_IMETHOD
- Initialize(nsISupports* browserInterfaces);
-#else
NS_IMETHOD
Initialize(void);
-#endif
NS_IMETHOD
Shutdown(void);
@@ -109,36 +105,36 @@ protected:
// Static stub functions that are exported to the 4.x plugin as entry
// points via the CALLBACKS variable.
//
- static nsresult NP_EXPORT
+ static NPError NP_EXPORT
_requestread(NPStream *pstream, NPByteRange *rangeList);
- static nsresult NP_EXPORT
+ static NPError NP_EXPORT
_geturlnotify(NPP npp, const char* relativeURL, const char* target, void* notifyData);
- static nsresult NP_EXPORT
+ static NPError NP_EXPORT
_getvalue(NPP npp, NPNVariable variable, void *r_value);
- static nsresult NP_EXPORT
+ static NPError NP_EXPORT
_setvalue(NPP npp, NPPVariable variable, void *r_value);
- static nsresult NP_EXPORT
+ static NPError NP_EXPORT
_geturl(NPP npp, const char* relativeURL, const char* target);
- static nsresult NP_EXPORT
+ static NPError NP_EXPORT
_posturlnotify(NPP npp, const char* relativeURL, const char *target,
uint32 len, const char *buf, NPBool file, void* notifyData);
- static nsresult NP_EXPORT
+ static NPError NP_EXPORT
_posturl(NPP npp, const char* relativeURL, const char *target, uint32 len,
const char *buf, NPBool file);
- static nsresult NP_EXPORT
+ static NPError NP_EXPORT
_newstream(NPP npp, NPMIMEType type, const char* window, NPStream** pstream);
static int32 NP_EXPORT
_write(NPP npp, NPStream *pstream, int32 len, void *buffer);
- static nsresult NP_EXPORT
+ static NPError NP_EXPORT
_destroystream(NPP npp, NPStream *pstream, NPError reason);
static void NP_EXPORT
diff --git a/mozilla/modules/plugin/base/src/ns4xPluginInstance.cpp b/mozilla/modules/plugin/base/src/ns4xPluginInstance.cpp
index b5642b2faa6..bca13548f3b 100644
--- a/mozilla/modules/plugin/base/src/ns4xPluginInstance.cpp
+++ b/mozilla/modules/plugin/base/src/ns4xPluginInstance.cpp
@@ -17,20 +17,11 @@
*/
#include "ns4xPluginInstance.h"
-
-#ifdef NEW_PLUGIN_STREAM_API
#include "nsIPluginStreamListener.h"
-#else
-#include "ns4xPluginStream.h"
-#endif
#include "prlog.h"
+#include "prmem.h"
-////////////////////////////////////////////////////////////////////////
-//
-////////////////////////////////////////////////////////////////////////
-
-#ifdef NEW_PLUGIN_STREAM_API
class ns4xPluginStreamListener : public nsIPluginStreamListener {
@@ -42,24 +33,20 @@ public:
// from nsIPluginStreamListener:
NS_IMETHOD
- OnStartBinding(const char* url, nsIPluginStreamInfo* pluginInfo);
+ OnStartBinding(nsIPluginStreamInfo* pluginInfo);
NS_IMETHOD
- OnDataAvailable(const char* url, nsIInputStream* input,
- PRUint32 offset, PRUint32 length, nsIPluginStreamInfo* pluginInfo);
+ OnDataAvailable(nsIPluginStreamInfo* pluginInfo, nsIInputStream* input, PRUint32 length);
NS_IMETHOD
- OnFileAvailable(const char* url, const char* fileName);
+ OnFileAvailable( nsIPluginStreamInfo* pluginInfo, const char* fileName);
NS_IMETHOD
- OnStopBinding(const char* url, nsresult status, nsIPluginStreamInfo* pluginInfo);
+ OnStopBinding(nsIPluginStreamInfo* pluginInfo, nsresult status);
NS_IMETHOD
GetStreamType(nsPluginStreamType *result);
- NS_IMETHOD
- OnNotify(const char* url, nsresult status);
-
////////////////////////////////////////////////////////////////////////////
// ns4xPluginStreamListener specific methods:
@@ -69,12 +56,13 @@ public:
protected:
void* mNotifyData;
- ns4xPluginInstance* mInst;
- NPStream mNPStream;
- PRUint32 mPosition;
- nsPluginStreamType mStreamType;
+ ns4xPluginInstance* mInst;
+ NPStream mNPStream;
+ PRUint32 mPosition;
+ nsPluginStreamType mStreamType;
};
+
////////////////////////////////////////////////////////////////////////////////
// ns4xPluginStreamListener Methods
////////////////////////////////////////////////////////////////////////////////
@@ -102,16 +90,17 @@ ns4xPluginStreamListener::~ns4xPluginStreamListener(void)
NS_IMPL_ISUPPORTS(ns4xPluginStreamListener, kIPluginStreamListenerIID);
NS_IMETHODIMP
-ns4xPluginStreamListener::OnStartBinding(const char* url, nsIPluginStreamInfo* pluginInfo)
+ns4xPluginStreamListener::OnStartBinding(nsIPluginStreamInfo* pluginInfo)
{
NPP npp;
const NPPluginFuncs *callbacks;
PRBool seekable;
nsMIMEType contentType;
-
+ PRUint16 streamType = NP_NORMAL;
+ NPError error;
mNPStream.ndata = (void*) this;
- mNPStream.url = url;
+ pluginInfo->GetURL(&mNPStream.url);
mNPStream.notifyData = mNotifyData;
pluginInfo->GetLength((PRUint32*)&(mNPStream.end));
@@ -122,19 +111,36 @@ ns4xPluginStreamListener::OnStartBinding(const char* url, nsIPluginStreamInfo* p
mInst->GetCallbacks(&callbacks);
mInst->GetNPP(&npp);
- nsresult error
- = (nsresult)CallNPP_NewStreamProc(callbacks->newstream,
+ error = CallNPP_NewStreamProc(callbacks->newstream,
npp,
(char *)contentType,
&mNPStream,
seekable,
- (PRUint16*)&mStreamType);
+ &streamType);
+ if(error != NPERR_NO_ERROR)
+ return NS_ERROR_FAILURE;
+
+ // translate the old 4x style stream type to the new one
+ switch(streamType)
+ {
+ case NP_NORMAL : mStreamType = nsPluginStreamType_Normal; break;
+
+ case NP_ASFILEONLY : mStreamType = nsPluginStreamType_AsFileOnly; break;
+
+ case NP_ASFILE : mStreamType = nsPluginStreamType_AsFile; break;
+
+ case NP_SEEK : mStreamType = nsPluginStreamType_Seek; break;
+
+ default: return NS_ERROR_FAILURE;
+ }
+
return NS_OK;
}
NS_IMETHODIMP
-ns4xPluginStreamListener::OnDataAvailable(const char* url, nsIInputStream* input,
- PRUint32 /*offset*/, PRUint32 length, nsIPluginStreamInfo* pluginInfo)
+ns4xPluginStreamListener::OnDataAvailable(nsIPluginStreamInfo* pluginInfo,
+ nsIInputStream* input,
+ PRUint32 length)
{
const NPPluginFuncs *callbacks;
NPP npp;
@@ -142,17 +148,17 @@ ns4xPluginStreamListener::OnDataAvailable(const char* url, nsIInputStream* input
PRUint32 amountRead = 0;
PRInt32 writeCount = 0;
- mNPStream.url = url;
+ pluginInfo->GetURL(&mNPStream.url);
pluginInfo->GetLastModified((PRUint32*)&(mNPStream.lastmodified));
mInst->GetCallbacks(&callbacks);
mInst->GetNPP(&npp);
- if (callbacks->write == NULL)
+ if (callbacks->write == NULL || length == 0)
return NS_OK; // XXX ?
// Get the data from the input stream
- char* buffer = new char[length];
+ char* buffer = (char*) PR_Malloc(length);
if (buffer)
input->Read(buffer, length, &amountRead);
@@ -162,42 +168,46 @@ ns4xPluginStreamListener::OnDataAvailable(const char* url, nsIInputStream* input
// Write until the buffer is empty
while (amountRead > 0)
{
- if (callbacks->writeready != NULL)
- {
- numtowrite = CallNPP_WriteReadyProc(callbacks->writeready,
+ if (callbacks->writeready != NULL)
+ {
+ numtowrite = CallNPP_WriteReadyProc(callbacks->writeready,
npp,
&mNPStream);
- if (numtowrite > amountRead)
- numtowrite = amountRead;
- }
- else // if WriteReady is not supported by the plugin, just write the whole buffer
- numtowrite = length;
+ if (numtowrite > amountRead)
+ numtowrite = amountRead;
+ }
+ else // if WriteReady is not supported by the plugin, just write the whole buffer
+ numtowrite = length;
-
- writeCount = CallNPP_WriteProc(callbacks->write,
+ // if WriteReady returned 0, the plugin is not ready to handle the data,
+ // so just skip the Write until WriteReady returns a >0 value
+ if(numtowrite > 0)
+ {
+ writeCount = CallNPP_WriteProc(callbacks->write,
npp,
&mNPStream,
mPosition,
numtowrite,
(void *)buffer);
- if(writeCount < 0)
- return NS_ERROR_FAILURE;
+ if(writeCount < 0)
+ return NS_ERROR_FAILURE;
- amountRead -= numtowrite;
- mPosition += numtowrite;
+ amountRead -= numtowrite;
+ mPosition += numtowrite;
+ }
}
return NS_OK;
}
NS_IMETHODIMP
-ns4xPluginStreamListener::OnFileAvailable(const char* url, const char* fileName)
+ns4xPluginStreamListener::OnFileAvailable(nsIPluginStreamInfo* pluginInfo, const char* fileName)
{
const NPPluginFuncs *callbacks;
NPP npp;
- mNPStream.url = url;
+ pluginInfo->GetURL(&mNPStream.url);
mInst->GetCallbacks(&callbacks);
mInst->GetNPP(&npp);
@@ -214,12 +224,13 @@ ns4xPluginStreamListener::OnFileAvailable(const char* url, const char* fileName)
}
NS_IMETHODIMP
-ns4xPluginStreamListener::OnStopBinding(const char* url, nsresult status, nsIPluginStreamInfo* pluginInfo)
+ns4xPluginStreamListener::OnStopBinding(nsIPluginStreamInfo* pluginInfo, nsresult status)
{
const NPPluginFuncs *callbacks;
NPP npp;
+ NPError error;
- mNPStream.url = url;
+ pluginInfo->GetURL(&mNPStream.url);
pluginInfo->GetLastModified((PRUint32*)&(mNPStream.lastmodified));
mInst->GetCallbacks(&callbacks);
@@ -227,10 +238,23 @@ ns4xPluginStreamListener::OnStopBinding(const char* url, nsresult status, nsIPlu
if (callbacks->destroystream != NULL)
{
- CallNPP_DestroyStreamProc(callbacks->destroystream,
+ // XXX need to convert status to NPReason
+ error = CallNPP_DestroyStreamProc(callbacks->destroystream,
npp,
&mNPStream,
- nsPluginReason_Done);
+ NPRES_DONE);
+ if(error != NPERR_NO_ERROR)
+ return NS_ERROR_FAILURE;
+ }
+
+ // check to see if we have a call back
+ if (callbacks->urlnotify != NULL && mNotifyData != nsnull)
+ {
+ CallNPP_URLNotifyProc(callbacks->urlnotify,
+ npp,
+ mNPStream.url,
+ nsPluginReason_Done,
+ mNotifyData);
}
return NS_OK;
@@ -243,32 +267,6 @@ ns4xPluginStreamListener::GetStreamType(nsPluginStreamType *result)
return NS_OK;
}
-NS_IMETHODIMP
-ns4xPluginStreamListener::OnNotify(const char* url, nsresult status)
-{
- const NPPluginFuncs *callbacks;
- NPP npp;
-
- mNPStream.url = url;
-
- mInst->GetCallbacks(&callbacks);
- mInst->GetNPP(&npp);
-
- // check to see if we have a call back
- if (callbacks->urlnotify != NULL && mNotifyData != nsnull)
- {
- CallNPP_URLNotifyProc(callbacks->urlnotify,
- npp,
- url,
- nsPluginReason_Done,
- mNotifyData);
- }
-
- return NS_OK;
-}
-
-#endif
-
ns4xPluginInstance :: ns4xPluginInstance(NPPluginFuncs* callbacks)
: fCallbacks(callbacks)
{
@@ -293,6 +291,7 @@ ns4xPluginInstance :: ~ns4xPluginInstance(void)
NS_RELEASE(fPeer);
}
+
////////////////////////////////////////////////////////////////////////
NS_IMPL_ADDREF(ns4xPluginInstance);
@@ -332,19 +331,18 @@ NS_IMETHODIMP ns4xPluginInstance :: Initialize(nsIPluginInstancePeer* peer)
PRUint16 count = 0;
const char* const* names = nsnull;
const char* const* values = nsnull;
+ nsresult rv;
+ NPError error;
+ nsIPluginTagInfo* taginfo;
NS_ASSERTION(peer != NULL, "null peer");
fPeer = peer;
-
NS_ADDREF(fPeer);
- nsresult error;
- nsIPluginTagInfo *taginfo = nsnull;
+ rv = fPeer->QueryInterface(kIPluginTagInfoIID, (void **)&taginfo);
- error = fPeer->QueryInterface(kIPluginTagInfoIID, (void **)&taginfo);
-
- if (NS_OK == error)
+ if (NS_OK == rv)
{
taginfo->GetAttributes(count, names, values);
NS_IF_RELEASE(taginfo);
@@ -362,8 +360,7 @@ NS_IMETHODIMP ns4xPluginInstance :: Initialize(nsIPluginInstancePeer* peer)
fPeer->GetMode(&mode);
fPeer->GetMIMEType(&mimetype);
- error = (nsresult)
- CallNPP_NewProc(fCallbacks->newp,
+ error = CallNPP_NewProc(fCallbacks->newp,
(char *)mimetype,
&fNPP,
(PRUint16)mode,
@@ -372,7 +369,10 @@ NS_IMETHODIMP ns4xPluginInstance :: Initialize(nsIPluginInstancePeer* peer)
(char**)values,
NULL); // saved data
- return error;
+ if(error != NPERR_NO_ERROR)
+ rv = NS_ERROR_FAILURE;
+
+ return rv;
}
NS_IMETHODIMP ns4xPluginInstance :: GetPeer(nsIPluginInstancePeer* *resultingPeer)
@@ -400,7 +400,7 @@ printf("instance stop called\n");
NS_IMETHODIMP ns4xPluginInstance::Destroy(void)
{
- nsresult error;
+ NPError error;
printf("instance destroy called\n");
if (fCallbacks->destroy == NULL)
@@ -410,8 +410,11 @@ printf("instance destroy called\n");
error = (nsresult)CallNPP_DestroyProc(fCallbacks->destroy,
&fNPP, &sdata); // saved data
-
- return error;
+
+ if(error != NPERR_NO_ERROR)
+ return NS_ERROR_FAILURE;
+ else
+ return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::SetWindow(nsPluginWindow* window)
@@ -421,14 +424,14 @@ NS_IMETHODIMP ns4xPluginInstance::SetWindow(nsPluginWindow* window)
if (window == NULL)
return NS_OK;
- nsresult error = NS_OK;
+ NPError error;
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,
+ error = CallNPP_SetWindowProc(fCallbacks->setwindow,
&fNPP,
(NPWindow*) window);
@@ -436,15 +439,13 @@ NS_IMETHODIMP ns4xPluginInstance::SetWindow(nsPluginWindow* window)
// back from the plugin's SetWindow(). Is this the correct
// behavior?!?
- if (error != NS_OK)
+ if (error != NPERR_NO_ERROR)
printf("error in setwindow %d\n", error);
}
- return error;
+ return NS_OK;
}
-#ifdef NEW_PLUGIN_STREAM_API
-
/* NOTE: the caller must free the stream listener */
NS_IMETHODIMP ns4xPluginInstance::NewStream(nsIPluginStreamListener** listener)
@@ -470,33 +471,6 @@ nsresult ns4xPluginInstance::NewNotifyStream(nsIPluginStreamListener** listener,
return NS_OK;
}
-#else
-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;
-}
-#endif
-
NS_IMETHODIMP ns4xPluginInstance::Print(nsPluginPrint* platformPrint)
{
printf("instance print called\n");
@@ -511,23 +485,6 @@ printf("instance handleevent called\n");
return NS_OK;
}
-#ifndef NEW_PLUGIN_STREAM_API
-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...
-}
-#endif
-
NS_IMETHODIMP ns4xPluginInstance :: GetValue(nsPluginInstanceVariable variable, void *value)
{
nsresult rv = NS_OK;
diff --git a/mozilla/modules/plugin/base/src/ns4xPluginInstance.h b/mozilla/modules/plugin/base/src/ns4xPluginInstance.h
index f1b1c1ff39a..be9334d4df3 100644
--- a/mozilla/modules/plugin/base/src/ns4xPluginInstance.h
+++ b/mozilla/modules/plugin/base/src/ns4xPluginInstance.h
@@ -61,23 +61,12 @@ public:
NS_IMETHOD
SetWindow(nsPluginWindow* window);
-#ifdef NEW_PLUGIN_STREAM_API
NS_IMETHOD
NewStream(nsIPluginStreamListener** listener);
-#else
- NS_IMETHOD
- NewStream(nsIPluginStreamPeer* peer, nsIPluginStream* *result);
-#endif
NS_IMETHOD
Print(nsPluginPrint* platformPrint);
-#ifndef NEW_PLUGIN_STREAM_API
- NS_IMETHOD
- URLNotify(const char* url, const char* target,
- nsPluginReason reason, void* notifyData);
-#endif
-
NS_IMETHOD
GetValue(nsPluginInstanceVariable variable, void *value);
diff --git a/mozilla/modules/plugin/base/src/nsIPluginHost.h b/mozilla/modules/plugin/base/src/nsIPluginHost.h
index a96e10654e5..b097dceb7d3 100644
--- a/mozilla/modules/plugin/base/src/nsIPluginHost.h
+++ b/mozilla/modules/plugin/base/src/nsIPluginHost.h
@@ -50,7 +50,7 @@ public:
GetPluginFactory(const char *aMimeType, nsIPlugin** aPlugin) = 0;
NS_IMETHOD
- InstantiateEmbededPlugin(const char *aMimeType, nsString& aURLSpec, nsIPluginInstanceOwner *aOwner) = 0;
+ InstantiateEmbededPlugin(const char *aMimeType, nsIURL* aURL, nsIPluginInstanceOwner *aOwner) = 0;
NS_IMETHOD
InstantiateFullPagePlugin(const char *aMimeType, nsString& aURLSpec, nsIStreamListener *&aStreamListener, nsIPluginInstanceOwner *aOwner) = 0;
diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp
index 2fe075eed98..57d6011d75b 100644
--- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp
+++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp
@@ -23,15 +23,11 @@
#include "ns4xPlugin.h"
#include "nsPluginInstancePeer.h"
-#ifdef NEW_PLUGIN_STREAM_API
#include "nsIPluginStreamListener.h"
-#else
-#include "nsPluginStreamPeer.h"
-#endif
-
#include "nsIStreamListener.h"
#include "nsIURL.h"
#include "nsIInputStream.h"
+#include "nsIOutputStream.h"
#include "nsINetService.h"
#include "nsIServiceManager.h"
#include "prprf.h"
@@ -66,11 +62,7 @@ static NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID);
static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID);
static NS_DEFINE_IID(kIPluginManager2IID, NS_IPLUGINMANAGER2_IID);
static NS_DEFINE_IID(kIPluginHostIID, NS_IPLUGINHOST_IID);
-#ifdef NEW_PLUGIN_STREAM_API
static NS_DEFINE_IID(kIPluginStreamInfoIID, NS_IPLUGINSTREAMINFO_IID);
-#else
-static NS_DEFINE_IID(kIPluginStreamPeerIID, NS_IPLUGINSTREAMPEER_IID);
-#endif
static NS_DEFINE_CID(kPluginCID, NS_PLUGIN_CID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
@@ -79,6 +71,7 @@ static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
static NS_DEFINE_IID(kINetServiceIID, NS_INETSERVICE_IID);
static NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID);
static NS_DEFINE_IID(kIFileUtilitiesIID, NS_IFILEUTILITIES_IID);
+static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
nsPluginTag :: nsPluginTag()
{
@@ -156,8 +149,6 @@ nsPluginTag :: ~nsPluginTag()
}
}
-#ifdef NEW_PLUGIN_STREAM_API
-
class nsPluginStreamInfo : public nsIPluginStreamInfo
{
public:
@@ -181,26 +172,33 @@ public:
NS_IMETHOD
GetLastModified(PRUint32* result);
+ NS_IMETHOD
+ GetURL(const char** result);
+
NS_IMETHOD
RequestRead(nsByteRange* rangeList);
// local methods
void
- SetContentType(const nsMIMEType result);
+ SetContentType(const nsMIMEType contentType);
void
- SetSeekable(const PRBool result);
+ SetSeekable(const PRBool seekable);
void
- SetLength(const PRUint32 result);
+ SetLength(const PRUint32 length);
void
- SetLastModified(const PRUint32 result);
+ SetLastModified(const PRUint32 modified);
+
+ void
+ SetURL(const char* url);
private:
char* mContentType;
+ char* mURL;
PRBool mSeekable;
PRUint32 mLength;
PRUint32 mModified;
@@ -211,6 +209,7 @@ nsPluginStreamInfo::nsPluginStreamInfo()
NS_INIT_REFCNT();
mContentType = nsnull;
+ mURL = nsnull;
mSeekable = PR_FALSE;
mLength = 0;
mModified = 0;
@@ -220,6 +219,8 @@ nsPluginStreamInfo::~nsPluginStreamInfo()
{
if(mContentType != nsnull)
PL_strfree(mContentType);
+ if(mURL != nsnull)
+ PL_strfree(mURL);
}
NS_IMPL_ADDREF(nsPluginStreamInfo)
@@ -278,6 +279,13 @@ nsPluginStreamInfo::GetLastModified(PRUint32* result)
return NS_OK;
}
+NS_IMETHODIMP
+nsPluginStreamInfo::GetURL(const char** result)
+{
+ *result = mURL;
+ return NS_OK;
+}
+
NS_IMETHODIMP
nsPluginStreamInfo::RequestRead(nsByteRange* rangeList)
{
@@ -313,7 +321,18 @@ nsPluginStreamInfo::SetLastModified(const PRUint32 modified)
mModified = modified;
}
-#endif
+void
+nsPluginStreamInfo::SetURL(const char* url)
+{
+ if(mURL != nsnull)
+ PL_strfree(mURL);
+
+ mURL = PL_strdup(url);
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+class nsPluginCacheListener;
class nsPluginStreamListenerPeer : public nsIStreamListener
{
@@ -333,71 +352,283 @@ public:
NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg);
- //NS_IMETHOD OnNotify(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg);
-
//nsIStreamListener interface
NS_IMETHOD GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* aInfo);
- NS_IMETHOD OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream,
- PRUint32 aLength);
+ NS_IMETHOD OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream, PRUint32 aLength);
//locals
// Called by GetURL and PostURL (via NewStream)
-#ifdef NEW_PLUGIN_STREAM_API
nsresult Initialize(nsIURL *aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener);
-#else
- nsresult Initialize(nsIURL *aURL, nsIPluginInstance *aInstance, void *aNotifyData);
-#endif
nsresult InitializeEmbeded(nsIURL *aURL, nsIPluginInstance* aInstance, nsIPluginInstanceOwner *aOwner = nsnull,
nsIPluginHost *aHost = nsnull);
nsresult InitializeFullPage(nsIPluginInstance *aInstance);
+ nsresult OnFileAvailable(const char* aFilename);
+
private:
-#ifdef NEW_PLUGIN_STREAM_API
nsresult SetUpCache(nsIURL* aURL);
nsresult SetUpStreamListener(nsIURL* aURL);
-#else
- nsresult SetUpStreamPeer(nsIURL* aURL, nsIPluginInstance *instance,
- const char* aContentType, PRInt32 aProgressMax = 0);
-#endif
nsIURL *mURL;
nsIPluginInstanceOwner *mOwner;
nsIPluginInstance *mInstance;
-#ifdef NEW_PLUGIN_STREAM_API
nsIPluginStreamListener *mPStreamListener;
nsPluginStreamInfo *mPluginStreamInfo;
PRBool mSetUpListener;
-#else
- nsPluginStreamPeer *mPeer;
- nsIPluginStream *mStream;
- void *mNotifyData;
-#endif // NEW_PLUGIN_STREAM_API
// these get passed to the plugin stream listener
char *mMIMEType;
PRUint32 mLength;
nsPluginStreamType mStreamType;
-
- PRUint8 *mBuffer;
- PRUint32 mBufSize;
nsIPluginHost *mHost;
PRBool mGotProgress;
PRBool mOnStartBinding;
+ PRBool mCacheDone;
+ PRBool mOnStopBinding;
+ nsresult mStatus;
+
#ifdef USE_CACHE
nsCacheObject* mCachedFile;
#else
FILE* mStreamFile;
+ char* mFileName;
#endif
};
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+class nsPluginCacheListener : public nsIStreamListener
+{
+public:
+ nsPluginCacheListener(nsPluginStreamListenerPeer* aListener);
+ ~nsPluginCacheListener();
+
+ NS_DECL_ISUPPORTS
+
+ //nsIStreamObserver interface
+
+ NS_IMETHOD OnStartBinding(nsIURL* aURL, const char *aContentType);
+
+ NS_IMETHOD OnProgress(nsIURL* aURL, PRUint32 aProgress, PRUint32 aProgressMax);
+
+ NS_IMETHOD OnStatus(nsIURL* aURL, const PRUnichar* aMsg);
+
+ NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg);
+
+ //nsIStreamListener interface
+
+ NS_IMETHOD GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* aInfo);
+
+ NS_IMETHOD OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream, PRUint32 aLength);
+
+private:
+
+ nsPluginStreamListenerPeer* mListener;
+
+#ifdef USE_CACHE
+ nsCacheObject* mCachedFile;
+#else
+ FILE* mStreamFile;
+ char* mFileName;
+#endif
+};
+
+nsPluginCacheListener :: nsPluginCacheListener(nsPluginStreamListenerPeer* aListener)
+{
+ NS_INIT_REFCNT();
+
+ mListener = aListener;
+ NS_ADDREF(mListener);
+
+#ifdef USE_CACHE
+ mCachedFile = nsnull;
+#else
+ mStreamFile = nsnull;
+ mFileName = nsnull;
+#endif
+}
+
+nsPluginCacheListener :: ~nsPluginCacheListener()
+{
+
+ NS_IF_RELEASE(mListener);
+
+#ifdef USE_CACHE
+ if (nsnull != mCachedFile)
+ {
+ delete mCachedFile;
+ mCachedFile = nsnull;
+ }
+#else // USE_CACHE
+ if(nsnull != mStreamFile)
+ {
+ fclose(mStreamFile);
+ mStreamFile = nsnull;
+ }
+
+ if(nsnull != mFileName)
+ PL_strfree(mFileName);
+#endif // USE_CACHE
+}
+
+NS_IMPL_ISUPPORTS(nsPluginCacheListener, kIStreamListenerIID);
+
+NS_IMETHODIMP
+nsPluginCacheListener::OnStartBinding(nsIURL* aURL, const char *aContentType)
+{
+#ifdef USE_CACHE
+ nsString urlString;
+ char* cString;
+ char* fileName;
+
+ aURL->ToString(urlString);
+ cString = urlString.ToNewCString();
+ mCachedFile = new nsCacheObject(cString);
+ delete [] cString;
+
+ if(mCachedFile == nsnull)
+ return NS_ERROR_OUT_OF_MEMORY;
+
+ // use the actual filename of the net-based file as the cache filename
+ aURL->GetFile(fileName);
+ mCachedFile->Filename(fileName);
+
+ nsCacheManager* cacheManager = nsCacheManager::GetInstance();
+ nsDiskModule* diskCache = cacheManager->GetDiskModule();
+ diskCache->AddObject(mCachedFile);
+#else // USE_CACHE
+ char buf[400], tpath[300];
+#ifdef XP_PC
+ ::GetTempPath(sizeof(tpath), tpath);
+ PRInt32 len = PL_strlen(tpath);
+
+ if((len > 0) && (tpath[len-1] != '\\'))
+ {
+ tpath[len] = '\\';
+ tpath[len+1] = 0;
+ }
+#elif defined (XP_UNIX)
+ PL_strcpy(tpath, "/tmp/");
+#else
+ tpath[0] = 0;
+#endif // XP_PC
+ const char* pathName;
+ char* fileName;
+ aURL->GetFile(&pathName);
+
+ // since GetFile actually returns us the full path, move to the last \ and skip it
+ fileName = PL_strrchr(pathName, '/');
+ if(fileName)
+ ++fileName;
+
+ // if we don't get a filename for some reason, just make one up using the address of this
+ // object to ensure uniqueness of the filename per stream
+ if(!fileName)
+ PR_snprintf(buf, sizeof(buf), "%s%08X.ngl", tpath, this);
+ else
+ PR_snprintf(buf, sizeof(buf), "%s%s", tpath, fileName);
+
+ mStreamFile = fopen(buf, "wb");
+ //setbuf(mStreamFile, NULL);
+
+ mFileName = PL_strdup(buf);
+#endif // USE_CACHE
+ return NS_OK;
+
+}
+
+NS_IMETHODIMP
+nsPluginCacheListener::OnProgress(nsIURL* aURL, PRUint32 aProgress, PRUint32 aProgressMax)
+{
+ return NS_OK;
+}
+
+
+NS_IMETHODIMP
+nsPluginCacheListener::OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream, PRUint32 aLength)
+{
+ PRUint32 readlen;
+ char* buffer = (char*) PR_Malloc(aLength);
+ if(buffer)
+ aIStream->Read(buffer, aLength, &readlen);
+ else
+ return NS_ERROR_OUT_OF_MEMORY;
+
+ NS_ASSERTION(aLength == readlen, "nsCacheListener->OnDataAvailable: readlen != aLength");
+
+#ifdef USE_CACHE
+ if(nsnull != mCachedFile)
+ mCachedFile->Write((char*)buffer, readlen);
+#else
+ if(nsnull != mStreamFile)
+ fwrite(buffer, sizeof(char), readlen, mStreamFile);
+#endif // USE_CACHE
+ PR_Free(buffer);
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsPluginCacheListener::OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg)
+{
+#ifdef USE_CACHE
+ if (nsnull != mCachedFile)
+ {
+ PRInt32 len;
+ nsCachePref* cachePref = nsCachePref::GetInstance();
+
+ const char* cachePath = cachePref->DiskCacheFolder();
+ const char* filename = mCachedFile->Filename();
+
+ // we need to pass the whole path and filename to the plugin
+ len = PL_strlen(cachePath) + PL_strlen(filename) + 1;
+ char* pathAndFilename = (char*)PR_Malloc(len * sizeof(char));
+ pathAndFilename = PL_strcpy(pathAndFilename, cachePath);
+ pathAndFilename = PL_strcat(pathAndFilename, filename);
+
+ const char* urlString;
+ aURL->GetSpec(&urlString);
+
+ if (mListener)
+ mListener->OnFileAvailable(pathAndFilename);
+ }
+#else // USE_CACHE
+ if(nsnull != mStreamFile)
+ {
+ fclose(mStreamFile);
+ mStreamFile = nsnull;
+
+ if (mListener)
+ mListener->OnFileAvailable(mFileName);
+ }
+#endif // USE_CACHE
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsPluginCacheListener::GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* aInfo)
+{
+ // not used
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsPluginCacheListener::OnStatus(nsIURL* aURL, const PRUnichar* aMsg)
+{
+ // not used
+ return NS_OK;
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////
+
nsPluginStreamListenerPeer :: nsPluginStreamListenerPeer()
{
NS_INIT_REFCNT();
@@ -405,30 +636,23 @@ nsPluginStreamListenerPeer :: nsPluginStreamListenerPeer()
mURL = nsnull;
mOwner = nsnull;
mInstance = nsnull;
-
-#ifdef NEW_PLUGIN_STREAM_API
mPStreamListener = nsnull;
mPluginStreamInfo = nsnull;
mSetUpListener = PR_FALSE;
-#else
- mPeer = nsnull;
- mStream = nsnull;
- mNotifyData = nsnull;
- mMIMEType = nsnull;
- mLength = 0;
-#endif // NEW_PLUGIN_STREAM_API
-
- mBuffer = nsnull;
- mBufSize = 0;
mHost = nsnull;
mGotProgress = PR_FALSE;
mOnStartBinding = PR_FALSE;
mStreamType = nsPluginStreamType_Normal;
+ mOnStopBinding = PR_FALSE;
+ mCacheDone = PR_FALSE;
+ mStatus = NS_OK;
+
#ifdef USE_CACHE
mCachedFile = nsnull;
#else
mStreamFile = nsnull;
+ mFileName = nsnull;
#endif
}
@@ -446,27 +670,7 @@ nsPluginStreamListenerPeer :: ~nsPluginStreamListenerPeer()
NS_IF_RELEASE(mURL);
NS_IF_RELEASE(mOwner);
NS_IF_RELEASE(mInstance);
-
-#ifdef NEW_PLUGIN_STREAM_API
NS_IF_RELEASE(mPStreamListener);
-#else
- NS_IF_RELEASE(mStream);
- NS_IF_RELEASE(mPeer);
- mNotifyData = nsnull;
-
- if (nsnull != mMIMEType)
- {
- PR_Free(mMIMEType);
- mMIMEType = nsnull;
- }
-#endif // NEW_PLUGIN_STREAM_API
-
- if (nsnull != mBuffer)
- {
- PR_Free(mBuffer);
- mBuffer = nsnull;
- }
-
NS_IF_RELEASE(mHost);
#ifdef USE_CACHE
@@ -481,11 +685,15 @@ nsPluginStreamListenerPeer :: ~nsPluginStreamListenerPeer()
fclose(mStreamFile);
mStreamFile = nsnull;
}
+
+ if(nsnull != mFileName)
+ PL_strfree(mFileName);
+
#endif // USE_CACHE
}
-NS_IMPL_ADDREF(nsPluginStreamListenerPeer)
-NS_IMPL_RELEASE(nsPluginStreamListenerPeer)
+NS_IMPL_ADDREF(nsPluginStreamListenerPeer);
+NS_IMPL_RELEASE(nsPluginStreamListenerPeer);
nsresult nsPluginStreamListenerPeer :: QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
@@ -519,8 +727,6 @@ nsresult nsPluginStreamListenerPeer :: QueryInterface(const nsIID& aIID,
return NS_NOINTERFACE;
}
-#ifdef NEW_PLUGIN_STREAM_API
-
/* Called as a result of GetURL and PostURL */
nsresult nsPluginStreamListenerPeer :: Initialize(nsIURL *aURL, nsIPluginInstance *aInstance,
@@ -542,35 +748,10 @@ nsresult nsPluginStreamListenerPeer :: Initialize(nsIURL *aURL, nsIPluginInstanc
NS_ADDREF(mPStreamListener);
mPluginStreamInfo = new nsPluginStreamInfo();
- //mPStreamListener->GetStreamType(&mStreamType);
return NS_OK;
}
-#else
-
-/* Called as a result of GetURL and PostURL - NewPluginURLStream() */
-
-nsresult nsPluginStreamListenerPeer :: Initialize(nsIURL *aURL, nsIPluginInstance *aInstance, void *aNotifyData)
-{
-#ifdef NS_DEBUG
- const char* spec;
- (void)aURL->GetSpec(&spec);
- printf("created stream for %s\n", spec);
-#endif
- mURL = aURL;
- NS_ADDREF(mURL);
-
- mInstance = aInstance;
- NS_ADDREF(mInstance);
-
- mNotifyData = aNotifyData;
-
- return NS_OK;
-}
-
-#endif
-
/*
Called by NewEmbededPluginStream() - if this is called, we weren't able to load the plugin,
so we need to load it later once we figure out the mimetype. In order to load it later,
@@ -604,9 +785,7 @@ nsresult nsPluginStreamListenerPeer :: InitializeEmbeded(nsIURL *aURL, nsIPlugin
NS_IF_ADDREF(mHost);
}
-#ifdef NEW_PLUGIN_STREAM_API
mPluginStreamInfo = new nsPluginStreamInfo();
-#endif
return NS_OK;
}
@@ -622,9 +801,7 @@ nsresult nsPluginStreamListenerPeer :: InitializeFullPage(nsIPluginInstance *aIn
mInstance = aInstance;
NS_ADDREF(mInstance);
-#ifdef NEW_PLUGIN_STREAM_API
mPluginStreamInfo = new nsPluginStreamInfo();
-#endif
return NS_OK;
}
@@ -635,19 +812,7 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnStartBinding(nsIURL* aURL, const cha
nsresult rv = NS_OK;
if (nsnull != aContentType)
- {
-#ifdef NEW_PLUGIN_STREAM_API
- mPluginStreamInfo->SetContentType(aContentType);
-#else
- PRInt32 len = PL_strlen(aContentType);
- mMIMEType = (char *)PR_Malloc(len + 1);
-
- if (nsnull != mMIMEType)
- PL_strcpy(mMIMEType, aContentType);
- else
- rv = NS_ERROR_OUT_OF_MEMORY;
-#endif
- }
+ mPluginStreamInfo->SetContentType(aContentType);
nsPluginWindow *window = nsnull;
@@ -680,15 +845,10 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnStartBinding(nsIURL* aURL, const cha
}
}
-#ifdef NEW_PLUGIN_STREAM_API
// only set up the stream listener if we have both the mimetype and
// have mLength set (as indicated by the mGotProgress bool)
if(mGotProgress == PR_TRUE && mSetUpListener == PR_FALSE)
rv = SetUpStreamListener(aURL);
-#else
- if ((PR_TRUE == mGotProgress) && (nsnull == mPeer) && (nsnull != mInstance))
- rv = SetUpStreamPeer(aURL, mInstance, aContentType);
-#endif
mOnStartBinding = PR_TRUE;
return rv;
@@ -699,34 +859,9 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnProgress(nsIURL* aURL, PRUint32 aP
{
nsresult rv = NS_OK;
-#ifdef NEW_PLUGIN_STREAM_API
-
mPluginStreamInfo->SetLength(aProgressMax);
- // if OnStartBinding already got called,
if(mOnStartBinding == PR_TRUE && mSetUpListener == PR_FALSE)
rv = SetUpStreamListener(aURL);
-#else
-
- mLength = aProgressMax;
- if ((aProgress == 0) && (nsnull == mPeer))
- {
- nsIPluginInstance *instance = nsnull;
-
- if (nsnull == mInstance)
- mOwner->GetInstance(instance);
- else
- {
- instance = mInstance;
- NS_ADDREF(instance);
- }
-
- if (nsnull != instance)
- {
- rv = SetUpStreamPeer(aURL, instance, nsnull, aProgressMax);
- NS_RELEASE(instance);
- }
- }
-#endif
mGotProgress = PR_TRUE;
@@ -746,41 +881,45 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: GetBindInfo(nsIURL* aURL, nsStreamBi
NS_IMETHODIMP nsPluginStreamListenerPeer :: OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream,
PRUint32 aLength)
{
-#ifdef NEW_PLUGIN_STREAM_API
- nsresult rv;
+ nsresult rv = NS_OK;
const char* url;
- aURL->GetSpec(&url);
- rv = mPStreamListener->OnDataAvailable(url, aIStream, 0, aLength,(nsIPluginStreamInfo*)mPluginStreamInfo);
- return rv;
-#else
- if (aLength > mBufSize)
- {
- if (nsnull != mBuffer)
- PR_Free((void *)mBuffer);
+ char* buffer;
+ PRUint32 readlen;
- mBuffer = (PRUint8 *)PR_Malloc(aLength);
- mBufSize = aLength;
- }
+ if(!mPStreamListener)
+ return NS_ERROR_FAILURE;
- if ((nsnull != mBuffer) && (nsnull != mStream))
- {
- PRUint32 readlen;
- aIStream->Read((char *)mBuffer, 0, aLength, &readlen);
+ const char* urlString;
+ aURL->GetSpec(&urlString);
+ mPluginStreamInfo->SetURL(urlString);
+
+#if 0
+ // determine if we need to write the data to the cache
+ if((mStreamType == nsPluginStreamType_AsFile) || (mStreamType == nsPluginStreamType_AsFileOnly))
+ {
+ buffer = (char*) PR_Malloc(aLength);
+ if(buffer)
+ aIStream->Read(buffer, aLength, &readlen);
#ifdef USE_CACHE
if(nsnull != mCachedFile)
- mCachedFile->Write((char*)mBuffer, aLength);
+ mCachedFile->Write((char*)buffer, aLength);
#else
if(nsnull != mStreamFile)
- fwrite(mBuffer, 1, aLength, mStreamFile);
+ fwrite(buffer, sizeof(char), aLength, mStreamFile);
+#endif // USE_CACHE
+ PR_Free(buffer);
+ }
#endif
- if (mStreamType != nsPluginStreamType_AsFileOnly)
- mStream->Write((char *)mBuffer, 0, aLength, &readlen);
- }
+ // if the plugin has requested an AsFileOnly stream, then don't call OnDataAvailable
+ if(mStreamType != nsPluginStreamType_AsFileOnly)
+ {
+ aURL->GetSpec(&url);
+ rv = mPStreamListener->OnDataAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, aIStream, aLength);
+ }
- return NS_OK;
-#endif // NEW_PLUGIN_STREAM_API
+ return rv;
}
NS_IMETHODIMP nsPluginStreamListenerPeer :: OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg)
@@ -788,32 +927,20 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnStopBinding(nsIURL* aURL, nsresult
nsresult rv = NS_OK;
nsPluginReason reason = nsPluginReason_NoReason;
- //XXX this is incomplete... MMP
-#ifndef NEW_PLUGIN_STREAM_API
- if (nsnull != mPeer)
- {
- if (aStatus == NS_BINDING_SUCCEEDED)
- reason = nsPluginReason_Done;
- else
- reason = nsPluginReason_UserBreak;
-
- mPeer->SetReason(reason);
-
- rv = NS_OK;
- }
- else
- rv = NS_ERROR_UNEXPECTED;
-#endif
-
-#ifdef NEW_PLUGIN_STREAM_API
if(nsnull != mPStreamListener)
-#else
- if (nsnull != mStream)
-#endif // NEW_PLUGIN_STREAM_API
{
+ const char* url;
+ aURL->GetSpec(&url);
+
+ const char* urlString;
+ aURL->GetSpec(&urlString);
+ mPluginStreamInfo->SetURL(urlString);
+
+#if 0
+ // see if we need to close out the cache
if ((mStreamType == nsPluginStreamType_AsFile) ||
(mStreamType == nsPluginStreamType_AsFileOnly))
- {
+ {
#ifdef USE_CACHE
if (nsnull != mCachedFile)
{
@@ -828,110 +955,45 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnStopBinding(nsIURL* aURL, nsresult
char* pathAndFilename = (char*)PR_Malloc(len * sizeof(char));
pathAndFilename = PL_strcpy(pathAndFilename, cachePath);
pathAndFilename = PL_strcat(pathAndFilename, filename);
-#ifdef NEW_PLUGIN_STREAM_API
+
const char* urlString;
aURL->GetSpec(&urlString);
if (mPStreamListener)
- mPStreamListener->OnFileAvailable(urlString, pathAndFilename);
-#else
- mStream->AsFile(pathAndFilename);
-#endif // NEW_PLUGIN_STREAM_API
- }
+ mPStreamListener->OnFileAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, pathAndFilename);
+ }
#else // USE_CACHE
if(nsnull != mStreamFile)
- {
+ {
fclose(mStreamFile);
mStreamFile = nsnull;
- char buf[400], tpath[300];
-#ifdef XP_PC
- ::GetTempPath(sizeof(tpath), tpath);
- PRInt32 len = PL_strlen(tpath);
-
- if((len > 0) && (tpath[len-1] != '\\'))
- {
- tpath[len] = '\\';
- tpath[len+1] = 0;
- }
-#elif defined (XP_UNIX)
- PL_strcpy(tpath, "/tmp/");
-#else
- tpath[0] = 0;
-#endif // XP_PC
- PR_snprintf(buf, sizeof(buf), "%s%08X.ngl", tpath, this);
-#ifdef NEW_PLUGIN_STREAM_API
- const char* urlString;
- aURL->GetSpec(&urlString);
if (mPStreamListener)
- mPStreamListener->OnFileAvailable(urlString, buf);
-#else
- mStream->AsFile(buf);
-#endif // NEW_PLUGIN_STREAM_API
- }
+ mPStreamListener->OnFileAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, mFileName);
+ }
#endif // USE_CACHE
}
+#endif
-#ifdef NEW_PLUGIN_STREAM_API
- const char* url;
- aURL->GetSpec(&url);
- if (mPStreamListener)
- {
- mPStreamListener->OnStopBinding(url, aStatus, (nsIPluginStreamInfo*)mPluginStreamInfo);
- mPStreamListener->OnNotify(url, aStatus);
- }
-#else
- nsIPluginInstance *instance = nsnull;
-
- if (nsnull == mInstance)
- mOwner->GetInstance(instance);
- else
- {
- instance = mInstance;
- NS_ADDREF(instance);
- }
-
- mStream->Close();
-
- if (nsnull != instance)
- {
- if (nsnull != mNotifyData)
- {
- const char *url;
-
- if (nsnull != mURL)
- rv = mURL->GetSpec(&url);
- else
- url = "";
-
- //XXX target is bad. MMP
- if (url)
- instance->URLNotify(url, "", reason, mNotifyData);
- }
-
- NS_RELEASE(instance);
- }
-#endif // NEW_PLUGIN_STREAM_API
+ // tell the plugin that the stream has ended only if the cache is done
+ if(mCacheDone)
+ mPStreamListener->OnStopBinding((nsIPluginStreamInfo*)mPluginStreamInfo, aStatus);
+ else // otherwise, we store the status so we can report it later in OnFileAvailable
+ mStatus = aStatus;
}
+ mOnStopBinding = PR_TRUE;
return rv;
}
-
-/*NS_IMETHODIMP nsPluginStreamListenerPeer :: OnNotify(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg)
-{
- return NS_OK;
-}*/
-
-
// private methods for nsPluginStreamListenerPeer
-#ifdef NEW_PLUGIN_STREAM_API
-
nsresult nsPluginStreamListenerPeer::SetUpCache(nsIURL* aURL)
{
+#if 0
#ifdef USE_CACHE
nsString urlString;
char* cString;
+ char* fileName;
aURL->ToString(urlString);
cString = urlString.ToNewCString();
@@ -942,12 +1004,14 @@ nsresult nsPluginStreamListenerPeer::SetUpCache(nsIURL* aURL)
return NS_ERROR_OUT_OF_MEMORY;
// use the actual filename of the net-based file as the cache filename
- mCachedFile->Filename(aURL->GetFile());
+ aURL->GetFile(fileName);
+ mCachedFile->Filename(fileName);
nsCacheManager* cacheManager = nsCacheManager::GetInstance();
nsDiskModule* diskCache = cacheManager->GetDiskModule();
diskCache->AddObject(mCachedFile);
#else // USE_CACHE
+
char buf[400], tpath[300];
#ifdef XP_PC
::GetTempPath(sizeof(tpath), tpath);
@@ -963,10 +1027,32 @@ nsresult nsPluginStreamListenerPeer::SetUpCache(nsIURL* aURL)
#else
tpath[0] = 0;
#endif // XP_PC
- PR_snprintf(buf, sizeof(buf), "%s%08X.ngl", tpath, this);
+ const char* pathName;
+ char* fileName;
+ aURL->GetFile(&pathName);
+
+ // since GetFile actually returns us the full path, move to the last \ and skip it
+ fileName = PL_strrchr(pathName, '/');
+ if(fileName)
+ ++fileName;
+
+ // if we don't get a filename for some reason, just make one up using the address of this
+ // object to ensure uniqueness of the filename per stream
+ if(!fileName)
+ PR_snprintf(buf, sizeof(buf), "%s%08X.ngl", tpath, this);
+ else
+ PR_snprintf(buf, sizeof(buf), "%s%s", tpath, fileName);
+
mStreamFile = fopen(buf, "wb");
+ //setbuf(mStreamFile, NULL);
+
+ mFileName = PL_strdup(buf);
#endif // USE_CACHE
return NS_OK;
+#endif
+
+ nsPluginCacheListener* cacheListener = new nsPluginCacheListener(this);
+ return NS_OpenURL(aURL, cacheListener);
}
nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIURL* aURL)
@@ -987,88 +1073,41 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIURL* aURL)
return NS_ERROR_NULL_POINTER;
mSetUpListener = PR_TRUE;
-
- mPStreamListener->GetStreamType(&mStreamType);
- if ((mStreamType == nsPluginStreamType_AsFile) ||
- (mStreamType == nsPluginStreamType_AsFileOnly))
- SetUpCache(aURL);
-
mPluginStreamInfo->SetSeekable(PR_FALSE);
//mPluginStreamInfo->SetModified(??);
const char* urlString;
aURL->GetSpec(&urlString);
- return mPStreamListener->OnStartBinding(urlString, (nsIPluginStreamInfo*)mPluginStreamInfo);
-}
+ mPluginStreamInfo->SetURL(urlString);
-#else
+ rv = mPStreamListener->OnStartBinding((nsIPluginStreamInfo*)mPluginStreamInfo);
-nsresult nsPluginStreamListenerPeer::SetUpStreamPeer(nsIURL* aURL, nsIPluginInstance *instance,
- const char* aContentType, PRInt32 aProgressMax)
-{
- mPeer = (nsPluginStreamPeer *)new nsPluginStreamPeer();
- if(mPeer == nsnull)
- return NS_ERROR_OUT_OF_MEMORY;
- NS_ADDREF(mPeer);
-
- if(aContentType != nsnull)
- mPeer->Initialize(aURL, mLength, 0, aContentType, mNotifyData);
- else
- mPeer->Initialize(aURL, aProgressMax, 0, mMIMEType, mNotifyData);
-
- instance->NewStream(mPeer, &mStream);
-
- if (nsnull != mStream)
- mStream->GetStreamType(&mStreamType);
-
- // check to see if we need to cache the file
- if ((mStreamType == nsPluginStreamType_AsFile) ||
- (mStreamType == nsPluginStreamType_AsFileOnly))
- {
-#ifdef USE_CACHE
- nsString urlString;
- char* cString;
-
- aURL->ToString(urlString);
- cString = urlString.ToNewCString();
- mCachedFile = new nsCacheObject(cString);
- delete [] cString;
-
- if(mCachedFile == nsnull)
- return NS_ERROR_OUT_OF_MEMORY;
-
- // use the actual filename of the net-based file as the cache filename
- //mCachedFile->Filename(aURL->GetFile());
- mCachedFile->Filename("xmas1.mid");
-
- nsCacheManager* cacheManager = nsCacheManager::GetInstance();
- nsDiskModule* diskCache = cacheManager->GetDiskModule();
- diskCache->AddObject(mCachedFile);
-#else // USE_CACHE
- char buf[400], tpath[300];
-#ifdef XP_PC
- ::GetTempPath(sizeof(tpath), tpath);
- PRInt32 len = PL_strlen(tpath);
-
- if((len > 0) && (tpath[len-1] != '\\'))
- {
- tpath[len] = '\\';
- tpath[len+1] = 0;
- }
-#elif defined (XP_UNIX)
- PL_strcpy(tpath, "/tmp/");
-#else
- tpath[0] = 0;
-#endif // XP_PC
- PR_snprintf(buf, sizeof(buf), "%s%08X.ngl", tpath, this);
- mStreamFile = fopen(buf, "wb");
-#endif // USE_CACHE
+ if(rv == NS_OK)
+ {
+ mPStreamListener->GetStreamType(&mStreamType);
+ // check to see if we need to cache the file as well
+ if ((mStreamType == nsPluginStreamType_AsFile) || (mStreamType == nsPluginStreamType_AsFileOnly))
+ rv = SetUpCache(aURL);
}
- return NS_OK;
+ return rv;
}
-#endif // NEW_PLUGIN_STREAM_API
+nsresult
+nsPluginStreamListenerPeer::OnFileAvailable(const char* aFilename)
+{
+ nsresult rv = NS_ERROR_FAILURE;
+ if (mPStreamListener)
+ rv = mPStreamListener->OnFileAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, aFilename);
+
+ if(mOnStopBinding)
+ mPStreamListener->OnStopBinding((nsIPluginStreamInfo*)mPluginStreamInfo, mStatus);
+
+ mCacheDone = PR_TRUE;
+ return rv;
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////
nsPluginHostImpl :: nsPluginHostImpl(nsIServiceManager *serviceMgr)
{
@@ -1194,8 +1233,6 @@ nsresult nsPluginHostImpl :: UserAgent(const char **retstring)
return res;
}
-#ifdef NEW_PLUGIN_STREAM_API
-
NS_IMETHODIMP nsPluginHostImpl::GetURL(nsISupports* pluginInst,
const char* url,
const char* target,
@@ -1317,114 +1354,6 @@ NS_IMETHODIMP nsPluginHostImpl::PostURL(nsISupports* pluginInst,
return rv;
}
-#else
-
-NS_IMETHODIMP nsPluginHostImpl :: GetURL(nsISupports* inst, const char* url,
- const char* target,
- void* notifyData, const char* altHost,
- const char* referrer, PRBool forceJSEnabled)
-{
- nsAutoString string = nsAutoString(url);
- nsIPluginInstance *instance;
- nsresult rv;
-
- rv = inst->QueryInterface(kIPluginInstanceIID, (void **)&instance);
-
- if (NS_OK == rv)
- {
- if (nsnull != target)
- {
- nsPluginInstancePeerImpl *peer;
-
- rv = instance->GetPeer((nsIPluginInstancePeer **)&peer);
-
- if (NS_OK == rv)
- {
- nsIPluginInstanceOwner *owner;
-
- rv = peer->GetOwner(owner);
-
- if (NS_OK == rv)
- {
- if ((0 == PL_strcmp(target, "newwindow")) ||
- (0 == PL_strcmp(target, "_new")))
- target = "_blank";
- else if (0 == PL_strcmp(target, "_current"))
- target = "_self";
-
- rv = owner->GetURL(url, target, nsnull);
- NS_RELEASE(owner);
- }
-
- NS_RELEASE(peer);
- }
- }
-
- if ((nsnull != notifyData) || (nsnull == target))
- rv = NewPluginURLStream(string, instance, notifyData);
-
- NS_RELEASE(instance);
- }
-
- return rv;
-}
-
-NS_IMETHODIMP nsPluginHostImpl :: PostURL(nsISupports* inst,
- 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)
-{
-
- nsAutoString string = nsAutoString(url);
- nsIPluginInstance *instance;
- nsresult rv;
-
- rv = inst->QueryInterface(kIPluginInstanceIID, (void **)&instance);
-
- if (NS_OK == rv)
- {
- if (nsnull != target)
- {
- nsPluginInstancePeerImpl *peer;
-
- rv = instance->GetPeer((nsIPluginInstancePeer **)&peer);
-
- if (NS_OK == rv)
- {
- nsIPluginInstanceOwner *owner;
-
- rv = peer->GetOwner(owner);
-
- if (NS_OK == rv)
- {
- if ((0 == PL_strcmp(target, "newwindow")) ||
- (0 == PL_strcmp(target, "_new")))
- target = "_blank";
- else if (0 == PL_strcmp(target, "_current"))
- target = "_self";
-
- rv = owner->GetURL(url, target, (void*)postData);
- NS_RELEASE(owner);
- }
-
- NS_RELEASE(peer);
- }
- }
-
- if ((nsnull != notifyData) || (nsnull == target))
- rv = NewPluginURLStream(string, instance, notifyData);
-
- NS_RELEASE(instance);
- }
-
- return rv;
-}
-
-#endif // NEW_PLUGIN_STREAM_API
-
NS_IMETHODIMP nsPluginHostImpl :: BeginWaitCursor(void)
{
printf("plugin manager2 beginwaitcursor called\n");
@@ -1513,35 +1442,33 @@ NS_IMETHODIMP nsPluginHostImpl::Destroy(void)
/* Called by nsPluginInstanceOwner (nsObjectFrame.cpp - embeded case) */
-NS_IMETHODIMP nsPluginHostImpl::InstantiateEmbededPlugin(const char *aMimeType, nsString& aURLSpec,
+NS_IMETHODIMP nsPluginHostImpl :: InstantiateEmbededPlugin(const char *aMimeType, nsIURL* aURL,
nsIPluginInstanceOwner *aOwner)
{
nsresult rv;
+ nsIPluginInstance *instance = nsnull;
- rv = SetUpPluginInstance(aMimeType, nsnull, aOwner);
+ rv = SetUpPluginInstance(aMimeType, aURL, aOwner);
+
+ if(rv == NS_OK)
+ rv = aOwner->GetInstance(instance);
- if ((rv != NS_OK) || (nsnull == aMimeType))
+ if(rv != NS_OK)
{
- //either the plugin could not be identified based
- //on the mime type or there was no mime type
-
- if (aURLSpec.Length() > 0)
+ // we have not been able to load a plugin because we have not determined the mimetype
+ if (aURL)
{
//we need to stream in enough to get the mime type...
-
- rv = NewEmbededPluginStream(aURLSpec, aOwner, nsnull);
+ rv = NewEmbededPluginStream(aURL, aOwner, nsnull);
}
else
rv = NS_ERROR_FAILURE;
}
- else
+ else // we have loaded a plugin for this mimetype
{
- nsIPluginInstance *instance = nsnull;
nsPluginWindow *window = nsnull;
//we got a plugin built, now stream
-
- aOwner->GetInstance(instance);
aOwner->GetWindow(window);
if (nsnull != instance)
@@ -1550,7 +1477,7 @@ NS_IMETHODIMP nsPluginHostImpl::InstantiateEmbededPlugin(const char *aMimeType,
aOwner->CreateWidget();
instance->SetWindow(window);
- rv = NewEmbededPluginStream(aURLSpec, nsnull, instance);
+ rv = NewEmbededPluginStream(aURL, nsnull, instance);
NS_RELEASE(instance);
}
@@ -1768,7 +1695,8 @@ NS_IMETHODIMP nsPluginHostImpl::SetUpPluginInstance(const char *aMimeType,
if (plugins->mFlags & NS_PLUGIN_FLAG_OLDSCHOOL)
{
// we have to load an old 4x style plugin
- nsresult rv = ns4xPlugin::CreatePlugin(plugins->mLibrary, (nsIPlugin **)&plugins->mEntryPoint,
+ nsresult rv = ns4xPlugin::CreatePlugin(plugins->mLibrary,
+ (nsIPlugin **)&plugins->mEntryPoint,
mServiceMgr);
}
else
@@ -2303,7 +2231,7 @@ PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const nsFileSpec &pluginSpec)
PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const char* pluginPath, const char* path)
{
#ifdef XP_PC
- BOOL restoreOrigDir = FALSE;
+ /*BOOL restoreOrigDir = FALSE;
char aOrigDir[MAX_PATH + 1];
DWORD dwCheck = ::GetCurrentDirectory(sizeof(aOrigDir), aOrigDir);
PR_ASSERT(dwCheck <= MAX_PATH + 1);
@@ -2312,15 +2240,15 @@ PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const char* pluginPath, const cha
{
restoreOrigDir = ::SetCurrentDirectory(pluginPath);
PR_ASSERT(restoreOrigDir);
- }
+ }*/
PRLibrary* plugin = PR_LoadLibrary(path);
- if (restoreOrigDir)
+ /*if (restoreOrigDir)
{
BOOL bCheck = ::SetCurrentDirectory(aOrigDir);
PR_ASSERT(bCheck);
- }
+ }*/
return plugin;
#else
@@ -2331,8 +2259,6 @@ PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const char* pluginPath, const cha
/* Called by GetURL and PostURL */
-#ifdef NEW_PLUGIN_STREAM_API
-
NS_IMETHODIMP nsPluginHostImpl :: NewPluginURLStream(const nsString& aURL,
nsIPluginInstance *aInstance,
nsIPluginStreamListener* aListener)
@@ -2362,77 +2288,36 @@ NS_IMETHODIMP nsPluginHostImpl :: NewPluginURLStream(const nsString& aURL,
return rv;
}
-#else
-
-/* Called by GetURL and PostURL */
-
-NS_IMETHODIMP nsPluginHostImpl :: NewPluginURLStream(const nsString& aURL,
- nsIPluginInstance *aInstance,
- void *aNotifyData)
-{
- nsIURL *url;
- nsPluginStreamListenerPeer *listener = (nsPluginStreamListenerPeer *)new nsPluginStreamListenerPeer();
- if (listener == NULL)
- return NS_ERROR_OUT_OF_MEMORY;
- nsresult rv;
-
- if (aURL.Length() <= 0)
- return NS_OK;
-
- rv = NS_NewURL(&url, aURL);
-
- if (NS_OK == rv)
- {
- rv = listener->Initialize(url, aInstance, aNotifyData);
-
- if (NS_OK == rv) {
- rv = NS_OpenURL(url, listener);
- }
-
- NS_RELEASE(url);
- }
-
- return rv;
-}
-
-#endif
-
/* Called by InstantiateEmbededPlugin() */
-nsresult nsPluginHostImpl :: NewEmbededPluginStream(const nsString& aURL,
+nsresult nsPluginHostImpl :: NewEmbededPluginStream(nsIURL* aURL,
nsIPluginInstanceOwner *aOwner,
nsIPluginInstance* aInstance)
{
- nsIURL *url;
- nsPluginStreamListenerPeer *listener = (nsPluginStreamListenerPeer *)new nsPluginStreamListenerPeer();
- nsresult rv;
+ nsPluginStreamListenerPeer *listener = (nsPluginStreamListenerPeer *)new nsPluginStreamListenerPeer();
+ nsresult rv;
- if (aURL.Length() <= 0)
- return NS_OK;
+ if (!aURL)
+ return NS_OK;
- rv = NS_NewURL(&url, aURL);
-
- if (NS_OK == rv)
- {
// if we have an instance, everything has been set up
// if we only have an owner, then we need to pass it in
// so the listener can set up the instance later after
// we've determined the mimetype of the stream
if(aInstance != nsnull)
- rv = listener->InitializeEmbeded(url, aInstance);
+ rv = listener->InitializeEmbeded(aURL, aInstance);
else if(aOwner != nsnull)
- rv = listener->InitializeEmbeded(url, nsnull, aOwner, (nsIPluginHost *)this);
+ rv = listener->InitializeEmbeded(aURL, nsnull, aOwner, (nsIPluginHost *)this);
else
rv = NS_ERROR_ILLEGAL_VALUE;
- if (NS_OK == rv) {
- rv = NS_OpenURL(url, listener);
- }
+ if (NS_OK == rv) {
+ rv = NS_OpenURL(aURL, listener);
+ }
- NS_RELEASE(url);
- }
+ //NS_RELEASE(aURL);
- return rv;
+ return rv;
}
/* Called by InstantiateFullPagePlugin() */
@@ -2462,11 +2347,6 @@ nsresult nsPluginHostImpl::CreateInstance(nsISupports *aOuter,
nsISupports *inst = nsnull;
-#ifndef NEW_PLUGIN_STREAM_API
- if (aIID.Equals(kIPluginStreamPeerIID))
- inst = (nsISupports *)(nsIPluginStreamPeer *)new nsPluginStreamPeer();
-#endif
-
if (inst == NULL)
return NS_ERROR_OUT_OF_MEMORY;
diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.h b/mozilla/modules/plugin/base/src/nsPluginHostImpl.h
index fba4d6bb92f..1c24273f762 100644
--- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.h
+++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.h
@@ -79,10 +79,8 @@ public:
NS_IMETHOD
UserAgent(const char* *resultingAgentString);
-#ifdef NEW_PLUGIN_STREAM_API
-
- NS_IMETHOD
- GetURL(nsISupports* pluginInst,
+ NS_IMETHOD
+ GetURL(nsISupports* pluginInst,
const char* url,
const char* target = NULL,
nsIPluginStreamListener* streamListener = NULL,
@@ -90,8 +88,8 @@ public:
const char* referrer = NULL,
PRBool forceJSEnabled = PR_FALSE);
- NS_IMETHOD
- PostURL(nsISupports* pluginInst,
+ NS_IMETHOD
+ PostURL(nsISupports* pluginInst,
const char* url,
PRUint32 postDataLen,
const char* postData,
@@ -103,21 +101,6 @@ public:
PRBool forceJSEnabled = PR_FALSE,
PRUint32 postHeadersLength = 0,
const char* postHeaders = NULL);
-#else
-
- NS_IMETHOD
- GetURL(nsISupports* inst, 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* inst, 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);
-#endif
//nsIPluginHost interface - used to communicate to the nsPluginInstanceOwner
@@ -134,7 +117,7 @@ public:
GetPluginFactory(const char *aMimeType, nsIPlugin** aPlugin);
NS_IMETHOD
- InstantiateEmbededPlugin(const char *aMimeType, nsString& aURLSpec, nsIPluginInstanceOwner *aOwner);
+ InstantiateEmbededPlugin(const char *aMimeType, nsIURL* aURL, nsIPluginInstanceOwner *aOwner);
NS_IMETHOD
InstantiateFullPagePlugin(const char *aMimeType, nsString& aURLSpec, nsIStreamListener *&aStreamListener, nsIPluginInstanceOwner *aOwner);
@@ -195,20 +178,15 @@ public:
/* Called by GetURL and PostURL */
-#ifdef NEW_PLUGIN_STREAM_API
NS_IMETHOD
NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener);
-#else
- NS_IMETHOD
- NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, void *aNotifyData);
-#endif
private:
/* Called by InstantiatePlugin */
nsresult
- NewEmbededPluginStream(const nsString& aURL, nsIPluginInstanceOwner *aOwner, nsIPluginInstance* aInstance);
+ NewEmbededPluginStream(nsIURL* aURL, nsIPluginInstanceOwner *aOwner, nsIPluginInstance* aInstance);
nsresult
NewFullPagePluginStream(nsIStreamListener *&aStreamListener, nsIPluginInstance *aInstance);
diff --git a/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp b/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp
index 311e0a12560..7d7bac95c2d 100644
--- a/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp
+++ b/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp
@@ -157,7 +157,6 @@ public:
Close(void);
protected:
-
char* mTarget;
nsFileURL mFileURL;
nsFileSpec mFileSpec;
@@ -165,11 +164,16 @@ protected:
nsIPluginInstanceOwner* mOwner;
};
+NS_IMPL_ADDREF(nsPluginStreamToFile);
+NS_IMPL_RELEASE(nsPluginStreamToFile);
+
nsPluginStreamToFile::nsPluginStreamToFile(const char* target, nsIPluginInstanceOwner* owner)
: mTarget(PL_strdup(target))
, mFileURL(nsnull)
, mOwner(owner)
{
+ NS_INIT_REFCNT();
+
// open the file and prepare it for writing
char buf[400], tpath[300];
#ifdef XP_PC
@@ -192,7 +196,7 @@ nsPluginStreamToFile::nsPluginStreamToFile(const char* target, nsIPluginInstance
// Create and validate the file spec object. (When we have a constructor for the temp
// directory, we should use this instead of the per-platform hack above).
- mFileSpec = buf;
+ mFileSpec = PL_strdup(buf);
if (mFileSpec.Error())
return;
@@ -218,10 +222,6 @@ nsPluginStreamToFile::~nsPluginStreamToFile()
}
-
-NS_IMPL_ADDREF(nsPluginStreamToFile)
-NS_IMPL_RELEASE(nsPluginStreamToFile)
-
nsresult nsPluginStreamToFile::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
diff --git a/mozilla/modules/plugin/nglsrc/Makefile.in b/mozilla/modules/plugin/nglsrc/Makefile.in
index 8bd676ef362..baadc115123 100644
--- a/mozilla/modules/plugin/nglsrc/Makefile.in
+++ b/mozilla/modules/plugin/nglsrc/Makefile.in
@@ -41,7 +41,6 @@ CPPSRCS = \
ns4xPlugin.cpp \
ns4xPluginInstance.cpp \
nsPluginInstancePeer.cpp \
- nsMalloc.cpp \
$(NULL)
REQUIRES = raptor plugin java xpcom netlib libplc21 oji
diff --git a/mozilla/modules/plugin/nglsrc/makefile.win b/mozilla/modules/plugin/nglsrc/makefile.win
index c563abda4ac..9411e87a1db 100644
--- a/mozilla/modules/plugin/nglsrc/makefile.win
+++ b/mozilla/modules/plugin/nglsrc/makefile.win
@@ -37,10 +37,7 @@ OBJS = \
.\$(OBJDIR)\nsPluginFactory.obj \
.\$(OBJDIR)\ns4xPlugin.obj \
.\$(OBJDIR)\ns4xPluginInstance.obj \
-# .\$(OBJDIR)\ns4xPluginStream.obj \
.\$(OBJDIR)\nsPluginInstancePeer.obj \
-# .\$(OBJDIR)\nsPluginStreamPeer.obj \
- .\$(OBJDIR)\nsMalloc.obj \
$(NULL)
LINCS = \
diff --git a/mozilla/modules/plugin/nglsrc/ns4xPlugin.cpp b/mozilla/modules/plugin/nglsrc/ns4xPlugin.cpp
index 5e487c4e257..b72d5d15b28 100644
--- a/mozilla/modules/plugin/nglsrc/ns4xPlugin.cpp
+++ b/mozilla/modules/plugin/nglsrc/ns4xPlugin.cpp
@@ -24,12 +24,13 @@
#include "ns4xPluginInstance.h"
#include "nsIServiceManager.h"
#include "nsIAllocator.h"
+#include "nsIPluginStreamListener.h"
////////////////////////////////////////////////////////////////////////
NPNetscapeFuncs ns4xPlugin::CALLBACKS;
nsIPluginManager * ns4xPlugin::mPluginManager;
-nsIAllocator * ns4xPlugin::mMalloc;
+nsIAllocator * ns4xPlugin::mMalloc;
void
ns4xPlugin::CheckClassInitialized(void)
@@ -87,32 +88,23 @@ static NS_DEFINE_IID(kPluginManagerCID, NS_PLUGINMANAGER_CID);
static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID);
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID);
-
-#ifndef NEW_PLUGIN_STREAM_API
-static NS_DEFINE_IID(kISeekablePluginStreamPeerIID, NS_ISEEKABLEPLUGINSTREAMPEER_IID);
-#endif
+static NS_DEFINE_IID(kIPluginStreamListenerIID, NS_IPLUGINSTREAMLISTENER_IID);
////////////////////////////////////////////////////////////////////////
-#ifdef NEW_PLUGIN_STREAM_API
ns4xPlugin::ns4xPlugin(NPPluginFuncs* callbacks, NP_PLUGINSHUTDOWN aShutdown, nsIServiceManager* serviceMgr)
-#else
-ns4xPlugin::ns4xPlugin(NPPluginFuncs* callbacks, NP_PLUGINSHUTDOWN aShutdown)
-#endif
{
NS_INIT_REFCNT();
memcpy((void*) &fCallbacks, (void*) callbacks, sizeof(fCallbacks));
fShutdownEntry = aShutdown;
-#ifdef NEW_PLUGIN_STREAM_API
- // set up the connections to the plugin manager
+ // set up the connections to the plugin manager
if (nsnull == mPluginManager)
serviceMgr->GetService(kPluginManagerCID, kIPluginManagerIID, (nsISupports**)&mPluginManager);
- if (nsnull == mMalloc)
+ if (nsnull == mMalloc)
serviceMgr->GetService(kAllocatorCID, kIAllocatorIID, (nsISupports**)&mMalloc);
-#endif
}
@@ -165,7 +157,8 @@ ns4xPlugin::QueryInterface(const nsIID& iid, void** instance)
nsresult
ns4xPlugin::CreatePlugin(PRLibrary *library,
- nsIPlugin **result, nsIServiceManager* serviceMgr)
+ nsIPlugin **result,
+ nsIServiceManager* serviceMgr)
{
CheckClassInitialized();
@@ -203,11 +196,7 @@ ns4xPlugin::CreatePlugin(PRLibrary *library,
// we must init here because the plugin may call NPN functions
// when we call into the NP_Initialize entry point - NPN functions
// require that mBrowserManager be set up
-#ifdef NEW_PLUGIN_STREAM_API
(*result)->Initialize();
-#else
- (*result)->Initialize(browserInterfaces);
-#endif
// the NP_Initialize entry point was misnamed as NP_PluginInit,
// early in plugin project development. Its correct name is
@@ -273,30 +262,11 @@ nsresult ns4xPlugin :: LockFactory(PRBool aLock)
return NS_OK;
}
-#ifndef NEW_PLUGIN_STREAM_API
-nsresult
-ns4xPlugin::Initialize(nsISupports* browserInterfaces)
-{
- nsresult rv = NS_OK;
-
- // set up the connections to the plugin manager
- if (nsnull == mPluginManager)
- if((rv = browserInterfaces->QueryInterface(kIPluginManagerIID, (void **)&mPluginManager)) != NS_OK)
- return rv;
- if (nsnull == mMalloc)
- if((rv = browserInterfaces->QueryInterface(kIMallocIID, (void **)&mMalloc)) != NS_OK)
- return rv;
-
- return rv;
-}
-#else
nsresult
ns4xPlugin::Initialize(void)
{
return NS_OK;
}
-#endif
-
nsresult
ns4xPlugin::Shutdown(void)
@@ -336,101 +306,106 @@ printf("plugin getvalue %d called\n", variable);
// Static callbacks that get routed back through the new C++ API
//
-nsresult NP_EXPORT
+NPError NP_EXPORT
ns4xPlugin::_geturl(NPP npp, const char* relativeURL, const char* target)
{
+ if(!npp)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
NS_ASSERTION(mPluginManager != NULL, "null manager");
if (inst == NULL)
- return NS_ERROR_UNEXPECTED; // XXX
+ return NPERR_INVALID_INSTANCE_ERROR;
-#ifdef NEW_PLUGIN_STREAM_API
nsIPluginStreamListener* listener = nsnull;
if(target == nsnull)
inst->NewStream(&listener);
- return mPluginManager->GetURL(inst, relativeURL, target, listener);
-#else
- return mPluginManager->GetURL(inst, relativeURL, target);
-#endif
+ if(mPluginManager->GetURL(inst, relativeURL, target, listener) != NS_OK)
+ return NPERR_GENERIC_ERROR;
+
+ return NPERR_NO_ERROR;
}
-nsresult NP_EXPORT
+NPError NP_EXPORT
ns4xPlugin::_geturlnotify(NPP npp, const char* relativeURL, const char* target,
void* notifyData)
{
+ if(!npp)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
NS_ASSERTION(mPluginManager != NULL, "null manager");
if (inst == NULL)
- return NS_ERROR_UNEXPECTED; // XXX
+ return NPERR_INVALID_INSTANCE_ERROR;
-#ifdef NEW_PLUGIN_STREAM_API
nsIPluginStreamListener* listener = nsnull;
if(target == nsnull)
((ns4xPluginInstance*)inst)->NewNotifyStream(&listener, notifyData);
- return mPluginManager->GetURL(inst, relativeURL, target, listener);
-#else
- return mPluginManager->GetURL(inst, relativeURL, target,
- notifyData);
-#endif
+ if(mPluginManager->GetURL(inst, relativeURL, target, listener) != NS_OK)
+ return NPERR_GENERIC_ERROR;
+
+ return NPERR_NO_ERROR;
}
-nsresult NP_EXPORT
+NPError NP_EXPORT
ns4xPlugin::_posturlnotify(NPP npp, const char* relativeURL, const char *target,
uint32 len, const char *buf, NPBool file,
void* notifyData)
{
+ if(!npp)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
NS_ASSERTION(mPluginManager != NULL, "null manager");
if (inst == NULL)
- return NS_ERROR_UNEXPECTED; // XXX
+ return NPERR_INVALID_INSTANCE_ERROR;
-#ifdef NEW_PLUGIN_STREAM_API
nsIPluginStreamListener* listener = nsnull;
if(target == nsnull)
((ns4xPluginInstance*)inst)->NewNotifyStream(&listener, notifyData);
- return mPluginManager->PostURL(inst, relativeURL, len, buf, file, target, listener);
-#else
- return mPluginManager->PostURL(inst, relativeURL, target,
- len, buf, file, notifyData);
-#endif
+ if(mPluginManager->PostURL(inst, relativeURL, len, buf, file, target, listener) != NS_OK)
+ return NPERR_GENERIC_ERROR;
+
+ return NPERR_NO_ERROR;
}
-nsresult NP_EXPORT
+NPError NP_EXPORT
ns4xPlugin::_posturl(NPP npp, const char* relativeURL, const char *target, uint32 len,
const char *buf, NPBool file)
{
+ if(!npp)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
NS_ASSERTION(mPluginManager != NULL, "null manager");
if (inst == NULL)
- return NS_ERROR_UNEXPECTED; // XXX
+ return NPERR_INVALID_INSTANCE_ERROR;
-#ifdef NEW_PLUGIN_STREAM_API
nsIPluginStreamListener* listener = nsnull;
if(target == nsnull)
inst->NewStream(&listener);
- return mPluginManager->PostURL(inst, relativeURL, len, buf, file, target, listener);
-#else
- return mPluginManager->PostURL(inst, relativeURL, target,
- len, buf, file);
-#endif
+ if(mPluginManager->PostURL(inst, relativeURL, len, buf, file, target, listener) != NS_OK)
+ return NPERR_GENERIC_ERROR;
+
+ return NPERR_NO_ERROR;
}
////////////////////////////////////////////////////////////////////////
@@ -449,8 +424,7 @@ public:
ns4xStreamWrapper(nsIOutputStream* stream);
~ns4xStreamWrapper();
- nsIOutputStream*
- GetStream(void);
+ void GetStream(nsIOutputStream* &result);
NPStream*
GetNPStream(void) {
@@ -464,7 +438,6 @@ ns4xStreamWrapper::ns4xStreamWrapper(nsIOutputStream* stream)
NS_ASSERTION(stream != NULL, "bad stream");
fStream = stream;
-
NS_ADDREF(fStream);
memset(&fNPStream, 0, sizeof(fNPStream));
@@ -474,41 +447,42 @@ ns4xStreamWrapper::ns4xStreamWrapper(nsIOutputStream* stream)
ns4xStreamWrapper::~ns4xStreamWrapper(void)
{
fStream->Close();
-
NS_IF_RELEASE(fStream);
}
-nsIOutputStream*
-ns4xStreamWrapper::GetStream(void)
-{
- NS_IF_ADDREF(fStream);
- return fStream;
+void
+ns4xStreamWrapper::GetStream(nsIOutputStream* &result)
+{
+ result = fStream;
+ NS_IF_ADDREF(fStream);
}
////////////////////////////////////////////////////////////////////////
-nsresult NP_EXPORT
+NPError NP_EXPORT
ns4xPlugin::_newstream(NPP npp, NPMIMEType type, const char* window, NPStream* *result)
{
+ if(!npp)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
if (inst == NULL)
- return NS_ERROR_UNEXPECTED; // XXX
+ return NPERR_INVALID_INSTANCE_ERROR;
- nsresult error;
nsIOutputStream* stream;
nsIPluginInstancePeer *peer;
if (NS_OK == inst->GetPeer(&peer))
{
- if ((error = peer->NewStream((const char*) type, window, &stream)) != NS_OK)
+ if (peer->NewStream((const char*) type, window, &stream) != NS_OK)
{
NS_RELEASE(peer);
- return error;
+ return NPERR_GENERIC_ERROR;
}
ns4xStreamWrapper* wrapper = new ns4xStreamWrapper(stream);
@@ -517,58 +491,83 @@ ns4xPlugin::_newstream(NPP npp, NPMIMEType type, const char* window, NPStream* *
{
NS_RELEASE(peer);
NS_RELEASE(stream);
- return NS_ERROR_OUT_OF_MEMORY;
+ return NPERR_OUT_OF_MEMORY_ERROR;
}
(*result) = wrapper->GetNPStream();
NS_RELEASE(peer);
- return error;
+ return NPERR_NO_ERROR;
}
else
- return NS_ERROR_UNEXPECTED;
+ return NPERR_GENERIC_ERROR;
}
int32 NP_EXPORT
ns4xPlugin::_write(NPP npp, NPStream *pstream, int32 len, void *buffer)
{
- ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) pstream->ndata;
+ // negative return indicates failure to the plugin
+ if(!npp)
+ return -1;
- NS_ASSERTION(wrapper != NULL, "null wrapper");
+ ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) pstream->ndata;
+ NS_ASSERTION(wrapper != NULL, "null stream");
if (wrapper == NULL)
- return 0;
+ return -1;
- nsIOutputStream* stream = wrapper->GetStream();
+ nsIOutputStream* stream;
+ wrapper->GetStream(stream);
PRUint32 count = 0;
nsresult rv = stream->Write((char *)buffer, len, &count);
-
NS_RELEASE(stream);
+ if(rv != NS_OK)
+ return -1;
+
return (int32)count;
}
-nsresult NP_EXPORT
+NPError NP_EXPORT
ns4xPlugin::_destroystream(NPP npp, NPStream *pstream, NPError reason)
{
+ if(!npp)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ nsISupports* stream = (nsISupports*) pstream->ndata;
+ nsIPluginStreamListener* listener;
+
+ // DestroyStream can kill two kinds of streams: NPP derived and
+ // NPN derived.
+ // check to see if they're trying to kill a NPP stream
+ if(stream->QueryInterface(kIPluginStreamListenerIID, (void**)&listener) == NS_OK)
+ {
+ // XXX we should try to kill this listener here somehow
+ NS_RELEASE(listener);
+ return NPERR_NO_ERROR;
+ }
+
ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) pstream->ndata;
NS_ASSERTION(wrapper != NULL, "null wrapper");
if (wrapper == NULL)
- return 0;
+ return NPERR_INVALID_PARAM;
// This will release the wrapped nsIOutputStream.
delete wrapper;
- return NS_OK;
+ return NPERR_NO_ERROR;
}
void NP_EXPORT
ns4xPlugin::_status(NPP npp, const char *message)
{
+ if(!npp)
+ return;
+
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
@@ -588,7 +587,8 @@ ns4xPlugin::_status(NPP npp, const char *message)
void NP_EXPORT
ns4xPlugin::_memfree (void *ptr)
{
- mMalloc->Free(ptr);
+ if(ptr)
+ mMalloc->Free(ptr);
}
uint32 NP_EXPORT
@@ -608,6 +608,9 @@ ns4xPlugin::_reloadplugins(NPBool reloadPages)
void NP_EXPORT
ns4xPlugin::_invalidaterect(NPP npp, NPRect *invalidRect)
{
+ if(!npp)
+ return;
+
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
@@ -634,6 +637,9 @@ ns4xPlugin::_invalidaterect(NPP npp, NPRect *invalidRect)
void NP_EXPORT
ns4xPlugin::_invalidateregion(NPP npp, NPRegion invalidRegion)
{
+ if(!npp)
+ return;
+
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
@@ -660,6 +666,9 @@ ns4xPlugin::_invalidateregion(NPP npp, NPRegion invalidRegion)
void NP_EXPORT
ns4xPlugin::_forceredraw(NPP npp)
{
+ if(!npp)
+ return;
+
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
@@ -682,15 +691,18 @@ ns4xPlugin::_forceredraw(NPP npp)
}
}
-nsresult NP_EXPORT
+NPError NP_EXPORT
ns4xPlugin::_getvalue(NPP npp, NPNVariable variable, void *result)
{
+ if(!npp)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
if (inst == NULL)
- return NS_ERROR_FAILURE; // XXX
+ return NPERR_INVALID_INSTANCE_ERROR;
nsIPluginInstancePeer *peer;
@@ -705,18 +717,21 @@ ns4xPlugin::_getvalue(NPP npp, NPNVariable variable, void *result)
return rv;
}
else
- return NS_ERROR_UNEXPECTED;
+ return NPERR_GENERIC_ERROR;
}
-nsresult NP_EXPORT
+NPError NP_EXPORT
ns4xPlugin::_setvalue(NPP npp, NPPVariable variable, void *result)
{
+ if(!npp)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
ns4xPluginInstance *inst = (ns4xPluginInstance *) npp->ndata;
NS_ASSERTION(inst != NULL, "null instance");
if (inst == NULL)
- return NS_ERROR_FAILURE; // XXX
+ return NPERR_INVALID_INSTANCE_ERROR;
switch (variable)
{
@@ -727,7 +742,7 @@ ns4xPlugin::_setvalue(NPP npp, NPPVariable variable, void *result)
return inst->SetTransparent(*((NPBool *)result));
default:
- return NS_OK;
+ return NPERR_NO_ERROR;
}
#if 0
@@ -748,31 +763,10 @@ ns4xPlugin::_setvalue(NPP npp, NPPVariable variable, void *result)
#endif
}
-nsresult NP_EXPORT
+NPError NP_EXPORT
ns4xPlugin::_requestread(NPStream *pstream, NPByteRange *rangeList)
{
-#ifndef NEW_PLUGIN_STREAM_API
- nsIPluginStreamPeer* streamPeer = (nsIPluginStreamPeer*) pstream->ndata;
-
- NS_ASSERTION(streamPeer != NULL, "null streampeer");
-
- if (streamPeer == NULL)
- return NS_ERROR_FAILURE; // XXX
-
- nsISeekablePluginStreamPeer* seekablePeer = NULL;
-
- if (streamPeer->QueryInterface(kISeekablePluginStreamPeerIID,
- (void**)seekablePeer) == NS_OK)
- {
- nsresult error;
-
- // XXX nsByteRange & NPByteRange are structurally equivalent.
- error = seekablePeer->RequestRead((nsByteRange *)rangeList);
- NS_RELEASE(seekablePeer);
- return error;
- }
-#endif
- return NS_ERROR_UNEXPECTED;
+ return NPERR_STREAM_NOT_SEEKABLE;
}
diff --git a/mozilla/modules/plugin/nglsrc/ns4xPlugin.h b/mozilla/modules/plugin/nglsrc/ns4xPlugin.h
index 99466b0fda4..3f78a3b3588 100644
--- a/mozilla/modules/plugin/nglsrc/ns4xPlugin.h
+++ b/mozilla/modules/plugin/nglsrc/ns4xPlugin.h
@@ -54,6 +54,7 @@ class nsIAllocator;
class ns4xPlugin : public nsIPlugin
{
public:
+
ns4xPlugin(NPPluginFuncs* callbacks, NP_PLUGINSHUTDOWN aShutdown, nsIServiceManager* serviceMgr);
~ns4xPlugin(void);
@@ -69,13 +70,8 @@ public:
//nsIPlugin interface
-#ifndef NEW_PLUGIN_STREAM_API
- NS_IMETHOD
- Initialize(nsISupports* browserInterfaces);
-#else
NS_IMETHOD
Initialize(void);
-#endif
NS_IMETHOD
Shutdown(void);
@@ -109,36 +105,36 @@ protected:
// Static stub functions that are exported to the 4.x plugin as entry
// points via the CALLBACKS variable.
//
- static nsresult NP_EXPORT
+ static NPError NP_EXPORT
_requestread(NPStream *pstream, NPByteRange *rangeList);
- static nsresult NP_EXPORT
+ static NPError NP_EXPORT
_geturlnotify(NPP npp, const char* relativeURL, const char* target, void* notifyData);
- static nsresult NP_EXPORT
+ static NPError NP_EXPORT
_getvalue(NPP npp, NPNVariable variable, void *r_value);
- static nsresult NP_EXPORT
+ static NPError NP_EXPORT
_setvalue(NPP npp, NPPVariable variable, void *r_value);
- static nsresult NP_EXPORT
+ static NPError NP_EXPORT
_geturl(NPP npp, const char* relativeURL, const char* target);
- static nsresult NP_EXPORT
+ static NPError NP_EXPORT
_posturlnotify(NPP npp, const char* relativeURL, const char *target,
uint32 len, const char *buf, NPBool file, void* notifyData);
- static nsresult NP_EXPORT
+ static NPError NP_EXPORT
_posturl(NPP npp, const char* relativeURL, const char *target, uint32 len,
const char *buf, NPBool file);
- static nsresult NP_EXPORT
+ static NPError NP_EXPORT
_newstream(NPP npp, NPMIMEType type, const char* window, NPStream** pstream);
static int32 NP_EXPORT
_write(NPP npp, NPStream *pstream, int32 len, void *buffer);
- static nsresult NP_EXPORT
+ static NPError NP_EXPORT
_destroystream(NPP npp, NPStream *pstream, NPError reason);
static void NP_EXPORT
diff --git a/mozilla/modules/plugin/nglsrc/ns4xPluginInstance.cpp b/mozilla/modules/plugin/nglsrc/ns4xPluginInstance.cpp
index b5642b2faa6..bca13548f3b 100644
--- a/mozilla/modules/plugin/nglsrc/ns4xPluginInstance.cpp
+++ b/mozilla/modules/plugin/nglsrc/ns4xPluginInstance.cpp
@@ -17,20 +17,11 @@
*/
#include "ns4xPluginInstance.h"
-
-#ifdef NEW_PLUGIN_STREAM_API
#include "nsIPluginStreamListener.h"
-#else
-#include "ns4xPluginStream.h"
-#endif
#include "prlog.h"
+#include "prmem.h"
-////////////////////////////////////////////////////////////////////////
-//
-////////////////////////////////////////////////////////////////////////
-
-#ifdef NEW_PLUGIN_STREAM_API
class ns4xPluginStreamListener : public nsIPluginStreamListener {
@@ -42,24 +33,20 @@ public:
// from nsIPluginStreamListener:
NS_IMETHOD
- OnStartBinding(const char* url, nsIPluginStreamInfo* pluginInfo);
+ OnStartBinding(nsIPluginStreamInfo* pluginInfo);
NS_IMETHOD
- OnDataAvailable(const char* url, nsIInputStream* input,
- PRUint32 offset, PRUint32 length, nsIPluginStreamInfo* pluginInfo);
+ OnDataAvailable(nsIPluginStreamInfo* pluginInfo, nsIInputStream* input, PRUint32 length);
NS_IMETHOD
- OnFileAvailable(const char* url, const char* fileName);
+ OnFileAvailable( nsIPluginStreamInfo* pluginInfo, const char* fileName);
NS_IMETHOD
- OnStopBinding(const char* url, nsresult status, nsIPluginStreamInfo* pluginInfo);
+ OnStopBinding(nsIPluginStreamInfo* pluginInfo, nsresult status);
NS_IMETHOD
GetStreamType(nsPluginStreamType *result);
- NS_IMETHOD
- OnNotify(const char* url, nsresult status);
-
////////////////////////////////////////////////////////////////////////////
// ns4xPluginStreamListener specific methods:
@@ -69,12 +56,13 @@ public:
protected:
void* mNotifyData;
- ns4xPluginInstance* mInst;
- NPStream mNPStream;
- PRUint32 mPosition;
- nsPluginStreamType mStreamType;
+ ns4xPluginInstance* mInst;
+ NPStream mNPStream;
+ PRUint32 mPosition;
+ nsPluginStreamType mStreamType;
};
+
////////////////////////////////////////////////////////////////////////////////
// ns4xPluginStreamListener Methods
////////////////////////////////////////////////////////////////////////////////
@@ -102,16 +90,17 @@ ns4xPluginStreamListener::~ns4xPluginStreamListener(void)
NS_IMPL_ISUPPORTS(ns4xPluginStreamListener, kIPluginStreamListenerIID);
NS_IMETHODIMP
-ns4xPluginStreamListener::OnStartBinding(const char* url, nsIPluginStreamInfo* pluginInfo)
+ns4xPluginStreamListener::OnStartBinding(nsIPluginStreamInfo* pluginInfo)
{
NPP npp;
const NPPluginFuncs *callbacks;
PRBool seekable;
nsMIMEType contentType;
-
+ PRUint16 streamType = NP_NORMAL;
+ NPError error;
mNPStream.ndata = (void*) this;
- mNPStream.url = url;
+ pluginInfo->GetURL(&mNPStream.url);
mNPStream.notifyData = mNotifyData;
pluginInfo->GetLength((PRUint32*)&(mNPStream.end));
@@ -122,19 +111,36 @@ ns4xPluginStreamListener::OnStartBinding(const char* url, nsIPluginStreamInfo* p
mInst->GetCallbacks(&callbacks);
mInst->GetNPP(&npp);
- nsresult error
- = (nsresult)CallNPP_NewStreamProc(callbacks->newstream,
+ error = CallNPP_NewStreamProc(callbacks->newstream,
npp,
(char *)contentType,
&mNPStream,
seekable,
- (PRUint16*)&mStreamType);
+ &streamType);
+ if(error != NPERR_NO_ERROR)
+ return NS_ERROR_FAILURE;
+
+ // translate the old 4x style stream type to the new one
+ switch(streamType)
+ {
+ case NP_NORMAL : mStreamType = nsPluginStreamType_Normal; break;
+
+ case NP_ASFILEONLY : mStreamType = nsPluginStreamType_AsFileOnly; break;
+
+ case NP_ASFILE : mStreamType = nsPluginStreamType_AsFile; break;
+
+ case NP_SEEK : mStreamType = nsPluginStreamType_Seek; break;
+
+ default: return NS_ERROR_FAILURE;
+ }
+
return NS_OK;
}
NS_IMETHODIMP
-ns4xPluginStreamListener::OnDataAvailable(const char* url, nsIInputStream* input,
- PRUint32 /*offset*/, PRUint32 length, nsIPluginStreamInfo* pluginInfo)
+ns4xPluginStreamListener::OnDataAvailable(nsIPluginStreamInfo* pluginInfo,
+ nsIInputStream* input,
+ PRUint32 length)
{
const NPPluginFuncs *callbacks;
NPP npp;
@@ -142,17 +148,17 @@ ns4xPluginStreamListener::OnDataAvailable(const char* url, nsIInputStream* input
PRUint32 amountRead = 0;
PRInt32 writeCount = 0;
- mNPStream.url = url;
+ pluginInfo->GetURL(&mNPStream.url);
pluginInfo->GetLastModified((PRUint32*)&(mNPStream.lastmodified));
mInst->GetCallbacks(&callbacks);
mInst->GetNPP(&npp);
- if (callbacks->write == NULL)
+ if (callbacks->write == NULL || length == 0)
return NS_OK; // XXX ?
// Get the data from the input stream
- char* buffer = new char[length];
+ char* buffer = (char*) PR_Malloc(length);
if (buffer)
input->Read(buffer, length, &amountRead);
@@ -162,42 +168,46 @@ ns4xPluginStreamListener::OnDataAvailable(const char* url, nsIInputStream* input
// Write until the buffer is empty
while (amountRead > 0)
{
- if (callbacks->writeready != NULL)
- {
- numtowrite = CallNPP_WriteReadyProc(callbacks->writeready,
+ if (callbacks->writeready != NULL)
+ {
+ numtowrite = CallNPP_WriteReadyProc(callbacks->writeready,
npp,
&mNPStream);
- if (numtowrite > amountRead)
- numtowrite = amountRead;
- }
- else // if WriteReady is not supported by the plugin, just write the whole buffer
- numtowrite = length;
+ if (numtowrite > amountRead)
+ numtowrite = amountRead;
+ }
+ else // if WriteReady is not supported by the plugin, just write the whole buffer
+ numtowrite = length;
-
- writeCount = CallNPP_WriteProc(callbacks->write,
+ // if WriteReady returned 0, the plugin is not ready to handle the data,
+ // so just skip the Write until WriteReady returns a >0 value
+ if(numtowrite > 0)
+ {
+ writeCount = CallNPP_WriteProc(callbacks->write,
npp,
&mNPStream,
mPosition,
numtowrite,
(void *)buffer);
- if(writeCount < 0)
- return NS_ERROR_FAILURE;
+ if(writeCount < 0)
+ return NS_ERROR_FAILURE;
- amountRead -= numtowrite;
- mPosition += numtowrite;
+ amountRead -= numtowrite;
+ mPosition += numtowrite;
+ }
}
return NS_OK;
}
NS_IMETHODIMP
-ns4xPluginStreamListener::OnFileAvailable(const char* url, const char* fileName)
+ns4xPluginStreamListener::OnFileAvailable(nsIPluginStreamInfo* pluginInfo, const char* fileName)
{
const NPPluginFuncs *callbacks;
NPP npp;
- mNPStream.url = url;
+ pluginInfo->GetURL(&mNPStream.url);
mInst->GetCallbacks(&callbacks);
mInst->GetNPP(&npp);
@@ -214,12 +224,13 @@ ns4xPluginStreamListener::OnFileAvailable(const char* url, const char* fileName)
}
NS_IMETHODIMP
-ns4xPluginStreamListener::OnStopBinding(const char* url, nsresult status, nsIPluginStreamInfo* pluginInfo)
+ns4xPluginStreamListener::OnStopBinding(nsIPluginStreamInfo* pluginInfo, nsresult status)
{
const NPPluginFuncs *callbacks;
NPP npp;
+ NPError error;
- mNPStream.url = url;
+ pluginInfo->GetURL(&mNPStream.url);
pluginInfo->GetLastModified((PRUint32*)&(mNPStream.lastmodified));
mInst->GetCallbacks(&callbacks);
@@ -227,10 +238,23 @@ ns4xPluginStreamListener::OnStopBinding(const char* url, nsresult status, nsIPlu
if (callbacks->destroystream != NULL)
{
- CallNPP_DestroyStreamProc(callbacks->destroystream,
+ // XXX need to convert status to NPReason
+ error = CallNPP_DestroyStreamProc(callbacks->destroystream,
npp,
&mNPStream,
- nsPluginReason_Done);
+ NPRES_DONE);
+ if(error != NPERR_NO_ERROR)
+ return NS_ERROR_FAILURE;
+ }
+
+ // check to see if we have a call back
+ if (callbacks->urlnotify != NULL && mNotifyData != nsnull)
+ {
+ CallNPP_URLNotifyProc(callbacks->urlnotify,
+ npp,
+ mNPStream.url,
+ nsPluginReason_Done,
+ mNotifyData);
}
return NS_OK;
@@ -243,32 +267,6 @@ ns4xPluginStreamListener::GetStreamType(nsPluginStreamType *result)
return NS_OK;
}
-NS_IMETHODIMP
-ns4xPluginStreamListener::OnNotify(const char* url, nsresult status)
-{
- const NPPluginFuncs *callbacks;
- NPP npp;
-
- mNPStream.url = url;
-
- mInst->GetCallbacks(&callbacks);
- mInst->GetNPP(&npp);
-
- // check to see if we have a call back
- if (callbacks->urlnotify != NULL && mNotifyData != nsnull)
- {
- CallNPP_URLNotifyProc(callbacks->urlnotify,
- npp,
- url,
- nsPluginReason_Done,
- mNotifyData);
- }
-
- return NS_OK;
-}
-
-#endif
-
ns4xPluginInstance :: ns4xPluginInstance(NPPluginFuncs* callbacks)
: fCallbacks(callbacks)
{
@@ -293,6 +291,7 @@ ns4xPluginInstance :: ~ns4xPluginInstance(void)
NS_RELEASE(fPeer);
}
+
////////////////////////////////////////////////////////////////////////
NS_IMPL_ADDREF(ns4xPluginInstance);
@@ -332,19 +331,18 @@ NS_IMETHODIMP ns4xPluginInstance :: Initialize(nsIPluginInstancePeer* peer)
PRUint16 count = 0;
const char* const* names = nsnull;
const char* const* values = nsnull;
+ nsresult rv;
+ NPError error;
+ nsIPluginTagInfo* taginfo;
NS_ASSERTION(peer != NULL, "null peer");
fPeer = peer;
-
NS_ADDREF(fPeer);
- nsresult error;
- nsIPluginTagInfo *taginfo = nsnull;
+ rv = fPeer->QueryInterface(kIPluginTagInfoIID, (void **)&taginfo);
- error = fPeer->QueryInterface(kIPluginTagInfoIID, (void **)&taginfo);
-
- if (NS_OK == error)
+ if (NS_OK == rv)
{
taginfo->GetAttributes(count, names, values);
NS_IF_RELEASE(taginfo);
@@ -362,8 +360,7 @@ NS_IMETHODIMP ns4xPluginInstance :: Initialize(nsIPluginInstancePeer* peer)
fPeer->GetMode(&mode);
fPeer->GetMIMEType(&mimetype);
- error = (nsresult)
- CallNPP_NewProc(fCallbacks->newp,
+ error = CallNPP_NewProc(fCallbacks->newp,
(char *)mimetype,
&fNPP,
(PRUint16)mode,
@@ -372,7 +369,10 @@ NS_IMETHODIMP ns4xPluginInstance :: Initialize(nsIPluginInstancePeer* peer)
(char**)values,
NULL); // saved data
- return error;
+ if(error != NPERR_NO_ERROR)
+ rv = NS_ERROR_FAILURE;
+
+ return rv;
}
NS_IMETHODIMP ns4xPluginInstance :: GetPeer(nsIPluginInstancePeer* *resultingPeer)
@@ -400,7 +400,7 @@ printf("instance stop called\n");
NS_IMETHODIMP ns4xPluginInstance::Destroy(void)
{
- nsresult error;
+ NPError error;
printf("instance destroy called\n");
if (fCallbacks->destroy == NULL)
@@ -410,8 +410,11 @@ printf("instance destroy called\n");
error = (nsresult)CallNPP_DestroyProc(fCallbacks->destroy,
&fNPP, &sdata); // saved data
-
- return error;
+
+ if(error != NPERR_NO_ERROR)
+ return NS_ERROR_FAILURE;
+ else
+ return NS_OK;
}
NS_IMETHODIMP ns4xPluginInstance::SetWindow(nsPluginWindow* window)
@@ -421,14 +424,14 @@ NS_IMETHODIMP ns4xPluginInstance::SetWindow(nsPluginWindow* window)
if (window == NULL)
return NS_OK;
- nsresult error = NS_OK;
+ NPError error;
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,
+ error = CallNPP_SetWindowProc(fCallbacks->setwindow,
&fNPP,
(NPWindow*) window);
@@ -436,15 +439,13 @@ NS_IMETHODIMP ns4xPluginInstance::SetWindow(nsPluginWindow* window)
// back from the plugin's SetWindow(). Is this the correct
// behavior?!?
- if (error != NS_OK)
+ if (error != NPERR_NO_ERROR)
printf("error in setwindow %d\n", error);
}
- return error;
+ return NS_OK;
}
-#ifdef NEW_PLUGIN_STREAM_API
-
/* NOTE: the caller must free the stream listener */
NS_IMETHODIMP ns4xPluginInstance::NewStream(nsIPluginStreamListener** listener)
@@ -470,33 +471,6 @@ nsresult ns4xPluginInstance::NewNotifyStream(nsIPluginStreamListener** listener,
return NS_OK;
}
-#else
-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;
-}
-#endif
-
NS_IMETHODIMP ns4xPluginInstance::Print(nsPluginPrint* platformPrint)
{
printf("instance print called\n");
@@ -511,23 +485,6 @@ printf("instance handleevent called\n");
return NS_OK;
}
-#ifndef NEW_PLUGIN_STREAM_API
-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...
-}
-#endif
-
NS_IMETHODIMP ns4xPluginInstance :: GetValue(nsPluginInstanceVariable variable, void *value)
{
nsresult rv = NS_OK;
diff --git a/mozilla/modules/plugin/nglsrc/ns4xPluginInstance.h b/mozilla/modules/plugin/nglsrc/ns4xPluginInstance.h
index f1b1c1ff39a..be9334d4df3 100644
--- a/mozilla/modules/plugin/nglsrc/ns4xPluginInstance.h
+++ b/mozilla/modules/plugin/nglsrc/ns4xPluginInstance.h
@@ -61,23 +61,12 @@ public:
NS_IMETHOD
SetWindow(nsPluginWindow* window);
-#ifdef NEW_PLUGIN_STREAM_API
NS_IMETHOD
NewStream(nsIPluginStreamListener** listener);
-#else
- NS_IMETHOD
- NewStream(nsIPluginStreamPeer* peer, nsIPluginStream* *result);
-#endif
NS_IMETHOD
Print(nsPluginPrint* platformPrint);
-#ifndef NEW_PLUGIN_STREAM_API
- NS_IMETHOD
- URLNotify(const char* url, const char* target,
- nsPluginReason reason, void* notifyData);
-#endif
-
NS_IMETHOD
GetValue(nsPluginInstanceVariable variable, void *value);
diff --git a/mozilla/modules/plugin/nglsrc/nsIPluginHost.h b/mozilla/modules/plugin/nglsrc/nsIPluginHost.h
index a96e10654e5..b097dceb7d3 100644
--- a/mozilla/modules/plugin/nglsrc/nsIPluginHost.h
+++ b/mozilla/modules/plugin/nglsrc/nsIPluginHost.h
@@ -50,7 +50,7 @@ public:
GetPluginFactory(const char *aMimeType, nsIPlugin** aPlugin) = 0;
NS_IMETHOD
- InstantiateEmbededPlugin(const char *aMimeType, nsString& aURLSpec, nsIPluginInstanceOwner *aOwner) = 0;
+ InstantiateEmbededPlugin(const char *aMimeType, nsIURL* aURL, nsIPluginInstanceOwner *aOwner) = 0;
NS_IMETHOD
InstantiateFullPagePlugin(const char *aMimeType, nsString& aURLSpec, nsIStreamListener *&aStreamListener, nsIPluginInstanceOwner *aOwner) = 0;
diff --git a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp
index 2fe075eed98..57d6011d75b 100644
--- a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp
+++ b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp
@@ -23,15 +23,11 @@
#include "ns4xPlugin.h"
#include "nsPluginInstancePeer.h"
-#ifdef NEW_PLUGIN_STREAM_API
#include "nsIPluginStreamListener.h"
-#else
-#include "nsPluginStreamPeer.h"
-#endif
-
#include "nsIStreamListener.h"
#include "nsIURL.h"
#include "nsIInputStream.h"
+#include "nsIOutputStream.h"
#include "nsINetService.h"
#include "nsIServiceManager.h"
#include "prprf.h"
@@ -66,11 +62,7 @@ static NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID);
static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID);
static NS_DEFINE_IID(kIPluginManager2IID, NS_IPLUGINMANAGER2_IID);
static NS_DEFINE_IID(kIPluginHostIID, NS_IPLUGINHOST_IID);
-#ifdef NEW_PLUGIN_STREAM_API
static NS_DEFINE_IID(kIPluginStreamInfoIID, NS_IPLUGINSTREAMINFO_IID);
-#else
-static NS_DEFINE_IID(kIPluginStreamPeerIID, NS_IPLUGINSTREAMPEER_IID);
-#endif
static NS_DEFINE_CID(kPluginCID, NS_PLUGIN_CID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
@@ -79,6 +71,7 @@ static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
static NS_DEFINE_IID(kINetServiceIID, NS_INETSERVICE_IID);
static NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID);
static NS_DEFINE_IID(kIFileUtilitiesIID, NS_IFILEUTILITIES_IID);
+static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
nsPluginTag :: nsPluginTag()
{
@@ -156,8 +149,6 @@ nsPluginTag :: ~nsPluginTag()
}
}
-#ifdef NEW_PLUGIN_STREAM_API
-
class nsPluginStreamInfo : public nsIPluginStreamInfo
{
public:
@@ -181,26 +172,33 @@ public:
NS_IMETHOD
GetLastModified(PRUint32* result);
+ NS_IMETHOD
+ GetURL(const char** result);
+
NS_IMETHOD
RequestRead(nsByteRange* rangeList);
// local methods
void
- SetContentType(const nsMIMEType result);
+ SetContentType(const nsMIMEType contentType);
void
- SetSeekable(const PRBool result);
+ SetSeekable(const PRBool seekable);
void
- SetLength(const PRUint32 result);
+ SetLength(const PRUint32 length);
void
- SetLastModified(const PRUint32 result);
+ SetLastModified(const PRUint32 modified);
+
+ void
+ SetURL(const char* url);
private:
char* mContentType;
+ char* mURL;
PRBool mSeekable;
PRUint32 mLength;
PRUint32 mModified;
@@ -211,6 +209,7 @@ nsPluginStreamInfo::nsPluginStreamInfo()
NS_INIT_REFCNT();
mContentType = nsnull;
+ mURL = nsnull;
mSeekable = PR_FALSE;
mLength = 0;
mModified = 0;
@@ -220,6 +219,8 @@ nsPluginStreamInfo::~nsPluginStreamInfo()
{
if(mContentType != nsnull)
PL_strfree(mContentType);
+ if(mURL != nsnull)
+ PL_strfree(mURL);
}
NS_IMPL_ADDREF(nsPluginStreamInfo)
@@ -278,6 +279,13 @@ nsPluginStreamInfo::GetLastModified(PRUint32* result)
return NS_OK;
}
+NS_IMETHODIMP
+nsPluginStreamInfo::GetURL(const char** result)
+{
+ *result = mURL;
+ return NS_OK;
+}
+
NS_IMETHODIMP
nsPluginStreamInfo::RequestRead(nsByteRange* rangeList)
{
@@ -313,7 +321,18 @@ nsPluginStreamInfo::SetLastModified(const PRUint32 modified)
mModified = modified;
}
-#endif
+void
+nsPluginStreamInfo::SetURL(const char* url)
+{
+ if(mURL != nsnull)
+ PL_strfree(mURL);
+
+ mURL = PL_strdup(url);
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+class nsPluginCacheListener;
class nsPluginStreamListenerPeer : public nsIStreamListener
{
@@ -333,71 +352,283 @@ public:
NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg);
- //NS_IMETHOD OnNotify(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg);
-
//nsIStreamListener interface
NS_IMETHOD GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* aInfo);
- NS_IMETHOD OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream,
- PRUint32 aLength);
+ NS_IMETHOD OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream, PRUint32 aLength);
//locals
// Called by GetURL and PostURL (via NewStream)
-#ifdef NEW_PLUGIN_STREAM_API
nsresult Initialize(nsIURL *aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener);
-#else
- nsresult Initialize(nsIURL *aURL, nsIPluginInstance *aInstance, void *aNotifyData);
-#endif
nsresult InitializeEmbeded(nsIURL *aURL, nsIPluginInstance* aInstance, nsIPluginInstanceOwner *aOwner = nsnull,
nsIPluginHost *aHost = nsnull);
nsresult InitializeFullPage(nsIPluginInstance *aInstance);
+ nsresult OnFileAvailable(const char* aFilename);
+
private:
-#ifdef NEW_PLUGIN_STREAM_API
nsresult SetUpCache(nsIURL* aURL);
nsresult SetUpStreamListener(nsIURL* aURL);
-#else
- nsresult SetUpStreamPeer(nsIURL* aURL, nsIPluginInstance *instance,
- const char* aContentType, PRInt32 aProgressMax = 0);
-#endif
nsIURL *mURL;
nsIPluginInstanceOwner *mOwner;
nsIPluginInstance *mInstance;
-#ifdef NEW_PLUGIN_STREAM_API
nsIPluginStreamListener *mPStreamListener;
nsPluginStreamInfo *mPluginStreamInfo;
PRBool mSetUpListener;
-#else
- nsPluginStreamPeer *mPeer;
- nsIPluginStream *mStream;
- void *mNotifyData;
-#endif // NEW_PLUGIN_STREAM_API
// these get passed to the plugin stream listener
char *mMIMEType;
PRUint32 mLength;
nsPluginStreamType mStreamType;
-
- PRUint8 *mBuffer;
- PRUint32 mBufSize;
nsIPluginHost *mHost;
PRBool mGotProgress;
PRBool mOnStartBinding;
+ PRBool mCacheDone;
+ PRBool mOnStopBinding;
+ nsresult mStatus;
+
#ifdef USE_CACHE
nsCacheObject* mCachedFile;
#else
FILE* mStreamFile;
+ char* mFileName;
#endif
};
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+class nsPluginCacheListener : public nsIStreamListener
+{
+public:
+ nsPluginCacheListener(nsPluginStreamListenerPeer* aListener);
+ ~nsPluginCacheListener();
+
+ NS_DECL_ISUPPORTS
+
+ //nsIStreamObserver interface
+
+ NS_IMETHOD OnStartBinding(nsIURL* aURL, const char *aContentType);
+
+ NS_IMETHOD OnProgress(nsIURL* aURL, PRUint32 aProgress, PRUint32 aProgressMax);
+
+ NS_IMETHOD OnStatus(nsIURL* aURL, const PRUnichar* aMsg);
+
+ NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg);
+
+ //nsIStreamListener interface
+
+ NS_IMETHOD GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* aInfo);
+
+ NS_IMETHOD OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream, PRUint32 aLength);
+
+private:
+
+ nsPluginStreamListenerPeer* mListener;
+
+#ifdef USE_CACHE
+ nsCacheObject* mCachedFile;
+#else
+ FILE* mStreamFile;
+ char* mFileName;
+#endif
+};
+
+nsPluginCacheListener :: nsPluginCacheListener(nsPluginStreamListenerPeer* aListener)
+{
+ NS_INIT_REFCNT();
+
+ mListener = aListener;
+ NS_ADDREF(mListener);
+
+#ifdef USE_CACHE
+ mCachedFile = nsnull;
+#else
+ mStreamFile = nsnull;
+ mFileName = nsnull;
+#endif
+}
+
+nsPluginCacheListener :: ~nsPluginCacheListener()
+{
+
+ NS_IF_RELEASE(mListener);
+
+#ifdef USE_CACHE
+ if (nsnull != mCachedFile)
+ {
+ delete mCachedFile;
+ mCachedFile = nsnull;
+ }
+#else // USE_CACHE
+ if(nsnull != mStreamFile)
+ {
+ fclose(mStreamFile);
+ mStreamFile = nsnull;
+ }
+
+ if(nsnull != mFileName)
+ PL_strfree(mFileName);
+#endif // USE_CACHE
+}
+
+NS_IMPL_ISUPPORTS(nsPluginCacheListener, kIStreamListenerIID);
+
+NS_IMETHODIMP
+nsPluginCacheListener::OnStartBinding(nsIURL* aURL, const char *aContentType)
+{
+#ifdef USE_CACHE
+ nsString urlString;
+ char* cString;
+ char* fileName;
+
+ aURL->ToString(urlString);
+ cString = urlString.ToNewCString();
+ mCachedFile = new nsCacheObject(cString);
+ delete [] cString;
+
+ if(mCachedFile == nsnull)
+ return NS_ERROR_OUT_OF_MEMORY;
+
+ // use the actual filename of the net-based file as the cache filename
+ aURL->GetFile(fileName);
+ mCachedFile->Filename(fileName);
+
+ nsCacheManager* cacheManager = nsCacheManager::GetInstance();
+ nsDiskModule* diskCache = cacheManager->GetDiskModule();
+ diskCache->AddObject(mCachedFile);
+#else // USE_CACHE
+ char buf[400], tpath[300];
+#ifdef XP_PC
+ ::GetTempPath(sizeof(tpath), tpath);
+ PRInt32 len = PL_strlen(tpath);
+
+ if((len > 0) && (tpath[len-1] != '\\'))
+ {
+ tpath[len] = '\\';
+ tpath[len+1] = 0;
+ }
+#elif defined (XP_UNIX)
+ PL_strcpy(tpath, "/tmp/");
+#else
+ tpath[0] = 0;
+#endif // XP_PC
+ const char* pathName;
+ char* fileName;
+ aURL->GetFile(&pathName);
+
+ // since GetFile actually returns us the full path, move to the last \ and skip it
+ fileName = PL_strrchr(pathName, '/');
+ if(fileName)
+ ++fileName;
+
+ // if we don't get a filename for some reason, just make one up using the address of this
+ // object to ensure uniqueness of the filename per stream
+ if(!fileName)
+ PR_snprintf(buf, sizeof(buf), "%s%08X.ngl", tpath, this);
+ else
+ PR_snprintf(buf, sizeof(buf), "%s%s", tpath, fileName);
+
+ mStreamFile = fopen(buf, "wb");
+ //setbuf(mStreamFile, NULL);
+
+ mFileName = PL_strdup(buf);
+#endif // USE_CACHE
+ return NS_OK;
+
+}
+
+NS_IMETHODIMP
+nsPluginCacheListener::OnProgress(nsIURL* aURL, PRUint32 aProgress, PRUint32 aProgressMax)
+{
+ return NS_OK;
+}
+
+
+NS_IMETHODIMP
+nsPluginCacheListener::OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream, PRUint32 aLength)
+{
+ PRUint32 readlen;
+ char* buffer = (char*) PR_Malloc(aLength);
+ if(buffer)
+ aIStream->Read(buffer, aLength, &readlen);
+ else
+ return NS_ERROR_OUT_OF_MEMORY;
+
+ NS_ASSERTION(aLength == readlen, "nsCacheListener->OnDataAvailable: readlen != aLength");
+
+#ifdef USE_CACHE
+ if(nsnull != mCachedFile)
+ mCachedFile->Write((char*)buffer, readlen);
+#else
+ if(nsnull != mStreamFile)
+ fwrite(buffer, sizeof(char), readlen, mStreamFile);
+#endif // USE_CACHE
+ PR_Free(buffer);
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsPluginCacheListener::OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg)
+{
+#ifdef USE_CACHE
+ if (nsnull != mCachedFile)
+ {
+ PRInt32 len;
+ nsCachePref* cachePref = nsCachePref::GetInstance();
+
+ const char* cachePath = cachePref->DiskCacheFolder();
+ const char* filename = mCachedFile->Filename();
+
+ // we need to pass the whole path and filename to the plugin
+ len = PL_strlen(cachePath) + PL_strlen(filename) + 1;
+ char* pathAndFilename = (char*)PR_Malloc(len * sizeof(char));
+ pathAndFilename = PL_strcpy(pathAndFilename, cachePath);
+ pathAndFilename = PL_strcat(pathAndFilename, filename);
+
+ const char* urlString;
+ aURL->GetSpec(&urlString);
+
+ if (mListener)
+ mListener->OnFileAvailable(pathAndFilename);
+ }
+#else // USE_CACHE
+ if(nsnull != mStreamFile)
+ {
+ fclose(mStreamFile);
+ mStreamFile = nsnull;
+
+ if (mListener)
+ mListener->OnFileAvailable(mFileName);
+ }
+#endif // USE_CACHE
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsPluginCacheListener::GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* aInfo)
+{
+ // not used
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsPluginCacheListener::OnStatus(nsIURL* aURL, const PRUnichar* aMsg)
+{
+ // not used
+ return NS_OK;
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////
+
nsPluginStreamListenerPeer :: nsPluginStreamListenerPeer()
{
NS_INIT_REFCNT();
@@ -405,30 +636,23 @@ nsPluginStreamListenerPeer :: nsPluginStreamListenerPeer()
mURL = nsnull;
mOwner = nsnull;
mInstance = nsnull;
-
-#ifdef NEW_PLUGIN_STREAM_API
mPStreamListener = nsnull;
mPluginStreamInfo = nsnull;
mSetUpListener = PR_FALSE;
-#else
- mPeer = nsnull;
- mStream = nsnull;
- mNotifyData = nsnull;
- mMIMEType = nsnull;
- mLength = 0;
-#endif // NEW_PLUGIN_STREAM_API
-
- mBuffer = nsnull;
- mBufSize = 0;
mHost = nsnull;
mGotProgress = PR_FALSE;
mOnStartBinding = PR_FALSE;
mStreamType = nsPluginStreamType_Normal;
+ mOnStopBinding = PR_FALSE;
+ mCacheDone = PR_FALSE;
+ mStatus = NS_OK;
+
#ifdef USE_CACHE
mCachedFile = nsnull;
#else
mStreamFile = nsnull;
+ mFileName = nsnull;
#endif
}
@@ -446,27 +670,7 @@ nsPluginStreamListenerPeer :: ~nsPluginStreamListenerPeer()
NS_IF_RELEASE(mURL);
NS_IF_RELEASE(mOwner);
NS_IF_RELEASE(mInstance);
-
-#ifdef NEW_PLUGIN_STREAM_API
NS_IF_RELEASE(mPStreamListener);
-#else
- NS_IF_RELEASE(mStream);
- NS_IF_RELEASE(mPeer);
- mNotifyData = nsnull;
-
- if (nsnull != mMIMEType)
- {
- PR_Free(mMIMEType);
- mMIMEType = nsnull;
- }
-#endif // NEW_PLUGIN_STREAM_API
-
- if (nsnull != mBuffer)
- {
- PR_Free(mBuffer);
- mBuffer = nsnull;
- }
-
NS_IF_RELEASE(mHost);
#ifdef USE_CACHE
@@ -481,11 +685,15 @@ nsPluginStreamListenerPeer :: ~nsPluginStreamListenerPeer()
fclose(mStreamFile);
mStreamFile = nsnull;
}
+
+ if(nsnull != mFileName)
+ PL_strfree(mFileName);
+
#endif // USE_CACHE
}
-NS_IMPL_ADDREF(nsPluginStreamListenerPeer)
-NS_IMPL_RELEASE(nsPluginStreamListenerPeer)
+NS_IMPL_ADDREF(nsPluginStreamListenerPeer);
+NS_IMPL_RELEASE(nsPluginStreamListenerPeer);
nsresult nsPluginStreamListenerPeer :: QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
@@ -519,8 +727,6 @@ nsresult nsPluginStreamListenerPeer :: QueryInterface(const nsIID& aIID,
return NS_NOINTERFACE;
}
-#ifdef NEW_PLUGIN_STREAM_API
-
/* Called as a result of GetURL and PostURL */
nsresult nsPluginStreamListenerPeer :: Initialize(nsIURL *aURL, nsIPluginInstance *aInstance,
@@ -542,35 +748,10 @@ nsresult nsPluginStreamListenerPeer :: Initialize(nsIURL *aURL, nsIPluginInstanc
NS_ADDREF(mPStreamListener);
mPluginStreamInfo = new nsPluginStreamInfo();
- //mPStreamListener->GetStreamType(&mStreamType);
return NS_OK;
}
-#else
-
-/* Called as a result of GetURL and PostURL - NewPluginURLStream() */
-
-nsresult nsPluginStreamListenerPeer :: Initialize(nsIURL *aURL, nsIPluginInstance *aInstance, void *aNotifyData)
-{
-#ifdef NS_DEBUG
- const char* spec;
- (void)aURL->GetSpec(&spec);
- printf("created stream for %s\n", spec);
-#endif
- mURL = aURL;
- NS_ADDREF(mURL);
-
- mInstance = aInstance;
- NS_ADDREF(mInstance);
-
- mNotifyData = aNotifyData;
-
- return NS_OK;
-}
-
-#endif
-
/*
Called by NewEmbededPluginStream() - if this is called, we weren't able to load the plugin,
so we need to load it later once we figure out the mimetype. In order to load it later,
@@ -604,9 +785,7 @@ nsresult nsPluginStreamListenerPeer :: InitializeEmbeded(nsIURL *aURL, nsIPlugin
NS_IF_ADDREF(mHost);
}
-#ifdef NEW_PLUGIN_STREAM_API
mPluginStreamInfo = new nsPluginStreamInfo();
-#endif
return NS_OK;
}
@@ -622,9 +801,7 @@ nsresult nsPluginStreamListenerPeer :: InitializeFullPage(nsIPluginInstance *aIn
mInstance = aInstance;
NS_ADDREF(mInstance);
-#ifdef NEW_PLUGIN_STREAM_API
mPluginStreamInfo = new nsPluginStreamInfo();
-#endif
return NS_OK;
}
@@ -635,19 +812,7 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnStartBinding(nsIURL* aURL, const cha
nsresult rv = NS_OK;
if (nsnull != aContentType)
- {
-#ifdef NEW_PLUGIN_STREAM_API
- mPluginStreamInfo->SetContentType(aContentType);
-#else
- PRInt32 len = PL_strlen(aContentType);
- mMIMEType = (char *)PR_Malloc(len + 1);
-
- if (nsnull != mMIMEType)
- PL_strcpy(mMIMEType, aContentType);
- else
- rv = NS_ERROR_OUT_OF_MEMORY;
-#endif
- }
+ mPluginStreamInfo->SetContentType(aContentType);
nsPluginWindow *window = nsnull;
@@ -680,15 +845,10 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnStartBinding(nsIURL* aURL, const cha
}
}
-#ifdef NEW_PLUGIN_STREAM_API
// only set up the stream listener if we have both the mimetype and
// have mLength set (as indicated by the mGotProgress bool)
if(mGotProgress == PR_TRUE && mSetUpListener == PR_FALSE)
rv = SetUpStreamListener(aURL);
-#else
- if ((PR_TRUE == mGotProgress) && (nsnull == mPeer) && (nsnull != mInstance))
- rv = SetUpStreamPeer(aURL, mInstance, aContentType);
-#endif
mOnStartBinding = PR_TRUE;
return rv;
@@ -699,34 +859,9 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnProgress(nsIURL* aURL, PRUint32 aP
{
nsresult rv = NS_OK;
-#ifdef NEW_PLUGIN_STREAM_API
-
mPluginStreamInfo->SetLength(aProgressMax);
- // if OnStartBinding already got called,
if(mOnStartBinding == PR_TRUE && mSetUpListener == PR_FALSE)
rv = SetUpStreamListener(aURL);
-#else
-
- mLength = aProgressMax;
- if ((aProgress == 0) && (nsnull == mPeer))
- {
- nsIPluginInstance *instance = nsnull;
-
- if (nsnull == mInstance)
- mOwner->GetInstance(instance);
- else
- {
- instance = mInstance;
- NS_ADDREF(instance);
- }
-
- if (nsnull != instance)
- {
- rv = SetUpStreamPeer(aURL, instance, nsnull, aProgressMax);
- NS_RELEASE(instance);
- }
- }
-#endif
mGotProgress = PR_TRUE;
@@ -746,41 +881,45 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: GetBindInfo(nsIURL* aURL, nsStreamBi
NS_IMETHODIMP nsPluginStreamListenerPeer :: OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream,
PRUint32 aLength)
{
-#ifdef NEW_PLUGIN_STREAM_API
- nsresult rv;
+ nsresult rv = NS_OK;
const char* url;
- aURL->GetSpec(&url);
- rv = mPStreamListener->OnDataAvailable(url, aIStream, 0, aLength,(nsIPluginStreamInfo*)mPluginStreamInfo);
- return rv;
-#else
- if (aLength > mBufSize)
- {
- if (nsnull != mBuffer)
- PR_Free((void *)mBuffer);
+ char* buffer;
+ PRUint32 readlen;
- mBuffer = (PRUint8 *)PR_Malloc(aLength);
- mBufSize = aLength;
- }
+ if(!mPStreamListener)
+ return NS_ERROR_FAILURE;
- if ((nsnull != mBuffer) && (nsnull != mStream))
- {
- PRUint32 readlen;
- aIStream->Read((char *)mBuffer, 0, aLength, &readlen);
+ const char* urlString;
+ aURL->GetSpec(&urlString);
+ mPluginStreamInfo->SetURL(urlString);
+
+#if 0
+ // determine if we need to write the data to the cache
+ if((mStreamType == nsPluginStreamType_AsFile) || (mStreamType == nsPluginStreamType_AsFileOnly))
+ {
+ buffer = (char*) PR_Malloc(aLength);
+ if(buffer)
+ aIStream->Read(buffer, aLength, &readlen);
#ifdef USE_CACHE
if(nsnull != mCachedFile)
- mCachedFile->Write((char*)mBuffer, aLength);
+ mCachedFile->Write((char*)buffer, aLength);
#else
if(nsnull != mStreamFile)
- fwrite(mBuffer, 1, aLength, mStreamFile);
+ fwrite(buffer, sizeof(char), aLength, mStreamFile);
+#endif // USE_CACHE
+ PR_Free(buffer);
+ }
#endif
- if (mStreamType != nsPluginStreamType_AsFileOnly)
- mStream->Write((char *)mBuffer, 0, aLength, &readlen);
- }
+ // if the plugin has requested an AsFileOnly stream, then don't call OnDataAvailable
+ if(mStreamType != nsPluginStreamType_AsFileOnly)
+ {
+ aURL->GetSpec(&url);
+ rv = mPStreamListener->OnDataAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, aIStream, aLength);
+ }
- return NS_OK;
-#endif // NEW_PLUGIN_STREAM_API
+ return rv;
}
NS_IMETHODIMP nsPluginStreamListenerPeer :: OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg)
@@ -788,32 +927,20 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnStopBinding(nsIURL* aURL, nsresult
nsresult rv = NS_OK;
nsPluginReason reason = nsPluginReason_NoReason;
- //XXX this is incomplete... MMP
-#ifndef NEW_PLUGIN_STREAM_API
- if (nsnull != mPeer)
- {
- if (aStatus == NS_BINDING_SUCCEEDED)
- reason = nsPluginReason_Done;
- else
- reason = nsPluginReason_UserBreak;
-
- mPeer->SetReason(reason);
-
- rv = NS_OK;
- }
- else
- rv = NS_ERROR_UNEXPECTED;
-#endif
-
-#ifdef NEW_PLUGIN_STREAM_API
if(nsnull != mPStreamListener)
-#else
- if (nsnull != mStream)
-#endif // NEW_PLUGIN_STREAM_API
{
+ const char* url;
+ aURL->GetSpec(&url);
+
+ const char* urlString;
+ aURL->GetSpec(&urlString);
+ mPluginStreamInfo->SetURL(urlString);
+
+#if 0
+ // see if we need to close out the cache
if ((mStreamType == nsPluginStreamType_AsFile) ||
(mStreamType == nsPluginStreamType_AsFileOnly))
- {
+ {
#ifdef USE_CACHE
if (nsnull != mCachedFile)
{
@@ -828,110 +955,45 @@ NS_IMETHODIMP nsPluginStreamListenerPeer :: OnStopBinding(nsIURL* aURL, nsresult
char* pathAndFilename = (char*)PR_Malloc(len * sizeof(char));
pathAndFilename = PL_strcpy(pathAndFilename, cachePath);
pathAndFilename = PL_strcat(pathAndFilename, filename);
-#ifdef NEW_PLUGIN_STREAM_API
+
const char* urlString;
aURL->GetSpec(&urlString);
if (mPStreamListener)
- mPStreamListener->OnFileAvailable(urlString, pathAndFilename);
-#else
- mStream->AsFile(pathAndFilename);
-#endif // NEW_PLUGIN_STREAM_API
- }
+ mPStreamListener->OnFileAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, pathAndFilename);
+ }
#else // USE_CACHE
if(nsnull != mStreamFile)
- {
+ {
fclose(mStreamFile);
mStreamFile = nsnull;
- char buf[400], tpath[300];
-#ifdef XP_PC
- ::GetTempPath(sizeof(tpath), tpath);
- PRInt32 len = PL_strlen(tpath);
-
- if((len > 0) && (tpath[len-1] != '\\'))
- {
- tpath[len] = '\\';
- tpath[len+1] = 0;
- }
-#elif defined (XP_UNIX)
- PL_strcpy(tpath, "/tmp/");
-#else
- tpath[0] = 0;
-#endif // XP_PC
- PR_snprintf(buf, sizeof(buf), "%s%08X.ngl", tpath, this);
-#ifdef NEW_PLUGIN_STREAM_API
- const char* urlString;
- aURL->GetSpec(&urlString);
if (mPStreamListener)
- mPStreamListener->OnFileAvailable(urlString, buf);
-#else
- mStream->AsFile(buf);
-#endif // NEW_PLUGIN_STREAM_API
- }
+ mPStreamListener->OnFileAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, mFileName);
+ }
#endif // USE_CACHE
}
+#endif
-#ifdef NEW_PLUGIN_STREAM_API
- const char* url;
- aURL->GetSpec(&url);
- if (mPStreamListener)
- {
- mPStreamListener->OnStopBinding(url, aStatus, (nsIPluginStreamInfo*)mPluginStreamInfo);
- mPStreamListener->OnNotify(url, aStatus);
- }
-#else
- nsIPluginInstance *instance = nsnull;
-
- if (nsnull == mInstance)
- mOwner->GetInstance(instance);
- else
- {
- instance = mInstance;
- NS_ADDREF(instance);
- }
-
- mStream->Close();
-
- if (nsnull != instance)
- {
- if (nsnull != mNotifyData)
- {
- const char *url;
-
- if (nsnull != mURL)
- rv = mURL->GetSpec(&url);
- else
- url = "";
-
- //XXX target is bad. MMP
- if (url)
- instance->URLNotify(url, "", reason, mNotifyData);
- }
-
- NS_RELEASE(instance);
- }
-#endif // NEW_PLUGIN_STREAM_API
+ // tell the plugin that the stream has ended only if the cache is done
+ if(mCacheDone)
+ mPStreamListener->OnStopBinding((nsIPluginStreamInfo*)mPluginStreamInfo, aStatus);
+ else // otherwise, we store the status so we can report it later in OnFileAvailable
+ mStatus = aStatus;
}
+ mOnStopBinding = PR_TRUE;
return rv;
}
-
-/*NS_IMETHODIMP nsPluginStreamListenerPeer :: OnNotify(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg)
-{
- return NS_OK;
-}*/
-
-
// private methods for nsPluginStreamListenerPeer
-#ifdef NEW_PLUGIN_STREAM_API
-
nsresult nsPluginStreamListenerPeer::SetUpCache(nsIURL* aURL)
{
+#if 0
#ifdef USE_CACHE
nsString urlString;
char* cString;
+ char* fileName;
aURL->ToString(urlString);
cString = urlString.ToNewCString();
@@ -942,12 +1004,14 @@ nsresult nsPluginStreamListenerPeer::SetUpCache(nsIURL* aURL)
return NS_ERROR_OUT_OF_MEMORY;
// use the actual filename of the net-based file as the cache filename
- mCachedFile->Filename(aURL->GetFile());
+ aURL->GetFile(fileName);
+ mCachedFile->Filename(fileName);
nsCacheManager* cacheManager = nsCacheManager::GetInstance();
nsDiskModule* diskCache = cacheManager->GetDiskModule();
diskCache->AddObject(mCachedFile);
#else // USE_CACHE
+
char buf[400], tpath[300];
#ifdef XP_PC
::GetTempPath(sizeof(tpath), tpath);
@@ -963,10 +1027,32 @@ nsresult nsPluginStreamListenerPeer::SetUpCache(nsIURL* aURL)
#else
tpath[0] = 0;
#endif // XP_PC
- PR_snprintf(buf, sizeof(buf), "%s%08X.ngl", tpath, this);
+ const char* pathName;
+ char* fileName;
+ aURL->GetFile(&pathName);
+
+ // since GetFile actually returns us the full path, move to the last \ and skip it
+ fileName = PL_strrchr(pathName, '/');
+ if(fileName)
+ ++fileName;
+
+ // if we don't get a filename for some reason, just make one up using the address of this
+ // object to ensure uniqueness of the filename per stream
+ if(!fileName)
+ PR_snprintf(buf, sizeof(buf), "%s%08X.ngl", tpath, this);
+ else
+ PR_snprintf(buf, sizeof(buf), "%s%s", tpath, fileName);
+
mStreamFile = fopen(buf, "wb");
+ //setbuf(mStreamFile, NULL);
+
+ mFileName = PL_strdup(buf);
#endif // USE_CACHE
return NS_OK;
+#endif
+
+ nsPluginCacheListener* cacheListener = new nsPluginCacheListener(this);
+ return NS_OpenURL(aURL, cacheListener);
}
nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIURL* aURL)
@@ -987,88 +1073,41 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIURL* aURL)
return NS_ERROR_NULL_POINTER;
mSetUpListener = PR_TRUE;
-
- mPStreamListener->GetStreamType(&mStreamType);
- if ((mStreamType == nsPluginStreamType_AsFile) ||
- (mStreamType == nsPluginStreamType_AsFileOnly))
- SetUpCache(aURL);
-
mPluginStreamInfo->SetSeekable(PR_FALSE);
//mPluginStreamInfo->SetModified(??);
const char* urlString;
aURL->GetSpec(&urlString);
- return mPStreamListener->OnStartBinding(urlString, (nsIPluginStreamInfo*)mPluginStreamInfo);
-}
+ mPluginStreamInfo->SetURL(urlString);
-#else
+ rv = mPStreamListener->OnStartBinding((nsIPluginStreamInfo*)mPluginStreamInfo);
-nsresult nsPluginStreamListenerPeer::SetUpStreamPeer(nsIURL* aURL, nsIPluginInstance *instance,
- const char* aContentType, PRInt32 aProgressMax)
-{
- mPeer = (nsPluginStreamPeer *)new nsPluginStreamPeer();
- if(mPeer == nsnull)
- return NS_ERROR_OUT_OF_MEMORY;
- NS_ADDREF(mPeer);
-
- if(aContentType != nsnull)
- mPeer->Initialize(aURL, mLength, 0, aContentType, mNotifyData);
- else
- mPeer->Initialize(aURL, aProgressMax, 0, mMIMEType, mNotifyData);
-
- instance->NewStream(mPeer, &mStream);
-
- if (nsnull != mStream)
- mStream->GetStreamType(&mStreamType);
-
- // check to see if we need to cache the file
- if ((mStreamType == nsPluginStreamType_AsFile) ||
- (mStreamType == nsPluginStreamType_AsFileOnly))
- {
-#ifdef USE_CACHE
- nsString urlString;
- char* cString;
-
- aURL->ToString(urlString);
- cString = urlString.ToNewCString();
- mCachedFile = new nsCacheObject(cString);
- delete [] cString;
-
- if(mCachedFile == nsnull)
- return NS_ERROR_OUT_OF_MEMORY;
-
- // use the actual filename of the net-based file as the cache filename
- //mCachedFile->Filename(aURL->GetFile());
- mCachedFile->Filename("xmas1.mid");
-
- nsCacheManager* cacheManager = nsCacheManager::GetInstance();
- nsDiskModule* diskCache = cacheManager->GetDiskModule();
- diskCache->AddObject(mCachedFile);
-#else // USE_CACHE
- char buf[400], tpath[300];
-#ifdef XP_PC
- ::GetTempPath(sizeof(tpath), tpath);
- PRInt32 len = PL_strlen(tpath);
-
- if((len > 0) && (tpath[len-1] != '\\'))
- {
- tpath[len] = '\\';
- tpath[len+1] = 0;
- }
-#elif defined (XP_UNIX)
- PL_strcpy(tpath, "/tmp/");
-#else
- tpath[0] = 0;
-#endif // XP_PC
- PR_snprintf(buf, sizeof(buf), "%s%08X.ngl", tpath, this);
- mStreamFile = fopen(buf, "wb");
-#endif // USE_CACHE
+ if(rv == NS_OK)
+ {
+ mPStreamListener->GetStreamType(&mStreamType);
+ // check to see if we need to cache the file as well
+ if ((mStreamType == nsPluginStreamType_AsFile) || (mStreamType == nsPluginStreamType_AsFileOnly))
+ rv = SetUpCache(aURL);
}
- return NS_OK;
+ return rv;
}
-#endif // NEW_PLUGIN_STREAM_API
+nsresult
+nsPluginStreamListenerPeer::OnFileAvailable(const char* aFilename)
+{
+ nsresult rv = NS_ERROR_FAILURE;
+ if (mPStreamListener)
+ rv = mPStreamListener->OnFileAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, aFilename);
+
+ if(mOnStopBinding)
+ mPStreamListener->OnStopBinding((nsIPluginStreamInfo*)mPluginStreamInfo, mStatus);
+
+ mCacheDone = PR_TRUE;
+ return rv;
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////
nsPluginHostImpl :: nsPluginHostImpl(nsIServiceManager *serviceMgr)
{
@@ -1194,8 +1233,6 @@ nsresult nsPluginHostImpl :: UserAgent(const char **retstring)
return res;
}
-#ifdef NEW_PLUGIN_STREAM_API
-
NS_IMETHODIMP nsPluginHostImpl::GetURL(nsISupports* pluginInst,
const char* url,
const char* target,
@@ -1317,114 +1354,6 @@ NS_IMETHODIMP nsPluginHostImpl::PostURL(nsISupports* pluginInst,
return rv;
}
-#else
-
-NS_IMETHODIMP nsPluginHostImpl :: GetURL(nsISupports* inst, const char* url,
- const char* target,
- void* notifyData, const char* altHost,
- const char* referrer, PRBool forceJSEnabled)
-{
- nsAutoString string = nsAutoString(url);
- nsIPluginInstance *instance;
- nsresult rv;
-
- rv = inst->QueryInterface(kIPluginInstanceIID, (void **)&instance);
-
- if (NS_OK == rv)
- {
- if (nsnull != target)
- {
- nsPluginInstancePeerImpl *peer;
-
- rv = instance->GetPeer((nsIPluginInstancePeer **)&peer);
-
- if (NS_OK == rv)
- {
- nsIPluginInstanceOwner *owner;
-
- rv = peer->GetOwner(owner);
-
- if (NS_OK == rv)
- {
- if ((0 == PL_strcmp(target, "newwindow")) ||
- (0 == PL_strcmp(target, "_new")))
- target = "_blank";
- else if (0 == PL_strcmp(target, "_current"))
- target = "_self";
-
- rv = owner->GetURL(url, target, nsnull);
- NS_RELEASE(owner);
- }
-
- NS_RELEASE(peer);
- }
- }
-
- if ((nsnull != notifyData) || (nsnull == target))
- rv = NewPluginURLStream(string, instance, notifyData);
-
- NS_RELEASE(instance);
- }
-
- return rv;
-}
-
-NS_IMETHODIMP nsPluginHostImpl :: PostURL(nsISupports* inst,
- 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)
-{
-
- nsAutoString string = nsAutoString(url);
- nsIPluginInstance *instance;
- nsresult rv;
-
- rv = inst->QueryInterface(kIPluginInstanceIID, (void **)&instance);
-
- if (NS_OK == rv)
- {
- if (nsnull != target)
- {
- nsPluginInstancePeerImpl *peer;
-
- rv = instance->GetPeer((nsIPluginInstancePeer **)&peer);
-
- if (NS_OK == rv)
- {
- nsIPluginInstanceOwner *owner;
-
- rv = peer->GetOwner(owner);
-
- if (NS_OK == rv)
- {
- if ((0 == PL_strcmp(target, "newwindow")) ||
- (0 == PL_strcmp(target, "_new")))
- target = "_blank";
- else if (0 == PL_strcmp(target, "_current"))
- target = "_self";
-
- rv = owner->GetURL(url, target, (void*)postData);
- NS_RELEASE(owner);
- }
-
- NS_RELEASE(peer);
- }
- }
-
- if ((nsnull != notifyData) || (nsnull == target))
- rv = NewPluginURLStream(string, instance, notifyData);
-
- NS_RELEASE(instance);
- }
-
- return rv;
-}
-
-#endif // NEW_PLUGIN_STREAM_API
-
NS_IMETHODIMP nsPluginHostImpl :: BeginWaitCursor(void)
{
printf("plugin manager2 beginwaitcursor called\n");
@@ -1513,35 +1442,33 @@ NS_IMETHODIMP nsPluginHostImpl::Destroy(void)
/* Called by nsPluginInstanceOwner (nsObjectFrame.cpp - embeded case) */
-NS_IMETHODIMP nsPluginHostImpl::InstantiateEmbededPlugin(const char *aMimeType, nsString& aURLSpec,
+NS_IMETHODIMP nsPluginHostImpl :: InstantiateEmbededPlugin(const char *aMimeType, nsIURL* aURL,
nsIPluginInstanceOwner *aOwner)
{
nsresult rv;
+ nsIPluginInstance *instance = nsnull;
- rv = SetUpPluginInstance(aMimeType, nsnull, aOwner);
+ rv = SetUpPluginInstance(aMimeType, aURL, aOwner);
+
+ if(rv == NS_OK)
+ rv = aOwner->GetInstance(instance);
- if ((rv != NS_OK) || (nsnull == aMimeType))
+ if(rv != NS_OK)
{
- //either the plugin could not be identified based
- //on the mime type or there was no mime type
-
- if (aURLSpec.Length() > 0)
+ // we have not been able to load a plugin because we have not determined the mimetype
+ if (aURL)
{
//we need to stream in enough to get the mime type...
-
- rv = NewEmbededPluginStream(aURLSpec, aOwner, nsnull);
+ rv = NewEmbededPluginStream(aURL, aOwner, nsnull);
}
else
rv = NS_ERROR_FAILURE;
}
- else
+ else // we have loaded a plugin for this mimetype
{
- nsIPluginInstance *instance = nsnull;
nsPluginWindow *window = nsnull;
//we got a plugin built, now stream
-
- aOwner->GetInstance(instance);
aOwner->GetWindow(window);
if (nsnull != instance)
@@ -1550,7 +1477,7 @@ NS_IMETHODIMP nsPluginHostImpl::InstantiateEmbededPlugin(const char *aMimeType,
aOwner->CreateWidget();
instance->SetWindow(window);
- rv = NewEmbededPluginStream(aURLSpec, nsnull, instance);
+ rv = NewEmbededPluginStream(aURL, nsnull, instance);
NS_RELEASE(instance);
}
@@ -1768,7 +1695,8 @@ NS_IMETHODIMP nsPluginHostImpl::SetUpPluginInstance(const char *aMimeType,
if (plugins->mFlags & NS_PLUGIN_FLAG_OLDSCHOOL)
{
// we have to load an old 4x style plugin
- nsresult rv = ns4xPlugin::CreatePlugin(plugins->mLibrary, (nsIPlugin **)&plugins->mEntryPoint,
+ nsresult rv = ns4xPlugin::CreatePlugin(plugins->mLibrary,
+ (nsIPlugin **)&plugins->mEntryPoint,
mServiceMgr);
}
else
@@ -2303,7 +2231,7 @@ PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const nsFileSpec &pluginSpec)
PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const char* pluginPath, const char* path)
{
#ifdef XP_PC
- BOOL restoreOrigDir = FALSE;
+ /*BOOL restoreOrigDir = FALSE;
char aOrigDir[MAX_PATH + 1];
DWORD dwCheck = ::GetCurrentDirectory(sizeof(aOrigDir), aOrigDir);
PR_ASSERT(dwCheck <= MAX_PATH + 1);
@@ -2312,15 +2240,15 @@ PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const char* pluginPath, const cha
{
restoreOrigDir = ::SetCurrentDirectory(pluginPath);
PR_ASSERT(restoreOrigDir);
- }
+ }*/
PRLibrary* plugin = PR_LoadLibrary(path);
- if (restoreOrigDir)
+ /*if (restoreOrigDir)
{
BOOL bCheck = ::SetCurrentDirectory(aOrigDir);
PR_ASSERT(bCheck);
- }
+ }*/
return plugin;
#else
@@ -2331,8 +2259,6 @@ PRLibrary* nsPluginHostImpl::LoadPluginLibrary(const char* pluginPath, const cha
/* Called by GetURL and PostURL */
-#ifdef NEW_PLUGIN_STREAM_API
-
NS_IMETHODIMP nsPluginHostImpl :: NewPluginURLStream(const nsString& aURL,
nsIPluginInstance *aInstance,
nsIPluginStreamListener* aListener)
@@ -2362,77 +2288,36 @@ NS_IMETHODIMP nsPluginHostImpl :: NewPluginURLStream(const nsString& aURL,
return rv;
}
-#else
-
-/* Called by GetURL and PostURL */
-
-NS_IMETHODIMP nsPluginHostImpl :: NewPluginURLStream(const nsString& aURL,
- nsIPluginInstance *aInstance,
- void *aNotifyData)
-{
- nsIURL *url;
- nsPluginStreamListenerPeer *listener = (nsPluginStreamListenerPeer *)new nsPluginStreamListenerPeer();
- if (listener == NULL)
- return NS_ERROR_OUT_OF_MEMORY;
- nsresult rv;
-
- if (aURL.Length() <= 0)
- return NS_OK;
-
- rv = NS_NewURL(&url, aURL);
-
- if (NS_OK == rv)
- {
- rv = listener->Initialize(url, aInstance, aNotifyData);
-
- if (NS_OK == rv) {
- rv = NS_OpenURL(url, listener);
- }
-
- NS_RELEASE(url);
- }
-
- return rv;
-}
-
-#endif
-
/* Called by InstantiateEmbededPlugin() */
-nsresult nsPluginHostImpl :: NewEmbededPluginStream(const nsString& aURL,
+nsresult nsPluginHostImpl :: NewEmbededPluginStream(nsIURL* aURL,
nsIPluginInstanceOwner *aOwner,
nsIPluginInstance* aInstance)
{
- nsIURL *url;
- nsPluginStreamListenerPeer *listener = (nsPluginStreamListenerPeer *)new nsPluginStreamListenerPeer();
- nsresult rv;
+ nsPluginStreamListenerPeer *listener = (nsPluginStreamListenerPeer *)new nsPluginStreamListenerPeer();
+ nsresult rv;
- if (aURL.Length() <= 0)
- return NS_OK;
+ if (!aURL)
+ return NS_OK;
- rv = NS_NewURL(&url, aURL);
-
- if (NS_OK == rv)
- {
// if we have an instance, everything has been set up
// if we only have an owner, then we need to pass it in
// so the listener can set up the instance later after
// we've determined the mimetype of the stream
if(aInstance != nsnull)
- rv = listener->InitializeEmbeded(url, aInstance);
+ rv = listener->InitializeEmbeded(aURL, aInstance);
else if(aOwner != nsnull)
- rv = listener->InitializeEmbeded(url, nsnull, aOwner, (nsIPluginHost *)this);
+ rv = listener->InitializeEmbeded(aURL, nsnull, aOwner, (nsIPluginHost *)this);
else
rv = NS_ERROR_ILLEGAL_VALUE;
- if (NS_OK == rv) {
- rv = NS_OpenURL(url, listener);
- }
+ if (NS_OK == rv) {
+ rv = NS_OpenURL(aURL, listener);
+ }
- NS_RELEASE(url);
- }
+ //NS_RELEASE(aURL);
- return rv;
+ return rv;
}
/* Called by InstantiateFullPagePlugin() */
@@ -2462,11 +2347,6 @@ nsresult nsPluginHostImpl::CreateInstance(nsISupports *aOuter,
nsISupports *inst = nsnull;
-#ifndef NEW_PLUGIN_STREAM_API
- if (aIID.Equals(kIPluginStreamPeerIID))
- inst = (nsISupports *)(nsIPluginStreamPeer *)new nsPluginStreamPeer();
-#endif
-
if (inst == NULL)
return NS_ERROR_OUT_OF_MEMORY;
diff --git a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h
index fba4d6bb92f..1c24273f762 100644
--- a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h
+++ b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h
@@ -79,10 +79,8 @@ public:
NS_IMETHOD
UserAgent(const char* *resultingAgentString);
-#ifdef NEW_PLUGIN_STREAM_API
-
- NS_IMETHOD
- GetURL(nsISupports* pluginInst,
+ NS_IMETHOD
+ GetURL(nsISupports* pluginInst,
const char* url,
const char* target = NULL,
nsIPluginStreamListener* streamListener = NULL,
@@ -90,8 +88,8 @@ public:
const char* referrer = NULL,
PRBool forceJSEnabled = PR_FALSE);
- NS_IMETHOD
- PostURL(nsISupports* pluginInst,
+ NS_IMETHOD
+ PostURL(nsISupports* pluginInst,
const char* url,
PRUint32 postDataLen,
const char* postData,
@@ -103,21 +101,6 @@ public:
PRBool forceJSEnabled = PR_FALSE,
PRUint32 postHeadersLength = 0,
const char* postHeaders = NULL);
-#else
-
- NS_IMETHOD
- GetURL(nsISupports* inst, 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* inst, 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);
-#endif
//nsIPluginHost interface - used to communicate to the nsPluginInstanceOwner
@@ -134,7 +117,7 @@ public:
GetPluginFactory(const char *aMimeType, nsIPlugin** aPlugin);
NS_IMETHOD
- InstantiateEmbededPlugin(const char *aMimeType, nsString& aURLSpec, nsIPluginInstanceOwner *aOwner);
+ InstantiateEmbededPlugin(const char *aMimeType, nsIURL* aURL, nsIPluginInstanceOwner *aOwner);
NS_IMETHOD
InstantiateFullPagePlugin(const char *aMimeType, nsString& aURLSpec, nsIStreamListener *&aStreamListener, nsIPluginInstanceOwner *aOwner);
@@ -195,20 +178,15 @@ public:
/* Called by GetURL and PostURL */
-#ifdef NEW_PLUGIN_STREAM_API
NS_IMETHOD
NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener);
-#else
- NS_IMETHOD
- NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, void *aNotifyData);
-#endif
private:
/* Called by InstantiatePlugin */
nsresult
- NewEmbededPluginStream(const nsString& aURL, nsIPluginInstanceOwner *aOwner, nsIPluginInstance* aInstance);
+ NewEmbededPluginStream(nsIURL* aURL, nsIPluginInstanceOwner *aOwner, nsIPluginInstance* aInstance);
nsresult
NewFullPagePluginStream(nsIStreamListener *&aStreamListener, nsIPluginInstance *aInstance);
diff --git a/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp b/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp
index 311e0a12560..7d7bac95c2d 100644
--- a/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp
+++ b/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp
@@ -157,7 +157,6 @@ public:
Close(void);
protected:
-
char* mTarget;
nsFileURL mFileURL;
nsFileSpec mFileSpec;
@@ -165,11 +164,16 @@ protected:
nsIPluginInstanceOwner* mOwner;
};
+NS_IMPL_ADDREF(nsPluginStreamToFile);
+NS_IMPL_RELEASE(nsPluginStreamToFile);
+
nsPluginStreamToFile::nsPluginStreamToFile(const char* target, nsIPluginInstanceOwner* owner)
: mTarget(PL_strdup(target))
, mFileURL(nsnull)
, mOwner(owner)
{
+ NS_INIT_REFCNT();
+
// open the file and prepare it for writing
char buf[400], tpath[300];
#ifdef XP_PC
@@ -192,7 +196,7 @@ nsPluginStreamToFile::nsPluginStreamToFile(const char* target, nsIPluginInstance
// Create and validate the file spec object. (When we have a constructor for the temp
// directory, we should use this instead of the per-platform hack above).
- mFileSpec = buf;
+ mFileSpec = PL_strdup(buf);
if (mFileSpec.Error())
return;
@@ -218,10 +222,6 @@ nsPluginStreamToFile::~nsPluginStreamToFile()
}
-
-NS_IMPL_ADDREF(nsPluginStreamToFile)
-NS_IMPL_RELEASE(nsPluginStreamToFile)
-
nsresult nsPluginStreamToFile::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
diff --git a/mozilla/modules/plugin/public/nsIPluginInstance.h b/mozilla/modules/plugin/public/nsIPluginInstance.h
index e7822176edc..39d2fb211bb 100644
--- a/mozilla/modules/plugin/public/nsIPluginInstance.h
+++ b/mozilla/modules/plugin/public/nsIPluginInstance.h
@@ -36,10 +36,7 @@
#include "nsplugindefs.h"
#include "nsISupports.h"
-
-#ifdef NEW_PLUGIN_STREAM_API
#include "nsIPluginStreamListener.h"
-#endif
#define NS_IPLUGININSTANCE_IID \
{ /* ebe00f40-0199-11d2-815b-006008119d7a */ \
@@ -140,7 +137,6 @@ public:
NS_IMETHOD
SetWindow(nsPluginWindow* window) = 0;
-#ifdef NEW_PLUGIN_STREAM_API
/**
* Called to tell the plugin that the initial src/data stream is
* ready. Expects the plugin to return a nsIPluginStreamListener.
@@ -152,21 +148,6 @@ public:
*/
NS_IMETHOD
NewStream(nsIPluginStreamListener** listener) = 0;
-#else
- /**
- * Called when a new plugin stream must be constructed in order for the plugin
- * instance to receive a stream of data from the browser.
- *
- * (Corresponds to NPP_NewStream.)
- *
- * @param peer - the plugin stream peer, representing information about the
- * incoming stream, and stream-specific callbacks into the browser
- * @param result - the resulting plugin stream
- * @result - NS_OK if this operation was successful
- */
- NS_IMETHOD
- NewStream(nsIPluginStreamPeer* peer, nsIPluginStream* *result) = 0;
-#endif
/**
* Called to instruct the plugin instance to print itself to a printer.
@@ -179,24 +160,6 @@ public:
NS_IMETHOD
Print(nsPluginPrint* platformPrint) = 0;
-#ifndef NEW_PLUGIN_STREAM_API
- /**
- * Called to notify the plugin instance that a URL request has been
- * completed. (See nsIPluginManager::GetURL and nsIPluginManager::PostURL).
- *
- * (Corresponds to NPP_URLNotify.)
- *
- * @param url - the requested URL
- * @param target - the target window name
- * @param reason - the reason for completion
- * @param notifyData - the notify data supplied to GetURL or PostURL
- * @result - NS_OK if this operation was successful
- */
- NS_IMETHOD
- URLNotify(const char* url, const char* target,
- nsPluginReason reason, void* notifyData) = 0;
-#endif
-
/**
* Returns the value of a variable associated with the plugin instance.
*
diff --git a/mozilla/modules/plugin/public/nsIPluginManager.h b/mozilla/modules/plugin/public/nsIPluginManager.h
index 36951cc1793..615b9bd9751 100644
--- a/mozilla/modules/plugin/public/nsIPluginManager.h
+++ b/mozilla/modules/plugin/public/nsIPluginManager.h
@@ -102,32 +102,6 @@ public:
NS_IMETHOD
UserAgent(const char* *resultingAgentString) = 0;
-#ifdef NEW_PLUGIN_STREAM_API
-
- NS_IMETHOD
- GetURL(nsISupports* pluginInst,
- const char* url,
- const char* target = NULL,
- nsIPluginStreamListener* streamListener = NULL,
- const char* altHost = NULL,
- const char* referrer = NULL,
- PRBool forceJSEnabled = PR_FALSE) = 0;
-
- NS_IMETHOD
- PostURL(nsISupports* pluginInst,
- const char* url,
- PRUint32 postDataLen,
- const char* postData,
- PRBool isFile = PR_FALSE,
- const char* target = NULL,
- nsIPluginStreamListener* streamListener = NULL,
- const char* altHost = NULL,
- const char* referrer = NULL,
- PRBool forceJSEnabled = PR_FALSE,
- PRUint32 postHeadersLength = 0,
- const char* postHeaders = NULL) = 0;
-
-#else // !NEW_PLUGIN_STREAM_API
/**
* Fetches a URL.
*
@@ -149,10 +123,15 @@ public:
* specify PR_FALSE)
* @result - NS_OK if this operation was successful
*/
+
NS_IMETHOD
- GetURL(nsISupports* pluginInst, const char* url, const char* target,
- void* notifyData = NULL, const char* altHost = NULL,
- const char* referrer = NULL, PRBool forceJSEnabled = PR_FALSE) = 0;
+ GetURL(nsISupports* pluginInst,
+ const char* url,
+ const char* target = NULL,
+ nsIPluginStreamListener* streamListener = NULL,
+ const char* altHost = NULL,
+ const char* referrer = NULL,
+ PRBool forceJSEnabled = PR_FALSE) = 0;
/**
* Posts to a URL with post data and/or post headers.
@@ -183,14 +162,20 @@ public:
* are no post headers
* @result - NS_OK if this operation was successful
*/
+
NS_IMETHOD
- PostURL(nsISupports* pluginInst, 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,
+ PostURL(nsISupports* pluginInst,
+ const char* url,
+ PRUint32 postDataLen,
+ const char* postData,
+ PRBool isFile = PR_FALSE,
+ const char* target = NULL,
+ nsIPluginStreamListener* streamListener = NULL,
+ const char* altHost = NULL,
+ const char* referrer = NULL,
PRBool forceJSEnabled = PR_FALSE,
- PRUint32 postHeadersLength = 0, const char* postHeaders = NULL) = 0;
-#endif // !NEW_PLUGIN_STREAM_API
+ PRUint32 postHeadersLength = 0,
+ const char* postHeaders = NULL) = 0;
};
diff --git a/mozilla/modules/plugin/public/nsIPluginStreamInfo.h b/mozilla/modules/plugin/public/nsIPluginStreamInfo.h
index fc874022bce..62d9898403a 100644
--- a/mozilla/modules/plugin/public/nsIPluginStreamInfo.h
+++ b/mozilla/modules/plugin/public/nsIPluginStreamInfo.h
@@ -38,6 +38,9 @@ public:
NS_IMETHOD
GetLastModified(PRUint32* result) = 0;
+ NS_IMETHOD
+ GetURL(const char** result) = 0;
+
NS_IMETHOD
RequestRead(nsByteRange* rangeList) = 0;
};
diff --git a/mozilla/modules/plugin/public/nsIPluginStreamListener.h b/mozilla/modules/plugin/public/nsIPluginStreamListener.h
index 8e22c7a4637..591f0526d61 100644
--- a/mozilla/modules/plugin/public/nsIPluginStreamListener.h
+++ b/mozilla/modules/plugin/public/nsIPluginStreamListener.h
@@ -56,7 +56,7 @@ public:
* used to cancel the URL load..
*/
NS_IMETHOD
- OnStartBinding(const char* url, nsIPluginStreamInfo* pluginInfo) = 0;
+ OnStartBinding(nsIPluginStreamInfo* pluginInfo) = 0;
/**
* Notify the client that data is available in the input stream. This
@@ -69,12 +69,12 @@ public:
* @return The return value is currently ignored.
*/
NS_IMETHOD
- OnDataAvailable(const char* url, nsIInputStream* input,
- PRUint32 offset, PRUint32 length, nsIPluginStreamInfo* pluginInfo) = 0;
+ OnDataAvailable(nsIPluginStreamInfo* pluginInfo, nsIInputStream* input, PRUint32 length) = 0;
NS_IMETHOD
- OnFileAvailable(const char* url, const char* fileName) = 0;
- /**
+ OnFileAvailable(nsIPluginStreamInfo* pluginInfo, const char* fileName) = 0;
+
+ /**
* Notify the observer that the URL has finished loading. This method is
* called once when the networking library has finished processing the
* URL transaction initiatied via the nsINetService::Open(...) call.
@@ -86,10 +86,8 @@ public:
* @return The return value is currently ignored.
*/
NS_IMETHOD
- OnStopBinding(const char* url, nsresult status, nsIPluginStreamInfo* pluginInfo) = 0;
+ OnStopBinding(nsIPluginStreamInfo* pluginInfo, nsresult status) = 0;
- NS_IMETHOD
- OnNotify(const char* url, nsresult status) = 0;
NS_IMETHOD
GetStreamType(nsPluginStreamType *result) = 0;
diff --git a/mozilla/modules/plugin/public/nsplugin.h b/mozilla/modules/plugin/public/nsplugin.h
index 181a01500e3..dc9f9c702ee 100644
--- a/mozilla/modules/plugin/public/nsplugin.h
+++ b/mozilla/modules/plugin/public/nsplugin.h
@@ -79,8 +79,7 @@
#ifndef nsplugins_h___
#define nsplugins_h___
-#define NEW_PLUGIN_STREAM_API
-
+#include "nsRepository.h" // for NSGetFactory
#include "nsIComponentManager.h" // for NSGetFactory
////////////////////////////////////////////////////////////////////////////////
@@ -114,23 +113,11 @@
*/
#include "nsIPluginInstance.h"
-#ifdef NEW_PLUGIN_STREAM_API
-
/**
* A plugin stream listener ...
*/
#include "nsIPluginStreamListener.h"
-#else // !NEW_PLUGIN_STREAM_API
-
-/**
- * A plugin stream gets instantiated when a plugin instance receives data from
- * the browser.
- */
-#include "nsIPluginStream.h"
-
-#endif // !NEW_PLUGIN_STREAM_API
-
/**
* The nsILiveConnectPlugin interface provides additional operations that a
* plugin must implement if it is to be controlled by JavaScript through
@@ -177,32 +164,11 @@
*/
#include "nsIWindowlessPlugInstPeer.h"
-#ifdef NEW_PLUGIN_STREAM_API
-
/**
*
*/
#include "nsIPluginInputStream.h"
-#else // !NEW_PLUGIN_STREAM_API
-
-/**
- * A plugin stream peer gets create by the browser and associated with each
- * plugin stream to represent stream and URL information, and provides
- * other callbacks needed by the plugin stream.
- */
-#include "nsIPluginStreamPeer.h"
-
-/**
- * The nsISeekablePluginStreamPeer provides additional operations for seekable
- * plugin streams.
- *
- * To obtain: QueryInterface on nsIPluginStreamPeer
- */
-#include "nsISeekablePluginStreamPeer.h"
-
-#endif // !NEW_PLUGIN_STREAM_API
-
////////////////////////////////////////////////////////////////////////////////
/**
* Interfaces implemented by the browser (new for 5.0):
@@ -236,25 +202,11 @@
*/
//#include "nsILiveConnectPlugInstPeer.h"
-#ifdef NEW_PLUGIN_STREAM_API
-
/**
*
*/
#include "nsIPluginInputStream2.h"
-#else // !NEW_PLUGIN_STREAM_API
-
-/**
- * The nsIPluginStreamPeer2 interface provides additional plugin stream
- * peer features only available in Communicator 5.0.
- *
- * To obtain: QueryInterface on nsIPluginStreamPeer
- */
-#include "nsIPluginStreamPeer2.h"
-
-#endif // !NEW_PLUGIN_STREAM_API
-
/**
* The nsIPluginTagInfo2 interface provides additional html tag information
* only available in Communicator 5.0.
diff --git a/mozilla/modules/plugin/public/nsplugindefs.h b/mozilla/modules/plugin/public/nsplugindefs.h
index 3c70aa12d03..60de04887eb 100644
--- a/mozilla/modules/plugin/public/nsplugindefs.h
+++ b/mozilla/modules/plugin/public/nsplugindefs.h
@@ -34,8 +34,6 @@
#ifndef nsplugindefs_h___
#define nsplugindefs_h___
-#define NEW_PLUGIN_STREAM_API
-
#ifndef prtypes_h___
#include "prtypes.h"
#endif