VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/java/src/nsJavaXPCOMGlue.cpp@ 98262

Last change on this file since 98262 was 56605, checked in by vboxsync, 10 years ago

xpcom/java: properly setup the JNI native finalize function as its name is different from what Java expects

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.4 KB
Line 
1/* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is Java XPCOM Bindings.
15 *
16 * The Initial Developer of the Original Code is IBM Corporation.
17 * Portions created by the Initial Developer are Copyright (C) 2006
18 * IBM Corporation. All Rights Reserved.
19 *
20 * Contributor(s):
21 * Javier Pedemonte (jhpedemonte@gmail.com)
22 *
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
34 *
35 * ***** END LICENSE BLOCK ***** */
36
37#include "jni.h"
38#include "nsXPCOMPrivate.h" // for XPCOM_DLL defines.
39#include "nsXPCOMGlue.h"
40#include <stdlib.h>
41
42
43#ifdef VBOX
44#include <string.h>
45#include "nsDebug.h"
46#endif
47
48#if defined(XP_WIN) || defined(XP_OS2)
49#define JX_EXPORT JNIEXPORT
50#else
51#define JX_EXPORT JNIEXPORT NS_EXPORT
52#endif
53
54
55/***********************
56 * JNI Load & Unload
57 ***********************/
58
59extern "C" JX_EXPORT jint JNICALL
60JNI_OnLoad(JavaVM* vm, void* reserved)
61{
62 // Let the JVM know that we are using JDK 1.2 JNI features.
63 return JNI_VERSION_1_2;
64}
65
66extern "C" JX_EXPORT void JNICALL
67JNI_OnUnload(JavaVM* vm, void* reserved)
68{
69}
70
71/********************************
72 * JavaXPCOM JNI interfaces
73 ********************************/
74
75#define JXM_NATIVE(func) Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_##func
76
77enum {
78 kFunc_Initialize,
79 kFunc_InitEmbedding,
80 kFunc_TermEmbedding,
81 kFunc_LockProfileDirectory,
82 kFunc_NotifyProfile,
83 kFunc_InitXPCOM,
84 kFunc_ShutdownXPCOM,
85 kFunc_GetComponentManager,
86 kFunc_GetComponentRegistrar,
87 kFunc_GetServiceManager,
88 kFunc_NewLocalFile,
89 kFunc_CallXPCOMMethod,
90 kFunc_FinalizeProxy,
91 kFunc_IsSameXPCOMObject,
92 kFunc_ReleaseProfileLock,
93 kFunc_GetNativeHandleFromAWT,
94 kFunc_WrapJavaObject,
95 kFunc_WrapXPCOMObject
96};
97
98#define JX_NUM_FUNCS 18
99
100
101// Get path string from java.io.File object.
102jstring
103GetJavaFilePath(JNIEnv* env, jobject aFile)
104{
105 jclass clazz = env->FindClass("java/io/File");
106 if (clazz) {
107 jmethodID pathMID = env->GetMethodID(clazz, "getCanonicalPath",
108 "()Ljava/lang/String;");
109 if (pathMID) {
110 return (jstring) env->CallObjectMethod(aFile, pathMID);
111 }
112 }
113
114 return nsnull;
115}
116#ifdef VBOX
117
118#include "nsXPTCUtils.h"
119#include "nsCOMPtr.h"
120#include "nsIInterfaceInfoManager.h"
121#include "nsJavaInterfaces.h"
122
123void
124ThrowException(JNIEnv* env, const nsresult aErrorCode, const char* aMessage);
125
126class nsXPTCJStub : public nsXPTCStubBase
127{
128 nsCOMPtr<nsIInterfaceInfo> mII;
129 nsIXPTCProxy* mOuter;
130 public:
131 NS_DECL_ISUPPORTS_INHERITED
132
133 nsXPTCJStub(REFNSIID aIID, nsIXPTCProxy* aOuter, nsIInterfaceInfo* ii)
134 {
135 mOuter = aOuter;
136 mII = ii;
137 }
138
139 virtual ~nsXPTCJStub()
140 {
141 }
142
143 NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info)
144 {
145 *info = mII;
146 (*info)->AddRef();
147 return NS_OK;
148 }
149 // call this method and return result
150 NS_IMETHOD CallMethod(PRUint16 methodIndex,
151 const nsXPTMethodInfo* info,
152 nsXPTCMiniVariant* params)
153 {
154 return mOuter->CallMethod(methodIndex, info, params);
155 }
156};
157
158NS_IMETHODIMP_(nsrefcnt)
159nsXPTCJStub::AddRef()
160{
161 return mOuter->AddRef();
162}
163
164NS_IMETHODIMP_(nsrefcnt)
165nsXPTCJStub::Release()
166{
167 return mOuter->Release();
168}
169
170NS_IMETHODIMP nsXPTCJStub::QueryInterface(REFNSIID aIID, void** aInstancePtr)
171{
172 nsIID* mIID;
173 mII->GetInterfaceIID(&mIID);
174
175 if (mIID->Equals(aIID)) {
176 NS_ADDREF_THIS();
177 *aInstancePtr = static_cast<nsISupports*>(this);
178 return NS_OK;
179 }
180
181 return mOuter->QueryInterface(aIID, aInstancePtr);
182}
183
184nsresult
185NS_GetXPTCallStub(REFNSIID aIID, nsIXPTCProxy* aOuter,
186 nsISomeInterface* *aResult)
187{
188 NS_ENSURE_ARG(aOuter && aResult);
189#if 0
190 xptiInterfaceInfoManager *iim =
191 xptiInterfaceInfoManager::GetInterfaceInfoManagerNoAddRef();
192 NS_ENSURE_TRUE(iim, NS_ERROR_NOT_INITIALIZED);
193
194 xptiInterfaceEntry *iie = iim->GetInterfaceEntryForIID(&aIID);
195 if (!iie || !iie->EnsureResolved())
196 return NS_ERROR_FAILURE;
197
198 nsXPTCStubBase* newbase = new nsXPTCStubBase(aOuter, iie);
199 if (!newbase)
200 return NS_ERROR_OUT_OF_MEMORY;
201
202 *aResult = newbase;
203#else
204 nsCOMPtr<nsIInterfaceInfoManager> iim = XPTI_GetInterfaceInfoManager();
205 nsCOMPtr<nsIInterfaceInfo> ii;
206 nsresult rv;
207
208 rv = iim->GetInfoForIID(&aIID, getter_AddRefs(ii));
209 if (NS_FAILED(rv))
210 return rv;
211
212 nsXPTCStubBase* newbase = new nsXPTCJStub(aIID, aOuter, ii);
213 if (!newbase)
214 return NS_ERROR_OUT_OF_MEMORY;
215 *aResult = newbase;
216#endif
217 return NS_OK;
218}
219
220void
221NS_DestroyXPTCallStub(nsISomeInterface* aStub)
222{
223 nsXPTCStubBase* stub = static_cast<nsXPTCStubBase*>(aStub);
224 delete(stub);
225}
226
227
228extern "C" void JAVAPROXY_NATIVE(finalizeProxy)(JNIEnv *env, jclass that, jobject aJavaProxy);
229
230nsresult
231FindVBoxMethods(JNIEnv* env, jobject aXPCOMPath, void** aFunctions)
232{
233 nsresult rv = 0;
234
235 // We only need to care about this function because the C function we offer
236 // is different from what the Java side expects
237 aFunctions[kFunc_FinalizeProxy] = (void*)JAVAPROXY_NATIVE(finalizeProxy);
238
239 return rv;
240}
241#else
242// Calls XPCOMGlueStartup using the given java.io.File object, and loads
243// the JavaXPCOM methods from the XUL shared library.
244nsresult
245LoadXULMethods(JNIEnv* env, jobject aXPCOMPath, void** aFunctions)
246{
247 jstring pathString = GetJavaFilePath(env, aXPCOMPath);
248 if (!pathString)
249 return NS_ERROR_FAILURE;
250 const char* path = env->GetStringUTFChars(pathString, nsnull);
251 if (!path)
252 return NS_ERROR_OUT_OF_MEMORY;
253
254 int len = strlen(path);
255 char* xpcomPath = (char*) malloc(len + sizeof(XPCOM_DLL) +
256 sizeof(XPCOM_FILE_PATH_SEPARATOR) + 1);
257 if (!xpcomPath)
258 return NS_ERROR_OUT_OF_MEMORY;
259 sprintf(xpcomPath, "%s" XPCOM_FILE_PATH_SEPARATOR XPCOM_DLL, path);
260
261 nsresult rv = XPCOMGlueStartup(xpcomPath);
262 free(xpcomPath);
263 if (NS_FAILED(rv))
264 return rv;
265
266#ifdef XP_WIN32
267 // The JNICALL calling convention defines to "__stdcall" on Win32, which
268 // mangles the name.
269 nsDynamicFunctionLoad funcs[] = {
270 { "_Java_org_mozilla_xpcom_internal_MozillaImpl_initialize@8",
271 (NSFuncPtr*) &aFunctions[kFunc_Initialize] },
272 { "_Java_org_mozilla_xpcom_internal_GREImpl_initEmbedding@20",
273 (NSFuncPtr*) &aFunctions[kFunc_InitEmbedding] },
274 { "_Java_org_mozilla_xpcom_internal_GREImpl_termEmbedding@8",
275 (NSFuncPtr*) &aFunctions[kFunc_TermEmbedding] },
276 { "_Java_org_mozilla_xpcom_internal_GREImpl_lockProfileDirectory@12",
277 (NSFuncPtr*) &aFunctions[kFunc_LockProfileDirectory] },
278 { "_Java_org_mozilla_xpcom_internal_GREImpl_notifyProfile@8",
279 (NSFuncPtr*) &aFunctions[kFunc_NotifyProfile] },
280 { "_Java_org_mozilla_xpcom_internal_XPCOMImpl_initXPCOM@16",
281 (NSFuncPtr*) &aFunctions[kFunc_InitXPCOM] },
282 { "_Java_org_mozilla_xpcom_internal_XPCOMImpl_shutdownXPCOM@12",
283 (NSFuncPtr*) &aFunctions[kFunc_ShutdownXPCOM] },
284 { "_Java_org_mozilla_xpcom_internal_XPCOMImpl_getComponentManager@8",
285 (NSFuncPtr*) &aFunctions[kFunc_GetComponentManager] },
286 { "_Java_org_mozilla_xpcom_internal_XPCOMImpl_getComponentRegistrar@8",
287 (NSFuncPtr*) &aFunctions[kFunc_GetComponentRegistrar] },
288 { "_Java_org_mozilla_xpcom_internal_XPCOMImpl_getServiceManager@8",
289 (NSFuncPtr*) &aFunctions[kFunc_GetServiceManager] },
290 { "_Java_org_mozilla_xpcom_internal_XPCOMImpl_newLocalFile@16",
291 (NSFuncPtr*) &aFunctions[kFunc_NewLocalFile] },
292 { "_Java_org_mozilla_xpcom_internal_XPCOMJavaProxy_callXPCOMMethod@20",
293 (NSFuncPtr*) &aFunctions[kFunc_CallXPCOMMethod] },
294 { "_Java_org_mozilla_xpcom_internal_XPCOMJavaProxy_finalizeProxy@12",
295 (NSFuncPtr*) &aFunctions[kFunc_FinalizeProxy] },
296 { "_Java_org_mozilla_xpcom_internal_XPCOMJavaProxy_isSameXPCOMObject@16",
297 (NSFuncPtr*) &aFunctions[kFunc_IsSameXPCOMObject] },
298 { "_Java_org_mozilla_xpcom_ProfileLock_release@16",
299 (NSFuncPtr*) &aFunctions[kFunc_ReleaseProfileLock] },
300 { "_Java_org_mozilla_xpcom_internal_MozillaImpl_getNativeHandleFromAWT@12",
301 (NSFuncPtr*) &aFunctions[kFunc_GetNativeHandleFromAWT] },
302 { "_Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_wrapJavaObject@16",
303 (NSFuncPtr*) &aFunctions[kFunc_WrapJavaObject] },
304 { "_Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_wrapXPCOMObject@20",
305 (NSFuncPtr*) &aFunctions[kFunc_WrapXPCOMObject] },
306 { nsnull, nsnull }
307 };
308#else
309 nsDynamicFunctionLoad funcs[] = {
310 { "Java_org_mozilla_xpcom_internal_MozillaImpl_initialize",
311 (NSFuncPtr*) &aFunctions[kFunc_Initialize] },
312 { "Java_org_mozilla_xpcom_internal_GREImpl_initEmbedding",
313 (NSFuncPtr*) &aFunctions[kFunc_InitEmbedding] },
314 { "Java_org_mozilla_xpcom_internal_GREImpl_termEmbedding",
315 (NSFuncPtr*) &aFunctions[kFunc_TermEmbedding] },
316 { "Java_org_mozilla_xpcom_internal_GREImpl_lockProfileDirectory",
317 (NSFuncPtr*) &aFunctions[kFunc_LockProfileDirectory] },
318 { "Java_org_mozilla_xpcom_internal_GREImpl_notifyProfile",
319 (NSFuncPtr*) &aFunctions[kFunc_NotifyProfile] },
320 { "Java_org_mozilla_xpcom_internal_XPCOMImpl_initXPCOM",
321 (NSFuncPtr*) &aFunctions[kFunc_InitXPCOM] },
322 { "Java_org_mozilla_xpcom_internal_XPCOMImpl_shutdownXPCOM",
323 (NSFuncPtr*) &aFunctions[kFunc_ShutdownXPCOM] },
324 { "Java_org_mozilla_xpcom_internal_XPCOMImpl_getComponentManager",
325 (NSFuncPtr*) &aFunctions[kFunc_GetComponentManager] },
326 { "Java_org_mozilla_xpcom_internal_XPCOMImpl_getComponentRegistrar",
327 (NSFuncPtr*) &aFunctions[kFunc_GetComponentRegistrar] },
328 { "Java_org_mozilla_xpcom_internal_XPCOMImpl_getServiceManager",
329 (NSFuncPtr*) &aFunctions[kFunc_GetServiceManager] },
330 { "Java_org_mozilla_xpcom_internal_XPCOMImpl_newLocalFile",
331 (NSFuncPtr*) &aFunctions[kFunc_NewLocalFile] },
332 { "Java_org_mozilla_xpcom_internal_XPCOMJavaProxy_callXPCOMMethod",
333 (NSFuncPtr*) &aFunctions[kFunc_CallXPCOMMethod] },
334 { "Java_org_mozilla_xpcom_internal_XPCOMJavaProxy_finalizeProxy",
335 (NSFuncPtr*) &aFunctions[kFunc_FinalizeProxy] },
336 { "Java_org_mozilla_xpcom_internal_XPCOMJavaProxy_isSameXPCOMObject",
337 (NSFuncPtr*) &aFunctions[kFunc_IsSameXPCOMObject] },
338 { "Java_org_mozilla_xpcom_ProfileLock_release",
339 (NSFuncPtr*) &aFunctions[kFunc_ReleaseProfileLock] },
340 { "Java_org_mozilla_xpcom_internal_MozillaImpl_getNativeHandleFromAWT",
341 (NSFuncPtr*) &aFunctions[kFunc_GetNativeHandleFromAWT] },
342 { "Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_wrapJavaObject",
343 (NSFuncPtr*) &aFunctions[kFunc_WrapJavaObject] },
344 { "Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_wrapXPCOMObject",
345 (NSFuncPtr*) &aFunctions[kFunc_WrapXPCOMObject] },
346 { nsnull, nsnull }
347 };
348#endif
349
350 rv = XPCOMGlueLoadXULFunctions(funcs);
351 if (NS_FAILED(rv))
352 return rv;
353
354 return NS_OK;
355}
356
357void
358ThrowException(JNIEnv* env, const nsresult aErrorCode, const char* aMessage)
359{
360 // Only throw this exception if one hasn't already been thrown, so we don't
361 // mask a previous exception/error.
362 if (env->ExceptionCheck())
363 return;
364
365 // If the error code we get is for an Out Of Memory error, try to throw an
366 // OutOfMemoryError. The JVM may have enough memory to create this error.
367 if (aErrorCode == NS_ERROR_OUT_OF_MEMORY) {
368 jclass clazz = env->FindClass("java/lang/OutOfMemoryError");
369 if (clazz) {
370 env->ThrowNew(clazz, aMessage);
371 }
372 env->DeleteLocalRef(clazz);
373 return;
374 }
375
376 // If the error was not handled above, then create an XPCOMException with the
377 // given error code.
378 jthrowable throwObj = nsnull;
379 jclass exceptionClass = env->FindClass("org/mozilla/xpcom/XPCOMException");
380 if (exceptionClass) {
381 jmethodID mid = env->GetMethodID(exceptionClass, "<init>",
382 "(JLjava/lang/String;)V");
383 if (mid) {
384 throwObj = (jthrowable) env->NewObject(exceptionClass, mid,
385 (PRInt64) aErrorCode,
386 env->NewStringUTF(aMessage));
387 }
388 }
389 NS_ASSERTION(throwObj, "Failed to create XPCOMException object");
390
391 // throw exception
392 if (throwObj) {
393 env->Throw(throwObj);
394 }
395}
396#endif // VBOX
397
398// Register the JavaXPCOM native methods. This associates a native Java
399// method with its C implementation.
400nsresult
401RegisterNativeMethods(JNIEnv* env, void** aFunctions)
402{
403 JNINativeMethod mozilla_methods[] = {
404 { "initializeNative", "()V",
405 (void*) aFunctions[kFunc_Initialize] },
406 { "getNativeHandleFromAWT", "(Ljava/lang/Object;)J",
407 (void*) aFunctions[kFunc_GetNativeHandleFromAWT] }
408 };
409
410 JNINativeMethod gre_methods[] = {
411 { "initEmbeddingNative",
412 "(Ljava/io/File;Ljava/io/File;Lorg/mozilla/xpcom/IAppFileLocProvider;)V",
413 (void*) aFunctions[kFunc_InitEmbedding] },
414 { "termEmbedding", "()V",
415 (void*) aFunctions[kFunc_TermEmbedding] },
416 { "lockProfileDirectory", "(Ljava/io/File;)Lorg/mozilla/xpcom/ProfileLock;",
417 (void*) aFunctions[kFunc_LockProfileDirectory] },
418 { "notifyProfile", "()V",
419 (void*) aFunctions[kFunc_NotifyProfile] },
420 };
421
422 JNINativeMethod xpcom_methods[] = {
423 { "initXPCOMNative",
424 "(Ljava/io/File;Lorg/mozilla/xpcom/IAppFileLocProvider;)Lorg/mozilla/interfaces/nsIServiceManager;",
425 (void*) aFunctions[kFunc_InitXPCOM] },
426 { "shutdownXPCOM", "(Lorg/mozilla/interfaces/nsIServiceManager;)V",
427 (void*) aFunctions[kFunc_ShutdownXPCOM] },
428 { "getComponentManager", "()Lorg/mozilla/interfaces/nsIComponentManager;",
429 (void*) aFunctions[kFunc_GetComponentManager] },
430 { "getComponentRegistrar", "()Lorg/mozilla/interfaces/nsIComponentRegistrar;",
431 (void*) aFunctions[kFunc_GetComponentRegistrar] },
432 { "getServiceManager", "()Lorg/mozilla/interfaces/nsIServiceManager;",
433 (void*) aFunctions[kFunc_GetServiceManager] },
434 { "newLocalFile", "(Ljava/lang/String;Z)Lorg/mozilla/interfaces/nsILocalFile;",
435 (void*) aFunctions[kFunc_NewLocalFile] }
436 };
437
438 JNINativeMethod proxy_methods[] = {
439 { "callXPCOMMethod",
440 "(Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/Object;",
441 (void*) aFunctions[kFunc_CallXPCOMMethod] },
442 { "finalizeProxyNative", "(Ljava/lang/Object;)V",
443 (void*) aFunctions[kFunc_FinalizeProxy] },
444 { "isSameXPCOMObject", "(Ljava/lang/Object;Ljava/lang/Object;)Z",
445 (void*) aFunctions[kFunc_IsSameXPCOMObject] }
446 };
447
448 JNINativeMethod lockProxy_methods[] = {
449 { "releaseNative", "(J)V",
450 (void*) aFunctions[kFunc_ReleaseProfileLock] }
451 };
452
453 JNINativeMethod util_methods[] = {
454 { "wrapJavaObject", "(Ljava/lang/Object;Ljava/lang/String;)J",
455 (void*) aFunctions[kFunc_WrapJavaObject] },
456 { "wrapXPCOMObject", "(JLjava/lang/String;)Ljava/lang/Object;",
457 (void*) aFunctions[kFunc_WrapXPCOMObject] }
458 };
459
460 jint rc = -1;
461 jclass clazz = env->FindClass("org/mozilla/xpcom/internal/MozillaImpl");
462 if (clazz) {
463 rc = env->RegisterNatives(clazz, mozilla_methods,
464 sizeof(mozilla_methods) / sizeof(mozilla_methods[0]));
465 }
466 NS_ENSURE_TRUE(rc == 0, NS_ERROR_FAILURE);
467
468 rc = -1;
469 clazz = env->FindClass("org/mozilla/xpcom/internal/GREImpl");
470 if (clazz) {
471 rc = env->RegisterNatives(clazz, gre_methods,
472 sizeof(gre_methods) / sizeof(gre_methods[0]));
473 }
474 NS_ENSURE_TRUE(rc == 0, NS_ERROR_FAILURE);
475
476 rc = -1;
477 clazz = env->FindClass("org/mozilla/xpcom/internal/XPCOMImpl");
478 if (clazz) {
479 rc = env->RegisterNatives(clazz, xpcom_methods,
480 sizeof(xpcom_methods) / sizeof(xpcom_methods[0]));
481 }
482 NS_ENSURE_TRUE(rc == 0, NS_ERROR_FAILURE);
483
484 rc = -1;
485 clazz = env->FindClass("org/mozilla/xpcom/internal/XPCOMJavaProxy");
486 if (clazz) {
487 rc = env->RegisterNatives(clazz, proxy_methods,
488 sizeof(proxy_methods) / sizeof(proxy_methods[0]));
489 }
490 NS_ENSURE_TRUE(rc == 0, NS_ERROR_FAILURE);
491
492 rc = -1;
493 clazz = env->FindClass("org/mozilla/xpcom/ProfileLock");
494 if (clazz) {
495 rc = env->RegisterNatives(clazz, lockProxy_methods,
496 sizeof(lockProxy_methods) / sizeof(lockProxy_methods[0]));
497 }
498 NS_ENSURE_TRUE(rc == 0, NS_ERROR_FAILURE);
499
500 rc = -1;
501 clazz = env->FindClass("org/mozilla/xpcom/internal/JavaXPCOMMethods");
502 if (clazz) {
503 rc = env->RegisterNatives(clazz, util_methods,
504 sizeof(util_methods) / sizeof(util_methods[0]));
505 }
506 NS_ENSURE_TRUE(rc == 0, NS_ERROR_FAILURE);
507
508 return NS_OK;
509}
510
511// Load the JavaXPCOM methods from the XUL shared library, and registers them
512// as Java native methods.
513extern "C" JX_EXPORT void JNICALL
514JXM_NATIVE(registerJavaXPCOMMethodsNative) (JNIEnv *env, jclass that,
515 jobject aXPCOMPath)
516{
517 void* functions[JX_NUM_FUNCS];
518 memset(functions, 0, JX_NUM_FUNCS * sizeof(void*));
519
520#ifdef VBOX
521 nsresult rv = FindVBoxMethods(env, aXPCOMPath, functions);
522 if (NS_SUCCEEDED(rv)) {
523 rv = RegisterNativeMethods(env, functions);
524 }
525#else
526 nsresult rv = LoadXULMethods(env, aXPCOMPath, functions);
527 if (NS_SUCCEEDED(rv)) {
528 rv = RegisterNativeMethods(env, functions);
529 }
530#endif
531
532 if (NS_FAILED(rv)) {
533 ThrowException(env, rv, "Failed to register JavaXPCOM methods");
534 }
535}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette