Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes
nsJVMConfigManagerUnix Class Reference

#include <nsJVMConfigManagerUnix.h>

Inheritance diagram for nsJVMConfigManagerUnix:
Inheritance graph
[legend]
Collaboration diagram for nsJVMConfigManagerUnix:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIJVMCONFIGMANAGER 
nsJVMConfigManagerUnix ()
virtual ~nsJVMConfigManagerUnix ()
nsIArray getJVMConfigList ()
 This function returns a list of existing Java installations.
void setCurrentJVMConfig (in nsIJVMConfig jvmConfig)
 This function tells the browser to use a specific Java installation.

Protected Member Functions

nsresult InitJVMConfigList ()
void ClearJVMConfigList ()
nsresult InitJVMConfigList (nsILineInputStream *aGlobal, nsILineInputStream *aPrivate)
nsresult ParseStream (nsILineInputStream *aStream)
 Parse a stream for information about Java installation(s).
nsresult ParseLine (nsAString &aLine)
 Parse a line for information about a Java installation, and ensure its JVMConfig is in our JVMConfigList.
nsresult SearchDefault ()
 Search for Java installations in the default location.
nsresult SearchDirectory (nsAString &aDirName)
 Search a specific directory to see if there are Java installations.
nsresult AddDirectory (nsIFile *aHomeDir)
 Add a directory to the Java configuration list if it contains a java installation.
nsresult AddDirectory (nsAString &aHomeDirName)

Static Protected Member Functions

static PRBool GetValueFromLine (nsAString &aLine, const char *aKey, nsAString &_retval)
 Get a value by specific key from the line.
static nsresult GetLineInputStream (nsIFile *aFile, nsILineInputStream **_retval)
static nsresult GetMozillaPluginPath (nsAString &aLine, nsAString &_retval)
 Get value of mozilla<version>.plugin.path from a line.
static nsresult GetAgentVersion (nsCAutoString &_retval)
 Get agent version by string.
static nsresult GetAgentVersion (float *_retval)
 Get agent version by float.
static nsresult GetNSVersion (nsAString &_retval)
static PRBool TestArch (nsILocalFile *aPluginPath, nsAString &aArch)
 Check for existing arch directory.
static PRBool TestNSVersion (nsILocalFile *aArchPath, nsAString &aNSVersion)
 Check for existing NS version directory.
static PRBool TestExists (nsILocalFile *aBaseDir, nsAString &aSubName)
 Test if a specific node in the base directory exists.

Protected Attributes

nsHashtable mJVMConfigList
 The table to store the config list.

Detailed Description

Definition at line 50 of file nsJVMConfigManagerUnix.h.


Constructor & Destructor Documentation

Definition at line 61 of file nsJVMConfigManagerUnix.cpp.

Definition at line 87 of file nsJVMConfigManagerUnix.cpp.

Here is the call graph for this function:


Member Function Documentation

Add a directory to the Java configuration list if it contains a java installation.

Definition at line 544 of file nsJVMConfigManagerUnix.cpp.

{
    NS_ENSURE_ARG_POINTER(aHomeDir);
    nsAutoString homeDirName;
    aHomeDir->GetPath(homeDirName);
    return AddDirectory(homeDirName);
}

Here is the caller graph for this function:

nsresult nsJVMConfigManagerUnix::AddDirectory ( nsAString &  aHomeDirName) [protected]

Definition at line 553 of file nsJVMConfigManagerUnix.cpp.

{
    nsresult rv = NS_OK;

    nsAutoString type;
    nsAutoString mozillaPluginPath;

    nsCOMPtr<nsILocalFile>
        testPath(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    testPath->InitWithPath(aHomeDirName);
    testPath->Append(NS_LITERAL_STRING("jre"));

    PRBool exists;
    testPath->Exists(&exists);
    if (exists) {
        type.AssignLiteral("jdk");
    } else {
        type.AssignLiteral("jre");
        testPath->InitWithPath(aHomeDirName);
    }

    testPath->Append(NS_LITERAL_STRING("plugin"));

    // Get Arch. "sparc" or "i386"
    nsAutoString arch;
    NS_ENSURE_TRUE(TestArch(testPath, arch), NS_OK);

    // Get NS Version. "ns610" or "ns7"
    nsAutoString nsVersion;
    NS_ENSURE_TRUE(TestNSVersion(testPath, nsVersion), NS_OK);

    nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
    NS_ENSURE_TRUE(prefs, NS_ERROR_FAILURE);

    nsCAutoString javaLibName("java.java_plugin_library_name");
    nsXPIDLCString javaLibNameXPIDLValue;
    prefs->GetCharPref(javaLibName.get(),
                        getter_Copies(javaLibNameXPIDLValue));

    char* temp = PR_GetLibraryName(nsnull, javaLibNameXPIDLValue.get());
    nsCAutoString pluginFileName(temp);
    testPath->AppendNative(pluginFileName);
    PR_FreeLibraryName(temp);

    // If the plugin file doesn't exist, we just return NS_OK
    testPath->Exists(&exists);
    NS_ENSURE_TRUE(exists, NS_OK);

    nsCOMPtr<nsIFile> mozPluginPath(do_QueryInterface(testPath, &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsILocalFile>
        path(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
    NS_ENSURE_SUCCESS(rv, rv);
    path->InitWithPath(aHomeDirName);

    nsAutoString version;
    path->GetLeafName(version);

    nsStringKey key(aHomeDirName);
    nsJVMConfig* config = NS_STATIC_CAST(nsJVMConfig *,
                                         mJVMConfigList.Get(&key));
    if (!config) {
        config = new nsJVMConfig(version, type, EmptyString(), arch, path,
                                 mozPluginPath, EmptyString());
        NS_ENSURE_TRUE(config, NS_ERROR_OUT_OF_MEMORY);
        mJVMConfigList.Put(&key, NS_STATIC_CAST(void *, config));
        NS_ADDREF(config);
    }

    return NS_OK;
}

Here is the call graph for this function:

Definition at line 93 of file nsJVMConfigManagerUnix.cpp.

{
    if (mJVMConfigList.Count() > 0) {
        mJVMConfigList.Reset(FreeJVMConfig);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Get agent version by string.

Definition at line 392 of file nsJVMConfigManagerUnix.cpp.

{
    nsresult rv = NS_OK;

    nsCOMPtr<nsIHttpProtocolHandler> http = do_GetService(kHttpHandlerCID, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCAutoString userAgent;
    rv = http->GetUserAgent(userAgent);
    NS_ENSURE_SUCCESS(rv, rv);
    PRInt32 rvOffset = userAgent.Find("rv:");

    if (rvOffset != kNotFound)
        _retval.Assign(Substring(userAgent, rvOffset + 3, 3));

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsJVMConfigManagerUnix::GetAgentVersion ( float *  _retval) [static, protected]

Get agent version by float.

Definition at line 411 of file nsJVMConfigManagerUnix.cpp.

{
    NS_ENSURE_ARG_POINTER(_retval);
    nsresult rv = NS_OK;

    nsCAutoString agentVersion;
    GetAgentVersion(agentVersion);
    nsCOMPtr <nsIWritableVariant> p =
        do_CreateInstance(NS_VARIANT_CONTRACTID, &rv);
    NS_ENSURE_SUCCESS(rv, rv);
    
    rv = p->SetAsACString(agentVersion);
    NS_ENSURE_SUCCESS(rv, rv);

    return p->GetAsFloat(_retval);
}

Here is the call graph for this function:

This function returns a list of existing Java installations.

nsresult nsJVMConfigManagerUnix::GetLineInputStream ( nsIFile aFile,
nsILineInputStream **  _retval 
) [static, protected]

Definition at line 213 of file nsJVMConfigManagerUnix.cpp.

{
    NS_ENSURE_ARG_POINTER(_retval);
    
    nsresult rv = NS_OK;
    
    nsCOMPtr<nsILocalFile> file(do_QueryInterface(aFile, &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIFileInputStream>
        fileStream(do_CreateInstance(NS_LOCALFILEINPUTSTREAM_CONTRACTID, &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    rv = fileStream->Init(file, -1, -1, PR_FALSE);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsILineInputStream> lineStream(do_QueryInterface(fileStream, &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    *_retval = lineStream;
    NS_IF_ADDREF(*_retval);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsJVMConfigManagerUnix::GetMozillaPluginPath ( nsAString &  aLine,
nsAString &  _retval 
) [static, protected]

Get value of mozilla<version>.plugin.path from a line.

Definition at line 357 of file nsJVMConfigManagerUnix.cpp.

{
    nsCAutoString agentVersion;
    nsresult rv = GetAgentVersion(agentVersion);
    NS_ENSURE_SUCCESS(rv, rv);

    // Get mozilla plugin path from key
    // mozilla<version>.plugin.path
    // <version> should like this: "1.2", "1.3"
    nsCAutoString key("mozilla");
    key.Append(agentVersion);
    key.Append(".plugin.path");

    GetValueFromLine(aLine, key.get(), _retval);

    if (!_retval.IsEmpty()) return NS_OK;

    nsAutoString versionStr;
    rv = GetNSVersion(versionStr);
    NS_ENSURE_SUCCESS(rv, rv);

    key.AssignWithConversion(versionStr);
    key.Append(".plugin.path");

    GetValueFromLine(aLine, key.get(), _retval);

    // Fall back to use ns610.plugin.path if _retval is still empty.
    if (_retval.IsEmpty())
        GetValueFromLine(aLine, "ns610.plugin.path", _retval);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsJVMConfigManagerUnix::GetNSVersion ( nsAString &  _retval) [static, protected]

Definition at line 461 of file nsJVMConfigManagerUnix.cpp.

{
    float version;
    nsresult rv = GetAgentVersion(&version);
    NS_ENSURE_SUCCESS(rv, rv);

    // Check mozilla's version
    // ns7 is for mozilla1.3 or later
    // ns610 is for earlier version of mozilla.
    if (version >= 1.3) {
        _retval.AssignLiteral("ns7");
    } else {
        _retval.AssignLiteral("ns610");
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsJVMConfigManagerUnix::GetValueFromLine ( nsAString &  aLine,
const char *  aKey,
nsAString &  _retval 
) [static, protected]

Get a value by specific key from the line.

A line should look like this: key=value | key2=value2 | key3=value3 Please see the proposal in bug 185000 for more detail about the format.

Definition at line 429 of file nsJVMConfigManagerUnix.cpp.

{
    _retval.Truncate();

    nsAutoString line(aLine);
    // Find the offset of the given key in the line
    PRInt32 keyOffset = line.Find(aKey);

    // make sure the key exists in the line.
    NS_ENSURE_TRUE(keyOffset != kNotFound, PR_FALSE);

    // Find '=' right after the key
    PRInt32 equalsOffset = aLine.FindChar('=', keyOffset);
    NS_ENSURE_TRUE(equalsOffset != kNotFound, PR_FALSE);

    // Find '|' which is the terminal of a pair of key/value
    PRInt32 lineOffset = aLine.FindChar('|', equalsOffset);
    lineOffset = lineOffset != kNotFound ? lineOffset : aLine.Length();

    // OK, we separate the value from the line between '=' and '|'
    nsAutoString value(Substring(aLine,
                                 equalsOffset + 1,
                                 lineOffset - equalsOffset -1));

    // Removing the leading/trailing spaces
    value.Trim(" ");
    _retval = value;
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 124 of file nsJVMConfigManagerUnix.cpp.

{
    nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
    NS_ENSURE_TRUE(prefs, NS_ERROR_FAILURE);

    nsCOMPtr<nsILocalFile> globalFile;
    prefs->GetComplexValue("java.global_java_version_file",
                           NS_GET_IID(nsILocalFile),
                           getter_AddRefs(globalFile));

    nsCOMPtr<nsILocalFile> privateFile;
    prefs->GetComplexValue("java.private_java_version_file",
                           NS_GET_IID(nsILocalFile),
                           getter_AddRefs(privateFile));

    nsCOMPtr<nsILineInputStream> globalStream;
    nsresult rv = GetLineInputStream(globalFile, getter_AddRefs(globalStream));
    NS_ENSURE_TRUE(NS_SUCCEEDED(rv) || rv == NS_ERROR_FILE_NOT_FOUND, rv);

    nsCOMPtr<nsILineInputStream> privateStream;
    rv = GetLineInputStream(privateFile, getter_AddRefs(privateStream));
    NS_ENSURE_TRUE(NS_SUCCEEDED(rv) || rv == NS_ERROR_FILE_NOT_FOUND, rv);

    rv = InitJVMConfigList(globalStream, privateStream);
    NS_ENSURE_SUCCESS(rv, rv);

    // Search for a Java installation in the default install location.
    return SearchDefault();
}

Here is the call graph for this function:

Definition at line 194 of file nsJVMConfigManagerUnix.cpp.

{
    nsresult rv = NS_OK;

    if (aGlobal) {
        rv = ParseStream(aGlobal);
        NS_ENSURE_SUCCESS(rv, rv);
    }

    if (aPrivate) {
        rv = ParseStream(aPrivate);
        NS_ENSURE_SUCCESS(rv, rv);
    }

    return NS_OK;
}

Here is the call graph for this function:

nsresult nsJVMConfigManagerUnix::ParseLine ( nsAString &  aLine) [protected]

Parse a line for information about a Java installation, and ensure its JVMConfig is in our JVMConfigList.

" A line looks like this: "version=1.4.2 | type=jre | os=linux | arch=i386 | ......"

Definition at line 279 of file nsJVMConfigManagerUnix.cpp.

{
#if (NS_COMPILER_GNUC3)
    nsAutoString compiler;
    GetValueFromLine(aLine, "compiler", compiler);

    NS_ENSURE_TRUE(compiler.Find("gcc32") != kNotFound, NS_OK);
#endif

    nsAutoString version;
    GetValueFromLine(aLine, "version", version);
    
    nsAutoString type;
    GetValueFromLine(aLine, "type", type);
    
    nsAutoString os;
    GetValueFromLine(aLine, "os", os);
    
    nsAutoString arch;
    GetValueFromLine(aLine, "arch", arch);
    
    nsAutoString pathStr;
    GetValueFromLine(aLine, "path", pathStr);

    nsAutoString mozillaPluginPath;
    GetMozillaPluginPath(aLine, mozillaPluginPath);

    NS_ENSURE_TRUE(!mozillaPluginPath.IsEmpty(), NS_OK);

    nsAutoString description;
    GetValueFromLine(aLine, "description", description);
    description.Trim("\"");

    // Test whether the plugin file is existing.
    nsresult rv = NS_OK;
    nsCOMPtr<nsILocalFile>
        testPath(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    nsAutoString testPathStr(pathStr);
    if (type.EqualsLiteral("jdk"))
        testPathStr.AppendLiteral("/jre");

    testPathStr.Append(mozillaPluginPath);
    testPath->InitWithPath(testPathStr);

    // If the file doesn't exists, we just return NS_OK
    PRBool exists;
    testPath->Exists(&exists);
    NS_ENSURE_TRUE(exists, NS_OK);

    nsCOMPtr<nsIFile> mozPluginPath(do_QueryInterface(testPath, &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsILocalFile>
        path(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
    path->InitWithPath(pathStr);

    // We use java home as the key because one home
    // will contain only one java installation.
    // This could make sure we don't duplicate the config info in the list
    nsStringKey key(pathStr);
    nsJVMConfig* config = NS_STATIC_CAST(nsJVMConfig *,
                                         mJVMConfigList.Get(&key));

    // Only create it and add the config to list if it doesn't exist.
    if (!config) {
        config = new nsJVMConfig(version, type, os, arch, path,
                                 mozPluginPath, description);
        NS_ENSURE_TRUE(config, NS_ERROR_OUT_OF_MEMORY);
        mJVMConfigList.Put(&key, NS_STATIC_CAST(void *, config));
        NS_ADDREF(config);
    }
    
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Parse a stream for information about Java installation(s).

Definition at line 240 of file nsJVMConfigManagerUnix.cpp.

{
    NS_ENSURE_ARG_POINTER(aStream);

    PRBool notEOF = PR_TRUE;

    nsAutoString lineBuffer;
    do {
        nsAutoString line;
        nsCAutoString cLine;
        nsresult rv = aStream->ReadLine(cLine, &notEOF);
        NS_ENSURE_SUCCESS(rv, rv);
        CopyASCIItoUTF16(cLine, line);

        PRInt32 slashOffset, equalsOffset;
        slashOffset = line.FindChar('\\');
        equalsOffset = line.FindChar('=');

        // Since one java installation contains several key/value pair
        // and they are separeted by '\'. We need to join them together
        // to a single line and then parse it.
        if (slashOffset != kNotFound && equalsOffset != kNotFound) {
            // This means the line not finished, we need to append it to buffer
            lineBuffer.Append(Substring(line, 0, slashOffset));
        } else if (slashOffset == kNotFound && equalsOffset != kNotFound) {
            // This should the last one of a line. Append it to line
            // and then we can Parse it and get necessary information
            lineBuffer.Append(line);
            ParseLine(lineBuffer);
        } else {
            // Start of a new line
            lineBuffer.Truncate();
        }
    } while (notEOF);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Search for Java installations in the default location.

Definition at line 480 of file nsJVMConfigManagerUnix.cpp.

{
#ifdef SPARC
    const char* defaultLocationName = "java.default_java_location_solaris";
#else
    const char* defaultLocationName = "java.default_java_location_others";
#endif

    nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
    NS_ENSURE_TRUE(prefs, NS_ERROR_FAILURE);

    nsXPIDLCString defaultLocationXPIDLValue;
    prefs->GetCharPref(defaultLocationName,
                       getter_Copies(defaultLocationXPIDLValue));

    NS_ConvertUTF8toUCS2 defaultLocation(defaultLocationXPIDLValue);

#ifdef SPARC
    // On Solaris, the default location is the java home
    return AddDirectory(defaultLocation);
#else
    // On Linux and other platform,
    // the default location can contain multiple java installations
    return SearchDirectory(defaultLocation);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsJVMConfigManagerUnix::SearchDirectory ( nsAString &  aDirName) [protected]

Search a specific directory to see if there are Java installations.

Definition at line 508 of file nsJVMConfigManagerUnix.cpp.

{
    nsresult rv = NS_OK;

    nsCOMPtr<nsILocalFile>
        localDir(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    rv = localDir->InitWithPath(aDirName);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIFile> dir(do_QueryInterface(localDir, &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsISimpleEnumerator> entries;
    rv = dir->GetDirectoryEntries(getter_AddRefs(entries));
    NS_ENSURE_SUCCESS(rv, rv);

    PRBool hasMoreElements;
    entries->HasMoreElements(&hasMoreElements);
    while (hasMoreElements) {
        nsCOMPtr<nsISupports> next;
        rv = entries->GetNext(getter_AddRefs(next));
        NS_ENSURE_SUCCESS(rv, rv);

        nsCOMPtr<nsIFile> entry(do_QueryInterface(next, &rv));
        NS_ENSURE_SUCCESS(rv, rv);

        AddDirectory(entry);
        entries->HasMoreElements(&hasMoreElements);
    }
    
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

This function tells the browser to use a specific Java installation.

PRBool nsJVMConfigManagerUnix::TestArch ( nsILocalFile aPluginPath,
nsAString &  aArch 
) [static, protected]

Check for existing arch directory.

Definition at line 629 of file nsJVMConfigManagerUnix.cpp.

{
#ifdef SPARC
    aArch.AssignLiteral("sparc");
#else
    aArch.AssignLiteral("i386");
#endif
    return TestExists(aPluginPath, aArch);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsJVMConfigManagerUnix::TestExists ( nsILocalFile aBaseDir,
nsAString &  aSubName 
) [static, protected]

Test if a specific node in the base directory exists.

Definition at line 655 of file nsJVMConfigManagerUnix.cpp.

{
    NS_ENSURE_ARG_POINTER(aBaseDir);

    aBaseDir->Append(aSubName);
    PRBool exists;
    aBaseDir->Exists(&exists);

    return exists;
}

Here is the caller graph for this function:

PRBool nsJVMConfigManagerUnix::TestNSVersion ( nsILocalFile aArchPath,
nsAString &  aNSVersion 
) [static, protected]

Check for existing NS version directory.

Definition at line 640 of file nsJVMConfigManagerUnix.cpp.

{
    nsAutoString versionStr;
    nsresult rv = GetNSVersion(versionStr);
    NS_ENSURE_SUCCESS(rv, PR_FALSE);

    aNSVersion.Assign(versionStr);
#if (NS_COMPILER_GNUC3)
    aNSVersion.AppendLiteral("-gcc32");
#endif
    return TestExists(aArchPath, aNSVersion);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

nsHashtable nsJVMConfigManagerUnix::mJVMConfigList [protected]

The table to store the config list.

Definition at line 145 of file nsJVMConfigManagerUnix.h.


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