For 73856, adding simple scriptability to the old style plugins, sr=vidur, ra=av

This commit is contained in:
av%netscape.com 2001-04-03 22:49:38 +00:00
Родитель 7fb2cbef9a
Коммит 4343179a46
8 изменённых файлов: 168 добавлений и 40 удалений

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

@ -418,7 +418,7 @@ ns4xPluginInstance :: IsStarted(void)
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
NS_IMPL_ISUPPORTS1(ns4xPluginInstance, nsIPluginInstance) NS_IMPL_ISUPPORTS2(ns4xPluginInstance, nsIPluginInstance, nsIScriptablePlugin)
static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID); static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID);
static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID); static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID);
@ -728,7 +728,10 @@ NS_IMETHODIMP ns4xPluginInstance::HandleEvent(nsPluginEvent* event, PRBool* hand
NS_IMETHODIMP ns4xPluginInstance :: GetValue(nsPluginInstanceVariable variable, NS_IMETHODIMP ns4xPluginInstance :: GetValue(nsPluginInstanceVariable variable,
void *value) void *value)
{ {
nsresult rv = NS_OK; if(!mStarted)
return NS_OK;
nsresult res = NS_OK;
switch (variable) switch (variable)
{ {
@ -741,30 +744,38 @@ NS_IMETHODIMP ns4xPluginInstance :: GetValue(nsPluginInstanceVariable variable,
break; break;
default: default:
rv = NS_ERROR_FAILURE; //XXX this is bad if(fCallbacks->getvalue)
{
NS_TRY_SAFE_CALL_RETURN(res,
CallNPP_GetValueProc(fCallbacks->getvalue,
&fNPP,
(NPPVariable)variable,
value),
fLibrary);
}
} }
return rv; return res;
} }
nsresult ns4xPluginInstance::GetNPP(NPP* aNPP) nsresult ns4xPluginInstance::GetNPP(NPP* aNPP)
{ {
if(aNPP != nsnull) if(aNPP != nsnull)
*aNPP = &fNPP; *aNPP = &fNPP;
else else
return NS_ERROR_NULL_POINTER; return NS_ERROR_NULL_POINTER;
return NS_OK; return NS_OK;
} }
nsresult ns4xPluginInstance::GetCallbacks(const NPPluginFuncs ** aCallbacks) nsresult ns4xPluginInstance::GetCallbacks(const NPPluginFuncs ** aCallbacks)
{ {
if(aCallbacks != nsnull) if(aCallbacks != nsnull)
*aCallbacks = fCallbacks; *aCallbacks = fCallbacks;
else else
return NS_ERROR_NULL_POINTER; return NS_ERROR_NULL_POINTER;
return NS_OK; return NS_OK;
} }
nsresult ns4xPluginInstance :: SetWindowless(PRBool aWindowless) nsresult ns4xPluginInstance :: SetWindowless(PRBool aWindowless)
@ -779,5 +790,22 @@ nsresult ns4xPluginInstance :: SetTransparent(PRBool aTransparent)
return NS_OK; return NS_OK;
} }
/* readonly attribute nsQIResult scriptablePeer; */
NS_IMETHODIMP ns4xPluginInstance :: GetScriptablePeer(void * *aScriptablePeer)
{
if (!aScriptablePeer)
return NS_ERROR_NULL_POINTER;
*aScriptablePeer = nsnull;
return GetValue(nsPluginInstanceVariable_ScriptableInstance, aScriptablePeer);
}
/* readonly attribute nsIIDPtr scriptableInterface; */
NS_IMETHODIMP ns4xPluginInstance :: GetScriptableInterface(nsIID * *aScriptableInterface)
{
if (!aScriptableInterface)
return NS_ERROR_NULL_POINTER;
*aScriptableInterface = nsnull;
return GetValue(nsPluginInstanceVariable_ScriptableIID, (void*)aScriptableInterface);
}

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

