--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -182,18 +182,16 @@ MOZ_DIRECTX_SDK_PATH = @MOZ_DIRECTX_SDK_
MOZ_DIRECTX_SDK_CPU_SUFFIX = @MOZ_DIRECTX_SDK_CPU_SUFFIX@
MOZ_D3DX9_VERSION = @MOZ_D3DX9_VERSION@
MOZ_D3DX9_CAB = @MOZ_D3DX9_CAB@
MOZ_D3DCOMPILER_CAB = @MOZ_D3DCOMPILER_CAB@
MOZ_D3DX9_DLL = @MOZ_D3DX9_DLL@
MOZ_D3DCOMPILER_DLL = @MOZ_D3DCOMPILER_DLL@
-MOZ_JAVAXPCOM = @MOZ_JAVAXPCOM@
-JAVA_INCLUDE_PATH="@JAVA_INCLUDE_PATH@"
JAVA="@JAVA@"
JAVAC="@JAVAC@"
JAR="@JAR@"
TAR=@TAR@
MAKENSISU=@MAKENSISU@
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -1446,23 +1446,16 @@ endif
###############################################################################
# Bunch of things that extend the 'export' rule (in order):
###############################################################################
################################################################################
# Copy each element of EXPORTS to $(DIST)/include
-ifdef MOZ_JAVAXPCOM
-ifneq ($(XPIDLSRCS),)
-$(JAVA_DIST_DIR)::
- $(NSINSTALL) -D $@
-endif
-endif
-
ifneq ($(XPI_NAME),)
$(FINAL_TARGET):
$(NSINSTALL) -D $@
export:: $(FINAL_TARGET)
endif
ifndef NO_DIST_INSTALL
@@ -1625,56 +1618,16 @@ ifndef NO_DIST_INSTALL
export-idl:: $(XPIDLSRCS) $(IDL_DIR)
$(INSTALL) $(IFLAGS1) $^
endif
endif
$(LOOP_OVER_PARALLEL_DIRS)
$(LOOP_OVER_DIRS)
$(LOOP_OVER_TOOL_DIRS)
-ifdef MOZ_JAVAXPCOM
-ifneq ($(XPIDLSRCS),)
-
-JAVA_XPIDLSRCS = $(XPIDLSRCS)
-
-# A single IDL file can contain multiple interfaces, which result in multiple
-# Java interface files. So use hidden dependency files.
-JAVADEPFILES = $(addprefix $(JAVA_GEN_DIR)/.,$(JAVA_XPIDLSRCS:.idl=.java.pp))
-
-$(JAVA_GEN_DIR):
- $(NSINSTALL) -D $@
-GARBAGE_DIRS += $(JAVA_GEN_DIR)
-
-# generate .java files into _javagen/[package name dirs]
-_JAVA_GEN_DIR = $(JAVA_GEN_DIR)/$(JAVA_IFACES_PKG_NAME)
-$(_JAVA_GEN_DIR):
- $(NSINSTALL) -D $@
-
-$(JAVA_GEN_DIR)/.%.java.pp: %.idl $(XPIDL_COMPILE) $(_JAVA_GEN_DIR)
- $(REPORT_BUILD)
- $(ELOG) $(XPIDL_COMPILE) -m java -w $(XPIDL_FLAGS) -I$(srcdir) -I$(IDL_DIR) -o $(_JAVA_GEN_DIR)/$* $(_VPATH_SRCS)
- @touch $@
-
-# "Install" generated Java interfaces. We segregate them based on the XPI_NAME.
-# If XPI_NAME is not set, install into the "default" directory.
-ifneq ($(XPI_NAME),)
-JAVA_INSTALL_DIR = $(JAVA_DIST_DIR)/$(XPI_NAME)
-else
-JAVA_INSTALL_DIR = $(JAVA_DIST_DIR)/default
-endif
-
-$(JAVA_INSTALL_DIR):
- $(NSINSTALL) -D $@
-
-export:: $(JAVA_DIST_DIR) $(JAVADEPFILES) $(JAVA_INSTALL_DIR)
- (cd $(JAVA_GEN_DIR) && tar $(TAR_CREATE_FLAGS) - .) | (cd $(JAVA_INSTALL_DIR) && tar -xf -)
-
-endif # XPIDLSRCS
-endif # MOZ_JAVAXPCOM
-
################################################################################
# Copy each element of EXTRA_COMPONENTS to $(FINAL_TARGET)/components
ifneq (,$(filter %.js,$(EXTRA_COMPONENTS) $(EXTRA_PP_COMPONENTS)))
ifeq (,$(filter %.manifest,$(EXTRA_COMPONENTS) $(EXTRA_PP_COMPONENTS)))
ifndef NO_JS_MANIFEST
$(error .js component without matching .manifest. See https://developer.mozilla.org/en/XPCOM/XPCOM_changes_in_Gecko_2.0)
endif
endif
--- a/configure.in
+++ b/configure.in
@@ -4918,21 +4918,16 @@ if test -n "$SYSTEM_HUNSPELL"; then
PKG_CHECK_MODULES(MOZ_HUNSPELL, hunspell)
fi
AC_SUBST(SYSTEM_HUNSPELL)
dnl ========================================================
dnl Java SDK support
dnl ========================================================
-JAVA_INCLUDE_PATH=
-MOZ_ARG_WITH_STRING(java-include-path,
-[ --with-java-include-path=dir
- Location of Java SDK headers],
- JAVA_INCLUDE_PATH=$withval)
JAVA_BIN_PATH=
MOZ_ARG_WITH_STRING(java-bin-path,
[ --with-java-bin-path=dir
Location of Java binaries (java, javac, jar)],
JAVA_BIN_PATH=$withval)
dnl ========================================================
@@ -4945,17 +4940,16 @@ MOZ_ARG_HEADER(Application)
BUILD_STATIC_LIBS=
ENABLE_TESTS=1
MOZ_ACTIVEX_SCRIPTING_SUPPORT=
MOZ_BRANDING_DIRECTORY=
MOZ_OFFICIAL_BRANDING=
MOZ_FEEDS=1
MOZ_INSTALLER=1
-MOZ_JAVAXPCOM=
MOZ_JSDEBUGGER=1
MOZ_MATHML=1
MOZ_MORK=
MOZ_MORKREADER=1
MOZ_AUTH_EXTENSION=1
MOZ_NO_ACTIVEX_SUPPORT=1
MOZ_NO_FAST_LOAD=
MOZ_OGG=1
@@ -6211,80 +6205,26 @@ dnl ====================================
dnl = Universalchardet
dnl ========================================================
MOZ_ARG_DISABLE_BOOL(universalchardet,
[ --disable-universalchardet
Disable universal encoding detection],
MOZ_UNIVERSALCHARDET=,
MOZ_UNIVERSALCHARDET=1 )
-dnl ========================================================
-dnl JavaXPCOM
-dnl ========================================================
-case "${target}" in
-*-wince*)
- MOZ_JAVAXPCOM=
- ;;
-esac
-
-MOZ_ARG_ENABLE_BOOL(javaxpcom,
-[ --enable-javaxpcom
- Enable Java-XPCOM bridge],
- MOZ_JAVAXPCOM=1,
- MOZ_JAVAXPCOM=)
-
-case "$host_os" in
- *mingw*)
- if test -n "$JAVA_HOME"; then
- JAVA_HOME=`cd "$JAVA_HOME" && pwd`
- fi
- ;;
-esac
-
-if test -n "${JAVA_BIN_PATH}"; then
- dnl Look for javac and jar in the specified path.
- JAVA_PATH="$JAVA_BIN_PATH"
-else
- dnl No path specified, so look for javac and jar in $JAVA_HOME & $PATH.
- JAVA_PATH="$JAVA_HOME/bin:$PATH"
-fi
-
MOZ_PATH_PROG(JAVA, java, :, [$JAVA_PATH])
MOZ_PATH_PROG(JAVAC, javac, :, [$JAVA_PATH])
MOZ_PATH_PROG(JAR, jar, :, [$JAVA_PATH])
if test -n "${JAVA_BIN_PATH}" -o "$OS_TARGET" = Android; then
if test -z "$JAVA" -o "$JAVA" = ":" -o -z "$JAVAC" -o "$JAVAC" = ":" -o -z "$JAR" -o "$JAR" = ":"; then
AC_MSG_ERROR([The programs java, javac and jar were not found. Set \$JAVA_HOME to your java sdk directory or use --with-java-bin-path={java-bin-dir}])
fi
fi
-if test -n "${MOZ_JAVAXPCOM}"; then
- if test -n "${JAVA_INCLUDE_PATH}"; then
- dnl Make sure jni.h exists in the given include path.
- if test ! -f "$JAVA_INCLUDE_PATH/jni.h"; then
- AC_MSG_ERROR([jni.h was not found in given include path $JAVA_INCLUDE_PATH.])
- fi
- else
- case "$target_os" in
- darwin*)
- dnl Default to java system location
- JAVA_INCLUDE_PATH=/System/Library/Frameworks/JavaVM.framework/Headers
- ;;
- *)
- dnl Try $JAVA_HOME
- JAVA_INCLUDE_PATH="$JAVA_HOME/include"
- ;;
- esac
- if test ! -f "$JAVA_INCLUDE_PATH/jni.h"; then
- AC_MSG_ERROR([The header jni.h was not found. Set \$JAVA_HOME to your java sdk directory, use --with-java-bin-path={java-bin-dir}, or reconfigure with --disable-javaxpcom.])
- fi
- fi
-fi
-
dnl ========================================================
dnl = ANGLE OpenGL->D3D translator for WebGL
dnl = * only applies to win32
dnl = * enabled by default (shipping build); requires explicit --disable to disable
dnl ========================================================
MOZ_ANGLE=
MOZ_DIRECTX_SDK_PATH=
MOZ_DIRECTX_SDK_CPU_SUFFIX=
@@ -6579,21 +6519,16 @@ if test `echo "$MOZ_EXTENSIONS" | grep -
MOZ_EXTENSIONS=`echo $MOZ_EXTENSIONS | sed -e 's|pref||g'`
fi
if test `echo "$MOZ_EXTENSIONS" | grep -c universalchardet` -ne 0; then
AC_MSG_WARN([universalchardet is no longer an extension, use --disable-universalchardet to disable.])
MOZ_EXTENSIONS=`echo $MOZ_EXTENSIONS | sed -e 's|universalchardet||g'`
fi
-if test `echo "$MOZ_EXTENSIONS" | grep -c java` -ne 0; then
- AC_MSG_WARN([java is no longer an extension, use --enable-javaxpcom to enable.])
- MOZ_EXTENSIONS=`echo $MOZ_EXTENSIONS | sed -e 's|java||g'`
-fi
-
if test `echo "$MOZ_EXTENSIONS" | grep -c spellcheck` -ne 0; then
AC_MSG_WARN([spellcheck is no longer an extension.])
MOZ_EXTENSIONS=`echo $MOZ_EXTENSIONS | sed -e 's|spellcheck||g'`
fi
dnl Remove dupes
MOZ_EXTENSIONS=`${PERL} ${srcdir}/build/unix/uniq.pl ${MOZ_EXTENSIONS}`
@@ -9036,18 +8971,16 @@ AC_SUBST(MOZ_PLACES)
AC_SUBST(MOZ_PLACES_BOOKMARKS)
AC_SUBST(MOZ_STORAGE)
AC_SUBST(MOZ_TOOLKIT_SEARCH)
AC_SUBST(MOZ_FEEDS)
AC_SUBST(NS_PRINTING)
AC_SUBST(MOZ_WEBGL)
AC_SUBST(MOZ_HELP_VIEWER)
-AC_SUBST(MOZ_JAVAXPCOM)
-AC_SUBST(JAVA_INCLUDE_PATH)
AC_SUBST(JAVA)
AC_SUBST(JAVAC)
AC_SUBST(JAR)
AC_SUBST(MOZ_PROFILELOCKING)
AC_SUBST(HAVE_XIE)
AC_SUBST(MOZ_XIE_LIBS)
deleted file mode 100644
--- a/extensions/java/Makefile.in
+++ /dev/null
@@ -1,48 +0,0 @@
-# ***** 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 Java XPCOM Bindings.
-#
-# The Initial Developer of the Original Code is
-# IBM Corporation.
-# Portions created by the Initial Developer are Copyright (C) 2004
-# IBM Corporation. All Rights Reserved.
-#
-# Contributor(s):
-# Javier Pedemonte (jhpedemonte@gmail.com)
-#
-# 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 *****
-
-DEPTH = ../..
-topsrcdir = @top_srcdir@
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-include $(DEPTH)/config/autoconf.mk
-
-DIRS = xpcom
-
-include $(topsrcdir)/config/rules.mk
-
deleted file mode 100644
--- a/extensions/java/xpcom/Makefile.in
+++ /dev/null
@@ -1,57 +0,0 @@
-# ***** 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 Java XPCOM Bindings.
-#
-# The Initial Developer of the Original Code is IBM Corporation.
-# Portions created by the Initial Developer are Copyright (C) 2007
-# IBM Corporation. All Rights Reserved.
-#
-# Contributor(s):
-# Javier Pedemonte (jhpedemonte@gmail.com)
-#
-# 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 *****
-
-DEPTH = ../../..
-topsrcdir = @top_srcdir@
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-include $(DEPTH)/config/autoconf.mk
-
-DIRS = interfaces glue
-
-ifdef ENABLE_TESTS
-DIRS += tests
-endif
-
-include $(topsrcdir)/config/rules.mk
-
-# Build the implementation Java classes
-libs::
- $(MAKE) -C src jar-libs
-
-install::
- $(MAKE) -C src jar-install
deleted file mode 100644
--- a/extensions/java/xpcom/glue/Makefile.in
+++ /dev/null
@@ -1,87 +0,0 @@
-# ***** 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 Java XPCOM Bindings.
-#
-# The Initial Developer of the Original Code is
-# IBM Corporation.
-# Portions created by the Initial Developer are Copyright (C) 2005
-# IBM Corporation. All Rights Reserved.
-#
-# Contributor(s):
-# Javier Pedemonte (jhpedemonte@gmail.com)
-#
-# 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 *****
-
-DEPTH = ../../../..
-topsrcdir = @top_srcdir@
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-include $(DEPTH)/config/autoconf.mk
-
-MODULE = javaxpcomglue
-LIBRARY_NAME = javaxpcomglue
-SHORT_LIBNAME = jxpcmglu
-
-# On Mac OS X, JNI libraries must end with a '.jnilib' extension
-ifeq ($(OS_ARCH),Darwin)
-DLL_SUFFIX = .jnilib
-endif
-
-CPPSRCS = nsJavaXPCOMGlue.cpp
-
-DEFINES += -DXPCOM_GLUE
-
-
-LOCAL_INCLUDES = -I$(JAVA_INCLUDE_PATH)
-
-ifeq ($(OS_ARCH),WINNT)
-LOCAL_INCLUDES += -I$(JAVA_INCLUDE_PATH)/win32
-else
-ifeq ($(OS_ARCH),OS2)
-LOCAL_INCLUDES += -I$(JAVA_INCLUDE_PATH)/OS2
-else
-ifeq ($(OS_ARCH),FreeBSD)
-LOCAL_INCLUDES += -I$(JAVA_INCLUDE_PATH)/freebsd
-else
-LOCAL_INCLUDES += -I$(JAVA_INCLUDE_PATH)/linux
-endif
-endif
-endif
-
-LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build
-
-EXTRA_DSO_LDOPTS = \
- $(XPCOM_STANDALONE_GLUE_LDOPTS) \
- $(NULL)
-
-# Need to link with CoreFoundation on Mac
-ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
-EXTRA_DSO_LDOPTS += $(TK_LIBS)
-endif
-
-include $(topsrcdir)/config/rules.mk
-
deleted file mode 100644
--- a/extensions/java/xpcom/glue/nsJavaXPCOMGlue.cpp
+++ /dev/null
@@ -1,398 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2006
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 "jni.h"
-#include "nsXPCOMPrivate.h" // for XPCOM_DLL defines.
-#include "nsXPCOMGlue.h"
-#include "nsDebug.h"
-#include <stdlib.h>
-
-#if defined(XP_WIN) || defined(XP_OS2)
-#define JX_EXPORT JNIEXPORT
-#else
-#define JX_EXPORT JNIEXPORT NS_EXPORT
-#endif
-
-
-/***********************
- * JNI Load & Unload
- ***********************/
-
-extern "C" JX_EXPORT jint JNICALL
-JNI_OnLoad(JavaVM* vm, void* reserved)
-{
- // Let the JVM know that we are using JDK 1.2 JNI features.
- return JNI_VERSION_1_2;
-}
-
-extern "C" JX_EXPORT void JNICALL
-JNI_OnUnload(JavaVM* vm, void* reserved)
-{
-}
-
-/********************************
- * JavaXPCOM JNI interfaces
- ********************************/
-
-#define JXM_NATIVE(func) Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_##func
-
-enum {
- kFunc_Initialize,
- kFunc_InitEmbedding,
- kFunc_TermEmbedding,
- kFunc_LockProfileDirectory,
- kFunc_NotifyProfile,
- kFunc_InitXPCOM,
- kFunc_ShutdownXPCOM,
- kFunc_GetComponentManager,
- kFunc_GetComponentRegistrar,
- kFunc_GetServiceManager,
- kFunc_NewLocalFile,
- kFunc_CallXPCOMMethod,
- kFunc_FinalizeProxy,
- kFunc_IsSameXPCOMObject,
- kFunc_ReleaseProfileLock,
- kFunc_GetNativeHandleFromAWT,
- kFunc_WrapJavaObject,
- kFunc_WrapXPCOMObject
-};
-
-#define JX_NUM_FUNCS 18
-
-
-// Get path string from java.io.File object.
-jstring
-GetJavaFilePath(JNIEnv* env, jobject aFile)
-{
- jclass clazz = env->FindClass("java/io/File");
- if (clazz) {
- jmethodID pathMID = env->GetMethodID(clazz, "getCanonicalPath",
- "()Ljava/lang/String;");
- if (pathMID) {
- return (jstring) env->CallObjectMethod(aFile, pathMID);
- }
- }
-
- return nsnull;
-}
-
-// Calls XPCOMGlueStartup using the given java.io.File object, and loads
-// the JavaXPCOM methods from the XUL shared library.
-nsresult
-LoadXULMethods(JNIEnv* env, jobject aXPCOMPath, void** aFunctions)
-{
- jstring pathString = GetJavaFilePath(env, aXPCOMPath);
- if (!pathString)
- return NS_ERROR_FAILURE;
- const char* path = env->GetStringUTFChars(pathString, nsnull);
- if (!path)
- return NS_ERROR_OUT_OF_MEMORY;
-
- int len = strlen(path);
- char* xpcomPath = (char*) malloc(len + sizeof(XPCOM_DLL) +
- sizeof(XPCOM_FILE_PATH_SEPARATOR) + 1);
- if (!xpcomPath)
- return NS_ERROR_OUT_OF_MEMORY;
- sprintf(xpcomPath, "%s" XPCOM_FILE_PATH_SEPARATOR XPCOM_DLL, path);
-
- nsresult rv = XPCOMGlueStartup(xpcomPath);
- free(xpcomPath);
- if (NS_FAILED(rv))
- return rv;
-
-#ifdef XP_WIN32
- // The JNICALL calling convention defines to "__stdcall" on Win32, which
- // mangles the name.
- nsDynamicFunctionLoad funcs[] = {
- { "_Java_org_mozilla_xpcom_internal_MozillaImpl_initialize@8",
- (NSFuncPtr*) &aFunctions[kFunc_Initialize] },
- { "_Java_org_mozilla_xpcom_internal_GREImpl_initEmbedding@20",
- (NSFuncPtr*) &aFunctions[kFunc_InitEmbedding] },
- { "_Java_org_mozilla_xpcom_internal_GREImpl_termEmbedding@8",
- (NSFuncPtr*) &aFunctions[kFunc_TermEmbedding] },
- { "_Java_org_mozilla_xpcom_internal_GREImpl_lockProfileDirectory@12",
- (NSFuncPtr*) &aFunctions[kFunc_LockProfileDirectory] },
- { "_Java_org_mozilla_xpcom_internal_GREImpl_notifyProfile@8",
- (NSFuncPtr*) &aFunctions[kFunc_NotifyProfile] },
- { "_Java_org_mozilla_xpcom_internal_XPCOMImpl_initXPCOM@16",
- (NSFuncPtr*) &aFunctions[kFunc_InitXPCOM] },
- { "_Java_org_mozilla_xpcom_internal_XPCOMImpl_shutdownXPCOM@12",
- (NSFuncPtr*) &aFunctions[kFunc_ShutdownXPCOM] },
- { "_Java_org_mozilla_xpcom_internal_XPCOMImpl_getComponentManager@8",
- (NSFuncPtr*) &aFunctions[kFunc_GetComponentManager] },
- { "_Java_org_mozilla_xpcom_internal_XPCOMImpl_getComponentRegistrar@8",
- (NSFuncPtr*) &aFunctions[kFunc_GetComponentRegistrar] },
- { "_Java_org_mozilla_xpcom_internal_XPCOMImpl_getServiceManager@8",
- (NSFuncPtr*) &aFunctions[kFunc_GetServiceManager] },
- { "_Java_org_mozilla_xpcom_internal_XPCOMImpl_newLocalFile@16",
- (NSFuncPtr*) &aFunctions[kFunc_NewLocalFile] },
- { "_Java_org_mozilla_xpcom_internal_XPCOMJavaProxy_callXPCOMMethod@20",
- (NSFuncPtr*) &aFunctions[kFunc_CallXPCOMMethod] },
- { "_Java_org_mozilla_xpcom_internal_XPCOMJavaProxy_finalizeProxy@12",
- (NSFuncPtr*) &aFunctions[kFunc_FinalizeProxy] },
- { "_Java_org_mozilla_xpcom_internal_XPCOMJavaProxy_isSameXPCOMObject@16",
- (NSFuncPtr*) &aFunctions[kFunc_IsSameXPCOMObject] },
- { "_Java_org_mozilla_xpcom_ProfileLock_release@16",
- (NSFuncPtr*) &aFunctions[kFunc_ReleaseProfileLock] },
- { "_Java_org_mozilla_xpcom_internal_MozillaImpl_getNativeHandleFromAWT@12",
- (NSFuncPtr*) &aFunctions[kFunc_GetNativeHandleFromAWT] },
- { "_Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_wrapJavaObject@16",
- (NSFuncPtr*) &aFunctions[kFunc_WrapJavaObject] },
- { "_Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_wrapXPCOMObject@20",
- (NSFuncPtr*) &aFunctions[kFunc_WrapXPCOMObject] },
- { nsnull, nsnull }
- };
-#else
- nsDynamicFunctionLoad funcs[] = {
- { "Java_org_mozilla_xpcom_internal_MozillaImpl_initialize",
- (NSFuncPtr*) &aFunctions[kFunc_Initialize] },
- { "Java_org_mozilla_xpcom_internal_GREImpl_initEmbedding",
- (NSFuncPtr*) &aFunctions[kFunc_InitEmbedding] },
- { "Java_org_mozilla_xpcom_internal_GREImpl_termEmbedding",
- (NSFuncPtr*) &aFunctions[kFunc_TermEmbedding] },
- { "Java_org_mozilla_xpcom_internal_GREImpl_lockProfileDirectory",
- (NSFuncPtr*) &aFunctions[kFunc_LockProfileDirectory] },
- { "Java_org_mozilla_xpcom_internal_GREImpl_notifyProfile",
- (NSFuncPtr*) &aFunctions[kFunc_NotifyProfile] },
- { "Java_org_mozilla_xpcom_internal_XPCOMImpl_initXPCOM",
- (NSFuncPtr*) &aFunctions[kFunc_InitXPCOM] },
- { "Java_org_mozilla_xpcom_internal_XPCOMImpl_shutdownXPCOM",
- (NSFuncPtr*) &aFunctions[kFunc_ShutdownXPCOM] },
- { "Java_org_mozilla_xpcom_internal_XPCOMImpl_getComponentManager",
- (NSFuncPtr*) &aFunctions[kFunc_GetComponentManager] },
- { "Java_org_mozilla_xpcom_internal_XPCOMImpl_getComponentRegistrar",
- (NSFuncPtr*) &aFunctions[kFunc_GetComponentRegistrar] },
- { "Java_org_mozilla_xpcom_internal_XPCOMImpl_getServiceManager",
- (NSFuncPtr*) &aFunctions[kFunc_GetServiceManager] },
- { "Java_org_mozilla_xpcom_internal_XPCOMImpl_newLocalFile",
- (NSFuncPtr*) &aFunctions[kFunc_NewLocalFile] },
- { "Java_org_mozilla_xpcom_internal_XPCOMJavaProxy_callXPCOMMethod",
- (NSFuncPtr*) &aFunctions[kFunc_CallXPCOMMethod] },
- { "Java_org_mozilla_xpcom_internal_XPCOMJavaProxy_finalizeProxy",
- (NSFuncPtr*) &aFunctions[kFunc_FinalizeProxy] },
- { "Java_org_mozilla_xpcom_internal_XPCOMJavaProxy_isSameXPCOMObject",
- (NSFuncPtr*) &aFunctions[kFunc_IsSameXPCOMObject] },
- { "Java_org_mozilla_xpcom_ProfileLock_release",
- (NSFuncPtr*) &aFunctions[kFunc_ReleaseProfileLock] },
- { "Java_org_mozilla_xpcom_internal_MozillaImpl_getNativeHandleFromAWT",
- (NSFuncPtr*) &aFunctions[kFunc_GetNativeHandleFromAWT] },
- { "Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_wrapJavaObject",
- (NSFuncPtr*) &aFunctions[kFunc_WrapJavaObject] },
- { "Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_wrapXPCOMObject",
- (NSFuncPtr*) &aFunctions[kFunc_WrapXPCOMObject] },
- { nsnull, nsnull }
- };
-#endif
-
- rv = XPCOMGlueLoadXULFunctions(funcs);
- if (NS_FAILED(rv))
- return rv;
-
- return NS_OK;
-}
-
-void
-ThrowException(JNIEnv* env, const nsresult aErrorCode, const char* aMessage)
-{
- // Only throw this exception if one hasn't already been thrown, so we don't
- // mask a previous exception/error.
- if (env->ExceptionCheck())
- return;
-
- // If the error code we get is for an Out Of Memory error, try to throw an
- // OutOfMemoryError. The JVM may have enough memory to create this error.
- if (aErrorCode == NS_ERROR_OUT_OF_MEMORY) {
- jclass clazz = env->FindClass("java/lang/OutOfMemoryError");
- if (clazz) {
- env->ThrowNew(clazz, aMessage);
- }
- env->DeleteLocalRef(clazz);
- return;
- }
-
- // If the error was not handled above, then create an XPCOMException with the
- // given error code.
- jthrowable throwObj = nsnull;
- jclass exceptionClass = env->FindClass("org/mozilla/xpcom/XPCOMException");
- if (exceptionClass) {
- jmethodID mid = env->GetMethodID(exceptionClass, "<init>",
- "(JLjava/lang/String;)V");
- if (mid) {
- throwObj = (jthrowable) env->NewObject(exceptionClass, mid,
- (PRInt64) aErrorCode,
- env->NewStringUTF(aMessage));
- }
- }
- NS_ASSERTION(throwObj, "Failed to create XPCOMException object");
-
- // throw exception
- if (throwObj) {
- env->Throw(throwObj);
- }
-}
-
-// Register the JavaXPCOM native methods. This associates a native Java
-// method with its C implementation.
-nsresult
-RegisterNativeMethods(JNIEnv* env, void** aFunctions)
-{
- JNINativeMethod mozilla_methods[] = {
- { "initializeNative", "()V",
- (void*) aFunctions[kFunc_Initialize] },
- { "getNativeHandleFromAWT", "(Ljava/lang/Object;)J",
- (void*) aFunctions[kFunc_GetNativeHandleFromAWT] }
- };
-
- JNINativeMethod gre_methods[] = {
- { "initEmbeddingNative",
- "(Ljava/io/File;Ljava/io/File;Lorg/mozilla/xpcom/IAppFileLocProvider;)V",
- (void*) aFunctions[kFunc_InitEmbedding] },
- { "termEmbedding", "()V",
- (void*) aFunctions[kFunc_TermEmbedding] },
- { "lockProfileDirectory", "(Ljava/io/File;)Lorg/mozilla/xpcom/ProfileLock;",
- (void*) aFunctions[kFunc_LockProfileDirectory] },
- { "notifyProfile", "()V",
- (void*) aFunctions[kFunc_NotifyProfile] },
- };
-
- JNINativeMethod xpcom_methods[] = {
- { "initXPCOMNative",
- "(Ljava/io/File;Lorg/mozilla/xpcom/IAppFileLocProvider;)Lorg/mozilla/interfaces/nsIServiceManager;",
- (void*) aFunctions[kFunc_InitXPCOM] },
- { "shutdownXPCOM", "(Lorg/mozilla/interfaces/nsIServiceManager;)V",
- (void*) aFunctions[kFunc_ShutdownXPCOM] },
- { "getComponentManager", "()Lorg/mozilla/interfaces/nsIComponentManager;",
- (void*) aFunctions[kFunc_GetComponentManager] },
- { "getComponentRegistrar", "()Lorg/mozilla/interfaces/nsIComponentRegistrar;",
- (void*) aFunctions[kFunc_GetComponentRegistrar] },
- { "getServiceManager", "()Lorg/mozilla/interfaces/nsIServiceManager;",
- (void*) aFunctions[kFunc_GetServiceManager] },
- { "newLocalFile", "(Ljava/lang/String;Z)Lorg/mozilla/interfaces/nsILocalFile;",
- (void*) aFunctions[kFunc_NewLocalFile] }
- };
-
- JNINativeMethod proxy_methods[] = {
- { "callXPCOMMethod",
- "(Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/Object;",
- (void*) aFunctions[kFunc_CallXPCOMMethod] },
- { "finalizeProxyNative", "(Ljava/lang/Object;)V",
- (void*) aFunctions[kFunc_FinalizeProxy] },
- { "isSameXPCOMObject", "(Ljava/lang/Object;Ljava/lang/Object;)Z",
- (void*) aFunctions[kFunc_IsSameXPCOMObject] }
- };
-
- JNINativeMethod lockProxy_methods[] = {
- { "releaseNative", "(J)V",
- (void*) aFunctions[kFunc_ReleaseProfileLock] }
- };
-
- JNINativeMethod util_methods[] = {
- { "wrapJavaObject", "(Ljava/lang/Object;Ljava/lang/String;)J",
- (void*) aFunctions[kFunc_WrapJavaObject] },
- { "wrapXPCOMObject", "(JLjava/lang/String;)Ljava/lang/Object;",
- (void*) aFunctions[kFunc_WrapXPCOMObject] }
- };
-
- jint rc = -1;
- jclass clazz = env->FindClass("org/mozilla/xpcom/internal/MozillaImpl");
- if (clazz) {
- rc = env->RegisterNatives(clazz, mozilla_methods,
- sizeof(mozilla_methods) / sizeof(mozilla_methods[0]));
- }
- NS_ENSURE_TRUE(rc == 0, NS_ERROR_FAILURE);
-
- rc = -1;
- clazz = env->FindClass("org/mozilla/xpcom/internal/GREImpl");
- if (clazz) {
- rc = env->RegisterNatives(clazz, gre_methods,
- sizeof(gre_methods) / sizeof(gre_methods[0]));
- }
- NS_ENSURE_TRUE(rc == 0, NS_ERROR_FAILURE);
-
- rc = -1;
- clazz = env->FindClass("org/mozilla/xpcom/internal/XPCOMImpl");
- if (clazz) {
- rc = env->RegisterNatives(clazz, xpcom_methods,
- sizeof(xpcom_methods) / sizeof(xpcom_methods[0]));
- }
- NS_ENSURE_TRUE(rc == 0, NS_ERROR_FAILURE);
-
- rc = -1;
- clazz = env->FindClass("org/mozilla/xpcom/internal/XPCOMJavaProxy");
- if (clazz) {
- rc = env->RegisterNatives(clazz, proxy_methods,
- sizeof(proxy_methods) / sizeof(proxy_methods[0]));
- }
- NS_ENSURE_TRUE(rc == 0, NS_ERROR_FAILURE);
-
- rc = -1;
- clazz = env->FindClass("org/mozilla/xpcom/ProfileLock");
- if (clazz) {
- rc = env->RegisterNatives(clazz, lockProxy_methods,
- sizeof(lockProxy_methods) / sizeof(lockProxy_methods[0]));
- }
- NS_ENSURE_TRUE(rc == 0, NS_ERROR_FAILURE);
-
- rc = -1;
- clazz = env->FindClass("org/mozilla/xpcom/internal/JavaXPCOMMethods");
- if (clazz) {
- rc = env->RegisterNatives(clazz, util_methods,
- sizeof(util_methods) / sizeof(util_methods[0]));
- }
- NS_ENSURE_TRUE(rc == 0, NS_ERROR_FAILURE);
-
- return NS_OK;
-}
-
-// Load the JavaXPCOM methods from the XUL shared library, and registers them
-// as Java native methods.
-extern "C" JX_EXPORT void JNICALL
-JXM_NATIVE(registerJavaXPCOMMethodsNative) (JNIEnv *env, jclass that,
- jobject aXPCOMPath)
-{
- void* functions[JX_NUM_FUNCS];
- memset(functions, 0, JX_NUM_FUNCS * sizeof(void*));
-
- nsresult rv = LoadXULMethods(env, aXPCOMPath, functions);
- if (NS_SUCCEEDED(rv)) {
- rv = RegisterNativeMethods(env, functions);
- }
-
- if (NS_FAILED(rv)) {
- ThrowException(env, rv, "Failed to register JavaXPCOM methods");
- }
-}
-
deleted file mode 100644
--- a/extensions/java/xpcom/interfaces/Makefile.in
+++ /dev/null
@@ -1,132 +0,0 @@
-# ***** 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 Java XPCOM Bindings.
-#
-# The Initial Developer of the Original Code is IBM Corporation.
-# Portions created by the Initial Developer are Copyright (C) 2006
-# IBM Corporation. All Rights Reserved.
-#
-# Contributor(s):
-# Javier Pedemonte (jhpedemonte@gmail.com)
-#
-# 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 *****
-
-DEPTH = ../../../..
-topsrcdir = @top_srcdir@
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-include $(DEPTH)/config/autoconf.mk
-
-JAVA_LIBRARY_NAME = MozillaGlue
-
-# Don't install MozillaGlue.jar in $(DIST)/bin
-NO_DIST_INSTALL=1
-NO_INSTALL=1
-
-PACKAGE_DIR = org/mozilla/xpcom
-
-JAVA_SRCS = \
- $(PACKAGE_DIR)/Mozilla.java \
- $(PACKAGE_DIR)/GREVersionRange.java \
- $(PACKAGE_DIR)/IMozilla.java \
- $(PACKAGE_DIR)/IGRE.java \
- $(PACKAGE_DIR)/IXPCOM.java \
- $(PACKAGE_DIR)/IJavaXPCOMUtils.java \
- $(PACKAGE_DIR)/IAppFileLocProvider.java \
- $(PACKAGE_DIR)/INIParser.java \
- $(PACKAGE_DIR)/VersionComparator.java \
- $(PACKAGE_DIR)/IXPCOMError.java \
- $(PACKAGE_DIR)/ProfileLock.java \
- $(PACKAGE_DIR)/XPCOMException.java \
- $(PACKAGE_DIR)/XPCOMInitializationException.java \
- $(NULL)
-
-IFACES_JAR = MozillaInterfaces.jar
-IFACES_JAR_SRC = $(patsubst %.jar,%-src.jar,$(IFACES_JAR))
-
-JAVA_CLASSPATH += $(IFACES_JAR)
-
-# install jars into SDK
-SDK_LIBRARY = $(JAVA_LIBRARY_NAME).jar $(IFACES_JAR) $(IFACES_JAR_SRC)
-
-GARBAGE += $(IFACES_JAR) $(IFACES_JAR_SRC) $(PACKAGE_DIR)/IXPCOMError.java java.files
-
-include $(topsrcdir)/config/rules.mk
-
-# MozillaGlue.jar depends on MozillaInterfaces.jar, so make sure to generate
-# the Mozilla Java interfaces first.
-$(addprefix $(_JAVA_DIR)/,$(JAVA_SRCS:.java=.class)): $(IFACES_JAR)
-
-##
-# Generate IXPCOMError.java
-##
-
-$(_JAVA_DIR)/$(PACKAGE_DIR)/Mozilla.class: $(PACKAGE_DIR)/IXPCOMError.java
-
-$(PACKAGE_DIR)::
- $(NSINSTALL) -D $@
-
-$(PACKAGE_DIR)/IXPCOMError.java: $(topsrcdir)/xpcom/base/nsError.h gen-nsError.pl $(PACKAGE_DIR) $(GLOBAL_DEPS)
- $(PERL) $(srcdir)/gen-nsError.pl < $< > $@
-
-##
-# Compile generated Java interfaces
-##
-
-IFACES_DIR = _ifaces
-$(IFACES_DIR)::
- $(NSINSTALL) -D $@
-
-GARBAGE_DIRS += $(IFACES_DIR)
-
-# exclude interfaces that we don't need
-IGNORE_IFACES_NAMES =
-ifneq (,$(IGNORE_IFACES_NAMES))
-IGNORE_IFACES = $(patsubst %, ! -name "*%.java", $(IGNORE_IFACES_NAMES))
-endif
-
-# Using the temporary "java.files" avoids an "argument list too long"
-# error on Windows when using *.java
-$(IFACES_DIR)/$(JAVA_IFACES_PKG_NAME)/nsISupports.class: $(IFACES_DIR) $(wildcard $(JAVA_DIST_DIR)/default/$(JAVA_IFACES_PKG_NAME)/*.java) $(GLOBAL_DEPS)
- @echo Compiling Java interfaces
- find $(JAVA_DIST_DIR)/default -name "*.java" $(IGNORE_IFACES) > java.files
- $(CYGWIN_WRAPPER) $(JAVAC) $(JAVAC_FLAGS) -classpath $(IFACES_DIR) \
- -d $(IFACES_DIR) -sourcepath $(JAVA_DIST_DIR)/default @java.files
-
-$(IFACES_JAR): $(IFACES_DIR)/$(JAVA_IFACES_PKG_NAME)/nsISupports.class Makefile
- $(JAR) cf $@ -C $(IFACES_DIR) org
-
-$(IFACES_JAR_SRC): $(IFACES_JAR)
- $(JAR) cf $@ -C $(JAVA_DIST_DIR)/default org
-ifneq (,$(IGNORE_IFACES_NAMES))
- $(ZIP) -d $@ $(patsubst %, $(JAVA_IFACES_PKG_NAME)/%.java, $(IGNORE_IFACES_NAMES))
-endif
-
-# Since we set NO_DIST_INSTALL above, the jars don't get copied into the SDK.
-# Handle that here.
-libs:: $(SDK_LIBRARY) $(SDK_LIB_DIR)
- $(INSTALL) $(IFLAGS2) $^
deleted file mode 100644
--- a/extensions/java/xpcom/interfaces/gen-nsError.pl
+++ /dev/null
@@ -1,163 +0,0 @@
-#! /usr/bin/env perl
-# ***** 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 Java XPCOM Bindings.
-#
-# The Initial Developer of the Original Code is
-# Michal Ceresna.
-# Portions created by the Initial Developer are Copyright (C) 2005
-# the Initial Developer. All Rights Reserved.
-#
-# Contributor(s):
-# Michal Ceresna (ceresna@dbai.tuwien.ac.at)
-# Javier Pedemonte (jhpedemonte@gmail.com)
-#
-# 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 *****
-
-# Generates IXPCOMError.java from xpcom/base/nsError.h
-#
-# usage: perl gen-nsErrors.pl < <topsrcdir>/xpcom/base/nsError.h > IXPCOMError.java
-
-
-print "/* ***** BEGIN LICENSE BLOCK *****\n";
-print " * Version: MPL 1.1/GPL 2.0/LGPL 2.1\n";
-print " *\n";
-print " * The contents of this file are subject to the Mozilla Public License Version\n";
-print " * 1.1 (the \"License\"); you may not use this file except in compliance with\n";
-print " * the License. You may obtain a copy of the License at\n";
-print " * http://www.mozilla.org/MPL/\n";
-print " *\n";
-print " * Software distributed under the License is distributed on an \"AS IS\" basis,\n";
-print " * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License\n";
-print " * for the specific language governing rights and limitations under the\n";
-print " * License.\n";
-print " *\n";
-print " * The Original Code is mozilla.org code.\n";
-print " *\n";
-print " * The Initial Developer of the Original Code is\n";
-print " * Netscape Communications Corporation.\n";
-print " * Portions created by the Initial Developer are Copyright (C) 1998\n";
-print " * the Initial Developer. All Rights Reserved.\n";
-print " *\n";
-print " * Contributor(s):\n";
-print " *\n";
-print " * Alternatively, the contents of this file may be used under the terms of\n";
-print " * either of the GNU General Public License Version 2 or later (the \"GPL\"),\n";
-print " * or the GNU Lesser General Public License Version 2.1 or later (the \"LGPL\"),\n";
-print " * in which case the provisions of the GPL or the LGPL are applicable instead\n";
-print " * of those above. If you wish to allow use of your version of this file only\n";
-print " * under the terms of either the GPL or the LGPL, and not to allow others to\n";
-print " * use your version of this file under the terms of the MPL, indicate your\n";
-print " * decision by deleting the provisions above and replace them with the notice\n";
-print " * and other provisions required by the GPL or the LGPL. If you do not delete\n";
-print " * the provisions above, a recipient may use your version of this file under\n";
-print " * the terms of any one of the MPL, the GPL or the LGPL.\n";
-print " *\n";
-print " * ***** END LICENSE BLOCK ***** */\n";
-
-print "\n";
-print "package org.mozilla.xpcom;\n";
-print "\n\n";
-
-print "/**\n";
-print " * Mozilla XPCOM error codes.\n";
-print " * <p>\n";
-print " * THIS FILE GENERATED FROM mozilla/xpcom/base/nsError.h.\n";
-print " * PLEASE SEE THAT FILE FOR FULL DOCUMENTATION.\n";
-print " */\n";
-print "public interface IXPCOMError {\n";
-
-while (<STDIN>) {
- $line = $_;
-
- if ($prevline) {
- $_ = $prevline.$_;
- }
- if (/(.*)\\$/) {
- #splitted line
- $prevline = $1;
- next;
- }
- $prevline = "";
-
- if (/^\s*#define\s+(NS_[A-Z_]+)\s+(0x)?([0-9a-fA-F]+)\s*$/) {
- #define NS_ERROR_MODULE_XPCOM 1
- #define NS_ERROR_MODULE_BASE_OFFSET 0x45
- print " long $1 = $2$3L;\n";
- }
- elsif (/^\s*#define\s+(NS_[A-Z_]+)\s+\((NS_[A-Z_]+)\s+\+\s+(0x)?([0-9a-fA-F]+)\s*\)\s*/) {
- #define NS_ERROR_NOT_INITIALIZED (NS_ERROR_BASE + 1)
- #define NS_ERROR_FACTORY_EXISTS (NS_ERROR_BASE + 0x100)
- print " long $1 = $2 + $3$4L;\n";
- }
- elsif (/^\s*#define\s+(NS_[A-Z_]+)\s+(NS_[A-Z_]+)\s\s*/) {
- #define NS_ERROR_NO_INTERFACE NS_NOINTERFACE
- print " long $1 = $2;\n";
- }
- elsif (/^\s*#define\s+(NS_[A-Z_]+)\s+\(\(nsresult\)\s*(0x)?([0-9a-fA-F]+)L?\)\s*$/) {
- #define NS_ERROR_BASE ((nsresult) 0xC1F30000)
- #define NS_ERROR_ABORT ((nsresult) 0x80004004L)
- print " long $1 = $2$3L;\n";
- }
- elsif (/^\s*#define\s+(NS_[A-Z_]+)\s+NS_ERROR_GENERATE_FAILURE\s*\(\s*(NS_[A-Z_]+)\s*,\s*([0-9]+)\s*\)\s*$/) {
- #define NS_BASE_STREAM_CLOSED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 2)
- $module = $2;
- $code = $3;
- print " long $1 = ((NS_ERROR_SEVERITY_ERROR<<31) |\n";
- print " (($module+NS_ERROR_MODULE_BASE_OFFSET)<<16) | $code);\n";
- }
- elsif (/^\s*#define\s+(NS_[A-Z_]+)\s+NS_ERROR_GENERATE_SUCCESS\s*\(\s*(NS_[A-Z_]+)\s*,\s*([0-9]+)\s*\)\s*$/) {
- #define NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_XPCOM, 1)
- $module = $2;
- $code = $3;
- print " long $1 = ((NS_ERROR_SEVERITY_SUCCESS<<31) |\n";
- print " (($module+NS_ERROR_MODULE_BASE_OFFSET)<<16) | $code);\n";
- }
- elsif (/^\s*\/\*(.*)\*\/\s*$/ && !/^\s*\/\*@[\{\}]\*\/\s*$/ &&
- !/^\s*\/\*\ -\*- Mode:/) {
- #single line comment, but not
- #/*@{*/, /*@}*/,
- #/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
- print " /*$1*/\n";
- }
- elsif (/^\s*$/) {
- #empty line, but write only the first
- #line from a sequence of empty lines
- if (!$wasEmpty) {
- print "\n";
- }
- $wasEmpty = 1;
- next;
- }
- else {
- next;
- }
-
- $wasEmpty = 0;
-}
-
-print "}\n";
-
deleted file mode 100644
--- a/extensions/java/xpcom/interfaces/org/mozilla/xpcom/GREVersionRange.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is
- * IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2005
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 ***** */
-
-package org.mozilla.xpcom;
-
-
-public class GREVersionRange {
-
- private String lower;
- private boolean lowerInclusive;
- private String upper;
- private boolean upperInclusive;
-
- public GREVersionRange(String aLower, boolean aLowerInclusive,
- String aUpper, boolean aUpperInclusive) {
- lower = aLower;
- lowerInclusive = aLowerInclusive;
- upper = aUpper;
- upperInclusive = aUpperInclusive;
- }
-
- public boolean check(String aVersion) {
- VersionComparator comparator = new VersionComparator();
- int c = comparator.compare(aVersion, lower);
- if (c < 0) {
- return false;
- }
-
- if (c == 0 && !lowerInclusive) {
- return false;
- }
-
- c = comparator.compare(aVersion, upper);
- if (c > 0) {
- return false;
- }
-
- if (c == 0 && !upperInclusive) {
- return false;
- }
-
- return true;
- }
-
-}
-
deleted file mode 100644
--- a/extensions/java/xpcom/interfaces/org/mozilla/xpcom/IAppFileLocProvider.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is
- * IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2004
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 ***** */
-
-package org.mozilla.xpcom;
-
-import java.io.File;
-
-
-/**
- * Used by XPCOM's Directory Service to get file locations.
- * <p>
- * This interface is similar to <code>nsIDirectoryServiceProvider</code> and
- * <code>nsIDirectoryServiceProvider2</code>, except that its methods use
- * <code>java.io.File</code> instead of <code>nsIFile</code>.
- * </p>
- *
- * @see Mozilla#initEmbedding
- * @see Mozilla#initXPCOM
- * @see <a href=
- * "http://lxr.mozilla.org/mozilla/source/xpcom/io/nsIDirectoryService.idl">
- * nsIDirectoryServiceProvider </a>
- * @see <a href=
- * "http://lxr.mozilla.org/mozilla/source/xpcom/io/nsDirectoryServiceDefs.h">
- * Directory Service property names </a>
- */
-public interface IAppFileLocProvider {
-
- /**
- * Directory Service calls this when it gets the first request for
- * a property or on every request if the property is not persistent.
- *
- * @param prop the symbolic name of the file
- * @param persistent an array of length one used to supply the output value:
- * <ul>
- * <li><code>true</code> - The returned file will be
- * cached by Directory Service. Subsequent requests for
- * this prop will bypass the provider and use the cache.
- * </li>
- * <li><code>false</code> - The provider will be asked
- * for this prop each time it is requested. </li>
- * </ul>
- *
- * @return the file represented by the property
- */
- File getFile(String prop, boolean[] persistent);
-
- /**
- * Directory Service calls this when it gets a request for
- * a property and the requested type is nsISimpleEnumerator.
- *
- * @param prop the symbolic name of the file list
- *
- * @return an array of file locations
- */
- File[] getFiles(String prop);
-
-}
-
deleted file mode 100644
--- a/extensions/java/xpcom/interfaces/org/mozilla/xpcom/IGRE.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2006
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 ***** */
-
-package org.mozilla.xpcom;
-
-import java.io.File;
-
-
-public interface IGRE {
-
- /**
- * Initializes libXUL for embedding purposes.
- * <p>
- * NOTE: This function must be called from the "main" thread.
- * <p>
- * NOTE: At the present time, this function may only be called once in
- * a given process. Use <code>termEmbedding</code> to clean up and free
- * resources allocated by <code>initEmbedding</code>.
- *
- * @param aLibXULDirectory The directory in which the libXUL shared library
- * was found.
- * @param aAppDirectory The directory in which the application components
- * and resources can be found. This will map to
- * the "resource:app" directory service key.
- * @param aAppDirProvider A directory provider for the application. This
- * provider will be aggregated by a libXUL provider
- * which will provide the base required GRE keys.
- *
- * @throws XPCOMException if a failure occurred during initialization
- */
- void initEmbedding(File aLibXULDirectory, File aAppDirectory,
- IAppFileLocProvider aAppDirProvider) throws XPCOMException;
-
- /**
- * Terminates libXUL embedding.
- * <p>
- * NOTE: Release any references to XPCOM objects that you may be holding
- * before calling this function.
- */
- void termEmbedding();
-
- /**
- * Lock a profile directory using platform-specific semantics.
- *
- * @param aDirectory The profile directory to lock.
- *
- * @return A lock object. The directory will remain locked until the lock is
- * released by invoking the <code>release</code> method, or by the
- * termination of the JVM, whichever comes first.
- *
- * @throws XPCOMException if a failure occurred
- */
- ProfileLock lockProfileDirectory(File aDirectory) throws XPCOMException;
-
- /**
- * Fire notifications to inform the toolkit about a new profile. This
- * method should be called after <code>initEmbedding</code> if the
- * embedder wishes to run with a profile.
- * <p>
- * Normally the embedder should call <code>lockProfileDirectory</code>
- * to lock the directory before calling this method.
- * <p>
- * NOTE: There are two possibilities for selecting a profile:
- * <ul>
- * <li>
- * Select the profile before calling <code>initEmbedding</code>.
- * The aAppDirProvider object passed to <code>initEmbedding</code>
- * should provide the NS_APP_USER_PROFILE_50_DIR key, and
- * may also provide the following keys:
- * <ul>
- * <li>NS_APP_USER_PROFILE_LOCAL_50_DIR
- * <li>NS_APP_PROFILE_DIR_STARTUP
- * <li>NS_APP_PROFILE_LOCAL_DIR_STARTUP
- * </ul>
- * In this scenario <code>notifyProfile</code> should be called
- * immediately after <code>initEmbedding</code>. Component
- * registration information will be stored in the profile and
- * JS components may be stored in the fastload cache.
- * </li>
- * <li>
- * Select a profile some time after calling <code>initEmbedding</code>.
- * In this case the embedder must install a directory service
- * provider which provides NS_APP_USER_PROFILE_50_DIR and optionally
- * NS_APP_USER_PROFILE_LOCAL_50_DIR. Component registration information
- * will be stored in the application directory and JS components will not
- * fastload.
- * </li>
- * </ul>
- */
- void notifyProfile();
-
-}
-
-
deleted file mode 100644
--- a/extensions/java/xpcom/interfaces/org/mozilla/xpcom/IJavaXPCOMUtils.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2007
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 ***** */
-
-package org.mozilla.xpcom;
-
-public interface IJavaXPCOMUtils {
-
- /**
- * Returns a pointer to a C++ proxy object for the given Java object.
- *
- * @param aJavaObject Java object to encapsulate in C++ proxy
- * @param aIID interface ID for requested proxy
- * @return C pointer (as long) of new proxy
- */
- long wrapJavaObject(Object aJavaObject, String aIID);
-
- /**
- * Returns a Java proxy for the given C++ XPCOM object
- *
- * @param aXPCOMObject C++ XPCOM object to encapsulate in Java proxy
- * @param aIID interface ID for requested proxy
- * @return new Proxy
- */
- Object wrapXPCOMObject(long aXPCOMObject, String aIID);
-
-}
deleted file mode 100644
--- a/extensions/java/xpcom/interfaces/org/mozilla/xpcom/IMozilla.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2006
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 ***** */
-
-package org.mozilla.xpcom;
-
-import java.io.File;
-
-public interface IMozilla {
-
- /**
- * Initialize the Mozilla object with the given XULRunner path. All
- * subsequent Mozilla method invocations be done against the given XULRunner
- * version.
- *
- * @param aLibXULDirectory path of XULRunner build to use
- *
- * @throws XPCOMInitializationException if failure occurred during
- * initialization
- */
- void initialize(File aLibXULDirectory) throws XPCOMInitializationException;
-
- /**
- * Return the native window handle for an AWT component.
- *
- * @param widget An AWT component (such as Canvas, Frame) that is backed by
- * a real native window.
- * @return the pointer to the native window (platform specific)
- */
- long getNativeHandleFromAWT(Object widget);
-}
deleted file mode 100644
--- a/extensions/java/xpcom/interfaces/org/mozilla/xpcom/INIParser.java
+++ /dev/null
@@ -1,244 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is
- * IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2005
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 ***** */
-
-package org.mozilla.xpcom;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.nio.charset.Charset;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Properties;
-import java.util.StringTokenizer;
-
-
-/**
- * A simple parser for INI files.
- */
-public class INIParser {
-
- private HashMap mSections;
-
- /**
- * Creates a new <code>INIParser</code> instance from the INI file at the
- * given path. <code>aCharset</code> specifies the character encoding of
- * the file.
- *
- * @param aFilename path of INI file to parse
- * @param aCharset character encoding of file
- * @throws FileNotFoundException if <code>aFilename</code> does not exist.
- * @throws IOException if there is a problem reading the given file.
- */
- public INIParser(String aFilename, Charset aCharset)
- throws FileNotFoundException, IOException {
- initFromFile(new File(aFilename), aCharset);
- }
-
- /**
- * Creates a new <code>INIParser</code> instance from the INI file at the
- * given path, which is assumed to be in the <code>UTF-8</code> charset.
- *
- * @param aFilename path of INI file to parse
- * @throws FileNotFoundException if <code>aFilename</code> does not exist.
- * @throws IOException if there is a problem reading the given file.
- */
- public INIParser(String aFilename) throws FileNotFoundException, IOException {
- initFromFile(new File(aFilename), Charset.forName("UTF-8"));
- }
-
- /**
- * Creates a new <code>INIParser</code> instance from the given file.
- * <code>aCharset</code> specifies the character encoding of the file.
- *
- * @param aFile INI file to parse
- * @param aCharset character encoding of file
- * @throws FileNotFoundException if <code>aFile</code> does not exist.
- * @throws IOException if there is a problem reading the given file.
- */
- public INIParser(File aFile, Charset aCharset)
- throws FileNotFoundException, IOException {
- initFromFile(aFile, aCharset);
- }
-
- /**
- * Creates a new <code>INIParser</code> instance from the given file,
- * which is assumed to be in the <code>UTF-8</code> charset.
- *
- * @param aFile INI file to parse
- * @throws FileNotFoundException if <code>aFile</code> does not exist.
- * @throws IOException if there is a problem reading the given file.
- */
- public INIParser(File aFile) throws FileNotFoundException, IOException {
- initFromFile(aFile, Charset.forName("UTF-8"));
- }
-
- /**
- * Parses given INI file.
- *
- * @param aFile INI file to parse
- * @param aCharset character encoding of file
- * @throws FileNotFoundException if <code>aFile</code> does not exist.
- * @throws IOException if there is a problem reading the given file.
- */
- private void initFromFile(File aFile, Charset aCharset)
- throws FileNotFoundException, IOException {
- FileInputStream fileStream = new FileInputStream(aFile);
- InputStreamReader inStream = new InputStreamReader(fileStream, aCharset);
- BufferedReader reader = new BufferedReader(inStream);
-
- mSections = new HashMap();
- String currSection = null;
-
- String line;
- while ((line = reader.readLine()) != null) {
- // skip empty lines and comment lines
- String trimmedLine = line.trim();
- if (trimmedLine.length() == 0 || trimmedLine.startsWith("#")
- || trimmedLine.startsWith(";")) {
- continue;
- }
-
- // Look for section headers (i.e. "[Section]").
- if (line.startsWith("[")) {
- /*
- * We are looking for a well-formed "[Section]". If this header is
- * malformed (i.e. "[Section" or "[Section]Moretext"), just skip it
- * and go on to next well-formed section header.
- */
- if (!trimmedLine.endsWith("]") ||
- trimmedLine.indexOf("]") != (trimmedLine.length() - 1)) {
- currSection = null;
- continue;
- }
-
- // remove enclosing brackets
- currSection = trimmedLine.substring(1, trimmedLine.length() - 1);
- continue;
- }
-
- // If we haven't found a valid section header, continue to next line
- if (currSection == null) {
- continue;
- }
-
- StringTokenizer tok = new StringTokenizer(line, "=");
- if (tok.countTokens() != 2) { // looking for value pairs
- continue;
- }
-
- Properties props = (Properties) mSections.get(currSection);
- if (props == null) {
- props = new Properties();
- mSections.put(currSection, props);
- }
- props.setProperty(tok.nextToken(), tok.nextToken());
- }
-
- reader.close();
- }
-
- /**
- * Returns an iterator over the section names available in the INI file.
- *
- * @return an iterator over the section names
- */
- public Iterator getSections() {
- return mSections.keySet().iterator();
- }
-
- /**
- * Returns an iterator over the keys available within a section.
- *
- * @param aSection section name whose keys are to be returned
- * @return an iterator over section keys, or <code>null</code> if no
- * such section exists
- */
- public Iterator getKeys(String aSection) {
- /*
- * Simple wrapper class to convert Enumeration to Iterator
- */
- class PropertiesIterator implements Iterator {
- private Enumeration e;
-
- public PropertiesIterator(Enumeration aEnum) {
- e = aEnum;
- }
-
- public boolean hasNext() {
- return e.hasMoreElements();
- }
-
- public Object next() {
- return e.nextElement();
- }
-
- public void remove() {
- return;
- }
- }
-
- Properties props = (Properties) mSections.get(aSection);
- if (props == null) {
- return null;
- }
-
- return new PropertiesIterator(props.propertyNames());
- }
-
- /**
- * Gets the string value for a particular section and key.
- *
- * @param aSection a section name
- * @param aKey the key whose value is to be returned.
- * @return string value of particular section and key
- */
- public String getString(String aSection, String aKey) {
- Properties props = (Properties) mSections.get(aSection);
- if (props == null) {
- return null;
- }
-
- return props.getProperty(aKey);
- }
-
-}
-
deleted file mode 100644
--- a/extensions/java/xpcom/interfaces/org/mozilla/xpcom/IXPCOM.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2006
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 ***** */
-
-package org.mozilla.xpcom;
-
-import java.io.File;
-
-import org.mozilla.interfaces.nsIComponentManager;
-import org.mozilla.interfaces.nsIComponentRegistrar;
-import org.mozilla.interfaces.nsILocalFile;
-import org.mozilla.interfaces.nsIServiceManager;
-
-
-public interface IXPCOM {
-
- /**
- * Initializes XPCOM. You must call this method before proceeding
- * to use XPCOM.
- *
- * @param aMozBinDirectory The directory containing the component
- * registry and runtime libraries;
- * or use <code>null</code> to use the working
- * directory.
- *
- * @param aAppFileLocProvider The object to be used by Gecko that specifies
- * to Gecko where to find profiles, the component
- * registry preferences and so on; or use
- * <code>null</code> for the default behaviour.
- *
- * @return the service manager
- *
- * @throws XPCOMException <ul>
- * <li> NS_ERROR_NOT_INITIALIZED - if static globals were not initialied,
- * which can happen if XPCOM is reloaded, but did not completly
- * shutdown. </li>
- * <li> Other error codes indicate a failure during initialisation. </li>
- * </ul>
- */
- nsIServiceManager initXPCOM(File aMozBinDirectory,
- IAppFileLocProvider aAppFileLocProvider) throws XPCOMException;
-
- /**
- * Shutdown XPCOM. You must call this method after you are finished
- * using xpcom.
- *
- * @param aServMgr The service manager which was returned by initXPCOM.
- * This will release servMgr.
- *
- * @throws XPCOMException if a failure occurred during termination
- */
- void shutdownXPCOM(nsIServiceManager aServMgr) throws XPCOMException;
-
- /**
- * Public Method to access to the service manager.
- *
- * @return the service manager
- *
- * @throws XPCOMException
- */
- nsIServiceManager getServiceManager() throws XPCOMException;
-
- /**
- * Public Method to access to the component manager.
- *
- * @return the component manager
- *
- * @throws XPCOMException
- */
- nsIComponentManager getComponentManager() throws XPCOMException;
-
- /**
- * Public Method to access to the component registration manager.
- *
- * @return the component registration manager
- *
- * @throws XPCOMException
- */
- nsIComponentRegistrar getComponentRegistrar() throws XPCOMException;
-
- /**
- * Public Method to create an instance of a nsILocalFile.
- *
- * @param aPath A string which specifies a full file path to a
- * location. Relative paths will be treated as an
- * error (NS_ERROR_FILE_UNRECOGNIZED_PATH).
- * @param aFollowLinks This attribute will determine if the nsLocalFile will
- * auto resolve symbolic links. By default, this value
- * will be false on all non unix systems. On unix, this
- * attribute is effectively a noop.
- *
- * @return an instance of an nsILocalFile that points to given path
- *
- * @throws XPCOMException <ul>
- * <li> NS_ERROR_FILE_UNRECOGNIZED_PATH - raised for unrecognized paths
- * or relative paths (must supply full file path) </li>
- * </ul>
- */
- nsILocalFile newLocalFile(String aPath, boolean aFollowLinks)
- throws XPCOMException;
-
-}
-
deleted file mode 100644
--- a/extensions/java/xpcom/interfaces/org/mozilla/xpcom/Mozilla.java
+++ /dev/null
@@ -1,1067 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2006
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 ***** */
-
-package org.mozilla.xpcom;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.Properties;
-
-import org.mozilla.interfaces.nsIComponentManager;
-import org.mozilla.interfaces.nsIComponentRegistrar;
-import org.mozilla.interfaces.nsILocalFile;
-import org.mozilla.interfaces.nsIServiceManager;
-import org.mozilla.interfaces.nsISupports;
-
-
-/**
- * A singleton class which provides access to the Mozilla browser. Requires
- * that XULRunner be installed on the user's system.
- * <p>
- * You would use to class to find a XULRunner installation, setup a profile (if
- * necessary), and initialize embedding. A typical scenario would look like
- * this:
- * </p><pre>
- * Mozilla mozilla = Mozilla.getInstance();
- * GREVersionRange[] range = new GREVersionRange[1];
- * range[0] = new GREVersionRange("1.8.0.*", false, "1.8.1.*", true);
- * try {
- * File grePath = Mozilla.getGREPathWithProperties(range, null);
- * mozilla.initialize(grePath);
- * profLock = mozilla.lockProfileDirectory(profileDir);
- * // LocationProvider is a user class that implements IAppFileLocProvider
- * LocationProvider locProvider = new LocationProvider(grePath, profileDir);
- * mozilla.initEmbedding(grePath, grePath, locProvider);
- * mozilla.notifyProfile();
- * } catch (XPCOMInitializationException xie) {
- * // handle exception
- * } catch (XPCOMException xe) {
- * // handle exception
- * }
- * </pre>
- *
- * @see http://www.mozilla.org/projects/embedding/GRE.html
- */
-public class Mozilla implements IMozilla, IGRE, IXPCOM, IJavaXPCOMUtils,
-IXPCOMError {
-
- private static Mozilla mozillaInstance = new Mozilla();
-
- private static final String JAVAXPCOM_JAR = "javaxpcom.jar";
-
- private IMozilla mozilla = null;
- private IGRE gre = null;
- private IXPCOM xpcom = null;
- private IJavaXPCOMUtils jxutils = null;
-
- /**
- * @return
- */
- public static Mozilla getInstance() {
- return mozillaInstance;
- }
-
- /**
- *
- */
- private Mozilla() {
- }
-
- /**
- * Locates the path of a GRE with the specified properties. This method
- * will only return GREs that support Java embedding (looks for the
- * presence of "javaxpcom.jar").
- * <p>
- * Currently this uses a "first-fit" algorithm, it does not select
- * the newest available GRE.
- *
- * @param aVersions An array of version ranges: if any version range
- * matches, the GRE is considered acceptable.
- * @param aProperties A list of GRE property/value pairs which must
- * all be satisfied. This parameter is ignored on
- * Macintosh, because of the manner in which the
- * XUL frameworks are installed.
- *
- * @return A file object of the appropriate path. If
- * the "local" GRE is specified (via the USE_LOCAL_GRE
- * environment variable, for example), returns
- * <code>null</code>.
- *
- * @throws FileNotFoundException if an appropriate GRE could not be found
- */
- public static File getGREPathWithProperties(GREVersionRange[] aVersions,
- Properties aProperties) throws FileNotFoundException {
- File grePath = null;
-
- // if GRE_HOME is in the environment, use that GRE
- String env = System.getProperty("GRE_HOME");
- if (env != null) {
- try {
- grePath = new File(env).getCanonicalFile();
- } catch (IOException e) {
- throw new FileNotFoundException("cannot access GRE_HOME");
- }
- if (!grePath.exists()) {
- throw new FileNotFoundException("GRE_HOME doesn't exist");
- }
- return grePath;
- }
-
- // the Gecko bits that sit next to the application or in the PATH
- env = System.getProperty("USE_LOCAL_GRE");
- if (env != null) {
- return null;
- }
-
- // Search for GRE in platform specific locations. We want a GRE that
- // supports Java, so we look for the "javaxpcom" property by default.
- if (aProperties == null) {
- aProperties = new Properties();
- }
- aProperties.setProperty("javaxpcom", "1");
-
- String osName = System.getProperty("os.name").toLowerCase();
- if (osName.startsWith("mac os x")) {
- grePath = getGREPathMacOSX(aVersions);
- } else if (osName.startsWith("windows")) {
- grePath = getGREPathWindows(aVersions, aProperties);
- } else {
- // assume everything else is Unix/Linux
- grePath = getGREPathUnix(aVersions, aProperties);
- }
-
- if (grePath == null) {
- throw new FileNotFoundException("GRE not found");
- }
-
- return grePath;
- }
-
- /**
- * @param aVersions
- * @return
- */
- private static File getGREPathMacOSX(GREVersionRange[] aVersions) {
- /*
- * Check the application bundle first, for
- * <bundle>/Contents/Frameworks/XUL.framework/libxpcom.dylib.
- */
- File grePath = findGREBundleFramework();
- if (grePath != null) {
- return grePath;
- }
-
- // Check ~/Library/Frameworks/XUL.framework/Versions/<version>/libxpcom.dylib
- String home = System.getProperty("user.home");
- if (home != null) {
- grePath = findGREFramework(home, aVersions);
- if (grePath != null) {
- return grePath;
- }
- }
-
- // Check /Library/Frameworks/XUL.framework/Versions/<version>/libxpcom.dylib
- return findGREFramework("", aVersions);
- }
-
- /**
- * @return
- */
- private static File findGREBundleFramework() {
- /*
- * Use reflection to get Apple's NSBundle class, which can be used
- * to get the bundle's "Frameworks" directory.
- */
- try {
- URL[] urls = new URL[1];
- urls[0] = new File("/System/Library/Java/").toURL();
- ClassLoader loader = new URLClassLoader(urls);
- Class bundleClass = Class.forName("com.apple.cocoa.foundation.NSBundle",
- true, loader);
-
- // Get the bundle for this app. If this is not executing from
- // a bundle, this will return null.
- Method mainBundleMethod = bundleClass.getMethod("mainBundle", null);
- Object bundle = mainBundleMethod.invoke(null, null);
-
- if (bundle != null) {
- // Get the path to the bundle's "Frameworks" directory
- Method fwPathMethod = bundleClass.getMethod("privateFrameworksPath",
- null);
- String path = (String) fwPathMethod.invoke(bundle, null);
-
- // look for libxpcom.dylib
- if (path.length() != 0) {
- File xulDir = new File(path, "XUL.framework");
- if (xulDir.isDirectory()) {
- File xpcomLib = new File(xulDir, "libxpcom.dylib");
- if (xpcomLib.canRead()) {
- File grePath = xpcomLib.getCanonicalFile().getParentFile();
-
- // Since GRE Properties aren't supported on Mac OS X, we check
- // for the existence of the "javaxpcom.jar" file in the GRE.
- File jar = new File(grePath, JAVAXPCOM_JAR);
- if (jar.canRead()) {
- // found GRE
- return grePath;
- }
- }
- }
- }
- }
- } catch (Exception e) { }
-
- return null;
- }
-
- /**
- * @param aRootPath
- * @param aVersions
- * @return
- */
- private static File findGREFramework(String aRootPath,
- GREVersionRange[] aVersions) {
- File frameworkDir = new File(aRootPath +
- "/Library/Frameworks/XUL.framework/Versions");
- if (!frameworkDir.exists())
- return null;
-
- File[] files = frameworkDir.listFiles();
- for (int i = 0; i < files.length; i++) {
- if (checkVersion(files[i].getName(), aVersions)) {
- File xpcomLib = new File(files[i], "libxpcom.dylib");
-
- // Since GRE Properties aren't supported on Mac OS X, we check
- // for the existence of the "javaxpcom.jar" file in the GRE.
- File jar = new File(files[i], JAVAXPCOM_JAR);
- if (xpcomLib.canRead() && jar.canRead()) {
- return files[i];
- }
- }
- }
-
- return null;
- }
-
- /**
- * @param aVersions
- * @param aProperties
- * @return
- */
- private static File getGREPathWindows(GREVersionRange[] aVersions,
- Properties aProperties) {
- /*
- * Note the usage of the "Software\\mozilla.org\\GRE" subkey - this allows
- * us to have multiple versions of GREs on the same machine by having
- * subkeys such as 1.0, 1.1, 2.0 etc. under it.
- *
- * Please see http://www.mozilla.org/projects/embedding/GRE.html for
- * more info.
- */
-
- final String greKey = "Software\\mozilla.org\\GRE";
-
- // See if there is a GRE registered for the current user.
- // If not, look for one on the system.
- String key = "HKEY_CURRENT_USER" + "\\" + greKey;
- File grePath = getGREPathFromRegKey(key, aVersions, aProperties);
- if (grePath == null) {
- key = "HKEY_LOCAL_MACHINE" + "\\" + greKey;
- grePath = getGREPathFromRegKey(key, aVersions, aProperties);
- }
-
- return grePath;
- }
-
- /**
- * @param aRegKey
- * @param aVersions
- * @param aProperties
- * @return
- */
- private static File getGREPathFromRegKey(String aRegKey,
- GREVersionRange[] aVersions, Properties aProperties) {
- // create a temp file for the registry export
- File tempFile;
- try {
- tempFile = File.createTempFile("jx_registry", null);
- } catch (IOException e) {
- // failed to create temp file. ABORT
- return null;
- }
-
- Process proc;
- try {
- proc = Runtime.getRuntime().exec("regedit /e " + "\"" + tempFile.getPath()
- + "\" \"" + aRegKey + "\"");
- proc.waitFor();
- } catch (Exception e) {
- // Failed to run regedit.exe. Length of temp file is zero, and that's
- // handled next.
- }
-
- // If there is a key by that name in the registry, then the file length
- // will not be zero.
- File grePath = null;
- if (tempFile.length() != 0) {
- grePath = getGREPathFromRegistryFile(tempFile.getPath(),
- aRegKey, aVersions, aProperties);
- }
-
- tempFile.delete();
- return grePath;
- }
-
- /**
- * @param aFileName
- * @param aCharset
- * @param aKeyName
- * @param aVersions
- * @param aProperties
- * @return
- */
- private static File getGREPathFromRegistryFile(String aFileName,
- String aKeyName, GREVersionRange[] aVersions,
- Properties aProperties) {
- INIParser parser;
- try {
- parser = new INIParser(aFileName, Charset.forName("UTF-16"));
- } catch (Exception e) {
- // Problem reading from file. Bail out.
- return null;
- }
-
- Iterator sectionsIter = parser.getSections();
- while (sectionsIter.hasNext()) {
- // get 'section' name, which will be a registry key name
- String section = (String) sectionsIter.next();
-
- // Skip over GRE key ("<root>\Software\mozilla.org\GRE")
- int gre_len = aKeyName.length();
- if (section.length() <= gre_len) {
- continue;
- }
-
- // Get the GRE subkey; that is, everything after
- // "<root>\Software\mozilla.org\GRE\"
- String subkeyName = section.substring(gre_len + 1);
-
- // We are only interested in _immediate_ subkeys. We want
- // "<root>\Software\mozilla.org\GRE\<version>" but not
- // "<root>\Software\mozilla.org\GRE\<version>\<moretext>".
- if (subkeyName.indexOf('\\') != -1) {
- continue;
- }
-
- // See if this registry key has a "Version" value, and if so, compare
- // it to our desired versions.
- String version = parser.getString(section, "\"Version\"");
- if (version == null) {
- continue;
- }
- // remove quotes around string
- version = version.substring(1, version.length() - 1);
- if (!checkVersion(version, aVersions)) {
- continue;
- }
-
- // All properties must match, keeping in mind that the propery/value
- // pairs returned by regedit.exe have quotes around them.
- if (aProperties != null) {
- boolean ok = true;
- Enumeration e = aProperties.propertyNames();
- while (ok && e.hasMoreElements()) {
- String prop = (String) e.nextElement();
- String greValue = parser.getString(section, "\"" + prop + "\"");
- if (greValue == null) {
- // No such property is set for this GRE. Go on to next GRE.
- ok = false;
- } else {
- // See if the value of the property for the GRE matches
- // the given value.
- String value = aProperties.getProperty(prop);
- if (!greValue.equals("\"" + value + "\"")) {
- ok = false;
- }
- }
- }
- if (!ok) {
- continue;
- }
- }
-
- String pathStr = parser.getString(section, "\"GreHome\"");
- if (pathStr != null) {
- // remove quotes around string
- pathStr = pathStr.substring(1, pathStr.length() - 1);
- File grePath = new File(pathStr);
- if (grePath.exists()) {
- File xpcomLib = new File(grePath, "xpcom.dll");
- if (xpcomLib.canRead()) {
- // found a good GRE
- return grePath;
- }
- }
- }
- }
-
- return null;
- }
-
- /**
- * @param aVersions
- * @param aProperties
- * @return
- */
- private static File getGREPathUnix(GREVersionRange[] aVersions,
- Properties aProperties) {
- File grePath = null;
-
- String env = System.getProperty("MOZ_GRE_CONF");
- if (env != null) {
- grePath = getPathFromConfigFile(env, aVersions, aProperties);
- if (grePath != null) {
- return grePath;
- }
- }
-
- final String greUserConfFile = ".gre.config";
- final String greUserConfDir = ".gre.d";
- final String greConfPath = "/etc/gre.conf";
- final String greConfDir = "/etc/gre.d";
-
- env = System.getProperty("user.home");
- if (env != null) {
- // Look in ~/.gre.config
- grePath = getPathFromConfigFile(env + File.separator + greUserConfFile,
- aVersions, aProperties);
- if (grePath != null) {
- return grePath;
- }
-
- // Look in ~/.gre.d/*.conf
- grePath = getPathFromConfigDir(env + File.separator + greUserConfDir,
- aVersions, aProperties);
- if (grePath != null) {
- return grePath;
- }
- }
-
- // Look for a global /etc/gre.conf file
- grePath = getPathFromConfigFile(greConfPath, aVersions, aProperties);
- if (grePath != null) {
- return grePath;
- }
-
- // Look for a group of config files in /etc/gre.d/
- grePath = getPathFromConfigDir(greConfDir, aVersions, aProperties);
- return grePath;
- }
-
- /**
- * @param aFileName
- * @param aVersions
- * @param aProperties
- * @return
- */
- private static File getPathFromConfigFile(String aFileName,
- GREVersionRange[] aVersions, Properties aProperties) {
- INIParser parser;
- try {
- parser = new INIParser(aFileName);
- } catch (Exception e) {
- // Problem reading from file. Bail out.
- return null;
- }
-
- Iterator sectionsIter = parser.getSections();
- while (sectionsIter.hasNext()) {
- // get 'section' name, which will be a version string
- String section = (String) sectionsIter.next();
-
- // if this isn't one of the versions we are looking for, move
- // on to next section
- if (!checkVersion(section, aVersions)) {
- continue;
- }
-
- // all properties must match
- if (aProperties != null) {
- boolean ok = true;
- Enumeration e = aProperties.propertyNames();
- while (ok && e.hasMoreElements()) {
- String prop = (String) e.nextElement();
- String greValue = parser.getString(section, prop);
- if (greValue == null) {
- // No such property is set for this GRE. Go on to next GRE.
- ok = false;
- } else {
- // See if the value of the property for the GRE matches
- // the given value.
- if (!greValue.equals(aProperties.getProperty(prop))) {
- ok = false;
- }
- }
- }
- if (!ok) {
- continue;
- }
- }
-
- String pathStr = parser.getString(section, "GRE_PATH");
- if (pathStr != null) {
- File grePath = new File(pathStr);
- if (grePath.exists()) {
- File xpcomLib = new File(grePath, "libxpcom.so");
- if (xpcomLib.canRead()) {
- // found a good GRE
- return grePath;
- }
- }
- }
- }
-
- return null;
- }
-
- /**
- * @param aDirName
- * @param aVersions
- * @param aProperties
- * @return
- */
- private static File getPathFromConfigDir(String aDirName,
- GREVersionRange[] aVersions, Properties aProperties) {
- /*
- * Open the directory provided and try to read any files in that
- * directory that end with .conf. We look for an entry that might
- * point to the GRE that we're interested in.
- */
-
- File dir = new File(aDirName);
- if (!dir.isDirectory()) {
- return null;
- }
-
- File grePath = null;
- File[] files = dir.listFiles();
- for (int i = 0; i < files.length && grePath == null; i++) {
- // only look for files that end in '.conf'
- if (!files[i].getName().endsWith(".conf")) {
- continue;
- }
-
- grePath = getPathFromConfigFile(files[i].getPath(), aVersions,
- aProperties);
- }
-
- return grePath;
- }
-
- /**
- * @param aVersionToCheck
- * @param aVersions
- * @return
- */
- private static boolean checkVersion(String aVersionToCheck,
- GREVersionRange[] aVersions) {
- for (int i = 0; i < aVersions.length; i++) {
- if (aVersions[i].check(aVersionToCheck)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Initialize the Mozilla object with the given XULRunner path. All
- * subsequent Mozilla method invocations be done against the given XULRunner
- * version.
- *
- * @param aLibXULDirectory path of XULRunner build to use
- *
- * @throws XPCOMInitializationException if failure occurred during
- * initialization
- */
- public void initialize(File aLibXULDirectory)
- throws XPCOMInitializationException {
- File jar = new File(aLibXULDirectory, JAVAXPCOM_JAR);
- if (!jar.exists()) {
- throw new XPCOMInitializationException("Could not find " + JAVAXPCOM_JAR +
- " in " + aLibXULDirectory);
- }
-
- URL[] urls = new URL[1];
- try {
- urls[0] = jar.toURL();
- } catch (MalformedURLException e) {
- throw new XPCOMInitializationException(e);
- }
- ClassLoader loader = new URLClassLoader(urls,
- this.getClass().getClassLoader());
-
- try {
- Class mozillaClass = Class.forName("org.mozilla.xpcom.internal.MozillaImpl",
- true, loader);
- mozilla = (IMozilla) mozillaClass.newInstance();
-
- Class greClass = Class.forName("org.mozilla.xpcom.internal.GREImpl",
- true, loader);
- gre = (IGRE) greClass.newInstance();
-
- Class xpcomClass = Class.forName("org.mozilla.xpcom.internal.XPCOMImpl",
- true, loader);
- xpcom = (IXPCOM) xpcomClass.newInstance();
-
- Class javaXPCOMClass =
- Class.forName("org.mozilla.xpcom.internal.JavaXPCOMMethods",
- true, loader);
- jxutils = (IJavaXPCOMUtils) javaXPCOMClass.newInstance();
- } catch (Exception e) {
- throw new XPCOMInitializationException("Could not load " +
- "org.mozilla.xpcom.internal.* classes", e);
- }
-
- mozilla.initialize(aLibXULDirectory);
- }
-
- /**
- * Initializes libXUL for embedding purposes.
- * <p>
- * NOTE: This function must be called from the "main" thread.
- * <p>
- * NOTE: At the present time, this function may only be called once in
- * a given process. Use <code>termEmbedding</code> to clean up and free
- * resources allocated by <code>initEmbedding</code>.
- *
- * @param aLibXULDirectory The directory in which the libXUL shared library
- * was found.
- * @param aAppDirectory The directory in which the application components
- * and resources can be found. This will map to
- * the "resource:app" directory service key.
- * @param aAppDirProvider A directory provider for the application. This
- * provider will be aggregated by a libXUL provider
- * which will provide the base required GRE keys.
- *
- * @throws XPCOMException if a failure occurred during initialization
- * @throws XPCOMInitializationException if Mozilla was not properly
- * initialized
- */
- public void initEmbedding(File aLibXULDirectory, File aAppDirectory,
- IAppFileLocProvider aAppDirProvider) throws XPCOMException {
- try {
- gre.initEmbedding(aLibXULDirectory, aAppDirectory, aAppDirProvider);
- } catch (NullPointerException e) {
- throw new XPCOMInitializationException("Must call " +
- "Mozilla.getInstance().initialize() before using this method", e);
- }
- }
-
- /**
- * Terminates libXUL embedding.
- * <p>
- * NOTE: Release any references to XPCOM objects that you may be holding
- * before calling this function.
- *
- * @throws XPCOMInitializationException if Mozilla was not properly
- * initialized
- */
- public void termEmbedding() {
- try {
- gre.termEmbedding();
- } catch (NullPointerException e) {
- throw new XPCOMInitializationException("Must call " +
- "Mozilla.getInstance().initialize() before using this method", e);
- } finally {
- mozilla = null;
- gre = null;
- xpcom = null;
- }
- }
-
- /**
- * Lock a profile directory using platform-specific semantics.
- *
- * @param aDirectory The profile directory to lock.
- *
- * @return A lock object. The directory will remain locked until the lock is
- * released by invoking the <code>release</code> method, or by the
- * termination of the JVM, whichever comes first.
- *
- * @throws XPCOMException if profile is already locked (with
- * <code>errorcode</code> == <code>NS_ERROR_FILE_ACCESS_DENIED</code>);
- * or if a failure occurred
- * @throws XPCOMInitializationException if Mozilla was not properly
- * initialized
- */
- public ProfileLock lockProfileDirectory(File aDirectory)
- throws XPCOMException {
- try {
- return gre.lockProfileDirectory(aDirectory);
- } catch (NullPointerException e) {
- throw new XPCOMInitializationException("Must call " +
- "Mozilla.getInstance().initialize() before using this method", e);
- }
- }
-
- /**
- * Fire notifications to inform the toolkit about a new profile. This
- * method should be called after <code>initEmbedding</code> if the
- * embedder wishes to run with a profile.
- * <p>
- * Normally the embedder should call <code>lockProfileDirectory</code>
- * to lock the directory before calling this method.
- * <p>
- * NOTE: There are two possibilities for selecting a profile:
- * <ul>
- * <li>
- * Select the profile before calling <code>initEmbedding</code>.
- * The aAppDirProvider object passed to <code>initEmbedding</code>
- * should provide the NS_APP_USER_PROFILE_50_DIR key, and
- * may also provide the following keys:
- * <ul>
- * <li>NS_APP_USER_PROFILE_LOCAL_50_DIR
- * <li>NS_APP_PROFILE_DIR_STARTUP
- * <li>NS_APP_PROFILE_LOCAL_DIR_STARTUP
- * </ul>
- * In this scenario <code>notifyProfile</code> should be called
- * immediately after <code>initEmbedding</code>. Component
- * registration information will be stored in the profile and
- * JS components may be stored in the fastload cache.
- * </li>
- * <li>
- * Select a profile some time after calling <code>initEmbedding</code>.
- * In this case the embedder must install a directory service
- * provider which provides NS_APP_USER_PROFILE_50_DIR and optionally
- * NS_APP_USER_PROFILE_LOCAL_50_DIR. Component registration information
- * will be stored in the application directory and JS components will not
- * fastload.
- * </li>
- * </ul>
- *
- * @throws XPCOMInitializationException if Mozilla was not properly
- * initialized
- */
- public void notifyProfile() {
- try {
- gre.notifyProfile();
- } catch (NullPointerException e) {
- throw new XPCOMInitializationException("Must call " +
- "Mozilla.getInstance().initialize() before using this method", e);
- }
- }
-
- /**
- * Initializes XPCOM. You must call this method before proceeding
- * to use XPCOM.
- *
- * @param aMozBinDirectory The directory containing the component
- * registry and runtime libraries;
- * or use <code>null</code> to use the working
- * directory.
- *
- * @param aAppFileLocProvider The object to be used by Gecko that specifies
- * to Gecko where to find profiles, the component
- * registry preferences and so on; or use
- * <code>null</code> for the default behaviour.
- *
- * @return the service manager
- *
- * @throws XPCOMException <ul>
- * <li> NS_ERROR_NOT_INITIALIZED - if static globals were not initialied,
- * which can happen if XPCOM is reloaded, but did not completly
- * shutdown. </li>
- * <li> Other error codes indicate a failure during initialisation. </li>
- * </ul>
- * @throws XPCOMInitializationException if Mozilla was not properly
- * initialized
- */
- public nsIServiceManager initXPCOM(File aMozBinDirectory,
- IAppFileLocProvider aAppFileLocProvider) throws XPCOMException {
- try {
- return xpcom.initXPCOM(aMozBinDirectory, aAppFileLocProvider);
- } catch (NullPointerException e) {
- throw new XPCOMInitializationException("Must call " +
- "Mozilla.getInstance().initialize() before using this method", e);
- }
- }
-
- /**
- * Shutdown XPCOM. You must call this method after you are finished
- * using xpcom.
- *
- * @param aServMgr The service manager which was returned by initXPCOM.
- * This will release servMgr.
- *
- * @throws XPCOMException if a failure occurred during termination
- * @throws XPCOMInitializationException if Mozilla was not properly
- * initialized
- */
- public void shutdownXPCOM(nsIServiceManager aServMgr) throws XPCOMException {
- try {
- xpcom.shutdownXPCOM(aServMgr);
- } catch (NullPointerException e) {
- throw new XPCOMInitializationException("Must call " +
- "Mozilla.getInstance().initialize() before using this method", e);
- } finally {
- mozilla = null;
- gre = null;
- xpcom = null;
- }
- }
-
- /**
- * Public Method to access to the service manager.
- *
- * @return the service manager
- *
- * @throws XPCOMException if a failure occurred
- * @throws XPCOMInitializationException if Mozilla was not properly
- * initialized
- */
- public nsIServiceManager getServiceManager() throws XPCOMException {
- try {
- return xpcom.getServiceManager();
- } catch (NullPointerException e) {
- throw new XPCOMInitializationException("Must call " +
- "Mozilla.getInstance().initialize() before using this method", e);
- }
- }
-
- /**
- * Public Method to access to the component manager.
- *
- * @return the component manager
- *
- * @throws XPCOMException if a failure occurred
- * @throws XPCOMInitializationException if Mozilla was not properly
- * initialized
- */
- public nsIComponentManager getComponentManager() throws XPCOMException {
- try {
- return xpcom.getComponentManager();
- } catch (NullPointerException e) {
- throw new XPCOMInitializationException("Must call " +
- "Mozilla.getInstance().initialize() before using this method", e);
- }
- }
-
- /**
- * Public Method to access to the component registration manager.
- *
- * @return the component registration manager
- *
- * @throws XPCOMException if a failure occurred
- * @throws XPCOMInitializationException if Mozilla was not properly
- * initialized
- */
- public nsIComponentRegistrar getComponentRegistrar() throws XPCOMException {
- try {
- return xpcom.getComponentRegistrar();
- } catch (NullPointerException e) {
- throw new XPCOMInitializationException("Must call " +
- "Mozilla.getInstance().initialize() before using this method", e);
- }
- }
-
- /**
- * Public Method to create an instance of a nsILocalFile.
- *
- * @param aPath A string which specifies a full file path to a
- * location. Relative paths will be treated as an
- * error (NS_ERROR_FILE_UNRECOGNIZED_PATH).
- * @param aFollowLinks This attribute will determine if the nsLocalFile will
- * auto resolve symbolic links. By default, this value
- * will be false on all non unix systems. On unix, this
- * attribute is effectively a noop.
- *
- * @return an instance of an nsILocalFile that points to given path
- *
- * @throws XPCOMException <ul>
- * <li> NS_ERROR_FILE_UNRECOGNIZED_PATH - raised for unrecognized paths
- * or relative paths (must supply full file path) </li>
- * </ul>
- * @throws XPCOMInitializationException if Mozilla was not properly
- * initialized
- */
- public nsILocalFile newLocalFile(String aPath, boolean aFollowLinks)
- throws XPCOMException {
- try {
- return xpcom.newLocalFile(aPath, aFollowLinks);
- } catch (NullPointerException e) {
- throw new XPCOMInitializationException("Must call " +
- "Mozilla.getInstance().initialize() before using this method", e);
- }
- }
-
- /**
- * If you create a class that implements nsISupports, you will need to provide
- * an implementation of the <code>queryInterface</code> method. This helper
- * function provides a simple implementation. Therefore, if your class does
- * not need to do anything special with <code>queryInterface</code>, your
- * implementation would look like:
- * <pre>
- * public nsISupports queryInterface(String aIID) {
- * return XPCOM.queryInterface(this, aIID);
- * }
- * </pre>
- *
- * @param aObject object to query
- * @param aIID requested interface IID
- *
- * @return <code>aObject</code> if the given object supports that
- * interface;
- * <code>null</code> otherwise.
- */
- public static nsISupports queryInterface(nsISupports aObject, String aIID) {
- ArrayList classes = new ArrayList();
- classes.add(aObject.getClass());
-
- while (!classes.isEmpty()) {
- Class clazz = (Class) classes.remove(0);
-
- // Skip over any class/interface in the "java.*" and "javax.*" domains.
- String className = clazz.getName();
- if (className.startsWith("java.") || className.startsWith("javax.")) {
- continue;
- }
-
- // If given IID matches that of the current interface, then we
- // know that aObject implements the interface specified by the given IID.
- if (clazz.isInterface() && className.startsWith("org.mozilla")) {
- String iid = Mozilla.getInterfaceIID(clazz);
- if (iid != null && aIID.equals(iid)) {
- return aObject;
- }
- }
-
- // clazz didn't match, so add the interfaces it implements
- Class[] interfaces = clazz.getInterfaces();
- for (int i = 0; i < interfaces.length; i++ ) {
- classes.add(interfaces[i]);
- }
-
- // Also add its superclass
- Class superclass = clazz.getSuperclass();
- if (superclass != null) {
- classes.add(superclass);
- }
- }
-
- return null;
- }
-
- /**
- * Gets the interface IID for a particular Java interface. This is similar
- * to NS_GET_IID in the C++ Mozilla files.
- *
- * @param aInterface interface which has defined an IID
- *
- * @return IID for given interface
- */
- public static String getInterfaceIID(Class aInterface) {
- // Get short class name (i.e. "bar", not "org.blah.foo.bar")
- StringBuffer iidName = new StringBuffer();
- String fullClassName = aInterface.getName();
- int index = fullClassName.lastIndexOf(".");
- String className = index > 0 ? fullClassName.substring(index + 1)
- : fullClassName;
-
- // Create iid field name
- if (className.startsWith("ns")) {
- iidName.append("NS_");
- iidName.append(className.substring(2).toUpperCase());
- } else {
- iidName.append(className.toUpperCase());
- }
- iidName.append("_IID");
-
- String iid;
- try {
- Field iidField = aInterface.getDeclaredField(iidName.toString());
- iid = (String) iidField.get(null);
- } catch (NoSuchFieldException e) {
- // Class may implement non-Mozilla interfaces, which would not have an
- // IID method. In that case, just null.
- iid = null;
- } catch (IllegalAccessException e) {
- // Not allowed to access that field for some reason. Write out an
- // error message, but don't fail.
- System.err.println("ERROR: Could not get field " + iidName.toString());
- iid = null;
- }
-
- return iid;
- }
-
- public long getNativeHandleFromAWT(Object widget) {
- try {
- return mozilla.getNativeHandleFromAWT(widget);
- } catch (NullPointerException e) {
- throw new XPCOMInitializationException("Must call " +
- "Mozilla.getInstance().initialize() before using this method", e);
- }
- }
-
- public long wrapJavaObject(Object aJavaObject, String aIID) {
- try {
- return jxutils.wrapJavaObject(aJavaObject, aIID);
- } catch (NullPointerException e) {
- throw new XPCOMInitializationException("Must call " +
- "Mozilla.getInstance().initialize() before using this method", e);
- }
- }
-
- public Object wrapXPCOMObject(long aXPCOMObject, String aIID) {
- try {
- return jxutils.wrapXPCOMObject(aXPCOMObject, aIID);
- } catch (NullPointerException e) {
- throw new XPCOMInitializationException("Must call " +
- "Mozilla.getInstance().initialize() before using this method", e);
- }
- }
-
-}
deleted file mode 100644
--- a/extensions/java/xpcom/interfaces/org/mozilla/xpcom/ProfileLock.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2006
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 ***** */
-
-package org.mozilla.xpcom;
-
-public class ProfileLock {
-
- private long lock = 0;
-
- public ProfileLock(long aLockObject) {
- lock = aLockObject;
- }
-
- public void release() {
- releaseNative(lock);
- lock = 0;
- }
-
- private native void releaseNative(long aLockObject);
-
- public boolean isValid() {
- return lock != 0;
- }
-
- protected void finalize() throws Throwable {
- release();
- super.finalize();
- }
-
-}
deleted file mode 100644
--- a/extensions/java/xpcom/interfaces/org/mozilla/xpcom/VersionComparator.java
+++ /dev/null
@@ -1,273 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is
- * IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2005
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 ***** */
-
-package org.mozilla.xpcom;
-
-import java.util.Enumeration;
-import java.util.StringTokenizer;
-
-import org.mozilla.interfaces.nsISupports;
-import org.mozilla.interfaces.nsIVersionComparator;
-
-
-/**
- * Version strings are dot-separated sequences of version-parts.
- * <p>
- * A version-part consists of up to four parts, all of which are optional:
- * <br><code>
- * <number-a><string-b><number-c>
- * <string-d (everything else)>
- * </code> <p>
- * A version-part may also consist of a single asterisk "*" which indicates
- * "infinity".
- * <p>
- * Numbers are base-10, and are zero if left out.
- * Strings are compared bytewise.
- * <p>
- * For additional backwards compatibility, if "string-b" is "+" then
- * "number-a" is incremented by 1 and "string-b" becomes "pre".
- * <p> <pre>
- * 1.0pre1
- * < 1.0pre2
- * < 1.0 == 1.0.0 == 1.0.0.0
- * < 1.1pre == 1.1pre0 == 1.0+
- * < 1.1pre1a
- * < 1.1pre1
- * < 1.1pre10a
- * < 1.1pre10
- * </pre>
- * Although not required by this interface, it is recommended that
- * numbers remain within the limits of a signed char, i.e. -127 to 128.
- */
-public class VersionComparator implements nsIVersionComparator {
-
- public nsISupports queryInterface(String aIID) {
- return Mozilla.queryInterface(this, aIID);
- }
-
- /**
- * Compare two version strings
- * @param A a version string
- * @param B a version string
- * @return a value less than 0 if A < B;
- * the value 0 if A == B;
- * or a value greater than 0 if A > B
- */
- public int compare(String A, String B) {
- int result;
- String a = A, b = B;
-
- do {
- VersionPart va = new VersionPart();
- VersionPart vb = new VersionPart();
- a = parseVersionPart(a, va);
- b = parseVersionPart(b, vb);
-
- result = compareVersionPart(va, vb);
- if (result != 0) {
- break;
- }
- } while (a != null || b != null);
-
- return result;
- }
-
- private class VersionPart {
- int numA = 0;
- String strB;
- int numC = 0;
- String extraD;
- }
-
- private static String parseVersionPart(String aVersion, VersionPart result) {
- if (aVersion == null || aVersion.length() == 0) {
- return aVersion;
- }
-
- StringTokenizer tok = new StringTokenizer(aVersion.trim(), ".");
- String part = tok.nextToken();
-
- if (part.equals("*")) {
- result.numA = Integer.MAX_VALUE;
- result.strB = "";
- } else {
- VersionPartTokenizer vertok = new VersionPartTokenizer(part);
- try {
- result.numA = Integer.parseInt(vertok.nextToken());
- } catch (NumberFormatException e) {
- // parsing error; default to zero like 'strtol' C function
- result.numA = 0;
- }
-
- if (vertok.hasMoreElements()) {
- String str = vertok.nextToken();
-
- // if part is of type "<num>+"
- if (str.charAt(0) == '+') {
- result.numA++;
- result.strB = "pre";
- } else {
- // else if part is of type "<num><alpha>..."
- result.strB = str;
-
- if (vertok.hasMoreTokens()) {
- try {
- result.numC = Integer.parseInt(vertok.nextToken());
- } catch (NumberFormatException e) {
- // parsing error; default to zero like 'strtol' C function
- result.numC = 0;
- }
- if (vertok.hasMoreTokens()) {
- result.extraD = vertok.getRemainder();
- }
- }
- }
- }
- }
-
- if (tok.hasMoreTokens()) {
- // return everything after "."
- return aVersion.substring(part.length() + 1);
- }
- return null;
- }
-
- private int compareVersionPart(VersionPart va, VersionPart vb) {
- int res = compareInt(va.numA, vb.numA);
- if (res != 0) {
- return res;
- }
-
- res = compareString(va.strB, vb.strB);
- if (res != 0) {
- return res;
- }
-
- res = compareInt(va.numC, vb.numC);
- if (res != 0) {
- return res;
- }
-
- return compareString(va.extraD, vb.extraD);
- }
-
- private int compareInt(int n1, int n2) {
- return n1 - n2;
- }
-
- private int compareString(String str1, String str2) {
- // any string is *before* no string
- if (str1 == null) {
- return (str2 != null) ? 1 : 0;
- }
-
- if (str2 == null) {
- return -1;
- }
-
- return str1.compareTo(str2);
- }
-
-}
-
-/**
- * Specialized tokenizer for Mozilla version strings. A token can
- * consist of one of the four sections of a version string: <code>
- * <number-a><string-b><number-c>
- * <string-d (everything else)></code>.
- */
-class VersionPartTokenizer implements Enumeration {
-
- String part;
-
- public VersionPartTokenizer(String aPart) {
- part = aPart;
- }
-
- public boolean hasMoreElements() {
- return part.length() != 0;
- }
-
- public boolean hasMoreTokens() {
- return part.length() != 0;
- }
-
- public Object nextElement() {
- if (part.matches("[\\+\\-]?[0-9].*")) {
- // if string starts with a number...
- int index = 0;
- if (part.charAt(0) == '+' || part.charAt(0) == '-') {
- index = 1;
- }
-
- while (index < part.length() && Character.isDigit(part.charAt(index))) {
- index++;
- }
-
- String numPart = part.substring(0, index);
- part = part.substring(index);
- return numPart;
- } else {
- // ... or if this is the non-numeric part of version string
- int index = 0;
- while (index < part.length() && !Character.isDigit(part.charAt(index))) {
- index++;
- }
-
- String alphaPart = part.substring(0, index);
- part = part.substring(index);
- return alphaPart;
- }
- }
-
- public String nextToken() {
- return (String) nextElement();
- }
-
- /**
- * Returns what remains of the original string, without tokenization. This
- * method is useful for getting the <code><string-d (everything else)>
- * </code> section of a version string.
- *
- * @return remaining version string
- */
- public String getRemainder() {
- return part;
- }
-
-}
-
deleted file mode 100644
--- a/extensions/java/xpcom/interfaces/org/mozilla/xpcom/XPCOMException.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is
- * IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2004
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 ***** */
-
-package org.mozilla.xpcom;
-
-
-/**
- * This exception is thrown whenever an internal XPCOM/Gecko error occurs.
- * You can query the error ID returned by XPCOM by checking
- * <code>errorcode</code> field.
- */
-public class XPCOMException extends RuntimeException {
-
- /**
- * The XPCOM error value.
- */
- public long errorcode;
-
- private static final long serialVersionUID = 198521829884000593L;
-
- /**
- * Constructs a new XPCOMException instance, with a default error
- * (NS_ERROR_FAILURE) and message.
- */
- public XPCOMException() {
- this(0x80004005L, "Unspecified internal XPCOM error");
- }
-
- /**
- * Constructs a new XPCOMException instance with the given message, passing
- * NS_ERROR_FAILURE as the error code.
- *
- * @param message detailed message of exception
- */
- public XPCOMException(String message) {
- this(0x80004005L, message);
- }
-
- /**
- * Constructs a new XPCOMException instance with the given code, passing
- * a default message.
- *
- * @param code internal XPCOM error ID
- */
- public XPCOMException(long code) {
- this(code, "Internal XPCOM error");
- }
-
- /**
- * Constructs a new XPCOMException instance with an error code and message.
- *
- * @param code internal XPCOM error ID
- * @param message detailed message of exception
- */
- public XPCOMException(long code, String message) {
- super(message + " (0x" + Long.toHexString(code) + ")");
- this.errorcode = code;
- }
-
-}
-
deleted file mode 100644
--- a/extensions/java/xpcom/interfaces/org/mozilla/xpcom/XPCOMInitializationException.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2006
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 ***** */
-
-package org.mozilla.xpcom;
-
-
-public class XPCOMInitializationException extends RuntimeException {
-
- private static final long serialVersionUID = -7067350325909231055L;
-
- public XPCOMInitializationException(String message) {
- super(message);
- }
-
- public XPCOMInitializationException(Throwable cause) {
- super(cause);
- }
-
- public XPCOMInitializationException(String message, Throwable cause) {
- super(message, cause);
- }
-
-}
deleted file mode 100644
--- a/extensions/java/xpcom/package/Makefile.in
+++ /dev/null
@@ -1,84 +0,0 @@
-# ***** 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
-# IBM Corporation.
-# Portions created by the Initial Developer are Copyright (C) 2005
-# the Initial Developer. All Rights Reserved.
-#
-# Contributor(s):
-# Brian Ryner <bryner@brianryner.com>
-# Javier Pedemonte <jhpedemonte@gmail.com>
-#
-# 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 *****
-
-
-DEPTH = ../../../..
-topsrcdir = @top_srcdir@
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-include $(DEPTH)/config/autoconf.mk
-
-ifeq ($(OS_ARCH),WINNT)
-PKGCP_PLATFORM = dos
-PACKAGE_FILE = packages-win
-else
-PKGCP_PLATFORM=unix
-ifeq ($(OS_ARCH),Darwin)
-PACKAGE_FILE = packages-mac
-else
-PACKAGE_FILE = packages-unix
-endif
-endif
-
-PACKAGE_VERSION = 0.1
-
-GARBAGE += javaconnect.js javaconnect.template
-GARBAGE_DIRS += stage
-
-include $(topsrcdir)/config/rules.mk
-
-stage/javaconnect/.done:
- @echo Copying files to staging area...
- rm -rf stage
- $(NSINSTALL) -D stage
- $(PERL) $(topsrcdir)/xpinstall/packager/pkgcp.pl -o $(PKGCP_PLATFORM) \
- -s $(DIST) -d stage -f $(srcdir)/$(PACKAGE_FILE) -v
-
-javaconnect.js: stage/javaconnect/.done
- @echo Creating $@...
- rm -f javaconnect.js
- @if test ! -e "javaconnect.jst"; then \
- $(INSTALL) -m 644 $(srcdir)/javaconnect.jst .; \
- fi
- $(PERL) $(topsrcdir)/toolkit/mozapps/installer/makejs.pl javaconnect.jst \
- $(PACKAGE_VERSION) stage/javaconnect
-
-xpi: javaconnect.js
- @echo Creating XPI...
- $(PERL) $(topsrcdir)/toolkit/mozapps/installer/makexpi.pl javaconnect stage .
deleted file mode 100755
--- a/extensions/java/xpcom/package/javaconnect.jst
+++ /dev/null
@@ -1,24 +0,0 @@
-var err = initInstall("Mozilla Javaconnect", "Javaconnect", "0.1");
-logComment("initInstall: " + err);
-
-var fProgram = getFolder("Program");
-var srLibs = $SpaceRequired$:bin;
-
-if (verifyDiskSpace(fProgram, srLibs))
-{
- err = addDirectory("", "0.1", "bin", fProgram, "", true);
- logComment("addDirectory(): " + err);
-
- if (err == SUCCESS)
- {
- err = performInstall();
- logComment("performInstall() returned: " + err);
- }
- else
- {
- cancelInstall();
- logComment("cancelInstall() due to error: "+err);
- }
-}
-else
- cancelInstall(INSUFFICIENT_DISK_SPACE);
deleted file mode 100755
--- a/extensions/java/xpcom/package/packages-mac
+++ /dev/null
@@ -1,3 +0,0 @@
-[javaconnect]
-bin/mozjava.jar
-bin/libjavaxpcom.jnilib
deleted file mode 100755
--- a/extensions/java/xpcom/package/packages-unix
+++ /dev/null
@@ -1,3 +0,0 @@
-[javaconnect]
-bin/mozjava.jar
-bin/libjavaxpcom.so
deleted file mode 100755
--- a/extensions/java/xpcom/package/packages-win
+++ /dev/null
@@ -1,3 +0,0 @@
-[javaconnect]
-bin/mozjava.jar
-bin/javaxpcom.dll
deleted file mode 100644
--- a/extensions/java/xpcom/src/MacJawt.mm
+++ /dev/null
@@ -1,47 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2006
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 <jni.h>
-#import <JavaVM/jawt_md.h>
-#include "prtypes.h"
-
-
-PRUint64 GetPlatformHandle(JAWT_DrawingSurfaceInfo* dsi)
-{
- JAWT_MacOSXDrawingSurfaceInfo* dsi_mac =
- static_cast<JAWT_MacOSXDrawingSurfaceInfo*> (dsi->platformInfo);
- return reinterpret_cast<PRUint64> (dsi_mac->cocoaViewRef);
-}
deleted file mode 100644
--- a/extensions/java/xpcom/src/Makefile.in
+++ /dev/null
@@ -1,119 +0,0 @@
-# ***** 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 Java XPCOM Bindings.
-#
-# The Initial Developer of the Original Code is IBM Corporation.
-# Portions created by the Initial Developer are Copyright (C) 2006
-# IBM Corporation. All Rights Reserved.
-#
-# Contributor(s):
-# Javier Pedemonte (jhpedemonte@gmail.com)
-#
-# 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 *****
-
-DEPTH = ../../../..
-topsrcdir = @top_srcdir@
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-include $(DEPTH)/config/autoconf.mk
-
-MODULE = javaxpcom
-LIBRARY_NAME = javaxpcom
-LIBXUL_LIBRARY = 1
-FORCE_STATIC_LIB = 1
-
-ifndef MOZ_ENABLE_LIBXUL
-DEFINES += -DIMPL_XREAPI
-endif
-
-
-CPPSRCS = \
- nsAppFileLocProviderProxy.cpp \
- nsJavaInterfaces.cpp \
- nsJavaWrapper.cpp \
- nsJavaXPTCStub.cpp \
- nsJavaXPTCStubWeakRef.cpp \
- nsJavaXPCOMBindingUtils.cpp \
- $(NULL)
-
-ifeq ($(OS_ARCH),Darwin)
-CMMSRCS = MacJawt.mm
-endif
-
-LOCAL_INCLUDES = -I$(JAVA_INCLUDE_PATH)
-
-ifeq ($(OS_ARCH),WINNT)
-LOCAL_INCLUDES += -I$(JAVA_INCLUDE_PATH)/win32
-else
-ifeq ($(OS_ARCH),OS2)
-LOCAL_INCLUDES += -I$(JAVA_INCLUDE_PATH)/OS2
-else
-ifeq ($(OS_ARCH),Darwin)
-LOCAL_INCLUDES += -I/System/Library/Frameworks/CoreFoundation.framework/Headers
-else
-ifeq ($(OS_ARCH),FreeBSD)
-LOCAL_INCLUDES += -I$(JAVA_INCLUDE_PATH)/freebsd
-else
-LOCAL_INCLUDES += -I$(JAVA_INCLUDE_PATH)/linux
-endif
-endif
-endif
-endif
-
-# Don't set JAVA_LIBRARY_NAME, since we don't want to build during 'libs'
-# stage, but rather when explicitly called.
-#JAVA_LIBRARY_NAME = javaxpcom
-JARFILE = javaxpcom.jar
-
-PACKAGE_DIR = org/mozilla/xpcom/internal
-
-JAVA_SRCS = \
- $(PACKAGE_DIR)/XPCOMJavaProxy.java \
- $(PACKAGE_DIR)/XPCOMJavaProxyBase.java \
- $(PACKAGE_DIR)/MozillaImpl.java \
- $(PACKAGE_DIR)/GREImpl.java \
- $(PACKAGE_DIR)/XPCOMImpl.java \
- $(PACKAGE_DIR)/JavaXPCOMMethods.java \
- $(NULL)
-
-JAVA_CLASSPATH = \
- ../interfaces/MozillaInterfaces.jar \
- ../interfaces/MozillaGlue.jar \
- $(NULL)
-
-GARBAGE += $(JARFILE)
-
-include $(topsrcdir)/config/rules.mk
-
-$(JARFILE): $(addprefix $(_JAVA_DIR)/,$(JAVA_SRCS:.java=.class)) Makefile Makefile.in
- $(JAR) cf $@ -C $(_JAVA_DIR) .
-
-jar-libs:: $(JARFILE)
- $(INSTALL) $(IFLAGS1) $(JARFILE) $(FINAL_TARGET)
-
-jar-install:: $(JARFILE)
- $(SYSINSTALL) $(IFLAGS2) $(JARFILE) $(DESTDIR)$(mozappdir)
deleted file mode 100644
--- a/extensions/java/xpcom/src/dlldeps-javaxpcom.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2006
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 "nsJavaInterfaces.h"
-
-
-void XXXNeverCalled_javaxpcom()
-{
- MOZILLA_NATIVE(initialize) (nsnull, nsnull);
-
- GRE_NATIVE(initEmbedding) (nsnull, nsnull, nsnull, nsnull, nsnull);
-
- GRE_NATIVE(termEmbedding) (nsnull, nsnull);
-
- GRE_NATIVE(lockProfileDirectory) (nsnull, nsnull, nsnull);
-
- GRE_NATIVE(notifyProfile) (nsnull, nsnull);
-
- GRE_NATIVE(lockProfileDirectory) (nsnull, nsnull, nsnull);
-
- GRE_NATIVE(notifyProfile) (nsnull, nsnull);
-
- XPCOM_NATIVE(initXPCOM) (nsnull, nsnull, nsnull, nsnull);
-
- XPCOM_NATIVE(shutdownXPCOM) (nsnull, nsnull, nsnull);
-
- XPCOM_NATIVE(newLocalFile) (nsnull, nsnull, nsnull, nsnull);
-
- XPCOM_NATIVE(getComponentManager) (nsnull, nsnull);
-
- XPCOM_NATIVE(getComponentRegistrar) (nsnull, nsnull);
-
- XPCOM_NATIVE(getServiceManager) (nsnull, nsnull);
-
- JAVAPROXY_NATIVE(callXPCOMMethod) (nsnull, nsnull, nsnull, nsnull, nsnull);
-
- JAVAPROXY_NATIVE(finalizeProxy) (nsnull, nsnull, nsnull);
-
- JAVAPROXY_NATIVE(isSameXPCOMObject) (nsnull, nsnull, nsnull, nsnull);
-
- LOCKPROXY_NATIVE(release) (nsnull, nsnull, nsnull);
-
- MOZILLA_NATIVE(getNativeHandleFromAWT) (nsnull, nsnull, nsnull);
-
- JXUTILS_NATIVE(wrapJavaObject) (nsnull, nsnull, nsnull, nsnull);
-
- JXUTILS_NATIVE(wrapXPCOMObject) (nsnull, nsnull, nsnull, nsnull);
-}
-
deleted file mode 100644
--- a/extensions/java/xpcom/src/nsAppFileLocProviderProxy.cpp
+++ /dev/null
@@ -1,253 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is
- * IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2005
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 "nsAppFileLocProviderProxy.h"
-#include "nsJavaXPCOMBindingUtils.h"
-#include "nsILocalFile.h"
-#include "nsISimpleEnumerator.h"
-
-
-nsAppFileLocProviderProxy::nsAppFileLocProviderProxy(jobject aJavaObject)
-{
- mJavaLocProvider = GetJNIEnv()->NewGlobalRef(aJavaObject);
-}
-
-nsAppFileLocProviderProxy::~nsAppFileLocProviderProxy()
-{
- GetJNIEnv()->DeleteGlobalRef(mJavaLocProvider);
-}
-
-NS_IMPL_ISUPPORTS2(nsAppFileLocProviderProxy,
- nsIDirectoryServiceProvider,
- nsIDirectoryServiceProvider2)
-
-
-// nsIDirectoryServiceProvider
-
-NS_IMETHODIMP
-nsAppFileLocProviderProxy::GetFile(const char* aProp, PRBool* aIsPersistant,
- nsIFile** aResult)
-{
- // Setup params for calling Java function
- JNIEnv* env = GetJNIEnv();
- jstring prop = env->NewStringUTF(aProp);
- if (!prop)
- return NS_ERROR_OUT_OF_MEMORY;
- jbooleanArray persistant = env->NewBooleanArray(1);
- if (!persistant)
- return NS_ERROR_OUT_OF_MEMORY;
-
- // Create method ID
- jmethodID mid = nsnull;
- jclass clazz = env->GetObjectClass(mJavaLocProvider);
- if (clazz) {
- mid = env->GetMethodID(clazz, "getFile",
- "(Ljava/lang/String;[Z)Ljava/io/File;");
- }
- if (!mid)
- return NS_ERROR_FAILURE;
-
- // Call Java function
- jobject javaFile = nsnull;
- javaFile = env->CallObjectMethod(mJavaLocProvider, mid, prop, persistant);
- if (javaFile == nsnull || env->ExceptionCheck())
- return NS_ERROR_FAILURE;
-
- // Set boolean output value
- env->GetBooleanArrayRegion(persistant, 0, 1, (jboolean*) aIsPersistant);
-
- // Set nsIFile result value
- nsCOMPtr<nsILocalFile> localFile;
- nsresult rv = File_to_nsILocalFile(env, javaFile, getter_AddRefs(localFile));
- if (NS_SUCCEEDED(rv)) {
- return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)aResult);
- }
-
- return rv;
-}
-
-
-// nsIDirectoryServiceProvider2
-
-class DirectoryEnumerator : public nsISimpleEnumerator
-{
-public:
- NS_DECL_ISUPPORTS
-
- DirectoryEnumerator(jobjectArray aJavaFileArray)
- : mIndex(0)
- {
- JNIEnv* env = GetJNIEnv();
- mJavaFileArray = static_cast<jobjectArray>
- (env->NewGlobalRef(aJavaFileArray));
- mArraySize = env->GetArrayLength(aJavaFileArray);
- }
-
- ~DirectoryEnumerator()
- {
- GetJNIEnv()->DeleteGlobalRef(mJavaFileArray);
- }
-
- NS_IMETHOD HasMoreElements(PRBool* aResult)
- {
- if (!mJavaFileArray) {
- *aResult = PR_FALSE;
- } else {
- *aResult = (mIndex < mArraySize);
- }
- return NS_OK;
- }
-
- NS_IMETHOD GetNext(nsISupports** aResult)
- {
- nsresult rv = NS_ERROR_FAILURE;
-
- JNIEnv* env = GetJNIEnv();
- jobject javaFile = env->GetObjectArrayElement(mJavaFileArray, mIndex++);
- if (javaFile) {
- nsCOMPtr<nsILocalFile> localFile;
- rv = File_to_nsILocalFile(env, javaFile, getter_AddRefs(localFile));
- env->DeleteLocalRef(javaFile);
-
- if (NS_SUCCEEDED(rv)) {
- return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)aResult);
- }
- }
-
- env->ExceptionClear();
- return NS_ERROR_FAILURE;
- }
-
-private:
- jobjectArray mJavaFileArray;
- PRUint32 mArraySize;
- PRUint32 mIndex;
-};
-
-NS_IMPL_ISUPPORTS1(DirectoryEnumerator, nsISimpleEnumerator)
-
-NS_IMETHODIMP
-nsAppFileLocProviderProxy::GetFiles(const char* aProp,
- nsISimpleEnumerator** aResult)
-{
- nsresult rv = NS_OK;
-
- // Setup params for calling Java function
- JNIEnv* env = GetJNIEnv();
- jstring prop = env->NewStringUTF(aProp);
- if (!prop)
- rv = NS_ERROR_OUT_OF_MEMORY;
-
- // Create method ID
- jmethodID mid = nsnull;
- if (NS_SUCCEEDED(rv)) {
- jclass clazz = env->GetObjectClass(mJavaLocProvider);
- if (clazz) {
- mid = env->GetMethodID(clazz, "getFiles",
- "(Ljava/lang/String;)[Ljava/io/File;");
- env->DeleteLocalRef(clazz);
- }
- if (!mid)
- rv = NS_ERROR_FAILURE;
- }
-
- // Call Java function
- jobject javaFileArray = nsnull;
- if (NS_SUCCEEDED(rv)) {
- javaFileArray = env->CallObjectMethod(mJavaLocProvider, mid, prop);
-
- // Handle any exception thrown by Java method.
- jthrowable exp = env->ExceptionOccurred();
- if (exp) {
-#ifdef DEBUG
- env->ExceptionDescribe();
-#endif
-
- // If the exception is an instance of XPCOMException, then get the
- // nsresult from the exception instance. Else, default to
- // NS_ERROR_FAILURE.
- if (env->IsInstanceOf(exp, xpcomExceptionClass)) {
- jfieldID fid;
- fid = env->GetFieldID(xpcomExceptionClass, "errorcode", "J");
- if (fid) {
- rv = env->GetLongField(exp, fid);
- } else {
- rv = NS_ERROR_FAILURE;
- }
- NS_ASSERTION(fid, "Couldn't get 'errorcode' field of XPCOMException");
- } else {
- rv = NS_ERROR_FAILURE;
- }
- } else {
- // No exception thrown. Check the result.
- if (javaFileArray == nsnull) {
- rv = NS_ERROR_FAILURE;
- }
- }
- }
-
- if (NS_SUCCEEDED(rv)) {
- // Parse return value
- *aResult = new DirectoryEnumerator(static_cast<jobjectArray>
- (javaFileArray));
- NS_ADDREF(*aResult);
- return NS_OK;
- }
-
- // Handle error conditions
- *aResult = nsnull;
- env->ExceptionClear();
- return rv;
-}
-
-
-////////////////////////////////////////////////////////////////////////////////
-
-nsresult
-NS_NewAppFileLocProviderProxy(jobject aJavaLocProvider,
- nsIDirectoryServiceProvider** aResult)
-{
- nsAppFileLocProviderProxy* provider =
- new nsAppFileLocProviderProxy(aJavaLocProvider);
- if (provider == nsnull)
- return NS_ERROR_OUT_OF_MEMORY;
- NS_ADDREF(provider);
-
- *aResult = provider;
- return NS_OK;
-}
-
deleted file mode 100644
--- a/extensions/java/xpcom/src/nsAppFileLocProviderProxy.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is
- * IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2005
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 _nsAppFileLocProviderProxy_h_
-#define _nsAppFileLocProviderProxy_h_
-
-#include "nsIDirectoryService.h"
-#include "jni.h"
-
-
-class nsAppFileLocProviderProxy : public nsIDirectoryServiceProvider2
-{
-public:
- nsAppFileLocProviderProxy(jobject aJavaLocProvider);
- ~nsAppFileLocProviderProxy();
-
- NS_DECL_ISUPPORTS
- NS_DECL_NSIDIRECTORYSERVICEPROVIDER
- NS_DECL_NSIDIRECTORYSERVICEPROVIDER2
-
-private:
- jobject mJavaLocProvider;
-};
-
-extern "C" nsresult
-NS_NewAppFileLocProviderProxy(jobject aJavaLocProvider,
- nsIDirectoryServiceProvider** aResult);
-
-
-#endif //_nsAppFileLocProviderProxy_h_
-
deleted file mode 100644
--- a/extensions/java/xpcom/src/nsJavaInterfaces.cpp
+++ /dev/null
@@ -1,430 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2007
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 "nsJavaInterfaces.h"
-#include "nsJavaWrapper.h"
-#include "nsJavaXPCOMBindingUtils.h"
-#include "nsJavaXPTCStub.h"
-#include "nsIComponentRegistrar.h"
-#include "nsString.h"
-#include "nsISimpleEnumerator.h"
-#include "nsIInterfaceInfoManager.h"
-#include "nsIInputStream.h"
-#include "nsEnumeratorUtils.h"
-#include "nsAppFileLocProviderProxy.h"
-#include "nsXULAppAPI.h"
-#include "nsILocalFile.h"
-
-#ifdef XP_MACOSX
-#include "jawt.h"
-#endif
-
-
-extern "C" NS_EXPORT void JNICALL
-MOZILLA_NATIVE(initialize) (JNIEnv* env, jobject)
-{
- if (!InitializeJavaGlobals(env)) {
- jclass clazz =
- env->FindClass("org/mozilla/xpcom/XPCOMInitializationException");
- if (clazz) {
- env->ThrowNew(clazz, "Failed to initialize JavaXPCOM");
- }
- }
-}
-
-nsresult
-InitEmbedding_Impl(JNIEnv* env, jobject aLibXULDirectory,
- jobject aAppDirectory, jobject aAppDirProvider)
-{
- nsresult rv;
-
- // create an nsILocalFile from given java.io.File
- nsCOMPtr<nsILocalFile> libXULDir;
- if (aLibXULDirectory) {
- rv = File_to_nsILocalFile(env, aLibXULDirectory, getter_AddRefs(libXULDir));
- NS_ENSURE_SUCCESS(rv, rv);
- }
- nsCOMPtr<nsILocalFile> appDir;
- if (aAppDirectory) {
- rv = File_to_nsILocalFile(env, aAppDirectory, getter_AddRefs(appDir));
- NS_ENSURE_SUCCESS(rv, rv);
- }
-
- // create nsAppFileLocProviderProxy from given Java object
- nsCOMPtr<nsIDirectoryServiceProvider> provider;
- if (aAppDirProvider) {
- rv = NS_NewAppFileLocProviderProxy(aAppDirProvider,
- getter_AddRefs(provider));
- NS_ENSURE_SUCCESS(rv, rv);
- }
-
- // init libXUL
- return XRE_InitEmbedding(libXULDir, appDir, provider, nsnull, 0);
-}
-
-extern "C" NS_EXPORT void JNICALL
-GRE_NATIVE(initEmbedding) (JNIEnv* env, jobject, jobject aLibXULDirectory,
- jobject aAppDirectory, jobject aAppDirProvider)
-{
- nsresult rv = InitEmbedding_Impl(env, aLibXULDirectory, aAppDirectory,
- aAppDirProvider);
-
- if (NS_FAILED(rv)) {
- ThrowException(env, rv, "Failure in initEmbedding");
- FreeJavaGlobals(env);
- }
-}
-
-extern "C" NS_EXPORT void JNICALL
-GRE_NATIVE(termEmbedding) (JNIEnv *env, jobject)
-{
- // Free globals before calling XRE_TermEmbedding(), since we need some
- // XPCOM services.
- FreeJavaGlobals(env);
-
- XRE_TermEmbedding();
-}
-
-nsresult
-InitXPCOM_Impl(JNIEnv* env, jobject aMozBinDirectory,
- jobject aAppFileLocProvider, jobject* aResult)
-{
- nsresult rv;
-
- // create an nsILocalFile from given java.io.File
- nsCOMPtr<nsILocalFile> directory;
- if (aMozBinDirectory) {
- rv = File_to_nsILocalFile(env, aMozBinDirectory, getter_AddRefs(directory));
- NS_ENSURE_SUCCESS(rv, rv);
- }
-
- // create nsAppFileLocProviderProxy from given Java object
- nsCOMPtr<nsIDirectoryServiceProvider> provider;
- if (aAppFileLocProvider) {
- rv = NS_NewAppFileLocProviderProxy(aAppFileLocProvider,
- getter_AddRefs(provider));
- NS_ENSURE_SUCCESS(rv, rv);
- }
-
- // init XPCOM
- nsCOMPtr<nsIServiceManager> servMan;
- rv = NS_InitXPCOM2(getter_AddRefs(servMan), directory, provider);
- NS_ENSURE_SUCCESS(rv, rv);
-
- // create Java proxy for service manager returned by NS_InitXPCOM2
- return NativeInterfaceToJavaObject(env, servMan, NS_GET_IID(nsIServiceManager),
- nsnull, aResult);
-}
-
-extern "C" NS_EXPORT jobject JNICALL
-XPCOM_NATIVE(initXPCOM) (JNIEnv* env, jobject, jobject aMozBinDirectory,
- jobject aAppFileLocProvider)
-{
- jobject servMan;
- nsresult rv = InitXPCOM_Impl(env, aMozBinDirectory, aAppFileLocProvider,
- &servMan);
- if (NS_SUCCEEDED(rv))
- return servMan;
-
- ThrowException(env, rv, "Failure in initXPCOM");
- FreeJavaGlobals(env);
- return nsnull;
-}
-
-extern "C" NS_EXPORT void JNICALL
-XPCOM_NATIVE(shutdownXPCOM) (JNIEnv *env, jobject, jobject aServMgr)
-{
- nsresult rv;
- nsIServiceManager* servMgr = nsnull;
- if (aServMgr) {
- // Get native XPCOM instance
- nsISupports* instancePtr = nsnull;
- rv = JavaObjectToNativeInterface(env, aServMgr,
- NS_GET_IID(nsIServiceManager), (void**) &instancePtr);
- NS_ASSERTION(NS_SUCCEEDED(rv) && instancePtr != nsnull,
- "Failed to get XPCOM obj for ServiceMgr.");
- if (NS_SUCCEEDED(rv)) {
- rv = instancePtr->QueryInterface(NS_GET_IID(nsIServiceManager),
- (void**) &servMgr);
- NS_ASSERTION(NS_SUCCEEDED(rv), "QI for nsIServiceManager failed");
- }
-
- // Even if we failed to get the matching xpcom object, we don't abort this
- // function. Just call NS_ShutdownXPCOM with a null service manager.
- }
-
- // Free globals before calling NS_ShutdownXPCOM(), since we need some
- // XPCOM services.
- FreeJavaGlobals(env);
-
- rv = NS_ShutdownXPCOM(servMgr);
- if (NS_FAILED(rv))
- ThrowException(env, rv, "NS_ShutdownXPCOM failed");
-}
-
-extern "C" NS_EXPORT jobject JNICALL
-XPCOM_NATIVE(newLocalFile) (JNIEnv *env, jobject, jstring aPath,
- jboolean aFollowLinks)
-{
- // Create a Mozilla string from the jstring
- const PRUnichar* buf = nsnull;
- if (aPath) {
- buf = env->GetStringChars(aPath, nsnull);
- if (!buf)
- return nsnull; // exception already thrown
- }
-
- nsAutoString path_str(buf);
- env->ReleaseStringChars(aPath, buf);
-
- // Make call to given function
- nsCOMPtr<nsILocalFile> file;
- nsresult rv = NS_NewLocalFile(path_str, aFollowLinks, getter_AddRefs(file));
-
- if (NS_SUCCEEDED(rv)) {
- jobject javaProxy;
- rv = NativeInterfaceToJavaObject(env, file, NS_GET_IID(nsILocalFile),
- nsnull, &javaProxy);
- if (NS_SUCCEEDED(rv))
- return javaProxy;
- }
-
- ThrowException(env, rv, "Failure in newLocalFile");
- return nsnull;
-}
-
-extern "C" NS_EXPORT jobject JNICALL
-XPCOM_NATIVE(getComponentManager) (JNIEnv *env, jobject)
-{
- // Call XPCOM method
- nsCOMPtr<nsIComponentManager> cm;
- nsresult rv = NS_GetComponentManager(getter_AddRefs(cm));
-
- if (NS_SUCCEEDED(rv)) {
- jobject javaProxy;
- rv = NativeInterfaceToJavaObject(env, cm, NS_GET_IID(nsIComponentManager),
- nsnull, &javaProxy);
- if (NS_SUCCEEDED(rv))
- return javaProxy;
- }
-
- ThrowException(env, rv, "Failure in getComponentManager");
- return nsnull;
-}
-
-extern "C" NS_EXPORT jobject JNICALL
-XPCOM_NATIVE(getComponentRegistrar) (JNIEnv *env, jobject)
-{
- // Call XPCOM method
- nsCOMPtr<nsIComponentRegistrar> cr;
- nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(cr));
-
- if (NS_SUCCEEDED(rv)) {
- jobject javaProxy;
- rv = NativeInterfaceToJavaObject(env, cr, NS_GET_IID(nsIComponentRegistrar),
- nsnull, &javaProxy);
- if (NS_SUCCEEDED(rv))
- return javaProxy;
- }
-
- ThrowException(env, rv, "Failure in getComponentRegistrar");
- return nsnull;
-}
-
-extern "C" NS_EXPORT jobject JNICALL
-XPCOM_NATIVE(getServiceManager) (JNIEnv *env, jobject)
-{
- // Call XPCOM method
- nsCOMPtr<nsIServiceManager> sm;
- nsresult rv = NS_GetServiceManager(getter_AddRefs(sm));
-
- if (NS_SUCCEEDED(rv)) {
- jobject javaProxy;
- rv = NativeInterfaceToJavaObject(env, sm, NS_GET_IID(nsIServiceManager),
- nsnull, &javaProxy);
- if (NS_SUCCEEDED(rv))
- return javaProxy;
- }
-
- ThrowException(env, rv, "Failure in getServiceManager");
- return nsnull;
-}
-
-extern "C" NS_EXPORT jobject JNICALL
-GRE_NATIVE(lockProfileDirectory) (JNIEnv* env, jobject, jobject aDirectory)
-{
- nsresult rv = NS_ERROR_FAILURE;
-
- if (aDirectory) {
- nsCOMPtr<nsILocalFile> profileDir;
- rv = File_to_nsILocalFile(env, aDirectory, getter_AddRefs(profileDir));
-
- if (NS_SUCCEEDED(rv)) {
- nsISupports* lock;
- rv = XRE_LockProfileDirectory(profileDir, &lock);
-
- if (NS_SUCCEEDED(rv)) {
- jclass clazz =
- env->FindClass("org/mozilla/xpcom/ProfileLock");
- if (clazz) {
- jmethodID mid = env->GetMethodID(clazz, "<init>", "(J)V");
- if (mid) {
- return env->NewObject(clazz, mid, reinterpret_cast<jlong>(lock));
- }
- }
-
- // if we get here, then something failed
- rv = NS_ERROR_FAILURE;
- }
- }
- }
-
- ThrowException(env, rv, "Failure in lockProfileDirectory");
- return nsnull;
-}
-
-extern "C" NS_EXPORT void JNICALL
-GRE_NATIVE(notifyProfile) (JNIEnv *env, jobject)
-{
- XRE_NotifyProfile();
-}
-
-#ifdef XP_MACOSX
-extern PRUint64 GetPlatformHandle(JAWT_DrawingSurfaceInfo* dsi);
-#endif
-
-extern "C" NS_EXPORT jlong JNICALL
-MOZILLA_NATIVE(getNativeHandleFromAWT) (JNIEnv* env, jobject clazz,
- jobject widget)
-{
- PRUint64 handle = 0;
-
-#ifdef XP_MACOSX
- JAWT awt;
- awt.version = JAWT_VERSION_1_4;
- jboolean result = JAWT_GetAWT(env, &awt);
- if (result == JNI_FALSE)
- return 0;
-
- JAWT_DrawingSurface* ds = awt.GetDrawingSurface(env, widget);
- if (ds != nsnull) {
- jint lock = ds->Lock(ds);
- if (!(lock & JAWT_LOCK_ERROR)) {
- JAWT_DrawingSurfaceInfo* dsi = ds->GetDrawingSurfaceInfo(ds);
- if (dsi) {
- handle = GetPlatformHandle(dsi);
- ds->FreeDrawingSurfaceInfo(dsi);
- }
-
- ds->Unlock(ds);
- }
-
- awt.FreeDrawingSurface(ds);
- }
-#else
- NS_WARNING("getNativeHandleFromAWT JNI method not implemented");
-#endif
-
- return handle;
-}
-
-extern "C" NS_EXPORT jlong JNICALL
-JXUTILS_NATIVE(wrapJavaObject) (JNIEnv* env, jobject, jobject aJavaObject,
- jstring aIID)
-{
- nsresult rv;
- void* xpcomObject = nsnull;
-
- if (!aJavaObject || !aIID) {
- rv = NS_ERROR_NULL_POINTER;
- } else {
- const char* str = env->GetStringUTFChars(aIID, nsnull);
- if (!str) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- } else {
- nsID iid;
- if (iid.Parse(str)) {
- rv = JavaObjectToNativeInterface(env, aJavaObject, iid, &xpcomObject);
- if (NS_SUCCEEDED(rv)) {
- rv = ((nsISupports*) xpcomObject)->QueryInterface(iid, &xpcomObject);
- }
- } else {
- rv = NS_ERROR_INVALID_ARG;
- }
-
- env->ReleaseStringUTFChars(aIID, str);
- }
- }
-
- if (NS_FAILED(rv)) {
- ThrowException(env, rv, "Failed to create XPCOM proxy for Java object");
- }
- return reinterpret_cast<jlong>(xpcomObject);
-}
-
-extern "C" NS_EXPORT jobject JNICALL
-JXUTILS_NATIVE(wrapXPCOMObject) (JNIEnv* env, jobject, jlong aXPCOMObject,
- jstring aIID)
-{
- nsresult rv;
- jobject javaObject = nsnull;
- nsISupports* xpcomObject = reinterpret_cast<nsISupports*>(aXPCOMObject);
-
- if (!xpcomObject || !aIID) {
- rv = NS_ERROR_NULL_POINTER;
- } else {
- const char* str = env->GetStringUTFChars(aIID, nsnull);
- if (!str) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- } else {
- nsID iid;
- if (iid.Parse(str)) {
- // XXX Should we be passing something other than NULL for aObjectLoader?
- rv = NativeInterfaceToJavaObject(env, xpcomObject, iid, nsnull,
- &javaObject);
- } else {
- rv = NS_ERROR_INVALID_ARG;
- }
-
- env->ReleaseStringUTFChars(aIID, str);
- }
- }
-
- if (NS_FAILED(rv)) {
- ThrowException(env, rv, "Failed to create XPCOM proxy for Java object");
- }
- return javaObject;
-}
deleted file mode 100644
--- a/extensions/java/xpcom/src/nsJavaInterfaces.h
+++ /dev/null
@@ -1,114 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2006
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 _nsJavaInterfaces_h_
-#define _nsJavaInterfaces_h_
-
-#include "jni.h"
-#include "nscore.h"
-
-#define MOZILLA_NATIVE(func) Java_org_mozilla_xpcom_internal_MozillaImpl_##func
-#define GRE_NATIVE(func) Java_org_mozilla_xpcom_internal_GREImpl_##func
-#define XPCOM_NATIVE(func) Java_org_mozilla_xpcom_internal_XPCOMImpl_##func
-#define JAVAPROXY_NATIVE(func) \
- Java_org_mozilla_xpcom_internal_XPCOMJavaProxy_##func
-#define LOCKPROXY_NATIVE(func) Java_org_mozilla_xpcom_ProfileLock_##func
-#define JXUTILS_NATIVE(func) \
- Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_##func
-
-
-extern "C" NS_EXPORT void JNICALL
-MOZILLA_NATIVE(initialize) (JNIEnv* env, jobject);
-
-extern "C" NS_EXPORT void JNICALL
-GRE_NATIVE(initEmbedding) (JNIEnv* env, jobject, jobject aLibXULDirectory,
- jobject aAppDirectory, jobject aAppDirProvider);
-
-extern "C" NS_EXPORT void JNICALL
-GRE_NATIVE(termEmbedding) (JNIEnv *env, jobject);
-
-extern "C" NS_EXPORT jobject JNICALL
-GRE_NATIVE(lockProfileDirectory) (JNIEnv *, jobject, jobject aDirectory);
-
-extern "C" NS_EXPORT void JNICALL
-GRE_NATIVE(notifyProfile) (JNIEnv *env, jobject);
-
-extern "C" NS_EXPORT jobject JNICALL
-XPCOM_NATIVE(initXPCOM) (JNIEnv* env, jobject, jobject aMozBinDirectory,
- jobject aAppFileLocProvider);
-
-extern "C" NS_EXPORT void JNICALL
-XPCOM_NATIVE(shutdownXPCOM) (JNIEnv *env, jobject, jobject aServMgr);
-
-extern "C" NS_EXPORT jobject JNICALL
-XPCOM_NATIVE(newLocalFile) (JNIEnv *env, jobject, jstring aPath,
- jboolean aFollowLinks);
-
-extern "C" NS_EXPORT jobject JNICALL
-XPCOM_NATIVE(getComponentManager) (JNIEnv *env, jobject);
-
-extern "C" NS_EXPORT jobject JNICALL
-XPCOM_NATIVE(getComponentRegistrar) (JNIEnv *env, jobject);
-
-extern "C" NS_EXPORT jobject JNICALL
-XPCOM_NATIVE(getServiceManager) (JNIEnv *env, jobject);
-
-extern "C" NS_EXPORT jobject JNICALL
-JAVAPROXY_NATIVE(callXPCOMMethod) (JNIEnv *env, jclass that, jobject aJavaProxy,
- jstring aMethodName, jobjectArray aParams);
-
-extern "C" NS_EXPORT void JNICALL
-JAVAPROXY_NATIVE(finalizeProxy) (JNIEnv *env, jclass that, jobject aJavaProxy);
-
-extern "C" NS_EXPORT jboolean JNICALL
-JAVAPROXY_NATIVE(isSameXPCOMObject) (JNIEnv *env, jclass that, jobject aProxy1,
- jobject aProxy2);
-
-extern "C" NS_EXPORT void JNICALL
-LOCKPROXY_NATIVE(release) (JNIEnv *env, jclass that, jlong aLockObject);
-
-extern "C" NS_EXPORT jlong JNICALL
-MOZILLA_NATIVE(getNativeHandleFromAWT) (JNIEnv* env, jobject, jobject widget);
-
-extern "C" NS_EXPORT jlong JNICALL
-JXUTILS_NATIVE(wrapJavaObject) (JNIEnv* env, jobject, jobject aJavaObject,
- jstring aIID);
-
-extern "C" NS_EXPORT jobject JNICALL
-JXUTILS_NATIVE(wrapXPCOMObject) (JNIEnv* env, jobject, jlong aXPCOMObject,
- jstring aIID);
-
-#endif // _nsJavaInterfaces_h_
deleted file mode 100644
--- a/extensions/java/xpcom/src/nsJavaWrapper.cpp
+++ /dev/null
@@ -1,1941 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2006
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 "nsJavaInterfaces.h"
-#include "nsJavaWrapper.h"
-#include "nsJavaXPTCStub.h"
-#include "nsJavaXPCOMBindingUtils.h"
-#include "jni.h"
-#include "xptcall.h"
-#include "nsIInterfaceInfoManager.h"
-#include "nsString.h"
-#include "nsCRT.h"
-#include "prmem.h"
-#include "nsServiceManagerUtils.h"
-#include "nsThreadUtils.h"
-#include "nsProxyRelease.h"
-
-static nsID nullID = {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
-
-
-nsresult
-CreateJavaArray(JNIEnv* env, PRUint8 aType, PRUint32 aSize, const nsID& aIID,
- jobject* aResult)
-{
- jobject array = nsnull;
- switch (aType)
- {
- case nsXPTType::T_I8:
- array = env->NewByteArray(aSize);
- break;
-
- case nsXPTType::T_I16:
- case nsXPTType::T_U8:
- array = env->NewShortArray(aSize);
- break;
-
- case nsXPTType::T_I32:
- case nsXPTType::T_U16:
- array = env->NewIntArray(aSize);
- break;
-
- case nsXPTType::T_I64:
- case nsXPTType::T_U32:
- array = env->NewLongArray(aSize);
- break;
-
- case nsXPTType::T_FLOAT:
- array = env->NewFloatArray(aSize);
- break;
-
- // XXX how do we handle unsigned 64-bit values?
- case nsXPTType::T_U64:
- case nsXPTType::T_DOUBLE:
- array = env->NewDoubleArray(aSize);
- break;
-
- case nsXPTType::T_BOOL:
- array = env->NewBooleanArray(aSize);
- break;
-
- case nsXPTType::T_CHAR:
- case nsXPTType::T_WCHAR:
- array = env->NewCharArray(aSize);
- break;
-
- case nsXPTType::T_CHAR_STR:
- case nsXPTType::T_WCHAR_STR:
- case nsXPTType::T_IID:
- case nsXPTType::T_ASTRING:
- case nsXPTType::T_DOMSTRING:
- case nsXPTType::T_UTF8STRING:
- case nsXPTType::T_CSTRING:
- array = env->NewObjectArray(aSize, stringClass, nsnull);
- break;
-
- case nsXPTType::T_INTERFACE:
- case nsXPTType::T_INTERFACE_IS:
- {
- nsCOMPtr<nsIInterfaceInfoManager>
- iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID));
- NS_ASSERTION(iim, "Failed to get InterfaceInfoManager");
- if (!iim)
- return NS_ERROR_FAILURE;
-
- // Get interface info for given IID
- nsCOMPtr<nsIInterfaceInfo> info;
- nsresult rv = iim->GetInfoForIID(&aIID, getter_AddRefs(info));
- if (NS_FAILED(rv))
- return rv;
-
- // Get interface name
- const char* iface_name;
- rv = info->GetNameShared(&iface_name);
- if (NS_FAILED(rv))
- return rv;
-
- // Create proper Java interface name
- nsCAutoString class_name("org/mozilla/interfaces/");
- class_name.AppendASCII(iface_name);
- jclass ifaceClass = env->FindClass(class_name.get());
- if (!ifaceClass)
- return NS_ERROR_FAILURE;
-
- array = env->NewObjectArray(aSize, ifaceClass, nsnull);
- break;
- }
-
- case nsXPTType::T_VOID:
- array = env->NewLongArray(aSize);
- break;
-
- default:
- NS_WARNING("unknown type");
- return NS_ERROR_FAILURE;
- }
-
- if (!array)
- return NS_ERROR_OUT_OF_MEMORY;
-
- *aResult = array;
- return NS_OK;
-}
-
-nsresult
-GetNativeArrayElement(PRUint8 aType, void* aArray, PRUint32 aIndex,
- nsXPTCVariant* aResult)
-{
- switch (aType)
- {
- case nsXPTType::T_I8:
- case nsXPTType::T_U8:
- aResult->val.u8 = static_cast<PRUint8*>(aArray)[aIndex];
- break;
-
- case nsXPTType::T_I16:
- case nsXPTType::T_U16:
- aResult->val.u16 = static_cast<PRUint16*>(aArray)[aIndex];
- break;
-
- case nsXPTType::T_I32:
- case nsXPTType::T_U32:
- aResult->val.u32 = static_cast<PRUint32*>(aArray)[aIndex];
- break;
-
- case nsXPTType::T_I64:
- case nsXPTType::T_U64:
- aResult->val.u64 = static_cast<PRUint64*>(aArray)[aIndex];
- break;
-
- case nsXPTType::T_FLOAT:
- aResult->val.f = static_cast<float*>(aArray)[aIndex];
- break;
-
- case nsXPTType::T_DOUBLE:
- aResult->val.d = static_cast<double*>(aArray)[aIndex];
- break;
-
- case nsXPTType::T_BOOL:
- aResult->val.b = static_cast<PRBool*>(aArray)[aIndex];
- break;
-
- case nsXPTType::T_CHAR:
- aResult->val.c = static_cast<char*>(aArray)[aIndex];
- break;
-
- case nsXPTType::T_WCHAR:
- aResult->val.wc = static_cast<PRUnichar*>(aArray)[aIndex];
- break;
-
- case nsXPTType::T_CHAR_STR:
- aResult->val.p = static_cast<char**>(aArray)[aIndex];
- break;
-
- case nsXPTType::T_WCHAR_STR:
- aResult->val.p = static_cast<PRUnichar**>(aArray)[aIndex];
- break;
-
- case nsXPTType::T_IID:
- aResult->val.p = static_cast<nsID**>(aArray)[aIndex];
- break;
-
- case nsXPTType::T_INTERFACE:
- case nsXPTType::T_INTERFACE_IS:
- aResult->val.p = static_cast<nsISupports**>(aArray)[aIndex];
- break;
-
- case nsXPTType::T_ASTRING:
- case nsXPTType::T_DOMSTRING:
- aResult->val.p = static_cast<nsString**>(aArray)[aIndex];
- break;
-
- case nsXPTType::T_UTF8STRING:
- case nsXPTType::T_CSTRING:
- aResult->val.p = static_cast<nsCString**>(aArray)[aIndex];
- break;
-
- case nsXPTType::T_VOID:
- aResult->val.p = static_cast<void**>(aArray)[aIndex];
- break;
-
- default:
- NS_WARNING("unknown type");
- return NS_ERROR_FAILURE;
- }
-
- return NS_OK;
-}
-
-nsresult
-CreateNativeArray(PRUint8 aType, PRUint32 aSize, void** aResult)
-{
- void* array = nsnull;
- switch (aType)
- {
- case nsXPTType::T_I8:
- case nsXPTType::T_U8:
- array = PR_Malloc(aSize * sizeof(PRUint8));
- break;
-
- case nsXPTType::T_I16:
- case nsXPTType::T_U16:
- array = PR_Malloc(aSize * sizeof(PRUint16));
- break;
-
- case nsXPTType::T_I32:
- case nsXPTType::T_U32:
- array = PR_Malloc(aSize * sizeof(PRUint32));
- break;
-
- case nsXPTType::T_I64:
- case nsXPTType::T_U64:
- array = PR_Malloc(aSize * sizeof(PRUint64));
- break;
-
- case nsXPTType::T_FLOAT:
- array = PR_Malloc(aSize * sizeof(float));
- break;
-
- case nsXPTType::T_DOUBLE:
- array = PR_Malloc(aSize * sizeof(double));
- break;
-
- case nsXPTType::T_BOOL:
- array = PR_Malloc(aSize * sizeof(PRBool));
- break;
-
- case nsXPTType::T_CHAR:
- array = PR_Malloc(aSize * sizeof(char));
- break;
-
- case nsXPTType::T_WCHAR:
- array = PR_Malloc(aSize * sizeof(PRUnichar));
- break;
-
- case nsXPTType::T_CHAR_STR:
- case nsXPTType::T_WCHAR_STR:
- case nsXPTType::T_IID:
- case nsXPTType::T_ASTRING:
- case nsXPTType::T_DOMSTRING:
- case nsXPTType::T_UTF8STRING:
- case nsXPTType::T_CSTRING:
- case nsXPTType::T_INTERFACE:
- case nsXPTType::T_INTERFACE_IS:
- array = PR_Malloc(aSize * sizeof(void*));
- break;
-
- case nsXPTType::T_VOID:
- array = PR_Malloc(aSize * sizeof(void*));
- break;
-
- default:
- NS_WARNING("unknown type");
- return NS_ERROR_FAILURE;
- }
-
- if (!array)
- return NS_ERROR_OUT_OF_MEMORY;
-
- *aResult = array;
- return NS_OK;
-}
-
-/**
- * Handle 'in' and 'inout' params.
- */
-nsresult
-SetupParams(JNIEnv *env, const jobject aParam, PRUint8 aType, PRBool aIsOut,
- const nsID& aIID, PRUint8 aArrayType, PRUint32 aArraySize,
- PRBool aIsArrayElement, PRUint32 aIndex, nsXPTCVariant &aVariant)
-{
- nsresult rv = NS_OK;
-
- switch (aType)
- {
- case nsXPTType::T_I8:
- {
- LOG(("byte\n"));
- if (!aIsOut && !aIsArrayElement) { // 'in'
- aVariant.val.i8 = env->CallByteMethod(aParam, byteValueMID);
- } else { // 'inout' & 'array'
- jbyte value;
- if (aParam) {
- env->GetByteArrayRegion((jbyteArray) aParam, aIndex, 1, &value);
- }
-
- if (aIsOut) { // 'inout'
- if (aParam) {
- aVariant.val.i8 = value;
- aVariant.ptr = &aVariant.val;
- } else {
- aVariant.ptr = nsnull;
- }
- aVariant.SetPtrIsData();
- } else { // 'array'
- static_cast<PRInt8*>(aVariant.val.p)[aIndex] = value;
- }
- }
- break;
- }
-
- case nsXPTType::T_I16:
- case nsXPTType::T_U8: // C++ unsigned octet <=> Java short
- {
- LOG(("short\n"));
- if (!aIsOut && !aIsArrayElement) { // 'in'
- jshort value = env->CallShortMethod(aParam, shortValueMID);
- if (aType == nsXPTType::T_I16)
- aVariant.val.i16 = value;
- else
- aVariant.val.u8 = value;
- } else { // 'inout' & 'array'
- jshort value;
- if (aParam) {
- env->GetShortArrayRegion((jshortArray) aParam, aIndex, 1, &value);
- }
-
- if (aIsOut) { // 'inout'
- if (aParam) {
- if (aType == nsXPTType::T_I16)
- aVariant.val.i16 = value;
- else
- aVariant.val.u8 = value;
- aVariant.ptr = &aVariant.val;
- } else {
- aVariant.ptr = nsnull;
- }
- aVariant.SetPtrIsData();
- } else { // 'array'
- if (aType == nsXPTType::T_I16)
- static_cast<PRInt16*>(aVariant.val.p)[aIndex] = value;
- else
- static_cast<PRUint8*>(aVariant.val.p)[aIndex] = value;
- }
- }
- break;
- }
-
- case nsXPTType::T_I32:
- case nsXPTType::T_U16: // C++ unsigned short <=> Java int
- {
- LOG(("int\n"));
- if (!aIsOut && !aIsArrayElement) { // 'in'
- jint value = env->CallIntMethod(aParam, intValueMID);
- if (aType == nsXPTType::T_I32)
- aVariant.val.i32 = value;
- else
- aVariant.val.u16 = value;
- } else { // 'inout' & 'array'
- jint value;
- if (aParam) {
- env->GetIntArrayRegion((jintArray) aParam, aIndex, 1, &value);
- }
-
- if (aIsOut) { // 'inout'
- if (aParam) {
- if (aType == nsXPTType::T_I32)
- aVariant.val.i32 = value;
- else
- aVariant.val.u16 = value;
- aVariant.ptr = &aVariant.val;
- } else {
- aVariant.ptr = nsnull;
- }
- aVariant.SetPtrIsData();
- } else { // 'array'
- if (aType == nsXPTType::T_I32)
- static_cast<PRInt32*>(aVariant.val.p)[aIndex] = value;
- else
- static_cast<PRUint16*>(aVariant.val.p)[aIndex] = value;
- }
- }
- break;
- }
-
- case nsXPTType::T_I64:
- case nsXPTType::T_U32: // C++ unsigned int <=> Java long
- {
- LOG(("long\n"));
- if (!aIsOut && !aIsArrayElement) { // 'in'
- jlong value = env->CallLongMethod(aParam, longValueMID);
- if (aType == nsXPTType::T_I64)
- aVariant.val.i64 = value;
- else
- aVariant.val.u32 = value;
- } else { // 'inout' & 'array'
- jlong value;
- if (aParam) {
- env->GetLongArrayRegion((jlongArray) aParam, aIndex, 1, &value);
- }
-
- if (aIsOut) { // 'inout'
- if (aParam) {
- if (aType == nsXPTType::T_I64)
- aVariant.val.i64 = value;
- else
- aVariant.val.u32 = value;
- aVariant.ptr = &aVariant.val;
- } else {
- aVariant.ptr = nsnull;
- }
- aVariant.SetPtrIsData();
- } else { // 'array'
- if (aType == nsXPTType::T_I64)
- static_cast<PRInt64*>(aVariant.val.p)[aIndex] = value;
- else
- static_cast<PRUint32*>(aVariant.val.p)[aIndex] = value;
- }
- }
- break;
- }
-
- case nsXPTType::T_FLOAT:
- {
- LOG(("float\n"));
- if (!aIsOut && !aIsArrayElement) { // 'in'
- aVariant.val.f = env->CallFloatMethod(aParam, floatValueMID);
- } else { // 'inout' & 'array'
- jfloat value;
- if (aParam) {
- env->GetFloatArrayRegion((jfloatArray) aParam, aIndex, 1, &value);
- }
-
- if (aIsOut) { // 'inout'
- if (aParam) {
- aVariant.val.f = value;
- aVariant.ptr = &aVariant.val;
- } else {
- aVariant.ptr = nsnull;
- }
- aVariant.SetPtrIsData();
- } else { // 'array'
- static_cast<float*>(aVariant.val.p)[aIndex] = value;
- }
- }
- break;
- }
-
- // XXX how do we handle unsigned 64-bit value?
- case nsXPTType::T_U64: // C++ unsigned long <=> Java double
- case nsXPTType::T_DOUBLE:
- {
- LOG(("double\n"));
- if (!aIsOut && !aIsArrayElement) { // 'in'
- jdouble value = env->CallDoubleMethod(aParam, doubleValueMID);
- if (aType == nsXPTType::T_DOUBLE)
- aVariant.val.d = value;
- else
- aVariant.val.u64 = static_cast<PRUint64>(value);
- } else { // 'inout' & 'array'
- jdouble value;
- if (aParam) {
- env->GetDoubleArrayRegion((jdoubleArray) aParam, aIndex, 1, &value);
- }
-
- if (aIsOut) { // 'inout'
- if (aParam) {
- if (aType == nsXPTType::T_DOUBLE)
- aVariant.val.d = value;
- else
- aVariant.val.u64 = static_cast<PRUint64>(value);
- aVariant.ptr = &aVariant.val;
- } else {
- aVariant.ptr = nsnull;
- }
- aVariant.SetPtrIsData();
- } else { // 'array'
- if (aType == nsXPTType::T_DOUBLE)
- static_cast<double*>(aVariant.val.p)[aIndex] = value;
- else
- static_cast<PRUint64*>(aVariant.val.p)[aIndex] =
- static_cast<PRUint64>(value);
- }
- }
- break;
- }
-
- case nsXPTType::T_BOOL:
- {
- LOG(("boolean\n"));
- if (!aIsOut && !aIsArrayElement) { // 'in'
- aVariant.val.b = env->CallBooleanMethod(aParam, booleanValueMID);
- } else { // 'inout' & 'array'
- jboolean value;
- if (aParam) {
- env->GetBooleanArrayRegion((jbooleanArray) aParam, aIndex, 1, &value);
- }
-
- if (aIsOut) { // 'inout'
- if (aParam) {
- aVariant.val.b = value;
- aVariant.ptr = &aVariant.val;
- } else {
- aVariant.ptr = nsnull;
- }
- aVariant.SetPtrIsData();
- } else { // 'array'
- static_cast<PRBool*>(aVariant.val.p)[aIndex] = value;
- }
- }
- break;
- }
-
- case nsXPTType::T_CHAR:
- {
- LOG(("char\n"));
- if (!aIsOut && !aIsArrayElement) { // 'in'
- aVariant.val.c = env->CallCharMethod(aParam, charValueMID);
- } else { // 'inout' & 'array'
- jchar value;
- if (aParam) {
- env->GetCharArrayRegion((jcharArray) aParam, aIndex, 1, &value);
- }
-
- if (aIsOut) { // 'inout'
- if (aParam) {
- aVariant.val.c = value;
- aVariant.ptr = &aVariant.val;
- } else {
- aVariant.ptr = nsnull;
- }
- aVariant.SetPtrIsData();
- } else { // 'array'
- static_cast<char*>(aVariant.val.p)[aIndex] = value;
- }
- }
- break;
- }
-
- case nsXPTType::T_WCHAR:
- {
- LOG(("char\n"));
- if (!aIsOut && !aIsArrayElement) { // 'in'
- aVariant.val.wc = env->CallCharMethod(aParam, charValueMID);
- } else { // 'inout' & 'array'
- jchar value;
- if (aParam) {
- env->GetCharArrayRegion((jcharArray) aParam, aIndex, 1, &value);
- }
-
- if (aIsOut) { // 'inout'
- if (aParam) {
- aVariant.val.wc = value;
- aVariant.ptr = &aVariant.val;
- } else {
- aVariant.ptr = nsnull;
- }
- aVariant.SetPtrIsData();
- } else { // 'array'
- static_cast<PRUnichar*>(aVariant.val.p)[aIndex] = value;
- }
- }
- break;
- }
-
- case nsXPTType::T_CHAR_STR:
- case nsXPTType::T_WCHAR_STR:
- {
- LOG(("String\n"));
- jstring data = nsnull;
- if (!aIsOut && !aIsArrayElement) { // 'in'
- data = (jstring) aParam;
- } else if (aParam) { // 'inout' & 'array'
- data = (jstring) env->GetObjectArrayElement((jobjectArray) aParam,
- aIndex);
- }
-
- void* buf = nsnull;
- if (data) {
- jsize uniLength = env->GetStringLength(data);
- if (uniLength > 0) {
- if (aType == nsXPTType::T_CHAR_STR) {
- jsize utf8Length = env->GetStringUTFLength(data);
- buf = nsMemory::Alloc((utf8Length + 1) * sizeof(char));
- if (!buf) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
-
- char* char_str = static_cast<char*>(buf);
- env->GetStringUTFRegion(data, 0, uniLength, char_str);
- char_str[utf8Length] = '\0';
-
- } else { // if T_WCHAR_STR
- buf = nsMemory::Alloc((uniLength + 1) * sizeof(jchar));
- if (!buf) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
-
- jchar* jchar_str = static_cast<jchar*>(buf);
- env->GetStringRegion(data, 0, uniLength, jchar_str);
- jchar_str[uniLength] = '\0';
- }
- } else {
- // create empty string
- buf = nsMemory::Alloc(2);
- if (!buf) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
- ((jchar*)buf)[0] = '\0';
- }
- }
-
- if (!aIsArrayElement) { // 'in' & 'inout'
- aVariant.val.p = buf;
- if (aIsOut) { // 'inout'
- aVariant.ptr = &aVariant.val;
- aVariant.SetPtrIsData();
- }
- } else { // 'array'
- if (aType == nsXPTType::T_CHAR_STR) {
- char* str = static_cast<char*>(buf);
- static_cast<char**>(aVariant.val.p)[aIndex] = str;
- } else {
- PRUnichar* str = static_cast<PRUnichar*>(buf);
- static_cast<PRUnichar**>(aVariant.val.p)[aIndex] = str;
- }
- }
- break;
- }
-
- case nsXPTType::T_IID:
- {
- LOG(("String(IID)\n"));
- jstring data = nsnull;
- if (!aIsOut && !aIsArrayElement) { // 'in'
- data = (jstring) aParam;
- } else if (aParam) { // 'inout' & 'array'
- data = (jstring) env->GetObjectArrayElement((jobjectArray) aParam,
- aIndex);
- }
-
- nsID* iid = new nsID;
- if (!iid) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
- if (data) {
- // extract IID string from Java string
- const char* str = env->GetStringUTFChars(data, nsnull);
- if (!str) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
-
- // parse string into IID object
- iid->Parse(str);
- env->ReleaseStringUTFChars(data, str);
- } else {
- *iid = nullID;
- }
-
- if (!aIsArrayElement) { // 'in' & 'inout'
- aVariant.val.p = iid;
- if (aIsOut) { // 'inout'
- aVariant.ptr = &aVariant.val;
- aVariant.SetPtrIsData();
- }
- } else { // 'array'
- static_cast<nsID**>(aVariant.val.p)[aIndex] = iid;
- }
- break;
- }
-
- case nsXPTType::T_INTERFACE:
- case nsXPTType::T_INTERFACE_IS:
- {
- LOG(("nsISupports\n"));
- jobject java_obj = nsnull;
- if (!aIsOut && !aIsArrayElement) { // 'in'
- java_obj = (jobject) aParam;
- } else if (aParam) { // 'inout' & 'array'
- java_obj = (jobject) env->GetObjectArrayElement((jobjectArray) aParam,
- aIndex);
- }
-
- void* xpcom_obj;
- if (java_obj) {
- // If the requested interface is nsIWeakReference, then we look for or
- // create a stub for the nsISupports interface. Then we create a weak
- // reference from that stub.
- PRBool isWeakRef;
- nsID iid;
- if (aIID.Equals(NS_GET_IID(nsIWeakReference))) {
- isWeakRef = PR_TRUE;
- iid = NS_GET_IID(nsISupports);
- } else {
- isWeakRef = PR_FALSE;
- iid = aIID;
- }
-
- rv = JavaObjectToNativeInterface(env, java_obj, iid, &xpcom_obj);
- if (NS_FAILED(rv))
- break;
- rv = ((nsISupports*) xpcom_obj)->QueryInterface(iid, &xpcom_obj);
- if (NS_FAILED(rv))
- break;
-
- // If the function expects a weak reference, then we need to
- // create it here.
- if (isWeakRef) {
- nsISupports* isupports = (nsISupports*) xpcom_obj;
- nsCOMPtr<nsISupportsWeakReference> supportsweak =
- do_QueryInterface(isupports);
- if (supportsweak) {
- nsWeakPtr weakref;
- supportsweak->GetWeakReference(getter_AddRefs(weakref));
- NS_RELEASE(isupports);
- xpcom_obj = weakref;
- NS_ADDREF((nsISupports*) xpcom_obj);
- } else {
- xpcom_obj = nsnull;
- }
- }
- } else {
- xpcom_obj = nsnull;
- }
-
- if (!aIsArrayElement) { // 'in' & 'inout'
- aVariant.val.p = xpcom_obj;
- aVariant.SetValIsInterface();
- if (aIsOut) { // 'inout'
- aVariant.ptr = &aVariant.val;
- aVariant.SetPtrIsData();
- }
- } else { // 'array'
- static_cast<void**>(aVariant.val.p)[aIndex] = xpcom_obj;
- }
- break;
- }
-
- case nsXPTType::T_ASTRING:
- case nsXPTType::T_DOMSTRING:
- {
- LOG(("String\n"));
- // Expecting only 'in' and 'in dipper'
- NS_PRECONDITION(!aIsOut, "unexpected param descriptor");
- if (aIsOut) {
- rv = NS_ERROR_UNEXPECTED;
- break;
- }
-
- jstring jstr = static_cast<jstring>(aParam);
- nsAString* str = jstring_to_nsAString(env, jstr);
- if (!str) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
-
- aVariant.val.p = str;
- aVariant.SetValIsDOMString();
- break;
- }
-
- case nsXPTType::T_UTF8STRING:
- case nsXPTType::T_CSTRING:
- {
- LOG(("StringUTF\n"));
- // Expecting only 'in' and 'in dipper'
- NS_PRECONDITION(!aIsOut, "unexpected param descriptor");
- if (aIsOut) {
- rv = NS_ERROR_UNEXPECTED;
- break;
- }
-
- jstring jstr = static_cast<jstring>(aParam);
- nsACString* str = jstring_to_nsACString(env, jstr);
- if (!str) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
-
- aVariant.val.p = str;
- if (aType == nsXPTType::T_CSTRING) {
- aVariant.SetValIsCString();
- } else {
- aVariant.SetValIsUTF8String();
- }
- break;
- }
-
- // handle "void *" as an "long" in Java
- case nsXPTType::T_VOID:
- {
- LOG(("long (void*)\n"));
- if (!aIsOut && !aIsArrayElement) { // 'in'
- aVariant.val.p =
- reinterpret_cast<void*>(env->CallLongMethod(aParam, longValueMID));
- } else { // 'inout' & 'array'
- jlong value;
- if (aParam) {
- env->GetLongArrayRegion((jlongArray) aParam, aIndex, 1, &value);
- }
-
- if (aIsOut) { // 'inout'
- if (aParam) {
- aVariant.val.p = reinterpret_cast<void*>(value);
- aVariant.ptr = &aVariant.val;
- } else {
- aVariant.ptr = nsnull;
- }
- aVariant.SetPtrIsData();
- } else { // 'array'
- static_cast<void**>(aVariant.val.p)[aIndex] =
- reinterpret_cast<void*>(value);
- }
- }
- break;
- }
-
- case nsXPTType::T_ARRAY:
- {
- jobject sourceArray = nsnull;
- if (!aIsOut) { // 'in'
- sourceArray = aParam;
- } else if (aParam) { // 'inout'
- jobjectArray array = static_cast<jobjectArray>(aParam);
- sourceArray = env->GetObjectArrayElement(array, 0);
- }
-
- if (sourceArray) {
- rv = CreateNativeArray(aArrayType, aArraySize, &aVariant.val.p);
-
- for (PRUint32 i = 0; i < aArraySize && NS_SUCCEEDED(rv); i++) {
- rv = SetupParams(env, sourceArray, aArrayType, PR_FALSE, aIID, 0, 0,
- PR_TRUE, i, aVariant);
- }
- }
-
- if (aIsOut) { // 'inout'
- aVariant.ptr = &aVariant.val.p;
- aVariant.SetPtrIsData();
- }
- break;
- }
-
- case nsXPTType::T_PSTRING_SIZE_IS:
- case nsXPTType::T_PWSTRING_SIZE_IS:
- {
- NS_PRECONDITION(!aIsArrayElement, "sized string array not supported");
-
- LOG(("Sized string\n"));
- jstring data = nsnull;
- if (!aIsOut) { // 'in'
- data = (jstring) aParam;
- } else if (aParam) { // 'inout'
- data = (jstring) env->GetObjectArrayElement((jobjectArray) aParam,
- aIndex);
- }
-
- PRUint32 length = 0;
- if (data) {
- if (aType == nsXPTType::T_PSTRING_SIZE_IS) {
- length = env->GetStringUTFLength(data);
- } else {
- length = env->GetStringLength(data);
- }
- if (length > aArraySize) {
- rv = NS_ERROR_ILLEGAL_VALUE;
- break;
- }
- }
-
- PRUint32 size_of_char = (aType == nsXPTType::T_PSTRING_SIZE_IS) ?
- sizeof(char) : sizeof(jchar);
- PRUint32 allocLength = (aArraySize + 1) * size_of_char;
- void* buf = nsMemory::Alloc(allocLength);
- if (!buf) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
-
- if (data) {
- if (aType == nsXPTType::T_PSTRING_SIZE_IS) {
- const char* str = env->GetStringUTFChars(data, nsnull);
- if (!str) {
- nsMemory::Free(buf);
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
- memcpy(buf, str, length);
- env->ReleaseStringUTFChars(data, str);
- } else {
- jchar* jchar_str = static_cast<jchar*>(buf);
- env->GetStringRegion(data, 0, length, jchar_str);
- }
- }
-
- aVariant.val.p = buf;
- if (aIsOut) { // 'inout'
- aVariant.ptr = &aVariant.val;
- aVariant.SetPtrIsData();
- }
-
- break;
- }
-
- default:
- NS_WARNING("unexpected parameter type");
- return NS_ERROR_UNEXPECTED;
- }
-
- return rv;
-}
-
-/**
- * Does any cleanup from objects created in SetupParams, as well as converting
- * any out params to Java.
- *
- * NOTE: If aInvokeResult is an error condition, then we just do cleanup in
- * this function.
- */
-nsresult
-FinalizeParams(JNIEnv *env, const nsXPTParamInfo &aParamInfo, PRUint8 aType,
- nsXPTCVariant &aVariant, const nsID& aIID,
- PRBool aIsArrayElement, PRUint8 aArrayType, PRUint32 aArraySize,
- PRUint32 aIndex, nsresult aInvokeResult, jobject* aParam)
-{
- nsresult rv = NS_OK;
-
- switch (aType)
- {
- case nsXPTType::T_I8:
- {
- if (NS_SUCCEEDED(aInvokeResult)) {
- jbyte value = aVariant.val.i8;
- if (aParamInfo.IsRetval() && !aIsArrayElement) {
- *aParam = env->NewObject(byteClass, byteInitMID, value);
- } else if ((aParamInfo.IsOut() || aIsArrayElement) && *aParam) {
- env->SetByteArrayRegion((jbyteArray) *aParam, aIndex, 1, &value);
- }
- }
- break;
- }
-
- case nsXPTType::T_I16:
- case nsXPTType::T_U8:
- {
- if (NS_SUCCEEDED(aInvokeResult)) {
- jshort value = (aType == nsXPTType::T_I16) ? aVariant.val.i16 :
- aVariant.val.u8;
- if (aParamInfo.IsRetval() && !aIsArrayElement) {
- *aParam = env->NewObject(shortClass, shortInitMID, value);
- } else if ((aParamInfo.IsOut() || aIsArrayElement) && aParam) {
- env->SetShortArrayRegion((jshortArray) *aParam, aIndex, 1, &value);
- }
- }
- break;
- }
-
- case nsXPTType::T_I32:
- case nsXPTType::T_U16:
- {
- if (NS_SUCCEEDED(aInvokeResult)) {
- jint value = (aType == nsXPTType::T_I32) ? aVariant.val.i32 :
- aVariant.val.u16;
- if (aParamInfo.IsRetval() && !aIsArrayElement) {
- *aParam = env->NewObject(intClass, intInitMID, value);
- } else if ((aParamInfo.IsOut() || aIsArrayElement) && *aParam) {
- env->SetIntArrayRegion((jintArray) *aParam, aIndex, 1, &value);
- }
- }
- break;
- }
-
- case nsXPTType::T_I64:
- case nsXPTType::T_U32:
- {
- if (NS_SUCCEEDED(aInvokeResult)) {
- jlong value = (aType == nsXPTType::T_I64) ? aVariant.val.i64 :
- aVariant.val.u32;
- if (aParamInfo.IsRetval() && !aIsArrayElement) {
- *aParam = env->NewObject(longClass, longInitMID, value);
- } else if ((aParamInfo.IsOut() || aIsArrayElement) && *aParam) {
- env->SetLongArrayRegion((jlongArray) *aParam, aIndex, 1, &value);
- }
- }
- break;
- }
-
- case nsXPTType::T_FLOAT:
- {
- if (NS_SUCCEEDED(aInvokeResult)) {
- jfloat value = aVariant.val.f;
- if (aParamInfo.IsRetval() && !aIsArrayElement) {
- *aParam = env->NewObject(floatClass, floatInitMID, value);
- } else if ((aParamInfo.IsOut() || aIsArrayElement) && *aParam) {
- env->SetFloatArrayRegion((jfloatArray) *aParam, aIndex, 1, &value);
- }
- }
- break;
- }
-
- // XXX how do we handle unsigned 64-bit values?
- case nsXPTType::T_U64:
- case nsXPTType::T_DOUBLE:
- {
- if (NS_SUCCEEDED(aInvokeResult)) {
- jdouble value = (aType == nsXPTType::T_DOUBLE) ? aVariant.val.d :
- aVariant.val.u64;
- if (aParamInfo.IsRetval() && !aIsArrayElement) {
- *aParam = env->NewObject(doubleClass, doubleInitMID, value);
- } else if ((aParamInfo.IsOut() || aIsArrayElement) && *aParam) {
- env->SetDoubleArrayRegion((jdoubleArray) *aParam, aIndex, 1, &value);
- }
- }
- break;
- }
-
- case nsXPTType::T_BOOL:
- {
- if (NS_SUCCEEDED(aInvokeResult)) {
- jboolean value = aVariant.val.b;
- if (aParamInfo.IsRetval() && !aIsArrayElement) {
- *aParam = env->NewObject(booleanClass, booleanInitMID, value);
- } else if ((aParamInfo.IsOut() || aIsArrayElement) && *aParam) {
- env->SetBooleanArrayRegion((jbooleanArray) *aParam, aIndex, 1, &value);
- }
- }
- break;
- }
-
- case nsXPTType::T_CHAR:
- case nsXPTType::T_WCHAR:
- {
- if (NS_SUCCEEDED(aInvokeResult)) {
- jchar value;
- if (aType == nsXPTType::T_CHAR)
- value = aVariant.val.c;
- else
- value = aVariant.val.wc;
- if (aParamInfo.IsRetval() && !aIsArrayElement) {
- *aParam = env->NewObject(charClass, charInitMID, value);
- } else if ((aParamInfo.IsOut() || aIsArrayElement) && *aParam) {
- env->SetCharArrayRegion((jcharArray) *aParam, aIndex, 1, &value);
- }
- }
- break;
- }
-
- case nsXPTType::T_CHAR_STR:
- case nsXPTType::T_WCHAR_STR:
- {
- if ((aParamInfo.IsOut() || aIsArrayElement) &&
- NS_SUCCEEDED(aInvokeResult))
- {
- // create new string from data
- jstring str = nsnull;
- if (aVariant.val.p) {
- if (aType == nsXPTType::T_CHAR_STR) {
- str = env->NewStringUTF((const char*) aVariant.val.p);
- } else {
- PRUint32 length = nsCRT::strlen((const PRUnichar*) aVariant.val.p);
- str = env->NewString((const jchar*) aVariant.val.p, length);
- }
- if (!str) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
- }
-
- if (aParamInfo.IsRetval() && !aIsArrayElement) {
- *aParam = str;
- } else if (*aParam) {
- // put new string into output array
- env->SetObjectArrayElement((jobjectArray) *aParam, aIndex, str);
- }
- }
-
- // cleanup
- if (aVariant.val.p)
- nsMemory::Free(aVariant.val.p);
- break;
- }
-
- case nsXPTType::T_IID:
- {
- nsID* iid = static_cast<nsID*>(aVariant.val.p);
-
- if ((aParamInfo.IsOut() || aIsArrayElement) &&
- NS_SUCCEEDED(aInvokeResult))
- {
- // Create the string from nsID
- jstring str = nsnull;
- if (iid) {
- char iid_str[NSID_LENGTH];
- iid->ToProvidedString(iid_str);
- str = env->NewStringUTF(iid_str);
- if (!str) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
- }
-
- if (aParamInfo.IsRetval() && !aIsArrayElement) {
- *aParam = str;
- } else if (*aParam) {
- // put new string into output array
- env->SetObjectArrayElement((jobjectArray) *aParam, aIndex, str);
- }
- }
-
- // Ordinarily, we would delete 'iid' here. But we cannot do that until
- // we've handled all of the params. See comment in CallXPCOMMethod.
- // We can safely delete array elements, though.
- if (aIsArrayElement)
- delete iid;
-
- break;
- }
-
- case nsXPTType::T_INTERFACE:
- case nsXPTType::T_INTERFACE_IS:
- {
- nsISupports* xpcom_obj = static_cast<nsISupports*>(aVariant.val.p);
-
- if ((aParamInfo.IsOut() || aIsArrayElement) &&
- NS_SUCCEEDED(aInvokeResult))
- {
- jobject java_obj = nsnull;
- if (xpcom_obj) {
- // Get matching Java object for given xpcom object
- rv = NativeInterfaceToJavaObject(env, xpcom_obj, aIID, nsnull,
- &java_obj);
- if (NS_FAILED(rv))
- break;
- }
-
- if (aParamInfo.IsRetval() && !aIsArrayElement) {
- *aParam = java_obj;
- } else if (*aParam) {
- // put new Java object into output array
- env->SetObjectArrayElement((jobjectArray) *aParam, aIndex, java_obj);
- }
- }
-
- // cleanup
- NS_IF_RELEASE(xpcom_obj);
- break;
- }
-
- case nsXPTType::T_ASTRING:
- case nsXPTType::T_DOMSTRING:
- {
- NS_PRECONDITION(aParamInfo.IsIn(), "unexpected param descriptor");
- if (!aParamInfo.IsIn()) {
- rv = NS_ERROR_UNEXPECTED;
- break;
- }
-
- nsString* str = static_cast<nsString*>(aVariant.val.p);
- if (NS_SUCCEEDED(aInvokeResult) && aParamInfo.IsDipper()) {
- // Create Java string from returned nsString
- jstring jstr = nsnull;
- if (str && !str->IsVoid()) {
- jstr = env->NewString((const jchar*) str->get(), str->Length());
- if (!jstr) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
- }
-
- *aParam = jstr;
- }
-
- // cleanup
- if (str) {
- delete str;
- }
- break;
- }
-
- case nsXPTType::T_UTF8STRING:
- case nsXPTType::T_CSTRING:
- {
- NS_PRECONDITION(aParamInfo.IsIn(), "unexpected param descriptor");
- if (!aParamInfo.IsIn()) {
- rv = NS_ERROR_UNEXPECTED;
- break;
- }
-
- nsCString* str = static_cast<nsCString*>(aVariant.val.p);
- if (NS_SUCCEEDED(aInvokeResult) && aParamInfo.IsDipper()) {
- // Create Java string from returned nsString
- jstring jstr = nsnull;
- if (str && !str->IsVoid()) {
- jstr = env->NewStringUTF((const char*) str->get());
- if (!jstr) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
- }
-
- *aParam = jstr;
- }
-
- // cleanup
- if (str) {
- delete str;
- }
- break;
- }
-
- case nsXPTType::T_VOID:
- {
- if (NS_SUCCEEDED(aInvokeResult)) {
- jlong value = reinterpret_cast<jlong>(aVariant.val.p);
- if (aParamInfo.IsRetval() && !aIsArrayElement) {
- *aParam = env->NewObject(longClass, longInitMID, value);
- } else if ((aParamInfo.IsOut() || aIsArrayElement) && *aParam) {
- env->SetLongArrayRegion((jlongArray) *aParam, aIndex, 1, &value);
- }
- }
- break;
- }
-
- case nsXPTType::T_ARRAY:
- {
- if (aParamInfo.IsOut() && NS_SUCCEEDED(aInvokeResult)) {
- // Create Java array from returned native array
- jobject jarray = nsnull;
- if (aVariant.val.p) {
- rv = CreateJavaArray(env, aArrayType, aArraySize, aIID, &jarray);
- if (NS_FAILED(rv))
- break;
-
- nsXPTCVariant var;
- for (PRUint32 i = 0; i < aArraySize && NS_SUCCEEDED(rv); i++) {
- rv = GetNativeArrayElement(aArrayType, aVariant.val.p, i, &var);
- if (NS_SUCCEEDED(rv)) {
- rv = FinalizeParams(env, aParamInfo, aArrayType, var, aIID,
- PR_TRUE, 0, 0, i, aInvokeResult, &jarray);
- }
- }
- }
-
- if (aParamInfo.IsRetval()) {
- *aParam = jarray;
- } else if (*aParam) {
- // put new Java array into output array
- env->SetObjectArrayElement((jobjectArray) *aParam, 0, jarray);
- }
- }
-
- // cleanup
- // If this is not an out param or if the invokeResult is a failure case,
- // then the array elements have not been cleaned up. Do so now.
- if (!aParamInfo.IsOut() || (NS_FAILED(aInvokeResult) && aVariant.val.p)) {
- nsXPTCVariant var;
- for (PRUint32 i = 0; i < aArraySize; i++) {
- rv = GetNativeArrayElement(aArrayType, aVariant.val.p, i, &var);
- if (NS_SUCCEEDED(rv)) {
- FinalizeParams(env, aParamInfo, aArrayType, var, aIID, PR_TRUE,
- 0, 0, i, NS_ERROR_FAILURE, nsnull);
- }
- }
- }
- PR_Free(aVariant.val.p);
- break;
- }
-
- case nsXPTType::T_PSTRING_SIZE_IS:
- case nsXPTType::T_PWSTRING_SIZE_IS:
- {
- NS_PRECONDITION(!aIsArrayElement, "sized string array not supported");
-
- if ((aParamInfo.IsOut()) && NS_SUCCEEDED(aInvokeResult))
- {
- // create new string from data
- jstring str = nsnull;
- if (aVariant.val.p) {
- if (aType == nsXPTType::T_PSTRING_SIZE_IS) {
- PRUint32 len = (aArraySize + 1) * sizeof(char);
- char* buf = (char*) nsMemory::Alloc(len);
- if (buf) {
- memcpy(buf, aVariant.val.p, len);
- buf[aArraySize] = '\0';
- str = env->NewStringUTF((const char*) buf);
- nsMemory::Free(buf);
- }
- } else {
- str = env->NewString((const jchar*) aVariant.val.p, aArraySize);
- }
- if (!str) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
- }
-
- if (aParamInfo.IsRetval()) {
- *aParam = str;
- } else if (*aParam) {
- // put new string into output array
- env->SetObjectArrayElement((jobjectArray) *aParam, aIndex, str);
- }
- }
-
- // cleanup
- if (aVariant.val.p)
- nsMemory::Free(aVariant.val.p);
- break;
- }
-
- default:
- NS_WARNING("unexpected parameter type");
- return NS_ERROR_UNEXPECTED;
- }
-
- // Check for Java exception, but don't overwrite pre-existing error code.
- if (NS_SUCCEEDED(rv) && env->ExceptionCheck())
- rv = NS_ERROR_FAILURE;
-
- return rv;
-}
-
-nsresult
-QueryAttributeInfo(nsIInterfaceInfo* aIInfo, const char* aMethodName,
- PRBool aCapitalizedAttr, PRUint16* aMethodIndex,
- const nsXPTMethodInfo** aMethodInfo)
-
-{
- nsresult rv = NS_ERROR_FAILURE;
-
- // An 'attribute' will start with either "get" or "set". But first,
- // we check the length, in order to skip over method names that match exactly
- // "get" or "set".
- if (strlen(aMethodName) > 3) {
- if (strncmp("get", aMethodName, 3) == 0) {
- char* getterName = strdup(aMethodName + 3);
- if (!aCapitalizedAttr) {
- getterName[0] = tolower(getterName[0]);
- }
- rv = aIInfo->GetMethodInfoForName(getterName, aMethodIndex, aMethodInfo);
- free(getterName);
- } else if (strncmp("set", aMethodName, 3) == 0) {
- char* setterName = strdup(aMethodName + 3);
- if (!aCapitalizedAttr) {
- setterName[0] = tolower(setterName[0]);
- }
- rv = aIInfo->GetMethodInfoForName(setterName, aMethodIndex, aMethodInfo);
- if (NS_SUCCEEDED(rv)) {
- // If this succeeded, GetMethodInfoForName will have returned the
- // method info for the 'getter'. We want the 'setter', so increase
- // method index by one ('setter' immediately follows the 'getter'),
- // and get its method info.
- (*aMethodIndex)++;
- rv = aIInfo->GetMethodInfo(*aMethodIndex, aMethodInfo);
- if (NS_SUCCEEDED(rv)) {
- // Double check that this methodInfo matches the given method.
- if (!(*aMethodInfo)->IsSetter() ||
- strcmp(setterName, (*aMethodInfo)->name) != 0) {
- rv = NS_ERROR_FAILURE;
- }
- }
- }
- free(setterName);
- }
- }
-
- return rv;
-}
-
-/**
- * Given an interface info struct and a method name, returns the method info
- * and index, if that method exists.
- *
- * Most method names are lower case. Unfortunately, the method names of some
- * interfaces (such as nsIAppShell) start with a capital letter. This function
- * will try all of the permutations.
- */
-nsresult
-QueryMethodInfo(nsIInterfaceInfo* aIInfo, const char* aMethodName,
- PRUint16* aMethodIndex, const nsXPTMethodInfo** aMethodInfo)
-{
- // Skip over any leading underscores, since these are methods that conflicted
- // with existing Java keywords
- const char* methodName = aMethodName;
- if (methodName[0] == '_') {
- methodName++;
- }
-
- // The common case is that the method name is lower case, so we check
- // that first.
- nsresult rv;
- rv = aIInfo->GetMethodInfoForName(methodName, aMethodIndex, aMethodInfo);
- if (NS_SUCCEEDED(rv))
- return rv;
-
- // If there is no method called <aMethodName>, then maybe it is an
- // 'attribute'.
- rv = QueryAttributeInfo(aIInfo, methodName, PR_FALSE, aMethodIndex,
- aMethodInfo);
- if (NS_SUCCEEDED(rv))
- return rv;
-
- // If we get here, then maybe the method name is capitalized.
- char* name = strdup(methodName);
- name[0] = toupper(name[0]);
- rv = aIInfo->GetMethodInfoForName(name, aMethodIndex, aMethodInfo);
- free(name);
- if (NS_SUCCEEDED(rv))
- return rv;
-
- // If there is no method called <aMethodName>, then maybe it is an
- // 'attribute'.
- rv = QueryAttributeInfo(aIInfo, methodName, PR_TRUE, aMethodIndex,
- aMethodInfo);
-
- return rv;
-}
-
-/**
- * org.mozilla.xpcom.XPCOMJavaProxy.internal.callXPCOMMethod
- */
-extern "C" NS_EXPORT jobject JNICALL
-JAVAPROXY_NATIVE(callXPCOMMethod) (JNIEnv *env, jclass that, jobject aJavaProxy,
- jstring aMethodName, jobjectArray aParams)
-{
- nsresult rv;
-
- // Get native XPCOM instance
- void* xpcom_obj;
- rv = GetXPCOMInstFromProxy(env, aJavaProxy, &xpcom_obj);
- if (NS_FAILED(rv)) {
- ThrowException(env, 0, "Failed to get matching XPCOM object");
- return nsnull;
- }
- JavaXPCOMInstance* inst = static_cast<JavaXPCOMInstance*>(xpcom_obj);
-
- // Get method info
- PRUint16 methodIndex;
- const nsXPTMethodInfo* methodInfo;
- nsIInterfaceInfo* iinfo = inst->InterfaceInfo();
- const char* methodName = env->GetStringUTFChars(aMethodName, nsnull);
- rv = QueryMethodInfo(iinfo, methodName, &methodIndex, &methodInfo);
- env->ReleaseStringUTFChars(aMethodName, methodName);
-
- if (NS_FAILED(rv)) {
- ThrowException(env, rv, "GetMethodInfoForName failed");
- return nsnull;
- }
-
-#ifdef DEBUG_JAVAXPCOM
- const char* ifaceName;
- iinfo->GetNameShared(&ifaceName);
- LOG(("===> (XPCOM) %s::%s()\n", ifaceName, methodInfo->GetName()));
-#endif
-
- // Convert the Java params
- PRUint8 paramCount = methodInfo->GetParamCount();
- nsXPTCVariant* params = nsnull;
- if (paramCount)
- {
- params = new nsXPTCVariant[paramCount];
- if (!params) {
- ThrowException(env, NS_ERROR_OUT_OF_MEMORY, "Can't create params array");
- return nsnull;
- }
- memset(params, 0, paramCount * sizeof(nsXPTCVariant));
-
- PRBool foundDependentParam = PR_FALSE;
- for (PRUint8 i = 0; i < paramCount && NS_SUCCEEDED(rv); i++)
- {
- LOG(("\t Param %d: ", i));
- const nsXPTParamInfo ¶mInfo = methodInfo->GetParam(i);
- params[i].type = paramInfo.GetType();
-
- if (params[i].type.IsDependent() && paramInfo.IsIn()) {
- foundDependentParam = PR_TRUE;
- continue;
- }
-
- if (paramInfo.IsIn()) {
- PRUint8 type = params[i].type.TagPart();
-
- // get IID for interface params
- nsID iid;
- if (type == nsXPTType::T_INTERFACE) {
- rv = GetIIDForMethodParam(iinfo, methodInfo, paramInfo, type,
- methodIndex, params, PR_TRUE, iid);
- }
-
- if (NS_SUCCEEDED(rv)) {
- jobject param = nsnull;
- if (aParams && !paramInfo.IsRetval()) {
- param = env->GetObjectArrayElement(aParams, i);
- }
- rv = SetupParams(env, param, type, paramInfo.IsOut(), iid, 0, 0,
- PR_FALSE, 0, params[i]);
- }
- } else {
- LOG(("out/retval\n"));
- params[i].ptr = &(params[i].val);
- params[i].SetPtrIsData();
- }
- }
-
- // Handle any dependent params by doing a second pass
- if (foundDependentParam) {
-
- for (PRUint8 j = 0; j < paramCount && NS_SUCCEEDED(rv); j++) {
-
- const nsXPTParamInfo ¶mInfo = methodInfo->GetParam(j);
- params[j].type = paramInfo.GetType();
-
- if (!params[j].type.IsDependent())
- continue;
-
- if (paramInfo.IsIn()) {
- PRUint8 type = params[j].type.TagPart();
-
- // is paramater an array or sized string?
- PRUint8 arrayType = 0;
- PRUint32 arraySize = 0;
- PRBool isArray = params[j].type.IsArray();
- PRBool isSizedString = isArray ? PR_FALSE :
- type == nsXPTType::T_PSTRING_SIZE_IS ||
- type == nsXPTType::T_PWSTRING_SIZE_IS;
-
- if (isArray) {
- // get array type
- nsXPTType xpttype;
- rv = iinfo->GetTypeForParam(methodIndex, ¶mInfo, 1, &xpttype);
- if (NS_FAILED(rv))
- break;
- arrayType = xpttype.TagPart();
- // IDL 'octet' arrays are not 'promoted' to short, but kept as 'byte';
- // therefore, treat as a signed 8bit value
- if (arrayType == nsXPTType::T_U8)
- arrayType = nsXPTType::T_I8;
- }
-
- if (isArray || isSizedString) {
- // get size of array or string
- PRUint8 argnum;
- rv = iinfo->GetSizeIsArgNumberForParam(methodIndex, ¶mInfo, 0,
- &argnum);
- if (NS_FAILED(rv))
- break;
- arraySize = params[argnum].val.u32;
- }
-
- // get IID for interface params
- nsID iid;
- if (type == nsXPTType::T_INTERFACE_IS ||
- type == nsXPTType::T_ARRAY &&
- (arrayType == nsXPTType::T_INTERFACE ||
- arrayType == nsXPTType::T_INTERFACE_IS))
- {
- PRUint8 paramType = type == nsXPTType::T_ARRAY ? arrayType : type;
- rv = GetIIDForMethodParam(iinfo, methodInfo, paramInfo, paramType,
- methodIndex, params, PR_TRUE, iid);
- }
-
- if (NS_SUCCEEDED(rv)) {
- jobject param = nsnull;
- if (aParams && !paramInfo.IsRetval()) {
- param = env->GetObjectArrayElement(aParams, j);
- }
- rv = SetupParams(env, param, type, paramInfo.IsOut(), iid, arrayType,
- arraySize, PR_FALSE, 0, params[j]);
- }
- }
- }
- }
-
- if (NS_FAILED(rv)) {
- ThrowException(env, rv, "SetupParams failed");
- return nsnull;
- }
- }
-
- // Call the XPCOM method
- const nsIID* iid;
- iinfo->GetIIDShared(&iid);
- nsISupports* realObject;
- rv = inst->GetInstance()->QueryInterface(*iid, (void**) &realObject);
- if (NS_FAILED(rv)) {
- ThrowException(env, rv, "Failed to get real XPCOM object");
- return nsnull;
- }
- nsresult invokeResult = NS_InvokeByIndex(realObject, methodIndex,
- paramCount, params);
- NS_RELEASE(realObject);
-
- // Clean up params
- jobject result = nsnull;
- for (PRUint8 i = 0; i < paramCount && NS_SUCCEEDED(rv); i++)
- {
- const nsXPTParamInfo ¶mInfo = methodInfo->GetParam(i);
- PRUint8 type = paramInfo.GetType().TagPart();
-
- // is paramater an array or sized string?
- PRUint8 arrayType = 0;
- PRUint32 arraySize = 0;
- PRBool isArray = params[i].type.IsArray();
- PRBool isSizedString = isArray ? PR_FALSE :
- type == nsXPTType::T_PSTRING_SIZE_IS ||
- type == nsXPTType::T_PWSTRING_SIZE_IS;
-
- if (isArray) {
- // get array type
- nsXPTType array_xpttype;
- rv = iinfo->GetTypeForParam(methodIndex, ¶mInfo, 1, &array_xpttype);
- if (NS_FAILED(rv))
- break;
- arrayType = array_xpttype.TagPart();
- // IDL 'octet' arrays are not 'promoted' to short, but kept as 'byte';
- // therefore, treat as a signed 8bit value
- if (arrayType == nsXPTType::T_U8)
- arrayType = nsXPTType::T_I8;
- }
-
- if (isArray || isSizedString) {
- // get size of array
- PRUint8 argnum;
- rv = iinfo->GetSizeIsArgNumberForParam(methodIndex, ¶mInfo, 0,
- &argnum);
- if (NS_FAILED(rv))
- break;
- arraySize = params[argnum].val.u32;
- }
-
- // get IID for interface params
- nsID iid;
- if (type == nsXPTType::T_INTERFACE || type == nsXPTType::T_INTERFACE_IS ||
- type == nsXPTType::T_ARRAY && (arrayType == nsXPTType::T_INTERFACE ||
- arrayType == nsXPTType::T_INTERFACE_IS))
- {
- PRUint8 paramType = type == nsXPTType::T_ARRAY ? arrayType : type;
- rv = GetIIDForMethodParam(iinfo, methodInfo, paramInfo, paramType,
- methodIndex, params, PR_TRUE, iid);
- if (NS_FAILED(rv))
- break;
- }
-
- jobject* javaElement;
- if (!paramInfo.IsRetval()) {
- jobject element = env->GetObjectArrayElement(aParams, i);
- javaElement = &element;
- } else {
- javaElement = &result;
- }
- rv = FinalizeParams(env, paramInfo, type, params[i], iid, PR_FALSE,
- arrayType, arraySize, 0, invokeResult, javaElement);
- }
-
- // Normally, we would delete any created nsID object in the above loop.
- // However, GetIIDForMethodParam may need some of the nsID params when it's
- // looking for the IID of an INTERFACE_IS. Therefore, we can't delete it
- // until we've gone through the 'Finalize' loop once and created the result.
- for (PRUint8 j = 0; j < paramCount; j++)
- {
- const nsXPTParamInfo ¶mInfo = methodInfo->GetParam(j);
- const nsXPTType &type = paramInfo.GetType();
- if (type.TagPart() == nsXPTType::T_IID) {
- nsID* iid = (nsID*) params[j].val.p;
- delete iid;
- }
- }
-
- if (params) {
- delete params;
- }
-
- // If the XPCOM method invocation failed, we don't immediately throw an
- // exception and return so that we can clean up any parameters.
- if (NS_FAILED(invokeResult)) {
- nsCAutoString message("The function \"");
- message.AppendASCII(methodInfo->GetName());
- message.AppendLiteral("\" returned an error condition");
- ThrowException(env, invokeResult, message.get());
- }
- if (NS_FAILED(rv)) {
- ThrowException(env, rv, "FinalizeParams failed");
- return nsnull;
- }
-
- LOG(("<=== (XPCOM) %s::%s()\n", ifaceName, methodInfo->GetName()));
- return result;
-}
-
-nsresult
-GetNewOrUsedJavaWrapper(JNIEnv* env, nsISupports* aXPCOMObject,
- const nsIID& aIID, jobject aObjectLoader,
- jobject* aResult)
-{
- NS_PRECONDITION(aResult != nsnull, "null ptr");
- if (!aResult)
- return NS_ERROR_NULL_POINTER;
-
- // Get the root nsISupports of the xpcom object
- nsresult rv;
- nsCOMPtr<nsISupports> rootObject = do_QueryInterface(aXPCOMObject, &rv);
- NS_ENSURE_SUCCESS(rv, rv);
-
- // Get associated Java object from hash table
- rv = gNativeToJavaProxyMap->Find(env, rootObject, aIID, aResult);
- NS_ENSURE_SUCCESS(rv, rv);
- if (*aResult)
- return NS_OK;
-
- // No Java object is associated with the given XPCOM object, so we
- // create a Java proxy.
-
- nsCOMPtr<nsIInterfaceInfoManager>
- iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID));
- NS_ASSERTION(iim, "Failed to get InterfaceInfoManager");
- if (!iim)
- return NS_ERROR_FAILURE;
-
- // Get interface info for class
- nsCOMPtr<nsIInterfaceInfo> info;
- rv = iim->GetInfoForIID(&aIID, getter_AddRefs(info));
- if (NS_FAILED(rv))
- return rv;
-
- // Wrap XPCOM object (addrefs rootObject)
- JavaXPCOMInstance* inst = new JavaXPCOMInstance(rootObject, info);
- if (!inst)
- return NS_ERROR_OUT_OF_MEMORY;
-
- // Get interface name
- const char* iface_name;
- rv = info->GetNameShared(&iface_name);
-
- if (NS_SUCCEEDED(rv)) {
- jobject java_obj = nsnull;
-
- // Create proper Java interface name
- nsCAutoString class_name("org.mozilla.interfaces.");
- class_name.AppendASCII(iface_name);
- jclass ifaceClass = FindClassInLoader(env, aObjectLoader, class_name.get());
-
- if (ifaceClass) {
- java_obj = env->CallStaticObjectMethod(xpcomJavaProxyClass,
- createProxyMID, ifaceClass,
- reinterpret_cast<jlong>(inst));
- if (env->ExceptionCheck())
- java_obj = nsnull;
- }
-
- if (java_obj) {
-#ifdef DEBUG_JAVAXPCOM
- char* iid_str = aIID.ToString();
- LOG(("+ CreateJavaProxy (Java=%08x | XPCOM=%08x | IID=%s)\n",
- (PRUint32) env->CallStaticIntMethod(systemClass, hashCodeMID,
- java_obj),
- (PRUint32) rootObject, iid_str));
- NS_Free(iid_str);
-#endif
-
- // Associate XPCOM object with Java proxy
- rv = gNativeToJavaProxyMap->Add(env, rootObject, aIID, java_obj);
- if (NS_SUCCEEDED(rv)) {
- *aResult = java_obj;
- return NS_OK;
- }
- } else {
- rv = NS_ERROR_FAILURE;
- }
- }
-
- // If there was an error, clean up.
- delete inst;
- return rv;
-}
-
-nsresult
-GetXPCOMInstFromProxy(JNIEnv* env, jobject aJavaObject, void** aResult)
-{
- NS_PRECONDITION(aResult != nsnull, "null ptr");
- if (!aResult)
- return NS_ERROR_NULL_POINTER;
-
- jlong xpcom_obj = env->CallStaticLongMethod(xpcomJavaProxyClass,
- getNativeXPCOMInstMID, aJavaObject);
-
- if (!xpcom_obj || env->ExceptionCheck()) {
- return NS_ERROR_FAILURE;
- }
-
- *aResult = reinterpret_cast<void*>(xpcom_obj);
-#ifdef DEBUG_JAVAXPCOM
- JavaXPCOMInstance* inst = static_cast<JavaXPCOMInstance*>(*aResult);
- nsIID* iid;
- inst->InterfaceInfo()->GetInterfaceIID(&iid);
- char* iid_str = iid->ToString();
- LOG(("< GetXPCOMInstFromProxy (Java=%08x | XPCOM=%08x | IID=%s)\n",
- (PRUint32) env->CallStaticIntMethod(systemClass, hashCodeMID,
- aJavaObject),
- (PRUint32) inst->GetInstance(), iid_str));
- NS_Free(iid_str);
- nsMemory::Free(iid);
-#endif
- return NS_OK;
-}
-
-/**
- * org.mozilla.xpcom.internal.XPCOMJavaProxy.finalizeProxy
- */
-extern "C" NS_EXPORT void JNICALL
-JAVAPROXY_NATIVE(finalizeProxy) (JNIEnv *env, jclass that, jobject aJavaProxy)
-{
-#ifdef DEBUG_JAVAXPCOM
- PRUint32 xpcom_addr = 0;
-#endif
-
- // Due to Java's garbage collection, this finalize statement may get called
- // after FreeJavaGlobals(). So check to make sure that everything is still
- // initialized.
- if (gJavaXPCOMLock) {
- nsAutoLock lock(gJavaXPCOMLock);
-
- // If may be possible for the lock to be acquired here when FreeGlobals is
- // in the middle of running. If so, then this thread will sleep until
- // FreeGlobals releases its lock. At that point, we resume this thread
- // here, but JavaXPCOM may no longer be initialized. So we need to check
- // that everything is legit after acquiring the lock.
- if (gJavaXPCOMInitialized) {
- // Get native XPCOM instance
- void* xpcom_obj;
- nsresult rv = GetXPCOMInstFromProxy(env, aJavaProxy, &xpcom_obj);
- if (NS_SUCCEEDED(rv)) {
- JavaXPCOMInstance* inst = static_cast<JavaXPCOMInstance*>(xpcom_obj);
-#ifdef DEBUG_JAVAXPCOM
- xpcom_addr = reinterpret_cast<PRUint32>(inst->GetInstance());
-#endif
- nsIID* iid;
- rv = inst->InterfaceInfo()->GetInterfaceIID(&iid);
- if (NS_SUCCEEDED(rv)) {
- rv = gNativeToJavaProxyMap->Remove(env, inst->GetInstance(), *iid);
- nsMemory::Free(iid);
- }
- NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to RemoveJavaProxy");
- // Release gJavaXPCOMLock before deleting inst (see bug 340022)
- lock.unlock();
- delete inst;
- }
- }
- }
-
-#ifdef DEBUG_JAVAXPCOM
- LOG(("- Finalize (Java=%08x | XPCOM=%08x)\n",
- (PRUint32) env->CallStaticIntMethod(systemClass, hashCodeMID,
- aJavaProxy),
- xpcom_addr));
-#endif
-}
-
-/**
- * org.mozilla.xpcom.XPCOMJavaProxy.isSameXPCOMObject
- */
-extern "C" NS_EXPORT jboolean JNICALL
-JAVAPROXY_NATIVE(isSameXPCOMObject) (JNIEnv *env, jclass that,
- jobject aProxy1, jobject aProxy2)
-{
- void* xpcom_obj1;
- nsresult rv = GetXPCOMInstFromProxy(env, aProxy1, &xpcom_obj1);
- if (NS_SUCCEEDED(rv)) {
- void* xpcom_obj2;
- rv = GetXPCOMInstFromProxy(env, aProxy2, &xpcom_obj2);
- if (NS_SUCCEEDED(rv)) {
- JavaXPCOMInstance* inst1 = static_cast<JavaXPCOMInstance*>(xpcom_obj1);
- JavaXPCOMInstance* inst2 = static_cast<JavaXPCOMInstance*>(xpcom_obj2);
- if (inst1->GetInstance() == inst2->GetInstance()) {
- return JNI_TRUE;
- }
- }
- }
- return JNI_FALSE;
-}
-
-/**
- * org.mozilla.xpcom.ProfileLock.release
- */
-extern "C" NS_EXPORT void JNICALL
-LOCKPROXY_NATIVE(release) (JNIEnv *env, jclass that, jlong aLockObject)
-{
- // Need to release object on the main thread.
- nsresult rv = NS_ERROR_FAILURE;
- nsCOMPtr<nsIThread> thread = do_GetMainThread();
- if (thread) {
- rv = NS_ProxyRelease(thread, reinterpret_cast<nsISupports*>(aLockObject));
- }
- NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to release using NS_ProxyRelease");
-}
deleted file mode 100644
--- a/extensions/java/xpcom/src/nsJavaWrapper.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is
- * IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2004
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 _nsJavaWrapper_h_
-#define _nsJavaWrapper_h_
-
-#include "jni.h"
-#include "nsISupports.h"
-
-
-/**
- * Finds the associated Java wraper for the given XPCOM object and IID. If no
- * such Java wrapper exists, then a new one is created.
- *
- * @param env Java environment pointer
- * @param aXPCOMObject XPCOM object for which to find/create Java wrapper
- * @param aIID desired interface IID for Java wrapper
- * @param aObjectLoader Java wrapper whose class loader we use for finding
- * classes; can be null
- * @param aResult on success, holds reference to Java wrapper
- *
- * @return NS_OK if succeeded; all other return values are error codes.
- */
-nsresult GetNewOrUsedJavaWrapper(JNIEnv* env, nsISupports* aXPCOMObject,
- const nsIID& aIID, jobject aObjectLoader,
- jobject* aResult);
-
-/**
- * Returns the XPCOM object for which the given Java proxy was created.
- *
- * @param env pointer to Java context
- * @param aJavaObject a Java proxy created by CreateJavaProxy()
- * @param aResult on exit, holds pointer to XPCOM instance
- *
- * @return NS_OK if the XPCOM object was successfully retrieved;
- * any other value denotes an error condition.
- */
-nsresult GetXPCOMInstFromProxy(JNIEnv* env, jobject aJavaObject,
- void** aResult);
-
-#endif // _nsJavaWrapper_h_
deleted file mode 100644
--- a/extensions/java/xpcom/src/nsJavaXPCOMBindingUtils.cpp
+++ /dev/null
@@ -1,1061 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is
- * IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2005
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 "nsJavaXPCOMBindingUtils.h"
-#include "nsJavaXPTCStub.h"
-#include "nsJavaWrapper.h"
-#include "jni.h"
-#include "nsIInterfaceInfoManager.h"
-#include "nsILocalFile.h"
-#include "nsThreadUtils.h"
-#include "nsProxyRelease.h"
-
-
-/* Java JNI globals */
-
-JavaVM* gCachedJVM = nsnull;
-
-jclass systemClass = nsnull;
-jclass booleanClass = nsnull;
-jclass charClass = nsnull;
-jclass byteClass = nsnull;
-jclass shortClass = nsnull;
-jclass intClass = nsnull;
-jclass longClass = nsnull;
-jclass floatClass = nsnull;
-jclass doubleClass = nsnull;
-jclass stringClass = nsnull;
-jclass nsISupportsClass = nsnull;
-jclass xpcomExceptionClass = nsnull;
-jclass xpcomJavaProxyClass = nsnull;
-jclass weakReferenceClass = nsnull;
-jclass javaXPCOMUtilsClass = nsnull;
-
-jmethodID hashCodeMID = nsnull;
-jmethodID booleanValueMID = nsnull;
-jmethodID booleanInitMID = nsnull;
-jmethodID charValueMID = nsnull;
-jmethodID charInitMID = nsnull;
-jmethodID byteValueMID = nsnull;
-jmethodID byteInitMID = nsnull;
-jmethodID shortValueMID = nsnull;
-jmethodID shortInitMID = nsnull;
-jmethodID intValueMID = nsnull;
-jmethodID intInitMID = nsnull;
-jmethodID longValueMID = nsnull;
-jmethodID longInitMID = nsnull;
-jmethodID floatValueMID = nsnull;
-jmethodID floatInitMID = nsnull;
-jmethodID doubleValueMID = nsnull;
-jmethodID doubleInitMID = nsnull;
-jmethodID createProxyMID = nsnull;
-jmethodID isXPCOMJavaProxyMID = nsnull;
-jmethodID getNativeXPCOMInstMID = nsnull;
-jmethodID weakReferenceConstructorMID = nsnull;
-jmethodID getReferentMID = nsnull;
-jmethodID clearReferentMID = nsnull;
-jmethodID findClassInLoaderMID = nsnull;
-
-#ifdef DEBUG_JAVAXPCOM
-jmethodID getNameMID = nsnull;
-jmethodID proxyToStringMID = nsnull;
-#endif
-
-NativeToJavaProxyMap* gNativeToJavaProxyMap = nsnull;
-JavaToXPTCStubMap* gJavaToXPTCStubMap = nsnull;
-
-PRBool gJavaXPCOMInitialized = PR_FALSE;
-PRLock* gJavaXPCOMLock = nsnull;
-
-static const char* kJavaKeywords[] = {
- "abstract", "default" , "if" , "private" , "throw" ,
- "boolean" , "do" , "implements", "protected" , "throws" ,
- "break" , "double" , "import", "public" , "transient" ,
- "byte" , "else" , "instanceof", "return" , "try" ,
- "case" , "extends" , "int" , "short" , "void" ,
- "catch" , "final" , "interface" , "static" , "volatile" ,
- "char" , "finally" , "long" , "super" , "while" ,
- "class" , "float" , "native" , "switch" ,
- "const" , "for" , "new" , "synchronized",
- "continue", "goto" , "package" , "this" ,
- /* added in Java 1.2 */
- "strictfp",
- /* added in Java 1.4 */
- "assert" ,
- /* added in Java 5.0 */
- "enum" ,
- /* Java constants */
- "true" , "false" , "null" ,
- /* java.lang.Object methods *
- * - don't worry about "toString", since it does the same thing *
- * as Object's "toString" */
- "clone" , "equals" , "finalize" , "getClass" , "hashCode" ,
- "notify" , "notifyAll", /*"toString" ,*/ "wait"
-};
-
-nsTHashtable<nsDepCharHashKey>* gJavaKeywords = nsnull;
-
-
-/******************************
- * InitializeJavaGlobals
- ******************************/
-PRBool
-InitializeJavaGlobals(JNIEnv *env)
-{
- if (gJavaXPCOMInitialized)
- return PR_TRUE;
-
- // Save pointer to JavaVM, which is valid across threads.
- jint rc = env->GetJavaVM(&gCachedJVM);
- if (rc != 0) {
- NS_WARNING("Failed to get JavaVM");
- goto init_error;
- }
-
- jclass clazz;
- if (!(clazz = env->FindClass("java/lang/System")) ||
- !(systemClass = (jclass) env->NewGlobalRef(clazz)) ||
- !(hashCodeMID = env->GetStaticMethodID(clazz, "identityHashCode",
- "(Ljava/lang/Object;)I")))
- {
- NS_WARNING("Problem creating java.lang.System globals");
- goto init_error;
- }
-
- if (!(clazz = env->FindClass("java/lang/Boolean")) ||
- !(booleanClass = (jclass) env->NewGlobalRef(clazz)) ||
- !(booleanValueMID = env->GetMethodID(clazz, "booleanValue", "()Z")) ||
- !(booleanInitMID = env->GetMethodID(clazz, "<init>", "(Z)V")))
- {
- NS_WARNING("Problem creating java.lang.Boolean globals");
- goto init_error;
- }
-
- if (!(clazz = env->FindClass("java/lang/Character")) ||
- !(charClass = (jclass) env->NewGlobalRef(clazz)) ||
- !(charValueMID = env->GetMethodID(clazz, "charValue", "()C")) ||
- !(charInitMID = env->GetMethodID(clazz, "<init>", "(C)V")))
- {
- NS_WARNING("Problem creating java.lang.Character globals");
- goto init_error;
- }
-
- if (!(clazz = env->FindClass("java/lang/Byte")) ||
- !(byteClass = (jclass) env->NewGlobalRef(clazz)) ||
- !(byteValueMID = env->GetMethodID(clazz, "byteValue", "()B")) ||
- !(byteInitMID = env->GetMethodID(clazz, "<init>", "(B)V")))
- {
- NS_WARNING("Problem creating java.lang.Byte globals");
- goto init_error;
- }
-
- if (!(clazz = env->FindClass("java/lang/Short")) ||
- !(shortClass = (jclass) env->NewGlobalRef(clazz)) ||
- !(shortValueMID = env->GetMethodID(clazz, "shortValue", "()S")) ||
- !(shortInitMID = env->GetMethodID(clazz, "<init>", "(S)V")))
- {
- NS_WARNING("Problem creating java.lang.Short globals");
- goto init_error;
- }
-
- if (!(clazz = env->FindClass("java/lang/Integer")) ||
- !(intClass = (jclass) env->NewGlobalRef(clazz)) ||
- !(intValueMID = env->GetMethodID(clazz, "intValue", "()I")) ||
- !(intInitMID = env->GetMethodID(clazz, "<init>", "(I)V")))
- {
- NS_WARNING("Problem creating java.lang.Integer globals");
- goto init_error;
- }
-
- if (!(clazz = env->FindClass("java/lang/Long")) ||
- !(longClass = (jclass) env->NewGlobalRef(clazz)) ||
- !(longValueMID = env->GetMethodID(clazz, "longValue", "()J")) ||
- !(longInitMID = env->GetMethodID(clazz, "<init>", "(J)V")))
- {
- NS_WARNING("Problem creating java.lang.Long globals");
- goto init_error;
- }
-
- if (!(clazz = env->FindClass("java/lang/Float")) ||
- !(floatClass = (jclass) env->NewGlobalRef(clazz)) ||
- !(floatValueMID = env->GetMethodID(clazz, "floatValue", "()F")) ||
- !(floatInitMID = env->GetMethodID(clazz, "<init>", "(F)V")))
- {
- NS_WARNING("Problem creating java.lang.Float globals");
- goto init_error;
- }
-
- if (!(clazz = env->FindClass("java/lang/Double")) ||
- !(doubleClass = (jclass) env->NewGlobalRef(clazz)) ||
- !(doubleValueMID = env->GetMethodID(clazz, "doubleValue", "()D")) ||
- !(doubleInitMID = env->GetMethodID(clazz, "<init>", "(D)V")))
- {
- NS_WARNING("Problem creating java.lang.Double globals");
- goto init_error;
- }
-
- if (!(clazz = env->FindClass("java/lang/String")) ||
- !(stringClass = (jclass) env->NewGlobalRef(clazz)))
- {
- NS_WARNING("Problem creating java.lang.String globals");
- goto init_error;
- }
-
- if (!(clazz = env->FindClass("org/mozilla/interfaces/nsISupports")) ||
- !(nsISupportsClass = (jclass) env->NewGlobalRef(clazz)))
- {
- NS_WARNING("Problem creating org.mozilla.interfaces.nsISupports globals");
- goto init_error;
- }
-
- if (!(clazz = env->FindClass("org/mozilla/xpcom/XPCOMException")) ||
- !(xpcomExceptionClass = (jclass) env->NewGlobalRef(clazz)))
- {
- NS_WARNING("Problem creating org.mozilla.xpcom.XPCOMException globals");
- goto init_error;
- }
-
- if (!(clazz = env->FindClass("org/mozilla/xpcom/internal/XPCOMJavaProxy")) ||
- !(xpcomJavaProxyClass = (jclass) env->NewGlobalRef(clazz)) ||
- !(createProxyMID = env->GetStaticMethodID(clazz, "createProxy",
- "(Ljava/lang/Class;J)Ljava/lang/Object;")) ||
- !(isXPCOMJavaProxyMID = env->GetStaticMethodID(clazz, "isXPCOMJavaProxy",
- "(Ljava/lang/Object;)Z")) ||
- !(getNativeXPCOMInstMID = env->GetStaticMethodID(xpcomJavaProxyClass,
- "getNativeXPCOMInstance",
- "(Ljava/lang/Object;)J")))
- {
- NS_WARNING("Problem creating org.mozilla.xpcom.internal.XPCOMJavaProxy globals");
- goto init_error;
- }
-
- if (!(clazz = env->FindClass("java/lang/ref/WeakReference")) ||
- !(weakReferenceClass = (jclass) env->NewGlobalRef(clazz)) ||
- !(weakReferenceConstructorMID = env->GetMethodID(weakReferenceClass,
- "<init>","(Ljava/lang/Object;)V")) ||
- !(getReferentMID = env->GetMethodID(weakReferenceClass,
- "get", "()Ljava/lang/Object;")) ||
- !(clearReferentMID = env->GetMethodID(weakReferenceClass,
- "clear", "()V")))
- {
- NS_WARNING("Problem creating java.lang.ref.WeakReference globals");
- goto init_error;
- }
-
- if (!(clazz = env->FindClass("org/mozilla/xpcom/internal/JavaXPCOMMethods")) ||
- !(javaXPCOMUtilsClass = (jclass) env->NewGlobalRef(clazz)) ||
- !(findClassInLoaderMID = env->GetStaticMethodID(clazz,
- "findClassInLoader",
- "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Class;")))
- {
- NS_WARNING("Problem creating org.mozilla.xpcom.internal.JavaXPCOMMethods globals");
- goto init_error;
- }
-
-#ifdef DEBUG_JAVAXPCOM
- if (!(clazz = env->FindClass("java/lang/Class")) ||
- !(getNameMID = env->GetMethodID(clazz, "getName","()Ljava/lang/String;")))
- {
- NS_WARNING("Problem creating java.lang.Class globals");
- goto init_error;
- }
-
- if (!(proxyToStringMID = env->GetStaticMethodID(xpcomJavaProxyClass,
- "proxyToString",
- "(Ljava/lang/Object;)Ljava/lang/String;")))
- {
- NS_WARNING("Problem creating proxyToString global");
- goto init_error;
- }
-#endif
-
- gNativeToJavaProxyMap = new NativeToJavaProxyMap();
- if (!gNativeToJavaProxyMap || NS_FAILED(gNativeToJavaProxyMap->Init())) {
- NS_WARNING("Problem creating NativeToJavaProxyMap");
- goto init_error;
- }
- gJavaToXPTCStubMap = new JavaToXPTCStubMap();
- if (!gJavaToXPTCStubMap || NS_FAILED(gJavaToXPTCStubMap->Init())) {
- NS_WARNING("Problem creating JavaToXPTCStubMap");
- goto init_error;
- }
-
- {
- nsresult rv = NS_OK;
- PRUint32 size = NS_ARRAY_LENGTH(kJavaKeywords);
- gJavaKeywords = new nsTHashtable<nsDepCharHashKey>();
- if (!gJavaKeywords || NS_FAILED(gJavaKeywords->Init(size))) {
- NS_WARNING("Failed to init JavaKeywords HashSet");
- goto init_error;
- }
- for (PRUint32 i = 0; i < size && NS_SUCCEEDED(rv); i++) {
- if (!gJavaKeywords->PutEntry(kJavaKeywords[i])) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- }
- }
- if (NS_FAILED(rv)) {
- NS_WARNING("Failed to populate JavaKeywords hash");
- goto init_error;
- }
- }
-
- gJavaXPCOMLock = nsAutoLock::NewLock("gJavaXPCOMLock");
- gJavaXPCOMInitialized = PR_TRUE;
- return PR_TRUE;
-
-init_error:
- // If we encounter an error during initialization, then free any globals that
- // were allocated, and return false.
- FreeJavaGlobals(env);
- return PR_FALSE;
-}
-
-/*************************
- * FreeJavaGlobals
- *************************/
-void
-FreeJavaGlobals(JNIEnv* env)
-{
- PRLock* tempLock = nsnull;
- if (gJavaXPCOMLock) {
- PR_Lock(gJavaXPCOMLock);
-
- // null out global lock so no one else can use it
- tempLock = gJavaXPCOMLock;
- gJavaXPCOMLock = nsnull;
- }
-
- gJavaXPCOMInitialized = PR_FALSE;
-
- // Free the mappings first, since that process depends on some of the Java
- // globals that are freed later.
- if (gNativeToJavaProxyMap) {
- gNativeToJavaProxyMap->Destroy(env);
- delete gNativeToJavaProxyMap;
- gNativeToJavaProxyMap = nsnull;
- }
- if (gJavaToXPTCStubMap) {
- gJavaToXPTCStubMap->Destroy();
- delete gJavaToXPTCStubMap;
- gJavaToXPTCStubMap = nsnull;
- }
-
- // Free remaining Java globals
- if (systemClass) {
- env->DeleteGlobalRef(systemClass);
- systemClass = nsnull;
- }
- if (booleanClass) {
- env->DeleteGlobalRef(booleanClass);
- booleanClass = nsnull;
- }
- if (charClass) {
- env->DeleteGlobalRef(charClass);
- charClass = nsnull;
- }
- if (byteClass) {
- env->DeleteGlobalRef(byteClass);
- byteClass = nsnull;
- }
- if (shortClass) {
- env->DeleteGlobalRef(shortClass);
- shortClass = nsnull;
- }
- if (intClass) {
- env->DeleteGlobalRef(intClass);
- intClass = nsnull;
- }
- if (longClass) {
- env->DeleteGlobalRef(longClass);
- longClass = nsnull;
- }
- if (floatClass) {
- env->DeleteGlobalRef(floatClass);
- floatClass = nsnull;
- }
- if (doubleClass) {
- env->DeleteGlobalRef(doubleClass);
- doubleClass = nsnull;
- }
- if (stringClass) {
- env->DeleteGlobalRef(stringClass);
- stringClass = nsnull;
- }
- if (nsISupportsClass) {
- env->DeleteGlobalRef(nsISupportsClass);
- nsISupportsClass = nsnull;
- }
- if (xpcomExceptionClass) {
- env->DeleteGlobalRef(xpcomExceptionClass);
- xpcomExceptionClass = nsnull;
- }
- if (xpcomJavaProxyClass) {
- env->DeleteGlobalRef(xpcomJavaProxyClass);
- xpcomJavaProxyClass = nsnull;
- }
- if (weakReferenceClass) {
- env->DeleteGlobalRef(weakReferenceClass);
- weakReferenceClass = nsnull;
- }
-
- if (gJavaKeywords) {
- delete gJavaKeywords;
- gJavaKeywords = nsnull;
- }
-
- if (tempLock) {
- PR_Unlock(tempLock);
- nsAutoLock::DestroyLock(tempLock);
- }
-}
-
-
-/**************************************
- * Java<->XPCOM object mappings
- **************************************/
-
-// NativeToJavaProxyMap: The common case is that each XPCOM object will have
-// one Java proxy. But there are instances where there will be multiple Java
-// proxies for a given XPCOM object, each representing a different interface.
-// So we optimize the common case by using a hash table. Then, if there are
-// multiple Java proxies, we cycle through the linked list, comparing IIDs.
-
-nsresult
-NativeToJavaProxyMap::Init()
-{
- mHashTable = PL_NewDHashTable(PL_DHashGetStubOps(), nsnull,
- sizeof(Entry), 16);
- if (!mHashTable)
- return NS_ERROR_OUT_OF_MEMORY;
- return NS_OK;
-}
-
-PLDHashOperator
-DestroyJavaProxyMappingEnum(PLDHashTable* aTable, PLDHashEntryHdr* aHeader,
- PRUint32 aNumber, void* aData)
-{
- JNIEnv* env = static_cast<JNIEnv*>(aData);
- NativeToJavaProxyMap::Entry* entry =
- static_cast<NativeToJavaProxyMap::Entry*>(aHeader);
-
- // first, delete XPCOM instances from the Java proxies
- nsresult rv;
- NativeToJavaProxyMap::ProxyList* item = entry->list;
- while(item != nsnull) {
- void* xpcom_obj;
- jobject javaObject = env->CallObjectMethod(item->javaObject, getReferentMID);
- rv = GetXPCOMInstFromProxy(env, javaObject, &xpcom_obj);
- NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to get XPCOM instance from Java proxy");
-
- if (NS_SUCCEEDED(rv)) {
- JavaXPCOMInstance* inst = static_cast<JavaXPCOMInstance*>(xpcom_obj);
-#ifdef DEBUG_JAVAXPCOM
- char* iid_str = item->iid.ToString();
- LOG(("- NativeToJavaProxyMap (Java=%08x | XPCOM=%08x | IID=%s)\n",
- (PRUint32) env->CallStaticIntMethod(systemClass, hashCodeMID,
- javaObject),
- (PRUint32) entry, iid_str));
- NS_Free(iid_str);
-#endif
- delete inst; // releases native XPCOM object
- }
-
- NativeToJavaProxyMap::ProxyList* next = item->next;
- env->CallVoidMethod(item->javaObject, clearReferentMID);
- env->DeleteGlobalRef(item->javaObject);
- delete item;
- item = next;
- }
-
- return PL_DHASH_REMOVE;
-}
-
-nsresult
-NativeToJavaProxyMap::Destroy(JNIEnv* env)
-{
- // This is only called from FreeGlobals(), which already holds the lock.
- // nsAutoLock lock(gJavaXPCOMLock);
-
- PL_DHashTableEnumerate(mHashTable, DestroyJavaProxyMappingEnum, env);
- PL_DHashTableDestroy(mHashTable);
- mHashTable = nsnull;
-
- return NS_OK;
-}
-
-nsresult
-NativeToJavaProxyMap::Add(JNIEnv* env, nsISupports* aXPCOMObject,
- const nsIID& aIID, jobject aProxy)
-{
- nsAutoLock lock(gJavaXPCOMLock);
-
- Entry* e = static_cast<Entry*>(PL_DHashTableOperate(mHashTable,
- aXPCOMObject,
- PL_DHASH_ADD));
- if (!e)
- return NS_ERROR_FAILURE;
-
- jobject ref = nsnull;
- jobject weakRefObj = env->NewObject(weakReferenceClass,
- weakReferenceConstructorMID, aProxy);
- if (weakRefObj)
- ref = env->NewGlobalRef(weakRefObj);
- if (!ref)
- return NS_ERROR_OUT_OF_MEMORY;
-
- // Add Java proxy weak reference ref to start of list
- ProxyList* item = new ProxyList(ref, aIID, e->list);
- e->key = aXPCOMObject;
- e->list = item;
-
-#ifdef DEBUG_JAVAXPCOM
- char* iid_str = aIID.ToString();
- LOG(("+ NativeToJavaProxyMap (Java=%08x | XPCOM=%08x | IID=%s)\n",
- (PRUint32) env->CallStaticIntMethod(systemClass, hashCodeMID, aProxy),
- (PRUint32) aXPCOMObject, iid_str));
- NS_Free(iid_str);
-#endif
- return NS_OK;
-}
-
-nsresult
-NativeToJavaProxyMap::Find(JNIEnv* env, nsISupports* aNativeObject,
- const nsIID& aIID, jobject* aResult)
-{
- NS_PRECONDITION(aResult != nsnull, "null ptr");
- if (!aResult)
- return NS_ERROR_FAILURE;
-
- nsAutoLock lock(gJavaXPCOMLock);
-
- *aResult = nsnull;
- Entry* e = static_cast<Entry*>(PL_DHashTableOperate(mHashTable,
- aNativeObject,
- PL_DHASH_LOOKUP));
-
- if (PL_DHASH_ENTRY_IS_FREE(e))
- return NS_OK;
-
- ProxyList* item = e->list;
- while (item != nsnull && *aResult == nsnull) {
- if (item->iid.Equals(aIID)) {
- jobject referentObj = env->CallObjectMethod(item->javaObject,
- getReferentMID);
- if (!env->IsSameObject(referentObj, NULL)) {
- *aResult = referentObj;
-#ifdef DEBUG_JAVAXPCOM
- char* iid_str = aIID.ToString();
- LOG(("< NativeToJavaProxyMap (Java=%08x | XPCOM=%08x | IID=%s)\n",
- (PRUint32) env->CallStaticIntMethod(systemClass, hashCodeMID,
- *aResult),
- (PRUint32) aNativeObject, iid_str));
- NS_Free(iid_str);
-#endif
- }
- }
- item = item->next;
- }
-
- return NS_OK;
-}
-
-nsresult
-NativeToJavaProxyMap::Remove(JNIEnv* env, nsISupports* aNativeObject,
- const nsIID& aIID)
-{
- // This is only called from finalizeProxy(), which already holds the lock.
- // nsAutoLock lock(gJavaXPCOMLock);
-
- Entry* e = static_cast<Entry*>(PL_DHashTableOperate(mHashTable,
- aNativeObject,
- PL_DHASH_LOOKUP));
-
- if (PL_DHASH_ENTRY_IS_FREE(e)) {
- NS_WARNING("XPCOM object not found in hash table");
- return NS_ERROR_FAILURE;
- }
-
- ProxyList* item = e->list;
- ProxyList* last = e->list;
- while (item != nsnull) {
- if (item->iid.Equals(aIID)) {
-#ifdef DEBUG_JAVAXPCOM
- char* iid_str = aIID.ToString();
- LOG(("- NativeToJavaProxyMap (Java=%08x | XPCOM=%08x | IID=%s)\n",
- (PRUint32) env->CallStaticIntMethod(systemClass, hashCodeMID,
- item->javaObject),
- (PRUint32) aNativeObject, iid_str));
- NS_Free(iid_str);
-#endif
-
- env->CallVoidMethod(item->javaObject, clearReferentMID);
- env->DeleteGlobalRef(item->javaObject);
- if (item == e->list) {
- e->list = item->next;
- if (e->list == nsnull)
- PL_DHashTableOperate(mHashTable, aNativeObject, PL_DHASH_REMOVE);
- } else {
- last->next = item->next;
- }
-
- delete item;
- return NS_OK;
- }
-
- last = item;
- item = item->next;
- }
-
- NS_WARNING("Java proxy matching given IID not found");
- return NS_ERROR_FAILURE;
-}
-
-nsresult
-JavaToXPTCStubMap::Init()
-{
- mHashTable = PL_NewDHashTable(PL_DHashGetStubOps(), nsnull,
- sizeof(Entry), 16);
- if (!mHashTable)
- return NS_ERROR_OUT_OF_MEMORY;
- return NS_OK;
-}
-
-
-PLDHashOperator
-DestroyXPTCMappingEnum(PLDHashTable* aTable, PLDHashEntryHdr* aHeader,
- PRUint32 aNumber, void* aData)
-{
- JavaToXPTCStubMap::Entry* entry =
- static_cast<JavaToXPTCStubMap::Entry*>(aHeader);
-
- // The XPTC stub will be released by the XPCOM side, if it hasn't been
- // already. We just need to delete the Java global ref held by the XPTC stub,
- // so the Java garbage collector can handle the Java object when necessary.
- entry->xptcstub->DeleteStrongRef();
-
- return PL_DHASH_REMOVE;
-}
-
-nsresult
-JavaToXPTCStubMap::Destroy()
-{
- // This is only called from FreeGlobals(), which already holds the lock.
- // nsAutoLock lock(gJavaXPCOMLock);
-
- PL_DHashTableEnumerate(mHashTable, DestroyXPTCMappingEnum, nsnull);
- PL_DHashTableDestroy(mHashTable);
- mHashTable = nsnull;
-
- return NS_OK;
-}
-
-nsresult
-JavaToXPTCStubMap::Add(jint aJavaObjectHashCode, nsJavaXPTCStub* aProxy)
-{
- nsAutoLock lock(gJavaXPCOMLock);
-
- Entry* e = static_cast<Entry*>
- (PL_DHashTableOperate(mHashTable,
- NS_INT32_TO_PTR(aJavaObjectHashCode),
- PL_DHASH_ADD));
- if (!e)
- return NS_ERROR_FAILURE;
-
- NS_ASSERTION(e->key == nsnull,
- "XPTCStub for given Java object already exists in hash table");
- e->key = aJavaObjectHashCode;
- e->xptcstub = aProxy;
-
-#ifdef DEBUG_JAVAXPCOM
- nsIInterfaceInfo* iface_info;
- aProxy->GetInterfaceInfo(&iface_info);
- nsIID* iid;
- iface_info->GetInterfaceIID(&iid);
- char* iid_str = iid->ToString();
- LOG(("+ JavaToXPTCStubMap (Java=%08x | XPCOM=%08x | IID=%s)\n",
- (PRUint32) aJavaObjectHashCode, (PRUint32) aProxy, iid_str));
- NS_Free(iid_str);
- nsMemory::Free(iid);
- NS_RELEASE(iface_info);
-#endif
- return NS_OK;
-}
-
-nsresult
-JavaToXPTCStubMap::Find(jint aJavaObjectHashCode, const nsIID& aIID,
- nsJavaXPTCStub** aResult)
-{
- NS_PRECONDITION(aResult != nsnull, "null ptr");
- if (!aResult)
- return NS_ERROR_FAILURE;
-
- nsAutoLock lock(gJavaXPCOMLock);
-
- *aResult = nsnull;
- Entry* e = static_cast<Entry*>
- (PL_DHashTableOperate(mHashTable,
- NS_INT32_TO_PTR(aJavaObjectHashCode),
- PL_DHASH_LOOKUP));
-
- if (PL_DHASH_ENTRY_IS_FREE(e))
- return NS_OK;
-
- nsresult rv = e->xptcstub->QueryInterface(aIID, (void**) aResult);
-
-#ifdef DEBUG_JAVAXPCOM
- if (NS_SUCCEEDED(rv)) {
- char* iid_str = aIID.ToString();
- LOG(("< JavaToXPTCStubMap (Java=%08x | XPCOM=%08x | IID=%s)\n",
- (PRUint32) aJavaObjectHashCode, (PRUint32) *aResult, iid_str));
- PR_Free(iid_str);
- }
-#endif
-
- // NS_NOINTERFACE is not an error condition
- if (rv == NS_NOINTERFACE)
- rv = NS_OK;
- return rv;
-}
-
-nsresult
-JavaToXPTCStubMap::Remove(jint aJavaObjectHashCode)
-{
- PL_DHashTableOperate(mHashTable, NS_INT32_TO_PTR(aJavaObjectHashCode),
- PL_DHASH_REMOVE);
-
-#ifdef DEBUG_JAVAXPCOM
- LOG(("- JavaToXPTCStubMap (Java=%08x)\n", (PRUint32) aJavaObjectHashCode));
-#endif
-
- return NS_OK;
-}
-
-
-/**********************************************************
- * JavaXPCOMInstance
- *********************************************************/
-JavaXPCOMInstance::JavaXPCOMInstance(nsISupports* aInstance,
- nsIInterfaceInfo* aIInfo)
- : mInstance(aInstance)
- , mIInfo(aIInfo)
-{
- NS_ADDREF(mInstance);
- NS_ADDREF(mIInfo);
-}
-
-JavaXPCOMInstance::~JavaXPCOMInstance()
-{
- nsresult rv = NS_OK;
-
- // Need to release these objects on the main thread.
- nsCOMPtr<nsIThread> thread = do_GetMainThread();
- if (thread) {
- rv = NS_ProxyRelease(thread, mInstance);
- rv |= NS_ProxyRelease(thread, mIInfo);
- }
- NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to release using NS_ProxyRelease");
-}
-
-
-/*******************************
- * Helper functions
- *******************************/
-
-nsresult
-NativeInterfaceToJavaObject(JNIEnv* env, nsISupports* aXPCOMObject,
- const nsIID& aIID, jobject aObjectLoader,
- jobject* aResult)
-{
- NS_PRECONDITION(aResult != nsnull, "null ptr");
- if (!aResult)
- return NS_ERROR_NULL_POINTER;
-
- // If the object is an nsJavaXPTCStub, then get the Java object directly
- nsJavaXPTCStub* stub = nsnull;
- aXPCOMObject->QueryInterface(NS_GET_IID(nsJavaXPTCStub), (void**) &stub);
- if (stub) {
- *aResult = stub->GetJavaObject();
- NS_ASSERTION(*aResult != nsnull, "nsJavaXPTCStub w/o matching Java object");
- NS_RELEASE(stub);
- return NS_OK;
- }
-
- // ... else, get a Java wrapper for the native object
- return GetNewOrUsedJavaWrapper(env, aXPCOMObject, aIID, aObjectLoader,
- aResult);
-}
-
-nsresult
-JavaObjectToNativeInterface(JNIEnv* env, jobject aJavaObject, const nsIID& aIID,
- void** aResult)
-{
- NS_PRECONDITION(aResult != nsnull, "null ptr");
- if (!aResult)
- return NS_ERROR_NULL_POINTER;
-
- nsresult rv;
- *aResult = nsnull;
-
- // If the given Java object is one of our Java proxies, then query the
- // associated XPCOM object directly from the proxy.
- jboolean isProxy = env->CallStaticBooleanMethod(xpcomJavaProxyClass,
- isXPCOMJavaProxyMID,
- aJavaObject);
- if (env->ExceptionCheck())
- return NS_ERROR_FAILURE;
-
- if (isProxy) {
- void* inst;
- rv = GetXPCOMInstFromProxy(env, aJavaObject, &inst);
- NS_ENSURE_SUCCESS(rv, rv);
-
- nsISupports* rootObject =
- static_cast<JavaXPCOMInstance*>(inst)->GetInstance();
- rv = rootObject->QueryInterface(aIID, aResult);
- NS_ENSURE_SUCCESS(rv, rv);
-
- return NS_OK;
- }
-
- // ... else, we get an nsJavaXPTCStub
- return nsJavaXPTCStub::GetNewOrUsed(env, aJavaObject, aIID, aResult);
-}
-
-nsresult
-GetIIDForMethodParam(nsIInterfaceInfo *iinfo,
- const XPTMethodDescriptor *methodInfo,
- const nsXPTParamInfo ¶mInfo, PRUint8 paramType,
- PRUint16 methodIndex, nsXPTCMiniVariant *dispatchParams,
- PRBool isFullVariantArray, nsID &result)
-{
- nsresult rv;
-
- switch (paramType)
- {
- case nsXPTType::T_INTERFACE:
- rv = iinfo->GetIIDForParamNoAlloc(methodIndex, ¶mInfo, &result);
- break;
-
- case nsXPTType::T_INTERFACE_IS:
- {
- PRUint8 argnum;
- rv = iinfo->GetInterfaceIsArgNumberForParam(methodIndex, ¶mInfo,
- &argnum);
- if (NS_FAILED(rv))
- break;
-
- const nsXPTParamInfo& arg_param = methodInfo->params[argnum];
- const nsXPTType& arg_type = arg_param.GetType();
-
- // The xpidl compiler ensures this. We reaffirm it for safety.
- if (!arg_type.IsPointer() || arg_type.TagPart() != nsXPTType::T_IID) {
- rv = NS_ERROR_UNEXPECTED;
- break;
- }
-
- nsID *p = nsnull;
- if (isFullVariantArray) {
- p = (nsID *) ((nsXPTCVariant*) dispatchParams)[argnum].val.p;
- } else {
- p = (nsID *) dispatchParams[argnum].val.p;
- }
- if (!p)
- return NS_ERROR_UNEXPECTED;
-
- result = *p;
- break;
- }
-
- default:
- rv = NS_ERROR_UNEXPECTED;
- }
- return rv;
-}
-
-
-/*******************************
- * JNI helper functions
- *******************************/
-
-JNIEnv*
-GetJNIEnv()
-{
- JNIEnv* env;
- jint rc = gCachedJVM->GetEnv((void**) &env, JNI_VERSION_1_2);
- NS_ASSERTION(rc == JNI_OK && env != nsnull,
- "Current thread not attached to given JVM instance");
- return env;
-}
-
-void
-ThrowException(JNIEnv* env, const nsresult aErrorCode, const char* aMessage)
-{
- // Only throw this exception if one hasn't already been thrown, so we don't
- // mask a previous exception/error.
- if (env->ExceptionCheck())
- return;
-
- // If the error code we get is for an Out Of Memory error, try to throw an
- // OutOfMemoryError. The JVM may have enough memory to create this error.
- if (aErrorCode == NS_ERROR_OUT_OF_MEMORY) {
- jclass clazz = env->FindClass("java/lang/OutOfMemoryError");
- if (clazz) {
- env->ThrowNew(clazz, aMessage);
- }
- env->DeleteLocalRef(clazz);
- return;
- }
-
- // If the error was not handled above, then create an XPCOMException with the
- // given error code and message.
-
- // Create parameters and method signature. Max of 2 params. The error code
- // comes before the message string.
- PRInt64 errorCode = aErrorCode ? aErrorCode : NS_ERROR_FAILURE;
- nsCAutoString methodSig("(J");
- jstring message = nsnull;
- if (aMessage) {
- message = env->NewStringUTF(aMessage);
- if (!message) {
- return;
- }
- methodSig.AppendLiteral("Ljava/lang/String;");
- }
- methodSig.AppendLiteral(")V");
-
- // In some instances (such as in shutdownXPCOM() and termEmbedding()), we
- // will need to throw an exception when JavaXPCOM has already been
- // terminated. In such a case, 'xpcomExceptionClass' will be null. So we
- // reset it temporarily in order to throw the appropriate exception.
- if (xpcomExceptionClass == nsnull) {
- xpcomExceptionClass = env->FindClass("org/mozilla/xpcom/XPCOMException");
- if (!xpcomExceptionClass) {
- return;
- }
- }
-
- // create exception object
- jthrowable throwObj = nsnull;
- jmethodID mid = env->GetMethodID(xpcomExceptionClass, "<init>",
- methodSig.get());
- if (mid) {
- throwObj = (jthrowable) env->NewObject(xpcomExceptionClass, mid, errorCode,
- message);
- }
- NS_ASSERTION(throwObj, "Failed to create XPCOMException object");
-
- // throw exception
- if (throwObj) {
- env->Throw(throwObj);
- }
-}
-
-nsAString*
-jstring_to_nsAString(JNIEnv* env, jstring aString)
-{
- const PRUnichar* buf = nsnull;
- if (aString) {
- buf = env->GetStringChars(aString, nsnull);
- if (!buf)
- return nsnull; // exception already thrown
- }
-
- nsString* str = new nsString(buf);
-
- if (aString) {
- env->ReleaseStringChars(aString, buf);
- } else {
- str->SetIsVoid(PR_TRUE);
- }
-
- // returns string, or nsnull if 'new' failed
- return str;
-}
-
-nsACString*
-jstring_to_nsACString(JNIEnv* env, jstring aString)
-{
- const char* buf = nsnull;
- if (aString) {
- buf = env->GetStringUTFChars(aString, nsnull);
- if (!buf)
- return nsnull; // exception already thrown
- }
-
- nsCString* str = new nsCString(buf);
-
- if (aString) {
- env->ReleaseStringUTFChars(aString, buf);
- } else {
- str->SetIsVoid(PR_TRUE);
- }
-
- // returns string, or nsnull if 'new' failed
- return str;
-}
-
-nsresult
-File_to_nsILocalFile(JNIEnv* env, jobject aFile, nsILocalFile** aLocalFile)
-{
- nsresult rv = NS_ERROR_FAILURE;
- jstring pathName = nsnull;
- jclass clazz = env->FindClass("java/io/File");
- if (clazz) {
- jmethodID pathMID = env->GetMethodID(clazz, "getCanonicalPath",
- "()Ljava/lang/String;");
- if (pathMID) {
- pathName = (jstring) env->CallObjectMethod(aFile, pathMID);
- if (pathName != nsnull && !env->ExceptionCheck())
- rv = NS_OK;
- }
- }
-
- if (NS_SUCCEEDED(rv)) {
- nsAString* path = jstring_to_nsAString(env, pathName);
- if (!path)
- rv = NS_ERROR_OUT_OF_MEMORY;
-
- if (NS_SUCCEEDED(rv)) {
- rv = NS_NewLocalFile(*path, false, aLocalFile);
- delete path;
- }
- }
-
- return rv;
-}
-
deleted file mode 100644
--- a/extensions/java/xpcom/src/nsJavaXPCOMBindingUtils.h
+++ /dev/null
@@ -1,391 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is
- * IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2005
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 _nsJavaXPCOMBindingUtils_h_
-#define _nsJavaXPCOMBindingUtils_h_
-
-#include "jni.h"
-#include "xptcall.h"
-#include "nsCOMPtr.h"
-#include "nsString.h"
-#include "pldhash.h"
-#include "nsJavaXPTCStub.h"
-#include "nsAutoLock.h"
-#include "nsTHashtable.h"
-#include "nsHashKeys.h"
-
-//#define DEBUG_JAVAXPCOM
-//#define DEBUG_JAVAXPCOM_REFCNT
-
-#ifdef DEBUG_JAVAXPCOM
-#define LOG(x) printf x
-#else
-#define LOG(x) /* nothing */
-#endif
-
-
-/*********************
- * Java JNI globals
- *********************/
-
-extern jclass systemClass;
-extern jclass booleanClass;
-extern jclass charClass;
-extern jclass byteClass;
-extern jclass shortClass;
-extern jclass intClass;
-extern jclass longClass;
-extern jclass floatClass;
-extern jclass doubleClass;
-extern jclass stringClass;
-extern jclass nsISupportsClass;
-extern jclass xpcomExceptionClass;
-extern jclass xpcomJavaProxyClass;
-extern jclass weakReferenceClass;
-extern jclass javaXPCOMUtilsClass;
-
-extern jmethodID hashCodeMID;
-extern jmethodID booleanValueMID;
-extern jmethodID booleanInitMID;
-extern jmethodID charValueMID;
-extern jmethodID charInitMID;
-extern jmethodID byteValueMID;
-extern jmethodID byteInitMID;
-extern jmethodID shortValueMID;
-extern jmethodID shortInitMID;
-extern jmethodID intValueMID;
-extern jmethodID intInitMID;
-extern jmethodID longValueMID;
-extern jmethodID longInitMID;
-extern jmethodID floatValueMID;
-extern jmethodID floatInitMID;
-extern jmethodID doubleValueMID;
-extern jmethodID doubleInitMID;
-extern jmethodID createProxyMID;
-extern jmethodID isXPCOMJavaProxyMID;
-extern jmethodID getNativeXPCOMInstMID;
-extern jmethodID weakReferenceConstructorMID;
-extern jmethodID getReferentMID;
-extern jmethodID clearReferentMID;
-extern jmethodID findClassInLoaderMID;
-
-#ifdef DEBUG_JAVAXPCOM
-extern jmethodID getNameMID;
-extern jmethodID proxyToStringMID;
-#endif
-
-class NativeToJavaProxyMap;
-extern NativeToJavaProxyMap* gNativeToJavaProxyMap;
-class JavaToXPTCStubMap;
-extern JavaToXPTCStubMap* gJavaToXPTCStubMap;
-
-extern nsTHashtable<nsDepCharHashKey>* gJavaKeywords;
-
-// The Java garbage collector runs in a separate thread. Since it calls the
-// finalizeProxy() function in nsJavaWrapper.cpp, we need to make sure that
-// all the structures touched by finalizeProxy() are multithread aware.
-extern PRLock* gJavaXPCOMLock;
-
-extern PRBool gJavaXPCOMInitialized;
-
-/**
- * Initialize global structures used by JavaXPCOM.
- * @param env Java environment pointer
- * @return PR_TRUE if JavaXPCOM is initialized; PR_FALSE if an error occurred
- */
-PRBool InitializeJavaGlobals(JNIEnv *env);
-
-/**
- * Frees global structures that were allocated by InitializeJavaGlobals().
- * @param env Java environment pointer
- */
-void FreeJavaGlobals(JNIEnv* env);
-
-
-/*************************
- * JavaXPCOMInstance
- *************************/
-
-class JavaXPCOMInstance
-{
-public:
- JavaXPCOMInstance(nsISupports* aInstance, nsIInterfaceInfo* aIInfo);
- ~JavaXPCOMInstance();
-
- nsISupports* GetInstance() { return mInstance; }
- nsIInterfaceInfo* InterfaceInfo() { return mIInfo; }
-
-private:
- nsISupports* mInstance;
- nsIInterfaceInfo* mIInfo;
-};
-
-
-/**************************************
- * Java<->XPCOM object mappings
- **************************************/
-
-/**
- * Maps native XPCOM objects to their associated Java proxy object.
- */
-class NativeToJavaProxyMap
-{
- friend PLDHashOperator DestroyJavaProxyMappingEnum(PLDHashTable* aTable,
- PLDHashEntryHdr* aHeader,
- PRUint32 aNumber,
- void* aData);
-
-protected:
- struct ProxyList
- {
- ProxyList(const jobject aRef, const nsIID& aIID, ProxyList* aList)
- : javaObject(aRef)
- , iid(aIID)
- , next(aList)
- { }
-
- const jobject javaObject;
- const nsIID iid;
- ProxyList* next;
- };
-
- struct Entry : public PLDHashEntryHdr
- {
- nsISupports* key;
- ProxyList* list;
- };
-
-public:
- NativeToJavaProxyMap()
- : mHashTable(nsnull)
- { }
-
- ~NativeToJavaProxyMap()
- {
- NS_ASSERTION(mHashTable == nsnull,
- "MUST call Destroy() before deleting object");
- }
-
- nsresult Init();
-
- nsresult Destroy(JNIEnv* env);
-
- nsresult Add(JNIEnv* env, nsISupports* aXPCOMObject, const nsIID& aIID,
- jobject aProxy);
-
- nsresult Find(JNIEnv* env, nsISupports* aNativeObject, const nsIID& aIID,
- jobject* aResult);
-
- nsresult Remove(JNIEnv* env, nsISupports* aNativeObject, const nsIID& aIID);
-
-protected:
- PLDHashTable* mHashTable;
-};
-
-/**
- * Maps Java objects to their associated nsJavaXPTCStub.
- */
-class JavaToXPTCStubMap
-{
- friend PLDHashOperator DestroyXPTCMappingEnum(PLDHashTable* aTable,
- PLDHashEntryHdr* aHeader,
- PRUint32 aNumber, void* aData);
-
-protected:
- struct Entry : public PLDHashEntryHdr
- {
- jint key;
- nsJavaXPTCStub* xptcstub;
- };
-
-public:
- JavaToXPTCStubMap()
- : mHashTable(nsnull)
- { }
-
- ~JavaToXPTCStubMap()
- {
- NS_ASSERTION(mHashTable == nsnull,
- "MUST call Destroy() before deleting object");
- }
-
- nsresult Init();
-
- nsresult Destroy();
-
- nsresult Add(jint aJavaObjectHashCode, nsJavaXPTCStub* aProxy);
-
- nsresult Find(jint aJavaObjectHashCode, const nsIID& aIID,
- nsJavaXPTCStub** aResult);
-
- nsresult Remove(jint aJavaObjectHashCode);
-
-protected:
- PLDHashTable* mHashTable;
-};
-
-
-/*******************************
- * Helper functions
- *******************************/
-
-/**
- * Convert a native nsISupports to a Java object.
- *
- * @param env Java environment pointer
- * @param aXPCOMObject XPCOM object for which to find/create Java object
- * @param aIID desired interface IID for Java object
- * @param aObjectLoader Java object whose class loader we use for finding
- * classes; can be null
- * @param aResult on success, holds reference to Java object
- *
- * @return NS_OK if succeeded; all other return values are error codes.
- */
-nsresult NativeInterfaceToJavaObject(JNIEnv* env, nsISupports* aXPCOMObject,
- const nsIID& aIID, jobject aObjectLoader,
- jobject* aResult);
-
-/**
- * Convert a Java object to a native nsISupports object.
- *
- * @param env Java environment pointer
- * @param aJavaObject Java object for which to find/create XPCOM object
- * @param aIID desired interface IID for XPCOM object
- * @param aResult on success, holds AddRef'd reference to XPCOM object
- *
- * @return NS_OK if succeeded; all other return values are error codes.
- */
-nsresult JavaObjectToNativeInterface(JNIEnv* env, jobject aJavaObject,
- const nsIID& aIID, void** aResult);
-
-nsresult GetIIDForMethodParam(nsIInterfaceInfo *iinfo,
- const XPTMethodDescriptor *methodInfo,
- const nsXPTParamInfo ¶mInfo,
- PRUint8 paramType, PRUint16 methodIndex,
- nsXPTCMiniVariant *dispatchParams,
- PRBool isFullVariantArray,
- nsID &result);
-
-/**
- * Returns the Class object associated with the class or interface with the
- * given string name, using the class loader of the given object.
- *
- * @param env Java environment pointer
- * @param aObjectLoader Java object whose class loader is used to load class
- * @param aClassName fully qualified name of class to load
- *
- * @return java.lang.Class object of requested Class; NULL if the class
- * wasn't found
- *
- * @see http://java.sun.com/j2se/1.3/docs/guide/jni/jni-12.html#classops
- */
-inline jclass
-FindClassInLoader(JNIEnv* env, jobject aObjectLoader, const char* aClassName)
-{
- jclass clazz = nsnull;
- jstring name = env->NewStringUTF(aClassName);
- if (name)
- clazz = (jclass) env->CallStaticObjectMethod(javaXPCOMUtilsClass,
- findClassInLoaderMID, aObjectLoader, name);
-
-#ifdef DEBUG
- if (!clazz)
- fprintf(stderr, "WARNING: failed to find class [%s]\n", aClassName);
-#endif
- return clazz;
-}
-
-
-/*******************************
- * JNI helper functions
- *******************************/
-
-/**
- * Returns a pointer to the appropriate JNIEnv structure. This function is
- * useful in callbacks or other functions that are not called directly from
- * Java and therefore do not have the JNIEnv structure passed in.
- *
- * @return pointer to JNIEnv structure for current thread
- */
-JNIEnv* GetJNIEnv();
-
-/**
- * Constructs and throws an exception. Some error codes (such as
- * NS_ERROR_OUT_OF_MEMORY) are handled by the appropriate Java exception/error.
- * Otherwise, an instance of XPCOMException is created with the given error
- * code and message.
- *
- * @param env Java environment pointer
- * @param aErrorCode The error code returned by an XPCOM/Gecko function. Pass
- * zero for the default behaviour.
- * @param aMessage A string that provides details for throwing this
- * exception. Pass in <code>nsnull</code> for the default
- * behaviour.
- *
- * @throws OutOfMemoryError if aErrorCode == NS_ERROR_OUT_OF_MEMORY
- * XPCOMException for all other error codes
- */
-void ThrowException(JNIEnv* env, const nsresult aErrorCode,
- const char* aMessage);
-
-/**
- * Helper functions for converting from java.lang.String to
- * nsAString/nsACstring. Caller must delete nsAString/nsACString.
- *
- * @param env Java environment pointer
- * @param aString Java string to convert
- *
- * @return nsAString/nsACString with same content as given Java string;
- * a 'void' nsAString/nsACString object if aString is
- * <code>null</code>; or <code>nsnull</code> if out of memory
- */
-nsAString* jstring_to_nsAString(JNIEnv* env, jstring aString);
-nsACString* jstring_to_nsACString(JNIEnv* env, jstring aString);
-
-/**
- * Helper function for converting from java.io.File to nsILocalFile.
- *
- * @param env Java environment pointer
- * @param aFile Java File to convert
- * @param aLocalFile returns the converted nsILocalFile
- *
- * @return NS_OK for success; other values indicate error in conversion
- */
-nsresult File_to_nsILocalFile(JNIEnv* env, jobject aFile,
- nsILocalFile** aLocalFile);
-
-#endif // _nsJavaXPCOMBindingUtils_h_
deleted file mode 100644
--- a/extensions/java/xpcom/src/nsJavaXPTCStub.cpp
+++ /dev/null
@@ -1,1711 +0,0 @@
-/* ***** 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 Java XPCOM Bindings.
- *
- * The Initial Developer of the Original Code is
- * IBM Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2005
- * IBM Corporation. All Rights Reserved.
- *
- * Contributor(s):
- * Javier Pedemonte (jhpedemonte@gmail.com)
- *
- * 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 "nsJavaXPTCStub.h"
-#include "nsJavaWrapper.h"
-#include "nsJavaXPCOMBindingUtils.h"
-#include "prmem.h"
-#include "nsIInterfaceInfoManager.h"
-#include "nsString.h"
-#include "nsString.h"
-#include "nsCRT.h"
-#include "nsServiceManagerUtils.h"
-
-
-nsJavaXPTCStub::nsJavaXPTCStub(jobject aJavaObject, nsIInterfaceInfo *aIInfo,
- nsresult *rv)
- : mJavaStrongRef(nsnull)
- , mIInfo(aIInfo)
- , mMaster(nsnull)
- , mWeakRefCnt(0)
-{
- const nsIID *iid = nsnull;
- aIInfo->GetIIDShared(&iid);
- NS_ASSERTION(iid, "GetIIDShared must not fail!");
-
- *rv = InitStub(*iid);
- if (NS_FAILED(*rv))
- return;
-
- JNIEnv* env = GetJNIEnv();
- jobject weakref = env->NewObject(weakReferenceClass,
- weakReferenceConstructorMID, aJavaObject);
- mJavaWeakRef = env->NewGlobalRef(weakref);
- mJavaRefHashCode = env->CallStaticIntMethod(systemClass, hashCodeMID,
- aJavaObject);
-
-#ifdef DEBUG_JAVAXPCOM
- char* iid_str = iid->ToString();
- LOG(("+ nsJavaXPTCStub (Java=%08x | XPCOM=%08x | IID=%s)\n",
- (PRUint32) mJavaRefHashCode, (PRUint32) this, iid_str));
- NS_Free(iid_str);
-#endif
-}
-
-nsJavaXPTCStub::~nsJavaXPTCStub()
-{
-}
-
-NS_IMETHODIMP_(nsrefcnt)
-nsJavaXPTCStub::AddRefInternal()
-{
- // If this is the first AddRef call, we create a strong global ref to the
- // Java object to keep it from being garbage collected.
- if (mRefCnt == 0) {
- JNIEnv* env = GetJNIEnv();
- jobject referent = env->CallObjectMethod(mJavaWeakRef, getReferentMID);
- if (!env->IsSameObject(referent, NULL)) {
- mJavaStrongRef = env->NewGlobalRef(referent);
- }
- NS_ASSERTION(mJavaStrongRef != nsnull, "Failed to acquire strong ref");
- }
-
- // if this is the master interface
- NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");
- NS_ASSERT_OWNINGTHREAD(nsJavaXPTCStub);
- ++mRefCnt;
- NS_LOG_ADDREF(this, mRefCnt, "nsJavaXPTCStub", sizeof(*this));
- return mRefCnt;
-}
-
-NS_IMETHODIMP_(nsrefcnt)
-nsJavaXPTCStub::AddRef()
-{
-#ifdef DEBUG_JAVAXPCOM_REFCNT
- nsIID* iid;
- mIInfo->GetInterfaceIID(&iid);
- char* iid_str = iid->ToString();
- int refcnt = PRInt32(mMaster ? mMaster->mRefCnt : mRefCnt) + 1;
- LOG(("= nsJavaXPTCStub::AddRef (XPCOM=%08x | refcnt = %d | IID=%s)\n",
- (int) this, refcnt, iid_str));
- NS_Free(iid_str);
- nsMemory::Free(iid);
-#endif
-
- nsJavaXPTCStub* master = mMaster ? mMaster : this;
- return master->AddRefInternal();
-}
-
-NS_IMETHODIMP_(nsrefcnt)
-nsJavaXPTCStub::ReleaseInternal()
-{
- NS_PRECONDITION(0 != mRefCnt, "dup release");
- NS_ASSERT_OWNINGTHREAD(nsJavaXPTCStub);
- --mRefCnt;
- NS_LOG_RELEASE(this, mRefCnt, "nsJavaXPTCStub");
- if (mRefCnt == 0) {
- // delete strong ref; allows Java object to be garbage collected
- DeleteStrongRef();
-
- // If we have a weak ref, we don't delete this object.
- if (mWeakRefCnt == 0) {
- mRefCnt = 1; /* stabilize */
- Destroy();
- delete this;
- }
- return 0;
- }
- return mRefCnt;
-}
-
-NS_IMETHODIMP_(nsrefcnt)
-nsJavaXPTCStub::Release()
-{
-#ifdef DEBUG_JAVAXPCOM_REFCNT
- nsIID* iid;
- mIInfo->GetInterfaceIID(&iid);
- char* iid_str = iid->ToString();
- int refcnt = PRInt32(mMaster ? mMaster->mRefCnt : mRefCnt) - 1;
- LOG(("= nsJavaXPTCStub::Release (XPCOM=%08x | refcnt = %d | IID=%s)\n",
- (int) this, refcnt, iid_str));
- NS_Free(iid_str);
- nsMemory::Free(iid);
-#endif
-
- nsJavaXPTCStub* master = mMaster ? mMaster : this;
- return master->ReleaseInternal();
-}
-
-void
-nsJavaXPTCStub::Destroy()
-{
- JNIEnv* env = GetJNIEnv();
-
-#ifdef DEBUG_JAVAXPCOM
- nsIID* iid;
- mIInfo->GetInterfaceIID(&iid);
- char* iid_str = iid->ToString();
- LOG(("- nsJavaXPTCStub (Java=%08x | XPCOM=%08x | IID=%s)\n",
- (PRUint32) mJavaRefHashCode, (PRUint32) this, iid_str));
- NS_Free(iid_str);
- nsMemory::Free(iid);
-#endif
-
- if (!mMaster) {
- // delete each child stub
- for (PRInt32 i = 0; i < mChildren.Count(); i++) {
- delete (nsJavaXPTCStub*) mChildren[i];
- }
-
- // Since we are destroying this stub, also remove the mapping.
- // It is possible for mJavaStrongRef to be NULL here. That is why we
- // store the hash code value earlier.
- if (gJavaXPCOMInitialized) {
- gJavaToXPTCStubMap->Remove(mJavaRefHashCode);
- }
- }
-
- env->CallVoidMethod(mJavaWeakRef, clearReferentMID);
- env->DeleteGlobalRef(mJavaWeakRef);
-}
-
-void
-nsJavaXPTCStub::ReleaseWeakRef()
-{
- // if this is a child
- if (mMaster)
- mMaster->ReleaseWeakRef();
-
- --mWeakRefCnt;
-
- // If there are no more associated weak refs, and no one else holds a strong
- // ref to this object, then delete it.
- if (mWeakRefCnt == 0 && mRefCnt == 0) {
- NS_ASSERT_OWNINGTHREAD(nsJavaXPTCStub);
- mRefCnt = 1; /* stabilize */
- Destroy();
- delete this;
- }
-}
-
-void
-nsJavaXPTCStub::DeleteStrongRef()
-{
- if (mJavaStrongRef == nsnull)
- return;
-
- GetJNIEnv()->DeleteGlobalRef(mJavaStrongRef);
- mJavaStrongRef = nsnull;
-}
-
-NS_IMETHODIMP
-nsJavaXPTCStub::QueryInterface(const nsID &aIID, void **aInstancePtr)
-{
- nsresult rv;
-
- LOG(("JavaStub::QueryInterface()\n"));
- *aInstancePtr = nsnull;
- nsJavaXPTCStub *master = mMaster ? mMaster : this;
-
- // This helps us differentiate between the help classes.
- if (aIID.Equals(NS_GET_IID(nsJavaXPTCStub)))
- {
- *aInstancePtr = master;
- NS_ADDREF(this);
- return NS_OK;
- }
-
- // always return the master stub for nsISupports
- if (aIID.Equals(NS_GET_IID(nsISupports)))
- {
- *aInstancePtr = master->mXPTCStub;
- NS_ADDREF(master);
- return NS_OK;
- }
-
- // All Java objects support weak references
- if (aIID.Equals(NS_GET_IID(nsISupportsWeakReference)))
- {
- *aInstancePtr = static_cast<nsISupportsWeakReference*>(master);
- NS_ADDREF(master);
- return NS_OK;
- }
-
- // does any existing stub support the requested IID?
- nsJavaXPTCStub *stub = master->FindStubSupportingIID(aIID);
- if (stub)
- {
- *aInstancePtr = stub->mXPTCStub;
- NS_ADDREF(stub);
- return NS_OK;
- }
-
- JNIEnv* env = GetJNIEnv();
-
- // Query Java object
- LOG(("\tCalling Java object queryInterface\n"));
- jobject javaObject = env->CallObjectMethod(mJavaWeakRef, getReferentMID);
-
- jmethodID qiMID = 0;
- jclass clazz = env->GetObjectClass(javaObject);
- if (clazz) {
- char* sig = "(Ljava/lang/String;)Lorg/mozilla/interfaces/nsISupports;";
- qiMID = env->GetMethodID(clazz, "queryInterface", sig);
- NS_ASSERTION(qiMID, "Failed to get queryInterface method ID");
- }
-
- if (qiMID == 0) {
- env->ExceptionClear();
- return NS_NOINTERFACE;
- }
-
- // construct IID string
- jstring iid_jstr = nsnull;
- char* iid_str = aIID.ToString();
- if (iid_str) {
- iid_jstr = env->NewStringUTF(iid_str);
- }
- if (!iid_str || !iid_jstr) {
- env->ExceptionClear();
- return NS_ERROR_OUT_OF_MEMORY;
- }
- NS_Free(iid_str);
-
- // call queryInterface method
- jobject obj = env->CallObjectMethod(javaObject, qiMID, iid_jstr);
- if (env->ExceptionCheck()) {
- env->ExceptionClear();
- return NS_ERROR_FAILURE;
- }
- if (!obj)
- return NS_NOINTERFACE;
-
- // Get interface info for new java object
- nsCOMPtr<nsIInterfaceInfoManager>
- iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID, &rv));
- NS_ENSURE_SUCCESS(rv, rv);
-
- nsCOMPtr<nsIInterfaceInfo> iinfo;
- rv = iim->GetInfoForIID(&aIID, getter_AddRefs(iinfo));
- if (NS_FAILED(rv))
- return rv;
-
- stub = new nsJavaXPTCStub(obj, iinfo, &rv);
- if (!stub)
- return NS_ERROR_OUT_OF_MEMORY;
-
- if (NS_FAILED(rv)) {
- delete stub;
- return rv;
- }
-
- // add stub to the master's list of children, so we can preserve
- // symmetry in future QI calls. the master will delete each child
- // when it is destroyed. the refcount of each child is bound to
- // the refcount of the master. this is done to deal with code
- // like this:
- //
- // nsCOMPtr<nsIBar> bar = ...;
- // nsIFoo *foo;
- // {
- // nsCOMPtr<nsIFoo> temp = do_QueryInterface(bar);
- // foo = temp;
- // }
- // foo->DoStuff();
- //
- // while this code is not valid XPCOM (since it is using |foo|
- // after having called Release on it), such code is unfortunately
- // very common in the mozilla codebase. the assumption this code
- // is making is that so long as |bar| is alive, it should be valid
- // to access |foo| even if the code doesn't own a strong reference
- // to |foo|! clearly wrong, but we need to support it anyways.
-
- stub->mMaster = master;
- master->mChildren.AppendElement(stub);
-
- *aInstancePtr = stub->mXPTCStub;
- NS_ADDREF(stub);
- return NS_OK;
-}
-
-PRBool
-nsJavaXPTCStub::SupportsIID(const nsID &iid)
-{
- PRBool match;
- nsCOMPtr<nsIInterfaceInfo> iter = mIInfo;
- do
- {
- if (NS_SUCCEEDED(iter->IsIID(&iid, &match)) && match)
- return PR_TRUE;
-
- nsCOMPtr<nsIInterfaceInfo> parent;
- iter->GetParent(getter_AddRefs(parent));
- iter = parent;
- }
- while (iter != nsnull);
-
- return PR_FALSE;
-}
-
-nsJavaXPTCStub *
-nsJavaXPTCStub::FindStubSupportingIID(const nsID &iid)
-{
- NS_ASSERTION(mMaster == nsnull, "this is not a master stub");
-
- if (SupportsIID(iid))
- return this;
-
- for (PRInt32 i = 0; i < mChildren.Count(); i++)
- {
- nsJavaXPTCStub *child = (nsJavaXPTCStub *) mChildren[i];
- if (child->SupportsIID(iid))
- return child;
- }
- return nsnull;
-}
-
-NS_IMETHODIMP
-nsJavaXPTCStub::CallMethod(PRUint16 aMethodIndex,
- const XPTMethodDescriptor *aMethodInfo,
- nsXPTCMiniVariant *aParams)
-{
-#ifdef DEBUG_JAVAXPCOM
- const char* ifaceName;
- mIInfo->GetNameShared(&ifaceName);
- LOG(("---> (Java) %s::%s()\n", ifaceName, aMethodInfo->name));
-#endif
-
- nsresult rv = NS_OK;
- JNIEnv* env = GetJNIEnv();
- jobject javaObject = env->CallObjectMethod(mJavaWeakRef, getReferentMID);
-
- nsCAutoString methodSig("(");
-
- // Create jvalue array to hold Java params
- PRUint8 paramCount = aMethodInfo->num_args;
- jvalue* java_params = nsnull;
- const nsXPTParamInfo* retvalInfo = nsnull;
- if (paramCount) {
- java_params = new jvalue[paramCount];
- if (!java_params)
- return NS_ERROR_OUT_OF_MEMORY;
-
- for (PRUint8 i = 0; i < paramCount && NS_SUCCEEDED(rv); i++)
- {
- const nsXPTParamInfo ¶mInfo = aMethodInfo->params[i];
- if (!paramInfo.IsRetval()) {
- rv = SetupJavaParams(paramInfo, aMethodInfo, aMethodIndex, aParams,
- aParams[i], java_params[i], methodSig);
- } else {
- retvalInfo = ¶mInfo;
- }
- }
- NS_ASSERTION(NS_SUCCEEDED(rv), "SetupJavaParams failed");
- }
-
- // Finish method signature
- if (NS_SUCCEEDED(rv)) {
- methodSig.Append(')');
- if (retvalInfo) {
- nsCAutoString retvalSig;
- rv = GetRetvalSig(retvalInfo, aMethodInfo, aMethodIndex, aParams,
- retvalSig);
- methodSig.Append(retvalSig);
- } else {
- methodSig.Append('V');
- }
- NS_ASSERTION(NS_SUCCEEDED(rv), "GetRetvalSig failed");
- }
-
- // Get Java method to call
- jmethodID mid = nsnull;
- if (NS_SUCCEEDED(rv)) {
- nsCAutoString methodName;
- if (XPT_MD_IS_GETTER(aMethodInfo->flags) ||
- XPT_MD_IS_SETTER(aMethodInfo->flags)) {
- if (XPT_MD_IS_GETTER(aMethodInfo->flags))
- methodName.AppendLiteral("get");
- else
- methodName.AppendLiteral("set");
- methodName.AppendASCII(aMethodInfo->name);
- methodName.SetCharAt(toupper(methodName[3]), 3);
- } else {
- methodName.AppendASCII(aMethodInfo->name);
- methodName.SetCharAt(tolower(methodName[0]), 0);
- }
- // If it's a Java keyword, then prepend an underscore
- if (gJavaKeywords->GetEntry(methodName.get())) {
- methodName.Insert('_', 0);
- }
-
- jclass clazz = env->GetObjectClass(javaObject);
- if (clazz)
- mid = env->GetMethodID(clazz, methodName.get(), methodSig.get());
- NS_ASSERTION(mid, "Failed to get requested method for Java object");
- if (!mid)
- rv = NS_ERROR_FAILURE;
- }
-
- // Call method
- jvalue retval;
- if (NS_SUCCEEDED(rv)) {
- if (!retvalInfo) {
- env->CallVoidMethodA(javaObject, mid, java_params);
- } else {
- switch (retvalInfo->GetType().TagPart())
- {
- case nsXPTType::T_I8:
- retval.b = env->CallByteMethodA(javaObject, mid, java_params);
- break;
-
- case nsXPTType::T_I16:
- case nsXPTType::T_U8:
- retval.s = env->CallShortMethodA(javaObject, mid, java_params);
- break;
-
- case nsXPTType::T_I32:
- case nsXPTType::T_U16:
- retval.i = env->CallIntMethodA(javaObject, mid, java_params);
- break;
-
- case nsXPTType::T_I64:
- case nsXPTType::T_U32:
- retval.j = env->CallLongMethodA(javaObject, mid, java_params);
- break;
-
- case nsXPTType::T_FLOAT:
- retval.f = env->CallFloatMethodA(javaObject, mid, java_params);
- break;
-
- case nsXPTType::T_U64:
- case nsXPTType::T_DOUBLE:
- retval.d = env->CallDoubleMethodA(javaObject, mid, java_params);
- break;
-
- case nsXPTType::T_BOOL:
- retval.z = env->CallBooleanMethodA(javaObject, mid, java_params);
- break;
-
- case nsXPTType::T_CHAR:
- case nsXPTType::T_WCHAR:
- retval.c = env->CallCharMethodA(javaObject, mid, java_params);
- break;
-
- case nsXPTType::T_CHAR_STR:
- case nsXPTType::T_WCHAR_STR:
- case nsXPTType::T_IID:
- case nsXPTType::T_ASTRING:
- case nsXPTType::T_DOMSTRING:
- case nsXPTType::T_UTF8STRING:
- case nsXPTType::T_CSTRING:
- case nsXPTType::T_INTERFACE:
- case nsXPTType::T_INTERFACE_IS:
- retval.l = env->CallObjectMethodA(javaObject, mid, java_params);
- break;
-
- case nsXPTType::T_VOID:
- retval.j = env->CallLongMethodA(javaObject, mid, java_params);
- break;
-
- default:
- NS_WARNING("Unhandled retval type");
- break;
- }
- }
-
- // Check for exception from called Java function
- jthrowable exp = env->ExceptionOccurred();
- if (exp) {
- // If the exception is an instance of XPCOMException, then get the
- // nsresult from the exception instance. Else, default to
- // NS_ERROR_FAILURE.
- if (env->IsInstanceOf(exp, xpcomExceptionClass)) {
- jfieldID fid;
- fid = env->GetFieldID(xpcomExceptionClass, "errorcode", "J");
- if (fid) {
- rv = env->GetLongField(exp, fid);
- } else {
- rv = NS_ERROR_FAILURE;
- }
- NS_ASSERTION(fid, "Couldn't get 'errorcode' field of XPCOMException");
- } else {
- rv = NS_ERROR_FAILURE;
- }
- }
- }
-
- // Handle any 'inout', 'out' and 'retval' params
- if (NS_SUCCEEDED(rv)) {
- for (PRUint8 i = 0; i < paramCount; i++)
- {
- const nsXPTParamInfo ¶mInfo = aMethodInfo->params[i];
- if (paramInfo.IsIn() && !paramInfo.IsOut() && !paramInfo.IsDipper()) // 'in'
- continue;
-
- // If param is null, then caller is not expecting an output value.
- if (aParams[i].val.p == nsnull)
- continue;
-
- if (!paramInfo.IsRetval()) {
- rv = FinalizeJavaParams(paramInfo, aMethodInfo, aMethodIndex, aParams,
- aParams[i], java_params[i]);
- } else {
- rv = FinalizeJavaParams(paramInfo, aMethodInfo, aMethodIndex, aParams,
- aParams[i], retval);
- }
- }
- NS_ASSERTION(NS_SUCCEEDED(rv), "FinalizeJavaParams/SetXPCOMRetval failed");
- }
-
- if (java_params)
- delete [] java_params;
-
-#ifdef DEBUG
- if (env->ExceptionCheck())
- env->ExceptionDescribe();
-#endif
- env->ExceptionClear();
-
- LOG(("<--- (Java) %s::%s()\n", ifaceName, aMethodInfo->name));
- return rv;
-}
-
-/**
- * Handle 'in', 'inout', and 'out' params
- */
-nsresult
-nsJavaXPTCStub::SetupJavaParams(const nsXPTParamInfo &aParamInfo,
- const XPTMethodDescriptor* aMethodInfo,
- PRUint16 aMethodIndex,
- nsXPTCMiniVariant* aDispatchParams,
- nsXPTCMiniVariant &aVariant, jvalue &aJValue,
- nsACString &aMethodSig)
-{
- nsresult rv = NS_OK;
- JNIEnv* env = GetJNIEnv();
- const nsXPTType &type = aParamInfo.GetType();
-
- PRUint8 tag = type.TagPart();
- switch (tag)
- {
- case nsXPTType::T_I8:
- {
- if (!aParamInfo.IsOut()) { // 'in'
- aJValue.b = aVariant.val.i8;
- aMethodSig.Append('B');
- } else { // 'inout' & 'out'
- if (aVariant.val.p) {
- jbyteArray array = env->NewByteArray(1);
- if (!array) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
-
- env->SetByteArrayRegion(array, 0, 1, (jbyte*) aVariant.val.p);
- aJValue.l = array;
- } else {
- aJValue.l = nsnull;
- }
- aMethodSig.AppendLiteral("[B");
- }
- }
- break;
-
- case nsXPTType::T_I16:
- case nsXPTType::T_U8:
- {
- if (!aParamInfo.IsOut()) { // 'in'
- aJValue.s = (tag == nsXPTType::T_I16) ? aVariant.val.i16 :
- aVariant.val.u8;
- aMethodSig.Append('S');
- } else { // 'inout' & 'out'
- if (aVariant.val.p) {
- jshortArray array = env->NewShortArray(1);
- if (!array) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
-
- env->SetShortArrayRegion(array, 0, 1, (jshort*) aVariant.val.p);
- aJValue.l = array;
- } else {
- aJValue.l = nsnull;
- }
- aMethodSig.AppendLiteral("[S");
- }
- }
- break;
-
- case nsXPTType::T_I32:
- case nsXPTType::T_U16:
- {
- if (!aParamInfo.IsOut()) { // 'in'
- aJValue.i = (tag == nsXPTType::T_I32) ? aVariant.val.i32 :
- aVariant.val.u16;
- aMethodSig.Append('I');
- } else { // 'inout' & 'out'
- if (aVariant.val.p) {
- jintArray array = env->NewIntArray(1);
- if (!array) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
-
- env->SetIntArrayRegion(array, 0, 1, (jint*) aVariant.val.p);
- aJValue.l = array;
- } else {
- aJValue.l = nsnull;
- }
- aMethodSig.AppendLiteral("[I");
- }
- }
- break;
-
- case nsXPTType::T_I64:
- case nsXPTType::T_U32:
- {
- if (!aParamInfo.IsOut()) { // 'in'
- aJValue.j = (tag == nsXPTType::T_I64) ? aVariant.val.i64 :
- aVariant.val.u32;
- aMethodSig.Append('J');
- } else { // 'inout' & 'out'
- if (aVariant.val.p) {
- jlongArray array = env->NewLongArray(1);
- if (!array) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
-
- env->SetLongArrayRegion(array, 0, 1, (jlong*) aVariant.val.p);
- aJValue.l = array;
- } else {
- aJValue.l = nsnull;
- }
- aMethodSig.AppendLiteral("[J");
- }
- }
- break;
-
- case nsXPTType::T_FLOAT:
- {
- if (!aParamInfo.IsOut()) { // 'in'
- aJValue.f = aVariant.val.f;
- aMethodSig.Append('F');
- } else { // 'inout' & 'out'
- if (aVariant.val.p) {
- jfloatArray array = env->NewFloatArray(1);
- if (!array) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
-
- env->SetFloatArrayRegion(array, 0, 1, (jfloat*) aVariant.val.p);
- aJValue.l = array;
- } else {
- aJValue.l = nsnull;
- }
- aMethodSig.AppendLiteral("[F");
- }
- }
- break;
-
- // XXX how do we handle unsigned 64-bit values?
- case nsXPTType::T_U64:
- case nsXPTType::T_DOUBLE:
- {
- if (!aParamInfo.IsOut()) { // 'in'
- aJValue.d = (tag == nsXPTType::T_DOUBLE) ? aVariant.val.d :
- aVariant.val.u64;
- aMethodSig.Append('D');
- } else { // 'inout' & 'out'
- if (aVariant.val.p) {
- jdoubleArray array = env->NewDoubleArray(1);
- if (!array) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
-
- env->SetDoubleArrayRegion(array, 0, 1, (jdouble*) aVariant.val.p);
- aJValue.l = array;
- } else {
- aJValue.l = nsnull;
- }
- aMethodSig.AppendLiteral("[D");
- }
- }
- break;
-
- case nsXPTType::T_BOOL:
- {
- if (!aParamInfo.IsOut()) { // 'in'
- aJValue.z = aVariant.val.b;
- aMethodSig.Append('Z');
- } else { // 'inout' & 'out'
- if (aVariant.val.p) {
- jbooleanArray array = env->NewBooleanArray(1);
- if (!array) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
-
- env->SetBooleanArrayRegion(array, 0, 1, (jboolean*) aVariant.val.p);
- aJValue.l = array;
- } else {
- aJValue.l = nsnull;
- }
- aMethodSig.AppendLiteral("[Z");
- }
- }
- break;
-
- case nsXPTType::T_CHAR:
- case nsXPTType::T_WCHAR:
- {
- if (!aParamInfo.IsOut()) { // 'in'
- if (tag == nsXPTType::T_CHAR)
- aJValue.c = aVariant.val.c;
- else
- aJValue.c = aVariant.val.wc;
- aMethodSig.Append('C');
- } else { // 'inout' & 'out'
- if (aVariant.val.p) {
- jcharArray array = env->NewCharArray(1);
- if (!array) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
-
- env->SetCharArrayRegion(array, 0, 1, (jchar*) aVariant.val.p);
- aJValue.l = array;
- } else {
- aJValue.l = nsnull;
- }
- aMethodSig.AppendLiteral("[C");
- }
- }
- break;
-
- case nsXPTType::T_CHAR_STR:
- case nsXPTType::T_WCHAR_STR:
- {
- void* ptr = nsnull;
- if (!aParamInfo.IsOut()) { // 'in'
- ptr = aVariant.val.p;
- } else if (aVariant.val.p) { // 'inout' & 'out'
- void** variant = static_cast<void**>(aVariant.val.p);
- ptr = *variant;
- }
-
- jobject str;
- if (ptr) {
- if (tag == nsXPTType::T_CHAR_STR) {
- str = env->NewStringUTF((const char*) ptr);
- } else {
- const PRUnichar* buf = (const PRUnichar*) ptr;
- str = env->NewString(buf, nsCRT::strlen(buf));
- }
- if (!str) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
- } else {
- str = nsnull;
- }
-
- if (!aParamInfo.IsOut()) { // 'in'
- aJValue.l = str;
- aMethodSig.AppendLiteral("Ljava/lang/String;");
- } else { // 'inout' & 'out'
- if (aVariant.val.p) {
- aJValue.l = env->NewObjectArray(1, stringClass, str);
- if (aJValue.l == nsnull) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
- } else {
- aJValue.l = nsnull;
- }
- aMethodSig.AppendLiteral("[Ljava/lang/String;");
- }
- }
- break;
-
- case nsXPTType::T_IID:
- {
- nsID* iid = nsnull;
- if (!aParamInfo.IsOut()) { // 'in'
- iid = static_cast<nsID*>(aVariant.val.p);
- } else if (aVariant.val.p) { // 'inout' & 'out'
- nsID** variant = static_cast<nsID**>(aVariant.val.p);
- iid = *variant;
- }
-
- jobject str = nsnull;
- if (iid) {
- char iid_str[NSID_LENGTH];
- iid->ToProvidedString(iid_str);
- str = env->NewStringUTF(iid_str);
- if (!str) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
- }
-
- if (!aParamInfo.IsOut()) { // 'in'
- aJValue.l = str;
- aMethodSig.AppendLiteral("Ljava/lang/String;");
- } else { // 'inout' & 'out'
- if (aVariant.val.p) {
- aJValue.l = env->NewObjectArray(1, stringClass, str);
- if (aJValue.l == nsnull) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
- } else {
- aJValue.l = nsnull;
- }
- aMethodSig.AppendLiteral("[Ljava/lang/String;");
- }
- }
- break;
-
- case nsXPTType::T_INTERFACE:
- case nsXPTType::T_INTERFACE_IS:
- {
- nsISupports* xpcom_obj = nsnull;
- if (!aParamInfo.IsOut()) { // 'in'
- xpcom_obj = static_cast<nsISupports*>(aVariant.val.p);
- } else if (aVariant.val.p) { // 'inout' & 'out'
- nsISupports** variant = static_cast<nsISupports**>(aVariant.val.p);
- xpcom_obj = *variant;
- }
-
- nsID iid;
- rv = GetIIDForMethodParam(mIInfo, aMethodInfo, aParamInfo,
- aParamInfo.GetType().TagPart(), aMethodIndex,
- aDispatchParams, PR_FALSE, iid);
- if (NS_FAILED(rv))
- break;
-
- // get name of interface
- char* iface_name = nsnull;
- nsCOMPtr<nsIInterfaceInfoManager>
- iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID, &rv));
- if (NS_FAILED(rv))
- break;
-
- rv = iim->GetNameForIID(&iid, &iface_name);
- if (NS_FAILED(rv) || !iface_name)
- break;
-
- jobject java_stub = nsnull;
- if (xpcom_obj) {
- // Get matching Java object for given xpcom object
- jobject objLoader = env->CallObjectMethod(mJavaWeakRef, getReferentMID);
- rv = NativeInterfaceToJavaObject(env, xpcom_obj, iid, objLoader,
- &java_stub);
- if (NS_FAILED(rv))
- break;
- }
-
- if (!aParamInfo.IsOut()) { // 'in'
- aJValue.l = java_stub;
- } else { // 'inout' & 'out'
- if (aVariant.val.p) {
- aJValue.l = env->NewObjectArray(1, nsISupportsClass, java_stub);
- if (aJValue.l == nsnull) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
- } else {
- aJValue.l = nsnull;
- }
- aMethodSig.Append('[');
- }
-
- if (tag != nsXPTType::T_INTERFACE_IS) {
- aMethodSig.AppendLiteral("Lorg/mozilla/interfaces/");
- aMethodSig.AppendASCII(iface_name);
- aMethodSig.Append(';');
- } else {
- aMethodSig.AppendLiteral("Lorg/mozilla/interfaces/nsISupports;");
- }
-
- nsMemory::Free(iface_name);
- }
- break;
-
- case nsXPTType::T_ASTRING:
- case nsXPTType::T_DOMSTRING:
- {
- // This only handle 'in' or 'in dipper' params. In XPIDL, the 'out'
- // descriptor is mapped to 'in dipper'.
- NS_PRECONDITION(aParamInfo.IsIn(), "unexpected param descriptor");
- if (!aParamInfo.IsIn()) {
- rv = NS_ERROR_UNEXPECTED;
- break;
- }
-
- nsString* str = static_cast<nsString*>(aVariant.val.p);
- if (!str) {
- rv = NS_ERROR_FAILURE;
- break;
- }
-
- jstring jstr = nsnull;
- if (!str->IsVoid()) {
- jstr = env->NewString(str->get(), str->Length());
- if (!jstr) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
- }
-
- aJValue.l = jstr;
- aMethodSig.AppendLiteral("Ljava/lang/String;");
- }
- break;
-
- case nsXPTType::T_UTF8STRING:
- case nsXPTType::T_CSTRING:
- {
- // This only handle 'in' or 'in dipper' params. In XPIDL, the 'out'
- // descriptor is mapped to 'in dipper'.
- NS_PRECONDITION(aParamInfo.IsIn(), "unexpected param descriptor");
- if (!aParamInfo.IsIn()) {
- rv = NS_ERROR_UNEXPECTED;
- break;
- }
-
- nsCString* str = static_cast<nsCString*>(aVariant.val.p);
- if (!str) {
- rv = NS_ERROR_FAILURE;
- break;
- }
-
- jstring jstr = nsnull;
- if (!str->IsVoid()) {
- jstr = env->NewStringUTF(str->get());
- if (!jstr) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;