Make Integration of mozilla and Java Plugin be better
This commit is contained in:
Родитель
76652928b5
Коммит
ed7f7aa45d
|
@ -98,6 +98,11 @@ pref("helpers.global_mime_types_file", "/etc/mime.types");
|
|||
pref("helpers.global_mailcap_file", "/etc/mailcap");
|
||||
pref("helpers.private_mime_types_file", "~/.mime.types");
|
||||
pref("helpers.private_mailcap_file", "~/.mailcap");
|
||||
pref("java.global_java_version_file", "/etc/.java/versions");
|
||||
pref("java.private_java_version_file", "~/.java/versions");
|
||||
pref("java.default_java_location_solaris", "/usr/j2se");
|
||||
pref("java.default_java_location_others", "/usr/java");
|
||||
pref("java.java_plugin_library_name", "javaplugin_oji");
|
||||
pref("applications.telnet", "xterm -e telnet %h %p");
|
||||
pref("applications.tn3270", "xterm -e tn3270 %h");
|
||||
pref("applications.rlogin", "xterm -e rlogin %h");
|
||||
|
|
|
@ -33,6 +33,7 @@ XPIDLSRCS = \
|
|||
nsIJVMManager.idl \
|
||||
nsIJVMPluginInstance.idl \
|
||||
nsIJVMAuthTools.idl \
|
||||
nsIJVMConfigManager.idl \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2003
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pete Zha <pete.zha@sun.com> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIArray.idl"
|
||||
#include "nsIFile.idl"
|
||||
|
||||
%{C++
|
||||
#define NS_JVMCONFIGMANAGER_CID \
|
||||
{ /* 4a68cee9-6f07-4950-b441-a1ce6a082e2f */ \
|
||||
0x4a68cee9, \
|
||||
0x6f07, \
|
||||
0x4950, \
|
||||
{0xb4, 0x41, 0xa1, 0xce, 0x6a, 0x08, 0x2e, 0x2f} \
|
||||
}
|
||||
%}
|
||||
/**
|
||||
* This interface contains information for the Java installation.
|
||||
*/
|
||||
[scriptable, uuid(3e333e20-b190-42d8-b993-d5fa435e46c4)]
|
||||
interface nsIJVMConfig : nsISupports {
|
||||
readonly attribute AString version;
|
||||
readonly attribute AString type;
|
||||
readonly attribute AString OS;
|
||||
readonly attribute AString arch;
|
||||
readonly attribute nsIFile path;
|
||||
readonly attribute nsIFile mozillaPluginPath;
|
||||
readonly attribute AString description;
|
||||
};
|
||||
|
||||
/**
|
||||
* This interface is a manager that can get information about Java
|
||||
* installations.
|
||||
*/
|
||||
[scriptable, uuid(ca29fff1-a677-493c-9d80-3dc60432212b)]
|
||||
interface nsIJVMConfigManager : nsISupports {
|
||||
/**
|
||||
* This function returns a list of existing Java installations.
|
||||
*/
|
||||
nsIArray getJVMConfigList();
|
||||
|
||||
/**
|
||||
* This function tells the browser to use a specific Java installation.
|
||||
*/
|
||||
void setCurrentJVMConfig(in nsIJVMConfig jvmConfig);
|
||||
};
|
||||
|
|
@ -70,10 +70,17 @@ CPPSRCS = \
|
|||
ProxyClassLoader.cpp \
|
||||
nsCSecurityContext.cpp \
|
||||
nsCJVMManagerFactory.cpp \
|
||||
nsJVMConfigManager.cpp \
|
||||
lcglue.cpp \
|
||||
nsJVMAuthTools.cpp \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(TARGET_MD_ARCH), unix)
|
||||
CPPSRCS += \
|
||||
nsJVMConfigManagerUnix.cpp \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
EXPORTS = \
|
||||
jvmmgr.h \
|
||||
nsJVMManager.h \
|
||||
|
|
|
@ -40,12 +40,20 @@
|
|||
#include "nsIGenericFactory.h"
|
||||
#include "nsJVMAuthTools.h"
|
||||
#include "nsJVMManager.h"
|
||||
#include "nsJVMConfigManager.h"
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#include "nsJVMConfigManagerUnix.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Note: In revision 1.17 of this file (and earlier) there was a
|
||||
* commented out implementation of nsCJVMManagerFactory, a hand-crafted
|
||||
* implementation of nsIFactory.
|
||||
*/
|
||||
#ifdef XP_UNIX
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsJVMConfigManagerUnix)
|
||||
#endif
|
||||
|
||||
// The list of components we register
|
||||
static const nsModuleComponentInfo components[] =
|
||||
|
@ -61,6 +69,13 @@ static const nsModuleComponentInfo components[] =
|
|||
"@mozilla.org/oji/jvm-auth-tools;1",
|
||||
nsJVMAuthTools::Create
|
||||
},
|
||||
#ifdef XP_UNIX
|
||||
{ "JVM Config Manager",
|
||||
NS_JVMCONFIGMANAGER_CID,
|
||||
"@mozilla.org/oji/jvm-config-mgr;1",
|
||||
nsJVMConfigManagerUnixConstructor
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE(nsCJVMManagerModule, components);
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2003
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pete Zha <pete.zha@sun.com> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsJVMConfigManager.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsJVMConfig, nsIJVMConfig)
|
||||
|
||||
nsJVMConfig::nsJVMConfig(const nsAString& aVersion, const nsAString& aType,
|
||||
const nsAString& aOS, const nsAString& aArch,
|
||||
nsIFile* aPath, nsIFile* aMozillaPluginPath,
|
||||
const nsAString& aDescription) :
|
||||
mVersion(aVersion),
|
||||
mType(aType),
|
||||
mOS(aOS),
|
||||
mArch(aArch),
|
||||
mPath(aPath),
|
||||
mMozillaPluginPath(aMozillaPluginPath),
|
||||
mDescription(aDescription)
|
||||
{
|
||||
}
|
||||
|
||||
nsJVMConfig::~nsJVMConfig()
|
||||
{
|
||||
}
|
||||
|
||||
/* readonly attribute AString version; */
|
||||
NS_IMETHODIMP
|
||||
nsJVMConfig::GetVersion(nsAString & aVersion)
|
||||
{
|
||||
aVersion = mVersion;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute AString type; */
|
||||
NS_IMETHODIMP
|
||||
nsJVMConfig::GetType(nsAString & aType)
|
||||
{
|
||||
aType = mType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute AString os; */
|
||||
NS_IMETHODIMP
|
||||
nsJVMConfig::GetOS(nsAString & aOS)
|
||||
{
|
||||
aOS = mOS;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute AString arch; */
|
||||
NS_IMETHODIMP
|
||||
nsJVMConfig::GetArch(nsAString & aArch)
|
||||
{
|
||||
aArch = mArch;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJVMConfig::GetPath(nsIFile** aPath)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aPath);
|
||||
|
||||
*aPath = mPath;
|
||||
NS_IF_ADDREF(*aPath);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJVMConfig::GetMozillaPluginPath(nsIFile** aMozillaPluginPath)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aMozillaPluginPath);
|
||||
|
||||
*aMozillaPluginPath = mMozillaPluginPath;
|
||||
NS_IF_ADDREF(*aMozillaPluginPath);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute AString description; */
|
||||
NS_IMETHODIMP
|
||||
nsJVMConfig::GetDescription(nsAString & aDescription)
|
||||
{
|
||||
aDescription = mDescription;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2003
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pete Zha <pete.zha@sun.com> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsJVMConfigManager_h___
|
||||
#define nsJVMConfigManager_h___
|
||||
|
||||
#include "nsIJVMConfigManager.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIFile.h"
|
||||
|
||||
class nsJVMConfig : public nsIJVMConfig
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIJVMCONFIG
|
||||
|
||||
nsJVMConfig(const nsAString& aVersion, const nsAString& aType,
|
||||
const nsAString& aOS, const nsAString& aArch,
|
||||
nsIFile* aPath, nsIFile* aMozillaPluginPath,
|
||||
const nsAString& aDescription);
|
||||
|
||||
virtual ~nsJVMConfig();
|
||||
/* additional members */
|
||||
protected:
|
||||
nsString mVersion;
|
||||
nsString mType;
|
||||
nsString mOS;
|
||||
nsString mArch;
|
||||
nsCOMPtr<nsIFile> mPath;
|
||||
nsCOMPtr<nsIFile> mMozillaPluginPath;
|
||||
nsString mDescription;
|
||||
};
|
||||
|
||||
#endif // nsJVMConfigManager_h___
|
|
@ -0,0 +1,663 @@
|
|||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2003
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pete Zha <pete.zha@sun.com> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "nsJVMConfigManagerUnix.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "prprf.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsIHttpProtocolHandler.h"
|
||||
#include "nsIVariant.h"
|
||||
#include "nsISimpleEnumerator.h"
|
||||
#include <stdio.h> /* OSF/1 requires this before grp.h, so put it first */
|
||||
#include <unistd.h>
|
||||
|
||||
#define NS_COMPILER_GNUC3 defined(__GXX_ABI_VERSION) && \
|
||||
(__GXX_ABI_VERSION >= 102) /* G++ V3 ABI */
|
||||
|
||||
static NS_DEFINE_CID(kHttpHandlerCID, NS_HTTPPROTOCOLHANDLER_CID);
|
||||
|
||||
// Implementation of nsJVMConfigManagerUnix
|
||||
NS_IMPL_ISUPPORTS1(nsJVMConfigManagerUnix, nsIJVMConfigManager)
|
||||
|
||||
nsJVMConfigManagerUnix::nsJVMConfigManagerUnix()
|
||||
{
|
||||
InitJVMConfigList();
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(PRBool)
|
||||
FreeJVMConfig(nsHashKey *aKey, void *aData, void* aClosure)
|
||||
{
|
||||
nsJVMConfig* config = NS_STATIC_CAST(nsJVMConfig *, aData);
|
||||
|
||||
NS_IF_RELEASE(config);
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(PRBool)
|
||||
AppendJVMConfig(nsHashKey *aKey, void *aData, void* aClosure)
|
||||
{
|
||||
nsJVMConfig* config = NS_STATIC_CAST(nsJVMConfig *, aData);
|
||||
nsIMutableArray *array = NS_STATIC_CAST(nsIMutableArray *, aClosure);
|
||||
NS_ENSURE_TRUE(config && array, PR_FALSE);
|
||||
|
||||
array->AppendElement(config, PR_FALSE);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsJVMConfigManagerUnix::~nsJVMConfigManagerUnix()
|
||||
{
|
||||
ClearJVMConfigList();
|
||||
}
|
||||
|
||||
void
|
||||
nsJVMConfigManagerUnix::ClearJVMConfigList()
|
||||
{
|
||||
if (mJVMConfigList.Count() > 0) {
|
||||
mJVMConfigList.Reset(FreeJVMConfig);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJVMConfigManagerUnix::GetJVMConfigList(nsIArray **_retval)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
ClearJVMConfigList();
|
||||
InitJVMConfigList();
|
||||
|
||||
nsCOMPtr<nsIMutableArray> array;
|
||||
nsresult rv = NS_NewArray(getter_AddRefs(array));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (mJVMConfigList.Count() > 0) {
|
||||
mJVMConfigList.Enumerate(AppendJVMConfig,
|
||||
NS_STATIC_CAST(void *, array));
|
||||
*_retval = NS_STATIC_CAST(nsIArray *, array);
|
||||
NS_IF_ADDREF(*_retval);
|
||||
} else
|
||||
*_retval = nsnull;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJVMConfigManagerUnix::InitJVMConfigList()
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJVMConfigManagerUnix::SetCurrentJVMConfig(nsIJVMConfig* aJVMConfig)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aJVMConfig);
|
||||
|
||||
nsCOMPtr<nsIFile> srcFile;
|
||||
nsresult rv = aJVMConfig->GetMozillaPluginPath(getter_AddRefs(srcFile));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIFile> pluginDir;
|
||||
rv = NS_GetSpecialDirectory(NS_APP_PLUGINS_DIR, getter_AddRefs(pluginDir));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
PRBool hasPermission = PR_FALSE;
|
||||
pluginDir->IsWritable(&hasPermission);
|
||||
if (!hasPermission) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsAutoString fileName;
|
||||
srcFile->GetLeafName(fileName);
|
||||
nsCOMPtr<nsILocalFile> destFile(do_QueryInterface(pluginDir));
|
||||
if (TestExists(destFile, fileName))
|
||||
destFile->Remove(PR_FALSE);
|
||||
|
||||
nsCAutoString srcFileName;
|
||||
rv = srcFile->GetNativePath(srcFileName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCAutoString destFileName;
|
||||
destFile->GetNativePath(destFileName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
PRInt16 result = 0;
|
||||
result = symlink(srcFileName.get(), destFileName.get());
|
||||
|
||||
return result >= 0 ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJVMConfigManagerUnix::InitJVMConfigList(nsILineInputStream* aGlobal,
|
||||
nsILineInputStream* aPrivate)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJVMConfigManagerUnix::GetLineInputStream(nsIFile* aFile,
|
||||
nsILineInputStream** _retval)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJVMConfigManagerUnix::ParseStream(nsILineInputStream* aStream)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aStream);
|
||||
|
||||
PRBool notEOF = PR_TRUE;
|
||||
|
||||
nsAutoString lineBuffer;
|
||||
do {
|
||||
nsAutoString line;
|
||||
nsresult rv = aStream->ReadLine(line, ¬EOF);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJVMConfigManagerUnix::ParseLine(nsAString& aLine)
|
||||
{
|
||||
#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.Equals(NS_LITERAL_STRING("jdk")))
|
||||
testPathStr.Append(NS_LITERAL_STRING("/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;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJVMConfigManagerUnix::GetMozillaPluginPath(nsAString& aLine,
|
||||
nsAString& _retval)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJVMConfigManagerUnix::GetAgentVersion(nsCAutoString& _retval)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJVMConfigManagerUnix::GetAgentVersion(float* _retval)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsJVMConfigManagerUnix::GetValueFromLine(nsAString& aLine, const char* aKey,
|
||||
nsAString& _retval)
|
||||
{
|
||||
_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;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJVMConfigManagerUnix::GetNSVersion(nsAString& _retval)
|
||||
{
|
||||
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.Assign(NS_LITERAL_STRING("ns7"));
|
||||
} else {
|
||||
_retval.Assign(NS_LITERAL_STRING("ns610"));
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJVMConfigManagerUnix::SearchDefault()
|
||||
{
|
||||
#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
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJVMConfigManagerUnix::SearchDirectory(nsAString& aDirName)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJVMConfigManagerUnix::AddDirectory(nsIFile* aHomeDir)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aHomeDir);
|
||||
nsAutoString homeDirName;
|
||||
aHomeDir->GetPath(homeDirName);
|
||||
return AddDirectory(homeDirName);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJVMConfigManagerUnix::AddDirectory(nsAString& aHomeDirName)
|
||||
{
|
||||
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.Assign(NS_LITERAL_STRING("jdk"));
|
||||
} else {
|
||||
type.Assign(NS_LITERAL_STRING("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, nsString(), arch, path,
|
||||
mozPluginPath, nsString());
|
||||
NS_ENSURE_TRUE(config, NS_ERROR_OUT_OF_MEMORY);
|
||||
mJVMConfigList.Put(&key, NS_STATIC_CAST(void *, config));
|
||||
NS_ADDREF(config);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsJVMConfigManagerUnix::TestArch(nsILocalFile* aPluginPath, nsAString& aArch)
|
||||
{
|
||||
#ifdef SPARC
|
||||
aArch.Assign(NS_LITERAL_STRING("sparc"));
|
||||
#else
|
||||
aArch.Assign(NS_LITERAL_STRING("i386"));
|
||||
#endif
|
||||
return TestExists(aPluginPath, aArch);
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsJVMConfigManagerUnix::TestNSVersion(nsILocalFile* aArchPath,
|
||||
nsAString& aNSVersion)
|
||||
{
|
||||
nsAutoString versionStr;
|
||||
nsresult rv = GetNSVersion(versionStr);
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
|
||||
aNSVersion.Assign(versionStr);
|
||||
#if (NS_COMPILER_GNUC3)
|
||||
aNSVersion.Append(NS_LITERAL_STRING("-gcc32"));
|
||||
#endif
|
||||
return TestExists(aArchPath, aNSVersion);
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsJVMConfigManagerUnix::TestExists(nsILocalFile* aBaseDir, nsAString& aSubName)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aBaseDir);
|
||||
|
||||
aBaseDir->Append(aSubName);
|
||||
PRBool exists;
|
||||
aBaseDir->Exists(&exists);
|
||||
|
||||
return exists;
|
||||
}
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2003
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pete Zha <pete.zha@sun.com> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsJVMConfigManagerUnix_h___
|
||||
#define nsJVMConfigManagerUnix_h___
|
||||
|
||||
#include "nsJVMConfigManager.h"
|
||||
#include "nsString.h"
|
||||
#include "nsILineInputStream.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsIFileStreams.h"
|
||||
#include "nsArray.h"
|
||||
|
||||
class nsJVMConfigManagerUnix : public nsIJVMConfigManager
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIJVMCONFIGMANAGER
|
||||
|
||||
nsJVMConfigManagerUnix();
|
||||
virtual ~nsJVMConfigManagerUnix();
|
||||
|
||||
protected:
|
||||
nsresult InitJVMConfigList();
|
||||
|
||||
void ClearJVMConfigList();
|
||||
|
||||
nsresult InitJVMConfigList(nsILineInputStream* aGlobal,
|
||||
nsILineInputStream* aPrivate);
|
||||
|
||||
/**
|
||||
* Parse a stream for information about Java installation(s).
|
||||
*/
|
||||
nsresult ParseStream(nsILineInputStream* aStream);
|
||||
|
||||
/**
|
||||
* 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 | ......"
|
||||
*/
|
||||
|
||||
nsresult ParseLine(nsAString& aLine);
|
||||
|
||||
/**
|
||||
* Search for Java installations in the default location.
|
||||
*/
|
||||
nsresult SearchDefault();
|
||||
|
||||
/**
|
||||
* Search a specific directory to see if there are Java installations.
|
||||
*/
|
||||
nsresult SearchDirectory(nsAString& aDirName);
|
||||
|
||||
/**
|
||||
* Add a directory to the Java configuration list if
|
||||
* it contains a java installation.
|
||||
*/
|
||||
nsresult AddDirectory(nsIFile* aHomeDir);
|
||||
|
||||
nsresult AddDirectory(nsAString& aHomeDirName);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
static PRBool GetValueFromLine(nsAString& aLine, const char* aKey,
|
||||
nsAString& _retval);
|
||||
|
||||
static nsresult GetLineInputStream(nsIFile* aFile,
|
||||
nsILineInputStream** _retval);
|
||||
|
||||
/**
|
||||
* Get value of mozilla<version>.plugin.path from a line
|
||||
*/
|
||||
static nsresult GetMozillaPluginPath(nsAString& aLine, nsAString& _retval);
|
||||
|
||||
/**
|
||||
* Get agent version by string
|
||||
*/
|
||||
static nsresult GetAgentVersion(nsCAutoString& _retval);
|
||||
|
||||
/**
|
||||
* Get agent version by float
|
||||
*/
|
||||
static nsresult GetAgentVersion(float* _retval);
|
||||
|
||||
static nsresult GetNSVersion(nsAString& _retval);
|
||||
|
||||
/**
|
||||
* Check for existing arch directory.
|
||||
*/
|
||||
static PRBool TestArch(nsILocalFile* aPluginPath, nsAString& aArch);
|
||||
|
||||
/**
|
||||
* Check for existing NS version directory.
|
||||
*/
|
||||
static PRBool TestNSVersion(nsILocalFile* aArchPath, nsAString& aNSVersion);
|
||||
|
||||
/**
|
||||
* Test if a specific node in the base directory exists.
|
||||
*/
|
||||
static PRBool TestExists(nsILocalFile* aBaseDir, nsAString& aSubName);
|
||||
|
||||
/**
|
||||
* The table to store the config list.
|
||||
*/
|
||||
nsHashtable mJVMConfigList;
|
||||
};
|
||||
|
||||
#endif // nsJVMConfigManagerUnix_h___
|
|
@ -41,6 +41,7 @@
|
|||
ftpCheck(false);
|
||||
turboCheck();
|
||||
sysPrefCheck();
|
||||
initJVMConfigList();
|
||||
}
|
||||
|
||||
function ftpCheck(setFocus) {
|
||||
|
@ -161,7 +162,8 @@
|
|||
<caption label="&advancedTitle.label;"/>
|
||||
<vbox align="start" id="contentEnablingBox">
|
||||
<checkbox id="advancedJavaAllow" label="&enbJavaCheck.label;" accesskey="&enbJavaCheck.accesskey;"
|
||||
prefstring="security.enable_java"/>
|
||||
prefstring="security.enable_java"
|
||||
oncommand="javaCheck(true)"/>
|
||||
</vbox>
|
||||
<vbox>
|
||||
<vbox align="start">
|
||||
|
@ -177,6 +179,187 @@
|
|||
</vbox>
|
||||
<separator/>
|
||||
</groupbox>
|
||||
|
||||
<script type="application/x-javascript">
|
||||
<![CDATA[
|
||||
function javaCheck(setFocus) {
|
||||
if (!jvmConfigList) return;
|
||||
var checked = document.getElementById("advancedJavaAllow").checked;
|
||||
setVisible(checked);
|
||||
}
|
||||
|
||||
const nsIJVMConfig = Components.interfaces.nsIJVMConfig;
|
||||
const jvmConfigMgr = getJVMConfigMgr();
|
||||
const jvmConfigList = getJVMConfigList();
|
||||
const currentJVMPluginPath = getCurrentJVMPluginPath();
|
||||
var oldJVMConfig = null;
|
||||
|
||||
function getJVMConfigMgr() {
|
||||
return Components.classes["@mozilla.org/oji/jvm-config-mgr;1"]
|
||||
.getService(Components.interfaces.nsIJVMConfigManager);
|
||||
}
|
||||
|
||||
function getJVMConfigList() {
|
||||
if (!jvmConfigMgr)
|
||||
jvmConfigMgr = getJVMConfigMgr();
|
||||
|
||||
if (jvmConfigMgr)
|
||||
return jvmConfigMgr.getJVMConfigList();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getCurrentJVMPluginPath() {
|
||||
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
|
||||
if (prefs) {
|
||||
// Since we don't have a fullPath attribute in nsIDOMPlugin,
|
||||
// we have to set the set pref "plugin.expose_full_path"
|
||||
// to true and then get it. Related bug is 204476
|
||||
var oldValue = prefs.getBoolPref("plugin.expose_full_path");
|
||||
if (!oldValue)
|
||||
prefs.setBoolPref("plugin.expose_full_path", true);
|
||||
|
||||
var result;
|
||||
try {
|
||||
result = navigator.mimeTypes["application/x-java-vm"]
|
||||
.enabledPlugin.filename;
|
||||
} catch (e) { result = ""; };
|
||||
|
||||
// Set the pref to original value.
|
||||
if (!oldValue)
|
||||
prefs.setBoolPref("plugin.expose_full_path", oldValue);
|
||||
return result;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
const jvmConfigListView = {
|
||||
currentJVMConfig : null,
|
||||
|
||||
rowCount : 0,
|
||||
|
||||
setTree : function(tree) {},
|
||||
getImageSrc : function(row, column) {},
|
||||
getProgressMode : function(row, column) {},
|
||||
getCellValue : function(row, column) {},
|
||||
isSeparator : function(index) {return false;},
|
||||
isSorted: function() { return false; },
|
||||
isContainer : function(index) {return false;},
|
||||
cycleHeader : function(aColId, aElt) {},
|
||||
getRowProperties : function(row, column, prop) {},
|
||||
getColumnProperties : function(column, columnElement, prop) {},
|
||||
getCellProperties : function(row, prop) {},
|
||||
|
||||
getCellText : function(row,column) {
|
||||
if (jvmConfigList) {
|
||||
var jvmConfig = jvmConfigList.queryElementAt(row, nsIJVMConfig);
|
||||
if (column == "name")
|
||||
return jvmConfig.version;
|
||||
if (column == "home")
|
||||
return jvmConfig.path.path;
|
||||
}
|
||||
return "";
|
||||
},
|
||||
|
||||
refresh : function(jvmConfigListObj) {
|
||||
if (jvmConfigList) {
|
||||
this.rowCount = jvmConfigList.length;
|
||||
var currentIndex = -1;
|
||||
for (i = 0; i < this.rowCount; i++) {
|
||||
var jvmConfig = jvmConfigList.queryElementAt(i, nsIJVMConfig)
|
||||
var jvmHome = jvmConfig.path.path;
|
||||
if (currentJVMPluginPath.indexOf(jvmHome + "/") >= 0) {
|
||||
this.currentJVMConfig = jvmConfig;
|
||||
currentIndex = i;
|
||||
}
|
||||
}
|
||||
// Only show the panel if we have the choice.
|
||||
if (jvmConfigList.length == 0 ||
|
||||
(jvmConfigList.length == 1 && currentIndex >= 0)) {
|
||||
setVisible(false);
|
||||
return;
|
||||
}
|
||||
jvmConfigListObj.treeBoxObject.view = this;
|
||||
if (currentIndex >= 0)
|
||||
jvmConfigListView.selection.select(currentIndex);
|
||||
} else {
|
||||
this.rowCount = 0;
|
||||
}
|
||||
},
|
||||
|
||||
getCurrentJVMConfig : function() {
|
||||
return this.currentJVMConfig;
|
||||
},
|
||||
};
|
||||
|
||||
function setVisible(visible) {
|
||||
var javaConfigPanel = document.getElementById("javaPluginSettings");
|
||||
javaConfigPanel.setAttribute("hidden", visible ? "" : "true");
|
||||
}
|
||||
|
||||
function initJVMConfigList() {
|
||||
var javaChecked = document.getElementById("advancedJavaAllow").checked;
|
||||
if (jvmConfigList) {
|
||||
var jvmConfigListObj = document.getElementById("jvmConfigListObj");
|
||||
if (jvmConfigListObj) {
|
||||
jvmConfigListView.refresh(jvmConfigListObj);
|
||||
oldJVMConfig = jvmConfigListView.getCurrentJVMConfig();
|
||||
parent.hPrefWindow.registerOKCallbackFunc(switchJVM);
|
||||
}
|
||||
if (!javaChecked) setVisible(false);
|
||||
} else {
|
||||
setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
function switchJVM() {
|
||||
var currentIndex = jvmConfigListView.selection.currentIndex;
|
||||
if (currentIndex >= 0 && jvmConfigMgr && jvmConfigList) {
|
||||
var currentJVMConfig =
|
||||
jvmConfigList.queryElementAt(currentIndex, nsIJVMConfig);
|
||||
if (currentJVMConfig && currentJVMConfig != oldJVMConfig) {
|
||||
var promptService =
|
||||
Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
|
||||
.getService(Components.interfaces.nsIPromptService);
|
||||
|
||||
var navbundle = document.getElementById("navBundle");
|
||||
var brandbundle = document.getElementById("brandBundle");
|
||||
var dialogTitle = navbundle.getString("switchJVMTitle");
|
||||
|
||||
try {
|
||||
jvmConfigMgr.setCurrentJVMConfig(currentJVMConfig);
|
||||
} catch (e) {
|
||||
errorMsg = navbundle.getString("switchJVMFailed");
|
||||
promptService.alert(window, dialogTitle, errorMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
oldJVMConfig = currentJVMConfig;
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</script>
|
||||
<stringbundle id="navBundle"
|
||||
src="chrome://navigator/locale/navigator.properties"/>
|
||||
<stringbundle id="brandBundle"
|
||||
src="chrome://global/locale/brand.properties"/>
|
||||
<groupbox id="javaPluginSettings" align="start">
|
||||
<caption label="&jvm.configuration;"/>
|
||||
<tree id="jvmConfigListObj" style="width: 60em; height: 10em"
|
||||
hidecolumnpicker="true">
|
||||
<treecols>
|
||||
<treecol id="name" label="&jvm.name;" flex="2"/>
|
||||
<splitter class="tree-splitter"/>
|
||||
<treecol id="home" label="&jvm.home;" flex="13"/>
|
||||
</treecols>
|
||||
<treechildren/>
|
||||
</tree>
|
||||
</groupbox>
|
||||
|
||||
<groupbox id="perfSettings">
|
||||
<caption id="perfLabel" label="&perfTitle.label;"/>
|
||||
<vbox id="perfBox" align="start">
|
||||
|
|
Загрузка…
Ссылка в новой задаче