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

This commit is contained in:
av%netscape.com 2002-03-25 23:42:32 +00:00
Родитель 5d694a5ed1
Коммит b7a126ab4d
5 изменённых файлов: 37 добавлений и 33 удалений

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

@ -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 */

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

@ -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;

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

@ -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;
}

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

@ -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;

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

@ -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;
}