From 5d2985287043ebc03e6345830c59fae85a2df1c2 Mon Sep 17 00:00:00 2001 From: "av%netscape.com" Date: Mon, 25 Mar 2002 23:42:32 +0000 Subject: [PATCH] Fix for 116357 -- NPAPI plugins should have an ability to stay in memory beyond page life time, patch by peterl, r=av, sr=beard, a=asa git-svn-id: svn://10.0.0.236/trunk@117428 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/modules/plugin/base/public/npapi.h | 9 +++---- .../modules/plugin/base/src/ns4xPlugin.cpp | 4 ++++ .../plugin/base/src/ns4xPluginInstance.cpp | 24 ++++++++++++------- .../plugin/base/src/ns4xPluginInstance.h | 10 +++++--- .../plugin/base/src/nsPluginHostImpl.cpp | 23 +++++------------- 5 files changed, 37 insertions(+), 33 deletions(-) diff --git a/mozilla/modules/plugin/base/public/npapi.h b/mozilla/modules/plugin/base/public/npapi.h index 33e802cb3dc..f7b0955c8c7 100644 --- a/mozilla/modules/plugin/base/public/npapi.h +++ b/mozilla/modules/plugin/base/public/npapi.h @@ -38,7 +38,7 @@ /* - * npapi.h $Revision: 3.21 $ + * npapi.h $Revision: 3.22 $ * Netscape client plug-in API spec */ @@ -312,7 +312,7 @@ typedef enum { NPPVpluginDescriptionString, NPPVpluginWindowBool, NPPVpluginTransparentBool, - NPPVjavaClass, + NPPVjavaClass, /* Not implemented in Mozilla 1.0 */ NPPVpluginWindowSize, NPPVpluginTimerInterval, @@ -320,7 +320,8 @@ typedef enum { NPPVpluginScriptableIID = 11, /* 12 and over are available on Mozilla builds starting with 0.9.9 */ - NPPVjavascriptPushCallerBool = 12 + NPPVjavascriptPushCallerBool = 12, + NPPVpluginKeepLibraryInMemory = 13 /* available in Mozilla 1.0 */ } NPPVariable; /* @@ -521,7 +522,7 @@ enum NPEventType { #define NPVERS_WIN16_HAS_LIVECONNECT 9 #define NPVERS_68K_HAS_LIVECONNECT 11 #define NPVERS_HAS_WINDOWLESS 11 - +#define NPVERS_HAS_XPCONNECT_SCRIPTING 13 /*----------------------------------------------------------------------*/ /* Function Prototypes */ diff --git a/mozilla/modules/plugin/base/src/ns4xPlugin.cpp b/mozilla/modules/plugin/base/src/ns4xPlugin.cpp index 7ce893c13de..62b09c038ae 100644 --- a/mozilla/modules/plugin/base/src/ns4xPlugin.cpp +++ b/mozilla/modules/plugin/base/src/ns4xPlugin.cpp @@ -1242,6 +1242,10 @@ _setvalue(NPP npp, NPPVariable variable, void *result) } break; + case NPPVpluginKeepLibraryInMemory: { + NPBool bCached = (result != nsnull); + return inst->SetCached(bCached); + } default: return NPERR_NO_ERROR; diff --git a/mozilla/modules/plugin/base/src/ns4xPluginInstance.cpp b/mozilla/modules/plugin/base/src/ns4xPluginInstance.cpp index ed1c15cbe1e..65d8f02f06b 100644 --- a/mozilla/modules/plugin/base/src/ns4xPluginInstance.cpp +++ b/mozilla/modules/plugin/base/src/ns4xPluginInstance.cpp @@ -691,6 +691,7 @@ ns4xPluginInstance :: ns4xPluginInstance(NPPluginFuncs* callbacks, PRLibrary* aL mTransparent = PR_FALSE; mStarted = PR_FALSE; mStreams = nsnull; + mCached = PR_FALSE; PLUGIN_LOG(PLUGIN_LOG_BASIC, ("ns4xPluginInstance ctor: this=%p\n",this)); } @@ -1226,8 +1227,7 @@ NS_IMETHODIMP ns4xPluginInstance :: GetValue(nsPluginInstanceVariable variable, nsresult res = NS_OK; - switch (variable) - { + switch (variable) { case nsPluginInstanceVariable_WindowlessBool: *(PRBool *)value = mWindowless; break; @@ -1236,22 +1236,28 @@ NS_IMETHODIMP ns4xPluginInstance :: GetValue(nsPluginInstanceVariable variable, *(PRBool *)value = mTransparent; break; + case nsPluginInstanceVariable_DoCacheBool: + *(PRBool *)value = mCached; + break; + + case nsPluginInstanceVariable_CallSetWindowAfterDestroyBool: + *(PRBool *)value = 0; // not supported for 4.x plugins + break; + default: - if(fCallbacks->getvalue) - { + if(fCallbacks->getvalue) { NS_TRY_SAFE_CALL_RETURN(res, CallNPP_GetValueProc(fCallbacks->getvalue, &fNPP, (NPPVariable)variable, value), - fLibrary); + fLibrary); + NPP_PLUGIN_LOG(PLUGIN_LOG_NORMAL, + ("NPP GetValue called: this=%p, npp=%p, var=%d, value=%d, return=%d\n", + this, &fNPP, variable, value, res)); } } - NPP_PLUGIN_LOG(PLUGIN_LOG_NORMAL, - ("NPP GetValue called: this=%p, npp=%p, var=%d, value=%d, return=%d\n", - this, &fNPP, variable, value, res)); - return res; } diff --git a/mozilla/modules/plugin/base/src/ns4xPluginInstance.h b/mozilla/modules/plugin/base/src/ns4xPluginInstance.h index b8687aa2329..452ba06d8e2 100644 --- a/mozilla/modules/plugin/base/src/ns4xPluginInstance.h +++ b/mozilla/modules/plugin/base/src/ns4xPluginInstance.h @@ -146,6 +146,9 @@ public: // returns the state of mStarted PRBool IsStarted(void); + + // cache this 4.x plugin like an XPCOM plugin + nsresult SetCached(PRBool aCache) { mCached = aCache; return NS_OK; }; protected: @@ -182,9 +185,10 @@ protected: //these are used to store the windowless properties //which the browser will later query - PRBool mWindowless; - PRBool mTransparent; - PRBool mStarted; + PRPackedBool mWindowless; + PRPackedBool mTransparent; + PRPackedBool mStarted; + PRPackedBool mCached; public: PRLibrary* fLibrary; diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp index e02119402c2..85f92b35237 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -5728,21 +5728,14 @@ nsPluginHostImpl::StopPluginInstance(nsIPluginInstance* aInstance) nsActivePlugin * plugin = mActivePluginList.find(aInstance); - if(plugin != nsnull) - { + if(plugin != nsnull) { plugin->setStopped(PR_TRUE); // be sure we set the "stop" bit // if the plugin does not want to be 'cached' just remove it PRBool doCache = PR_TRUE; aInstance->GetValue(nsPluginInstanceVariable_DoCacheBool, (void *) &doCache); - // we also do that for 4x plugin, shall we? Let's see if it is - PRBool oldSchool = PR_TRUE; - if(plugin->mPluginTag) - oldSchool = plugin->mPluginTag->mFlags & NS_PLUGIN_FLAG_OLDSCHOOL ? PR_TRUE : PR_FALSE; - - if (!doCache || oldSchool) - { + if (!doCache) { PRLibrary * library = nsnull; if(plugin->mPluginTag) library = plugin->mPluginTag->mLibrary; @@ -5752,9 +5745,8 @@ nsPluginHostImpl::StopPluginInstance(nsIPluginInstance* aInstance) if(unloadLibLater) AddToUnusedLibraryList(library); - } - else - { + } + else { // if it is allowed to be cached simply stop it, but first we should check // if we haven't exceeded the maximum allowed number of cached instances @@ -5765,11 +5757,9 @@ nsPluginHostImpl::StopPluginInstance(nsIPluginInstance* aInstance) if (prefs) rv = prefs->GetIntPref(NS_PREF_MAX_NUM_CACHED_PLUGINS,(int *)&max_num); if (NS_FAILED(rv)) max_num = DEFAULT_NUMBER_OF_STOPPED_PLUGINS; - if(mActivePluginList.getStoppedCount() >= max_num) - { + if(mActivePluginList.getStoppedCount() >= max_num) { nsActivePlugin * oldest = mActivePluginList.findOldestStopped(); - if(oldest != nsnull) - { + if(oldest != nsnull) { PRLibrary * library = oldest->mPluginTag->mLibrary; PRBool unloadLibLater = PR_FALSE; @@ -5781,7 +5771,6 @@ nsPluginHostImpl::StopPluginInstance(nsIPluginInstance* aInstance) } } } - return NS_OK; }