2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
nsPluginsDirDarwin.cpp
|
|
|
|
|
|
|
|
Mac OS X implementation of the nsPluginsDir/nsPluginsFile classes.
|
|
|
|
|
|
|
|
by Patrick C. Beard.
|
|
|
|
*/
|
|
|
|
|
2010-09-15 23:09:19 -07:00
|
|
|
#include "GeckoChildProcessHost.h"
|
|
|
|
#include "base/process_util.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "prlink.h"
|
|
|
|
#include "prnetdb.h"
|
2008-08-14 05:47:04 -07:00
|
|
|
#include "nsXPCOM.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsPluginsDir.h"
|
2008-09-15 05:45:01 -07:00
|
|
|
#include "nsNPAPIPlugin.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsPluginsDirUtils.h"
|
|
|
|
|
|
|
|
#include "nsILocalFileMac.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2008-12-15 09:29:44 -08:00
|
|
|
#include <Carbon/Carbon.h>
|
2007-03-22 10:30:00 -07:00
|
|
|
#include <CoreServices/CoreServices.h>
|
|
|
|
#include <mach-o/loader.h>
|
|
|
|
#include <mach-o/fat.h>
|
|
|
|
|
2008-09-15 05:45:01 -07:00
|
|
|
typedef NS_NPAPIPLUGIN_CALLBACK(const char *, NP_GETMIMEDESCRIPTION) ();
|
|
|
|
typedef NS_NPAPIPLUGIN_CALLBACK(OSErr, BP_GETSUPPORTEDMIMETYPES) (BPSupportedMIMETypes *mimeInfo, UInt32 flags);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-04-14 09:38:11 -07:00
|
|
|
** Returns a CFBundleRef if the path refers to a Mac OS X bundle directory.
|
2007-03-22 10:30:00 -07:00
|
|
|
** The caller is responsible for calling CFRelease() to deallocate.
|
|
|
|
*/
|
|
|
|
static CFBundleRef getPluginBundle(const char* path)
|
|
|
|
{
|
2008-12-09 09:01:29 -08:00
|
|
|
CFBundleRef bundle = NULL;
|
|
|
|
CFStringRef pathRef = ::CFStringCreateWithCString(NULL, path, kCFStringEncodingUTF8);
|
|
|
|
if (pathRef) {
|
|
|
|
CFURLRef bundleURL = ::CFURLCreateWithFileSystemPath(NULL, pathRef, kCFURLPOSIXPathStyle, true);
|
|
|
|
if (bundleURL) {
|
|
|
|
bundle = ::CFBundleCreate(NULL, bundleURL);
|
|
|
|
::CFRelease(bundleURL);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-12-09 09:01:29 -08:00
|
|
|
::CFRelease(pathRef);
|
|
|
|
}
|
|
|
|
return bundle;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult toCFURLRef(nsIFile* file, CFURLRef& outURL)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsILocalFileMac> lfm = do_QueryInterface(file);
|
|
|
|
if (!lfm)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
CFURLRef url;
|
|
|
|
nsresult rv = lfm->GetCFURL(&url);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
outURL = url;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsPluginsDir::IsPluginFile(nsIFile* file)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-09-15 23:09:19 -07:00
|
|
|
nsCString fileName;
|
|
|
|
file->GetNativeLeafName(fileName);
|
2008-09-09 08:43:21 -07:00
|
|
|
/*
|
|
|
|
* Don't load the VDP fake plugin, to avoid tripping a bad bug in OS X
|
|
|
|
* 10.5.3 (see bug 436575).
|
|
|
|
*/
|
2010-09-15 23:09:19 -07:00
|
|
|
if (!strcmp(fileName.get(), "VerifiedDownloadPlugin.plugin")) {
|
2008-09-09 08:43:21 -07:00
|
|
|
NS_WARNING("Preventing load of VerifiedDownloadPlugin.plugin (see bug 436575)");
|
2011-09-29 23:02:59 -07:00
|
|
|
return false;
|
2008-09-09 08:43:21 -07:00
|
|
|
}
|
2011-09-29 23:02:59 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-08-14 05:47:04 -07:00
|
|
|
// Caller is responsible for freeing returned buffer.
|
|
|
|
static char* CFStringRefToUTF8Buffer(CFStringRef cfString)
|
|
|
|
{
|
2011-01-14 05:15:48 -08:00
|
|
|
const char* buffer = ::CFStringGetCStringPtr(cfString, kCFStringEncodingUTF8);
|
|
|
|
if (buffer) {
|
|
|
|
return PL_strdup(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bufferLength =
|
|
|
|
::CFStringGetMaximumSizeForEncoding(::CFStringGetLength(cfString),
|
|
|
|
kCFStringEncodingUTF8) + 1;
|
2008-08-14 05:47:04 -07:00
|
|
|
char* newBuffer = static_cast<char*>(NS_Alloc(bufferLength));
|
2011-01-14 05:15:48 -08:00
|
|
|
if (!newBuffer) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-01-14 05:15:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!::CFStringGetCString(cfString, newBuffer, bufferLength,
|
|
|
|
kCFStringEncodingUTF8)) {
|
2008-08-14 05:47:04 -07:00
|
|
|
NS_Free(newBuffer);
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-08-14 05:47:04 -07:00
|
|
|
}
|
2011-01-14 05:15:48 -08:00
|
|
|
|
|
|
|
newBuffer = static_cast<char*>(NS_Realloc(newBuffer,
|
|
|
|
PL_strlen(newBuffer) + 1));
|
2008-08-14 05:47:04 -07:00
|
|
|
return newBuffer;
|
|
|
|
}
|
|
|
|
|
2010-10-25 10:56:46 -07:00
|
|
|
class AutoCFTypeObject {
|
|
|
|
public:
|
|
|
|
AutoCFTypeObject(CFTypeRef object)
|
|
|
|
{
|
|
|
|
mObject = object;
|
|
|
|
}
|
|
|
|
~AutoCFTypeObject()
|
|
|
|
{
|
|
|
|
::CFRelease(mObject);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
CFTypeRef mObject;
|
|
|
|
};
|
|
|
|
|
2010-11-15 14:21:18 -08:00
|
|
|
static Boolean MimeTypeEnabled(CFDictionaryRef mimeDict) {
|
|
|
|
if (!mimeDict) {
|
2010-11-06 02:38:45 -07:00
|
|
|
return true;
|
2010-11-15 14:21:18 -08:00
|
|
|
}
|
2010-11-06 02:38:45 -07:00
|
|
|
|
2010-11-15 14:21:18 -08:00
|
|
|
CFTypeRef value;
|
|
|
|
if (::CFDictionaryGetValueIfPresent(mimeDict, CFSTR("WebPluginTypeEnabled"), &value)) {
|
|
|
|
if (value && ::CFGetTypeID(value) == ::CFBooleanGetTypeID()) {
|
|
|
|
return ::CFBooleanGetValue(static_cast<CFBooleanRef>(value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2010-11-06 02:38:45 -07:00
|
|
|
}
|
|
|
|
|
2010-10-25 10:56:46 -07:00
|
|
|
static CFDictionaryRef ParsePlistForMIMETypesFilename(CFBundleRef bundle)
|
2008-08-14 05:47:04 -07:00
|
|
|
{
|
2010-10-25 10:56:46 -07:00
|
|
|
CFTypeRef mimeFileName = ::CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("WebPluginMIMETypesFilename"));
|
|
|
|
if (!mimeFileName || ::CFGetTypeID(mimeFileName) != ::CFStringGetTypeID()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
FSRef homeDir;
|
|
|
|
if (::FSFindFolder(kUserDomain, kCurrentUserFolderType, kDontCreateFolder, &homeDir) != noErr) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CFURLRef userDirURL = ::CFURLCreateFromFSRef(kCFAllocatorDefault, &homeDir);
|
|
|
|
if (!userDirURL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoCFTypeObject userDirURLAutorelease(userDirURL);
|
|
|
|
CFStringRef mimeFilePath = ::CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("Library/Preferences/%@"), static_cast<CFStringRef>(mimeFileName));
|
|
|
|
if (!mimeFilePath) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoCFTypeObject mimeFilePathAutorelease(mimeFilePath);
|
|
|
|
CFURLRef mimeFileURL = ::CFURLCreateWithFileSystemPathRelativeToBase(kCFAllocatorDefault, mimeFilePath, kCFURLPOSIXPathStyle, false, userDirURL);
|
|
|
|
if (!mimeFileURL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoCFTypeObject mimeFileURLAutorelease(mimeFileURL);
|
|
|
|
SInt32 errorCode = 0;
|
|
|
|
CFDataRef mimeFileData = NULL;
|
|
|
|
Boolean result = ::CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, mimeFileURL, &mimeFileData, NULL, NULL, &errorCode);
|
|
|
|
if (!result) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoCFTypeObject mimeFileDataAutorelease(mimeFileData);
|
|
|
|
if (errorCode != 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CFPropertyListRef propertyList = ::CFPropertyListCreateFromXMLData(kCFAllocatorDefault, mimeFileData, kCFPropertyListImmutable, NULL);
|
|
|
|
if (!propertyList) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoCFTypeObject propertyListAutorelease(propertyList);
|
|
|
|
if (::CFGetTypeID(propertyList) != ::CFDictionaryGetTypeID()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-01-07 04:47:41 -08:00
|
|
|
|
2010-10-25 10:56:46 -07:00
|
|
|
CFTypeRef mimeTypes = ::CFDictionaryGetValue(static_cast<CFDictionaryRef>(propertyList), CFSTR("WebPluginMIMETypes"));
|
|
|
|
if (!mimeTypes || ::CFGetTypeID(mimeTypes) != ::CFDictionaryGetTypeID() || ::CFDictionaryGetCount(static_cast<CFDictionaryRef>(mimeTypes)) == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return static_cast<CFDictionaryRef>(::CFRetain(mimeTypes));
|
|
|
|
}
|
2008-08-14 05:47:04 -07:00
|
|
|
|
2010-10-25 10:56:46 -07:00
|
|
|
static void ParsePlistPluginInfo(nsPluginInfo& info, CFBundleRef bundle)
|
|
|
|
{
|
|
|
|
CFDictionaryRef mimeDict = ParsePlistForMIMETypesFilename(bundle);
|
|
|
|
|
|
|
|
if (!mimeDict) {
|
|
|
|
CFTypeRef mimeTypes = ::CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("WebPluginMIMETypes"));
|
|
|
|
if (!mimeTypes || ::CFGetTypeID(mimeTypes) != ::CFDictionaryGetTypeID() || ::CFDictionaryGetCount(static_cast<CFDictionaryRef>(mimeTypes)) == 0)
|
2008-08-14 05:47:04 -07:00
|
|
|
return;
|
2010-10-25 10:56:46 -07:00
|
|
|
mimeDict = static_cast<CFDictionaryRef>(::CFRetain(mimeTypes));
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoCFTypeObject mimeDictAutorelease(mimeDict);
|
|
|
|
int mimeDictKeyCount = ::CFDictionaryGetCount(mimeDict);
|
2008-08-14 05:47:04 -07:00
|
|
|
|
2010-10-25 10:56:46 -07:00
|
|
|
// Allocate memory for mime data
|
|
|
|
int mimeDataArraySize = mimeDictKeyCount * sizeof(char*);
|
|
|
|
info.fMimeTypeArray = static_cast<char**>(NS_Alloc(mimeDataArraySize));
|
|
|
|
if (!info.fMimeTypeArray)
|
|
|
|
return;
|
|
|
|
memset(info.fMimeTypeArray, 0, mimeDataArraySize);
|
|
|
|
info.fExtensionArray = static_cast<char**>(NS_Alloc(mimeDataArraySize));
|
|
|
|
if (!info.fExtensionArray)
|
|
|
|
return;
|
|
|
|
memset(info.fExtensionArray, 0, mimeDataArraySize);
|
|
|
|
info.fMimeDescriptionArray = static_cast<char**>(NS_Alloc(mimeDataArraySize));
|
|
|
|
if (!info.fMimeDescriptionArray)
|
|
|
|
return;
|
|
|
|
memset(info.fMimeDescriptionArray, 0, mimeDataArraySize);
|
2008-08-14 05:47:04 -07:00
|
|
|
|
2010-10-25 10:56:46 -07:00
|
|
|
// Allocate memory for mime dictionary keys and values
|
|
|
|
nsAutoArrayPtr<CFTypeRef> keys(new CFTypeRef[mimeDictKeyCount]);
|
|
|
|
if (!keys)
|
|
|
|
return;
|
|
|
|
nsAutoArrayPtr<CFTypeRef> values(new CFTypeRef[mimeDictKeyCount]);
|
|
|
|
if (!values)
|
|
|
|
return;
|
2010-11-06 02:38:45 -07:00
|
|
|
|
|
|
|
info.fVariantCount = 0;
|
2010-10-25 10:56:46 -07:00
|
|
|
|
|
|
|
::CFDictionaryGetKeysAndValues(mimeDict, keys, values);
|
|
|
|
for (int i = 0; i < mimeDictKeyCount; i++) {
|
|
|
|
CFTypeRef mimeString = keys[i];
|
2010-11-15 14:21:18 -08:00
|
|
|
if (!mimeString || ::CFGetTypeID(mimeString) != ::CFStringGetTypeID()) {
|
2010-10-25 10:56:46 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
CFTypeRef mimeDict = values[i];
|
|
|
|
if (mimeDict && ::CFGetTypeID(mimeDict) == ::CFDictionaryGetTypeID()) {
|
2010-11-15 14:21:18 -08:00
|
|
|
if (!MimeTypeEnabled(static_cast<CFDictionaryRef>(mimeDict))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
info.fMimeTypeArray[info.fVariantCount] = CFStringRefToUTF8Buffer(static_cast<CFStringRef>(mimeString));
|
|
|
|
if (!info.fMimeTypeArray[info.fVariantCount]) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-10-25 10:56:46 -07:00
|
|
|
CFTypeRef extensions = ::CFDictionaryGetValue(static_cast<CFDictionaryRef>(mimeDict), CFSTR("WebPluginExtensions"));
|
|
|
|
if (extensions && ::CFGetTypeID(extensions) == ::CFArrayGetTypeID()) {
|
|
|
|
int extensionCount = ::CFArrayGetCount(static_cast<CFArrayRef>(extensions));
|
|
|
|
CFMutableStringRef extensionList = ::CFStringCreateMutable(kCFAllocatorDefault, 0);
|
|
|
|
for (int j = 0; j < extensionCount; j++) {
|
|
|
|
CFTypeRef extension = ::CFArrayGetValueAtIndex(static_cast<CFArrayRef>(extensions), j);
|
|
|
|
if (extension && ::CFGetTypeID(extension) == ::CFStringGetTypeID()) {
|
|
|
|
if (j > 0)
|
|
|
|
::CFStringAppend(extensionList, CFSTR(","));
|
|
|
|
::CFStringAppend(static_cast<CFMutableStringRef>(extensionList), static_cast<CFStringRef>(extension));
|
2008-08-14 05:47:04 -07:00
|
|
|
}
|
|
|
|
}
|
2010-11-06 02:38:45 -07:00
|
|
|
info.fExtensionArray[info.fVariantCount] = CFStringRefToUTF8Buffer(static_cast<CFStringRef>(extensionList));
|
2010-10-25 10:56:46 -07:00
|
|
|
::CFRelease(extensionList);
|
2008-08-14 05:47:04 -07:00
|
|
|
}
|
2010-10-25 10:56:46 -07:00
|
|
|
CFTypeRef description = ::CFDictionaryGetValue(static_cast<CFDictionaryRef>(mimeDict), CFSTR("WebPluginTypeDescription"));
|
|
|
|
if (description && ::CFGetTypeID(description) == ::CFStringGetTypeID())
|
2010-11-06 02:38:45 -07:00
|
|
|
info.fMimeDescriptionArray[info.fVariantCount] = CFStringRefToUTF8Buffer(static_cast<CFStringRef>(description));
|
2008-08-14 05:47:04 -07:00
|
|
|
}
|
2010-11-06 02:38:45 -07:00
|
|
|
info.fVariantCount++;
|
2008-08-14 05:47:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPluginFile::nsPluginFile(nsIFile *spec)
|
|
|
|
: mPlugin(spec)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPluginFile::~nsPluginFile() {}
|
|
|
|
|
2010-08-17 17:05:48 -07:00
|
|
|
nsresult nsPluginFile::LoadPlugin(PRLibrary **outLibrary)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-12-09 09:01:29 -08:00
|
|
|
if (!mPlugin)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-21 09:27:13 -07:00
|
|
|
// 64-bit NSPR does not (yet) support bundles. So in 64-bit builds we need
|
|
|
|
// (for now) to load the bundle's executable. However this can cause
|
|
|
|
// problems: CFBundleCreate() doesn't run the bundle's executable's
|
|
|
|
// initialization code, while NSAddImage() and dlopen() do run it. So using
|
|
|
|
// NSPR's dyld loading mechanisms here (NSAddImage() or dlopen()) can cause
|
|
|
|
// a bundle's initialization code to run earlier than expected, and lead to
|
|
|
|
// crashes. See bug 577967.
|
|
|
|
#ifdef __LP64__
|
2010-02-08 11:22:25 -08:00
|
|
|
char executablePath[PATH_MAX];
|
|
|
|
executablePath[0] = '\0';
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString bundlePath;
|
2010-02-08 11:22:25 -08:00
|
|
|
mPlugin->GetNativePath(bundlePath);
|
|
|
|
CFStringRef pathRef = ::CFStringCreateWithCString(NULL, bundlePath.get(), kCFStringEncodingUTF8);
|
|
|
|
if (pathRef) {
|
|
|
|
CFURLRef bundleURL = ::CFURLCreateWithFileSystemPath(NULL, pathRef, kCFURLPOSIXPathStyle, true);
|
|
|
|
if (bundleURL) {
|
|
|
|
CFBundleRef bundle = ::CFBundleCreate(NULL, bundleURL);
|
|
|
|
if (bundle) {
|
|
|
|
CFURLRef executableURL = ::CFBundleCopyExecutableURL(bundle);
|
|
|
|
if (executableURL) {
|
|
|
|
if (!::CFURLGetFileSystemRepresentation(executableURL, true, (UInt8*)&executablePath, PATH_MAX))
|
|
|
|
executablePath[0] = '\0';
|
|
|
|
::CFRelease(executableURL);
|
|
|
|
}
|
|
|
|
::CFRelease(bundle);
|
|
|
|
}
|
|
|
|
::CFRelease(bundleURL);
|
|
|
|
}
|
|
|
|
::CFRelease(pathRef);
|
|
|
|
}
|
2010-07-21 09:27:13 -07:00
|
|
|
#else
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString bundlePath;
|
2010-07-21 09:27:13 -07:00
|
|
|
mPlugin->GetNativePath(bundlePath);
|
|
|
|
const char *executablePath = bundlePath.get();
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-17 17:05:48 -07:00
|
|
|
*outLibrary = PR_LoadLibrary(executablePath);
|
|
|
|
pLibrary = *outLibrary;
|
|
|
|
if (!pLibrary) {
|
2008-12-09 09:01:29 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
2010-02-08 11:22:25 -08:00
|
|
|
printf("[loaded plugin %s]\n", bundlePath.get());
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2008-12-09 09:01:29 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static char* p2cstrdup(StringPtr pstr)
|
|
|
|
{
|
2008-12-09 09:01:29 -08:00
|
|
|
int len = pstr[0];
|
|
|
|
char* cstr = static_cast<char*>(NS_Alloc(len + 1));
|
|
|
|
if (cstr) {
|
2009-04-14 09:38:11 -07:00
|
|
|
memmove(cstr, pstr + 1, len);
|
2008-12-09 09:01:29 -08:00
|
|
|
cstr[len] = '\0';
|
|
|
|
}
|
|
|
|
return cstr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static char* GetNextPluginStringFromHandle(Handle h, short *index)
|
|
|
|
{
|
|
|
|
char *ret = p2cstrdup((unsigned char*)(*h + *index));
|
|
|
|
*index += (ret ? PL_strlen(ret) : 0) + 1;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsCompatibleArch(nsIFile *file)
|
2010-12-27 11:15:15 -08:00
|
|
|
{
|
|
|
|
CFURLRef pluginURL = NULL;
|
|
|
|
if (NS_FAILED(toCFURLRef(file, pluginURL)))
|
2011-09-29 23:02:59 -07:00
|
|
|
return false;
|
2010-12-27 11:15:15 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isPluginFile = false;
|
2010-12-27 11:15:15 -08:00
|
|
|
|
|
|
|
CFBundleRef pluginBundle = ::CFBundleCreate(kCFAllocatorDefault, pluginURL);
|
|
|
|
if (pluginBundle) {
|
|
|
|
UInt32 packageType, packageCreator;
|
|
|
|
::CFBundleGetPackageInfo(pluginBundle, &packageType, &packageCreator);
|
|
|
|
if (packageType == 'BRPL' || packageType == 'IEPL' || packageType == 'NSPL') {
|
|
|
|
// Get path to plugin as a C string.
|
|
|
|
char executablePath[PATH_MAX];
|
|
|
|
executablePath[0] = '\0';
|
|
|
|
if (!::CFURLGetFileSystemRepresentation(pluginURL, true, (UInt8*)&executablePath, PATH_MAX)) {
|
|
|
|
executablePath[0] = '\0';
|
|
|
|
}
|
|
|
|
|
2012-10-11 16:38:04 -07:00
|
|
|
uint32_t pluginLibArchitectures;
|
2010-12-27 11:15:15 -08:00
|
|
|
nsresult rv = mozilla::ipc::GeckoChildProcessHost::GetArchitecturesForBinary(executablePath, &pluginLibArchitectures);
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-09-29 23:02:59 -07:00
|
|
|
return false;
|
2010-12-27 11:15:15 -08:00
|
|
|
}
|
|
|
|
|
2012-10-11 16:38:04 -07:00
|
|
|
uint32_t containerArchitectures = mozilla::ipc::GeckoChildProcessHost::GetSupportedArchitecturesForProcessType(GeckoProcessType_Plugin);
|
2010-12-27 11:15:15 -08:00
|
|
|
|
|
|
|
// Consider the plugin architecture valid if there is any overlap in the masks.
|
|
|
|
isPluginFile = !!(containerArchitectures & pluginLibArchitectures);
|
|
|
|
}
|
|
|
|
::CFRelease(pluginBundle);
|
|
|
|
}
|
|
|
|
|
|
|
|
::CFRelease(pluginURL);
|
|
|
|
return isPluginFile;
|
|
|
|
}
|
|
|
|
|
2008-12-15 09:29:44 -08:00
|
|
|
/**
|
|
|
|
* Obtains all of the information currently available for this plugin.
|
|
|
|
*/
|
2010-08-17 17:05:48 -07:00
|
|
|
nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info, PRLibrary **outLibrary)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*outLibrary = nullptr;
|
2010-08-17 17:05:48 -07:00
|
|
|
|
2009-04-14 09:38:11 -07:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2010-12-27 11:15:15 -08:00
|
|
|
if (!IsCompatibleArch(mPlugin)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// clear out the info, except for the first field.
|
2008-12-09 09:15:49 -08:00
|
|
|
memset(&info, 0, sizeof(info));
|
2008-08-14 05:47:04 -07:00
|
|
|
|
|
|
|
// Try to get a bundle reference.
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString path;
|
2009-04-14 09:38:11 -07:00
|
|
|
if (NS_FAILED(rv = mPlugin->GetNativePath(path)))
|
|
|
|
return rv;
|
2008-08-14 05:47:04 -07:00
|
|
|
CFBundleRef bundle = getPluginBundle(path.get());
|
2008-12-15 09:29:44 -08:00
|
|
|
|
2009-04-14 09:38:11 -07:00
|
|
|
// fill in full path
|
|
|
|
info.fFullPath = PL_strdup(path.get());
|
|
|
|
|
|
|
|
// fill in file name
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString fileName;
|
2009-04-14 09:38:11 -07:00
|
|
|
if (NS_FAILED(rv = mPlugin->GetNativeLeafName(fileName)))
|
|
|
|
return rv;
|
|
|
|
info.fFileName = PL_strdup(fileName.get());
|
|
|
|
|
2008-08-14 05:47:04 -07:00
|
|
|
// Get fName
|
|
|
|
if (bundle) {
|
|
|
|
CFTypeRef name = ::CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("WebPluginName"));
|
|
|
|
if (name && ::CFGetTypeID(name) == ::CFStringGetTypeID())
|
|
|
|
info.fName = CFStringRefToUTF8Buffer(static_cast<CFStringRef>(name));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get fDescription
|
|
|
|
if (bundle) {
|
|
|
|
CFTypeRef description = ::CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("WebPluginDescription"));
|
|
|
|
if (description && ::CFGetTypeID(description) == ::CFStringGetTypeID())
|
|
|
|
info.fDescription = CFStringRefToUTF8Buffer(static_cast<CFStringRef>(description));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get fVersion
|
2007-03-22 10:30:00 -07:00
|
|
|
if (bundle) {
|
2008-07-15 03:50:42 -07:00
|
|
|
// Look for the release version first
|
2008-08-14 05:47:04 -07:00
|
|
|
CFTypeRef version = ::CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("CFBundleShortVersionString"));
|
|
|
|
if (!version) // try the build version
|
|
|
|
version = ::CFBundleGetValueForInfoDictionaryKey(bundle, kCFBundleVersionKey);
|
|
|
|
if (version && ::CFGetTypeID(version) == ::CFStringGetTypeID())
|
|
|
|
info.fVersion = CFStringRefToUTF8Buffer(static_cast<CFStringRef>(version));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-08-14 05:47:04 -07:00
|
|
|
|
|
|
|
// The last thing we need to do is get MIME data
|
|
|
|
// fVariantCount, fMimeTypeArray, fExtensionArray, fMimeDescriptionArray
|
|
|
|
|
|
|
|
// First look for data in a bundle plist
|
|
|
|
if (bundle) {
|
|
|
|
ParsePlistPluginInfo(info, bundle);
|
|
|
|
::CFRelease(bundle);
|
|
|
|
if (info.fVariantCount > 0)
|
2010-08-17 17:05:48 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-08-14 05:47:04 -07:00
|
|
|
// It's possible that our plugin has 2 entry points that'll give us mime type
|
|
|
|
// info. Quicktime does this to get around the need of having admin rights to
|
|
|
|
// change mime info in the resource fork. We need to use this info instead of
|
|
|
|
// the resource. See bug 113464.
|
|
|
|
|
2010-08-17 17:05:48 -07:00
|
|
|
// Sadly we have to load the library for this to work.
|
|
|
|
rv = LoadPlugin(outLibrary);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2008-08-14 05:47:04 -07:00
|
|
|
// Try to get data from NP_GetMIMEDescription
|
|
|
|
if (pLibrary) {
|
|
|
|
NP_GETMIMEDESCRIPTION pfnGetMimeDesc = (NP_GETMIMEDESCRIPTION)PR_FindFunctionSymbol(pLibrary, NP_GETMIMEDESCRIPTION_NAME);
|
|
|
|
if (pfnGetMimeDesc)
|
|
|
|
ParsePluginMimeDescription(pfnGetMimeDesc(), info);
|
|
|
|
if (info.fVariantCount)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We'll fill this in using BP_GetSupportedMIMETypes and/or resource fork data
|
2007-03-22 10:30:00 -07:00
|
|
|
BPSupportedMIMETypes mi = {kBPSupportedMIMETypesStructVers_1, NULL, NULL};
|
2008-08-14 05:47:04 -07:00
|
|
|
|
|
|
|
// Try to get data from BP_GetSupportedMIMETypes
|
2007-03-22 10:30:00 -07:00
|
|
|
if (pLibrary) {
|
2008-08-14 05:47:04 -07:00
|
|
|
BP_GETSUPPORTEDMIMETYPES pfnMime = (BP_GETSUPPORTEDMIMETYPES)PR_FindFunctionSymbol(pLibrary, "BP_GetSupportedMIMETypes");
|
|
|
|
if (pfnMime && noErr == pfnMime(&mi, 0) && mi.typeStrings) {
|
2007-03-22 10:30:00 -07:00
|
|
|
info.fVariantCount = (**(short**)mi.typeStrings) / 2;
|
|
|
|
::HLock(mi.typeStrings);
|
|
|
|
if (mi.infoStrings) // it's possible some plugins have infoStrings missing
|
|
|
|
::HLock(mi.infoStrings);
|
|
|
|
}
|
|
|
|
}
|
2008-08-14 05:47:04 -07:00
|
|
|
|
|
|
|
// Fill in the info struct based on the data in the BPSupportedMIMETypes struct
|
2007-03-22 10:30:00 -07:00
|
|
|
int variantCount = info.fVariantCount;
|
2008-10-28 12:29:16 -07:00
|
|
|
info.fMimeTypeArray = static_cast<char**>(NS_Alloc(variantCount * sizeof(char*)));
|
|
|
|
if (!info.fMimeTypeArray)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
info.fExtensionArray = static_cast<char**>(NS_Alloc(variantCount * sizeof(char*)));
|
|
|
|
if (!info.fExtensionArray)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
if (mi.infoStrings) {
|
|
|
|
info.fMimeDescriptionArray = static_cast<char**>(NS_Alloc(variantCount * sizeof(char*)));
|
|
|
|
if (!info.fMimeDescriptionArray)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
short mimeIndex = 2;
|
|
|
|
short descriptionIndex = 2;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (int i = 0; i < variantCount; i++) {
|
|
|
|
info.fMimeTypeArray[i] = GetNextPluginStringFromHandle(mi.typeStrings, &mimeIndex);
|
|
|
|
info.fExtensionArray[i] = GetNextPluginStringFromHandle(mi.typeStrings, &mimeIndex);
|
|
|
|
if (mi.infoStrings)
|
|
|
|
info.fMimeDescriptionArray[i] = GetNextPluginStringFromHandle(mi.infoStrings, &descriptionIndex);
|
|
|
|
}
|
2008-08-14 05:47:04 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
::HUnlock(mi.typeStrings);
|
|
|
|
::DisposeHandle(mi.typeStrings);
|
|
|
|
if (mi.infoStrings) {
|
2008-08-14 05:47:04 -07:00
|
|
|
::HUnlock(mi.infoStrings);
|
2007-03-22 10:30:00 -07:00
|
|
|
::DisposeHandle(mi.infoStrings);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
|
|
|
|
{
|
2008-12-09 09:15:49 -08:00
|
|
|
NS_Free(info.fName);
|
|
|
|
NS_Free(info.fDescription);
|
|
|
|
int variantCount = info.fVariantCount;
|
|
|
|
for (int i = 0; i < variantCount; i++) {
|
|
|
|
NS_Free(info.fMimeTypeArray[i]);
|
|
|
|
NS_Free(info.fExtensionArray[i]);
|
|
|
|
NS_Free(info.fMimeDescriptionArray[i]);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-12-09 09:15:49 -08:00
|
|
|
NS_Free(info.fMimeTypeArray);
|
|
|
|
NS_Free(info.fMimeDescriptionArray);
|
|
|
|
NS_Free(info.fExtensionArray);
|
|
|
|
NS_Free(info.fFileName);
|
|
|
|
NS_Free(info.fFullPath);
|
|
|
|
NS_Free(info.fVersion);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|