Fix for not opening bundles plugin resources on Mac fixing crashes (and tab clean up) bug 91988 r=bnesse sr=sfraser

This commit is contained in:
peterlubczynski%netscape.com 2001-08-22 03:55:53 +00:00
Родитель 5e263b2559
Коммит fde7ebe790
3 изменённых файлов: 116 добавлений и 102 удалений

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

@ -339,10 +339,10 @@ ns4xPlugin::CreatePlugin(nsIServiceManager* aServiceMgr,
FSSpec spec = file;
if (!nsCRT::memcmp(spec.name + 1, aFileName, spec.name[0]))
{
Boolean targetIsFolder, wasAliased;
OSErr err = ::ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased);
pluginRefNum = ::FSpOpenResFile(&spec, fsRdPerm);
found = true;
nsPluginFile pluginFile(file);
pluginRefNum = pluginFile.OpenPluginResource();
if (pluginRefNum != -1)
found = true;
}
}
}
@ -364,10 +364,10 @@ ns4xPlugin::CreatePlugin(nsIServiceManager* aServiceMgr,
FSSpec spec = file;
if (!nsCRT::memcmp(spec.name + 1, aFileName, spec.name[0]))
{
Boolean targetIsFolder, wasAliased;
OSErr err = ::ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased);
pluginRefNum = ::FSpOpenResFile(&spec, fsRdPerm);
found = PR_TRUE;
nsPluginFile pluginFile(file);
pluginRefNum = pluginFile.OpenPluginResource();
if (pluginRefNum != -1)
found = true;
}
}
}
@ -544,6 +544,7 @@ ns4xPlugin::Shutdown(void)
fShutdownEntry = nsnull;
}
PLUGIN_LOG(PLUGIN_LOG_NORMAL,("4xPlugin Shutdown done, this=%p",this));
return NS_OK;
}

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

@ -102,6 +102,9 @@ public:
* Should be called after GetPluginInfo to free all allocated stuff
*/
nsresult FreePluginInfo(nsPluginInfo &PluginInfo);
// Open the resource fork for the plugin
short OpenPluginResource(void);
};
#endif /* nsPluginsDir_h___ */

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

