Back to index

lightning-sunbird  0.9+nobinonly
Typedefs | Functions
nsPluginsDirDarwin.cpp File Reference
#include "prlink.h"
#include "prnetdb.h"
#include "nsPluginsDir.h"
#include "ns4xPlugin.h"
#include "nsPluginsDirUtils.h"
#include "nsILocalFileMac.h"
#include <Carbon/Carbon.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <mach-o/loader.h>
#include <mach-o/fat.h>
#include <CFURL.h>
#include <CFBundle.h>
#include <CFString.h>
#include <CodeFragments.h>

Go to the source code of this file.

Typedefs

typedef UInt32 flags

Functions

typedef NS_4XPLUGIN_CALLBACK (const char *, NP_GETMIMEDESCRIPTION)()
typedef NS_4XPLUGIN_CALLBACK (OSErr, BP_GETSUPPORTEDMIMETYPES)(BPSupportedMIMETypes *mimeInfo
static CFBundleRef getPluginBundle (const char *path)
static OSErr toFSSpec (nsIFile *file, FSSpec &outSpec)
static nsresult toCFURLRef (nsIFile *file, CFURLRef &outURL)
static short OpenPluginResourceFork (nsIFile *pluginFile)
static PRBool IsLoadablePlugin (CFURLRef aURL)
static char * p2cstrdup (StringPtr pstr)
static char * GetNextPluginStringFromHandle (Handle h, short *index)
static char * GetPluginString (short id, short index)

Typedef Documentation

Definition at line 70 of file nsPluginsDirDarwin.cpp.


Function Documentation

static char* GetNextPluginStringFromHandle ( Handle  h,
short *  index 
) [static]

Definition at line 281 of file nsPluginsDirDarwin.cpp.

{
  char *ret = p2cstrdup((unsigned char*)(*h + *index));
  *index += (ret ? PL_strlen(ret) : 0) + 1;
  return ret;
}

Here is the call graph for this function:

static CFBundleRef getPluginBundle ( const char *  path) [static]

Definition at line 77 of file nsPluginsDirDarwin.cpp.

{
    CFBundleRef bundle = NULL;
    CFStringRef pathRef = CFStringCreateWithCString(NULL, path, kCFStringEncodingUTF8);
    if (pathRef) {
        CFURLRef bundleURL = CFURLCreateWithFileSystemPath(NULL, pathRef, kCFURLPOSIXPathStyle, true);
        if (bundleURL != NULL) {
            bundle = CFBundleCreate(NULL, bundleURL);
            CFRelease(bundleURL);
        }
        CFRelease(pathRef);
    }
    return bundle;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* GetPluginString ( short  id,
short  index 
) [static]

Definition at line 288 of file nsPluginsDirDarwin.cpp.

{
    Str255 str;
    ::GetIndString(str, id, index);
    return p2cstrdup(str);
}

Here is the call graph for this function:

static PRBool IsLoadablePlugin ( CFURLRef  aURL) [static]

Definition at line 141 of file nsPluginsDirDarwin.cpp.

{
  if (!aURL)
    return PR_FALSE;
  
  PRBool isLoadable = PR_FALSE;
  char path[PATH_MAX];
  if (CFURLGetFileSystemRepresentation(aURL, TRUE, (UInt8*)path, sizeof(path))) {
    UInt32 magic;
    int f = open(path, O_RDONLY);
    if (f != -1) {
      // Mach-O headers use the byte ordering of the architecture on which
      // they run, so test against the magic number in the byte order
      // we're compiling for. Fat headers are always big-endian, so swap
      // them to host before comparing to host representation of the magic
      if (read(f, &magic, sizeof(magic)) == sizeof(magic)) {
        if ((magic == MH_MAGIC) || (PR_ntohl(magic) == FAT_MAGIC))
          isLoadable = PR_TRUE;
#ifdef __POWERPC__
        // if we're on ppc, we can use CFM plugins
        if (isLoadable == PR_FALSE) {
          UInt32 magic2;
          if (read(f, &magic2, sizeof(magic2)) == sizeof(magic2)) {
            UInt32 cfm_header1 = 0x4A6F7921; // 'Joy!'
            UInt32 cfm_header2 = 0x70656666; // 'peff'
            if (cfm_header1 == magic && cfm_header2 == magic2)
              isLoadable = PR_TRUE;
          }
        }
#endif
      }
      close(f);
    }
  }
  return isLoadable;
}
typedef NS_4XPLUGIN_CALLBACK ( const char *  ,
NP_GETMIMEDESCRIPTION   
)
typedef NS_4XPLUGIN_CALLBACK ( OSErr  ,
BP_GETSUPPORTEDMIMETYPES   
)
static short OpenPluginResourceFork ( nsIFile pluginFile) [static]

Definition at line 120 of file nsPluginsDirDarwin.cpp.

{
    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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* p2cstrdup ( StringPtr  pstr) [static]

Definition at line 270 of file nsPluginsDirDarwin.cpp.

{
    int len = pstr[0];
    char* cstr = new char[len + 1];
    if (cstr != NULL) {
        ::BlockMoveData(pstr + 1, cstr, len);
        cstr[len] = '\0';
    }
    return cstr;
}

Here is the caller graph for this function:

static nsresult toCFURLRef ( nsIFile file,
CFURLRef outURL 
) [static]

Definition at line 104 of file nsPluginsDirDarwin.cpp.

{
  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;
}

Here is the call graph for this function:

static OSErr toFSSpec ( nsIFile file,
FSSpec outSpec 
) [static]

Definition at line 92 of file nsPluginsDirDarwin.cpp.

{
    nsCOMPtr<nsILocalFileMac> lfm = do_QueryInterface(file);
    if (!lfm)
        return -1;
    FSSpec foo;
    lfm->GetFSSpec(&foo);
    outSpec = foo;

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function: