From 0acad8cefd3e2ab1df597b54b26902897551fede Mon Sep 17 00:00:00 2001 From: "warren%netscape.com" Date: Thu, 1 Oct 1998 02:59:16 +0000 Subject: [PATCH] Added networking changes under ifdef NEW_PLUGIN_STREAM_API git-svn-id: svn://10.0.0.236/trunk@11637 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/modules/plugin/bad/badapter.cpp | 587 ++- mozilla/modules/plugin/base/public/Makefile | 13 +- .../modules/plugin/base/public/Makefile.in | 13 +- .../modules/plugin/base/public/makefile.win | 14 +- .../plugin/base/public/nsIPluginInstance.h | 4 + .../plugin/base/public/nsIPluginManager.h | 39 +- .../plugin/base/public/nsIPluginManager2.h | 3 +- .../plugin/base/public/nsIPluginStream.h | 6 +- .../plugin/base/public/nsIPluginStreamPeer.h | 4 + .../plugin/base/public/nsIPluginStreamPeer2.h | 4 + .../base/public/nsISeekablePluginStreamPeer.h | 4 + mozilla/modules/plugin/base/public/nsplugin.h | 44 +- mozilla/modules/plugin/public/Makefile | 13 +- mozilla/modules/plugin/public/Makefile.in | 13 +- mozilla/modules/plugin/public/makefile.win | 14 +- .../modules/plugin/public/nsIPluginInstance.h | 4 + .../modules/plugin/public/nsIPluginManager.h | 39 +- .../modules/plugin/public/nsIPluginManager2.h | 3 +- .../modules/plugin/public/nsIPluginStream.h | 6 +- .../plugin/public/nsIPluginStreamPeer.h | 4 + .../plugin/public/nsIPluginStreamPeer2.h | 4 + .../public/nsISeekablePluginStreamPeer.h | 4 + mozilla/modules/plugin/public/nsplugin.h | 44 +- .../plugin/samples/backward/badapter.cpp | 587 ++- .../plugin/samples/simple/makefile.win | 7 +- .../plugin/samples/simple/npsimple.cpp | 179 +- mozilla/modules/plugin/src/makefile.win | 6 + mozilla/modules/plugin/src/npglue.cpp | 3671 +++++++++-------- mozilla/modules/plugin/src/npglue.h | 141 + mozilla/modules/plugin/src/nppriv.h | 5 +- mozilla/modules/plugin/src/nsplugin.cpp | 417 +- mozilla/modules/plugin/test/makefile.win | 7 +- mozilla/modules/plugin/test/npsimple.cpp | 179 +- 33 files changed, 3970 insertions(+), 2112 deletions(-) diff --git a/mozilla/modules/plugin/bad/badapter.cpp b/mozilla/modules/plugin/bad/badapter.cpp index d5e4845cf78..d2cbbdca919 100644 --- a/mozilla/modules/plugin/bad/badapter.cpp +++ b/mozilla/modules/plugin/bad/badapter.cpp @@ -68,9 +68,34 @@ public: NS_IMETHOD UserAgent(const char* *result); - //////////////////////////////////////////////////////////////////////////// - // from nsINetworkManager: +#ifdef NEW_PLUGIN_STREAM_API + NS_IMETHOD + GetURL(nsISupports* pluginInst, + const char* url, + const char* target = NULL, + nsIPluginStreamListener* streamListener = NULL, + nsPluginStreamType streamType = nsPluginStreamType_Normal, + const char* altHost = NULL, + const char* referrer = NULL, + PRBool forceJSEnabled = PR_FALSE); + + NS_IMETHOD + PostURL(nsISupports* pluginInst, + const char* url, + PRUint32 postDataLen, + const char* postData, + PRBool isFile = PR_FALSE, + const char* target = NULL, + nsIPluginStreamListener* streamListener = NULL, + nsPluginStreamType streamType = nsPluginStreamType_Normal, + const char* altHost = NULL, + const char* referrer = NULL, + PRBool forceJSEnabled = PR_FALSE, + PRUint32 postHeadersLength = 0, + const char* postHeaders = NULL); + +#else // !NEW_PLUGIN_STREAM_API NS_IMETHOD GetURL(nsISupports* peer, const char* url, const char* target, void* notifyData = NULL, const char* altHost = NULL, @@ -84,8 +109,7 @@ public: PRBool forceJSEnabled = PR_FALSE, PRUint32 postHeadersLength = 0, const char* postHeaders = NULL); - NS_IMETHOD - FindProxyForURL(const char* url, char* *result); +#endif // !NEW_PLUGIN_STREAM_API }; @@ -235,6 +259,92 @@ protected: char** values_list; }; +#ifdef NEW_PLUGIN_STREAM_API + +class CPluginInputStream : public nsIPluginInputStream { +public: + + NS_DECL_ISUPPORTS + + //////////////////////////////////////////////////////////////////////////// + // from nsIBaseStream: + + /** Close the stream. */ + NS_IMETHOD + Close(void); + + //////////////////////////////////////////////////////////////////////////// + // from nsIInputStream: + + /** Return the number of bytes in the stream + * @param aLength out parameter to hold the length + * of the stream. if an error occurs, the length + * will be undefined + * @return error status + */ + NS_IMETHOD + GetLength(PRInt32 *aLength); + + /** Read data from the stream. + * @param aErrorCode the error code if an error occurs + * @param aBuf the buffer into which the data is read + * @param aOffset the start offset of the data + * @param aCount the maximum number of bytes to read + * @param aReadCount out parameter to hold the number of + * bytes read, eof if 0. if an error occurs, the + * read count will be undefined + * @return error status + */ + NS_IMETHOD + Read(char* aBuf, PRInt32 aOffset, PRInt32 aCount, PRInt32 *aReadCount); + + //////////////////////////////////////////////////////////////////////////// + // from nsIPluginInputStream: + + // (Corresponds to NPStream's lastmodified field.) + NS_IMETHOD + GetLastModified(PRUint32 *result); + + NS_IMETHOD + RequestRead(nsByteRange* rangeList); + + //////////////////////////////////////////////////////////////////////////// + // CPluginInputStream specific methods: + + CPluginInputStream(nsIPluginStreamListener* listener, + nsPluginStreamType streamType); + virtual ~CPluginInputStream(void); + + void SetStreamInfo(NPP npp, NPStream* stream) { + mNPP = npp; + mStream = stream; + } + + nsIPluginStreamListener* GetListener(void) { return mListener; } + nsPluginStreamType GetStreamType(void) { return mStreamType; } + + nsresult SetReadBuffer(PRUint32 len, const char* buffer) { + // XXX this has to be way more sophisticated + mBuffer = strdup(buffer); + mBufferLength = len; + mAmountRead = 0; + return NS_OK; + } + +protected: + const char* mURL; + nsIPluginStreamListener* mListener; + nsPluginStreamType mStreamType; + NPP mNPP; + NPStream* mStream; + char* mBuffer; + PRUint32 mBufferLength; + PRUint32 mAmountRead; + +}; + +#else // !NEW_PLUGIN_STREAM_API + //////////////////////////////////////////////////////////////////////////////// // // CPluginStreamPeer @@ -299,6 +409,8 @@ protected: }; +#endif // !NEW_PLUGIN_STREAM_API + ////////////////////////////////////////////////////////////////////////////// #ifdef XP_UNIX @@ -350,8 +462,13 @@ NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID); NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID); NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID); NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID); + +#ifdef NEW_PLUGIN_STREAM_API +NS_DEFINE_IID(kIPluginInputStreamIID, NS_IPLUGININPUTSTREAM_IID); +#else // !NEW_PLUGIN_STREAM_API NS_DEFINE_IID(kIPluginStreamPeerIID, NS_IPLUGINSTREAMPEER_IID); NS_DEFINE_IID(kISeekablePluginStreamPeerIID, NS_ISEEKABLEPLUGINSTREAMPEER_IID); +#endif // !NEW_PLUGIN_STREAM_API // mapping from NPError to nsresult nsresult fromNPError[] = { @@ -510,18 +627,19 @@ jref NPP_GetJavaClass(void) { // Only call initialize the plugin if it hasn't been `d. - /* if (thePluginManager == NULL) { +#if 0 + if (thePluginManager == NULL) { // Create the plugin manager and plugin objects. NPError result = CPluginManager::Create(); if (result) return NULL; - assert( thePluginManager != NULL ); + assert( thePluginManager != NULL ); thePluginManager->AddRef(); NP_CreatePlugin(thePluginManager, (nsIPlugin** )(&thePlugin)); assert( thePlugin != NULL ); - } - */ -// return thePlugin->GetJavaClass(); - return NULL; + } + return thePlugin->GetJavaClass(); +#endif + return NULL; } //+++++++++++++++++++++++++++++++++++++++++++++++++ @@ -535,19 +653,19 @@ NPP_GetJavaClass(void) void NPP_Shutdown(void) { -// TRACE("NPP_Shutdown\n"); +// TRACE("NPP_Shutdown\n"); - if (thePlugin) - { - thePlugin->Shutdown(); - thePlugin->Release(); - thePlugin = NULL; - } + if (thePlugin) + { + thePlugin->Shutdown(); + thePlugin->Release(); + thePlugin = NULL; + } - if (thePluginManager) { - thePluginManager->Release(); - thePluginManager = NULL; - } + if (thePluginManager) { + thePluginManager->Release(); + thePluginManager = NULL; + } return; } @@ -664,10 +782,10 @@ NPP_SetWindow(NPP instance, NPWindow* window) NPError NPP_NewStream(NPP instance, - NPMIMEType type, - NPStream *stream, - NPBool seekable, - PRUint16 *stype) + NPMIMEType type, + NPStream *stream, + NPBool seekable, + PRUint16 *stype) { // XXX - How do you set the fields of the peer stream and stream? // XXX - Looks like these field will have to be created since @@ -678,11 +796,29 @@ NPP_NewStream(NPP instance, if (instance == NULL) return NPERR_INVALID_INSTANCE_ERROR; +#ifdef NEW_PLUGIN_STREAM_API + + CPluginInputStream* inStr = (CPluginInputStream*)stream->notifyData; + if (inStr == NULL) + return NPERR_GENERIC_ERROR; + nsPluginStreamInfo info; + info.contentType = type; + info.seekable = seekable; + nsresult err = inStr->GetListener()->OnStartBinding(stream->url, &info); + if (err) return err; + + inStr->SetStreamInfo(instance, stream); + stream->pdata = inStr; + *stype = inStr->GetStreamType(); + +#else // !NEW_PLUGIN_STREAM_API + // Create a new plugin stream peer and plugin stream. CPluginStreamPeer* speer = new CPluginStreamPeer((nsMIMEType)type, stream, (PRBool)seekable, stype); if (speer == NULL) return NPERR_OUT_OF_MEMORY_ERROR; speer->AddRef(); + nsIPluginStream* pluginStream = NULL; CPluginInstancePeer* peer = (CPluginInstancePeer*) instance->pdata; nsIPluginInstance* pluginInstance = peer->GetInstance(); @@ -697,6 +833,8 @@ NPP_NewStream(NPP instance, err = pluginStream->GetStreamType((nsPluginStreamType*)stype); assert(err == NS_OK); +#endif // !NEW_PLUGIN_STREAM_API + return NPERR_NO_ERROR; } @@ -714,11 +852,22 @@ NPP_WriteReady(NPP instance, NPStream *stream) if (instance == NULL) return -1; +#ifdef NEW_PLUGIN_STREAM_API + + CPluginInputStream* inStr = (CPluginInputStream*)stream->pdata; + if (inStr == NULL) + return -1; + return NP_MAXREADY; + +#else // !NEW_PLUGIN_STREAM_API + nsIPluginStream* theStream = (nsIPluginStream*) stream->pdata; if( theStream == 0 ) return -1; return 8192; + +#endif // !NEW_PLUGIN_STREAM_API } @@ -735,6 +884,19 @@ NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer) if (instance == NULL) return -1; +#ifdef NEW_PLUGIN_STREAM_API + + CPluginInputStream* inStr = (CPluginInputStream*)stream->pdata; + if (inStr == NULL) + return -1; + nsresult err = inStr->SetReadBuffer((PRUint32)len, (const char*)buffer); + if (err != NS_OK) return -1; + err = inStr->GetListener()->OnDataAvailable(stream->url, inStr, offset, len); + if (err != NS_OK) return -1; + return len; + +#else // !NEW_PLUGIN_STREAM_API + nsIPluginStream* theStream = (nsIPluginStream*) stream->pdata; if( theStream == 0 ) return -1; @@ -742,6 +904,8 @@ NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer) PRInt32 count; nsresult err = theStream->Write((const char* )buffer, offset, len, &count); return (err == NS_OK) ? count : -1; + +#endif // !NEW_PLUGIN_STREAM_API } //+++++++++++++++++++++++++++++++++++++++++++++++++ @@ -760,12 +924,25 @@ NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason) if (instance == NULL) return NPERR_INVALID_INSTANCE_ERROR; +#ifdef NEW_PLUGIN_STREAM_API + + CPluginInputStream* inStr = (CPluginInputStream*)stream->pdata; + if (inStr == NULL) + return NPERR_GENERIC_ERROR; + inStr->GetListener()->OnStopBinding(stream->url, (nsPluginReason)reason); + inStr->Release(); + stream->pdata = NULL; + +#else // !NEW_PLUGIN_STREAM_API + nsIPluginStream* theStream = (nsIPluginStream*) stream->pdata; if( theStream == 0 ) return NPERR_GENERIC_ERROR; theStream->Release(); stream->pdata = NULL; + +#endif // !NEW_PLUGIN_STREAM_API return NPERR_NO_ERROR; } @@ -778,16 +955,27 @@ NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason) void NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname) { -// TRACE("NPP_StreamAsFile\n"); +// TRACE("NPP_StreamAsFile\n"); - if (instance == NULL) - return; + if (instance == NULL) + return; - nsIPluginStream* theStream = (nsIPluginStream*) stream->pdata; - if( theStream == 0 ) - return; +#ifdef NEW_PLUGIN_STREAM_API - theStream->AsFile( fname ); + CPluginInputStream* inStr = (CPluginInputStream*)stream->pdata; + if (inStr == NULL) + return; + (void)inStr->GetListener()->OnFileAvailable(stream->url, fname); + +#else // !NEW_PLUGIN_STREAM_API + + nsIPluginStream* theStream = (nsIPluginStream*) stream->pdata; + if( theStream == 0 ) + return; + + theStream->AsFile( fname ); + +#endif // !NEW_PLUGIN_STREAM_API } //+++++++++++++++++++++++++++++++++++++++++++++++++ @@ -802,12 +990,12 @@ NPP_Print(NPP instance, NPPrint* printInfo) if(printInfo == NULL) // trap invalid parm return; - if (instance != NULL) - { - CPluginInstancePeer* peer = (CPluginInstancePeer*) instance->pdata; - nsIPluginInstance* pluginInstance = peer->GetInstance(); - pluginInstance->Print((nsPluginPrint* ) printInfo ); - } + if (instance != NULL) + { + CPluginInstancePeer* peer = (CPluginInstancePeer*) instance->pdata; + nsIPluginInstance* pluginInstance = peer->GetInstance(); + pluginInstance->Print((nsPluginPrint* ) printInfo ); + } } //+++++++++++++++++++++++++++++++++++++++++++++++++ @@ -818,14 +1006,22 @@ NPP_Print(NPP instance, NPPrint* printInfo) void NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData) { -// TRACE("NPP_URLNotify\n"); +// TRACE("NPP_URLNotify\n"); - if( instance != NULL ) - { - CPluginInstancePeer* peer = (CPluginInstancePeer*) instance->pdata; - nsIPluginInstance* pluginInstance = peer->GetInstance(); - pluginInstance->URLNotify(url, NULL, (nsPluginReason)reason, notifyData); - } + if (instance != NULL) { +#ifdef NEW_PLUGIN_STREAM_API + + CPluginInputStream* inStr = (CPluginInputStream*)notifyData; + (void)inStr->GetListener()->OnStopBinding(url, (nsPluginReason)reason); + +#else // !NEW_PLUGIN_STREAM_API + + CPluginInstancePeer* peer = (CPluginInstancePeer*) instance->pdata; + nsIPluginInstance* pluginInstance = peer->GetInstance(); + pluginInstance->URLNotify(url, NULL, (nsPluginReason)reason, notifyData); + +#endif // !NEW_PLUGIN_STREAM_API + } } //+++++++++++++++++++++++++++++++++++++++++++++++++ @@ -839,29 +1035,29 @@ int16 NPP_HandleEvent(NPP instance, void* event) { // TRACE("NPP_HandleEvent\n"); - int16 eventHandled = FALSE; - if (instance == NULL) - return eventHandled; + int16 eventHandled = FALSE; + if (instance == NULL) + return eventHandled; - NPEvent* npEvent = (NPEvent*) event; - nsPluginEvent pluginEvent = { + NPEvent* npEvent = (NPEvent*) event; + nsPluginEvent pluginEvent = { #ifdef XP_MAC - npEvent, NULL + npEvent, NULL #else - npEvent->event, npEvent->wParam, npEvent->lParam + npEvent->event, npEvent->wParam, npEvent->lParam #endif - }; + }; CPluginInstancePeer* peer = (CPluginInstancePeer*) instance->pdata; nsIPluginInstance* pluginInstance = peer->GetInstance(); - if (pluginInstance) { + if (pluginInstance) { PRBool handled; - nsresult err = pluginInstance->HandleEvent(&pluginEvent, &handled); + nsresult err = pluginInstance->HandleEvent(&pluginEvent, &handled); if (err) return FALSE; eventHandled = (handled == PR_TRUE); } - return eventHandled; + return eventHandled; } #endif // ndef XP_UNIX @@ -923,9 +1119,9 @@ NS_METHOD CPluginManager::MemFlush(PRUint32 size) { #ifdef XP_MAC - return NPN_MemFlush(size); + return NPN_MemFlush(size); #else - return 0; + return 0; #endif } #endif @@ -937,10 +1133,109 @@ CPluginManager::MemFlush(PRUint32 size) NS_METHOD CPluginManager::ReloadPlugins(PRBool reloadPages) { - NPN_ReloadPlugins(reloadPages); + NPN_ReloadPlugins(reloadPages); return NS_OK; } +#ifdef NEW_PLUGIN_STREAM_API + +NS_METHOD +CPluginManager::GetURL(nsISupports* pluginInst, + const char* url, + const char* target, + nsIPluginStreamListener* streamListener, + nsPluginStreamType streamType, + const char* altHost, + const char* referrer, + PRBool forceJSEnabled) +{ + if (altHost != NULL || referrer != NULL || forceJSEnabled != PR_FALSE) { + return NPERR_INVALID_PARAM; + } + + nsIPluginInstance* inst = NULL; + nsresult rslt = pluginInst->QueryInterface(kIPluginInstanceIID, (void**)&inst); + if (rslt != NS_OK) return rslt; + CPluginInstancePeer* instancePeer = NULL; + rslt = inst->GetPeer((nsIPluginInstancePeer**)&instancePeer); + if (rslt != NS_OK) { + inst->Release(); + return rslt; + } + NPP npp = instancePeer->GetNPPInstance(); + + NPError err; + if (streamListener) { + CPluginInputStream* inStr = new CPluginInputStream(streamListener, streamType); + if (inStr == NULL) { + instancePeer->Release(); + inst->Release(); + return NS_ERROR_OUT_OF_MEMORY; + } + inStr->AddRef(); + + err = NPN_GetURLNotify(npp, url, target, inStr); + } + else { + err = NPN_GetURL(npp, url, target); + } + instancePeer->Release(); + inst->Release(); + return fromNPError[err]; +} + +NS_METHOD +CPluginManager::PostURL(nsISupports* pluginInst, + const char* url, + PRUint32 postDataLen, + const char* postData, + PRBool isFile, + const char* target, + nsIPluginStreamListener* streamListener, + nsPluginStreamType streamType, + const char* altHost, + const char* referrer, + PRBool forceJSEnabled, + PRUint32 postHeadersLength, + const char* postHeaders) +{ + if (altHost != NULL || referrer != NULL || forceJSEnabled != PR_FALSE + || postHeadersLength != 0 || postHeaders != NULL) { + return NPERR_INVALID_PARAM; + } + + nsIPluginInstance* inst = NULL; + nsresult rslt = pluginInst->QueryInterface(kIPluginInstanceIID, (void**)&inst); + if (rslt != NS_OK) return rslt; + CPluginInstancePeer* instancePeer = NULL; + rslt = inst->GetPeer((nsIPluginInstancePeer**)&instancePeer); + if (rslt != NS_OK) { + inst->Release(); + return rslt; + } + NPP npp = instancePeer->GetNPPInstance(); + + NPError err; + if (streamListener) { + CPluginInputStream* inStr = new CPluginInputStream(streamListener, streamType); + if (inStr == NULL) { + instancePeer->Release(); + inst->Release(); + return NS_ERROR_OUT_OF_MEMORY; + } + inStr->AddRef(); + + err = NPN_PostURLNotify(npp, url, target, postDataLen, postData, isFile, inStr); + } + else { + err = NPN_PostURL(npp, url, target, postDataLen, postData, isFile); + } + instancePeer->Release(); + inst->Release(); + return fromNPError[err]; +} + +#else // !NEW_PLUGIN_STREAM_API // (Corresponds to NPN_GetURL and NPN_GetURLNotify.) // notifyData: When present, URLNotify is called passing the notifyData back @@ -968,7 +1263,7 @@ CPluginManager::GetURL(nsISupports* pinst, const char* url, const char* target, inst->Release(); return rslt; } - NPP npp = instancePeer->GetNPPInstance(); + NPP npp = instancePeer->GetNPPInstance(); NPError err; // Call the correct GetURL* function. @@ -1001,7 +1296,7 @@ CPluginManager::PostURL(nsISupports* pinst, const char* url, const char* target, inst->Release(); return rslt; } - NPP npp = instancePeer->GetNPPInstance(); + NPP npp = instancePeer->GetNPPInstance(); NPError err; // Call the correct PostURL* function. @@ -1016,11 +1311,7 @@ CPluginManager::PostURL(nsISupports* pinst, const char* url, const char* target, return fromNPError[err]; } -NS_METHOD -CPluginManager::FindProxyForURL(const char* url, char* *result) -{ - return NS_ERROR_FAILURE; -} +#endif // !NEW_PLUGIN_STREAM_API //+++++++++++++++++++++++++++++++++++++++++++++++++ // UserAgent: @@ -1122,33 +1413,33 @@ CPluginInstancePeer::CPluginInstancePeer(nsIPluginInstance* pluginInstance, mInstance->AddRef(); - attribute_list = (char**) NPN_MemAlloc(attr_cnt * sizeof(const char*)); - values_list = (char**) NPN_MemAlloc(attr_cnt * sizeof(const char*)); + attribute_list = (char**) NPN_MemAlloc(attr_cnt * sizeof(const char*)); + values_list = (char**) NPN_MemAlloc(attr_cnt * sizeof(const char*)); - if (attribute_list != NULL && values_list != NULL) { - for (int i = 0; i < attribute_cnt; i++) { - attribute_list[i] = (char*) NPN_MemAlloc(strlen(attr_list[i]) + 1); - if (attribute_list[i] != NULL) - strcpy(attribute_list[i], attr_list[i]); + if (attribute_list != NULL && values_list != NULL) { + for (int i = 0; i < attribute_cnt; i++) { + attribute_list[i] = (char*) NPN_MemAlloc(strlen(attr_list[i]) + 1); + if (attribute_list[i] != NULL) + strcpy(attribute_list[i], attr_list[i]); - values_list[i] = (char*) NPN_MemAlloc(strlen(val_list[i]) + 1); - if (values_list[i] != NULL) - strcpy(values_list[i], val_list[i]); - } - } + values_list[i] = (char*) NPN_MemAlloc(strlen(val_list[i]) + 1); + if (values_list[i] != NULL) + strcpy(values_list[i], val_list[i]); + } + } } CPluginInstancePeer::~CPluginInstancePeer(void) { - if (attribute_list != NULL && values_list != NULL) { - for (int i = 0; i < attribute_cnt; i++) { - NPN_MemFree(attribute_list[i]); - NPN_MemFree(values_list[i]); - } + if (attribute_list != NULL && values_list != NULL) { + for (int i = 0; i < attribute_cnt; i++) { + NPN_MemFree(attribute_list[i]); + NPN_MemFree(values_list[i]); + } - NPN_MemFree(attribute_list); - NPN_MemFree(values_list); - } + NPN_MemFree(attribute_list); + NPN_MemFree(values_list); + } } @@ -1212,45 +1503,45 @@ CPluginInstancePeer::GetMode(nsPluginMode *result) NS_METHOD CPluginInstancePeer::GetAttributes(PRUint16& n, const char* const*& names, const char* const*& values) { - n = attribute_cnt; - names = attribute_list; - values = values_list; + n = attribute_cnt; + names = attribute_list; + values = values_list; - return NS_OK; + return NS_OK; } #if defined(XP_MAC) inline unsigned char toupper(unsigned char c) { - return (c >= 'a' && c <= 'z') ? (c - ('a' - 'A')) : c; + return (c >= 'a' && c <= 'z') ? (c - ('a' - 'A')) : c; } static int strcasecmp(const char * str1, const char * str2) { #if __POWERPC__ - const unsigned char * p1 = (unsigned char *) str1 - 1; - const unsigned char * p2 = (unsigned char *) str2 - 1; - unsigned long c1, c2; + const unsigned char * p1 = (unsigned char *) str1 - 1; + const unsigned char * p2 = (unsigned char *) str2 - 1; + unsigned long c1, c2; - while (toupper(c1 = *++p1) == toupper(c2 = *++p2)) - if (!c1) - return(0); + while (toupper(c1 = *++p1) == toupper(c2 = *++p2)) + if (!c1) + return(0); #else - const unsigned char * p1 = (unsigned char *) str1; - const unsigned char * p2 = (unsigned char *) str2; - unsigned char c1, c2; + const unsigned char * p1 = (unsigned char *) str1; + const unsigned char * p2 = (unsigned char *) str2; + unsigned char c1, c2; - while (toupper(c1 = *p1++) == toupper(c2 = *p2++)) - if (!c1) - return(0); + while (toupper(c1 = *p1++) == toupper(c2 = *p2++)) + if (!c1) + return(0); #endif - return(toupper(c1) - toupper(c2)); + return(toupper(c1) - toupper(c2)); } #endif /* XP_MAC */ @@ -1260,19 +1551,19 @@ static int strcasecmp(const char * str1, const char * str2) NS_METHOD CPluginInstancePeer::GetAttribute(const char* name, const char* *result) { - for (int i=0; i < attribute_cnt; i++) { + for (int i=0; i < attribute_cnt; i++) { #if defined(XP_UNIX) || defined(XP_MAC) - if (strcasecmp(name, attribute_list[i]) == 0) + if (strcasecmp(name, attribute_list[i]) == 0) #else - if (stricmp(name, attribute_list[i]) == 0) + if (stricmp(name, attribute_list[i]) == 0) #endif - { - *result = values_list[i]; - return NS_OK; - } - } + { + *result = values_list[i]; + return NS_OK; + } + } - return NS_ERROR_FAILURE; + return NS_ERROR_FAILURE; } //+++++++++++++++++++++++++++++++++++++++++++++++++ @@ -1280,7 +1571,7 @@ CPluginInstancePeer::GetAttribute(const char* name, const char* *result) //+++++++++++++++++++++++++++++++++++++++++++++++++ NS_METHOD CPluginInstancePeer::NewStream(nsMIMEType type, const char* target, - nsIOutputStream* *result) + nsIOutputStream* *result) { assert( npp != NULL ); @@ -1464,13 +1755,77 @@ NS_IMPL_QUERY_INTERFACE(CPluginManagerStream, kIOutputStreamIID); ////////////////////////////////////////////////////////////////////////////// +#ifdef NEW_PLUGIN_STREAM_API + +CPluginInputStream::CPluginInputStream(nsIPluginStreamListener* listener, + nsPluginStreamType streamType) + : mListener(listener), mStreamType(streamType), + mNPP(NULL), mStream(NULL), + mBuffer(NULL), mBufferLength(0), mAmountRead(0) +{ + NS_INIT_REFCNT(); + mListener->AddRef(); +} + +CPluginInputStream::~CPluginInputStream(void) +{ + mListener->Release(); + free(mBuffer); +} + +NS_IMPL_ISUPPORTS(CPluginInputStream, kIPluginInputStreamIID); + +NS_METHOD +CPluginInputStream::Close(void) +{ + if (mNPP == NULL || mStream == NULL) + return NS_ERROR_FAILURE; + NPError err = NPN_DestroyStream(mNPP, mStream, NPRES_USER_BREAK); + return fromNPError[err]; +} + +NS_METHOD +CPluginInputStream::GetLength(PRInt32 *aLength) +{ + *aLength = mStream->end; + return NS_OK; +} + +NS_METHOD +CPluginInputStream::Read(char* aBuf, PRInt32 aOffset, PRInt32 aCount, PRInt32 *aReadCount) +{ + if (aOffset > (PRInt32)mBufferLength) + return NS_ERROR_FAILURE; // XXX right error? + PRUint32 cnt = PR_MIN(aCount, (PRInt32)mBufferLength - aOffset); + memcpy(aBuf, &mBuffer[aOffset], cnt); + *aReadCount = cnt; + mAmountRead -= cnt; + return NS_OK; +} + +NS_METHOD +CPluginInputStream::GetLastModified(PRUint32 *result) +{ + *result = mStream->lastmodified; + return NS_OK; +} + +NS_METHOD +CPluginInputStream::RequestRead(nsByteRange* rangeList) +{ + NPError err = NPN_RequestRead(mStream, (NPByteRange*)rangeList); + return fromNPError[err]; +} + +#else // !NEW_PLUGIN_STREAM_API + ////////////////////////////////////////////////////////////////////////////// // // CPluginStreamPeer // CPluginStreamPeer::CPluginStreamPeer(nsMIMEType type, NPStream* npStream, - PRBool seekable, PRUint16* stype) + PRBool seekable, PRUint16* stype) : type(type), npStream(npStream), seekable(seekable), stype(stype), reason(nsPluginReason_NoReason) { @@ -1583,6 +1938,8 @@ nsresult CPluginStreamPeer::QueryInterface(const nsIID& iid, void** ptr) return NS_NOINTERFACE; } +#endif // !NEW_PLUGIN_STREAM_API + ////////////////////////////////////////////////////////////////////////////// #if defined(__cplusplus) diff --git a/mozilla/modules/plugin/base/public/Makefile b/mozilla/modules/plugin/base/public/Makefile index a9a67df8278..d0c3e5b5848 100644 --- a/mozilla/modules/plugin/base/public/Makefile +++ b/mozilla/modules/plugin/base/public/Makefile @@ -33,13 +33,20 @@ EXPORTS = \ nsIPluginManager.h \ nsIPluginManager2.h \ nsIPluginStream.h \ - nsIPluginStreamPeer.h \ - nsIPluginStreamPeer2.h \ nsIPluginTagInfo.h \ nsIPluginTagInfo2.h \ - nsISeekablePluginStreamPeer.h \ nsIWindowlessPlugInstPeer.h \ + nsIPluginInputStream.h \ + nsIPluginInputStream2.h \ + nsIPluginStreamListener.h \ nsplugin.h \ nsplugindefs.h +# DEPRECATED -- remove before we ship 5.0 +EXPORTS += \ + nsIPluginStream.h \ + nsIPluginStreamPeer.h \ + nsIPluginStreamPeer2.h \ + nsISeekablePluginStreamPeer.h \ + include $(DEPTH)/config/rules.mk diff --git a/mozilla/modules/plugin/base/public/Makefile.in b/mozilla/modules/plugin/base/public/Makefile.in index f10c41b5676..6d5122e405e 100644 --- a/mozilla/modules/plugin/base/public/Makefile.in +++ b/mozilla/modules/plugin/base/public/Makefile.in @@ -38,15 +38,22 @@ EXPORTS = \ nsIPluginManager.h \ nsIPluginManager2.h \ nsIPluginStream.h \ - nsIPluginStreamPeer.h \ - nsIPluginStreamPeer2.h \ nsIPluginTagInfo.h \ nsIPluginTagInfo2.h \ - nsISeekablePluginStreamPeer.h \ nsIWindowlessPlugInstPeer.h \ + nsIPluginInputStream.h \ + nsIPluginInputStream2.h \ + nsIPluginStreamListener.h \ nsplugin.h \ nsplugindefs.h +# DEPRECATED -- remove before we ship 5.0 +EXPORTS += \ + nsIPluginStream.h \ + nsIPluginStreamPeer.h \ + nsIPluginStreamPeer2.h \ + nsISeekablePluginStreamPeer.h \ + EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) include $(topsrcdir)/config/rules.mk diff --git a/mozilla/modules/plugin/base/public/makefile.win b/mozilla/modules/plugin/base/public/makefile.win index 9db9fe57661..37a54a3c85a 100644 --- a/mozilla/modules/plugin/base/public/makefile.win +++ b/mozilla/modules/plugin/base/public/makefile.win @@ -34,15 +34,21 @@ EXPORTS = \ nsIPluginInstancePeer.h \ nsIPluginManager.h \ nsIPluginManager2.h \ - nsIPluginStream.h \ - nsIPluginStreamPeer.h \ - nsIPluginStreamPeer2.h \ nsIPluginTagInfo.h \ nsIPluginTagInfo2.h \ - nsISeekablePluginStreamPeer.h \ nsIWindowlessPlugInstPeer.h \ + nsIPluginInputStream.h \ + nsIPluginInputStream2.h \ + nsIPluginStreamListener.h \ nsplugin.h \ nsplugindefs.h +# DEPRECATED -- remove before we ship 5.0 +EXPORTS = $(EXPORTS) \ + nsIPluginStream.h \ + nsIPluginStreamPeer.h \ + nsIPluginStreamPeer2.h \ + nsISeekablePluginStreamPeer.h \ + include <$(DEPTH)/config/rules.mak> diff --git a/mozilla/modules/plugin/base/public/nsIPluginInstance.h b/mozilla/modules/plugin/base/public/nsIPluginInstance.h index 4f0a6b1256e..2d27139a05f 100644 --- a/mozilla/modules/plugin/base/public/nsIPluginInstance.h +++ b/mozilla/modules/plugin/base/public/nsIPluginInstance.h @@ -126,6 +126,7 @@ public: NS_IMETHOD SetWindow(nsPluginWindow* window) = 0; +#ifndef NEW_PLUGIN_STREAM_API /** * Called when a new plugin stream must be constructed in order for the plugin * instance to receive a stream of data from the browser. @@ -139,6 +140,7 @@ public: */ NS_IMETHOD NewStream(nsIPluginStreamPeer* peer, nsIPluginStream* *result) = 0; +#endif /** * Called to instruct the plugin instance to print itself to a printer. @@ -151,6 +153,7 @@ public: NS_IMETHOD Print(nsPluginPrint* platformPrint) = 0; +#ifndef NEW_PLUGIN_STREAM_API /** * Called to notify the plugin instance that a URL request has been * completed. (See nsIPluginManager::GetURL and nsIPluginManager::PostURL). @@ -166,6 +169,7 @@ public: NS_IMETHOD URLNotify(const char* url, const char* target, nsPluginReason reason, void* notifyData) = 0; +#endif /** * Returns the value of a variable associated with the plugin instance. diff --git a/mozilla/modules/plugin/base/public/nsIPluginManager.h b/mozilla/modules/plugin/base/public/nsIPluginManager.h index de04e5ec71e..4b1c09c24b7 100644 --- a/mozilla/modules/plugin/base/public/nsIPluginManager.h +++ b/mozilla/modules/plugin/base/public/nsIPluginManager.h @@ -37,6 +37,8 @@ #include "nsplugindefs.h" #include "nsISupports.h" +class nsIPluginStreamListener; + /** * The nsIPluginManager interface defines the minimum set of functionality that * the browser will support if it allows plugins. Plugins can call QueryInterface @@ -82,11 +84,41 @@ public: NS_IMETHOD UserAgent(const char* *resultingAgentString) = 0; +#ifdef NEW_PLUGIN_STREAM_API + + NS_IMETHOD + GetURL(nsISupports* pluginInst, + const char* url, + const char* target = NULL, + nsIPluginStreamListener* streamListener = NULL, + nsPluginStreamType streamType = nsPluginStreamType_Normal, + const char* altHost = NULL, + const char* referrer = NULL, + PRBool forceJSEnabled = PR_FALSE) = 0; + + NS_IMETHOD + PostURL(nsISupports* pluginInst, + const char* url, + PRUint32 postDataLen, + const char* postData, + PRBool isFile = PR_FALSE, + const char* target = NULL, + nsIPluginStreamListener* streamListener = NULL, + nsPluginStreamType streamType = nsPluginStreamType_Normal, + const char* altHost = NULL, + const char* referrer = NULL, + PRBool forceJSEnabled = PR_FALSE, + PRUint32 postHeadersLength = 0, + const char* postHeaders = NULL) = 0; + +#else // !NEW_PLUGIN_STREAM_API /** * Fetches a URL. * * (Corresponds to NPN_GetURL and NPN_GetURLNotify.) * + * @param pluginInst - the plugin making the request. If NULL, the URL + * is fetched in the background. * @param url - the URL to fetch * @param target - the target window into which to load the URL * @param notifyData - when present, URLNotify is called passing the @@ -102,7 +134,7 @@ public: * @result - NS_OK if this operation was successful */ NS_IMETHOD - GetURL(nsISupports* peer, const char* url, const char* target, + GetURL(nsISupports* pluginInst, const char* url, const char* target, void* notifyData = NULL, const char* altHost = NULL, const char* referrer = NULL, PRBool forceJSEnabled = PR_FALSE) = 0; @@ -111,6 +143,8 @@ public: * * (Corresponds to NPN_PostURL and NPN_PostURLNotify.) * + * @param pluginInst - the plugin making the request. If NULL, the URL + * is fetched in the background. * @param url - the URL to fetch * @param target - the target window into which to load the URL * @param postDataLength - the length of postData (if non-NULL) @@ -134,12 +168,13 @@ public: * @result - NS_OK if this operation was successful */ NS_IMETHOD - PostURL(nsISupports* peer, const char* url, const char* target, + PostURL(nsISupports* pluginInst, const char* url, const char* target, PRUint32 postDataLen, const char* postData, PRBool isFile = PR_FALSE, void* notifyData = NULL, const char* altHost = NULL, const char* referrer = NULL, PRBool forceJSEnabled = PR_FALSE, PRUint32 postHeadersLength = 0, const char* postHeaders = NULL) = 0; +#endif // !NEW_PLUGIN_STREAM_API }; diff --git a/mozilla/modules/plugin/base/public/nsIPluginManager2.h b/mozilla/modules/plugin/base/public/nsIPluginManager2.h index ec4aad7e6a9..3ebd1c7fa9f 100644 --- a/mozilla/modules/plugin/base/public/nsIPluginManager2.h +++ b/mozilla/modules/plugin/base/public/nsIPluginManager2.h @@ -155,6 +155,7 @@ public: NS_IMETHOD HasAllocatedMenuID(nsIEventHandler* handler, PRInt16 menuID, PRBool *result) = 0; +#if 0 // problematic /** * This operation causes the next browser event to be processed. This is * handy for implement nested event loops where some other activity must @@ -171,7 +172,7 @@ public: */ NS_IMETHOD ProcessNextEvent(PRBool *bEventHandled) = 0; - +#endif }; #define NS_IPLUGINMANAGER2_IID \ diff --git a/mozilla/modules/plugin/base/public/nsIPluginStream.h b/mozilla/modules/plugin/base/public/nsIPluginStream.h index 4389b6280da..99f29c0aa03 100644 --- a/mozilla/modules/plugin/base/public/nsIPluginStream.h +++ b/mozilla/modules/plugin/base/public/nsIPluginStream.h @@ -34,13 +34,15 @@ #ifndef nsIPluginStream_h___ #define nsIPluginStream_h___ +#ifndef NEW_PLUGIN_STREAM_API + #include "nsplugindefs.h" #include "nsIOutputStream.h" /** * The nsIPluginStream interface specifies the minimal set of operations that * must be implemented by a plugin stream in order to receive data from the - * browser. When a nsIPluginManager::FetchURL request is made, a subsequent + * browser. When a nsIPluginManager::GetURL request is made, a subsequent * nsIPluginInstance::NewStream request will be made to instruct the plugin * instance to construct a new stream to receive the data. */ @@ -80,6 +82,8 @@ public: {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ } +#endif // !NEW_PLUGIN_STREAM_API + //////////////////////////////////////////////////////////////////////////////// #endif /* nsIPluginStream_h___ */ diff --git a/mozilla/modules/plugin/base/public/nsIPluginStreamPeer.h b/mozilla/modules/plugin/base/public/nsIPluginStreamPeer.h index 3b9de94d8e0..50e9512fd04 100644 --- a/mozilla/modules/plugin/base/public/nsIPluginStreamPeer.h +++ b/mozilla/modules/plugin/base/public/nsIPluginStreamPeer.h @@ -34,6 +34,8 @@ #ifndef nsIPluginStreamPeer_h___ #define nsIPluginStreamPeer_h___ +#ifndef NEW_PLUGIN_STREAM_API + #include "nsplugindefs.h" #include "nsISupports.h" @@ -80,6 +82,8 @@ public: {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ } +#endif // !NEW_PLUGIN_STREAM_API + //////////////////////////////////////////////////////////////////////////////// #endif /* nsIPluginStreamPeer_h___ */ diff --git a/mozilla/modules/plugin/base/public/nsIPluginStreamPeer2.h b/mozilla/modules/plugin/base/public/nsIPluginStreamPeer2.h index bc686306c3c..07b0b174608 100644 --- a/mozilla/modules/plugin/base/public/nsIPluginStreamPeer2.h +++ b/mozilla/modules/plugin/base/public/nsIPluginStreamPeer2.h @@ -34,6 +34,8 @@ #ifndef nsIPluginStreamPeer2_h___ #define nsIPluginStreamPeer2_h___ +#ifndef NEW_PLUGIN_STREAM_API + #include "nsIPluginStreamPeer.h" //////////////////////////////////////////////////////////////////////////////// @@ -65,6 +67,8 @@ public: {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ } +#endif // !NEW_PLUGIN_STREAM_API + //////////////////////////////////////////////////////////////////////////////// #endif /* nsIPluginStreamPeer2_h___ */ diff --git a/mozilla/modules/plugin/base/public/nsISeekablePluginStreamPeer.h b/mozilla/modules/plugin/base/public/nsISeekablePluginStreamPeer.h index 85b2ced1bfb..6e7ed03fdce 100644 --- a/mozilla/modules/plugin/base/public/nsISeekablePluginStreamPeer.h +++ b/mozilla/modules/plugin/base/public/nsISeekablePluginStreamPeer.h @@ -34,6 +34,8 @@ #ifndef nsISeekablePluginStreamPeer_h___ #define nsISeekablePluginStreamPeer_h___ +#ifndef NEW_PLUGIN_STREAM_API + #include "nsplugindefs.h" #include "nsISupports.h" @@ -63,6 +65,8 @@ public: {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ } +#endif // !NEW_PLUGIN_STREAM_API + //////////////////////////////////////////////////////////////////////////////// #endif /* nsISeekablePluginStreamPeer_h___ */ diff --git a/mozilla/modules/plugin/base/public/nsplugin.h b/mozilla/modules/plugin/base/public/nsplugin.h index d901c8bc672..9f6645a7763 100644 --- a/mozilla/modules/plugin/base/public/nsplugin.h +++ b/mozilla/modules/plugin/base/public/nsplugin.h @@ -57,11 +57,10 @@ * | v v * | +---------------------------------+ +----------------------------+ * | | nsIPluginInstancePeer |+ | nsIPluginStreamPeer |+ - * | | nsIPluginInstancePeer2 || | nsISeekablePluginStreamPeer|| - * | | nsIWindowlessPluginInstancePeer || | nsIPluginstreamPeer2 || - * | | nsILiveConnectPluginInstancePeer|| +----------------------------+| - * | | nsIPluginTagInfo || +---------------------------+ - * | | nsIPluginTagInfo2 || + * | | nsIWindowlessPluginInstancePeer || | nsISeekablePluginStreamPeer|| + * | | nsILiveConnectPluginInstancePeer|| | nsIPluginstreamPeer2 || + * | | nsIPluginTagInfo || +----------------------------+| + * | | nsIPluginTagInfo2 || +---------------------------+ * | +---------------------------------+| * | +--------------------------------+ * | @@ -110,12 +109,23 @@ */ #include "nsIPluginInstance.h" +#ifdef NEW_PLUGIN_STREAM_API + +/** + * A plugin stream listener ... + */ +#include "nsIPluginStreamListener.h" + +#else // !NEW_PLUGIN_STREAM_API + /** * A plugin stream gets instantiated when a plugin instance receives data from * the browser. */ #include "nsIPluginStream.h" +#endif // !NEW_PLUGIN_STREAM_API + /** * The nsILiveConnectPlugin interface provides additional operations that a * plugin must implement if it is to be controlled by JavaScript through @@ -162,6 +172,15 @@ */ #include "nsIWindowlessPlugInstPeer.h" +#ifdef NEW_PLUGIN_STREAM_API + +/** + * + */ +#include "nsIPluginInputStream.h" + +#else // !NEW_PLUGIN_STREAM_API + /** * A plugin stream peer gets create by the browser and associated with each * plugin stream to represent stream and URL information, and provides @@ -177,6 +196,8 @@ */ #include "nsISeekablePluginStreamPeer.h" +#endif // !NEW_PLUGIN_STREAM_API + //////////////////////////////////////////////////////////////////////////////// /** * Interfaces implemented by the browser (new for 5.0): @@ -210,6 +231,15 @@ */ #include "nsILiveConnectPlugInstPeer.h" +#ifdef NEW_PLUGIN_STREAM_API + +/** + * + */ +#include "nsIPluginInputStream2.h" + +#else // !NEW_PLUGIN_STREAM_API + /** * The nsIPluginStreamPeer2 interface provides additional plugin stream * peer features only available in Communicator 5.0. @@ -218,6 +248,8 @@ */ #include "nsIPluginStreamPeer2.h" +#endif // !NEW_PLUGIN_STREAM_API + /** * The nsIPluginTagInfo2 interface provides additional html tag information * only available in Communicator 5.0. @@ -226,5 +258,7 @@ */ #include "nsIPluginTagInfo2.h" +#include "nsIOutputStream.h" + //////////////////////////////////////////////////////////////////////////////// #endif // nsplugins_h___ diff --git a/mozilla/modules/plugin/public/Makefile b/mozilla/modules/plugin/public/Makefile index a9a67df8278..d0c3e5b5848 100644 --- a/mozilla/modules/plugin/public/Makefile +++ b/mozilla/modules/plugin/public/Makefile @@ -33,13 +33,20 @@ EXPORTS = \ nsIPluginManager.h \ nsIPluginManager2.h \ nsIPluginStream.h \ - nsIPluginStreamPeer.h \ - nsIPluginStreamPeer2.h \ nsIPluginTagInfo.h \ nsIPluginTagInfo2.h \ - nsISeekablePluginStreamPeer.h \ nsIWindowlessPlugInstPeer.h \ + nsIPluginInputStream.h \ + nsIPluginInputStream2.h \ + nsIPluginStreamListener.h \ nsplugin.h \ nsplugindefs.h +# DEPRECATED -- remove before we ship 5.0 +EXPORTS += \ + nsIPluginStream.h \ + nsIPluginStreamPeer.h \ + nsIPluginStreamPeer2.h \ + nsISeekablePluginStreamPeer.h \ + include $(DEPTH)/config/rules.mk diff --git a/mozilla/modules/plugin/public/Makefile.in b/mozilla/modules/plugin/public/Makefile.in index f10c41b5676..6d5122e405e 100644 --- a/mozilla/modules/plugin/public/Makefile.in +++ b/mozilla/modules/plugin/public/Makefile.in @@ -38,15 +38,22 @@ EXPORTS = \ nsIPluginManager.h \ nsIPluginManager2.h \ nsIPluginStream.h \ - nsIPluginStreamPeer.h \ - nsIPluginStreamPeer2.h \ nsIPluginTagInfo.h \ nsIPluginTagInfo2.h \ - nsISeekablePluginStreamPeer.h \ nsIWindowlessPlugInstPeer.h \ + nsIPluginInputStream.h \ + nsIPluginInputStream2.h \ + nsIPluginStreamListener.h \ nsplugin.h \ nsplugindefs.h +# DEPRECATED -- remove before we ship 5.0 +EXPORTS += \ + nsIPluginStream.h \ + nsIPluginStreamPeer.h \ + nsIPluginStreamPeer2.h \ + nsISeekablePluginStreamPeer.h \ + EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) include $(topsrcdir)/config/rules.mk diff --git a/mozilla/modules/plugin/public/makefile.win b/mozilla/modules/plugin/public/makefile.win index 9db9fe57661..37a54a3c85a 100644 --- a/mozilla/modules/plugin/public/makefile.win +++ b/mozilla/modules/plugin/public/makefile.win @@ -34,15 +34,21 @@ EXPORTS = \ nsIPluginInstancePeer.h \ nsIPluginManager.h \ nsIPluginManager2.h \ - nsIPluginStream.h \ - nsIPluginStreamPeer.h \ - nsIPluginStreamPeer2.h \ nsIPluginTagInfo.h \ nsIPluginTagInfo2.h \ - nsISeekablePluginStreamPeer.h \ nsIWindowlessPlugInstPeer.h \ + nsIPluginInputStream.h \ + nsIPluginInputStream2.h \ + nsIPluginStreamListener.h \ nsplugin.h \ nsplugindefs.h +# DEPRECATED -- remove before we ship 5.0 +EXPORTS = $(EXPORTS) \ + nsIPluginStream.h \ + nsIPluginStreamPeer.h \ + nsIPluginStreamPeer2.h \ + nsISeekablePluginStreamPeer.h \ + include <$(DEPTH)/config/rules.mak> diff --git a/mozilla/modules/plugin/public/nsIPluginInstance.h b/mozilla/modules/plugin/public/nsIPluginInstance.h index 4f0a6b1256e..2d27139a05f 100644 --- a/mozilla/modules/plugin/public/nsIPluginInstance.h +++ b/mozilla/modules/plugin/public/nsIPluginInstance.h @@ -126,6 +126,7 @@ public: NS_IMETHOD SetWindow(nsPluginWindow* window) = 0; +#ifndef NEW_PLUGIN_STREAM_API /** * Called when a new plugin stream must be constructed in order for the plugin * instance to receive a stream of data from the browser. @@ -139,6 +140,7 @@ public: */ NS_IMETHOD NewStream(nsIPluginStreamPeer* peer, nsIPluginStream* *result) = 0; +#endif /** * Called to instruct the plugin instance to print itself to a printer. @@ -151,6 +153,7 @@ public: NS_IMETHOD Print(nsPluginPrint* platformPrint) = 0; +#ifndef NEW_PLUGIN_STREAM_API /** * Called to notify the plugin instance that a URL request has been * completed. (See nsIPluginManager::GetURL and nsIPluginManager::PostURL). @@ -166,6 +169,7 @@ public: NS_IMETHOD URLNotify(const char* url, const char* target, nsPluginReason reason, void* notifyData) = 0; +#endif /** * Returns the value of a variable associated with the plugin instance. diff --git a/mozilla/modules/plugin/public/nsIPluginManager.h b/mozilla/modules/plugin/public/nsIPluginManager.h index de04e5ec71e..4b1c09c24b7 100644 --- a/mozilla/modules/plugin/public/nsIPluginManager.h +++ b/mozilla/modules/plugin/public/nsIPluginManager.h @@ -37,6 +37,8 @@ #include "nsplugindefs.h" #include "nsISupports.h" +class nsIPluginStreamListener; + /** * The nsIPluginManager interface defines the minimum set of functionality that * the browser will support if it allows plugins. Plugins can call QueryInterface @@ -82,11 +84,41 @@ public: NS_IMETHOD UserAgent(const char* *resultingAgentString) = 0; +#ifdef NEW_PLUGIN_STREAM_API + + NS_IMETHOD + GetURL(nsISupports* pluginInst, + const char* url, + const char* target = NULL, + nsIPluginStreamListener* streamListener = NULL, + nsPluginStreamType streamType = nsPluginStreamType_Normal, + const char* altHost = NULL, + const char* referrer = NULL, + PRBool forceJSEnabled = PR_FALSE) = 0; + + NS_IMETHOD + PostURL(nsISupports* pluginInst, + const char* url, + PRUint32 postDataLen, + const char* postData, + PRBool isFile = PR_FALSE, + const char* target = NULL, + nsIPluginStreamListener* streamListener = NULL, + nsPluginStreamType streamType = nsPluginStreamType_Normal, + const char* altHost = NULL, + const char* referrer = NULL, + PRBool forceJSEnabled = PR_FALSE, + PRUint32 postHeadersLength = 0, + const char* postHeaders = NULL) = 0; + +#else // !NEW_PLUGIN_STREAM_API /** * Fetches a URL. * * (Corresponds to NPN_GetURL and NPN_GetURLNotify.) * + * @param pluginInst - the plugin making the request. If NULL, the URL + * is fetched in the background. * @param url - the URL to fetch * @param target - the target window into which to load the URL * @param notifyData - when present, URLNotify is called passing the @@ -102,7 +134,7 @@ public: * @result - NS_OK if this operation was successful */ NS_IMETHOD - GetURL(nsISupports* peer, const char* url, const char* target, + GetURL(nsISupports* pluginInst, const char* url, const char* target, void* notifyData = NULL, const char* altHost = NULL, const char* referrer = NULL, PRBool forceJSEnabled = PR_FALSE) = 0; @@ -111,6 +143,8 @@ public: * * (Corresponds to NPN_PostURL and NPN_PostURLNotify.) * + * @param pluginInst - the plugin making the request. If NULL, the URL + * is fetched in the background. * @param url - the URL to fetch * @param target - the target window into which to load the URL * @param postDataLength - the length of postData (if non-NULL) @@ -134,12 +168,13 @@ public: * @result - NS_OK if this operation was successful */ NS_IMETHOD - PostURL(nsISupports* peer, const char* url, const char* target, + PostURL(nsISupports* pluginInst, const char* url, const char* target, PRUint32 postDataLen, const char* postData, PRBool isFile = PR_FALSE, void* notifyData = NULL, const char* altHost = NULL, const char* referrer = NULL, PRBool forceJSEnabled = PR_FALSE, PRUint32 postHeadersLength = 0, const char* postHeaders = NULL) = 0; +#endif // !NEW_PLUGIN_STREAM_API }; diff --git a/mozilla/modules/plugin/public/nsIPluginManager2.h b/mozilla/modules/plugin/public/nsIPluginManager2.h index ec4aad7e6a9..3ebd1c7fa9f 100644 --- a/mozilla/modules/plugin/public/nsIPluginManager2.h +++ b/mozilla/modules/plugin/public/nsIPluginManager2.h @@ -155,6 +155,7 @@ public: NS_IMETHOD HasAllocatedMenuID(nsIEventHandler* handler, PRInt16 menuID, PRBool *result) = 0; +#if 0 // problematic /** * This operation causes the next browser event to be processed. This is * handy for implement nested event loops where some other activity must @@ -171,7 +172,7 @@ public: */ NS_IMETHOD ProcessNextEvent(PRBool *bEventHandled) = 0; - +#endif }; #define NS_IPLUGINMANAGER2_IID \ diff --git a/mozilla/modules/plugin/public/nsIPluginStream.h b/mozilla/modules/plugin/public/nsIPluginStream.h index 4389b6280da..99f29c0aa03 100644 --- a/mozilla/modules/plugin/public/nsIPluginStream.h +++ b/mozilla/modules/plugin/public/nsIPluginStream.h @@ -34,13 +34,15 @@ #ifndef nsIPluginStream_h___ #define nsIPluginStream_h___ +#ifndef NEW_PLUGIN_STREAM_API + #include "nsplugindefs.h" #include "nsIOutputStream.h" /** * The nsIPluginStream interface specifies the minimal set of operations that * must be implemented by a plugin stream in order to receive data from the - * browser. When a nsIPluginManager::FetchURL request is made, a subsequent + * browser. When a nsIPluginManager::GetURL request is made, a subsequent * nsIPluginInstance::NewStream request will be made to instruct the plugin * instance to construct a new stream to receive the data. */ @@ -80,6 +82,8 @@ public: {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ } +#endif // !NEW_PLUGIN_STREAM_API + //////////////////////////////////////////////////////////////////////////////// #endif /* nsIPluginStream_h___ */ diff --git a/mozilla/modules/plugin/public/nsIPluginStreamPeer.h b/mozilla/modules/plugin/public/nsIPluginStreamPeer.h index 3b9de94d8e0..50e9512fd04 100644 --- a/mozilla/modules/plugin/public/nsIPluginStreamPeer.h +++ b/mozilla/modules/plugin/public/nsIPluginStreamPeer.h @@ -34,6 +34,8 @@ #ifndef nsIPluginStreamPeer_h___ #define nsIPluginStreamPeer_h___ +#ifndef NEW_PLUGIN_STREAM_API + #include "nsplugindefs.h" #include "nsISupports.h" @@ -80,6 +82,8 @@ public: {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ } +#endif // !NEW_PLUGIN_STREAM_API + //////////////////////////////////////////////////////////////////////////////// #endif /* nsIPluginStreamPeer_h___ */ diff --git a/mozilla/modules/plugin/public/nsIPluginStreamPeer2.h b/mozilla/modules/plugin/public/nsIPluginStreamPeer2.h index bc686306c3c..07b0b174608 100644 --- a/mozilla/modules/plugin/public/nsIPluginStreamPeer2.h +++ b/mozilla/modules/plugin/public/nsIPluginStreamPeer2.h @@ -34,6 +34,8 @@ #ifndef nsIPluginStreamPeer2_h___ #define nsIPluginStreamPeer2_h___ +#ifndef NEW_PLUGIN_STREAM_API + #include "nsIPluginStreamPeer.h" //////////////////////////////////////////////////////////////////////////////// @@ -65,6 +67,8 @@ public: {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ } +#endif // !NEW_PLUGIN_STREAM_API + //////////////////////////////////////////////////////////////////////////////// #endif /* nsIPluginStreamPeer2_h___ */ diff --git a/mozilla/modules/plugin/public/nsISeekablePluginStreamPeer.h b/mozilla/modules/plugin/public/nsISeekablePluginStreamPeer.h index 85b2ced1bfb..6e7ed03fdce 100644 --- a/mozilla/modules/plugin/public/nsISeekablePluginStreamPeer.h +++ b/mozilla/modules/plugin/public/nsISeekablePluginStreamPeer.h @@ -34,6 +34,8 @@ #ifndef nsISeekablePluginStreamPeer_h___ #define nsISeekablePluginStreamPeer_h___ +#ifndef NEW_PLUGIN_STREAM_API + #include "nsplugindefs.h" #include "nsISupports.h" @@ -63,6 +65,8 @@ public: {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ } +#endif // !NEW_PLUGIN_STREAM_API + //////////////////////////////////////////////////////////////////////////////// #endif /* nsISeekablePluginStreamPeer_h___ */ diff --git a/mozilla/modules/plugin/public/nsplugin.h b/mozilla/modules/plugin/public/nsplugin.h index d901c8bc672..9f6645a7763 100644 --- a/mozilla/modules/plugin/public/nsplugin.h +++ b/mozilla/modules/plugin/public/nsplugin.h @@ -57,11 +57,10 @@ * | v v * | +---------------------------------+ +----------------------------+ * | | nsIPluginInstancePeer |+ | nsIPluginStreamPeer |+ - * | | nsIPluginInstancePeer2 || | nsISeekablePluginStreamPeer|| - * | | nsIWindowlessPluginInstancePeer || | nsIPluginstreamPeer2 || - * | | nsILiveConnectPluginInstancePeer|| +----------------------------+| - * | | nsIPluginTagInfo || +---------------------------+ - * | | nsIPluginTagInfo2 || + * | | nsIWindowlessPluginInstancePeer || | nsISeekablePluginStreamPeer|| + * | | nsILiveConnectPluginInstancePeer|| | nsIPluginstreamPeer2 || + * | | nsIPluginTagInfo || +----------------------------+| + * | | nsIPluginTagInfo2 || +---------------------------+ * | +---------------------------------+| * | +--------------------------------+ * | @@ -110,12 +109,23 @@ */ #include "nsIPluginInstance.h" +#ifdef NEW_PLUGIN_STREAM_API + +/** + * A plugin stream listener ... + */ +#include "nsIPluginStreamListener.h" + +#else // !NEW_PLUGIN_STREAM_API + /** * A plugin stream gets instantiated when a plugin instance receives data from * the browser. */ #include "nsIPluginStream.h" +#endif // !NEW_PLUGIN_STREAM_API + /** * The nsILiveConnectPlugin interface provides additional operations that a * plugin must implement if it is to be controlled by JavaScript through @@ -162,6 +172,15 @@ */ #include "nsIWindowlessPlugInstPeer.h" +#ifdef NEW_PLUGIN_STREAM_API + +/** + * + */ +#include "nsIPluginInputStream.h" + +#else // !NEW_PLUGIN_STREAM_API + /** * A plugin stream peer gets create by the browser and associated with each * plugin stream to represent stream and URL information, and provides @@ -177,6 +196,8 @@ */ #include "nsISeekablePluginStreamPeer.h" +#endif // !NEW_PLUGIN_STREAM_API + //////////////////////////////////////////////////////////////////////////////// /** * Interfaces implemented by the browser (new for 5.0): @@ -210,6 +231,15 @@ */ #include "nsILiveConnectPlugInstPeer.h" +#ifdef NEW_PLUGIN_STREAM_API + +/** + * + */ +#include "nsIPluginInputStream2.h" + +#else // !NEW_PLUGIN_STREAM_API + /** * The nsIPluginStreamPeer2 interface provides additional plugin stream * peer features only available in Communicator 5.0. @@ -218,6 +248,8 @@ */ #include "nsIPluginStreamPeer2.h" +#endif // !NEW_PLUGIN_STREAM_API + /** * The nsIPluginTagInfo2 interface provides additional html tag information * only available in Communicator 5.0. @@ -226,5 +258,7 @@ */ #include "nsIPluginTagInfo2.h" +#include "nsIOutputStream.h" + //////////////////////////////////////////////////////////////////////////////// #endif // nsplugins_h___ diff --git a/mozilla/modules/plugin/samples/backward/badapter.cpp b/mozilla/modules/plugin/samples/backward/badapter.cpp index d5e4845cf78..d2cbbdca919 100644 --- a/mozilla/modules/plugin/samples/backward/badapter.cpp +++ b/mozilla/modules/plugin/samples/backward/badapter.cpp @@ -68,9 +68,34 @@ public: NS_IMETHOD UserAgent(const char* *result); - //////////////////////////////////////////////////////////////////////////// - // from nsINetworkManager: +#ifdef NEW_PLUGIN_STREAM_API + NS_IMETHOD + GetURL(nsISupports* pluginInst, + const char* url, + const char* target = NULL, + nsIPluginStreamListener* streamListener = NULL, + nsPluginStreamType streamType = nsPluginStreamType_Normal, + const char* altHost = NULL, + const char* referrer = NULL, + PRBool forceJSEnabled = PR_FALSE); + + NS_IMETHOD + PostURL(nsISupports* pluginInst, + const char* url, + PRUint32 postDataLen, + const char* postData, + PRBool isFile = PR_FALSE, + const char* target = NULL, + nsIPluginStreamListener* streamListener = NULL, + nsPluginStreamType streamType = nsPluginStreamType_Normal, + const char* altHost = NULL, + const char* referrer = NULL, + PRBool forceJSEnabled = PR_FALSE, + PRUint32 postHeadersLength = 0, + const char* postHeaders = NULL); + +#else // !NEW_PLUGIN_STREAM_API NS_IMETHOD GetURL(nsISupports* peer, const char* url, const char* target, void* notifyData = NULL, const char* altHost = NULL, @@ -84,8 +109,7 @@ public: PRBool forceJSEnabled = PR_FALSE, PRUint32 postHeadersLength = 0, const char* postHeaders = NULL); - NS_IMETHOD - FindProxyForURL(const char* url, char* *result); +#endif // !NEW_PLUGIN_STREAM_API }; @@ -235,6 +259,92 @@ protected: char** values_list; }; +#ifdef NEW_PLUGIN_STREAM_API + +class CPluginInputStream : public nsIPluginInputStream { +public: + + NS_DECL_ISUPPORTS + + //////////////////////////////////////////////////////////////////////////// + // from nsIBaseStream: + + /** Close the stream. */ + NS_IMETHOD + Close(void); + + //////////////////////////////////////////////////////////////////////////// + // from nsIInputStream: + + /** Return the number of bytes in the stream + * @param aLength out parameter to hold the length + * of the stream. if an error occurs, the length + * will be undefined + * @return error status + */ + NS_IMETHOD + GetLength(PRInt32 *aLength); + + /** Read data from the stream. + * @param aErrorCode the error code if an error occurs + * @param aBuf the buffer into which the data is read + * @param aOffset the start offset of the data + * @param aCount the maximum number of bytes to read + * @param aReadCount out parameter to hold the number of + * bytes read, eof if 0. if an error occurs, the + * read count will be undefined + * @return error status + */ + NS_IMETHOD + Read(char* aBuf, PRInt32 aOffset, PRInt32 aCount, PRInt32 *aReadCount); + + //////////////////////////////////////////////////////////////////////////// + // from nsIPluginInputStream: + + // (Corresponds to NPStream's lastmodified field.) + NS_IMETHOD + GetLastModified(PRUint32 *result); + + NS_IMETHOD + RequestRead(nsByteRange* rangeList); + + //////////////////////////////////////////////////////////////////////////// + // CPluginInputStream specific methods: + + CPluginInputStream(nsIPluginStreamListener* listener, + nsPluginStreamType streamType); + virtual ~CPluginInputStream(void); + + void SetStreamInfo(NPP npp, NPStream* stream) { + mNPP = npp; + mStream = stream; + } + + nsIPluginStreamListener* GetListener(void) { return mListener; } + nsPluginStreamType GetStreamType(void) { return mStreamType; } + + nsresult SetReadBuffer(PRUint32 len, const char* buffer) { + // XXX this has to be way more sophisticated + mBuffer = strdup(buffer); + mBufferLength = len; + mAmountRead = 0; + return NS_OK; + } + +protected: + const char* mURL; + nsIPluginStreamListener* mListener; + nsPluginStreamType mStreamType; + NPP mNPP; + NPStream* mStream; + char* mBuffer; + PRUint32 mBufferLength; + PRUint32 mAmountRead; + +}; + +#else // !NEW_PLUGIN_STREAM_API + //////////////////////////////////////////////////////////////////////////////// // // CPluginStreamPeer @@ -299,6 +409,8 @@ protected: }; +#endif // !NEW_PLUGIN_STREAM_API + ////////////////////////////////////////////////////////////////////////////// #ifdef XP_UNIX @@ -350,8 +462,13 @@ NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID); NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID); NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID); NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID); + +#ifdef NEW_PLUGIN_STREAM_API +NS_DEFINE_IID(kIPluginInputStreamIID, NS_IPLUGININPUTSTREAM_IID); +#else // !NEW_PLUGIN_STREAM_API NS_DEFINE_IID(kIPluginStreamPeerIID, NS_IPLUGINSTREAMPEER_IID); NS_DEFINE_IID(kISeekablePluginStreamPeerIID, NS_ISEEKABLEPLUGINSTREAMPEER_IID); +#endif // !NEW_PLUGIN_STREAM_API // mapping from NPError to nsresult nsresult fromNPError[] = { @@ -510,18 +627,19 @@ jref NPP_GetJavaClass(void) { // Only call initialize the plugin if it hasn't been `d. - /* if (thePluginManager == NULL) { +#if 0 + if (thePluginManager == NULL) { // Create the plugin manager and plugin objects. NPError result = CPluginManager::Create(); if (result) return NULL; - assert( thePluginManager != NULL ); + assert( thePluginManager != NULL ); thePluginManager->AddRef(); NP_CreatePlugin(thePluginManager, (nsIPlugin** )(&thePlugin)); assert( thePlugin != NULL ); - } - */ -// return thePlugin->GetJavaClass(); - return NULL; + } + return thePlugin->GetJavaClass(); +#endif + return NULL; } //+++++++++++++++++++++++++++++++++++++++++++++++++ @@ -535,19 +653,19 @@ NPP_GetJavaClass(void) void NPP_Shutdown(void) { -// TRACE("NPP_Shutdown\n"); +// TRACE("NPP_Shutdown\n"); - if (thePlugin) - { - thePlugin->Shutdown(); - thePlugin->Release(); - thePlugin = NULL; - } + if (thePlugin) + { + thePlugin->Shutdown(); + thePlugin->Release(); + thePlugin = NULL; + } - if (thePluginManager) { - thePluginManager->Release(); - thePluginManager = NULL; - } + if (thePluginManager) { + thePluginManager->Release(); + thePluginManager = NULL; + } return; } @@ -664,10 +782,10 @@ NPP_SetWindow(NPP instance, NPWindow* window) NPError NPP_NewStream(NPP instance, - NPMIMEType type, - NPStream *stream, - NPBool seekable, - PRUint16 *stype) + NPMIMEType type, + NPStream *stream, + NPBool seekable, + PRUint16 *stype) { // XXX - How do you set the fields of the peer stream and stream? // XXX - Looks like these field will have to be created since @@ -678,11 +796,29 @@ NPP_NewStream(NPP instance, if (instance == NULL) return NPERR_INVALID_INSTANCE_ERROR; +#ifdef NEW_PLUGIN_STREAM_API + + CPluginInputStream* inStr = (CPluginInputStream*)stream->notifyData; + if (inStr == NULL) + return NPERR_GENERIC_ERROR; + nsPluginStreamInfo info; + info.contentType = type; + info.seekable = seekable; + nsresult err = inStr->GetListener()->OnStartBinding(stream->url, &info); + if (err) return err; + + inStr->SetStreamInfo(instance, stream); + stream->pdata = inStr; + *stype = inStr->GetStreamType(); + +#else // !NEW_PLUGIN_STREAM_API + // Create a new plugin stream peer and plugin stream. CPluginStreamPeer* speer = new CPluginStreamPeer((nsMIMEType)type, stream, (PRBool)seekable, stype); if (speer == NULL) return NPERR_OUT_OF_MEMORY_ERROR; speer->AddRef(); + nsIPluginStream* pluginStream = NULL; CPluginInstancePeer* peer = (CPluginInstancePeer*) instance->pdata; nsIPluginInstance* pluginInstance = peer->GetInstance(); @@ -697,6 +833,8 @@ NPP_NewStream(NPP instance, err = pluginStream->GetStreamType((nsPluginStreamType*)stype); assert(err == NS_OK); +#endif // !NEW_PLUGIN_STREAM_API + return NPERR_NO_ERROR; } @@ -714,11 +852,22 @@ NPP_WriteReady(NPP instance, NPStream *stream) if (instance == NULL) return -1; +#ifdef NEW_PLUGIN_STREAM_API + + CPluginInputStream* inStr = (CPluginInputStream*)stream->pdata; + if (inStr == NULL) + return -1; + return NP_MAXREADY; + +#else // !NEW_PLUGIN_STREAM_API + nsIPluginStream* theStream = (nsIPluginStream*) stream->pdata; if( theStream == 0 ) return -1; return 8192; + +#endif // !NEW_PLUGIN_STREAM_API } @@ -735,6 +884,19 @@ NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer) if (instance == NULL) return -1; +#ifdef NEW_PLUGIN_STREAM_API + + CPluginInputStream* inStr = (CPluginInputStream*)stream->pdata; + if (inStr == NULL) + return -1; + nsresult err = inStr->SetReadBuffer((PRUint32)len, (const char*)buffer); + if (err != NS_OK) return -1; + err = inStr->GetListener()->OnDataAvailable(stream->url, inStr, offset, len); + if (err != NS_OK) return -1; + return len; + +#else // !NEW_PLUGIN_STREAM_API + nsIPluginStream* theStream = (nsIPluginStream*) stream->pdata; if( theStream == 0 ) return -1; @@ -742,6 +904,8 @@ NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer) PRInt32 count; nsresult err = theStream->Write((const char* )buffer, offset, len, &count); return (err == NS_OK) ? count : -1; + +#endif // !NEW_PLUGIN_STREAM_API } //+++++++++++++++++++++++++++++++++++++++++++++++++ @@ -760,12 +924,25 @@ NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason) if (instance == NULL) return NPERR_INVALID_INSTANCE_ERROR; +#ifdef NEW_PLUGIN_STREAM_API + + CPluginInputStream* inStr = (CPluginInputStream*)stream->pdata; + if (inStr == NULL) + return NPERR_GENERIC_ERROR; + inStr->GetListener()->OnStopBinding(stream->url, (nsPluginReason)reason); + inStr->Release(); + stream->pdata = NULL; + +#else // !NEW_PLUGIN_STREAM_API + nsIPluginStream* theStream = (nsIPluginStream*) stream->pdata; if( theStream == 0 ) return NPERR_GENERIC_ERROR; theStream->Release(); stream->pdata = NULL; + +#endif // !NEW_PLUGIN_STREAM_API return NPERR_NO_ERROR; } @@ -778,16 +955,27 @@ NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason) void NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname) { -// TRACE("NPP_StreamAsFile\n"); +// TRACE("NPP_StreamAsFile\n"); - if (instance == NULL) - return; + if (instance == NULL) + return; - nsIPluginStream* theStream = (nsIPluginStream*) stream->pdata; - if( theStream == 0 ) - return; +#ifdef NEW_PLUGIN_STREAM_API - theStream->AsFile( fname ); + CPluginInputStream* inStr = (CPluginInputStream*)stream->pdata; + if (inStr == NULL) + return; + (void)inStr->GetListener()->OnFileAvailable(stream->url, fname); + +#else // !NEW_PLUGIN_STREAM_API + + nsIPluginStream* theStream = (nsIPluginStream*) stream->pdata; + if( theStream == 0 ) + return; + + theStream->AsFile( fname ); + +#endif // !NEW_PLUGIN_STREAM_API } //+++++++++++++++++++++++++++++++++++++++++++++++++ @@ -802,12 +990,12 @@ NPP_Print(NPP instance, NPPrint* printInfo) if(printInfo == NULL) // trap invalid parm return; - if (instance != NULL) - { - CPluginInstancePeer* peer = (CPluginInstancePeer*) instance->pdata; - nsIPluginInstance* pluginInstance = peer->GetInstance(); - pluginInstance->Print((nsPluginPrint* ) printInfo ); - } + if (instance != NULL) + { + CPluginInstancePeer* peer = (CPluginInstancePeer*) instance->pdata; + nsIPluginInstance* pluginInstance = peer->GetInstance(); + pluginInstance->Print((nsPluginPrint* ) printInfo ); + } } //+++++++++++++++++++++++++++++++++++++++++++++++++ @@ -818,14 +1006,22 @@ NPP_Print(NPP instance, NPPrint* printInfo) void NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData) { -// TRACE("NPP_URLNotify\n"); +// TRACE("NPP_URLNotify\n"); - if( instance != NULL ) - { - CPluginInstancePeer* peer = (CPluginInstancePeer*) instance->pdata; - nsIPluginInstance* pluginInstance = peer->GetInstance(); - pluginInstance->URLNotify(url, NULL, (nsPluginReason)reason, notifyData); - } + if (instance != NULL) { +#ifdef NEW_PLUGIN_STREAM_API + + CPluginInputStream* inStr = (CPluginInputStream*)notifyData; + (void)inStr->GetListener()->OnStopBinding(url, (nsPluginReason)reason); + +#else // !NEW_PLUGIN_STREAM_API + + CPluginInstancePeer* peer = (CPluginInstancePeer*) instance->pdata; + nsIPluginInstance* pluginInstance = peer->GetInstance(); + pluginInstance->URLNotify(url, NULL, (nsPluginReason)reason, notifyData); + +#endif // !NEW_PLUGIN_STREAM_API + } } //+++++++++++++++++++++++++++++++++++++++++++++++++ @@ -839,29 +1035,29 @@ int16 NPP_HandleEvent(NPP instance, void* event) { // TRACE("NPP_HandleEvent\n"); - int16 eventHandled = FALSE; - if (instance == NULL) - return eventHandled; + int16 eventHandled = FALSE; + if (instance == NULL) + return eventHandled; - NPEvent* npEvent = (NPEvent*) event; - nsPluginEvent pluginEvent = { + NPEvent* npEvent = (NPEvent*) event; + nsPluginEvent pluginEvent = { #ifdef XP_MAC - npEvent, NULL + npEvent, NULL #else - npEvent->event, npEvent->wParam, npEvent->lParam + npEvent->event, npEvent->wParam, npEvent->lParam #endif - }; + }; CPluginInstancePeer* peer = (CPluginInstancePeer*) instance->pdata; nsIPluginInstance* pluginInstance = peer->GetInstance(); - if (pluginInstance) { + if (pluginInstance) { PRBool handled; - nsresult err = pluginInstance->HandleEvent(&pluginEvent, &handled); + nsresult err = pluginInstance->HandleEvent(&pluginEvent, &handled); if (err) return FALSE; eventHandled = (handled == PR_TRUE); } - return eventHandled; + return eventHandled; } #endif // ndef XP_UNIX @@ -923,9 +1119,9 @@ NS_METHOD CPluginManager::MemFlush(PRUint32 size) { #ifdef XP_MAC - return NPN_MemFlush(size); + return NPN_MemFlush(size); #else - return 0; + return 0; #endif } #endif @@ -937,10 +1133,109 @@ CPluginManager::MemFlush(PRUint32 size) NS_METHOD CPluginManager::ReloadPlugins(PRBool reloadPages) { - NPN_ReloadPlugins(reloadPages); + NPN_ReloadPlugins(reloadPages); return NS_OK; } +#ifdef NEW_PLUGIN_STREAM_API + +NS_METHOD +CPluginManager::GetURL(nsISupports* pluginInst, + const char* url, + const char* target, + nsIPluginStreamListener* streamListener, + nsPluginStreamType streamType, + const char* altHost, + const char* referrer, + PRBool forceJSEnabled) +{ + if (altHost != NULL || referrer != NULL || forceJSEnabled != PR_FALSE) { + return NPERR_INVALID_PARAM; + } + + nsIPluginInstance* inst = NULL; + nsresult rslt = pluginInst->QueryInterface(kIPluginInstanceIID, (void**)&inst); + if (rslt != NS_OK) return rslt; + CPluginInstancePeer* instancePeer = NULL; + rslt = inst->GetPeer((nsIPluginInstancePeer**)&instancePeer); + if (rslt != NS_OK) { + inst->Release(); + return rslt; + } + NPP npp = instancePeer->GetNPPInstance(); + + NPError err; + if (streamListener) { + CPluginInputStream* inStr = new CPluginInputStream(streamListener, streamType); + if (inStr == NULL) { + instancePeer->Release(); + inst->Release(); + return NS_ERROR_OUT_OF_MEMORY; + } + inStr->AddRef(); + + err = NPN_GetURLNotify(npp, url, target, inStr); + } + else { + err = NPN_GetURL(npp, url, target); + } + instancePeer->Release(); + inst->Release(); + return fromNPError[err]; +} + +NS_METHOD +CPluginManager::PostURL(nsISupports* pluginInst, + const char* url, + PRUint32 postDataLen, + const char* postData, + PRBool isFile, + const char* target, + nsIPluginStreamListener* streamListener, + nsPluginStreamType streamType, + const char* altHost, + const char* referrer, + PRBool forceJSEnabled, + PRUint32 postHeadersLength, + const char* postHeaders) +{ + if (altHost != NULL || referrer != NULL || forceJSEnabled != PR_FALSE + || postHeadersLength != 0 || postHeaders != NULL) { + return NPERR_INVALID_PARAM; + } + + nsIPluginInstance* inst = NULL; + nsresult rslt = pluginInst->QueryInterface(kIPluginInstanceIID, (void**)&inst); + if (rslt != NS_OK) return rslt; + CPluginInstancePeer* instancePeer = NULL; + rslt = inst->GetPeer((nsIPluginInstancePeer**)&instancePeer); + if (rslt != NS_OK) { + inst->Release(); + return rslt; + } + NPP npp = instancePeer->GetNPPInstance(); + + NPError err; + if (streamListener) { + CPluginInputStream* inStr = new CPluginInputStream(streamListener, streamType); + if (inStr == NULL) { + instancePeer->Release(); + inst->Release(); + return NS_ERROR_OUT_OF_MEMORY; + } + inStr->AddRef(); + + err = NPN_PostURLNotify(npp, url, target, postDataLen, postData, isFile, inStr); + } + else { + err = NPN_PostURL(npp, url, target, postDataLen, postData, isFile); + } + instancePeer->Release(); + inst->Release(); + return fromNPError[err]; +} + +#else // !NEW_PLUGIN_STREAM_API // (Corresponds to NPN_GetURL and NPN_GetURLNotify.) // notifyData: When present, URLNotify is called passing the notifyData back @@ -968,7 +1263,7 @@ CPluginManager::GetURL(nsISupports* pinst, const char* url, const char* target, inst->Release(); return rslt; } - NPP npp = instancePeer->GetNPPInstance(); + NPP npp = instancePeer->GetNPPInstance(); NPError err; // Call the correct GetURL* function. @@ -1001,7 +1296,7 @@ CPluginManager::PostURL(nsISupports* pinst, const char* url, const char* target, inst->Release(); return rslt; } - NPP npp = instancePeer->GetNPPInstance(); + NPP npp = instancePeer->GetNPPInstance(); NPError err; // Call the correct PostURL* function. @@ -1016,11 +1311,7 @@ CPluginManager::PostURL(nsISupports* pinst, const char* url, const char* target, return fromNPError[err]; } -NS_METHOD -CPluginManager::FindProxyForURL(const char* url, char* *result) -{ - return NS_ERROR_FAILURE; -} +#endif // !NEW_PLUGIN_STREAM_API //+++++++++++++++++++++++++++++++++++++++++++++++++ // UserAgent: @@ -1122,33 +1413,33 @@ CPluginInstancePeer::CPluginInstancePeer(nsIPluginInstance* pluginInstance, mInstance->AddRef(); - attribute_list = (char**) NPN_MemAlloc(attr_cnt * sizeof(const char*)); - values_list = (char**) NPN_MemAlloc(attr_cnt * sizeof(const char*)); + attribute_list = (char**) NPN_MemAlloc(attr_cnt * sizeof(const char*)); + values_list = (char**) NPN_MemAlloc(attr_cnt * sizeof(const char*)); - if (attribute_list != NULL && values_list != NULL) { - for (int i = 0; i < attribute_cnt; i++) { - attribute_list[i] = (char*) NPN_MemAlloc(strlen(attr_list[i]) + 1); - if (attribute_list[i] != NULL) - strcpy(attribute_list[i], attr_list[i]); + if (attribute_list != NULL && values_list != NULL) { + for (int i = 0; i < attribute_cnt; i++) { + attribute_list[i] = (char*) NPN_MemAlloc(strlen(attr_list[i]) + 1); + if (attribute_list[i] != NULL) + strcpy(attribute_list[i], attr_list[i]); - values_list[i] = (char*) NPN_MemAlloc(strlen(val_list[i]) + 1); - if (values_list[i] != NULL) - strcpy(values_list[i], val_list[i]); - } - } + values_list[i] = (char*) NPN_MemAlloc(strlen(val_list[i]) + 1); + if (values_list[i] != NULL) + strcpy(values_list[i], val_list[i]); + } + } } CPluginInstancePeer::~CPluginInstancePeer(void) { - if (attribute_list != NULL && values_list != NULL) { - for (int i = 0; i < attribute_cnt; i++) { - NPN_MemFree(attribute_list[i]); - NPN_MemFree(values_list[i]); - } + if (attribute_list != NULL && values_list != NULL) { + for (int i = 0; i < attribute_cnt; i++) { + NPN_MemFree(attribute_list[i]); + NPN_MemFree(values_list[i]); + } - NPN_MemFree(attribute_list); - NPN_MemFree(values_list); - } + NPN_MemFree(attribute_list); + NPN_MemFree(values_list); + } } @@ -1212,45 +1503,45 @@ CPluginInstancePeer::GetMode(nsPluginMode *result) NS_METHOD CPluginInstancePeer::GetAttributes(PRUint16& n, const char* const*& names, const char* const*& values) { - n = attribute_cnt; - names = attribute_list; - values = values_list; + n = attribute_cnt; + names = attribute_list; + values = values_list; - return NS_OK; + return NS_OK; } #if defined(XP_MAC) inline unsigned char toupper(unsigned char c) { - return (c >= 'a' && c <= 'z') ? (c - ('a' - 'A')) : c; + return (c >= 'a' && c <= 'z') ? (c - ('a' - 'A')) : c; } static int strcasecmp(const char * str1, const char * str2) { #if __POWERPC__ - const unsigned char * p1 = (unsigned char *) str1 - 1; - const unsigned char * p2 = (unsigned char *) str2 - 1; - unsigned long c1, c2; + const unsigned char * p1 = (unsigned char *) str1 - 1; + const unsigned char * p2 = (unsigned char *) str2 - 1; + unsigned long c1, c2; - while (toupper(c1 = *++p1) == toupper(c2 = *++p2)) - if (!c1) - return(0); + while (toupper(c1 = *++p1) == toupper(c2 = *++p2)) + if (!c1) + return(0); #else - const unsigned char * p1 = (unsigned char *) str1; - const unsigned char * p2 = (unsigned char *) str2; - unsigned char c1, c2; + const unsigned char * p1 = (unsigned char *) str1; + const unsigned char * p2 = (unsigned char *) str2; + unsigned char c1, c2; - while (toupper(c1 = *p1++) == toupper(c2 = *p2++)) - if (!c1) - return(0); + while (toupper(c1 = *p1++) == toupper(c2 = *p2++)) + if (!c1) + return(0); #endif - return(toupper(c1) - toupper(c2)); + return(toupper(c1) - toupper(c2)); } #endif /* XP_MAC */ @@ -1260,19 +1551,19 @@ static int strcasecmp(const char * str1, const char * str2) NS_METHOD CPluginInstancePeer::GetAttribute(const char* name, const char* *result) { - for (int i=0; i < attribute_cnt; i++) { + for (int i=0; i < attribute_cnt; i++) { #if defined(XP_UNIX) || defined(XP_MAC) - if (strcasecmp(name, attribute_list[i]) == 0) + if (strcasecmp(name, attribute_list[i]) == 0) #else - if (stricmp(name, attribute_list[i]) == 0) + if (stricmp(name, attribute_list[i]) == 0) #endif - { - *result = values_list[i]; - return NS_OK; - } - } + { + *result = values_list[i]; + return NS_OK; + } + } - return NS_ERROR_FAILURE; + return NS_ERROR_FAILURE; } //+++++++++++++++++++++++++++++++++++++++++++++++++ @@ -1280,7 +1571,7 @@ CPluginInstancePeer::GetAttribute(const char* name, const char* *result) //+++++++++++++++++++++++++++++++++++++++++++++++++ NS_METHOD CPluginInstancePeer::NewStream(nsMIMEType type, const char* target, - nsIOutputStream* *result) + nsIOutputStream* *result) { assert( npp != NULL ); @@ -1464,13 +1755,77 @@ NS_IMPL_QUERY_INTERFACE(CPluginManagerStream, kIOutputStreamIID); ////////////////////////////////////////////////////////////////////////////// +#ifdef NEW_PLUGIN_STREAM_API + +CPluginInputStream::CPluginInputStream(nsIPluginStreamListener* listener, + nsPluginStreamType streamType) + : mListener(listener), mStreamType(streamType), + mNPP(NULL), mStream(NULL), + mBuffer(NULL), mBufferLength(0), mAmountRead(0) +{ + NS_INIT_REFCNT(); + mListener->AddRef(); +} + +CPluginInputStream::~CPluginInputStream(void) +{ + mListener->Release(); + free(mBuffer); +} + +NS_IMPL_ISUPPORTS(CPluginInputStream, kIPluginInputStreamIID); + +NS_METHOD +CPluginInputStream::Close(void) +{ + if (mNPP == NULL || mStream == NULL) + return NS_ERROR_FAILURE; + NPError err = NPN_DestroyStream(mNPP, mStream, NPRES_USER_BREAK); + return fromNPError[err]; +} + +NS_METHOD +CPluginInputStream::GetLength(PRInt32 *aLength) +{ + *aLength = mStream->end; + return NS_OK; +} + +NS_METHOD +CPluginInputStream::Read(char* aBuf, PRInt32 aOffset, PRInt32 aCount, PRInt32 *aReadCount) +{ + if (aOffset > (PRInt32)mBufferLength) + return NS_ERROR_FAILURE; // XXX right error? + PRUint32 cnt = PR_MIN(aCount, (PRInt32)mBufferLength - aOffset); + memcpy(aBuf, &mBuffer[aOffset], cnt); + *aReadCount = cnt; + mAmountRead -= cnt; + return NS_OK; +} + +NS_METHOD +CPluginInputStream::GetLastModified(PRUint32 *result) +{ + *result = mStream->lastmodified; + return NS_OK; +} + +NS_METHOD +CPluginInputStream::RequestRead(nsByteRange* rangeList) +{ + NPError err = NPN_RequestRead(mStream, (NPByteRange*)rangeList); + return fromNPError[err]; +} + +#else // !NEW_PLUGIN_STREAM_API + ////////////////////////////////////////////////////////////////////////////// // // CPluginStreamPeer // CPluginStreamPeer::CPluginStreamPeer(nsMIMEType type, NPStream* npStream, - PRBool seekable, PRUint16* stype) + PRBool seekable, PRUint16* stype) : type(type), npStream(npStream), seekable(seekable), stype(stype), reason(nsPluginReason_NoReason) { @@ -1583,6 +1938,8 @@ nsresult CPluginStreamPeer::QueryInterface(const nsIID& iid, void** ptr) return NS_NOINTERFACE; } +#endif // !NEW_PLUGIN_STREAM_API + ////////////////////////////////////////////////////////////////////////////// #if defined(__cplusplus) diff --git a/mozilla/modules/plugin/samples/simple/makefile.win b/mozilla/modules/plugin/samples/simple/makefile.win index 94ce1054697..c5ccfd69d0e 100644 --- a/mozilla/modules/plugin/samples/simple/makefile.win +++ b/mozilla/modules/plugin/samples/simple/makefile.win @@ -78,6 +78,11 @@ include <$(DEPTH)/config/rules.mak> LINCS=$(LINCS) -I$(PUBLIC)\plugin -I$(PUBLIC)\xpcom -I$(PUBLIC)\java -I$(PUBLIC)\plugimpl -I$(PUBLIC)\raptor -I_jri +!ifdef NEW_PLUGIN_STREAM_API +LCFLAGS = $(LCFLAGS) -DNEW_PLUGIN_STREAM_API +!endif + install:: $(DLL) - $(MAKE_INSTALL) $(XPDIST)\classes11\Simple.class $(DEPTH)\cmd\winfe\mkfiles32\x86dbg\plugins\simple +# $(MAKE_INSTALL) $(XPDIST)\classes11\Simple.class $(DEPTH)\cmd\winfe\mkfiles32\x86dbg\plugins\simple + $(MAKE_INSTALL) Simple.class $(DEPTH)\cmd\winfe\mkfiles32\x86dbg\plugins\simple $(MAKE_INSTALL) $(OBJDIR)\npsimple.dll $(DEPTH)\cmd\winfe\mkfiles32\x86dbg\plugins\simple diff --git a/mozilla/modules/plugin/samples/simple/npsimple.cpp b/mozilla/modules/plugin/samples/simple/npsimple.cpp index 89d8d677c4e..b550dc9ce34 100644 --- a/mozilla/modules/plugin/samples/simple/npsimple.cpp +++ b/mozilla/modules/plugin/samples/simple/npsimple.cpp @@ -249,19 +249,27 @@ public: NS_IMETHOD SetWindow(nsPluginWindow* window); +#ifndef NEW_PLUGIN_STREAM_API + // (Corresponds to NPP_NewStream.) NS_IMETHOD NewStream(nsIPluginStreamPeer* peer, nsIPluginStream* *result); +#endif // NEW_PLUGIN_STREAM_API + // (Corresponds to NPP_Print.) NS_IMETHOD Print(nsPluginPrint* platformPrint); +#ifndef NEW_PLUGIN_STREAM_API + // (Corresponds to NPP_URLNotify.) NS_IMETHOD URLNotify(const char* url, const char* target, nsPluginReason reason, void* notifyData); +#endif // NEW_PLUGIN_STREAM_API + NS_IMETHOD GetValue(nsPluginInstanceVariable variable, void *value); @@ -302,6 +310,70 @@ protected: // SimplePluginStream represents the stream used by SimplePluginInstances // to receive data from the browser. +#ifdef NEW_PLUGIN_STREAM_API + +class SimplePluginStreamListener : public nsIPluginStreamListener { +public: + + NS_DECL_ISUPPORTS + + //////////////////////////////////////////////////////////////////////////// + // from nsIPluginStreamListener: + + /** + * Notify the observer that the URL has started to load. This method is + * called only once, at the beginning of a URL load.

+ * + * @return The return value is currently ignored. In the future it may be + * used to cancel the URL load.. + */ + NS_IMETHOD + OnStartBinding(const char* url, const nsPluginStreamInfo* info); + + /** + * Notify the client that data is available in the input stream. This + * method is called whenver data is written into the input stream by the + * networking library...

+ * + * @param aIStream The input stream containing the data. This stream can + * be either a blocking or non-blocking stream. + * @param length The amount of data that was just pushed into the stream. + * @return The return value is currently ignored. + */ + NS_IMETHOD + OnDataAvailable(const char* url, nsIPluginInputStream* input, + PRUint32 offset, PRUint32 length); + + NS_IMETHOD + OnFileAvailable(const char* url, const char* fileName); + + /** + * Notify the observer that the URL has finished loading. This method is + * called once when the networking library has finished processing the + * URL transaction initiatied via the nsINetService::Open(...) call.

+ * + * This method is called regardless of whether the URL loaded successfully.

+ * + * @param status Status code for the URL load. + * @param msg A text string describing the error. + * @return The return value is currently ignored. + */ + NS_IMETHOD + OnStopBinding(const char* url, nsresult status); + + //////////////////////////////////////////////////////////////////////////// + // SimplePluginStreamListener specific methods: + + SimplePluginStreamListener(SimplePluginInstance* inst); + virtual ~SimplePluginStreamListener(void); + +protected: + SimplePluginInstance* fInst; + +}; + +#else // !NEW_PLUGIN_STREAM_API + class SimplePluginStream : public nsIPluginStream { public: @@ -350,19 +422,34 @@ protected: }; +#endif // !NEW_PLUGIN_STREAM_API + // Interface IDs we'll need: static NS_DEFINE_IID(kIPluginIID, NS_IPLUGIN_IID); static NS_DEFINE_IID(kIJRILiveConnectPluginIID, NS_IJRILIVECONNECTPLUGIN_IID); static NS_DEFINE_IID(kIJRILiveConnectPluginInstancePeerIID, NS_IJRILIVECONNECTPLUGININSTANCEPEER_IID); static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID); -static NS_DEFINE_IID(kIPluginStreamIID, NS_IPLUGINSTREAM_IID); static NS_DEFINE_IID(kIJRIEnvIID, NS_IJRIENV_IID); static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID); +#ifdef NEW_PLUGIN_STREAM_API +static NS_DEFINE_IID(kIPluginStreamListenerIID, NS_IPLUGINSTREAMLISTENER_IID); +#else // !NEW_PLUGIN_STREAM_API +static NS_DEFINE_IID(kIPluginStreamIID, NS_IPLUGINSTREAM_IID); +#endif // !NEW_PLUGIN_STREAM_API + /******************************************************************************* * SECTION 3 - API Plugin Implementations ******************************************************************************/ +// This counter is used to keep track of the number of outstanding objects. +// It is used to determine whether the plugin's DLL can be unloaded. +static PRUint32 gPluginObjectCount = 0; + +// This flag is used to keep track of whether the plugin's DLL is explicitly +// being retained by some client. +static PRBool gPluginLocked = PR_FALSE; + //////////////////////////////////////////////////////////////////////////////// // SimplePlugin Methods //////////////////////////////////////////////////////////////////////////////// @@ -371,10 +458,12 @@ SimplePlugin::SimplePlugin() : mgr(NULL) { NS_INIT_REFCNT(); + gPluginObjectCount++; } SimplePlugin::~SimplePlugin(void) { + gPluginObjectCount--; if (env) Simple::_unuse(env); } @@ -436,6 +525,12 @@ NSGetFactory(const nsCID &aClass, nsIFactory **aFactory) return NS_ERROR_FAILURE; // XXX right error? } +extern "C" NS_EXPORT PRBool +NSCanUnload(void) +{ + return gPluginObjectCount == 1 && !gPluginLocked; +} + NS_METHOD SimplePlugin::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult) { @@ -443,13 +538,14 @@ SimplePlugin::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult) if (inst == NULL) return NS_ERROR_OUT_OF_MEMORY; inst->AddRef(); + *aResult = inst; return NS_OK; } NS_METHOD SimplePlugin::LockFactory(PRBool aLock) { - // XXX what to do here? + gPluginLocked = aLock; return NS_OK; } @@ -457,7 +553,7 @@ NS_METHOD SimplePlugin::Initialize(nsISupports* browserInterfaces) { if (browserInterfaces->QueryInterface(kIPluginManagerIID, - (void**)mgr) != NS_OK) { + (void**)&mgr) != NS_OK) { return NS_ERROR_FAILURE; } return NS_OK; @@ -542,10 +638,12 @@ SimplePluginInstance::SimplePluginInstance(void) : fPeer(NULL), fWindow(NULL), fMode(nsPluginMode_Embedded) { NS_INIT_REFCNT(); + gPluginObjectCount++; } SimplePluginInstance::~SimplePluginInstance(void) { + gPluginObjectCount--; PlatformDestroy(); // Perform platform specific cleanup DisplayJavaMessage("Calling SimplePluginInstance::Release.", -1); } @@ -572,6 +670,7 @@ NS_METHOD SimplePluginInstance::Initialize(nsIPluginInstancePeer* peer) { fPeer = peer; + peer->AddRef(); nsresult err = peer->GetMode(&fMode); if (err) return err; PlatformNew(); /* Call Platform-specific initializations */ @@ -656,6 +755,8 @@ SimplePluginInstance::SetWindow(nsPluginWindow* window) return result; } +#ifndef NEW_PLUGIN_STREAM_API + /*+++++++++++++++++++++++++++++++++++++++++++++++++ * NewStream: * Notifies an instance of a new data stream and returns an error value. @@ -678,6 +779,8 @@ SimplePluginInstance::NewStream(nsIPluginStreamPeer* peer, nsIPluginStream* *res return NS_OK; } +#endif // NEW_PLUGIN_STREAM_API + /*+++++++++++++++++++++++++++++++++++++++++++++++++ * NPP_Print: +++++++++++++++++++++++++++++++++++++++++++++++++*/ @@ -754,6 +857,8 @@ SimplePluginInstance::HandleEvent(nsPluginEvent* event, PRBool* handled) return NS_OK; } +#ifndef NEW_PLUGIN_STREAM_API + /*+++++++++++++++++++++++++++++++++++++++++++++++++ * URLNotify: * Notifies the instance of the completion of a URL request. @@ -781,12 +886,76 @@ SimplePluginInstance::URLNotify(const char* url, const char* target, return NS_OK; } +#endif // NEW_PLUGIN_STREAM_API + NS_METHOD SimplePluginInstance::GetValue(nsPluginInstanceVariable variable, void *value) { + return NS_ERROR_FAILURE; +} + +#ifdef NEW_PLUGIN_STREAM_API + +//////////////////////////////////////////////////////////////////////////////// +// SimplePluginStreamListener Methods +//////////////////////////////////////////////////////////////////////////////// + +SimplePluginStreamListener::SimplePluginStreamListener(SimplePluginInstance* inst) + : fInst(inst) +{ + gPluginObjectCount++; + NS_INIT_REFCNT(); +} + +SimplePluginStreamListener::~SimplePluginStreamListener(void) +{ + gPluginObjectCount--; + fInst->DisplayJavaMessage("Calling SimplePluginStream destructor.", -1); +} + +// This macro produces a simple version of QueryInterface, AddRef and Release. +// See the nsISupports.h header file for details. + +NS_IMPL_ISUPPORTS(SimplePluginStreamListener, kIPluginStreamListenerIID); + +NS_METHOD +SimplePluginStreamListener::OnStartBinding(const char* url, const nsPluginStreamInfo* info) +{ + fInst->DisplayJavaMessage("Opening plugin stream.", -1); return NS_OK; } +NS_METHOD +SimplePluginStreamListener::OnDataAvailable(const char* url, nsIPluginInputStream* input, + PRUint32 offset, PRUint32 length) +{ + char* buffer = new char[length]; + if (buffer) { + PRInt32 amountRead = 0; + nsresult rslt = input->Read(buffer, offset, length, &amountRead); + if (rslt == NS_OK) + fInst->DisplayJavaMessage(buffer, amountRead); + delete buffer; + } + return NS_OK; +} + +NS_METHOD +SimplePluginStreamListener::OnFileAvailable(const char* url, const char* fileName) +{ + fInst->DisplayJavaMessage("Calling SimplePluginStreamListener::OnFileAvailable.", -1); + return NS_OK; +} + +NS_METHOD +SimplePluginStreamListener::OnStopBinding(const char* url, nsresult status) +{ + fInst->DisplayJavaMessage("Closing plugin stream.", -1); + return NS_OK; +} + +#else // !NEW_PLUGIN_STREAM_API + //////////////////////////////////////////////////////////////////////////////// // SimplePluginStream Methods //////////////////////////////////////////////////////////////////////////////// @@ -795,11 +964,13 @@ SimplePluginStream::SimplePluginStream(nsIPluginStreamPeer* peer, SimplePluginInstance* inst) : fPeer(peer), fInst(inst) { + gPluginObjectCount++; NS_INIT_REFCNT(); } SimplePluginStream::~SimplePluginStream(void) { + gPluginObjectCount--; fInst->DisplayJavaMessage("Calling SimplePluginStream::Release.", -1); } @@ -875,7 +1046,7 @@ SimplePluginStream::AsFile(const char* fname) return NS_OK; } - +#endif // !NEW_PLUGIN_STREAM_API /******************************************************************************* diff --git a/mozilla/modules/plugin/src/makefile.win b/mozilla/modules/plugin/src/makefile.win index d59836e1adf..83ff08ac706 100644 --- a/mozilla/modules/plugin/src/makefile.win +++ b/mozilla/modules/plugin/src/makefile.win @@ -19,6 +19,8 @@ IGNORE_MANIFEST=1 DEPTH= ..\..\.. +include <$(DEPTH)/config/config.mak> + MODULE = plugimpl EXPORTS = \ @@ -48,6 +50,10 @@ OBJS = .\$(OBJDIR)\npassoc.obj \ .\$(OBJDIR)\npglue.obj \ .\$(OBJDIR)\nsMalloc.obj +!ifdef NEW_PLUGIN_STREAM_API +LCFLAGS = $(LCFLAGS) -DNEW_PLUGIN_STREAM_API +!endif + include <$(DEPTH)/config/rules.mak> install:: $(LIBRARY) diff --git a/mozilla/modules/plugin/src/npglue.cpp b/mozilla/modules/plugin/src/npglue.cpp index 0e20d4a8fca..13739079da0 100644 --- a/mozilla/modules/plugin/src/npglue.cpp +++ b/mozilla/modules/plugin/src/npglue.cpp @@ -62,6 +62,11 @@ int np_debug = 0; static XP_Bool gForcingRedraw = FALSE; #endif /* XP_MAC */ +#define NP_GET_URL_APP(urls) ((NPEmbeddedApp*)((urls)->fe_data)) +#define NP_SET_URL_APP(urls, a) ((urls)->fe_data = (void*)(a)) + +#define NP_GET_PLUGIN_INSTANCE(npp) ((nsIPluginInstance*)((np_data*)((np_instance*)(npp)->ndata)->app->np_data)->sdata) + NPNetscapeFuncs npp_funcs; /* @@ -78,18 +83,18 @@ np_is50StylePlugin(np_handle* handle) static np_mimetype * np_getmimetype(np_handle *handle, const char *mimeStr, XP_Bool wildCard) { - np_mimetype *mimetype; + np_mimetype *mimetype; - for (mimetype = handle->mimetypes; mimetype; mimetype = mimetype->next) - { - if (mimetype->enabled) - { - if ((wildCard && !strcmp(mimetype->type, "*")) || - !strcasecomp(mimetype->type, mimeStr)) - return (mimetype); - } - } - return (NULL); + for (mimetype = handle->mimetypes; mimetype; mimetype = mimetype->next) + { + if (mimetype->enabled) + { + if ((wildCard && !strcmp(mimetype->type, "*")) || + !strcasecomp(mimetype->type, mimeStr)) + return (mimetype); + } + } + return (NULL); } @@ -100,12 +105,12 @@ np_getmimetype(np_handle *handle, const char *mimeStr, XP_Bool wildCard) static NPReason np_statusToReason(int status) { - if (status == MK_DATA_LOADED) - return NPRES_DONE; - else if (status == MK_INTERRUPTED) - return NPRES_USER_BREAK; - else - return NPRES_NETWORK_ERR; + if (status == MK_DATA_LOADED) + return NPRES_DONE; + else if (status == MK_INTERRUPTED) + return NPRES_USER_BREAK; + else + return NPRES_NETWORK_ERR; } @@ -117,23 +122,23 @@ np_statusToReason(int status) static np_urlsnode* np_addURLtoList(np_instance* instance) { - np_urlsnode* node; + np_urlsnode* node; - if (!instance) - return NULL; + if (!instance) + return NULL; - if (!instance->url_list) - instance->url_list = XP_ListNew(); - if (!instance->url_list) - return NULL; + if (!instance->url_list) + instance->url_list = XP_ListNew(); + if (!instance->url_list) + return NULL; - node = XP_NEW_ZAP(np_urlsnode); - if (!node) - return NULL; + node = XP_NEW_ZAP(np_urlsnode); + if (!node) + return NULL; - XP_ListAddObject(instance->url_list, node); + XP_ListAddObject(instance->url_list, node); - return node; + return node; } @@ -148,36 +153,46 @@ np_addURLtoList(np_instance* instance) static void np_processURLNode(np_urlsnode* node, np_instance* instance, int status) { - if (node->cached) - { - /* Unlock the cache file */ - XP_ASSERT(!node->notify); - if (node->urls) - { - NET_ChangeCacheFileLock(node->urls, NP_UNLOCK); + if (node->cached) + { + /* Unlock the cache file */ + XP_ASSERT(!node->notify); + if (node->urls) + { + NET_ChangeCacheFileLock(node->urls, NP_UNLOCK); - NET_FreeURLStruct(node->urls); - node->urls = NULL; + NET_FreeURLStruct(node->urls); + node->urls = NULL; } - return; - } + return; + } - if (node->notify) - { - /* Notify the plug-in */ - XP_ASSERT(!node->cached); + if (node->notify) + { + /* Notify the plug-in */ + XP_ASSERT(!node->cached); if (instance) { TRACEMSG(("npglue.c: CallNPP_URLNotifyProc")); if (np_is50StylePlugin(instance->handle)) { - nsPluginInstancePeer* peerInst = (nsPluginInstancePeer*)instance->npp->pdata; - nsIPluginInstance* pluginInst = peerInst->GetPluginInstance(); +#ifdef NEW_PLUGIN_STREAM_API + + nsPluginInputStream* inStr = (nsPluginInputStream*)node->notifyData; + nsIPluginStreamListener* listener = inStr->GetListener(); + nsresult err = listener->OnStopBinding(node->urls->address, + (nsPluginReason)np_statusToReason(status)); + // XXX ignore error? + +#else // !NEW_PLUGIN_STREAM_API + + nsIPluginInstance* pluginInst = NP_GET_PLUGIN_INSTANCE(instance->npp); if (pluginInst != NULL) { pluginInst->URLNotify(node->urls->address, node->urls->window_target, - (nsPluginReason)np_statusToReason(status), - node->notifyData); - pluginInst->Release(); + (nsPluginReason)np_statusToReason(status), + node->notifyData); } + +#endif // !NEW_PLUGIN_STREAM_API } else if (ISFUNCPTR(instance->handle->f->urlnotify)) { CallNPP_URLNotifyProc(instance->handle->f->urlnotify, @@ -186,15 +201,35 @@ np_processURLNode(np_urlsnode* node, np_instance* instance, int status) np_statusToReason(status), node->notifyData); } - } - } + } + } - /* Break the reference from the URL to the instance */ - if (node->urls) - node->urls->fe_data = NULL; + /* Break the reference from the URL to the instance */ + if (node->urls) { + NP_SET_URL_APP(node->urls, NULL); + } } +static np_urlsnode* +np_getURLfromList(np_instance* instance, URL_Struct* urls) +{ + XP_List* url_list; + np_urlsnode* node; + + if (!instance || !urls || !instance->url_list) + return NULL; + + /* Look for the URL in the list */ + url_list = instance->url_list; + while ((node = (np_urlsnode*)XP_ListNextObject(url_list)) != NULL) + { + if (node->urls == urls) + return node; + } + return NULL; +} + /* * Remove an individual URL from the list of URLs for this instance. */ @@ -213,20 +248,20 @@ np_removeURLfromList(np_instance* instance, URL_Struct* urls, int status) { if (node->urls == urls) { - XP_ASSERT(!node->cached); - np_processURLNode(node, instance, status); + XP_ASSERT(!node->cached); + np_processURLNode(node, instance, status); - XP_ListRemoveObject(instance->url_list, node); - XP_FREE(node); + XP_ListRemoveObject(instance->url_list, node); + XP_FREE(node); - /* If the list is now empty, delete it */ - if (XP_ListCount(instance->url_list) == 0) - { - XP_ListDestroy(instance->url_list); - instance->url_list = NULL; - } + /* If the list is now empty, delete it */ + if (XP_ListCount(instance->url_list) == 0) + { + XP_ListDestroy(instance->url_list); + instance->url_list = NULL; + } - return; + return; } } } @@ -238,29 +273,29 @@ np_removeURLfromList(np_instance* instance, URL_Struct* urls, int status) static void np_removeAllURLsFromList(np_instance* instance) { - XP_List* url_list; + XP_List* url_list; np_urlsnode* node; if (!instance || !instance->url_list) return; - url_list = instance->url_list; - while ((node = (np_urlsnode*)XP_ListNextObject(url_list)) != NULL) - { - /* No notification of URLs now: the instance is going away */ - node->notify = FALSE; - np_processURLNode(node, instance, 0); - } + url_list = instance->url_list; + while ((node = (np_urlsnode*)XP_ListNextObject(url_list)) != NULL) + { + /* No notification of URLs now: the instance is going away */ + node->notify = FALSE; + np_processURLNode(node, instance, 0); + } - /* Remove all elements from the list */ - url_list = instance->url_list; + /* Remove all elements from the list */ + url_list = instance->url_list; while ((node = (np_urlsnode*)XP_ListRemoveTopObject(url_list)) != NULL) XP_FREE(node); - /* The list should now be empty, so delete it */ - XP_ASSERT(XP_ListCount(instance->url_list) == 0); - XP_ListDestroy(instance->url_list); - instance->url_list = NULL; + /* The list should now be empty, so delete it */ + XP_ASSERT(XP_ListCount(instance->url_list) == 0); + XP_ListDestroy(instance->url_list); + instance->url_list = NULL; } @@ -277,7 +312,7 @@ np_get_stream(URL_Struct *urls) { if(urls) { - NPEmbeddedApp *pEmbeddedApp = (NPEmbeddedApp*)urls->fe_data; + NPEmbeddedApp *pEmbeddedApp = NP_GET_URL_APP(urls); if(pEmbeddedApp) { np_data *ndata = (np_data *)pEmbeddedApp->np_data; @@ -286,23 +321,23 @@ np_get_stream(URL_Struct *urls) np_stream *stream; for (stream=ndata->instance->streams; stream; stream=stream->next) { - /* - * Matching algorithm: Either this URL is the inital URL for - * the stream, or it's a URL generated by a subsequent byte- - * range request. We don't bother to keep track of all the - * URLs for byte-range requests, but we can still detect if - * the URL matches this stream: since we know that this URL - * belongs to one of the streams for this instance and that - * there can only be one seekable stream for an instance - * active at a time, then we know if this stream is seekable - * and the URL is a byte-range URL then they must match. - * NOTE: We check both urls->high_range and urls->range_header - * because we could have been called before the range_header - * has been parsed and the high_range set. - */ - if ((stream->initial_urls == urls) || - (stream->seek && (urls->high_range || urls->range_header))) - return stream; + /* + * Matching algorithm: Either this URL is the inital URL for + * the stream, or it's a URL generated by a subsequent byte- + * range request. We don't bother to keep track of all the + * URLs for byte-range requests, but we can still detect if + * the URL matches this stream: since we know that this URL + * belongs to one of the streams for this instance and that + * there can only be one seekable stream for an instance + * active at a time, then we know if this stream is seekable + * and the URL is a byte-range URL then they must match. + * NOTE: We check both urls->high_range and urls->range_header + * because we could have been called before the range_header + * has been parsed and the high_range set. + */ + if ((stream->initial_urls == urls) || + (stream->seek && (urls->high_range || urls->range_header))) + return stream; } } } @@ -323,15 +358,15 @@ np_get_stream(URL_Struct *urls) static np_stream* np_makestreamobjects(np_instance* instance, NET_StreamClass* netstream, URL_Struct* urls) { - np_stream* stream; - NPStream* pstream; + np_stream* stream; + NPStream* pstream; XP_List* url_list; np_urlsnode* node; void* notifyData; - /* check params */ - if (!instance || !netstream || !urls) - return NULL; + /* check params */ + if (!instance || !netstream || !urls) + return NULL; /* make a npglue stream */ stream = XP_NEW_ZAP(np_stream); @@ -347,15 +382,15 @@ np_makestreamobjects(np_instance* instance, NET_StreamClass* netstream, URL_Stru StrAllocCopy(stream->url, urls->address); stream->len = urls->content_length; - /* Look for notification data for this URL */ - notifyData = NULL; + /* Look for notification data for this URL */ + notifyData = NULL; url_list = instance->url_list; while ((node = (np_urlsnode*)XP_ListNextObject(url_list)) != NULL) { if (node->urls == urls && node->notify) { - notifyData = node->notifyData; - break; + notifyData = node->notifyData; + break; } } @@ -370,7 +405,7 @@ np_makestreamobjects(np_instance* instance, NET_StreamClass* netstream, URL_Stru pstream->url = stream->url; pstream->end = urls->content_length; pstream->lastmodified = (uint32) urls->last_modified; - pstream->notifyData = notifyData; + pstream->notifyData = notifyData; /* make a record of it */ stream->pstream = pstream; @@ -379,7 +414,7 @@ np_makestreamobjects(np_instance* instance, NET_StreamClass* netstream, URL_Stru NPTRACE(0,("np: new stream, %s, %s", instance->mimetype->type, urls->address)); - return stream; + return stream; } /* @@ -391,7 +426,7 @@ np_makestreamobjects(np_instance* instance, NET_StreamClass* netstream, URL_Stru static void np_deletestreamobjects(np_stream* stream) { - np_instance* instance = stream->instance; + np_instance* instance = stream->instance; /* remove it from the instance list */ if (stream == instance->streams) @@ -427,7 +462,7 @@ np_deletestreamobjects(np_stream* stream) static void np_dofetch(URL_Struct *urls, int status, MWContext *window_id) { - np_stream *stream = np_get_stream(urls); + np_stream *stream = np_get_stream(urls); if(stream && stream->instance) { FE_GetURL(stream->instance->cx, stream->instance->delayedload); @@ -445,15 +480,15 @@ NPL_WriteReady(NET_StreamClass *stream) if(!(newstream = np_get_stream(urls))) return 0; - if (newstream->asfile == NP_ASFILEONLY) - return NP_MAXREADY; + if (newstream->asfile == NP_ASFILEONLY) + return NP_MAXREADY; - /* if prev_stream is not ready to write, then neither is this one... */ - if (newstream->prev_stream != NULL){ - ret = (newstream->prev_stream->is_write_ready(newstream->prev_stream)); - if (ret == FALSE) - return FALSE; - } + /* if prev_stream is not ready to write, then neither is this one... */ + if (newstream->prev_stream != NULL){ + ret = (newstream->prev_stream->is_write_ready(newstream->prev_stream)); + if (ret == FALSE) + return FALSE; + } XP_ASSERT(newstream->instance); newstream->instance->reentrant = 1; @@ -478,18 +513,18 @@ NPL_WriteReady(NET_StreamClass *stream) ret = NP_MAXREADY; #if defined(XP_WIN) || defined(XP_OS2) - /* Prevent WinFE from going to sleep when plug-in blocks */ - if (ret == 0){ - if(!newstream->instance->calling_netlib_all_the_time){ - newstream->instance->calling_netlib_all_the_time = TRUE; - NET_SetCallNetlibAllTheTime(newstream->instance->cx, "npglue"); - } - else{ + /* Prevent WinFE from going to sleep when plug-in blocks */ + if (ret == 0){ + if(!newstream->instance->calling_netlib_all_the_time){ + newstream->instance->calling_netlib_all_the_time = TRUE; + NET_SetCallNetlibAllTheTime(newstream->instance->cx, "npglue"); + } + else{ - NET_ClearCallNetlibAllTheTime(newstream->instance->cx, "npglue"); - newstream->instance->calling_netlib_all_the_time = FALSE; - } - } + NET_ClearCallNetlibAllTheTime(newstream->instance->cx, "npglue"); + newstream->instance->calling_netlib_all_the_time = FALSE; + } + } #endif if(!newstream->instance->reentrant) { @@ -511,13 +546,13 @@ NPL_Write(NET_StreamClass *stream, const unsigned char *str, int32 len) if(!newstream || !(newstream->handle->userPlugin ? 1 : ISFUNCPTR(newstream->handle->f->write))) return -1; - if (newstream->asfile == NP_ASFILEONLY) - return len; + if (newstream->asfile == NP_ASFILEONLY) + return len; - if (newstream->prev_stream != NULL){ - ret = newstream->prev_stream->put_block(newstream->prev_stream,(const char *)str,len); - /* should put check here for ret == len? if not, then what? */ - } + if (newstream->prev_stream != NULL){ + ret = newstream->prev_stream->put_block(newstream->prev_stream,(const char *)str,len); + /* should put check here for ret == len? if not, then what? */ + } /* if this is the first non seek write after we turned the @@ -541,14 +576,26 @@ NPL_Write(NET_StreamClass *stream, const unsigned char *str, int32 len) urls->position = urls->low_range; } /*TRACEMSG(("npglue.c: CallNPP_WriteProc")); - */ + */ if (newstream->handle->userPlugin) { +#ifdef NEW_PLUGIN_STREAM_API + + nsPluginInputStream* instr = (nsPluginInputStream*)newstream->pstream->pdata; + nsIPluginStreamListener* listener = instr->GetListener(); + instr->SetReadBuffer(len, (const char*)str); + nsresult err = listener->OnDataAvailable((const char*)urls->address, instr, urls->position, len); + PR_ASSERT(err == NS_OK); // XXX this error should go somewhere + +#else // !NEW_PLUGIN_STREAM_API + nsPluginStreamPeer* peerStream = (nsPluginStreamPeer*)newstream->pstream->pdata; nsIPluginStream* userStream = peerStream->GetUserStream(); PRInt32 written; nsresult err = userStream->Write((const char*)str, 0, len, &written); PR_ASSERT(err == NS_OK); // XXX this error should go somewhere PR_ASSERT(written == len); + +#endif // !NEW_PLUGIN_STREAM_API } else if (ISFUNCPTR(newstream->handle->f->write)) { ret = CallNPP_WriteProc(newstream->handle->f->write, newstream->instance->npp, newstream->pstream, @@ -588,11 +635,11 @@ np_make_byterange_string(NPByteRange *ranges) iBytesEqualsLen = strlen(RANGE_EQUALS); - /* the range must begin with bytes= - * a final range string looks like: - * bytes=5-8,12-56 - */ - XP_STRCPY(burl, RANGE_EQUALS); + /* the range must begin with bytes= + * a final range string looks like: + * bytes=5-8,12-56 + */ + XP_STRCPY(burl, RANGE_EQUALS); for(br=ranges; br; br=br->next) { @@ -659,13 +706,13 @@ np_unlock(np_stream *stream) } static void -np_GetURL(URL_Struct *pURL,FO_Present_Types iFormatOut,MWContext *cx, Net_GetUrlExitFunc *pExitFunc, NPBool notify){ - - XP_ASSERT(pURL->owner_data == NULL); - pURL->owner_id = 0x0000BAC0; /* plugin's unique identifier */ - pURL->owner_data = pURL->fe_data; - pURL->fe_data = NULL; - FE_GetURL(cx,pURL); +np_GetURL(URL_Struct *pURL,FO_Present_Types iFormatOut,MWContext *cx, Net_GetUrlExitFunc *pExitFunc, NPBool notify) +{ + XP_ASSERT(pURL->owner_data == NULL); + pURL->owner_id = 0x0000BAC0; /* plugin's unique identifier */ + pURL->owner_data = pURL->fe_data; + pURL->fe_data = NULL; + FE_GetURL(cx,pURL); } @@ -735,7 +782,7 @@ npn_requestread(NPStream *pstream, NPByteRange *rangeList) XP_ASSERT(stream->instance); if(stream->instance) { - urls->fe_data = (void *)stream->instance->app; + NP_SET_URL_APP(urls, stream->instance->app); (void) NET_GetURL(urls, FO_CACHE_AND_BYTERANGE, stream->instance->cx, NPL_URLExit); } } @@ -755,18 +802,23 @@ np_destroystream(np_stream *stream, NPError reason) np_instance *instance = stream->instance; TRACEMSG(("npglue.c: CallNPP_DestroyStreamProc")); if (stream->handle->userPlugin) { +#ifdef NEW_PLUGIN_STREAM_API + nsPluginInputStream* inStr = (nsPluginInputStream*)stream->pstream->pdata; + inStr->Release(); +#else // !NEW_PLUGIN_STREAM_API nsPluginStreamPeer* peerStream = (nsPluginStreamPeer*)stream->pstream->pdata; nsIPluginStream* userStream = peerStream->GetUserStream(); peerStream->SetReason((nsPluginReason)reason); userStream->Close(); peerStream->Release(); +#endif // !NEW_PLUGIN_STREAM_API } else if (ISFUNCPTR(stream->handle->f->destroystream)) { CallNPP_DestroyStreamProc(stream->handle->f->destroystream, instance->npp, stream->pstream, reason); } - /* Delete the np_stream and associated NPStream objects */ - np_deletestreamobjects(stream); + /* Delete the np_stream and associated NPStream objects */ + np_deletestreamobjects(stream); } } @@ -820,9 +872,17 @@ np_streamAsFile(np_stream* stream) /* fname can be NULL if something went wrong */ TRACEMSG(("npglue.c: CallNPP_StreamAsFileProc")); if (stream->handle->userPlugin) { +#ifdef NEW_PLUGIN_STREAM_API + nsPluginInputStream* instr = (nsPluginInputStream*)stream->pstream->pdata; + nsIPluginStreamListener* listener = instr->GetListener(); + nsresult err = listener->OnFileAvailable(stream->url, fname); + PR_ASSERT(err == NS_OK); + // XXX ignore error? +#else // !NEW_PLUGIN_STREAM_API nsPluginStreamPeer* peerStream = (nsPluginStreamPeer*)stream->pstream->pdata; nsIPluginStream* userStream = peerStream->GetUserStream(); userStream->AsFile(fname); +#endif // !NEW_PLUGIN_STREAM_API } else if (ISFUNCPTR(stream->handle->f->asfile)) { CallNPP_StreamAsFileProc(stream->handle->f->asfile, stream->instance->npp, @@ -963,7 +1023,7 @@ NPL_URLExit(URL_Struct *urls, int status, MWContext *cx) (urls->owner_id == 0x0000BAC0)) urls->fe_data = urls->owner_data; - app = (NPEmbeddedApp*) urls->fe_data; + app = NP_GET_URL_APP(urls); pstream = np_get_stream(urls); if (pstream) @@ -1004,8 +1064,6 @@ NPL_URLExit(URL_Struct *urls, int status, MWContext *cx) } } - - static URL_Struct* np_makeurlstruct(np_instance* instance, const char* relativeURL, @@ -1099,7 +1157,7 @@ np_geturlinternal(NPP npp, const char* relativeURL, const char* target, np_urlsnode* node = NULL; NPError err = NPERR_NO_ERROR; #ifdef XP_WIN32 - void* pPrevState; + void* pPrevState; #endif if (!npp || !relativeURL) /* OK for window to be NULL */ @@ -1115,29 +1173,29 @@ np_geturlinternal(NPP npp, const char* relativeURL, const char* target, { err = NPERR_OUT_OF_MEMORY_ERROR; goto error; - } + } - /* - * Add this URL to the list of URLs for this instance, - * and remember if the instance would like notification. - */ - node = np_addURLtoList(instance); - if (node) - { - node->urls = urls; - if (notify) - { - node->notify = TRUE; - node->notifyData = notifyData; - } - } - else - { + /* + * Add this URL to the list of URLs for this instance, + * and remember if the instance would like notification. + */ + node = np_addURLtoList(instance); + if (node) + { + node->urls = urls; + if (notify) + { + node->notify = TRUE; + node->notifyData = notifyData; + } + } + else + { err = NPERR_OUT_OF_MEMORY_ERROR; goto error; - } + } - urls->fe_data = (void*) instance->app; + NP_SET_URL_APP(urls, instance->app); /* * If the plug-in passed NULL for the target, load the URL with a special stream @@ -1146,35 +1204,35 @@ np_geturlinternal(NPP npp, const char* relativeURL, const char* target, * the plug-in in the process, if the target context is the plug-in's context). */ if (!target) - { + { #ifdef XP_WIN32 - pPrevState = WFE_BeginSetModuleState(); + pPrevState = WFE_BeginSetModuleState(); #endif (void) NET_GetURL(urls, FO_CACHE_AND_PLUGIN, instance->cx, NPL_URLExit); #ifdef XP_WIN32 - WFE_EndSetModuleState(pPrevState); + WFE_EndSetModuleState(pPrevState); #endif } - else + else { cx = np_makecontext(instance, target); - if (!cx) - { - err = NPERR_OUT_OF_MEMORY_ERROR; - goto error; - } + if (!cx) + { + err = NPERR_OUT_OF_MEMORY_ERROR; + goto error; + } - /* - * Prevent loading "about:" URLs into the plug-in's context: NET_GetURL - * for these URLs will complete immediately, and the new layout thus - * generated will blow away the plug-in and possibly unload its code, - * causing us to crash when we return from this function. - */ - if (cx == instance->cx && NET_URL_Type(urls->address) == ABOUT_TYPE_URL) - { - err = NPERR_INVALID_URL; - goto error; - } + /* + * Prevent loading "about:" URLs into the plug-in's context: NET_GetURL + * for these URLs will complete immediately, and the new layout thus + * generated will blow away the plug-in and possibly unload its code, + * causing us to crash when we return from this function. + */ + if (cx == instance->cx && NET_URL_Type(urls->address) == ABOUT_TYPE_URL) + { + err = NPERR_INVALID_URL; + goto error; + } if (forceJSEnabled && !cx->forceJSEnabled) { LM_ForceJSEnabled(cx); @@ -1182,144 +1240,144 @@ np_geturlinternal(NPP npp, const char* relativeURL, const char* target, } #ifdef XP_MAC - /* - * One day the code below should call FE_GetURL, and this call will be - * unnecessary since the FE will do the right thing. Right now (3.0b6) - * starting to use FE_GetURL is not an option so we'll just create - * (yet another) FE callback for our purposes: we need to ask the FE - * to reset any timer it might have (for META REFRESH) so that the - * timer doesn't go off after leaving the original page via plug-in - * request. - */ - FE_ResetRefreshURLTimer(cx); + /* + * One day the code below should call FE_GetURL, and this call will be + * unnecessary since the FE will do the right thing. Right now (3.0b6) + * starting to use FE_GetURL is not an option so we'll just create + * (yet another) FE callback for our purposes: we need to ask the FE + * to reset any timer it might have (for META REFRESH) so that the + * timer doesn't go off after leaving the original page via plug-in + * request. + */ + FE_ResetRefreshURLTimer(cx); #endif /* reentrancy matters for this case because it will cause the current stream to be unloaded which netlib can't deal with */ if (instance->reentrant && (cx == instance->cx)) { - XP_ASSERT(instance->delayedload == NULL); /* We lose queued requests if this is non-NULL! */ + XP_ASSERT(instance->delayedload == NULL); /* We lose queued requests if this is non-NULL! */ if (instance->delayedload) NET_FreeURLStruct(instance->delayedload); instance->delayedload = urls; instance->reentrant = 0; } else - { - if ((cx == instance->cx) || - (XP_IsChildContext(cx,instance->cx)) ) - { - /* re-target: use this until figure out why thread violation. - this method obviates question of self-trouncing... */ - if ((instance->cx->type == MWContextBrowser || - instance->cx->type == MWContextPane) - && ((XP_STRNCMP(urls->address, "mailbox:", 8)==0) - || (XP_STRNCMP(urls->address, "mailto:" , 7)==0) - || (XP_STRNCMP(urls->address, "news:" , 5)==0))) - cx = np_makecontext(instance,"_self"); - else{ - /* Since the previous stuff generally worked for this, keep using it */ - urls->fe_data = NULL; + { + if ((cx == instance->cx) || + (XP_IsChildContext(cx,instance->cx)) ) + { + /* re-target: use this until figure out why thread violation. + this method obviates question of self-trouncing... */ + if ((instance->cx->type == MWContextBrowser || + instance->cx->type == MWContextPane) + && ((XP_STRNCMP(urls->address, "mailbox:", 8)==0) + || (XP_STRNCMP(urls->address, "mailto:" , 7)==0) + || (XP_STRNCMP(urls->address, "news:" , 5)==0))) + cx = np_makecontext(instance,"_self"); + else{ + /* Since the previous stuff generally worked for this, keep using it */ + NP_SET_URL_APP(urls, NULL); #ifdef XP_WIN32 - pPrevState = WFE_BeginSetModuleState(); + pPrevState = WFE_BeginSetModuleState(); #endif - /* clear the exit routine, since the recipient may not be present! */ - (void) NET_GetURL(urls, FO_CACHE_AND_PRESENT, cx, NPL_URLExit); + /* clear the exit routine, since the recipient may not be present! */ + (void) NET_GetURL(urls, FO_CACHE_AND_PRESENT, cx, NPL_URLExit); #ifdef XP_WIN32 - WFE_EndSetModuleState(pPrevState); + WFE_EndSetModuleState(pPrevState); #endif - return NPERR_NO_ERROR; - } - /* Eventually, we should shut down the current instance and - startup a new one */ - } + return NPERR_NO_ERROR; + } + /* Eventually, we should shut down the current instance and + startup a new one */ + } #ifdef XP_WIN32 - pPrevState = WFE_BeginSetModuleState(); + pPrevState = WFE_BeginSetModuleState(); #endif - (void) np_GetURL(urls, FO_CACHE_AND_PRESENT, cx, NPL_URLExit,notify); + (void) np_GetURL(urls, FO_CACHE_AND_PRESENT, cx, NPL_URLExit,notify); #ifdef XP_WIN32 - WFE_EndSetModuleState(pPrevState); + WFE_EndSetModuleState(pPrevState); #endif - } + } } return NPERR_NO_ERROR; -error: - if (node) - { - node->notify = FALSE; /* Remove node without notification */ - np_removeURLfromList(instance, urls, 0); - } - if (urls) - NET_FreeURLStruct(urls); - return err; + error: + if (node) + { + node->notify = FALSE; /* Remove node without notification */ + np_removeURLfromList(instance, urls, 0); + } + if (urls) + NET_FreeURLStruct(urls); + return err; } static NPError np_parsepostbuffer(URL_Struct* urls, const char* buf, uint32 len) { - /* - * Search the buffer passed in for a /n/n. If we find it, break the - * buffer in half: the first part is the header, the rest is the body. + /* + * Search the buffer passed in for a /n/n. If we find it, break the + * buffer in half: the first part is the header, the rest is the body. */ - uint32 index; - for (index = 0; index < len; index++) - { - if (buf[index] == '\n' && ++index < len && buf[index] == '\n') - break; - } + uint32 index; + for (index = 0; index < len; index++) + { + if (buf[index] == '\n' && ++index < len && buf[index] == '\n') + break; + } - /* + /* * If we found '\n\n' somewhere in the middle of the string then we * have headers, so we need to allocate a new string for the headers, * copy the header data from the plug-in's buffer into it, and put * it in the appropriate place of the URL struct. */ - if (index > 1 && index < len) - { - uint32 headerLength = index; - char* headers = (char*) XP_ALLOC(headerLength + 1); - if (!headers) - return NPERR_OUT_OF_MEMORY_ERROR; - XP_MEMCPY(headers, buf, headerLength); - headers[headerLength] = 0; - urls->post_headers = headers; - } + if (index > 1 && index < len) + { + uint32 headerLength = index; + char* headers = (char*) XP_ALLOC(headerLength + 1); + if (!headers) + return NPERR_OUT_OF_MEMORY_ERROR; + XP_MEMCPY(headers, buf, headerLength); + headers[headerLength] = 0; + urls->post_headers = headers; + } - /* + /* * If we didn't find '\n\n', then the body starts at the beginning; * otherwise, it starts right after the second '\n'. Make sure the * body is non-emtpy, allocate a new string for it, copy the data * from the plug-in's buffer, and put it in the URL struct. */ - if (index >= len) - index = 0; /* No '\n\n', start body from beginning */ - else - index++; /* Found '\n\n', start body after it */ + if (index >= len) + index = 0; /* No '\n\n', start body from beginning */ + else + index++; /* Found '\n\n', start body after it */ - if (len - index > 0) /* Non-empty body? */ - { - uint32 bodyLength = len - index + 1; - char* body = (char*) XP_ALLOC(bodyLength); - if (!body) - return NPERR_OUT_OF_MEMORY_ERROR; - XP_MEMCPY(body, &(buf[index]), bodyLength); - urls->post_data = body; - urls->post_data_size = bodyLength; - urls->post_data_is_file = FALSE; - } - else - { - /* Uh-oh, no data to post */ - return NPERR_NO_DATA; - } + if (len - index > 0) /* Non-empty body? */ + { + uint32 bodyLength = len - index + 1; + char* body = (char*) XP_ALLOC(bodyLength); + if (!body) + return NPERR_OUT_OF_MEMORY_ERROR; + XP_MEMCPY(body, &(buf[index]), bodyLength); + urls->post_data = body; + urls->post_data_size = bodyLength; + urls->post_data_is_file = FALSE; + } + else + { + /* Uh-oh, no data to post */ + return NPERR_NO_DATA; + } - return NPERR_NO_ERROR; + return NPERR_NO_ERROR; } @@ -1335,7 +1393,7 @@ np_posturlinternal(NPP npp, const char* relativeURL, const char *target, np_urlsnode* node = NULL; NPError err = NPERR_NO_ERROR; #ifdef XP_WIN32 - void* pPrevState; + void* pPrevState; #endif /* Validate paramters */ @@ -1352,203 +1410,203 @@ np_posturlinternal(NPP npp, const char* relativeURL, const char *target, return NPERR_INVALID_URL; - /* - * Add this URL to the list of URLs for this instance, - * and remember if the instance would like notification. - */ - node = np_addURLtoList(instance); - if (node) - { - node->urls = urls; - if (notify) - { - node->notify = TRUE; - node->notifyData = notifyData; - } - } - else - { - err = NPERR_OUT_OF_MEMORY_ERROR; - goto error; - } + /* + * Add this URL to the list of URLs for this instance, + * and remember if the instance would like notification. + */ + node = np_addURLtoList(instance); + if (node) + { + node->urls = urls; + if (notify) + { + node->notify = TRUE; + node->notifyData = notifyData; + } + } + else + { + err = NPERR_OUT_OF_MEMORY_ERROR; + goto error; + } - /* - * FTP protocol requires that the data be in a file. - * If we really wanted to, we could write code to dump the buffer to - * a temporary file, give the temp file to netlib, and delete it when - * the exit routine fires. - */ - ftp = (strncasecomp(urls->address, "ftp:", 4) == 0); - if (ftp && !file) - { - err = NPERR_INVALID_URL; - goto error; - } + /* + * FTP protocol requires that the data be in a file. + * If we really wanted to, we could write code to dump the buffer to + * a temporary file, give the temp file to netlib, and delete it when + * the exit routine fires. + */ + ftp = (strncasecomp(urls->address, "ftp:", 4) == 0); + if (ftp && !file) + { + err = NPERR_INVALID_URL; + goto error; + } - if (file) - { - XP_StatStruct stat; + if (file) + { + XP_StatStruct stat; - /* If the plug-in passed a file URL, strip the 'file://' */ - if (!strncasecomp(buf, "file://", 7)) - filename = XP_STRDUP((char*) buf + 7); - else - filename = XP_STRDUP((char*) buf); + /* If the plug-in passed a file URL, strip the 'file://' */ + if (!strncasecomp(buf, "file://", 7)) + filename = XP_STRDUP((char*) buf + 7); + else + filename = XP_STRDUP((char*) buf); - if (!filename) - { - err = NPERR_OUT_OF_MEMORY_ERROR; - goto error; - } + if (!filename) + { + err = NPERR_OUT_OF_MEMORY_ERROR; + goto error; + } - /* If the file doesn't exist, return an error NOW before netlib get it */ - if (XP_Stat(filename, &stat, xpURL)) - { - err = NPERR_FILE_NOT_FOUND; - goto error; - } - } + /* If the file doesn't exist, return an error NOW before netlib get it */ + if (XP_Stat(filename, &stat, xpURL)) + { + err = NPERR_FILE_NOT_FOUND; + goto error; + } + } - /* - * NET_GetURL handles FTP posts differently: the post_data fields are - * ignored; instead, files_to_post contains an array of the files. - */ - if (ftp) - { - XP_ASSERT(filename); - urls->files_to_post = (char**) XP_ALLOC(sizeof(char*) + sizeof(char*)); - if (!(urls->files_to_post)) - { - err = NPERR_OUT_OF_MEMORY_ERROR; - goto error; - } - urls->files_to_post[0] = filename; - urls->files_to_post[1] = NULL; - urls->post_data = NULL; - urls->post_data_size = 0; - urls->post_data_is_file = FALSE; - } - else if (file) - { - XP_ASSERT(filename); - urls->post_data = filename; - urls->post_data_size = XP_STRLEN(filename); - urls->post_data_is_file = TRUE; - } - else - { - /* - * There are two different sets of buffer-parsing code. - * The new code is contained within np_parsepostbuffer, - * and is used when the plug-in calls NPN_PostURLNotify. - * The old code, below, is preserved for compatibility - * for when the plug-in calls NPN_PostURL. - */ - if (notify) - { - NPError err = np_parsepostbuffer(urls, buf, len); - if (err != NPERR_NO_ERROR) - goto error; - } - else - { - urls->post_data = (char*)XP_ALLOC(len); - if (!urls->post_data) - { - err = NPERR_OUT_OF_MEMORY_ERROR; - goto error; - } - XP_MEMCPY(urls->post_data, buf, len); - urls->post_data_size = len; - urls->post_data_is_file = FALSE; - } - } + /* + * NET_GetURL handles FTP posts differently: the post_data fields are + * ignored; instead, files_to_post contains an array of the files. + */ + if (ftp) + { + XP_ASSERT(filename); + urls->files_to_post = (char**) XP_ALLOC(sizeof(char*) + sizeof(char*)); + if (!(urls->files_to_post)) + { + err = NPERR_OUT_OF_MEMORY_ERROR; + goto error; + } + urls->files_to_post[0] = filename; + urls->files_to_post[1] = NULL; + urls->post_data = NULL; + urls->post_data_size = 0; + urls->post_data_is_file = FALSE; + } + else if (file) + { + XP_ASSERT(filename); + urls->post_data = filename; + urls->post_data_size = XP_STRLEN(filename); + urls->post_data_is_file = TRUE; + } + else + { + /* + * There are two different sets of buffer-parsing code. + * The new code is contained within np_parsepostbuffer, + * and is used when the plug-in calls NPN_PostURLNotify. + * The old code, below, is preserved for compatibility + * for when the plug-in calls NPN_PostURL. + */ + if (notify) + { + NPError err = np_parsepostbuffer(urls, buf, len); + if (err != NPERR_NO_ERROR) + goto error; + } + else + { + urls->post_data = (char*)XP_ALLOC(len); + if (!urls->post_data) + { + err = NPERR_OUT_OF_MEMORY_ERROR; + goto error; + } + XP_MEMCPY(urls->post_data, buf, len); + urls->post_data_size = len; + urls->post_data_is_file = FALSE; + } + } urls->method = URL_POST_METHOD; if (!target) { - urls->fe_data = (void*) instance->app; + NP_SET_URL_APP(urls, instance->app); #ifdef XP_WIN32 - pPrevState = WFE_BeginSetModuleState(); + pPrevState = WFE_BeginSetModuleState(); #endif (void) NET_GetURL(urls, FO_CACHE_AND_PLUGIN, instance->cx, NPL_URLExit); #ifdef XP_WIN32 - WFE_EndSetModuleState(pPrevState); + WFE_EndSetModuleState(pPrevState); #endif } else { MWContext* cx = np_makecontext(instance, target); - if (!cx) - { - err = NPERR_OUT_OF_MEMORY_ERROR; - goto error; - } - urls->fe_data = (void*) instance->app; + if (!cx) + { + err = NPERR_OUT_OF_MEMORY_ERROR; + goto error; + } + NP_SET_URL_APP(urls, instance->app); if (forceJSEnabled && !cx->forceJSEnabled) { LM_ForceJSEnabled(cx); urls->pre_exit_fn = np_redisable_js; } - /* - * NOTE: The following (compound) if block was added to avoid the crash - * encountered when np_GetURL is used when the target resolves to replacing - * the context in which the plugin lives, thereby shutting down the context. - * The problem here was that np_GetURL was copying the fe_data pointer - * into owner_data, and that fe_data was being (correctly) deleted and nulled - * somewhere, but not so the owner_data. Other possible solutions to this - * problem would be to null out the owner_data in the appropriate place, - * or perhaps to call np_GetURL w/ a null exit routine. - */ - if ((cx == instance->cx) || - (XP_IsChildContext(cx,instance->cx)) ) { - /* use NET_GetURL here to avoid crashing... */ + /* + * NOTE: The following (compound) if block was added to avoid the crash + * encountered when np_GetURL is used when the target resolves to replacing + * the context in which the plugin lives, thereby shutting down the context. + * The problem here was that np_GetURL was copying the fe_data pointer + * into owner_data, and that fe_data was being (correctly) deleted and nulled + * somewhere, but not so the owner_data. Other possible solutions to this + * problem would be to null out the owner_data in the appropriate place, + * or perhaps to call np_GetURL w/ a null exit routine. + */ + if ((cx == instance->cx) || + (XP_IsChildContext(cx,instance->cx)) ) { + /* use NET_GetURL here to avoid crashing... */ #ifdef XP_WIN32 - pPrevState = WFE_BeginSetModuleState(); + pPrevState = WFE_BeginSetModuleState(); #endif - (void) NET_GetURL(urls, FO_CACHE_AND_PRESENT, cx, NPL_URLExit); + (void) NET_GetURL(urls, FO_CACHE_AND_PRESENT, cx, NPL_URLExit); #ifdef XP_WIN32 - WFE_EndSetModuleState(pPrevState); + WFE_EndSetModuleState(pPrevState); #endif - return NPERR_NO_ERROR; - } + return NPERR_NO_ERROR; + } #ifdef XP_MAC - /* - * One day the code below should call FE_GetURL, and this call will be - * unnecessary since the FE will do the right thing. Right now (3.0b6) - * starting to use FE_GetURL is not an option so we'll just create - * (yet another) FE callback for our purposes: we need to ask the FE - * to reset any timer it might have (for META REFRESH) so that the - * timer doesn't go off after leaving the original page via plug-in - * request. - */ - FE_ResetRefreshURLTimer(cx); + /* + * One day the code below should call FE_GetURL, and this call will be + * unnecessary since the FE will do the right thing. Right now (3.0b6) + * starting to use FE_GetURL is not an option so we'll just create + * (yet another) FE callback for our purposes: we need to ask the FE + * to reset any timer it might have (for META REFRESH) so that the + * timer doesn't go off after leaving the original page via plug-in + * request. + */ + FE_ResetRefreshURLTimer(cx); #endif #ifdef XP_WIN32 - pPrevState = WFE_BeginSetModuleState(); + pPrevState = WFE_BeginSetModuleState(); #endif - (void) np_GetURL(urls, FO_CACHE_AND_PRESENT, cx, NPL_URLExit,notify); + (void) np_GetURL(urls, FO_CACHE_AND_PRESENT, cx, NPL_URLExit,notify); #ifdef XP_WIN32 - WFE_EndSetModuleState(pPrevState); + WFE_EndSetModuleState(pPrevState); #endif - } + } return NPERR_NO_ERROR; -error: - if (node) - { - node->notify = FALSE; /* Remove node without notification */ - np_removeURLfromList(instance, urls, 0); - } - if (urls) - NET_FreeURLStruct(urls); - return err; + error: + if (node) + { + node->notify = FALSE; /* Remove node without notification */ + np_removeURLfromList(instance, urls, 0); + } + if (urls) + NET_FreeURLStruct(urls); + return err; } @@ -1556,51 +1614,51 @@ error: NPError NP_EXPORT npn_geturlnotify(NPP npp, const char* relativeURL, const char* target, void* notifyData) { - return np_geturlinternal(npp, relativeURL, target, NULL, NULL, PR_FALSE, TRUE, notifyData); + return np_geturlinternal(npp, relativeURL, target, NULL, NULL, PR_FALSE, TRUE, notifyData); } NPError NP_EXPORT npn_getvalue(NPP npp, NPNVariable variable, void *r_value) { np_instance* instance; - NPError ret = NPERR_NO_ERROR; + NPError ret = NPERR_NO_ERROR; - if (r_value == NULL) - return NPERR_INVALID_PARAM; + if (r_value == NULL) + return NPERR_INVALID_PARAM; - /* Some of these variabled may be handled by backend. The rest is FE. - * So Handle all the backend variables and pass the rest over to FE. - */ + /* Some of these variabled may be handled by backend. The rest is FE. + * So Handle all the backend variables and pass the rest over to FE. + */ - switch(variable) { - case NPNVjavascriptEnabledBool : - ret = PREF_GetBoolPref("javascript.enabled", (XP_Bool*)r_value); - break; - case NPNVasdEnabledBool : - ret = PREF_GetBoolPref("autoupdate.enabled", (XP_Bool*)r_value); - break; + switch(variable) { + case NPNVjavascriptEnabledBool : + ret = PREF_GetBoolPref("javascript.enabled", (XP_Bool*)r_value); + break; + case NPNVasdEnabledBool : + ret = PREF_GetBoolPref("autoupdate.enabled", (XP_Bool*)r_value); + break; #ifdef MOZ_OFFLINE - case NPNVisOfflineBool :{ - XP_Bool *bptr = (XP_Bool *)r_value; - *bptr = NET_IsOffline(); - ret = NPERR_NO_ERROR; - break; } + case NPNVisOfflineBool :{ + XP_Bool *bptr = (XP_Bool *)r_value; + *bptr = NET_IsOffline(); + ret = NPERR_NO_ERROR; + break; } #endif /* MOZ_OFFLINE */ - default: - instance = NULL; - if (npp != NULL) { - instance = (np_instance*) npp->ndata; - } + default: + instance = NULL; + if (npp != NULL) { + instance = (np_instance*) npp->ndata; + } #ifdef XP_UNIX - ret = FE_PluginGetValue(instance?instance->handle->pdesc:NULL, - variable, r_value); + ret = FE_PluginGetValue(instance?instance->handle->pdesc:NULL, + variable, r_value); #else - ret = FE_PluginGetValue(instance->cx, instance->app, variable, - r_value); + ret = FE_PluginGetValue(instance->cx, instance->app, variable, + r_value); #endif /* XP_UNIX */ - } + } - return(ret); + return(ret); } NPError @@ -1668,7 +1726,7 @@ NPError NP_EXPORT npn_setvalue(NPP npp, NPPVariable variable, void *r_value) { np_instance* instance = NULL; - NPError ret = NPERR_NO_ERROR; + NPError ret = NPERR_NO_ERROR; if (npp != NULL) { instance = (np_instance*) npp->ndata; @@ -1705,21 +1763,21 @@ npn_setvalue(NPP npp, NPPVariable variable, void *r_value) NPError NP_EXPORT npn_geturl(NPP npp, const char* relativeURL, const char* target) { - return np_geturlinternal(npp, relativeURL, target, NULL, NULL, PR_FALSE, FALSE, NULL); + return np_geturlinternal(npp, relativeURL, target, NULL, NULL, PR_FALSE, FALSE, NULL); } NPError NP_EXPORT npn_posturlnotify(NPP npp, const char* relativeURL, const char *target, uint32 len, const char *buf, NPBool file, void* notifyData) { - return np_posturlinternal(npp, relativeURL, target, NULL, NULL, PR_FALSE, len, buf, file, TRUE, notifyData); + return np_posturlinternal(npp, relativeURL, target, NULL, NULL, PR_FALSE, len, buf, file, TRUE, notifyData); } NPError NP_EXPORT npn_posturl(NPP npp, const char* relativeURL, const char *target, uint32 len, const char *buf, NPBool file) { - return np_posturlinternal(npp, relativeURL, target, NULL, NULL, PR_FALSE, len, buf, file, FALSE, NULL); + return np_posturlinternal(npp, relativeURL, target, NULL, NULL, PR_FALSE, len, buf, file, FALSE, NULL); } @@ -1728,11 +1786,11 @@ NPError NP_EXPORT npn_newstream(NPP npp, NPMIMEType type, const char* window, NPStream** pstream) { np_instance* instance; - np_stream* stream; + np_stream* stream; NET_StreamClass* netstream; URL_Struct* urls; MWContext* cx; - *pstream = NULL; + *pstream = NULL; if (!npp || !type) return NPERR_INVALID_PARAM; @@ -1740,22 +1798,22 @@ npn_newstream(NPP npp, NPMIMEType type, const char* window, NPStream** pstream) if (!instance) return NPERR_INVALID_PARAM; - /* Convert the window name to a context */ - cx = np_makecontext(instance, window); + /* Convert the window name to a context */ + cx = np_makecontext(instance, window); if (!cx) return NPERR_OUT_OF_MEMORY_ERROR; - /* - * Make a bogus URL struct. The URL doesn't point to - * anything, but we need it to build the stream. - */ + /* + * Make a bogus URL struct. The URL doesn't point to + * anything, but we need it to build the stream. + */ urls = NET_CreateURLStruct("", NET_DONT_RELOAD); if (!urls) return NPERR_OUT_OF_MEMORY_ERROR; StrAllocCopy(urls->content_type, type); - /* Make a netlib stream */ + /* Make a netlib stream */ netstream = NET_StreamBuilder(FO_PRESENT, urls, cx); if (!netstream) { @@ -1772,7 +1830,7 @@ npn_newstream(NPP npp, NPMIMEType type, const char* window, NPStream** pstream) return NPERR_OUT_OF_MEMORY_ERROR; } - *pstream = stream->pstream; + *pstream = stream->pstream; return NPERR_NO_ERROR; } @@ -1831,32 +1889,32 @@ npn_destroystream(NPP npp, NPStream *pstream, NPError reason) * stream around because stream->dontclose was TRUE), * just inform the plug-in and delete our objects. */ - stream->dontclose = FALSE; /* Make sure we really delete */ + stream->dontclose = FALSE; /* Make sure we really delete */ if (urls) { - if (NET_InterruptStream(urls) < 0) - { - /* Netlib doesn't know about this stream; we must have made it */ - /*MWContext* cx = netstream->window_id;*/ - switch (reason) - { - case NPRES_DONE: - (*netstream->complete)(netstream); - break; - case NPRES_USER_BREAK: - (*netstream->abort)(netstream, MK_INTERRUPTED); - break; - case NPRES_NETWORK_ERR: - (*netstream->abort)(netstream, MK_BAD_CONNECT); - break; - default: /* Unknown reason code */ - (*netstream->abort)(netstream, -1); - break; - } - np_destroystream(stream, reason); - XP_FREE(netstream); - } - } + if (NET_InterruptStream(urls) < 0) + { + /* Netlib doesn't know about this stream; we must have made it */ + /*MWContext* cx = netstream->window_id;*/ + switch (reason) + { + case NPRES_DONE: + (*netstream->complete)(netstream); + break; + case NPRES_USER_BREAK: + (*netstream->abort)(netstream, MK_INTERRUPTED); + break; + case NPRES_NETWORK_ERR: + (*netstream->abort)(netstream, MK_BAD_CONNECT); + break; + default: /* Unknown reason code */ + (*netstream->abort)(netstream, -1); + break; + } + np_destroystream(stream, reason); + XP_FREE(netstream); + } + } else np_destroystream(stream, reason); @@ -1878,10 +1936,10 @@ npn_status(NPP npp, const char *message) np_instance *instance = (np_instance *)npp->ndata; if(instance && instance->cx) #ifdef XP_MAC - /* Special entry point so MacFE can save/restore port state */ - FE_PluginProgress(instance->cx, message); + /* Special entry point so MacFE can save/restore port state */ + FE_PluginProgress(instance->cx, message); #else - FE_Progress(instance->cx, message); + FE_Progress(instance->cx, message); #endif } } @@ -1935,7 +1993,7 @@ npn_memflush(uint32 size) return size; else #endif - return 0; + return 0; } @@ -1954,24 +2012,24 @@ np_switchHandlers(np_instance* instance, np_mimetype* newMimeType, char* requestedType) { - NPEmbeddedApp* app = instance->app; - MWContext* cx = instance->cx; + NPEmbeddedApp* app = instance->app; + MWContext* cx = instance->cx; np_data* ndata = (np_data*) app->np_data; - if (app == NULL || cx == NULL || ndata == NULL) - return NPERR_INVALID_PARAM; + if (app == NULL || cx == NULL || ndata == NULL) + return NPERR_INVALID_PARAM; - /* - * If it's a full-page plug-in, just reload the document. - * We have to reload the data anyway to send it to the - * new instance, and since the instance is the only thing - * on the page it's easier to just reload the whole thing. - * NOTE: This case shouldn't ever happen, since you can't - * have full-page Default plug-ins currently. - */ - XP_ASSERT(app->pagePluginType != NP_FullPage); - if (app->pagePluginType == NP_FullPage) - { + /* + * If it's a full-page plug-in, just reload the document. + * We have to reload the data anyway to send it to the + * new instance, and since the instance is the only thing + * on the page it's easier to just reload the whole thing. + * NOTE: This case shouldn't ever happen, since you can't + * have full-page Default plug-ins currently. + */ + XP_ASSERT(app->pagePluginType != NP_FullPage); + if (app->pagePluginType == NP_FullPage) + { History_entry* history = SHIST_GetCurrent(&cx->hist); URL_Struct* urls = SHIST_CreateURLStructFromHistoryEntry(cx, history); if (urls != NULL) @@ -1981,42 +2039,42 @@ np_switchHandlers(np_instance* instance, return NPERR_NO_ERROR; } else - return NPERR_GENERIC_ERROR; - } + return NPERR_GENERIC_ERROR; + } - /* Nuke the old instance */ - np_delete_instance(instance); - if (ndata != NULL && ndata->instance == instance) - ndata->instance = NULL; + /* Nuke the old instance */ + np_delete_instance(instance); + if (ndata != NULL && ndata->instance == instance) + ndata->instance = NULL; - /* Make a new instance */ - ndata->instance = np_newinstance(newHandle, cx, app, newMimeType, requestedType); - NPL_EmbedSize(app); + /* Make a new instance */ + ndata->instance = np_newinstance(newHandle, cx, app, newMimeType, requestedType); + NPL_EmbedSize(app); - if (ndata->instance == NULL) + if (ndata->instance == NULL) return NPERR_GENERIC_ERROR; /* Get the data stream for the new instance, if necessary */ if (ndata->lo_struct->embed_src != NULL) { - char* address; + char* address; URL_Struct* urls; - PA_LOCK(address, char*, ndata->lo_struct->embed_src); - XP_ASSERT(address); + PA_LOCK(address, char*, ndata->lo_struct->embed_src); + XP_ASSERT(address); urls = NET_CreateURLStruct(address, NET_DONT_RELOAD); - PA_UNLOCK(ndata->lo_struct->embed_src); + PA_UNLOCK(ndata->lo_struct->embed_src); if (urls != NULL) { - urls->fe_data = (void*) app; - (void) NET_GetURL(urls, FO_CACHE_AND_EMBED, cx, NPL_EmbedURLExit); - return NPERR_NO_ERROR; - } + NP_SET_URL_APP(urls, app); + (void) NET_GetURL(urls, FO_CACHE_AND_EMBED, cx, NPL_EmbedURLExit); + return NPERR_NO_ERROR; + } else - return NPERR_GENERIC_ERROR; + return NPERR_GENERIC_ERROR; } return NPERR_NO_ERROR; @@ -2037,18 +2095,18 @@ np_switchHandlers(np_instance* instance, void NP_EXPORT npn_reloadplugins(NPBool reloadPages) { - np_handle* oldHead = NULL; + np_handle* oldHead = NULL; - /* - * We won't unregister old plug-ins, we just register new ones. - * The new plug-ins will go on the front of the list, so to see - * if we got any new ones we just need to save a pointer to the - * current front of the list. - */ - if (reloadPages) - oldHead = np_plist; + /* + * We won't unregister old plug-ins, we just register new ones. + * The new plug-ins will go on the front of the list, so to see + * if we got any new ones we just need to save a pointer to the + * current front of the list. + */ + if (reloadPages) + oldHead = np_plist; - /* Ask the FE to load new plug-ins */ + /* Ask the FE to load new plug-ins */ FE_RegisterPlugins(); /* @@ -2064,69 +2122,69 @@ npn_reloadplugins(NPBool reloadPages) /* First look for the default plug-in */ while (defaultPlugin != NULL) { - if (defaultPlugin->mimetypes != NULL && - defaultPlugin->mimetypes->type && - XP_STRCMP(defaultPlugin->mimetypes->type, "*") == 0) - { - break; - } - defaultPlugin = defaultPlugin->next; + if (defaultPlugin->mimetypes != NULL && + defaultPlugin->mimetypes->type && + XP_STRCMP(defaultPlugin->mimetypes->type, "*") == 0) + { + break; + } + defaultPlugin = defaultPlugin->next; } if (defaultPlugin == NULL) - return; + return; /* Found the default plug-in; now check its instances */ instance = defaultPlugin->instances; while (instance != NULL) { - NPBool switchedHandler = FALSE; - char* type = instance->typeString; - XP_ASSERT(instance->mimetype == defaultPlugin->mimetypes); + NPBool switchedHandler = FALSE; + char* type = instance->typeString; + XP_ASSERT(instance->mimetype == defaultPlugin->mimetypes); - if (type != NULL) - { - /* - * Try to match this instance's type against the - * types of all new plug-ins to see if any of them - * can handle it. Since the new plug-is were added - * to the front of the list, we only need to look - * at plug-ins up to the old head of the list. - */ - np_handle* handle = np_plist; - while (handle != NULL && handle != oldHead) - { - np_mimetype* mimeType; - XP_ASSERT(handle != defaultPlugin); - mimeType = np_getmimetype(handle, type, FALSE); + if (type != NULL) + { + /* + * Try to match this instance's type against the + * types of all new plug-ins to see if any of them + * can handle it. Since the new plug-is were added + * to the front of the list, we only need to look + * at plug-ins up to the old head of the list. + */ + np_handle* handle = np_plist; + while (handle != NULL && handle != oldHead) + { + np_mimetype* mimeType; + XP_ASSERT(handle != defaultPlugin); + mimeType = np_getmimetype(handle, type, FALSE); - /* - * We found a new handler for this type! Now we - * can destroy the plug-in instance and make a - * new instance handled by the new plug-in. - * Note that we have to point "instance" to the - * next object NOW, because np_switchHandlers - * will remove it from the list. - */ - if (mimeType != NULL) - { - np_instance* switcher = instance; - instance = instance->next; - (void) np_switchHandlers(switcher, handle, mimeType, type); - switchedHandler = TRUE; - break; /* Out of handle "while" loop */ - } + /* + * We found a new handler for this type! Now we + * can destroy the plug-in instance and make a + * new instance handled by the new plug-in. + * Note that we have to point "instance" to the + * next object NOW, because np_switchHandlers + * will remove it from the list. + */ + if (mimeType != NULL) + { + np_instance* switcher = instance; + instance = instance->next; + (void) np_switchHandlers(switcher, handle, mimeType, type); + switchedHandler = TRUE; + break; /* Out of handle "while" loop */ + } - handle = handle->next; - } - } + handle = handle->next; + } + } - /* - * In the case where we switch the handler (above), - * "instance" already points to the next objTag. - */ - if (!switchedHandler) - instance = instance->next; + /* + * In the case where we switch the handler (above), + * "instance" already points to the next objTag. + */ + if (!switchedHandler) + instance = instance->next; } } } @@ -2135,8 +2193,8 @@ npn_reloadplugins(NPBool reloadPages) NPError NPL_RefreshPluginList(XP_Bool reloadPages) { - npn_reloadplugins(reloadPages); - return NPERR_NO_ERROR; /* Always succeeds for now */ + npn_reloadplugins(reloadPages); + return NPERR_NO_ERROR; /* Always succeeds for now */ } @@ -2182,7 +2240,7 @@ npn_invalidateregion(NPP npp, NPRegion invalidRegion) */ XP_Bool NPL_IsForcingRedraw() { - return gForcingRedraw; + return gForcingRedraw; } #endif /* XP_MAC */ @@ -2224,8 +2282,8 @@ npn_getJavaEnv(void) { #ifdef XP_MAC - short resNum1, resNum2; - resNum1 = CurResFile(); + short resNum1, resNum2; + resNum1 = CurResFile(); #endif /* XP_MAC */ JNIEnv *pJNIEnv = NULL; @@ -2236,10 +2294,10 @@ npn_getJavaEnv(void) pJNIEnv = JVM_GetJNIEnv(); /* This may startup the VM. */ #ifdef XP_MAC - /* if Java changed the res file, change it back to the plugin's res file */ - resNum2 = CurResFile(); - if(resNum1 != resNum2) - UseResFile(resNum1); + /* if Java changed the res file, change it back to the plugin's res file */ + resNum2 = CurResFile(); + if(resNum1 != resNum2) + UseResFile(resNum1); #endif /* XP_MAC */ return pJNIEnv; @@ -2249,20 +2307,20 @@ JRIEnv* NP_EXPORT npn_getJavaEnv(void) { #ifdef JAVA - JRIEnv* env; + JRIEnv* env; #ifdef XP_MAC - short resNum1, resNum2; - resNum1 = CurResFile(); + short resNum1, resNum2; + resNum1 = CurResFile(); #endif /* XP_MAC */ - env = LJ_EnsureJavaEnv(NULL); /* NULL means for the current thread */ + env = LJ_EnsureJavaEnv(NULL); /* NULL means for the current thread */ #ifdef XP_MAC - /* if Java changed the res file, change it back to the plugin's res file */ - resNum2 = CurResFile(); - if(resNum1 != resNum2) - UseResFile(resNum1); + /* if Java changed the res file, change it back to the plugin's res file */ + resNum2 = CurResFile(); + if(resNum1 != resNum2) + UseResFile(resNum1); #endif /* XP_MAC */ return env; @@ -2287,14 +2345,14 @@ npn_getJavaClass(np_handle* handle); static void np_recover_mochaWindow(JNIEnv * env, np_instance * instance) { - if (env && instance && instance->mochaWindow && instance->javaInstance){ - /* Store the JavaScript context as the window object: */ - env->SetObjectField(instance->javaInstance, - env->GetFieldID(npn_getJavaClass(instance->handle), - fieldname_netscape_plugin_Plugin_window, fieldsig_netscape_plugin_Plugin_window), - (jobject)instance->mochaWindow); + if (env && instance && instance->mochaWindow && instance->javaInstance){ + /* Store the JavaScript context as the window object: */ + env->SetObjectField(instance->javaInstance, + env->GetFieldID(npn_getJavaClass(instance->handle), + fieldname_netscape_plugin_Plugin_window, fieldsig_netscape_plugin_Plugin_window), + (jobject)instance->mochaWindow); - } + } } jobject classPlugin = NULL; #define NPN_NO_JAVA_INSTANCE ((jobject)-1) @@ -2303,18 +2361,18 @@ jobject classPlugin = NULL; static void np_recover_mochaWindow(JRIEnv * env, np_instance * instance) { - netscape_plugin_Plugin* javaInstance = NULL; + netscape_plugin_Plugin* javaInstance = NULL; - if (env && instance && instance->mochaWindow && instance->javaInstance){ - javaInstance = (struct netscape_plugin_Plugin *) - JRI_GetGlobalRef(env, instance->javaInstance); - if (javaInstance) { - /* Store the JavaScript context as the window object: */ - set_netscape_plugin_Plugin_window(env, javaInstance, + if (env && instance && instance->mochaWindow && instance->javaInstance){ + javaInstance = (struct netscape_plugin_Plugin *) + JRI_GetGlobalRef(env, instance->javaInstance); + if (javaInstance) { + /* Store the JavaScript context as the window object: */ + set_netscape_plugin_Plugin_window(env, javaInstance, (netscape_javascript_JSObject*) JRI_GetGlobalRef(env, instance->mochaWindow)); - } - } + } + } } jglobal classPlugin = NULL; #define NPN_NO_JAVA_INSTANCE ((jglobal)-1) @@ -2342,7 +2400,7 @@ npn_getJavaClass(np_handle* handle) nsIPlugin* userPluginClass = (nsIPlugin*)handle->userPlugin; nsILiveConnectPlugin* lcPlugin; if (userPluginClass->QueryInterface(kLiveConnectPluginIID, - (void**)&lcPlugin) != NS_NOINTERFACE) { + (void**)&lcPlugin) == NS_OK) { jclass clazz; nsresult err = lcPlugin->GetJavaClass(&clazz); PR_ASSERT(err == NS_OK); @@ -2413,7 +2471,7 @@ npn_getJavaPeer(NPP npp) ** create the instance that we're just about to return. */ - /* But first, see if we need to recover the mochaWindow... */ + /* But first, see if we need to recover the mochaWindow... */ np_recover_mochaWindow(npn_getJavaEnv(), instance); return (jref)instance->javaInstance; @@ -2431,7 +2489,7 @@ npn_getJavaPeer(NPP npp) classPlugin = env->NewGlobalRef(clazz); } - /* instantiate the plugin's class: */ + /* instantiate the plugin's class: */ #define methodname_netscape_plugin_Plugin_new "" #define methodsig_netscape_plugin_Plugin_new "()V" @@ -2441,7 +2499,7 @@ npn_getJavaPeer(NPP npp) instance->javaInstance = env->NewGlobalRef(javaInstance); np_recover_mochaWindow(env,instance); - /* Store the plugin as the peer: */ + /* Store the plugin as the peer: */ #define fieldname_netscape_plugin_Plugin_peer "peer" #define fieldsig_netscape_plugin_Plugin_peer "I" env->SetIntField(javaInstance, @@ -2478,59 +2536,59 @@ npn_getJavaPeer(NPP npp) np_instance* instance; if (npp == NULL) - return NULL; + return NULL; instance = (np_instance*) npp->ndata; - if (instance == NULL) return NULL; + if (instance == NULL) return NULL; - if (instance->javaInstance == NPN_NO_JAVA_INSTANCE) { - /* Been there, done that. */ - return NULL; - } + if (instance->javaInstance == NPN_NO_JAVA_INSTANCE) { + /* Been there, done that. */ + return NULL; + } else if (instance->javaInstance != NULL) { - /* - ** It's ok to get the JRIEnv here -- it won't initialize the - ** runtime because it would have already been initialized to - ** create the instance that we're just about to return. - */ + /* + ** It's ok to get the JRIEnv here -- it won't initialize the + ** runtime because it would have already been initialized to + ** create the instance that we're just about to return. + */ - /* But first, see if we need to recover the mochaWindow... */ - np_recover_mochaWindow(npn_getJavaEnv(), instance); + /* But first, see if we need to recover the mochaWindow... */ + np_recover_mochaWindow(npn_getJavaEnv(), instance); - return (jref)JRI_GetGlobalRef(npn_getJavaEnv(), instance->javaInstance); - } + return (jref)JRI_GetGlobalRef(npn_getJavaEnv(), instance->javaInstance); + } else { - jclass clazz = npn_getJavaClass(instance->handle); + jclass clazz = npn_getJavaClass(instance->handle); if (clazz) { JRIEnv* env = npn_getJavaEnv(); /* may start up the java runtime */ - if (classPlugin == NULL) { - /* - ** Make sure we never unload the Plugin class. Why? Because - ** the method and field IDs we're using below have the same - ** lifetime as the class (theoretically): - */ - classPlugin = JRI_NewGlobalRef(env, use_netscape_plugin_Plugin(env)); - } + if (classPlugin == NULL) { + /* + ** Make sure we never unload the Plugin class. Why? Because + ** the method and field IDs we're using below have the same + ** lifetime as the class (theoretically): + */ + classPlugin = JRI_NewGlobalRef(env, use_netscape_plugin_Plugin(env)); + } - /* instantiate the plugin's class: */ - javaInstance = netscape_plugin_Plugin_new(env, clazz); - if (javaInstance) { + /* instantiate the plugin's class: */ + javaInstance = netscape_plugin_Plugin_new(env, clazz); + if (javaInstance) { - instance->javaInstance = JRI_NewGlobalRef(env, javaInstance); + instance->javaInstance = JRI_NewGlobalRef(env, javaInstance); - np_recover_mochaWindow(env,instance); + np_recover_mochaWindow(env,instance); - /* Store the plugin as the peer: */ - set_netscape_plugin_Plugin_peer(env, javaInstance, (jint)instance->npp); + /* Store the plugin as the peer: */ + set_netscape_plugin_Plugin_peer(env, javaInstance, (jint)instance->npp); - netscape_plugin_Plugin_init(env, javaInstance); - } - } - else { - instance->javaInstance = NPN_NO_JAVA_INSTANCE; /* prevent trying this every time around */ - return NULL; - } - } + netscape_plugin_Plugin_init(env, javaInstance); + } + } + else { + instance->javaInstance = NPN_NO_JAVA_INSTANCE; /* prevent trying this every time around */ + return NULL; + } + } return (jref)javaInstance; #else return NULL; @@ -2568,21 +2626,21 @@ np_IsLiveConnected(np_handle* handle) XP_Bool NPL_IsLiveConnected(LO_EmbedStruct *embed) { #if defined(JAVA) || defined(OJI) - NPEmbeddedApp* app; - np_data* ndata; + NPEmbeddedApp* app; + np_data* ndata; - if (embed == NULL) - return FALSE; + if (embed == NULL) + return FALSE; - app = (NPEmbeddedApp*) embed->objTag.FE_Data; - if (app == NULL) - return FALSE; + app = (NPEmbeddedApp*) embed->objTag.FE_Data; + if (app == NULL) + return FALSE; - ndata = (np_data*) app->np_data; - XP_ASSERT(ndata); + ndata = (np_data*) app->np_data; + XP_ASSERT(ndata); if(ndata->instance != NULL) { - return np_IsLiveConnected(ndata->instance->handle); + return np_IsLiveConnected(ndata->instance->handle); } return FALSE; #else @@ -2598,36 +2656,35 @@ XP_Bool NPL_IsLiveConnected(LO_EmbedStruct *embed) static PRBool np_setwindow(np_instance *instance, NPWindow *appWin) { - /* - * On Windows and UNIX, we don't want to give a window - * to hidden plug-ins. To determine if we're hidden, - * we can look at the flag bit of the LO_EmbedStruct. - */ - NPEmbeddedApp* app; - np_data* ndata; - LO_EmbedStruct* lo_struct=NULL; + /* + * On Windows and UNIX, we don't want to give a window + * to hidden plug-ins. To determine if we're hidden, + * we can look at the flag bit of the LO_EmbedStruct. + */ + NPEmbeddedApp* app; + np_data* ndata; + LO_EmbedStruct* lo_struct=NULL; - if (instance) - { - app = instance->app; - if (app) - { - ndata = (np_data*) app->np_data; - lo_struct = ndata->lo_struct; + if (instance) + { + app = instance->app; + if (app) + { + ndata = (np_data*) app->np_data; + lo_struct = ndata->lo_struct; #ifndef XP_MAC - if (lo_struct && lo_struct->objTag.ele_attrmask & LO_ELE_HIDDEN) - return PR_TRUE; + if (lo_struct && lo_struct->objTag.ele_attrmask & LO_ELE_HIDDEN) + return PR_TRUE; #endif - } - } + } + } XP_ASSERT(instance); if (instance && appWin) { TRACEMSG(("npglue.c: CallNPP_SetWindowProc")); if (instance->handle->userPlugin) { - nsPluginInstancePeer* peerInst = (nsPluginInstancePeer*)instance->npp->pdata; - nsIPluginInstance* pluginInst = peerInst->GetPluginInstance(); + nsIPluginInstance* pluginInst = NP_GET_PLUGIN_INSTANCE(instance->npp); if (pluginInst != NULL) { pluginInst->SetWindow((nsPluginWindow*)appWin); @@ -2635,14 +2692,11 @@ np_setwindow(np_instance *instance, NPWindow *appWin) // the plugin's Start() method. if (lo_struct && ! (lo_struct->objTag.ele_attrmask & LO_ELE_DRAWN)) { nsresult err = pluginInst->Start(); - pluginInst->Release(); if (err != NS_OK) { np_delete_instance(instance); return PR_FALSE; } - } else { - pluginInst->Release(); - } + } } } else if (ISFUNCPTR(instance->handle->f->setwindow)) { @@ -2659,32 +2713,32 @@ np_setwindow(np_instance *instance, NPWindow *appWin) static void np_UnloadPluginClass(np_handle *handle) { - /* only called when we truly want to dispose the plugin class */ - XP_ASSERT(handle && handle->refs == 0); + /* only called when we truly want to dispose the plugin class */ + XP_ASSERT(handle && handle->refs == 0); #if defined(OJI) if (handle->userPlugin == NULL && handle->f && handle->f->javaClass != NULL) { - /* Don't get the environment unless there is a Java class, - because this would cause the java runtime to start up. */ - JNIEnv* env = npn_getJavaEnv(); - env->DeleteGlobalRef((jobject)handle->f->javaClass); - handle->f->javaClass = NULL; - } + /* Don't get the environment unless there is a Java class, + because this would cause the java runtime to start up. */ + JNIEnv* env = npn_getJavaEnv(); + env->DeleteGlobalRef((jobject)handle->f->javaClass); + handle->f->javaClass = NULL; + } #elif defined(JAVA) if (handle->userPlugin == NULL && handle->f && handle->f->javaClass != NULL) { - /* Don't get the environment unless there is a Java class, - because this would cause the java runtime to start up. */ - JRIEnv* env = npn_getJavaEnv(); - JRI_DisposeGlobalRef(env, handle->f->javaClass); - handle->f->javaClass = NULL; - } + /* Don't get the environment unless there is a Java class, + because this would cause the java runtime to start up. */ + JRIEnv* env = npn_getJavaEnv(); + JRI_DisposeGlobalRef(env, handle->f->javaClass); + handle->f->javaClass = NULL; + } #endif /* JAVA */ - FE_UnloadPlugin(handle->pdesc, handle); - handle->f = NULL; + FE_UnloadPlugin(handle->pdesc, handle); + handle->f = NULL; - XP_ASSERT(handle->instances == NULL); - handle->instances = NULL; + XP_ASSERT(handle->instances == NULL); + handle->instances = NULL; } @@ -2694,21 +2748,21 @@ PR_IMPLEMENT(void) NPL_SetPluginWindow(void *data) { #ifdef JAVA - JRIEnv * env = NULL; - np_instance *instance = (np_instance *) data; - struct netscape_javascript_JSObject *mochaWindow = NULL; + JRIEnv * env = NULL; + np_instance *instance = (np_instance *) data; + struct netscape_javascript_JSObject *mochaWindow = NULL; - if (instance && instance->cx) - mochaWindow = LJ_GetMochaWindow(instance->cx); + if (instance && instance->cx) + mochaWindow = LJ_GetMochaWindow(instance->cx); - env = LJ_EnsureJavaEnv(PR_CurrentThread()); + env = LJ_EnsureJavaEnv(PR_CurrentThread()); - if (mochaWindow){ - instance->mochaWindow = JRI_NewGlobalRef(env, (jref) mochaWindow); + if (mochaWindow){ + instance->mochaWindow = JRI_NewGlobalRef(env, (jref) mochaWindow); - /* That's done, now stuff it in */ - np_recover_mochaWindow(env,instance); - } + /* That's done, now stuff it in */ + np_recover_mochaWindow(env,instance); + } #endif } @@ -2723,7 +2777,7 @@ np_newinstance(np_handle *handle, MWContext *cx, NPEmbeddedApp *app, void* tmp; np_data* ndata; - XP_ASSERT(handle && app); + XP_ASSERT(handle && app); if (!handle || !app) return NULL; @@ -2731,31 +2785,31 @@ np_newinstance(np_handle *handle, MWContext *cx, NPEmbeddedApp *app, if (!handle->refs) { #ifdef JAVA - JRIEnv* env = NULL; + JRIEnv* env = NULL; #endif - FE_Progress(cx, XP_GetString(XP_PLUGIN_LOADING_PLUGIN)); + FE_Progress(cx, XP_GetString(XP_PLUGIN_LOADING_PLUGIN)); if (!(handle->f = FE_LoadPlugin(handle->pdesc, &npp_funcs, handle))) - { - char* msg = PR_smprintf(XP_GetString(XP_PLUGIN_CANT_LOAD_PLUGIN), handle->name, mimetype->type); - FE_Alert(cx, msg); - XP_FREE(msg); - return NULL; - } + { + char* msg = PR_smprintf(XP_GetString(XP_PLUGIN_CANT_LOAD_PLUGIN), handle->name, mimetype->type); + FE_Alert(cx, msg); + XP_FREE(msg); + return NULL; + } #ifdef JAVA - /* - ** Don't use npn_getJavaEnv here. We don't want to start the - ** interpreter, just use env if it already exists. - */ - env = JRI_GetCurrentEnv(); + /* + ** Don't use npn_getJavaEnv here. We don't want to start the + ** interpreter, just use env if it already exists. + */ + env = JRI_GetCurrentEnv(); - /* - ** An exception could have occurred when the plugin tried to load - ** it's class file. We'll print any exception to the console. - */ - if (env && JRI_ExceptionOccurred(env)) { - JRI_ExceptionDescribe(env); - JRI_ExceptionClear(env); - } + /* + ** An exception could have occurred when the plugin tried to load + ** it's class file. We'll print any exception to the console. + */ + if (env && JRI_ExceptionOccurred(env)) { + JRI_ExceptionDescribe(env); + JRI_ExceptionClear(env); + } #endif } @@ -2816,22 +2870,27 @@ np_newinstance(np_handle *handle, MWContext *cx, NPEmbeddedApp *app, nsresult err2 = pluginClass->CreateInstance(NULL, kPluginInstanceIID, (void**)&pluginInst); if (err2 == NS_OK && pluginInst != NULL) { - peerInst->SetPluginInstance(pluginInst); + + // The main reference to the peer will be held by the instance + // via Initialize. nsresult err3 = pluginInst->Initialize(peerInst); + if (err3 == NS_OK) { - npp->pdata = peerInst; + // The user's plugin instance is stored in the saved data of the np_data + // structure. This is _the_ main reference to the instance, and the one + // that holds the refcount (initialized to 1 by CreateInstance). ndata->sdata = (NPSavedData*)pluginInst; + err = NPERR_NO_ERROR; // This used to be done by the NPN_SetValue call. The user was required // to call them during NPP_New: extern nsresult fromNPError[]; - void* value; - // It's an abomination that we don't pass the address of value here: - err3 = pluginInst->GetValue(nsPluginInstanceVariable_WindowlessBool, value); + NPBool value; + err3 = pluginInst->GetValue(nsPluginInstanceVariable_WindowlessBool, &value); if (err3 == NS_OK) (void)npn_SetWindowless(instance, (PRBool)value); - err3 = pluginInst->GetValue(nsPluginInstanceVariable_TransparentBool, value); + err3 = pluginInst->GetValue(nsPluginInstanceVariable_TransparentBool, &value); if (err3 == NS_OK) (void)npn_SetTransparent(instance, (PRBool)value); } @@ -2840,6 +2899,10 @@ np_newinstance(np_handle *handle, MWContext *cx, NPEmbeddedApp *app, peerInst->SetPluginInstance(NULL); err = NPERR_INVALID_INSTANCE_ERROR; } + + // If the instance doesn't want to hang on to the peer (via Initialize), it + // will get deleted right here. + peerInst->Release(); } else err = NPERR_INVALID_INSTANCE_ERROR; @@ -2918,8 +2981,9 @@ np_newinstance(np_handle *handle, MWContext *cx, NPEmbeddedApp *app, } } #endif +#if 0 /* XXX This is _not_ where Start() should go (IMO). Start() should be - called whenever we re-visit an applet + called whenever we re-visit an applet */ // Finally, if it's a 5.0-style (C++) plugin, send it the Start message. // Do this before sending the mocha OnLoad message. @@ -2928,7 +2992,7 @@ np_newinstance(np_handle *handle, MWContext *cx, NPEmbeddedApp *app, nsresult err = pluginInst->Start(); if (err != NS_OK) goto error; } - */ +#endif #endif { @@ -2959,14 +3023,14 @@ np_newinstance(np_handle *handle, MWContext *cx, NPEmbeddedApp *app, return instance; -error: + error: /* Unload the plugin if there are no other instances */ if (handle->refs == 0) { - np_UnloadPluginClass(handle); + np_UnloadPluginClass(handle); } - if (instance) + if (instance) XP_FREE(instance); if (npp) XP_FREE(npp); @@ -2983,28 +3047,28 @@ np_newstream(URL_Struct *urls, np_handle *handle, np_instance *instance) np_stream *stream = nil; uint stype; uint16 stype2; - XP_Bool alreadyLocal; + XP_Bool alreadyLocal; XP_Bool b1; - XP_Bool b2; + XP_Bool b2; /* make a netlib stream */ if (!(nstream = XP_NEW_ZAP(NET_StreamClass))) return 0; - /* make the plugin stream data structures */ - stream = np_makestreamobjects(instance, nstream, urls); - if (!stream) - { + /* make the plugin stream data structures */ + stream = np_makestreamobjects(instance, nstream, urls); + if (!stream) + { XP_FREE(nstream); return 0; - } - pstream = stream->pstream; + } + pstream = stream->pstream; - stream->prev_stream = NULL; + stream->prev_stream = NULL; /* Let us treat mailbox as remote too Not doing so causes problems with some attachments (Adobe) - */ + */ b1 = NET_IsURLInDiskCache(stream->initial_urls); b2 = (XP_STRNCASECMP(urls->address, "mailbox:", 8) == 0) ? 0 : NET_IsLocalFileURL(urls->address); @@ -3019,7 +3083,7 @@ np_newstream(URL_Struct *urls, np_handle *handle, np_instance *instance) * stream if a byterange request is made. */ if (urls->content_length > 0) - stream->seekable = 1; + stream->seekable = 1; } /* and call the plugin */ @@ -3028,8 +3092,37 @@ np_newstream(URL_Struct *urls, np_handle *handle, np_instance *instance) stype2 = NP_NORMAL; TRACEMSG(("npglue.c: CallNPP_NewStreamProc")); if (handle->userPlugin) { - nsPluginInstancePeer* peerInst = (nsPluginInstancePeer*)instance->npp->pdata; - nsIPluginInstance* pluginInst = peerInst->GetPluginInstance(); + +#ifdef NEW_PLUGIN_STREAM_API + + nsresult err; + np_urlsnode* node = np_getURLfromList(instance, urls); + if (node == NULL) { + err = NPERR_GENERIC_ERROR; + } + else { + nsPluginInputStream* inStr = (nsPluginInputStream*)node->notifyData; + if (inStr == NULL) { + err = NS_ERROR_OUT_OF_MEMORY; + } + else { + inStr->SetStreamInfo(urls, stream); + nsPluginStreamInfo info; + info.contentType = urls->content_type; + info.seekable = stream->seekable; + + stype = inStr->GetStreamType(); + pstream->pdata = inStr; + nsIPluginStreamListener* listener = inStr->GetListener(); + err = listener->OnStartBinding(urls->address, &info); + } + } + PR_ASSERT(err == NS_OK); + // XXX where does err go? + +#else // !NEW_PLUGIN_STREAM_API + + nsIPluginInstance* pluginInst = NP_GET_PLUGIN_INSTANCE(instance->npp); nsPluginStreamPeer* peerStream = new nsPluginStreamPeer(urls, stream); if (peerStream == NULL) { /* XXX where's the error go? */ @@ -3049,7 +3142,8 @@ np_newstream(URL_Struct *urls, np_handle *handle, np_instance *instance) /* XXX where's the error go? */ } } - pluginInst->Release(); + +#endif // !NEW_PLUGIN_STREAM_API } else if (ISFUNCPTR(handle->f->newstream)) { @@ -3073,35 +3167,35 @@ np_newstream(URL_Struct *urls, np_handle *handle, np_instance *instance) NPTRACE(0,("stream is dumb, force caching")); stream->seek = 2; } - /* for a seekable stream that doesn't require caching, in the SSL case, don't cache, because that - will leave the supposedly secure file laying around in the cache! */ - if ( !alreadyLocal - && !(XP_STRNCASECMP(urls->address, "https:", 6)==0)) - urls->must_cache = TRUE; - stream->dontclose++; + /* for a seekable stream that doesn't require caching, in the SSL case, don't cache, because that + will leave the supposedly secure file laying around in the cache! */ + if ( !alreadyLocal + && !(XP_STRNCASECMP(urls->address, "https:", 6)==0)) + urls->must_cache = TRUE; + stream->dontclose++; } - else if (stype == NP_ASFILE || stype == NP_ASFILEONLY) + else if (stype == NP_ASFILE || stype == NP_ASFILEONLY) { NPTRACE(0,("stream as file")); if (!alreadyLocal) - urls->must_cache = TRUE; + urls->must_cache = TRUE; stream->asfile = stype; } - /* - * If they want just the file, and the file is local, there's - * no need to continue with the netlib stream: just give them - * the file and we're done. - */ - if (stype == NP_ASFILEONLY) - { - if (urls->cache_file || NET_IsLocalFileURL(urls->address)) - { - np_streamAsFile(stream); - np_destroystream(stream, NPRES_DONE); - XP_FREE(nstream); - return NULL; - } + /* + * If they want just the file, and the file is local, there's + * no need to continue with the netlib stream: just give them + * the file and we're done. + */ + if (stype == NP_ASFILEONLY) + { + if (urls->cache_file || NET_IsLocalFileURL(urls->address)) + { + np_streamAsFile(stream); + np_destroystream(stream, NPRES_DONE); + XP_FREE(nstream); + return NULL; + } } /* and populate the netlib stream */ @@ -3113,51 +3207,51 @@ np_newstream(URL_Struct *urls, np_handle *handle, np_instance *instance) nstream->data_object = (void *)urls; nstream->window_id = instance->cx; - /* In case of Mailbox->StreamAsFile, use cache code to store, handle... */ - if ( ((stype == NP_ASFILE) || (stype == NP_ASFILEONLY)) && - ((XP_STRNCASECMP(urls->address, "mailbox:", 8)==0) - || (XP_STRNCASECMP(urls->address, "news:" , 5)==0) - || (XP_STRNCASECMP(urls->address, "snews:" , 6)==0)) - && - (stream != NULL) && - (urls->cache_file == NULL)) /* if already cached, is well-handled */ - { - urls->must_cache = TRUE; - stream->prev_stream = NET_StreamBuilder(FO_CACHE_ONLY,urls,instance->cx); - } + /* In case of Mailbox->StreamAsFile, use cache code to store, handle... */ + if ( ((stype == NP_ASFILE) || (stype == NP_ASFILEONLY)) && + ((XP_STRNCASECMP(urls->address, "mailbox:", 8)==0) + || (XP_STRNCASECMP(urls->address, "news:" , 5)==0) + || (XP_STRNCASECMP(urls->address, "snews:" , 6)==0)) + && + (stream != NULL) && + (urls->cache_file == NULL)) /* if already cached, is well-handled */ + { + urls->must_cache = TRUE; + stream->prev_stream = NET_StreamBuilder(FO_CACHE_ONLY,urls,instance->cx); + } return nstream; } XP_Bool np_FakeHTMLStream(URL_Struct* urls, MWContext* cx, char * fakehtml) { - NET_StreamClass* viewstream; - char* org_content_type = urls->content_type; - XP_Bool ret = FALSE; + NET_StreamClass* viewstream; + char* org_content_type = urls->content_type; + XP_Bool ret = FALSE; - urls->content_type = NULL; + urls->content_type = NULL; - StrAllocCopy(urls->content_type, TEXT_HTML); - if(urls->content_type == NULL) /* StrAllocCopy failed */ - goto Exit; + StrAllocCopy(urls->content_type, TEXT_HTML); + if(urls->content_type == NULL) /* StrAllocCopy failed */ + goto Exit; - urls->is_binary = 1; /* flag for mailto and saveas */ + urls->is_binary = 1; /* flag for mailto and saveas */ - if ((viewstream = NET_StreamBuilder(FO_PRESENT, urls, cx)) != 0) - { - (*viewstream->put_block)(viewstream, fakehtml, XP_STRLEN(fakehtml)); - (*viewstream->complete)(viewstream); + if ((viewstream = NET_StreamBuilder(FO_PRESENT, urls, cx)) != 0) + { + (*viewstream->put_block)(viewstream, fakehtml, XP_STRLEN(fakehtml)); + (*viewstream->complete)(viewstream); - XP_FREEIF(viewstream); - viewstream = NULL; - ret = TRUE; - } + XP_FREEIF(viewstream); + viewstream = NULL; + ret = TRUE; + } - XP_FREE(urls->content_type); + XP_FREE(urls->content_type); -Exit: - urls->content_type = org_content_type; - return ret; + Exit: + urls->content_type = org_content_type; + return ret; } NET_StreamClass* @@ -3165,123 +3259,123 @@ NPL_NewPresentStream(FO_Present_Types format_out, void* type, URL_Struct* urls, { np_handle* handle = (np_handle*) type; np_instance* instance = NULL; - np_data* ndata = NULL; - np_mimetype* mimetype = NULL; - np_reconnect* reconnect; + np_data* ndata = NULL; + np_mimetype* mimetype = NULL; + np_reconnect* reconnect; NPEmbeddedApp *app = NULL; #ifdef ANTHRAX - char* fileName; - char* newTag; - uint32 strLen; + char* fileName; + char* newTag; + uint32 strLen; #endif /* ANTHRAX */ XP_ASSERT(type && urls && cx); - if (!type || !urls || !cx) - return NULL; + if (!type || !urls || !cx) + return NULL; - /* fe_data is set by EmbedCreate, which hasn't happed yet for PRESENT streams */ - XP_ASSERT(urls->fe_data == NULL); + /* fe_data is set by EmbedCreate, which hasn't happed yet for PRESENT streams */ + XP_ASSERT(NP_GET_URL_APP(urls) == NULL); #ifdef ANTHRAX - if((fileName = NPL_FindAppletEnabledForMimetype(handle->name)) != NULL) - { - XP_FREE(fileName); /* we don't need the applet name here, so discard it */ - fileName = strrchr(urls->address, '/')+1; + if((fileName = NPL_FindAppletEnabledForMimetype(handle->name)) != NULL) + { + XP_FREE(fileName); /* we don't need the applet name here, so discard it */ + fileName = strrchr(urls->address, '/')+1; - strLen = XP_STRLEN(fileName); + strLen = XP_STRLEN(fileName); - newTag = (char*)XP_ALLOC((36+strLen)*sizeof(char)); - newTag[0] = 0; + newTag = (char*)XP_ALLOC((36+strLen)*sizeof(char)); + newTag[0] = 0; - XP_STRCAT(newTag, ""); + XP_STRCAT(newTag, ""); - np_FakeHTMLStream(urls,cx,newTag); - XP_FREE(newTag); - return NULL; + np_FakeHTMLStream(urls,cx,newTag); + XP_FREE(newTag); + return NULL; } #endif /* ANTHRAX */ - mimetype = np_getmimetype(handle, urls->content_type, TRUE); - if (!mimetype) - return NULL; + mimetype = np_getmimetype(handle, urls->content_type, TRUE); + if (!mimetype) + return NULL; - /* - * The following code special-cases the LiveAudio plug-in to open - * a new chromeless window. A new window is only opened if there's - * history information for the current context; that prevents us from - * opening ANOTHER new window if the FE has already made one (for - * example, if the user chose "New window for this link" from the - * popup). - */ - if (handle->name && (XP_STRCASECMP(handle->name, "LiveAudio") == 0)) - { - History_entry* history = SHIST_GetCurrent(&cx->hist); - if (history) - { - MWContext* oldContext = cx; - Chrome* customChrome = XP_NEW_ZAP(Chrome); - if (customChrome == NULL) - return NULL; - customChrome->w_hint = 144 + 1; - customChrome->h_hint = 60 + 1; - customChrome->allow_close = TRUE; + /* + * The following code special-cases the LiveAudio plug-in to open + * a new chromeless window. A new window is only opened if there's + * history information for the current context; that prevents us from + * opening ANOTHER new window if the FE has already made one (for + * example, if the user chose "New window for this link" from the + * popup). + */ + if (handle->name && (XP_STRCASECMP(handle->name, "LiveAudio") == 0)) + { + History_entry* history = SHIST_GetCurrent(&cx->hist); + if (history) + { + MWContext* oldContext = cx; + Chrome* customChrome = XP_NEW_ZAP(Chrome); + if (customChrome == NULL) + return NULL; + customChrome->w_hint = 144 + 1; + customChrome->h_hint = 60 + 1; + customChrome->allow_close = TRUE; - /* Make a new window with no URL or window name, but special chrome */ - cx = FE_MakeNewWindow(oldContext, NULL, NULL, customChrome); - if (cx == NULL) - { - XP_FREE(customChrome); - return NULL; - } - /* Insert some HTML to notify of Java delay: */ - { - JRIEnv* env = NULL; - /* Has Java already been started? */ + /* Make a new window with no URL or window name, but special chrome */ + cx = FE_MakeNewWindow(oldContext, NULL, NULL, customChrome); + if (cx == NULL) + { + XP_FREE(customChrome); + return NULL; + } + /* Insert some HTML to notify of Java delay: */ + { + JRIEnv* env = NULL; + /* Has Java already been started? */ #ifdef JAVA - env = JRI_GetCurrentEnv(); + env = JRI_GetCurrentEnv(); #endif - if (env == NULL){ - /* nope, java not yet started */ - static char fakehtml[255] = ""; + if (env == NULL){ + /* nope, java not yet started */ + static char fakehtml[255] = ""; - XP_SPRINTF(fakehtml,"

