From 91e241ffe5168df73ad890e1470d590ba989b167 Mon Sep 17 00:00:00 2001 From: Josh Aas Date: Thu, 11 Dec 2008 16:52:42 -0500 Subject: [PATCH] remove support for resource (.rsrc) files in Mac OS X plugins. b=468678 r=smichaud sr=roc --- modules/plugin/base/src/nsNPAPIPlugin.cpp | 18 ---- modules/plugin/base/src/nsNPAPIPlugin.h | 4 - modules/plugin/base/src/nsPluginHostImpl.cpp | 2 +- modules/plugin/base/src/nsPluginsDir.h | 12 +-- .../plugin/base/src/nsPluginsDirDarwin.cpp | 100 ++---------------- 5 files changed, 11 insertions(+), 125 deletions(-) diff --git a/modules/plugin/base/src/nsNPAPIPlugin.cpp b/modules/plugin/base/src/nsNPAPIPlugin.cpp index 6ceae2ef2bb..2ed92ebecf3 100644 --- a/modules/plugin/base/src/nsNPAPIPlugin.cpp +++ b/modules/plugin/base/src/nsNPAPIPlugin.cpp @@ -344,15 +344,6 @@ nsNPAPIPlugin::~nsNPAPIPlugin(void) memset((void*) &fCallbacks, 0, sizeof(fCallbacks)); } - -#if defined(XP_MACOSX) -void -nsNPAPIPlugin::SetPluginRefNum(short aRefNum) -{ - fPluginRefNum = aRefNum; -} -#endif - // Creates the nsNPAPIPlugin object. One nsNPAPIPlugin object exists per plugin (not instance). nsresult nsNPAPIPlugin::CreatePlugin(const char* aFileName, const char* aFullPath, @@ -511,18 +502,13 @@ nsNPAPIPlugin::CreatePlugin(const char* aFileName, const char* aFullPath, #endif #if defined(XP_MACOSX) - short appRefNum = ::CurResFile(); - short pluginRefNum; - nsCOMPtr pluginPath; NS_NewNativeLocalFile(nsDependentCString(aFullPath), PR_TRUE, getter_AddRefs(pluginPath)); nsPluginFile pluginFile(pluginPath); - pluginRefNum = pluginFile.OpenPluginResource(); nsNPAPIPlugin* plugin = new nsNPAPIPlugin(nsnull, aLibrary, nsnull); - ::UseResFile(appRefNum); if (!plugin) return NS_ERROR_OUT_OF_MEMORY; @@ -533,8 +519,6 @@ nsNPAPIPlugin::CreatePlugin(const char* aFileName, const char* aFullPath, NS_RELEASE(*aResult); return NS_ERROR_FAILURE; } - - plugin->SetPluginRefNum(pluginRefNum); #endif #ifdef XP_BEOS @@ -629,8 +613,6 @@ nsNPAPIPlugin::Shutdown(void) if (fShutdownEntry) { #if defined(XP_MACOSX) (*fShutdownEntry)(); - if (fPluginRefNum > 0) - ::CloseResFile(fPluginRefNum); #else NS_TRY_SAFE_CALL_VOID(fShutdownEntry(), fLibrary, nsnull); #endif diff --git a/modules/plugin/base/src/nsNPAPIPlugin.h b/modules/plugin/base/src/nsNPAPIPlugin.h index 8e7c3658c01..001d94efc91 100644 --- a/modules/plugin/base/src/nsNPAPIPlugin.h +++ b/modules/plugin/base/src/nsNPAPIPlugin.h @@ -97,10 +97,6 @@ protected: // Ensures that the static CALLBACKS is properly initialized static void CheckClassInitialized(void); -#ifdef XP_MACOSX - short fPluginRefNum; -#endif - // The plugin-side callbacks that the browser calls. One set of // plugin callbacks for each plugin. NPPluginFuncs fCallbacks; diff --git a/modules/plugin/base/src/nsPluginHostImpl.cpp b/modules/plugin/base/src/nsPluginHostImpl.cpp index 8857b626fc3..8d5d3e6b8ed 100644 --- a/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -718,7 +718,7 @@ nsPluginTag::nsPluginTag(nsPluginInfo* aPluginInfo) mLibrary(nsnull), mEntryPoint(nsnull), #ifdef XP_MACOSX - mCanUnloadLibrary(!aPluginInfo->fBundle), + mCanUnloadLibrary(PR_FALSE), #else mCanUnloadLibrary(PR_TRUE), #endif diff --git a/modules/plugin/base/src/nsPluginsDir.h b/modules/plugin/base/src/nsPluginsDir.h index 1887f271147..7c5c109a51a 100644 --- a/modules/plugin/base/src/nsPluginsDir.h +++ b/modules/plugin/base/src/nsPluginsDir.h @@ -35,8 +35,8 @@ * * ***** END LICENSE BLOCK ***** */ -#ifndef nsPluginsDir_h___ -#define nsPluginsDir_h___ +#ifndef nsPluginsDir_h_ +#define nsPluginsDir_h_ #include "nsError.h" #include "nsIFile.h" @@ -66,9 +66,6 @@ struct nsPluginInfo { char* fFileName; char* fFullPath; char* fVersion; -#ifdef XP_MACOSX - PRBool fBundle; -#endif }; /** @@ -104,9 +101,6 @@ 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___ */ +#endif /* nsPluginsDir_h_ */ diff --git a/modules/plugin/base/src/nsPluginsDirDarwin.cpp b/modules/plugin/base/src/nsPluginsDirDarwin.cpp index 81874fcffaa..334a9709fd1 100644 --- a/modules/plugin/base/src/nsPluginsDirDarwin.cpp +++ b/modules/plugin/base/src/nsPluginsDirDarwin.cpp @@ -60,7 +60,6 @@ #include #include -#include #include #include #include @@ -158,12 +157,12 @@ PRBool nsPluginsDir::IsPluginFile(nsIFile* file) PRBool isPluginFile = PR_FALSE; - CFBundleRef pluginBundle = CFBundleCreate(kCFAllocatorDefault, pluginURL); + CFBundleRef pluginBundle = ::CFBundleCreate(kCFAllocatorDefault, pluginURL); if (pluginBundle) { UInt32 packageType, packageCreator; CFBundleGetPackageInfo(pluginBundle, &packageType, &packageCreator); if (packageType == 'BRPL' || packageType == 'IEPL' || packageType == 'NSPL') { - CFURLRef executableURL = CFBundleCopyExecutableURL(pluginBundle); + CFURLRef executableURL = ::CFBundleCopyExecutableURL(pluginBundle); if (executableURL) { isPluginFile = IsLoadablePlugin(executableURL); ::CFRelease(executableURL); @@ -317,79 +316,18 @@ static char* GetNextPluginStringFromHandle(Handle h, short *index) return ret; } -static char* GetPluginString(short id, short index) -{ - 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 -static short OpenPluginResourceFork(nsIFile *pluginFile) -{ - FSSpec spec; - OSErr err = toFSSpec(pluginFile, spec); - Boolean targetIsFolder, wasAliased; - err = ::ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased); - short refNum = ::FSpOpenResFile(&spec, fsRdPerm); - if (refNum < 0) { - nsCString path; - pluginFile->GetNativePath(path); - CFBundleRef bundle = getPluginBundle(path.get()); - if (bundle) { - refNum = CFBundleOpenBundleResourceMap(bundle); - ::CFRelease(bundle); - } - } - return refNum; -} - -short nsPluginFile::OpenPluginResource() -{ - return OpenPluginResourceFork(mPlugin); -} - -class nsAutoCloseResourceObject { -public: - nsAutoCloseResourceObject(nsIFile *pluginFile) - { - mRefNum = OpenPluginResourceFork(pluginFile); - } - ~nsAutoCloseResourceObject() - { - if (mRefNum > 0) - ::CloseResFile(mRefNum); - } - PRBool ResourceOpened() - { - return (mRefNum > 0); - } -private: - short mRefNum; -}; - -/** - * Obtains all of the information currently available for this plugin. - */ +// Obtains all of the information currently available for this plugin. nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info) { // clear out the info, except for the first field. memset(&info, 0, sizeof(info)); - // First open up resource we can use to get plugin info. - - // Try to open a resource fork. - nsAutoCloseResourceObject resourceObject(mPlugin); - bool resourceOpened = resourceObject.ResourceOpened(); // Try to get a bundle reference. nsCString path; mPlugin->GetNativePath(path); CFBundleRef bundle = getPluginBundle(path.get()); - - // Get fBundle - if (bundle) - info.fBundle = PR_TRUE; + if (!bundle) + return NS_ERROR_FAILURE; // Get fName if (bundle) { @@ -397,10 +335,6 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info) if (name && ::CFGetTypeID(name) == ::CFStringGetTypeID()) info.fName = CFStringRefToUTF8Buffer(static_cast(name)); } - if (!info.fName && resourceOpened) { - // 'STR#', 126, 2 => plugin name. - info.fName = GetPluginString(126, 2); - } // Get fDescription if (bundle) { @@ -408,10 +342,6 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info) if (description && ::CFGetTypeID(description) == ::CFStringGetTypeID()) info.fDescription = CFStringRefToUTF8Buffer(static_cast(description)); } - if (!info.fDescription && resourceOpened) { - // 'STR#', 126, 1 => plugin description. - info.fDescription = GetPluginString(126, 1); - } // Get fFileName FSSpec spec; @@ -470,24 +400,8 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info) } } - // Try to get data from the resource fork - if (!info.fVariantCount && resourceObject.ResourceOpened()) { - mi.typeStrings = ::Get1Resource('STR#', 128); - if (mi.typeStrings) { - info.fVariantCount = (**(short**)mi.typeStrings) / 2; - ::DetachResource(mi.typeStrings); - ::HLock(mi.typeStrings); - } else { - // Don't add this plugin because no mime types could be found - return NS_ERROR_FAILURE; - } - - mi.infoStrings = ::Get1Resource('STR#', 127); - if (mi.infoStrings) { - ::DetachResource(mi.infoStrings); - ::HLock(mi.infoStrings); - } - } + if (!info.fVariantCount) + return NS_ERROR_FAILURE; // Fill in the info struct based on the data in the BPSupportedMIMETypes struct int variantCount = info.fVariantCount;