Bug 328901 - Delete moved files

git-svn-id: svn://10.0.0.236/trunk@212715 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
pedemont%us.ibm.com
2006-09-27 16:44:44 +00:00
parent ae852fc217
commit ee2255a95f
27 changed files with 0 additions and 8732 deletions

View File

@@ -1,95 +0,0 @@
/* ***** 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) 2004
* 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;
/**
* This exception is thrown whenever an internal XPCOM/Gecko error occurs.
* You can query the error ID returned by XPCOM by checking
* <code>errorcode</code> field.
*/
public class XPCOMException extends RuntimeException {
/**
* The XPCOM error value.
*/
public long errorcode;
private static final long serialVersionUID = 198521829884000593L;
/**
* Constructs a new XPCOMException instance, with a default error
* (NS_ERROR_FAILURE) and message.
*/
public XPCOMException() {
this(0x80004005L, "Unspecified internal XPCOM error");
}
/**
* Constructs a new XPCOMException instance with the given message, passing
* NS_ERROR_FAILURE as the error code.
*
* @param message detailed message of exception
*/
public XPCOMException(String message) {
this(0x80004005L, message);
}
/**
* Constructs a new XPCOMException instance with the given code, passing
* a default message.
*
* @param code internal XPCOM error ID
*/
public XPCOMException(long code) {
this(code, "Internal XPCOM error");
}
/**
* Constructs a new XPCOMException instance with an error code and message.
*
* @param code internal XPCOM error ID
* @param message detailed message of exception
*/
public XPCOMException(long code, String message) {
super(message + " (0x" + Long.toHexString(code) + ")");
this.errorcode = code;
}
}

View File

@@ -1,255 +0,0 @@
/* ***** 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) 2004
* 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.lang.reflect.*;
import org.mozilla.xpcom.*;
/**
* This class is used to pass XPCOM objects to Java functions. A
* <code>java.lang.reflect.Proxy</code> instance is created using the expected
* interface, and all calls to the proxy are forwarded to the XPCOM object.
*/
public class XPCOMJavaProxy implements InvocationHandler {
/**
* Pointer to the XPCOM object for which we are a proxy.
*/
protected long nativeXPCOMPtr;
/**
* Default constructor.
*
* @param aXPCOMInstance address of XPCOM object as a long
*/
public XPCOMJavaProxy(long aXPCOMInstance) {
nativeXPCOMPtr = aXPCOMInstance;
}
/**
* Returns the XPCOM object that the given proxy references.
*
* @param aProxy Proxy created by <code>createProxy</code>
*
* @return address of XPCOM object as a long
*/
protected static long getNativeXPCOMInstance(Object aProxy) {
XPCOMJavaProxy proxy = (XPCOMJavaProxy) Proxy.getInvocationHandler(aProxy);
return proxy.nativeXPCOMPtr;
}
/**
* Creates a Proxy for the given XPCOM object.
*
* @param aInterface interface from which to create Proxy
* @param aXPCOMInstance address of XPCOM object as a long
*
* @return Proxy of given XPCOM object
*/
protected static Object createProxy(Class aInterface, long aXPCOMInstance) {
// XXX We should really get the class loader from |aInterface|. However,
// that class loader doesn't know about |XPCOMJavaProxyBase|. So for
// now, we get the class loader that loaded |XPCOMJavaProxy|. When
// we get rid of the "XPCOMJavaProxyBase.java" class, we can revert
// to the old method below.
// return Proxy.newProxyInstance(aInterface.getClassLoader(),
return Proxy.newProxyInstance(XPCOMJavaProxy.class.getClassLoader(),
new Class[] { aInterface, XPCOMJavaProxyBase.class },
new XPCOMJavaProxy(aXPCOMInstance));
}
/**
* All calls to the Java proxy are forwarded to this method. This method
* takes care of a few of the <code>Object</code> method calls; all other
* calls are forwarded to the XPCOM object.
*
* @param aProxy Proxy created by <code>createProxy</code>
* @param aMethod object that describes the called method
* @param aParams array of the arguments passed to the method
*
* @return return value as defined by given <code>aMethod</code>
*/
public Object invoke(Object aProxy, Method aMethod, Object[] aParams)
throws Throwable {
String methodName = aMethod.getName();
// Handle the three java.lang.Object methods that are passed to us.
if (aMethod.getDeclaringClass() == Object.class) {
if (methodName.equals("hashCode")) {
return proxyHashCode(aProxy);
}
if (methodName.equals("equals")) {
return proxyEquals(aProxy, aParams[0]);
}
if (methodName.equals("toString")) {
return proxyToString(aProxy);
}
System.err.println("WARNING: Unhandled Object method [" +
methodName + "]");
return null;
}
// Handle the 'finalize' method called during garbage collection
if (aMethod.getDeclaringClass() == XPCOMJavaProxyBase.class) {
if (methodName.equals("finalize")) {
finalizeProxy(aProxy);
} else {
System.err.println("WARNING: Unhandled XPCOMJavaProxyBase method [" +
methodName + "]");
}
return null;
}
// If not already handled, pass method calls to XPCOM object.
return callXPCOMMethod(aProxy, methodName, aParams);
}
/**
* Handles method calls of <code>java.lang.Object.hashCode</code>
*
* @param aProxy Proxy created by <code>createProxy</code>
*
* @return Integer object representing hash code of given object
*
* @see Object#hashCode()
*/
protected static Integer proxyHashCode(Object aProxy) {
return new Integer(System.identityHashCode(aProxy));
}
/**
* Handles method calls of <code>java.lang.Object.equals</code>
*
* @param aProxy Proxy created by <code>createProxy</code>
* @param aOther another object
*
* @return <code>true</code> if the given objects are the same;
* <code>false</code> otherwise
*
* @see Object#equals(Object)
*/
protected static Boolean proxyEquals(Object aProxy, Object aOther) {
// See if the two are the same Java object
if (aProxy == aOther) {
return Boolean.TRUE;
} else {
// If not, then see if they represent the same XPCOM object. But first,
// we need to check if |aOther| is an XPCOMJavaProxy.
if (isXPCOMJavaProxy(aOther) && isSameXPCOMObject(aProxy, aOther)) {
return Boolean.TRUE;
}
}
return Boolean.FALSE;
}
/**
* Indicates whether the given object is an XPCOMJavaProxy.
*
* @param aObject object to check
*
* @return <code>true</code> if the given object is an XPCOMJavaProxy;
* <code>false</code> otherwise
*/
protected static boolean isXPCOMJavaProxy(Object aObject) {
if (aObject != null && Proxy.isProxyClass(aObject.getClass())) {
InvocationHandler h = Proxy.getInvocationHandler(aObject);
if (h instanceof XPCOMJavaProxy) {
return true;
}
}
return false;
}
/**
* Checks if the two given XPCOMJavaProxy objects are proxies for
* the same XPCOM object.
*
* @param aProxy1 XPCOMJavaProxy created by <code>createProxy</code>
* @param aProxy2 XPCOMJavaProxy created by <code>createProxy</code>
*
* @return <code>true</code> if both proxies represent the same XPCOM object;
* <code>false</code> otherwise
*/
protected static native boolean isSameXPCOMObject(Object aProxy1,
Object aProxy2);
/**
* Handles method calls of <code>java.lang.Object.toString</code>
*
* @param aProxy Proxy created by <code>createProxy</code>
*
* @return String representation of given object
*
* @see Object#toString()
*/
protected static String proxyToString(Object aProxy) {
return aProxy.getClass().getInterfaces()[0].getName() + '@' +
Integer.toHexString(aProxy.hashCode());
}
/**
* Called when the proxy is garbage collected by the JVM. Allows us to clean
* up any references to the XPCOM object.
*
* @param aProxy reference to Proxy that is being garbage collected
*/
protected void finalizeProxy(Object aProxy) throws Throwable {
finalizeProxyNative(aProxy);
super.finalize();
}
protected static native void finalizeProxyNative(Object aProxy);
/**
* Calls the XPCOM object referenced by the proxy with the given method.
*
* @param aProxy Proxy created by <code>createProxy</code>
* @param aMethodName name of method that we want to call
* @param aParams array of params passed to method
*
* @return return value as defined by given method
*
* @exception XPCOMException if XPCOM method failed. Values of XPCOMException
* are defined by the method called.
*/
protected static native Object callXPCOMMethod(Object aProxy,
String aMethodName, Object[] aParams);
}

View File

@@ -1,53 +0,0 @@
/* ***** 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) 2004
* 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;
/**
* This interface forms the foundation of any XPCOMJavaProxy that is created.
* It allows us to handle any JVM calls to <code>finalize</code> when the Proxy
* is garbage collected.
*/
public interface XPCOMJavaProxyBase {
/**
* @see java.lang.Object#finalize()
*/
void finalize() throws Throwable;
}

View File

@@ -1,91 +0,0 @@
/* ***** 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) 2004
* 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;
/**
* This class contains methods that are used by the JavaXPCOM proxy classes.
* They are for internal JavaXPCOM use only and should not be used by
* developers.
*/
public final class XPCOMPrivate {
public static native
void CallXPCOMMethodVoid(Object thisObj, int fnNumber, Object[] params);
public static native
boolean CallXPCOMMethodBool(Object thisObj, int fnNumber, Object[] params);
public static native
boolean[] CallXPCOMMethodBoolA(Object thisObj, int fnNumber, Object[] params);
public static native
byte CallXPCOMMethodByte(Object thisObj, int fnNumber, Object[] params);
public static native
byte[] CallXPCOMMethodByteA(Object thisObj, int fnNumber, Object[] params);
public static native
char CallXPCOMMethodChar(Object thisObj, int fnNumber, Object[] params);
public static native
char[] CallXPCOMMethodCharA(Object thisObj, int fnNumber, Object[] params);
public static native
short CallXPCOMMethodShort(Object thisObj, int fnNumber, Object[] params);
public static native
short[] CallXPCOMMethodShortA(Object thisObj, int fnNumber, Object[] params);
public static native
int CallXPCOMMethodInt(Object thisObj, int fnNumber, Object[] params);
public static native
int[] CallXPCOMMethodIntA(Object thisObj, int fnNumber, Object[] params);
public static native
long CallXPCOMMethodLong(Object thisObj, int fnNumber, Object[] params);
public static native
long[] CallXPCOMMethodLongA(Object thisObj, int fnNumber, Object[] params);
public static native
float CallXPCOMMethodFloat(Object thisObj, int fnNumber, Object[] params);
public static native
float[] CallXPCOMMethodFloatA(Object thisObj, int fnNumber, Object[] params);
public static native
double CallXPCOMMethodDouble(Object thisObj, int fnNumber, Object[] params);
public static native
double[] CallXPCOMMethodDoubleA(Object thisObj, int fnNumber, Object[] params);
public static native
Object CallXPCOMMethodObj(Object thisObj, int fnNumber, Object[] params);
public static native
Object[] CallXPCOMMethodObjA(Object thisObj, int fnNumber, Object[] params);
public static native
void FinalizeStub(Object thisObj);
}

View File