%s
",XP_GetString(XP_PROGRESS_STARTING_JAVA)); - np_FakeHTMLStream(urls,cx,fakehtml); - } - } + XP_SPRINTF(fakehtml,"

%s
",XP_GetString(XP_PROGRESS_STARTING_JAVA)); + np_FakeHTMLStream(urls,cx,fakehtml); + } + } - /* Switch to the new context, but don't change the exit routine */ - NET_SetNewContext(urls, cx, NULL); - } - } + /* Switch to the new context, but don't change the exit routine */ + NET_SetNewContext(urls, cx, NULL); + } + } - /* - * Set up the "reconnect" data, which is used to communicate between this - * function and the call to EmbedCreate that will result from pushing the - * data into the stream below. EmbedCreate needs to know from us the - * np_mimetype and requestedtype for this stream, and we need to know from - * it the NPEmbeddedApp that it created. - */ + /* + * Set up the "reconnect" data, which is used to communicate between this + * function and the call to EmbedCreate that will result from pushing the + * data into the stream below. EmbedCreate needs to know from us the + * np_mimetype and requestedtype for this stream, and we need to know from + * it the NPEmbeddedApp that it created. + */ XP_ASSERT(cx->pluginReconnect == NULL); - reconnect = XP_NEW_ZAP(np_reconnect); - if (!reconnect) - return NULL; + reconnect = XP_NEW_ZAP(np_reconnect); + if (!reconnect) + return NULL; cx->pluginReconnect = (void*) reconnect; reconnect->mimetype = mimetype; reconnect->requestedtype = XP_STRDUP(urls->content_type); - /* - * To actually create the instance we need to create a stream of - * fake HTML to cause layout to create a new embedded objTag. - * EmbedCreate will be called, which will created the NPEmbeddedApp - * and put it into urls->fe_data, where we can retrieve it. - */ - { - static char fakehtml[] = ""; - np_FakeHTMLStream(urls,cx,fakehtml); + /* + * To actually create the instance we need to create a stream of + * fake HTML to cause layout to create a new embedded objTag. + * EmbedCreate will be called, which will created the NPEmbeddedApp + * and put it into urls->fe_data, where we can retrieve it. + */ + { + static char fakehtml[] = ""; + np_FakeHTMLStream(urls,cx,fakehtml); } /* @@ -3297,7 +3391,7 @@ NPL_NewPresentStream(FO_Present_Types format_out, void* type, URL_Struct* urls, return NULL; /* will be NULL if the plugin failed to initialize */ XP_ASSERT(app->pagePluginType == NP_FullPage); - urls->fe_data = (void*) app; /* fe_data of plug-in URLs always holds NPEmbeddedApp */ + NP_SET_URL_APP(urls, app); /* fe_data of plug-in URLs always holds NPEmbeddedApp */ ndata = (np_data*) app->np_data; XP_ASSERT(ndata); @@ -3307,8 +3401,8 @@ NPL_NewPresentStream(FO_Present_Types format_out, void* type, URL_Struct* urls, handle = ndata->handle; instance = ndata->instance; XP_ASSERT(handle && instance); - if (!handle || !instance) - return NULL; + if (!handle || !instance) + return NULL; /* now actually make a plugin and netlib stream */ return np_newstream(urls, handle, instance); @@ -3320,42 +3414,42 @@ NET_StreamClass* NPL_NewEmbedStream(FO_Present_Types format_out, void* type, URL_Struct* urls, MWContext* cx) { np_handle* handle = (np_handle*) type; - np_data* ndata = NULL; + np_data* ndata = NULL; NPEmbeddedApp* app = NULL; XP_ASSERT(type && urls && cx); - if (!type || !urls || !cx) - return NULL; + if (!type || !urls || !cx) + return NULL; - /* fe_data is set by EmbedCreate, which has already happened for EMBED streams */ - app = (NPEmbeddedApp*) urls->fe_data; + /* fe_data is set by EmbedCreate, which has already happened for EMBED streams */ + app = NP_GET_URL_APP(urls); XP_ASSERT(app); if (!app) return NULL; XP_ASSERT(app->pagePluginType == NP_Embedded); ndata = (np_data*) app->np_data; - XP_ASSERT(ndata && ndata->lo_struct); - if (!ndata) - return NULL; + XP_ASSERT(ndata && ndata->lo_struct); + if (!ndata) + return NULL; - if (ndata->instance == NULL) - { - np_instance* instance; - np_mimetype* mimetype; + if (ndata->instance == NULL) + { + np_instance* instance; + np_mimetype* mimetype; - /* Map the stream's MIME type to a np_mimetype object */ - mimetype = np_getmimetype(handle, urls->content_type, TRUE); - if (!mimetype) - return NULL; + /* Map the stream's MIME type to a np_mimetype object */ + mimetype = np_getmimetype(handle, urls->content_type, TRUE); + if (!mimetype) + return NULL; - /* Now that we have the MIME type and the layout data, we can create an instance */ - instance = np_newinstance(handle, cx, app, mimetype, urls->content_type); - if (!instance) - return NULL; + /* Now that we have the MIME type and the layout data, we can create an instance */ + instance = np_newinstance(handle, cx, app, mimetype, urls->content_type); + if (!instance) + return NULL; - ndata->instance = instance; - ndata->handle = handle; + ndata->instance = instance; + ndata->handle = handle; #ifdef LAYERS LO_SetEmbedType(ndata->lo_struct, (PRBool) ndata->instance->windowed); #endif @@ -3392,7 +3486,7 @@ np_newbyterangestream(FO_Present_Types format_out, void *type, URL_Struct *urls, static NET_StreamClass * np_newpluginstream(FO_Present_Types format_out, void *type, URL_Struct *urls, MWContext *cx) { - NPEmbeddedApp* app = (NPEmbeddedApp*) urls->fe_data; + NPEmbeddedApp* app = NP_GET_URL_APP(urls); if (app) { @@ -3415,23 +3509,23 @@ NPL_RegisterPluginFile(const char* pluginname, const char* filename, const char* NPTRACE(0,("np: register file %s", filename)); #ifdef DEBUG - /* Ensure uniqueness of pdesc values! */ - for (handle = np_plist; handle; handle = handle->next) - XP_ASSERT(handle->pdesc != pdesc); + /* Ensure uniqueness of pdesc values! */ + for (handle = np_plist; handle; handle = handle->next) + XP_ASSERT(handle->pdesc != pdesc); #endif - handle = XP_NEW_ZAP(np_handle); - if (!handle) - return NPERR_OUT_OF_MEMORY_ERROR; + handle = XP_NEW_ZAP(np_handle); + if (!handle) + return NPERR_OUT_OF_MEMORY_ERROR; - StrAllocCopy(handle->name, pluginname); - StrAllocCopy(handle->filename, filename); - StrAllocCopy(handle->description, description); + StrAllocCopy(handle->name, pluginname); + StrAllocCopy(handle->filename, filename); + StrAllocCopy(handle->description, description); - handle->pdesc = pdesc; - handle->next = np_plist; + handle->pdesc = pdesc; + handle->next = np_plist; handle->userPlugin = NULL; - np_plist = handle; + np_plist = handle; #ifdef OJI char* pluginDir = PL_strdup(filename); @@ -3443,7 +3537,7 @@ NPL_RegisterPluginFile(const char* pluginname, const char* filename, const char* } #endif - return NPERR_NO_ERROR; + return NPERR_NO_ERROR; } /* @@ -3462,92 +3556,92 @@ NPL_EnablePlugin(NPMIMEType type, const char *pluginName, XP_Bool enabled) np_mimetype* mimetype; NPTRACE(0,("np: enable plugin %s for type %s", pluginName, type)); - if (!pluginName || !*pluginName || !type || !*type) - return(NPERR_INVALID_PARAM); + if (!pluginName || !*pluginName || !type || !*type) + return(NPERR_INVALID_PARAM); - for (handle = np_plist; handle; handle = handle->next) - { - if (!strcmp(handle->name, pluginName)) - break; - } + for (handle = np_plist; handle; handle = handle->next) + { + if (!strcmp(handle->name, pluginName)) + break; + } - if (!handle) - /* Plugin with the specified name not found */ - return(NPERR_INVALID_INSTANCE_ERROR); + if (!handle) + /* Plugin with the specified name not found */ + return(NPERR_INVALID_INSTANCE_ERROR); - /* Look for an existing MIME type object for the specified type */ - /* We can't use np_getmimetype, because it respects enabledness and - here we don't care */ - for (mimetype = handle->mimetypes; mimetype; mimetype = mimetype->next) - { - if (strcasecomp(mimetype->type, type) == 0) - break; - } + /* Look for an existing MIME type object for the specified type */ + /* We can't use np_getmimetype, because it respects enabledness and + here we don't care */ + for (mimetype = handle->mimetypes; mimetype; mimetype = mimetype->next) + { + if (strcasecomp(mimetype->type, type) == 0) + break; + } - if (!mimetype) - /* This plugin cannot handler the specified mimetype */ - return(NPERR_INVALID_PLUGIN_ERROR); + if (!mimetype) + /* This plugin cannot handler the specified mimetype */ + return(NPERR_INVALID_PLUGIN_ERROR); - /* Find the plug-in that was previously enabled for this type and - disable it */ - if (enabled) - { - XP_Bool foundType = FALSE; - np_handle* temphandle; - np_mimetype* temptype; + /* Find the plug-in that was previously enabled for this type and + disable it */ + if (enabled) + { + XP_Bool foundType = FALSE; + np_handle* temphandle; + np_mimetype* temptype; - for (temphandle = np_plist; temphandle && !foundType; temphandle = temphandle->next) - { - for (temptype = temphandle->mimetypes; temptype && !foundType; temptype = temptype->next) - { - if (temptype->enabled && strcasecomp(temptype->type, type) == 0) - { - temptype->enabled = FALSE; - foundType = TRUE; - } - } - } - } + for (temphandle = np_plist; temphandle && !foundType; temphandle = temphandle->next) + { + for (temptype = temphandle->mimetypes; temptype && !foundType; temptype = temptype->next) + { + if (temptype->enabled && strcasecomp(temptype->type, type) == 0) + { + temptype->enabled = FALSE; + foundType = TRUE; + } + } + } + } - mimetype->enabled = enabled; + mimetype->enabled = enabled; - if (mimetype->enabled) - { - /* - * Is this plugin the wildcard (a.k.a. null) plugin? - * If so, we don't want to register it for FO_PRESENT - * or it will interfere with our normal unknown-mime- - * type handling. - */ - XP_Bool wildtype = (strcmp(type, "*") == 0); + if (mimetype->enabled) + { + /* + * Is this plugin the wildcard (a.k.a. null) plugin? + * If so, we don't want to register it for FO_PRESENT + * or it will interfere with our normal unknown-mime- + * type handling. + */ + XP_Bool wildtype = (strcmp(type, "*") == 0); #if defined(XP_WIN) || defined(XP_OS2) - /* EmbedStream does some Windows FE work and then calls NPL_NewStream */ - if (!wildtype) - NET_RegisterContentTypeConverter(type, FO_PRESENT, handle, EmbedStream); - NET_RegisterContentTypeConverter(type, FO_EMBED, handle, EmbedStream); /* XXX I dont think this does anything useful */ + /* EmbedStream does some Windows FE work and then calls NPL_NewStream */ + if (!wildtype) + NET_RegisterContentTypeConverter(type, FO_PRESENT, handle, EmbedStream); + NET_RegisterContentTypeConverter(type, FO_EMBED, handle, EmbedStream); /* XXX I dont think this does anything useful */ #else - if (!wildtype) - { - NET_RegisterContentTypeConverter(type, FO_PRESENT, handle, NPL_NewPresentStream); + if (!wildtype) + { + NET_RegisterContentTypeConverter(type, FO_PRESENT, handle, NPL_NewPresentStream); #ifdef XP_UNIX - /* The following three lines should be outside the ifdef someday */ - NET_RegisterAllEncodingConverters(type, FO_PRESENT); - NET_RegisterAllEncodingConverters(type, FO_EMBED); - NET_RegisterAllEncodingConverters(type, FO_PLUGIN); + /* The following three lines should be outside the ifdef someday */ + NET_RegisterAllEncodingConverters(type, FO_PRESENT); + NET_RegisterAllEncodingConverters(type, FO_EMBED); + NET_RegisterAllEncodingConverters(type, FO_PLUGIN); - /* While printing we use the FO_SAVE_AS_POSTSCRIPT format type. We want - * plugin to possibly handle that case too. Hence this. - */ - NET_RegisterContentTypeConverter(type, FO_SAVE_AS_POSTSCRIPT, handle, - NPL_NewPresentStream); + /* While printing we use the FO_SAVE_AS_POSTSCRIPT format type. We want + * plugin to possibly handle that case too. Hence this. + */ + NET_RegisterContentTypeConverter(type, FO_SAVE_AS_POSTSCRIPT, handle, + NPL_NewPresentStream); #endif /* XP_UNIX */ - } - NET_RegisterContentTypeConverter(type, FO_EMBED, handle, NPL_NewEmbedStream); + } + NET_RegisterContentTypeConverter(type, FO_EMBED, handle, NPL_NewEmbedStream); #endif - NET_RegisterContentTypeConverter(type, FO_PLUGIN, handle, np_newpluginstream); - NET_RegisterContentTypeConverter(type, FO_BYTERANGE, handle, np_newbyterangestream); - } + NET_RegisterContentTypeConverter(type, FO_PLUGIN, handle, np_newpluginstream); + NET_RegisterContentTypeConverter(type, FO_BYTERANGE, handle, np_newbyterangestream); + } return(NPERR_NO_ERROR); } @@ -3564,96 +3658,96 @@ np_findPluginType(NPMIMEType type, void* pdesc, np_handle** outHandle, np_mimety np_handle* handle; np_mimetype* mimetype; - *outHandle = NULL; - *outMimetype = NULL; + *outHandle = NULL; + *outMimetype = NULL; - /* Look for an existing handle */ - for (handle = np_plist; handle; handle = handle->next) - { - if (handle->pdesc == pdesc) - break; - } + /* Look for an existing handle */ + for (handle = np_plist; handle; handle = handle->next) + { + if (handle->pdesc == pdesc) + break; + } - if (!handle) - return; - *outHandle = handle; + if (!handle) + return; + *outHandle = handle; - /* Look for an existing MIME type object for the specified type */ - /* We can't use np_getmimetype, because it respects enabledness and here we don't care */ - for (mimetype = handle->mimetypes; mimetype; mimetype = mimetype->next) - { - if (strcasecomp(mimetype->type, type) == 0) - break; - } + /* Look for an existing MIME type object for the specified type */ + /* We can't use np_getmimetype, because it respects enabledness and here we don't care */ + for (mimetype = handle->mimetypes; mimetype; mimetype = mimetype->next) + { + if (strcasecomp(mimetype->type, type) == 0) + break; + } - if (!mimetype) - return; - *outMimetype = mimetype; + if (!mimetype) + return; + *outMimetype = mimetype; } void np_enablePluginType(np_handle* handle, np_mimetype* mimetype, XP_Bool enabled) { - char* type = mimetype->type; + char* type = mimetype->type; - /* - * Find the plug-in that was previously - * enabled for this type and disable it. - */ - if (enabled) - { - XP_Bool foundType = FALSE; - np_handle* temphandle; - np_mimetype* temptype; + /* + * Find the plug-in that was previously + * enabled for this type and disable it. + */ + if (enabled) + { + XP_Bool foundType = FALSE; + np_handle* temphandle; + np_mimetype* temptype; - for (temphandle = np_plist; temphandle && !foundType; temphandle = temphandle->next) - { - for (temptype = temphandle->mimetypes; temptype && !foundType; temptype = temptype->next) - { - if (temptype->enabled && strcasecomp(temptype->type, type) == 0) - { - temptype->enabled = FALSE; - foundType = TRUE; - } - } - } - } + for (temphandle = np_plist; temphandle && !foundType; temphandle = temphandle->next) + { + for (temptype = temphandle->mimetypes; temptype && !foundType; temptype = temptype->next) + { + if (temptype->enabled && strcasecomp(temptype->type, type) == 0) + { + temptype->enabled = FALSE; + foundType = TRUE; + } + } + } + } - mimetype->enabled = enabled; + mimetype->enabled = enabled; - if (enabled) - { - /* - * Is this plugin the wildcard (a.k.a. null) plugin? - * If so, we don't want to register it for FO_PRESENT - * or it will interfere with our normal unknown-mime- - * type handling. - */ - XP_Bool wildtype = (strcmp(type, "*") == 0); + if (enabled) + { + /* + * Is this plugin the wildcard (a.k.a. null) plugin? + * If so, we don't want to register it for FO_PRESENT + * or it will interfere with our normal unknown-mime- + * type handling. + */ + XP_Bool wildtype = (strcmp(type, "*") == 0); #ifdef XP_WIN - /* EmbedStream does some Windows FE work and then calls NPL_NewStream */ - if (!wildtype) - NET_RegisterContentTypeConverter(type, FO_PRESENT, handle, EmbedStream); - NET_RegisterContentTypeConverter(type, FO_EMBED, handle, EmbedStream); /* XXX I dont think this does anything useful */ + /* EmbedStream does some Windows FE work and then calls NPL_NewStream */ + if (!wildtype) + NET_RegisterContentTypeConverter(type, FO_PRESENT, handle, EmbedStream); + NET_RegisterContentTypeConverter(type, FO_EMBED, handle, EmbedStream); /* XXX I dont think this does anything useful */ #else - if (!wildtype) - { - NET_RegisterContentTypeConverter(type, FO_PRESENT, handle, NPL_NewPresentStream); + if (!wildtype) + { + NET_RegisterContentTypeConverter(type, FO_PRESENT, handle, NPL_NewPresentStream); #ifdef XP_UNIX - /* While printing we use the FO_SAVE_AS_POSTSCRIPT format type. We want - * plugin to possibly handle that case too. Hence this. - */ - NET_RegisterContentTypeConverter(type, FO_SAVE_AS_POSTSCRIPT, handle, - NPL_NewPresentStream); + /* While printing we use the FO_SAVE_AS_POSTSCRIPT format type. We want + * plugin to possibly handle that case too. Hence this. + */ + NET_RegisterContentTypeConverter(type, FO_SAVE_AS_POSTSCRIPT, handle, + NPL_NewPresentStream); #endif /* XP_UNIX */ - } - NET_RegisterContentTypeConverter(type, FO_EMBED, handle, NPL_NewEmbedStream); + } + NET_RegisterContentTypeConverter(type, FO_EMBED, handle, NPL_NewEmbedStream); #endif - NET_RegisterContentTypeConverter(type, FO_PLUGIN, handle, np_newpluginstream); - NET_RegisterContentTypeConverter(type, FO_BYTERANGE, handle, np_newbyterangestream); - } + NET_RegisterContentTypeConverter(type, FO_PLUGIN, handle, np_newpluginstream); + NET_RegisterContentTypeConverter(type, FO_BYTERANGE, handle, np_newbyterangestream); + } } @@ -3663,16 +3757,16 @@ NPL_EnablePluginType(NPMIMEType type, void* pdesc, XP_Bool enabled) np_handle* handle; np_mimetype* mimetype; - if (!type) - return NPERR_INVALID_PARAM; + if (!type) + return NPERR_INVALID_PARAM; - np_findPluginType(type, pdesc, &handle, &mimetype); + np_findPluginType(type, pdesc, &handle, &mimetype); - if (!handle || !mimetype) - return NPERR_INVALID_PARAM; + if (!handle || !mimetype) + return NPERR_INVALID_PARAM; - np_enablePluginType(handle, mimetype, enabled); - return NPERR_NO_ERROR; + np_enablePluginType(handle, mimetype, enabled); + return NPERR_NO_ERROR; } @@ -3685,43 +3779,43 @@ NPL_RegisterPluginType(NPMIMEType type, const char *extensions, const char* desc np_mimetype* mimetype = NULL; NPTRACE(0,("np: register type %s", type)); - np_findPluginType(type, pdesc, &handle, &mimetype); + np_findPluginType(type, pdesc, &handle, &mimetype); - /* We have to find the handle to do anything */ - XP_ASSERT(handle); - if (!handle) - return NPERR_INVALID_PARAM; + /* We have to find the handle to do anything */ + XP_ASSERT(handle); + if (!handle) + return NPERR_INVALID_PARAM; - /*If no existing mime type, add a new type to this handle */ - if (!mimetype) - { - mimetype = XP_NEW_ZAP(np_mimetype); - if (!mimetype) - return NPERR_OUT_OF_MEMORY_ERROR; - mimetype->next = handle->mimetypes; - handle->mimetypes = mimetype; - mimetype->handle = handle; - StrAllocCopy(mimetype->type, type); - } + /*If no existing mime type, add a new type to this handle */ + if (!mimetype) + { + mimetype = XP_NEW_ZAP(np_mimetype); + if (!mimetype) + return NPERR_OUT_OF_MEMORY_ERROR; + mimetype->next = handle->mimetypes; + handle->mimetypes = mimetype; + mimetype->handle = handle; + StrAllocCopy(mimetype->type, type); + } - /* Enable this plug-in for this type and disable any others */ - np_enablePluginType(handle, mimetype, enabled); + /* Enable this plug-in for this type and disable any others */ + np_enablePluginType(handle, mimetype, enabled); - /* Get rid of old file association info, if any */ - if (mimetype->fassoc) - { - void* fileType; - fileType = NPL_DeleteFileAssociation(mimetype->fassoc); + /* Get rid of old file association info, if any */ + if (mimetype->fassoc) + { + void* fileType; + fileType = NPL_DeleteFileAssociation(mimetype->fassoc); #if 0 - /* Any FE that needs to free this, implement FE_FreeNPFileType */ - if (fileType) - FE_FreeNPFileType(fileType); + /* Any FE that needs to free this, implement FE_FreeNPFileType */ + if (fileType) + FE_FreeNPFileType(fileType); #endif - mimetype->fassoc = NULL; - } + mimetype->fassoc = NULL; + } - /* Make a new file association and register it with netlib if enabled */ - XP_ASSERT(extensions && description); + /* Make a new file association and register it with netlib if enabled */ + XP_ASSERT(extensions && description); mimetype->fassoc = NPL_NewFileAssociation(type, extensions, description, fileType); if (mimetype->fassoc && enabled) NPL_RegisterFileAssociation(mimetype->fassoc); @@ -3738,10 +3832,10 @@ NPL_RegisterPluginType(NPMIMEType type, const char *extensions, const char* desc void np_bindContext(NPEmbeddedApp* app, MWContext* cx) { - np_data* ndata; + np_data* ndata; - XP_ASSERT(app && cx); - XP_ASSERT(app->next == NULL); + XP_ASSERT(app && cx); + XP_ASSERT(app->next == NULL); if (cx->pluginList == NULL) /* no list yet, just insert item */ cx->pluginList = app; @@ -3758,7 +3852,7 @@ np_bindContext(NPEmbeddedApp* app, MWContext* cx) { np_instance* instance = (np_instance*) ndata->instance; if (instance) - instance->cx = cx; + instance->cx = cx; } } @@ -3766,9 +3860,9 @@ np_bindContext(NPEmbeddedApp* app, MWContext* cx) void np_unbindContext(NPEmbeddedApp* app, MWContext* cx) { - np_data* ndata; + np_data* ndata; - XP_ASSERT(app && cx); + XP_ASSERT(app && cx); if (app == cx->pluginList) cx->pluginList = app->next; @@ -3783,7 +3877,7 @@ np_unbindContext(NPEmbeddedApp* app, MWContext* cx) } } - app->next = NULL; + app->next = NULL; /* If there's an instance, clear the instance's context */ ndata = (np_data*) app->np_data; @@ -3791,7 +3885,7 @@ np_unbindContext(NPEmbeddedApp* app, MWContext* cx) { np_instance* instance = (np_instance*) ndata->instance; if (instance) - instance->cx = NULL; + instance->cx = NULL; } } @@ -3807,17 +3901,18 @@ np_delete_instance(np_instance *instance) /* nuke all open streams */ for(stream=instance->streams; stream;) { - np_stream *next = stream->next; + np_stream *next = stream->next; stream->dontclose = 0; if (stream->nstream) { /* Make sure the urls doesn't still point to us */ URL_Struct* urls = (URL_Struct*) stream->nstream->data_object; - if (urls) - urls->fe_data = NULL; + if (urls) { + NP_SET_URL_APP(urls, NULL); + } } np_destroystream(stream, NPRES_USER_BREAK); - stream = next; + stream = next; } instance->streams = 0; @@ -3826,20 +3921,15 @@ np_delete_instance(np_instance *instance) TRACEMSG(("npglue.c: CallNPP_DestroyProc")); if (np_is50StylePlugin(instance->handle)) { - nsPluginInstancePeer* peerInst = (nsPluginInstancePeer*)instance->npp->pdata; - nsIPluginInstance* pluginInst = peerInst->GetPluginInstance(); - + nsIPluginInstance* pluginInst = NP_GET_PLUGIN_INSTANCE(instance->npp); pluginInst->SetWindow(NULL); // tell the plugin instance the browser is through with it. nsresult err = pluginInst->Destroy(); XP_ASSERT(err == NS_OK); - pluginInst->Release(); - // break the reference cycle and release the instance peer. - peerInst->SetPluginInstance(NULL); - nsrefcnt cnt = peerInst->Release(); - XP_ASSERT(cnt == 0); + // releasing the instance will release the peer + pluginInst->Release(); // XXX Any other bookkeeping we need to do here? @@ -3856,28 +3946,28 @@ np_delete_instance(np_instance *instance) pnp->sdata = save; } #ifdef JAVA - /* - ** Break any association we have made between this instance and - ** its corresponding Java objTag. That way other java objects - ** still referring to it will be able to detect that the plugin - ** went away (by calling isActive). - */ - if (instance->javaInstance != NULL && - instance->javaInstance != NPN_NO_JAVA_INSTANCE) - { - /* Don't get the environment unless there is a Java instance, - because this would cause the java runtime to start up. */ - JRIEnv* env = npn_getJavaEnv(); - netscape_plugin_Plugin* javaInstance = (netscape_plugin_Plugin*) - JRI_GetGlobalRef(env, instance->javaInstance); + /* + ** Break any association we have made between this instance and + ** its corresponding Java objTag. That way other java objects + ** still referring to it will be able to detect that the plugin + ** went away (by calling isActive). + */ + if (instance->javaInstance != NULL && + instance->javaInstance != NPN_NO_JAVA_INSTANCE) + { + /* Don't get the environment unless there is a Java instance, + because this would cause the java runtime to start up. */ + JRIEnv* env = npn_getJavaEnv(); + netscape_plugin_Plugin* javaInstance = (netscape_plugin_Plugin*) + JRI_GetGlobalRef(env, instance->javaInstance); - /* upcall to the user's code */ - netscape_plugin_Plugin_destroy(env, javaInstance); + /* upcall to the user's code */ + netscape_plugin_Plugin_destroy(env, javaInstance); - set_netscape_plugin_Plugin_peer(env, javaInstance, 0); - JRI_DisposeGlobalRef(env, instance->javaInstance); - instance->javaInstance = NULL; - } + set_netscape_plugin_Plugin_peer(env, javaInstance, 0); + JRI_DisposeGlobalRef(env, instance->javaInstance); + instance->javaInstance = NULL; + } #endif /* JAVA */ /* If we come through here after having been unbound from @@ -3916,18 +4006,18 @@ np_delete_instance(np_instance *instance) XP_ASSERT(handle->refs>=0); if(!handle->refs) { - np_UnloadPluginClass(handle); + np_UnloadPluginClass(handle); } } - np_removeAllURLsFromList(instance); + np_removeAllURLsFromList(instance); - if (instance->typeString) - XP_FREE(instance->typeString); + if (instance->typeString) + XP_FREE(instance->typeString); #ifdef PLUGIN_TIMER_EVENT - if(instance->timeout) - FE_ClearTimeout(instance->timeout); + if(instance->timeout) + FE_ClearTimeout(instance->timeout); #endif XP_FREE(instance); @@ -3940,15 +4030,15 @@ np_noembedfound (FO_Present_Types format_out, void *type, URL_Struct *urls, MWContext *cx) { - char *msg = PR_smprintf(XP_GetString(XP_PLUGIN_NOT_FOUND), - urls->content_type); - if(msg) - { - FE_Alert(cx, msg); - XP_FREE(msg); - } + char *msg = PR_smprintf(XP_GetString(XP_PLUGIN_NOT_FOUND), + urls->content_type); + if(msg) + { + FE_Alert(cx, msg); + XP_FREE(msg); + } - return(NULL); + return(NULL); } #endif /* XP_UNIX */ @@ -3984,10 +4074,10 @@ NPL_Init() #endif /* Register all default plugin converters. Do this before - * FE_RegisterPlugins() because this registers a not found converter - * for "*" and FE can override that with the nullplugin if one is - * available. - */ + * FE_RegisterPlugins() because this registers a not found converter + * for "*" and FE can override that with the nullplugin if one is + * available. + */ NPL_RegisterDefaultConverters(); /* ** Initialize caps manager so that factory for nsCCapsManager gets registered. @@ -4050,8 +4140,8 @@ NPL_Shutdown() /* beard: since we initialize refs to 1, we have to reduce it to zero here. */ if (dh->refs > 0) { dh->refs--; - np_UnloadPluginClass(dh); - } + np_UnloadPluginClass(dh); + } } } @@ -4064,17 +4154,17 @@ NPL_Shutdown() void NPL_SameElement(LO_EmbedStruct* embed_struct) { - if (embed_struct) - { - NPEmbeddedApp* app = (NPEmbeddedApp*) embed_struct->objTag.FE_Data; - if (app) - { - np_data* ndata = (np_data*) app->np_data; - XP_ASSERT(ndata); - if (ndata && ndata->state != NPDataSaved) - ndata->state = NPDataCache; - } - } + if (embed_struct) + { + NPEmbeddedApp* app = (NPEmbeddedApp*) embed_struct->objTag.FE_Data; + if (app) + { + np_data* ndata = (np_data*) app->np_data; + XP_ASSERT(ndata); + if (ndata && ndata->state != NPDataSaved) + ndata->state = NPDataCache; + } + } } @@ -4089,28 +4179,28 @@ NPL_SameElement(LO_EmbedStruct* embed_struct) void NPL_SamePage(MWContext* resizedContext) { - MWContext* cx; - XP_List* children; - NPEmbeddedApp* app; + MWContext* cx; + XP_List* children; + NPEmbeddedApp* app; - if (!resizedContext) - return; + if (!resizedContext) + return; - /* Mark all plug-ins in this context */ - app = resizedContext->pluginList; - while (app) - { - np_data* ndata = (np_data*) app->np_data; - XP_ASSERT(ndata); - if (ndata && ndata->state != NPDataSaved) - ndata->state = NPDataCache; - app = app->next; - } + /* Mark all plug-ins in this context */ + app = resizedContext->pluginList; + while (app) + { + np_data* ndata = (np_data*) app->np_data; + XP_ASSERT(ndata); + if (ndata && ndata->state != NPDataSaved) + ndata->state = NPDataCache; + app = app->next; + } - /* Recursively traverse child contexts */ - children = resizedContext->grid_children; - while ((cx = (MWContext*)XP_ListNextObject(children)) != NULL) - NPL_SamePage(cx); + /* Recursively traverse child contexts */ + children = resizedContext->grid_children; + while ((cx = (MWContext*)XP_ListNextObject(children)) != NULL) + NPL_SamePage(cx); } int @@ -4125,8 +4215,7 @@ NPL_HandleEvent(NPEmbeddedApp *app, void *event, void* window) if (handle) { TRACEMSG(("npglue.c: CallNPP_HandleEventProc")); if (handle->userPlugin) { - nsPluginInstancePeer* peerInst = (nsPluginInstancePeer*)ndata->instance->npp->pdata; - nsIPluginInstance* pluginInst = peerInst->GetPluginInstance(); + nsIPluginInstance* pluginInst = NP_GET_PLUGIN_INSTANCE(ndata->instance->npp); if (pluginInst == NULL) return 0; @@ -4151,9 +4240,8 @@ NPL_HandleEvent(NPEmbeddedApp *app, void *event, void* window) XP_MEMCPY(&newEvent.event, event, sizeof(XEvent)); // we don't need window for unix -- it's already in the event #endif - PRBool eventHandled = PR_FALSE; + PRBool eventHandled = PR_FALSE; nsresult result = pluginInst->HandleEvent(&newEvent, &eventHandled); - pluginInst->Release(); return eventHandled; } else if (handle->f && ISFUNCPTR(handle->f->event)) { @@ -4171,7 +4259,7 @@ void npn_registerwindow(nsIEventHandler* handler, nsPluginPlatformWindowRef wind { #ifdef XP_MAC #if 1 - FE_RegisterWindow(handler, window); + FE_RegisterWindow(handler, window); #else if (npp) { np_instance* instance = (np_instance*) npp->ndata; @@ -4185,7 +4273,7 @@ void npn_unregisterwindow(nsIEventHandler* handler, nsPluginPlatformWindowRef wi { #ifdef XP_MAC #if 1 - FE_UnregisterWindow(handler, window); + FE_UnregisterWindow(handler, window); #else if(npp) { np_instance* instance = (np_instance*) npp->ndata; @@ -4231,54 +4319,50 @@ NPL_Print(NPEmbeddedApp *app, void *pdata) np_handle *handle = ndata->instance->handle; if(handle) { - NPPrint * nppr = (NPPrint *)pdata; - if (nppr && (nppr->mode == NP_EMBED) && !npn_IsWindowless(handle)) - { - /* - If old (pre-4.0) plugin version, have to the "platformPrint" void * up, - because window.type didn't previously exist. + NPPrint * nppr = (NPPrint *)pdata; + if (nppr && (nppr->mode == NP_EMBED) && !npn_IsWindowless(handle)) + { + /* + If old (pre-4.0) plugin version, have to the "platformPrint" void * up, + because window.type didn't previously exist. - check plugin version: - Major,Minor version = 0,11 or greater => 4.0, - else < 4.0 - */ + check plugin version: + Major,Minor version = 0,11 or greater => 4.0, + else < 4.0 + */ - NPWindowType old_type = nppr->print.embedPrint.window.type; - void * addr1 = (void *)&nppr->print.embedPrint.window.type; + NPWindowType old_type = nppr->print.embedPrint.window.type; + void * addr1 = (void *)&nppr->print.embedPrint.window.type; - void * old_plat_print = nppr->print.embedPrint.platformPrint; - void * addr2 = (void *)&nppr->print.embedPrint.platformPrint; + void * old_plat_print = nppr->print.embedPrint.platformPrint; + void * addr2 = (void *)&nppr->print.embedPrint.platformPrint; - XP_MEMCPY(addr1,addr2,sizeof(nppr->print.embedPrint.platformPrint)); + XP_MEMCPY(addr1,addr2,sizeof(nppr->print.embedPrint.platformPrint)); - TRACEMSG(("npglue.c: CallNPP_PrintProc(1)")); + TRACEMSG(("npglue.c: CallNPP_PrintProc(1)")); if (handle->userPlugin) { - nsPluginInstancePeer* peerInst = (nsPluginInstancePeer*)ndata->instance->npp->pdata; - nsIPluginInstance* pluginInst = peerInst->GetPluginInstance(); + nsIPluginInstance* pluginInst = NP_GET_PLUGIN_INSTANCE(ndata->instance->npp); pluginInst->Print((nsPluginPrint*)pdata); - pluginInst->Release(); } else if (handle->f && ISFUNCPTR(handle->f->print)) { CallNPP_PrintProc(handle->f->print, ndata->instance->npp, (NPPrint*)pdata); } - /* Now restore for downstream dependencies */ - nppr->print.embedPrint.window.type = old_type; - nppr->print.embedPrint.platformPrint = old_plat_print; + /* Now restore for downstream dependencies */ + nppr->print.embedPrint.window.type = old_type; + nppr->print.embedPrint.platformPrint = old_plat_print; - } - else{ - TRACEMSG(("npglue.c: CallNPP_PrintProc(2)")); + } + else{ + TRACEMSG(("npglue.c: CallNPP_PrintProc(2)")); if (handle->userPlugin) { - nsPluginInstancePeer* peerInst = (nsPluginInstancePeer*)ndata->instance->npp->pdata; - nsIPluginInstance* pluginInst = peerInst->GetPluginInstance(); + nsIPluginInstance* pluginInst = NP_GET_PLUGIN_INSTANCE(ndata->instance->npp); pluginInst->Print((nsPluginPrint*)pdata); - pluginInst->Release(); } else if (handle->f && ISFUNCPTR(handle->f->print)) { CallNPP_PrintProc(handle->f->print, ndata->instance->npp, (NPPrint*)pdata); } - } + } } } @@ -4288,13 +4372,13 @@ NPL_Print(NPEmbeddedApp *app, void *pdata) void np_deleteapp(MWContext* cx, NPEmbeddedApp* app) { - if (app) - { - if (cx) - np_unbindContext(app, cx); + if (app) + { + if (cx) + np_unbindContext(app, cx); XP_FREE(app); - } + } } /* @@ -4307,14 +4391,14 @@ np_deleteapp(MWContext* cx, NPEmbeddedApp* app) extern void NPL_EmbedDelete(MWContext* cx, LO_EmbedStruct* embed_struct) { - NPEmbeddedApp* app; - np_data* ndata; + NPEmbeddedApp* app; + np_data* ndata; - if (!cx || !embed_struct || !embed_struct->objTag.FE_Data) - return; + if (!cx || !embed_struct || !embed_struct->objTag.FE_Data) + return; - app = (NPEmbeddedApp*) embed_struct->objTag.FE_Data; - embed_struct->objTag.FE_Data = NULL; + app = (NPEmbeddedApp*) embed_struct->objTag.FE_Data; + embed_struct->objTag.FE_Data = NULL; ndata = (np_data*) app->np_data; @@ -4324,27 +4408,27 @@ NPL_EmbedDelete(MWContext* cx, LO_EmbedStruct* embed_struct) ndata->refs--; - /* -1 case is added. It happens when this is fake object */ + /* -1 case is added. It happens when this is fake object */ // XXX I think that "fake objects" should no longer be // required now that we actually have a front-end callback to // destroy the window. - XP_ASSERT(/* ndata->refs == -1 || */ ndata->refs == 0 || ndata->refs == 1); + XP_ASSERT(/* ndata->refs == -1 || */ ndata->refs == 0 || ndata->refs == 1); if (ndata->refs > 0) { - /* When done printing, don't delete and don't save session data */ - XP_ASSERT(cx->type == MWContextPrint || cx->type == MWContextMetaFile || - cx->type == MWContextPostScript); - ndata->state = NPDataCached; + /* When done printing, don't delete and don't save session data */ + XP_ASSERT(cx->type == MWContextPrint || cx->type == MWContextMetaFile || + cx->type == MWContextPostScript); + ndata->state = NPDataCached; /* Tell the front-end to save the embedded window for us */ FE_SaveEmbedWindow(cx, app); return; - } - else if (ndata->state == NPDataCache) + } + else if (ndata->state == NPDataCache) { /* Someone is telling us to cache the window; e.g., during a nasty resize */ - XP_ASSERT(ndata->app); + XP_ASSERT(ndata->app); ndata->state = NPDataCached; ndata->lo_struct = NULL; /* Remove ref to layout structure since it's about to be deleted */ np_unbindContext(app, cx); /* Remove ref to context since it may change */ @@ -4364,11 +4448,9 @@ NPL_EmbedDelete(MWContext* cx, LO_EmbedStruct* embed_struct) /* XXX We could just get the _real_ instance by traversing ndata->sdata, but that scares me for some reason. */ - nsPluginInstancePeer* peerInst = (nsPluginInstancePeer*) ndata->instance->npp->pdata; - nsIPluginInstance* pluginInst = peerInst->GetPluginInstance(); + nsIPluginInstance* pluginInst = NP_GET_PLUGIN_INSTANCE(ndata->instance->npp); nsresult err = pluginInst->Stop(); - pluginInst->Release(); if (err == NS_OK) { /* XXX So I'm going out on a limb here and saying that by keeping the plugin in a "cached" state, we @@ -4403,10 +4485,10 @@ NPL_EmbedDelete(MWContext* cx, LO_EmbedStruct* embed_struct) } else { - /* If there's no instance, there's no need to save session data */ - embed_struct->objTag.session_data = NULL; - app->np_data = NULL; - XP_FREE(ndata); + /* If there's no instance, there's no need to save session data */ + embed_struct->objTag.session_data = NULL; + app->np_data = NULL; + XP_FREE(ndata); } } @@ -4425,26 +4507,26 @@ NPL_EmbedDelete(MWContext* cx, LO_EmbedStruct* embed_struct) void NPL_PreparePrint(MWContext* context, SHIST_SavedData* savedData) { - NPEmbeddedApp* app; + NPEmbeddedApp* app; - XP_ASSERT(context && savedData); - if (!context || !savedData) - return; + XP_ASSERT(context && savedData); + if (!context || !savedData) + return; - for (app = context->pluginList; app != NULL; app = app->next) - { - np_data* ndata = (np_data*)app->np_data; - XP_ASSERT(ndata); - if (ndata && ndata->lo_struct) - { - /* ignore this assert if the plugin is hidden */ - XP_ASSERT(ndata->state == NPDataNormal); - ndata->state = NPDataCached; - LO_AddEmbedData(context, ndata->lo_struct, ndata); - } - } + for (app = context->pluginList; app != NULL; app = app->next) + { + np_data* ndata = (np_data*)app->np_data; + XP_ASSERT(ndata); + if (ndata && ndata->lo_struct) + { + /* ignore this assert if the plugin is hidden */ + XP_ASSERT(ndata->state == NPDataNormal); + ndata->state = NPDataCached; + LO_AddEmbedData(context, ndata->lo_struct, ndata); + } + } - LO_CopySavedEmbedData(context, savedData); + LO_CopySavedEmbedData(context, savedData); } @@ -4456,20 +4538,20 @@ NPL_PreparePrint(MWContext* context, SHIST_SavedData* savedData) static char* np_findTypeAttribute(LO_EmbedStruct* embed_struct) { - char* typeAttribute = NULL; - unsigned int i; + char* typeAttribute = NULL; + unsigned int i; - /* Look for the TYPE attribute */ - for (i = 0; i < embed_struct->attributes.n; i++) - { - if (XP_STRCASECMP(embed_struct->attributes.names[i], "TYPE") == 0) - { - typeAttribute = embed_struct->attributes.values[i]; - break; - } - } + /* Look for the TYPE attribute */ + for (i = 0; i < embed_struct->attributes.n; i++) + { + if (XP_STRCASECMP(embed_struct->attributes.names[i], "TYPE") == 0) + { + typeAttribute = embed_struct->attributes.values[i]; + break; + } + } - return typeAttribute; + return typeAttribute; } void @@ -4573,8 +4655,7 @@ NPL_GetText(LO_CommonPluginStruct* lo_embed) if (instance == NULL) return NULL; - nsPluginInstancePeer* peerInst = (nsPluginInstancePeer*)instance->npp->pdata; - nsIPluginInstance* pluginInst = peerInst->GetPluginInstance(); + nsIPluginInstance* pluginInst = NP_GET_PLUGIN_INSTANCE(instance->npp); if (pluginInst == NULL) return NULL; @@ -4584,7 +4665,6 @@ NPL_GetText(LO_CommonPluginStruct* lo_embed) PR_ASSERT(err == NS_OK); jvmInst->Release(); } - pluginInst->Release(); #endif return text; } @@ -4593,7 +4673,7 @@ PR_IMPLEMENT(jobject) NPL_GetJavaObject(LO_CommonPluginStruct* lo_embed) { jobject javaobject = NULL; -#if OJI +#ifdef OJI NPEmbeddedApp *embed = (NPEmbeddedApp*) lo_embed->FE_Data; if (embed == NULL) return NULL; @@ -4602,8 +4682,7 @@ NPL_GetJavaObject(LO_CommonPluginStruct* lo_embed) if (instance == NULL) return NULL; - nsPluginInstancePeer* peerInst = (nsPluginInstancePeer*)instance->npp->pdata; - nsIPluginInstance* pluginInst = peerInst->GetPluginInstance(); + nsIPluginInstance* pluginInst = NP_GET_PLUGIN_INSTANCE(instance->npp); if (pluginInst == NULL) return NULL; @@ -4613,7 +4692,6 @@ NPL_GetJavaObject(LO_CommonPluginStruct* lo_embed) PR_ASSERT(err == NS_OK); jvmInst->Release(); } - pluginInst->Release(); #endif return javaobject; } @@ -4650,36 +4728,36 @@ NPL_EmbedCreate(MWContext* cx, LO_EmbedStruct* embed_struct) if (ndata->state == NPDataCached) /* We cached this app, so don't create another */ { - XP_ASSERT(ndata->app); - if (cx->type == MWContextPrint || + XP_ASSERT(ndata->app); + if (cx->type == MWContextPrint || cx->type == MWContextMetaFile || - cx->type == MWContextPostScript) - { + cx->type == MWContextPostScript) + { /* This is a printing "instance" that we're restoring from the session data */ - if (ndata->app->pagePluginType == NP_FullPage) - { - np_reconnect* reconnect; - if (!cx->pluginReconnect) - cx->pluginReconnect = XP_NEW_ZAP(np_reconnect); - reconnect = (np_reconnect*) cx->pluginReconnect; - if (reconnect) - reconnect->app = ndata->app; - } + if (ndata->app->pagePluginType == NP_FullPage) + { + np_reconnect* reconnect; + if (!cx->pluginReconnect) + cx->pluginReconnect = XP_NEW_ZAP(np_reconnect); + reconnect = (np_reconnect*) cx->pluginReconnect; + if (reconnect) + reconnect->app = ndata->app; + } #ifdef LAYERS if ((cx->compositor) && ndata->instance) { LO_SetEmbedType(embed_struct, (PRBool)ndata->instance->windowed); } #endif /* LAYERS */ - } - else - { + } + else + { /* It's a real instance that we're restoring from the session data */ - ndata->lo_struct = embed_struct; /* Set reference to new layout structure */ - np_bindContext(ndata->app, cx); /* Set reference to (potentially) new context */ - ndata->state = NPDataNormal; + ndata->lo_struct = embed_struct; /* Set reference to new layout structure */ + np_bindContext(ndata->app, cx); /* Set reference to (potentially) new context */ + ndata->state = NPDataNormal; #ifdef LAYERS if (ndata->instance) { ndata->instance->layer = embed_struct->objTag.layer; @@ -4712,28 +4790,28 @@ NPL_EmbedCreate(MWContext* cx, LO_EmbedStruct* embed_struct) /* Tie the app to the layout struct. */ embed_struct->objTag.FE_Data = ndata->app; - return ndata->app; - } + return ndata->app; + } /* If not cached, it's just saved data. (XXX NPL_StartPlugin will take care of re-constituting it?) */ - XP_ASSERT(ndata->state == NPDataSaved); - XP_ASSERT(ndata->app == NULL); - XP_ASSERT(ndata->instance == NULL); - XP_ASSERT(ndata->lo_struct == NULL); - XP_ASSERT(ndata->streamStarted == FALSE); - XP_ASSERT(ndata->refs == 0); + XP_ASSERT(ndata->state == NPDataSaved); + XP_ASSERT(ndata->app == NULL); + XP_ASSERT(ndata->instance == NULL); + XP_ASSERT(ndata->lo_struct == NULL); + XP_ASSERT(ndata->streamStarted == FALSE); + XP_ASSERT(ndata->refs == 0); } /* So now we either have a "saved" pre-5.0 style plugin, or a brand new plugin. */ - if (!ndata) + if (!ndata) { ndata = XP_NEW_ZAP(np_data); if (!ndata) - goto error; + goto error; } - ndata->state = NPDataNormal; + ndata->state = NPDataNormal; ndata->lo_struct = embed_struct; /* @@ -4745,8 +4823,8 @@ NPL_EmbedCreate(MWContext* cx, LO_EmbedStruct* embed_struct) app->np_data = (void*) ndata; app->type = NP_Untyped; ndata->refs = 1; - ndata->app = app; - np_bindContext(app, cx); + ndata->app = app; + np_bindContext(app, cx); /* Tell the front-end to create the plugin window for us. */ if (! (embed_struct->objTag.ele_attrmask & LO_ELE_HIDDEN)) @@ -4756,21 +4834,21 @@ NPL_EmbedCreate(MWContext* cx, LO_EmbedStruct* embed_struct) embed_struct->objTag.FE_Data = ndata->app; return app; -error: - if (app) - np_deleteapp(cx, app); /* Unlink app from context and delete app */ - if (ndata) - XP_FREE(ndata); - return NULL; + error: + if (app) + np_deleteapp(cx, app); /* Unlink app from context and delete app */ + if (ndata) + XP_FREE(ndata); + return NULL; } NPError NPL_EmbedStart(MWContext* cx, LO_EmbedStruct* embed_struct, NPEmbeddedApp* app) { - np_handle* handle; - np_mimetype* mimetype; - char* typeAttribute; + np_handle* handle; + np_mimetype* mimetype; + char* typeAttribute; np_data* ndata = NULL; if (!cx || !embed_struct || !app) @@ -4792,126 +4870,126 @@ NPL_EmbedStart(MWContext* cx, LO_EmbedStruct* embed_struct, NPEmbeddedApp* app) return NPERR_NO_ERROR; ndata->streamStarted = TRUE; /* Remember that we've been here */ - /* - * First check for a TYPE attribute. The type specified - * will override the MIME type of the SRC (if present). - */ - typeAttribute = np_findTypeAttribute(embed_struct); - if (typeAttribute) - { - /* Only embedded plug-ins can have a TYPE attribute */ - app->pagePluginType = NP_Embedded; + /* + * First check for a TYPE attribute. The type specified + * will override the MIME type of the SRC (if present). + */ + typeAttribute = np_findTypeAttribute(embed_struct); + if (typeAttribute) + { + /* Only embedded plug-ins can have a TYPE attribute */ + app->pagePluginType = NP_Embedded; - /* Found the TYPE attribute, so look for a matching handler */ + /* Found the TYPE attribute, so look for a matching handler */ np_FindHandleByType(typeAttribute, &handle, &mimetype); - /* - * If we found a handler, now we can create an instance. - * If we didn't find a handler, we have to use the SRC - * to determine the MIME type later (so there better be - * SRC, or it's an error). - */ - if (mimetype) - { - ndata->instance = np_newinstance(handle, cx, app, mimetype, typeAttribute); - if (ndata->instance == NULL) - goto error; + /* + * If we found a handler, now we can create an instance. + * If we didn't find a handler, we have to use the SRC + * to determine the MIME type later (so there better be + * SRC, or it's an error). + */ + if (mimetype) + { + ndata->instance = np_newinstance(handle, cx, app, mimetype, typeAttribute); + if (ndata->instance == NULL) + goto error; #ifdef LAYERS LO_SetEmbedType(ndata->lo_struct, (PRBool) ndata->instance->windowed); #endif - } - } + } + } - /* - * Now check for the SRC attribute. - * - If it's full-page, create a instance now since we already - * know the MIME type (NPL_NewStream has already happened). - * - If it's embedded, create a stream for the URL (we'll create - * the instance when we get the stream in NPL_NewStream). - */ + /* + * Now check for the SRC attribute. + * - If it's full-page, create a instance now since we already + * know the MIME type (NPL_NewStream has already happened). + * - If it's embedded, create a stream for the URL (we'll create + * the instance when we get the stream in NPL_NewStream). + */ if (embed_struct->embed_src) { - char* theURL; - PA_LOCK(theURL, char*, embed_struct->embed_src); - XP_ASSERT(theURL); - if (XP_STRCMP(theURL, "internal-external-plugin") == 0) - { - /* - * Full-page case: Stream already exists, so now - * we can create the instance. - */ - np_reconnect* reconnect; - np_mimetype* mimetype; - np_handle* handle; - np_instance* instance; - char* requestedtype; + char* theURL; + PA_LOCK(theURL, char*, embed_struct->embed_src); + XP_ASSERT(theURL); + if (XP_STRCMP(theURL, "internal-external-plugin") == 0) + { + /* + * Full-page case: Stream already exists, so now + * we can create the instance. + */ + np_reconnect* reconnect; + np_mimetype* mimetype; + np_handle* handle; + np_instance* instance; + char* requestedtype; - app->pagePluginType = NP_FullPage; + app->pagePluginType = NP_FullPage; - reconnect = (np_reconnect*) cx->pluginReconnect; - XP_ASSERT(reconnect); - if (!reconnect) - { - PA_UNLOCK(embed_struct->embed_src); - goto error; - } + reconnect = (np_reconnect*) cx->pluginReconnect; + XP_ASSERT(reconnect); + if (!reconnect) + { + PA_UNLOCK(embed_struct->embed_src); + goto error; + } - mimetype = reconnect->mimetype; - requestedtype = reconnect->requestedtype; - handle = mimetype->handle; + mimetype = reconnect->mimetype; + requestedtype = reconnect->requestedtype; + handle = mimetype->handle; - /* Now we can create the instance */ - XP_ASSERT(ndata->instance == NULL); - instance = np_newinstance(handle, cx, app, mimetype, requestedtype); - if (!instance) - { - PA_UNLOCK(embed_struct->embed_src); - goto error; - } + /* Now we can create the instance */ + XP_ASSERT(ndata->instance == NULL); + instance = np_newinstance(handle, cx, app, mimetype, requestedtype); + if (!instance) + { + PA_UNLOCK(embed_struct->embed_src); + goto error; + } - reconnect->app = app; - ndata->instance = instance; - ndata->handle = handle; - ndata->instance->app = app; - FE_ShowScrollBars(cx, FALSE); + reconnect->app = app; + ndata->instance = instance; + ndata->handle = handle; + ndata->instance->app = app; + FE_ShowScrollBars(cx, FALSE); #ifdef LAYERS LO_SetEmbedType(ndata->lo_struct, (PRBool) ndata->instance->windowed); #endif - } - else - { - /* - * Embedded case: Stream doesn't exist yet, so - * we need to create it before we can make the - * instance (exception: if there was a TYPE tag, - * we already know the MIME type so the instance - * already exists). - */ - app->pagePluginType = NP_Embedded; + } + else + { + /* + * Embedded case: Stream doesn't exist yet, so + * we need to create it before we can make the + * instance (exception: if there was a TYPE tag, + * we already know the MIME type so the instance + * already exists). + */ + app->pagePluginType = NP_Embedded; - if ((embed_struct->objTag.ele_attrmask & LO_ELE_STREAM_STARTED) == 0) - { - URL_Struct* pURL; - pURL = NET_CreateURLStruct(theURL, NET_DONT_RELOAD); - pURL->fe_data = (void*) app; + if ((embed_struct->objTag.ele_attrmask & LO_ELE_STREAM_STARTED) == 0) + { + URL_Struct* pURL; + pURL = NET_CreateURLStruct(theURL, NET_DONT_RELOAD); + NP_SET_URL_APP(pURL, app); - /* start a stream */ - (void) NET_GetURL(pURL, FO_CACHE_AND_EMBED, cx, NPL_EmbedURLExit); - } - } + /* start a stream */ + (void) NET_GetURL(pURL, FO_CACHE_AND_EMBED, cx, NPL_EmbedURLExit); + } + } - PA_UNLOCK(embed_struct->embed_src); - } + PA_UNLOCK(embed_struct->embed_src); + } - return NPERR_NO_ERROR; + return NPERR_NO_ERROR; -error: - if (cx && app) - np_deleteapp(cx, app); /* Unlink app from context and delete app */ - if (ndata) - XP_FREE(ndata); - return NPERR_GENERIC_ERROR; + error: + if (cx && app) + np_deleteapp(cx, app); /* Unlink app from context and delete app */ + if (ndata) + XP_FREE(ndata); + return NPERR_GENERIC_ERROR; } @@ -4935,9 +5013,9 @@ NPL_EmbedSize(NPEmbeddedApp *app) int32 NPL_GetEmbedReferenceCount(NPEmbeddedApp *app) { - np_data *ndata = (np_data *)app->np_data; - int32 iRet = ndata->refs; - return iRet; + np_data *ndata = (np_data *)app->np_data; + int32 iRet = ndata->refs; + return iRet; } XP_Bool @@ -5041,35 +5119,35 @@ NPL_DeleteSessionData(MWContext* context, void* sdata) * so check session_data which is zeroed in this case */ if(bFreeSessionData) - { - /* - * Saved instance data case - * - * This case occurs when session history is deleted for - * a document that previously contained a plug-in. - * The plug-in may have given us a NPSavedData structure - * to store for it, which we must delete here. - */ - XP_ASSERT(ndata->state == NPDataSaved); - XP_ASSERT(ndata->app == NULL); - XP_ASSERT(ndata->streamStarted == FALSE); + { + /* + * Saved instance data case + * + * This case occurs when session history is deleted for + * a document that previously contained a plug-in. + * The plug-in may have given us a NPSavedData structure + * to store for it, which we must delete here. + */ + XP_ASSERT(ndata->state == NPDataSaved); + XP_ASSERT(ndata->app == NULL); + XP_ASSERT(ndata->streamStarted == FALSE); - // XXX I don't think we should ever get here with a - // 5.0-style (C++) plugin since, by default, they cache - // themselves. Throw in an assert just to make sure... - XP_ASSERT(ndata->instance == NULL || !np_is50StylePlugin(ndata->instance->handle)); + // XXX I don't think we should ever get here with a + // 5.0-style (C++) plugin since, by default, they cache + // themselves. Throw in an assert just to make sure... + XP_ASSERT(ndata->instance == NULL || !np_is50StylePlugin(ndata->instance->handle)); - if (ndata->sdata) { - if (ndata->sdata->buf) - XP_FREE(ndata->sdata->buf); - XP_FREE(ndata->sdata); - ndata->sdata = 0; - } - - ndata->handle = NULL; - XP_FREE(ndata); + if (ndata->sdata) { + if (ndata->sdata->buf) + XP_FREE(ndata->sdata->buf); + XP_FREE(ndata->sdata); + ndata->sdata = 0; } + ndata->handle = NULL; + XP_FREE(ndata); + } + // XXX Err...what's the point? ndata = NULL; } @@ -5078,25 +5156,25 @@ NPL_DeleteSessionData(MWContext* context, void* sdata) NPBool NPL_IteratePluginFiles(NPReference* ref, char** name, char** filename, char** description) { - np_handle* handle; + np_handle* handle; - if (*ref == NPRefFromStart) - handle = np_plist; - else - handle = ((np_handle*) *ref)->next; + if (*ref == NPRefFromStart) + handle = np_plist; + else + handle = ((np_handle*) *ref)->next; - if (handle) - { - if (name) - *name = handle->name; - if (filename) - *filename = handle->filename; - if (description) - *description = handle->description; - } + if (handle) + { + if (name) + *name = handle->name; + if (filename) + *filename = handle->filename; + if (description) + *description = handle->description; + } - *ref = handle; - return (handle != NULL); + *ref = handle; + return (handle != NULL); } @@ -5104,28 +5182,28 @@ NPBool NPL_IteratePluginTypes(NPReference* ref, NPReference plugin, NPMIMEType* type, char*** extents, char** description, void** fileType) { - np_handle* handle = (np_handle*) plugin; - np_mimetype* mimetype; + np_handle* handle = (np_handle*) plugin; + np_mimetype* mimetype; - if (*ref == NPRefFromStart) - mimetype = handle->mimetypes; - else - mimetype = ((np_mimetype*) *ref)->next; + if (*ref == NPRefFromStart) + mimetype = handle->mimetypes; + else + mimetype = ((np_mimetype*) *ref)->next; - if (mimetype) - { - if (type) - *type = mimetype->type; - if (description) - *description = mimetype->fassoc->description; - if (extents) - *extents = mimetype->fassoc->extentlist; - if (fileType) - *fileType = mimetype->fassoc->fileType; - } + if (mimetype) + { + if (type) + *type = mimetype->type; + if (description) + *description = mimetype->fassoc->description; + if (extents) + *extents = mimetype->fassoc->extentlist; + if (fileType) + *fileType = mimetype->fassoc->fileType; + } - *ref = mimetype; - return (mimetype != NULL); + *ref = mimetype; + return (mimetype != NULL); } @@ -5142,53 +5220,53 @@ NPL_IteratePluginTypes(NPReference* ref, NPReference plugin, NPMIMEType* type, c PR_IMPLEMENT(char**) NPL_FindPluginsForType(const char* typeToFind) { - char** result; - uint32 count = 0; + char** result; + uint32 count = 0; - /* First count plug-ins that support this type */ - { - NPReference plugin = NPRefFromStart; - while (NPL_IteratePluginFiles(&plugin, NULL, NULL, NULL)) - { - char* type; - NPReference mimetype = NPRefFromStart; - while (NPL_IteratePluginTypes(&mimetype, plugin, &type, NULL, NULL, NULL)) - { - if (strcmp(type, typeToFind) == 0) - count++; - } - } - } + /* First count plug-ins that support this type */ + { + NPReference plugin = NPRefFromStart; + while (NPL_IteratePluginFiles(&plugin, NULL, NULL, NULL)) + { + char* type; + NPReference mimetype = NPRefFromStart; + while (NPL_IteratePluginTypes(&mimetype, plugin, &type, NULL, NULL, NULL)) + { + if (strcmp(type, typeToFind) == 0) + count++; + } + } + } - /* Bail if no plug-ins match this type */ - if (count == 0) - return NULL; + /* Bail if no plug-ins match this type */ + if (count == 0) + return NULL; - /* Make an array big enough to hold the plug-ins */ - result = (char**) XP_ALLOC((count + 1) * sizeof(char*)); - if (!result) - return NULL; + /* Make an array big enough to hold the plug-ins */ + result = (char**) XP_ALLOC((count + 1) * sizeof(char*)); + if (!result) + return NULL; - /* Look for plug-ins that support this type and put them in the array */ - count = 0; - { - char* name; - NPReference plugin = NPRefFromStart; - while (NPL_IteratePluginFiles(&plugin, &name, NULL, NULL)) - { - char* type; - NPReference mimetype = NPRefFromStart; - while (NPL_IteratePluginTypes(&mimetype, plugin, &type, NULL, NULL, NULL)) - { - if (strcmp(type, typeToFind) == 0) - result[count++] = XP_STRDUP(name); - } - } - } + /* Look for plug-ins that support this type and put them in the array */ + count = 0; + { + char* name; + NPReference plugin = NPRefFromStart; + while (NPL_IteratePluginFiles(&plugin, &name, NULL, NULL)) + { + char* type; + NPReference mimetype = NPRefFromStart; + while (NPL_IteratePluginTypes(&mimetype, plugin, &type, NULL, NULL, NULL)) + { + if (strcmp(type, typeToFind) == 0) + result[count++] = XP_STRDUP(name); + } + } + } - /* Null-terminate the array and return it */ - result[count] = NULL; - return result; + /* Null-terminate the array and return it */ + result[count] = NULL; + return result; } @@ -5200,21 +5278,21 @@ NPL_FindPluginsForType(const char* typeToFind) char* NPL_FindPluginEnabledForType(const char* typeToFind) { - np_handle* handle = np_plist; - while (handle) - { - np_mimetype* mimetype = handle->mimetypes; - while (mimetype) - { - if ((strcmp(mimetype->type, typeToFind) == 0) && mimetype->enabled) - return XP_STRDUP(handle->name); - mimetype = mimetype->next; - } + np_handle* handle = np_plist; + while (handle) + { + np_mimetype* mimetype = handle->mimetypes; + while (mimetype) + { + if ((strcmp(mimetype->type, typeToFind) == 0) && mimetype->enabled) + return XP_STRDUP(handle->name); + mimetype = mimetype->next; + } - handle = handle->next; - } + handle = handle->next; + } - return NULL; + return NULL; } @@ -5246,16 +5324,16 @@ NPL_DisplayPluginsAsHTML(FO_Present_Types format_out, URL_Struct *urls, MWContex if (!stream) return; - if (np_plist) - { - PUT("Installed plug-ins
"); - } - else - { - PUT("No plug-ins are installed.
"); - } + if (np_plist) + { + PUT("Installed plug-ins
"); + } + else + { + PUT("No plug-ins are installed.
"); + } - PUT("For more information on plug-ins, click here.


"); + PUT("For more information on plug-ins, click here.


"); for (handle = np_plist; handle; handle = handle->next) { @@ -5265,34 +5343,34 @@ NPL_DisplayPluginsAsHTML(FO_Present_Types format_out, URL_Struct *urls, MWContex PUT(handle->name); PUT("

"); - PUT("File name: "); - PUT(handle->filename); - PUT("
"); + PUT("File name: "); + PUT(handle->filename); + PUT("
"); - PUT("MIME types:
"); - PUT(""); PUT("

"); PUT("


"); @@ -5322,29 +5400,27 @@ NPL_DisplayPluginsAsHTML(FO_Present_Types format_out, URL_Struct *urls, MWContex #ifdef ANTHRAX char* NPL_FindAppletEnabledForMimetype(const char* mimetype) { - char* prefName; - char* temp; - char* applet; - uint32 len; - int32 loadAction; + char* prefName; + char* applet; + int32 loadAction; - prefName = np_CreateMimePref(mimetype, "applet"); + prefName = np_CreateMimePref(mimetype, "applet"); - if(PREF_CopyCharPref(prefName, &applet) == PREF_OK) - { - /* also check the load action on Mac - this may be XP in the future */ - XP_FREE(prefName); - prefName = np_CreateMimePref(mimetype, "load_action"); - if(PREF_GetIntPref(prefName, &loadAction) == PREF_OK) - if(loadAction == 5) - { - XP_FREE(prefName); - return applet; - } - } + if(PREF_CopyCharPref(prefName, &applet) == PREF_OK) + { + /* also check the load action on Mac - this may be XP in the future */ + XP_FREE(prefName); + prefName = np_CreateMimePref(mimetype, "load_action"); + if(PREF_GetIntPref(prefName, &loadAction) == PREF_OK) + if(loadAction == 5) + { + XP_FREE(prefName); + return applet; + } + } - XP_FREE(prefName); - return NULL; + XP_FREE(prefName); + return NULL; } @@ -5364,28 +5440,28 @@ char* NPL_FindAppletEnabledForMimetype(const char* mimetype) char** NPL_FindAppletsForType(const char* mimetype) { - char** result; - char* appletName; - int32 numApplets; - int32 i; + char** result; + char* appletName; + int32 numApplets; + int32 i; - numApplets = np_GetNumberOfInstalledApplets(mimetype); - if(numApplets == 0) - return NULL; + numApplets = np_GetNumberOfInstalledApplets(mimetype); + if(numApplets == 0) + return NULL; - result = (char**) XP_ALLOC(numApplets * sizeof(char*)); - if (!result) - return NULL; + result = (char**) XP_ALLOC(numApplets * sizeof(char*)); + if (!result) + return NULL; - for(i=1; i<=numApplets; i++) - { - if((appletName = np_FindAppletNForMimeType(mimetype, (char)i)) == NULL) - return NULL; - result[i-1] = appletName; - } - result[i-1] = NULL; + for(i=1; i<=numApplets; i++) + { + if((appletName = np_FindAppletNForMimeType(mimetype, (char)i)) == NULL) + return NULL; + result[i-1] = appletName; + } + result[i-1] = NULL; - return result; + return result; } /* @@ -5399,48 +5475,48 @@ NPL_FindAppletsForType(const char* mimetype) NPError NPL_RegisterAppletType(NPMIMEType type, char* filename) { - /* - * Is this Applet the wildcard (a.k.a. null) plugin? - * If so, we don't want to register it for FO_PRESENT - * or it will interfere with our normal unknown-mime- - * type handling. - */ - XP_Bool wildtype = (strcmp(type, "*") == 0); - np_handle* handle = NULL; - char* newPref; + /* + * Is this Applet the wildcard (a.k.a. null) plugin? + * If so, we don't want to register it for FO_PRESENT + * or it will interfere with our normal unknown-mime- + * type handling. + */ + XP_Bool wildtype = (strcmp(type, "*") == 0); + np_handle* handle = NULL; + char* newPref; - for(handle = np_alist; handle != NULL; handle = handle->next) - { - if(!XP_STRCMP(handle->name, type) && !XP_STRCMP(handle->filename, filename)) - break; - } + for(handle = np_alist; handle != NULL; handle = handle->next) + { + if(!XP_STRCMP(handle->name, type) && !XP_STRCMP(handle->filename, filename)) + break; + } - if(handle == NULL) - { - handle = XP_NEW_ZAP(np_handle); - if (!handle) - return NPERR_OUT_OF_MEMORY_ERROR; + if(handle == NULL) + { + handle = XP_NEW_ZAP(np_handle); + if (!handle) + return NPERR_OUT_OF_MEMORY_ERROR; - StrAllocCopy(handle->name, type); - StrAllocCopy(handle->filename, filename); + StrAllocCopy(handle->name, type); + StrAllocCopy(handle->filename, filename); - handle->pdesc = NULL; - handle->next = np_alist; - np_alist = handle; - } + handle->pdesc = NULL; + handle->next = np_alist; + np_alist = handle; + } #ifdef XP_WIN /* EmbedStream does some Windows FE work and then calls NPL_NewStream */ - if (!wildtype) + if (!wildtype) NET_RegisterContentTypeConverter(type, FO_PRESENT, handle, EmbedStream); #else - if (!wildtype) + if (!wildtype) NET_RegisterContentTypeConverter(type, FO_PRESENT, handle, NPL_NewPresentStream); #endif - newPref = np_CreateMimePref(type, "load_action"); - PREF_SetIntPref(newPref, 5); - XP_FREE(newPref); + newPref = np_CreateMimePref(type, "load_action"); + PREF_SetIntPref(newPref, 5); + XP_FREE(newPref); return NPERR_NO_ERROR; } @@ -5448,60 +5524,60 @@ NPL_RegisterAppletType(NPMIMEType type, char* filename) void NPL_InstallAppletHandler(char* appletName, char* mimetype, char* extension) { - char* newPref; - char buffer[100]; - int32 numApplets; - int bufLen = 100; + char* newPref; + char buffer[100]; + int32 numApplets; + int bufLen = 100; - /* check if it's an entirely new mimetype */ - newPref = np_CreateMimePref(mimetype, "mimetype"); - if(PREF_GetCharPref(newPref, buffer, &bufLen) != PREF_OK) - { - PREF_SetCharPref(newPref, mimetype); - XP_FREE(newPref); + /* check if it's an entirely new mimetype */ + newPref = np_CreateMimePref(mimetype, "mimetype"); + if(PREF_GetCharPref(newPref, buffer, &bufLen) != PREF_OK) + { + PREF_SetCharPref(newPref, mimetype); + XP_FREE(newPref); - newPref = np_CreateMimePref(mimetype, "extension"); - PREF_SetCharPref(newPref, extension); - } - XP_FREE(newPref); + newPref = np_CreateMimePref(mimetype, "extension"); + PREF_SetCharPref(newPref, extension); + } + XP_FREE(newPref); - newPref = np_CreateMimePref(mimetype, "num_applets"); + newPref = np_CreateMimePref(mimetype, "num_applets"); - /* check if this is the first applet installed for this mimetype */ - if(PREF_GetIntPref(newPref, &numApplets) != PREF_OK) - { - /* First Applet installed for mimetype */ - PREF_SetIntPref(newPref, 1); - XP_FREE(newPref); + /* check if this is the first applet installed for this mimetype */ + if(PREF_GetIntPref(newPref, &numApplets) != PREF_OK) + { + /* First Applet installed for mimetype */ + PREF_SetIntPref(newPref, 1); + XP_FREE(newPref); - newPref = np_CreateMimePref(mimetype, "applet1"); - PREF_SetCharPref(newPref, appletName); - XP_FREE(newPref); + newPref = np_CreateMimePref(mimetype, "applet1"); + PREF_SetCharPref(newPref, appletName); + XP_FREE(newPref); - newPref = np_CreateMimePref(mimetype, "applet"); - PREF_SetCharPref(newPref, appletName); - XP_FREE(newPref); - } - else - { - char appletN[] = { 'a', 'p', 'p', 'l', 'e', 't', '1', '\0'}; - ++numApplets; - PREF_SetIntPref(newPref, numApplets); - XP_FREE(newPref); + newPref = np_CreateMimePref(mimetype, "applet"); + PREF_SetCharPref(newPref, appletName); + XP_FREE(newPref); + } + else + { + char appletN[] = { 'a', 'p', 'p', 'l', 'e', 't', '1', '\0'}; + ++numApplets; + PREF_SetIntPref(newPref, numApplets); + XP_FREE(newPref); - XP_ASSERT(numApplets < 10); - appletN[6] = (numApplets+48); - newPref = np_CreateMimePref(mimetype, appletN); - PREF_SetCharPref(newPref, appletName); - XP_FREE(newPref); + XP_ASSERT(numApplets < 10); + appletN[6] = (numApplets+48); + newPref = np_CreateMimePref(mimetype, appletN); + PREF_SetCharPref(newPref, appletName); + XP_FREE(newPref); - /* Set the new Applet as the default */ - newPref = np_CreateMimePref(mimetype, "applet"); - PREF_SetCharPref(newPref, appletName); - XP_FREE(newPref); - } + /* Set the new Applet as the default */ + newPref = np_CreateMimePref(mimetype, "applet"); + PREF_SetCharPref(newPref, appletName); + XP_FREE(newPref); + } - NPL_RegisterAppletType(mimetype, appletName); + NPL_RegisterAppletType(mimetype, appletName); } /* ANTHRAX STATIC FUNCTIONS */ @@ -5519,24 +5595,23 @@ NPL_InstallAppletHandler(char* appletName, char* mimetype, char* extension) static char* np_FindAppletNForMimeType(const char* mimetype, char index) { - char* prefName; - char pref[] = { 'a', 'p', 'p', 'l', 'e', 't', '1', '\0'}; - char* applet; - uint32 len; + char* prefName; + char pref[] = { 'a', 'p', 'p', 'l', 'e', 't', '1', '\0'}; + char* applet; - pref[6] = (index+48); - prefName = np_CreateMimePref(mimetype, pref); + pref[6] = (index+48); + prefName = np_CreateMimePref(mimetype, pref); - if(PREF_CopyCharPref(prefName, &applet) == PREF_OK) - { - XP_FREE(prefName); - return applet; - } - else - { - XP_FREE(prefName); - return NULL; - } + if(PREF_CopyCharPref(prefName, &applet) == PREF_OK) + { + XP_FREE(prefName); + return applet; + } + else + { + XP_FREE(prefName); + return NULL; + } } /* @@ -5550,19 +5625,17 @@ static char* np_FindAppletNForMimeType(const char* mimetype, char index) static int32 np_GetNumberOfInstalledApplets(const char* mimetype) { - char* prefName; - char* temp; - uint32 len; - int32 numApplets; + char* prefName; + int32 numApplets; - numApplets = 0; + numApplets = 0; - prefName = np_CreateMimePref(mimetype, "num_applets"); + prefName = np_CreateMimePref(mimetype, "num_applets"); - PREF_GetIntPref(prefName, &numApplets); + PREF_GetIntPref(prefName, &numApplets); - XP_FREE(prefName); - return numApplets; + XP_FREE(prefName); + return numApplets; } /* @@ -5581,27 +5654,27 @@ static int32 np_GetNumberOfInstalledApplets(const char* mimetype) static char* np_CreateMimePref(const char* mimetype, const char* pref) { - uint32 len; - char* prefName; + uint32 len; + char* prefName; - len = XP_STRLEN("mime..") + XP_STRLEN(mimetype) + XP_STRLEN(pref); + len = XP_STRLEN("mime..") + XP_STRLEN(mimetype) + XP_STRLEN(pref); - prefName = (char*)XP_ALLOC((len+1)*sizeof(char)); - XP_ASSERT(prefName); - if(!prefName) - return NULL; + prefName = (char*)XP_ALLOC((len+1)*sizeof(char)); + XP_ASSERT(prefName); + if(!prefName) + return NULL; - prefName[0] = 0; + prefName[0] = 0; - XP_STRCAT(prefName, "mime."); - XP_STRCAT(prefName, mimetype); - XP_STRCAT(prefName, "."); - XP_STRCAT(prefName, pref); + XP_STRCAT(prefName, "mime."); + XP_STRCAT(prefName, mimetype); + XP_STRCAT(prefName, "."); + XP_STRCAT(prefName, pref); - np_ReplaceChars(prefName, '-', '_'); - np_ReplaceChars(prefName, '/', '_'); + np_ReplaceChars(prefName, '-', '_'); + np_ReplaceChars(prefName, '/', '_'); - return prefName; + return prefName; } /* @@ -5613,11 +5686,11 @@ static char* np_CreateMimePref(const char* mimetype, const char* pref) static void np_ReplaceChars(char* word, char oldChar, char newChar) { - char* index; - XP_ASSERT(word); - for(index = word; *index != 0; ++index) - if(*index == oldChar) - *index = newChar; + char* index; + XP_ASSERT(word); + for(index = word; *index != 0; ++index) + if(*index == oldChar) + *index = newChar; } #endif /* ANTHRAX */ @@ -5629,30 +5702,30 @@ static void np_SetTimerInterval(NPP npp, uint32 msecs) if(npp) { np_instance* instance = (np_instance*) npp->ndata; if(instance) - { - instance->interval = msecs; - instance->timeout = FE_SetTimeout(np_TimerCallback, (void*)instance, instance->interval); - } + { + instance->interval = msecs; + instance->timeout = FE_SetTimeout(np_TimerCallback, (void*)instance, instance->interval); + } } } static void np_TimerCallback(void* data) { - NPEvent event; - np_instance* instance = (np_instance*) data; + NPEvent event; + np_instance* instance = (np_instance*) data; #ifdef XP_MAC - ((EventRecord)event).what = nullEvent; + ((EventRecord)event).what = nullEvent; #elif defined(XP_WIN) - event.event = 0; // ? + event.event = 0; // ? #elif defined(XP_OS2) - event.event = 0; // ? + event.event = 0; // ? #elif defined(XP_UNIX) - // not sure what to do here + // not sure what to do here #endif - instance->timeout = FE_SetTimeout(np_TimerCallback, (void*)instance, instance->interval); - NPL_HandleEvent(instance->app, &event, NULL); + instance->timeout = FE_SetTimeout(np_TimerCallback, (void*)instance, instance->interval); + NPL_HandleEvent(instance->app, &event, NULL); } #endif diff --git a/mozilla/modules/plugin/src/npglue.h b/mozilla/modules/plugin/src/npglue.h index 43ffe2da9d7..8fbb96add61 100644 --- a/mozilla/modules/plugin/src/npglue.h +++ b/mozilla/modules/plugin/src/npglue.h @@ -64,6 +64,8 @@ struct nsIJVMManager; class nsHashtable; #endif /* OJI */ +#include "plstr.h" + extern int XP_PLUGIN_LOADING_PLUGIN; extern int MK_BAD_CONNECT; extern int XP_PLUGIN_NOT_FOUND; @@ -299,6 +301,34 @@ public: NS_IMETHOD UserAgent(const char* *result); +#ifdef NEW_PLUGIN_STREAM_API + + NS_IMETHOD + GetURL(nsISupports* pluginInst, + const char* url, + const char* target = NULL, + nsIPluginStreamListener* streamListener = NULL, + nsPluginStreamType streamType = nsPluginStreamType_Normal, + const char* altHost = NULL, + const char* referrer = NULL, + PRBool forceJSEnabled = PR_FALSE); + + NS_IMETHOD + PostURL(nsISupports* pluginInst, + const char* url, + PRUint32 postDataLen, + const char* postData, + PRBool isFile = PR_FALSE, + const char* target = NULL, + nsIPluginStreamListener* streamListener = NULL, + nsPluginStreamType streamType = nsPluginStreamType_Normal, + const char* altHost = NULL, + const char* referrer = NULL, + PRBool forceJSEnabled = PR_FALSE, + PRUint32 postHeadersLength = 0, + const char* postHeaders = NULL); + +#else // !NEW_PLUGIN_STREAM_API NS_IMETHOD GetURL(nsISupports* peer, const char* url, const char* target, void* notifyData = NULL, const char* altHost = NULL, @@ -311,6 +341,7 @@ public: const char* altHost = NULL, const char* referrer = NULL, PRBool forceJSEnabled = PR_FALSE, PRUint32 postHeadersLength = 0, const char* postHeaders = NULL); +#endif // !NEW_PLUGIN_STREAM_API //////////////////////////////////////////////////////////////////////////// // from nsIPluginManager2: @@ -355,6 +386,7 @@ public: NS_IMETHOD HasAllocatedMenuID(nsIEventHandler* handler, PRInt16 menuID, PRBool *result); +#if 0 // On the mac (and most likely win16), network activity can // only occur on the main thread. Therefore, we provide a hook // here for the case that the main thread needs to tickle itself. @@ -362,6 +394,7 @@ public: // the tickle code can notify it without freezing. NS_IMETHOD ProcessNextEvent(PRBool *bEventHandled); +#endif //////////////////////////////////////////////////////////////////////////// // nsPluginManager specific methods: @@ -660,6 +693,112 @@ protected: //////////////////////////////////////////////////////////////////////////////// +#ifdef NEW_PLUGIN_STREAM_API + +#include "nsIPluginInputStream2.h" + +class nsPluginInputStream; + +// stored in the fe_data of the URL_Struct: +struct nsPluginURLData { + NPEmbeddedApp* app; + nsIPluginStreamListener* listener; + nsPluginInputStream* inStr; +}; + +class nsPluginInputStream : public nsIPluginInputStream2 { +public: + + NS_DECL_ISUPPORTS + + //////////////////////////////////////////////////////////////////////////// + // from nsIBaseStream: + + /** Close the stream. */ + NS_IMETHOD + Close(void); + + //////////////////////////////////////////////////////////////////////////// + // from nsIInputStream: + + /** Return the number of bytes in the stream + * @param aLength out parameter to hold the length + * of the stream. if an error occurs, the length + * will be undefined + * @return error status + */ + NS_IMETHOD + GetLength(PRInt32 *aLength); + + /** Read data from the stream. + * @param aErrorCode the error code if an error occurs + * @param aBuf the buffer into which the data is read + * @param aOffset the start offset of the data + * @param aCount the maximum number of bytes to read + * @param aReadCount out parameter to hold the number of + * bytes read, eof if 0. if an error occurs, the + * read count will be undefined + * @return error status + */ + NS_IMETHOD + Read(char* aBuf, PRInt32 aOffset, PRInt32 aCount, PRInt32 *aReadCount); + + //////////////////////////////////////////////////////////////////////////// + // from nsIPluginInputStream: + + // (Corresponds to NPStream's lastmodified field.) + NS_IMETHOD + GetLastModified(PRUint32 *result); + + NS_IMETHOD + RequestRead(nsByteRange* rangeList); + + //////////////////////////////////////////////////////////////////////////// + // from nsIPluginInputStream2: + + NS_IMETHOD + GetContentLength(PRUint32 *result); + + NS_IMETHOD + GetHeaderFields(PRUint16& n, const char*const*& names, const char*const*& values); + + NS_IMETHOD + GetHeaderField(const char* name, const char* *result); + + //////////////////////////////////////////////////////////////////////////// + // nsPluginInputStream specific methods: + + nsPluginInputStream(nsIPluginStreamListener* listener, + nsPluginStreamType streamType); + virtual ~nsPluginInputStream(void); + + nsIPluginStreamListener* GetListener(void) { return mListener; } + nsPluginStreamType GetStreamType(void) { return mStreamType; } + + void SetStreamInfo(URL_Struct* urls, np_stream* stream) { + mUrls = urls; + mStream = stream; + } + + void SetReadBuffer(PRUint32 len, const char* buffer) { + mBuffer = PL_strdup(buffer); + mBufferLength = len; + mAmountRead = 0; + } + +protected: + nsIPluginStreamListener* mListener; + nsPluginStreamType mStreamType; + URL_Struct* mUrls; + np_stream* mStream; + char* mBuffer; + PRUint32 mBufferLength; + PRUint32 mAmountRead; + +}; + +#else // !NEW_PLUGIN_STREAM_API + class nsPluginStreamPeer : public nsIPluginStreamPeer2, public nsISeekablePluginStreamPeer { @@ -742,6 +881,8 @@ protected: }; +#endif // !NEW_PLUGIN_STREAM_API + //////////////////////////////////////////////////////////////////////////////// #if defined(__cplusplus) diff --git a/mozilla/modules/plugin/src/nppriv.h b/mozilla/modules/plugin/src/nppriv.h index 360042e1484..77d67357f36 100644 --- a/mozilla/modules/plugin/src/nppriv.h +++ b/mozilla/modules/plugin/src/nppriv.h @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * The contents of this file are subject to the Netscape Public License * Version 1.0 (the "NPL"); you may not use this file except in @@ -141,6 +141,9 @@ struct _np_urlsnode { void* notifyData; XP_Bool cached; XP_Bool notify; +#ifdef NEW_PLUGIN_STREAM_API + uint16 streamType; +#endif }; /* MWContext.pluginReconnect -> np_reconnect */ diff --git a/mozilla/modules/plugin/src/nsplugin.cpp b/mozilla/modules/plugin/src/nsplugin.cpp index 4406312114f..3aade698453 100644 --- a/mozilla/modules/plugin/src/nsplugin.cpp +++ b/mozilla/modules/plugin/src/nsplugin.cpp @@ -32,7 +32,6 @@ #include "jvmmgr.h" #include "nsILiveconnect.h" #endif -#include "plstr.h" /* PL_strcasecmp */ #include "xp_mem.h" #include "xpassert.h" @@ -66,10 +65,16 @@ static NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID); static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID); static NS_DEFINE_IID(kIPluginTagInfo2IID, NS_IPLUGINTAGINFO2_IID); static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID); +static NS_DEFINE_IID(kIFileUtilitiesIID, NS_IFILEUTILITIES_IID); +#ifdef NEW_PLUGIN_STREAM_API +static NS_DEFINE_IID(kIPluginInputStreamIID, NS_IPLUGININPUTSTREAM_IID); +static NS_DEFINE_IID(kIPluginInputStream2IID, NS_IPLUGININPUTSTREAM2_IID); +static NS_DEFINE_IID(kIPluginStreamListenerIID, NS_IPLUGINSTREAMLISTENER_IID); +#else // !NEW_PLUGIN_STREAM_API static NS_DEFINE_IID(kISeekablePluginStreamPeerIID, NS_ISEEKABLEPLUGINSTREAMPEER_IID); static NS_DEFINE_IID(kIPluginStreamPeerIID, NS_IPLUGINSTREAMPEER_IID); static NS_DEFINE_IID(kIPluginStreamPeer2IID, NS_IPLUGINSTREAMPEER2_IID); -static NS_DEFINE_IID(kIFileUtilitiesIID, NS_IFILEUTILITIES_IID); +#endif // !NEW_PLUGIN_STREAM_API #include "prerror.h" @@ -263,37 +268,37 @@ nsPluginManager::GetCapsManager(const nsIID& aIID) PRThread *threadAttached = NULL; #ifdef OJI if (fCapsManager == NULL) { - if ( PR_GetCurrentThread() == NULL ) - { - threadAttached = PR_AttachThread(PR_USER_THREAD, PR_PRIORITY_NORMAL, NULL); - } + if ( PR_GetCurrentThread() == NULL ) + { + threadAttached = PR_AttachThread(PR_USER_THREAD, PR_PRIORITY_NORMAL, NULL); + } - NS_DEFINE_CID(kCCapsManagerCID, NS_CCAPSMANAGER_CID); - nsresult err = NS_OK; - err = nsRepository::CreateInstance(kCCapsManagerCID, - (nsIPluginManager*)this, /* outer */ - kISupportsIID, - (void **)&fCapsManager); - NS_DEFINE_IID(kICapsManagerIID, NS_ICAPSMANAGER_IID); - if ( (err == NS_OK) - && (fCapsManager != NULL) - && (err = (fCapsManager->QueryInterface(kICapsManagerIID, (void**)&result)) == NS_OK) - ) - { - ((nsCCapsManager*)result)->SetSystemPrivilegeManager(); - result->Release(); - } - } - if ( (err == NS_OK) - &&(fCapsManager->QueryInterface(aIID, (void**)&result) != NS_OK) + NS_DEFINE_CID(kCCapsManagerCID, NS_CCAPSMANAGER_CID); + nsresult err = NS_OK; + err = nsRepository::CreateInstance(kCCapsManagerCID, + (nsIPluginManager*)this, /* outer */ + kISupportsIID, + (void **)&fCapsManager); + NS_DEFINE_IID(kICapsManagerIID, NS_ICAPSMANAGER_IID); + if ( (err == NS_OK) + && (fCapsManager != NULL) + && (err = (fCapsManager->QueryInterface(kICapsManagerIID, (void**)&result)) == NS_OK) + ) + { + ((nsCCapsManager*)result)->SetSystemPrivilegeManager(); + result->Release(); + } + } + if ( (err == NS_OK) + &&(fCapsManager->QueryInterface(aIID, (void**)&result) != NS_OK) ) - { - result = NULL; - } - if (threadAttached != NULL ) - { - PR_DetachThread(); - } + { + result = NULL; + } + if (threadAttached != NULL ) + { + PR_DetachThread(); + } #endif return result; } @@ -527,6 +532,7 @@ nsPluginManager::HasAllocatedMenuID(nsIEventHandler* handler, PRInt16 menuID, PR #endif } +#if 0 // problematic static NPL_ProcessNextEventProc npl_ProcessNextEventProc = NULL; static void* npl_ProcessNextEventData = NULL; @@ -549,6 +555,7 @@ nsPluginManager::ProcessNextEvent(PRBool *bEventHandled) return NS_OK; #endif } +#endif //////////////////////////////////////////////////////////////////////////////// @@ -559,6 +566,220 @@ extern PREventQueue* mozilla_event_queue; extern PRThread* mozilla_thread; }; +#ifdef NEW_PLUGIN_STREAM_API + +struct GetURLEvent { + PLEvent event; + nsPluginInstancePeer* peer; + const char* url; + const char* target; + void* notifyData; + const char* altHost; + const char* referrer; + PRBool forceJSEnabled; +}; + +static void* +HandleGetURLEvent(PLEvent* event) +{ + PR_ASSERT(PR_CurrentThread() == mozilla_thread); + GetURLEvent* e = (GetURLEvent*)event; + NPP npp = e->peer->GetNPP(); + NPError rslt = np_geturlinternal(npp, + e->url, + e->target, + e->altHost, + e->referrer, + e->forceJSEnabled, + e->notifyData != NULL, + e->notifyData); + return (void*)rslt; +} + +static void +DestroyGetURLEvent(PLEvent* event) +{ + GetURLEvent* e = (GetURLEvent*)event; + PR_Free(event); +} + +NS_METHOD +nsPluginManager::GetURL(nsISupports* pluginInst, + const char* url, + const char* target, + nsIPluginStreamListener* listener, + nsPluginStreamType streamType, + const char* altHost, + const char* referrer, + PRBool forceJSEnabled) +{ + NPError rslt = NPERR_INVALID_PARAM; + nsIPluginInstance* inst = NULL; + if (pluginInst->QueryInterface(kIPluginInstanceIID, (void**)&inst) == NS_OK) { + // Warning: Casting to our implementation type of plugin instance peer here: + nsPluginInstancePeer* peer; + nsresult err = inst->GetPeer((nsIPluginInstancePeer**)&peer); + if (err == NS_OK) { + void* notifyData = NULL; + if (listener) { + nsPluginInputStream* inStr = new nsPluginInputStream(listener, streamType); + notifyData = inStr; + } + + if (PR_CurrentThread() == mozilla_thread) { + NPP npp = peer->GetNPP(); + rslt = np_geturlinternal(npp, + url, + target, + altHost, + referrer, + forceJSEnabled, + notifyData != NULL, + notifyData); + } + else { + GetURLEvent* e = PR_NEW(GetURLEvent); + if (e == NULL) { + rslt = NPERR_OUT_OF_MEMORY_ERROR; + } + else { + PL_InitEvent(&e->event, NULL, HandleGetURLEvent, DestroyGetURLEvent); + e->peer = peer; + e->url = url; + e->target = target; + e->notifyData = notifyData; + e->altHost = altHost; + e->referrer = referrer; + e->forceJSEnabled = forceJSEnabled; + /*rslt = (NPError)*/PL_PostSynchronousEvent(mozilla_event_queue, &e->event); + rslt = NPERR_NO_ERROR; /* XXX irix c++ compiler doesn't like the above cast */ + } + } + peer->Release(); + } + inst->Release(); + } + return fromNPError[rslt]; +} + +struct PostURLEvent { + PLEvent event; + nsPluginInstancePeer* peer; + const char* url; + const char* target; + PRUint32 postDataLen; + const char* postData; + PRBool isFile; + void* notifyData; + const char* altHost; + const char* referrer; + PRBool forceJSEnabled; + PRUint32 postHeadersLen; + const char* postHeaders; +}; + +static void* +HandlePostURLEvent(PLEvent* event) +{ + PR_ASSERT(PR_CurrentThread() == mozilla_thread); + PostURLEvent* e = (PostURLEvent*)event; + NPP npp = e->peer->GetNPP(); + NPError rslt = np_posturlinternal(npp, + e->url, + e->target, + e->altHost, + e->referrer, + e->forceJSEnabled, + e->postDataLen, + e->postData, + e->isFile, + e->notifyData != NULL, + e->notifyData); + return (void*)rslt; +} + +static void +DestroyPostURLEvent(PLEvent* event) +{ + PostURLEvent* e = (PostURLEvent*)event; + PR_Free(event); +} + +NS_METHOD +nsPluginManager::PostURL(nsISupports* pluginInst, + const char* url, + PRUint32 postDataLen, + const char* postData, + PRBool isFile, + const char* target, + nsIPluginStreamListener* listener, + nsPluginStreamType streamType, + const char* altHost, + const char* referrer, + PRBool forceJSEnabled, + PRUint32 postHeadersLen, + const char* postHeaders) +{ + NPError rslt = NPERR_INVALID_PARAM; + nsIPluginInstance* inst = NULL; + if (pluginInst->QueryInterface(kIPluginInstanceIID, (void**)&inst) == NS_OK) { + // Warning: Casting to our implementation type of plugin instance peer here: + nsPluginInstancePeer* peer; + nsresult err = inst->GetPeer((nsIPluginInstancePeer**)&peer); + if (err == NS_OK) { + void* notifyData = NULL; + if (listener) { + nsPluginInputStream* inStr = new nsPluginInputStream(listener, streamType); + notifyData = inStr; + } + + if (PR_CurrentThread() == mozilla_thread) { + NPP npp = peer->GetNPP(); + PR_ASSERT(postHeaders == NULL); // XXX need to deal with postHeaders + rslt = np_posturlinternal(npp, + url, + target, + altHost, + referrer, + forceJSEnabled, + postDataLen, + postData, + isFile, + notifyData != NULL, + notifyData); + } + else { + PostURLEvent* e = PR_NEW(PostURLEvent); + if (e == NULL) { + rslt = NPERR_OUT_OF_MEMORY_ERROR; + } + else { + PL_InitEvent(&e->event, NULL, HandlePostURLEvent, DestroyPostURLEvent); + e->peer = peer; + e->url = url; + e->target = target; + e->notifyData = notifyData; + e->altHost = altHost; + e->referrer = referrer; + e->forceJSEnabled = forceJSEnabled; + e->postDataLen = postDataLen; + e->postData = postData; + e->isFile = isFile; + e->postHeadersLen = postHeadersLen; + e->postHeaders = postHeaders; + /*rslt = (NPError)*/PL_PostSynchronousEvent(mozilla_event_queue, &e->event); + rslt = NPERR_NO_ERROR; /* XXX irix c++ compiler doesn't like the above cast */ + } + } + peer->Release(); + } + inst->Release(); + } + return fromNPError[rslt]; +} + +#else // !NEW_PLUGIN_STREAM_API + struct GetURLEvent { PLEvent event; nsPluginInstancePeer* peer; @@ -745,6 +966,8 @@ nsPluginManager::PostURL(nsISupports* pinst, const char* url, const char* target return fromNPError[rslt]; } +#endif // !NEW_PLUGIN_STREAM_API + extern "C" char *pacf_find_proxies_for_url(MWContext *context, URL_Struct *URL_s); @@ -1003,13 +1226,20 @@ nsPluginInstancePeer::GetJavaPeer(jref *peer) void nsPluginInstancePeer::SetPluginInstance(nsIPluginInstance* inst) { + // We're now maintaining our reference to plugin instance in the + // npp->ndata->sdata (saved data) field, and we access the peer + // from there. This method should be totally unnecessary. +#if 0 if (fPluginInst != NULL) { fPluginInst->Release(); } +#endif fPluginInst = inst; +#if 0 if (fPluginInst != NULL) { fPluginInst->AddRef(); - } + } +#endif } nsIPluginInstance* nsPluginInstancePeer::GetPluginInstance() @@ -1168,7 +1398,7 @@ nsPluginTagInfo::GetAttribute(const char* name, const char* *result) } } - return NS_OK; + return NS_ERROR_FAILURE; } NS_METHOD @@ -1257,7 +1487,7 @@ nsPluginTagInfo::GetParameter(const char* name, const char* *result) } } - return NS_OK; + return NS_ERROR_FAILURE; } NS_METHOD @@ -1390,6 +1620,123 @@ NS_IMPL_QUERY_INTERFACE(nsPluginManagerStream, kIOutputStreamIID); NS_IMPL_ADDREF(nsPluginManagerStream); NS_IMPL_RELEASE(nsPluginManagerStream); +#ifdef NEW_PLUGIN_STREAM_API +//////////////////////////////////////////////////////////////////////////////// +// Plugin Input Stream Interface + +nsPluginInputStream::nsPluginInputStream(nsIPluginStreamListener* listener, + nsPluginStreamType streamType) + : mListener(listener), mStreamType(streamType), + mUrls(NULL), mStream(NULL), + mBuffer(NULL), mBufferLength(0), mAmountRead(0) +{ + NS_INIT_REFCNT(); + listener->AddRef(); +} + +nsPluginInputStream::~nsPluginInputStream(void) +{ + mListener->Release(); + PL_strfree(mBuffer); +} + +NS_IMPL_ADDREF(nsPluginInputStream); +NS_IMPL_RELEASE(nsPluginInputStream); + +NS_METHOD +nsPluginInputStream::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + if (aIID.Equals(kIPluginInputStream2IID) || + aIID.Equals(kIPluginInputStreamIID) || + aIID.Equals(kISupportsIID)) { + *aInstancePtr = (nsIPluginInputStream2*)this; + AddRef(); + return NS_OK; + } + return NS_NOINTERFACE; +} + +NS_METHOD +nsPluginInputStream::Close(void) +{ + NPError err = npn_destroystream(mStream->instance->npp, mStream->pstream, + nsPluginReason_UserBreak); + return fromNPError[err]; +} + +NS_METHOD +nsPluginInputStream::GetLength(PRInt32 *aLength) +{ + *aLength = mStream->pstream->end; + return NS_OK; +#if 0 + *aLength = mBufferLength; + return NS_OK; +#endif +} + +NS_METHOD +nsPluginInputStream::Read(char* aBuf, PRInt32 aOffset, PRInt32 aCount, + PRInt32 *aReadCount) +{ + if (aOffset > (PRInt32)mBufferLength) + return NS_ERROR_FAILURE; // XXX right error? + PRUint32 cnt = PR_MIN(aCount, (PRInt32)mBufferLength - aOffset); + memcpy(aBuf, &mBuffer[aOffset], cnt); + *aReadCount = cnt; + mAmountRead -= cnt; + return NS_OK; +} + +NS_METHOD +nsPluginInputStream::GetLastModified(PRUint32 *result) +{ + *result = mStream->pstream->lastmodified; + return NS_OK; +} + +NS_METHOD +nsPluginInputStream::RequestRead(nsByteRange* rangeList) +{ + NPError err = npn_requestread(mStream->pstream, + (NPByteRange*)rangeList); + return fromNPError[err]; +} + +NS_METHOD +nsPluginInputStream::GetContentLength(PRUint32 *result) +{ + *result = mUrls->content_length; + return NS_OK; +} + +NS_METHOD +nsPluginInputStream::GetHeaderFields(PRUint16& n, const char*const*& names, + const char*const*& values) +{ + n = (PRUint16)mUrls->all_headers.empty_index; + names = (const char*const*)mUrls->all_headers.key; + values = (const char*const*)mUrls->all_headers.value; + return NS_OK; +} + +NS_METHOD +nsPluginInputStream::GetHeaderField(const char* name, const char* *result) +{ + PRUint16 i; + for (i = 0; i < mUrls->all_headers.empty_index; i++) { + if (PL_strcmp(mUrls->all_headers.key[i], name) == 0) { + *result = mUrls->all_headers.value[i]; + return NS_OK; + } + } + return NS_ERROR_FAILURE; +} + +#else // !NEW_PLUGIN_STREAM_API //////////////////////////////////////////////////////////////////////////////// // Plugin Stream Peer Interface @@ -1554,4 +1901,6 @@ nsPluginStreamPeer::QueryInterface(const nsIID& aIID, void** aInstancePtr) return NS_NOINTERFACE; } +#endif // !NEW_PLUGIN_STREAM_API + //////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/modules/plugin/test/makefile.win b/mozilla/modules/plugin/test/makefile.win index 94ce1054697..c5ccfd69d0e 100644 --- a/mozilla/modules/plugin/test/makefile.win +++ b/mozilla/modules/plugin/test/makefile.win @@ -78,6 +78,11 @@ include <$(DEPTH)/config/rules.mak> LINCS=$(LINCS) -I$(PUBLIC)\plugin -I$(PUBLIC)\xpcom -I$(PUBLIC)\java -I$(PUBLIC)\plugimpl -I$(PUBLIC)\raptor -I_jri +!ifdef NEW_PLUGIN_STREAM_API +LCFLAGS = $(LCFLAGS) -DNEW_PLUGIN_STREAM_API +!endif + install:: $(DLL) - $(MAKE_INSTALL) $(XPDIST)\classes11\Simple.class $(DEPTH)\cmd\winfe\mkfiles32\x86dbg\plugins\simple +# $(MAKE_INSTALL) $(XPDIST)\classes11\Simple.class $(DEPTH)\cmd\winfe\mkfiles32\x86dbg\plugins\simple + $(MAKE_INSTALL) Simple.class $(DEPTH)\cmd\winfe\mkfiles32\x86dbg\plugins\simple $(MAKE_INSTALL) $(OBJDIR)\npsimple.dll $(DEPTH)\cmd\winfe\mkfiles32\x86dbg\plugins\simple diff --git a/mozilla/modules/plugin/test/npsimple.cpp b/mozilla/modules/plugin/test/npsimple.cpp index 89d8d677c4e..b550dc9ce34 100644 --- a/mozilla/modules/plugin/test/npsimple.cpp +++ b/mozilla/modules/plugin/test/npsimple.cpp @@ -249,19 +249,27 @@ public: NS_IMETHOD SetWindow(nsPluginWindow* window); +#ifndef NEW_PLUGIN_STREAM_API + // (Corresponds to NPP_NewStream.) NS_IMETHOD NewStream(nsIPluginStreamPeer* peer, nsIPluginStream* *result); +#endif // NEW_PLUGIN_STREAM_API + // (Corresponds to NPP_Print.) NS_IMETHOD Print(nsPluginPrint* platformPrint); +#ifndef NEW_PLUGIN_STREAM_API + // (Corresponds to NPP_URLNotify.) NS_IMETHOD URLNotify(const char* url, const char* target, nsPluginReason reason, void* notifyData); +#endif // NEW_PLUGIN_STREAM_API + NS_IMETHOD GetValue(nsPluginInstanceVariable variable, void *value); @@ -302,6 +310,70 @@ protected: // SimplePluginStream represents the stream used by SimplePluginInstances // to receive data from the browser. +#ifdef NEW_PLUGIN_STREAM_API + +class SimplePluginStreamListener : public nsIPluginStreamListener { +public: + + NS_DECL_ISUPPORTS + + //////////////////////////////////////////////////////////////////////////// + // from nsIPluginStreamListener: + + /** + * Notify the observer that the URL has started to load. This method is + * called only once, at the beginning of a URL load.

+ * + * @return The return value is currently ignored. In the future it may be + * used to cancel the URL load.. + */ + NS_IMETHOD + OnStartBinding(const char* url, const nsPluginStreamInfo* info); + + /** + * Notify the client that data is available in the input stream. This + * method is called whenver data is written into the input stream by the + * networking library...

+ * + * @param aIStream The input stream containing the data. This stream can + * be either a blocking or non-blocking stream. + * @param length The amount of data that was just pushed into the stream. + * @return The return value is currently ignored. + */ + NS_IMETHOD + OnDataAvailable(const char* url, nsIPluginInputStream* input, + PRUint32 offset, PRUint32 length); + + NS_IMETHOD + OnFileAvailable(const char* url, const char* fileName); + + /** + * Notify the observer that the URL has finished loading. This method is + * called once when the networking library has finished processing the + * URL transaction initiatied via the nsINetService::Open(...) call.

+ * + * This method is called regardless of whether the URL loaded successfully.

+ * + * @param status Status code for the URL load. + * @param msg A text string describing the error. + * @return The return value is currently ignored. + */ + NS_IMETHOD + OnStopBinding(const char* url, nsresult status); + + //////////////////////////////////////////////////////////////////////////// + // SimplePluginStreamListener specific methods: + + SimplePluginStreamListener(SimplePluginInstance* inst); + virtual ~SimplePluginStreamListener(void); + +protected: + SimplePluginInstance* fInst; + +}; + +#else // !NEW_PLUGIN_STREAM_API + class SimplePluginStream : public nsIPluginStream { public: @@ -350,19 +422,34 @@ protected: }; +#endif // !NEW_PLUGIN_STREAM_API + // Interface IDs we'll need: static NS_DEFINE_IID(kIPluginIID, NS_IPLUGIN_IID); static NS_DEFINE_IID(kIJRILiveConnectPluginIID, NS_IJRILIVECONNECTPLUGIN_IID); static NS_DEFINE_IID(kIJRILiveConnectPluginInstancePeerIID, NS_IJRILIVECONNECTPLUGININSTANCEPEER_IID); static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID); -static NS_DEFINE_IID(kIPluginStreamIID, NS_IPLUGINSTREAM_IID); static NS_DEFINE_IID(kIJRIEnvIID, NS_IJRIENV_IID); static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID); +#ifdef NEW_PLUGIN_STREAM_API +static NS_DEFINE_IID(kIPluginStreamListenerIID, NS_IPLUGINSTREAMLISTENER_IID); +#else // !NEW_PLUGIN_STREAM_API +static NS_DEFINE_IID(kIPluginStreamIID, NS_IPLUGINSTREAM_IID); +#endif // !NEW_PLUGIN_STREAM_API + /******************************************************************************* * SECTION 3 - API Plugin Implementations ******************************************************************************/ +// This counter is used to keep track of the number of outstanding objects. +// It is used to determine whether the plugin's DLL can be unloaded. +static PRUint32 gPluginObjectCount = 0; + +// This flag is used to keep track of whether the plugin's DLL is explicitly +// being retained by some client. +static PRBool gPluginLocked = PR_FALSE; + //////////////////////////////////////////////////////////////////////////////// // SimplePlugin Methods //////////////////////////////////////////////////////////////////////////////// @@ -371,10 +458,12 @@ SimplePlugin::SimplePlugin() : mgr(NULL) { NS_INIT_REFCNT(); + gPluginObjectCount++; } SimplePlugin::~SimplePlugin(void) { + gPluginObjectCount--; if (env) Simple::_unuse(env); } @@ -436,6 +525,12 @@ NSGetFactory(const nsCID &aClass, nsIFactory **aFactory) return NS_ERROR_FAILURE; // XXX right error? } +extern "C" NS_EXPORT PRBool +NSCanUnload(void) +{ + return gPluginObjectCount == 1 && !gPluginLocked; +} + NS_METHOD SimplePlugin::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult) { @@ -443,13 +538,14 @@ SimplePlugin::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult) if (inst == NULL) return NS_ERROR_OUT_OF_MEMORY; inst->AddRef(); + *aResult = inst; return NS_OK; } NS_METHOD SimplePlugin::LockFactory(PRBool aLock) { - // XXX what to do here? + gPluginLocked = aLock; return NS_OK; } @@ -457,7 +553,7 @@ NS_METHOD SimplePlugin::Initialize(nsISupports* browserInterfaces) { if (browserInterfaces->QueryInterface(kIPluginManagerIID, - (void**)mgr) != NS_OK) { + (void**)&mgr) != NS_OK) { return NS_ERROR_FAILURE; } return NS_OK; @@ -542,10 +638,12 @@ SimplePluginInstance::SimplePluginInstance(void) : fPeer(NULL), fWindow(NULL), fMode(nsPluginMode_Embedded) { NS_INIT_REFCNT(); + gPluginObjectCount++; } SimplePluginInstance::~SimplePluginInstance(void) { + gPluginObjectCount--; PlatformDestroy(); // Perform platform specific cleanup DisplayJavaMessage("Calling SimplePluginInstance::Release.", -1); } @@ -572,6 +670,7 @@ NS_METHOD SimplePluginInstance::Initialize(nsIPluginInstancePeer* peer) { fPeer = peer; + peer->AddRef(); nsresult err = peer->GetMode(&fMode); if (err) return err; PlatformNew(); /* Call Platform-specific initializations */ @@ -656,6 +755,8 @@ SimplePluginInstance::SetWindow(nsPluginWindow* window) return result; } +#ifndef NEW_PLUGIN_STREAM_API + /*+++++++++++++++++++++++++++++++++++++++++++++++++ * NewStream: * Notifies an instance of a new data stream and returns an error value. @@ -678,6 +779,8 @@ SimplePluginInstance::NewStream(nsIPluginStreamPeer* peer, nsIPluginStream* *res return NS_OK; } +#endif // NEW_PLUGIN_STREAM_API + /*+++++++++++++++++++++++++++++++++++++++++++++++++ * NPP_Print: +++++++++++++++++++++++++++++++++++++++++++++++++*/ @@ -754,6 +857,8 @@ SimplePluginInstance::HandleEvent(nsPluginEvent* event, PRBool* handled) return NS_OK; } +#ifndef NEW_PLUGIN_STREAM_API + /*+++++++++++++++++++++++++++++++++++++++++++++++++ * URLNotify: * Notifies the instance of the completion of a URL request. @@ -781,12 +886,76 @@ SimplePluginInstance::URLNotify(const char* url, const char* target, return NS_OK; } +#endif // NEW_PLUGIN_STREAM_API + NS_METHOD SimplePluginInstance::GetValue(nsPluginInstanceVariable variable, void *value) { + return NS_ERROR_FAILURE; +} + +#ifdef NEW_PLUGIN_STREAM_API + +//////////////////////////////////////////////////////////////////////////////// +// SimplePluginStreamListener Methods +//////////////////////////////////////////////////////////////////////////////// + +SimplePluginStreamListener::SimplePluginStreamListener(SimplePluginInstance* inst) + : fInst(inst) +{ + gPluginObjectCount++; + NS_INIT_REFCNT(); +} + +SimplePluginStreamListener::~SimplePluginStreamListener(void) +{ + gPluginObjectCount--; + fInst->DisplayJavaMessage("Calling SimplePluginStream destructor.", -1); +} + +// This macro produces a simple version of QueryInterface, AddRef and Release. +// See the nsISupports.h header file for details. + +NS_IMPL_ISUPPORTS(SimplePluginStreamListener, kIPluginStreamListenerIID); + +NS_METHOD +SimplePluginStreamListener::OnStartBinding(const char* url, const nsPluginStreamInfo* info) +{ + fInst->DisplayJavaMessage("Opening plugin stream.", -1); return NS_OK; } +NS_METHOD +SimplePluginStreamListener::OnDataAvailable(const char* url, nsIPluginInputStream* input, + PRUint32 offset, PRUint32 length) +{ + char* buffer = new char[length]; + if (buffer) { + PRInt32 amountRead = 0; + nsresult rslt = input->Read(buffer, offset, length, &amountRead); + if (rslt == NS_OK) + fInst->DisplayJavaMessage(buffer, amountRead); + delete buffer; + } + return NS_OK; +} + +NS_METHOD +SimplePluginStreamListener::OnFileAvailable(const char* url, const char* fileName) +{ + fInst->DisplayJavaMessage("Calling SimplePluginStreamListener::OnFileAvailable.", -1); + return NS_OK; +} + +NS_METHOD +SimplePluginStreamListener::OnStopBinding(const char* url, nsresult status) +{ + fInst->DisplayJavaMessage("Closing plugin stream.", -1); + return NS_OK; +} + +#else // !NEW_PLUGIN_STREAM_API + //////////////////////////////////////////////////////////////////////////////// // SimplePluginStream Methods //////////////////////////////////////////////////////////////////////////////// @@ -795,11 +964,13 @@ SimplePluginStream::SimplePluginStream(nsIPluginStreamPeer* peer, SimplePluginInstance* inst) : fPeer(peer), fInst(inst) { + gPluginObjectCount++; NS_INIT_REFCNT(); } SimplePluginStream::~SimplePluginStream(void) { + gPluginObjectCount--; fInst->DisplayJavaMessage("Calling SimplePluginStream::Release.", -1); } @@ -875,7 +1046,7 @@ SimplePluginStream::AsFile(const char* fname) return NS_OK; } - +#endif // !NEW_PLUGIN_STREAM_API /*******************************************************************************