mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Improve stream listener management for plugin instances. b=554524 r=jst
This commit is contained in:
parent
adeecd8bf0
commit
83ec99695c
@ -204,29 +204,12 @@ nsNPAPIPluginStreamListener::nsNPAPIPluginStreamListener(nsNPAPIPluginInstance*
|
||||
mResponseHeaderBuf(nsnull)
|
||||
{
|
||||
memset(&mNPStream, 0, sizeof(mNPStream));
|
||||
|
||||
NS_IF_ADDREF(mInst);
|
||||
}
|
||||
|
||||
nsNPAPIPluginStreamListener::~nsNPAPIPluginStreamListener(void)
|
||||
nsNPAPIPluginStreamListener::~nsNPAPIPluginStreamListener()
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
// remove this from the plugin instance's stream list
|
||||
mInst->mStreamListeners.RemoveElement(this);
|
||||
|
||||
// For those cases when NewStream is never called, we still may need
|
||||
// to fire a notification callback. Return network error as fallback
|
||||
@ -240,8 +223,6 @@ nsNPAPIPluginStreamListener::~nsNPAPIPluginStreamListener(void)
|
||||
mStreamBuffer=nsnull;
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(inst);
|
||||
|
||||
if (mNotifyURL)
|
||||
PL_strfree(mNotifyURL);
|
||||
|
||||
@ -319,7 +300,6 @@ void nsNPAPIPluginStreamListener::CallURLNotify(NPReason reason)
|
||||
return;
|
||||
|
||||
if (callbacks->urlnotify) {
|
||||
|
||||
NPP npp;
|
||||
mInst->GetNPP(&npp);
|
||||
|
||||
@ -473,8 +453,11 @@ nsNPAPIPluginStreamListener::StopDataPump()
|
||||
PRBool
|
||||
nsNPAPIPluginStreamListener::PluginInitJSLoadInProgress()
|
||||
{
|
||||
for (nsInstanceStream *is = mInst->mStreams; is; is = is->mNext) {
|
||||
if (is->mPluginStreamListener->mIsPluginInitJSStream) {
|
||||
if (!mInst)
|
||||
return PR_FALSE;
|
||||
|
||||
for (unsigned int i = 0; i < mInst->mStreamListeners.Length(); i++) {
|
||||
if (mInst->mStreamListeners[i]->mIsPluginInitJSStream) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
@ -873,16 +856,6 @@ 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,
|
||||
@ -903,7 +876,7 @@ nsNPAPIPluginInstance::nsNPAPIPluginInstance(NPPluginFuncs* callbacks,
|
||||
mWantsAllNetworkStreams(PR_FALSE),
|
||||
mInPluginInitCall(PR_FALSE),
|
||||
mLibrary(aLibrary),
|
||||
mStreams(nsnull),
|
||||
mStreamListeners(nsnull),
|
||||
mMIMEType(nsnull),
|
||||
mOwner(nsnull),
|
||||
mCurrentPluginEvent(nsnull)
|
||||
@ -918,17 +891,10 @@ nsNPAPIPluginInstance::nsNPAPIPluginInstance(NPPluginFuncs* callbacks,
|
||||
PLUGIN_LOG(PLUGIN_LOG_BASIC, ("nsNPAPIPluginInstance ctor: this=%p\n",this));
|
||||
}
|
||||
|
||||
nsNPAPIPluginInstance::~nsNPAPIPluginInstance(void)
|
||||
nsNPAPIPluginInstance::~nsNPAPIPluginInstance()
|
||||
{
|
||||
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;
|
||||
@ -1004,19 +970,10 @@ NS_IMETHODIMP nsNPAPIPluginInstance::Stop()
|
||||
OnPluginDestroy(&mNPP);
|
||||
|
||||
// clean up open streams
|
||||
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);
|
||||
for (unsigned int i = 0; i < mStreamListeners.Length(); i++) {
|
||||
mStreamListeners[i]->CleanUpStream(NPRES_USER_BREAK);
|
||||
}
|
||||
mStreamListeners.Clear();
|
||||
|
||||
NPError error = NPERR_GENERIC_ERROR;
|
||||
if (mCallbacks->destroy) {
|
||||
@ -1296,23 +1253,10 @@ nsresult nsNPAPIPluginInstance::NewNotifyStream(nsIPluginStreamListener** listen
|
||||
nsNPAPIPluginStreamListener* stream = new nsNPAPIPluginStreamListener(this, notifyData, aURL);
|
||||
NS_ENSURE_TRUE(stream, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
// 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;
|
||||
mStreamListeners.AppendElement(stream);
|
||||
stream->SetCallNotify(aCallNotify); // set flag in stream to call URLNotify
|
||||
|
||||
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;
|
||||
return stream->QueryInterface(kIPluginStreamListenerIID, (void**)listener);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsNPAPIPluginInstance::Print(NPPrint* platformPrint)
|
||||
|
@ -56,15 +56,6 @@
|
||||
class nsNPAPIPluginStreamListener;
|
||||
class nsPIDOMWindow;
|
||||
|
||||
struct nsInstanceStream
|
||||
{
|
||||
nsInstanceStream *mNext;
|
||||
nsNPAPIPluginStreamListener *mPluginStreamListener;
|
||||
|
||||
nsInstanceStream();
|
||||
~nsInstanceStream();
|
||||
};
|
||||
|
||||
class nsNPAPITimer
|
||||
{
|
||||
public:
|
||||
@ -180,7 +171,7 @@ public:
|
||||
// True while creating the plugin, or calling NPP_SetWindow() on it.
|
||||
PRPackedBool mInPluginInitCall;
|
||||
PluginLibrary* mLibrary;
|
||||
nsInstanceStream *mStreams;
|
||||
nsTArray<nsNPAPIPluginStreamListener*> mStreamListeners;
|
||||
|
||||
private:
|
||||
nsTArray<PopupControlState> mPopupStates;
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "nsIHTTPHeaderListener.h"
|
||||
#include "nsIRequest.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#define MAX_PLUGIN_NECKO_BUFFER 16384
|
||||
@ -85,7 +86,7 @@ protected:
|
||||
void* mNotifyData;
|
||||
char* mStreamBuffer;
|
||||
char* mNotifyURL;
|
||||
nsNPAPIPluginInstance* mInst;
|
||||
nsRefPtr<nsNPAPIPluginInstance> mInst;
|
||||
NPStream mNPStream;
|
||||
PRUint32 mStreamBufferSize;
|
||||
PRInt32 mStreamBufferByteCount;
|
||||
|
Loading…
Reference in New Issue
Block a user