diff --git a/mozilla/modules/plugin/base/src/ns4xPlugin.cpp b/mozilla/modules/plugin/base/src/ns4xPlugin.cpp index acfd477c8f1..e345424c64c 100644 --- a/mozilla/modules/plugin/base/src/ns4xPlugin.cpp +++ b/mozilla/modules/plugin/base/src/ns4xPlugin.cpp @@ -428,6 +428,45 @@ ns4xPlugin::CreatePlugin(nsIServiceManager* aServiceMgr, NS_ADDREF(*aResult); #endif +#ifdef XP_BEOS +// I just copied UNIX version. +// Makoto Hamanaka + + ns4xPlugin *plptr; + + NPPluginFuncs callbacks; + memset((void*) &callbacks, 0, sizeof(callbacks)); + callbacks.size = sizeof(callbacks); + + NP_PLUGINSHUTDOWN pfnShutdown = + (NP_PLUGINSHUTDOWN)PR_FindSymbol(aLibrary, "NP_Shutdown"); + + // create the new plugin handler + *aResult = plptr = new ns4xPlugin(&callbacks, aLibrary, pfnShutdown, aServiceMgr); + + if (*aResult == NULL) + return NS_ERROR_OUT_OF_MEMORY; + + 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 + plptr->Initialize(); + + NP_PLUGINUNIXINIT pfnInitialize = + (NP_PLUGINUNIXINIT)PR_FindSymbol(aLibrary, "NP_Initialize"); + + if (pfnInitialize == NULL) + return NS_ERROR_FAILURE; + + if (pfnInitialize(&(ns4xPlugin::CALLBACKS),&callbacks) != NS_OK) + return NS_ERROR_FAILURE; + + // now copy function table back to ns4xPlugin instance + memcpy((void*) &(plptr->fCallbacks), (void*)&callbacks, sizeof(callbacks)); +#endif + return NS_OK; } diff --git a/mozilla/modules/plugin/base/src/nsPluginsDirBeOS.cpp b/mozilla/modules/plugin/base/src/nsPluginsDirBeOS.cpp index 3b485653e8e..3a0469a628c 100644 --- a/mozilla/modules/plugin/base/src/nsPluginsDirBeOS.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginsDirBeOS.cpp @@ -18,6 +18,8 @@ * Rights Reserved. * * Contributor(s): + * Alex Musil + * Makoto Hamanaka */ /* @@ -35,6 +37,13 @@ #include "nsSpecialSystemDirectory.h" +#include +#include +#include +#include + +//#define NS_PLUGIN_BEOS_DEBUG + /* Local helper functions */ static char* GetFileName(const char* pathname) @@ -51,18 +60,40 @@ static char* GetFileName(const char* pathname) return PL_strdup(filename); } -static PRUint32 CalculateVariantCount(char* mimeTypes) +static nsresult GetMimeExtensions(const char *mimeType, char *extensions, int extLen) { - PRUint32 variants = 0; - char* ptr = mimeTypes; - while (*ptr) - { - if (*ptr == ';') - variants++; - - ++ptr; + // check variables + if (!mimeType || !extensions || extLen < 1) return NS_ERROR_FAILURE; + extensions[0] = '\0'; + + // make mime object + BMimeType mime(mimeType) ; + if (mime.InitCheck() != B_OK) + return NS_ERROR_FAILURE; + + // get extensions : comma separated (if multiple extensions in a mime-type) + // ex) "jpg,jpeg" + BString extStr(""); + BMessage extMsg; + mime.GetFileExtensions(&extMsg); + uint32 type; + int32 types_num; + if (extMsg.GetInfo("extensions", &type, &types_num) != B_OK + || type != B_STRING_TYPE || types_num == 0) + return NS_ERROR_FAILURE; + + for (int i = 0 ; i < types_num ; i ++) { + const char *ext; + if (extMsg.FindString("extensions", i, &ext) != B_OK) { + break; } - return variants; + if (i > 0) + extStr.Append(","); + extStr.Append(ext); + } + PL_strncpyz(extensions, extStr.String(), extLen) ; + + return NS_OK; } /////////////////////////////////////////////////////////////////////////// @@ -144,82 +175,116 @@ typedef char* (*BeOS_Plugin_GetMIMEDescription)(); nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info) { const char *path = this->GetCString(); - char *mimedescr,*mdesc,*start,*nexttoc,*mtype,*exten,*descr; - int i,num; + int i; - BeOS_Plugin_GetMIMEDescription procedure = nsnull; - mimedescr=(char *)""; - - if((procedure = (BeOS_Plugin_GetMIMEDescription)PR_FindSymbol(pLibrary,"NP_GetMIMEDescription")) != 0) { - mimedescr = procedure(); - } else { -#ifdef NS_DEBUG - printf("Cannot get plugin info: no GetMIMEDescription procedure!\n"); +#ifdef NS_PLUGIN_BEOS_DEBUG + printf("nsPluginFile::GetPluginInfo() an attempt to load MIME String\n"); + printf("path = <%s>\n", path); #endif + + // get supported mime types + BFile file(path, B_READ_ONLY); + if (file.InitCheck() != B_OK) return NS_ERROR_FAILURE; - } - info.fName = GetFileName(path); + BAppFileInfo appinfo(&file); + if (appinfo.InitCheck() != B_OK) + return NS_ERROR_FAILURE; -#ifdef NS_DEBUG - printf("GetMIMEDescription() %lx returned \"%s\"\n", - (unsigned long)procedure, mimedescr); -#endif + BMessage msg; + if (appinfo.GetSupportedTypes(&msg) != B_OK) + return NS_ERROR_FAILURE; - // copy string - - mdesc = (char *)PR_Malloc(strlen(mimedescr)+1); - strcpy(mdesc,mimedescr); - num=CalculateVariantCount(mimedescr)+1; - info.fVariantCount = num; + uint32 type; + int32 types_num; + if (msg.GetInfo("types", &type, &types_num) != B_OK + || type != B_STRING_TYPE) + return NS_ERROR_FAILURE; - info.fMimeTypeArray =(char **)PR_Malloc(num * sizeof(char *)); - info.fMimeDescriptionArray =(char **)PR_Malloc(num * sizeof(char *)); - info.fExtensionArray =(char **)PR_Malloc(num * sizeof(char *)); + // set mime types to plugin info + info.fMimeTypeArray =(char **)PR_Malloc(types_num * sizeof(char *)); + info.fMimeDescriptionArray =(char **)PR_Malloc(types_num * sizeof(char *)); + info.fExtensionArray =(char **)PR_Malloc(types_num * sizeof(char *)); - start=mdesc; - for(i=0;i 0) { + // XXX convert UTF-8 2byte chars to 1 byte chars, to avoid string corruption + info.fName = PL_strdup(NS_ConvertUTF8toUCS2(vinfo.short_info).ToNewCString()); + info.fDescription = PL_strdup(NS_ConvertUTF8toUCS2(vinfo.long_info).ToNewCString()); + } else { + // use filename as its name + info.fName = GetFileName(path); + info.fDescription = PL_strdup(""); + } + + info.fVariantCount = types_num; + info.fFileName = PL_strdup(path); + + +#ifdef NS_PLUGIN_BEOS_DEBUG + printf("info.fFileName = %s\n", info.fFileName); + printf("info.fName = %s\n", info.fName); + printf("info.fDescription = %s\n", info.fDescription); +#endif + + return NS_OK; } nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info) { - return NS_OK; + if (info.fName) + PL_strfree(info.fName); + + if (info.fDescription) + PL_strfree(info.fDescription); + + for (PRUint32 i = 0; i < info.fVariantCount; i++) { + if (info.fMimeTypeArray[i]) + PL_strfree(info.fMimeTypeArray[i]); + + if (info.fMimeDescriptionArray[i]) + PL_strfree(info.fMimeDescriptionArray[i]); + + if (info.fExtensionArray[i]) + PL_strfree(info.fExtensionArray[i]); + } + + PR_FREEIF(info.fMimeTypeArray); + PR_FREEIF(info.fMimeDescriptionArray); + PR_FREEIF(info.fExtensionArray); + + if (info.fFileName) + PL_strfree(info.fFileName); + + return NS_OK; } diff --git a/mozilla/modules/plugin/nglsrc/ns4xPlugin.cpp b/mozilla/modules/plugin/nglsrc/ns4xPlugin.cpp index acfd477c8f1..e345424c64c 100644 --- a/mozilla/modules/plugin/nglsrc/ns4xPlugin.cpp +++ b/mozilla/modules/plugin/nglsrc/ns4xPlugin.cpp @@ -428,6 +428,45 @@ ns4xPlugin::CreatePlugin(nsIServiceManager* aServiceMgr, NS_ADDREF(*aResult); #endif +#ifdef XP_BEOS +// I just copied UNIX version. +// Makoto Hamanaka + + ns4xPlugin *plptr; + + NPPluginFuncs callbacks; + memset((void*) &callbacks, 0, sizeof(callbacks)); + callbacks.size = sizeof(callbacks); + + NP_PLUGINSHUTDOWN pfnShutdown = + (NP_PLUGINSHUTDOWN)PR_FindSymbol(aLibrary, "NP_Shutdown"); + + // create the new plugin handler + *aResult = plptr = new ns4xPlugin(&callbacks, aLibrary, pfnShutdown, aServiceMgr); + + if (*aResult == NULL) + return NS_ERROR_OUT_OF_MEMORY; + + 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 + plptr->Initialize(); + + NP_PLUGINUNIXINIT pfnInitialize = + (NP_PLUGINUNIXINIT)PR_FindSymbol(aLibrary, "NP_Initialize"); + + if (pfnInitialize == NULL) + return NS_ERROR_FAILURE; + + if (pfnInitialize(&(ns4xPlugin::CALLBACKS),&callbacks) != NS_OK) + return NS_ERROR_FAILURE; + + // now copy function table back to ns4xPlugin instance + memcpy((void*) &(plptr->fCallbacks), (void*)&callbacks, sizeof(callbacks)); +#endif + return NS_OK; } diff --git a/mozilla/modules/plugin/nglsrc/nsPluginsDirBeOS.cpp b/mozilla/modules/plugin/nglsrc/nsPluginsDirBeOS.cpp index 3b485653e8e..3a0469a628c 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginsDirBeOS.cpp +++ b/mozilla/modules/plugin/nglsrc/nsPluginsDirBeOS.cpp @@ -18,6 +18,8 @@ * Rights Reserved. * * Contributor(s): + * Alex Musil + * Makoto Hamanaka */ /* @@ -35,6 +37,13 @@ #include "nsSpecialSystemDirectory.h" +#include +#include +#include +#include + +//#define NS_PLUGIN_BEOS_DEBUG + /* Local helper functions */ static char* GetFileName(const char* pathname) @@ -51,18 +60,40 @@ static char* GetFileName(const char* pathname) return PL_strdup(filename); } -static PRUint32 CalculateVariantCount(char* mimeTypes) +static nsresult GetMimeExtensions(const char *mimeType, char *extensions, int extLen) { - PRUint32 variants = 0; - char* ptr = mimeTypes; - while (*ptr) - { - if (*ptr == ';') - variants++; - - ++ptr; + // check variables + if (!mimeType || !extensions || extLen < 1) return NS_ERROR_FAILURE; + extensions[0] = '\0'; + + // make mime object + BMimeType mime(mimeType) ; + if (mime.InitCheck() != B_OK) + return NS_ERROR_FAILURE; + + // get extensions : comma separated (if multiple extensions in a mime-type) + // ex) "jpg,jpeg" + BString extStr(""); + BMessage extMsg; + mime.GetFileExtensions(&extMsg); + uint32 type; + int32 types_num; + if (extMsg.GetInfo("extensions", &type, &types_num) != B_OK + || type != B_STRING_TYPE || types_num == 0) + return NS_ERROR_FAILURE; + + for (int i = 0 ; i < types_num ; i ++) { + const char *ext; + if (extMsg.FindString("extensions", i, &ext) != B_OK) { + break; } - return variants; + if (i > 0) + extStr.Append(","); + extStr.Append(ext); + } + PL_strncpyz(extensions, extStr.String(), extLen) ; + + return NS_OK; } /////////////////////////////////////////////////////////////////////////// @@ -144,82 +175,116 @@ typedef char* (*BeOS_Plugin_GetMIMEDescription)(); nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info) { const char *path = this->GetCString(); - char *mimedescr,*mdesc,*start,*nexttoc,*mtype,*exten,*descr; - int i,num; + int i; - BeOS_Plugin_GetMIMEDescription procedure = nsnull; - mimedescr=(char *)""; - - if((procedure = (BeOS_Plugin_GetMIMEDescription)PR_FindSymbol(pLibrary,"NP_GetMIMEDescription")) != 0) { - mimedescr = procedure(); - } else { -#ifdef NS_DEBUG - printf("Cannot get plugin info: no GetMIMEDescription procedure!\n"); +#ifdef NS_PLUGIN_BEOS_DEBUG + printf("nsPluginFile::GetPluginInfo() an attempt to load MIME String\n"); + printf("path = <%s>\n", path); #endif + + // get supported mime types + BFile file(path, B_READ_ONLY); + if (file.InitCheck() != B_OK) return NS_ERROR_FAILURE; - } - info.fName = GetFileName(path); + BAppFileInfo appinfo(&file); + if (appinfo.InitCheck() != B_OK) + return NS_ERROR_FAILURE; -#ifdef NS_DEBUG - printf("GetMIMEDescription() %lx returned \"%s\"\n", - (unsigned long)procedure, mimedescr); -#endif + BMessage msg; + if (appinfo.GetSupportedTypes(&msg) != B_OK) + return NS_ERROR_FAILURE; - // copy string - - mdesc = (char *)PR_Malloc(strlen(mimedescr)+1); - strcpy(mdesc,mimedescr); - num=CalculateVariantCount(mimedescr)+1; - info.fVariantCount = num; + uint32 type; + int32 types_num; + if (msg.GetInfo("types", &type, &types_num) != B_OK + || type != B_STRING_TYPE) + return NS_ERROR_FAILURE; - info.fMimeTypeArray =(char **)PR_Malloc(num * sizeof(char *)); - info.fMimeDescriptionArray =(char **)PR_Malloc(num * sizeof(char *)); - info.fExtensionArray =(char **)PR_Malloc(num * sizeof(char *)); + // set mime types to plugin info + info.fMimeTypeArray =(char **)PR_Malloc(types_num * sizeof(char *)); + info.fMimeDescriptionArray =(char **)PR_Malloc(types_num * sizeof(char *)); + info.fExtensionArray =(char **)PR_Malloc(types_num * sizeof(char *)); - start=mdesc; - for(i=0;i 0) { + // XXX convert UTF-8 2byte chars to 1 byte chars, to avoid string corruption + info.fName = PL_strdup(NS_ConvertUTF8toUCS2(vinfo.short_info).ToNewCString()); + info.fDescription = PL_strdup(NS_ConvertUTF8toUCS2(vinfo.long_info).ToNewCString()); + } else { + // use filename as its name + info.fName = GetFileName(path); + info.fDescription = PL_strdup(""); + } + + info.fVariantCount = types_num; + info.fFileName = PL_strdup(path); + + +#ifdef NS_PLUGIN_BEOS_DEBUG + printf("info.fFileName = %s\n", info.fFileName); + printf("info.fName = %s\n", info.fName); + printf("info.fDescription = %s\n", info.fDescription); +#endif + + return NS_OK; } nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info) { - return NS_OK; + if (info.fName) + PL_strfree(info.fName); + + if (info.fDescription) + PL_strfree(info.fDescription); + + for (PRUint32 i = 0; i < info.fVariantCount; i++) { + if (info.fMimeTypeArray[i]) + PL_strfree(info.fMimeTypeArray[i]); + + if (info.fMimeDescriptionArray[i]) + PL_strfree(info.fMimeDescriptionArray[i]); + + if (info.fExtensionArray[i]) + PL_strfree(info.fExtensionArray[i]); + } + + PR_FREEIF(info.fMimeTypeArray); + PR_FREEIF(info.fMimeDescriptionArray); + PR_FREEIF(info.fExtensionArray); + + if (info.fFileName) + PL_strfree(info.fFileName); + + return NS_OK; }