Merge of backout for 8e2ff18bc67e, bug 554524

This commit is contained in:
Josh Aas 2010-06-09 01:26:01 -04:00
Родитель a3c64abed6 d4374546c4
Коммит 5f7472e719
3 изменённых файлов: 86 добавлений и 27 удалений

Просмотреть файл

@ -204,10 +204,30 @@ nsNPAPIPluginStreamListener::nsNPAPIPluginStreamListener(nsNPAPIPluginInstance*
mResponseHeaderBuf(nsnull)
{
memset(&mNPStream, 0, sizeof(mNPStream));
NS_IF_ADDREF(mInst);
}
nsNPAPIPluginStreamListener::~nsNPAPIPluginStreamListener()
nsNPAPIPluginStreamListener::~nsNPAPIPluginStreamListener(void)
{
// remove itself from the instance stream list
nsNPAPIPluginInstance *inst = mInst;
if (inst) {
nsInstanceStream * prev = nsnull;
for (nsInstanceStream *is = inst->mStreams; is != nsnull; is = is->mNext) {
if (is->mPluginStreamListener == this) {
if (!prev)
inst->mStreams = is->mNext;
else
prev->mNext = is->mNext;
delete is;
break;
}
prev = is;
}
}
// For those cases when NewStream is never called, we still may need
// to fire a notification callback. Return network error as fallback
// reason because for other cases, notify should have already been
@ -220,6 +240,8 @@ nsNPAPIPluginStreamListener::~nsNPAPIPluginStreamListener()
mStreamBuffer=nsnull;
}
NS_IF_RELEASE(inst);
if (mNotifyURL)
PL_strfree(mNotifyURL);
@ -229,12 +251,9 @@ nsNPAPIPluginStreamListener::~nsNPAPIPluginStreamListener()
nsresult nsNPAPIPluginStreamListener::CleanUpStream(NPReason reason)
{
// We must null out the instance (mInst) before this method completes but
// after all of its code has run.
nsresult rv = NS_ERROR_FAILURE;
if (mStreamCleanedUp || !mInst)
if (mStreamCleanedUp)
return NS_OK;
mStreamCleanedUp = PR_TRUE;
@ -246,10 +265,8 @@ nsresult nsNPAPIPluginStreamListener::CleanUpStream(NPReason reason)
if (NP_SEEK == mStreamType)
NS_RELEASE_THIS();
if (!mInst->CanFireNotifications()) {
mInst = nsnull;
if (!mInst || !mInst->CanFireNotifications())
return rv;
}
mStreamInfo = NULL;
@ -257,13 +274,12 @@ nsresult nsNPAPIPluginStreamListener::CleanUpStream(NPReason reason)
const NPPluginFuncs *callbacks = nsnull;
mInst->GetCallbacks(&callbacks);
if (!callbacks) {
mInst = nsnull;
if (!callbacks)
return rv;
}
NPP npp;
mInst->GetNPP(&npp);
if (mStreamStarted && callbacks->destroystream) {
NPPAutoPusher nppPusher(npp);
@ -285,8 +301,6 @@ nsresult nsNPAPIPluginStreamListener::CleanUpStream(NPReason reason)
// fire notification back to plugin, just like before
CallURLNotify(reason);
mInst = nsnull;
return rv;
}
@ -305,6 +319,7 @@ void nsNPAPIPluginStreamListener::CallURLNotify(NPReason reason)
return;
if (callbacks->urlnotify) {
NPP npp;
mInst->GetNPP(&npp);
@ -458,11 +473,8 @@ nsNPAPIPluginStreamListener::StopDataPump()
PRBool
nsNPAPIPluginStreamListener::PluginInitJSLoadInProgress()
{
if (!mInst)
return PR_FALSE;
for (unsigned int i = 0; i < mInst->mStreams.Length(); i++) {
if (mInst->mStreams[i]->mIsPluginInitJSStream) {
for (nsInstanceStream *is = mInst->mStreams; is; is = is->mNext) {
if (is->mPluginStreamListener->mIsPluginInitJSStream) {
return PR_TRUE;
}
}
@ -861,6 +873,16 @@ nsNPAPIPluginStreamListener::NewResponseHeader(const char* headerName,
return NS_OK;
}
nsInstanceStream::nsInstanceStream()
{
mNext = nsnull;
mPluginStreamListener = nsnull;
}
nsInstanceStream::~nsInstanceStream()
{
}
NS_IMPL_ISUPPORTS1(nsNPAPIPluginInstance, nsIPluginInstance)
nsNPAPIPluginInstance::nsNPAPIPluginInstance(NPPluginFuncs* callbacks,
@ -896,10 +918,17 @@ nsNPAPIPluginInstance::nsNPAPIPluginInstance(NPPluginFuncs* callbacks,
PLUGIN_LOG(PLUGIN_LOG_BASIC, ("nsNPAPIPluginInstance ctor: this=%p\n",this));
}
nsNPAPIPluginInstance::~nsNPAPIPluginInstance()
nsNPAPIPluginInstance::~nsNPAPIPluginInstance(void)
{
PLUGIN_LOG(PLUGIN_LOG_BASIC, ("nsNPAPIPluginInstance dtor: this=%p\n",this));
// clean the stream list if any
for (nsInstanceStream *is = mStreams; is != nsnull;) {
nsInstanceStream * next = is->mNext;
delete is;
is = next;
}
if (mMIMEType) {
PR_Free((void *)mMIMEType);
mMIMEType = nsnull;
@ -975,10 +1004,19 @@ NS_IMETHODIMP nsNPAPIPluginInstance::Stop()
OnPluginDestroy(&mNPP);
// clean up open streams
for (unsigned int i = 0; i < mStreams.Length(); i++) {
mStreams[i]->CleanUpStream(NPRES_USER_BREAK);
for (nsInstanceStream *is = mStreams; is != nsnull;) {
nsRefPtr<nsNPAPIPluginStreamListener> listener = is->mPluginStreamListener;
nsInstanceStream *next = is->mNext;
delete is;
is = next;
mStreams = is;
// Clean up our stream after removing it from the list because
// it may be released and destroyed at this point.
if (listener)
listener->CleanUpStream(NPRES_USER_BREAK);
}
mStreams.Clear();
NPError error = NPERR_GENERIC_ERROR;
if (mCallbacks->destroy) {
@ -1258,10 +1296,23 @@ nsresult nsNPAPIPluginInstance::NewNotifyStream(nsIPluginStreamListener** listen
nsNPAPIPluginStreamListener* stream = new nsNPAPIPluginStreamListener(this, notifyData, aURL);
NS_ENSURE_TRUE(stream, NS_ERROR_OUT_OF_MEMORY);
mStreams.AppendElement(stream);
// add it to the list
nsInstanceStream * is = new nsInstanceStream();
NS_ENSURE_TRUE(is, NS_ERROR_OUT_OF_MEMORY);
is->mNext = mStreams;
is->mPluginStreamListener = stream;
mStreams = is;
stream->SetCallNotify(aCallNotify); // set flag in stream to call URLNotify
return stream->QueryInterface(kIPluginStreamListenerIID, (void**)listener);
NS_ADDREF(stream); // Stabilize
nsresult res = stream->QueryInterface(kIPluginStreamListenerIID, (void**)listener);
// Destabilize and avoid leaks. Avoid calling delete <interface pointer>
NS_RELEASE(stream);
return res;
}
NS_IMETHODIMP nsNPAPIPluginInstance::Print(NPPrint* platformPrint)

Просмотреть файл

@ -41,7 +41,6 @@
#define nsNPAPIPluginInstance_h_
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
#include "nsTArray.h"
#include "nsIPlugin.h"
#include "nsIPluginInstance.h"
@ -57,6 +56,15 @@
class nsNPAPIPluginStreamListener;
class nsPIDOMWindow;
struct nsInstanceStream
{
nsInstanceStream *mNext;
nsNPAPIPluginStreamListener *mPluginStreamListener;
nsInstanceStream();
~nsInstanceStream();
};
class nsNPAPITimer
{
public:
@ -172,7 +180,7 @@ public:
// True while creating the plugin, or calling NPP_SetWindow() on it.
PRPackedBool mInPluginInitCall;
PluginLibrary* mLibrary;
nsTArray< nsRefPtr<nsNPAPIPluginStreamListener> > mStreams;
nsInstanceStream *mStreams;
private:
nsTArray<PopupControlState> mPopupStates;

Просмотреть файл

@ -85,7 +85,7 @@ protected:
void* mNotifyData;
char* mStreamBuffer;
char* mNotifyURL;
nsNPAPIPluginInstance* mInst; // weak, can be NULL
nsNPAPIPluginInstance* mInst;
NPStream mNPStream;
PRUint32 mStreamBufferSize;
PRInt32 mStreamBufferByteCount;