зеркало из https://github.com/mozilla/gecko-dev.git
Bug 37522. Implement ns4xPlugin::GetMIMEDescription() and ns4xPlugin::GetValue(); alter nsPluginsDirUNIX to use these routines (instead of directly calling the NP_* routine) while grovelling through 4.x plugins. r=av
This commit is contained in:
Родитель
d5b4381214
Коммит
b95b383548
|
@ -110,13 +110,14 @@ static NS_DEFINE_IID(kIPluginStreamListenerIID, NS_IPLUGINSTREAMLISTENER_IID);
|
|||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ns4xPlugin::ns4xPlugin(NPPluginFuncs* callbacks, NP_PLUGINSHUTDOWN aShutdown, nsIServiceManager* serviceMgr)
|
||||
ns4xPlugin::ns4xPlugin(NPPluginFuncs* callbacks, PRLibrary* aLibrary, NP_PLUGINSHUTDOWN aShutdown, nsIServiceManager* serviceMgr)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
memcpy((void*) &fCallbacks, (void*) callbacks, sizeof(fCallbacks));
|
||||
fShutdownEntry = aShutdown;
|
||||
|
||||
fLibrary = aLibrary;
|
||||
mServiceMgr = serviceMgr;
|
||||
}
|
||||
|
||||
|
@ -186,14 +187,17 @@ ns4xPlugin::SetPluginRefNum(short aRefNum)
|
|||
*/
|
||||
|
||||
nsresult
|
||||
ns4xPlugin::CreatePlugin(nsPluginTag* pluginTag, nsIServiceManager* serviceMgr)
|
||||
ns4xPlugin::CreatePlugin(nsIServiceManager* aServiceMgr,
|
||||
const char* aFileName,
|
||||
PRLibrary* aLibrary,
|
||||
nsIPlugin** aResult)
|
||||
{
|
||||
CheckClassInitialized();
|
||||
|
||||
// set up the MemAllocator service now because it might be used by the plugin
|
||||
if (serviceMgr != nsnull) {
|
||||
if (aServiceMgr != nsnull) {
|
||||
if (nsnull == mMalloc)
|
||||
serviceMgr->GetService(kMemoryCID, kIMemoryIID, (nsISupports**)&mMalloc);
|
||||
aServiceMgr->GetService(kMemoryCID, kIMemoryIID, (nsISupports**)&mMalloc);
|
||||
}
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
|
@ -213,15 +217,15 @@ ns4xPlugin::CreatePlugin(nsPluginTag* pluginTag, nsIServiceManager* serviceMgr)
|
|||
#endif
|
||||
|
||||
NP_PLUGINSHUTDOWN pfnShutdown =
|
||||
(NP_PLUGINSHUTDOWN)PR_FindSymbol(pluginTag->mLibrary, "NP_Shutdown");
|
||||
(NP_PLUGINSHUTDOWN)PR_FindSymbol(aLibrary, "NP_Shutdown");
|
||||
|
||||
// create the new plugin handler
|
||||
pluginTag->mEntryPoint = plptr = new ns4xPlugin(&callbacks, pfnShutdown, serviceMgr);
|
||||
*aResult = plptr = new ns4xPlugin(&callbacks, aLibrary, pfnShutdown, aServiceMgr);
|
||||
|
||||
if (pluginTag->mEntryPoint == NULL)
|
||||
if (*aResult == NULL)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(pluginTag->mEntryPoint);
|
||||
NS_ADDREF(*aResult);
|
||||
|
||||
// we must init here because the plugin may call NPN functions
|
||||
// when we call into the NP_Initialize entry point - NPN functions
|
||||
|
@ -229,7 +233,7 @@ ns4xPlugin::CreatePlugin(nsPluginTag* pluginTag, nsIServiceManager* serviceMgr)
|
|||
plptr->Initialize();
|
||||
|
||||
NP_PLUGINUNIXINIT pfnInitialize =
|
||||
(NP_PLUGINUNIXINIT)PR_FindSymbol(pluginTag->mLibrary, "NP_Initialize");
|
||||
(NP_PLUGINUNIXINIT)PR_FindSymbol(aLibrary, "NP_Initialize");
|
||||
|
||||
if (pfnInitialize == NULL)
|
||||
return NS_ERROR_UNEXPECTED; // XXX Right error?
|
||||
|
@ -249,7 +253,7 @@ ns4xPlugin::CreatePlugin(nsPluginTag* pluginTag, nsIServiceManager* serviceMgr)
|
|||
#ifdef XP_PC
|
||||
// XXX this only applies on Windows
|
||||
NP_GETENTRYPOINTS pfnGetEntryPoints =
|
||||
(NP_GETENTRYPOINTS)PR_FindSymbol(pluginTag->mLibrary, "NP_GetEntryPoints");
|
||||
(NP_GETENTRYPOINTS)PR_FindSymbol(aLibrary, "NP_GetEntryPoints");
|
||||
|
||||
if (pfnGetEntryPoints == NULL)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -268,20 +272,20 @@ ns4xPlugin::CreatePlugin(nsPluginTag* pluginTag, nsIServiceManager* serviceMgr)
|
|||
#endif
|
||||
|
||||
NP_PLUGINSHUTDOWN pfnShutdown =
|
||||
(NP_PLUGINSHUTDOWN)PR_FindSymbol(pluginTag->mLibrary, "NP_Shutdown");
|
||||
(NP_PLUGINSHUTDOWN)PR_FindSymbol(aLibrary, "NP_Shutdown");
|
||||
|
||||
// create the new plugin handler
|
||||
pluginTag->mEntryPoint = new ns4xPlugin(&callbacks, pfnShutdown, serviceMgr);
|
||||
*aResult = new ns4xPlugin(&callbacks, aLibrary, pfnShutdown, aServiceMgr);
|
||||
|
||||
if (pluginTag->mEntryPoint == NULL)
|
||||
if (*aResult == NULL)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(pluginTag->mEntryPoint);
|
||||
NS_ADDREF(*aResult);
|
||||
|
||||
// we must init here because the plugin may call NPN functions
|
||||
// when we call into the NP_Initialize entry point - NPN functions
|
||||
// require that mBrowserManager be set up
|
||||
pluginTag->mEntryPoint->Initialize();
|
||||
(*aResult)->Initialize();
|
||||
|
||||
// the NP_Initialize entry point was misnamed as NP_PluginInit,
|
||||
// early in plugin project development. Its correct name is
|
||||
|
@ -290,11 +294,11 @@ ns4xPlugin::CreatePlugin(nsPluginTag* pluginTag, nsIServiceManager* serviceMgr)
|
|||
// we'll accept either name
|
||||
|
||||
NP_PLUGININIT pfnInitialize =
|
||||
(NP_PLUGININIT)PR_FindSymbol(pluginTag->mLibrary, "NP_Initialize");
|
||||
(NP_PLUGININIT)PR_FindSymbol(aLibrary, "NP_Initialize");
|
||||
|
||||
if (!pfnInitialize) {
|
||||
pfnInitialize =
|
||||
(NP_PLUGININIT)PR_FindSymbol(pluginTag->mLibrary, "NP_PluginInit");
|
||||
(NP_PLUGININIT)PR_FindSymbol(aLibrary, "NP_PluginInit");
|
||||
}
|
||||
|
||||
if (pfnInitialize == NULL)
|
||||
|
@ -306,7 +310,7 @@ ns4xPlugin::CreatePlugin(nsPluginTag* pluginTag, nsIServiceManager* serviceMgr)
|
|||
|
||||
#if defined(XP_MAC) && !TARGET_CARBON
|
||||
// get the mainRD entry point
|
||||
NP_MAIN pfnMain = (NP_MAIN) PR_FindSymbol(pluginTag->mLibrary, "mainRD");
|
||||
NP_MAIN pfnMain = (NP_MAIN) PR_FindSymbol(aLibrary, "mainRD");
|
||||
if(pfnMain == NULL)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
|
@ -328,7 +332,7 @@ ns4xPlugin::CreatePlugin(nsPluginTag* pluginTag, nsIServiceManager* serviceMgr)
|
|||
{
|
||||
FSSpec spec = file;
|
||||
char* fileName = p2cstrdup(spec.name);
|
||||
if(!PL_strcmp(fileName, pluginTag->mFileName))
|
||||
if(!PL_strcmp(fileName, aFileName))
|
||||
{
|
||||
Boolean targetIsFolder, wasAliased;
|
||||
OSErr err = ::ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased);
|
||||
|
@ -347,25 +351,23 @@ ns4xPlugin::CreatePlugin(nsPluginTag* pluginTag, nsIServiceManager* serviceMgr)
|
|||
return NS_ERROR_FAILURE;
|
||||
|
||||
// create the new plugin handler
|
||||
ns4xPlugin* plugin = new ns4xPlugin(&callbacks, (NP_PLUGINSHUTDOWN)pfnShutdown, serviceMgr);
|
||||
ns4xPlugin* plugin = new ns4xPlugin(&callbacks, aLibrary, (NP_PLUGINSHUTDOWN)pfnShutdown, aServiceMgr);
|
||||
|
||||
if(plugin == NULL)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
plugin->SetPluginRefNum(pluginRefNum);
|
||||
|
||||
pluginTag->mEntryPoint = plugin;
|
||||
*aResult = plugin;
|
||||
|
||||
NS_ADDREF(pluginTag->mEntryPoint);
|
||||
#endif
|
||||
|
||||
#ifdef XP_UNIX
|
||||
return NS_ERROR_FAILURE;
|
||||
NS_ADDREF(*aResult);
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
CreateInstance()
|
||||
----------------
|
||||
|
@ -447,9 +449,11 @@ ns4xPlugin::GetMIMEDescription(const char* *resultingDesc)
|
|||
#ifdef NS_DEBUG
|
||||
printf("plugin getmimedescription called\n");
|
||||
#endif
|
||||
const char* (*npGetMIMEDescrpition)() =
|
||||
(const char* (*)()) PR_FindSymbol(fLibrary, "NP_GetMIMEDescription");
|
||||
|
||||
*resultingDesc = "";
|
||||
return NS_OK; // XXX make a callback, etc.
|
||||
*resultingDesc = npGetMIMEDescrpition ? npGetMIMEDescrpition() : "";
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -459,7 +463,15 @@ ns4xPlugin::GetValue(nsPluginVariable variable, void *value)
|
|||
printf("plugin getvalue %d called\n", variable);
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
NPError (*npGetValue)(void*, nsPluginVariable, void*) =
|
||||
(NPError (*)(void*, nsPluginVariable, void*)) PR_FindSymbol(fLibrary, "NP_GetValue");
|
||||
|
||||
if (npGetValue && NPERR_NO_ERROR == npGetValue(nsnull, variable, value)) {
|
||||
return NS_OK;
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -68,7 +68,7 @@ class ns4xPlugin : public nsIPlugin
|
|||
{
|
||||
public:
|
||||
|
||||
ns4xPlugin(NPPluginFuncs* callbacks, NP_PLUGINSHUTDOWN aShutdown, nsIServiceManager* serviceMgr);
|
||||
ns4xPlugin(NPPluginFuncs* callbacks, PRLibrary* aLibrary, NP_PLUGINSHUTDOWN aShutdown, nsIServiceManager* serviceMgr);
|
||||
virtual ~ns4xPlugin(void);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
@ -114,7 +114,10 @@ public:
|
|||
*/
|
||||
|
||||
static nsresult
|
||||
CreatePlugin(nsPluginTag* pluginTag, nsIServiceManager* serviceMgr);
|
||||
CreatePlugin(nsIServiceManager* aServiceMgr,
|
||||
const char* aFileName,
|
||||
PRLibrary* aLibrary,
|
||||
nsIPlugin** aResult);
|
||||
|
||||
#ifdef XP_MAC
|
||||
void
|
||||
|
@ -238,6 +241,7 @@ protected:
|
|||
* plugin callbacks for each plugin.
|
||||
*/
|
||||
NPPluginFuncs fCallbacks;
|
||||
PRLibrary* fLibrary;
|
||||
|
||||
NP_PLUGINSHUTDOWN fShutdownEntry;
|
||||
|
||||
|
|
|
@ -2462,7 +2462,11 @@ NS_IMETHODIMP nsPluginHostImpl::GetPluginFactory(const char *aMimeType, nsIPlugi
|
|||
}
|
||||
else
|
||||
{
|
||||
rv = ns4xPlugin::CreatePlugin(pluginTag, mServiceMgr);
|
||||
rv = ns4xPlugin::CreatePlugin(mServiceMgr,
|
||||
pluginTag->mFileName,
|
||||
pluginTag->mLibrary,
|
||||
&pluginTag->mEntryPoint);
|
||||
|
||||
plugin = pluginTag->mEntryPoint;
|
||||
pluginTag->mFlags |= NS_PLUGIN_FLAG_OLDSCHOOL;
|
||||
|
||||
|
|
|
@ -28,33 +28,23 @@
|
|||
by Alex Musil
|
||||
*/
|
||||
|
||||
#include "xp_core.h"
|
||||
#include "nsplugin.h"
|
||||
#include "ns4xPlugin.h"
|
||||
#include "ns4xPluginInstance.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIMemory.h"
|
||||
#include "nsIPluginStreamListener.h"
|
||||
#include "nsPluginsDir.h"
|
||||
#include "prlink.h"
|
||||
#include "plstr.h"
|
||||
#include "prmem.h"
|
||||
#include "nsString.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
#include "prmem.h"
|
||||
|
||||
/* Local helper functions */
|
||||
|
||||
static char* GetFileName(const char* pathname)
|
||||
{
|
||||
const char* filename = nsnull;
|
||||
|
||||
// this is most likely a path, so skip to the filename
|
||||
filename = PL_strrchr(pathname, '/');
|
||||
if(filename)
|
||||
++filename;
|
||||
else
|
||||
filename = pathname;
|
||||
|
||||
return PL_strdup(filename);
|
||||
}
|
||||
|
||||
static PRUint32 CalculateVariantCount(char* mimeTypes)
|
||||
static PRUint32 CalculateVariantCount(const char* mimeTypes)
|
||||
{
|
||||
PRUint32 variants = 0;
|
||||
char* ptr = mimeTypes;
|
||||
const char* ptr = mimeTypes;
|
||||
while (*ptr)
|
||||
{
|
||||
if (*ptr == ';')
|
||||
|
@ -162,35 +152,60 @@ nsresult nsPluginFile::LoadPlugin(PRLibrary* &outLibrary)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
typedef char* (*UNIX_Plugin_GetMIMEDescription)();
|
||||
|
||||
|
||||
/**
|
||||
* Obtains all of the information currently available for this plugin.
|
||||
*/
|
||||
nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
{
|
||||
const char *path = this->GetCString();
|
||||
char *mimedescr,*mdesc,*start,*nexttoc,*mtype,*exten,*descr;
|
||||
NS_ERROR("stop");
|
||||
|
||||
nsresult rv;
|
||||
const char* mimedescr;
|
||||
char *mdesc,*start,*nexttoc,*mtype,*exten,*descr;
|
||||
int i,num;
|
||||
|
||||
UNIX_Plugin_GetMIMEDescription procedure = nsnull;
|
||||
mimedescr=(char *)"";
|
||||
// No, this doesn't leak. GetGlobalServiceManager() doesn't addref
|
||||
// it's out pointer. Maybe it should.
|
||||
nsIServiceManager* mgr;
|
||||
nsServiceManager::GetGlobalServiceManager(&mgr);
|
||||
|
||||
if((procedure = (UNIX_Plugin_GetMIMEDescription)PR_FindSymbol(pLibrary,"NP_GetMIMEDescription")) != 0) {
|
||||
mimedescr = procedure();
|
||||
} else {
|
||||
#ifdef NS_DEBUG
|
||||
printf("Cannot get plugin info: no GetMIMEDescription procedure!\n");
|
||||
#endif
|
||||
return NS_ERROR_FAILURE;
|
||||
nsFactoryProc nsGetFactory =
|
||||
(nsFactoryProc) PR_FindSymbol(pLibrary, "NSGetFactory");
|
||||
|
||||
nsCOMPtr<nsIPlugin> plugin;
|
||||
|
||||
if (nsGetFactory) {
|
||||
// It's an almost-new-style plugin. The "truly new" plugins
|
||||
// are just XPCOM components, but there are some Mozilla
|
||||
// Classic holdovers that live in the plugins directory but
|
||||
// implement nsIPlugin and the factory stuff.
|
||||
static NS_DEFINE_CID(kPluginCID, NS_PLUGIN_CID);
|
||||
|
||||
nsCOMPtr<nsIFactory> factory;
|
||||
rv = nsGetFactory(mgr, kPluginCID, nsnull, nsnull, getter_AddRefs(factory));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
plugin = do_QueryInterface(factory);
|
||||
}
|
||||
else {
|
||||
// It's old sk00l
|
||||
rv = ns4xPlugin::CreatePlugin(mgr, this->GetCString(), pLibrary, getter_AddRefs(plugin));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
info.fName = GetFileName(path);
|
||||
if (plugin) {
|
||||
plugin->GetValue(nsPluginVariable_NameString, &info.fName);
|
||||
plugin->GetValue(nsPluginVariable_DescriptionString, &info.fDescription);
|
||||
plugin->GetMIMEDescription(&mimedescr);
|
||||
}
|
||||
else {
|
||||
info.fName = PL_strdup(this->GetCString()); // XXXwaterson LEAK
|
||||
info.fDescription = "";
|
||||
info.fMimeDescription = "";
|
||||
}
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
printf("GetMIMEDescription() %lx returned \"%s\"\n",
|
||||
(unsigned long)procedure, mimedescr);
|
||||
printf("GetMIMEDescription() returned \"%s\"\n", mimedescr);
|
||||
#endif
|
||||
|
||||
// copy string
|
||||
|
|
|
@ -110,13 +110,14 @@ static NS_DEFINE_IID(kIPluginStreamListenerIID, NS_IPLUGINSTREAMLISTENER_IID);
|
|||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ns4xPlugin::ns4xPlugin(NPPluginFuncs* callbacks, NP_PLUGINSHUTDOWN aShutdown, nsIServiceManager* serviceMgr)
|
||||
ns4xPlugin::ns4xPlugin(NPPluginFuncs* callbacks, PRLibrary* aLibrary, NP_PLUGINSHUTDOWN aShutdown, nsIServiceManager* serviceMgr)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
memcpy((void*) &fCallbacks, (void*) callbacks, sizeof(fCallbacks));
|
||||
fShutdownEntry = aShutdown;
|
||||
|
||||
fLibrary = aLibrary;
|
||||
mServiceMgr = serviceMgr;
|
||||
}
|
||||
|
||||
|
@ -186,14 +187,17 @@ ns4xPlugin::SetPluginRefNum(short aRefNum)
|
|||
*/
|
||||
|
||||
nsresult
|
||||
ns4xPlugin::CreatePlugin(nsPluginTag* pluginTag, nsIServiceManager* serviceMgr)
|
||||
ns4xPlugin::CreatePlugin(nsIServiceManager* aServiceMgr,
|
||||
const char* aFileName,
|
||||
PRLibrary* aLibrary,
|
||||
nsIPlugin** aResult)
|
||||
{
|
||||
CheckClassInitialized();
|
||||
|
||||
// set up the MemAllocator service now because it might be used by the plugin
|
||||
if (serviceMgr != nsnull) {
|
||||
if (aServiceMgr != nsnull) {
|
||||
if (nsnull == mMalloc)
|
||||
serviceMgr->GetService(kMemoryCID, kIMemoryIID, (nsISupports**)&mMalloc);
|
||||
aServiceMgr->GetService(kMemoryCID, kIMemoryIID, (nsISupports**)&mMalloc);
|
||||
}
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
|
@ -213,15 +217,15 @@ ns4xPlugin::CreatePlugin(nsPluginTag* pluginTag, nsIServiceManager* serviceMgr)
|
|||
#endif
|
||||
|
||||
NP_PLUGINSHUTDOWN pfnShutdown =
|
||||
(NP_PLUGINSHUTDOWN)PR_FindSymbol(pluginTag->mLibrary, "NP_Shutdown");
|
||||
(NP_PLUGINSHUTDOWN)PR_FindSymbol(aLibrary, "NP_Shutdown");
|
||||
|
||||
// create the new plugin handler
|
||||
pluginTag->mEntryPoint = plptr = new ns4xPlugin(&callbacks, pfnShutdown, serviceMgr);
|
||||
*aResult = plptr = new ns4xPlugin(&callbacks, aLibrary, pfnShutdown, aServiceMgr);
|
||||
|
||||
if (pluginTag->mEntryPoint == NULL)
|
||||
if (*aResult == NULL)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(pluginTag->mEntryPoint);
|
||||
NS_ADDREF(*aResult);
|
||||
|
||||
// we must init here because the plugin may call NPN functions
|
||||
// when we call into the NP_Initialize entry point - NPN functions
|
||||
|
@ -229,7 +233,7 @@ ns4xPlugin::CreatePlugin(nsPluginTag* pluginTag, nsIServiceManager* serviceMgr)
|
|||
plptr->Initialize();
|
||||
|
||||
NP_PLUGINUNIXINIT pfnInitialize =
|
||||
(NP_PLUGINUNIXINIT)PR_FindSymbol(pluginTag->mLibrary, "NP_Initialize");
|
||||
(NP_PLUGINUNIXINIT)PR_FindSymbol(aLibrary, "NP_Initialize");
|
||||
|
||||
if (pfnInitialize == NULL)
|
||||
return NS_ERROR_UNEXPECTED; // XXX Right error?
|
||||
|
@ -249,7 +253,7 @@ ns4xPlugin::CreatePlugin(nsPluginTag* pluginTag, nsIServiceManager* serviceMgr)
|
|||
#ifdef XP_PC
|
||||
// XXX this only applies on Windows
|
||||
NP_GETENTRYPOINTS pfnGetEntryPoints =
|
||||
(NP_GETENTRYPOINTS)PR_FindSymbol(pluginTag->mLibrary, "NP_GetEntryPoints");
|
||||
(NP_GETENTRYPOINTS)PR_FindSymbol(aLibrary, "NP_GetEntryPoints");
|
||||
|
||||
if (pfnGetEntryPoints == NULL)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -268,20 +272,20 @@ ns4xPlugin::CreatePlugin(nsPluginTag* pluginTag, nsIServiceManager* serviceMgr)
|
|||
#endif
|
||||
|
||||
NP_PLUGINSHUTDOWN pfnShutdown =
|
||||
(NP_PLUGINSHUTDOWN)PR_FindSymbol(pluginTag->mLibrary, "NP_Shutdown");
|
||||
(NP_PLUGINSHUTDOWN)PR_FindSymbol(aLibrary, "NP_Shutdown");
|
||||
|
||||
// create the new plugin handler
|
||||
pluginTag->mEntryPoint = new ns4xPlugin(&callbacks, pfnShutdown, serviceMgr);
|
||||
*aResult = new ns4xPlugin(&callbacks, aLibrary, pfnShutdown, aServiceMgr);
|
||||
|
||||
if (pluginTag->mEntryPoint == NULL)
|
||||
if (*aResult == NULL)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(pluginTag->mEntryPoint);
|
||||
NS_ADDREF(*aResult);
|
||||
|
||||
// we must init here because the plugin may call NPN functions
|
||||
// when we call into the NP_Initialize entry point - NPN functions
|
||||
// require that mBrowserManager be set up
|
||||
pluginTag->mEntryPoint->Initialize();
|
||||
(*aResult)->Initialize();
|
||||
|
||||
// the NP_Initialize entry point was misnamed as NP_PluginInit,
|
||||
// early in plugin project development. Its correct name is
|
||||
|
@ -290,11 +294,11 @@ ns4xPlugin::CreatePlugin(nsPluginTag* pluginTag, nsIServiceManager* serviceMgr)
|
|||
// we'll accept either name
|
||||
|
||||
NP_PLUGININIT pfnInitialize =
|
||||
(NP_PLUGININIT)PR_FindSymbol(pluginTag->mLibrary, "NP_Initialize");
|
||||
(NP_PLUGININIT)PR_FindSymbol(aLibrary, "NP_Initialize");
|
||||
|
||||
if (!pfnInitialize) {
|
||||
pfnInitialize =
|
||||
(NP_PLUGININIT)PR_FindSymbol(pluginTag->mLibrary, "NP_PluginInit");
|
||||
(NP_PLUGININIT)PR_FindSymbol(aLibrary, "NP_PluginInit");
|
||||
}
|
||||
|
||||
if (pfnInitialize == NULL)
|
||||
|
@ -306,7 +310,7 @@ ns4xPlugin::CreatePlugin(nsPluginTag* pluginTag, nsIServiceManager* serviceMgr)
|
|||
|
||||
#if defined(XP_MAC) && !TARGET_CARBON
|
||||
// get the mainRD entry point
|
||||
NP_MAIN pfnMain = (NP_MAIN) PR_FindSymbol(pluginTag->mLibrary, "mainRD");
|
||||
NP_MAIN pfnMain = (NP_MAIN) PR_FindSymbol(aLibrary, "mainRD");
|
||||
if(pfnMain == NULL)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
|
@ -328,7 +332,7 @@ ns4xPlugin::CreatePlugin(nsPluginTag* pluginTag, nsIServiceManager* serviceMgr)
|
|||
{
|
||||
FSSpec spec = file;
|
||||
char* fileName = p2cstrdup(spec.name);
|
||||
if(!PL_strcmp(fileName, pluginTag->mFileName))
|
||||
if(!PL_strcmp(fileName, aFileName))
|
||||
{
|
||||
Boolean targetIsFolder, wasAliased;
|
||||
OSErr err = ::ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased);
|
||||
|
@ -347,25 +351,23 @@ ns4xPlugin::CreatePlugin(nsPluginTag* pluginTag, nsIServiceManager* serviceMgr)
|
|||
return NS_ERROR_FAILURE;
|
||||
|
||||
// create the new plugin handler
|
||||
ns4xPlugin* plugin = new ns4xPlugin(&callbacks, (NP_PLUGINSHUTDOWN)pfnShutdown, serviceMgr);
|
||||
ns4xPlugin* plugin = new ns4xPlugin(&callbacks, aLibrary, (NP_PLUGINSHUTDOWN)pfnShutdown, aServiceMgr);
|
||||
|
||||
if(plugin == NULL)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
plugin->SetPluginRefNum(pluginRefNum);
|
||||
|
||||
pluginTag->mEntryPoint = plugin;
|
||||
*aResult = plugin;
|
||||
|
||||
NS_ADDREF(pluginTag->mEntryPoint);
|
||||
#endif
|
||||
|
||||
#ifdef XP_UNIX
|
||||
return NS_ERROR_FAILURE;
|
||||
NS_ADDREF(*aResult);
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
CreateInstance()
|
||||
----------------
|
||||
|
@ -447,9 +449,11 @@ ns4xPlugin::GetMIMEDescription(const char* *resultingDesc)
|
|||
#ifdef NS_DEBUG
|
||||
printf("plugin getmimedescription called\n");
|
||||
#endif
|
||||
const char* (*npGetMIMEDescrpition)() =
|
||||
(const char* (*)()) PR_FindSymbol(fLibrary, "NP_GetMIMEDescription");
|
||||
|
||||
*resultingDesc = "";
|
||||
return NS_OK; // XXX make a callback, etc.
|
||||
*resultingDesc = npGetMIMEDescrpition ? npGetMIMEDescrpition() : "";
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -459,7 +463,15 @@ ns4xPlugin::GetValue(nsPluginVariable variable, void *value)
|
|||
printf("plugin getvalue %d called\n", variable);
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
NPError (*npGetValue)(void*, nsPluginVariable, void*) =
|
||||
(NPError (*)(void*, nsPluginVariable, void*)) PR_FindSymbol(fLibrary, "NP_GetValue");
|
||||
|
||||
if (npGetValue && NPERR_NO_ERROR == npGetValue(nsnull, variable, value)) {
|
||||
return NS_OK;
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -68,7 +68,7 @@ class ns4xPlugin : public nsIPlugin
|
|||
{
|
||||
public:
|
||||
|
||||
ns4xPlugin(NPPluginFuncs* callbacks, NP_PLUGINSHUTDOWN aShutdown, nsIServiceManager* serviceMgr);
|
||||
ns4xPlugin(NPPluginFuncs* callbacks, PRLibrary* aLibrary, NP_PLUGINSHUTDOWN aShutdown, nsIServiceManager* serviceMgr);
|
||||
virtual ~ns4xPlugin(void);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
@ -114,7 +114,10 @@ public:
|
|||
*/
|
||||
|
||||
static nsresult
|
||||
CreatePlugin(nsPluginTag* pluginTag, nsIServiceManager* serviceMgr);
|
||||
CreatePlugin(nsIServiceManager* aServiceMgr,
|
||||
const char* aFileName,
|
||||
PRLibrary* aLibrary,
|
||||
nsIPlugin** aResult);
|
||||
|
||||
#ifdef XP_MAC
|
||||
void
|
||||
|
@ -238,6 +241,7 @@ protected:
|
|||
* plugin callbacks for each plugin.
|
||||
*/
|
||||
NPPluginFuncs fCallbacks;
|
||||
PRLibrary* fLibrary;
|
||||
|
||||
NP_PLUGINSHUTDOWN fShutdownEntry;
|
||||
|
||||
|
|
|
@ -2462,7 +2462,11 @@ NS_IMETHODIMP nsPluginHostImpl::GetPluginFactory(const char *aMimeType, nsIPlugi
|
|||
}
|
||||
else
|
||||
{
|
||||
rv = ns4xPlugin::CreatePlugin(pluginTag, mServiceMgr);
|
||||
rv = ns4xPlugin::CreatePlugin(mServiceMgr,
|
||||
pluginTag->mFileName,
|
||||
pluginTag->mLibrary,
|
||||
&pluginTag->mEntryPoint);
|
||||
|
||||
plugin = pluginTag->mEntryPoint;
|
||||
pluginTag->mFlags |= NS_PLUGIN_FLAG_OLDSCHOOL;
|
||||
|
||||
|
|
|
@ -28,33 +28,23 @@
|
|||
by Alex Musil
|
||||
*/
|
||||
|
||||
#include "xp_core.h"
|
||||
#include "nsplugin.h"
|
||||
#include "ns4xPlugin.h"
|
||||
#include "ns4xPluginInstance.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIMemory.h"
|
||||
#include "nsIPluginStreamListener.h"
|
||||
#include "nsPluginsDir.h"
|
||||
#include "prlink.h"
|
||||
#include "plstr.h"
|
||||
#include "prmem.h"
|
||||
#include "nsString.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
#include "prmem.h"
|
||||
|
||||
/* Local helper functions */
|
||||
|
||||
static char* GetFileName(const char* pathname)
|
||||
{
|
||||
const char* filename = nsnull;
|
||||
|
||||
// this is most likely a path, so skip to the filename
|
||||
filename = PL_strrchr(pathname, '/');
|
||||
if(filename)
|
||||
++filename;
|
||||
else
|
||||
filename = pathname;
|
||||
|
||||
return PL_strdup(filename);
|
||||
}
|
||||
|
||||
static PRUint32 CalculateVariantCount(char* mimeTypes)
|
||||
static PRUint32 CalculateVariantCount(const char* mimeTypes)
|
||||
{
|
||||
PRUint32 variants = 0;
|
||||
char* ptr = mimeTypes;
|
||||
const char* ptr = mimeTypes;
|
||||
while (*ptr)
|
||||
{
|
||||
if (*ptr == ';')
|
||||
|
@ -162,35 +152,60 @@ nsresult nsPluginFile::LoadPlugin(PRLibrary* &outLibrary)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
typedef char* (*UNIX_Plugin_GetMIMEDescription)();
|
||||
|
||||
|
||||
/**
|
||||
* Obtains all of the information currently available for this plugin.
|
||||
*/
|
||||
nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
{
|
||||
const char *path = this->GetCString();
|
||||
char *mimedescr,*mdesc,*start,*nexttoc,*mtype,*exten,*descr;
|
||||
NS_ERROR("stop");
|
||||
|
||||
nsresult rv;
|
||||
const char* mimedescr;
|
||||
char *mdesc,*start,*nexttoc,*mtype,*exten,*descr;
|
||||
int i,num;
|
||||
|
||||
UNIX_Plugin_GetMIMEDescription procedure = nsnull;
|
||||
mimedescr=(char *)"";
|
||||
// No, this doesn't leak. GetGlobalServiceManager() doesn't addref
|
||||
// it's out pointer. Maybe it should.
|
||||
nsIServiceManager* mgr;
|
||||
nsServiceManager::GetGlobalServiceManager(&mgr);
|
||||
|
||||
if((procedure = (UNIX_Plugin_GetMIMEDescription)PR_FindSymbol(pLibrary,"NP_GetMIMEDescription")) != 0) {
|
||||
mimedescr = procedure();
|
||||
} else {
|
||||
#ifdef NS_DEBUG
|
||||
printf("Cannot get plugin info: no GetMIMEDescription procedure!\n");
|
||||
#endif
|
||||
return NS_ERROR_FAILURE;
|
||||
nsFactoryProc nsGetFactory =
|
||||
(nsFactoryProc) PR_FindSymbol(pLibrary, "NSGetFactory");
|
||||
|
||||
nsCOMPtr<nsIPlugin> plugin;
|
||||
|
||||
if (nsGetFactory) {
|
||||
// It's an almost-new-style plugin. The "truly new" plugins
|
||||
// are just XPCOM components, but there are some Mozilla
|
||||
// Classic holdovers that live in the plugins directory but
|
||||
// implement nsIPlugin and the factory stuff.
|
||||
static NS_DEFINE_CID(kPluginCID, NS_PLUGIN_CID);
|
||||
|
||||
nsCOMPtr<nsIFactory> factory;
|
||||
rv = nsGetFactory(mgr, kPluginCID, nsnull, nsnull, getter_AddRefs(factory));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
plugin = do_QueryInterface(factory);
|
||||
}
|
||||
else {
|
||||
// It's old sk00l
|
||||
rv = ns4xPlugin::CreatePlugin(mgr, this->GetCString(), pLibrary, getter_AddRefs(plugin));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
info.fName = GetFileName(path);
|
||||
if (plugin) {
|
||||
plugin->GetValue(nsPluginVariable_NameString, &info.fName);
|
||||
plugin->GetValue(nsPluginVariable_DescriptionString, &info.fDescription);
|
||||
plugin->GetMIMEDescription(&mimedescr);
|
||||
}
|
||||
else {
|
||||
info.fName = PL_strdup(this->GetCString()); // XXXwaterson LEAK
|
||||
info.fDescription = "";
|
||||
info.fMimeDescription = "";
|
||||
}
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
printf("GetMIMEDescription() %lx returned \"%s\"\n",
|
||||
(unsigned long)procedure, mimedescr);
|
||||
printf("GetMIMEDescription() returned \"%s\"\n", mimedescr);
|
||||
#endif
|
||||
|
||||
// copy string
|
||||
|
|
Загрузка…
Ссылка в новой задаче