@ -21,11 +21,11 @@
*/
/*
nsPluginsDirMac.cpp
Mac OS implementation of the nsPluginsDir/nsPluginsFile classes.
by Patrick C. Beard.
nsPluginsDirMac.cpp
Mac OS implementation of the nsPluginsDir/nsPluginsFile classes.
by Patrick C. Beard.
*/
#include "nsPluginsDir.h"
@ -67,12 +67,12 @@ static CFBundleRef getPluginBundle(const FSSpec& spec)
if (err == noErr) {
CFStringRef pathRef = CFStringCreateWithCString(NULL, path, kCFStringEncodingUTF8);
if (pathRef) {
CFURLRef bundleURL = CFURLCreateWithFileSystemPath(NULL, pathRef, kCFURLPOSIXPathStyle, true);
if (bundleURL != NULL) {
CFURLRef bundleURL = CFURLCreateWithFileSystemPath(NULL, pathRef, kCFURLPOSIXPathStyle, true);
if (bundleURL != NULL) {
bundle = CFBundleCreate(NULL, bundleURL);
CFRelease(bundleURL);
}
CFRelease(pathRef);
}
CFRelease(pathRef);
}
}
}
@ -92,23 +92,23 @@ CFBundleGetPackageInfo(CFBundleRef bundle, UInt32 * packageType, UInt32 * packag
static nsresult getApplicationSpec(FSSpec& outAppSpec)
{
// Use the process manager to get the application's FSSpec,
// then construct an nsFileSpec that encapsulates it.
ProcessInfoRec info;
info.processInfoLength = sizeof(info);
info.processName = NULL;
info.processAppSpec = &outAppSpec;
ProcessSerialNumber psn = { 0, kCurrentProcess };
OSErr result = GetProcessInformation(&psn, &info);
return (result == noErr ? NS_OK : NS_ERROR_FAILURE);
// Use the process manager to get the application's FSSpec,
// then construct an nsFileSpec that encapsulates it.
ProcessInfoRec info;
info.processInfoLength = sizeof(info);
info.processName = NULL;
info.processAppSpec = &outAppSpec;
ProcessSerialNumber psn = { 0, kCurrentProcess };
OSErr result = GetProcessInformation(&psn, &info);
return (result == noErr ? NS_OK : NS_ERROR_FAILURE);
}
nsPluginsDir::nsPluginsDir(PRUint16 location)
{
PRBool wasAliased;
PRBool wasAliased;
switch (location)
{
{
case PLUGINS_DIR_LOCATION_MAC_SYSTEM_PLUGINS_FOLDER:
// The system's shared "Plugin-ins" folder
#if TARGET_CARBON // on OS X, we must try kLocalDomain first
@ -127,26 +127,26 @@ nsPluginsDir::nsPluginsDir(PRUint16 location)
*(nsFileSpec*)this = plugDir + "Plug-ins";
break;
}
if (IsSymlink())
ResolveSymlink(wasAliased);
if (IsSymlink())
ResolveSymlink(wasAliased);
}
nsPluginsDir::~nsPluginsDir() {}
PRBool nsPluginsDir::IsPluginFile(const nsFileSpec& fileSpec)
{
// look at file's creator/type and make sure it is a code fragment, etc.
FInfo info;
const FSSpec& spec = fileSpec;
OSErr result = FSpGetFInfo(&spec, &info);
if (result == noErr && ((info.fdType == 'shlb' && info.fdCreator == 'MOSS') ||
info.fdType == 'NSPL'))
return PR_TRUE;
// look at file's creator/type and make sure it is a code fragment, etc.
FInfo info;
const FSSpec& spec = fileSpec;
OSErr result = FSpGetFInfo(&spec, &info);
if (result == noErr && ((info.fdType == 'shlb' && info.fdCreator == 'MOSS') ||
info.fdType == 'NSPL'))
return PR_TRUE;
#if TARGET_CARBON
// Some additional plugin types for Carbon/Mac OS X
if (result == noErr && (info.fdType == 'BRPL' || info.fdType == 'IEPL'))
return PR_TRUE;
// Some additional plugin types for Carbon/Mac OS X
if (result == noErr && (info.fdType == 'BRPL' || info.fdType == 'IEPL'))
return PR_TRUE;
// for Mac OS X bundles.
CFBundleRef bundle = getPluginBundle(spec);
@ -163,11 +163,11 @@ PRBool nsPluginsDir::IsPluginFile(const nsFileSpec& fileSpec)
}
#endif
return PR_FALSE;
return PR_FALSE;
}
nsPluginFile::nsPluginFile(const nsFileSpec& spec)
: nsFileSpec(spec)
: nsFileSpec(spec)
{
}
@ -179,27 +179,49 @@ nsPluginFile::~nsPluginFile() {}
*/
nsresult nsPluginFile::LoadPlugin(PRLibrary* &outLibrary)
{
const char* path = this->GetCString();
outLibrary = PR_LoadLibrary(path);
return NS_OK;
const char* path = this->GetCString();
outLibrary = PR_LoadLibrary(path);
return NS_OK;
}
static char* p2cstrdup(StringPtr pstr)
{
int len = pstr[0];
char* cstr = new char[len + 1];
if (cstr != NULL) {
::BlockMoveData(pstr + 1, cstr, len);
cstr[len] = '\0';
}
return cstr;
int len = pstr[0];
char* cstr = new char[len + 1];
if (cstr != NULL) {
::BlockMoveData(pstr + 1, cstr, len);
cstr[len] = '\0';
}
return cstr;
}
static char* GetPluginString(short id, short index)
{
Str255 str;
::GetIndString(str, id, index);
return p2cstrdup(str);
Str255 str;
::GetIndString(str, id, index);
return p2cstrdup(str);
}
// Opens the resource fork for the plugin
// Also checks if the plugin is a CFBundle and opens gets the correct resource
short nsPluginFile::OpenPluginResource()
{
FSSpec spec = *this;
Boolean targetIsFolder, wasAliased;
OSErr err = ::ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased);
short refNum = ::FSpOpenResFile(&spec, fsRdPerm);
#if TARGET_CARBON
if (refNum == -1) {
CFBundleRef bundle = getPluginBundle(spec);
if (bundle) {
refNum = CFBundleOpenBundleResourceMap(bundle);
CFRelease(bundle);
}
}
#endif
return refNum;
}
/**
@ -211,55 +233,43 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
nsCRT::memset(&info.fName, 0, sizeof(info) - sizeof(PRUint32));
// need to open the plugin's resource file and read some resources.
FSSpec spec = *this;
Boolean targetIsFolder, wasAliased;
OSErr err = ::ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased);
short refNum = ::FSpOpenResFile(&spec, fsRdPerm);
short refNum = OpenPluginResource();
#if TARGET_CARBON
if (refNum == -1) {
CFBundleRef bundle = getPluginBundle(spec);
if (bundle) {
refNum = CFBundleOpenBundleResourceMap(bundle);
CFRelease(bundle);
}
if (refNum != -1) {
if (info.fPluginInfoSize >= sizeof(nsPluginInfo)) {
// 'STR#', 126, 2 => plugin name.
info.fName = GetPluginString(126, 2);
// 'STR#', 126, 1 => plugin description.
info.fDescription = GetPluginString(126, 1);
// Determine how many 'STR#' resource for all MIME types/extensions.
Handle typeList = ::Get1Resource('STR#', 128);
if (typeList != NULL) {
short stringCount = **(short**)typeList;
info.fVariantCount = stringCount / 2;
::ReleaseResource(typeList);
}
FSSpec spec = *this;
int variantCount = info.fVariantCount;
info.fMimeTypeArray = new char*[variantCount];
info.fMimeDescriptionArray = new char*[variantCount];
info.fExtensionArray = new char*[variantCount];
info.fFileName = p2cstrdup(spec.name);
info.fFullPath = PL_strdup(this->GetCString());
short mimeIndex = 1, descriptionIndex = 1;
for (int i = 0; i < variantCount; i++) {
info.fMimeTypeArray[i] = GetPluginString(128, mimeIndex++);
info.fExtensionArray[i] = GetPluginString(128, mimeIndex++);
info.fMimeDescriptionArray[i] = GetPluginString(127, descriptionIndex++);
}
}
#endif
if (refNum != -1) {
if (info.fPluginInfoSize >= sizeof(nsPluginInfo)) {
// 'STR#', 126, 2 => plugin name.
info.fName = GetPluginString(126, 2);
// 'STR#', 126, 1 => plugin description.
info.fDescription = GetPluginString(126, 1);
// Determine how many 'STR#' resource for all MIME types/extensions.
Handle typeList = ::Get1Resource('STR#', 128);
if (typeList != NULL) {
short stringCount = **(short**)typeList;
info.fVariantCount = stringCount / 2;
::ReleaseResource(typeList);
}
int variantCount = info.fVariantCount;
info.fMimeTypeArray = new char*[variantCount];
info.fMimeDescriptionArray = new char*[variantCount];
info.fExtensionArray = new char*[variantCount];
info.fFileName = p2cstrdup(spec.name);
info.fFullPath = PL_strdup(this->GetCString());
short mimeIndex = 1, descriptionIndex = 1;
for (int i = 0; i < variantCount; i++) {
info.fMimeTypeArray[i] = GetPluginString(128, mimeIndex++);
info.fExtensionArray[i] = GetPluginString(128, mimeIndex++);
info.fMimeDescriptionArray[i] = GetPluginString(127, descriptionIndex++);
}
}
::CloseResFile(refNum);
}
return NS_OK;
::CloseResFile(refNum);
}
return NS_OK;
}
nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)