From 1861ebaf8f148b3c137983e0c5678182c71c7c42 Mon Sep 17 00:00:00 2001 From: "pedemont%us.ibm.com" Date: Wed, 18 Oct 2006 15:03:50 +0000 Subject: [PATCH] Bug 340960 - Provide proper profile locking and notification. r=bsmedberg. XULRunner only. --- .../java/xpcom/glue/nsJavaXPCOMGlue.cpp | 40 ++- extensions/java/xpcom/interfaces/Makefile.in | 5 +- .../mozilla/xpcom/IAppFileLocProvider.java | 2 +- .../interfaces/org/mozilla/xpcom/IGRE.java | 36 +-- .../org/mozilla/xpcom/IMozilla.java | 55 ++++ .../org/mozilla/xpcom/INIParser.java | 13 +- .../interfaces/org/mozilla/xpcom/IXPCOM.java | 19 +- .../interfaces/org/mozilla/xpcom/Mozilla.java | 296 +++++++++++++----- .../org/mozilla/xpcom/ProfileLock.java | 63 ++++ .../org/mozilla/xpcom/VersionComparator.java | 3 +- .../xpcom/XPCOMInitializationException.java | 56 ++++ extensions/java/xpcom/src/Makefile.in | 1 + .../java/xpcom/src/dlldeps-javaxpcom.cpp | 13 +- .../java/xpcom/src/nsJavaInterfaces.cpp | 71 +++-- extensions/java/xpcom/src/nsJavaInterfaces.h | 19 +- extensions/java/xpcom/src/nsJavaWrapper.cpp | 21 +- .../org/mozilla/xpcom/internal/GREImpl.java | 12 +- .../mozilla/xpcom/internal/MozillaImpl.java | 54 ++++ .../org/mozilla/xpcom/internal/XPCOMImpl.java | 13 +- .../xpcom/internal/XPCOMJavaProxy.java | 7 +- 20 files changed, 623 insertions(+), 176 deletions(-) create mode 100644 extensions/java/xpcom/interfaces/org/mozilla/xpcom/IMozilla.java create mode 100644 extensions/java/xpcom/interfaces/org/mozilla/xpcom/ProfileLock.java create mode 100644 extensions/java/xpcom/interfaces/org/mozilla/xpcom/XPCOMInitializationException.java create mode 100644 extensions/java/xpcom/src/org/mozilla/xpcom/internal/MozillaImpl.java diff --git a/extensions/java/xpcom/glue/nsJavaXPCOMGlue.cpp b/extensions/java/xpcom/glue/nsJavaXPCOMGlue.cpp index 1e791f02270..01541690ee0 100644 --- a/extensions/java/xpcom/glue/nsJavaXPCOMGlue.cpp +++ b/extensions/java/xpcom/glue/nsJavaXPCOMGlue.cpp @@ -70,6 +70,7 @@ JNI_OnUnload(JavaVM* vm, void* reserved) #define JXM_NATIVE(func) Java_org_mozilla_xpcom_internal_JavaXPCOMMethods_##func enum { + kFunc_Initialize, kFunc_InitEmbedding, kFunc_TermEmbedding, kFunc_LockProfileDirectory, @@ -82,10 +83,11 @@ enum { kFunc_NewLocalFile, kFunc_CallXPCOMMethod, kFunc_FinalizeProxy, - kFunc_IsSameXPCOMObject + kFunc_IsSameXPCOMObject, + kFunc_ReleaseProfileLock }; -#define JX_NUM_FUNCS 13 +#define JX_NUM_FUNCS 15 // Get path string from java.io.File object. @@ -129,6 +131,8 @@ LoadXULMethods(JNIEnv* env, jobject aXPCOMPath, void** aFunctions) return rv; 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", @@ -155,6 +159,8 @@ LoadXULMethods(JNIEnv* env, jobject aXPCOMPath, void** aFunctions) (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] }, { nsnull, nsnull } }; @@ -210,13 +216,18 @@ ThrowException(JNIEnv* env, const nsresult aErrorCode, const char* aMessage) nsresult RegisterNativeMethods(JNIEnv* env, void** aFunctions) { + JNINativeMethod mozilla_methods[] = { + { "initializeNative", "()V", + (void*) aFunctions[kFunc_Initialize] }, + }; + 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/nsISupports;", + { "lockProfileDirectory", "(Ljava/io/File;)Lorg/mozilla/xpcom/ProfileLock;", (void*) aFunctions[kFunc_LockProfileDirectory] }, { "notifyProfile", "()V", (void*) aFunctions[kFunc_NotifyProfile] }, @@ -248,8 +259,21 @@ RegisterNativeMethods(JNIEnv* env, void** aFunctions) (void*) aFunctions[kFunc_IsSameXPCOMObject] } }; + JNINativeMethod lockProxy_methods[] = { + { "releaseNative", "(J)V", + (void*) aFunctions[kFunc_ReleaseProfileLock] } + }; + jint rc = -1; - jclass clazz = env->FindClass("org/mozilla/xpcom/internal/GREImpl"); + 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])); @@ -272,6 +296,14 @@ RegisterNativeMethods(JNIEnv* env, void** aFunctions) } 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); + return NS_OK; } diff --git a/extensions/java/xpcom/interfaces/Makefile.in b/extensions/java/xpcom/interfaces/Makefile.in index 4fc14b7f6d3..4658048458c 100644 --- a/extensions/java/xpcom/interfaces/Makefile.in +++ b/extensions/java/xpcom/interfaces/Makefile.in @@ -51,13 +51,16 @@ 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)/XPCOMException.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 diff --git a/extensions/java/xpcom/interfaces/org/mozilla/xpcom/IAppFileLocProvider.java b/extensions/java/xpcom/interfaces/org/mozilla/xpcom/IAppFileLocProvider.java index 2b5232f2289..633d8bbcb13 100644 --- a/extensions/java/xpcom/interfaces/org/mozilla/xpcom/IAppFileLocProvider.java +++ b/extensions/java/xpcom/interfaces/org/mozilla/xpcom/IAppFileLocProvider.java @@ -37,7 +37,7 @@ package org.mozilla.xpcom; -import java.io.*; +import java.io.File; /** diff --git a/extensions/java/xpcom/interfaces/org/mozilla/xpcom/IGRE.java b/extensions/java/xpcom/interfaces/org/mozilla/xpcom/IGRE.java index 35ecd6e0118..ecf000fe5c4 100644 --- a/extensions/java/xpcom/interfaces/org/mozilla/xpcom/IGRE.java +++ b/extensions/java/xpcom/interfaces/org/mozilla/xpcom/IGRE.java @@ -13,9 +13,8 @@ * * 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 + * 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): @@ -37,7 +36,7 @@ package org.mozilla.xpcom; -import java.io.*; +import java.io.File; public interface IGRE { @@ -70,25 +69,26 @@ public interface IGRE { *

* NOTE: Release any references to XPCOM objects that you may be holding * before calling this function. - * - * @throws XPCOMException if a failure occurred during initialization */ - void termEmbedding() throws XPCOMException; + void termEmbedding(); /** * Lock a profile directory using platform-specific semantics. * * @param aDirectory The profile directory to lock. - * @param aLockObject An opaque lock object. The directory will remain locked - * as long as the XPCOM reference is held. + * + * @return A lock object. The directory will remain locked until the lock is + * released by invoking the release method, or by the + * termination of the JVM, whichever comes first. + * + * @throws XPCOMException if a failure occurred */ - nsISupports lockProfileDirectory(File aDirectory) - throws XPCOMException; + ProfileLock lockProfileDirectory(File aDirectory) throws XPCOMException; - /** + /** * Fire notifications to inform the toolkit about a new profile. This - * method should be called after initEmbedding if the - * embedder wishes to run with a profile. + * method should be called after initEmbedding if the + * embedder wishes to run with a profile. *

* Normally the embedder should call lockProfileDirectory * to lock the directory before calling this method. @@ -96,9 +96,9 @@ public interface IGRE { * NOTE: There are two possibilities for selecting a profile: *