Bug 323231 - Expose new XRE Profile APIs to Java embedders. r=jhpedemonte/bsmedberg

This commit is contained in:
pedemont%us.ibm.com 2006-06-09 13:40:08 +00:00
parent c33cbd3c72
commit b3c06f576f
7 changed files with 131 additions and 1 deletions

View File

@ -72,6 +72,8 @@ JNI_OnUnload(JavaVM* vm, void* reserved)
enum {
kFunc_InitEmbedding,
kFunc_TermEmbedding,
kFunc_LockProfileDirectory,
kFunc_NotifyProfile,
kFunc_InitXPCOM,
kFunc_ShutdownXPCOM,
kFunc_GetComponentManager,
@ -83,7 +85,7 @@ enum {
kFunc_IsSameXPCOMObject
};
#define JX_NUM_FUNCS 11
#define JX_NUM_FUNCS 13
// Get path string from java.io.File object.
@ -131,6 +133,10 @@ LoadXULMethods(JNIEnv* env, jobject aXPCOMPath, void** aFunctions)
(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",
@ -210,6 +216,10 @@ RegisterNativeMethods(JNIEnv* env, void** aFunctions)
(void*) aFunctions[kFunc_InitEmbedding] },
{ "termEmbedding", "()V",
(void*) aFunctions[kFunc_TermEmbedding] },
{ "lockProfileDirectory", "(Ljava/io/File;)Lorg/mozilla/xpcom/nsISupports;",
(void*) aFunctions[kFunc_LockProfileDirectory] },
{ "notifyProfile", "()V",
(void*) aFunctions[kFunc_NotifyProfile] },
};
JNINativeMethod xpcom_methods[] = {

View File

@ -75,6 +75,53 @@ public interface IGRE {
*/
void termEmbedding() throws XPCOMException;
/**
* 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.
*/
nsISupports 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 XRE_InitEmbedding
* 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();
}

View File

@ -882,6 +882,22 @@ public class Mozilla implements IGRE, IXPCOM, IXPCOMError {
return iid;
}
/**
* @see IGRE#lockProfileDirectory(File, nsISupports)
*/
public nsISupports lockProfileDirectory(File aDirectory)
throws XPCOMException
{
return gre.lockProfileDirectory(aDirectory);
}
/**
* @see IGRE#notifyProfile()
*/
public void notifyProfile() {
gre.notifyProfile();
}
}

View File

@ -268,3 +268,46 @@ XPCOM_NATIVE(getServiceManager) (JNIEnv *env, jobject)
return nsnull;
}
nsresult
LockProfileDirectory_Impl(JNIEnv* env, jobject aDirectory,
jobject* aJavaLock)
{
nsresult rv;
nsCOMPtr<nsILocalFile> profDir;
if (!aDirectory) return NS_ERROR_NULL_POINTER;
rv = File_to_nsILocalFile(env, aDirectory, getter_AddRefs(profDir));
NS_ENSURE_SUCCESS(rv, rv);
nsISupports* lockObj;
rv = XRE_LockProfileDirectory(profDir, &lockObj);
NS_ENSURE_SUCCESS(rv, rv);
rv = GetNewOrUsedJavaObject(env, lockObj, NS_GET_IID(nsISupports),
aJavaLock);
NS_IF_RELEASE(lockObj);
return rv;
}
extern "C" NS_EXPORT jobject
GRE_NATIVE(lockProfileDirectory) (JNIEnv* env, jobject, jobject aDirectory)
{
jobject profLock;
nsresult rv = LockProfileDirectory_Impl(env, aDirectory, &profLock);
if (NS_SUCCEEDED(rv)) {
return profLock;
}
ThrowException(env, rv, "Failure in lockProfileDirectory");
return nsnull;
}
extern "C" NS_EXPORT void
GRE_NATIVE(notifyProfile) (JNIEnv *env, jobject)
{
XRE_NotifyProfile();
}

View File

@ -53,5 +53,9 @@ public class GREImpl extends JavaXPCOMMethods implements IGRE {
public native void termEmbedding();
public native nsISupports lockProfileDirectory(File aDirectory);
public native void notifyProfile();
}

View File

@ -44,6 +44,10 @@ void XXXNeverCalled_javaxpcom()
GRE_NATIVE(termEmbedding) (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);

View File

@ -54,6 +54,12 @@ GRE_NATIVE(initEmbedding) (JNIEnv* env, jobject, jobject aLibXULDirectory,
extern "C" NS_EXPORT void
GRE_NATIVE(termEmbedding) (JNIEnv *env, jobject);
extern "C" NS_EXPORT jobject
GRE_NATIVE(lockProfileDirectory) (JNIEnv *, jobject, jobject aDirectory);
extern "C" NS_EXPORT void
GRE_NATIVE(notifyProfile) (JNIEnv *env, jobject);
extern "C" NS_EXPORT jobject
XPCOM_NATIVE(initXPCOM) (JNIEnv* env, jobject, jobject aMozBinDirectory,
jobject aAppFileLocProvider);