зеркало из https://github.com/mozilla/pjs.git
Bug 340960 - Provide proper profile locking and notification. r=bsmedberg. XULRunner only.
This commit is contained in:
Родитель
13b5c04084
Коммит
1861ebaf8f
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
package org.mozilla.xpcom;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -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,20 +69,21 @@ public interface IGRE {
|
|||
* <p>
|
||||
* 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 <code>release</code> 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
|
||||
|
@ -96,8 +96,8 @@ public interface IGRE {
|
|||
* 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
|
||||
* 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>
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/* ***** 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;
|
||||
|
||||
}
|
|
@ -37,9 +37,18 @@
|
|||
|
||||
package org.mozilla.xpcom;
|
||||
|
||||
import java.io.*;
|
||||
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.*;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 IXPCOM {
|
||||
|
@ -58,7 +57,7 @@ public interface IXPCOM {
|
|||
*
|
||||
* @return the service manager
|
||||
*
|
||||
* @exception XPCOMException <ul>
|
||||
* @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>
|
||||
|
@ -75,7 +74,7 @@ public interface IXPCOM {
|
|||
* @param aServMgr The service manager which was returned by initXPCOM.
|
||||
* This will release servMgr.
|
||||
*
|
||||
* @exception XPCOMException if a failure occurred during termination
|
||||
* @throws XPCOMException if a failure occurred during termination
|
||||
*/
|
||||
void shutdownXPCOM(nsIServiceManager aServMgr) throws XPCOMException;
|
||||
|
||||
|
@ -84,7 +83,7 @@ public interface IXPCOM {
|
|||
*
|
||||
* @return the service manager
|
||||
*
|
||||
* @exception XPCOMException
|
||||
* @throws XPCOMException
|
||||
*/
|
||||
nsIServiceManager getServiceManager() throws XPCOMException;
|
||||
|
||||
|
@ -93,7 +92,7 @@ public interface IXPCOM {
|
|||
*
|
||||
* @return the component manager
|
||||
*
|
||||
* @exception XPCOMException
|
||||
* @throws XPCOMException
|
||||
*/
|
||||
nsIComponentManager getComponentManager() throws XPCOMException;
|
||||
|
||||
|
@ -102,7 +101,7 @@ public interface IXPCOM {
|
|||
*
|
||||
* @return the component registration manager
|
||||
*
|
||||
* @exception XPCOMException
|
||||
* @throws XPCOMException
|
||||
*/
|
||||
nsIComponentRegistrar getComponentRegistrar() throws XPCOMException;
|
||||
|
||||
|
@ -119,7 +118,7 @@ public interface IXPCOM {
|
|||
*
|
||||
* @return an instance of an nsILocalFile that points to given path
|
||||
*
|
||||
* @exception XPCOMException <ul>
|
||||
* @throws XPCOMException <ul>
|
||||
* <li> NS_ERROR_FILE_UNRECOGNIZED_PATH - raised for unrecognized paths
|
||||
* or relative paths (must supply full file path) </li>
|
||||
* </ul>
|
||||
|
|
|
@ -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) 2005
|
||||
* 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,22 +36,57 @@
|
|||
|
||||
package org.mozilla.xpcom;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.net.*;
|
||||
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.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
|
||||
|
||||
/**
|
||||
* 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 IGRE, IXPCOM, IXPCOMError {
|
||||
public class Mozilla implements IMozilla, IGRE, IXPCOM, 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;
|
||||
|
@ -576,6 +610,53 @@ public class Mozilla implements IGRE, IXPCOM, IXPCOMError {
|
|||
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();
|
||||
} catch (Exception e) {
|
||||
throw new XPCOMInitializationException("Could not load " +
|
||||
"org.mozilla.xpcom.internal.* classes", e);
|
||||
}
|
||||
|
||||
mozilla.initialize(aLibXULDirectory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes libXUL for embedding purposes.
|
||||
* <p>
|
||||
|
@ -594,49 +675,17 @@ public class Mozilla implements IGRE, IXPCOM, IXPCOMError {
|
|||
* provider will be aggregated by a libXUL provider
|
||||
* which will provide the base required GRE keys.
|
||||
*
|
||||
* @throws IllegalArgumentException if <code>aLibXULDirectory</code> is not
|
||||
* a valid path
|
||||
* @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 {
|
||||
loadJavaXPCOM(aLibXULDirectory, true);
|
||||
try {
|
||||
gre.initEmbedding(aLibXULDirectory, aAppDirectory, aAppDirProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param aLibXULDirectory
|
||||
* @param aLoadGREImpl
|
||||
* @throws XPCOMException
|
||||
*/
|
||||
private void loadJavaXPCOM(File aLibXULDirectory, boolean aLoadGREImpl)
|
||||
throws XPCOMException {
|
||||
File jar = new File(aLibXULDirectory, JAVAXPCOM_JAR);
|
||||
if (!jar.exists()) {
|
||||
throw new XPCOMException(NS_ERROR_FILE_INVALID_PATH);
|
||||
}
|
||||
|
||||
URL[] urls = new URL[1];
|
||||
try {
|
||||
urls[0] = jar.toURL();
|
||||
} catch (MalformedURLException e) {
|
||||
throw new XPCOMException(NS_ERROR_FILE_INVALID_PATH);
|
||||
}
|
||||
ClassLoader loader = new URLClassLoader(urls,
|
||||
this.getClass().getClassLoader());
|
||||
|
||||
try {
|
||||
if (aLoadGREImpl) {
|
||||
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();
|
||||
} catch (Exception e) {
|
||||
throw new XPCOMException(NS_ERROR_FAILURE,
|
||||
"failure creating org.mozilla.xpcom.internal.*");
|
||||
} catch (NullPointerException e) {
|
||||
throw new XPCOMInitializationException("Must call " +
|
||||
"Mozilla.getInstance().initialize() before using this method", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -645,19 +694,95 @@ public class Mozilla implements IGRE, IXPCOM, IXPCOMError {
|
|||
* <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() throws XPCOMException {
|
||||
public void termEmbedding() {
|
||||
try {
|
||||
gre.termEmbedding();
|
||||
} catch (NullPointerException e) {
|
||||
throw new XPCOMException(Mozilla.NS_ERROR_NULL_POINTER,
|
||||
"Attempt to use unitialized GRE object");
|
||||
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.
|
||||
|
@ -674,17 +799,23 @@ public class Mozilla implements IGRE, IXPCOM, IXPCOMError {
|
|||
*
|
||||
* @return the service manager
|
||||
*
|
||||
* @exception XPCOMException <ul>
|
||||
* @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 {
|
||||
loadJavaXPCOM(aMozBinDirectory, false);
|
||||
try {
|
||||
return xpcom.initXPCOM(aMozBinDirectory, aAppFileLocProvider);
|
||||
} catch (NullPointerException e) {
|
||||
throw new XPCOMInitializationException("Must call " +
|
||||
"Mozilla.getInstance().initialize() before using this method", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -694,15 +825,19 @@ public class Mozilla implements IGRE, IXPCOM, IXPCOMError {
|
|||
* @param aServMgr The service manager which was returned by initXPCOM.
|
||||
* This will release servMgr.
|
||||
*
|
||||
* @exception XPCOMException if a failure occurred during termination
|
||||
* @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 XPCOMException(Mozilla.NS_ERROR_NULL_POINTER,
|
||||
"Attempt to use unitialized XPCOM object");
|
||||
throw new XPCOMInitializationException("Must call " +
|
||||
"Mozilla.getInstance().initialize() before using this method", e);
|
||||
} finally {
|
||||
mozilla = null;
|
||||
gre = null;
|
||||
xpcom = null;
|
||||
}
|
||||
}
|
||||
|
@ -712,14 +847,16 @@ public class Mozilla implements IGRE, IXPCOM, IXPCOMError {
|
|||
*
|
||||
* @return the service manager
|
||||
*
|
||||
* @exception XPCOMException
|
||||
* @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 XPCOMException(Mozilla.NS_ERROR_NULL_POINTER,
|
||||
"Attempt to use unitialized XPCOM object");
|
||||
throw new XPCOMInitializationException("Must call " +
|
||||
"Mozilla.getInstance().initialize() before using this method", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -728,14 +865,16 @@ public class Mozilla implements IGRE, IXPCOM, IXPCOMError {
|
|||
*
|
||||
* @return the component manager
|
||||
*
|
||||
* @exception XPCOMException
|
||||
* @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 XPCOMException(Mozilla.NS_ERROR_NULL_POINTER,
|
||||
"Attempt to use unitialized XPCOM object");
|
||||
throw new XPCOMInitializationException("Must call " +
|
||||
"Mozilla.getInstance().initialize() before using this method", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -744,14 +883,16 @@ public class Mozilla implements IGRE, IXPCOM, IXPCOMError {
|
|||
*
|
||||
* @return the component registration manager
|
||||
*
|
||||
* @exception XPCOMException
|
||||
* @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 XPCOMException(Mozilla.NS_ERROR_NULL_POINTER,
|
||||
"Attempt to use unitialized XPCOM object");
|
||||
throw new XPCOMInitializationException("Must call " +
|
||||
"Mozilla.getInstance().initialize() before using this method", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -768,18 +909,20 @@ public class Mozilla implements IGRE, IXPCOM, IXPCOMError {
|
|||
*
|
||||
* @return an instance of an nsILocalFile that points to given path
|
||||
*
|
||||
* @exception XPCOMException <ul>
|
||||
* @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 XPCOMException(Mozilla.NS_ERROR_NULL_POINTER,
|
||||
"Attempt to use unitialized XPCOM object");
|
||||
throw new XPCOMInitializationException("Must call " +
|
||||
"Mozilla.getInstance().initialize() before using this method", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -883,21 +1026,4 @@ 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/* ***** 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();
|
||||
}
|
||||
|
||||
}
|
|
@ -37,7 +37,8 @@
|
|||
|
||||
package org.mozilla.xpcom;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Enumeration;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/* ***** 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -84,6 +84,7 @@ JARFILE = javaxpcom.jar
|
|||
JAVA_SRCS = \
|
||||
org/mozilla/xpcom/internal/XPCOMJavaProxy.java \
|
||||
org/mozilla/xpcom/internal/XPCOMJavaProxyBase.java \
|
||||
org/mozilla/xpcom/internal/MozillaImpl.java \
|
||||
org/mozilla/xpcom/internal/GREImpl.java \
|
||||
org/mozilla/xpcom/internal/XPCOMImpl.java \
|
||||
org/mozilla/xpcom/internal/JavaXPCOMMethods.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) 2005
|
||||
* 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):
|
||||
|
@ -40,6 +39,8 @@
|
|||
|
||||
void XXXNeverCalled_javaxpcom()
|
||||
{
|
||||
MOZILLA_NATIVE(initialize) (nsnull, nsnull);
|
||||
|
||||
GRE_NATIVE(initEmbedding) (nsnull, nsnull, nsnull, nsnull, nsnull);
|
||||
|
||||
GRE_NATIVE(termEmbedding) (nsnull, nsnull);
|
||||
|
@ -48,6 +49,10 @@ void XXXNeverCalled_javaxpcom()
|
|||
|
||||
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);
|
||||
|
@ -65,5 +70,7 @@ void XXXNeverCalled_javaxpcom()
|
|||
JAVAPROXY_NATIVE(finalizeProxy) (nsnull, nsnull, nsnull);
|
||||
|
||||
JAVAPROXY_NATIVE(isSameXPCOMObject) (nsnull, nsnull, nsnull, nsnull);
|
||||
|
||||
LOCKPROXY_NATIVE(release) (nsnull, nsnull, nsnull);
|
||||
}
|
||||
|
||||
|
|
|
@ -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) 2005
|
||||
* 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):
|
||||
|
@ -50,13 +49,23 @@
|
|||
#include "nsILocalFile.h"
|
||||
|
||||
|
||||
extern "C" NS_EXPORT void
|
||||
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;
|
||||
if (!InitializeJavaGlobals(env))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// create an nsILocalFile from given java.io.File
|
||||
nsCOMPtr<nsILocalFile> libXULDir;
|
||||
|
@ -110,8 +119,6 @@ InitXPCOM_Impl(JNIEnv* env, jobject aMozBinDirectory,
|
|||
jobject aAppFileLocProvider, jobject* aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
if (!InitializeJavaGlobals(env))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// create an nsILocalFile from given java.io.File
|
||||
nsCOMPtr<nsILocalFile> directory;
|
||||
|
@ -268,37 +275,33 @@ 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),
|
||||
nsnull, aJavaLock);
|
||||
NS_IF_RELEASE(lockObj);
|
||||
return rv;
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT jobject
|
||||
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));
|
||||
|
||||
jobject profLock;
|
||||
nsresult rv = LockProfileDirectory_Impl(env, aDirectory, &profLock);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
return profLock;
|
||||
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, NS_REINTERPRET_CAST(jlong, lock));
|
||||
}
|
||||
}
|
||||
|
||||
// if we get here, then something failed
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ThrowException(env, rv, "Failure in lockProfileDirectory");
|
||||
|
|
|
@ -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) 2005
|
||||
* 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):
|
||||
|
@ -41,12 +40,17 @@
|
|||
#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
|
||||
|
||||
|
||||
extern "C" NS_EXPORT void
|
||||
MOZILLA_NATIVE(initialize) (JNIEnv* env, jobject);
|
||||
|
||||
extern "C" NS_EXPORT void
|
||||
GRE_NATIVE(initEmbedding) (JNIEnv* env, jobject, jobject aLibXULDirectory,
|
||||
jobject aAppDirectory, jobject aAppDirProvider);
|
||||
|
@ -60,6 +64,12 @@ GRE_NATIVE(lockProfileDirectory) (JNIEnv *, jobject, jobject aDirectory);
|
|||
extern "C" NS_EXPORT void
|
||||
GRE_NATIVE(notifyProfile) (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);
|
||||
|
@ -91,4 +101,7 @@ extern "C" NS_EXPORT jboolean
|
|||
JAVAPROXY_NATIVE(isSameXPCOMObject) (JNIEnv *env, jclass that, jobject aProxy1,
|
||||
jobject aProxy2);
|
||||
|
||||
extern "C" NS_EXPORT void
|
||||
LOCKPROXY_NATIVE(release) (JNIEnv *env, jclass that, jlong aLockObject);
|
||||
|
||||
#endif // _nsJavaInterfaces_h_
|
||||
|
|
|
@ -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) 2005
|
||||
* 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):
|
||||
|
@ -46,6 +45,8 @@
|
|||
#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}};
|
||||
|
||||
|
@ -1742,3 +1743,17 @@ JAVAPROXY_NATIVE(isSameXPCOMObject) (JNIEnv *env, jclass that,
|
|||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* org.mozilla.xpcom.ProfileLock.release
|
||||
*/
|
||||
extern "C" NS_EXPORT void
|
||||
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, NS_REINTERPRET_CAST(nsISupports*, aLockObject));
|
||||
}
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to release using NS_ProxyRelease");
|
||||
}
|
||||
|
|
|
@ -36,15 +36,17 @@
|
|||
|
||||
package org.mozilla.xpcom.internal;
|
||||
|
||||
import java.io.*;
|
||||
import org.mozilla.xpcom.*;
|
||||
import java.io.File;
|
||||
|
||||
import org.mozilla.xpcom.IAppFileLocProvider;
|
||||
import org.mozilla.xpcom.IGRE;
|
||||
import org.mozilla.xpcom.ProfileLock;
|
||||
|
||||
|
||||
public class GREImpl extends JavaXPCOMMethods implements IGRE {
|
||||
public class GREImpl implements IGRE {
|
||||
|
||||
public void initEmbedding(File aLibXULDirectory, File aAppDirectory,
|
||||
IAppFileLocProvider aAppDirProvider) {
|
||||
registerJavaXPCOMMethods(aLibXULDirectory);
|
||||
initEmbeddingNative(aLibXULDirectory, aAppDirectory, aAppDirProvider);
|
||||
}
|
||||
|
||||
|
@ -53,7 +55,7 @@ public class GREImpl extends JavaXPCOMMethods implements IGRE {
|
|||
|
||||
public native void termEmbedding();
|
||||
|
||||
public native nsISupports lockProfileDirectory(File aDirectory);
|
||||
public native ProfileLock lockProfileDirectory(File aDirectory);
|
||||
|
||||
public native void notifyProfile();
|
||||
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/* ***** 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.internal;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.mozilla.xpcom.IMozilla;
|
||||
import org.mozilla.xpcom.XPCOMInitializationException;
|
||||
|
||||
public class MozillaImpl implements IMozilla {
|
||||
|
||||
public void initialize(File aLibXULDirectory)
|
||||
throws XPCOMInitializationException {
|
||||
JavaXPCOMMethods.registerJavaXPCOMMethods(aLibXULDirectory);
|
||||
initializeNative();
|
||||
}
|
||||
|
||||
private native void initializeNative();
|
||||
|
||||
}
|
|
@ -36,15 +36,20 @@
|
|||
|
||||
package org.mozilla.xpcom.internal;
|
||||
|
||||
import java.io.*;
|
||||
import org.mozilla.xpcom.*;
|
||||
import java.io.File;
|
||||
|
||||
import org.mozilla.xpcom.IAppFileLocProvider;
|
||||
import org.mozilla.xpcom.IXPCOM;
|
||||
import org.mozilla.xpcom.nsIComponentManager;
|
||||
import org.mozilla.xpcom.nsIComponentRegistrar;
|
||||
import org.mozilla.xpcom.nsILocalFile;
|
||||
import org.mozilla.xpcom.nsIServiceManager;
|
||||
|
||||
|
||||
public class XPCOMImpl extends JavaXPCOMMethods implements IXPCOM {
|
||||
public class XPCOMImpl implements IXPCOM {
|
||||
|
||||
public nsIServiceManager initXPCOM(File aMozBinDirectory,
|
||||
IAppFileLocProvider aAppFileLocProvider) {
|
||||
registerJavaXPCOMMethods(aMozBinDirectory);
|
||||
return initXPCOMNative(aMozBinDirectory, aAppFileLocProvider);
|
||||
}
|
||||
|
||||
|
|
|
@ -37,8 +37,11 @@
|
|||
|
||||
package org.mozilla.xpcom.internal;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import org.mozilla.xpcom.*;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
import org.mozilla.xpcom.XPCOMException;
|
||||
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче