Bug fixes with plugin instance caching. We now keep track of a plugin instance's start/stop state.

This commit is contained in:
amusil%netscape.com 1999-06-04 22:32:27 +00:00
parent 50b315979f
commit eb37612c76
12 changed files with 142 additions and 12 deletions

View File

@ -71,6 +71,9 @@ public:
NS_IMETHOD
GetPlugins(PRUint32 aPluginCount, nsIDOMPlugin* aPluginArray[]) = 0;
NS_IMETHOD
StopPluginInstance(nsIPluginInstance* aInstance) = 0;
};
#endif // nsIPluginHost_h___

View File

@ -86,6 +86,7 @@ nsPluginTag::nsPluginTag()
mLibrary = nsnull;
mEntryPoint = nsnull;
mFlags = NS_PLUGIN_FLAG_ENABLED;
mFileName = nsnull;
}
inline char* new_str(char* str)
@ -118,6 +119,7 @@ nsPluginTag::nsPluginTag(nsPluginTag* aPluginTag)
mLibrary = nsnull;
mEntryPoint = nsnull;
mFlags = NS_PLUGIN_FLAG_ENABLED;
mFileName = new_str(aPluginTag->mFileName);
}
nsPluginTag::~nsPluginTag()
@ -168,6 +170,12 @@ nsPluginTag::~nsPluginTag()
PR_UnloadLibrary(mLibrary);
mLibrary = nsnull;
}
if(nsnull != mFileName)
{
delete [] mFileName;
mFileName = nsnull;
}
}
class nsPluginStreamInfo : public nsIPluginStreamInfo
@ -1470,10 +1478,9 @@ nsresult nsPluginHostImpl::FindStoppedPluginForURL(nsIURL* aURL, nsIPluginInstan
for(i=0; i<mNumActivePlugins; i++)
{
if(!PL_strcmp(url, mActivePluginList[i].mURL))
if(!PL_strcmp(url, mActivePluginList[i].mURL) && mActivePluginList[i].mStopped)
{
nsIPluginInstance* instance = mActivePluginList[i].mInstance;
nsIPluginInstancePeer* peer;
nsPluginWindow *window = nsnull;
aOwner->GetWindow(window);
@ -1487,6 +1494,8 @@ nsresult nsPluginHostImpl::FindStoppedPluginForURL(nsIURL* aURL, nsIPluginInstan
instance->SetWindow(window);
instance->Start();
mActivePluginList[i].mStopped = PR_FALSE;
return NS_OK;
}
}
@ -1507,6 +1516,8 @@ void nsPluginHostImpl::AddInstanceToActiveList(nsIPluginInstance* aInstance, nsI
mActivePluginList[mNumActivePlugins].mInstance = aInstance;
aInstance->GetPeer(&(mActivePluginList[mNumActivePlugins].mPeer));
mActivePluginList[mNumActivePlugins].mStopped = PR_FALSE;
++mNumActivePlugins;
}
else
@ -1523,6 +1534,7 @@ void nsPluginHostImpl::AddInstanceToActiveList(nsIPluginInstance* aInstance, nsI
mActivePluginList[mOldestActivePlugin].mURL = PL_strdup(url);
mActivePluginList[mOldestActivePlugin].mInstance = aInstance;
aInstance->GetPeer(&(mActivePluginList[mOldestActivePlugin].mPeer));
mActivePluginList[mOldestActivePlugin].mStopped = PR_FALSE;
++mOldestActivePlugin;
if(mOldestActivePlugin == MAX_ACTIVE_PLUGINS)
@ -1727,8 +1739,7 @@ public:
NS_METHOD GetFilename(nsString& aFilename)
{
// FIXME: need to keep the filename around.
aFilename = mPluginTag.mName;
aFilename = mPluginTag.mFileName;
return NS_OK;
}
@ -1970,6 +1981,23 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL,
return rv;
}
NS_IMETHODIMP
nsPluginHostImpl::StopPluginInstance(nsIPluginInstance* aInstance)
{
PRUint32 i;
for(i=0; i<mNumActivePlugins; i++)
{
if(mActivePluginList[i].mInstance == aInstance)
{
mActivePluginList[i].mStopped = PR_TRUE;
break;
}
}
return NS_OK;
}
/* Called by InstantiateEmbededPlugin() */
nsresult nsPluginHostImpl::NewEmbededPluginStream(nsIURL* aURL,

View File

@ -59,9 +59,10 @@ public:
typedef struct nsActivePlugin
{
char* mURL;
char* mURL;
nsIPluginInstancePeer* mPeer;
nsIPluginInstance* mInstance;
nsIPluginInstance* mInstance;
PRBool mStopped;
} nsActivePlugin;
#define NS_PLUGIN_FLAG_ENABLED 0x0001 //is this plugin enabled?
@ -225,6 +226,10 @@ public:
NS_IMETHOD
NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener);
NS_IMETHOD
StopPluginInstance(nsIPluginInstance* aInstance);
private:
/* Called by InstantiatePlugin */

View File

@ -895,3 +895,20 @@ NS_IMETHODIMP nsPluginInstancePeerImpl::ForceRedraw(void)
return NS_OK;
}
/*void
nsPluginInstancePeerImpl::SetStopped()
{
mStopped = PR_TRUE;
}
void
nsPluginInstancePeerImpl::SetStarted()
{
mStopped = PR_FALSE;
}
void
nsPluginInstancePeerImpl::IsStopped(PRBool *result)
{
*result = mStopped;
}*/

View File

@ -158,11 +158,17 @@ public:
nsresult GetOwner(nsIPluginInstanceOwner *&aOwner);
/* void SetStopped();
void SetStarted();
void IsStopped(PRBool *result);*/
private:
nsIPluginInstance *mInstance; //we don't add a ref to this
nsIPluginInstanceOwner *mOwner; //we don't add a ref to this
nsMIMEType mMIMEType;
PRUint32 mThreadID;
PRBool mStopped;
};
#endif

View File

@ -279,8 +279,13 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
{
DWORD zerome, versionsize;
char* verbuf = nsnull;
const char* fileName;
const char* path = this->GetCString();
fileName = PL_strrchr(path, '\\');
if(fileName)
++fileName;
versionsize = ::GetFileVersionInfoSize((char*)path, &zerome);
if (versionsize > 0)
verbuf = (char *)PR_Malloc(versionsize);
@ -300,6 +305,7 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
info.fMimeTypeArray = MakeStringArray(info.fVariantCount, info.fMimeType);
info.fMimeDescriptionArray = MakeStringArray(info.fVariantCount, info.fMimeDescription);
info.fExtensionArray = MakeStringArray(info.fVariantCount, info.fExtensions);
info.fFileName = PL_strdup(fileName);
}
else
return NS_ERROR_FAILURE;

View File

@ -71,6 +71,9 @@ public:
NS_IMETHOD
GetPlugins(PRUint32 aPluginCount, nsIDOMPlugin* aPluginArray[]) = 0;
NS_IMETHOD
StopPluginInstance(nsIPluginInstance* aInstance) = 0;
};
#endif // nsIPluginHost_h___

View File

@ -86,6 +86,7 @@ nsPluginTag::nsPluginTag()
mLibrary = nsnull;
mEntryPoint = nsnull;
mFlags = NS_PLUGIN_FLAG_ENABLED;
mFileName = nsnull;
}
inline char* new_str(char* str)
@ -118,6 +119,7 @@ nsPluginTag::nsPluginTag(nsPluginTag* aPluginTag)
mLibrary = nsnull;
mEntryPoint = nsnull;
mFlags = NS_PLUGIN_FLAG_ENABLED;
mFileName = new_str(aPluginTag->mFileName);
}
nsPluginTag::~nsPluginTag()
@ -168,6 +170,12 @@ nsPluginTag::~nsPluginTag()
PR_UnloadLibrary(mLibrary);
mLibrary = nsnull;
}
if(nsnull != mFileName)
{
delete [] mFileName;
mFileName = nsnull;
}
}
class nsPluginStreamInfo : public nsIPluginStreamInfo
@ -1470,10 +1478,9 @@ nsresult nsPluginHostImpl::FindStoppedPluginForURL(nsIURL* aURL, nsIPluginInstan
for(i=0; i<mNumActivePlugins; i++)
{
if(!PL_strcmp(url, mActivePluginList[i].mURL))
if(!PL_strcmp(url, mActivePluginList[i].mURL) && mActivePluginList[i].mStopped)
{
nsIPluginInstance* instance = mActivePluginList[i].mInstance;
nsIPluginInstancePeer* peer;
nsPluginWindow *window = nsnull;
aOwner->GetWindow(window);
@ -1487,6 +1494,8 @@ nsresult nsPluginHostImpl::FindStoppedPluginForURL(nsIURL* aURL, nsIPluginInstan
instance->SetWindow(window);
instance->Start();
mActivePluginList[i].mStopped = PR_FALSE;
return NS_OK;
}
}
@ -1507,6 +1516,8 @@ void nsPluginHostImpl::AddInstanceToActiveList(nsIPluginInstance* aInstance, nsI
mActivePluginList[mNumActivePlugins].mInstance = aInstance;
aInstance->GetPeer(&(mActivePluginList[mNumActivePlugins].mPeer));
mActivePluginList[mNumActivePlugins].mStopped = PR_FALSE;
++mNumActivePlugins;
}
else
@ -1523,6 +1534,7 @@ void nsPluginHostImpl::AddInstanceToActiveList(nsIPluginInstance* aInstance, nsI
mActivePluginList[mOldestActivePlugin].mURL = PL_strdup(url);
mActivePluginList[mOldestActivePlugin].mInstance = aInstance;
aInstance->GetPeer(&(mActivePluginList[mOldestActivePlugin].mPeer));
mActivePluginList[mOldestActivePlugin].mStopped = PR_FALSE;
++mOldestActivePlugin;
if(mOldestActivePlugin == MAX_ACTIVE_PLUGINS)
@ -1727,8 +1739,7 @@ public:
NS_METHOD GetFilename(nsString& aFilename)
{
// FIXME: need to keep the filename around.
aFilename = mPluginTag.mName;
aFilename = mPluginTag.mFileName;
return NS_OK;
}
@ -1970,6 +1981,23 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL,
return rv;
}
NS_IMETHODIMP
nsPluginHostImpl::StopPluginInstance(nsIPluginInstance* aInstance)
{
PRUint32 i;
for(i=0; i<mNumActivePlugins; i++)
{
if(mActivePluginList[i].mInstance == aInstance)
{
mActivePluginList[i].mStopped = PR_TRUE;
break;
}
}
return NS_OK;
}
/* Called by InstantiateEmbededPlugin() */
nsresult nsPluginHostImpl::NewEmbededPluginStream(nsIURL* aURL,

View File

@ -59,9 +59,10 @@ public:
typedef struct nsActivePlugin
{
char* mURL;
char* mURL;
nsIPluginInstancePeer* mPeer;
nsIPluginInstance* mInstance;
nsIPluginInstance* mInstance;
PRBool mStopped;
} nsActivePlugin;
#define NS_PLUGIN_FLAG_ENABLED 0x0001 //is this plugin enabled?
@ -225,6 +226,10 @@ public:
NS_IMETHOD
NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener);
NS_IMETHOD
StopPluginInstance(nsIPluginInstance* aInstance);
private:
/* Called by InstantiatePlugin */

View File

@ -895,3 +895,20 @@ NS_IMETHODIMP nsPluginInstancePeerImpl::ForceRedraw(void)
return NS_OK;
}
/*void
nsPluginInstancePeerImpl::SetStopped()
{
mStopped = PR_TRUE;
}
void
nsPluginInstancePeerImpl::SetStarted()
{
mStopped = PR_FALSE;
}
void
nsPluginInstancePeerImpl::IsStopped(PRBool *result)
{
*result = mStopped;
}*/

View File

@ -158,11 +158,17 @@ public:
nsresult GetOwner(nsIPluginInstanceOwner *&aOwner);
/* void SetStopped();
void SetStarted();
void IsStopped(PRBool *result);*/
private:
nsIPluginInstance *mInstance; //we don't add a ref to this
nsIPluginInstanceOwner *mOwner; //we don't add a ref to this
nsMIMEType mMIMEType;
PRUint32 mThreadID;
PRBool mStopped;
};
#endif

View File

@ -279,8 +279,13 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
{
DWORD zerome, versionsize;
char* verbuf = nsnull;
const char* fileName;
const char* path = this->GetCString();
fileName = PL_strrchr(path, '\\');
if(fileName)
++fileName;
versionsize = ::GetFileVersionInfoSize((char*)path, &zerome);
if (versionsize > 0)
verbuf = (char *)PR_Malloc(versionsize);
@ -300,6 +305,7 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
info.fMimeTypeArray = MakeStringArray(info.fVariantCount, info.fMimeType);
info.fMimeDescriptionArray = MakeStringArray(info.fVariantCount, info.fMimeDescription);
info.fExtensionArray = MakeStringArray(info.fVariantCount, info.fExtensions);
info.fFileName = PL_strdup(fileName);
}
else
return NS_ERROR_FAILURE;