Bug 1136930: Fix nsNPAPIPluginStreamListener so that destroystream calls are made during async plugin init; r=jimm

This commit is contained in:
Aaron Klotz 2015-03-12 11:45:31 -06:00
parent fd511a4b5b
commit 8998230090
2 changed files with 31 additions and 23 deletions

View File

@ -134,21 +134,21 @@ NS_IMPL_ISUPPORTS(nsNPAPIPluginStreamListener,
nsNPAPIPluginStreamListener::nsNPAPIPluginStreamListener(nsNPAPIPluginInstance* inst, nsNPAPIPluginStreamListener::nsNPAPIPluginStreamListener(nsNPAPIPluginInstance* inst,
void* notifyData, void* notifyData,
const char* aURL) const char* aURL)
: mStreamBuffer(nullptr), : mStreamBuffer(nullptr)
mNotifyURL(aURL ? PL_strdup(aURL) : nullptr), , mNotifyURL(aURL ? PL_strdup(aURL) : nullptr)
mInst(inst), , mInst(inst)
mStreamBufferSize(0), , mStreamBufferSize(0)
mStreamBufferByteCount(0), , mStreamBufferByteCount(0)
mStreamType(NP_NORMAL), , mStreamType(NP_NORMAL)
mStreamStarted(false), , mStreamState(eStreamStopped)
mStreamCleanedUp(false), , mStreamCleanedUp(false)
mCallNotify(notifyData ? true : false), , mCallNotify(notifyData ? true : false)
mIsSuspended(false), , mIsSuspended(false)
mIsPluginInitJSStream(mInst->mInPluginInitCall && , mIsPluginInitJSStream(mInst->mInPluginInitCall &&
aURL && strncmp(aURL, "javascript:", aURL && strncmp(aURL, "javascript:",
sizeof("javascript:") - 1) == 0), sizeof("javascript:") - 1) == 0)
mRedirectDenied(false), , mRedirectDenied(false)
mResponseHeaderBuf(nullptr) , mResponseHeaderBuf(nullptr)
{ {
mNPStreamWrapper = new nsNPAPIStreamWrapper(nullptr, this); mNPStreamWrapper = new nsNPAPIStreamWrapper(nullptr, this);
mNPStreamWrapper->mNPStream.notifyData = notifyData; mNPStreamWrapper->mNPStream.notifyData = notifyData;
@ -208,7 +208,7 @@ nsNPAPIPluginStreamListener::CleanUpStream(NPReason reason)
// Seekable streams have an extra addref when they are created which must // Seekable streams have an extra addref when they are created which must
// be matched here. // be matched here.
if (NP_SEEK == mStreamType && mStreamStarted) if (NP_SEEK == mStreamType && mStreamState == eStreamTypeSet)
NS_RELEASE_THIS(); NS_RELEASE_THIS();
if (mStreamListenerPeer) { if (mStreamListenerPeer) {
@ -230,7 +230,7 @@ nsNPAPIPluginStreamListener::CleanUpStream(NPReason reason)
NPP npp; NPP npp;
mInst->GetNPP(&npp); mInst->GetNPP(&npp);
if (mStreamStarted && pluginFunctions->destroystream) { if (mStreamState >= eNewStreamCalled && pluginFunctions->destroystream) {
NPPAutoPusher nppPusher(npp); NPPAutoPusher nppPusher(npp);
NPError error; NPError error;
@ -245,7 +245,7 @@ nsNPAPIPluginStreamListener::CleanUpStream(NPReason reason)
rv = NS_OK; rv = NS_OK;
} }
mStreamStarted = false; mStreamState = eStreamStopped;
// fire notification back to plugin, just like before // fire notification back to plugin, just like before
CallURLNotify(reason); CallURLNotify(reason);
@ -367,7 +367,7 @@ nsNPAPIPluginStreamListener::SetStreamType(uint16_t aType, bool aNeedsResume)
default: default:
return false; return false;
} }
mStreamStarted = true; mStreamState = eStreamTypeSet;
if (aNeedsResume) { if (aNeedsResume) {
if (mStreamListenerPeer) { if (mStreamListenerPeer) {
mStreamListenerPeer->OnStreamTypeSet(mStreamType); mStreamListenerPeer->OnStreamTypeSet(mStreamType);
@ -591,7 +591,7 @@ nsNPAPIPluginStreamListener::OnDataAvailable(nsPluginStreamListenerPeer* streamP
"return(towrite)=%d, url=%s\n", "return(towrite)=%d, url=%s\n",
this, npp, numtowrite, mNPStreamWrapper->mNPStream.url)); this, npp, numtowrite, mNPStreamWrapper->mNPStream.url));
if (!mStreamStarted) { if (mStreamState == eStreamStopped) {
// The plugin called NPN_DestroyStream() from within // The plugin called NPN_DestroyStream() from within
// NPP_WriteReady(), kill the stream. // NPP_WriteReady(), kill the stream.
@ -643,7 +643,7 @@ nsNPAPIPluginStreamListener::OnDataAvailable(nsPluginStreamListenerPeer* streamP
this, npp, streamPosition, numtowrite, this, npp, streamPosition, numtowrite,
ptrStreamBuffer, writeCount, mNPStreamWrapper->mNPStream.url)); ptrStreamBuffer, writeCount, mNPStreamWrapper->mNPStream.url));
if (!mStreamStarted) { if (mStreamState == eStreamStopped) {
// The plugin called NPN_DestroyStream() from within // The plugin called NPN_DestroyStream() from within
// NPP_Write(), kill the stream. // NPP_Write(), kill the stream.
return NS_BINDING_ABORTED; return NS_BINDING_ABORTED;
@ -814,7 +814,7 @@ nsNPAPIPluginStreamListener::Notify(nsITimer *aTimer)
} }
if (mStreamBufferByteCount != oldStreamBufferByteCount && if (mStreamBufferByteCount != oldStreamBufferByteCount &&
((mStreamStarted && mStreamBufferByteCount < 1024) || ((mStreamState == eStreamTypeSet && mStreamBufferByteCount < 1024) ||
mStreamBufferByteCount == 0)) { mStreamBufferByteCount == 0)) {
// The plugin read some data and we've got less than 1024 bytes in // The plugin read some data and we've got less than 1024 bytes in
// our buffer (or its empty and the stream is already // our buffer (or its empty and the stream is already

View File

@ -105,6 +105,14 @@ public:
void URLRedirectResponse(NPBool allow); void URLRedirectResponse(NPBool allow);
protected: protected:
enum StreamState
{
eStreamStopped = 0, // The stream is stopped
eNewStreamCalled, // NPP_NewStream was called but has not completed yet
eStreamTypeSet // The stream is fully initialized
};
virtual ~nsNPAPIPluginStreamListener(); virtual ~nsNPAPIPluginStreamListener();
char* mStreamBuffer; char* mStreamBuffer;
char* mNotifyURL; char* mNotifyURL;
@ -113,7 +121,7 @@ protected:
uint32_t mStreamBufferSize; uint32_t mStreamBufferSize;
int32_t mStreamBufferByteCount; int32_t mStreamBufferByteCount;
int32_t mStreamType; int32_t mStreamType;
bool mStreamStarted; StreamState mStreamState;
bool mStreamCleanedUp; bool mStreamCleanedUp;
bool mCallNotify; bool mCallNotify;
bool mIsSuspended; bool mIsSuspended;