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

View File

@ -105,6 +105,14 @@ public:
void URLRedirectResponse(NPBool allow);
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();
char* mStreamBuffer;
char* mNotifyURL;
@ -113,7 +121,7 @@ protected:
uint32_t mStreamBufferSize;
int32_t mStreamBufferByteCount;
int32_t mStreamType;
bool mStreamStarted;
StreamState mStreamState;
bool mStreamCleanedUp;
bool mCallNotify;
bool mIsSuspended;