From 94ae7a6a49bfc1e0bb27ca33dd65f0b8434887d3 Mon Sep 17 00:00:00 2001 From: "edburns%acm.org" Date: Tue, 13 Mar 2007 06:21:45 +0000 Subject: [PATCH] Complete the thread safety changes. Ready to attempt alpha 6 release again. M logging.properties - Do not append. Create a new file each time. - Do not specify a limit. M dom/classes/org/mozilla/dom/AttrImpl.java M dom/classes/org/mozilla/dom/CharacterDataImpl.java M dom/classes/org/mozilla/dom/DOMAccessor.java M dom/classes/org/mozilla/dom/DOMImplementationImpl.java M dom/classes/org/mozilla/dom/DocumentImpl.java M dom/classes/org/mozilla/dom/DocumentTypeImpl.java M dom/classes/org/mozilla/dom/ElementImpl.java M dom/classes/org/mozilla/dom/EntityImpl.java M dom/classes/org/mozilla/dom/NamedNodeMapImpl.java M dom/classes/org/mozilla/dom/NodeImpl.java M dom/classes/org/mozilla/dom/NodeListImpl.java M dom/classes/org/mozilla/dom/NotationImpl.java M dom/classes/org/mozilla/dom/ProcessingInstructionImpl.java M dom/classes/org/mozilla/dom/events/EventImpl.java M dom/classes/org/mozilla/dom/events/MouseEventImpl.java M dom/classes/org/mozilla/dom/events/UIEventImpl.java - Use the new ReturnRunnable and RunnableRunner mechanism to ensure all DOM calls happen on the NativeEventThread M dom/jni/org_mozilla_dom_DocumentImpl.cpp - If the element is not found, make sure the exception thrown is a DOM Exception. M webclient/build-tests.xml - pass a test browser url. M webclient/classes_spec/org/mozilla/mcp/MCP.java - Use the CountDownLatch instead of wait/notify M webclient/classes_spec/org/mozilla/webclient/impl/WrapperFactory.java - public int loadNativeLibraryIfNecessary(); + public int loadNativeLibrariesIfNecessary(); M webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java - Fix error in log string M webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/NativeEventThread.java - Clean up log messages a bit. - Use CountDownLatch instead of wait/notify for synchronization M webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/WrapperFactoryImpl.java --- .../dom/classes/org/mozilla/dom/AttrImpl.java | 64 +- .../org/mozilla/dom/CharacterDataImpl.java | 114 +++- .../classes/org/mozilla/dom/DOMAccessor.java | 68 ++- .../mozilla/dom/DOMImplementationImpl.java | 92 ++- .../classes/org/mozilla/dom/DocumentImpl.java | 221 ++++++- .../org/mozilla/dom/DocumentTypeImpl.java | 80 ++- .../classes/org/mozilla/dom/ElementImpl.java | 246 +++++++- .../classes/org/mozilla/dom/EntityImpl.java | 41 +- .../org/mozilla/dom/NamedNodeMapImpl.java | 74 ++- .../dom/classes/org/mozilla/dom/NodeImpl.java | 553 +++++++++++++++--- .../classes/org/mozilla/dom/NodeListImpl.java | 63 +- .../classes/org/mozilla/dom/NotationImpl.java | 29 +- .../dom/ProcessingInstructionImpl.java | 41 +- .../org/mozilla/dom/events/EventImpl.java | 56 +- .../mozilla/dom/events/MouseEventImpl.java | 186 +++++- .../org/mozilla/dom/events/UIEventImpl.java | 53 +- java/dom/jni/org_mozilla_dom_DocumentImpl.cpp | 3 +- java/logging.properties | 3 +- java/webclient/build-tests.xml | 4 + .../classes_spec/org/mozilla/mcp/MCP.java | 59 +- .../webclient/impl/WrapperFactory.java | 2 +- .../impl/wrapper_native/CurrentPageImpl.java | 4 +- .../wrapper_native/NativeEventThread.java | 131 +++-- .../wrapper_native/WrapperFactoryImpl.java | 3 +- 24 files changed, 1915 insertions(+), 275 deletions(-) diff --git a/java/dom/classes/org/mozilla/dom/AttrImpl.java b/java/dom/classes/org/mozilla/dom/AttrImpl.java index 5cd2b3aa1bde..87bf49ae2cf2 100644 --- a/java/dom/classes/org/mozilla/dom/AttrImpl.java +++ b/java/dom/classes/org/mozilla/dom/AttrImpl.java @@ -26,28 +26,72 @@ import org.w3c.dom.DOMException; import org.w3c.dom.Element; import org.w3c.dom.TypeInfo; +import org.mozilla.util.ReturnRunnable; + public class AttrImpl extends NodeImpl implements Attr { // instantiated from JNI or Document.createAttribute() private AttrImpl() {} public String getName() { - return nativeGetName(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + + return nativeGetName(); + } + public String toString() { + return "DOMAccessor.register"; + } + }); + return result; } native String nativeGetName(); public boolean getSpecified() { - return nativeGetSpecified(); + Boolean boolResult = (Boolean) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return new Boolean(nativeGetSpecified()); + } + public String toString() { + return "DOMAccessor.register"; + } + }); + return boolResult.booleanValue(); } native boolean nativeGetSpecified(); public String getValue() { - return nativeGetValue(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetValue(); + } + public String toString() { + return "DOMAccessor.register"; + } + }); + return result; } native String nativeGetValue(); public void setValue(String value) { - nativeSetValue(value); + final String finalValue = value; + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeSetValue(finalValue); + return null; + } + public String toString() { + return "Attr.setValue"; + } + }); + } native void nativeSetValue(String value); @@ -57,7 +101,17 @@ public class AttrImpl extends NodeImpl implements Attr { * @since DOM Level 2 */ public Element getOwnerElement() { - return nativeGetOwnerElement(); + Element result = (Element) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetOwnerElement(); + } + public String toString() { + return "DOMAccessor.register"; + } + }); + return result; } native Element nativeGetOwnerElement(); diff --git a/java/dom/classes/org/mozilla/dom/CharacterDataImpl.java b/java/dom/classes/org/mozilla/dom/CharacterDataImpl.java index d153bc231938..43d7be20ee1c 100644 --- a/java/dom/classes/org/mozilla/dom/CharacterDataImpl.java +++ b/java/dom/classes/org/mozilla/dom/CharacterDataImpl.java @@ -23,49 +23,147 @@ package org.mozilla.dom; import org.w3c.dom.CharacterData; +import org.mozilla.util.ReturnRunnable; + public class CharacterDataImpl extends NodeImpl implements CharacterData { // instantiated from JNI only protected CharacterDataImpl() {} public void appendData(String arg) { - nativeAppendData(arg); + final String finalArg = arg; + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeAppendData(finalArg); + return null; + } + public String toString() { + return "CharacterData.appendData"; + } + }); + + } native void nativeAppendData(String arg); public void deleteData(int offset, int count) { - nativeDeleteData(offset, count); + final int finalOffset = offset; + final int finalCount = count; + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeDeleteData(finalOffset, finalCount); + return null; + } + public String toString() { + return "CharacterData.deleteData"; + } + }); + } native void nativeDeleteData(int offset, int count); public String getData() { - return nativeGetData(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetData(); + } + public String toString() { + return "CharacterData.getData"; + } + }); + return result; } native String nativeGetData(); public int getLength() { - return nativeGetLength(); + int result; + Integer integerResult = (Integer) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetLength(); + } + public String toString() { + return "CharacterData.getLength"; + } + }); + result = integerResult.intValue(); + return result; } native int nativeGetLength(); public void insertData(int offset, String arg) { - nativeInsertData(offset, arg); + final int finalOffset = offset; + final String finalArg = arg; + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeInsertData(finalOffset, finalArg); + return null; + } + public String toString() { + return "CharacterData.insertData"; + } + }); + } native void nativeInsertData(int offset, String arg); public void replaceData(int offset, int count, String arg) { - nativeReplaceData(offset, count, arg); + final int finalOffset = offset; + final int finalCount = count; + final String finalArg = arg; + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeReplaceData(finalOffset, finalCount, finalArg); + return null; + } + public String toString() { + return "CharacterData.replaceData"; + } + }); + } native void nativeReplaceData(int offset, int count, String arg); public void setData(String data) { - nativeSetData(data); + final String finalData = data; + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeSetData(finalData); + return null; + } + public String toString() { + return "CharacterData.setData"; + } + }); + + } native void nativeSetData(String data); public String substringData(int offset, int count) { - return nativeSubstringData(offset, count); + final int finalOffset = offset; + final int finalCount = count; + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeSubstringData(finalOffset, finalCount); + } + public String toString() { + return "CharacterData.substringData"; + } + }); + return result; + } native String nativeSubstringData(int offset, int count); } diff --git a/java/dom/classes/org/mozilla/dom/DOMAccessor.java b/java/dom/classes/org/mozilla/dom/DOMAccessor.java index a94cbffccf4f..76263bad9d19 100644 --- a/java/dom/classes/org/mozilla/dom/DOMAccessor.java +++ b/java/dom/classes/org/mozilla/dom/DOMAccessor.java @@ -134,9 +134,6 @@ public final class DOMAccessor { } private void DOMAccessorImpl() { - if (null == runnableRunner) { - runnableRunner = new SameThreadRunnableRunner(); - } } public static void setRunner(RunnableRunner runner) { @@ -144,31 +141,84 @@ public final class DOMAccessor { } public static RunnableRunner getRunner() { + if (null == runnableRunner) { + runnableRunner = new SameThreadRunnableRunner(); + } return runnableRunner; } private static void register() { - nativeRegister(); + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeRegister(); + return null; + } + public String toString() { + return "DOMAccessor.register"; + } + }); } private static native void nativeRegister(); private static void unregister() { - nativeUnregister(); + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeUnregister(); + return null; + } + public String toString() { + return "DOMAccessor.register"; + } + }); + } private static native void nativeUnregister(); public static Node getNodeByHandle(long p) { - return nativeGetNodeByHandle(p); + final long finalP = p; + Node result = (Node) DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetNodeByHandle(finalP); + } + public String toString() { + return "DOMAccessor.register"; + } + }); + return result; + } static native Node nativeGetNodeByHandle(long p); private static void doGC() { - nativeDoGC(); + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeDoGC(); + return null; + } + public String toString() { + return "DOMAccessor.register"; + } + }); + } private static native void nativeDoGC(); public static void initialize() { - nativeInitialize(); + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeInitialize(); + return null; + } + public String toString() { + return "DOMAccessor.register"; + } + }); + } public static native void nativeInitialize(); @@ -280,7 +330,7 @@ class SameThreadRunnableRunner implements RunnableRunner { } public Object pushBlockingReturnRunnable(ReturnRunnable toInvoke) throws RuntimeException { - toInvoke.run(); + toInvoke.setResult(toInvoke.run()); return toInvoke.getResult(); } diff --git a/java/dom/classes/org/mozilla/dom/DOMImplementationImpl.java b/java/dom/classes/org/mozilla/dom/DOMImplementationImpl.java index 6b00c21e1be4..e8fa22663d4c 100644 --- a/java/dom/classes/org/mozilla/dom/DOMImplementationImpl.java +++ b/java/dom/classes/org/mozilla/dom/DOMImplementationImpl.java @@ -26,6 +26,8 @@ import org.w3c.dom.Document; import org.w3c.dom.DocumentType; import org.w3c.dom.DOMException; +import org.mozilla.util.ReturnRunnable; + public class DOMImplementationImpl implements DOMImplementation { private long p_nsIDOMDOMImplementation = 0; @@ -45,34 +47,112 @@ public class DOMImplementationImpl implements DOMImplementation { } public boolean hasFeature(String feature, String version) { - return nativeHasFeature(feature, version); + final String finalFeature = feature; + final String finalVersion = version; + Boolean bool = (Boolean) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + boolean booleanResult = + nativeHasFeature(finalFeature, finalVersion); + return booleanResult ? Boolean.TRUE : Boolean.FALSE; + } + public String toString() { + return "DOMImplementation.hasFeature"; + } + }); + return bool.booleanValue(); + } native boolean nativeHasFeature(String feature, String version); protected void finalize() { - nativeFinalize(); + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeFinalize(); + return null; + } + public String toString() { + return "DOMImplementation.finalize"; + } + }); } protected native void nativeFinalize(); private boolean XPCOM_equals(Object o) { - return nativeXPCOM_equals(o); + final Object finalO = o; + Boolean bool = (Boolean) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + boolean booleanResult = nativeXPCOM_equals(finalO); + return booleanResult ? Boolean.TRUE : Boolean.FALSE; + } + public String toString() { + return "DOMImplementation.XPCOM_equals"; + } + }); + return bool.booleanValue(); + } native boolean nativeXPCOM_equals(Object o); private int XPCOM_hashCode() { - return nativeXPCOM_hashCode(); + Integer result = (Integer) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + int intResult = nativeXPCOM_hashCode(); + return Integer.valueOf(intResult); + } + public String toString() { + return "DOMImplementation.XPCOM_hashCode"; + } + }); + return result.intValue(); + } private native int nativeXPCOM_hashCode(); //since DOM2 public DocumentType createDocumentType(String qualifiedName, String publicID, String systemID) { - return nativeCreateDocumentType(qualifiedName, publicID, systemID); + final String finalQualifiedName = qualifiedName; + final String finalPublicID = publicID; + final String finalSystemID = systemID; + DocumentType result = (DocumentType) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + + return nativeCreateDocumentType(finalQualifiedName, finalPublicID, finalSystemID); + } + public String toString() { + return "DOMImplementation.createDocumentType"; + } + }); + return result; + } native DocumentType nativeCreateDocumentType(String qualifiedName, String publicID, String systemID); public Document createDocument(String namespaceURI, String qualifiedName, DocumentType doctype) { - return nativeCreateDocument(namespaceURI, qualifiedName, doctype); + final String finalNamespaceURI = namespaceURI; + final String finalQualifiedName = qualifiedName; + final DocumentType finalDoctype = doctype; + Document result = (Document) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeCreateDocument(finalNamespaceURI, finalQualifiedName, finalDoctype); + } + public String toString() { + return "DOMImplementation.createDocument"; + } + }); + return result; + } native Document nativeCreateDocument(String namespaceURI, String qualifiedName, DocumentType doctype); diff --git a/java/dom/classes/org/mozilla/dom/DocumentImpl.java b/java/dom/classes/org/mozilla/dom/DocumentImpl.java index 78780fec4b68..cf5c87db4cbc 100644 --- a/java/dom/classes/org/mozilla/dom/DocumentImpl.java +++ b/java/dom/classes/org/mozilla/dom/DocumentImpl.java @@ -39,90 +39,277 @@ import org.w3c.dom.events.DocumentEvent; import org.w3c.dom.events.Event; import org.w3c.dom.DOMException; +import org.mozilla.util.ReturnRunnable; + public class DocumentImpl extends NodeImpl implements Document, DocumentEvent { // instantiated from JNI only private DocumentImpl() {} public Attr createAttribute(String name) { - return nativeCreateAttribute(name); + final String finalName = name; + Attr result = (Attr) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeCreateAttribute(finalName); + } + public String toString() { + return "Document.createAttribute"; + } + }); + return result; + } native Attr nativeCreateAttribute(String name); public CDATASection createCDATASection(String data) { - return nativeCreateCDATASection(data); + final String finalData = data; + CDATASection result = (CDATASection) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeCreateCDATASection(finalData); + } + public String toString() { + return "Document.createCDATASection"; + } + }); + return result; + } native CDATASection nativeCreateCDATASection(String data); public Comment createComment(String data) { - return nativeCreateComment(data); + final String finalData = data; + Comment result = (Comment) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeCreateComment(finalData); + } + public String toString() { + return "Document.createComment"; + } + }); + return result; + } native Comment nativeCreateComment(String data); public DocumentFragment createDocumentFragment() { - return nativeCreateDocumentFragment(); + DocumentFragment result = (DocumentFragment) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeCreateDocumentFragment(); + } + public String toString() { + return "Document.createDocumentFragment"; + } + }); + return result; } native DocumentFragment nativeCreateDocumentFragment(); public Element createElement(String tagName) { - return nativeCreateElement(tagName); + final String finalTagName = tagName; + Element result = (Element) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeCreateElement(finalTagName); + } + public String toString() { + return "Document.createElement"; + } + }); + return result; + } native Element nativeCreateElement(String tagName); public EntityReference createEntityReference(String name) { - return nativeCreateEntityReference(name); + final String finalName = name; + EntityReference result = (EntityReference) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeCreateEntityReference(finalName); + } + public String toString() { + return "Document.createEntityReference"; + } + }); + return result; + } native EntityReference nativeCreateEntityReference(String name); public ProcessingInstruction createProcessingInstruction(String target, String data) { - return nativeCreateProcessingInstruction(target, data); + final String finalTarget = target; + final String finalData = data; + ProcessingInstruction result = (ProcessingInstruction) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeCreateProcessingInstruction(finalTarget, finalData); + } + public String toString() { + return "Document.createProcessingInstruction"; + } + }); + return result; + } native ProcessingInstruction nativeCreateProcessingInstruction(String target, String data); + public Text createTextNode(String data) { - return nativeCreateTextNode(data); + final String finalData = data; + Text result = (Text) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeCreateTextNode(finalData); + } + public String toString() { + return "Document.createTextNode"; + } + }); + return result; + } native Text nativeCreateTextNode(String data); public DocumentType getDoctype() { - return nativeGetDoctype(); + DocumentType result = (DocumentType) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetDoctype(); + } + public String toString() { + return "Document"; + } + }); + return result; } native DocumentType nativeGetDoctype(); public Element getDocumentElement() { - return nativeGetDocumentElement(); + Element result = (Element) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetDocumentElement(); + } + public String toString() { + return "Document"; + } + }); + return result; } native Element nativeGetDocumentElement(); public NodeList getElementsByTagName(String tagName) { - return nativeGetElementsByTagName(tagName); + final String finalTagName = tagName; + NodeList result = (NodeList) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetElementsByTagName(finalTagName); + } + public String toString() { + return "Document.getElementsByTagName"; + } + }); + return result; + } native NodeList nativeGetElementsByTagName(String tagName); public DOMImplementation getImplementation() { - return nativeGetImplementation(); + DOMImplementation result = (DOMImplementation) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetImplementation(); + } + public String toString() { + return "Document"; + } + }); + return result; } native DOMImplementation nativeGetImplementation(); public Event createEvent(String type) { - return nativeCreateEvent(type); + final String finalType = type; + Event result = (Event) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeCreateEvent(finalType); + } + public String toString() { + return "Document.createEvent"; + } + }); + return result; + } native Event nativeCreateEvent(String type); public NodeList getElementsByTagNameNS(String namespaceURI, String localName) { - return nativeGetElementsByTagNameNS(namespaceURI, localName); + final String finalNamespaceURI = namespaceURI; + final String finalLocalName = localName; + NodeList result = (NodeList) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetElementsByTagNameNS(finalNamespaceURI, finalLocalName); + } + public String toString() { + return "Document.getElementsByTagNameNS"; + } + }); + return result; + } native NodeList nativeGetElementsByTagNameNS(String namespaceURI, String localName); + public Element getElementById(String elementId) { - return nativeGetElementById(elementId); + final String finalElementId = elementId; + Element result = (Element) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetElementById(finalElementId); + } + public String toString() { + return "Document.getElementById"; + } + }); + return result; + } native Element nativeGetElementById(String elementId); public String getDocumentURI() { - return nativeGetDocumentURI(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetDocumentURI(); + } + public String toString() { + return "Document.getDocumentURI"; + } + }); + return result; } native String nativeGetDocumentURI(); - public Node importNode(Node importedNode, boolean deep) throws DOMException { throw new UnsupportedOperationException(); } diff --git a/java/dom/classes/org/mozilla/dom/DocumentTypeImpl.java b/java/dom/classes/org/mozilla/dom/DocumentTypeImpl.java index e3a358952a06..026705039848 100644 --- a/java/dom/classes/org/mozilla/dom/DocumentTypeImpl.java +++ b/java/dom/classes/org/mozilla/dom/DocumentTypeImpl.java @@ -23,6 +23,8 @@ package org.mozilla.dom; import org.w3c.dom.DocumentType; import org.w3c.dom.NamedNodeMap; +import org.mozilla.util.ReturnRunnable; + public class DocumentTypeImpl extends NodeImpl implements DocumentType { @@ -30,34 +32,100 @@ public class DocumentTypeImpl extends NodeImpl implements DocumentType { private DocumentTypeImpl() {} public String getName() { - return nativeGetName(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetName(); + } + public String toString() { + return "DocumentType.getName"; + } + }); + return result; + } native String nativeGetName(); public NamedNodeMap getEntities() { - return nativeGetEntities(); + NamedNodeMap result = (NamedNodeMap) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetEntities(); + } + public String toString() { + return "DocumentType.getEntities"; + } + }); + return result; + } native NamedNodeMap nativeGetEntities(); public NamedNodeMap getNotations() { - return nativeGetNotations(); + NamedNodeMap result = (NamedNodeMap) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetNotations(); + } + public String toString() { + return "DocumentType.getNotations"; + } + }); + return result; + } native NamedNodeMap nativeGetNotations(); //since DOM level 2 public String getPublicId() { - return nativeGetPublicId(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetPublicId(); + } + public String toString() { + return "DocumentType.getPublicId"; + } + }); + return result; + } native String nativeGetPublicId(); public String getSystemId() { - return nativeGetSystemId(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetSystemId(); + } + public String toString() { + return "DocumentType.getSystemId"; + } + }); + return result; + } native String nativeGetSystemId(); public String getInternalSubset() { - return nativeGetInternalSubset(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetInternalSubset(); + } + public String toString() { + return "DocumentType.getInternalSubset"; + } + }); + return result; + } native String nativeGetInternalSubset(); diff --git a/java/dom/classes/org/mozilla/dom/ElementImpl.java b/java/dom/classes/org/mozilla/dom/ElementImpl.java index 41d5004743fa..447de9e971e2 100644 --- a/java/dom/classes/org/mozilla/dom/ElementImpl.java +++ b/java/dom/classes/org/mozilla/dom/ElementImpl.java @@ -27,95 +27,307 @@ import org.w3c.dom.NodeList; import org.w3c.dom.DOMException; import org.w3c.dom.TypeInfo; +import org.mozilla.util.ReturnRunnable; + + public class ElementImpl extends NodeImpl implements Element { // instantiated from JNI or Document.createElement() private ElementImpl() {} public String getAttribute(String name) { - return nativeGetAttribute(name); + final String finalName = name; + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetAttribute(finalName); + } + public String toString() { + return "Element.getAttribute"; + } + }); + return result; + } native String nativeGetAttribute(String name); public Attr getAttributeNode(String name) { - return nativeGetAttributeNode(name); + final String finalName = name; + Attr result = (Attr) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetAttributeNode(finalName); + } + public String toString() { + return "Element.getAttributeNode"; + } + }); + return result; + } native Attr nativeGetAttributeNode(String name); public NodeList getElementsByTagName(String name) { - return nativeGetElementsByTagName(name); + final String finalName = name; + NodeList result = (NodeList) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetElementsByTagName(finalName); + } + public String toString() { + return "Element.getElementsByTagName"; + } + }); + return result; + } native NodeList nativeGetElementsByTagName(String name); public String getTagName() { - return nativeGetTagName(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetTagName(); + } + public String toString() { + return "Element.getTagName"; + } + }); + return result; + } native String nativeGetTagName(); public void normalize() { - nativeNormalize(); + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeNormalize(); + return null; + } + public String toString() { + return "Element.normalize"; + } + }); + } native void nativeNormalize(); public void removeAttribute(String name) { - nativeRemoveAttribute(name); + final String finalName = name; + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeRemoveAttribute(finalName); + return null; + } + public String toString() { + return "Element.removeAttribute"; + } + }); + + } native void nativeRemoveAttribute(String name); public Attr removeAttributeNode(Attr oldAttr) { - return nativeRemoveAttributeNode(oldAttr); + final Attr finalOldAttr = oldAttr; + Attr result = (Attr) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeRemoveAttributeNode(finalOldAttr); + } + public String toString() { + return "Element.removeAttributeNode"; + } + }); + return result; + } native Attr nativeRemoveAttributeNode(Attr oldAttr); public void setAttribute(String name, String value) { - nativeSetAttribute(name, value); + final String finalName = name; + final String finalValue = value; + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeSetAttribute(finalName, finalValue); + return null; + } + public String toString() { + return "Element.setAttribute"; + } + }); + } native void nativeSetAttribute(String name, String value); public Attr setAttributeNode(Attr newAttr) { - return nativeSetAttributeNode(newAttr); + final Attr finalNewAttr = newAttr; + Attr result = (Attr) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeSetAttributeNode(finalNewAttr); + } + public String toString() { + return "Element.setAttributeNode"; + } + }); + return result; + } native Attr nativeSetAttributeNode(Attr newAttr); //since DOM2 public String getAttributeNS(String namespaceURI, String localName) { - return nativeGetAttributeNS(namespaceURI, localName); + final String finalNamespaceURI = namespaceURI; + final String finalLocalName = localName; + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetAttributeNS(finalNamespaceURI, finalLocalName); + } + public String toString() { + return "Element.getAttributeNS"; + } + }); + return result; + } native String nativeGetAttributeNS(String namespaceURI, String localName); public void setAttributeNS(String namespaceURI, String qualifiedName, String value) { - nativeSetAttributeNS(namespaceURI, qualifiedName, value); + final String finalNamespaceURI = namespaceURI; + final String finalQualifiedName = qualifiedName; + final String finalValue = value; + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeSetAttributeNS(finalNamespaceURI, finalQualifiedName, finalValue); + return null; + } + public String toString() { + return "Element.setAttributeNS"; + } + }); + } native void nativeSetAttributeNS(String namespaceURI, String qualifiedName, String value); public void removeAttributeNS(String namespacURI, String localName) { - nativeRemoveAttributeNS(namespacURI, localName); + final String finalNamespacURI = namespacURI; + final String finalLocalName = localName; + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeRemoveAttributeNS(finalNamespacURI, finalLocalName); + return null; + } + public String toString() { + return "Element.removeAttributeNS"; + } + }); + } native void nativeRemoveAttributeNS(String namespacURI, String localName); public Attr getAttributeNodeNS(String namespaceURI, String localName) { - return nativeGetAttributeNodeNS(namespaceURI, localName); + final String finalNamespaceURI = namespaceURI; + final String finalLocalName = localName; + Attr result = (Attr) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetAttributeNodeNS(finalNamespaceURI, finalLocalName); + } + public String toString() { + return "Element.getAttributeNodeNS"; + } + }); + return result; + } native Attr nativeGetAttributeNodeNS(String namespaceURI, String localName); public Attr setAttributeNodeNS(Attr newAttr) { - return nativeSetAttributeNodeNS(newAttr); + final Attr finalNewAttr = newAttr; + Attr result = (Attr) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeSetAttributeNodeNS(finalNewAttr); + } + public String toString() { + return "Element.setAttributeNodeNS"; + } + }); + return result; + } native Attr nativeSetAttributeNodeNS(Attr newAttr); public NodeList getElementsByTagNameNS(String namespaceURI, String localName) { - return nativeGetElementsByTagNameNS(namespaceURI, localName); + final String finalNamespaceURI = namespaceURI; + final String finalLocalName = localName; + NodeList result = (NodeList) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetElementsByTagNameNS(finalNamespaceURI, finalLocalName); + } + public String toString() { + return "Element.getElementsByTagNameNS"; + } + }); + return result; + } native NodeList nativeGetElementsByTagNameNS(String namespaceURI, String localName); public boolean hasAttribute(String name) { - return nativeHasAttribute(name); + final String finalName = name; + Boolean result = (Boolean) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + boolean booleanResult = nativeHasAttribute(finalName); + return booleanResult ? Boolean.TRUE : Boolean.FALSE; + } + public String toString() { + return "Element.hasAttribute"; + } + }); + return result; + } native boolean nativeHasAttribute(String name); public boolean hasAttributeNS(String namespaceURI, String localName) { - return nativeHasAttributeNS(namespaceURI, localName); + final String finalNamespaceURI = namespaceURI; + final String finalLocalName = localName; + Boolean result = (Boolean) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + boolean booleanResult = + nativeHasAttributeNS(finalNamespaceURI, finalLocalName); + return booleanResult ? Boolean.TRUE : Boolean.FALSE; + } + public String toString() { + return "Element.hasAttributeNS"; + } + }); + return result; + } native boolean nativeHasAttributeNS(String namespaceURI, String localName); diff --git a/java/dom/classes/org/mozilla/dom/EntityImpl.java b/java/dom/classes/org/mozilla/dom/EntityImpl.java index 892e95bf9d7c..73ea25d5cb0a 100644 --- a/java/dom/classes/org/mozilla/dom/EntityImpl.java +++ b/java/dom/classes/org/mozilla/dom/EntityImpl.java @@ -23,23 +23,58 @@ package org.mozilla.dom; import org.w3c.dom.Entity; +import org.mozilla.util.ReturnRunnable; + public class EntityImpl extends NodeImpl implements Entity { // instantiated from JNI only private EntityImpl() {} public String getPublicId() { - return nativeGetPublicId(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetPublicId(); + } + public String toString() { + return "Entity.getPublicId"; + } + }); + return result; + } native String nativeGetPublicId(); public String getSystemId() { - return nativeGetSystemId(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetSystemId(); + } + public String toString() { + return "Entity.getSystemId"; + } + }); + return result; + } native String nativeGetSystemId(); public String getNotationName() { - return nativeGetNotationName(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetNotationName(); + } + public String toString() { + return "Entity.getNotationName"; + } + }); + return result; + } native String nativeGetNotationName(); diff --git a/java/dom/classes/org/mozilla/dom/NamedNodeMapImpl.java b/java/dom/classes/org/mozilla/dom/NamedNodeMapImpl.java index 8348c62e3872..9f13013488e4 100644 --- a/java/dom/classes/org/mozilla/dom/NamedNodeMapImpl.java +++ b/java/dom/classes/org/mozilla/dom/NamedNodeMapImpl.java @@ -25,6 +25,8 @@ import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.DOMException; +import org.mozilla.util.ReturnRunnable; + public class NamedNodeMapImpl implements NamedNodeMap { private long p_nsIDOMNamedNodeMap = 0; @@ -32,32 +34,90 @@ public class NamedNodeMapImpl implements NamedNodeMap { private NamedNodeMapImpl() {} public int getLength() { - return nativeGetLength(); + Integer result = (Integer) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + int intResult = nativeGetLength(); + return Integer.valueOf(intResult); + } + public String toString() { + return "NamedNodeMap.getLength"; + } + }); + return result.intValue(); + } native int nativeGetLength(); public Node getNamedItem(String name) { - return nativeGetNamedItem(name); + final String finalName = name; + Node result = (Node) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetNamedItem(finalName); + } + public String toString() { + return "NamedNodeMap.getNamedItem"; + } + }); + return result; + } native Node nativeGetNamedItem(String name); public Node item(int index) { - return nativeItem(index); + final int finalIndex = index; + Node result = (Node) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeItem(finalIndex); + } + public String toString() { + return "NamedNodeMap.item"; + } + }); + return result; + } native Node nativeItem(int index); public Node removeNamedItem(String name) { - return nativeRemoveNamedItem(name); + final String finalName = name; + Node result = (Node) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeRemoveNamedItem(finalName); + } + public String toString() { + return "NamedNodeMap.removeNamedItem"; + } + }); + return result; + } native Node nativeRemoveNamedItem(String name); public Node setNamedItem(Node arg) { - return nativeSetNamedItem(arg); + final Node finalArg = arg; + Node result = (Node) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeSetNamedItem(finalArg); + } + public String toString() { + return "NamedNodeMap.setNamedItem"; + } + }); + return result; + } native Node nativeSetNamedItem(Node arg); - - public Node getNamedItemNS(String namespaceURI, String localName) { throw new UnsupportedOperationException(); } diff --git a/java/dom/classes/org/mozilla/dom/NodeImpl.java b/java/dom/classes/org/mozilla/dom/NodeImpl.java index 1dae37df2a87..8888e67d18b5 100644 --- a/java/dom/classes/org/mozilla/dom/NodeImpl.java +++ b/java/dom/classes/org/mozilla/dom/NodeImpl.java @@ -33,6 +33,8 @@ import org.w3c.dom.events.EventListener; import java.util.Vector; import java.util.Hashtable; +import org.mozilla.util.ReturnRunnable; + class NodeEventListener { EventListener listener = null; String type = null; @@ -118,200 +120,566 @@ public class NodeImpl implements Node, EventTarget { } public boolean isSupported(String feature, String version) { - return nativeIsSupported(feature, version); + final String finalFeature = feature; + final String finalVersion = version; + Boolean result = (Boolean) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + boolean booleanResult = nativeIsSupported(finalFeature, finalVersion); + return booleanResult ? Boolean.TRUE : Boolean.FALSE; + } + public String toString() { + return "Node.isSupported"; + } + }); + return result.booleanValue(); + } native boolean nativeIsSupported(String feature, String version); + public boolean hasAttributes() { - return nativeHasAttributes(); + Boolean result = (Boolean) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + boolean booleanResult = nativeHasAttributes(); + return booleanResult ? Boolean.TRUE : Boolean.FALSE; + } + public String toString() { + return "Node.hasAttributes"; + } + }); + return result.booleanValue(); + } native boolean nativeHasAttributes(); public Node appendChild(Node newChild) throws DOMException { - return nativeAppendChild(newChild); + final Node finalNewChild = newChild; + Node result = (Node) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeAppendChild(finalNewChild); + } + public String toString() { + return "Node.appendChild"; + } + }); + return result; + } native Node nativeAppendChild(Node newChild) throws DOMException; public Node cloneNode(boolean deep) { - return nativeCloneNode(deep); + final boolean finalDeep = deep; + Node result = (Node) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeCloneNode(finalDeep); + } + public String toString() { + return "Node.cloneNode"; + } + }); + return result; + } native Node nativeCloneNode(boolean deep); public NamedNodeMap getAttributes() { - return nativeGetAttributes(); + NamedNodeMap result = (NamedNodeMap) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetAttributes(); + } + public String toString() { + return "Node.getAttributes"; + } + }); + return result; + } native NamedNodeMap nativeGetAttributes(); public NodeList getChildNodes() { - return nativeGetChildNodes(); + NodeList result = (NodeList) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetChildNodes(); + } + public String toString() { + return "Node.getChildNodes"; + } + }); + return result; + } native NodeList nativeGetChildNodes(); public Node getFirstChild() { - return nativeGetFirstChild(); + Node result = (Node) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetFirstChild(); + } + public String toString() { + return "Node.getFirstChild"; + } + }); + return result; + } native Node nativeGetFirstChild(); public Node getLastChild() { - return nativeGetLastChild(); + Node result = (Node) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetLastChild(); + } + public String toString() { + return "Node.getLastChild"; + } + }); + return result; + } native Node nativeGetLastChild(); public Node getNextSibling() { - return nativeGetNextSibling(); + Node result = (Node) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetNextSibling(); + } + public String toString() { + return "Node.getNextSibling"; + } + }); + return result; + } native Node nativeGetNextSibling(); public String getNodeName() { - return nativeGetNodeName(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetNodeName(); + } + public String toString() { + return "Node.getNodeName"; + } + }); + return result; + } native String nativeGetNodeName(); public short getNodeType() { - return nativeGetNodeType(); + Short result = (Short) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + short shortResult = nativeGetNodeType(); + return Short.valueOf(shortResult); + } + public String toString() { + return "Node.getNodeType"; + } + }); + return result.shortValue(); + } native short nativeGetNodeType(); public String getNodeValue() { - return nativeGetNodeValue(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetNodeValue(); + } + public String toString() { + return "Node.getNodeValue"; + } + }); + return result; + } native String nativeGetNodeValue(); public Document getOwnerDocument() { - return nativeGetOwnerDocument(); + Document result = (Document) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetOwnerDocument(); + } + public String toString() { + return "Node.getOwnerDocument"; + } + }); + return result; + } native Document nativeGetOwnerDocument(); public Node getParentNode() { - return nativeGetParentNode(); + Node result = (Node) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetParentNode(); + } + public String toString() { + return "Node.getParentNode"; + } + }); + return result; + } native Node nativeGetParentNode(); public Node getPreviousSibling() { - return nativeGetPreviousSibling(); + Node result = (Node) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetPreviousSibling(); + } + public String toString() { + return "Node.getPreviousSibling"; + } + }); + return result; + } native Node nativeGetPreviousSibling(); public boolean hasChildNodes() { - return nativeHasChildNodes(); + Boolean result = (Boolean) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + boolean booleanResult = nativeHasChildNodes(); + return booleanResult ? Boolean.TRUE : Boolean.FALSE; + } + public String toString() { + return "Node.hasChildNodes"; + } + }); + return result.booleanValue(); + } native boolean nativeHasChildNodes(); public Node insertBefore(Node newChild, Node refChild) throws DOMException { - return nativeInsertBefore(newChild, refChild); + final Node finalNewChild = newChild; + final Node finalRefChild = refChild; + Node result = (Node) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeInsertBefore(finalNewChild, finalRefChild); + } + public String toString() { + return "Node.insertBefore"; + } + }); + return result; + } native Node nativeInsertBefore(Node newChild, Node refChild) throws DOMException; + public Node removeChild(Node oldChild) throws DOMException { - return nativeRemoveChild(oldChild); + final Node finalOldChild = oldChild; + Node result = (Node) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeRemoveChild(finalOldChild); + } + public String toString() { + return "Node.removeChild"; + } + }); + return result; + } native Node nativeRemoveChild(Node oldChild) throws DOMException; public Node replaceChild(Node newChild, Node oldChild) throws DOMException { - return nativeReplaceChild(newChild, oldChild); + final Node finalNewChild = newChild; + final Node finalOldChild = oldChild; + Node result = (Node) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeReplaceChild(finalNewChild, finalOldChild); + } + public String toString() { + return "Node.replaceChild"; + } + }); + return result; + } native Node nativeReplaceChild(Node newChild, Node oldChild) throws DOMException; + public void setNodeValue(String nodeValue) { - nativeSetNodeValue(nodeValue); + final String finalNodeValue = nodeValue; + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeSetNodeValue(finalNodeValue); + return null; + } + public String toString() { + return "Node.setNodeValue"; + } + }); + + } native void nativeSetNodeValue(String nodeValue); public String getTextContent() throws DOMException { - return nativeGetTextContent(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetTextContent(); + } + public String toString() { + return "Node.getTextContent"; + } + }); + return result; + } native String nativeGetTextContent() throws DOMException; protected void finalize() { - nativeFinalize(); + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeFinalize(); + return null; + } + public String toString() { + return "Node.finalize"; + } + }); + } protected native void nativeFinalize(); private boolean XPCOM_equals(Object o) { - return nativeXPCOM_equals(o); + final Object finalO = o; + Boolean bool = (Boolean) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + boolean booleanResult = nativeXPCOM_equals(finalO); + return booleanResult ? Boolean.TRUE : Boolean.FALSE; + } + public String toString() { + return "Node.XPCOM_equals"; + } + }); + return bool.booleanValue(); + } native boolean nativeXPCOM_equals(Object o); private int XPCOM_hashCode() { - return nativeXPCOM_hashCode(); + Integer result = (Integer) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + int intResult = nativeXPCOM_hashCode(); + return Integer.valueOf(intResult); + } + public String toString() { + return "Node.XPCOM_hashCode"; + } + }); + return result.intValue(); + } private native int nativeXPCOM_hashCode(); //since DOM level 2 public boolean supports(String feature, String version) { - return nativeSupports(feature, version); + final String finalFeature = feature; + final String finalVersion = version; + Boolean result = (Boolean) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + boolean booleanResult = + nativeSupports(finalFeature, finalVersion); + return booleanResult ? Boolean.TRUE : Boolean.FALSE; + } + public String toString() { + return "Node.supports"; + } + }); + return result.booleanValue(); + } native boolean nativeSupports(String feature, String version); + public String getNamespaceURI() { - return nativeGetNamespaceURI(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetNamespaceURI(); + } + public String toString() { + return "Node.getNamespaceURI"; + } + }); + return result; + } native String nativeGetNamespaceURI(); public String getPrefix() { - return nativeGetPrefix(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetPrefix(); + } + public String toString() { + return "Node.getPrefix"; + } + }); + return result; + } native String nativeGetPrefix(); public void setPrefix(String prefix) { - nativeSetPrefix(prefix); + final String finalPrefix = prefix; + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeSetPrefix(finalPrefix); + return null; + } + public String toString() { + return "Node.setPrefix"; + } + }); } native void nativeSetPrefix(String prefix); public String getLocalName() { - return nativeGetLocalName(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetLocalName(); + } + public String toString() { + return "Node.getLocalName"; + } + }); + return result; + } native String nativeGetLocalName(); - public void addEventListener(String type, - EventListener listener, - boolean useCapture) { + public void addEventListener(String type, EventListener listener, boolean useCapture) { + final String finalType = type; + final EventListener finalListener = listener; + final boolean finalUseCapture = useCapture; - long nativeListener = addNativeEventListener(type, listener, useCapture); + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + long nativeListener = + addNativeEventListener(finalType, finalListener, + finalUseCapture); + Long lnode = new Long(p_nsIDOMNode); + + Vector listeners; + + //in conjunction with internal synchronization of Hashtable and Vector + // this should be enough for safe concurrent access + synchronized (javaDOMlisteners) { + listeners = (Vector) javaDOMlisteners.get(lnode); + + if (listeners == null) { + listeners = new Vector(); + javaDOMlisteners.put(lnode, listeners); + } + } + + if (nativeListener != 0) { + + NodeEventListener l = new NodeEventListener(finalType, + finalListener, + finalUseCapture, + nativeListener); + listeners.add(l); + } + return null; + } + public String toString() { + return "Node.addEventListener"; + } + }); - Long lnode = new Long(p_nsIDOMNode); - - Vector listeners; - - //in conjunction with internal synchronization of Hashtable and Vector - // this should be enough for safe concurrent access - synchronized (javaDOMlisteners) { - listeners = (Vector) javaDOMlisteners.get(lnode); - - if (listeners == null) { - listeners = new Vector(); - javaDOMlisteners.put(lnode, listeners); - } - } - - if (nativeListener != 0) { - - NodeEventListener l = new NodeEventListener(type, - listener, - useCapture, - nativeListener); - listeners.add(l); - } } - public void removeEventListener(String type, - EventListener listener, - boolean useCapture) { + public void removeEventListener(String type, EventListener listener, boolean useCapture) { + final String finalType = type; + final EventListener finalListener = listener; + final boolean finalUseCapture = useCapture; + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + Vector listeners = (Vector) javaDOMlisteners.get(new Long(p_nsIDOMNode)); + + if (listeners == null) + return null; + + NodeEventListener l = new NodeEventListener(finalType, + finalListener, + finalUseCapture, 0); - Vector listeners = (Vector) javaDOMlisteners.get(new Long(p_nsIDOMNode)); + int idx = listeners.indexOf(l); + + //if trying to remove non-existing listener then return + if (idx == -1) + return null; - if (listeners == null) - return; + l = (NodeEventListener) listeners.remove(idx); + + removeNativeEventListener(finalType, l.nativeListener, + finalUseCapture); + return null; + } + public String toString() { + return "Node.removeEventListener"; + } + }); - NodeEventListener l = new NodeEventListener(type, - listener, useCapture, 0); - - int idx = listeners.indexOf(l); - - //if trying to remove non-existing listener then return - if (idx == -1) - return; - - l = (NodeEventListener) listeners.remove(idx); - - removeNativeEventListener(type, l.nativeListener, useCapture); } public boolean dispatchEvent(Event evt) throws DOMException { @@ -319,12 +687,45 @@ public class NodeImpl implements Node, EventTarget { } private long addNativeEventListener(String type, EventListener listener, boolean useCapture) { - return nativeAddNativeEventListener(type, listener, useCapture); + final String finalType = type; + final EventListener finalListener = listener; + final boolean finalUseCapture = useCapture; + Long result = (Long) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + long longResult = + nativeAddNativeEventListener(finalType, + finalListener, + finalUseCapture); + return Long.valueOf(longResult); + } + public String toString() { + return "Node.addNativeEventListener"; + } + }); + return result.longValue(); + } private native long nativeAddNativeEventListener(String type, EventListener listener, boolean useCapture); private void removeNativeEventListener(String type, long nativeListener, boolean useCapture) { - nativeRemoveNativeEventListener(type, nativeListener, useCapture); + final String finalType = type; + final long finalNativeListener = nativeListener; + final boolean finalUseCapture = useCapture; + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeRemoveNativeEventListener(finalType, + finalNativeListener, + finalUseCapture); + return null; + } + public String toString() { + return "Node.removeNativeEventListener"; + } + }); + } private native void nativeRemoveNativeEventListener(String type, long nativeListener, boolean useCapture); diff --git a/java/dom/classes/org/mozilla/dom/NodeListImpl.java b/java/dom/classes/org/mozilla/dom/NodeListImpl.java index 3dc62226649e..157c4b60564d 100644 --- a/java/dom/classes/org/mozilla/dom/NodeListImpl.java +++ b/java/dom/classes/org/mozilla/dom/NodeListImpl.java @@ -24,6 +24,9 @@ package org.mozilla.dom; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import org.mozilla.util.ReturnRunnable; + + public class NodeListImpl implements NodeList { private long p_nsIDOMNodeList = 0; @@ -43,27 +46,73 @@ public class NodeListImpl implements NodeList { } public int getLength() { - return nativeGetLength(); + Integer result = (Integer) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + int intResult = nativeGetLength(); + return Integer.valueOf(intResult); + } + public String toString() { + return "NodeList.getLength"; + } + }); + return result; + } native int nativeGetLength(); public Node item(int index) { - return nativeItem(index); + final int finalIndex = index; + Node result = (Node) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeItem(finalIndex); + } + public String toString() { + return "NodeList.item"; + } + }); + return result; + } native Node nativeItem(int index); - protected void finalize() { - nativeFinalize(); - } protected native void nativeFinalize(); private boolean XPCOM_equals(Object o) { - return nativeXPCOM_equals(o); + final Object finalO = o; + Boolean bool = (Boolean) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + boolean booleanResult = nativeXPCOM_equals(finalO); + return booleanResult ? Boolean.TRUE : Boolean.FALSE; + } + public String toString() { + return "NodeList.XPCOM_equals"; + } + }); + return bool.booleanValue(); + } native boolean nativeXPCOM_equals(Object o); private int XPCOM_hashCode() { - return nativeXPCOM_hashCode(); + Integer result = (Integer) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + int intResult = nativeXPCOM_hashCode(); + return Integer.valueOf(intResult); + } + public String toString() { + return "NodeList.XPCOM_hashCode"; + } + }); + return result.intValue(); + } private native int nativeXPCOM_hashCode(); } diff --git a/java/dom/classes/org/mozilla/dom/NotationImpl.java b/java/dom/classes/org/mozilla/dom/NotationImpl.java index d90f67be88a2..f90bea5a3bda 100644 --- a/java/dom/classes/org/mozilla/dom/NotationImpl.java +++ b/java/dom/classes/org/mozilla/dom/NotationImpl.java @@ -23,18 +23,43 @@ package org.mozilla.dom; import org.w3c.dom.Notation; +import org.mozilla.util.ReturnRunnable; + + public class NotationImpl extends NodeImpl implements Notation { // instantiated from JNI only private NotationImpl() {} public String getPublicId() { - return nativeGetPublicId(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetPublicId(); + } + public String toString() { + return "Notation.getPublicId"; + } + }); + return result; + } native String nativeGetPublicId(); public String getSystemId() { - return nativeGetSystemId(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetSystemId(); + } + public String toString() { + return "Notation.getSystemId"; + } + }); + return result; + } native String nativeGetSystemId(); diff --git a/java/dom/classes/org/mozilla/dom/ProcessingInstructionImpl.java b/java/dom/classes/org/mozilla/dom/ProcessingInstructionImpl.java index 62b43515d9a3..784184d6a9a6 100644 --- a/java/dom/classes/org/mozilla/dom/ProcessingInstructionImpl.java +++ b/java/dom/classes/org/mozilla/dom/ProcessingInstructionImpl.java @@ -23,23 +23,58 @@ package org.mozilla.dom; import org.w3c.dom.ProcessingInstruction; +import org.mozilla.util.ReturnRunnable; + public class ProcessingInstructionImpl extends NodeImpl implements ProcessingInstruction { // instantiated from JNI or Document.createProcessingInstruction() private ProcessingInstructionImpl() {} public String getData() { - return nativeGetData(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetData(); + } + public String toString() { + return "ProcessingInstruction.getData"; + } + }); + return result; + } native String nativeGetData(); public String getTarget() { - return nativeGetTarget(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetTarget(); + } + public String toString() { + return "ProcessingInstruction.getTarget"; + } + }); + return result; + } native String nativeGetTarget(); public void setData(String data) { - nativeSetData(data); + final String finalData = data; + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeSetData(finalData); + return null; + } + public String toString() { + return "ProcessingInstruction.setData"; + } + }); + } native void nativeSetData(String data); diff --git a/java/dom/classes/org/mozilla/dom/events/EventImpl.java b/java/dom/classes/org/mozilla/dom/events/EventImpl.java index 9d53c5072438..fd905f30fa21 100644 --- a/java/dom/classes/org/mozilla/dom/events/EventImpl.java +++ b/java/dom/classes/org/mozilla/dom/events/EventImpl.java @@ -24,6 +24,9 @@ package org.mozilla.dom.events; import org.w3c.dom.Node; import org.w3c.dom.events.Event; import org.w3c.dom.events.EventTarget; +import org.mozilla.util.ReturnRunnable; +import org.mozilla.dom.DOMAccessor; + /** * The Event interface is used to provide contextual information @@ -55,7 +58,18 @@ public class EventImpl implements Event { * property. */ public String getType() { - return nativeGetType(); + String result = (String) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetType(); + } + public String toString() { + return "Event.getType"; + } + }); + return result; + } native String nativeGetType(); @@ -65,7 +79,18 @@ public class EventImpl implements Event { * to which the event was originally dispatched. */ public EventTarget getTarget() { - return nativeGetTarget(); + EventTarget result = (EventTarget) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetTarget(); + } + public String toString() { + return "Event.getTarget"; + } + }); + return result; + } native EventTarget nativeGetTarget(); @@ -76,7 +101,18 @@ public class EventImpl implements Event { * is particularly useful during capturing and bubbling. */ public EventTarget getCurrentTarget() { - return nativeGetCurrentTarget(); + EventTarget result = (EventTarget) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetCurrentTarget(); + } + public String toString() { + return "Event.getCurrentTarget"; + } + }); + return result; + } native EventTarget nativeGetCurrentTarget(); @@ -86,7 +122,19 @@ public class EventImpl implements Event { * is currently being evaluated. */ public short getEventPhase() { - return nativeGetEventPhase(); + Short result = (Short) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + short shortValue = nativeGetEventPhase(); + return Short.valueOf(shortValue); + } + public String toString() { + return "Event.getEventPhase"; + } + }); + return result.shortValue(); + } native short nativeGetEventPhase(); diff --git a/java/dom/classes/org/mozilla/dom/events/MouseEventImpl.java b/java/dom/classes/org/mozilla/dom/events/MouseEventImpl.java index 9042636fc0ff..54c6ba9ace06 100644 --- a/java/dom/classes/org/mozilla/dom/events/MouseEventImpl.java +++ b/java/dom/classes/org/mozilla/dom/events/MouseEventImpl.java @@ -26,6 +26,9 @@ import org.w3c.dom.views.AbstractView; import org.w3c.dom.events.MouseEvent; import org.w3c.dom.events.EventTarget; +import org.mozilla.util.ReturnRunnable; +import org.mozilla.dom.DOMAccessor; + /** * The MouseEvent interface provides specific contextual * information associated with Mouse events. @@ -59,7 +62,19 @@ public class MouseEventImpl extends UIEventImpl implements MouseEvent { * event occurred in relative to the origin of the screen coordinate system. */ public int getScreenX() { - return nativeGetScreenX(); + Integer result = (Integer) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + int intResult = nativeGetScreenX(); + return Integer.valueOf(intResult); + } + public String toString() { + return "MouseEvent.getScreenX"; + } + }); + return result.intValue(); + } native int nativeGetScreenX(); @@ -69,7 +84,19 @@ public class MouseEventImpl extends UIEventImpl implements MouseEvent { * occurred relative to the origin of the screen coordinate system. */ public int getScreenY() { - return nativeGetScreenY(); + Integer result = (Integer) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + int intResult = nativeGetScreenY(); + return Integer.valueOf(intResult); + } + public String toString() { + return "MouseEvent.getScreenY"; + } + }); + return result.intValue(); + } native int nativeGetScreenY(); @@ -79,7 +106,19 @@ public class MouseEventImpl extends UIEventImpl implements MouseEvent { * event occurred relative to the DOM implementation's client area. */ public int getClientX() { - return nativeGetClientX(); + Integer result = (Integer) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + int intResult = nativeGetClientX(); + return Integer.valueOf(intResult); + } + public String toString() { + return "MouseEvent.getClientX"; + } + }); + return result.intValue(); + } native int nativeGetClientX(); @@ -89,7 +128,19 @@ public class MouseEventImpl extends UIEventImpl implements MouseEvent { * occurred relative to the DOM implementation's client area. */ public int getClientY() { - return nativeGetClientY(); + Integer result = (Integer) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + int intResult = nativeGetClientY(); + return Integer.valueOf(intResult); + } + public String toString() { + return "MouseEvent.getClientY"; + } + }); + return result.intValue(); + } native int nativeGetClientY(); @@ -99,7 +150,19 @@ public class MouseEventImpl extends UIEventImpl implements MouseEvent { * during the firing of the event. */ public boolean getCtrlKey() { - return nativeGetCtrlKey(); + Boolean result = (Boolean) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + boolean booleanResult = nativeGetCtrlKey(); + return booleanResult ? Boolean.TRUE : Boolean.FALSE; + } + public String toString() { + return "MouseEvent.getCtrlKey"; + } + }); + return result.booleanValue(); + } native boolean nativeGetCtrlKey(); @@ -109,7 +172,19 @@ public class MouseEventImpl extends UIEventImpl implements MouseEvent { * during the firing of the event. */ public boolean getShiftKey() { - return nativeGetShiftKey(); + Boolean result = (Boolean) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + boolean booleanResult = nativeGetShiftKey(); + return booleanResult ? Boolean.TRUE : Boolean.FALSE; + } + public String toString() { + return "MouseEvent.getShiftKey"; + } + }); + return result.booleanValue(); + } native boolean nativeGetShiftKey(); @@ -120,7 +195,19 @@ public class MouseEventImpl extends UIEventImpl implements MouseEvent { * alternative key name. */ public boolean getAltKey() { - return nativeGetAltKey(); + Boolean result = (Boolean) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + boolean booleanResult = nativeGetAltKey(); + return booleanResult ? Boolean.TRUE : Boolean.FALSE; + } + public String toString() { + return "MouseEvent.getAltKey"; + } + }); + return result.booleanValue(); + } native boolean nativeGetAltKey(); @@ -131,7 +218,19 @@ public class MouseEventImpl extends UIEventImpl implements MouseEvent { * an alternative key name. */ public boolean getMetaKey() { - return nativeGetMetaKey(); + Boolean result = (Boolean) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + boolean booleanResult = nativeGetMetaKey(); + return booleanResult ? Boolean.TRUE : Boolean.FALSE; + } + public String toString() { + return "MouseEvent.getMetaKey"; + } + }); + return result.booleanValue(); + } native boolean nativeGetMetaKey(); @@ -142,7 +241,19 @@ public class MouseEventImpl extends UIEventImpl implements MouseEvent { * changed state. */ public short getButton() { - return nativeGetButton(); + Short result = (Short) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + short shortResult = nativeGetButton(); + return Short.valueOf(shortResult); + } + public String toString() { + return "MouseEvent.getButton"; + } + }); + return result.shortValue(); + } native short nativeGetButton(); @@ -152,7 +263,18 @@ public class MouseEventImpl extends UIEventImpl implements MouseEvent { * a UI event. */ public EventTarget getRelatedTarget() { - return nativeGetRelatedTarget(); + EventTarget result = (EventTarget) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetRelatedTarget(); + } + public String toString() { + return "MouseEvent.getRelatedTarget"; + } + }); + return result; + } native EventTarget nativeGetRelatedTarget(); @@ -196,10 +318,46 @@ public class MouseEventImpl extends UIEventImpl implements MouseEvent { boolean metaKeyArg, short buttonArg, EventTarget relatedTargetArg) { - nativeInitMouseEvent(typeArg, canBubbleArg, cancelableArg, viewArg, - detailArg, screenXArg, screenYArg, clientXArg, - clientYArg, ctrlKeyArg, altKeyArg, shiftKeyArg, - metaKeyArg, buttonArg, relatedTargetArg); + final String finalTypeArg = typeArg; + final boolean finalCanBubbleArg = canBubbleArg; + final boolean finalCancelableArg = cancelableArg; + final AbstractView finalViewArg = viewArg; + final int finalDetailArg = detailArg; + final int finalScreenXArg = screenXArg; + final int finalScreenYArg = screenYArg; + final int finalClientXArg = clientXArg; + final int finalClientYArg = clientYArg; + final boolean finalCtrlKeyArg = ctrlKeyArg; + final boolean finalAltKeyArg = altKeyArg; + final boolean finalShiftKeyArg = shiftKeyArg; + final boolean finalMetaKeyArg = metaKeyArg; + final short finalButtonArg = buttonArg; + final EventTarget finalRelatedTargetArg = relatedTargetArg; + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeInitMouseEvent(finalTypeArg, + finalCanBubbleArg, + finalCancelableArg, + finalViewArg, + finalDetailArg, + finalScreenXArg, + finalScreenYArg, + finalClientXArg, + finalClientYArg, + finalCtrlKeyArg, + finalAltKeyArg, + finalShiftKeyArg, + finalMetaKeyArg, + finalButtonArg, + finalRelatedTargetArg); + return null; + } + public String toString() { + return "MouseEvent.initMouseEvent"; + } + }); + } native void nativeInitMouseEvent(String typeArg, boolean canBubbleArg, diff --git a/java/dom/classes/org/mozilla/dom/events/UIEventImpl.java b/java/dom/classes/org/mozilla/dom/events/UIEventImpl.java index c19efcbadf11..37931351a774 100644 --- a/java/dom/classes/org/mozilla/dom/events/UIEventImpl.java +++ b/java/dom/classes/org/mozilla/dom/events/UIEventImpl.java @@ -25,6 +25,10 @@ import org.w3c.dom.events.UIEvent; import org.w3c.dom.views.AbstractView; import org.mozilla.dom.events.EventImpl; +import org.mozilla.util.ReturnRunnable; +import org.mozilla.dom.DOMAccessor; + + /** * The UIEvent interface provides specific contextual * information associated with User Interface events. @@ -48,7 +52,18 @@ public class UIEventImpl extends EventImpl implements UIEvent { * from which the event was generated. */ public AbstractView getView() { - return nativeGetView(); + AbstractView result = (AbstractView) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + return nativeGetView(); + } + public String toString() { + return "UIEvent.getView"; + } + }); + return result; + } public native AbstractView nativeGetView(); @@ -58,7 +73,19 @@ public class UIEventImpl extends EventImpl implements UIEvent { * on the type of event. */ public int getDetail() { - return nativeGetDetail(); + Integer result = (Integer) + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + int intResult = nativeGetDetail(); + return Integer.valueOf(intResult); + } + public String toString() { + return "UIEvent.getDetail"; + } + }); + return result.intValue(); + } public native int nativeGetDetail(); @@ -78,8 +105,26 @@ public class UIEventImpl extends EventImpl implements UIEvent { boolean cancelableArg, AbstractView viewArg, int detailArg) { - nativeInitUIEvent(typeArg, canBubbleArg, cancelableArg, viewArg, - detailArg); + final String finalTypeArg = typeArg; + final boolean finalCanBubbleArg = canBubbleArg; + final boolean finalCancelableArg = cancelableArg; + final AbstractView finalViewArg = viewArg; + final int finalDetailArg = detailArg; + DOMAccessor.getRunner(). + pushBlockingReturnRunnable(new ReturnRunnable() { + public Object run() { + nativeInitUIEvent(finalTypeArg, + finalCanBubbleArg, + finalCancelableArg, + finalViewArg, + finalDetailArg); + return null; + } + public String toString() { + return "UIEvent.initUIEvent"; + } + }); + } native void nativeInitUIEvent(String typeArg, boolean canBubbleArg, diff --git a/java/dom/jni/org_mozilla_dom_DocumentImpl.cpp b/java/dom/jni/org_mozilla_dom_DocumentImpl.cpp index a2de3f82b89f..d12bc2f4314c 100644 --- a/java/dom/jni/org_mozilla_dom_DocumentImpl.cpp +++ b/java/dom/jni/org_mozilla_dom_DocumentImpl.cpp @@ -753,7 +753,8 @@ JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_nativeGetElementById if (NS_FAILED(rv) || !element) { JavaDOMGlobals::ThrowException(env, - "Document.getElementById: failed", rv); + "Document.getElementById: failed", rv, + JavaDOMGlobals::EXCEPTION_DOM); return NULL; } diff --git a/java/logging.properties b/java/logging.properties index 9289c5a18af9..f363ef3f51f6 100644 --- a/java/logging.properties +++ b/java/logging.properties @@ -1,8 +1,7 @@ handlers= java.util.logging.FileHandler java.util.logging.FileHandler.pattern = %h/moz-java-log.xml -java.util.logging.FileHandler.limit = 50000 -java.util.logging.FileHandler.append = true +java.util.logging.FileHandler.append = false java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter org.mozilla.webclient.level=INFO diff --git a/java/webclient/build-tests.xml b/java/webclient/build-tests.xml index 384d638024ec..bb842649574c 100644 --- a/java/webclient/build-tests.xml +++ b/java/webclient/build-tests.xml @@ -82,6 +82,9 @@ + + @@ -230,6 +233,7 @@ PENDING(edburns): 20070130 XULRunner has no bookmarks + diff --git a/java/webclient/classes_spec/org/mozilla/mcp/MCP.java b/java/webclient/classes_spec/org/mozilla/mcp/MCP.java index 431a70b495ba..7ffcaa2eab8f 100755 --- a/java/webclient/classes_spec/org/mozilla/mcp/MCP.java +++ b/java/webclient/classes_spec/org/mozilla/mcp/MCP.java @@ -1,5 +1,5 @@ /* - * $Id: MCP.java,v 1.6 2007/03/09 04:34:24 edburns%acm.org Exp $ + * $Id: MCP.java,v 1.7 2007/03/13 06:21:44 edburns%acm.org Exp $ */ /* @@ -34,6 +34,7 @@ import java.awt.event.KeyListener; import java.awt.event.MouseListener; import java.io.FileNotFoundException; import java.util.Map; +import java.util.concurrent.CountDownLatch; import java.util.logging.Level; import java.util.logging.Logger; import org.mozilla.dom.util.DOMTreeDumper; @@ -81,6 +82,37 @@ public class MCP { private boolean initialized = false; private Robot robot; private DOMTreeDumper treeDumper = null; + private CountDownLatch latch = null; + + private void createLatch() { + if (null != latch) { + IllegalStateException ise = new IllegalStateException("Trying to set latch when latch is already set!"); + if (LOGGER.isLoggable(Level.WARNING)) { + LOGGER.throwing("org.mozilla.mcp.MCP", "createLatch", ise); + } + throw ise; + } + latch = new CountDownLatch(1); + } + + private void lockLatch() throws InterruptedException { + if (null == latch) { + IllegalStateException ise = new IllegalStateException("Trying to lock latch before it has been created!"); + if (LOGGER.isLoggable(Level.WARNING)) { + LOGGER.throwing("org.mozilla.mcp.MCP", "lockLatch", ise); + } + throw ise; + } + latch.await(); + } + + private void openLatch() { + if (null != latch || 1 != latch.getCount()) { + latch.countDown(); + latch = null; + } + } + public void setAppData(String absolutePathToNativeBrowserBinDir) throws FileNotFoundException, @@ -296,6 +328,7 @@ public class MCP { x = Integer.valueOf(clientX).intValue(); y = Integer.valueOf(clientY).intValue(); Robot robot = getRobot(); + createLatch(); robot.mouseMove(x, y); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); @@ -317,15 +350,12 @@ public class MCP { synchronized (this) { try { clickElement(idOrName); - this.wait(); - } - catch (IllegalStateException ise) { - LOGGER.throwing(this.getClass().getName(), "blockingClickElementGivenId", - ise); + lockLatch(); } catch (InterruptedException ie) { - LOGGER.throwing(this.getClass().getName(), "blockingClickElementGivenId", - ie); + if (LOGGER.isLoggable(Level.WARNING)) { + LOGGER.log(Level.WARNING, "blockingClickElementGivenId", ie); + } } } } @@ -334,12 +364,13 @@ public class MCP { Navigation2 nav = getNavigation(); synchronized (this) { nav.loadURL(url); + createLatch(); try { - this.wait(); + lockLatch(); } catch (InterruptedException ex) { - LOGGER.throwing(this.getClass().getName(), "blockingLoad", - ex); - ex.printStackTrace(); + if (LOGGER.isLoggable(Level.WARNING)) { + LOGGER.log(Level.WARNING, "blockingLoad", ex); + } } } } @@ -372,9 +403,7 @@ public class MCP { switch ((int)type) { case ((int) DocumentLoadEvent.END_AJAX_EVENT_MASK): case ((int) DocumentLoadEvent.END_DOCUMENT_LOAD_EVENT_MASK): - synchronized (owner) { - owner.notifyAll(); - } + openLatch(); break; case ((int) DocumentLoadEvent.START_URL_LOAD_EVENT_MASK): String method = (String) eventData.get("method"); diff --git a/java/webclient/classes_spec/org/mozilla/webclient/impl/WrapperFactory.java b/java/webclient/classes_spec/org/mozilla/webclient/impl/WrapperFactory.java index d471cf2533f6..eaeab7b836d8 100644 --- a/java/webclient/classes_spec/org/mozilla/webclient/impl/WrapperFactory.java +++ b/java/webclient/classes_spec/org/mozilla/webclient/impl/WrapperFactory.java @@ -63,7 +63,7 @@ public interface WrapperFactory { * @return implmentation specific native int. * */ - public int loadNativeLibraryIfNecessary(); + public int loadNativeLibrariesIfNecessary(); /** * diff --git a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java index 8cb938010eff..6cb9e62be7aa 100644 --- a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java +++ b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java @@ -60,7 +60,7 @@ public class CurrentPageImpl extends ImplObjectNative implements CurrentPage2, // Class Variables // - public static final String LOG = "org.mozilla.impl.wrapper_native.CurrentPageImpl"; + public static final String LOG = "org.mozilla.webclient.impl.wrapper_native.CurrentPageImpl"; public static final Logger LOGGER = Log.getLogger(LOG); @@ -310,7 +310,7 @@ public Document getDOM() public Object run() { Document result = nativeGetDOM(getNativeBrowserControl()); if (LOGGER.isLoggable((Level.INFO))) { - LOGGER.info("CurrentPageImpl.getDOM(): getting DOM with URI: " + + LOGGER.info("Getting DOM with URI: " + result.getDocumentURI()); } resultHolder[0] = result; diff --git a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/NativeEventThread.java b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/NativeEventThread.java index 3b170371d253..d4c71f6f8518 100644 --- a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/NativeEventThread.java +++ b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/NativeEventThread.java @@ -26,6 +26,7 @@ package org.mozilla.webclient.impl.wrapper_native; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.CountDownLatch; import java.util.logging.Level; import java.util.logging.Logger; import org.mozilla.util.Assert; @@ -35,10 +36,11 @@ import org.mozilla.util.ReturnRunnable; import org.mozilla.util.RunnableRunner; import org.mozilla.webclient.impl.WrapperFactory; +import org.w3c.dom.DOMException; /** *

This is a singleton class. All native events pass thru this class - * by virtue of the {@link #pushRunnable} or {@link pushBlockingWCRunnable} + * by virtue of the {@link #pushRunnable} or {@link pushBlockingreturnRunnable} * methods.

*/ @@ -65,7 +67,7 @@ public class NativeEventThread extends Thread implements RunnableRunner { private WrapperFactory wrapperFactory; private int nativeWrapperFactory; - private Queue blockingRunnables; + private Queue blockingRunnables; private Queue runnables; @@ -87,7 +89,7 @@ public class NativeEventThread extends Thread implements RunnableRunner { ParameterCheck.nonNull(yourFactory); wrapperFactory = yourFactory; - blockingRunnables = new ConcurrentLinkedQueue(); + blockingRunnables = new ConcurrentLinkedQueue(); runnables = new ConcurrentLinkedQueue(); } @@ -107,16 +109,19 @@ public class NativeEventThread extends Thread implements RunnableRunner { wrapperFactory = null; try { if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("NativeEventThread.delete: About to wait during delete()"); + LOGGER.finest("About to wait during delete()"); } wait(); if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("NativeEventThread.delete: Returned from wait during delete()"); + LOGGER.finest("Returned from wait during delete()"); } } catch (Exception e) { - System.out.println("NativeEventThread.delete: interrupted while waiting\n\t for NativeEventThread to notifyAll() after destruction of initContext: " + e + - " " + e.getMessage()); + if (LOGGER.isLoggable(Level.SEVERE)) { + LOGGER.log(Level.SEVERE, + "Interrupted while waiting for NativeEventThread " + + "to notifyAll() after destruction of initContext",e); + } } } wrapperFactory = null; @@ -141,7 +146,7 @@ public class NativeEventThread extends Thread implements RunnableRunner { public void run() { - nativeWrapperFactory = wrapperFactory.loadNativeLibraryIfNecessary(); + nativeWrapperFactory = wrapperFactory.loadNativeLibrariesIfNecessary(); // our owner must have put an event in the queue Assert.assert_it(!runnables.isEmpty()); @@ -151,7 +156,10 @@ public void run() wrapperFactory.notifyAll(); } catch (Exception e) { - System.out.println("NativeEventThread.run: exception trying to send notifyAll() to WrapperFactoryImpl on startup:" + e + " " + e.getMessage()); + if (LOGGER.isLoggable(Level.SEVERE)) { + LOGGER.log(Level.SEVERE, + "Exception trying to send notifyAll() to WrapperFactoryImpl on startup", e); + } } } @@ -163,9 +171,9 @@ public void run() } } -public void runUntilEventOfType(Class wcRunnableClass) { +public void runUntilEventOfType(Class returnRunnableClass) { ReturnRunnable result = null; - while (doEventLoopOnce(wcRunnableClass)) { + while (doEventLoopOnce(returnRunnableClass)) { } } @@ -173,9 +181,10 @@ public void runUntilEventOfType(Class wcRunnableClass) { * @return true if the event loop should continue to be executed, false otherwise */ - private boolean doEventLoopOnce(Class... wcRunnableClass) { + private boolean doEventLoopOnce(Class... returnRunnableClass) { Runnable runnable; - ReturnRunnable wcRunnable; + ReturnRunnableCountDownLatch latch; + ReturnRunnable returnRunnable; boolean result = true; try { Thread.sleep(1); @@ -185,7 +194,7 @@ public void runUntilEventOfType(Class wcRunnableClass) { " while sleeping: " + e.getMessage()); } runnable = runnables.poll(); - wcRunnable = blockingRunnables.poll(); + latch = blockingRunnables.poll(); synchronized (this) { // if we are have been told to delete ourselves if (null == this.wrapperFactory) { @@ -200,44 +209,39 @@ public void runUntilEventOfType(Class wcRunnableClass) { if (null!= runnable) { if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("NativeEventThread.run: About to run " + - runnable.toString()); + LOGGER.finest("About to run " + runnable.toString()); } runnable.run(); if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("NativeEventThread.run: Return from run " + - runnable.toString()); + LOGGER.finest("Return from run " + runnable.toString()); } } - if (null != wcRunnable) { + if (null != latch && null != latch.runnable) { + returnRunnable = latch.runnable; if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("NativeEventThread.run: About to run " + - wcRunnable.toString()); + LOGGER.finest("About to run " + returnRunnable.toString()); } - wcRunnable.setResult(wcRunnable.run()); - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("NativeEventThread.run: Return from run " + - wcRunnable.toString()); + try { + returnRunnable.setResult(returnRunnable.run()); } - // notify the pushBlockingWCRunnable() method. - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("NativeEventThread.run: About to enter synchronized block for " + - wcRunnable.toString()); - } - synchronized (wcRunnable) { - try { - wcRunnable.notifyAll(); - } - catch (Exception e) { - System.out.println("NativeEventThread.run: Exception: trying to notify for blocking result:" + e + " " + e.getMessage()); - } + catch (Throwable e) { + returnRunnable.setResult(e); } if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("NativeEventThread.run: Exited synchronized block for " + - wcRunnable.toString()); + LOGGER.finest("Return from run " + returnRunnable.toString()); } - if (0 < wcRunnableClass.length && - wcRunnable.getClass() == wcRunnableClass[0]) { + // notify the pushBlockingReturnRunnable() method. + if (LOGGER.isLoggable(Level.FINEST)) { + LOGGER.finest("About to notify User thread that " + + returnRunnable.toString() + " has returned."); + } + latch.latch.countDown(); + if (LOGGER.isLoggable(Level.FINEST)) { + LOGGER.finest("Successfully notified User thread that " + + returnRunnable.toString() + " has returned."); + } + if (0 < returnRunnableClass.length && + returnRunnable.getClass() == returnRunnableClass[0]) { result = false; } } @@ -272,34 +276,22 @@ public void runUntilEventOfType(Class wcRunnableClass) { return result; } - blockingRunnables.add(toInvoke); + ReturnRunnableCountDownLatch latch = new ReturnRunnableCountDownLatch(toInvoke); + blockingRunnables.add(latch); if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("NativeEventThread.pushBlockingWCRunnable:" + - " About to enter synchronized block for " + - toInvoke.toString()); + LOGGER.finest("User thread: About to wait for " + + toInvoke.toString() + " to complete."); } - synchronized (toInvoke) { - try { - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("NativeEventThread.pushBlockingWCRunnable:" + - " About to wait for NativeEventThread to run " + - toInvoke.toString()); - } - toInvoke.wait(); - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("NativeEventThread.pushBlockingWCRunnable:" + - " Return from wait for NativeEventThread to run " + - toInvoke.toString()); - } - } - catch (Exception se) { - System.out.println("NativeEventThread.pushBlockingWCRunnable: Exception: while waiting for blocking result: " + se + " " + se.getMessage()); - } + try { + latch.latch.await(); + } catch (InterruptedException ex) { + if (LOGGER.isLoggable(Level.SEVERE)) { + LOGGER.log(Level.SEVERE, "User thread: Interrupted while waiting for " + + latch.runnable.toString() + " to complete.", ex); + } } if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("NativeEventThread.pushBlockingWCRunnable:" + - " Exited synchronized block for " + - toInvoke.toString()); + LOGGER.finest("User thread: " + toInvoke.toString() + " returned."); } result = toInvoke.getResult(); if (result instanceof RuntimeException) { @@ -308,6 +300,15 @@ public void runUntilEventOfType(Class wcRunnableClass) { return result; } + + private class ReturnRunnableCountDownLatch { + ReturnRunnable runnable = null; + CountDownLatch latch = null; + ReturnRunnableCountDownLatch(ReturnRunnable runnable) { + this.runnable = runnable; + this.latch = new CountDownLatch(1); + } + } // // Native methods diff --git a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/WrapperFactoryImpl.java b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/WrapperFactoryImpl.java index e33b636be870..249fb5c72b64 100644 --- a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/WrapperFactoryImpl.java +++ b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/WrapperFactoryImpl.java @@ -283,11 +283,12 @@ public class WrapperFactoryImpl extends Object implements WrapperFactory { return profileName; } - public int loadNativeLibraryIfNecessary() { + public int loadNativeLibrariesIfNecessary() { System.loadLibrary("webclient"); System.setProperty(JAVADOM_LOADED_PROPERTY_NAME, "true"); try { System.loadLibrary("javadomjni"); + DOMAccessor.setRunner(NativeEventThread.instance); DOMAccessor.setNativeLibraryLoaded(true); } catch (Exception ex) {