diff --git a/mozilla/modules/plugin/samples/simple/npsimple.cpp b/mozilla/modules/plugin/samples/simple/npsimple.cpp index 9f27ea1164e..1fcc08e1742 100644 --- a/mozilla/modules/plugin/samples/simple/npsimple.cpp +++ b/mozilla/modules/plugin/samples/simple/npsimple.cpp @@ -964,6 +964,11 @@ NS_METHOD SimplePluginStreamListener::OnDataAvailable(const char* url, nsIPluginInputStream* input, PRUint32 offset, PRUint32 length) { + if (strcmp(url, "http://warp/java/oji/") == 0 && offset != 0) { + // Try closing the stream prematurely + input->Close(); + return NS_OK; + } char* buffer = new char[length]; if (buffer) { PRInt32 amountRead = 0; diff --git a/mozilla/modules/plugin/src/npglue.cpp b/mozilla/modules/plugin/src/npglue.cpp index c259447da36..f4256200c96 100644 --- a/mozilla/modules/plugin/src/npglue.cpp +++ b/mozilla/modules/plugin/src/npglue.cpp @@ -503,6 +503,12 @@ NPL_WriteReady(NET_StreamClass *stream) ret = userStream->WriteReady(); #else ret = NP_MAXREADY; +#ifdef NEW_PLUGIN_STREAM_API + nsPluginInputStream* inStr = (nsPluginInputStream*)newstream->pstream->pdata; + if (inStr->IsClosed()) { + ret = -1; + } +#endif #endif } else if (ISFUNCPTR(newstream->handle->f->writeready)) { @@ -582,12 +588,18 @@ NPL_Write(NET_StreamClass *stream, const unsigned char *str, int32 len) #ifdef NEW_PLUGIN_STREAM_API nsPluginInputStream* inStr = (nsPluginInputStream*)newstream->pstream->pdata; - nsIPluginStreamListener* listener = inStr->GetListener(); - nsresult err = inStr->ReceiveData((const char*)str, urls->position, len); - if (err == NS_OK) { - err = listener->OnDataAvailable((const char*)urls->address, inStr, urls->position, len); + if (inStr->IsClosed()) { + ret = -1; + } + else { + nsIPluginStreamListener* listener = inStr->GetListener(); + nsresult err = inStr->ReceiveData((const char*)str, urls->position, len); + if (err == NS_OK) { + err = listener->OnDataAvailable((const char*)urls->address, inStr, urls->position, len); + } + if (err != NS_OK) + ret = -1; } - PR_ASSERT(err == NS_OK); // XXX this error should go somewhere #else // !NEW_PLUGIN_STREAM_API diff --git a/mozilla/modules/plugin/src/npglue.h b/mozilla/modules/plugin/src/npglue.h index 7619f89734e..5a2c064ab06 100644 --- a/mozilla/modules/plugin/src/npglue.h +++ b/mozilla/modules/plugin/src/npglue.h @@ -774,6 +774,7 @@ public: nsIPluginStreamListener* GetListener(void) { return mListener; } nsPluginStreamType GetStreamType(void) { return mStreamType; } + PRBool IsClosed(void) { return mClosed; } void SetStreamInfo(URL_Struct* urls, np_stream* stream) { mUrls = urls; @@ -797,6 +798,7 @@ protected: }; BufferElement* mBuffer; + PRBool mClosed; // PRUint32 mReadCursor; // PRUint32 mBufferLength; diff --git a/mozilla/modules/plugin/src/nsplugin.cpp b/mozilla/modules/plugin/src/nsplugin.cpp index 8bcc88c2c60..e581c04ad1e 100644 --- a/mozilla/modules/plugin/src/nsplugin.cpp +++ b/mozilla/modules/plugin/src/nsplugin.cpp @@ -1640,7 +1640,7 @@ nsPluginInputStream::nsPluginInputStream(nsIPluginStreamListener* listener, nsPluginStreamType streamType) : mListener(listener), mStreamType(streamType), mUrls(NULL), mStream(NULL), - mBuffer(NULL) + mBuffer(NULL), mClosed(PR_FALSE) // mBuffer(NULL), mBufferLength(0), mAmountRead(0) { NS_INIT_REFCNT(); @@ -1686,14 +1686,21 @@ nsPluginInputStream::Cleanup(void) } mBuffer = NULL; } + mClosed = PR_TRUE; } NS_METHOD nsPluginInputStream::Close(void) { + NPError err = NPERR_NO_ERROR; Cleanup(); - NPError err = npn_destroystream(mStream->instance->npp, mStream->pstream, - nsPluginReason_UserBreak); +#if 0 /* According to the plugin documentation, this would seem to be the + * right thing to do here, but it's not (and calling NPN_DestroyStream + * in the 4.0 browser during an NPP_Write call will crash the browser). + */ + err = npn_destroystream(mStream->instance->npp, mStream->pstream, + nsPluginReason_UserBreak); +#endif return fromNPError[err]; } diff --git a/mozilla/modules/plugin/test/npsimple.cpp b/mozilla/modules/plugin/test/npsimple.cpp index 9f27ea1164e..1fcc08e1742 100644 --- a/mozilla/modules/plugin/test/npsimple.cpp +++ b/mozilla/modules/plugin/test/npsimple.cpp @@ -964,6 +964,11 @@ NS_METHOD SimplePluginStreamListener::OnDataAvailable(const char* url, nsIPluginInputStream* input, PRUint32 offset, PRUint32 length) { + if (strcmp(url, "http://warp/java/oji/") == 0 && offset != 0) { + // Try closing the stream prematurely + input->Close(); + return NS_OK; + } char* buffer = new char[length]; if (buffer) { PRInt32 amountRead = 0;