2005-12-15 17:17:20 +03:00
|
|
|
/* ***** 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.
|
|
|
|
*
|
2006-04-04 01:16:49 +04:00
|
|
|
* The Initial Developer of the Original Code is IBM Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2006
|
2005-12-15 17:17:20 +03:00
|
|
|
* 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"
|
2006-05-03 21:18:09 +04:00
|
|
|
#include "nsDebug.h"
|
2005-12-15 17:17:20 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2006-05-18 01:42:41 +04:00
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
|
|
|
#define JX_EXPORT JNIEXPORT
|
|
|
|
#else
|
|
|
|
#define JX_EXPORT JNIEXPORT NS_EXPORT
|
|
|
|
#endif
|
|
|
|
|
2005-12-15 17:17:20 +03:00
|
|
|
|
|
|
|
/***********************
|
|
|
|
* JNI Load & Unload
|
|
|
|
***********************/
|
|
|
|
|
2006-05-18 01:42:41 +04:00
|
|
|
extern "C" JX_EXPORT jint JNICALL
|
2005-12-15 17:17:20 +03:00
|
|
|
JNI_OnLoad(JavaVM* vm, void* reserved)
|
|
|
|
{
|
|
|
|
// Let the JVM know that we are using JDK 1.2 JNI features.
|
|
|
|
return JNI_VERSION_1_2;
|
|
|
|
}
|
|
|
|
|
2006-05-18 01:42:41 +04:00
|
|
|
extern "C" JX_EXPORT void JNICALL
|
2005-12-15 17:17:20 +03:00
|
|
|
JNI_OnUnload(JavaVM* vm, void* reserved)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************
|
2005-12-16 20:32:45 +03:00
|
|
|
* JavaXPCOM JNI interfaces
|
2005-12-15 17:17:20 +03:00
|
|
|
********************************/
|
|
|
|
|
2006-04-04 01:16:49 +04:00
|
|
|
#define JXM_NATIVE(func) Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_##func
|
|
|
|
|
|
|
|
enum {
|
2006-10-18 19:03:50 +04:00
|
|
|
kFunc_Initialize,
|
2006-04-04 01:16:49 +04:00
|
|
|
kFunc_InitEmbedding,
|
|
|
|
kFunc_TermEmbedding,
|
2006-06-09 17:40:08 +04:00
|
|
|
kFunc_LockProfileDirectory,
|
|
|
|
kFunc_NotifyProfile,
|
2006-04-04 01:16:49 +04:00
|
|
|
kFunc_InitXPCOM,
|
|
|
|
kFunc_ShutdownXPCOM,
|
|
|
|
kFunc_GetComponentManager,
|
|
|
|
kFunc_GetComponentRegistrar,
|
|
|
|
kFunc_GetServiceManager,
|
|
|
|
kFunc_NewLocalFile,
|
|
|
|
kFunc_CallXPCOMMethod,
|
|
|
|
kFunc_FinalizeProxy,
|
2006-10-18 19:03:50 +04:00
|
|
|
kFunc_IsSameXPCOMObject,
|
2006-12-12 00:07:02 +03:00
|
|
|
kFunc_ReleaseProfileLock,
|
2007-02-13 21:55:34 +03:00
|
|
|
kFunc_GetNativeHandleFromAWT,
|
|
|
|
kFunc_WrapJavaObject,
|
|
|
|
kFunc_WrapXPCOMObject
|
2005-12-15 17:17:20 +03:00
|
|
|
};
|
|
|
|
|
2007-02-13 21:55:34 +03:00
|
|
|
#define JX_NUM_FUNCS 18
|
2006-04-04 01:16:49 +04:00
|
|
|
|
|
|
|
|
2005-12-15 17:17:20 +03:00
|
|
|
// 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
|
2005-12-16 20:32:45 +03:00
|
|
|
// the JavaXPCOM methods from the XUL shared library.
|
2005-12-15 17:17:20 +03:00
|
|
|
nsresult
|
2006-04-04 01:16:49 +04:00
|
|
|
LoadXULMethods(JNIEnv* env, jobject aXPCOMPath, void** aFunctions)
|
2005-12-15 17:17:20 +03:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2007-01-11 22:24:27 +03:00
|
|
|
#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] },
|
2007-01-23 00:46:02 +03:00
|
|
|
{ "_Java_org_mozilla_xpcom_internal_MozillaImpl_getNativeHandleFromAWT@12",
|
2007-01-11 22:24:27 +03:00
|
|
|
(NSFuncPtr*) &aFunctions[kFunc_GetNativeHandleFromAWT] },
|
2007-02-13 21:55:34 +03:00
|
|
|
{ "_Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_wrapJavaObject@16",
|
|
|
|
(NSFuncPtr*) &aFunctions[kFunc_WrapJavaObject] },
|
2007-02-17 01:32:35 +03:00
|
|
|
{ "_Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_wrapXPCOMObject@20",
|
2007-02-13 21:55:34 +03:00
|
|
|
(NSFuncPtr*) &aFunctions[kFunc_WrapXPCOMObject] },
|
2007-01-11 22:24:27 +03:00
|
|
|
{ nsnull, nsnull }
|
|
|
|
};
|
|
|
|
#else
|
2006-04-04 01:16:49 +04:00
|
|
|
nsDynamicFunctionLoad funcs[] = {
|
2006-10-18 19:03:50 +04:00
|
|
|
{ "Java_org_mozilla_xpcom_internal_MozillaImpl_initialize",
|
|
|
|
(NSFuncPtr*) &aFunctions[kFunc_Initialize] },
|
2006-04-04 01:16:49 +04:00
|
|
|
{ "Java_org_mozilla_xpcom_internal_GREImpl_initEmbedding",
|
|
|
|
(NSFuncPtr*) &aFunctions[kFunc_InitEmbedding] },
|
|
|
|
{ "Java_org_mozilla_xpcom_internal_GREImpl_termEmbedding",
|
|
|
|
(NSFuncPtr*) &aFunctions[kFunc_TermEmbedding] },
|
2006-06-09 17:40:08 +04:00
|
|
|
{ "Java_org_mozilla_xpcom_internal_GREImpl_lockProfileDirectory",
|
|
|
|
(NSFuncPtr*) &aFunctions[kFunc_LockProfileDirectory] },
|
|
|
|
{ "Java_org_mozilla_xpcom_internal_GREImpl_notifyProfile",
|
|
|
|
(NSFuncPtr*) &aFunctions[kFunc_NotifyProfile] },
|
2006-04-04 01:16:49 +04:00
|
|
|
{ "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] },
|
2006-10-18 19:03:50 +04:00
|
|
|
{ "Java_org_mozilla_xpcom_ProfileLock_release",
|
|
|
|
(NSFuncPtr*) &aFunctions[kFunc_ReleaseProfileLock] },
|
2006-12-12 00:07:02 +03:00
|
|
|
{ "Java_org_mozilla_xpcom_internal_MozillaImpl_getNativeHandleFromAWT",
|
|
|
|
(NSFuncPtr*) &aFunctions[kFunc_GetNativeHandleFromAWT] },
|
2007-02-13 21:55:34 +03:00
|
|
|
{ "Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_wrapJavaObject",
|
|
|
|
(NSFuncPtr*) &aFunctions[kFunc_WrapJavaObject] },
|
|
|
|
{ "Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_wrapXPCOMObject",
|
|
|
|
(NSFuncPtr*) &aFunctions[kFunc_WrapXPCOMObject] },
|
2006-04-04 01:16:49 +04:00
|
|
|
{ nsnull, nsnull }
|
|
|
|
};
|
2007-01-11 22:24:27 +03:00
|
|
|
#endif
|
2006-04-04 01:16:49 +04:00
|
|
|
|
2005-12-15 17:17:20 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-04 01:16:49 +04:00
|
|
|
// Register the JavaXPCOM native methods. This associates a native Java
|
|
|
|
// method with its C implementation.
|
|
|
|
nsresult
|
|
|
|
RegisterNativeMethods(JNIEnv* env, void** aFunctions)
|
2005-12-15 17:17:20 +03:00
|
|
|
{
|
2006-10-18 19:03:50 +04:00
|
|
|
JNINativeMethod mozilla_methods[] = {
|
|
|
|
{ "initializeNative", "()V",
|
|
|
|
(void*) aFunctions[kFunc_Initialize] },
|
2006-12-12 00:07:02 +03:00
|
|
|
{ "getNativeHandleFromAWT", "(Ljava/lang/Object;)J",
|
|
|
|
(void*) aFunctions[kFunc_GetNativeHandleFromAWT] }
|
2006-10-18 19:03:50 +04:00
|
|
|
};
|
|
|
|
|
2006-04-04 01:16:49 +04:00
|
|
|
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] },
|
2006-10-18 19:03:50 +04:00
|
|
|
{ "lockProfileDirectory", "(Ljava/io/File;)Lorg/mozilla/xpcom/ProfileLock;",
|
2006-06-09 17:40:08 +04:00
|
|
|
(void*) aFunctions[kFunc_LockProfileDirectory] },
|
|
|
|
{ "notifyProfile", "()V",
|
|
|
|
(void*) aFunctions[kFunc_NotifyProfile] },
|
2006-04-04 01:16:49 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
JNINativeMethod xpcom_methods[] = {
|
|
|
|
{ "initXPCOMNative",
|
2007-01-31 23:54:19 +03:00
|
|
|
"(Ljava/io/File;Lorg/mozilla/xpcom/IAppFileLocProvider;)Lorg/mozilla/interfaces/nsIServiceManager;",
|
2006-04-04 01:16:49 +04:00
|
|
|
(void*) aFunctions[kFunc_InitXPCOM] },
|
2007-01-31 23:54:19 +03:00
|
|
|
{ "shutdownXPCOM", "(Lorg/mozilla/interfaces/nsIServiceManager;)V",
|
2006-04-04 01:16:49 +04:00
|
|
|
(void*) aFunctions[kFunc_ShutdownXPCOM] },
|
2007-01-31 23:54:19 +03:00
|
|
|
{ "getComponentManager", "()Lorg/mozilla/interfaces/nsIComponentManager;",
|
2006-04-04 01:16:49 +04:00
|
|
|
(void*) aFunctions[kFunc_GetComponentManager] },
|
2007-01-31 23:54:19 +03:00
|
|
|
{ "getComponentRegistrar", "()Lorg/mozilla/interfaces/nsIComponentRegistrar;",
|
2006-04-04 01:16:49 +04:00
|
|
|
(void*) aFunctions[kFunc_GetComponentRegistrar] },
|
2007-01-31 23:54:19 +03:00
|
|
|
{ "getServiceManager", "()Lorg/mozilla/interfaces/nsIServiceManager;",
|
2006-04-04 01:16:49 +04:00
|
|
|
(void*) aFunctions[kFunc_GetServiceManager] },
|
2007-01-31 23:54:19 +03:00
|
|
|
{ "newLocalFile", "(Ljava/lang/String;Z)Lorg/mozilla/interfaces/nsILocalFile;",
|
2006-04-04 01:16:49 +04:00
|
|
|
(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] }
|
|
|
|
};
|
|
|
|
|
2007-02-13 21:55:34 +03:00
|
|
|
JNINativeMethod lockProxy_methods[] = {
|
2006-10-18 19:03:50 +04:00
|
|
|
{ "releaseNative", "(J)V",
|
|
|
|
(void*) aFunctions[kFunc_ReleaseProfileLock] }
|
|
|
|
};
|
|
|
|
|
2007-02-13 21:55:34 +03:00
|
|
|
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] }
|
|
|
|
};
|
|
|
|
|
2006-04-04 01:16:49 +04:00
|
|
|
jint rc = -1;
|
2006-10-18 19:03:50 +04:00
|
|
|
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");
|
2006-04-04 01:16:49 +04:00
|
|
|
if (clazz) {
|
|
|
|
rc = env->RegisterNatives(clazz, gre_methods,
|
|
|
|
sizeof(gre_methods) / sizeof(gre_methods[0]));
|
2005-12-15 17:17:20 +03:00
|
|
|
}
|
2006-04-04 01:16:49 +04:00
|
|
|
NS_ENSURE_TRUE(rc == 0, NS_ERROR_FAILURE);
|
2005-12-15 17:17:20 +03:00
|
|
|
|
2006-04-04 01:16:49 +04:00
|
|
|
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);
|
2005-12-15 17:17:20 +03:00
|
|
|
|
2006-04-04 01:16:49 +04:00
|
|
|
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]));
|
2005-12-15 17:17:20 +03:00
|
|
|
}
|
2006-04-04 01:16:49 +04:00
|
|
|
NS_ENSURE_TRUE(rc == 0, NS_ERROR_FAILURE);
|
2005-12-15 17:17:20 +03:00
|
|
|
|
2006-10-18 19:03:50 +04:00
|
|
|
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);
|
|
|
|
|
2007-02-13 21:55:34 +03:00
|
|
|
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);
|
|
|
|
|
2006-04-04 01:16:49 +04:00
|
|
|
return NS_OK;
|
2005-12-15 17:17:20 +03:00
|
|
|
}
|
|
|
|
|
2006-04-04 01:16:49 +04:00
|
|
|
// Load the JavaXPCOM methods from the XUL shared library, and registers them
|
|
|
|
// as Java native methods.
|
2006-05-18 01:42:41 +04:00
|
|
|
extern "C" JX_EXPORT void JNICALL
|
2006-04-04 01:16:49 +04:00
|
|
|
JXM_NATIVE(registerJavaXPCOMMethodsNative) (JNIEnv *env, jclass that,
|
|
|
|
jobject aXPCOMPath)
|
2005-12-15 17:17:20 +03:00
|
|
|
{
|
2006-04-04 01:16:49 +04:00
|
|
|
void* functions[JX_NUM_FUNCS];
|
|
|
|
memset(functions, 0, JX_NUM_FUNCS * sizeof(void*));
|
2005-12-15 17:17:20 +03:00
|
|
|
|
2006-04-04 01:16:49 +04:00
|
|
|
nsresult rv = LoadXULMethods(env, aXPCOMPath, functions);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = RegisterNativeMethods(env, functions);
|
|
|
|
}
|
2005-12-15 17:17:20 +03:00
|
|
|
|
2006-04-04 01:16:49 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
ThrowException(env, rv, "Failed to register JavaXPCOM methods");
|
|
|
|
}
|
2006-01-05 22:56:53 +03:00
|
|
|
}
|
|
|
|
|