bug=54291
a=brendan r=edburns, scc This checkin does three things: 1. Makes it so on Unix the user can set the env var NS600_PLUGIN_PATH to point to a directory that will be used as the location for searching for plugins. 2. Removes nsPluginsDirUNIX.cpp and replaces it with nsPluginsDirUnix.cpp 3. Correctly formats nsPluginsDirUnix per brendan's recommendation. git-svn-id: svn://10.0.0.236/trunk@80956 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
d98d18c7b7
commit
f684ef784c
@ -48,7 +48,7 @@ else
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
|
||||
CPPSRCS += nsPluginsDirOS2.cpp
|
||||
else
|
||||
CPPSRCS += nsPluginsDirUNIX.cpp
|
||||
CPPSRCS += nsPluginsDirUnix.cpp
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
@ -38,62 +38,74 @@
|
||||
#include "nsPluginsDir.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
#include "prmem.h"
|
||||
#include "prenv.h"
|
||||
|
||||
#define PLUGIN_PATH "NS600_PLUGIN_PATH"
|
||||
#define PLUGIN_DIR "/plugins"
|
||||
|
||||
|
||||
/* Local helper functions */
|
||||
|
||||
static PRUint32 CalculateVariantCount(const char* mimeTypes)
|
||||
{
|
||||
PRUint32 variants = 0;
|
||||
const char* ptr = mimeTypes;
|
||||
while (*ptr)
|
||||
{
|
||||
if (*ptr == ';')
|
||||
variants++;
|
||||
PRUint32 variants = 0;
|
||||
const char* ptr = mimeTypes;
|
||||
|
||||
++ptr;
|
||||
}
|
||||
return variants;
|
||||
while (*ptr) {
|
||||
if (*ptr == ';')
|
||||
variants++;
|
||||
++ptr;
|
||||
}
|
||||
|
||||
return variants;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* nsPluginsDir implementation */
|
||||
|
||||
// Get path to plugin directory.
|
||||
// If already defined in environment, use it; otherwise, use native path.
|
||||
nsPluginsDir::nsPluginsDir(PRUint16 location)
|
||||
{
|
||||
// this is somewhat lacking, in that it doesn't fall back to any
|
||||
// other directories. then again, I'm not sure we should be falling
|
||||
// back at all. plugins have been (and probably should continue to be)
|
||||
// loaded from both <libdir>/plugins and ~/.mozilla/plugins. There
|
||||
// doesn't seem to be any way to do this in the current nsPluginsDir
|
||||
// code, which is disheartening.
|
||||
nsSpecialSystemDirectory sysdir(nsSpecialSystemDirectory::
|
||||
OS_CurrentProcessDirectory);
|
||||
const char *pluginsDir;
|
||||
char *tmp_dir;
|
||||
|
||||
// use MOZILLA_FIVE_HOME/plugins
|
||||
if ((tmp_dir = PR_GetEnv(PLUGIN_PATH))) {
|
||||
pluginsDir = (const char *)tmp_dir;
|
||||
} else {
|
||||
sysdir += "plugins";
|
||||
pluginsDir = sysdir.GetCString(); // native path
|
||||
}
|
||||
|
||||
nsSpecialSystemDirectory sysdir(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
|
||||
sysdir += "plugins";
|
||||
const char *pluginsDir = sysdir.GetCString(); // native path
|
||||
if (pluginsDir != NULL)
|
||||
{
|
||||
*(nsFileSpec*)this = pluginsDir;
|
||||
}
|
||||
if (pluginsDir != NULL) {
|
||||
nsFileSpec::operator=(pluginsDir);
|
||||
// use |nsFileSpec|s assignment operator to set the path, would
|
||||
// be better if there was an, e.g., |nsFileSpec::SetPath( const
|
||||
// char* )|.
|
||||
}
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
printf("********** Got plugins path: %s\n", pluginsDir);
|
||||
#endif
|
||||
}
|
||||
|
||||
nsPluginsDir::~nsPluginsDir()
|
||||
{
|
||||
// do nothing
|
||||
// do nothing
|
||||
}
|
||||
|
||||
PRBool nsPluginsDir::IsPluginFile(const nsFileSpec& fileSpec)
|
||||
{
|
||||
const char* pathname = fileSpec.GetCString();
|
||||
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
printf("IsPluginFile(%s)\n", pathname);
|
||||
printf("IsPluginFile(%s)\n", pathname);
|
||||
#endif
|
||||
|
||||
return PR_TRUE;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@ -103,12 +115,12 @@ PRBool nsPluginsDir::IsPluginFile(const nsFileSpec& fileSpec)
|
||||
nsPluginFile::nsPluginFile(const nsFileSpec& spec)
|
||||
: nsFileSpec(spec)
|
||||
{
|
||||
// nada
|
||||
// nada
|
||||
}
|
||||
|
||||
nsPluginFile::~nsPluginFile()
|
||||
{
|
||||
// nada
|
||||
// nada
|
||||
}
|
||||
|
||||
/**
|
||||
@ -180,14 +192,15 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
static NS_DEFINE_CID(kPluginCID, NS_PLUGIN_CID);
|
||||
|
||||
nsCOMPtr<nsIFactory> factory;
|
||||
rv = nsGetFactory(mgr, kPluginCID, nsnull, nsnull, getter_AddRefs(factory));
|
||||
rv = nsGetFactory(mgr, kPluginCID, nsnull, nsnull,
|
||||
getter_AddRefs(factory));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
plugin = do_QueryInterface(factory);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// It's old sk00l
|
||||
rv = ns4xPlugin::CreatePlugin(mgr, this->GetCString(), pLibrary, getter_AddRefs(plugin));
|
||||
rv = ns4xPlugin::CreatePlugin(mgr, this->GetCString(), pLibrary,
|
||||
getter_AddRefs(plugin));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
@ -199,8 +212,7 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
info.fDescription = PL_strdup(description);
|
||||
|
||||
plugin->GetMIMEDescription(&mimedescr);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
info.fName = PL_strdup(this->GetCString());
|
||||
info.fDescription = PL_strdup("");
|
||||
}
|
||||
@ -213,40 +225,41 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
|
||||
mdesc = (char *)PR_Malloc(strlen(mimedescr)+1);
|
||||
strcpy(mdesc,mimedescr);
|
||||
num=CalculateVariantCount(mimedescr)+1;
|
||||
num = CalculateVariantCount(mimedescr)+1;
|
||||
info.fVariantCount = num;
|
||||
|
||||
info.fMimeTypeArray =(char **)PR_Malloc(num * sizeof(char *));
|
||||
info.fMimeDescriptionArray =(char **)PR_Malloc(num * sizeof(char *));
|
||||
info.fExtensionArray =(char **)PR_Malloc(num * sizeof(char *));
|
||||
info.fMimeTypeArray = (char **)PR_Malloc(num * sizeof(char *));
|
||||
info.fMimeDescriptionArray = (char **)PR_Malloc(num * sizeof(char *));
|
||||
info.fExtensionArray = (char **)PR_Malloc(num * sizeof(char *));
|
||||
|
||||
start=mdesc;
|
||||
for(i=0;i<num && *start;i++) {
|
||||
start = mdesc;
|
||||
for(i = 0;i < num && *start;i++) {
|
||||
// search start of next token (separator is ';')
|
||||
|
||||
if(i+1 < num) {
|
||||
if((nexttoc=PL_strchr(start, ';')) != 0)
|
||||
if((nexttoc = PL_strchr(start, ';')) != 0)
|
||||
*nexttoc++=0;
|
||||
else
|
||||
nexttoc=start+strlen(start);
|
||||
} else
|
||||
} else
|
||||
nexttoc=start+strlen(start);
|
||||
|
||||
// split string into: mime type ':' extensions ':' description
|
||||
|
||||
mtype=start;
|
||||
exten=PL_strchr(start, ':');
|
||||
mtype = start;
|
||||
exten = PL_strchr(start, ':');
|
||||
if(exten) {
|
||||
*exten++=0;
|
||||
descr=PL_strchr(exten, ':');
|
||||
*exten++ = 0;
|
||||
descr = PL_strchr(exten, ':');
|
||||
} else
|
||||
descr=NULL;
|
||||
descr = NULL;
|
||||
|
||||
if(descr)
|
||||
*descr++=0;
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
printf("Registering plugin for: \"%s\",\"%s\",\"%s\"\n", mtype,descr ? descr : "null",exten ? exten : "null");
|
||||
printf("Registering plugin for: \"%s\",\"%s\",\"%s\"\n",
|
||||
mtype,descr ? descr : "null",exten ? exten : "null");
|
||||
#endif
|
||||
|
||||
if(!*mtype && !descr && !exten) {
|
||||
@ -254,36 +267,37 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
info.fVariantCount--;
|
||||
} else {
|
||||
info.fMimeTypeArray[i] = mtype ? PL_strdup(mtype) : PL_strdup("");
|
||||
info.fMimeDescriptionArray[i] = descr ? PL_strdup(descr) : PL_strdup("");
|
||||
info.fMimeDescriptionArray[i] = descr ? PL_strdup(descr) :
|
||||
PL_strdup("");
|
||||
info.fExtensionArray[i] = exten ? PL_strdup(exten) : PL_strdup("");
|
||||
}
|
||||
start=nexttoc;
|
||||
start = nexttoc;
|
||||
}
|
||||
|
||||
PR_Free(mdesc);
|
||||
|
||||
return NS_OK;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
|
||||
{
|
||||
if(info.fName != nsnull)
|
||||
PL_strfree(info.fName);
|
||||
if(info.fName != nsnull)
|
||||
PL_strfree(info.fName);
|
||||
|
||||
if(info.fDescription != nsnull)
|
||||
PL_strfree(info.fDescription);
|
||||
if(info.fDescription != nsnull)
|
||||
PL_strfree(info.fDescription);
|
||||
|
||||
for(PRUint32 i = 0; i < info.fVariantCount; i++)
|
||||
{
|
||||
if(info.fMimeTypeArray[i] != nsnull)
|
||||
PL_strfree(info.fMimeTypeArray[i]);
|
||||
for(PRUint32 i = 0; i < info.fVariantCount; i++) {
|
||||
if (info.fMimeTypeArray[i] != nsnull)
|
||||
PL_strfree(info.fMimeTypeArray[i]);
|
||||
|
||||
if(info.fMimeDescriptionArray[i] != nsnull)
|
||||
PL_strfree(info.fMimeDescriptionArray[i]);
|
||||
if (info.fMimeDescriptionArray[i] != nsnull)
|
||||
PL_strfree(info.fMimeDescriptionArray[i]);
|
||||
|
||||
if(info.fExtensionArray[i] != nsnull)
|
||||
PL_strfree(info.fExtensionArray[i]);
|
||||
}
|
||||
return NS_OK;
|
||||
if(info.fExtensionArray[i] != nsnull)
|
||||
PL_strfree(info.fExtensionArray[i]);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -48,7 +48,7 @@ else
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
|
||||
CPPSRCS += nsPluginsDirOS2.cpp
|
||||
else
|
||||
CPPSRCS += nsPluginsDirUNIX.cpp
|
||||
CPPSRCS += nsPluginsDirUnix.cpp
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
@ -38,62 +38,74 @@
|
||||
#include "nsPluginsDir.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
#include "prmem.h"
|
||||
#include "prenv.h"
|
||||
|
||||
#define PLUGIN_PATH "NS600_PLUGIN_PATH"
|
||||
#define PLUGIN_DIR "/plugins"
|
||||
|
||||
|
||||
/* Local helper functions */
|
||||
|
||||
static PRUint32 CalculateVariantCount(const char* mimeTypes)
|
||||
{
|
||||
PRUint32 variants = 0;
|
||||
const char* ptr = mimeTypes;
|
||||
while (*ptr)
|
||||
{
|
||||
if (*ptr == ';')
|
||||
variants++;
|
||||
PRUint32 variants = 0;
|
||||
const char* ptr = mimeTypes;
|
||||
|
||||
++ptr;
|
||||
}
|
||||
return variants;
|
||||
while (*ptr) {
|
||||
if (*ptr == ';')
|
||||
variants++;
|
||||
++ptr;
|
||||
}
|
||||
|
||||
return variants;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* nsPluginsDir implementation */
|
||||
|
||||
// Get path to plugin directory.
|
||||
// If already defined in environment, use it; otherwise, use native path.
|
||||
nsPluginsDir::nsPluginsDir(PRUint16 location)
|
||||
{
|
||||
// this is somewhat lacking, in that it doesn't fall back to any
|
||||
// other directories. then again, I'm not sure we should be falling
|
||||
// back at all. plugins have been (and probably should continue to be)
|
||||
// loaded from both <libdir>/plugins and ~/.mozilla/plugins. There
|
||||
// doesn't seem to be any way to do this in the current nsPluginsDir
|
||||
// code, which is disheartening.
|
||||
nsSpecialSystemDirectory sysdir(nsSpecialSystemDirectory::
|
||||
OS_CurrentProcessDirectory);
|
||||
const char *pluginsDir;
|
||||
char *tmp_dir;
|
||||
|
||||
// use MOZILLA_FIVE_HOME/plugins
|
||||
if ((tmp_dir = PR_GetEnv(PLUGIN_PATH))) {
|
||||
pluginsDir = (const char *)tmp_dir;
|
||||
} else {
|
||||
sysdir += "plugins";
|
||||
pluginsDir = sysdir.GetCString(); // native path
|
||||
}
|
||||
|
||||
nsSpecialSystemDirectory sysdir(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
|
||||
sysdir += "plugins";
|
||||
const char *pluginsDir = sysdir.GetCString(); // native path
|
||||
if (pluginsDir != NULL)
|
||||
{
|
||||
*(nsFileSpec*)this = pluginsDir;
|
||||
}
|
||||
if (pluginsDir != NULL) {
|
||||
nsFileSpec::operator=(pluginsDir);
|
||||
// use |nsFileSpec|s assignment operator to set the path, would
|
||||
// be better if there was an, e.g., |nsFileSpec::SetPath( const
|
||||
// char* )|.
|
||||
}
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
printf("********** Got plugins path: %s\n", pluginsDir);
|
||||
#endif
|
||||
}
|
||||
|
||||
nsPluginsDir::~nsPluginsDir()
|
||||
{
|
||||
// do nothing
|
||||
// do nothing
|
||||
}
|
||||
|
||||
PRBool nsPluginsDir::IsPluginFile(const nsFileSpec& fileSpec)
|
||||
{
|
||||
const char* pathname = fileSpec.GetCString();
|
||||
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
printf("IsPluginFile(%s)\n", pathname);
|
||||
printf("IsPluginFile(%s)\n", pathname);
|
||||
#endif
|
||||
|
||||
return PR_TRUE;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@ -103,12 +115,12 @@ PRBool nsPluginsDir::IsPluginFile(const nsFileSpec& fileSpec)
|
||||
nsPluginFile::nsPluginFile(const nsFileSpec& spec)
|
||||
: nsFileSpec(spec)
|
||||
{
|
||||
// nada
|
||||
// nada
|
||||
}
|
||||
|
||||
nsPluginFile::~nsPluginFile()
|
||||
{
|
||||
// nada
|
||||
// nada
|
||||
}
|
||||
|
||||
/**
|
||||
@ -180,14 +192,15 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
static NS_DEFINE_CID(kPluginCID, NS_PLUGIN_CID);
|
||||
|
||||
nsCOMPtr<nsIFactory> factory;
|
||||
rv = nsGetFactory(mgr, kPluginCID, nsnull, nsnull, getter_AddRefs(factory));
|
||||
rv = nsGetFactory(mgr, kPluginCID, nsnull, nsnull,
|
||||
getter_AddRefs(factory));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
plugin = do_QueryInterface(factory);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// It's old sk00l
|
||||
rv = ns4xPlugin::CreatePlugin(mgr, this->GetCString(), pLibrary, getter_AddRefs(plugin));
|
||||
rv = ns4xPlugin::CreatePlugin(mgr, this->GetCString(), pLibrary,
|
||||
getter_AddRefs(plugin));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
@ -199,8 +212,7 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
info.fDescription = PL_strdup(description);
|
||||
|
||||
plugin->GetMIMEDescription(&mimedescr);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
info.fName = PL_strdup(this->GetCString());
|
||||
info.fDescription = PL_strdup("");
|
||||
}
|
||||
@ -213,40 +225,41 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
|
||||
mdesc = (char *)PR_Malloc(strlen(mimedescr)+1);
|
||||
strcpy(mdesc,mimedescr);
|
||||
num=CalculateVariantCount(mimedescr)+1;
|
||||
num = CalculateVariantCount(mimedescr)+1;
|
||||
info.fVariantCount = num;
|
||||
|
||||
info.fMimeTypeArray =(char **)PR_Malloc(num * sizeof(char *));
|
||||
info.fMimeDescriptionArray =(char **)PR_Malloc(num * sizeof(char *));
|
||||
info.fExtensionArray =(char **)PR_Malloc(num * sizeof(char *));
|
||||
info.fMimeTypeArray = (char **)PR_Malloc(num * sizeof(char *));
|
||||
info.fMimeDescriptionArray = (char **)PR_Malloc(num * sizeof(char *));
|
||||
info.fExtensionArray = (char **)PR_Malloc(num * sizeof(char *));
|
||||
|
||||
start=mdesc;
|
||||
for(i=0;i<num && *start;i++) {
|
||||
start = mdesc;
|
||||
for(i = 0;i < num && *start;i++) {
|
||||
// search start of next token (separator is ';')
|
||||
|
||||
if(i+1 < num) {
|
||||
if((nexttoc=PL_strchr(start, ';')) != 0)
|
||||
if((nexttoc = PL_strchr(start, ';')) != 0)
|
||||
*nexttoc++=0;
|
||||
else
|
||||
nexttoc=start+strlen(start);
|
||||
} else
|
||||
} else
|
||||
nexttoc=start+strlen(start);
|
||||
|
||||
// split string into: mime type ':' extensions ':' description
|
||||
|
||||
mtype=start;
|
||||
exten=PL_strchr(start, ':');
|
||||
mtype = start;
|
||||
exten = PL_strchr(start, ':');
|
||||
if(exten) {
|
||||
*exten++=0;
|
||||
descr=PL_strchr(exten, ':');
|
||||
*exten++ = 0;
|
||||
descr = PL_strchr(exten, ':');
|
||||
} else
|
||||
descr=NULL;
|
||||
descr = NULL;
|
||||
|
||||
if(descr)
|
||||
*descr++=0;
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
printf("Registering plugin for: \"%s\",\"%s\",\"%s\"\n", mtype,descr ? descr : "null",exten ? exten : "null");
|
||||
printf("Registering plugin for: \"%s\",\"%s\",\"%s\"\n",
|
||||
mtype,descr ? descr : "null",exten ? exten : "null");
|
||||
#endif
|
||||
|
||||
if(!*mtype && !descr && !exten) {
|
||||
@ -254,36 +267,37 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
|
||||
info.fVariantCount--;
|
||||
} else {
|
||||
info.fMimeTypeArray[i] = mtype ? PL_strdup(mtype) : PL_strdup("");
|
||||
info.fMimeDescriptionArray[i] = descr ? PL_strdup(descr) : PL_strdup("");
|
||||
info.fMimeDescriptionArray[i] = descr ? PL_strdup(descr) :
|
||||
PL_strdup("");
|
||||
info.fExtensionArray[i] = exten ? PL_strdup(exten) : PL_strdup("");
|
||||
}
|
||||
start=nexttoc;
|
||||
start = nexttoc;
|
||||
}
|
||||
|
||||
PR_Free(mdesc);
|
||||
|
||||
return NS_OK;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
|
||||
{
|
||||
if(info.fName != nsnull)
|
||||
PL_strfree(info.fName);
|
||||
if(info.fName != nsnull)
|
||||
PL_strfree(info.fName);
|
||||
|
||||
if(info.fDescription != nsnull)
|
||||
PL_strfree(info.fDescription);
|
||||
if(info.fDescription != nsnull)
|
||||
PL_strfree(info.fDescription);
|
||||
|
||||
for(PRUint32 i = 0; i < info.fVariantCount; i++)
|
||||
{
|
||||
if(info.fMimeTypeArray[i] != nsnull)
|
||||
PL_strfree(info.fMimeTypeArray[i]);
|
||||
for(PRUint32 i = 0; i < info.fVariantCount; i++) {
|
||||
if (info.fMimeTypeArray[i] != nsnull)
|
||||
PL_strfree(info.fMimeTypeArray[i]);
|
||||
|
||||
if(info.fMimeDescriptionArray[i] != nsnull)
|
||||
PL_strfree(info.fMimeDescriptionArray[i]);
|
||||
if (info.fMimeDescriptionArray[i] != nsnull)
|
||||
PL_strfree(info.fMimeDescriptionArray[i]);
|
||||
|
||||
if(info.fExtensionArray[i] != nsnull)
|
||||
PL_strfree(info.fExtensionArray[i]);
|
||||
}
|
||||
return NS_OK;
|
||||
if(info.fExtensionArray[i] != nsnull)
|
||||
PL_strfree(info.fExtensionArray[i]);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user