@ -35,6 +35,7 @@
#include "npupp.h" #include "npupp.h"
#include "jri.h" #include "jri.h"
#include "prlink.h" // for PRLibrary #include "prlink.h" // for PRLibrary
#include "nsIScriptablePlugin.h"
#ifdef MOZ_WIDGET_GTK #ifdef MOZ_WIDGET_GTK
#include <gtk/gtk.h> #include <gtk/gtk.h>
@ -42,7 +43,8 @@
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
class ns4xPluginInstance : public nsIPluginInstance class ns4xPluginInstance : public nsIPluginInstance,
public nsIScriptablePlugin
{ {
public: public:
@ -77,6 +79,13 @@ public:
NS_IMETHOD HandleEvent(nsPluginEvent* event, PRBool* handled); NS_IMETHOD HandleEvent(nsPluginEvent* event, PRBool* handled);
////////////////////////////////////////////////////////////////////////
// nsIScriptablePlugin methods
NS_IMETHOD GetScriptablePeer(void * *aScriptablePeer);
NS_IMETHOD GetScriptableInterface(nsIID * *aScriptableInterface);
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// ns4xPluginInstance-specific methods // ns4xPluginInstance-specific methods

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

@ -52,7 +52,7 @@
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsIProgressEventSink.h" #include "nsIProgressEventSink.h"
#include "nsIDocument.h" #include "nsIDocument.h"
#include "nsIScriptablePlugin.h"
#if MOZ_NEW_CACHE #if MOZ_NEW_CACHE
#include "nsICachingChannel.h" #include "nsICachingChannel.h"
@ -313,6 +313,7 @@ nsActivePlugin::nsActivePlugin(nsCOMPtr<nsIPlugin> aPlugin,
aInstance->GetPeer(&mPeer); aInstance->GetPeer(&mPeer);
NS_ADDREF(aInstance); NS_ADDREF(aInstance);
} }
mXPConnected = PR_FALSE;
mDefaultPlugin = aDefaultPlugin; mDefaultPlugin = aDefaultPlugin;
mStopped = PR_FALSE; mStopped = PR_FALSE;
mllStopTime = LL_ZERO; mllStopTime = LL_ZERO;
@ -1728,13 +1729,14 @@ nsPluginHostImpl::~nsPluginHostImpl()
Destroy(); Destroy();
} }
NS_IMPL_ISUPPORTS6(nsPluginHostImpl, NS_IMPL_ISUPPORTS7(nsPluginHostImpl,
nsIPluginManager, nsIPluginManager,
nsIPluginManager2, nsIPluginManager2,
nsIPluginHost, nsIPluginHost,
nsIFileUtilities, nsIFileUtilities,
nsICookieStorage, nsICookieStorage,
nsIObserver); nsIObserver,
nsPIPluginHost);
NS_METHOD NS_METHOD
nsPluginHostImpl::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult) nsPluginHostImpl::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult)
@ -4142,13 +4144,19 @@ nsPluginHostImpl::StopPluginInstance(nsIPluginInstance* aInstance)
if (!doCache || oldSchool) if (!doCache || oldSchool)
{ {
PRBool lastInstance = PR_FALSE; PRBool lastInstance = PR_FALSE;
PRBool xpConnected = plugin->mXPConnected;
mActivePluginList.remove(plugin, &lastInstance); mActivePluginList.remove(plugin, &lastInstance);
// and if this is the last instance we should unload the library // and if this was the last instance we should unload the library
// and clear mEntryPoint and mLibrary member of the pluginTag // and clear mEntryPoint and mLibrary member of the pluginTag
if(lastInstance) if(lastInstance)
{ {
pluginTag->mEntryPoint = nsnull; pluginTag->mEntryPoint = nsnull;
if(xpConnected)
pluginTag->mCanUnloadLibrary = PR_FALSE;
if ((nsnull != pluginTag->mLibrary) && pluginTag->mCanUnloadLibrary) if ((nsnull != pluginTag->mLibrary) && pluginTag->mCanUnloadLibrary)
{ {
PR_UnloadLibrary(pluginTag->mLibrary); PR_UnloadLibrary(pluginTag->mLibrary);
@ -4355,6 +4363,18 @@ NS_IMETHODIMP nsPluginHostImpl::Observe(nsISupports *aSubject,
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsPluginHostImpl::SetIsScriptableInstance(nsCOMPtr<nsIPluginInstance> aPluginInstance,
PRBool aScriptable)
{
nsActivePlugin * p = mActivePluginList.find(aPluginInstance.get());
if(p == nsnull)
return NS_ERROR_FAILURE;
p->mXPConnected = aScriptable;
return NS_OK;
}
NS_IMETHODIMP nsPluginHostImpl::HandleBadPlugin(PRLibrary* aLibrary) NS_IMETHODIMP nsPluginHostImpl::HandleBadPlugin(PRLibrary* aLibrary)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;

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

@ -28,6 +28,7 @@
#include "nsIPluginManager2.h" #include "nsIPluginManager2.h"
#include "nsIPluginHost.h" #include "nsIPluginHost.h"
#include "nsIObserver.h" #include "nsIObserver.h"
#include "nsPIPluginHost.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "prlink.h" #include "prlink.h"
@ -87,6 +88,7 @@ struct nsActivePlugin
PRBool mStopped; PRBool mStopped;
PRTime mllStopTime; PRTime mllStopTime;
PRBool mDefaultPlugin; PRBool mDefaultPlugin;
PRBool mXPConnected;
nsActivePlugin(nsCOMPtr<nsIPlugin> aPlugin, nsActivePlugin(nsCOMPtr<nsIPlugin> aPlugin,
nsIPluginInstance* aInstance, nsIPluginInstance* aInstance,
@ -144,7 +146,8 @@ class nsPluginHostImpl : public nsIPluginManager2,
public nsIPluginHost, public nsIPluginHost,
public nsIFileUtilities, public nsIFileUtilities,
public nsICookieStorage, public nsICookieStorage,
public nsIObserver public nsIObserver,
public nsPIPluginHost
{ {
public: public:
nsPluginHostImpl(); nsPluginHostImpl();
@ -327,6 +330,10 @@ public:
NS_IMETHOD NS_IMETHOD
Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData); Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData);
// Methods from nsPIPluginHost
NS_IMETHOD
SetIsScriptableInstance(nsCOMPtr<nsIPluginInstance> aPluginInstance, PRBool aScriptable);
/* Called by GetURL and PostURL */ /* Called by GetURL and PostURL */
NS_IMETHOD NS_IMETHOD

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

@ -418,7 +418,7 @@ ns4xPluginInstance :: IsStarted(void)
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
NS_IMPL_ISUPPORTS1(ns4xPluginInstance, nsIPluginInstance) NS_IMPL_ISUPPORTS2(ns4xPluginInstance, nsIPluginInstance, nsIScriptablePlugin)
static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID); static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID);
static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID); static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID);
@ -728,7 +728,10 @@ NS_IMETHODIMP ns4xPluginInstance::HandleEvent(nsPluginEvent* event, PRBool* hand
NS_IMETHODIMP ns4xPluginInstance :: GetValue(nsPluginInstanceVariable variable, NS_IMETHODIMP ns4xPluginInstance :: GetValue(nsPluginInstanceVariable variable,
void *value) void *value)
{ {
nsresult rv = NS_OK; if(!mStarted)
return NS_OK;
nsresult res = NS_OK;
switch (variable) switch (variable)
{ {
@ -741,30 +744,38 @@ NS_IMETHODIMP ns4xPluginInstance :: GetValue(nsPluginInstanceVariable variable,
break; break;
default: default:
rv = NS_ERROR_FAILURE; //XXX this is bad if(fCallbacks->getvalue)
{
NS_TRY_SAFE_CALL_RETURN(res,
CallNPP_GetValueProc(fCallbacks->getvalue,
&fNPP,
(NPPVariable)variable,
value),
fLibrary);
}
} }
return rv; return res;
} }
nsresult ns4xPluginInstance::GetNPP(NPP* aNPP) nsresult ns4xPluginInstance::GetNPP(NPP* aNPP)
{ {
if(aNPP != nsnull) if(aNPP != nsnull)
*aNPP = &fNPP; *aNPP = &fNPP;
else else
return NS_ERROR_NULL_POINTER; return NS_ERROR_NULL_POINTER;
return NS_OK; return NS_OK;
} }
nsresult ns4xPluginInstance::GetCallbacks(const NPPluginFuncs ** aCallbacks) nsresult ns4xPluginInstance::GetCallbacks(const NPPluginFuncs ** aCallbacks)
{ {
if(aCallbacks != nsnull) if(aCallbacks != nsnull)
*aCallbacks = fCallbacks; *aCallbacks = fCallbacks;
else else
return NS_ERROR_NULL_POINTER; return NS_ERROR_NULL_POINTER;
return NS_OK; return NS_OK;
} }
nsresult ns4xPluginInstance :: SetWindowless(PRBool aWindowless) nsresult ns4xPluginInstance :: SetWindowless(PRBool aWindowless)
@ -779,5 +790,22 @@ nsresult ns4xPluginInstance :: SetTransparent(PRBool aTransparent)
return NS_OK; return NS_OK;
} }
/* readonly attribute nsQIResult scriptablePeer; */
NS_IMETHODIMP ns4xPluginInstance :: GetScriptablePeer(void * *aScriptablePeer)
{
if (!aScriptablePeer)
return NS_ERROR_NULL_POINTER;
*aScriptablePeer = nsnull;
return GetValue(nsPluginInstanceVariable_ScriptableInstance, aScriptablePeer);
}
/* readonly attribute nsIIDPtr scriptableInterface; */
NS_IMETHODIMP ns4xPluginInstance :: GetScriptableInterface(nsIID * *aScriptableInterface)
{
if (!aScriptableInterface)
return NS_ERROR_NULL_POINTER;
*aScriptableInterface = nsnull;
return GetValue(nsPluginInstanceVariable_ScriptableIID, (void*)aScriptableInterface);
}

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

@ -35,6 +35,7 @@
#include "npupp.h" #include "npupp.h"
#include "jri.h" #include "jri.h"
#include "prlink.h" // for PRLibrary #include "prlink.h" // for PRLibrary
#include "nsIScriptablePlugin.h"
#ifdef MOZ_WIDGET_GTK #ifdef MOZ_WIDGET_GTK
#include <gtk/gtk.h> #include <gtk/gtk.h>
@ -42,7 +43,8 @@
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
class ns4xPluginInstance : public nsIPluginInstance class ns4xPluginInstance : public nsIPluginInstance,
public nsIScriptablePlugin
{ {
public: public:
@ -77,6 +79,13 @@ public:
NS_IMETHOD HandleEvent(nsPluginEvent* event, PRBool* handled); NS_IMETHOD HandleEvent(nsPluginEvent* event, PRBool* handled);
////////////////////////////////////////////////////////////////////////
// nsIScriptablePlugin methods
NS_IMETHOD GetScriptablePeer(void * *aScriptablePeer);
NS_IMETHOD GetScriptableInterface(nsIID * *aScriptableInterface);
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// ns4xPluginInstance-specific methods // ns4xPluginInstance-specific methods

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

@ -52,7 +52,7 @@
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsIProgressEventSink.h" #include "nsIProgressEventSink.h"
#include "nsIDocument.h" #include "nsIDocument.h"
#include "nsIScriptablePlugin.h"
#if MOZ_NEW_CACHE #if MOZ_NEW_CACHE
#include "nsICachingChannel.h" #include "nsICachingChannel.h"
@ -313,6 +313,7 @@ nsActivePlugin::nsActivePlugin(nsCOMPtr<nsIPlugin> aPlugin,
aInstance->GetPeer(&mPeer); aInstance->GetPeer(&mPeer);
NS_ADDREF(aInstance); NS_ADDREF(aInstance);
} }
mXPConnected = PR_FALSE;
mDefaultPlugin = aDefaultPlugin; mDefaultPlugin = aDefaultPlugin;
mStopped = PR_FALSE; mStopped = PR_FALSE;
mllStopTime = LL_ZERO; mllStopTime = LL_ZERO;
@ -1728,13 +1729,14 @@ nsPluginHostImpl::~nsPluginHostImpl()
Destroy(); Destroy();
} }
NS_IMPL_ISUPPORTS6(nsPluginHostImpl, NS_IMPL_ISUPPORTS7(nsPluginHostImpl,
nsIPluginManager, nsIPluginManager,
nsIPluginManager2, nsIPluginManager2,
nsIPluginHost, nsIPluginHost,
nsIFileUtilities, nsIFileUtilities,
nsICookieStorage, nsICookieStorage,
nsIObserver); nsIObserver,
nsPIPluginHost);
NS_METHOD NS_METHOD
nsPluginHostImpl::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult) nsPluginHostImpl::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult)
@ -4142,13 +4144,19 @@ nsPluginHostImpl::StopPluginInstance(nsIPluginInstance* aInstance)
if (!doCache || oldSchool) if (!doCache || oldSchool)
{ {
PRBool lastInstance = PR_FALSE; PRBool lastInstance = PR_FALSE;
PRBool xpConnected = plugin->mXPConnected;
mActivePluginList.remove(plugin, &lastInstance); mActivePluginList.remove(plugin, &lastInstance);
// and if this is the last instance we should unload the library // and if this was the last instance we should unload the library
// and clear mEntryPoint and mLibrary member of the pluginTag // and clear mEntryPoint and mLibrary member of the pluginTag
if(lastInstance) if(lastInstance)
{ {
pluginTag->mEntryPoint = nsnull; pluginTag->mEntryPoint = nsnull;
if(xpConnected)
pluginTag->mCanUnloadLibrary = PR_FALSE;
if ((nsnull != pluginTag->mLibrary) && pluginTag->mCanUnloadLibrary) if ((nsnull != pluginTag->mLibrary) && pluginTag->mCanUnloadLibrary)
{ {
PR_UnloadLibrary(pluginTag->mLibrary); PR_UnloadLibrary(pluginTag->mLibrary);
@ -4355,6 +4363,18 @@ NS_IMETHODIMP nsPluginHostImpl::Observe(nsISupports *aSubject,
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsPluginHostImpl::SetIsScriptableInstance(nsCOMPtr<nsIPluginInstance> aPluginInstance,
PRBool aScriptable)
{
nsActivePlugin * p = mActivePluginList.find(aPluginInstance.get());
if(p == nsnull)
return NS_ERROR_FAILURE;
p->mXPConnected = aScriptable;
return NS_OK;
}
NS_IMETHODIMP nsPluginHostImpl::HandleBadPlugin(PRLibrary* aLibrary) NS_IMETHODIMP nsPluginHostImpl::HandleBadPlugin(PRLibrary* aLibrary)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;

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

@ -28,6 +28,7 @@
#include "nsIPluginManager2.h" #include "nsIPluginManager2.h"
#include "nsIPluginHost.h" #include "nsIPluginHost.h"
#include "nsIObserver.h" #include "nsIObserver.h"
#include "nsPIPluginHost.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "prlink.h" #include "prlink.h"
@ -87,6 +88,7 @@ struct nsActivePlugin
PRBool mStopped; PRBool mStopped;
PRTime mllStopTime; PRTime mllStopTime;
PRBool mDefaultPlugin; PRBool mDefaultPlugin;
PRBool mXPConnected;
nsActivePlugin(nsCOMPtr<nsIPlugin> aPlugin, nsActivePlugin(nsCOMPtr<nsIPlugin> aPlugin,
nsIPluginInstance* aInstance, nsIPluginInstance* aInstance,
@ -144,7 +146,8 @@ class nsPluginHostImpl : public nsIPluginManager2,
public nsIPluginHost, public nsIPluginHost,
public nsIFileUtilities, public nsIFileUtilities,
public nsICookieStorage, public nsICookieStorage,
public nsIObserver public nsIObserver,
public nsPIPluginHost
{ {
public: public:
nsPluginHostImpl(); nsPluginHostImpl();
@ -327,6 +330,10 @@ public:
NS_IMETHOD NS_IMETHOD
Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData); Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData);
// Methods from nsPIPluginHost
NS_IMETHOD
SetIsScriptableInstance(nsCOMPtr<nsIPluginInstance> aPluginInstance, PRBool aScriptable);
/* Called by GetURL and PostURL */ /* Called by GetURL and PostURL */
NS_IMETHOD NS_IMETHOD