diff --git a/mozilla/java/Makefile.win b/mozilla/java/Makefile.win new file mode 100644 index 00000000000..3dfbb4c1d41 --- /dev/null +++ b/mozilla/java/Makefile.win @@ -0,0 +1,36 @@ +#!nmake +# +# The contents of this file are subject to the Mozilla Public License +# Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, +# Inc. Portions created by Sun are Copyright (C) 1999 Sun +# Microsystems, Inc. All Rights Reserved. + +IGNORE_MANIFEST=1 +#//------------------------------------------------------------------------ +#// +#// Makefile to build the java enhancers to mozilla +#// +#//------------------------------------------------------------------------ + + +#//------------------------------------------------------------------------ +#// +#// Specify the depth of the current directory relative to the +#// root of NS +#// +#//------------------------------------------------------------------------ +DEPTH = .. + +DIRS = util \ + webclient + +include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/java/README b/mozilla/java/README new file mode 100644 index 00000000000..74f5b9eebf2 --- /dev/null +++ b/mozilla/java/README @@ -0,0 +1,40 @@ +Here lies the code that comprises the java enhancers to mozilla. + +Authors: see the README files for each individual subdirectory + +Requirements: + +* JDK1.1.7 or greater (may work with lower versions, haven't checked). + +* M8 or post M8 mozilla tree + +* Perl 5 perl.exe must be in your path + +How To Build: + +* make it so the directory in which this file resides is a child of your + top level mozilla directory + +* Copy the files .\webclient\config\buildpkg.bat and + .\webclient\config\outofdate.pl to mozilla\config. These file were + modified after M8 and the modifications are required to build java. + +* make sure the environment var JDKHOME is set to your jdk installation + directory, ie SET JDKHOME=C:\jdk1.1.8 + +* type "nmake /f makefile.win all" and hope for the best + +* this should compile the clasess into %MOZ_SRC%\dist\classes + +Problems: + +* clobber_all doesn't remove the .class files from dist\classes. You + have to do this manually. + +* post to netscape.public.mozilla.java newsgroup + +General notes: + +* Please update the ChangeLog (changelo) files in the subdiroctories when + you make changes. + diff --git a/mozilla/java/util/Makefile.win b/mozilla/java/util/Makefile.win new file mode 100644 index 00000000000..8ba896802be --- /dev/null +++ b/mozilla/java/util/Makefile.win @@ -0,0 +1,37 @@ +#!nmake +# +# The contents of this file are subject to the Mozilla Public License +# Version 1.0 (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 "The Lighthouse Foundation Classes (LFC)" +# +# The Initial Developer of the Original Code is Sun Microsystems, +# Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun +# Microsystems, Inc. All Rights Reserved. + +IGNORE_MANIFEST=1 +#//------------------------------------------------------------------------ +#// +#// Makefile to build the java utility classes +#// +#//------------------------------------------------------------------------ + + +#//------------------------------------------------------------------------ +#// +#// Specify the depth of the current directory relative to the +#// root of NS +#// +#//------------------------------------------------------------------------ +DEPTH = ..\.. + +DIRS = classes + +include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/java/util/README b/mozilla/java/util/README new file mode 100644 index 00000000000..ce76da7c3d7 --- /dev/null +++ b/mozilla/java/util/README @@ -0,0 +1,41 @@ +Here lies the java classes that comprise the org.mozilla.util pagkage, +sometimes called MJUTIL for Mozilla Java Utils. This is not a complete +program, just a library. + +Authors: Rob Davis, Paul Kim, Alan Chung, Ray Ryan, Ed Burns, Keith Bernstein, David-John Burrowes + +Requirements: + +* JDK1.1.7 or greater (may work with lower versions, haven't checked). + +* M8 or post M8 mozilla tree + +* Perl 5 perl.exe must be in your path + +How To Build: + +* make it so the directory in which this file resides is a child of your + top level mozilla\java directory + +* Copy the files ..\webclient\config\buildpkg.bat and + ..\webclient\config\outofdate.pl to mozilla\config. These file were + modified after M8 and the modifications are required to build java. + +* make sure the environment var JDKHOME is set to your jdk installation + directory, ie SET JDKHOME=C:\jdk1.1.8 + +* type "nmake /f makefile.win all" and hope for the best + +* this should compile the clasess into %MOZ_SRC%\dist\classes + +Problems: + +* clobber_all doesn't remove the .class files from dist\classes. You + have to do this manually. + +* post to netscape.public.mozilla.java newsgroup + +General notes: + +* Please update the ChangeLog (changelo) when you make changes. + diff --git a/mozilla/java/util/changelo b/mozilla/java/util/changelo new file mode 100644 index 00000000000..b8a97b3da10 --- /dev/null +++ b/mozilla/java/util/changelo @@ -0,0 +1,4 @@ +Wed Jul 28 12:18:34 1999 + + * Created initial distribution and README + diff --git a/mozilla/java/util/classes/Makefile.win b/mozilla/java/util/classes/Makefile.win new file mode 100644 index 00000000000..adc7ae8979e --- /dev/null +++ b/mozilla/java/util/classes/Makefile.win @@ -0,0 +1,52 @@ +#!nmake +# +# The contents of this file are subject to the Mozilla Public License +# Version 1.0 (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 "The Lighthouse Foundation Classes (LFC)" +# +# The Initial Developer of the Original Code is Sun Microsystems, +# Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun +# Microsystems, Inc. All Rights Reserved. + +IGNORE_MANIFEST=1 +#//------------------------------------------------------------------------ +#// +#// Makefile to build the java util classes +#// +#//------------------------------------------------------------------------ + + +#//------------------------------------------------------------------------ +#// +#// Specify the depth of the current directory relative to the +#// root of NS +#// +#//------------------------------------------------------------------------ +DEPTH= ..\..\.. + +# PENDING(edburns): find out where this should really get defined +JAVA_OR_NSJVM=1 +NO_CAFE=1 + +include <$(DEPTH)\config\config.mak> + +JAR_MJUTIL_CLASSES = org\mozilla\util + +!ifdef JAVA_OR_NSJVM +JDIRS = $(JAR_MJUTIL_CLASSES) +!endif + +MJUTIL_JAR_NAME=mjutil$(VERSION_NUMBER).jar + +JAVAC_PROG=$(JDKHOME)\bin\javac +include <$(DEPTH)\config\rules.mak> + + diff --git a/mozilla/java/util/classes/org/mozilla/util/Assert.java b/mozilla/java/util/classes/org/mozilla/util/Assert.java new file mode 100644 index 00000000000..7e20d25c75e --- /dev/null +++ b/mozilla/java/util/classes/org/mozilla/util/Assert.java @@ -0,0 +1,126 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 "The Lighthouse Foundation Classes (LFC)" + * + * The Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.mozilla.util; + + +/** + * The Assert class provides convenient means for condition testing. + * Class methods in the Assert class can be used to verify certain + * conditions and to raise exceptions if the conditions are not met. + * Assertions are particularly useful during the development of a + * project and may be turned off in production code. Turning off + * exceptions causes Assert not to raise exceptions when conditions + * are not met.

+ * + * Typical usage: + *

+ * Assert.assert(Assert.enabled && mytest(), "my test failed"); + *

+ * + * Such usage prevents mytest() from being executed if assertions + * are disabled. This techinique allows assertions to do time-consuming + * checks (such as myArray.containsObject(myObject)) without + * worrying about them impacting the performance of the final release.

+ * + * If you know that the condition being tested is fast, you may omit the + * enabled flag: + *

+ * Assert.assert(myValue != null); + *

+ * + * Note that even in this second usage, if assertions are disabled, + * the assert() method will do nothing.

+ * + * Another usage that is more efficient but bulkier: + *

+ * if (Assert.enabled && Assert.assert(mytest(), "my test failed")); + *

+ * + * Such usage prevents not only mytest() from being executed if + * assertions are disabled but also the assert method itself, and some + * compilers can remove the entire statement if assertions are disabled.

+ * + * Assert is intended for general condition and invariant testing; + * for parameter testing, use ParameterCheck. + * + * @see ParameterCheck + */ +final public class Assert extends Object { + +// +// Public Constants +// + + /** + * True if failed assertions should raise exceptions, or false if they + * should do nothing. + */ + static public boolean enabled = true; + + +/** + * Private constructor prevents instances of this class from being created. + */ +private Assert() {} + +/** + * Sets enabled to newEnabled. + * + * @param newEnabled true if and only if assertions should be + * enabled + */ +static public void setEnabled(boolean newEnabled) { + enabled = newEnabled; +} + +/** + * Throws AssertionFailureException with a message of message + * if enabled is true and test is false; otherwise, does nothing. + * + * @param test value to verify + * @param message message of exception thrown if test is false + * @exception AssertionFailureException if test is false + * @return true + */ +static public boolean assert (boolean test, String message) { + if (enabled && !test) { + throw new AssertionFailureException (message); + } + return true; +} + +/** + * Throws AssertionFailureException if enabled is true and + * test is false; otherwise, does nothing. + * + * @param test value to verify + * @exception AssertionFailureException if test is false + * @return true + */ +static public boolean assert (boolean test) { + if (enabled && !test) { + throw new AssertionFailureException (); + } + return true; +} + + + +} // End of class Assert diff --git a/mozilla/java/util/classes/org/mozilla/util/AssertionFailureException.java b/mozilla/java/util/classes/org/mozilla/util/AssertionFailureException.java new file mode 100644 index 00000000000..fc6bba7710d --- /dev/null +++ b/mozilla/java/util/classes/org/mozilla/util/AssertionFailureException.java @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 "The Lighthouse Foundation Classes (LFC)" + * + * The Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + +// CUAssertionFailureException.java +// +// $Id: AssertionFailureException.java,v 1.1 1999-07-30 01:02:57 edburns%acm.org Exp $ +// + +package org.mozilla.util; + +/** + * This exception is thrown when an Assert.assert() fails. + * + * @see Assert + */ +public class AssertionFailureException + extends RuntimeException { + + +public AssertionFailureException () { super(); } +public AssertionFailureException (String s) { super("\n" + s + "\n"); } + + +} // End of class AssertionFailureException diff --git a/mozilla/java/util/classes/org/mozilla/util/Debug.java b/mozilla/java/util/classes/org/mozilla/util/Debug.java new file mode 100644 index 00000000000..cfb79699690 --- /dev/null +++ b/mozilla/java/util/classes/org/mozilla/util/Debug.java @@ -0,0 +1,515 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 "The Lighthouse Foundation Classes (LFC)" + * + * The Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + +package org.mozilla.util; + +import java.util.Vector; +import java.util.Enumeration; +import java.util.Date; + +/** + *

+ * Debug Vendor of debug "filter" strings set & queried by clients. This allows + * conditional code to only be executed if a certain filter is set.
+ * + * Example of use from JAG days:
+ * JDApplication allows the setting of filters from the commandline at app startup time, + * and Log supports printing debug messages only when a specific filter string has + * been set.
+ * + *

+ * + * Alternatively, users can use the System Properties table to define + * filter strings at runtime:

+ * + * + * java -DDebug.filters=String ...

+ * + * + * where String is comma (,) separated list of constants WITH NO + * WHITESPACE. ie "AXISPANEL_PAINT,BODYPANEL_PAINT".

+ * + * + * All filters are case-sensitive. + * + * This class also provides various timing routines. + * + *

+ * @author Keith Bernstein + * @version $Id: Debug.java,v 1.1 1999-07-30 01:02:57 edburns%acm.org Exp $ */ + +public class Debug extends Object { + static public final String HELP_FILTER_STRING = "HELP"; + static public final String ALL_FILTER_STRING = "ALL"; + static public final String TIMING_FILTER_STRING = "TIMING"; + static public final String PROGRESS_FILTER_STRING = "PROGRESS"; + + /** the name in the properties table where we look for filter strings */ + static final String PROPERTY_NAME = "Debug.filters"; + static final String SEP = ","; + + static boolean showedColumnTitleHelp = false; + // PENDING(kbern) When we start using JDK 1.2, we should change this filters Vector to a + // "Set" in the new collection API for increased access and verification times. + static Vector filters = null; + static long initializationTime = new Date().getTime(); + static long lastTime = initializationTime; + static long startTime = 0L; + static long lapTime = 0L; + + static { + /** This code adds to the filters Vector from the + * System.Properties variable named by PROPERTY_NAME + * The value of this variable must be a SEP separeted list + * and contain *NO WHITESPACE*!! + */ + String flags = System.getProperty(PROPERTY_NAME); + + if (null != flags) { + Vector flagVector = Utilities.vectorFromString(flags, SEP); + int i, size = (null != flagVector) ? flagVector.size() : 0; + String curFlag; + + for (i = 0; i < size; i++) { + curFlag = (String) flagVector.elementAt(i); + Debug.addFilter(curFlag); + } + } + } + + /** + * Sets a debug filter, for future consumption by this class, as well as other + * utility classes, like Log, etc. + * + * Virtually all "filters" are simply developer-meaningful strings which will be + * tested within developer code, to conditionally execute code. + * + * There are some predefined filters, which this class actually does something with + * (besides simply handing it back when asked for). + * + * The predefined filters are: + * HELP + * ALL + * TIMING + * + * If the "HELP" filter is found, this class will print a message displaying the + * predefined filters and what they do. + * + * If the "ALL" filter is found, this class will return "true" when queried for the + * existence of any filter, effectively turning on all debugging tests. + * This is useful for both quick and easy tests, as well as to find forgotten debug + * filters (see Log class for more info on this). + * + * If the "TIMING" filter is specified, then the time routines will always print + * their info, regardless of what filter string is passed to them. This is useful + * for turning on all timing tests. + * */ + static public synchronized void addFilter(String aFilter) { + if (aFilter != null) { + if (filters == null) { + Log.log("Debugging has been enabled."); + Log.log("os name: "+System.getProperty("os.name")); + Log.log("os version: "+System.getProperty("os.version")); + Log.log("Java version: "+System.getProperty("java.version")); + Log.log("Java home: "+System.getProperty("java.home")); + Log.log("User home: "+System.getProperty("user.home")); + filters = new Vector(1); + } + Log.log("Adding debug filter: "+aFilter); + if (!filters.contains(aFilter)) { + filters.addElement(aFilter); + } + if (aFilter.equalsIgnoreCase(Debug.HELP_FILTER_STRING)) { + Log.log("Set one or more debug filters (usually possible from the commandling), then simply wrap your debug code in a test for a particular debug filter, and only execute the code if that filter has been set."); + Log.log("Predifined debug filters:"); + Log.log(" HELP [prints this info]"); + Log.log(" ALL [causes all calls to \"containsFilter()\" to return \"true\", effectively enabling all filters]"); + Log.log(" TIMING [causes all timing messages generated by this class to print]"); + } + } else { + throw new IllegalArgumentException("null filter passed to addFilter()"); + } + } + + /** + * Removes the specified filter from the list of filters. + */ + static public synchronized void removeFilter(String aFilter) { + if (filters != null) { + filters.removeElement(aFilter); + } + } + + /** + * Removes all filters from the list of filters. + */ + static public synchronized void removeAllFilters() { + if (filters != null) { + filters.removeAllElements(); + } + } + + /** + * Look for any "filter" with the specified prefix. + * + * "ALL" is not considered to be a match. + * + * This method works in (normally) O-n time (if no match). + */ + + static public synchronized boolean containsFilterWithPrefix(String aFilterPrefix) { + boolean returnValue = false; + + if (Debug.filters != null) { + Enumeration filterEnumeration = Debug.filters.elements(); + + while (!returnValue && filterEnumeration.hasMoreElements()) { + String aFilter = (String)filterEnumeration.nextElement(); + + if (aFilter.startsWith(aFilterPrefix)) { + returnValue = true; + } + } + } + return returnValue; + } + + /** + * Funnel-point method, which takes a filter and an "allFiltersgMatchThisString" string. + * See the javadoc for "containsFilter(String aFilter)" for the rest of what this method + * does. + * + * This method works in (normally) O-1 time. + * + * NOTE: The "allFiltersgMatchThisString" parameter can be used to conditionally execute + * code while preventing the "ALL" filter from having any effect. So, the conditional code + * should use the test "if (Debug.containsFilter("SomeFilter", ""))" to see if a filter + * has been set, and not get a false positive from the "ALL" filter. + */ + static public synchronized boolean containsFilter(String aFilter, String allFiltersgMatchThisString) { + if (((aFilter != null) && ((filters != null) && filters.contains(aFilter))) + || ((filters != null) && filters.contains(allFiltersgMatchThisString)) + || (aFilter != null) && aFilter.equals("")) { + return true; + } else { + return false; + } + } + + /** + * Returns true if any of the following conditions are true: + * 1. The specified filter is contained in the current filter set. + * 2. The "ALL" filter is set (this is true even if the passed-in filter is "null"). + * 3. The passed-in filter is ""... as that filter is considered + * to always be a match, regardless of the current filter set. + * 4. The passed in filter is "null" and the "ALL" filter is currently set. + * Otherwise returns false. + * + * NOTE: This method, and all filtering of this class is case-sensitive. + */ + static public synchronized boolean containsFilter(String aFilter) { + return Debug.containsFilter(aFilter, Debug.ALL_FILTER_STRING); + } + + // Only used by the timing routines, since they ignore "ALL", but pay attention to + // "TIMING". + static private synchronized boolean containsTimingFilter(String aFilter) { + return Debug.containsFilter(aFilter, Debug.TIMING_FILTER_STRING); + } + + static private synchronized void maybeShowColumnHelp() { + if (!showedColumnTitleHelp) { + Log.enableTimestampPrefix(false); + Log.logErrorMessage("************************:"); + Log.logErrorMessage("Debugging time codes:"); + Log.logErrorMessage(" etset=elapsed time since elapsed time (since the previous elapsedTime() call)"); + Log.logErrorMessage(" etsst=elapsed time since start time (since the previous startTime() call)"); + Log.logErrorMessage(" etsit=elapsed time since initialization time (typically since the program was launched)"); + Log.logErrorMessage("************************:"); + showedColumnTitleHelp = true; + Log.enableTimestampPrefix(false); + } + } + + // We don't use Log's debugging logging methods for a few reasons: + // - They check for filters, but we've already had to check ourselves because of the + // "TIMING" filter, so we don't want to waste time checking again. + // - It doesn't know about "TIMING", so if the filter was null, it would assume that + // "ALL" was set, not "TIMING". + // - We need to add a suffix to the "baseName" of the filter that we deduce, and Log + // doesn't want to provide such a method ('cause it would be gross :-)) + // - We don't want the time and day stamp on each message, and though we could disable + // that around each call to Log's debugMessage stuff, that's pretty gross. + static private synchronized void logTimingMessageString(String debugMessage, String debugFilter) { + String filterString; + + if (debugFilter == null) { + if (Debug.containsFilter(Debug.TIMING_FILTER_STRING)) { + filterString = Debug.TIMING_FILTER_STRING; + } else { + // Quiets compiler... If we're here, we should always be able to set it below. + filterString = "UNMATCHED FILTER"; + } + } else if (debugFilter.equals("")) { + filterString = "ANY"; + } else { + filterString = debugFilter; + } + String baseStr = Log.getApplicationName(); + if ( baseStr == null) { + System.err.println("["+filterString+"]: "+ debugMessage); + System.err.flush(); + } + else { + System.err.println(baseStr + "["+filterString+"]: "+ debugMessage); + System.err.flush(); + } + } + + /** + * Starts a timer which can be stopped using one of the "stopTiming()" methods. + * + * This method does not check debug filters... it always does what it's told. + * + * Calling this method resets the elapsed time ("lap time"). + */ + static public synchronized void startTiming() { + startTime = new Date().getTime(); + lapTime = startTime; + } + + /** + * Identical to the "startTiming(String logMessage, String aFilter)" method, except it + * will only show the message if the filter "TIMING" exists in Debug's filter list. + */ + static public synchronized void startTiming(String logMessage) { + Debug.startTiming(logMessage, Debug.TIMING_FILTER_STRING); + } + + /** + * This method does absolutely nothing unless: + * 1. The specified filter is contained in the current filter set. + * 2. The "TIMING" filter is set (this is true even if the passed-in filter is "null"). + * 3. The passed-in filter is ""... as that filter is considered + * to always be a match, and so will cause this method to always work, + * regardless of the current filter set. + * NOTE: The "ALL" filter has no effect on timing methods. + * + * Otherwise, starts a timer which can be stopped using one of the "stopTiming()" methods + * and prints out a logMessage indicating that timing has begun. + * + * This method may be called with a "null" logMessage. A logMessage is sometimes + * unneccesary since the matched filter string is printed with the output anyway, and that + * is frequently enough information. + * + * Calling this method resets the elapsed time ("lap time"). + */ + static public synchronized void startTiming(String logMessage, String aFilter) { + if (Debug.containsTimingFilter(aFilter)) { + if (logMessage == null) { + logMessage = ""; + } else { + logMessage = " ["+logMessage+"]";; + } + Debug.maybeShowColumnHelp(); + Debug.startTiming(); + Debug.logTimingMessageString("Resetting start time at etsit of: "+Debug.formatTime(Debug.elapsedTimeSinceInitialization())+logMessage, aFilter); + } + } + + static private synchronized long elapsedTime(long startTime) { + lapTime = new Date().getTime(); + + return lapTime - startTime; // "lapTime" happens to be currTime right now! + } + + /** + * Returns the elapsed time since this class was initialized. + * + * This method does not check debug filters... it always does what it's told. + * + * Calling this method resets the elapsed time ("lap time"). + * + * This method may be called repeatedly to get "lap" times. + */ + static public synchronized long elapsedTimeSinceInitialization() { + return Debug.elapsedTime(initializationTime); + } + + /** + * Returns the elapsed time since the preceeding startTiming() call, + * + * This method does not check debug filters... it always does what it's told. + * + * Calling this method resets the elapsed time ("lap time"). + * + * This method may be called repeatedly to get "lap" times. + */ + static public synchronized long elapsedTimeSinceStartTime() { + if (startTime == 0) { + return 0L; // "startTime()" was never called. + } else { + return Debug.elapsedTime(startTime); + } + } + + /** + * Returns the elapsed time since this class was initialized. + * + * This method does not check debug filters... it always does what it's told. + * + * Calling this method resets the elapsed time ("lap time"). + * + * This method may be called repeatedly to get "lap" times. + */ + static public synchronized long elapsedTimeSinceElapsedTime() { + if (lapTime == 0) { + return 0L; // "elapsedTimeXXX()" was never called. + } else { + return Debug.elapsedTime(lapTime); + } + } + + /** + * Identical to the "elapsedTime(String logMessage, String aFilter)" method, except it + * will only show the message if the filter "TIMING" exists in Debug's filter list. + */ + static public synchronized void elapsedTime(String logMessage) { + Debug.elapsedTime(logMessage, Debug.TIMING_FILTER_STRING); + } + + /** + * This method does absolutely nothing unless: + * 1. The specified filter is contained in the current filter set. + * 2. The "TIMING" filter is set (this is true even if the passed-in filter is "null"). + * 3. The passed-in filter is ""... as that filter is considered + * to always be a match, and so will cause this method to always work, + * regardless of the current filter set. + * NOTE: The "ALL" filter has no effect on timing methods. + * + * Otherwise, prints the following information: + * 1. The elapsed time since initialization of this class. + * 2. The elapsed time since the preceeding startTiming() call. + * 3. The "lap" time, since the last time "elapsedTime()" was called. + * 4. A client-supplied message. + * + * When a filter matches, this method invokes the following methods: + * elapsedTime() + * elapsedTimeSinceInitialization() + * elapsedTimeSinceElapsedTime() + * + * When a filter matches, calling this method resets the elapsed time ("lap time"). + * + * + * This method may be called with a "null" logMessage. A logMessage is sometimes + * unneccesary since the matched filter string is printed with the output anyway, and that + * is frequently enough information. + * + * This method may be called repeatedly to get "lap" times. + */ + static public synchronized void elapsedTime(String logMessage, String aFilter) { + if (Debug.containsTimingFilter(aFilter)) { + if (logMessage == null) { + logMessage = ""; + } else { + logMessage = " ["+logMessage+"]";; + } + Debug.maybeShowColumnHelp(); + Debug.logTimingMessageString("etset: "+Debug.formatTime(Debug.elapsedTimeSinceElapsedTime())+" etsst: "+Debug.formatTime(Debug.elapsedTimeSinceStartTime())+" etsit: "+Debug.formatTime(Debug.elapsedTimeSinceInitialization())+logMessage, aFilter); + } + } + + /** + * format end - start to sec.millisec + */ + static private synchronized String formatTime(long milliseconds) { + String d1000sStr = String.valueOf( milliseconds % 1000); + int len = d1000sStr.length(); + return String.valueOf(milliseconds / 1000)+"."+ + "000".substring(len) + d1000sStr; + } + + /** + * format time to %4u%03u so that the decimal points will align + */ + private static synchronized String formatTimeAligned(long milliseconds) { + long deltaSecs = milliseconds / 1000; + String dSecsStr = null; + if ( deltaSecs == 0) + dSecsStr = " "; + else { + dSecsStr = String.valueOf( deltaSecs); + int len = dSecsStr.length(); + dSecsStr = " ".substring( len) + dSecsStr; + } + + String d1000sStr = String.valueOf( milliseconds % 1000); + int len = d1000sStr.length(); + return dSecsStr + "." + "000".substring(len) + d1000sStr; + } + + /** + * Print time since start of app, and time since the last time this method + * was called. + * Call this with a msg you want printed, and a filter. Then + * run with -jsdebug filter and all these timing msgs will come out. + */ + static public synchronized void printTime( String msg, String aFilter) { + if ( filters != null && filters.contains( aFilter)) { + long curTime = System.currentTimeMillis(); + System.out.println( formatTimeAligned( curTime - + initializationTime) + " " + + formatTimeAligned( curTime - lastTime) + " " + + msg); + System.out.flush(); + lastTime = curTime; + } + } + + /** + * Returns a String containing the hexadecimal hashCode of the passed in object, + * of the form: "0x0000" + */ + static public synchronized String getHashCode(Object anObject) { + String returnValue; + + if (anObject == null) { + returnValue = "0x0000"; + } else { + returnValue = "0x"+Integer.toHexString(anObject.hashCode()); + } + return returnValue; + } + + /** + * Returns a String containing the class name and hexadecimal hashCode of the + * passed in object, of the form: "fully.qualified.ClassName[0x0000]" + */ + static public synchronized String getNameAndHashCode(Object anObject) { + String returnValue; + + if (anObject == null) { + returnValue = "[0x0000]"; + } else { + returnValue = anObject.getClass().getName()+"["+Debug.getHashCode(anObject)+"]"; + } + return returnValue; + } +} // End of class Debug diff --git a/mozilla/java/util/classes/org/mozilla/util/Log.java b/mozilla/java/util/classes/org/mozilla/util/Log.java new file mode 100644 index 00000000000..525088af9b1 --- /dev/null +++ b/mozilla/java/util/classes/org/mozilla/util/Log.java @@ -0,0 +1,229 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 "The Lighthouse Foundation Classes (LFC)" + * + * The Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + +package org.mozilla.util; + +import java.util.Date; + +/** + *

+ * Log + *

+ * @author Keith Bernstein + * @version $Id: Log.java,v 1.1 1999-07-30 01:02:57 edburns%acm.org Exp $ + */ + +public class Log extends Object { + static String applicationName = "APPLICATION NAME UNKNOWN [call setApplicationName() from main]"; + static String applicationVersion = "APPLICATION VERSION UNKNOWN [call setApplicationVersion() from main]"; + static String applicationVersionDate = "APPLICATION VERSION DATE UNKNOWN [call setApplicationVersionDate() from main]"; + static int showTimestampPrefix = 1; + + /** + * This string will be prepended to all output from this class. + * + * This string is usually the application name, e.g. "JavaPlan". + * + * It is useful because it includes a timestamp and the base string (usually the + * application name), so that if two apps are launched from the same commandline + * (for example), with "&", or one app invokes another, it is clear who the message + * is comming from. The time stamp can help see how long operations took, etc. + * + * If you don't want your messages prefixed with anything (no time stamp or name), you must + * pass "null" for "applicationName". + * + * If this method is never called, "applicationName" will default to: + * "APPLICATION NAME UNKNOWN [call setApplicationName from main]" + * + */ + static public synchronized void setApplicationName(String newApplicationName) { + // It's really unfortunate that we can't discover this dynamically. + applicationName = newApplicationName; + } + + /** + * Returns the applicationName set by "setApplicationName()" + * + */ + static public synchronized String getApplicationName() { + // It's really unfortunate that we can't discover this dynamically. + return applicationName; + } + + static public synchronized void setApplicationVersion(String newApplicationVersion) { + // It's really unfortunate that we can't discover this dynamically. + applicationVersion = newApplicationVersion; + } + + /** + * Returns the applicationVersion set by "setApplicationVersion()" + * + */ + static public synchronized String getApplicationVersion() { + // It's really unfortunate that we can't discover this dynamically. + return applicationVersion; + } + + static public synchronized void setApplicationVersionDate(String newApplicationVersionDate) { + // It's really unfortunate that we can't discover this dynamically. + applicationVersionDate = newApplicationVersionDate; + } + + /** + * Returns the applicationVersion set by "setApplicationVersionDate()" + * + */ + static public synchronized String getApplicationVersionDate() { + // It's really unfortunate that we can't discover this dynamically. + return applicationVersionDate; + } + + static protected synchronized Object applicationNameWithTimeStamp() { + String timestampPrefix; + + if (showTimestampPrefix > 0) { + timestampPrefix = "["+new Date()+"] "; + } else { + timestampPrefix = ""; + } + if (applicationName != null) { + return timestampPrefix+Log.getApplicationName(); + } else { + return timestampPrefix; + } + } + + /** + * Incrememnts or decrements whether or not to prefix logged messages with a timestamp. + * Two (or "n") calls with a value of "false" must be followed by two (or "n") calls + * with a value of "true" to reenable timestamp prefixes. + */ + static public synchronized void enableTimestampPrefix(boolean enable) { + if (enable) { + showTimestampPrefix++; + } else { + showTimestampPrefix--; + } + } + + /** + * Writes "infoMessage" to stdout, prefixed by the string "ApplicationName: " + */ + static public synchronized void log(Object infoMessage) { + System.out.println(Log.applicationNameWithTimeStamp()+": "+infoMessage); + System.out.flush(); + } + + /** + * Writes "errorMessage" to stderr, prefixed by the string "ApplicationName error: " + */ + static public synchronized void logError(Object errorMessage) { + System.err.println(Log.applicationNameWithTimeStamp()+" error: "+errorMessage); + System.err.flush(); + } + + /** + * Writes "errorMessage" to stderr, prefixed by the string "ApplicationName: " + */ + static public synchronized void logErrorMessage(Object errorMessage) { + System.err.println(Log.applicationNameWithTimeStamp()+": "+errorMessage); + System.err.flush(); + } + + static private synchronized void logErrorMessage(String baseNameSuffixString, Object errorMessage) { + System.err.println(Log.applicationNameWithTimeStamp()+baseNameSuffixString+": "+errorMessage); + System.err.flush(); + } + + /** + * Funnel-point method for printing debug messages. + * + * Writes "debugMessage" to stderr, prefixed by the string "ApplicationName:" + * + * This method only works if the debugFilter string is found in Debug's list of + * filter strings (which you can normally set on the commandline, see JDApplication), + * or if the "ALL" filter has been set into Debug's list of filters, or if the passed + * in filter is "", which is considered to always be "set", and will print a line with + * "[DEBUG]" listed as the filter. + * + * This method may be called with a "null" debugMessage. A debugMessage is sometimes + * unneccesary since the matched filter string is printed with the output anyway, and that + * is frequently enough information. + */ + static public synchronized void logDebugMessage(Object debugMessage, String debugFilter) { + if (Debug.containsFilter(debugFilter)) { + String filterString; + + if (debugFilter == null) { + if (Debug.containsFilter(Debug.ALL_FILTER_STRING)) { + filterString = Debug.ALL_FILTER_STRING; + } else { + // Quiets compiler... If we're here, we should always be able to set it below. + filterString = "UNMATCHED FILTER"; + } + } else if (debugFilter.equals("")) { + filterString = "DEBUG"; + } else { + filterString = debugFilter; + } + Log.logErrorMessage("["+filterString+"]", debugMessage); + } + } + + /** + * Equivalent to calling "logDebugMessage(debugMessage, "ALL")". + */ + static public synchronized void logDebugMessage(Object debugMessage) { + logDebugMessage(debugMessage, "ALL"); + } + + /** + * Log a message when "aCondition" is true, otherwise be silent. + * Equivalent to calling "if (aCondition) logDebugMessage(debugMessage, "")". + */ + static public synchronized void logDebugMessage(Object debugMessage, boolean aCondition) { + if (aCondition) { + Log.logDebugMessage(debugMessage, ""); + } + } + + /** + * Log a message when "aCondition" is true, otherwise be silent. + */ + static public synchronized void logDebugMessage(Object anInstance, Object debugMessage, boolean aCondition) { + if (aCondition) { + Log.logDebugMessage(Debug.getNameAndHashCode(anInstance)+": "+debugMessage, ""); + } + } + + /** + * Equivalent to calling "logDebugMessage(anInstance, debugMessage, "ALL")". + */ + static public synchronized void logDebugMessage(Object anInstance, Object debugMessage) { + Log.logDebugMessage(anInstance, debugMessage, "ALL"); + } + + /** + * Writes "debugMessage" to stderr, prefixed by the string "ApplicationName: ClassName[0xhashCode]: " * + */ + static public synchronized void logDebugMessage(Object anInstance, Object debugMessage, String debugFilter) { + Log.logDebugMessage(Debug.getNameAndHashCode(anInstance)+": "+debugMessage, debugFilter); + } +} // End of class Log diff --git a/mozilla/java/util/classes/org/mozilla/util/ParameterCheck.java b/mozilla/java/util/classes/org/mozilla/util/ParameterCheck.java new file mode 100644 index 00000000000..93dd80d208b --- /dev/null +++ b/mozilla/java/util/classes/org/mozilla/util/ParameterCheck.java @@ -0,0 +1,372 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 "The Lighthouse Foundation Classes (LFC)" + * + * The Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + +package org.mozilla.util; + +/** + * ParameterCheck provides convenient means for parameter + * checking. Class methods in the ParameterCheck class can be + * used to verify that method parameters meet certain conditions and to + * raise exceptions if the conditions are not met.

+ * + * Typical usage: + *

+ * ParameterCheck.nonNull(myParameter); + *

+ * + * This verifies that myParameter is not null, throwing an + * IllegalArgumentException if it is.

+ * + * ParameterCheck is intended specifically for checking parameters; + * for general condition and invariant testing, use Assert. + * + * @version $Id: ParameterCheck.java,v 1.1 1999-07-30 01:02:58 edburns%acm.org Exp $ + * @author The LFC Team (Rob Davis, Paul Kim, Alan Chung, Ray Ryan, etc) + * @author David-John Burrowes (he moved it to the AU package) + * @see Assert + */ +final public class ParameterCheck extends Object { + /** + * The RCSID for this class. + */ + private static final String RCSID = + "$Id: ParameterCheck.java,v 1.1 1999-07-30 01:02:58 edburns%acm.org Exp $"; + + /** + * Private constructor prevents instances of this class from being + * created. + */ + private ParameterCheck() { + } + + /** + * Throws IllegalArgumentException if 'anObject' is null; otherwise, does + * nothing. + * + * @param anObject value to verify as non-null + * @exception IllegalArgumentException if 'anObject' is null + */ + static public void nonNull(Object anObject) { + if (anObject == null) { + throw new IllegalArgumentException("Object is null"); + } + } + + /** + * Throws IllegalArgumentException if 'aString' is null or if + * 'aString' is an empty string; otherwise, does nothing. + * + * @param aString string to verify as non-null and not empty + * @exception IllegalArgumentException if 'aString' is null or empty + */ + static public void notEmpty(String aString) { + if (aString == null) { + throw new IllegalArgumentException("String is null"); + } + else if (aString.equals("")) { + throw new IllegalArgumentException("String is empty"); + } + } + + /** + * Throws RangeException if 'anInt' is less than 'minimum'; otherwise, + * does nothing. + * + * @param anInt value to verify as not less than 'minimum' + * @param minimum smallest acceptable value for 'anInt' + * @exception RangeException if 'anInt' is less than 'minimum' + */ + static public void noLessThan(int anInt, int minimum) { + if (anInt < minimum) { + throw new RangeException("Value " + anInt + + " is out of range. It is should be no less than " + minimum); + } + } + + /** + * Throws RangeException if 'anInt' is not greater than 'minimum'; + * otherwise, does nothing. + * + * @param anInt value to verify as greater than 'minimum' + * @param minimum largest unacceptable value for 'anInt' + * @exception RangeException if 'anInt' is not greater than 'minimum' + */ + static public void greaterThan(int anInt, int minimum) { + if (anInt <= minimum) { + throw new RangeException ("Value " + anInt + + " is out of range. It should be greater than " + minimum); + } + } + + /** + * Throws RangeException if 'anInt' is greater than 'maximum'; otherwise, + * does nothing. + * + * @param anInt value to verify as not greater than 'maximum' + * @param maximum largest acceptable value for 'anInt' + * @exception RangeException if 'anInt' is greater than 'maximum' + */ + static public void noGreaterThan(int anInt, int maximum) { + if (anInt > maximum) { + throw new RangeException ("Value " + anInt + "is out of " + + "range. It should be no greater than " + maximum); + } + } + + /** + * Throws RangeException if 'anInt' is not less than 'maximum'; + * otherwise, does nothing. + * + * @param anInt value to verify as less than 'minimum' + * @param maximum smallest unacceptable value for 'anInt' + * @exception RangeException if 'anInt' is not less than 'maximum' + */ + static public void lessThan(int anInt, int maximum) { + if (anInt >= maximum) { + throw new RangeException ("Value " + anInt + + " is out of range. " + + "It should be less than " + maximum); + } + } + + /** + * Throws RangeException if 'aDouble' is less than 'minimum'; otherwise, + * does nothing. + * + * @param aDouble value to verify as not less than 'minimum' + * @param minimum smallest acceptable value for 'aDouble' + * @exception RangeException if 'aDouble' is less than 'minimum' + */ + static public void noLessThan(double aDouble, double minimum) { + if (aDouble < minimum) { + throw new RangeException ("Value " + aDouble + + " is out of range. " + + "It should be no less than " + minimum); + } + } + + /** + * Throws RangeException if 'aDouble' is not greater than 'minimum'; + * otherwise, does nothing. + * + * @param aDouble value to verify as greater than 'minimum' + * @param minimum largest unacceptable value for 'aDouble' + * @exception RangeException if 'aDouble' is not greater than 'minimum' + */ + static public void greaterThan(double aDouble, double minimum) { + if (aDouble <= minimum) { + throw new RangeException ("Value " + aDouble + + " is out of range. " + + "It should be greater than " + minimum); + } + } + + /** + * Throws RangeException if 'aDouble' is greater than + * 'maximum'; otherwise, does nothing. + * + * @param aDouble value to verify as not greater than 'maximum' + * @param maximum largest acceptable value for 'aDouble' + * @exception RangeException if 'aDouble' is greater than 'maximum' + */ + static public void noGreaterThan(double aDouble, double maximum) { + if (aDouble > maximum) { + throw new RangeException ("Value " + aDouble + + " is out of range. " + + "It should be no greater than " + maximum); + } + } + + /** + * Throws RangeException if 'aDouble' is not less than 'maximum'; + * otherwise, does nothing. + * + * @param aDouble value to verify as less than 'minimum' + * @param maximum smallest unacceptable value for 'aDouble' + * @exception RangeException if 'aDouble' is not less than 'maximum' + */ + static public void lessThan(double aDouble, double maximum) { + if (aDouble >= maximum) { + throw new RangeException ("Value " + aDouble + + " is out of range. It should be less than " + maximum); + } + } + + /** + * Throws RangeException if 'anInt' is less than 'minimum' or greater + * than 'maximum'; otherwise, does nothing. + * + * @param anInt value to verify as not greater than 'maximum' and + * not less than 'minimum' + * @param minimum smallest acceptable value for 'anInt' + * @param maximum largest acceptable value for 'anInt' + * @exception RangeException if 'anInt' is less than 'minimum' or + * greater than 'maximum' + */ + static public void withinRange(int anInt, int minimum, int maximum) { + ParameterCheck.noLessThan(anInt, minimum); + ParameterCheck.noGreaterThan(anInt, maximum); + } + + /** + * Throws RangeException if 'aDouble' is less than 'minimum' or greater + * than 'maximum'; otherwise, does nothing. + * + * @param aDouble value to verify as not greater than 'maximum' and + * not less than 'minimum' + * @param minimum smallest acceptable value for 'aDouble' + * @param maximum largest acceptable value for 'aDouble' + * @exception RangeException if 'aDouble' is less than 'minimum' or + * greater than 'maximum' + */ + static public void withinRange(double aDouble, double minimum, + double maximum) { + ParameterCheck.noLessThan(aDouble, minimum); + ParameterCheck.noGreaterThan(aDouble, maximum); + } + + + /** + * Throws RangeException if 'anInt' is not within 'aRange'; otherwise, + * does nothing. + * + * @param anInt value to verify as within 'aRange' + * @param aRange acceptable range for 'anInt' + * @exception RangeException if 'anInt' is not within 'aRange' + */ + static public void withinRange(int anInt, Range aRange) { + if (!aRange.containsIndex(anInt)) { + throw new RangeException ("Value " + anInt + + " should be in range " + aRange); + } + } + + + /** + * Throws RangeException if 'anInt' is not within a sequence that starts + * at 0 and has a length of 'count'; otherwise does nothing. + * + * (e.g. withinCount(myInt, array.length) will verify that 'myInt' is not + * less than 0 and not greater than 'array.length'-1) + * + * @param anInt value to verify as between 0 and 'count' - 1, inclusive + * @param count length of sequence + * @exception RangeException if 'anInt' is out of bounds + */ + static public void withinCount(int anInt, int count) { + ParameterCheck.withinRange(anInt, 0, count-1); + } + + + /** + * Throws RangeException if 'aRange' is not completely between 'minimum' + * and 'maximum', inclusive; otherwise, does nothing. + * + * @param aRange range to verify as between 'minimum' and 'maximum' + * @param minimum smallest acceptable index in 'aRange' + * @param maximum largest acceptable index in 'aRange' + * @exception RangeException if 'aRange' is out of bounds + */ + static public void rangeWithinBounds(Range aRange, int minimum, + int maximum) { + if (aRange.getStart() < minimum) { + throw new RangeException ("Range " + aRange + + " should not contain indices less than " + + minimum); + } + + if (aRange.getEnd() > maximum) { + throw new RangeException ("Range " + aRange + + " should not contain indices greater than " + + maximum); + } + } + + /** + * Throws RangeException if 'aRange' is not completely within a sequence + * that starts at 0 and has a length of 'count'; otherwise does nothing. + * + * (e.g. rangeWithinCount(range, array.length) will verify that 'range' + * does not start before 0 and does not end after 'array.length'-1). + * + * @param aRange range to verify as between 0 and 'count' - 1, inclusive + * @param count length of sequence + * @exception RangeException if 'aRange' is out of bounds + */ + static public void rangeWithinCount(Range aRange, int count) { + ParameterCheck.rangeWithinBounds(aRange, 0, count-1); + } + + /** + * Checks a string and a range which is intended to indicate a substring. + * Throws IllegalArgumentException if either argument is null. Throws + * RangeException if aRange does not indicate a valid substring of + * aString. + * + * @param aRange A range which must be contained within + * the string. + * @param aString A string to use for verifying the range. + * @exception IllegalArgumentException if either argument is null + * @exception RangeException if the range is not contained + * within the string + */ + static public void rangeWithinString(Range aRange, String aString) { + ParameterCheck.nonNull(aString); + ParameterCheck.nonNull(aRange); + + if (aRange.getStart() < 0) { + throw new RangeException("Range has negative start"); + } + if(aRange.getMax() > aString.length()) { + throw new RangeException("Range extends beyond end of String"); + } + } + + /** + * Throws IllegalArgumentException if 'generalTest' is false; otherwise, + * does nothing. 'message' will be the message of the exception. 'message' + * may be null, but use of a meaningful message is recommended. + * + * @param generalTest value to verify as true + * @param message message describing the failure + * @exception IllegalArgumentException if 'generalTest' is false + * @see #isFalse(boolean generalTest, String message) + */ + static public void isTrue(boolean generalTest, String message) { + if (!generalTest) { + throw new IllegalArgumentException(message); + } + } + + /** + * Identical to isTrue, except the test is inverted. + * + * @param generalTest value to verify as false + * @param message message describing the failure + * @exception IllegalArgumentException if 'generalTest' is false + * @see #isTrue(boolean generalTest, String message) + */ + static public void isFalse(boolean generalTest, String message) { + if (generalTest) { + throw new IllegalArgumentException(message); + } + } + +} // End of class ParameterCheck diff --git a/mozilla/java/util/classes/org/mozilla/util/Range.java b/mozilla/java/util/classes/org/mozilla/util/Range.java new file mode 100644 index 00000000000..d35d3e7c5b1 --- /dev/null +++ b/mozilla/java/util/classes/org/mozilla/util/Range.java @@ -0,0 +1,467 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 "The Lighthouse Foundation Classes (LFC)" + * + * The Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + +package org.mozilla.util; + +import java.io.Serializable; +import java.lang.Cloneable; +import java.lang.Math; + +/** + * An Range is an object representing a range of integer values. A + * range has a start index and a count. The count must be greater than or + * equal to 0. Instances of this class are immutable, but subclasses may + * introduce mutability. A mutable range will return true from + * isMutable(). + * + * @version $Id: Range.java,v 1.1 1999-07-30 01:02:58 edburns%acm.org Exp $ + * @author The LFC Team (Rob Davis, Paul Kim, Alan Chung, Ray Ryan, etc) + * @author David-John Burrowes (he moved it to the AU package) + * @see Range#isMutable() + * + */ + +public class Range extends Object implements Cloneable, Serializable { + + // + // STATIC VARIABLES + // + + /** + * The RCSID for this class. + */ + private static final String RCSID = + "$Id: Range.java,v 1.1 1999-07-30 01:02:58 edburns%acm.org Exp $"; + + /** + * A zero range + */ + static public final Range ZeroRange = new Range(-1, 0); + + // + // Instance Variables + // + + /** + * The start index of the range + */ + protected int start; + + /** + * The length of the range + */ + protected int count; + + // + // Constructors + // + + /** + * Creates an instance of Range from another Range object + * otherRange which must be non-null. + * + * @param range the reference range to create this range from + * @exception IllegalArgumentException if otherRange is null + */ + public Range(Range otherRange) { + // + // Do our own construction rather than calling Range(int,int) + // because we want to be able to do the parameter check. There is + // another way that allows us to use the other constructor, but + // this class is too simple to be worth the exta work. + // + super(); + ParameterCheck.nonNull(otherRange); + + this.start = otherRange.getStart(); + this.count = otherRange.getCount(); + } + + /** + * Creates an instance of Range with a start index newStart and + * an extent newCount. newCount must be greater than or equal to + * 0. + * + * @param newStart the start index of the range + * @param newCount the number of elements in the range + * @exception RangeException if newCount is less than 0. + */ + public Range(int newStart, int newCount) { + super(); + + this.start = newStart; + this.count = newCount; + } + + // + // PROPERTY ACCESS + // + + /** + * Returns the start index of the range. + * + * @return the start index of this range + */ + public synchronized int getStart() { + return this.start; + } + + /** + * Returns the number of elements in this range. + * + * @return the number of elements in this range + */ + public synchronized int getCount() { + return this.count; + } + + /** + * Returns the the last index contained within the range. + * + * @return the end index of this range + */ + public synchronized int getEnd() { + return this.getStart() + this.getCount() - 1; + } + + /** + * Returns the max index (the index at start + count). + * + * @return the max index. + */ + public synchronized int getMax() { + return this.getStart() + this.getCount(); + } + + /** + * Returns a number guaranteed to be within this range, including + * endpoints + * + * @return a number within the range, including endpoints. + */ + protected int getConstrainedInt(int number) { + int rc; + + if (number < this.getStart()) { + rc = this.getStart(); + } + else { + if (number > this.getEnd()) { + rc = this.getEnd(); + } else { + rc = number; + } + } + return rc; + } + + // + // METHODS + // + + /** + * Returns true if and only if index lies within this range. + * Note that if the receiver is of zero length, then this method will return + * false. + * + * @return true if and only if and only if index lies within this + * range + */ + public synchronized boolean containsIndex(int index) { + if (this.getCount() == 0) { + return false; + } else { + return (index >= this.getStart()) && (index <= this.getEnd()); + } + } + + /** + * Returns true if and only if the start index of this range is + * greater than index. + * + * @return true if and only if the start index of this range is + * greater than index + */ + public synchronized boolean isAfterIndex(int index){ + return (this.getStart() > index); + } + + + /** + * Return true if and only if the end index of this range is less than + * index. + * + * @return true if and only if the end index of this range is less than + * index + */ + public synchronized boolean isBeforeIndex(int index) + { + return (this.getEnd() < index); + } + + /** + * Returns true if and only if every element in otherRange is contained + * in this range. If the receiver is a zero length range, then + * this method will return false. Note that containment can apply to + * zero length ranges; a non-zero-length range contains any zero-length + * range. Contrast with range intersection. + * + * @see #intersectsWithRange(Range otherRange) + * @return true if and only if every element in otherRange is + * contained in this range + * @exception IllegalArgumentException if otherRange is null + * + */ + public synchronized boolean containsRange (Range otherRange) + { + ParameterCheck.nonNull(otherRange); + + if (this.getCount() == 0) { + return false; + } else if (otherRange.getCount() == 0) { + return true; + } + return ((this.getStart() <= otherRange.getStart()) && + (this.getEnd() >= otherRange.getEnd())); + } + + /** + * Returns true if and only if otherRange intersects with this range. A + * zero-length range intersects with no range. + * + * @return true if and only if otherRange intersects with this range + * @exception IllegalArgumentException if otherRange is null + * + */ + public synchronized boolean intersectsWithRange(Range otherRange) { + return this.overlapWithRange(otherRange) > 0; + } + + /** + * Returns the number of elements that are in both this range and + * otherRange. A zero-length range has no overlapping elements + * with any range. + * + * @param a range to check overlaps with this range + * @exception IllegalArgumentException if otherRange is null + * @return number of elements in both this range and otherRange + */ + public synchronized int overlapWithRange(Range otherRange) { + if (this.getCount() == 0 || otherRange.getCount() == 0) { + return 0; + } else { + return Math.max(0, (Math.min(this.getEnd(), otherRange.getEnd()) - + Math.max(this.getStart(), + otherRange.getStart())) + 1); + } + } + + /** + * Returns true if and only if otherRange is adjacent to this range; + * two ranges are adjacent if the max of one range is equal to the start of + * the other. A zero length range is adjacent to no range. + * + * @return true if and only if otherRange is adjacent to this range + * @exception IllegalArgumentException if otherRange is null + */ + public synchronized boolean isAdjacentToRange(Range otherRange) { + ParameterCheck.nonNull(otherRange); + + if (this.getCount() == 0 || otherRange.getCount() == 0) { + return false; + } + return (Math.max(this.getStart(), otherRange.getStart()) == + (Math.min(this.getEnd(), otherRange.getEnd()) + 1)); + } + + /** + * + * Returns true if and only if this range is before otherRange + * and the two ranges do not overlap. + * + * @return true if and only if this range is before otherRange + * and the two ranges do not overlap. + * @exception IllegalArgumentException if otherRange is null + */ + public synchronized boolean isBeforeRange(Range otherRange) { + ParameterCheck.nonNull(otherRange); + + if (this.getEnd() < otherRange.getStart()) { + return true; + } else { + return false; + } + } + + /** + * + * Returns true if this range is after otherRange and the two + * ranges do not overlap. + * + * @return true if this range is after otherRange and the two + * ranges do not overlap. + * @exception IllegalArgumentException if otherRange is null + */ + protected boolean isAfterRange(Range otherRange) { + ParameterCheck.nonNull(otherRange); + + return otherRange.isBeforeRange(this); + } + + + /** + * Returns the intersection of this range and otherRange. If the + * ranges do not intersect then Range.ZeroRange is returned. + * Note that a zero length range has no intersection with a non-zero + * length range. + * + * @return the intersection of this range and otherRange + * @exception IllegalArgumentException if otherRange is null + */ + public synchronized Range rangeFromIntersection(Range otherRange) { + ParameterCheck.nonNull(otherRange); + + if (this.intersectsWithRange(otherRange)) { + int newStart = Math.max(this.getStart(), otherRange.getStart()); + int newEnd = Math.min(this.getEnd(), otherRange.getEnd()); + return new Range(newStart, newEnd - newStart + 1); + } + return Range.ZeroRange; + } + + /** + * Returns the union of this range and otherRange. + * Returns the other range if one of them are zero length range. + * Returns Range.ZeroRange if both are zero length range.Note that the + * union of a non-zero length range with a zero length range is merely the + * non-zero length range. + * + * @return the union of this range and otherRange if both are + * non-zero range + * @exception IllegalArgumentException if otherRange is null + */ + public synchronized Range rangeFromUnion(Range otherRange) { + ParameterCheck.nonNull(otherRange); + Range retRange; + + int thisRangeCount = this.getCount(); + int otherRangeCount = otherRange.getCount(); + + if (thisRangeCount == 0 && otherRangeCount == 0) { + retRange = ZeroRange; + } else if (thisRangeCount == 0) { + retRange = new Range(otherRange); + } else if (otherRangeCount == 0) { + retRange = new Range(this); + } else { + int newStart; + int newEnd; + + newStart = Math.min(this.getStart(), otherRange.getStart()); + newEnd = Math.max(this.getEnd(), otherRange.getEnd()); + return new Range(newStart, newEnd - newStart + 1); + } + return retRange; + } + + /** + * Returns this range, with its start shifted by offset. + * + * @return this range, with its start offset by offset. + */ + public synchronized Range rangeShiftedByOffset(int offset) { + return new Range(this.getStart() + offset, this.getCount()); + } + + /** + * Returns a String representation of this Range. + * + * @return string representation of this range + */ + public synchronized String toString() { + return "start = " + this.getStart() + ", count = " + this.getCount(); + } + + + /** + * Returns true only if this instance can change after it is created.

+ * + * The default implementation returns false because instances of this + * class can't change; subclasses that introduce mutability should + * override this method to return true. + * + * @return true if and only if the range may change + */ + public boolean isMutable() { + return false; + } + + + /** + * Creates and returns an Range that is identical to this one. + * + * @return a reference to the immutable instance or + * a copy of the mutable instance + */ + public synchronized Object clone() { + if (this.isMutable()) { + Range newRange; + + try { + newRange = (Range)super.clone(); + } + catch (CloneNotSupportedException e) { + // Won't happen because we implement Cloneable + throw new InternalError(e.toString()); + } + return newRange; + } + else { + // No reason to clone an immutable object + return this; + } + } + + /** + * Returns true if and only if otherRange is an Range + * with the same start and count as this range. + * + * @return true if and only if otherRange equals this range + */ + public synchronized boolean equals(Object otherRange) { + return ((otherRange == this) || + ((otherRange != null) && + (otherRange instanceof Range) && + (this.getStart() == ((Range)otherRange).getStart()) && + (this.getEnd() == ((Range)otherRange).getEnd()))); + } + + /** + * Overridden because equals() is overridden. Returns a hash code + * that is based on the start and count of this range. + * + * @return a hash code based on the start index and count of this range + */ + public synchronized int hashCode() { + return Math.round(this.getStart()) ^ Math.round(this.getCount()); + } + +} // End of class Range + diff --git a/mozilla/java/util/classes/org/mozilla/util/RangeException.java b/mozilla/java/util/classes/org/mozilla/util/RangeException.java new file mode 100644 index 00000000000..4d4dc6945ea --- /dev/null +++ b/mozilla/java/util/classes/org/mozilla/util/RangeException.java @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 "The Lighthouse Foundation Classes (LFC)" + * + * The Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + +package org.mozilla.util; + +import java.lang.RuntimeException; + +/** + * An RangeException is an exception that is thrown when a value + * is outside of its acceptable range. + * + * @version $Id: RangeException.java,v 1.1 1999-07-30 01:02:58 edburns%acm.org Exp $ + * @author The LFC Team (Rob Davis, Paul Kim, Alan Chung, Ray Ryan, etc) + * @author David-John Burrowes (he moved it to the AU package) + */ +public class RangeException extends RuntimeException { + + // + // STATIC VARIABLES + // + + /** + * The RCSID for this class. + */ + private static final String RCSID = + "$Id: RangeException.java,v 1.1 1999-07-30 01:02:58 edburns%acm.org Exp $"; + + /** + * Constructs an exception with no error string. + */ + public RangeException() { + super(); + } + + /** + * Constructs an exception with an error string. + * + * @param message A message that will hopefully tell someone about the cause + * of this exception. + */ + public RangeException(String message) { + super(message); + } +} diff --git a/mozilla/java/util/classes/org/mozilla/util/Utilities.java b/mozilla/java/util/classes/org/mozilla/util/Utilities.java new file mode 100644 index 00000000000..5803379c795 --- /dev/null +++ b/mozilla/java/util/classes/org/mozilla/util/Utilities.java @@ -0,0 +1,285 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 "The Lighthouse Foundation Classes (LFC)" + * + * The Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + +package org.mozilla.util; + +import java.util.Date; +import java.util.Enumeration; +import java.util.Vector; +import java.util.StringTokenizer; +import java.util.ResourceBundle; +import java.util.MissingResourceException; + +import java.awt.Component; +import java.awt.Container; + + +public class Utilities extends Object { + // PENDING(kbern) NOTE: These Vector methods should eventually move into a file + // called "VectorUtilities", must like the already-existing "HashtableUtilities". + /** + * Take the given string and chop it up into a series + * of strings on "delimeter" boundries. This is useful + * for trying to get an array of strings out of the + * resource file. + */ + static public Vector vectorFromString(String input, String delimeter) { + Vector aVector = new Vector(); + StringTokenizer aTokenizer = new StringTokenizer(input, delimeter); + + while (aTokenizer.hasMoreTokens()) + aVector.addElement(aTokenizer.nextToken()); + return aVector; + } + + /** + * Creates a String by combining the elements of aVector. + * after each element it will insert the String "delimeter". + * If no "delimeter" is desired, the "delimeter" parameter should be "" + */ + static public String stringFromVector(Vector aVector, String delimeter) { + String returnString = null; + + if (aVector != null) { + Enumeration vectorEnumerator = aVector.elements(); + + if (delimeter == null) { + delimeter = ""; // Might as well be nice to sloppy caller! + } + while (vectorEnumerator.hasMoreElements()) { + if (returnString == null) { + returnString = ""; + } else { + returnString += delimeter; + } + returnString += vectorEnumerator.nextElement(); + } + } + return (returnString == null) ? "" : returnString; + } + + /** + * Convert an Array into a Vector. Can you *believe* that there is no Vector constructor + * which takes an Array!!! &()*&$#(*&$ + */ + static public Vector vectorFromArray(Object[] anArray) { + Vector returnVector; + + if ((anArray != null) && (anArray.length > 0)) { + returnVector = new Vector(anArray.length); + for (int i = anArray.length - 1; i >= 0; i--) { + returnVector.addElement(anArray[i]); + } + } else { + returnVector = new Vector(0); + } + return returnVector; + } + + /** + * Amazing that "Vector" does not override Object's "equals()" method to do this + * itself! + */ + static public boolean vectorsAreEqual(Vector vectorOne, Vector vectorTwo) { + boolean returnValue = vectorOne.equals(vectorTwo); // Give "Object" a chance. + + if (!returnValue && (vectorOne != null) && (vectorTwo != null)) { + int vectorSize = vectorOne.size(); + + if (vectorSize == vectorTwo.size()) { + int index; + + // "Object" says, "No", but maybe they really are... let's do the long check... + for (index = 0; index < vectorSize; index++) { + if (!(vectorOne.elementAt(index).equals(vectorTwo.elementAt(index)))) { + break; + } + } + if (index == vectorSize) { + // We made it to the end without "break"ing! They must be equal... + returnValue = true; + } + } // else, they're definately not equal! + } + return returnValue; + } + + /** + * Returns "true" if the passed in array contains the passed in element. + * Checks for equality using ".equals()". + * Returns "false" if "anArray" is null. + */ + static public boolean arrayContainsElement(Object[] anArray, Object anElement) { + boolean returnValue = false; + + if (anArray != null) { + for (int index = 0; (!returnValue && (index < anArray.length)); index++) { + if (anArray[index].equals(anElement)) { + returnValue = true; + } + } + } + return returnValue; + } + + /** + * Removes leading, trailing, and internal whitespace from the passed-in + * string. + * Returns a new string without any whitespace. + */ + static public String removeAllWhitespace(String aString) { + String returnString = aString; + + if (aString != null) { + returnString = aString.trim(); + Vector stringComponents = Utilities.vectorFromString(aString, " "); + + returnString = Utilities.stringFromVector(stringComponents, ""); + } + return returnString; + } + + /** + * Can return a string of the form "5:35:09pm", as opposed to "17:35:09" + * If "useTwentyFourHourTime" is "true", returns time in the form "17:35:09" + * If "showAMPMIndicator" is "true" it will include the "am" or "pm" text, + * otherwise it won't. + * Note that the "showAMPMIndicator" field is ignored if "useTwentyFourHourTime" is "true" + * since it provides redundant information in that case. + */ + static public String currentTimeString(boolean useTwentyFourHourTime, boolean showAMPMIndicator) { + // "ugly" is of the form, "17:35:09" + String returnString = new Date().toString().substring(11, 19); + + if (!useTwentyFourHourTime) { + Vector dateComponents = Utilities.vectorFromString(returnString, ":"); + try { + String ampmString; + int hourField = Integer.parseInt((String)(dateComponents.elementAt(0))); + + // Make it on 12 hour clock, with am and pm... + if (hourField > 12) { + // More common than == 12 + ampmString = "pm"; + hourField -= 12; + dateComponents.setElementAt(Integer.toString(hourField), 0); + returnString = Utilities.stringFromVector(dateComponents, ":"); + } else if (hourField == 12) { + ampmString = "pm"; + } else { + ampmString = "am"; + } + if (showAMPMIndicator) { + returnString += ampmString; + } + } catch (NumberFormatException anException) { + } + } + return returnString; + } + + /** + * Uses "getParent()" to find this Component's top-level ancestor. + * + * If this Component has no ancestors, this method will return the Component itself. + */ + static public Component getTopLevelParent(Component aComponent) { + Component returnComponent = aComponent; + + if (aComponent != null) { + Component testComponent = aComponent; + + do { + if (testComponent instanceof Container) { + returnComponent = testComponent; + testComponent = ((Container)testComponent).getParent(); + } else { + testComponent = null; + } + } while (testComponent != null); + } + return returnComponent; + } + + /** + * @param aClass the class whose package name should be returned + * + * @return the fully qualified package name of the given class, null + * if not found + */ + + static public String getPackageName(Class aClass) { + if (null == aClass) { + return null; + } + String baseName = aClass.getName(); + int index = baseName.lastIndexOf('.'); + return (index < 0 ? "" : baseName.substring(0, index+1)); + } + + /** + * + + * This method is a simpler alternative to + * ResourceLoader.loadResourceBundle. Instead of returning an + * PropertyResourceBundle, as ResourceLoader.loadResourceBundle + * does, it must returns a java.util.ResourceBundle + + * + * @param baseName the fully qualified name of the resource bundle, + * sans ".properties" suffix. For example, a + * valid value for baseName would be + * com.sun.jag.apps.spex.util.SUResources when the + * properties file SUResources.properties is in the + * classpath under the directory + * com/sun/jag/apps/spex/util. + * + * @return the actual ResourceBundle instance, or null if not found. + + * + + */ + + static public ResourceBundle getResourceBundle(String baseName) { + ResourceBundle resourceBundle = null; + try { + resourceBundle = ResourceBundle.getBundle(baseName); + } + catch (MissingResourceException e) { + Log.logError("Missing resource bundle: " + baseName); + } + return resourceBundle; + } + + /** + Case insensitive String.endsWith() + */ + public static boolean endsWithIgnoringCase(String aString, String possibleEnding) { + int endingLength; + if (aString == null || possibleEnding == null) + return false; + endingLength = possibleEnding.length(); + if (aString.length() < endingLength) + return false; + return aString.regionMatches(true, aString.length() - endingLength, + possibleEnding, 0, endingLength); + } +} + diff --git a/mozilla/java/webclient/Makefile.win b/mozilla/java/webclient/Makefile.win new file mode 100644 index 00000000000..ab9488bab8e --- /dev/null +++ b/mozilla/java/webclient/Makefile.win @@ -0,0 +1,38 @@ +#!nmake +# +# The contents of this file are subject to the Mozilla Public License +# Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, +# Inc. Portions created by Sun are Copyright (C) 1999 Sun +# Microsystems, Inc. All Rights Reserved. + +IGNORE_MANIFEST=1 +#//------------------------------------------------------------------------ +#// +#// Makefile to build the java wrapper to mozilla +#// +#//------------------------------------------------------------------------ + + +#//------------------------------------------------------------------------ +#// +#// Specify the depth of the current directory relative to the +#// root of NS +#// +#//------------------------------------------------------------------------ +DEPTH = ..\.. + +DIRS = classes \ + src + +include <$(DEPTH)\config\rules.mak> + + diff --git a/mozilla/java/webclient/README b/mozilla/java/webclient/README new file mode 100644 index 00000000000..0bdf1e362a8 --- /dev/null +++ b/mozilla/java/webclient/README @@ -0,0 +1,67 @@ +Here lies the MozWebShell java wrapper to mozilla M8. + +Authors: Kirk Baker + Ian Wilkinson + +Build hacking and packaging: Ed Burns + +Requirements: + +* built M8 mozilla tree for WinNT4.0 + +* JDK1.1.7 or greater + +* built org.mozilla.util java classes (see NOTE_UTIL) + +* Perl 5 perl.exe must be in your path + +How To Build: + +* make it so the directory in which this file resides is a child of your + top level mozilla\java directory + +* Copy the files .\config\buildpkg.bat and .\config\outofdate.pl to + mozilla\config. These file were modified after M8 and the + modifications are required to build java. + +* make sure the environment var JDKHOME is set to your jdk installation + directory, ie SET JDKHOME=C:\jdk1.1.8 + +* type "nmake /f makefile.win all" and hope for the best + +* Due to bug 10561 (http://bugzilla.mozilla.org/show_bug.cgi?id=10561) + one must do a horrendous workaround: + + In the directory mozilla/dist/WIN32_D.OBJ/bin, copy the components.reg + file and the components directory to the following places: + + C:\WINNT\System32 + %JDKHOME%\jre\bin + +How to Run: + +* once the build has successfully completed, run this batch file: + + .\src\WIN32_D.OBJ\runem.bat + + Note that YOUR_URL is probably necessary since firewall support wasn't + working in M8. + + +Problems: + +* clobber_all doesn't remove the .class files from dist\classes. You + have to do this manually. + +* post to netscape.public.mozilla.java newsgroup + +General notes: + +* Please update the ChangeLog (changelo) when you make changes. + +NOTE_UTIL: + +* this package depends on the org.mozilla.util classes, which can be + found in the mozilla tree under mozilla\java\util. They are a + separate checkout and build. Once you check out the org.mozilla.util + classes, see the README in the mozilla\java\util\README. diff --git a/mozilla/java/webclient/changelo b/mozilla/java/webclient/changelo new file mode 100644 index 00000000000..8dc656e6693 --- /dev/null +++ b/mozilla/java/webclient/changelo @@ -0,0 +1,13 @@ +Wed Jul 28 12:17:30 1999 + + * Renamed MozWebShell to webclient.BrowserControl + + * Moved util classes into separate package + + * updated README accordingly + +Mon Jul 26 21:32:18 1999 + + * Prepared the initial checkin of MozWebShell. Need to rename to + org.mozilla.webclient.BrowserControl. + diff --git a/mozilla/java/webclient/classes/Makefile.win b/mozilla/java/webclient/classes/Makefile.win new file mode 100644 index 00000000000..35128e21da4 --- /dev/null +++ b/mozilla/java/webclient/classes/Makefile.win @@ -0,0 +1,56 @@ +#!nmake +# +# The contents of this file are subject to the Mozilla Public License +# Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, +# Inc. Portions created by Sun are Copyright (C) 1999 Sun +# Microsystems, Inc. All Rights Reserved. + +IGNORE_MANIFEST=1 +#//------------------------------------------------------------------------ +#// +#// Makefile to build the java portion of the java wrapper to mozilla +#// +#//------------------------------------------------------------------------ + + +#//------------------------------------------------------------------------ +#// +#// Specify the depth of the current directory relative to the +#// root of NS +#// +#//------------------------------------------------------------------------ +DEPTH= ..\..\.. + +# PENDING(edburns): find out where this should really get defined +JAVA_OR_NSJVM=1 +NO_CAFE=1 + +include <$(DEPTH)\config\config.mak> + +JAR_WEBCLIENT_CLASSES = org\mozilla\webclient \ + org\mozilla\webclient\test + +!ifdef JAVA_OR_NSJVM +JDIRS = $(JAR_WEBCLIENT_CLASSES) +!endif + +WEBCLIENT_JAR_NAME=webclient(VERSION_NUMBER).jar + +JAVAC_PROG=$(JDKHOME)\bin\javac + +export:: + @echo +++ Checking that org.mozilla.util classes have been built... + if not exist $(MOZ_SRC)\mozilla\dist\classes\org\mozilla\util\Assert.class \ + stopbuild.exe + +include <$(DEPTH)\config\rules.mak> + diff --git a/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControl.java b/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControl.java new file mode 100644 index 00000000000..02f96c89ec2 --- /dev/null +++ b/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControl.java @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 RaptorCanvas + * + * The Initial Developer of the Original Code is Kirk Baker and * Ian Wilkinson BrowserControl simply declares the composition of the core and extended + * interfaces. + + * + * @version $Id: BrowserControl.java,v 1.1 1999-07-30 01:03:03 edburns%acm.org Exp $ + * + * @see org.mozilla.webclient.BrowserControlCore + * @see org.mozilla.webclient.BrowserControlExtended + * + */ + +public interface BrowserControl extends BrowserControlCore, BrowserControlExtended +{ + +} // end of interface BrowserControl diff --git a/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControlCanvas.java b/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControlCanvas.java new file mode 100644 index 00000000000..48173fd76da --- /dev/null +++ b/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControlCanvas.java @@ -0,0 +1,240 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 RaptorCanvas + * + * The Initial Developer of the Original Code is Kirk Baker and * Ian Wilkinson + + * Lifetime And Scope

+ + * See concrete subclasses for scope info. + + * @version $Id: BrowserControlCanvas.java,v 1.1 1999-07-30 01:03:04 edburns%acm.org Exp $ + + * @see org.mozilla.webclient.Win32BrowserControlCanvas + + */ + +import java.awt.*; +import java.awt.Canvas; +import java.awt.event.*; +import sun.awt.*; + +public abstract class BrowserControlCanvas extends Canvas +{ + +// +// Class Variables +// + +private static int webShellCount = 0; + +// +// Instance Variables +// + +// Attribute Instance Variables + +private boolean initializeOK; +private boolean boundsValid; +private boolean hasFocus; + +// Relationship Instance Variables + + +private BrowserControl webShell; +private int nativeWindow; +private Rectangle windowRelativeBounds; + +// PENDING(edburns): Is this needed: // private BrowserControlIdleThread idleThread; + +// +// Constructors and Initializers +// + +/** + * Initialize the BrowserControlMozillaShim. For now, + * this initializes the Mozilla registry. + */ +public BrowserControlCanvas () +{ + nativeWindow = 0; + webShell = null; + initializeOK = false; + boundsValid = false; + hasFocus = false; + + try { + BrowserControlMozillaShim.initialize(); + } catch (Exception e) { + System.out.println(e.toString()); + } +} // BrowserControlCanvas() ctor + + +/** + * Obtain the native window handle for this component's + * peer. + */ + +abstract protected int getWindow(DrawingSurfaceInfo dsi); + +// +// Methods from Canvas +// + + +/** + * Instantiate the Mozilla WebShell container. + */ +public void addNotify () +{ + super.addNotify(); + + DrawingSurface ds = (DrawingSurface)this.getPeer(); + DrawingSurfaceInfo dsi = ds.getDrawingSurfaceInfo(); + + windowRelativeBounds = new Rectangle(); + + // We must lock() the DrawingSurfaceInfo before + // accessing its native window handle. + dsi.lock(); + nativeWindow = getWindow(dsi); + + try { + Rectangle r = new Rectangle(getBoundsRelativeToWindow()); + webShell = new BrowserControlImpl(nativeWindow, r); + } catch (Exception e) { + dsi.unlock(); + System.out.println(e.toString()); + return; + } + + dsi.unlock(); + + initializeOK = true; + webShellCount++; + + /* + requestFocus(); + */ +} // addNotify() + +public BrowserControl getWebShell () +{ + return webShell; +} // getWebShell() + +protected Point getEventCoordsLocalToWindow(MouseEvent evt) +{ + Rectangle localBounds = getBoundsRelativeToWindow(); + int windowLocalX = evt.getX() + localBounds.x; + int windowLocalY = evt.getY() + localBounds.y; + + return new Point(windowLocalX, windowLocalY); +} // getEventCoordsLocalToWindow() + +protected Rectangle getWindowBounds () +{// Throw an Exception? + Container parent = getParent(); + + if (parent != null) { + do { + // if the parent is a window, then return its bounds + if (parent instanceof Window == true) { + return parent.getBounds(); + } + parent = parent.getParent(); + } while (parent != null); + } + + return new Rectangle(); +} // getWindowBounds() + +protected Rectangle getBoundsRelativeToWindow () +{ + if (boundsValid) { + return windowRelativeBounds; + } + + Container parent = getParent(); + Point ourLoc = getLocation(); + Rectangle ourBounds = getBounds(); + + if (parent != null) { + do { + // if the parent is a window, then don't adjust to its offset + // and look no further + if (parent instanceof Window == true) { + break; + } + + Point parentLoc = parent.getLocation(); + ourLoc.translate(-parentLoc.x, -parentLoc.y); + parent = parent.getParent(); + } while (parent != null); + } + + windowRelativeBounds.setBounds(-ourLoc.x, -ourLoc.y, ourBounds.width, ourBounds.height); + boundsValid = true; + + return windowRelativeBounds; +} // getBoundsRelativeToWindow() + +public void setBounds(int x, int y, int w, int h) +{ + super.setBounds(x, y, w, h); + if (webShell != null) { + System.out.println("in BrowserControlCanvas setBounds: x = " + x + " y = " + y + " w = " + w + " h = " + h); + try { + webShell.setBounds(new Rectangle(0, 0, w - 1, h - 1)); + } + catch(Exception ex) { + } + } +} + +public void setBounds(Rectangle rect) +{ + super.setBounds(rect); +} + +} // class BrowserControlCanvas + + +// EOF diff --git a/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControlCanvasFactory.java b/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControlCanvasFactory.java new file mode 100644 index 00000000000..c280eeaff0e --- /dev/null +++ b/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControlCanvasFactory.java @@ -0,0 +1,119 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.mozilla.webclient; + +// BrowserControlCanvasFactory.java + +import org.mozilla.util.Assert; +import org.mozilla.util.Log; +import org.mozilla.util.ParameterCheck; + +/** + * + * BrowserControlCanvasFactory creates concrete instances of BrowserControlCanvas + + * Lifetime And Scope

+ + * This is a static class, it is neven instantiated. + + * + * @version $Id: BrowserControlCanvasFactory.java,v 1.1 1999-07-30 01:03:04 edburns%acm.org Exp $ + * + * @see org.mozilla.webclient.test.EmbeddedMozilla + + */ + +public class BrowserControlCanvasFactory extends Object +{ +// +// Protected Constants +// + +// +// Class Variables +// + +// +// Instance Variables +// + +// Attribute Instance Variables + +// Relationship Instance Variables + +// +// Constructors and Initializers +// + +public BrowserControlCanvasFactory() +{ + Assert.assert(false, "This class shouldn't be constructed."); +} + +// +// Class methods +// + +public static BrowserControlCanvas newBrowserControlCanvas() +{ + BrowserControlCanvas result = null; + + // PENDING(edburns): do some magic to determine the right kind of + // BrowserControlCanvas to instantiate + + Class browserControlCanvasClass = null; + String className = "org.mozilla.webclient.Win32BrowserControlCanvas"; + + try { + if (null != (browserControlCanvasClass = Class.forName(className))) { + result = (BrowserControlCanvas) browserControlCanvasClass.newInstance(); + } + } + catch (Exception e) { + System.out.println(e.getMessage()); + } + + return result; +} + +// +// General Methods +// + +// ----UNIT_TEST_START + +// +// Test methods +// + +public static void main(String [] args) +{ + Assert.setEnabled(true); + Log.setApplicationName("BrowserControlCanvasFactory"); + Log.setApplicationVersion("0.0"); + Log.setApplicationVersionDate("$Id: BrowserControlCanvasFactory.java,v 1.1 1999-07-30 01:03:04 edburns%acm.org Exp $"); + + BrowserControlCanvas canvas = BrowserControlCanvasFactory.newBrowserControlCanvas(); + + Assert.assert(null != canvas); +} + +// ----UNIT_TEST_END + +} // end of class BrowserControlCanvasFactory diff --git a/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControlCore.java b/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControlCore.java new file mode 100644 index 00000000000..5cb3e8c92ae --- /dev/null +++ b/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControlCore.java @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 RaptorCanvas + * + * The Initial Developer of the Original Code is Kirk Baker and * Ian Wilkinson BrowserControlCore Defines the core methods for browsing + * + + * @version $Id: BrowserControlCore.java,v 1.1 1999-07-30 01:03:04 edburns%acm.org Exp $ + * + + * @see org.mozilla.webclient.BrowserControlExtended + * @see org.mozilla.webclient.BrowserControl + * + */ + +public interface BrowserControlCore +{ + +public void loadURL(String urlString) throws Exception; + +public void stop() throws Exception; + +public boolean canBack() throws Exception; + +public boolean canForward() throws Exception; + +public boolean back() throws Exception; + +public boolean forward() throws Exception; + +public int getNativeWebShell(); + +} // end of interface BrowserControlCore diff --git a/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControlExtended.java b/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControlExtended.java new file mode 100644 index 00000000000..81812d45c69 --- /dev/null +++ b/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControlExtended.java @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 RaptorCanvas + * + * The Initial Developer of the Original Code is Kirk Baker and * Ian Wilkinson BrowserControlExtended defines the interface for extended browser + * functionality + + * + * @version $Id: BrowserControlExtended.java,v 1.1 1999-07-30 01:03:05 edburns%acm.org Exp $ + * + * @see org.mozilla.webclient.BrowserControlCore + + * */ + +public interface BrowserControlExtended +{ + +public void show () throws Exception; + +public void hide () throws Exception; + +public void setBounds (Rectangle bounds) throws Exception; + +public void moveTo (int x, int y) throws Exception; + +public void setFocus () throws Exception; + +public void removeFocus () throws Exception; + +public void repaint (boolean forceRepaint) throws Exception; + +public boolean goTo (int historyIndex) throws Exception; + +public int getHistoryLength () throws Exception; + +public int getHistoryIndex () throws Exception; + +public String getURL (int historyIndex) throws Exception; + +} // end of interface BrowserControlExtended diff --git a/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControlImpl.java b/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControlImpl.java new file mode 100644 index 00000000000..cf1a9ecc2df --- /dev/null +++ b/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControlImpl.java @@ -0,0 +1,245 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 RaptorCanvas + * + * The Initial Developer of the Original Code is Kirk Baker and * Ian Wilkinson BrowserControlImpl provides the implementation for BrowserControl + * + * Lifetime And Scope

+ * + * @version $Id: BrowserControlImpl.java,v 1.1 1999-07-30 01:03:05 edburns%acm.org Exp $ + * + * @see org.mozilla.webclient.BrowserControl + * + */ + +public class BrowserControlImpl extends Object implements BrowserControl +{ +// +// Protected Constants +// + +// +// Class Variables +// + +// +// Instance Variables +// + +// Attribute Instance Variables + +// Relationship Instance Variables + + /** + + * a handle to the actual mozilla webShell + + */ + + private int nativeWebShell; + +// +// Constructors and Initializers +// + +public BrowserControlImpl(int windowPtr, Rectangle bounds) throws Exception +{ + nativeWebShell = BrowserControlMozillaShim.webShellCreate(windowPtr, bounds); +} + +// +// Class methods +// + +// +// General Methods +// + +// +// Methods from BrowserControl +// + +public void loadURL(String urlString) throws Exception +{ + BrowserControlMozillaShim.webShellLoadURL(nativeWebShell, urlString); +} + +public void stop() throws Exception +{ + BrowserControlMozillaShim.webShellStop(nativeWebShell); +} + +public void show () throws Exception +{ + BrowserControlMozillaShim.webShellShow(nativeWebShell); +} + +public void hide () throws Exception +{ + BrowserControlMozillaShim.webShellHide(nativeWebShell); +} + +public void setBounds (Rectangle bounds) throws Exception +{ + BrowserControlMozillaShim.webShellSetBounds(nativeWebShell, bounds); +} + +public void moveTo (int x, int y) throws Exception +{ + BrowserControlMozillaShim.webShellMoveTo(nativeWebShell, x, y); +} + +/** + * + */ +public void setFocus () throws Exception +{ + BrowserControlMozillaShim.webShellSetFocus(nativeWebShell); +} + +/** + * + */ +public void removeFocus () throws Exception +{ + BrowserControlMozillaShim.webShellRemoveFocus(nativeWebShell); +} + +/** + * + */ +public void repaint (boolean forceRepaint) throws Exception +{ + BrowserControlMozillaShim.webShellRepaint(nativeWebShell, forceRepaint); +} + +/** + * + */ +public boolean canBack () throws Exception +{ + return BrowserControlMozillaShim.webShellCanBack(nativeWebShell); +} + +/** + * + */ +public boolean canForward () throws Exception +{ + return BrowserControlMozillaShim.webShellCanForward(nativeWebShell); +} + +/** + * + */ +public boolean back () throws Exception +{ + return BrowserControlMozillaShim.webShellBack(nativeWebShell); +} + +/** + * + */ +public boolean forward () throws Exception +{ + return BrowserControlMozillaShim.webShellForward(nativeWebShell); +} + +/** + * + */ +public boolean goTo (int historyIndex) throws Exception +{ + return BrowserControlMozillaShim.webShellGoTo(nativeWebShell, historyIndex); +} + +/** + * + */ +public int getHistoryLength () throws Exception +{ + return BrowserControlMozillaShim.webShellGetHistoryLength(nativeWebShell); +} + +/** + * + */ +public int getHistoryIndex () throws Exception +{ + return BrowserControlMozillaShim.webShellGetHistoryIndex(nativeWebShell); +} + +/** + * + */ +public String getURL (int historyIndex) throws Exception +{ + return BrowserControlMozillaShim.webShellGetURL(nativeWebShell, historyIndex); +} + +/** + * + */ +public int getNativeWebShell () +{ + return nativeWebShell; +} + +/** + * + */ +public void finalize () +{ + try { + BrowserControlMozillaShim.webShellDelete(nativeWebShell); + } + catch (Exception ex) { + System.out.println(ex.toString()); + } + nativeWebShell = 0; +} + +// ----UNIT_TEST_START + +// +// Test methods +// + +public static void main(String [] args) +{ + Assert.setEnabled(true); + // BrowserControlImpl me = new BrowserControlImpl(); + Log.setApplicationName("BrowserControlImpl"); + Log.setApplicationVersion("0.0"); + Log.setApplicationVersionDate("$Id: BrowserControlImpl.java,v 1.1 1999-07-30 01:03:05 edburns%acm.org Exp $"); + +} + +// ----UNIT_TEST_END + +} // end of class BrowserControlImpl diff --git a/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControlMozillaShim.java b/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControlMozillaShim.java new file mode 100644 index 00000000000..5c5f773564e --- /dev/null +++ b/mozilla/java/webclient/classes/org/mozilla/webclient/BrowserControlMozillaShim.java @@ -0,0 +1,572 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 RaptorCanvas + * + * The Initial Developer of the Original Code is Kirk Baker and * Ian Wilkinson MWebShellMozillaShim is a class with native methods that + * provides the glue between MWebShell and nsIWebShell.

+ + * WAS: instance

+ + * Lifetime And Scope

+ + * There is one instance of this class and all of the exposed methods + * are static. + + * @version $Id: BrowserControlMozillaShim.java,v 1.1 1999-07-30 01:03:05 edburns%acm.org Exp $ + * + * @see org.mozilla.webclient.BrowserControlImpl + + * + + */ + +public class BrowserControlMozillaShim extends Object +{ +// +// Protected Constants +// + +// +// Class Variables +// + +private static boolean initialized = false; + +private static BrowserControlMozillaShim instance = null; + +private static Object lock = null; + + +// +// Instance Variables +// + +// Attribute Instance Variables + +// Relationship Instance Variables + +// +// Constructors and Initializers +// + +public BrowserControlMozillaShim() +{ + super(); + lock = new Object(); +} + +// +// Class methods +// + +public static void initialize () throws Exception +{ + if (!initialized) { + instance = new BrowserControlMozillaShim(); + + try { + System.loadLibrary("webclient"); + } + catch (java.lang.UnsatisfiedLinkError e) { + throw new Exception("Unable to open native webclient library"); + } + + instance.nativeInitialize(); + initialized = true; + } +} + +public static void terminate () throws Exception +{ + synchronized(lock) { + if (initialized) { + instance.nativeTerminate(); + initialized = false; + } + } +} + +public static void processEvents(int theWebShell) +{ + synchronized(lock) { + if (initialized) { + instance.nativeProcessEvents(theWebShell); + } + } +} + +// +// Window events +// + +public static void sendKeyDownEvent (int widgetPtr, + char keyChar, int keyCode, + int modifiers, int eventTime) +{ + synchronized(lock) { + if (initialized) { + instance.nativeSendKeyDownEvent(widgetPtr, + keyChar, keyCode, modifiers, + eventTime); + } + } +} + +public static void sendKeyUpEvent (int widgetPtr, + char keyChar, int keyCode, + int modifiers, int eventTime) +{ + synchronized(lock) { + if (initialized) { + instance.nativeSendKeyUpEvent(widgetPtr, keyChar, + keyCode, modifiers, eventTime); + + } + } +} + +public static void sendMouseEvent (int windowPtr, int widgetPtr, + int widgetX, int widgetY, + int windowX, int windowY, + int mouseMessage, int numClicks, + int modifiers, int eventTime) +{ + + synchronized(lock) { + if (initialized) { + instance.nativeSendMouseEvent(windowPtr, widgetPtr, + widgetX, widgetY, + windowX, windowY, + mouseMessage, numClicks, + modifiers, eventTime); + } + } +} + +public static void idleEvent (int windowPtr) +{ + synchronized(lock) { + if (initialized) { + instance.nativeIdleEvent(windowPtr, 0); + } + } +} + +public static void updateEvent (int windowPtr) +{ + synchronized(lock) { + if (initialized) { + instance.nativeUpdateEvent(windowPtr, 0); + } + } +} + +// +// Widget methods +// + +public static int widgetCreate (int windowPtr, + Rectangle bounds) throws Exception +{ + synchronized(lock) { + if (initialized) { + return(instance.nativeWidgetCreate(windowPtr, + bounds.x, bounds.y, + bounds.width + 1, bounds.height + 1)); + } else { + return 0; + } + } +} + +public static void widgetDelete (int widgetPtr) throws Exception +{ + synchronized(lock) { + if (initialized) { + instance.nativeWidgetDelete(widgetPtr); + } + } +} + +public static void widgetResize (int widgetPtr, Rectangle bounds, + boolean repaint) +{ + synchronized(lock) { + if (initialized) { + instance.nativeWidgetResize(widgetPtr, bounds.x, bounds.y, bounds.width + 1, bounds.height + 1, repaint); + } + } +} + +public static void widgetResize (int widgetPtr, int width, + int height, boolean repaint) +{ + synchronized(lock) { + if (initialized) { + instance.nativeWidgetResize(widgetPtr, 0, 0, width + 1, height + 1, repaint); + } + } +} + +public static void widgetEnable (int widgetPtr, boolean enable) +{ + synchronized(lock) { + if (initialized) { + instance.nativeWidgetEnable(widgetPtr, enable); + } + } +} + +public static void widgetShow (int widgetPtr, boolean show) +{ + synchronized(lock) { + if (initialized) { + instance.nativeWidgetShow(widgetPtr, show); + } + } +} + +public static void widgetInvalidate (int widgetPtr, boolean isSynchronous) +{ + synchronized(lock) { + if (initialized) { + instance.nativeWidgetInvalidate(widgetPtr, isSynchronous); + } + } +} + +public static void widgetUpdate (int widgetPtr) +{ + synchronized(lock) { + if (initialized) { + instance.nativeWidgetUpdate(widgetPtr); + } + } +} + +// +// WebShell methods +// + +public static int webShellCreate (int windowPtr, + Rectangle bounds) throws Exception +{ + synchronized(lock) { + if (initialized) { + return(instance.nativeWebShellCreate(windowPtr, bounds.x, bounds.y, bounds.width + 1, bounds.height + 1)); + } + else { + throw new Exception("Error: unable to create native nsIWebShell"); + } + } +} + +public static void webShellDelete (int webShellPtr) throws Exception +{ + synchronized(lock) { + if (initialized) { + instance.nativeWebShellDelete(webShellPtr); + } + } +} + +public static void webShellLoadURL (int webShellPtr, + String urlString) throws Exception +{ + synchronized(lock) { + if (initialized) { + instance.nativeWebShellLoadURL(webShellPtr, urlString); + } + } +} + +public static void webShellStop (int webShellPtr) throws Exception +{ + synchronized(lock) { + if (initialized) { + instance.nativeWebShellStop(webShellPtr); + } + } +} + +public static void webShellShow (int webShellPtr) throws Exception +{ + synchronized(lock) { + if (initialized) { + instance.nativeWebShellShow(webShellPtr); + } + } +} + +public static void webShellHide (int webShellPtr) throws Exception +{ + synchronized(lock) { + if (initialized) { + instance.nativeWebShellHide(webShellPtr); + } + } +} + +public static void webShellSetBounds (int webShellPtr, + Rectangle bounds) throws Exception +{ + synchronized(lock) { + if (initialized) { + instance.nativeWebShellSetBounds(webShellPtr, bounds.x, bounds.y, bounds.width + 1, bounds.height + 1); + } + } +} + +public static void webShellMoveTo (int webShellPtr, + int x, int y) throws Exception +{ + synchronized(lock) { + if (initialized) { + instance.nativeWebShellMoveTo(webShellPtr, x, y); + } + } +} + +public static void webShellSetFocus (int webShellPtr) throws Exception +{ + synchronized(lock) { + if (initialized) { + instance.nativeWebShellSetFocus(webShellPtr); + } + } +} + +public static void webShellRemoveFocus (int webShellPtr) throws Exception +{ + synchronized(lock) { + if (initialized) { + instance.nativeWebShellRemoveFocus(webShellPtr); + } + } +} + +public static void webShellRepaint (int webShellPtr, + boolean forceRepaint) throws Exception +{ + synchronized(lock) { + if (initialized) { + instance.nativeWebShellRepaint(webShellPtr, forceRepaint); + } + } +} + +public static boolean webShellCanBack (int webShellPtr) throws Exception +{ + synchronized(lock) { + if (initialized) { + return instance.nativeWebShellCanBack(webShellPtr); + } + else { + throw new Exception("instance is not initialized."); + } + } +} + +public static boolean webShellCanForward (int webShellPtr) throws Exception +{ + synchronized(lock) { + if (initialized) { + return instance.nativeWebShellCanForward(webShellPtr); + } + else { + throw new Exception("instance is not initialized."); + } + } +} + +public static boolean webShellBack (int webShellPtr) throws Exception +{ + synchronized(lock) { + if (initialized) { + return instance.nativeWebShellBack(webShellPtr); + } + else { + throw new Exception("instance is not initialized."); + } + } +} + +public static boolean webShellForward (int webShellPtr) throws Exception +{ + synchronized(lock) { + if (initialized) { + return instance.nativeWebShellForward(webShellPtr); + } + else { + throw new Exception("instance is not initialized."); + } + } +} + +public static boolean webShellGoTo (int webShellPtr, + int historyIndex) throws Exception +{ + synchronized(lock) { + if (initialized) { + return instance.nativeWebShellGoTo(webShellPtr, historyIndex); + } + else { + throw new Exception("instance is not initialized."); + } + } +} + +public static int webShellGetHistoryLength (int webShellPtr) throws Exception +{ + synchronized(lock) { + if (initialized) { + return instance.nativeWebShellGetHistoryLength(webShellPtr); + } + else { + throw new Exception("instance is not initialized."); + } + } +} + +public static int webShellGetHistoryIndex (int webShellPtr) throws Exception +{ + synchronized(lock) { + if (initialized) { + return instance.nativeWebShellGetHistoryIndex(webShellPtr); + } + else { + throw new Exception("instance is not initialized."); + } + } +} + +public static String webShellGetURL(int webShellPtr, + int historyIndex) throws Exception +{ + synchronized(lock) { + if (initialized) { + return instance.nativeWebShellGetURL(webShellPtr, historyIndex); + } + else { + throw new Exception("instance is not initialized."); + } + } +} + +// +// Native interfaces +// + +private native void nativeInitialize () throws Exception; +private native void nativeTerminate () throws Exception; + + +// +// Event interfaces +// + +private native void nativeSendKeyDownEvent(int widgetPtr, char keyChar, int keyCode, int modifiers, int eventTime); +private native void nativeSendKeyUpEvent(int widgetPtr, char keyChar, int keyCode, int modifiers, int eventTime); +private native void nativeSendMouseEvent(int windowPtr, int widgetPtr, + int widgetX, int widgetY, + int windowX, int windowY, + int mouseMessage, int numClicks, + int modifiers, int eventTime); +private native void nativeProcessEvents(int theWebShell); +private native void nativeIdleEvent (int windowPtr, int eventTime); +private native void nativeUpdateEvent (int windowPtr, int eventTime); + + +// +// Widget interfaces +// + +private native int nativeWidgetCreate (int windowPtr, int x, int y, int width, int height) throws Exception; +private native void nativeWidgetDelete (int widgetPtr) throws Exception; +private native void nativeWidgetResize (int widgetPtr, int x, int y, int width, int height, boolean repaint); + +/* + private native void nativeWidgetResize (int widgetPtr, int width, int height, boolean repaint); + */ + +private native void nativeWidgetEnable (int widgetPtr, boolean enable); +private native void nativeWidgetShow (int widgetPtr, boolean show); +private native void nativeWidgetInvalidate (int widgetPtr, boolean isSynchronous); +private native void nativeWidgetUpdate (int widgetPtr); + + + +// +// WebShell interface +// + +private native int nativeWebShellCreate (int windowPtr, + int x, int y, int width, int height) throws Exception; +private native void nativeWebShellDelete (int webShellPtr) throws Exception; +private native void nativeWebShellLoadURL (int webShellPtr, String urlString) throws Exception; +private native void nativeWebShellStop (int webShellPtr) throws Exception; +private native void nativeWebShellShow (int webShellPtr) throws Exception; +private native void nativeWebShellHide (int webShellPtr) throws Exception; +private native void nativeWebShellSetBounds (int webShellPtr, int x, int y, int width, int height) throws Exception; +private native void nativeWebShellMoveTo (int webShellPtr, int x, int y) throws Exception; +private native void nativeWebShellSetFocus (int webShellPtr) throws Exception; +private native void nativeWebShellRemoveFocus (int webShellPtr) throws Exception; +private native void nativeWebShellRepaint (int webShellPtr, boolean forceRepaint) throws Exception; +private native boolean nativeWebShellCanBack (int webShellPtr) throws Exception; +private native boolean nativeWebShellCanForward (int webShellPtr) throws Exception; +private native boolean nativeWebShellBack (int webShellPtr) throws Exception; +private native boolean nativeWebShellForward (int webShellPtr) throws Exception; +private native boolean nativeWebShellGoTo (int webShellPtr, int aHistoryIndex) throws Exception; +private native int nativeWebShellGetHistoryLength (int webShellPtr) throws Exception; +private native int nativeWebShellGetHistoryIndex (int webShellPtr) throws Exception; +private native String nativeWebShellGetURL (int webShellPtr, int aHistoryIndex) throws Exception; + +// +// General Methods +// + +// ----UNIT_TEST_START + +// +// Test methods +// + +public static void main(String [] args) +{ + Assert.setEnabled(true); + BrowserControlMozillaShim me = new BrowserControlMozillaShim(); + Log.setApplicationName("BrowserControlMozillaShim"); + Log.setApplicationVersion("0.0"); + Log.setApplicationVersionDate("$Id: BrowserControlMozillaShim.java,v 1.1 1999-07-30 01:03:05 edburns%acm.org Exp $"); + +} + +// ----UNIT_TEST_END + +} // end of class BrowserControlMozillaShim diff --git a/mozilla/java/webclient/classes/org/mozilla/webclient/Win32BrowserControlCanvas.java b/mozilla/java/webclient/classes/org/mozilla/webclient/Win32BrowserControlCanvas.java new file mode 100644 index 00000000000..e6940fb25be --- /dev/null +++ b/mozilla/java/webclient/classes/org/mozilla/webclient/Win32BrowserControlCanvas.java @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 RaptorCanvas + * + * The Initial Developer of the Original Code is Kirk Baker and * Ian Wilkinson Lifetime And Scope

+ + * There is one instance of the BrowserControlCanvas per top level awt Frame. + + * @version $Id: Win32BrowserControlCanvas.java,v 1.1 1999-07-30 01:03:06 edburns%acm.org Exp $ + * + * @see org.mozilla.webclient.BrowserControlCanvasFactory + * + + */ + +import sun.awt.*; +import sun.awt.windows.*; + +/** + * Win32BrowserControlCanvas provides a concrete realization + * of the RaptorCanvas. + */ +class Win32BrowserControlCanvas extends BrowserControlCanvas { + /** + * Obtain the native window handle for this + * component's peer. + * + * @returns The native window handle. + */ + protected int getWindow(DrawingSurfaceInfo dsi) { + WDrawingSurfaceInfo ds = (WDrawingSurfaceInfo)dsi; + return ds.getHWnd(); + } +} diff --git a/mozilla/java/webclient/classes/org/mozilla/webclient/test/EmbeddedMozilla.java b/mozilla/java/webclient/classes/org/mozilla/webclient/test/EmbeddedMozilla.java new file mode 100644 index 00000000000..d64816bf789 --- /dev/null +++ b/mozilla/java/webclient/classes/org/mozilla/webclient/test/EmbeddedMozilla.java @@ -0,0 +1,186 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 RaptorCanvas + * + * The Initial Developer of the Original Code is Kirk Baker and * Ian Wilkinson doit.bat +call doit.bat +del /F /A:A doit.bat + +:END + +popd diff --git a/mozilla/java/webclient/config/localdefs.mak b/mozilla/java/webclient/config/localdefs.mak new file mode 100644 index 00000000000..aa968f95c6a --- /dev/null +++ b/mozilla/java/webclient/config/localdefs.mak @@ -0,0 +1,4 @@ +JAVA=$(JDKHOME)\bin\java +JAVAH=$(JDKHOME)\bin\JAVAH +JAVAHFLAGS=-jni -classpath $(JAVAC_CLASSPATH) -d . + diff --git a/mozilla/java/webclient/config/outofdate.pl b/mozilla/java/webclient/config/outofdate.pl new file mode 100644 index 00000000000..25313c3dce0 --- /dev/null +++ b/mozilla/java/webclient/config/outofdate.pl @@ -0,0 +1,130 @@ +#!perl +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. +# + +# +#Input: [-d dir] foo1.java foo2.java +#Compares with: foo1.class foo2.class (if -d specified, checks in 'dir', +# otherwise assumes .class files in same directory as .java files) +#Returns: list of input arguments which are newer than corresponding class +#files (non-existant class files are considered to be real old :-) +# + +$found = 1; + +# GLOBALS +$SEP = 0; # the paltform independent path separator +$CFG = 0; # the value of the -cfg flag + +# determine the path separator +$_ = $ENV{"PATH"}; +if (m|/|) { + $SEP = "/"; +} +else { + $SEP = "\\"; +} + +if ($ARGV[0] eq '-d') { + $classdir = $ARGV[1]; + $classdir .= $SEP; + shift; + shift; +} else { + $classdir = "." . $SEP; +} + +# if -cfg is specified, print out the contents of the cfg file to stdout +if ($ARGV[0] eq '-cfg') { + $CFG = $ARGV[1]; + shift; + shift; +} + +$_ = $ARGV[0]; +if (m/\*.java/) { + # Account for the fact that the shell didn't expand *.java by doing it + # manually. + &manuallyExpandArgument("java"); +} + +$printFile = 0; + +foreach $filename (@ARGV) { + $classfilename = $classdir; + $classfilename .= $filename; + $classfilename =~ s/.java$/.class/; +# workaround to only build sun/io/* classes when necessary +# change the pathname of target file to be consistent +# with sun/io subdirectories +# +# sun/io was always getting rebuilt because the java files +# were split into subdirectories, but the package names +# remained the same. This was confusing outofdate.pl +# + $classfilename =~ s/sun\/io\/extended.\//sun\/io\//; + $classfilename =~ s/\.\.\/\.\.\/sun-java\/classsrc\///; + ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime, + $ctime,$blksize,$blocks) = stat($filename); + ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$classmtime, + $ctime,$blksize,$blocks) = stat($classfilename); +# print $filename, " ", $mtime, ", ", $classfilename, " ", $classmtime, "\n"; + if ($mtime > $classmtime) { + + # Only print the file header if we actually have some files to + # compile. + if (!$printFile) { + $printFile = 1; + &printFile($CFG); + } + print $filename, " "; + $found = 0; + } +} + +print "\n"; + +# push onto $ARG array all filenames with extension $ext + +# @param ext the extension of the file + +sub manuallyExpandArgument { + local($ext) = @_; + $ext = "\." . $ext; # put it in regexp + + $result = opendir(DIR, "."); + + @allfiles = grep(/$ext/, readdir(DIR)); + $i = 0; + foreach $file (@allfiles) { + #skip emacs save files + $_ = $file; + if (!/~/) { + $ARGV[$i++] = $file; + } + } +} + +sub printFile { + local($file) = @_; + + $result = open(CFG, $file); + while () { + chop; + print $_; + } +} diff --git a/mozilla/java/webclient/src/BrowserControlMozillaShim.cpp b/mozilla/java/webclient/src/BrowserControlMozillaShim.cpp new file mode 100644 index 00000000000..c483296b9b2 --- /dev/null +++ b/mozilla/java/webclient/src/BrowserControlMozillaShim.cpp @@ -0,0 +1,1806 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 RaptorCanvas + * + * The Initial Developer of the Original Code is Kirk Baker and * Ian Wilkinson +#include "BrowserControlMozillaShim.h" + +#ifdef XP_PC +#include +#endif + +// Raptor includes +#include +#include "nsIWidget.h" +#include "nsIWebShell.h" +#include "nsWidgetsCID.h" +#include "nsIComponentManager.h" +#include "nsString.h" +#include "nsRepository.h" +#include "nsINetService.h" +#include "nsIServiceManager.h" +#include "nsIEventQueueService.h" + +#include "prmem.h" + +#ifdef XP_MAC +#include "nsMacMessageSink.h" +#include "nsRepeater.h" + +nsMacMessageSink gMessageSink; + +#endif + +#include "nsActions.h" + +#include "nsIRegistry.h" + +#define DEBUG_RAPTOR_CANVAS 1 + +static NS_DEFINE_IID(kWindowCID, NS_WINDOW_CID); +static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); + +static NS_DEFINE_IID(kWebShellCID, NS_WEB_SHELL_CID); +static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID); + +static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID); +static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); + +extern "C" void NS_SetupRegistry(); + + +struct WebShellInitContext { + HWND parentHWnd; + nsIWebShell * webShell; + PLEventQueue * actionQueue; + PRThread * embeddedThread; + JNIEnv * env; + int stopThread; + int initComplete; + int initFailCode; + int x; + int y; + int w; + int h; +}; + + +static void +ThrowExceptionToJava (JNIEnv * env, const char * message) +{ + if (env->ExceptionOccurred()) + env->ExceptionClear(); + + jclass excCls = env->FindClass("java/lang/Exception"); + + if (excCls == 0) { // Unable to find the exception class, give up. + if (env->ExceptionOccurred()) + env->ExceptionClear(); + return; + } + + // Throw the exception with the error code and description + jmethodID jID = env->GetMethodID(excCls, "", "(Ljava/lang/String;)V"); // void Exception(String) + + if (jID != NULL) + { + jstring exceptionString = env->NewStringUTF(message); + jthrowable newException = (jthrowable) env->NewObject(excCls, jID, exceptionString); + + if (newException != NULL) + { + env->Throw(newException); + } + else + { + if (env->ExceptionOccurred()) + env->ExceptionClear(); + } + } + else + { + if (env->ExceptionOccurred()) + env->ExceptionClear(); + } +} // ThrowExceptionToJava() + + +enum { + kEventQueueError = 1, + kCreateWebShellError, + kInitWebShellError, + kShowWebShellError +}; + + +char * errorMessages[] = { + "No Error", + "Could not obtain the event queue service.", + "Unable to create the WebShell instance.", + "Unable to initialize the WebShell instance.", + "Unable to show the WebShell." +}; + + +void +EmbeddedEventHandler (void * arg) +{ + WebShellInitContext * initContext = (WebShellInitContext *) arg; + nsIEventQueueService* aEventQService = nsnull; + nsresult rv; + PRBool allowPlugins = PR_FALSE; + + //TODO Add tracing from nspr. + +#if DEBUG_RAPTOR_CANVAS + printf("EmbeddedEventHandler(%lx): Create the Event Queue for the UI thread...\n", initContext); +#endif + + // Create the Event Queue for the UI thread... + rv = nsServiceManager::GetService(kEventQueueServiceCID, + kIEventQueueServiceIID, + (nsISupports **)&aEventQService); + + if (NS_FAILED(rv)) { + initContext->initFailCode = kEventQueueError; + return; + } + + // Create the event queue. + rv = aEventQService->CreateThreadEventQueue(); + + NS_InitINetService(); + + // Create the action queue + if (initContext->embeddedThread) { +#if DEBUG_RAPTOR_CANVAS + printf("EmbeddedEventHandler(%lx): embeddedThread != NULL\n", initContext); +#endif + if (initContext->actionQueue == NULL) { +#if DEBUG_RAPTOR_CANVAS + printf("EmbeddedEventHandler(%lx): Create the action queue\n", initContext); +#endif + initContext->actionQueue = ::PL_CreateMonitoredEventQueue("Action Queue", initContext->embeddedThread); + } + } + +#if DEBUG_RAPTOR_CANVAS + printf("EmbeddedEventHandler(%lx): Create the WebShell...\n", initContext); +#endif + + // Create the WebShell. + rv = nsRepository::CreateInstance(kWebShellCID, nsnull, kIWebShellIID, (void**)&initContext->webShell); + if (NS_FAILED(rv)) { + initContext->initFailCode = kCreateWebShellError; + return; + } + +#if DEBUG_RAPTOR_CANVAS + printf("EmbeddedEventHandler(%lx): Init the WebShell...\n", initContext); +#endif + + rv = initContext->webShell->Init((nsNativeWidget *)initContext->parentHWnd, + initContext->x, initContext->y, initContext->w, initContext->h + ); + if (NS_FAILED(rv)) { + initContext->initFailCode = kInitWebShellError; + return; + } + +#if DEBUG_RAPTOR_CANVAS + printf("EmbeddedEventHandler(%lx): Show the WebShell...\n", initContext); +#endif + + rv = initContext->webShell->Show(); + if (NS_FAILED(rv)) { + initContext->initFailCode = kShowWebShellError; + return; + } + + initContext->initComplete = TRUE; + +#if DEBUG_RAPTOR_CANVAS + printf("EmbeddedEventHandler(%lx): enter event loop\n", initContext); +#endif + + do { + MSG msg; + + if (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { + if (::GetMessage(&msg, NULL, 0, 0)) { + ::TranslateMessage(&msg); + ::DispatchMessage(&msg); + } + } + + ::PR_Sleep(PR_INTERVAL_NO_WAIT); + + if ((initContext->initComplete) && (initContext->actionQueue)) { + + PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + if (::PL_EventAvailable(initContext->actionQueue)) { + + PLEvent * event = ::PL_GetEvent(initContext->actionQueue); + + if (event != NULL) { + ::PL_HandleEvent(event); + } + } + + PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + } + if (initContext->stopThread) { + initContext->stopThread++; + break; + } + } while (PR_TRUE); +} + +// It appears the current thread (belonging to Java) is assumed to be +// the "main GUI thread." (Creation story given below.) Hence the +// RunPump() of the nsToolkit conflicting with the Java event dispatching. +// +// I'm unsure whether threads created PR_LOCAL_THREAD have +// a one-to-one correspondence with the threads appearing +// on Win32. Changed the "main GUI thread" to be +// a global thread, rather than a local thread. +// +// Creation story... +// nsWebShell::Init() [ webshell/src/nsWebShell.cpp ] calling +// nsWindow::StandardWindowCreate() [ widget/src/windows/nsWindow.cpp ] calling +// nsBaseWidget::BaseCreate() [ widget/src/xpwidgets/nsBaseWidget.cpp ] calling +// nsToolkit::Init() [ widget/src/windows/nsToolkit.cpp ] +// +void +InitEmbeddedEventHandler (WebShellInitContext* initContext) +{ +#if DEBUG_RAPTOR_CANVAS + printf("InitEmbeddedEventHandler(%lx): Creating embedded thread...\n", initContext); +#endif + + initContext->embeddedThread = ::PR_CreateThread(PR_SYSTEM_THREAD, + EmbeddedEventHandler, + (void*)initContext, + PR_PRIORITY_NORMAL, + PR_GLOBAL_THREAD, + PR_UNJOINABLE_THREAD, + 0); +#if DEBUG_RAPTOR_CANVAS + printf("InitEmbeddedEventHandler(%lx): Embedded Thread created...\n", initContext); +#endif + + while (initContext->initComplete == FALSE) { + if (initContext->initFailCode != 0) { + ::ThrowExceptionToJava(initContext->env, errorMessages[initContext->initFailCode]); + return; + } + } + +} + + + +static nsEventStatus PR_CALLBACK +HandleRaptorEvent (nsGUIEvent *) +{ + nsEventStatus result = nsEventStatus_eIgnore; + return result; +} // HandleRaptorEvent() + + +static void +DispatchEvent (nsGUIEvent* eventPtr, nsIWidget* widgetPtr) +{ +#ifdef XP_MAC + + // Enable Raptor background activity + // Note: This will be moved to nsMacMessageSink very soon. + // The application will not have to do it anymore. + + EventRecord * macEventPtr = (EventRecord *) eventPtr->nativeMsg; + + gMessageSink.DispatchOSEvent(*macEventPtr, FrontWindow()); + Repeater::DoRepeaters(*macEventPtr); + + if (macEventPtr->what == nullEvent) + Repeater::DoIdlers(*macEventPtr); + +#else + + nsEventStatus aStatus = nsEventStatus_eIgnore; + + widgetPtr->DispatchEvent(eventPtr, aStatus); + +#endif +} // DispatchEvent() + + +const jint SHIFT_MASK = 1 << 0; +const jint CTRL_MASK = 1 << 1; +const jint META_MASK = 1 << 2; +const jint ALT_MASK = 1 << 3; +const jint BUTTON1_MASK = 1 << 4; +const jint BUTTON2_MASK = ALT_MASK; +const jint BUTTON3_MASK = META_MASK; + +#ifdef XP_MAC + +static unsigned short +ConvertModifiersToMacModifiers (jint modifiers) +{ + unsigned short convertedModifiers = 0; + + if (modifiers & META_MASK) + convertedModifiers |= cmdKey; + if (modifiers & SHIFT_MASK) + convertedModifiers |= shiftKey; + if (modifiers & ALT_MASK) + convertedModifiers |= optionKey; + if (modifiers & CTRL_MASK) + convertedModifiers |= controlKey; + if (modifiers & BUTTON1_MASK) + convertedModifiers |= btnState; + + // KAB alphaLock would be nice too... + + return convertedModifiers; +} // ConvertModifiersToMacModifiers() + + +static void +ConvertMouseCoordsToMacMouseCoords (jint windowPtr, jint x, jint y, Point& pt) +{ + GrafPtr savePort; + + pt.h = (short) x; + pt.v = (short) y; + GetPort(&savePort); + SetPort((WindowPtr) windowPtr); + LocalToGlobal(&pt); + SetPort(savePort); +} // ConvertMouseCoordsToMacMouseCoords() + +#endif // ifdef XP_MAC + + +static void +ConvertModifiersTo_nsInputEvent (jint modifiers, nsInputEvent& event) +{ + event.isShift = (modifiers & SHIFT_MASK) ? PR_TRUE : PR_FALSE; + event.isControl = (modifiers & CTRL_MASK) ? PR_TRUE : PR_FALSE; + event.isAlt = (modifiers & ALT_MASK) ? PR_TRUE : PR_FALSE; +#ifdef XP_MAC + event.isCommand = (modifiers & META_MASK) ? PR_TRUE : PR_FALSE; +#endif +} // ConvertModifiersTo_nsInputEvent() + + + +static unsigned long +ConvertKeys (jchar keyChar, jint keyCode) +{ + return 0; +} // ConvertKeys() + + + +const jint MOUSE_FIRST = 500; +const jint MOUSE_CLICKED = MOUSE_FIRST; +const jint MOUSE_PRESSED = 1 + MOUSE_FIRST; // Event.MOUSE_DOWN +const jint MOUSE_RELEASED = 2 + MOUSE_FIRST; // Event.MOUSE_UP +const jint RAPTOR_MOUSE_MOVED = 3 + MOUSE_FIRST; // Event.MOUSE_MOVE +const jint MOUSE_ENTERED = 4 + MOUSE_FIRST; //Event.MOUSE_ENTER +const jint MOUSE_EXITED = 5 + MOUSE_FIRST; //Event.MOUSE_EXIT +const jint MOUSE_DRAGGED = 6 + MOUSE_FIRST; //Event.MOUSE_DRAG + + + +static PRUint32 +ConvertMouseMessageTo_nsMouseMessage (jint message, jint modifiers, jint numClicks) +{ + if (RAPTOR_MOUSE_MOVED == message) + { + return NS_MOUSE_MOVE; + } + else if (MOUSE_CLICKED == message) + { + PRBool doubleClick = (numClicks & 1) ? PR_FALSE : PR_TRUE; + + if (modifiers & BUTTON1_MASK) + { + if (doubleClick) + return NS_MOUSE_LEFT_DOUBLECLICK; + return NS_MOUSE_LEFT_CLICK; + } + else if (modifiers & BUTTON2_MASK) + { + if (doubleClick) + return NS_MOUSE_MIDDLE_DOUBLECLICK; + return NS_MOUSE_MIDDLE_CLICK; + } + else if (modifiers & BUTTON3_MASK) + { + if (doubleClick) + return NS_MOUSE_RIGHT_DOUBLECLICK; + return NS_MOUSE_RIGHT_CLICK; + } + } + else if ((MOUSE_PRESSED == message) || (MOUSE_DRAGGED == message)) + { + if (modifiers & BUTTON1_MASK) + { + return NS_MOUSE_LEFT_BUTTON_DOWN; + } + else if (modifiers & BUTTON2_MASK) + { + return NS_MOUSE_MIDDLE_BUTTON_DOWN; + } + else if (modifiers & BUTTON3_MASK) + { + return NS_MOUSE_RIGHT_BUTTON_DOWN; + } + } + else if (MOUSE_RELEASED == message) + { + if (modifiers & BUTTON1_MASK) + { + return NS_MOUSE_LEFT_BUTTON_UP; + } + else if (modifiers & BUTTON2_MASK) + { + return NS_MOUSE_MIDDLE_BUTTON_UP; + } + else if (modifiers & BUTTON3_MASK) + { + return NS_MOUSE_RIGHT_BUTTON_UP; + } + } + else if (MOUSE_ENTERED == message) + { + return NS_MOUSE_ENTER; + } + else if (MOUSE_EXITED == message) + { + return NS_MOUSE_EXIT; + } + return NS_MOUSE_MOVE; +} // ConvertMouseMessageTo_nsMouseMessage() + + +#ifdef XP_MAC +static unsigned short +ConvertMouseMessageToMacMouseEvent (jint message) +{ + if (RAPTOR_MOUSE_MOVED == message) + { + return nullEvent; + } + else if (MOUSE_CLICKED == message) + { + return nullEvent; + } + else if ((MOUSE_PRESSED == message) || (MOUSE_DRAGGED == message)) + { + return mouseDown; + } + else if (MOUSE_RELEASED == message) + { + return mouseUp; + } + return nullEvent; +} // ConvertMouseMessageToMacMouseEvent() +#endif + + +/* + * JNI interfaces + */ + + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorInitialize + * Signature: ()V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeInitialize ( + JNIEnv * env, + jobject obj) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + static PRBool gFirstTime = PR_TRUE; + + if (gFirstTime) + { + NS_SetupRegistry(); + gFirstTime = PR_FALSE; + } +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeInitialize() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorTerminate + * Signature: ()V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeTerminate ( + JNIEnv * env, + jobject obj) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + +#if DEBUG_RAPTOR_CANVAS + printf("raptorTerminate() called\n"); +#endif + +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeTerminate() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorSendKeyDownEvent + * Signature: (ICIII)V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeSendKeyDownEvent ( + JNIEnv * env, + jobject obj, + jint widgetPtr, + jchar keyChar, + jint keyCode, + jint modifiers, + jint eventTime) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + nsKeyEvent keyEvent; + +#ifdef XP_MAC + EventRecord event; + + event.what = ::keyDown; + event.message = ConvertKeys(keyChar, keyCode); +// event.when = (unsigned long) eventTime; + event.when = TickCount(); + event.where.h = 0; + event.where.v = 0; + event.modifiers = ConvertModifiersToMacModifiers(modifiers); + + keyEvent.nativeMsg = &event; +#else + keyEvent.nativeMsg = nsnull; +#endif + + // nsEvent + keyEvent.eventStructType = NS_KEY_EVENT; + keyEvent.message = NS_KEY_DOWN; + keyEvent.point.x = 0; + keyEvent.point.y = 0; + // keyEvent.time = TickCount(); + + // nsGUIEvent + keyEvent.widget = (nsIWidget *) widgetPtr; + + // nsInputEvent + ConvertModifiersTo_nsInputEvent(modifiers, keyEvent); + + // nsKeyEvent + keyEvent.keyCode = (PRUint32) keyCode; + keyEvent.charCode = (PRUint32) keyChar; + + DispatchEvent(&keyEvent, keyEvent.widget); +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeSendKeyDownEvent() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorSendKeyUpEvent + * Signature: (ICIII)V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeSendKeyUpEvent ( + JNIEnv * env, + jobject obj, + jint widgetPtr, + jchar keyChar, + jint keyCode, + jint modifiers, + jint eventTime) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + nsKeyEvent keyEvent; + +#ifdef XP_MAC + EventRecord event; + + event.what = ::keyUp; + event.message = ConvertKeys(keyChar, keyCode); +// event.when = (unsigned long) eventTime; + event.when = TickCount(); + event.where.h = 0; + event.where.v = 0; + event.modifiers = ConvertModifiersToMacModifiers(modifiers); + + keyEvent.nativeMsg = &event; +#else + keyEvent.nativeMsg = nsnull; +#endif + + // nsEvent + keyEvent.eventStructType = NS_KEY_EVENT; + keyEvent.message = NS_KEY_UP; + keyEvent.point.x = 0; + keyEvent.point.y = 0; +#if 0 + keyEvent.time = TickCount(); +#endif + + // nsGUIEvent + keyEvent.widget = (nsIWidget *) widgetPtr; + + // nsInputEvent + ConvertModifiersTo_nsInputEvent(modifiers, keyEvent); + + // nsKeyEvent + keyEvent.keyCode = (PRUint32) keyCode; + keyEvent.charCode = (PRUint32) keyChar; + + DispatchEvent(&keyEvent, keyEvent.widget); +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeSendKeyUpEvent() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorSendMouseEvent + * Signature: (IIIIIIIIIII)V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeSendMouseEvent ( + JNIEnv * env, + jobject obj, + jint windowPtr, + jint widgetPtr, + jint widgetX, + jint widgetY, + jint windowX, + jint windowY, + jint mouseMessage, + jint numClicks, + jint modifiers, + jint eventTime) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + nsMouseEvent mouseEvent; + +#ifdef XP_MAC + EventRecord event; + Point pt; + + ConvertMouseCoordsToMacMouseCoords(windowPtr, windowX, windowY, pt); + + event.what = ConvertMouseMessageToMacMouseEvent(mouseMessage); + event.message = 0; +// event.when = (unsigned long) eventTime; + event.when = TickCount(); + event.where = pt; + event.modifiers = ConvertModifiersToMacModifiers(modifiers); + + mouseEvent.nativeMsg = &event; + mouseEvent.time = TickCount(); +#else + mouseEvent.nativeMsg = nsnull; +#endif + + // nsEvent + mouseEvent.eventStructType = NS_MOUSE_EVENT; + mouseEvent.message = ConvertMouseMessageTo_nsMouseMessage(mouseMessage, modifiers, numClicks); + mouseEvent.point.x = widgetX; + mouseEvent.point.y = widgetY; + + // nsGUIEvent + mouseEvent.widget = (nsIWidget *) widgetPtr; + + // nsInputEvent + ConvertModifiersTo_nsInputEvent(modifiers, mouseEvent); + + // nsMouseEvent + mouseEvent.clickCount = (PRUint32) numClicks; + + DispatchEvent(&mouseEvent, mouseEvent.widget); +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeSendMouseEvent() + + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorIdleEvent + * Signature: (I)V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeIdleEvent ( + JNIEnv * env, + jobject obj, + jint windowPtr, + jint eventTime) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; +#ifdef XP_MAC + EventRecord event; + + event.what = ::nullEvent; + event.message = 0; +// event.when = (unsigned long) eventTime; + event.when = TickCount(); + event.where.h = 0; + event.where.v = 0; + event.modifiers = 0; + + gMessageSink.DispatchOSEvent(event, (WindowPtr) windowPtr); + + // Enable Raptor background activity + // Note: This will be moved to nsMacMessageSink very soon. + // The application will not have to do it anymore. + + Repeater::DoRepeaters(event); + Repeater::DoIdlers(event); +#endif +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeIdleEvent() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorUpdateEvent + * Signature: (II)V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeUpdateEvent ( + JNIEnv * env, + jobject obj, + jint windowPtr, + jint eventTime) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; +#ifdef XP_MAC + EventRecord event; + + event.what = ::updateEvt; + event.message = 0; +// event.when = (unsigned long) eventTime; + event.when = TickCount(); + event.where.h = 0; + event.where.v = 0; + event.modifiers = 0; + + gMessageSink.DispatchOSEvent(event, (WindowPtr) windowPtr); +#endif +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeUpdateEvent() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWidgetCreate + * Signature: (I)I + */ +JNIEXPORT jint JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWidgetCreate ( + JNIEnv * env, + jobject obj, + jint windowPtr, + jint x, + jint y, + jint width, + jint height) +{ + jobject jobj = obj; + nsIWidget* widgetPtr = NULL; +#ifdef XP_MAC + WindowPtr pWindow = (WindowPtr) windowPtr; +#elif defined(XP_PC) + HWND pWindow = (HWND) windowPtr; +#endif + nsRect r(x, y, width, height); + nsresult rv; + + // create top-level widget + // IMPORTANT: It must be created before any controls are added to the window + + rv = nsComponentManager::CreateInstance(kWindowCID, nsnull, kIWidgetIID, (void**)&widgetPtr); + + if (rv != NS_OK) + { + ::ThrowExceptionToJava(env, "raptorWidgetCreate Exception: unable to create widget instance"); + return 0; + } + + rv = widgetPtr->Create((nsNativeWidget)pWindow, r, HandleRaptorEvent, nsnull); + + if (rv != NS_OK) + { + ::ThrowExceptionToJava(env, "raptorWidgetCreate Exception: unable to create widget"); + return 0; + } + + return (jint) widgetPtr; +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWidgetCreate() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWidgetDelete + * Signature: (I)I + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWidgetDelete ( + JNIEnv * env, + jobject obj, + jint widgetPtr) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + + if (widgetPtr) + { + delete ((nsIWidget *) widgetPtr); + } +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWidgetDelete() + + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWidgetResize + * Signature: (IIIZ)V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWidgetResize ( + JNIEnv * env, + jobject obj, + jint widgetPtr, + jint x, + jint y, + jint width, + jint height, + jboolean repaint) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + + ((nsIWidget *) widgetPtr)->Resize((PRUint32) x, (PRUint32) y, (PRUint32) width, (PRUint32) height, (PRBool) repaint); +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWidgetResize() + + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWidgetEnable + * Signature: (IZ)V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWidgetEnable ( + JNIEnv * env, + jobject obj, + jint widgetPtr, + jboolean enable) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + + ((nsIWidget *) widgetPtr)->Enable((PRBool) enable); +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWidgetEnable() + + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWidgetShow + * Signature: (IZ)V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWidgetShow ( + JNIEnv * env, + jobject obj, + jint widgetPtr, + jboolean show) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + + ((nsIWidget *) widgetPtr)->Show((PRBool) show); +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWidgetShow() + + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWidgetInvalidate + * Signature: (IZ)V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWidgetInvalidate ( + JNIEnv * env, + jobject obj, + jint widgetPtr, + jboolean isSynchronous) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + + ((nsIWidget *) widgetPtr)->Invalidate((PRBool) isSynchronous); +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWidgetInvalidate() + + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWidgetUpdate + * Signature: (I)V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWidgetUpdate ( + JNIEnv * env, + jobject obj, + jint widgetPtr) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + + ((nsIWidget *) widgetPtr)->Update(); +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWidgetUpdate() + + + +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeProcessEvents ( + JNIEnv* env, + jobject obj, + jint theWebShell) +{ + JNIEnv* pEnv = env; + jobject jobj = obj; + +// WebShellInitContext* initContext = (WebShellInitContext *) theWebShell; +// initContext->webShell->Show(); +} + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWebShellCreate + * Signature: (IIIIII)I + */ +JNIEXPORT jint JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellCreate ( + JNIEnv * env, + jobject obj, + jint windowPtr, + jint x, + jint y, + jint width, + jint height) +{ + jobject jobj = obj; +#ifdef XP_MAC + WindowPtr pWindow = (WindowPtr) windowPtr; + Rect webRect = pWindow->portRect; +// nsIWidget * pWidget = (nsIWidget *) widgetPtr; +#else +// elif defined(XP_WIN) + HWND parentHWnd = (HWND)windowPtr; +#endif + + if (parentHWnd == nsnull) { + ::ThrowExceptionToJava(env, "Exception: null window handle passed to raptorWebShellCreate"); + return (jint) 0; + } + + WebShellInitContext* initContext = new WebShellInitContext; + + initContext->initComplete = FALSE; + initContext->initFailCode = 0; + initContext->parentHWnd = parentHWnd; + initContext->webShell = NULL; + initContext->embeddedThread = NULL; + initContext->actionQueue = NULL; + initContext->env = env; + initContext->stopThread = FALSE; + initContext->x = x; + initContext->y = y; + initContext->w = width; + initContext->h = height; + + InitEmbeddedEventHandler(initContext); + + return (jint) initContext; +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellCreate() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWebShellDelete + * Signature: (I)V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellDelete ( + JNIEnv * env, + jobject obj, + jint webShellPtr) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + + if (webShellPtr) + { + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + // stop the event thread + initContext->stopThread = 1; + while (initContext->stopThread <= 1) { + ; // TODO there's got to be a better way than this. ::PR_Interrupt()? + } + + delete (initContext->webShell); + // TODO delete the other things too (thread, action queue, etc.) + delete initContext; + } + else { + ::ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellDelete"); + } + +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellDelete() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWebShellLoadURL + * Signature: (ILjava/lang/String;)V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellLoadURL ( + JNIEnv * env, + jobject obj, + jint webShellPtr, + jstring urlString) +{ + jobject jobj = obj; + const char * urlChars = (char *) env->GetStringUTFChars(urlString, 0); + + printf("Native URL = \"%s\"\n", urlChars); + env->ReleaseStringUTFChars(urlString, urlChars); + + PRUnichar * urlStringChars = (PRUnichar *) env->GetStringChars(urlString, 0); + + if (env->ExceptionOccurred()) + { + ::ThrowExceptionToJava(env, "raptorWebShellLoadURL Exception: unable to extract Java string"); + if (urlStringChars != NULL) + env->ReleaseStringChars(urlString, urlStringChars); + return; + } + + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellLoadURL"); + if (urlStringChars != NULL) + env->ReleaseStringChars(urlString, urlStringChars); + return; + } + + if (initContext->initComplete) { + wsLoadURLEvent * actionEvent = new wsLoadURLEvent(initContext->webShell, urlStringChars); + PLEvent * event = (PLEvent*) *actionEvent; + + PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + ::PL_PostEvent(initContext->actionQueue, event); + + PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + } + + env->ReleaseStringChars(urlString, urlStringChars); +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellLoadURL() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWebShellStop + * Signature: (I)V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellStop ( + JNIEnv * env, + jobject obj, + jint webShellPtr) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellStop"); + return; + } + + if (initContext->initComplete) { + wsStopEvent * actionEvent = new wsStopEvent(initContext->webShell); + PLEvent * event = (PLEvent*) *actionEvent; + + PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + ::PL_PostEvent(initContext->actionQueue, event); + + PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + } + +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellStop() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWebShellShow + * Signature: (I)V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellShow ( + JNIEnv * env, + jobject obj, + jint webShellPtr) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellShow"); + return; + } + + if (initContext->initComplete) { + wsShowEvent * actionEvent = new wsShowEvent(initContext->webShell); + PLEvent * event = (PLEvent*) *actionEvent; + + PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + ::PL_PostEvent(initContext->actionQueue, event); + + PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + } + +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellShow() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWebShellHide + * Signature: (I)V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellHide ( + JNIEnv * env, + jobject obj, + jint webShellPtr) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellHide"); + return; + } + + if (initContext->initComplete) { + wsHideEvent * actionEvent = new wsHideEvent(initContext->webShell); + PLEvent * event = (PLEvent*) *actionEvent; + + PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + ::PL_PostEvent(initContext->actionQueue, event); + + PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + } + +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellHide() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWebShellSetBounds + * Signature: (IIIII)V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellSetBounds ( + JNIEnv * env, + jobject obj, + jint webShellPtr, + jint x, + jint y, + jint width, + jint height) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellSetBounds"); + return; + } + + if (initContext->initComplete) { + wsResizeEvent * actionEvent = new wsResizeEvent(initContext->webShell, x, y, width, height); + PLEvent * event = (PLEvent*) *actionEvent; + + PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + ::PL_PostEvent(initContext->actionQueue, event); + + PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + } + +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellSetBounds() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWebShellMoveTo + * Signature: (III)V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellMoveTo ( + JNIEnv * env, + jobject obj, + jint webShellPtr, + jint x, + jint y) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellMoveTo"); + return; + } + + if (initContext->initComplete) { + wsMoveToEvent * actionEvent = new wsMoveToEvent(initContext->webShell, x, y); + PLEvent * event = (PLEvent*) *actionEvent; + + PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + ::PL_PostEvent(initContext->actionQueue, event); + + PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + } + +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellMoveTo() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWebShellSetFocus + * Signature: (I)V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellSetFocus ( + JNIEnv * env, + jobject obj, + jint webShellPtr) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellSetFocus"); + return; + } + + if (initContext->initComplete) { + wsSetFocusEvent * actionEvent = new wsSetFocusEvent(initContext->webShell); + PLEvent * event = (PLEvent*) *actionEvent; + + PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + ::PL_PostEvent(initContext->actionQueue, event); + + PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + } + +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellSetFocus() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWebShellRemoveFocus + * Signature: (I)V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellRemoveFocus ( + JNIEnv * env, + jobject obj, + jint webShellPtr) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellRemoveFocus"); + return; + } + + if (initContext->initComplete) { + wsRemoveFocusEvent * actionEvent = new wsRemoveFocusEvent(initContext->webShell); + PLEvent * event = (PLEvent*) *actionEvent; + + PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + ::PL_PostEvent(initContext->actionQueue, event); + + PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + } + +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellRemoveFocus() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWebShellRepaint + * Signature: (IZ)V + */ +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellRepaint ( + JNIEnv * env, + jobject obj, + jint webShellPtr, + jboolean forceRepaint) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellRepaint"); + return; + } + + if (initContext->initComplete) { + wsRepaintEvent * actionEvent = new wsRepaintEvent(initContext->webShell, (PRBool) forceRepaint); + PLEvent * event = (PLEvent*) *actionEvent; + + PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + ::PL_PostEvent(initContext->actionQueue, event); + + PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + } + +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellRepaint() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWebShellCanBack + * Signature: (I)Z + */ +JNIEXPORT jboolean JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellCanBack ( + JNIEnv * env, + jobject obj, + jint webShellPtr) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + void * voidResult = nsnull; + + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellCanBack"); + return JNI_FALSE; + } + + if (initContext->initComplete) { + wsCanBackEvent * actionEvent = new wsCanBackEvent(initContext->webShell); + PLEvent * event = (PLEvent*) *actionEvent; + + PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + ::PL_PostEvent(initContext->actionQueue, event); + + PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + while (actionEvent->isComplete() == PR_FALSE) { + Sleep(0); + } + voidResult = actionEvent->getResult(); + delete actionEvent; + + return (NS_FAILED((nsresult) voidResult)) ? JNI_FALSE : JNI_TRUE; + } + + return JNI_FALSE; +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellCanBack() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWebShellCanForward + * Signature: (I)Z + */ +JNIEXPORT jboolean JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellCanForward ( + JNIEnv * env, + jobject obj, + jint webShellPtr) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + void * voidResult = nsnull; + + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellCanForward"); + return JNI_FALSE; + } + + if (initContext->initComplete) { + wsCanForwardEvent * actionEvent = new wsCanForwardEvent(initContext->webShell); + PLEvent * event = (PLEvent*) *actionEvent; + + PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + ::PL_PostEvent(initContext->actionQueue, event); + + PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + while (actionEvent->isComplete() == PR_FALSE) { + Sleep(0); + } + voidResult = actionEvent->getResult(); + delete actionEvent; + + return (NS_FAILED((nsresult) voidResult)) ? JNI_FALSE : JNI_TRUE; + } + + return JNI_FALSE; +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellCanForward() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWebShellBack + * Signature: (I)Z + */ +JNIEXPORT jboolean JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellBack ( + JNIEnv * env, + jobject obj, + jint webShellPtr) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + void * voidResult = nsnull; + + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellBack"); + return JNI_FALSE; + } + + if (initContext->initComplete) { + wsBackEvent * actionEvent = new wsBackEvent(initContext->webShell); + PLEvent * event = (PLEvent*) *actionEvent; + + PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + ::PL_PostEvent(initContext->actionQueue, event); + + PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + while (actionEvent->isComplete() == PR_FALSE) { + Sleep(0); + } + voidResult = actionEvent->getResult(); + delete actionEvent; + + return (NS_FAILED((nsresult) voidResult)) ? JNI_FALSE : JNI_TRUE; + } + + return JNI_FALSE; +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellBack() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWebShellForward + * Signature: (I)Z + */ +JNIEXPORT jboolean JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellForward ( + JNIEnv * env, + jobject obj, + jint webShellPtr) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + void * voidResult = nsnull; + + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellForward"); + return JNI_FALSE; + } + + if (initContext->initComplete) { + wsForwardEvent * actionEvent = new wsForwardEvent(initContext->webShell); + PLEvent * event = (PLEvent*) *actionEvent; + + PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + ::PL_PostEvent(initContext->actionQueue, event); + + PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + while (actionEvent->isComplete() == PR_FALSE) { + Sleep(0); + } + voidResult = actionEvent->getResult(); + delete actionEvent; + + return (NS_FAILED((nsresult) voidResult)) ? JNI_FALSE : JNI_TRUE; + } + + return JNI_FALSE; +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellForward() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWebShellGoTo + * Signature: (II)Z + */ +JNIEXPORT jboolean JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellGoTo ( + JNIEnv * env, + jobject obj, + jint webShellPtr, + jint historyIndex) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + void * voidResult = nsnull; + + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellGoTo"); + return JNI_FALSE; + } + + if (initContext->initComplete) { + wsGoToEvent * actionEvent = new wsGoToEvent(initContext->webShell, historyIndex); + PLEvent * event = (PLEvent*) *actionEvent; + + PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + ::PL_PostEvent(initContext->actionQueue, event); + + PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + while (actionEvent->isComplete() == PR_FALSE) { + Sleep(0); + } + voidResult = actionEvent->getResult(); + delete actionEvent; + + return (NS_FAILED((nsresult) voidResult)) ? JNI_FALSE : JNI_TRUE; + } + + return JNI_FALSE; +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellGoTo() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWebShellGetHistoryLength + * Signature: (I)I + */ +JNIEXPORT jint JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellGetHistoryLength ( + JNIEnv * env, + jobject obj, + jint webShellPtr) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + void * voidResult = nsnull; + + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellGetHistoryLength"); + return 0; + } + + if (initContext->initComplete) { + wsGetHistoryLengthEvent * actionEvent = new wsGetHistoryLengthEvent(initContext->webShell); + PLEvent * event = (PLEvent*) *actionEvent; + + PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + ::PL_PostEvent(initContext->actionQueue, event); + + PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + while (actionEvent->isComplete() == PR_FALSE) { + Sleep(0); + } + voidResult = actionEvent->getResult(); + delete actionEvent; + + return ((jint) voidResult); + } + + return 0; +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellGetHistoryLength() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWebShellGetHistoryIndex + * Signature: (I)I + */ +JNIEXPORT jint JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellGetHistoryIndex ( + JNIEnv * env, + jobject obj, + jint webShellPtr) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + void * voidResult = nsnull; + + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellGetHistoryIndex"); + return 0; + } + + if (initContext->initComplete) { + wsGetHistoryIndexEvent * actionEvent = new wsGetHistoryIndexEvent(initContext->webShell); + PLEvent * event = (PLEvent*) *actionEvent; + + PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + ::PL_PostEvent(initContext->actionQueue, event); + + PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + while (actionEvent->isComplete() == PR_FALSE) { + Sleep(0); + } + voidResult = actionEvent->getResult(); + delete actionEvent; + + return ((jint) voidResult); + } + + return 0; +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellGetHistoryIndex() + + +/* + * Class: BrowserControlMozillaShim + * Method: raptorWebShellGetURL + * Signature: (II)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellGetURL ( + JNIEnv * env, + jobject obj, + jint webShellPtr, + jint historyIndex) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + void * voidResult = nsnull; + jstring urlString = nsnull; + + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellGetURL"); + return nsnull; + } + + if (initContext->initComplete) { + wsGetURLEvent * actionEvent = new wsGetURLEvent(initContext->webShell, historyIndex); + PLEvent * event = (PLEvent*) *actionEvent; + + PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + ::PL_PostEvent(initContext->actionQueue, event); + + PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + + while (actionEvent->isComplete() == PR_FALSE) { + Sleep(0); + } + voidResult = actionEvent->getResult(); + delete actionEvent; + + if (voidResult != nsnull) { + + nsString1 * string = new nsString1((PRUnichar *) voidResult); + + if (string == nsnull) { + ::ThrowExceptionToJava(env, "raptorWebShellGetURL Exception: unable to create Java string"); + return nsnull; + } + + int length = string->Length(); + + delete string; + + urlString = env->NewString((PRUnichar *) voidResult, length); + + if (env->ExceptionOccurred()) + { + ::ThrowExceptionToJava(env, "raptorWebShellGetURL Exception: unable to create Java string"); + return nsnull; + } + } + else { + ::ThrowExceptionToJava(env, "raptorWebShellGetURL Exception: GetURL() returned NULL"); + return nsnull; + } + } + + return urlString; +} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellGetURL() + + + +// EOF diff --git a/mozilla/java/webclient/src/Makefile.win b/mozilla/java/webclient/src/Makefile.win new file mode 100644 index 00000000000..bcb685b566a --- /dev/null +++ b/mozilla/java/webclient/src/Makefile.win @@ -0,0 +1,81 @@ +#!nmake +# +# The contents of this file are subject to the Mozilla Public License +# Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, +# Inc. Portions created by Sun are Copyright (C) 1999 Sun +# Microsystems, Inc. All Rights Reserved. + +DEPTH=..\..\.. +IGNORE_MANIFEST=1 + +MAKE_OBJ_TYPE = DLL +DLLNAME = webclient +DLL=.\$(OBJDIR)\$(DLLNAME).dll + +MODULE=webclient + +OBJS = \ + .\$(OBJDIR)\nsActions.obj \ + .\$(OBJDIR)\BrowserControlMozillaShim.obj \ + $(NULL) + +LINCS = \ + $(NULL) + + +LCFLAGS = \ + $(NULL) + +LLIBS = \ + $(DIST)\lib\raptorweb.lib \ + $(DIST)\lib\raptorbasewidget_s.lib \ + $(DIST)\lib\raptorwidget.lib \ + $(DIST)\lib\xpcom.lib \ + $(DIST)\lib\raptorgfxwin.lib \ + $(DIST)\lib\nsreg.lib \ + $(DIST)\lib\netlib.lib \ + $(DIST)\lib\nspr3.lib \ + $(DIST)\lib\plds3.lib \ + $(DEPTH)\xpfe\bootstrap\WIN32_D.OBJ\nsSetupRegistry.obj \ + $(NULL) + + # $(DIST)\lib\raptorbase.lib \ + # $(DIST)\lib\xpcom32.lib\ + # $(DIST)\lib\xpcomds_s.lib\ + +WIN_LIBS = \ + version.lib + +include <$(DEPTH)\config\rules.mak> + +include <..\config\localdefs.mak> + +!CMDSWITCHES -S + +# generate the jni header +export:: BrowserControlMozillaShim.h + +BrowserControlMozillaShim.h: + @echo Assuming class org.mozilla.webclient.BrowserControlMozillaShim is in $(JAVAH_FLAGS) + $(JAVAH) $(JAVAH_FLAGS) -o $@ org.mozilla.webclient.BrowserControlMozillaShim + +install:: $(DLL) + $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin + @echo +++ Creating .\$(OBJDIR)\runem.bat. Use this to run the test browser. + @echo $(JAVA) -Djava.library.path=$(MOZ_SRC)\mozilla\dist\WIN32_D.OBJ\bin -classpath $(JAVAC_CLASSPATH) org.mozilla.webclient.test.EmbeddedMozilla %1% > .\$(OBJDIR)\runem.bat + +clobber_all:: clobber + +clobber:: + rm -f $(DIST)\bin\$(DLLNAME).dll + rm -f BrowserControlMozillaShim.h + rm -f .\$(OBJDIR)\runem.bat diff --git a/mozilla/java/webclient/src/nsActions.cpp b/mozilla/java/webclient/src/nsActions.cpp new file mode 100644 index 00000000000..145576ce48e --- /dev/null +++ b/mozilla/java/webclient/src/nsActions.cpp @@ -0,0 +1,589 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 RaptorCanvas + * + * The Initial Developer of the Original Code is Kirk Baker and * Ian Wilkinson owner; + void * result = nsnull; + + if (actionEvent != NULL) { + actionEvent->setResult(result = actionEvent->handleEvent()); + actionEvent->setComplete(PR_TRUE); + } + return result; +} // handleEvent() + + +void +destroyEvent (PLEvent * event) +{ + nsActionEvent * actionEvent = (nsActionEvent*) event->owner; + + if (actionEvent != NULL) { + if (!actionEvent->isSynchronous()) { + // Only delete if non-synchronous. Synchronous events are deleted by the event poster. + actionEvent->destroyEvent(); + } + } +} // destroyEvent() + + + +/* + * nsActionEvent + */ + +nsActionEvent::nsActionEvent (PRBool synchronous) +{ + PL_InitEvent(&mEvent, this, + (PLHandleEventProc ) ::handleEvent, + (PLDestroyEventProc) ::destroyEvent); + mSynchronous = synchronous; + mComplete = PR_FALSE; + mResult = nsnull; +} + + +PRBool +nsActionEvent::isComplete (void) +{ + if (mSynchronous) { + return mComplete; + } + else { + return PR_TRUE; + } +} // isComplete() + + + +/* + * wsResizeEvent + */ + +wsResizeEvent::wsResizeEvent(nsIWebShell* webShell, PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h) : + nsActionEvent(PR_FALSE), + mWebShell(webShell), + mLeft(x), + mBottom(y), + mWidth(w), + mHeight(h) +{ +} + + +void * +wsResizeEvent::handleEvent () +{ + if (mWebShell) { + + printf("handleEvent(resize) x = %d y = %d w = %d h = %d\n", mLeft, mBottom, mWidth, mHeight); + + nsresult rv = mWebShell->SetBounds(mLeft, mBottom, mWidth, mHeight); + + printf("result = %lx\n", rv); + + return (void *) rv; + } + return NULL; +} // handleEvent() + + + + +/* + * wsLoadURLEvent + */ + +wsLoadURLEvent::wsLoadURLEvent(nsIWebShell* webShell, PRUnichar * urlString) : + nsActionEvent(PR_FALSE), + mWebShell(webShell), + mURL(nsnull) +{ + mURL = new nsString1(urlString); +} + + +void * +wsLoadURLEvent::handleEvent () +{ + if (mWebShell && mURL) { + + printf("handleEvent(loadURL)\n"); + + nsresult rv = mWebShell->LoadURL(mURL->GetUnicode()); + + printf("result = %lx\n", rv); + } + return NULL; +} // handleEvent() + + +wsLoadURLEvent::~wsLoadURLEvent () +{ + if (mURL != nsnull) + delete mURL; +} + + + +/* + * wsStopEvent + */ + +wsStopEvent::wsStopEvent(nsIWebShell* webShell) : + nsActionEvent(PR_FALSE), + mWebShell(webShell) +{ +} + + +void * +wsStopEvent::handleEvent () +{ + if (mWebShell) { + + printf("handleEvent(Stop)\n"); + + nsresult rv = mWebShell->Stop(); + + printf("result = %lx\n", rv); + } + return NULL; +} // handleEvent() + + + +/* + * wsShowEvent + */ + +wsShowEvent::wsShowEvent(nsIWebShell* webShell) : + nsActionEvent(PR_FALSE), + mWebShell(webShell) +{ +} + + +void * +wsShowEvent::handleEvent () +{ + if (mWebShell) { + + printf("handleEvent(Show)\n"); + + nsresult rv = mWebShell->Show(); + + printf("result = %lx\n", rv); + } + return NULL; +} // handleEvent() + + + +/* + * wsHideEvent + */ + +wsHideEvent::wsHideEvent(nsIWebShell* webShell) : + nsActionEvent(PR_FALSE), + mWebShell(webShell) +{ +} + + +void * +wsHideEvent::handleEvent () +{ + if (mWebShell) { + + printf("handleEvent(Hide)\n"); + + nsresult rv = mWebShell->Hide(); + + printf("result = %lx\n", rv); + } + return NULL; +} // handleEvent() + + + +/* + * wsMoveToEvent + */ + +wsMoveToEvent::wsMoveToEvent(nsIWebShell* webShell, PRInt32 x, PRInt32 y) : + nsActionEvent(PR_FALSE), + mWebShell(webShell), + mX(x), + mY(y) +{ +} + + +void * +wsMoveToEvent::handleEvent () +{ + if (mWebShell) { + + printf("handleEvent(MoveTo(%ld, %ld)\n", mX, mY); + + nsresult rv = mWebShell->MoveTo(mX, mY); + + printf("result = %lx\n", rv); + } + return NULL; +} // handleEvent() + + +/* + * wsSetFocusEvent + */ + +wsSetFocusEvent::wsSetFocusEvent(nsIWebShell* webShell) : + nsActionEvent(PR_FALSE), + mWebShell(webShell) +{ +} + + +void * +wsSetFocusEvent::handleEvent () +{ + if (mWebShell) { + + printf("handleEvent(SetFocus()\n"); + + nsresult rv = mWebShell->SetFocus(); + + printf("result = %lx\n", rv); + } + return NULL; +} // handleEvent() + + + +/* + * wsRemoveFocusEvent + */ + +wsRemoveFocusEvent::wsRemoveFocusEvent(nsIWebShell* webShell) : + nsActionEvent(PR_FALSE), + mWebShell(webShell) +{ +} + + +void * +wsRemoveFocusEvent::handleEvent () +{ + if (mWebShell) { + + printf("handleEvent(RemoveFocus()\n"); + + nsresult rv = mWebShell->RemoveFocus(); + + printf("result = %lx\n", rv); + } + return NULL; +} // handleEvent() + + + +/* + * wsRepaintEvent + */ + +wsRepaintEvent::wsRepaintEvent(nsIWebShell* webShell, PRBool forceRepaint) : + nsActionEvent(PR_FALSE), + mWebShell(webShell), + mForceRepaint(forceRepaint) +{ +} + + +void * +wsRepaintEvent::handleEvent () +{ + if (mWebShell) { + + printf("handleEvent(Repaint(%d)\n", mForceRepaint); + + nsresult rv = mWebShell->Repaint(mForceRepaint); + + printf("result = %lx\n", rv); + } + return NULL; +} // handleEvent() + + + +/* + * wsCanBackEvent + */ + +wsCanBackEvent::wsCanBackEvent(nsIWebShell* webShell) : + nsActionEvent(PR_TRUE), + mWebShell(webShell) +{ +} + + +void * +wsCanBackEvent::handleEvent () +{ + if (mWebShell) { + + printf("handleEvent(CanBack()\n"); + + nsresult rv = mWebShell->CanBack(); + + printf("result = %lx\n", rv); + + return (void *) rv; + } + return NULL; +} // handleEvent() + + + +/* + * wsCanForwardEvent + */ + +wsCanForwardEvent::wsCanForwardEvent(nsIWebShell* webShell) : + nsActionEvent(PR_TRUE), + mWebShell(webShell) +{ +} + + +void * +wsCanForwardEvent::handleEvent () +{ + if (mWebShell) { + + printf("handleEvent(CanForward()\n"); + + nsresult rv = mWebShell->CanForward(); + + printf("result = %lx\n", rv); + + return (void *) rv; + } + return NULL; +} // handleEvent() + + + +/* + * wsBackEvent + */ + +wsBackEvent::wsBackEvent(nsIWebShell* webShell) : + nsActionEvent(PR_TRUE), + mWebShell(webShell) +{ +} + + +void * +wsBackEvent::handleEvent () +{ + if (mWebShell) { + + printf("handleEvent(Back()\n"); + + nsresult rv = mWebShell->Back(); + + printf("result = %lx\n", rv); + + return (void *) rv; + } + return NULL; +} // handleEvent() + + + +/* + * wsForwardEvent + */ + +wsForwardEvent::wsForwardEvent(nsIWebShell* webShell) : + nsActionEvent(PR_TRUE), + mWebShell(webShell) +{ +} + + +void * +wsForwardEvent::handleEvent () +{ + if (mWebShell) { + + printf("handleEvent(Forward()\n"); + + nsresult rv = mWebShell->Forward(); + + printf("result = %lx\n", rv); + + return (void *) rv; + } + return NULL; +} // handleEvent() + + + +/* + * wsGoToEvent + */ + +wsGoToEvent::wsGoToEvent(nsIWebShell* webShell, PRInt32 historyIndex) : + nsActionEvent(PR_TRUE), + mWebShell(webShell), + mHistoryIndex(historyIndex) +{ +} + + +void * +wsGoToEvent::handleEvent () +{ + if (mWebShell) { + + printf("handleEvent(GoTo(%ld)\n", mHistoryIndex); + + nsresult rv = mWebShell->GoTo(mHistoryIndex); + + printf("result = %lx\n", rv); + + return (void *) rv; + } + return NULL; +} // handleEvent() + + + +/* + * wsGetHistoryLengthEvent + */ + +wsGetHistoryLengthEvent::wsGetHistoryLengthEvent(nsIWebShell* webShell) : + nsActionEvent(PR_TRUE), + mWebShell(webShell) +{ +} + + +void * +wsGetHistoryLengthEvent::handleEvent () +{ + if (mWebShell) { + + printf("handleEvent(wsGetHistoryLengthEvent()\n"); + + PRInt32 historyLength = 0; + + nsresult rv = mWebShell->GetHistoryLength(historyLength); + + printf("result = %lx\n", rv); + + return (void *) historyLength; + } + return NULL; +} // handleEvent() + + + +/* + * wsGetHistoryIndexEvent + */ + +wsGetHistoryIndexEvent::wsGetHistoryIndexEvent(nsIWebShell* webShell) : + nsActionEvent(PR_TRUE), + mWebShell(webShell) +{ +} + + +void * +wsGetHistoryIndexEvent::handleEvent () +{ + if (mWebShell) { + + printf("handleEvent(wsGetHistoryIndexEvent()\n"); + + PRInt32 historyIndex = 0; + + nsresult rv = mWebShell->GetHistoryIndex(historyIndex); + + printf("result = %lx\n", rv); + + return (void *) historyIndex; + } + return NULL; +} // handleEvent() + + + +/* + * wsGetURLEvent + */ + +wsGetURLEvent::wsGetURLEvent(nsIWebShell* webShell, PRInt32 historyIndex) : + nsActionEvent(PR_TRUE), + mWebShell(webShell), + mHistoryIndex(historyIndex) +{ +} + + +void * +wsGetURLEvent::handleEvent () +{ + if (mWebShell) { + + printf("handleEvent(wsGetURLEvent(%ld)\n", mHistoryIndex); + + const PRUnichar * url = nsnull; + + // returns PRUninchar * URL in . No need to delete. References internal buffer of an nsString + nsresult rv = mWebShell->GetURL(mHistoryIndex, &url); + + printf("result = %lx, url = %lx\n", rv, url); + + return (void *) url; + } + return NULL; +} // handleEvent() + + + +// EOF diff --git a/mozilla/java/webclient/src/nsActions.h b/mozilla/java/webclient/src/nsActions.h new file mode 100644 index 00000000000..2d9b6362894 --- /dev/null +++ b/mozilla/java/webclient/src/nsActions.h @@ -0,0 +1,251 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 RaptorCanvas + * + * The Initial Developer of the Original Code is Kirk Baker and * Ian Wilkinson +#include "nsIWebShell.h" +#include "nsString.h" +#include "plevent.h" + + +class nsActionEvent { +public: + nsActionEvent (PRBool synchronous); + virtual ~nsActionEvent () {}; + virtual void * handleEvent (void) { return NULL;}; + void destroyEvent (void) { delete this; }; + operator PLEvent* () { return &mEvent; }; + PRBool isSynchronous (void) { return mSynchronous; }; + PRBool isComplete (void); + void setComplete (PRBool complete) { mComplete = complete; }; + void * getResult (void) { return mResult; }; + void setResult (void * result) { mResult = result; }; + +protected: + PLEvent mEvent; + void * mResult; + PRBool mSynchronous; + PRBool mComplete; +}; + + +class wsResizeEvent : public nsActionEvent { +public: + wsResizeEvent (nsIWebShell* webShell, PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h); + void * handleEvent (void); + +protected: + nsIWebShell * mWebShell; + PRInt32 mLeft; + PRInt32 mBottom; + PRInt32 mWidth; + PRInt32 mHeight; +}; + + +class wsLoadURLEvent : public nsActionEvent { +public: + wsLoadURLEvent (nsIWebShell* webShell, PRUnichar * urlString); + ~wsLoadURLEvent (); + void * handleEvent (void); + +protected: + nsIWebShell * mWebShell; + nsString1 * mURL; +}; + + +class wsStopEvent : public nsActionEvent { +public: + wsStopEvent (nsIWebShell* webShell); + void * handleEvent (void); + +protected: + nsIWebShell * mWebShell; +}; + + + +class wsShowEvent : public nsActionEvent { +public: + wsShowEvent (nsIWebShell* webShell); + void * handleEvent (void); + +protected: + nsIWebShell * mWebShell; +}; + + + +class wsHideEvent : public nsActionEvent { +public: + wsHideEvent (nsIWebShell* webShell); + void * handleEvent (void); + +protected: + nsIWebShell * mWebShell; +}; + + + +class wsMoveToEvent : public nsActionEvent { +public: + wsMoveToEvent (nsIWebShell* webShell, PRInt32 x, PRInt32 y); + void * handleEvent (void); + +protected: + nsIWebShell * mWebShell; + PRInt32 mX; + PRInt32 mY; +}; + + + +class wsSetFocusEvent : public nsActionEvent { +public: + wsSetFocusEvent (nsIWebShell* webShell); + void * handleEvent (void); + +protected: + nsIWebShell * mWebShell; +}; + + + +class wsRemoveFocusEvent : public nsActionEvent { +public: + wsRemoveFocusEvent (nsIWebShell* webShell); + void * handleEvent (void); + +protected: + nsIWebShell * mWebShell; +}; + + + +class wsRepaintEvent : public nsActionEvent { +public: + wsRepaintEvent (nsIWebShell* webShell, PRBool forceRepaint); + void * handleEvent (void); + +protected: + nsIWebShell * mWebShell; + PRBool mForceRepaint; +}; + + + +class wsCanBackEvent : public nsActionEvent { +public: + wsCanBackEvent (nsIWebShell* webShell); + void * handleEvent (void); + +protected: + nsIWebShell * mWebShell; +}; + + + +class wsCanForwardEvent : public nsActionEvent { +public: + wsCanForwardEvent (nsIWebShell* webShell); + void * handleEvent (void); + +protected: + nsIWebShell * mWebShell; +}; + + + +class wsBackEvent : public nsActionEvent { +public: + wsBackEvent (nsIWebShell* webShell); + void * handleEvent (void); + +protected: + nsIWebShell * mWebShell; +}; + + + +class wsForwardEvent : public nsActionEvent { +public: + wsForwardEvent (nsIWebShell* webShell); + void * handleEvent (void); + +protected: + nsIWebShell * mWebShell; +}; + + + +class wsGoToEvent : public nsActionEvent { +public: + wsGoToEvent (nsIWebShell* webShell, PRInt32 historyIndex); + void * handleEvent (void); + +protected: + nsIWebShell * mWebShell; + PRInt32 mHistoryIndex; +}; + + + +class wsGetHistoryLengthEvent : public nsActionEvent { +public: + wsGetHistoryLengthEvent + (nsIWebShell* webShell); + void * handleEvent (void); + +protected: + nsIWebShell * mWebShell; +}; + + + +class wsGetHistoryIndexEvent : public nsActionEvent { +public: + wsGetHistoryIndexEvent + (nsIWebShell* webShell); + void * handleEvent (void); + +protected: + nsIWebShell * mWebShell; +}; + + + +class wsGetURLEvent : public nsActionEvent { +public: + wsGetURLEvent (nsIWebShell* webShell, PRInt32 historyIndex); + void * handleEvent (void); + +protected: + nsIWebShell * mWebShell; + PRInt32 mHistoryIndex; +}; + + +#endif /* nsActions_h___ */ + +// EOF