@@ -1,109 +0,0 @@
# ***** 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) 2004
# 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 *****
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
JARFILE = mozjava.jar
JARFILE_SRC = $(patsubst %.jar,%-src.jar,$(JARFILE))
GARBAGE += $(JARFILE) $(JARFILE_SRC)
GARBAGE_DIRS += _javagen org
JAVA_SRCS = \
XPCOM.java \
XPCOMJavaProxy.java \
XPCOMJavaProxyBase.java \
XPCOMException.java \
GeckoEmbed.java \
AppFileLocProvider.java \
$(NULL)
GEN_JAVA_SRCS = \
XPCOMError.java \
$(NULL)
include $(topsrcdir)/config/rules.mk
ifdef MOZ_DEBUG
JAVAC_FLAGS = -g
endif
ifeq ($(OS_ARCH),WINNT)
RUN =
OUTPUT_DIR = $(shell cygpath -w $(CURDIR)/_javagen/org/mozilla/xpcom)
else
RUN = $(DIST)/bin/run-mozilla.sh
OUTPUT_DIR = $(CURDIR)/_javagen/org/mozilla/xpcom
endif
_javagen/org/mozilla/xpcom/.iface_done:
@if test ! -d _javagen/org/mozilla/xpcom; then \
touch .done; \
$(INSTALL) -m 644 .done _javagen/org/mozilla/xpcom; \
fi
@echo Copying Java source files
@$(INSTALL) -m 644 $(addprefix $(srcdir)/../,$(JAVA_SRCS)) \
_javagen/org/mozilla/xpcom
@$(INSTALL) -m 644 $(addprefix ../,$(GEN_JAVA_SRCS)) \
_javagen/org/mozilla/xpcom
@echo Generating Java interface files
$(RUN) $(DIST)/bin/GenerateJavaInterfaces$(BIN_SUFFIX) -d $(OUTPUT_DIR)
@touch $@
# Use find and xargs for passing list of Java files to JAVAC. This avoids the
# "argument list too long" error on Windows when using *.java
org/mozilla/xpcom/.class_done: _javagen/org/mozilla/xpcom/.iface_done
@echo Compiling Java interface classes
find _javagen -name *.java | xargs $(JAVAC) $(JAVAC_FLAGS) -classpath . -d . \
-sourcepath _javagen
@touch $@
$(JARFILE): org/mozilla/xpcom/.class_done Makefile
$(JAR) cf $@ org
$(JARFILE_SRC): $(JARFILE)
$(JAR) cf $@ -C _javagen org
libs:: $(JARFILE) $(JARFILE_SRC)
$(INSTALL) $(IFLAGS1) $^ $(DIST)/bin

View File

@@ -1,163 +0,0 @@
#! /usr/bin/env perl
# ***** 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
# Michal Ceresna.
# Portions created by the Initial Developer are Copyright (C) 2005
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Michal Ceresna (ceresna@dbai.tuwien.ac.at)
# 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 *****
# Generates IXPCOMError.java from xpcom/base/nsError.h
#
# usage: perl gen-nsErrors.pl < <topsrcdir>/xpcom/base/nsError.h > IXPCOMError.java
print "/* ***** BEGIN LICENSE BLOCK *****\n";
print " * Version: MPL 1.1/GPL 2.0/LGPL 2.1\n";
print " *\n";
print " * The contents of this file are subject to the Mozilla Public License Version\n";
print " * 1.1 (the \"License\"); you may not use this file except in compliance with\n";
print " * the License. You may obtain a copy of the License at\n";
print " * http://www.mozilla.org/MPL/\n";
print " *\n";
print " * Software distributed under the License is distributed on an \"AS IS\" basis,\n";
print " * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License\n";
print " * for the specific language governing rights and limitations under the\n";
print " * License.\n";
print " *\n";
print " * The Original Code is mozilla.org code.\n";
print " *\n";
print " * The Initial Developer of the Original Code is\n";
print " * Netscape Communications Corporation.\n";
print " * Portions created by the Initial Developer are Copyright (C) 1998\n";
print " * the Initial Developer. All Rights Reserved.\n";
print " *\n";
print " * Contributor(s):\n";
print " *\n";
print " * Alternatively, the contents of this file may be used under the terms of\n";
print " * either of the GNU General Public License Version 2 or later (the \"GPL\"),\n";
print " * or the GNU Lesser General Public License Version 2.1 or later (the \"LGPL\"),\n";
print " * in which case the provisions of the GPL or the LGPL are applicable instead\n";
print " * of those above. If you wish to allow use of your version of this file only\n";
print " * under the terms of either the GPL or the LGPL, and not to allow others to\n";
print " * use your version of this file under the terms of the MPL, indicate your\n";
print " * decision by deleting the provisions above and replace them with the notice\n";
print " * and other provisions required by the GPL or the LGPL. If you do not delete\n";
print " * the provisions above, a recipient may use your version of this file under\n";
print " * the terms of any one of the MPL, the GPL or the LGPL.\n";
print " *\n";
print " * ***** END LICENSE BLOCK ***** */\n";
print "\n";
print "package org.mozilla.xpcom;\n";
print "\n\n";
print "/**\n";
print " * Mozilla XPCOM error codes.\n";
print " * <p>\n";
print " * THIS FILE GENERATED FROM mozilla/xpcom/base/nsError.h.\n";
print " * PLEASE SEE THAT FILE FOR FULL DOCUMENTATION.\n";
print " */\n";
print "public interface IXPCOMError {\n";
while (<STDIN>) {
$line = $_;
if ($prevline) {
$_ = $prevline.$_;
}
if (/(.*)\\$/) {
#splitted line
$prevline = $1;
next;
}
$prevline = "";
if (/^\s*#define\s+(NS_[A-Z_]+)\s+(0x)?([0-9a-fA-F]+)\s*$/) {
#define NS_ERROR_MODULE_XPCOM 1
#define NS_ERROR_MODULE_BASE_OFFSET 0x45
print " long $1 = $2$3L;\n";
}
elsif (/^\s*#define\s+(NS_[A-Z_]+)\s+\((NS_[A-Z_]+)\s+\+\s+(0x)?([0-9a-fA-F]+)\s*\)\s*/) {
#define NS_ERROR_NOT_INITIALIZED (NS_ERROR_BASE + 1)
#define NS_ERROR_FACTORY_EXISTS (NS_ERROR_BASE + 0x100)
print " long $1 = $2 + $3$4L;\n";
}
elsif (/^\s*#define\s+(NS_[A-Z_]+)\s+(NS_[A-Z_]+)\s\s*/) {
#define NS_ERROR_NO_INTERFACE NS_NOINTERFACE
print " long $1 = $2;\n";
}
elsif (/^\s*#define\s+(NS_[A-Z_]+)\s+\(\(nsresult\)\s*(0x)?([0-9a-fA-F]+)L?\)\s*$/) {
#define NS_ERROR_BASE ((nsresult) 0xC1F30000)
#define NS_ERROR_ABORT ((nsresult) 0x80004004L)
print " long $1 = $2$3L;\n";
}
elsif (/^\s*#define\s+(NS_[A-Z_]+)\s+NS_ERROR_GENERATE_FAILURE\s*\(\s*(NS_[A-Z_]+)\s*,\s*([0-9]+)\s*\)\s*$/) {
#define NS_BASE_STREAM_CLOSED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 2)
$module = $2;
$code = $3;
print " long $1 = ((NS_ERROR_SEVERITY_ERROR<<31) |\n";
print " (($module+NS_ERROR_MODULE_BASE_OFFSET)<<16) | $code);\n";
}
elsif (/^\s*#define\s+(NS_[A-Z_]+)\s+NS_ERROR_GENERATE_SUCCESS\s*\(\s*(NS_[A-Z_]+)\s*,\s*([0-9]+)\s*\)\s*$/) {
#define NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_XPCOM, 1)
$module = $2;
$code = $3;
print " long $1 = ((NS_ERROR_SEVERITY_SUCCESS<<31) |\n";
print " (($module+NS_ERROR_MODULE_BASE_OFFSET)<<16) | $code);\n";
}
elsif (/^\s*\/\*(.*)\*\/\s*$/ && !/^\s*\/\*@[\{\}]\*\/\s*$/ &&
!/^\s*\/\*\ -\*- Mode:/) {
#single line comment, but not
#/*@{*/, /*@}*/,
#/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
print " /*$1*/\n";
}
elsif (/^\s*$/) {
#empty line, but write only the first
#line from a sequence of empty lines
if (!$wasEmpty) {
print "\n";
}
$wasEmpty = 1;
next;
}
else {
next;
}
$wasEmpty = 0;
}
print "}\n";

View File

@@ -1,80 +0,0 @@
/* ***** 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) 2005
* 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 GREVersionRange {
private String lower;
private boolean lowerInclusive;
private String upper;
private boolean upperInclusive;
public GREVersionRange(String aLower, boolean aLowerInclusive,
String aUpper, boolean aUpperInclusive) {
lower = aLower;
lowerInclusive = aLowerInclusive;
upper = aUpper;
upperInclusive = aUpperInclusive;
}
public boolean check(String aVersion) {
VersionComparator comparator = new VersionComparator();
int c = comparator.compare(aVersion, lower);
if (c < 0) {
return false;
}
if (c == 0 && !lowerInclusive) {
return false;
}
c = comparator.compare(aVersion, upper);
if (c > 0) {
return false;
}
if (c == 0 && !upperInclusive) {
return false;
}
return true;
}
}

View File

@@ -1,92 +0,0 @@
/* ***** 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) 2004
* 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.*;
/**
* Used by XPCOM's Directory Service to get file locations.
* <p>
* This interface is similar to <code>nsIDirectoryServiceProvider</code> and
* <code>nsIDirectoryServiceProvider2</code>, except that its methods use
* <code>java.io.File</code> instead of <code>nsIFile</code>.
* </p>
*
* @see Mozilla#initEmbedding
* @see Mozilla#initXPCOM
* @see <a href=
* "http://lxr.mozilla.org/mozilla/source/xpcom/io/nsIDirectoryService.idl">
* nsIDirectoryServiceProvider </a>
* @see <a href=
* "http://lxr.mozilla.org/mozilla/source/xpcom/io/nsDirectoryServiceDefs.h">
* Directory Service property names </a>
*/
public interface IAppFileLocProvider {
/**
* Directory Service calls this when it gets the first request for
* a property or on every request if the property is not persistent.
*
* @param prop the symbolic name of the file
* @param persistent an array of length one used to supply the output value:
* <ul>
* <li><code>true</code> - The returned file will be
* cached by Directory Service. Subsequent requests for
* this prop will bypass the provider and use the cache.
* </li>
* <li><code>false</code> - The provider will be asked
* for this prop each time it is requested. </li>
* </ul>
*
* @return the file represented by the property
*/
File getFile(String prop, boolean[] persistent);
/**
* Directory Service calls this when it gets a request for
* a property and the requested type is nsISimpleEnumerator.
*
* @param prop the symbolic name of the file list
*
* @return an array of file locations
*/
File[] getFiles(String prop);
}

View File

@@ -1,127 +0,0 @@
/* ***** 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) 2004
* 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.*;
public interface IGRE {
/**
* Initializes libXUL for embedding purposes.
* <p>
* NOTE: This function must be called from the "main" thread.
* <p>
* NOTE: At the present time, this function may only be called once in
* a given process. Use <code>termEmbedding</code> to clean up and free
* resources allocated by <code>initEmbedding</code>.
*
* @param aLibXULDirectory The directory in which the libXUL shared library
* was found.
* @param aAppDirectory The directory in which the application components
* and resources can be found. This will map to
* the "resource:app" directory service key.
* @param aAppDirProvider A directory provider for the application. This
* provider will be aggregated by a libXUL provider
* which will provide the base required GRE keys.
*
* @throws XPCOMException if a failure occurred during initialization
*/
void initEmbedding(File aLibXULDirectory, File aAppDirectory,
IAppFileLocProvider aAppDirProvider) throws XPCOMException;
/**
* Terminates libXUL embedding.
* <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;
/**
* 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

@@ -1,235 +0,0 @@
/* ***** 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) 2005
* 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.*;
import java.nio.charset.Charset;
import java.util.*;
/**
* A simple parser for INI files.
*/
public class INIParser {
private HashMap mSections;
/**
* Creates a new <code>INIParser</code> instance from the INI file at the
* given path. <code>aCharset</code> specifies the character encoding of
* the file.
*
* @param aFilename path of INI file to parse
* @param aCharset character encoding of file
* @throws FileNotFoundException if <code>aFilename</code> does not exist.
* @throws IOException if there is a problem reading the given file.
*/
public INIParser(String aFilename, Charset aCharset)
throws FileNotFoundException, IOException {
initFromFile(new File(aFilename), aCharset);
}
/**
* Creates a new <code>INIParser</code> instance from the INI file at the
* given path, which is assumed to be in the <code>UTF-8</code> charset.
*
* @param aFilename path of INI file to parse
* @throws FileNotFoundException if <code>aFilename</code> does not exist.
* @throws IOException if there is a problem reading the given file.
*/
public INIParser(String aFilename) throws FileNotFoundException, IOException {
initFromFile(new File(aFilename), Charset.forName("UTF-8"));
}
/**
* Creates a new <code>INIParser</code> instance from the given file.
* <code>aCharset</code> specifies the character encoding of the file.
*
* @param aFile INI file to parse
* @param aCharset character encoding of file
* @throws FileNotFoundException if <code>aFile</code> does not exist.
* @throws IOException if there is a problem reading the given file.
*/
public INIParser(File aFile, Charset aCharset)
throws FileNotFoundException, IOException {
initFromFile(aFile, aCharset);
}
/**
* Creates a new <code>INIParser</code> instance from the given file,
* which is assumed to be in the <code>UTF-8</code> charset.
*
* @param aFile INI file to parse
* @throws FileNotFoundException if <code>aFile</code> does not exist.
* @throws IOException if there is a problem reading the given file.
*/
public INIParser(File aFile) throws FileNotFoundException, IOException {
initFromFile(aFile, Charset.forName("UTF-8"));
}
/**
* Parses given INI file.
*
* @param aFile INI file to parse
* @param aCharset character encoding of file
* @throws FileNotFoundException if <code>aFile</code> does not exist.
* @throws IOException if there is a problem reading the given file.
*/
private void initFromFile(File aFile, Charset aCharset)
throws FileNotFoundException, IOException {
FileInputStream fileStream = new FileInputStream(aFile);
InputStreamReader inStream = new InputStreamReader(fileStream, aCharset);
BufferedReader reader = new BufferedReader(inStream);
mSections = new HashMap();
String currSection = null;
String line;
while ((line = reader.readLine()) != null) {
// skip empty lines and comment lines
String trimmedLine = line.trim();
if (trimmedLine.length() == 0 || trimmedLine.startsWith("#")
|| trimmedLine.startsWith(";")) {
continue;
}
// Look for section headers (i.e. "[Section]").
if (line.startsWith("[")) {
/*
* We are looking for a well-formed "[Section]". If this header is
* malformed (i.e. "[Section" or "[Section]Moretext"), just skip it
* and go on to next well-formed section header.
*/
if (!trimmedLine.endsWith("]") ||
trimmedLine.indexOf("]") != (trimmedLine.length() - 1)) {
currSection = null;
continue;
}
// remove enclosing brackets
currSection = trimmedLine.substring(1, trimmedLine.length() - 1);
continue;
}
// If we haven't found a valid section header, continue to next line
if (currSection == null) {
continue;
}
StringTokenizer tok = new StringTokenizer(line, "=");
if (tok.countTokens() != 2) { // looking for value pairs
continue;
}
Properties props = (Properties) mSections.get(currSection);
if (props == null) {
props = new Properties();
mSections.put(currSection, props);
}
props.setProperty(tok.nextToken(), tok.nextToken());
}
reader.close();
}
/**
* Returns an iterator over the section names available in the INI file.
*
* @return an iterator over the section names
*/
public Iterator getSections() {
return mSections.keySet().iterator();
}
/**
* Returns an iterator over the keys available within a section.
*
* @param aSection section name whose keys are to be returned
* @return an iterator over section keys, or <code>null</code> if no
* such section exists
*/
public Iterator getKeys(String aSection) {
/*
* Simple wrapper class to convert Enumeration to Iterator
*/
class PropertiesIterator implements Iterator {
private Enumeration e;
public PropertiesIterator(Enumeration aEnum) {
e = aEnum;
}
public boolean hasNext() {
return e.hasMoreElements();
}
public Object next() {
return e.nextElement();
}
public void remove() {
return;
}
}
Properties props = (Properties) mSections.get(aSection);
if (props == null) {
return null;
}
return new PropertiesIterator(props.propertyNames());
}
/**
* Gets the string value for a particular section and key.
*
* @param aSection a section name
* @param aKey the key whose value is to be returned.
* @return string value of particular section and key
*/
public String getString(String aSection, String aKey) {
Properties props = (Properties) mSections.get(aSection);
if (props == null) {
return null;
}
return props.getProperty(aKey);
}
}

View File

@@ -1,131 +0,0 @@
/* ***** 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) 2004
* 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.*;
public interface IXPCOM {
/**
* Initializes XPCOM. You must call this method before proceeding
* to use XPCOM.
*
* @param aMozBinDirectory The directory containing the component
* registry and runtime libraries;
* or use <code>null</code> to use the working
* directory.
*
* @param aAppFileLocProvider The object to be used by Gecko that specifies
* to Gecko where to find profiles, the component
* registry preferences and so on; or use
* <code>null</code> for the default behaviour.
*
* @return the service manager
*
* @exception 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>
*/
nsIServiceManager initXPCOM(File aMozBinDirectory,
IAppFileLocProvider aAppFileLocProvider) throws XPCOMException;
/**
* Shutdown XPCOM. You must call this method after you are finished
* using xpcom.
*
* @param aServMgr The service manager which was returned by initXPCOM.
* This will release servMgr.
*
* @exception XPCOMException if a failure occurred during termination
*/
void shutdownXPCOM(nsIServiceManager aServMgr) throws XPCOMException;
/**
* Public Method to access to the service manager.
*
* @return the service manager
*
* @exception XPCOMException
*/
nsIServiceManager getServiceManager() throws XPCOMException;
/**
* Public Method to access to the component manager.
*
* @return the component manager
*
* @exception XPCOMException
*/
nsIComponentManager getComponentManager() throws XPCOMException;
/**
* Public Method to access to the component registration manager.
*
* @return the component registration manager
*
* @exception XPCOMException
*/
nsIComponentRegistrar getComponentRegistrar() throws XPCOMException;
/**
* Public Method to create an instance of a nsILocalFile.
*
* @param aPath A string which specifies a full file path to a
* location. Relative paths will be treated as an
* error (NS_ERROR_FILE_UNRECOGNIZED_PATH).
* @param aFollowLinks This attribute will determine if the nsLocalFile will
* auto resolve symbolic links. By default, this value
* will be false on all non unix systems. On unix, this
* attribute is effectively a noop.
*
* @return an instance of an nsILocalFile that points to given path
*
* @exception XPCOMException <ul>
* <li> NS_ERROR_FILE_UNRECOGNIZED_PATH - raised for unrecognized paths
* or relative paths (must supply full file path) </li>
* </ul>
*/
nsILocalFile newLocalFile(String aPath, boolean aFollowLinks)
throws XPCOMException;
}

View File

@@ -1,903 +0,0 @@
/* ***** 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) 2005
* 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.*;
import java.lang.reflect.*;
import java.net.*;
import java.nio.charset.Charset;
import java.util.*;
/**
* @see http://www.mozilla.org/projects/embedding/GRE.html
*/
public class Mozilla implements IGRE, IXPCOM, IXPCOMError {
private static Mozilla mozillaInstance = new Mozilla();
private static final String JAVAXPCOM_JAR = "javaxpcom.jar";
private IGRE gre = null;
private IXPCOM xpcom = null;
/**
* @return
*/
public static Mozilla getInstance() {
return mozillaInstance;
}
/**
*
*/
private Mozilla() {
}
/**
* Locates the path of a GRE with the specified properties. This method
* will only return GREs that support Java embedding (looks for the
* presence of "javaxpcom.jar").
* <p>
* Currently this uses a "first-fit" algorithm, it does not select
* the newest available GRE.
*
* @param aVersions An array of version ranges: if any version range
* matches, the GRE is considered acceptable.
* @param aProperties A list of GRE property/value pairs which must
* all be satisfied. This parameter is ignored on
* Macintosh, because of the manner in which the
* XUL frameworks are installed.
*
* @return A file object of the appropriate path. If
* the "local" GRE is specified (via the USE_LOCAL_GRE
* environment variable, for example), returns
* <code>null</code>.
*
* @throws FileNotFoundException if an appropriate GRE could not be found
*/
public static File getGREPathWithProperties(GREVersionRange[] aVersions,
Properties aProperties) throws FileNotFoundException {
File grePath = null;
// if GRE_HOME is in the environment, use that GRE
String env = System.getProperty("GRE_HOME");
if (env != null) {
try {
grePath = new File(env).getCanonicalFile();
} catch (IOException e) {
throw new FileNotFoundException("cannot access GRE_HOME");
}
if (!grePath.exists()) {
throw new FileNotFoundException("GRE_HOME doesn't exist");
}
return grePath;
}
// the Gecko bits that sit next to the application or in the PATH
env = System.getProperty("USE_LOCAL_GRE");
if (env != null) {
return null;
}
// Search for GRE in platform specific locations. We want a GRE that
// supports Java, so we look for the "javaxpcom" property by default.
if (aProperties == null) {
aProperties = new Properties();
}
aProperties.setProperty("javaxpcom", "1");
String osName = System.getProperty("os.name").toLowerCase();
if (osName.startsWith("mac os x")) {
grePath = getGREPathMacOSX(aVersions);
} else if (osName.startsWith("windows")) {
grePath = getGREPathWindows(aVersions, aProperties);
} else {
// assume everything else is Unix/Linux
grePath = getGREPathUnix(aVersions, aProperties);
}
if (grePath == null) {
throw new FileNotFoundException("GRE not found");
}
return grePath;
}
/**
* @param aVersions
* @return
*/
private static File getGREPathMacOSX(GREVersionRange[] aVersions) {
/*
* Check the application bundle first, for
* <bundle>/Contents/Frameworks/XUL.framework/libxpcom.dylib.
*/
File grePath = findGREBundleFramework();
if (grePath != null) {
return grePath;
}
// Check ~/Library/Frameworks/XUL.framework/Versions/<version>/libxpcom.dylib
String home = System.getProperty("user.home");
if (home != null) {
grePath = findGREFramework(home, aVersions);
if (grePath != null) {
return grePath;
}
}
// Check /Library/Frameworks/XUL.framework/Versions/<version>/libxpcom.dylib
return findGREFramework("", aVersions);
}
/**
* @return
*/
private static File findGREBundleFramework() {
/*
* Use reflection to get Apple's NSBundle class, which can be used
* to get the bundle's "Frameworks" directory.
*/
try {
URL[] urls = new URL[1];
urls[0] = new File("/System/Library/Java/").toURL();
ClassLoader loader = new URLClassLoader(urls);
Class bundleClass = Class.forName("com.apple.cocoa.foundation.NSBundle",
true, loader);
// Get the bundle for this app. If this is not executing from
// a bundle, this will return null.
Method mainBundleMethod = bundleClass.getMethod("mainBundle", null);
Object bundle = mainBundleMethod.invoke(null, null);
if (bundle != null) {
// Get the path to the bundle's "Frameworks" directory
Method fwPathMethod = bundleClass.getMethod("privateFrameworksPath",
null);
String path = (String) fwPathMethod.invoke(bundle, null);
// look for libxpcom.dylib
if (path.length() != 0) {
File xulDir = new File(path, "XUL.framework");
if (xulDir.isDirectory()) {
File xpcomLib = new File(xulDir, "libxpcom.dylib");
if (xpcomLib.canRead()) {
File grePath = xpcomLib.getCanonicalFile().getParentFile();
// Since GRE Properties aren't supported on Mac OS X, we check
// for the existence of the "javaxpcom.jar" file in the GRE.
File jar = new File(grePath, JAVAXPCOM_JAR);
if (jar.canRead()) {
// found GRE
return grePath;
}
}
}
}
}
} catch (Exception e) { }
return null;
}
/**
* @param aRootPath
* @param aVersions
* @return
*/
private static File findGREFramework(String aRootPath,
GREVersionRange[] aVersions) {
File frameworkDir = new File(aRootPath +
"/Library/Frameworks/XUL.framework/Versions");
if (!frameworkDir.exists())
return null;
File[] files = frameworkDir.listFiles();
for (int i = 0; i < files.length; i++) {
if (checkVersion(files[i].getName(), aVersions)) {
File xpcomLib = new File(files[i], "libxpcom.dylib");
// Since GRE Properties aren't supported on Mac OS X, we check
// for the existence of the "javaxpcom.jar" file in the GRE.
File jar = new File(files[i], JAVAXPCOM_JAR);
if (xpcomLib.canRead() && jar.canRead()) {
return files[i];
}
}
}
return null;
}
/**
* @param aVersions
* @param aProperties
* @return
*/
private static File getGREPathWindows(GREVersionRange[] aVersions,
Properties aProperties) {
/*
* Note the usage of the "Software\\mozilla.org\\GRE" subkey - this allows
* us to have multiple versions of GREs on the same machine by having
* subkeys such as 1.0, 1.1, 2.0 etc. under it.
*
* Please see http://www.mozilla.org/projects/embedding/GRE.html for
* more info.
*/
final String greKey = "Software\\mozilla.org\\GRE";
// See if there is a GRE registered for the current user.
// If not, look for one on the system.
String key = "HKEY_CURRENT_USER" + "\\" + greKey;
File grePath = getGREPathFromRegKey(key, aVersions, aProperties);
if (grePath == null) {
key = "HKEY_LOCAL_MACHINE" + "\\" + greKey;
grePath = getGREPathFromRegKey(key, aVersions, aProperties);
}
return grePath;
}
/**
* @param aRegKey
* @param aVersions
* @param aProperties
* @return
*/
private static File getGREPathFromRegKey(String aRegKey,
GREVersionRange[] aVersions, Properties aProperties) {
// create a temp file for the registry export
File tempFile;
try {
tempFile = File.createTempFile("jx_registry", null);
} catch (IOException e) {
// failed to create temp file. ABORT
return null;
}
Process proc;
try {
proc = Runtime.getRuntime().exec("regedit /e " + "\"" + tempFile.getPath()
+ "\" \"" + aRegKey + "\"");
proc.waitFor();
} catch (Exception e) {
// Failed to run regedit.exe. Length of temp file is zero, and that's
// handled next.
}
// If there is a key by that name in the registry, then the file length
// will not be zero.
File grePath = null;
if (tempFile.length() != 0) {
grePath = getGREPathFromRegistryFile(tempFile.getPath(),
aRegKey, aVersions, aProperties);
}
tempFile.delete();
return grePath;
}
/**
* @param aFileName
* @param aCharset
* @param aKeyName
* @param aVersions
* @param aProperties
* @return
*/
private static File getGREPathFromRegistryFile(String aFileName,
String aKeyName, GREVersionRange[] aVersions,
Properties aProperties) {
INIParser parser;
try {
parser = new INIParser(aFileName, Charset.forName("UTF-16"));
} catch (Exception e) {
// Problem reading from file. Bail out.
return null;
}
Iterator sectionsIter = parser.getSections();
while (sectionsIter.hasNext()) {
// get 'section' name, which will be a registry key name
String section = (String) sectionsIter.next();
// Skip over GRE key ("<root>\Software\mozilla.org\GRE")
int gre_len = aKeyName.length();
if (section.length() <= gre_len) {
continue;
}
// Get the GRE subkey; that is, everything after
// "<root>\Software\mozilla.org\GRE\"
String subkeyName = section.substring(gre_len + 1);
// We are only interested in _immediate_ subkeys. We want
// "<root>\Software\mozilla.org\GRE\<version>" but not
// "<root>\Software\mozilla.org\GRE\<version>\<moretext>".
if (subkeyName.indexOf('\\') != -1) {
continue;
}
// See if this registry key has a "Version" value, and if so, compare
// it to our desired versions.
String version = parser.getString(section, "\"Version\"");
if (version == null) {
continue;
}
// remove quotes around string
version = version.substring(1, version.length() - 1);
if (!checkVersion(version, aVersions)) {
continue;
}
// All properties must match, keeping in mind that the propery/value
// pairs returned by regedit.exe have quotes around them.
if (aProperties != null) {
boolean ok = true;
Enumeration e = aProperties.propertyNames();
while (ok && e.hasMoreElements()) {
String prop = (String) e.nextElement();
String greValue = parser.getString(section, "\"" + prop + "\"");
if (greValue == null) {
// No such property is set for this GRE. Go on to next GRE.
ok = false;
} else {
// See if the value of the property for the GRE matches
// the given value.
String value = aProperties.getProperty(prop);
if (!greValue.equals("\"" + value + "\"")) {
ok = false;
}
}
}
if (!ok) {
continue;
}
}
String pathStr = parser.getString(section, "\"GreHome\"");
if (pathStr != null) {
// remove quotes around string
pathStr = pathStr.substring(1, pathStr.length() - 1);
File grePath = new File(pathStr);
if (grePath.exists()) {
File xpcomLib = new File(grePath, "xpcom.dll");
if (xpcomLib.canRead()) {
// found a good GRE
return grePath;
}
}
}
}
return null;
}
/**
* @param aVersions
* @param aProperties
* @return
*/
private static File getGREPathUnix(GREVersionRange[] aVersions,
Properties aProperties) {
File grePath = null;
String env = System.getProperty("MOZ_GRE_CONF");
if (env != null) {
grePath = getPathFromConfigFile(env, aVersions, aProperties);
if (grePath != null) {
return grePath;
}
}
final String greUserConfFile = ".gre.config";
final String greUserConfDir = ".gre.d";
final String greConfPath = "/etc/gre.conf";
final String greConfDir = "/etc/gre.d";
env = System.getProperty("user.home");
if (env != null) {
// Look in ~/.gre.config
grePath = getPathFromConfigFile(env + File.separator + greUserConfFile,
aVersions, aProperties);
if (grePath != null) {
return grePath;
}
// Look in ~/.gre.d/*.conf
grePath = getPathFromConfigDir(env + File.separator + greUserConfDir,
aVersions, aProperties);
if (grePath != null) {
return grePath;
}
}
// Look for a global /etc/gre.conf file
grePath = getPathFromConfigFile(greConfPath, aVersions, aProperties);
if (grePath != null) {
return grePath;
}
// Look for a group of config files in /etc/gre.d/
grePath = getPathFromConfigDir(greConfDir, aVersions, aProperties);
return grePath;
}
/**
* @param aFileName
* @param aVersions
* @param aProperties
* @return
*/
private static File getPathFromConfigFile(String aFileName,
GREVersionRange[] aVersions, Properties aProperties) {
INIParser parser;
try {
parser = new INIParser(aFileName);
} catch (Exception e) {
// Problem reading from file. Bail out.
return null;
}
Iterator sectionsIter = parser.getSections();
while (sectionsIter.hasNext()) {
// get 'section' name, which will be a version string
String section = (String) sectionsIter.next();
// if this isn't one of the versions we are looking for, move
// on to next section
if (!checkVersion(section, aVersions)) {
continue;
}
// all properties must match
if (aProperties != null) {
boolean ok = true;
Enumeration e = aProperties.propertyNames();
while (ok && e.hasMoreElements()) {
String prop = (String) e.nextElement();
String greValue = parser.getString(section, prop);
if (greValue == null) {
// No such property is set for this GRE. Go on to next GRE.
ok = false;
} else {
// See if the value of the property for the GRE matches
// the given value.
if (!greValue.equals(aProperties.getProperty(prop))) {
ok = false;
}
}
}
if (!ok) {
continue;
}
}
String pathStr = parser.getString(section, "GRE_PATH");
if (pathStr != null) {
File grePath = new File(pathStr);
if (grePath.exists()) {
File xpcomLib = new File(grePath, "libxpcom.so");
if (xpcomLib.canRead()) {
// found a good GRE
return grePath;
}
}
}
}
return null;
}
/**
* @param aDirName
* @param aVersions
* @param aProperties
* @return
*/
private static File getPathFromConfigDir(String aDirName,
GREVersionRange[] aVersions, Properties aProperties) {
/*
* Open the directory provided and try to read any files in that
* directory that end with .conf. We look for an entry that might
* point to the GRE that we're interested in.
*/
File dir = new File(aDirName);
if (!dir.isDirectory()) {
return null;
}
File grePath = null;
File[] files = dir.listFiles();
for (int i = 0; i < files.length && grePath == null; i++) {
// only look for files that end in '.conf'
if (!files[i].getName().endsWith(".conf")) {
continue;
}
grePath = getPathFromConfigFile(files[i].getPath(), aVersions,
aProperties);
}
return grePath;
}
/**
* @param aVersionToCheck
* @param aVersions
* @return
*/
private static boolean checkVersion(String aVersionToCheck,
GREVersionRange[] aVersions) {
for (int i = 0; i < aVersions.length; i++) {
if (aVersions[i].check(aVersionToCheck)) {
return true;
}
}
return false;
}
/**
* Initializes libXUL for embedding purposes.
* <p>
* NOTE: This function must be called from the "main" thread.
* <p>
* NOTE: At the present time, this function may only be called once in
* a given process. Use <code>termEmbedding</code> to clean up and free
* resources allocated by <code>initEmbedding</code>.
*
* @param aLibXULDirectory The directory in which the libXUL shared library
* was found.
* @param aAppDirectory The directory in which the application components
* and resources can be found. This will map to
* the "resource:app" directory service key.
* @param aAppDirProvider A directory provider for the application. This
* 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
*/
public void initEmbedding(File aLibXULDirectory, File aAppDirectory,
IAppFileLocProvider aAppDirProvider) throws XPCOMException {
loadJavaXPCOM(aLibXULDirectory, true);
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.*");
}
}
/**
* Terminates libXUL embedding.
* <p>
* NOTE: Release any references to XPCOM objects that you may be holding
* before calling this function.
*/
public void termEmbedding() throws XPCOMException {
try {
gre.termEmbedding();
} catch (NullPointerException e) {
throw new XPCOMException(Mozilla.NS_ERROR_NULL_POINTER,
"Attempt to use unitialized GRE object");
} finally {
gre = null;
xpcom = null;
}
}
/**
* Initializes XPCOM. You must call this method before proceeding
* to use XPCOM.
*
* @param aMozBinDirectory The directory containing the component
* registry and runtime libraries;
* or use <code>null</code> to use the working
* directory.
*
* @param aAppFileLocProvider The object to be used by Gecko that specifies
* to Gecko where to find profiles, the component
* registry preferences and so on; or use
* <code>null</code> for the default behaviour.
*
* @return the service manager
*
* @exception 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>
*/
public nsIServiceManager initXPCOM(File aMozBinDirectory,
IAppFileLocProvider aAppFileLocProvider) throws XPCOMException {
loadJavaXPCOM(aMozBinDirectory, false);
return xpcom.initXPCOM(aMozBinDirectory, aAppFileLocProvider);
}
/**
* Shutdown XPCOM. You must call this method after you are finished
* using xpcom.
*
* @param aServMgr The service manager which was returned by initXPCOM.
* This will release servMgr.
*
* @exception XPCOMException if a failure occurred during termination
*/
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");
} finally {
xpcom = null;
}
}
/**
* Public Method to access to the service manager.
*
* @return the service manager
*
* @exception XPCOMException
*/
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");
}
}
/**
* Public Method to access to the component manager.
*
* @return the component manager
*
* @exception XPCOMException
*/
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");
}
}
/**
* Public Method to access to the component registration manager.
*
* @return the component registration manager
*
* @exception XPCOMException
*/
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");
}
}
/**
* Public Method to create an instance of a nsILocalFile.
*
* @param aPath A string which specifies a full file path to a
* location. Relative paths will be treated as an
* error (NS_ERROR_FILE_UNRECOGNIZED_PATH).
* @param aFollowLinks This attribute will determine if the nsLocalFile will
* auto resolve symbolic links. By default, this value
* will be false on all non unix systems. On unix, this
* attribute is effectively a noop.
*
* @return an instance of an nsILocalFile that points to given path
*
* @exception XPCOMException <ul>
* <li> NS_ERROR_FILE_UNRECOGNIZED_PATH - raised for unrecognized paths
* or relative paths (must supply full file path) </li>
* </ul>
*/
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");
}
}
/**
* If you create a class that implements nsISupports, you will need to provide
* an implementation of the <code>queryInterface</code> method. This helper
* function provides a simple implementation. Therefore, if your class does
* not need to do anything special with <code>queryInterface</code>, your
* implementation would look like:
* <pre>
* public nsISupports queryInterface(String aIID) {
* return XPCOM.queryInterface(this, aIID);
* }
* </pre>
*
* @param aObject object to query
* @param aIID requested interface IID
*
* @return <code>aObject</code> if the given object supports that
* interface;
* <code>null</code> otherwise.
*/
public static nsISupports queryInterface(nsISupports aObject, String aIID) {
ArrayList classes = new ArrayList();
classes.add(aObject.getClass());
while (!classes.isEmpty()) {
Class clazz = (Class) classes.remove(0);
// Skip over any class/interface in the "java.*" and "javax.*" domains.
String className = clazz.getName();
if (className.startsWith("java.") || className.startsWith("javax.")) {
continue;
}
// If given IID matches that of the current interface, then we
// know that aObject implements the interface specified by the given IID.
if (clazz.isInterface() && className.startsWith("org.mozilla")) {
String iid = Mozilla.getInterfaceIID(clazz);
if (iid != null && aIID.equals(iid)) {
return aObject;
}
}
// clazz didn't match, so add the interfaces it implements
Class[] interfaces = clazz.getInterfaces();
for (int i = 0; i < interfaces.length; i++ ) {
classes.add(interfaces[i]);
}
// Also add its superclass
Class superclass = clazz.getSuperclass();
if (superclass != null) {
classes.add(superclass);
}
}
return null;
}
/**
* Gets the interface IID for a particular Java interface. This is similar
* to NS_GET_IID in the C++ Mozilla files.
*
* @param aInterface interface which has defined an IID
*
* @return IID for given interface
*/
public static String getInterfaceIID(Class aInterface) {
// Get short class name (i.e. "bar", not "org.blah.foo.bar")
StringBuffer iidName = new StringBuffer();
String fullClassName = aInterface.getName();
int index = fullClassName.lastIndexOf(".");
String className = index > 0 ? fullClassName.substring(index + 1)
: fullClassName;
// Create iid field name
if (className.startsWith("ns")) {
iidName.append("NS_");
iidName.append(className.substring(2).toUpperCase());
} else {
iidName.append(className.toUpperCase());
}
iidName.append("_IID");
String iid;
try {
Field iidField = aInterface.getDeclaredField(iidName.toString());
iid = (String) iidField.get(null);
} catch (NoSuchFieldException e) {
// Class may implement non-Mozilla interfaces, which would not have an
// IID method. In that case, just null.
iid = null;
} catch (IllegalAccessException e) {
// Not allowed to access that field for some reason. Write out an
// error message, but don't fail.
System.err.println("ERROR: Could not get field " + iidName.toString());
iid = null;
}
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

@@ -1,269 +0,0 @@
/* ***** 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) 2005
* 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.util.*;
/**
* Version strings are dot-separated sequences of version-parts.
* <p>
* A version-part consists of up to four parts, all of which are optional:
* <br><code>
* &lt;number-a&gt;&lt;string-b&gt;&lt;number-c&gt;
* &lt;string-d (everything else)&gt;
* </code> <p>
* A version-part may also consist of a single asterisk "*" which indicates
* "infinity".
* <p>
* Numbers are base-10, and are zero if left out.
* Strings are compared bytewise.
* <p>
* For additional backwards compatibility, if "string-b" is "+" then
* "number-a" is incremented by 1 and "string-b" becomes "pre".
* <p> <pre>
* 1.0pre1
* < 1.0pre2
* < 1.0 == 1.0.0 == 1.0.0.0
* < 1.1pre == 1.1pre0 == 1.0+
* < 1.1pre1a
* < 1.1pre1
* < 1.1pre10a
* < 1.1pre10
* </pre>
* Although not required by this interface, it is recommended that
* numbers remain within the limits of a signed char, i.e. -127 to 128.
*/
public class VersionComparator implements nsIVersionComparator {
public nsISupports queryInterface(String aIID) {
return Mozilla.queryInterface(this, aIID);
}
/**
* Compare two version strings
* @param A a version string
* @param B a version string
* @return a value less than 0 if A < B;
* the value 0 if A == B;
* or a value greater than 0 if A > B
*/
public int compare(String A, String B) {
int result;
String a = A, b = B;
do {
VersionPart va = new VersionPart();
VersionPart vb = new VersionPart();
a = parseVersionPart(a, va);
b = parseVersionPart(b, vb);
result = compareVersionPart(va, vb);
if (result != 0) {
break;
}
} while (a != null || b != null);
return result;
}
private class VersionPart {
int numA = 0;
String strB;
int numC = 0;
String extraD;
}
private static String parseVersionPart(String aVersion, VersionPart result) {
if (aVersion == null || aVersion.length() == 0) {
return aVersion;
}
StringTokenizer tok = new StringTokenizer(aVersion.trim(), ".");
String part = tok.nextToken();
if (part.equals("*")) {
result.numA = Integer.MAX_VALUE;
result.strB = "";
} else {
VersionPartTokenizer vertok = new VersionPartTokenizer(part);
try {
result.numA = Integer.parseInt(vertok.nextToken());
} catch (NumberFormatException e) {
// parsing error; default to zero like 'strtol' C function
result.numA = 0;
}
if (vertok.hasMoreElements()) {
String str = vertok.nextToken();
// if part is of type "<num>+"
if (str.charAt(0) == '+') {
result.numA++;
result.strB = "pre";
} else {
// else if part is of type "<num><alpha>..."
result.strB = str;
if (vertok.hasMoreTokens()) {
try {
result.numC = Integer.parseInt(vertok.nextToken());
} catch (NumberFormatException e) {
// parsing error; default to zero like 'strtol' C function
result.numC = 0;
}
if (vertok.hasMoreTokens()) {
result.extraD = vertok.getRemainder();
}
}
}
}
}
if (tok.hasMoreTokens()) {
// return everything after "."
return aVersion.substring(part.length() + 1);
}
return null;
}
private int compareVersionPart(VersionPart va, VersionPart vb) {
int res = compareInt(va.numA, vb.numA);
if (res != 0) {
return res;
}
res = compareString(va.strB, vb.strB);
if (res != 0) {
return res;
}
res = compareInt(va.numC, vb.numC);
if (res != 0) {
return res;
}
return compareString(va.extraD, vb.extraD);
}
private int compareInt(int n1, int n2) {
return n1 - n2;
}
private int compareString(String str1, String str2) {
// any string is *before* no string
if (str1 == null) {
return (str2 != null) ? 1 : 0;
}
if (str2 == null) {
return -1;
}
return str1.compareTo(str2);
}
}
/**
* Specialized tokenizer for Mozilla version strings. A token can
* consist of one of the four sections of a version string: <code>
* &lt;number-a&gt;&lt;string-b&gt;&lt;number-c&gt;
* &lt;string-d (everything else)&gt;</code>.
*/
class VersionPartTokenizer implements Enumeration {
String part;
public VersionPartTokenizer(String aPart) {
part = aPart;
}
public boolean hasMoreElements() {
return part.length() != 0;
}
public boolean hasMoreTokens() {
return part.length() != 0;
}
public Object nextElement() {
if (part.matches("[\\+\\-]?[0-9].*")) {
// if string starts with a number...
int index = 0;
if (part.charAt(0) == '+' || part.charAt(0) == '-') {
index = 1;
}
while (index < part.length() && Character.isDigit(part.charAt(index))) {
index++;
}
String numPart = part.substring(0, index);
part = part.substring(index);
return numPart;
} else {
// ... or if this is the non-numeric part of version string
int index = 0;
while (index < part.length() && !Character.isDigit(part.charAt(index))) {
index++;
}
String alphaPart = part.substring(0, index);
part = part.substring(index);
return alphaPart;
}
}
public String nextToken() {
return (String) nextElement();
}
/**
* Returns what remains of the original string, without tokenization. This
* method is useful for getting the <code>&lt;string-d (everything else)&gt;
* </code> section of a version string.
*
* @return remaining version string
*/
public String getRemainder() {
return part;
}
}

View File

@@ -1,253 +0,0 @@
/* ***** 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) 2005
* 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 "nsAppFileLocProviderProxy.h"
#include "nsJavaXPCOMBindingUtils.h"
#include "nsILocalFile.h"
#include "nsISimpleEnumerator.h"
nsAppFileLocProviderProxy::nsAppFileLocProviderProxy(jobject aJavaObject)
{
mJavaLocProvider = GetJNIEnv()->NewGlobalRef(aJavaObject);
}
nsAppFileLocProviderProxy::~nsAppFileLocProviderProxy()
{
GetJNIEnv()->DeleteGlobalRef(mJavaLocProvider);
}
NS_IMPL_ISUPPORTS2(nsAppFileLocProviderProxy,
nsIDirectoryServiceProvider,
nsIDirectoryServiceProvider2)
// nsIDirectoryServiceProvider
NS_IMETHODIMP
nsAppFileLocProviderProxy::GetFile(const char* aProp, PRBool* aIsPersistant,
nsIFile** aResult)
{
// Setup params for calling Java function
JNIEnv* env = GetJNIEnv();
jstring prop = env->NewStringUTF(aProp);
if (!prop)
return NS_ERROR_OUT_OF_MEMORY;
jbooleanArray persistant = env->NewBooleanArray(1);
if (!persistant)
return NS_ERROR_OUT_OF_MEMORY;
// Create method ID
jmethodID mid = nsnull;
jclass clazz = env->GetObjectClass(mJavaLocProvider);
if (clazz) {
mid = env->GetMethodID(clazz, "getFile",
"(Ljava/lang/String;[Z)Ljava/io/File;");
}
if (!mid)
return NS_ERROR_FAILURE;
// Call Java function
jobject javaFile = nsnull;
javaFile = env->CallObjectMethod(mJavaLocProvider, mid, prop, persistant);
if (javaFile == nsnull || env->ExceptionCheck())
return NS_ERROR_FAILURE;
// Set boolean output value
env->GetBooleanArrayRegion(persistant, 0, 1, (jboolean*) aIsPersistant);
// Set nsIFile result value
nsCOMPtr<nsILocalFile> localFile;
nsresult rv = File_to_nsILocalFile(env, javaFile, getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv)) {
return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)aResult);
}
return rv;
}
// nsIDirectoryServiceProvider2
class DirectoryEnumerator : public nsISimpleEnumerator
{
public:
NS_DECL_ISUPPORTS
DirectoryEnumerator(jobjectArray aJavaFileArray)
: mIndex(0)
{
JNIEnv* env = GetJNIEnv();
mJavaFileArray = NS_STATIC_CAST(jobjectArray,
env->NewGlobalRef(aJavaFileArray));
mArraySize = env->GetArrayLength(aJavaFileArray);
}
~DirectoryEnumerator()
{
GetJNIEnv()->DeleteGlobalRef(mJavaFileArray);
}
NS_IMETHOD HasMoreElements(PRBool* aResult)
{
if (!mJavaFileArray) {
*aResult = PR_FALSE;
} else {
*aResult = (mIndex < mArraySize);
}
return NS_OK;
}
NS_IMETHOD GetNext(nsISupports** aResult)
{
nsresult rv = NS_ERROR_FAILURE;
JNIEnv* env = GetJNIEnv();
jobject javaFile = env->GetObjectArrayElement(mJavaFileArray, mIndex++);
if (javaFile) {
nsCOMPtr<nsILocalFile> localFile;
rv = File_to_nsILocalFile(env, javaFile, getter_AddRefs(localFile));
env->DeleteLocalRef(javaFile);
if (NS_SUCCEEDED(rv)) {
return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)aResult);
}
}
env->ExceptionClear();
return NS_ERROR_FAILURE;
}
private:
jobjectArray mJavaFileArray;
PRUint32 mArraySize;
PRUint32 mIndex;
};
NS_IMPL_ISUPPORTS1(DirectoryEnumerator, nsISimpleEnumerator)
NS_IMETHODIMP
nsAppFileLocProviderProxy::GetFiles(const char* aProp,
nsISimpleEnumerator** aResult)
{
nsresult rv = NS_OK;
// Setup params for calling Java function
JNIEnv* env = GetJNIEnv();
jstring prop = env->NewStringUTF(aProp);
if (!prop)
rv = NS_ERROR_OUT_OF_MEMORY;
// Create method ID
jmethodID mid = nsnull;
if (NS_SUCCEEDED(rv)) {
jclass clazz = env->GetObjectClass(mJavaLocProvider);
if (clazz) {
mid = env->GetMethodID(clazz, "getFiles",
"(Ljava/lang/String;)[Ljava/io/File;");
env->DeleteLocalRef(clazz);
}
if (!mid)
rv = NS_ERROR_FAILURE;
}
// Call Java function
jobject javaFileArray = nsnull;
if (NS_SUCCEEDED(rv)) {
javaFileArray = env->CallObjectMethod(mJavaLocProvider, mid, prop);
// Handle any exception thrown by Java method.
jthrowable exp = env->ExceptionOccurred();
if (exp) {
#ifdef DEBUG
env->ExceptionDescribe();
#endif
// If the exception is an instance of XPCOMException, then get the
// nsresult from the exception instance. Else, default to
// NS_ERROR_FAILURE.
if (env->IsInstanceOf(exp, xpcomExceptionClass)) {
jfieldID fid;
fid = env->GetFieldID(xpcomExceptionClass, "errorcode", "J");
if (fid) {
rv = env->GetLongField(exp, fid);
} else {
rv = NS_ERROR_FAILURE;
}
NS_ASSERTION(fid, "Couldn't get 'errorcode' field of XPCOMException");
} else {
rv = NS_ERROR_FAILURE;
}
} else {
// No exception thrown. Check the result.
if (javaFileArray == nsnull) {
rv = NS_ERROR_FAILURE;
}
}
}
if (NS_SUCCEEDED(rv)) {
// Parse return value
*aResult = new DirectoryEnumerator(NS_STATIC_CAST(jobjectArray,
javaFileArray));
NS_ADDREF(*aResult);
return NS_OK;
}
// Handle error conditions
*aResult = nsnull;
env->ExceptionClear();
return rv;
}
////////////////////////////////////////////////////////////////////////////////
nsresult
NS_NewAppFileLocProviderProxy(jobject aJavaLocProvider,
nsIDirectoryServiceProvider** aResult)
{
nsAppFileLocProviderProxy* provider =
new nsAppFileLocProviderProxy(aJavaLocProvider);
if (provider == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(provider);
*aResult = provider;
return NS_OK;
}

View File

@@ -1,65 +0,0 @@
/* ***** 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) 2005
* 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 ***** */
#ifndef _nsAppFileLocProviderProxy_h_
#define _nsAppFileLocProviderProxy_h_
#include "nsIDirectoryService.h"
#include "jni.h"
class nsAppFileLocProviderProxy : public nsIDirectoryServiceProvider2
{
public:
nsAppFileLocProviderProxy(jobject aJavaLocProvider);
~nsAppFileLocProviderProxy();
NS_DECL_ISUPPORTS
NS_DECL_NSIDIRECTORYSERVICEPROVIDER
NS_DECL_NSIDIRECTORYSERVICEPROVIDER2
private:
jobject mJavaLocProvider;
};
extern "C" nsresult
NS_NewAppFileLocProviderProxy(jobject aJavaLocProvider,
nsIDirectoryServiceProvider** aResult);
#endif //_nsAppFileLocProviderProxy_h_

View File

@@ -1,313 +0,0 @@
/* ***** 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) 2005
* 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 "nsJavaInterfaces.h"
#include "nsJavaWrapper.h"
#include "nsJavaXPCOMBindingUtils.h"
#include "nsJavaXPTCStub.h"
#include "nsIComponentRegistrar.h"
#include "nsString.h"
#include "nsISimpleEnumerator.h"
#include "nsIInterfaceInfoManager.h"
#include "nsIInputStream.h"
#include "nsEnumeratorUtils.h"
#include "nsAppFileLocProviderProxy.h"
#include "nsXULAppAPI.h"
#include "nsILocalFile.h"
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;
if (aLibXULDirectory) {
rv = File_to_nsILocalFile(env, aLibXULDirectory, getter_AddRefs(libXULDir));
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsILocalFile> appDir;
if (aAppDirectory) {
rv = File_to_nsILocalFile(env, aAppDirectory, getter_AddRefs(appDir));
NS_ENSURE_SUCCESS(rv, rv);
}
// create nsAppFileLocProviderProxy from given Java object
nsCOMPtr<nsIDirectoryServiceProvider> provider;
if (aAppDirProvider) {
rv = NS_NewAppFileLocProviderProxy(aAppDirProvider,
getter_AddRefs(provider));
NS_ENSURE_SUCCESS(rv, rv);
}
// init libXUL
return XRE_InitEmbedding(libXULDir, appDir, provider, nsnull, 0);
}
extern "C" NS_EXPORT void
GRE_NATIVE(initEmbedding) (JNIEnv* env, jobject, jobject aLibXULDirectory,
jobject aAppDirectory, jobject aAppDirProvider)
{
nsresult rv = InitEmbedding_Impl(env, aLibXULDirectory, aAppDirectory,
aAppDirProvider);
if (NS_FAILED(rv)) {
ThrowException(env, rv, "Failure in initEmbedding");
FreeJavaGlobals(env);
}
}
extern "C" NS_EXPORT void
GRE_NATIVE(termEmbedding) (JNIEnv *env, jobject)
{
// Free globals before calling XRE_TermEmbedding(), since we need some
// XPCOM services.
FreeJavaGlobals(env);
XRE_TermEmbedding();
}
nsresult
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;
if (aMozBinDirectory) {
rv = File_to_nsILocalFile(env, aMozBinDirectory, getter_AddRefs(directory));
NS_ENSURE_SUCCESS(rv, rv);
}
// create nsAppFileLocProviderProxy from given Java object
nsAppFileLocProviderProxy* provider = nsnull;
if (aAppFileLocProvider) {
provider = new nsAppFileLocProviderProxy(aAppFileLocProvider);
if (!provider)
return NS_ERROR_OUT_OF_MEMORY;
}
// init XPCOM
nsCOMPtr<nsIServiceManager> servMan;
rv = NS_InitXPCOM2(getter_AddRefs(servMan), directory, provider);
if (provider) {
delete provider;
}
NS_ENSURE_SUCCESS(rv, rv);
// create Java proxy for service manager returned by NS_InitXPCOM2
return GetNewOrUsedJavaObject(env, servMan, NS_GET_IID(nsIServiceManager),
aResult);
}
extern "C" NS_EXPORT jobject
XPCOM_NATIVE(initXPCOM) (JNIEnv* env, jobject, jobject aMozBinDirectory,
jobject aAppFileLocProvider)
{
jobject servMan;
nsresult rv = InitXPCOM_Impl(env, aMozBinDirectory, aAppFileLocProvider,
&servMan);
if (NS_SUCCEEDED(rv))
return servMan;
ThrowException(env, rv, "Failure in initXPCOM");
FreeJavaGlobals(env);
return nsnull;
}
extern "C" NS_EXPORT void
XPCOM_NATIVE(shutdownXPCOM) (JNIEnv *env, jobject, jobject aServMgr)
{
nsresult rv;
nsCOMPtr<nsIServiceManager> servMgr;
if (aServMgr) {
// Get native XPCOM instance
rv = GetNewOrUsedXPCOMObject(env, aServMgr, NS_GET_IID(nsIServiceManager),
getter_AddRefs(servMgr));
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to get XPCOM obj for ServiceMgr.");
// Even if we failed to get the matching xpcom object, we don't abort this
// function. Just call NS_ShutdownXPCOM with a null service manager.
}
// Free globals before calling NS_ShutdownXPCOM(), since we need some
// XPCOM services.
FreeJavaGlobals(env);
rv = NS_ShutdownXPCOM(servMgr);
if (NS_FAILED(rv))
ThrowException(env, rv, "NS_ShutdownXPCOM failed");
}
extern "C" NS_EXPORT jobject
XPCOM_NATIVE(newLocalFile) (JNIEnv *env, jobject, jstring aPath,
jboolean aFollowLinks)
{
// Create a Mozilla string from the jstring
const PRUnichar* buf = nsnull;
if (aPath) {
buf = env->GetStringChars(aPath, nsnull);
if (!buf)
return nsnull; // exception already thrown
}
nsAutoString path_str(buf);
env->ReleaseStringChars(aPath, buf);
// Make call to given function
nsCOMPtr<nsILocalFile> file;
nsresult rv = NS_NewLocalFile(path_str, aFollowLinks, getter_AddRefs(file));
if (NS_SUCCEEDED(rv)) {
jobject javaProxy;
rv = GetNewOrUsedJavaObject(env, file, NS_GET_IID(nsILocalFile),
&javaProxy);
if (NS_SUCCEEDED(rv))
return javaProxy;
}
ThrowException(env, rv, "Failure in newLocalFile");
return nsnull;
}
extern "C" NS_EXPORT jobject
XPCOM_NATIVE(getComponentManager) (JNIEnv *env, jobject)
{
// Call XPCOM method
nsCOMPtr<nsIComponentManager> cm;
nsresult rv = NS_GetComponentManager(getter_AddRefs(cm));
if (NS_SUCCEEDED(rv)) {
jobject javaProxy;
rv = GetNewOrUsedJavaObject(env, cm, NS_GET_IID(nsIComponentManager),
&javaProxy);
if (NS_SUCCEEDED(rv))
return javaProxy;
}
ThrowException(env, rv, "Failure in getComponentManager");
return nsnull;
}
extern "C" NS_EXPORT jobject
XPCOM_NATIVE(getComponentRegistrar) (JNIEnv *env, jobject)
{
// Call XPCOM method
nsCOMPtr<nsIComponentRegistrar> cr;
nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(cr));
if (NS_SUCCEEDED(rv)) {
jobject javaProxy;
rv = GetNewOrUsedJavaObject(env, cr, NS_GET_IID(nsIComponentRegistrar),
&javaProxy);
if (NS_SUCCEEDED(rv))
return javaProxy;
}
ThrowException(env, rv, "Failure in getComponentRegistrar");
return nsnull;
}
extern "C" NS_EXPORT jobject
XPCOM_NATIVE(getServiceManager) (JNIEnv *env, jobject)
{
// Call XPCOM method
nsCOMPtr<nsIServiceManager> sm;
nsresult rv = NS_GetServiceManager(getter_AddRefs(sm));
if (NS_SUCCEEDED(rv)) {
jobject javaProxy;
rv = GetNewOrUsedJavaObject(env, sm, NS_GET_IID(nsIServiceManager),
&javaProxy);
if (NS_SUCCEEDED(rv))
return javaProxy;
}
ThrowException(env, rv, "Failure in getServiceManager");
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();
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,72 +0,0 @@
/* ***** 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) 2004
* 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 ***** */
#ifndef _nsJavaWrapper_h_
#define _nsJavaWrapper_h_
#include "jni.h"
#include "nsISupports.h"
/**
* Creates a Java proxy around an XPCOM C++ object.
*
* @param env pointer to Java context
* @param aXPCOMObject XPCOM object to create proxy for
* @param aIID IID for XPCOM object
* @param aResult on exit, holds reference to Java proxy
*
* @return NS_OK if Java proxy was successfully created;
* any other value denotes an error condition.
*/
nsresult CreateJavaProxy(JNIEnv* env, nsISupports* aXPCOMObject,
const nsIID& aIID, jobject* aResult);
/**
* Returns the XPCOM object for which the given Java proxy was created.
*
* @param env pointer to Java context
* @param aJavaObject a Java proxy created by CreateJavaProxy()
* @param aResult on exit, holds pointer to XPCOM instance
*
* @return NS_OK if the XPCOM object was successfully retrieved;
* any other value denotes an error condition.
*/
nsresult GetXPCOMInstFromProxy(JNIEnv* env, jobject aJavaObject,
void** aResult);
#endif // _nsJavaWrapper_h_

File diff suppressed because it is too large Load Diff

View File

@@ -1,358 +0,0 @@
/* ***** 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) 2005
* 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 ***** */
#ifndef _nsJavaXPCOMBindingUtils_h_
#define _nsJavaXPCOMBindingUtils_h_
#include "jni.h"
#include "xptcall.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "pldhash.h"
#include "nsJavaXPTCStub.h"
#include "nsAutoLock.h"
#include "nsTHashtable.h"
#include "nsHashKeys.h"
//#define DEBUG_JAVAXPCOM
//#define DEBUG_JAVAXPCOM_REFCNT
#ifdef DEBUG_JAVAXPCOM
#define LOG(x) printf x
#else
#define LOG(x) /* nothing */
#endif
/*********************
* Java JNI globals
*********************/
extern jclass systemClass;
extern jclass booleanClass;
extern jclass charClass;
extern jclass byteClass;
extern jclass shortClass;
extern jclass intClass;
extern jclass longClass;
extern jclass floatClass;
extern jclass doubleClass;
extern jclass stringClass;
extern jclass nsISupportsClass;
extern jclass xpcomExceptionClass;
extern jclass xpcomJavaProxyClass;
extern jclass weakReferenceClass;
extern jmethodID hashCodeMID;
extern jmethodID booleanValueMID;
extern jmethodID booleanInitMID;
extern jmethodID charValueMID;
extern jmethodID charInitMID;
extern jmethodID byteValueMID;
extern jmethodID byteInitMID;
extern jmethodID shortValueMID;
extern jmethodID shortInitMID;
extern jmethodID intValueMID;
extern jmethodID intInitMID;
extern jmethodID longValueMID;
extern jmethodID longInitMID;
extern jmethodID floatValueMID;
extern jmethodID floatInitMID;
extern jmethodID doubleValueMID;
extern jmethodID doubleInitMID;
extern jmethodID createProxyMID;
extern jmethodID isXPCOMJavaProxyMID;
extern jmethodID getNativeXPCOMInstMID;
extern jmethodID weakReferenceConstructorMID;
extern jmethodID getReferentMID;
extern jmethodID clearReferentMID;
#ifdef DEBUG_JAVAXPCOM
extern jmethodID getNameMID;
extern jmethodID proxyToStringMID;
#endif
class NativeToJavaProxyMap;
extern NativeToJavaProxyMap* gNativeToJavaProxyMap;
class JavaToXPTCStubMap;
extern JavaToXPTCStubMap* gJavaToXPTCStubMap;
extern nsTHashtable<nsDepCharHashKey>* gJavaKeywords;
// The Java garbage collector runs in a separate thread. Since it calls the
// finalizeProxy() function in nsJavaWrapper.cpp, we need to make sure that
// all the structures touched by finalizeProxy() are multithread aware.
extern PRLock* gJavaXPCOMLock;
extern PRBool gJavaXPCOMInitialized;
/**
* Initialize global structures used by JavaXPCOM.
* @param env Java environment pointer
* @return PR_TRUE if JavaXPCOM is initialized; PR_FALSE if an error occurred
*/
PRBool InitializeJavaGlobals(JNIEnv *env);
/**
* Frees global structures that were allocated by InitializeJavaGlobals().
* @param env Java environment pointer
*/
void FreeJavaGlobals(JNIEnv* env);
/*************************
* JavaXPCOMInstance
*************************/
class JavaXPCOMInstance
{
public:
JavaXPCOMInstance(nsISupports* aInstance, nsIInterfaceInfo* aIInfo);
~JavaXPCOMInstance();
nsISupports* GetInstance() { return mInstance; }
nsIInterfaceInfo* InterfaceInfo() { return mIInfo; }
private:
nsISupports* mInstance;
nsIInterfaceInfo* mIInfo;
};
/**************************************
* Java<->XPCOM object mappings
**************************************/
/**
* Maps native XPCOM objects to their associated Java proxy object.
*/
class NativeToJavaProxyMap
{
friend PLDHashOperator DestroyJavaProxyMappingEnum(PLDHashTable* aTable,
PLDHashEntryHdr* aHeader,
PRUint32 aNumber,
void* aData);
protected:
struct ProxyList
{
ProxyList(const jobject aRef, const nsIID& aIID, ProxyList* aList)
: javaObject(aRef)
, iid(aIID)
, next(aList)
{ }
const jobject javaObject;
const nsIID iid;
ProxyList* next;
};
struct Entry : public PLDHashEntryHdr
{
nsISupports* key;
ProxyList* list;
};
public:
NativeToJavaProxyMap()
: mHashTable(nsnull)
{ }
~NativeToJavaProxyMap()
{
NS_ASSERTION(mHashTable == nsnull,
"MUST call Destroy() before deleting object");
}
nsresult Init();
nsresult Destroy(JNIEnv* env);
nsresult Add(JNIEnv* env, nsISupports* aXPCOMObject, const nsIID& aIID,
jobject aProxy);
nsresult Find(JNIEnv* env, nsISupports* aNativeObject, const nsIID& aIID,
jobject* aResult);
nsresult Remove(JNIEnv* env, nsISupports* aNativeObject, const nsIID& aIID);
protected:
PLDHashTable* mHashTable;
};
/**
* Maps Java objects to their associated nsJavaXPTCStub.
*/
class JavaToXPTCStubMap
{
friend PLDHashOperator DestroyXPTCMappingEnum(PLDHashTable* aTable,
PLDHashEntryHdr* aHeader,
PRUint32 aNumber, void* aData);
protected:
struct Entry : public PLDHashEntryHdr
{
jint key;
nsJavaXPTCStub* xptcstub;
};
public:
JavaToXPTCStubMap()
: mHashTable(nsnull)
{ }
~JavaToXPTCStubMap()
{
NS_ASSERTION(mHashTable == nsnull,
"MUST call Destroy() before deleting object");
}
nsresult Init();
nsresult Destroy();
nsresult Add(jint aJavaObjectHashCode, nsJavaXPTCStub* aProxy);
nsresult Find(jint aJavaObjectHashCode, const nsIID& aIID,
nsJavaXPTCStub** aResult);
nsresult Remove(jint aJavaObjectHashCode);
protected:
PLDHashTable* mHashTable;
};
/*******************************
* Helper functions
*******************************/
/**
* Finds the associated Java object for the given XPCOM object and IID. If no
* such Java object exists, then it creates one.
*
* @param env Java environment pointer
* @param aXPCOMObject XPCOM object for which to find/create Java object
* @param aIID desired interface IID for Java object
* @param aResult on success, holds reference to Java object
*
* @return NS_OK if succeeded; all other return values are error codes.
*/
nsresult GetNewOrUsedJavaObject(JNIEnv* env, nsISupports* aXPCOMObject,
const nsIID& aIID, jobject* aResult);
/**
* Finds the associated XPCOM object for the given Java object and IID. If no
* such XPCOM object exists, then it creates one.
*
* @param env Java environment pointer
* @param aJavaObject Java object for which to find/create XPCOM object
* @param aIID desired interface IID for XPCOM object
* @param aResult on success, holds AddRef'd reference to XPCOM object
*
* @return NS_OK if succeeded; all other return values are error codes.
*/
nsresult GetNewOrUsedXPCOMObject(JNIEnv* env, jobject aJavaObject,
const nsIID& aIID, nsISupports** aResult);
nsresult GetIIDForMethodParam(nsIInterfaceInfo *iinfo,
const nsXPTMethodInfo *methodInfo,
const nsXPTParamInfo &paramInfo,
PRUint8 paramType, PRUint16 methodIndex,
nsXPTCMiniVariant *dispatchParams,
PRBool isFullVariantArray,
nsID &result);
/*******************************
* JNI helper functions
*******************************/
/**
* Returns a pointer to the appropriate JNIEnv structure. This function is
* useful in callbacks or other functions that are not called directly from
* Java and therefore do not have the JNIEnv structure passed in.
*
* @return pointer to JNIEnv structure for current thread
*/
JNIEnv* GetJNIEnv();
/**
* Constructs and throws an exception. Some error codes (such as
* NS_ERROR_OUT_OF_MEMORY) are handled by the appropriate Java exception/error.
* Otherwise, an instance of XPCOMException is created with the given error
* code and message.
*
* @param env Java environment pointer
* @param aErrorCode The error code returned by an XPCOM/Gecko function. Pass
* zero for the default behaviour.
* @param aMessage A string that provides details for throwing this
* exception. Pass in <code>nsnull</code> for the default
* behaviour.
*
* @throws OutOfMemoryError if aErrorCode == NS_ERROR_OUT_OF_MEMORY
* XPCOMException for all other error codes
*/
void ThrowException(JNIEnv* env, const nsresult aErrorCode,
const char* aMessage);
/**
* Helper functions for converting from java.lang.String to
* nsAString/nsACstring. Caller must delete nsAString/nsACString.
*
* @param env Java environment pointer
* @param aString Java string to convert
*
* @return nsAString/nsACString with same content as given Java string; or
* <code>nsnull</code> if out of memory
*/
nsAString* jstring_to_nsAString(JNIEnv* env, jstring aString);
nsACString* jstring_to_nsACString(JNIEnv* env, jstring aString);
/**
* Helper function for converting from java.io.File to nsILocalFile.
*
* @param env Java environment pointer
* @param aFile Java File to convert
* @param aLocalFile returns the converted nsILocalFile
*
* @return NS_OK for success; other values indicate error in conversion
*/
nsresult File_to_nsILocalFile(JNIEnv* env, jobject aFile,
nsILocalFile** aLocalFile);
#endif // _nsJavaXPCOMBindingUtils_h_

File diff suppressed because it is too large Load Diff

View File

@@ -1,135 +0,0 @@
/* ***** 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) 2005
* 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 ***** */
#ifndef _nsJavaXPTCStub_h_
#define _nsJavaXPTCStub_h_
#include "xptcall.h"
#include "jni.h"
#include "nsVoidArray.h"
#include "nsIInterfaceInfo.h"
#include "nsCOMPtr.h"
#include "nsWeakReference.h"
#include "nsJavaXPTCStubWeakRef.h"
#define NS_JAVAXPTCSTUB_IID \
{0x88dd8130, 0xebe6, 0x4431, {0x9d, 0xa7, 0xe6, 0xb7, 0x54, 0x74, 0xfb, 0x21}}
class nsJavaXPTCStub : public nsXPTCStubBase,
public nsSupportsWeakReference
{
friend class nsJavaXPTCStubWeakRef;
public:
NS_DECL_ISUPPORTS
NS_DECL_NSISUPPORTSWEAKREFERENCE
NS_DECLARE_STATIC_IID_ACCESSOR(NS_JAVAXPTCSTUB_IID)
nsJavaXPTCStub(jobject aJavaObject, nsIInterfaceInfo *aIInfo);
virtual ~nsJavaXPTCStub();
// return a refcounted pointer to the InterfaceInfo for this object
// NOTE: on some platforms this MUST not fail or we crash!
NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo **aInfo);
// call this method and return result
NS_IMETHOD CallMethod(PRUint16 aMethodIndex,
const nsXPTMethodInfo *aInfo,
nsXPTCMiniVariant *aParams);
// getter for mJavaObject
jobject GetJavaObject();
// Deletes the strong global ref for the Java object, so it can be garbage
// collected if necessary. See DestroyXPTCMappingEnum().
void DeleteStrongRef();
private:
NS_IMETHOD_(nsrefcnt) AddRefInternal();
NS_IMETHOD_(nsrefcnt) ReleaseInternal();
// Deletes this object and its members. Called by ReleaseInternal() and
// ReleaseWeakRef().
void Destroy();
// When a nsJavaXPTCStubWeakRef associated with this object is released, it
// calls this function to let this object know that there is one less weak
// ref. If there are no more weakrefs referencing this object, and no one
// holds a strong ref, then this function takes care of deleting the object.
void ReleaseWeakRef();
// returns a weak reference to a child supporting the specified interface
nsJavaXPTCStub * FindStubSupportingIID(const nsID &aIID);
// returns true if this stub supports the specified interface
PRBool SupportsIID(const nsID &aIID);
nsresult SetupJavaParams(const nsXPTParamInfo &aParamInfo,
const nsXPTMethodInfo* aMethodInfo,
PRUint16 aMethodIndex,
nsXPTCMiniVariant* aDispatchParams,
nsXPTCMiniVariant &aVariant,
jvalue &aJValue, nsACString &aMethodSig);
nsresult GetRetvalSig(const nsXPTParamInfo* aParamInfo,
const nsXPTMethodInfo* aMethodInfo,
PRUint16 aMethodIndex,
nsXPTCMiniVariant* aDispatchParams,
nsACString &aRetvalSig);
nsresult FinalizeJavaParams(const nsXPTParamInfo &aParamInfo,
const nsXPTMethodInfo* aMethodInfo,
PRUint16 aMethodIndex,
nsXPTCMiniVariant* aDispatchParams,
nsXPTCMiniVariant &aVariant,
jvalue &aJValue);
nsresult SetXPCOMRetval();
jobject mJavaWeakRef;
jobject mJavaStrongRef;
jint mJavaRefHashCode;
nsCOMPtr<nsIInterfaceInfo> mIInfo;
nsVoidArray mChildren; // weak references (cleared by the children)
nsJavaXPTCStub *mMaster; // strong reference
nsAutoRefCnt mWeakRefCnt; // count for number of associated weak refs
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsJavaXPTCStub, NS_JAVAXPTCSTUB_IID)
#endif // _nsJavaXPTCStub_h_

View File

@@ -1,98 +0,0 @@
/* ***** 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) 2005
* 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 "nsJavaXPTCStubWeakRef.h"
#include "nsJavaXPTCStub.h"
#include "nsJavaXPCOMBindingUtils.h"
#include "nsIInterfaceInfoManager.h"
/**
* How we handle XPCOM weak references to a Java object:
*
* If XPCOM requires or asks for a weak reference of a Java object, we first
* find (or create) an nsJavaXPTCStub for that Java object. That way, there is
* always an nsJavaXPTCStub for any nsJavaXPTCStubWeakRef. However, the
* XPTCStub may not always be 'valid'; that is, its refcount may be zero if
* is not currently referenced by any XPCOM class.
* When an XPCOM method queries the referent from the weak reference, the
* weak ref checks first whether the Java object is still valid. If so, we can
* immediately return an addref'd nsJavaXPTCStub. The XPTCStub takes care of
* finding an XPTCStub for the required IID.
*/
nsJavaXPTCStubWeakRef::nsJavaXPTCStubWeakRef(jobject aJavaObject,
nsJavaXPTCStub* aXPTCStub)
: mXPTCStub(aXPTCStub)
{
JNIEnv* env = GetJNIEnv();
jobject weakref = env->NewObject(weakReferenceClass,
weakReferenceConstructorMID, aJavaObject);
mWeakRef = env->NewGlobalRef(weakref);
}
nsJavaXPTCStubWeakRef::~nsJavaXPTCStubWeakRef()
{
JNIEnv* env = GetJNIEnv();
env->CallVoidMethod(mWeakRef, clearReferentMID);
env->DeleteGlobalRef(mWeakRef);
mXPTCStub->ReleaseWeakRef();
}
NS_IMPL_ADDREF(nsJavaXPTCStubWeakRef)
NS_IMPL_RELEASE(nsJavaXPTCStubWeakRef)
NS_IMPL_QUERY_INTERFACE1(nsJavaXPTCStubWeakRef, nsIWeakReference)
NS_IMETHODIMP
nsJavaXPTCStubWeakRef::QueryReferent(const nsIID& aIID, void** aInstancePtr)
{
LOG(("nsJavaXPTCStubWeakRef::QueryReferent()\n"));
// Is weak ref still valid?
// We create a strong local ref to make sure Java object isn't garbage
// collected during this call.
JNIEnv* env = GetJNIEnv();
jobject javaObject = env->CallObjectMethod(mWeakRef, getReferentMID);
if (env->IsSameObject(javaObject, NULL))
return NS_ERROR_NULL_POINTER;
// Java object has not been garbage collected, so return QI from XPTCStub.
return mXPTCStub->QueryInterface(aIID, aInstancePtr);
}

View File

@@ -1,63 +0,0 @@
/* ***** 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) 2005
* 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 ***** */
#ifndef _nsJavaXPTCStubWeakRef_h_
#define _nsJavaXPTCStubWeakRef_h_
#include "jni.h"
#include "nsIWeakReference.h"
class nsJavaXPTCStub;
/**
* This class represents an XPCOM weak reference to a Java object.
*/
class nsJavaXPTCStubWeakRef : public nsIWeakReference
{
public:
nsJavaXPTCStubWeakRef(jobject aJavaObject, nsJavaXPTCStub* aXPTCStub);
virtual ~nsJavaXPTCStubWeakRef();
NS_DECL_ISUPPORTS
NS_DECL_NSIWEAKREFERENCE
protected:
jobject mWeakRef;
nsJavaXPTCStub* mXPTCStub;
};
#endif // _nsJavaXPTCStubWeakRef_h_

View File

@@ -1,61 +0,0 @@
/* ***** 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.*;
import org.mozilla.xpcom.*;
public class GREImpl extends JavaXPCOMMethods implements IGRE {
public void initEmbedding(File aLibXULDirectory, File aAppDirectory,
IAppFileLocProvider aAppDirProvider) {
registerJavaXPCOMMethods(aLibXULDirectory);
initEmbeddingNative(aLibXULDirectory, aAppDirectory, aAppDirProvider);
}
public native void initEmbeddingNative(File aLibXULDirectory,
File aAppDirectory, IAppFileLocProvider aAppDirProvider);
public native void termEmbedding();
public native nsISupports lockProfileDirectory(File aDirectory);
public native void notifyProfile();
}

View File

@@ -1,58 +0,0 @@
/* ***** 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;
public class JavaXPCOMMethods {
public static void registerJavaXPCOMMethods(File aLibXULDirectory) {
// load JNI library
String path = "";
if (aLibXULDirectory != null) {
path = aLibXULDirectory + File.separator;
}
System.load(path + System.mapLibraryName("javaxpcomglue"));
registerJavaXPCOMMethodsNative(aLibXULDirectory);
}
public static native void
registerJavaXPCOMMethodsNative(File aLibXULDirectory);
}

View File

@@ -1,65 +0,0 @@
/* ***** 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.*;
import org.mozilla.xpcom.*;
public class XPCOMImpl extends JavaXPCOMMethods implements IXPCOM {
public nsIServiceManager initXPCOM(File aMozBinDirectory,
IAppFileLocProvider aAppFileLocProvider) {
registerJavaXPCOMMethods(aMozBinDirectory);
return initXPCOMNative(aMozBinDirectory, aAppFileLocProvider);
}
public native nsIServiceManager initXPCOMNative(File aMozBinDirectory,
IAppFileLocProvider aAppFileLocProvider);
public native void shutdownXPCOM(nsIServiceManager aServMgr);
public native nsIComponentManager getComponentManager();
public native nsIComponentRegistrar getComponentRegistrar();
public native nsIServiceManager getServiceManager();
public native nsILocalFile newLocalFile(String aPath, boolean aFollowLinks);
}