Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Attributes
nsPluginFile Class Reference

Provides cross-platform access to a plugin file. More...

#include <nsPluginsDir.h>

Collaboration diagram for nsPluginFile:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsPluginFile (nsIFile *spec)
 If spec corresponds to a valid plugin file, constructs a reference to a plugin file on disk.
virtual ~nsPluginFile ()
nsresult LoadPlugin (PRLibrary *&outLibrary)
 Loads the plugin into memory using NSPR's shared-library loading mechanism.
nsresult GetPluginInfo (nsPluginInfo &outPluginInfo)
 Obtains all of the information currently available for this plugin.
nsresult FreePluginInfo (nsPluginInfo &PluginInfo)
 Should be called after GetPluginInfo to free all allocated stuff.
short OpenPluginResource (void)

Private Attributes

PRLibrarypLibrary
nsCOMPtr< nsIFilemPlugin

Detailed Description

Provides cross-platform access to a plugin file.

Deals with reading properties from the plugin file, and loading the plugin's shared library. Insulates core nsIPluginHost implementations from these details.

Definition at line 80 of file nsPluginsDir.h.


Constructor & Destructor Documentation

If spec corresponds to a valid plugin file, constructs a reference to a plugin file on disk.

Plugins are typically located using the nsPluginsDir class.

Definition at line 127 of file nsPluginsDirBeOS.cpp.

:      mPlugin(spec)
{
       // nada
}

Definition at line 133 of file nsPluginsDirBeOS.cpp.

{
       // nada
}

Member Function Documentation

Should be called after GetPluginInfo to free all allocated stuff.

Definition at line 257 of file nsPluginsDirBeOS.cpp.

{
    if (info.fName)
        PL_strfree(info.fName);

    if (info.fDescription)
        PL_strfree(info.fDescription);

    for (PRUint32 i = 0; i < info.fVariantCount; i++) {
        if (info.fMimeTypeArray[i])
            PL_strfree(info.fMimeTypeArray[i]);

        if (info.fMimeDescriptionArray[i])
            PL_strfree(info.fMimeDescriptionArray[i]);

        if (info.fExtensionArray[i])
            PL_strfree(info.fExtensionArray[i]);
    }

    PR_FREEIF(info.fMimeTypeArray);
    PR_FREEIF(info.fMimeDescriptionArray);
    PR_FREEIF(info.fExtensionArray);

    if (info.fFileName)
        PL_strfree(info.fFileName);

    return NS_OK;
}

Here is the caller graph for this function:

Obtains all of the information currently available for this plugin.

Definition at line 164 of file nsPluginsDirBeOS.cpp.

{
    nsCAutoString fpath;
    nsresult rv = mPlugin->GetNativePath(fpath);
    if (NS_OK != rv) {
        return rv;
    }
    const char *path = fpath.get();
    int i;

#ifdef NS_PLUGIN_BEOS_DEBUG
    printf("nsPluginFile::GetPluginInfo() an attempt to load MIME String\n");
    printf("path = <%s>\n", path);
#endif

    // get supported mime types
    BFile file(path, B_READ_ONLY);
    if (file.InitCheck() != B_OK)
        return NS_ERROR_FAILURE;

    BAppFileInfo appinfo(&file);
    if (appinfo.InitCheck() != B_OK)
        return NS_ERROR_FAILURE;

    BMessage msg;
    if (appinfo.GetSupportedTypes(&msg) != B_OK)
        return NS_ERROR_FAILURE;

    uint32 type;
    int32 types_num;
    if (msg.GetInfo("types", &type, &types_num) != B_OK
        || type != B_STRING_TYPE)
        return NS_ERROR_FAILURE;

    // set mime types to plugin info
    info.fMimeTypeArray =(char **)PR_Malloc(types_num * sizeof(char *));
    info.fMimeDescriptionArray =(char **)PR_Malloc(types_num * sizeof(char *));
    info.fExtensionArray =(char **)PR_Malloc(types_num * sizeof(char *));

    for (i = 0 ; i < types_num ; i ++) {
        // get mime string
        const char *mtype;
        if (msg.FindString("types", i, &mtype) != B_OK) {
            types_num = i;
            break;
        }
        
        // get (short)description for the mime
        char desc[B_MIME_TYPE_LENGTH+1] = "";
        BMimeType mime(mtype) ;
        if (mime.InitCheck() == B_OK)
            mime.GetShortDescription(desc);
        
        // get file extensions for the mime
        char extensions[B_MIME_TYPE_LENGTH+1] = "";
        GetMimeExtensions(mtype, extensions, B_MIME_TYPE_LENGTH+1);

        #ifdef NS_PLUGIN_BEOS_DEBUG
            printf("  mime = %30s | %10s | %15s |\n", 
                mtype, extensions, desc);
        #endif
        
        info.fMimeTypeArray[i] = PL_strdup( mtype ? mtype : (char *)"" ) ;
        info.fMimeDescriptionArray[i] = PL_strdup( desc ) ;
        info.fExtensionArray[i] = PL_strdup( extensions );
    }

    // get name and description of this plugin
    version_info vinfo;
    if (appinfo.GetVersionInfo(&vinfo, B_APP_VERSION_KIND) == B_OK
        && *vinfo.short_info) {
        // XXX convert UTF-8 2byte chars to 1 byte chars, to avoid string corruption
        info.fName = ToNewCString(NS_ConvertUTF8toUCS2(vinfo.short_info));
        info.fDescription = ToNewCString(NS_ConvertUTF8toUCS2(vinfo.long_info));
    } else {
        // use filename as its name
        info.fName = GetFileName(path);
        info.fDescription = PL_strdup("");
    }

    info.fVariantCount = types_num;
    info.fFileName = PL_strdup(path);


#ifdef NS_PLUGIN_BEOS_DEBUG
    printf("info.fFileName = %s\n", info.fFileName);
    printf("info.fName = %s\n", info.fName);
    printf("info.fDescription = %s\n", info.fDescription);
#endif

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Loads the plugin into memory using NSPR's shared-library loading mechanism.

Handles platform differences in loading shared libraries.

Definition at line 142 of file nsPluginsDirBeOS.cpp.

{
        nsCAutoString path;
        nsresult rv = mPlugin->GetNativePath(path);
        if (NS_OK != rv) {
            return rv;
        }
        pLibrary = outLibrary = PR_LoadLibrary(path.get());

#ifdef NS_DEBUG
        printf("LoadPlugin() %s returned %lx\n",path,(unsigned long)pLibrary);
#endif

        return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 295 of file nsPluginsDirDarwin.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 82 of file nsPluginsDir.h.

Definition at line 81 of file nsPluginsDir.h.


The documentation for this class was generated from the following files: