A major update:
- reduces a number of c++<--> java calls - added NULL checks - made DOMAccessor to be secure - added util and tests packages - wrote test applets - updated README
This commit is contained in:
Родитель
16939f7f71
Коммит
71962f8e25
124
java/dom/README
124
java/dom/README
|
@ -1,57 +1,90 @@
|
|||
|
||||
Sources
|
||||
=======
|
||||
|
||||
The sources are located in mozilla/java/dom.
|
||||
Subdirectories
|
||||
|
||||
classes
|
||||
jni
|
||||
src
|
||||
tests
|
||||
|
||||
contain Java sources, Java native methods implementation,
|
||||
native c++ code and Java DOM API tests respectively.
|
||||
|
||||
Building
|
||||
========
|
||||
|
||||
Requirenments:
|
||||
--------------
|
||||
Current mozilla build
|
||||
JDK1.2 or JDK1.3
|
||||
Perl 5 must be in your path
|
||||
JDKHOME environment variable set to your JDK dir
|
||||
CLASSPATH environment cvariable set to contain
|
||||
org.w3c.dom classes. The sources can be found at
|
||||
http://www.w3.org/TR/WD-DOM-Level-2/java-binding.zip
|
||||
|
||||
Solaris specific
|
||||
----------------
|
||||
Add following directories to LD_LIBRARY_PATH environment variable:
|
||||
$MOZILLA_FIVE_HOME
|
||||
$JDKHOME/jre/lib/$HOSTTYPE/native_threads
|
||||
$JDKHOME/jre/lib/$HOSTTYPE/classic
|
||||
$JDKHOME/jre/lib/$HOSTTYPE/
|
||||
|
||||
goto mozilla/java/dom directory and type "gmake"
|
||||
|
||||
|
||||
Windows NT specific
|
||||
-------------------
|
||||
To enable OJI usage set environment variable JAVA_DOM_OJI_ENABLE=1
|
||||
Add following directories to PATH environment variable:
|
||||
%MOZILLA_FIVE_HOME%
|
||||
%JDKHOME%\jre\bin\classic (only in case you don't use OJI)
|
||||
|
||||
goto mozilla/java/dom directory and type "nmake /f makefile.win"
|
||||
|
||||
|
||||
Using the Java DOM API
|
||||
----------------------
|
||||
======================
|
||||
|
||||
A Java component obtains a org.w3c.dom.Document by registering for
|
||||
Document load notifications. The Document is passed in along with the
|
||||
notifications. The preferred way for a Java component to register for
|
||||
Document load notifications is to register via the DOMAccessor
|
||||
class. However if OJI is not use to obtain JNIEnv one has to apply
|
||||
two patches
|
||||
Document load notifications is to register via the DOMAccessor class.
|
||||
|
||||
webshell/src/nsWebShell.cpp.patch
|
||||
java/dom/jni/DocumentImpl.java.patch
|
||||
However, this is possible only if OJI usage is enabled. This works
|
||||
on Windows NT platform.
|
||||
|
||||
The first one inits nsJavaDOM component and starts jvm. The second one
|
||||
registers a document load listener via DOMAccessor.
|
||||
On Solaris currently the nsJavaDOM component instantiates its own JVM.
|
||||
When an OJI-compatible JVM is available, we will move over to using it.
|
||||
So, one has to apply two patches to
|
||||
|
||||
mozilla/webshell/src/nsWebShell.cpp
|
||||
mozilla/java/dom/classes/org/mozilla/dom/DOMAccessor.java
|
||||
|
||||
They can be found at mozilla/java/dom directory.
|
||||
The first one inits nsJavaDOM component and adds it as a
|
||||
document load observer listener.
|
||||
|
||||
The second one registers a document load listener via DOMAccessor.
|
||||
Note:
|
||||
any class that implements the DocumentLoadListener interface may
|
||||
stand for TestDocLoadListener.
|
||||
See the section on Building for instructions on how to apply the patches.
|
||||
stand for GenericDocLoadListener.
|
||||
|
||||
To enable OJI usage on win nt add -DJAVA_DOM_OJI_ENABLE to the
|
||||
DEFINES variable in makefile.win and also set an environment
|
||||
variable JAVA_DOM_OJI_ENABLE=true
|
||||
After applying a patch to nsWebShell.cpp edit
|
||||
mozilla/webshell/src/Makefile.in to add -DJAVA_DOM to the list of
|
||||
defines. Then do a gmake in this directory.
|
||||
|
||||
After applying a patch to DOMAccessor.java go to mozilla/java/dom/classes
|
||||
and do a gmake. No changes in makefiles are needed.
|
||||
|
||||
Makefiles
|
||||
---------
|
||||
You can find examples of Java DOM API usage in
|
||||
|
||||
You may have to set DEPTH to point to the mozilla CVS workspace root
|
||||
in Makefile and jni/Makefile. Since this stuff is not part of the
|
||||
regular SeaMonkeyBuild, Makefiles are not generated from Makefile.in,
|
||||
so just go ahead and hack the Makefile.
|
||||
|
||||
Building
|
||||
--------
|
||||
|
||||
After having done a configure at the top level of SeaMonkey, do a make
|
||||
in the dom and the dom/jni directories. This will copy over a few
|
||||
header files that are needed by the patch to nsWebShell. You can then
|
||||
apply the patch to nsWebShell.cpp by executing
|
||||
|
||||
`patch nsWebShell.cpp <nsWebShell.cpp.patch`
|
||||
|
||||
Edit Makefile.in to add -DJAVA_DOM to the list of defines. Then do a
|
||||
gmake in this directory.
|
||||
|
||||
Similarly apply the DocumetnImpl.java patch. Then recompile the
|
||||
DocumentImpl class. No changes in makefiles are needed.
|
||||
|
||||
Define JDKHOME so that $JDKHOME/bin points to javac.
|
||||
|
||||
You will also need to get the w3c DOM level 2 interfaces from
|
||||
http://www.w3.org/TR/WD-DOM-Level-2/java-binding.zip
|
||||
and put the class files in your CLASSPATH.
|
||||
mozilla/java/dom/classes/org/mozilla/dom/util
|
||||
mozilla/java/dom/classes/org/mozilla/dom/tests
|
||||
|
||||
|
||||
DOM2 events
|
||||
|
@ -76,8 +109,6 @@ The basic implementation architecture is following:
|
|||
- javaDOMEventsGlobals class is used much like javaDOMGlobals for caching
|
||||
(this code may be moved to javaDOMGlobals)
|
||||
|
||||
|
||||
|
||||
NSPR Logging
|
||||
------------
|
||||
|
||||
|
@ -96,13 +127,6 @@ and from Java. The two should be identical. The code to write these
|
|||
files is, essentially, my regression test. Feel free to add to it.
|
||||
|
||||
|
||||
OJI
|
||||
---
|
||||
|
||||
Currently the nsJavaDOM component instantiates its own JVM. When an
|
||||
OJI-compatible JVM is available, we will move over to using it.
|
||||
|
||||
|
||||
Dependencies
|
||||
------------
|
||||
|
||||
|
|
|
@ -29,6 +29,8 @@ NO_CAFE=1
|
|||
|
||||
JDIRS = org/mozilla/dom \
|
||||
org/mozilla/dom/events \
|
||||
org/mozilla/dom/util \
|
||||
org/mozilla/dom/tests \
|
||||
$(NULL)
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
|
|
@ -29,6 +29,8 @@ NO_CAFE=1
|
|||
|
||||
JDIRS = org/mozilla/dom \
|
||||
org/mozilla/dom/events \
|
||||
org/mozilla/dom/util \
|
||||
org/mozilla/dom/tests \
|
||||
$(NULL)
|
||||
|
||||
|
||||
|
|
|
@ -31,6 +31,8 @@ include <$(DEPTH)\java\config\localdefs.mak>
|
|||
|
||||
JDIRS = org\mozilla\dom \
|
||||
org\mozilla\dom\events \
|
||||
org\mozilla\dom\util \
|
||||
org\mozilla\dom\tests \
|
||||
$(NULL)
|
||||
|
||||
JAVAC_PROG=$(JDKHOME)\bin\javac
|
||||
|
|
|
@ -21,15 +21,124 @@
|
|||
|
||||
package org.mozilla.dom;
|
||||
|
||||
public interface DOMAccessor {
|
||||
public void addDocumentLoadListener(DocumentLoadListener listener);
|
||||
public void removeDocumentLoadListener(DocumentLoadListener listener);
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* The getInstance method is available, it is not declared because
|
||||
* it is a static method and the Java Language Spec does not allow
|
||||
* us to declare a static method in an interface.
|
||||
*
|
||||
* public static synchronized DOMAccessor getInstance();
|
||||
*/
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import java.security.AccessController;
|
||||
|
||||
public final class DOMAccessor {
|
||||
|
||||
private static Vector documentLoadListeners = new Vector();
|
||||
private static JavaDOMPermission permission = new JavaDOMPermission("JavaDOM");
|
||||
|
||||
static {
|
||||
System.loadLibrary("javadomjni");
|
||||
}
|
||||
|
||||
private void DOMAccessorImpl() {}
|
||||
|
||||
private static native void register();
|
||||
private static native void unregister();
|
||||
private static native Node getNodeByHandle(long p);
|
||||
private static native void doGC();
|
||||
|
||||
public static synchronized void
|
||||
addDocumentLoadListener(DocumentLoadListener listener) {
|
||||
if (documentLoadListeners.size() == 0) {
|
||||
register();
|
||||
}
|
||||
documentLoadListeners.addElement(listener);
|
||||
}
|
||||
|
||||
public static synchronized void
|
||||
removeDocumentLoadListener(DocumentLoadListener listener) {
|
||||
|
||||
documentLoadListeners.removeElement(listener);
|
||||
if (documentLoadListeners.size() == 0) {
|
||||
unregister();
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void
|
||||
startURLLoad(String url, String contentType, long p_doc) {
|
||||
|
||||
AccessController.checkPermission(permission);
|
||||
for (Enumeration e = documentLoadListeners.elements();
|
||||
e.hasMoreElements();) {
|
||||
DocumentLoadListener listener =
|
||||
(DocumentLoadListener) e.nextElement();
|
||||
listener.startURLLoad(url, contentType, (Document)getNodeByHandle(p_doc));
|
||||
}
|
||||
doGC();
|
||||
}
|
||||
|
||||
public static synchronized void
|
||||
endURLLoad(String url, int status, long p_doc) {
|
||||
|
||||
AccessController.checkPermission(permission);
|
||||
for (Enumeration e = documentLoadListeners.elements();
|
||||
e.hasMoreElements();) {
|
||||
DocumentLoadListener listener =
|
||||
(DocumentLoadListener) e.nextElement();
|
||||
listener.endURLLoad(url, status, (Document)getNodeByHandle(p_doc));
|
||||
}
|
||||
doGC();
|
||||
}
|
||||
|
||||
public static synchronized void
|
||||
progressURLLoad(String url, int progress, int progressMax,
|
||||
long p_doc) {
|
||||
|
||||
AccessController.checkPermission(permission);
|
||||
for (Enumeration e = documentLoadListeners.elements();
|
||||
e.hasMoreElements();) {
|
||||
DocumentLoadListener listener =
|
||||
(DocumentLoadListener) e.nextElement();
|
||||
listener.progressURLLoad(url, progress, progressMax, (Document)getNodeByHandle(p_doc));
|
||||
}
|
||||
doGC();
|
||||
}
|
||||
|
||||
public static synchronized void
|
||||
statusURLLoad(String url, String message, long p_doc) {
|
||||
|
||||
AccessController.checkPermission(permission);
|
||||
for (Enumeration e = documentLoadListeners.elements();
|
||||
e.hasMoreElements();) {
|
||||
DocumentLoadListener listener =
|
||||
(DocumentLoadListener) e.nextElement();
|
||||
listener.statusURLLoad(url, message, (Document)getNodeByHandle(p_doc));
|
||||
}
|
||||
doGC();
|
||||
}
|
||||
|
||||
|
||||
public static synchronized void
|
||||
startDocumentLoad(String url) {
|
||||
|
||||
AccessController.checkPermission(permission);
|
||||
for (Enumeration e = documentLoadListeners.elements();
|
||||
e.hasMoreElements();) {
|
||||
DocumentLoadListener listener =
|
||||
(DocumentLoadListener) e.nextElement();
|
||||
listener.startDocumentLoad(url);
|
||||
}
|
||||
doGC();
|
||||
}
|
||||
|
||||
public static synchronized void
|
||||
endDocumentLoad(String url, int status, long p_doc) {
|
||||
|
||||
AccessController.checkPermission(permission);
|
||||
for (Enumeration e = documentLoadListeners.elements();
|
||||
e.hasMoreElements();) {
|
||||
DocumentLoadListener listener =
|
||||
(DocumentLoadListener) e.nextElement();
|
||||
listener.endDocumentLoad(url, status, (Document)getNodeByHandle(p_doc));
|
||||
}
|
||||
doGC();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,9 +42,6 @@ public class DocumentImpl extends NodeImpl implements Document, DocumentEvent {
|
|||
|
||||
// instantiated from JNI only
|
||||
private DocumentImpl() {}
|
||||
public DocumentImpl(long p) {
|
||||
super(p);
|
||||
}
|
||||
|
||||
public native Attr createAttribute(String name);
|
||||
public native CDATASection createCDATASection(String data);
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
The contents of this file are subject to the Mozilla Public
|
||||
License Version 1.1 (the "License"); you may not use this file
|
||||
except in compliance with the License. You may obtain a copy of
|
||||
the License at http://www.mozilla.org/MPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS
|
||||
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
implied. See the License for the specific language governing
|
||||
rights and limitations under the License.
|
||||
|
||||
The Original Code is mozilla.org code.
|
||||
|
||||
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.
|
||||
|
||||
Contributor(s):
|
||||
*/
|
||||
|
||||
package org.mozilla.dom;
|
||||
|
||||
import java.security.BasicPermission;
|
||||
|
||||
public final class JavaDOMPermission extends BasicPermission {
|
||||
public JavaDOMPermission(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
public JavaDOMPermission(String name, String actions)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,231 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* Contributor(s): Denis Sharypov <sdv@sparc.spb.su>
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mozilla.dom.util;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.DocumentType;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
public class DOMTreeDumper {
|
||||
|
||||
private String name;
|
||||
private boolean debug;
|
||||
private PrintStream ps;
|
||||
private boolean inA;
|
||||
private final String[] endTagForbiddenNames = {"AREA",
|
||||
"BASE",
|
||||
"BASEFONT",
|
||||
"BR",
|
||||
"COL",
|
||||
"FRAME",
|
||||
"HR",
|
||||
"IMG",
|
||||
"INPUT",
|
||||
"ISINDEX",
|
||||
"LINK",
|
||||
"META",
|
||||
"PARAM"};
|
||||
|
||||
public DOMTreeDumper() {
|
||||
this("DOMTreeDumper", true);
|
||||
}
|
||||
|
||||
public DOMTreeDumper(boolean debug) {
|
||||
this("DOMTreeDumper", debug);
|
||||
}
|
||||
|
||||
public DOMTreeDumper(String name) {
|
||||
this(name, true);
|
||||
}
|
||||
|
||||
public DOMTreeDumper(String name, boolean debug) {
|
||||
this.name = name;
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
private void dumpDocument(Document doc) {
|
||||
if (doc == null) return;
|
||||
Element element = doc.getDocumentElement();
|
||||
if (element == null) return;
|
||||
element.normalize();
|
||||
// DocumentType dt = doc.getDoctype();
|
||||
// dumpNode(dt);
|
||||
|
||||
dumpNode(element);
|
||||
ps.println();
|
||||
ps.flush();
|
||||
|
||||
element = null;
|
||||
doc = null;
|
||||
}
|
||||
|
||||
private void dumpNode(Node node) {
|
||||
dumpNode(node, false);
|
||||
}
|
||||
|
||||
private void dumpNode(Node node, boolean isMapNode) {
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int type = node.getNodeType();
|
||||
String name = node.getNodeName();
|
||||
String value = node.getNodeValue();
|
||||
|
||||
switch (type) {
|
||||
case Node.ELEMENT_NODE:
|
||||
if (name.equals("A")) inA = true;
|
||||
if (!(inA || name.equals("BR"))) {
|
||||
ps.println();
|
||||
}
|
||||
ps.print("<" + name);
|
||||
dumpAttributes(node);
|
||||
ps.print(">");
|
||||
dumpChildren(node);
|
||||
if (name.equals("A")) inA = false;
|
||||
if (!endTagForbidden(name)) {
|
||||
ps.print("</" + node.getNodeName() + ">");
|
||||
}
|
||||
break;
|
||||
case Node.ATTRIBUTE_NODE:
|
||||
ps.print(" " + name.toUpperCase() + "=\"" + value + "\"");
|
||||
break;
|
||||
case Node.TEXT_NODE:
|
||||
if (!node.getParentNode().getNodeName().equals("PRE")) {
|
||||
value = value.trim();
|
||||
}
|
||||
if (!value.equals("")) {
|
||||
if (!inA) {
|
||||
ps.println();
|
||||
}
|
||||
ps.print(canonicalize(value));
|
||||
}
|
||||
break;
|
||||
case Node.COMMENT_NODE:
|
||||
ps.print("\n<!--" + value + "-->");
|
||||
break;
|
||||
case Node.CDATA_SECTION_NODE:
|
||||
case Node.ENTITY_REFERENCE_NODE:
|
||||
case Node.ENTITY_NODE:
|
||||
case Node.PROCESSING_INSTRUCTION_NODE:
|
||||
case Node.DOCUMENT_NODE:
|
||||
case Node.DOCUMENT_TYPE_NODE:
|
||||
case Node.DOCUMENT_FRAGMENT_NODE:
|
||||
case Node.NOTATION_NODE:
|
||||
ps.println("\n<!-- NOT HANDLED: " + name +
|
||||
" value=" + value + " -->");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void dumpAttributes(Node node) {
|
||||
NamedNodeMap map = node.getAttributes();
|
||||
if (map == null) return;
|
||||
int length = map.getLength();
|
||||
for (int i=0; i < length; i++) {
|
||||
Node item = map.item(i);
|
||||
dumpNode(item, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void dumpChildren(Node node) {
|
||||
NodeList children = node.getChildNodes();
|
||||
int length = 0;
|
||||
boolean hasChildren = ((children != null) && ((length = children.getLength()) > 0));
|
||||
if (!hasChildren) {
|
||||
return;
|
||||
}
|
||||
for (int i=0; i < length; i++) {
|
||||
dumpNode(children.item(i), false);
|
||||
}
|
||||
if (!inA) {
|
||||
ps.println();
|
||||
}
|
||||
}
|
||||
|
||||
private String canonicalize(String str) {
|
||||
StringBuffer in = new StringBuffer(str);
|
||||
int length = in.length();
|
||||
StringBuffer out = new StringBuffer(length);
|
||||
char c;
|
||||
for (int i = 0; i < length; i++) {
|
||||
switch (c = in.charAt(i)) {
|
||||
case '&' :
|
||||
out.append("&");
|
||||
break;
|
||||
case '<':
|
||||
out.append("<");
|
||||
break;
|
||||
case '>':
|
||||
out.append(">");
|
||||
break;
|
||||
case '\u00A0':
|
||||
out.append(" ");
|
||||
break;
|
||||
default:
|
||||
out.append(c);
|
||||
}
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
private boolean endTagForbidden(String name) {
|
||||
for (int i = 0; i < endTagForbiddenNames.length; i++) {
|
||||
if (name.equals(endTagForbiddenNames[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void dumpToFile(String fileName, Document doc) {
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(fileName);
|
||||
ps = new PrintStream(new BufferedOutputStream(fos, 1024));
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
return;
|
||||
}
|
||||
dbg("dumping to " + fileName);
|
||||
dumpDocument(doc);
|
||||
dbg("finished dumping...");
|
||||
}
|
||||
|
||||
public void dumpToStream(PrintStream ps, Document doc) {
|
||||
this.ps = ps;
|
||||
dbg("dumping to stream...");
|
||||
dumpDocument(doc);
|
||||
dbg("finished dumping...");
|
||||
}
|
||||
|
||||
private void dbg(String str) {
|
||||
if (debug) {
|
||||
System.out.println(name + ": " + str);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
The contents of this file are subject to the Mozilla Public
|
||||
License Version 1.1 (the "License"); you may not use this file
|
||||
except in compliance with the License. You may obtain a copy of
|
||||
the License at http://www.mozilla.org/MPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS
|
||||
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
implied. See the License for the specific language governing
|
||||
rights and limitations under the License.
|
||||
|
||||
The Original Code is mozilla.org code.
|
||||
|
||||
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.
|
||||
|
||||
Contributor(s):
|
||||
*/
|
||||
|
||||
package org.mozilla.dom.util;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import org.w3c.dom.Document;
|
||||
import org.mozilla.dom.DocumentLoadListener;
|
||||
|
||||
public class GenericDocLoadListener implements DocumentLoadListener {
|
||||
|
||||
private String name;
|
||||
private PrintStream ps;
|
||||
|
||||
public GenericDocLoadListener() {
|
||||
this("GenericDocLoadListener",
|
||||
new PrintStream(System.out));
|
||||
}
|
||||
|
||||
public GenericDocLoadListener(String name) {
|
||||
this(name,
|
||||
new PrintStream(System.out));
|
||||
}
|
||||
|
||||
public GenericDocLoadListener(PrintStream ps) {
|
||||
this("GenericDocLoadListener", ps);
|
||||
}
|
||||
|
||||
public GenericDocLoadListener(String name, PrintStream ps) {
|
||||
this.name = name;
|
||||
this.ps = ps;
|
||||
}
|
||||
|
||||
public DocumentLoadListener getDocumentLoadListener() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void startURLLoad(String url, String contentType, Document doc) {
|
||||
if (ps != null) {
|
||||
ps.println(name + " :start URL load - " +
|
||||
url.toString() + " " +
|
||||
contentType);
|
||||
}
|
||||
}
|
||||
|
||||
public void endURLLoad(String url, int status, Document doc) {
|
||||
|
||||
if (ps != null) {
|
||||
ps.println(name + " :end URL load - " +
|
||||
url.toString() + " " +
|
||||
Integer.toHexString(status));
|
||||
}
|
||||
}
|
||||
|
||||
public void progressURLLoad(String url, int progress, int progressMax,
|
||||
Document doc) {
|
||||
if (ps != null) {
|
||||
ps.println(name + " :progress URL load - " +
|
||||
url.toString() + " " +
|
||||
Integer.toString(progress) + "/" +
|
||||
Integer.toString(progressMax));
|
||||
}
|
||||
}
|
||||
|
||||
public void statusURLLoad(String url, String message, Document doc) {
|
||||
if (ps != null) {
|
||||
ps.println(name + " :status URL load - " +
|
||||
url.toString() + " (" +
|
||||
message + ")");
|
||||
}
|
||||
}
|
||||
|
||||
public void startDocumentLoad(String url) {
|
||||
if (ps != null) {
|
||||
ps.println(name + " :start doc load - " +
|
||||
url.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void endDocumentLoad(String url, int status, Document doc) {
|
||||
if (ps != null) {
|
||||
ps.println(name + " :end doc load - " +
|
||||
url.toString() + " " +
|
||||
Integer.toHexString(status));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*/
|
||||
package org.mozilla.dom.util;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import org.w3c.dom.events.Event;
|
||||
import org.w3c.dom.events.EventListener;
|
||||
|
||||
public class GenericEventListener implements EventListener {
|
||||
|
||||
private String name;
|
||||
private PrintStream ps;
|
||||
|
||||
public GenericEventListener() {
|
||||
this("GenericEventListener",
|
||||
new PrintStream(System.out));
|
||||
}
|
||||
|
||||
public GenericEventListener(String name) {
|
||||
this(name, new PrintStream(System.out));
|
||||
}
|
||||
|
||||
public GenericEventListener(PrintStream ps) {
|
||||
this("GenericEventListener", ps);
|
||||
}
|
||||
|
||||
public GenericEventListener(String name, PrintStream ps) {
|
||||
this.name = name;
|
||||
this.ps = ps;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called whenever an event occurs of the type for which the
|
||||
* <code> EventListener</code> interface was registered.
|
||||
* @param event The <code>Event</code> contains contextual information about
|
||||
* the event. It also contains the <code>returnValue</code> and
|
||||
* <code>cancelBubble</code> properties which are used in determining
|
||||
* proper event flow.
|
||||
*/
|
||||
public void handleEvent(Event event) {
|
||||
try {
|
||||
if (ps != null) {
|
||||
ps.println(name + ": got event " + event);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (ps != null) {
|
||||
ps.println(name + ": exception in handleEvent " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -32,8 +32,7 @@ CPPSRCS = \
|
|||
javaDOMGlobals.cpp \
|
||||
javaDOMEventsGlobals.cpp \
|
||||
nativeDOMProxyListener.cpp \
|
||||
org_mozilla_dom_DOMGarbageCollector.cpp \
|
||||
org_mozilla_dom_DOMAccessorImpl.cpp \
|
||||
org_mozilla_dom_DOMAccessor.cpp \
|
||||
org_mozilla_dom_AttrImpl.cpp \
|
||||
org_mozilla_dom_CharacterDataImpl.cpp \
|
||||
org_mozilla_dom_DocumentImpl.cpp \
|
||||
|
|
|
@ -32,8 +32,7 @@ CPPSRCS = \
|
|||
javaDOMGlobals.cpp \
|
||||
javaDOMEventsGlobals.cpp \
|
||||
nativeDOMProxyListener.cpp \
|
||||
org_mozilla_dom_DOMGarbageCollector.cpp \
|
||||
org_mozilla_dom_DOMAccessorImpl.cpp \
|
||||
org_mozilla_dom_DOMAccessor.cpp \
|
||||
org_mozilla_dom_AttrImpl.cpp \
|
||||
org_mozilla_dom_CharacterDataImpl.cpp \
|
||||
org_mozilla_dom_DocumentImpl.cpp \
|
||||
|
|
|
@ -29,8 +29,7 @@ CPPSRCS= \
|
|||
javaDOMGlobals.cpp \
|
||||
javaDOMEventsGlobals.cpp \
|
||||
nativeDOMProxyListener.cpp \
|
||||
org_mozilla_dom_DOMAccessorImpl.cpp \
|
||||
org_mozilla_dom_DOMGarbageCollector.cpp \
|
||||
org_mozilla_dom_DOMAccessor.cpp \
|
||||
org_mozilla_dom_AttrImpl.cpp \
|
||||
org_mozilla_dom_CharacterDataImpl.cpp \
|
||||
org_mozilla_dom_DocumentImpl.cpp \
|
||||
|
@ -53,8 +52,7 @@ CPP_OBJS= \
|
|||
.\$(OBJDIR)\javaDOMGlobals.obj \
|
||||
.\$(OBJDIR)\javaDOMEventsGlobals.obj \
|
||||
.\$(OBJDIR)\nativeDOMProxyListener.obj \
|
||||
.\$(OBJDIR)\org_mozilla_dom_DOMAccessorImpl.obj \
|
||||
.\$(OBJDIR)\org_mozilla_dom_DOMGarbageCollector.obj \
|
||||
.\$(OBJDIR)\org_mozilla_dom_DOMAccessor.obj \
|
||||
.\$(OBJDIR)\org_mozilla_dom_AttrImpl.obj \
|
||||
.\$(OBJDIR)\org_mozilla_dom_CharacterDataImpl.obj \
|
||||
.\$(OBJDIR)\org_mozilla_dom_DocumentImpl.obj \
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
|
||||
#include "prlog.h"
|
||||
#include "javaDOMGlobals.h"
|
||||
#include "nsIDocumentLoader.h"
|
||||
#include "nsIDocumentLoaderObserver.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsCURILoader.h"
|
||||
|
||||
#include "nsIJavaDOM.h"
|
||||
#include "org_mozilla_dom_DOMAccessor.h"
|
||||
|
||||
static NS_DEFINE_IID(kDocLoaderServiceCID, NS_DOCUMENTLOADER_SERVICE_CID);
|
||||
static NS_DEFINE_IID(kJavaDOMCID, NS_JAVADOM_CID);
|
||||
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMAccessor
|
||||
* Method: register
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessor_register
|
||||
(JNIEnv *env, jclass jthis)
|
||||
{
|
||||
if (!JavaDOMGlobals::log) {
|
||||
JavaDOMGlobals::Initialize(env);
|
||||
}
|
||||
nsresult rv = NS_OK;
|
||||
NS_WITH_SERVICE(nsIDocumentLoader, docLoaderService, kDocLoaderServiceCID, &rv);
|
||||
if (NS_FAILED(rv) || !docLoaderService) {
|
||||
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
|
||||
("DOMAccessor::register: GetService(JavaDOM) failed: %x\n",
|
||||
rv));
|
||||
} else {
|
||||
NS_WITH_SERVICE(nsIDocumentLoaderObserver, javaDOM, kJavaDOMCID, &rv);
|
||||
if (NS_FAILED(rv) || !javaDOM) {
|
||||
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
|
||||
("DOMAccessor::register: GetService(JavaDOM) failed: %x\n",
|
||||
rv));
|
||||
} else {
|
||||
rv = docLoaderService->AddObserver((nsIDocumentLoaderObserver*)javaDOM);
|
||||
if (NS_FAILED(rv)) {
|
||||
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
|
||||
("DOMAccessor::register: AddObserver(JavaDOM) failed x\n",
|
||||
rv));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMAccessor
|
||||
* Method: unregister
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessor_unregister
|
||||
(JNIEnv *, jclass jthis)
|
||||
{
|
||||
PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG,
|
||||
("DOMAccessor::unregister: unregistering %x\n", jthis));
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
NS_WITH_SERVICE(nsIDocumentLoader, docLoaderService, kDocLoaderServiceCID, &rv);
|
||||
if (NS_FAILED(rv) || !docLoaderService) {
|
||||
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
|
||||
("DOMAccessor::unregister: GetService(DocLoaderService) failed %x\n",
|
||||
rv));
|
||||
} else {
|
||||
NS_WITH_SERVICE(nsIDocumentLoaderObserver, javaDOM, kJavaDOMCID, &rv);
|
||||
if (NS_FAILED(rv) || !javaDOM) {
|
||||
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
|
||||
("DOMAccessor::unregister: GetService(JavaDOM) failed %x\n",
|
||||
rv));
|
||||
} else {
|
||||
rv = docLoaderService->RemoveObserver((nsIDocumentLoaderObserver*)javaDOM);
|
||||
if (NS_FAILED(rv)) {
|
||||
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
|
||||
("DOMAccessor::unregister: RemoveObserver(JavaDOM) failed x\n",
|
||||
rv));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMAccessor
|
||||
* Method: createElement
|
||||
* Signature: (J)Lorg/w3c/dom/Element;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DOMAccessor_getNodeByHandle
|
||||
(JNIEnv *env, jclass jthis, jlong p)
|
||||
{
|
||||
if (!JavaDOMGlobals::log) {
|
||||
JavaDOMGlobals::Initialize(env);
|
||||
}
|
||||
nsIDOMNode *node = (nsIDOMNode*)p;
|
||||
return JavaDOMGlobals::CreateNodeSubtype(env, node);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMAccessor
|
||||
* Method: doGC
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessor_doGC
|
||||
(JNIEnv *, jclass)
|
||||
{
|
||||
JavaDOMGlobals::TakeOutGarbage();
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_mozilla_dom_DOMAccessor */
|
||||
|
||||
#ifndef _Included_org_mozilla_dom_DOMAccessor
|
||||
#define _Included_org_mozilla_dom_DOMAccessor
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* Inaccessible static: documentLoadListeners */
|
||||
/* Inaccessible static: permission */
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMAccessor
|
||||
* Method: register
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessor_register
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMAccessor
|
||||
* Method: unregister
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessor_unregister
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMAccessor
|
||||
* Method: getNodeByHandle
|
||||
* Signature: (J)Lorg/w3c/dom/Node;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DOMAccessor_getNodeByHandle
|
||||
(JNIEnv *, jclass, jlong);
|
||||
|
||||
/*
|
||||
* Class: org_mozilla_dom_DOMAccessor
|
||||
* Method: doGC
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessor_doGC
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,28 +1,25 @@
|
|||
Index: nsWebShell.cpp
|
||||
===================================================================
|
||||
RCS file: /cvsroot/mozilla/webshell/src/nsWebShell.cpp,v
|
||||
retrieving revision 1.377
|
||||
diff -r1.377 nsWebShell.cpp
|
||||
70a71
|
||||
>
|
||||
97a99,106
|
||||
retrieving revision 1.429
|
||||
diff -r1.429 nsWebShell.cpp
|
||||
111a112,116
|
||||
> #ifdef JAVA_DOM
|
||||
> #include "nsIJavaDOM.h"
|
||||
> static NS_DEFINE_IID(kJavaDOMCID, NS_JAVADOM_CID);
|
||||
> static NS_DEFINE_IID(kIJavaDOMIID, NS_IJAVADOM_IID);
|
||||
> #endif // JAVA_DOM
|
||||
3107a3113,3125
|
||||
>
|
||||
>
|
||||
>
|
||||
566a576
|
||||
>
|
||||
984a995,1003
|
||||
> #ifdef JAVA_DOM
|
||||
> nsresult jrv = NS_OK;
|
||||
> NS_WITH_SERVICE(nsISupports, javaDOM, kJavaDOMCID, &jrv);
|
||||
> NS_WITH_SERVICE(nsIDocumentLoaderObserver, javaDOM, kJavaDOMCID, &jrv);
|
||||
> if (NS_FAILED(jrv) || !javaDOM) {
|
||||
> fprintf(stderr,
|
||||
> "nsWebShell::Init: GetService of JavaDOM failed (error %x)\n",
|
||||
> jrv);
|
||||
> } else {
|
||||
> printf("\n webshell: added JAVADOM as observer...\n");
|
||||
> mDocLoader->AddObserver(javaDOM);
|
||||
> }
|
||||
> #endif // JAVA_DOM
|
||||
|
|
|
@ -34,11 +34,6 @@
|
|||
#include "nsIModule.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
|
||||
#ifdef JAVA_DOM_OJI_ENABLE
|
||||
#include "ProxyJNI.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG)
|
||||
#include <stdio.h>
|
||||
#include "nsIDOMElement.h"
|
||||
|
@ -53,8 +48,15 @@ static const char* describe_type(int type);
|
|||
#endif
|
||||
|
||||
#ifdef JAVA_DOM_OJI_ENABLE
|
||||
#include "ProxyJNI.h"
|
||||
#include "nsIServiceManager.h"
|
||||
nsJVMManager* nsJavaDOMImpl::jvmManager = NULL;
|
||||
JavaDOMSecurityContext* nsJavaDOMImpl::securityContext = NULL;
|
||||
static NS_DEFINE_CID(kJVMManagerCID,NS_JVMMANAGER_CID);
|
||||
#else
|
||||
JavaVM* nsJavaDOMImpl::jvm = NULL;
|
||||
#endif
|
||||
|
||||
static NS_DEFINE_IID(kIDocShellIID, NS_IDOCSHELL_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIJavaDOMIID, NS_IJAVADOM_IID);
|
||||
|
@ -65,6 +67,14 @@ static NS_DEFINE_IID(kIDocumentLoaderObserverIID, NS_IDOCUMENT_LOADER_OBSERVER_I
|
|||
NS_IMPL_ADDREF(nsJavaDOMImpl);
|
||||
NS_IMPL_RELEASE(nsJavaDOMImpl);
|
||||
|
||||
jclass nsJavaDOMImpl::domAccessorClass = NULL;
|
||||
|
||||
jmethodID nsJavaDOMImpl::startURLLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::endURLLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::progressURLLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::statusURLLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::startDocumentLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::endDocumentLoadMID = NULL;
|
||||
|
||||
#define NS_JAVADOM_PROGID \
|
||||
"component://netscape/blackwood/java-dom"
|
||||
|
@ -83,8 +93,6 @@ static nsModuleComponentInfo components[] =
|
|||
|
||||
NS_IMPL_NSGETMODULE("JavaDOMModule",components);
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP nsJavaDOMImpl::QueryInterface(REFNSIID aIID, void** aInstance)
|
||||
{
|
||||
if (NULL == aInstance)
|
||||
|
@ -111,126 +119,77 @@ NS_IMETHODIMP nsJavaDOMImpl::QueryInterface(REFNSIID aIID, void** aInstance)
|
|||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
#ifdef JAVA_DOM_OJI_ENABLE
|
||||
nsJVMManager* nsJavaDOMImpl::jvmManager = NULL;
|
||||
JavaDOMSecurityContext* nsJavaDOMImpl::securityContext = NULL;
|
||||
#else
|
||||
JavaVM* nsJavaDOMImpl::jvm = NULL;
|
||||
#endif
|
||||
|
||||
jclass nsJavaDOMImpl::domAccessorClass = NULL;
|
||||
jclass nsJavaDOMImpl::documentClass = NULL;
|
||||
jclass nsJavaDOMImpl::listenerClass = NULL;
|
||||
jclass nsJavaDOMImpl::gcClass = NULL;
|
||||
|
||||
jobject nsJavaDOMImpl::docListener = NULL;
|
||||
|
||||
jfieldID nsJavaDOMImpl::documentPtrFID = NULL;
|
||||
|
||||
jmethodID nsJavaDOMImpl::documentInitID = NULL;
|
||||
jmethodID nsJavaDOMImpl::getInstanceMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::startURLLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::endURLLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::progressURLLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::statusURLLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::startDocumentLoadMID = NULL;
|
||||
jmethodID nsJavaDOMImpl::endDocumentLoadMID = NULL;
|
||||
|
||||
jmethodID nsJavaDOMImpl::gcMID = NULL;
|
||||
|
||||
nsJavaDOMImpl::nsJavaDOMImpl()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
PRBool nsJavaDOMImpl::Init(JNIEnv** jniEnv) {
|
||||
JNIEnv* env = GetJNIEnv();
|
||||
if (!env) return PR_FALSE;
|
||||
*jniEnv = env;
|
||||
|
||||
gcClass = env->FindClass("org/mozilla/dom/DOMGarbageCollector");
|
||||
if (!gcClass) return;
|
||||
gcClass = (jclass) env->NewGlobalRef(gcClass);
|
||||
if (!gcClass) return;
|
||||
if (!domAccessorClass) {
|
||||
domAccessorClass = env->FindClass("org/mozilla/dom/DOMAccessor");
|
||||
if (!domAccessorClass) return PR_FALSE;
|
||||
domAccessorClass = (jclass) env->NewGlobalRef(domAccessorClass);
|
||||
if (!domAccessorClass) return PR_FALSE;
|
||||
|
||||
gcMID =
|
||||
env->GetStaticMethodID(gcClass,
|
||||
"doGC",
|
||||
"()V");
|
||||
if (!gcMID) return;
|
||||
startURLLoadMID =
|
||||
env->GetStaticMethodID(domAccessorClass,
|
||||
"startURLLoad",
|
||||
"(Ljava/lang/String;Ljava/lang/String;J)V");
|
||||
if (Cleanup(env) == PR_TRUE) {
|
||||
domAccessorClass = NULL;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
endURLLoadMID =
|
||||
env->GetStaticMethodID(domAccessorClass,
|
||||
"endURLLoad",
|
||||
"(Ljava/lang/String;IJ)V");
|
||||
if (Cleanup(env) == PR_TRUE) {
|
||||
domAccessorClass = NULL;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
domAccessorClass = env->FindClass("org/mozilla/dom/DOMAccessorImpl");
|
||||
if (!domAccessorClass) return;
|
||||
domAccessorClass = (jclass) env->NewGlobalRef(domAccessorClass);
|
||||
if (!domAccessorClass) return;
|
||||
progressURLLoadMID =
|
||||
env->GetStaticMethodID(domAccessorClass,
|
||||
"progressURLLoad",
|
||||
"(Ljava/lang/String;IIJ)V");
|
||||
if (Cleanup(env) == PR_TRUE) {
|
||||
domAccessorClass = NULL;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
getInstanceMID =
|
||||
env->GetStaticMethodID(domAccessorClass,
|
||||
"getInstance",
|
||||
"()Lorg/mozilla/dom/DOMAccessor;");
|
||||
if (!getInstanceMID) return;
|
||||
|
||||
docListener =
|
||||
env->CallStaticObjectMethod(domAccessorClass, getInstanceMID);
|
||||
if (!docListener) return;
|
||||
docListener = (jclass) env->NewGlobalRef(docListener);
|
||||
if (!docListener) return;
|
||||
|
||||
listenerClass =
|
||||
env->GetObjectClass(docListener);
|
||||
if (!listenerClass) return;
|
||||
listenerClass = (jclass) env->NewGlobalRef(listenerClass);
|
||||
if (!listenerClass) return;
|
||||
|
||||
documentClass =
|
||||
env->FindClass("org/mozilla/dom/DocumentImpl");
|
||||
if (!documentClass) return;
|
||||
documentClass = (jclass) env->NewGlobalRef(documentClass);
|
||||
if (!documentClass) return;
|
||||
|
||||
documentInitID =
|
||||
env->GetMethodID(documentClass, "<init>", "(J)V");
|
||||
if (!documentInitID) return;
|
||||
|
||||
documentPtrFID =
|
||||
env->GetFieldID(documentClass,
|
||||
"p_nsIDOMNode",
|
||||
"J");
|
||||
if (!documentPtrFID) return;
|
||||
|
||||
startURLLoadMID =
|
||||
env->GetMethodID(listenerClass,
|
||||
"startURLLoad",
|
||||
"(Ljava/lang/String;Ljava/lang/String;Lorg/w3c/dom/Document;)V");
|
||||
if (!startURLLoadMID) return;
|
||||
|
||||
endURLLoadMID =
|
||||
env->GetMethodID(listenerClass,
|
||||
"endURLLoad",
|
||||
"(Ljava/lang/String;ILorg/w3c/dom/Document;)V");
|
||||
if (!endURLLoadMID) return;
|
||||
|
||||
progressURLLoadMID =
|
||||
env->GetMethodID(listenerClass,
|
||||
"progressURLLoad",
|
||||
"(Ljava/lang/String;IILorg/w3c/dom/Document;)V");
|
||||
if (!progressURLLoadMID) return;
|
||||
|
||||
statusURLLoadMID =
|
||||
env->GetMethodID(listenerClass,
|
||||
"statusURLLoad",
|
||||
"(Ljava/lang/String;Ljava/lang/String;Lorg/w3c/dom/Document;)V");
|
||||
if (!statusURLLoadMID) return;
|
||||
|
||||
startDocumentLoadMID =
|
||||
env->GetMethodID(listenerClass,
|
||||
"startDocumentLoad",
|
||||
"(Ljava/lang/String;)V");
|
||||
if (!startDocumentLoadMID) return;
|
||||
|
||||
endDocumentLoadMID =
|
||||
env->GetMethodID(listenerClass,
|
||||
"endDocumentLoad",
|
||||
"(Ljava/lang/String;ILorg/w3c/dom/Document;)V");
|
||||
if (!endDocumentLoadMID) return;
|
||||
|
||||
Cleanup(env);
|
||||
statusURLLoadMID =
|
||||
env->GetStaticMethodID(domAccessorClass,
|
||||
"statusURLLoad",
|
||||
"(Ljava/lang/String;Ljava/lang/String;J)V");
|
||||
if (Cleanup(env) == PR_TRUE) {
|
||||
domAccessorClass = NULL;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
startDocumentLoadMID =
|
||||
env->GetStaticMethodID(domAccessorClass,
|
||||
"startDocumentLoad",
|
||||
"(Ljava/lang/String;)V");
|
||||
if (Cleanup(env) == PR_TRUE) {
|
||||
domAccessorClass = NULL;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
endDocumentLoadMID =
|
||||
env->GetStaticMethodID(domAccessorClass,
|
||||
"endDocumentLoad",
|
||||
"(Ljava/lang/String;IJ)V");
|
||||
if (Cleanup(env) == PR_TRUE) {
|
||||
domAccessorClass = NULL;
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsJavaDOMImpl::~nsJavaDOMImpl()
|
||||
|
@ -243,7 +202,6 @@ PRBool nsJavaDOMImpl::Cleanup(JNIEnv* env)
|
|||
env->ExceptionDescribe();
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
@ -290,43 +248,23 @@ nsIDOMDocument* nsJavaDOMImpl::GetDocument(nsIDocumentLoader* loader)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
// convert nsIDOMDocument to org.mozilla.dom.DocumentImpl
|
||||
jobject nsJavaDOMImpl::CaffienateDOMDocument(nsIDOMDocument* domDoc)
|
||||
{
|
||||
if (!domDoc) return NULL;
|
||||
JNIEnv* env = GetJNIEnv();
|
||||
|
||||
// jobject jdoc = env->AllocObject(documentClass);
|
||||
jobject jdoc = env->NewObject(documentClass,
|
||||
documentInitID,
|
||||
(jlong) (void*) domDoc);
|
||||
if (!jdoc) return NULL;
|
||||
// env->SetLongField(jdoc, documentPtrFID, (jlong) (void*) domDoc);
|
||||
if (Cleanup(env) == PR_TRUE) return NULL;
|
||||
|
||||
return jdoc;
|
||||
}
|
||||
|
||||
/* nsIDocumentLoaderObserver methods */
|
||||
|
||||
NS_IMETHODIMP nsJavaDOMImpl::OnStartDocumentLoad(nsIDocumentLoader* loader,
|
||||
nsIURI* aURL,
|
||||
const char* aCommand)
|
||||
{
|
||||
JNIEnv* env = GetJNIEnv();
|
||||
JNIEnv* env = NULL;
|
||||
if (Init(&env) == PR_FALSE) return NS_ERROR_FAILURE;
|
||||
|
||||
char* urlSpec = (char*) "";
|
||||
if (aURL)
|
||||
aURL->GetSpec(&urlSpec);
|
||||
jstring jURL = env->NewStringUTF(urlSpec);
|
||||
if (!jURL) return NS_ERROR_FAILURE;
|
||||
|
||||
env->CallVoidMethod(docListener,
|
||||
startDocumentLoadMID,
|
||||
jURL);
|
||||
env->CallStaticVoidMethod(domAccessorClass,
|
||||
startDocumentLoadMID,
|
||||
jURL);
|
||||
if (Cleanup(env) == PR_TRUE) return NS_ERROR_FAILURE;
|
||||
|
||||
env->CallStaticVoidMethod(gcClass, gcMID);
|
||||
Cleanup(env);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -334,7 +272,9 @@ NS_IMETHODIMP nsJavaDOMImpl::OnEndDocumentLoad(nsIDocumentLoader* loader,
|
|||
nsIChannel* channel,
|
||||
nsresult aStatus)
|
||||
{
|
||||
JNIEnv* env = GetJNIEnv();
|
||||
JNIEnv* env = NULL;
|
||||
if (Init(&env) == PR_FALSE) return NS_ERROR_FAILURE;
|
||||
|
||||
char* urlSpec = (char*) "";
|
||||
nsIURI* url = nsnull;
|
||||
if (channel && NS_SUCCEEDED(channel->GetURI(&url)))
|
||||
|
@ -343,24 +283,21 @@ NS_IMETHODIMP nsJavaDOMImpl::OnEndDocumentLoad(nsIDocumentLoader* loader,
|
|||
if (!jURL) return NS_ERROR_FAILURE;
|
||||
|
||||
nsIDOMDocument* domDoc = GetDocument(loader);
|
||||
jobject jdoc = CaffienateDOMDocument(domDoc);
|
||||
|
||||
env->CallVoidMethod(docListener,
|
||||
endDocumentLoadMID,
|
||||
jURL,
|
||||
(jint) aStatus,
|
||||
jdoc);
|
||||
env->CallStaticVoidMethod(domAccessorClass,
|
||||
endDocumentLoadMID,
|
||||
jURL,
|
||||
(jint) aStatus,
|
||||
(jlong)domDoc);
|
||||
if (Cleanup(env) == PR_TRUE) return NS_ERROR_FAILURE;
|
||||
|
||||
env->CallStaticVoidMethod(gcClass, gcMID);
|
||||
Cleanup(env);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsJavaDOMImpl::OnStartURLLoad(nsIDocumentLoader* loader,
|
||||
nsIChannel* channel)
|
||||
{
|
||||
JNIEnv* env = GetJNIEnv();
|
||||
JNIEnv* env = NULL;
|
||||
if (Init(&env) == PR_FALSE) return NS_ERROR_FAILURE;
|
||||
|
||||
char* urlSpec = (char*) "";
|
||||
nsIURI* url = nsnull;
|
||||
if (channel && NS_SUCCEEDED(channel->GetURI(&url)))
|
||||
|
@ -377,17 +314,12 @@ NS_IMETHODIMP nsJavaDOMImpl::OnStartURLLoad(nsIDocumentLoader* loader,
|
|||
if (!jContentType) return NS_ERROR_FAILURE;
|
||||
|
||||
nsIDOMDocument* domDoc = GetDocument(loader);
|
||||
jobject jdoc = CaffienateDOMDocument(domDoc);
|
||||
|
||||
env->CallVoidMethod(docListener,
|
||||
startURLLoadMID,
|
||||
jURL,
|
||||
jContentType,
|
||||
jdoc);
|
||||
env->CallStaticVoidMethod(domAccessorClass,
|
||||
startURLLoadMID,
|
||||
jURL,
|
||||
jContentType,
|
||||
(jlong)domDoc);
|
||||
if (Cleanup(env) == PR_TRUE) return NS_ERROR_FAILURE;
|
||||
|
||||
env->CallStaticVoidMethod(gcClass, gcMID);
|
||||
Cleanup(env);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -396,7 +328,9 @@ NS_IMETHODIMP nsJavaDOMImpl::OnProgressURLLoad(nsIDocumentLoader* loader,
|
|||
PRUint32 aProgress,
|
||||
PRUint32 aProgressMax)
|
||||
{
|
||||
JNIEnv* env = GetJNIEnv();
|
||||
JNIEnv* env = NULL;
|
||||
if (Init(&env) == PR_FALSE) return NS_ERROR_FAILURE;
|
||||
|
||||
char* urlSpec = (char*) "";
|
||||
nsIURI* url = nsnull;
|
||||
if (channel && NS_SUCCEEDED(channel->GetURI(&url)))
|
||||
|
@ -405,18 +339,13 @@ NS_IMETHODIMP nsJavaDOMImpl::OnProgressURLLoad(nsIDocumentLoader* loader,
|
|||
if (!jURL) return NS_ERROR_FAILURE;
|
||||
|
||||
nsIDOMDocument* domDoc = GetDocument(loader);
|
||||
jobject jdoc = CaffienateDOMDocument(domDoc);
|
||||
|
||||
env->CallVoidMethod(docListener,
|
||||
progressURLLoadMID,
|
||||
jURL,
|
||||
(jint) aProgress,
|
||||
(jint) aProgressMax,
|
||||
jdoc);
|
||||
env->CallStaticVoidMethod(domAccessorClass,
|
||||
progressURLLoadMID,
|
||||
jURL,
|
||||
(jint) aProgress,
|
||||
(jint) aProgressMax,
|
||||
(jlong)domDoc);
|
||||
if (Cleanup(env) == PR_TRUE) return NS_ERROR_FAILURE;
|
||||
|
||||
env->CallStaticVoidMethod(gcClass, gcMID);
|
||||
Cleanup(env);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -424,7 +353,9 @@ NS_IMETHODIMP nsJavaDOMImpl::OnStatusURLLoad(nsIDocumentLoader* loader,
|
|||
nsIChannel* channel,
|
||||
nsString& aMsg)
|
||||
{
|
||||
JNIEnv* env = GetJNIEnv();
|
||||
JNIEnv* env = NULL;
|
||||
if (Init(&env) == PR_FALSE) return NS_ERROR_FAILURE;
|
||||
|
||||
char* urlSpec = (char*) "";
|
||||
nsIURI* url = nsnull;
|
||||
if (channel && NS_SUCCEEDED(channel->GetURI(&url)))
|
||||
|
@ -437,17 +368,12 @@ NS_IMETHODIMP nsJavaDOMImpl::OnStatusURLLoad(nsIDocumentLoader* loader,
|
|||
if (!jMessage) return NS_ERROR_FAILURE;
|
||||
|
||||
nsIDOMDocument* domDoc = GetDocument(loader);
|
||||
jobject jdoc = CaffienateDOMDocument(domDoc);
|
||||
|
||||
env->CallVoidMethod(docListener,
|
||||
statusURLLoadMID,
|
||||
jURL,
|
||||
jMessage,
|
||||
jdoc);
|
||||
env->CallStaticVoidMethod(domAccessorClass,
|
||||
statusURLLoadMID,
|
||||
jURL,
|
||||
jMessage,
|
||||
(jlong)domDoc);
|
||||
if (Cleanup(env) == PR_TRUE) return NS_ERROR_FAILURE;
|
||||
|
||||
env->CallStaticVoidMethod(gcClass, gcMID);
|
||||
Cleanup(env);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -455,7 +381,9 @@ NS_IMETHODIMP nsJavaDOMImpl::OnEndURLLoad(nsIDocumentLoader* loader,
|
|||
nsIChannel* channel,
|
||||
nsresult aStatus)
|
||||
{
|
||||
JNIEnv* env = GetJNIEnv();
|
||||
JNIEnv* env = NULL;
|
||||
if (Init(&env) == PR_FALSE) return NS_ERROR_FAILURE;
|
||||
|
||||
char* urlSpec = (char*) "";
|
||||
nsIURI* url = nsnull;
|
||||
if (channel && NS_SUCCEEDED(channel->GetURI(&url)))
|
||||
|
@ -464,21 +392,15 @@ NS_IMETHODIMP nsJavaDOMImpl::OnEndURLLoad(nsIDocumentLoader* loader,
|
|||
if (!jURL) return NS_ERROR_FAILURE;
|
||||
|
||||
nsIDOMDocument* domDoc = GetDocument(loader);
|
||||
jobject jdoc = CaffienateDOMDocument(domDoc);
|
||||
|
||||
#if defined(DEBUG)
|
||||
dump_document(domDoc, urlSpec);
|
||||
#endif
|
||||
|
||||
env->CallVoidMethod(docListener,
|
||||
endURLLoadMID,
|
||||
jURL,
|
||||
(jint) aStatus,
|
||||
jdoc);
|
||||
env->CallStaticVoidMethod(domAccessorClass,
|
||||
endURLLoadMID,
|
||||
jURL,
|
||||
(jint) aStatus,
|
||||
(jlong)domDoc);
|
||||
if (Cleanup(env) == PR_TRUE) return NS_ERROR_FAILURE;
|
||||
|
||||
env->CallStaticVoidMethod(gcClass, gcMID);
|
||||
Cleanup(env);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -487,13 +409,9 @@ NS_IMETHODIMP nsJavaDOMImpl::HandleUnknownContentType(nsIDocumentLoader* loader,
|
|||
const char *aContentType,
|
||||
const char *aCommand)
|
||||
{
|
||||
JNIEnv* env = GetJNIEnv();
|
||||
env->CallStaticVoidMethod(gcClass, gcMID);
|
||||
Cleanup(env);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
JNIEnv* nsJavaDOMImpl::GetJNIEnv() {
|
||||
JNIEnv* env;
|
||||
#ifdef JAVA_DOM_OJI_ENABLE
|
||||
|
@ -511,7 +429,7 @@ JNIEnv* nsJavaDOMImpl::GetJNIEnv() {
|
|||
// if (!securityContext) {
|
||||
// securityContext = new JavaDOMSecurityContext();
|
||||
// }
|
||||
// SetSecurityContext(env,securityContext);
|
||||
// SetSecurityContext(env, securityContext);
|
||||
SetSecurityContext(env, new JavaDOMSecurityContext());
|
||||
#else /* JAVA_DOM_OJI_ENABLE */
|
||||
if (!jvm) {
|
||||
|
|
|
@ -58,16 +58,7 @@ class nsJavaDOMImpl : public nsIJavaDOM {
|
|||
#endif
|
||||
|
||||
static jclass domAccessorClass;
|
||||
static jclass documentClass;
|
||||
static jclass listenerClass;
|
||||
static jclass gcClass;
|
||||
|
||||
static jobject docListener;
|
||||
|
||||
static jfieldID documentPtrFID;
|
||||
static jmethodID documentInitID;
|
||||
|
||||
static jmethodID getInstanceMID;
|
||||
static jmethodID startURLLoadMID;
|
||||
static jmethodID endURLLoadMID;
|
||||
static jmethodID progressURLLoadMID;
|
||||
|
@ -75,14 +66,12 @@ class nsJavaDOMImpl : public nsIJavaDOM {
|
|||
static jmethodID startDocumentLoadMID;
|
||||
static jmethodID endDocumentLoadMID;
|
||||
|
||||
static jmethodID gcMID;
|
||||
|
||||
// cleanup after a JNI method invocation
|
||||
static PRBool Cleanup(JNIEnv* env);
|
||||
static JNIEnv* GetJNIEnv(void);
|
||||
static void StartJVM(void);
|
||||
static PRBool Init(JNIEnv**);
|
||||
// cleanup after a JNI method invocation
|
||||
static PRBool Cleanup(JNIEnv* env);
|
||||
nsIDOMDocument* GetDocument(nsIDocumentLoader* loader);
|
||||
jobject CaffienateDOMDocument(nsIDOMDocument* domDoc);
|
||||
};
|
||||
|
||||
#endif /* __nsJavaDOMImpl_h__ */
|
||||
|
|
Загрузка…
Ссылка в новой задаче