diff --git a/mozilla/modules/plugin/base/src/ns4xPlugin.cpp b/mozilla/modules/plugin/base/src/ns4xPlugin.cpp index 999a756dd0d..d6f482f4b97 100644 --- a/mozilla/modules/plugin/base/src/ns4xPlugin.cpp +++ b/mozilla/modules/plugin/base/src/ns4xPlugin.cpp @@ -327,12 +327,13 @@ ns4xPlugin::CreatePlugin(nsIServiceManager* aServiceMgr, memset((void*) &callbacks, 0, sizeof(callbacks)); callbacks.size = sizeof(callbacks); - nsPluginsDir pluginsDir(PLUGINS_DIR_LOCATION_MAC_OLD); + nsPluginsDir pluginsDir(PLUGINS_DIR_LOCATION_MAC_SYSTEM_PLUGINS_FOLDER); if(!pluginsDir.Valid()) return NS_ERROR_FAILURE; short appRefNum = ::CurResFile(); short pluginRefNum; + Boolean found = false; for(nsDirectoryIterator iter(pluginsDir, PR_TRUE); iter.Exists(); iter++) { const nsFileSpec& file = iter; @@ -344,9 +345,34 @@ ns4xPlugin::CreatePlugin(nsIServiceManager* aServiceMgr, Boolean targetIsFolder, wasAliased; OSErr err = ::ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased); pluginRefNum = ::FSpOpenResFile(&spec, fsRdPerm); + found = true; } } } + + // if we didn't find it, try locally + if (!found) + { + nsPluginsDir pluginsDir(PLUGINS_DIR_LOCATION_MOZ_LOCAL); + + appRefNum = ::CurResFile(); + for(nsDirectoryIterator iter(pluginsDir, PR_TRUE); iter.Exists(); iter++) + { + const nsFileSpec& file = iter; + if (pluginsDir.IsPluginFile(file)) + { + 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; + } + } + } + } + // call into the entry point NPError error; diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp index 17671d6aa64..ae3888acb14 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -3920,9 +3920,11 @@ NS_IMETHODIMP nsPluginHostImpl::LoadPlugins() rv = LoadXPCOMPlugins(compManager, path); } + + nsCOMPtr theprefs = do_GetService(NS_PREF_CONTRACTID); // scan the 4x plugins directory for eligible legacy plugin libraries -#ifndef XP_WIN // old plugin finding logic +#if !defined(XP_WIN) && !defined (XP_MAC) // old plugin finding logic // scan Mozilla plugins dir nsPluginsDir pluginsDir; @@ -3935,26 +3937,50 @@ NS_IMETHODIMP nsPluginHostImpl::LoadPlugins() ScanPluginsDirectory(pluginsDir, compManager, lpath); } +#endif -#ifdef XP_MAC - // try to scan old-spelled plugins dir ("Plug-ins") for Mac +#if defined (XP_MAC) + // try to scan plugins dir ("Plug-ins") for Mac // should we check for duplicate plugins here? We probably should. - nsPluginsDir pluginsDirMacOld(PLUGINS_DIR_LOCATION_MAC_OLD); + nsPluginsDir pluginsDirMac(PLUGINS_DIR_LOCATION_MOZ_LOCAL); + + // on Mac there is a common folder for storing plugins. Go and look there next + nsPluginsDir pluginsDirMacSystem(PLUGINS_DIR_LOCATION_MAC_SYSTEM_PLUGINS_FOLDER); + + if (pluginsDirMacSystem.Valid()) + { + PRBool skipSystem = PR_FALSE; + if (theprefs) + theprefs->GetBoolPref("browser.plugins.skipSystemInternetFolder",&skipSystem); + + // now do the "Internet plug-ins" + if (!skipSystem) + { + nsCOMPtr lpath = nsnull; + if(isLayoutPath) + lpath = path; - if (pluginsDirMacOld.Valid()) + ScanPluginsDirectory(pluginsDirMacSystem, + compManager, + lpath, + PR_FALSE); // don't check for specific plugins + } + } + + if (pluginsDirMac.Valid()) { nsCOMPtr lpath = nsnull; if(isLayoutPath) lpath = path; - ScanPluginsDirectory(pluginsDirMacOld, + ScanPluginsDirectory(pluginsDirMac, compManager, lpath, PR_FALSE); // don't check for specific plugins } #endif // XP_MAC -#else // XP_WIN go for new plugin finding logic on Windows +#if defined (XP_WIN) // XP_WIN go for new plugin finding logic on Windows // currently we decided to look in both local plugins dir and // that of the previous 4.x installation combining plugins from both places. @@ -4000,7 +4026,6 @@ NS_IMETHODIMP nsPluginHostImpl::LoadPlugins() #ifdef XP_WIN // Checks the installation path of Sun's JRE in scanning for plugins if the prefs are enabled - nsCOMPtr theprefs = do_GetService(NS_PREF_CONTRACTID); if (theprefs) // we got the pref service { PRBool javaEnabled = PR_FALSE; // don't bother the scan if java is OFF diff --git a/mozilla/modules/plugin/base/src/nsPluginsDir.h b/mozilla/modules/plugin/base/src/nsPluginsDir.h index 70d5a1848ef..84f30d1641e 100644 --- a/mozilla/modules/plugin/base/src/nsPluginsDir.h +++ b/mozilla/modules/plugin/base/src/nsPluginsDir.h @@ -37,7 +37,7 @@ #define PLUGINS_DIR_LOCATION_AUTO 0 #define PLUGINS_DIR_LOCATION_MOZ_LOCAL 1 #define PLUGINS_DIR_LOCATION_4DOTX 2 -#define PLUGINS_DIR_LOCATION_MAC_OLD 3 +#define PLUGINS_DIR_LOCATION_MAC_SYSTEM_PLUGINS_FOLDER 3 #define PLUGINS_DIR_LOCATION_JAVA_JRE 4 class nsPluginsDir : public nsFileSpec { diff --git a/mozilla/modules/plugin/base/src/nsPluginsDirMac.cpp b/mozilla/modules/plugin/base/src/nsPluginsDirMac.cpp index d03211de05c..6e9508c620e 100644 --- a/mozilla/modules/plugin/base/src/nsPluginsDirMac.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginsDirMac.cpp @@ -30,6 +30,7 @@ #include "nsPluginsDir.h" #include "prlink.h" +#include "nsSpecialSystemDirectory.h" #include #include @@ -38,34 +39,28 @@ #include #include -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); -} - nsPluginsDir::nsPluginsDir(PRUint16 location) { PRBool wasAliased; - // The "Plugins" folder in the application's directory is where plugins are loaded from. - mError = getApplicationSpec(mSpec); - if (NS_SUCCEEDED(mError)) + switch (location) { - if (location == PLUGINS_DIR_LOCATION_MAC_OLD) - SetLeafName("Plug-ins"); - else - SetLeafName("Plugins"); + case PLUGINS_DIR_LOCATION_MAC_SYSTEM_PLUGINS_FOLDER: + // The system's shared "Plugin-ins" folder + mError = ::FindFolder(kOnAppropriateDisk, kInternetPlugInFolderType, kDontCreateFolder, & mSpec.vRefNum, &mSpec.parID); + if (mError) + mError = ::FSMakeFSSpec(mSpec.vRefNum, mSpec.parID, "\p", &mSpec); + break; + case PLUGINS_DIR_LOCATION_MOZ_LOCAL: + default: + // The "Plug-ins" folder in the application's directory is where plugins are loaded from. + // Use the Moz_BinDirectory + nsSpecialSystemDirectory plugDir(nsSpecialSystemDirectory::Moz_BinDirectory); + *(nsFileSpec*)this = plugDir + "Plug-ins"; + break; + } if (IsSymlink()) ResolveSymlink(wasAliased); - } } nsPluginsDir::~nsPluginsDir() {} diff --git a/mozilla/modules/plugin/nglsrc/ns4xPlugin.cpp b/mozilla/modules/plugin/nglsrc/ns4xPlugin.cpp index 999a756dd0d..d6f482f4b97 100644 --- a/mozilla/modules/plugin/nglsrc/ns4xPlugin.cpp +++ b/mozilla/modules/plugin/nglsrc/ns4xPlugin.cpp @@ -327,12 +327,13 @@ ns4xPlugin::CreatePlugin(nsIServiceManager* aServiceMgr, memset((void*) &callbacks, 0, sizeof(callbacks)); callbacks.size = sizeof(callbacks); - nsPluginsDir pluginsDir(PLUGINS_DIR_LOCATION_MAC_OLD); + nsPluginsDir pluginsDir(PLUGINS_DIR_LOCATION_MAC_SYSTEM_PLUGINS_FOLDER); if(!pluginsDir.Valid()) return NS_ERROR_FAILURE; short appRefNum = ::CurResFile(); short pluginRefNum; + Boolean found = false; for(nsDirectoryIterator iter(pluginsDir, PR_TRUE); iter.Exists(); iter++) { const nsFileSpec& file = iter; @@ -344,9 +345,34 @@ ns4xPlugin::CreatePlugin(nsIServiceManager* aServiceMgr, Boolean targetIsFolder, wasAliased; OSErr err = ::ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased); pluginRefNum = ::FSpOpenResFile(&spec, fsRdPerm); + found = true; } } } + + // if we didn't find it, try locally + if (!found) + { + nsPluginsDir pluginsDir(PLUGINS_DIR_LOCATION_MOZ_LOCAL); + + appRefNum = ::CurResFile(); + for(nsDirectoryIterator iter(pluginsDir, PR_TRUE); iter.Exists(); iter++) + { + const nsFileSpec& file = iter; + if (pluginsDir.IsPluginFile(file)) + { + 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; + } + } + } + } + // call into the entry point NPError error; diff --git a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp index 17671d6aa64..ae3888acb14 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp @@ -3920,9 +3920,11 @@ NS_IMETHODIMP nsPluginHostImpl::LoadPlugins() rv = LoadXPCOMPlugins(compManager, path); } + + nsCOMPtr theprefs = do_GetService(NS_PREF_CONTRACTID); // scan the 4x plugins directory for eligible legacy plugin libraries -#ifndef XP_WIN // old plugin finding logic +#if !defined(XP_WIN) && !defined (XP_MAC) // old plugin finding logic // scan Mozilla plugins dir nsPluginsDir pluginsDir; @@ -3935,26 +3937,50 @@ NS_IMETHODIMP nsPluginHostImpl::LoadPlugins() ScanPluginsDirectory(pluginsDir, compManager, lpath); } +#endif -#ifdef XP_MAC - // try to scan old-spelled plugins dir ("Plug-ins") for Mac +#if defined (XP_MAC) + // try to scan plugins dir ("Plug-ins") for Mac // should we check for duplicate plugins here? We probably should. - nsPluginsDir pluginsDirMacOld(PLUGINS_DIR_LOCATION_MAC_OLD); + nsPluginsDir pluginsDirMac(PLUGINS_DIR_LOCATION_MOZ_LOCAL); + + // on Mac there is a common folder for storing plugins. Go and look there next + nsPluginsDir pluginsDirMacSystem(PLUGINS_DIR_LOCATION_MAC_SYSTEM_PLUGINS_FOLDER); + + if (pluginsDirMacSystem.Valid()) + { + PRBool skipSystem = PR_FALSE; + if (theprefs) + theprefs->GetBoolPref("browser.plugins.skipSystemInternetFolder",&skipSystem); + + // now do the "Internet plug-ins" + if (!skipSystem) + { + nsCOMPtr lpath = nsnull; + if(isLayoutPath) + lpath = path; - if (pluginsDirMacOld.Valid()) + ScanPluginsDirectory(pluginsDirMacSystem, + compManager, + lpath, + PR_FALSE); // don't check for specific plugins + } + } + + if (pluginsDirMac.Valid()) { nsCOMPtr lpath = nsnull; if(isLayoutPath) lpath = path; - ScanPluginsDirectory(pluginsDirMacOld, + ScanPluginsDirectory(pluginsDirMac, compManager, lpath, PR_FALSE); // don't check for specific plugins } #endif // XP_MAC -#else // XP_WIN go for new plugin finding logic on Windows +#if defined (XP_WIN) // XP_WIN go for new plugin finding logic on Windows // currently we decided to look in both local plugins dir and // that of the previous 4.x installation combining plugins from both places. @@ -4000,7 +4026,6 @@ NS_IMETHODIMP nsPluginHostImpl::LoadPlugins() #ifdef XP_WIN // Checks the installation path of Sun's JRE in scanning for plugins if the prefs are enabled - nsCOMPtr theprefs = do_GetService(NS_PREF_CONTRACTID); if (theprefs) // we got the pref service { PRBool javaEnabled = PR_FALSE; // don't bother the scan if java is OFF diff --git a/mozilla/modules/plugin/nglsrc/nsPluginsDir.h b/mozilla/modules/plugin/nglsrc/nsPluginsDir.h index 70d5a1848ef..84f30d1641e 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginsDir.h +++ b/mozilla/modules/plugin/nglsrc/nsPluginsDir.h @@ -37,7 +37,7 @@ #define PLUGINS_DIR_LOCATION_AUTO 0 #define PLUGINS_DIR_LOCATION_MOZ_LOCAL 1 #define PLUGINS_DIR_LOCATION_4DOTX 2 -#define PLUGINS_DIR_LOCATION_MAC_OLD 3 +#define PLUGINS_DIR_LOCATION_MAC_SYSTEM_PLUGINS_FOLDER 3 #define PLUGINS_DIR_LOCATION_JAVA_JRE 4 class nsPluginsDir : public nsFileSpec { diff --git a/mozilla/modules/plugin/nglsrc/nsPluginsDirMac.cpp b/mozilla/modules/plugin/nglsrc/nsPluginsDirMac.cpp index d03211de05c..6e9508c620e 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginsDirMac.cpp +++ b/mozilla/modules/plugin/nglsrc/nsPluginsDirMac.cpp @@ -30,6 +30,7 @@ #include "nsPluginsDir.h" #include "prlink.h" +#include "nsSpecialSystemDirectory.h" #include #include @@ -38,34 +39,28 @@ #include #include -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); -} - nsPluginsDir::nsPluginsDir(PRUint16 location) { PRBool wasAliased; - // The "Plugins" folder in the application's directory is where plugins are loaded from. - mError = getApplicationSpec(mSpec); - if (NS_SUCCEEDED(mError)) + switch (location) { - if (location == PLUGINS_DIR_LOCATION_MAC_OLD) - SetLeafName("Plug-ins"); - else - SetLeafName("Plugins"); + case PLUGINS_DIR_LOCATION_MAC_SYSTEM_PLUGINS_FOLDER: + // The system's shared "Plugin-ins" folder + mError = ::FindFolder(kOnAppropriateDisk, kInternetPlugInFolderType, kDontCreateFolder, & mSpec.vRefNum, &mSpec.parID); + if (mError) + mError = ::FSMakeFSSpec(mSpec.vRefNum, mSpec.parID, "\p", &mSpec); + break; + case PLUGINS_DIR_LOCATION_MOZ_LOCAL: + default: + // The "Plug-ins" folder in the application's directory is where plugins are loaded from. + // Use the Moz_BinDirectory + nsSpecialSystemDirectory plugDir(nsSpecialSystemDirectory::Moz_BinDirectory); + *(nsFileSpec*)this = plugDir + "Plug-ins"; + break; + } if (IsSymlink()) ResolveSymlink(wasAliased); - } } nsPluginsDir::~nsPluginsDir() {}