From e483742f91903e1ba3ae6dcfb646382d45ee06c7 Mon Sep 17 00:00:00 2001 From: "ashuk%eng.sun.com" Date: Mon, 2 Apr 2001 21:18:06 +0000 Subject: [PATCH] Merging JAVADEV_RTM_20001102 into Trunk _Ashu git-svn-id: svn://10.0.0.236/trunk@91051 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/java/Makefile.in | 16 +- mozilla/java/dom/classes/Makefile | 7 + mozilla/java/dom/classes/Makefile.in | 10 + mozilla/java/dom/jni/Makefile | 4 +- mozilla/java/dom/jni/Makefile.in | 2 + mozilla/java/dom/jni/makefile.win | 2 + mozilla/java/dom/src/makefile.win | 2 + .../dom/tests/src/BWTestClass.lst.html.ORIG | 54 - .../dom/tests/src/BWTestClass.lst.xml.ORIG | 11 +- .../DocumentImpl_createEvent_String_1.java | 8 +- ...ntImpl_getAttributeNS_String_String_0.java | 25 +- ...ntImpl_getAttributeNS_String_String_1.java | 13 +- ...ntImpl_getAttributeNS_String_String_2.java | 13 +- ...ntImpl_getAttributeNS_String_String_3.java | 9 + ...pl_getAttributeNodeNS_String_String_0.java | 11 +- ...pl_getAttributeNodeNS_String_String_1.java | 13 +- ...pl_getAttributeNodeNS_String_String_2.java | 13 +- ...pl_getAttributeNodeNS_String_String_3.java | 25 +- ...etElementsByTagNameNS_String_String_0.java | 13 +- ...etElementsByTagNameNS_String_String_1.java | 15 +- ...etElementsByTagNameNS_String_String_2.java | 15 +- ...etElementsByTagNameNS_String_String_3.java | 17 +- ...ntImpl_hasAttributeNS_String_String_0.java | 11 +- ...ntImpl_hasAttributeNS_String_String_1.java | 13 +- ...ntImpl_hasAttributeNS_String_String_2.java | 13 +- ...ntImpl_hasAttributeNS_String_String_3.java | 19 +- ...mpl_removeAttributeNS_String_String_0.java | 11 +- ...mpl_removeAttributeNS_String_String_1.java | 13 +- ...mpl_removeAttributeNS_String_String_2.java | 13 +- ...mpl_removeAttributeNS_String_String_3.java | 23 +- ...setAttributeNS_String_String_String_0.java | 15 +- ...setAttributeNS_String_String_String_1.java | 17 +- ...setAttributeNS_String_String_String_2.java | 15 +- ...setAttributeNS_String_String_String_3.java | 17 +- ...setAttributeNS_String_String_String_4.java | 15 +- ...setAttributeNS_String_String_String_5.java | 17 +- ...setAttributeNS_String_String_String_6.java | 17 +- ...setAttributeNS_String_String_String_7.java | 19 +- ...setAttributeNS_String_String_String_8.java | 17 +- ...setAttributeNS_String_String_String_9.java | 27 +- ...ElementImpl_setAttributeNodeNS_Attr_0.java | 11 +- ...ElementImpl_setAttributeNodeNS_Attr_1.java | 33 +- mozilla/java/dom/tests/src/autorun.sh | 22 +- mozilla/java/dom/tests/src/test.xml | 40 +- mozilla/java/util/Makefile.in | 10 + .../java/webclient/classes_spec/Makefile.in | 31 + .../java/webclient/classes_spec/Makefile.win | 26 +- .../org/mozilla/webclient/BookmarkEntry.java | 1 + .../mozilla/webclient/BrowserControlImpl.java | 18 +- .../org/mozilla/webclient/CurrentPage.java | 4 +- .../org/mozilla/webclient/Navigation.java | 17 + .../webclient/PrefChangedCallback.java | 30 + .../org/mozilla/webclient/Preferences.java | 35 + .../org/mozilla/webclient/Prompt.java | 136 ++ .../org/mozilla/webclient/test/EMWindow.java | 402 ++++- .../webclient/test/EmbeddedMozilla.java | 6 +- .../webclient/test/PasswordDialog.java | 194 +++ .../webclient/test/RandomHTMLInputStream.java | 268 ++++ .../webclient/test/UniversalDialog.java | 217 +++ .../wrapper_native/BookmarkEntryImpl.java | 17 +- .../wrapper_native/BookmarksImpl.java | 28 +- .../wrapper_native/CurrentPageImpl.java | 105 +- .../wrapper_native/NativeEventThread.java | 22 +- .../wrapper_native/NavigationImpl.java | 50 +- .../wrapper_native/PreferencesImpl.java | 186 +++ .../webclient/wrapper_native/RDFTreeNode.java | 84 +- .../wrapper_native/WrapperFactoryImpl.java | 6 +- mozilla/java/webclient/src_ie/CMyDialog.cpp | 2 +- .../java/webclient/src_moz/BookmarksImpl.cpp | 4 +- .../webclient/src_moz/CBrowserContainer.cpp | 203 ++- .../webclient/src_moz/CBrowserContainer.h | 2 + .../src_moz/CurrentPageActionEvents.cpp | 334 ++++ .../src_moz/CurrentPageActionEvents.h | 110 ++ .../webclient/src_moz/CurrentPageImpl.cpp | 214 +-- .../webclient/src_moz/HistoryActionEvents.cpp | 282 ++++ .../webclient/src_moz/HistoryActionEvents.h | 117 ++ .../java/webclient/src_moz/HistoryImpl.cpp | 69 +- .../webclient/src_moz/InputStreamShim.cpp | 414 +++++ .../java/webclient/src_moz/InputStreamShim.h | 179 +++ mozilla/java/webclient/src_moz/Makefile.in | 110 +- mozilla/java/webclient/src_moz/Makefile.win | 66 +- .../webclient/src_moz/NativeEventThread.cpp | 223 ++- .../src_moz/NativeEventThreadActionEvents.cpp | 160 ++ .../src_moz/NativeEventThreadActionEvents.h | 69 + .../src_moz/NavigationActionEvents.cpp | 258 ++++ .../src_moz/NavigationActionEvents.h | 116 ++ .../java/webclient/src_moz/NavigationImpl.cpp | 110 +- .../src_moz/PreferencesActionEvents.cpp | 283 ++++ .../src_moz/PreferencesActionEvents.h | 113 ++ .../webclient/src_moz/PreferencesImpl.cpp | 298 ++++ .../webclient/src_moz/PromptActionEvents.cpp | 211 +++ .../webclient/src_moz/PromptActionEvents.h | 89 ++ .../webclient/src_moz/RDFActionEvents.cpp | 934 +++++++++++ .../java/webclient/src_moz/RDFActionEvents.h | 188 +++ .../java/webclient/src_moz/RDFEnumeration.cpp | 3 +- .../java/webclient/src_moz/RDFTreeNode.cpp | 46 +- .../src_moz/WindowControlActionEvents.cpp | 299 ++++ .../src_moz/WindowControlActionEvents.h | 128 ++ .../webclient/src_moz/WindowControlImpl.cpp | 17 +- .../webclient/src_moz/WrapperFactoryImpl.cpp | 2 +- .../java/webclient/src_moz/install_win32.js | 64 + .../src_moz/motif/NativeLoaderStub.cpp | 160 +- mozilla/java/webclient/src_moz/nsActions.cpp | 1360 +---------------- mozilla/java/webclient/src_moz/nsActions.h | 430 ------ mozilla/java/webclient/src_moz/ns_util.cpp | 51 +- mozilla/java/webclient/src_moz/ns_util.h | 32 +- mozilla/java/webclient/src_moz/rdf_util.cpp | 36 + mozilla/java/webclient/src_moz/rdf_util.h | 4 + .../webclient/src_moz/wcIBrowserContainer.h | 6 +- .../java/webclient/src_moz/wsRDFObserver.cpp | 112 ++ .../java/webclient/src_moz/wsRDFObserver.h | 62 + mozilla/java/webclient/src_share/Makefile.in | 2 + mozilla/java/webclient/src_share/Makefile.win | 7 +- mozilla/java/webclient/src_share/jni_util.cpp | 268 +++- mozilla/java/webclient/src_share/jni_util.h | 57 +- .../webclient/src_share/jni_util_export.cpp | 7 + .../webclient/src_share/jni_util_export.h | 41 + mozilla/java/webclient/src_share/runem.pl | 5 + mozilla/java/webclient/test/index.html | 3 + 119 files changed, 8389 insertions(+), 2560 deletions(-) create mode 100644 mozilla/java/webclient/classes_spec/org/mozilla/webclient/PrefChangedCallback.java create mode 100644 mozilla/java/webclient/classes_spec/org/mozilla/webclient/Preferences.java create mode 100644 mozilla/java/webclient/classes_spec/org/mozilla/webclient/Prompt.java create mode 100644 mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/PasswordDialog.java create mode 100644 mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/RandomHTMLInputStream.java create mode 100644 mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/UniversalDialog.java create mode 100644 mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/PreferencesImpl.java create mode 100644 mozilla/java/webclient/src_moz/CurrentPageActionEvents.cpp create mode 100644 mozilla/java/webclient/src_moz/CurrentPageActionEvents.h create mode 100644 mozilla/java/webclient/src_moz/HistoryActionEvents.cpp create mode 100644 mozilla/java/webclient/src_moz/HistoryActionEvents.h create mode 100644 mozilla/java/webclient/src_moz/InputStreamShim.cpp create mode 100644 mozilla/java/webclient/src_moz/InputStreamShim.h create mode 100644 mozilla/java/webclient/src_moz/NativeEventThreadActionEvents.cpp create mode 100644 mozilla/java/webclient/src_moz/NativeEventThreadActionEvents.h create mode 100644 mozilla/java/webclient/src_moz/NavigationActionEvents.cpp create mode 100644 mozilla/java/webclient/src_moz/NavigationActionEvents.h create mode 100644 mozilla/java/webclient/src_moz/PreferencesActionEvents.cpp create mode 100644 mozilla/java/webclient/src_moz/PreferencesActionEvents.h create mode 100644 mozilla/java/webclient/src_moz/PreferencesImpl.cpp create mode 100644 mozilla/java/webclient/src_moz/PromptActionEvents.cpp create mode 100644 mozilla/java/webclient/src_moz/PromptActionEvents.h create mode 100644 mozilla/java/webclient/src_moz/RDFActionEvents.cpp create mode 100644 mozilla/java/webclient/src_moz/RDFActionEvents.h create mode 100644 mozilla/java/webclient/src_moz/WindowControlActionEvents.cpp create mode 100644 mozilla/java/webclient/src_moz/WindowControlActionEvents.h create mode 100644 mozilla/java/webclient/src_moz/install_win32.js create mode 100644 mozilla/java/webclient/src_moz/wsRDFObserver.cpp create mode 100644 mozilla/java/webclient/src_moz/wsRDFObserver.h create mode 100644 mozilla/java/webclient/test/index.html diff --git a/mozilla/java/Makefile.in b/mozilla/java/Makefile.in index 87f9bc0053d..57eb5dbdf2e 100644 --- a/mozilla/java/Makefile.in +++ b/mozilla/java/Makefile.in @@ -25,14 +25,16 @@ srcdir = @srcdir@ include $(DEPTH)/config/autoconf.mk -# PENDING(edburns): make it so it's possible to just build -# webclient and javadom - DIRS= util \ - dom \ - plugins \ - webclient \ - $(NULL) + external \ + dom + +ifeq ($(BUILD_WEBCLIENT_ONLY),) +DIRS += xpcom \ + plugins +endif + +DIRS += webclient include $(topsrcdir)/config/rules.mk diff --git a/mozilla/java/dom/classes/Makefile b/mozilla/java/dom/classes/Makefile index ba2e6ff2646..b931b14fc1c 100644 --- a/mozilla/java/dom/classes/Makefile +++ b/mozilla/java/dom/classes/Makefile @@ -40,3 +40,10 @@ JAVAC_PROG = $(JDKHOME)/bin/javac JAVAC_FLAGS = -classpath $(CLASSPATH):$(JAVA_DESTPATH) -d $(JAVA_DESTPATH) JAVAC = $(JAVAC_PROG) $(JAVAC_FLAGS) +rm_java: +ifeq ($(PACKAGE_BUILD),) + rm -Rf $(topsrcdir)/dist/classes/org/mozilla/dom +endif # PACKAGE_BUILD + + +clobber_all::rm_java diff --git a/mozilla/java/dom/classes/Makefile.in b/mozilla/java/dom/classes/Makefile.in index c4bb3e107bb..4a3e66d1ae5 100644 --- a/mozilla/java/dom/classes/Makefile.in +++ b/mozilla/java/dom/classes/Makefile.in @@ -33,6 +33,16 @@ JDIRS = org/mozilla/dom \ $(NULL) +rm_java: +ifeq ($(PACKAGE_BUILD),) + rm -Rf $(topsrcdir)/dist/classes/org/mozilla/dom +endif # PACKAGE_BUILD + + +clobber_all::rm_java + + + include $(DEPTH)/config/autoconf.mk include $(topsrcdir)/config/rules.mk diff --git a/mozilla/java/dom/jni/Makefile b/mozilla/java/dom/jni/Makefile index 2186f073798..575ef466de9 100644 --- a/mozilla/java/dom/jni/Makefile +++ b/mozilla/java/dom/jni/Makefile @@ -48,7 +48,7 @@ CPPSRCS = \ org_mozilla_dom_TextImpl.cpp \ org_mozilla_dom_events_EventImpl.cpp \ org_mozilla_dom_events_UIEventImpl.cpp \ - org_mozilla_dom_events_MouseEventImpl.cpp + org_mozilla_dom_events_MouseEventImpl.cpp include $(topsrcdir)/config/config.mk @@ -80,5 +80,7 @@ JAVAH_FLAGS=-jni -classpath $(CLASSPATH):$(JAVA_DESTPATH) export:: $(JAVAH_PROG) $(JAVAH_FLAGS) $(JAVA_CLS) +clobber_all:: clobber + clobber:: rm -f org_*.h diff --git a/mozilla/java/dom/jni/Makefile.in b/mozilla/java/dom/jni/Makefile.in index 0102469a8e6..575ef466de9 100644 --- a/mozilla/java/dom/jni/Makefile.in +++ b/mozilla/java/dom/jni/Makefile.in @@ -80,5 +80,7 @@ JAVAH_FLAGS=-jni -classpath $(CLASSPATH):$(JAVA_DESTPATH) export:: $(JAVAH_PROG) $(JAVAH_FLAGS) $(JAVA_CLS) +clobber_all:: clobber + clobber:: rm -f org_*.h diff --git a/mozilla/java/dom/jni/makefile.win b/mozilla/java/dom/jni/makefile.win index ce0b90ce66c..7f5b19f1612 100755 --- a/mozilla/java/dom/jni/makefile.win +++ b/mozilla/java/dom/jni/makefile.win @@ -122,6 +122,8 @@ install:: $(DLL) $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib +clobber_all:: clobber + clobber:: rm -f $(DIST)\bin\$(DLLNAME).dll rm -f $(DIST)\lib\$(DLLNAME).lib diff --git a/mozilla/java/dom/src/makefile.win b/mozilla/java/dom/src/makefile.win index 4a4ac23cf12..84268a8b169 100644 --- a/mozilla/java/dom/src/makefile.win +++ b/mozilla/java/dom/src/makefile.win @@ -79,6 +79,8 @@ install:: $(DLL) $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib +clobber_all:: clobber + clobber:: rm -f $(DIST)\bin\components\$(DLLNAME).dll rm -f $(DIST)\lib\$(DLLNAME).lib diff --git a/mozilla/java/dom/tests/src/BWTestClass.lst.html.ORIG b/mozilla/java/dom/tests/src/BWTestClass.lst.html.ORIG index da375a2598e..81399d7d317 100755 --- a/mozilla/java/dom/tests/src/BWTestClass.lst.html.ORIG +++ b/mozilla/java/dom/tests/src/BWTestClass.lst.html.ORIG @@ -68,19 +68,11 @@ org.mozilla.dom.test.DOMImplementationImpl_createDocument_String_String_Document org.mozilla.dom.test.DOMImplementationImpl_createDocument_String_String_DocumentType_4 org.mozilla.dom.test.DocumentImpl_createAttribute_String_0 org.mozilla.dom.test.DocumentImpl_createAttribute_String_1 -org.mozilla.dom.test.DocumentImpl_createAttributeNS_String_String_0 -org.mozilla.dom.test.DocumentImpl_createAttributeNS_String_String_1 -org.mozilla.dom.test.DocumentImpl_createAttributeNS_String_String_2 -org.mozilla.dom.test.DocumentImpl_createAttributeNS_String_String_3 org.mozilla.dom.test.DocumentImpl_createComment_String_0 org.mozilla.dom.test.DocumentImpl_createComment_String_1 org.mozilla.dom.test.DocumentImpl_createDocumentFragment org.mozilla.dom.test.DocumentImpl_createElement_String_0 org.mozilla.dom.test.DocumentImpl_createElement_String_1 -org.mozilla.dom.test.DocumentImpl_createElement_createElementNS_String_String_0 -org.mozilla.dom.test.DocumentImpl_createElement_createElementNS_String_String_1 -org.mozilla.dom.test.DocumentImpl_createElement_createElementNS_String_String_2 -org.mozilla.dom.test.DocumentImpl_createElement_createElementNS_String_String_3 org.mozilla.dom.test.DocumentImpl_createEvent_String_0 org.mozilla.dom.test.DocumentImpl_createEvent_String_1 org.mozilla.dom.test.DocumentImpl_createEvent_String_2 @@ -90,10 +82,6 @@ org.mozilla.dom.test.DocumentImpl_getDoctype org.mozilla.dom.test.DocumentImpl_getDocumentElement org.mozilla.dom.test.DocumentImpl_getElementsByTagName_String_0 org.mozilla.dom.test.DocumentImpl_getElementsByTagName_String_1 -org.mozilla.dom.test.DocumentImpl_getElementsByTagNameNS_String_String_0 -org.mozilla.dom.test.DocumentImpl_getElementsByTagNameNS_String_String_1 -org.mozilla.dom.test.DocumentImpl_getElementsByTagNameNS_String_String_2 -org.mozilla.dom.test.DocumentImpl_getElementsByTagNameNS_String_String_3 org.mozilla.dom.test.DocumentImpl_getElementById_String_0 org.mozilla.dom.test.DocumentImpl_getElementById_String_1 org.mozilla.dom.test.DocumentImpl_getElementById_String_2 @@ -106,76 +94,34 @@ org.mozilla.dom.test.ElementImpl_getAttributeNode_String_0 org.mozilla.dom.test.ElementImpl_getAttributeNode_String_1 org.mozilla.dom.test.ElementImpl_getAttribute_String_0 org.mozilla.dom.test.ElementImpl_getAttribute_String_1 -org.mozilla.dom.test.ElementImpl_getAttributeNS_String_String_0 -org.mozilla.dom.test.ElementImpl_getAttributeNS_String_String_1 -org.mozilla.dom.test.ElementImpl_getAttributeNS_String_String_2 -org.mozilla.dom.test.ElementImpl_getAttributeNS_String_String_3 -org.mozilla.dom.test.ElementImpl_getAttributeNodeNS_String_String_0 -org.mozilla.dom.test.ElementImpl_getAttributeNodeNS_String_String_1 -org.mozilla.dom.test.ElementImpl_getAttributeNodeNS_String_String_2 -org.mozilla.dom.test.ElementImpl_getAttributeNodeNS_String_String_3 org.mozilla.dom.test.ElementImpl_getElementsByTagName_String_0 org.mozilla.dom.test.ElementImpl_getElementsByTagName_String_1 -org.mozilla.dom.test.ElementImpl_getElementsByTagNameNS_String_String_0 -org.mozilla.dom.test.ElementImpl_getElementsByTagNameNS_String_String_1 -org.mozilla.dom.test.ElementImpl_getElementsByTagNameNS_String_String_2 -org.mozilla.dom.test.ElementImpl_getElementsByTagNameNS_String_String_3 org.mozilla.dom.test.ElementImpl_getTagName org.mozilla.dom.test.ElementImpl_hasAttribute_String_0 org.mozilla.dom.test.ElementImpl_hasAttribute_String_1 -org.mozilla.dom.test.ElementImpl_hasAttributeNS_String_String_0 -org.mozilla.dom.test.ElementImpl_hasAttributeNS_String_String_1 -org.mozilla.dom.test.ElementImpl_hasAttributeNS_String_String_2 -org.mozilla.dom.test.ElementImpl_hasAttributeNS_String_String_3 org.mozilla.dom.test.ElementImpl_normalize org.mozilla.dom.test.ElementImpl_removeAttributeNode_Attr_0 org.mozilla.dom.test.ElementImpl_removeAttributeNode_Attr_1 org.mozilla.dom.test.ElementImpl_removeAttribute_String_0 org.mozilla.dom.test.ElementImpl_removeAttribute_String_1 -org.mozilla.dom.test.ElementImpl_removeAttributeNS_String_String_0 -org.mozilla.dom.test.ElementImpl_removeAttributeNS_String_String_1 -org.mozilla.dom.test.ElementImpl_removeAttributeNS_String_String_2 -org.mozilla.dom.test.ElementImpl_removeAttributeNS_String_String_3 org.mozilla.dom.test.ElementImpl_setAttributeNode_Attr_0 org.mozilla.dom.test.ElementImpl_setAttributeNode_Attr_1 org.mozilla.dom.test.ElementImpl_setAttributeNode_Attr_2 -org.mozilla.dom.test.ElementImpl_setAttributeNodeNS_Attr_0 -org.mozilla.dom.test.ElementImpl_setAttributeNodeNS_Attr_1 org.mozilla.dom.test.ElementImpl_setAttribute_String_String_0 org.mozilla.dom.test.ElementImpl_setAttribute_String_String_1 org.mozilla.dom.test.ElementImpl_setAttribute_String_String_2 org.mozilla.dom.test.ElementImpl_setAttribute_String_String_3 -org.mozilla.dom.test.ElementImpl_setAttributeNS_String_String_String_0 -org.mozilla.dom.test.ElementImpl_setAttributeNS_String_String_String_1 -org.mozilla.dom.test.ElementImpl_setAttributeNS_String_String_String_2 -org.mozilla.dom.test.ElementImpl_setAttributeNS_String_String_String_3 -org.mozilla.dom.test.ElementImpl_setAttributeNS_String_String_String_4 -org.mozilla.dom.test.ElementImpl_setAttributeNS_String_String_String_5 -org.mozilla.dom.test.ElementImpl_setAttributeNS_String_String_String_6 -org.mozilla.dom.test.ElementImpl_setAttributeNS_String_String_String_7 -org.mozilla.dom.test.ElementImpl_setAttributeNS_String_String_String_8 -org.mozilla.dom.test.ElementImpl_setAttributeNS_String_String_String_9 org.mozilla.dom.test.NamedNodeMapImpl_getLength org.mozilla.dom.test.NamedNodeMapImpl_getNamedItem_String_0 org.mozilla.dom.test.NamedNodeMapImpl_getNamedItem_String_1 -org.mozilla.dom.test.NamedNodeMapImpl_getNamedItemNS_String_String_0 -org.mozilla.dom.test.NamedNodeMapImpl_getNamedItemNS_String_String_1 -org.mozilla.dom.test.NamedNodeMapImpl_getNamedItemNS_String_String_2 -org.mozilla.dom.test.NamedNodeMapImpl_getNamedItemNS_String_String_3 org.mozilla.dom.test.NamedNodeMapImpl_item_int_0 org.mozilla.dom.test.NamedNodeMapImpl_item_int_1 org.mozilla.dom.test.NamedNodeMapImpl_item_int_2 org.mozilla.dom.test.NamedNodeMapImpl_removeNamedItem_String_0 org.mozilla.dom.test.NamedNodeMapImpl_removeNamedItem_String_1 -org.mozilla.dom.test.NamedNodeMapImpl_removeNamedItemNS_String_String_0 -org.mozilla.dom.test.NamedNodeMapImpl_removeNamedItemNS_String_String_1 -org.mozilla.dom.test.NamedNodeMapImpl_removeNamedItemNS_String_String_2 -org.mozilla.dom.test.NamedNodeMapImpl_removeNamedItemNS_String_String_3 org.mozilla.dom.test.NamedNodeMapImpl_setNamedItem_Node_0 org.mozilla.dom.test.NamedNodeMapImpl_setNamedItem_Node_1 org.mozilla.dom.test.NamedNodeMapImpl_setNamedItem_Node_2 -org.mozilla.dom.test.NamedNodeMapImpl_setNamedItemNS_Node_0 -org.mozilla.dom.test.NamedNodeMapImpl_setNamedItemNS_Node_1 org.mozilla.dom.test.NodeImpl_appendChild_Node_0 org.mozilla.dom.test.NodeImpl_appendChild_Node_1 org.mozilla.dom.test.NodeImpl_cloneNode_boolean_0 diff --git a/mozilla/java/dom/tests/src/BWTestClass.lst.xml.ORIG b/mozilla/java/dom/tests/src/BWTestClass.lst.xml.ORIG index fa1458cc2aa..f76e9aecafd 100755 --- a/mozilla/java/dom/tests/src/BWTestClass.lst.xml.ORIG +++ b/mozilla/java/dom/tests/src/BWTestClass.lst.xml.ORIG @@ -109,4 +109,13 @@ org.mozilla.dom.test.NodeImpl_supports_String_String_0 org.mozilla.dom.test.NodeImpl_supports_String_String_1 org.mozilla.dom.test.NodeImpl_supports_String_String_2 org.mozilla.dom.test.NodeImpl_supports_String_String_3 - +org.mozilla.dom.test.NamedNodeMapImpl_getNamedItemNS_String_String_0 +org.mozilla.dom.test.NamedNodeMapImpl_getNamedItemNS_String_String_1 +org.mozilla.dom.test.NamedNodeMapImpl_getNamedItemNS_String_String_2 +org.mozilla.dom.test.NamedNodeMapImpl_getNamedItemNS_String_String_3 +org.mozilla.dom.test.NamedNodeMapImpl_removeNamedItemNS_String_String_0 +org.mozilla.dom.test.NamedNodeMapImpl_removeNamedItemNS_String_String_1 +org.mozilla.dom.test.NamedNodeMapImpl_removeNamedItemNS_String_String_2 +org.mozilla.dom.test.NamedNodeMapImpl_removeNamedItemNS_String_String_3 +org.mozilla.dom.test.NamedNodeMapImpl_setNamedItemNS_Node_0 +org.mozilla.dom.test.NamedNodeMapImpl_setNamedItemNS_Node_1 diff --git a/mozilla/java/dom/tests/src/api/DocumentImpl_createEvent_String_1.java b/mozilla/java/dom/tests/src/api/DocumentImpl_createEvent_String_1.java index ecb642e0424..2e4eeaccfa5 100755 --- a/mozilla/java/dom/tests/src/api/DocumentImpl_createEvent_String_1.java +++ b/mozilla/java/dom/tests/src/api/DocumentImpl_createEvent_String_1.java @@ -83,12 +83,10 @@ public class DocumentImpl_createEvent_String_1 extends BWBaseTest implements Exe if (d != null) { try { - Event me = d.createEvent("MouseEvent"); - Event ke = d.createEvent("KeyEvent"); - Event he = d.createEvent("HTMLEvent"); - if (me == null || ke == null || he == null) { + Event me = d.createEvent("UIEvents"); + if (me == null) { TestLoader.logErrPrint("DocumentEvent returned null ..."); - System.out.println("DocumentEvent returned null: me="+me+" ke="+ke+" he="+he); + //System.out.println("DocumentEvent returned null: me="+me+" ke="+ke+" he="+he); return BWBaseTest.FAILED; } } catch (Exception e) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNS_String_String_0.java b/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNS_String_String_0.java index f369a666e42..6dc629ed4ab 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNS_String_String_0.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNS_String_String_0.java @@ -86,13 +86,26 @@ public class ElementImpl_getAttributeNS_String_String_0 extends BWBaseTest imple TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { - String nuri = "xmlns:edi='http://ecommerce.com/schema'"; - String lname = "dummyattr"; - String val = "1"; - e.setAttributeNS(nuri, lname, val); + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + + String nuri = "http://www.foo.org/"; + String lname = "myattr"; + String retval = "ATTRVAL"; String s = e.getAttributeNS(nuri, lname); - if (s == null || !s.equals(val)) { - TestLoader.logErrPrint("Element 'getAttributeNS' returned incorrect value: "+s+" != "+val); + if (s == null) { + TestLoader.logErrPrint("Element 'getAttributeNS' returned null instad of " + retval); + return BWBaseTest.FAILED; + } + + if (!s.equals(retval)) { + TestLoader.logErrPrint("Element 'getAttributeNS' returned incorrect value: "+s+" != "+ retval); return BWBaseTest.FAILED; } } diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNS_String_String_1.java b/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNS_String_String_1.java index d393673a4cc..682f7b15197 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNS_String_String_1.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNS_String_String_1.java @@ -86,10 +86,19 @@ public class ElementImpl_getAttributeNS_String_String_1 extends BWBaseTest imple TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + String nuri = null; - String lname = "dummyattr"; + String lname = "myattr"; String s = e.getAttributeNS(nuri, lname); - TestLoader.logErrPrint("Element 'getAttributeNS' didn't throw exception"); + TestLoader.logErrPrint("Element 'getAttributeNS' didn't throw exception for null URI"); return BWBaseTest.FAILED; } } catch (Exception e) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNS_String_String_2.java b/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNS_String_String_2.java index bd61b1a69ac..e6f5e369b71 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNS_String_String_2.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNS_String_String_2.java @@ -86,10 +86,19 @@ public class ElementImpl_getAttributeNS_String_String_2 extends BWBaseTest imple TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { - String nuri = "xmlns:edi='http://ec.com/schema'"; + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + + String nuri = "http://www.foo.org/"; String lname = null; String s = e.getAttributeNS(nuri, lname); - TestLoader.logErrPrint("Element 'getAttributeNS' didn't throw exception "); + TestLoader.logErrPrint("Element 'getAttributeNS' did not throw Exception for localname set to null"); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNS_String_String_3.java b/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNS_String_String_3.java index 91cce8f5eca..5712763a53a 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNS_String_String_3.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNS_String_String_3.java @@ -86,6 +86,15 @@ public class ElementImpl_getAttributeNS_String_String_3 extends BWBaseTest imple TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + String nuri = null; String lname = null; String s = e.getAttributeNS(nuri, lname); diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNodeNS_String_String_0.java b/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNodeNS_String_String_0.java index 466d50eab75..d2225e6d23e 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNodeNS_String_String_0.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNodeNS_String_String_0.java @@ -86,10 +86,19 @@ public class ElementImpl_getAttributeNodeNS_String_String_0 extends BWBaseTest i TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + String nuri = null; String lname = null; Node n = e.getAttributeNodeNS(nuri, lname); - TestLoader.logErrPrint("Element 'getAttributeNodeNS' didn't throw exception... "); + TestLoader.logErrPrint("Element 'getAttributeNodeNS' didn't throw exception for URI set to null and local name set to null... "); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNodeNS_String_String_1.java b/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNodeNS_String_String_1.java index cad1e560e27..41002991f1b 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNodeNS_String_String_1.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNodeNS_String_String_1.java @@ -86,10 +86,19 @@ public class ElementImpl_getAttributeNodeNS_String_String_1 extends BWBaseTest i TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + String nuri = null; - String lname = "dummyattr"; + String lname = "myattr"; Node n = e.getAttributeNodeNS(nuri, lname); - TestLoader.logErrPrint("Element 'getAttributeNodeNS' didn't throw exception... "); + TestLoader.logErrPrint("Element 'getAttributeNodeNS' didn't throw exception for URI set to null... "); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNodeNS_String_String_2.java b/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNodeNS_String_String_2.java index 88fa6b47ce7..1831c821e1e 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNodeNS_String_String_2.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNodeNS_String_String_2.java @@ -86,10 +86,19 @@ public class ElementImpl_getAttributeNodeNS_String_String_2 extends BWBaseTest i TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { - String nuri = ""; + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + + String nuri = "http://www.foo.org/"; String lname = null; Node n = e.getAttributeNodeNS(nuri, lname); - TestLoader.logErrPrint("Element 'getAttributeNodeNS' didn't throw exception... "); + TestLoader.logErrPrint("Element 'getAttributeNodeNS' didn't throw exception for local name set to null... "); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNodeNS_String_String_3.java b/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNodeNS_String_String_3.java index a281da2fa6e..8406447f1b6 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNodeNS_String_String_3.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_getAttributeNodeNS_String_String_3.java @@ -86,13 +86,26 @@ public class ElementImpl_getAttributeNodeNS_String_String_3 extends BWBaseTest i TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { - String nuri = "xmlns:edi='http://ecommerce.org/schema'"; - String lname = "dummyattr"; - String val = "1"; - e.setAttributeNS(nuri, lname, val); + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + + String nuri = "http://www.foo.org/"; + String lname = "myattr"; + String val = "ATTRVAL"; Node n = e.getAttributeNodeNS(nuri, lname); - if (n == null || n.getNodeType() != Node.ATTRIBUTE_NODE || !((Attr)n).getValue().equals(val)) { - TestLoader.logErrPrint("Element 'getAttributeNS' returned incorrect value "); + if (n == null) + { + TestLoader.logErrPrint("Element 'getAttributeNS' returned null value instead of " + val); + return BWBaseTest.FAILED; + } + if (n.getNodeType() != Node.ATTRIBUTE_NODE || !((Attr)n).getValue().equals(val)) { + TestLoader.logErrPrint("Element 'getAttributeNS' returned value " + ((Attr)n).getValue() + " instead of " + val); return BWBaseTest.FAILED; } } diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_getElementsByTagNameNS_String_String_0.java b/mozilla/java/dom/tests/src/api/ElementImpl_getElementsByTagNameNS_String_String_0.java index 9c3b813d434..1d02aada1f7 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_getElementsByTagNameNS_String_String_0.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_getElementsByTagNameNS_String_String_0.java @@ -86,10 +86,19 @@ public class ElementImpl_getElementsByTagNameNS_String_String_0 extends BWBaseTe TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + String nuri = null; String lname = null; - NodeList nl = e.getElementsByTagNameNS(nuri, lname); - TestLoader.logErrPrint("Element 'getElementsByTagNameNS' didn't throw exception... "); + nl = e.getElementsByTagNameNS(nuri, lname); + TestLoader.logErrPrint("Element 'getElementsByTagNameNS' didn't throw exception for URI set to null and localname set to null... "); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_getElementsByTagNameNS_String_String_1.java b/mozilla/java/dom/tests/src/api/ElementImpl_getElementsByTagNameNS_String_String_1.java index 8b9435c8712..2a580949938 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_getElementsByTagNameNS_String_String_1.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_getElementsByTagNameNS_String_String_1.java @@ -86,10 +86,19 @@ public class ElementImpl_getElementsByTagNameNS_String_String_1 extends BWBaseTe TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + String nuri = null; - String lname = "dummyattr"; - NodeList nl = e.getElementsByTagNameNS(nuri, lname); - TestLoader.logErrPrint("Element 'getElementsByTagNameNS' didn't throw exception... "); + String lname = "myattr"; + nl = e.getElementsByTagNameNS(nuri, lname); + TestLoader.logErrPrint("Element 'getElementsByTagNameNS' didn't throw exception for URI set to null and localname set to myattr... "); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_getElementsByTagNameNS_String_String_2.java b/mozilla/java/dom/tests/src/api/ElementImpl_getElementsByTagNameNS_String_String_2.java index 487d2ae1508..bd092f6b56d 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_getElementsByTagNameNS_String_String_2.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_getElementsByTagNameNS_String_String_2.java @@ -86,10 +86,19 @@ public class ElementImpl_getElementsByTagNameNS_String_String_2 extends BWBaseTe TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { - String nuri = ""; + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + + String nuri = "http://www.foo.org/"; String lname = null; - NodeList nl = e.getElementsByTagNameNS(nuri, lname); - TestLoader.logErrPrint("Element 'getElementsByTagNameNS' didn't throw exception... "); + nl = e.getElementsByTagNameNS(nuri, lname); + TestLoader.logErrPrint("Element 'getElementsByTagNameNS' didn't throw exception for localname set to null... "); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_getElementsByTagNameNS_String_String_3.java b/mozilla/java/dom/tests/src/api/ElementImpl_getElementsByTagNameNS_String_String_3.java index b36e12e4f02..b2b19f2aad6 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_getElementsByTagNameNS_String_String_3.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_getElementsByTagNameNS_String_String_3.java @@ -86,9 +86,18 @@ public class ElementImpl_getElementsByTagNameNS_String_String_3 extends BWBaseTe TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { - String nuri = "xmlns:edi='http://ecommerce.org/schema'"; - String lname = "body"; - NodeList nl = e.getElementsByTagNameNS(nuri, lname); + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + + String nuri = "http://www.foo.org/"; + String lname = "myattr"; + nl = e.getElementsByTagNameNS(nuri, lname); if (nl == null) { TestLoader.logErrPrint("Element 'getElementsByTagNameNS' returned incorrect value "); return BWBaseTest.FAILED; @@ -128,4 +137,4 @@ public class ElementImpl_getElementsByTagNameNS_String_String_3 extends BWBaseTe else {} } } - \ No newline at end of file + diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_hasAttributeNS_String_String_0.java b/mozilla/java/dom/tests/src/api/ElementImpl_hasAttributeNS_String_String_0.java index f6227166e3b..84c29a77ee9 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_hasAttributeNS_String_String_0.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_hasAttributeNS_String_String_0.java @@ -85,8 +85,17 @@ public class ElementImpl_hasAttributeNS_String_String_0 extends BWBaseTest imple TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + if (e.hasAttributeNS(null, null)) ; - TestLoader.logErrPrint("Element 'hasAttributeNS didn't throw exception... "); + TestLoader.logErrPrint("Element 'hasAttributeNS didn't throw exception for URI set to null and localname set to null... "); return BWBaseTest.FAILED; } catch (Exception r) { String msg = "Caught Exception " + r ; diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_hasAttributeNS_String_String_1.java b/mozilla/java/dom/tests/src/api/ElementImpl_hasAttributeNS_String_String_1.java index cb1404c9505..e4cbb9e6ed7 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_hasAttributeNS_String_String_1.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_hasAttributeNS_String_String_1.java @@ -85,8 +85,17 @@ public class ElementImpl_hasAttributeNS_String_String_1 extends BWBaseTest imple TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } - if (e.hasAttributeNS("dummy", null)); - TestLoader.logErrPrint("Element 'hasAttributeNS didn't throw exception... "); + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + + if (e.hasAttributeNS("http://www.foo.org/", null)); + TestLoader.logErrPrint("Element 'hasAttributeNS didn't throw exception for localname set to null... "); return BWBaseTest.FAILED; } catch (Exception r) { String msg = "Caught Exception " + r ; diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_hasAttributeNS_String_String_2.java b/mozilla/java/dom/tests/src/api/ElementImpl_hasAttributeNS_String_String_2.java index d6b4d10126e..e0e193b34ff 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_hasAttributeNS_String_String_2.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_hasAttributeNS_String_String_2.java @@ -85,8 +85,17 @@ public class ElementImpl_hasAttributeNS_String_String_2 extends BWBaseTest imple TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } - if (e.hasAttributeNS(null, "dummy")); - TestLoader.logErrPrint("Element 'hasAttributeNS didn't throw exception... "); + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + + if (e.hasAttributeNS(null, "myattr")); + TestLoader.logErrPrint("Element 'hasAttributeNS didn't throw exception for URI set to null... "); return BWBaseTest.FAILED; } catch (Exception r) { String msg = "Caught Exception " + r ; diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_hasAttributeNS_String_String_3.java b/mozilla/java/dom/tests/src/api/ElementImpl_hasAttributeNS_String_String_3.java index 4fb983ef768..206147234c0 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_hasAttributeNS_String_String_3.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_hasAttributeNS_String_String_3.java @@ -85,12 +85,19 @@ public class ElementImpl_hasAttributeNS_String_String_3 extends BWBaseTest imple TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } - String nsuri = "xmlns:edi='http://ec.com/schema'"; - String lname = "dummyattr"; - String val = "1"; - e.setAttributeNS(nsuri, lname, val); - if (e.hasAttributeNS(nsuri, val) == false) { - TestLoader.logErrPrint("Element 'hasAttributeNS returned incorrect value... "); + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + + String nsuri = "http://www.foo.org/"; + String lname = "myattr"; + if (!(e.hasAttributeNS(nsuri, lname))) { + TestLoader.logErrPrint("Element 'hasAttributeNS returned false instead of true... "); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_removeAttributeNS_String_String_0.java b/mozilla/java/dom/tests/src/api/ElementImpl_removeAttributeNS_String_String_0.java index b5368fbc264..919273050d3 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_removeAttributeNS_String_String_0.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_removeAttributeNS_String_String_0.java @@ -86,10 +86,19 @@ public class ElementImpl_removeAttributeNS_String_String_0 extends BWBaseTest im TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + String nuri = null; String lname = null; e.removeAttributeNS(nuri, lname); - TestLoader.logErrPrint("Element 'removeAttributeNS' didn't throw exception... "); + TestLoader.logErrPrint("Element 'removeAttributeNS' didn't throw exception for URI set to null and lname set to null... "); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_removeAttributeNS_String_String_1.java b/mozilla/java/dom/tests/src/api/ElementImpl_removeAttributeNS_String_String_1.java index cdfb7a6bc76..d1e9860f30c 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_removeAttributeNS_String_String_1.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_removeAttributeNS_String_String_1.java @@ -86,10 +86,19 @@ public class ElementImpl_removeAttributeNS_String_String_1 extends BWBaseTest im TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + String nuri = null; - String lname = "dummyattr"; + String lname = "myattr"; e.removeAttributeNS(nuri, lname); - TestLoader.logErrPrint("Element 'removeAttributeNS' didn't throw exception... "); + TestLoader.logErrPrint("Element 'removeAttributeNS' didn't throw exception for URI set to null... "); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_removeAttributeNS_String_String_2.java b/mozilla/java/dom/tests/src/api/ElementImpl_removeAttributeNS_String_String_2.java index 2c73c330cd3..cb33c9a6ed9 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_removeAttributeNS_String_String_2.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_removeAttributeNS_String_String_2.java @@ -86,10 +86,19 @@ public class ElementImpl_removeAttributeNS_String_String_2 extends BWBaseTest im TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { - String nuri = ""; + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + + String nuri = "http://www.foo.org/"; String lname = null; e.removeAttributeNS(nuri, lname); - TestLoader.logErrPrint("Element 'removeAttributeNS' didn't throw exception... "); + TestLoader.logErrPrint("Element 'removeAttributeNS' didn't throw exception for localname set to null... "); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_removeAttributeNS_String_String_3.java b/mozilla/java/dom/tests/src/api/ElementImpl_removeAttributeNS_String_String_3.java index 925bf761ad6..e765530d65d 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_removeAttributeNS_String_String_3.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_removeAttributeNS_String_String_3.java @@ -86,10 +86,27 @@ public class ElementImpl_removeAttributeNS_String_String_3 extends BWBaseTest im TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { - String nuri = "xmlns:edi='http://ecommerce.org/schema'"; - String lname = "dummyattr"; - e.setAttributeNS(nuri, lname, "1"); + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + + String nuri = "http://www.foo.org/"; + String lname = "myattr"; + String retval= "ATTRVAL"; e.removeAttributeNS(nuri, lname); + String s = e.getAttributeNS(nuri, lname); + if ((s == null) || !(s.equals(""))) + { + TestLoader.logErrPrint("Element 'removeAttributeNS' failedto remove attribute myattr "); + return BWBaseTest.FAILED; + + } + } } catch (Exception r) { String msg = "Caught Exception " + r ; diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_0.java b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_0.java index a41717ad264..541da5084d9 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_0.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_0.java @@ -87,11 +87,20 @@ public class ElementImpl_setAttributeNS_String_String_String_0 extends BWBaseTes TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + String nuri = null; - String lname = null; + String qname = null; String val = null; - e.setAttributeNS(nuri, lname, val); - TestLoader.logErrPrint("setAttributeNS didn't throw exception ..."); + e.setAttributeNS(nuri, qname, val); + TestLoader.logErrPrint("setAttributeNS didn't throw exception for URI set to NULL and qualified name set to null ..."); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_1.java b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_1.java index dcf925ebaa8..eac576c7974 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_1.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_1.java @@ -87,11 +87,20 @@ public class ElementImpl_setAttributeNS_String_String_String_1 extends BWBaseTes TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + String nuri = null; - String lname = null; - String val = "1"; - e.setAttributeNS(nuri, lname, val); - TestLoader.logErrPrint("setAttributeNS didn't throw exception ..."); + String qname = null; + String val = "MYVAL"; + e.setAttributeNS(nuri, qname, val); + TestLoader.logErrPrint("setAttributeNS didn't throw exception for URI set to null and qualifiedname set to null ..."); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_2.java b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_2.java index 91982fd441c..9bd67a98aba 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_2.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_2.java @@ -87,11 +87,20 @@ public class ElementImpl_setAttributeNS_String_String_String_2 extends BWBaseTes TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + String nuri = null; - String lname = "dummyattr"; + String qname = "foo:myattr"; String val = null; - e.setAttributeNS(nuri, lname, val); - TestLoader.logErrPrint("setAttributeNS didn't throw exception ..."); + e.setAttributeNS(nuri, qname, val); + TestLoader.logErrPrint("setAttributeNS didn't throw exception for URI set to null and qualifiedname set to foo:myattr..."); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_3.java b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_3.java index 9a126b14d3f..fb7600631d4 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_3.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_3.java @@ -87,11 +87,20 @@ public class ElementImpl_setAttributeNS_String_String_String_3 extends BWBaseTes TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + String nuri = null; - String lname = "dummyattr"; - String val = "1"; - e.setAttributeNS(nuri, lname, val); - TestLoader.logErrPrint("setAttributeNS didn't throw exception ..."); + String qname = "foo:myattr"; + String val = "ATTRVAL"; + e.setAttributeNS(nuri, qname, val); + TestLoader.logErrPrint("setAttributeNS didn't throw exception for URI set to NULL and qualifiedname set to foo:myattr..."); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_4.java b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_4.java index 37899838ff0..1a140eab773 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_4.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_4.java @@ -87,11 +87,20 @@ public class ElementImpl_setAttributeNS_String_String_String_4 extends BWBaseTes TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + String nuri = null; - String lname = "dummyattr"; + String qname = "foo:myattr"; String val = null; - e.setAttributeNS(nuri, lname, val); - TestLoader.logErrPrint("setAttributeNS didn't throw exception ..."); + e.setAttributeNS(nuri, qname, val); + TestLoader.logErrPrint("setAttributeNS didn't throw exception for URI set to null and qualifiedname set to foo:myattr..."); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_5.java b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_5.java index c404af55df8..9114b9c73d2 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_5.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_5.java @@ -87,11 +87,20 @@ public class ElementImpl_setAttributeNS_String_String_String_5 extends BWBaseTes TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + String nuri = null; - String lname = "dummyattr"; - String val = "1"; - e.setAttributeNS(nuri, lname, val); - TestLoader.logErrPrint("setAttributeNS didn't throw exception ..."); + String qname = "foo:myattr"; + String val = "ATTRVAL"; + e.setAttributeNS(nuri, qname, val); + TestLoader.logErrPrint("setAttributeNS didn't throw exception for URI=null Qualifiedname=foo:myattr Value=ATTRVAL..."); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_6.java b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_6.java index 277d2ef573c..e6a4d77e505 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_6.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_6.java @@ -87,11 +87,20 @@ public class ElementImpl_setAttributeNS_String_String_String_6 extends BWBaseTes TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { - String nuri = "xmlns:edi='http://ecommerce.org/schema'"; - String lname = null; + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + + String nuri = "http://www.foo.org/"; + String qname = null; String val = null; - e.setAttributeNS(nuri, lname, val); - TestLoader.logErrPrint("setAttributeNS didn't throw exception ..."); + e.setAttributeNS(nuri, qname, val); + TestLoader.logErrPrint("setAttributeNS didn't throw exception for qualifiedname=null and Value=null ..."); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_7.java b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_7.java index d7d598e0ff1..21a14c2fc0c 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_7.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_7.java @@ -87,11 +87,20 @@ public class ElementImpl_setAttributeNS_String_String_String_7 extends BWBaseTes TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { - String nuri = "xmlns:edi='http://ecommerce.org/schema'"; - String lname = null; - String val = "1"; - e.setAttributeNS(nuri, lname, val); - TestLoader.logErrPrint("setAttributeNS didn't throw exception ..."); + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + + String nuri = "http://www.foo.org/"; + String qname = null; + String val = "MYVAL"; + e.setAttributeNS(nuri, qname, val); + TestLoader.logErrPrint("setAttributeNS didn't throw exception for QualifiedName=null and val=MYVAL..."); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_8.java b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_8.java index 78e1edc9d56..a648be2d7aa 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_8.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_8.java @@ -87,11 +87,20 @@ public class ElementImpl_setAttributeNS_String_String_String_8 extends BWBaseTes TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { - String nuri = "xmlns:edi='http://ecommerce.org/schema'"; - String lname = "dummyattr"; + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + + String nuri = "http://www.foo.org/"; + String qname = "foo:myattr"; String val = null; - e.setAttributeNS(nuri, lname, val); - TestLoader.logErrPrint("setAttributeNS didn't throw exception ..."); + e.setAttributeNS(nuri, qname, val); + TestLoader.logErrPrint("setAttributeNS didn't throw exception for value=Null..."); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_9.java b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_9.java index 442bfa33a4b..f884d68fe83 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_9.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNS_String_String_String_9.java @@ -87,13 +87,28 @@ public class ElementImpl_setAttributeNS_String_String_String_9 extends BWBaseTes TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { - String nuri = "xmlns:edi='http://ecommerce.org/schema'"; - String lname = "dummyattr"; - String val = "1"; - e.setAttributeNS(nuri, lname, val); + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + + String nuri = "http://www.foo.org/"; + String qname = "foo:myattr"; + String lname = "myattr"; + String val = "MYVAL"; + e.setAttributeNS(nuri, qname, val); String s = e.getAttributeNS(nuri, lname); - if (s == null || !s.equals(val)) { - TestLoader.logErrPrint("'setAttributeNS' didn't set attribute correctly"); + if (s == null) { + TestLoader.logErrPrint("'setAttributeNS' returned null attirbute value"); + return BWBaseTest.FAILED; + } + + if (!s.equals(val)) { + TestLoader.logErrPrint("'setAttributeNS' set attribute to " + s + " instead of " + val); return BWBaseTest.FAILED; } } diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNodeNS_Attr_0.java b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNodeNS_Attr_0.java index de245d8c567..6562b9305dc 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNodeNS_Attr_0.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNodeNS_Attr_0.java @@ -87,8 +87,17 @@ public class ElementImpl_setAttributeNodeNS_Attr_0 extends BWBaseTest implements TestLoader.logErrPrint("Document Element is NULL.."); return BWBaseTest.FAILED; } else { + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + Attr anode = e.setAttributeNodeNS(null); - TestLoader.logErrPrint("Document setAttributeNodeNS didn't throw exception..."); + TestLoader.logErrPrint("Document setAttributeNodeNS didn't throw exception for null attribute..."); return BWBaseTest.FAILED; } } catch (Exception r) { diff --git a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNodeNS_Attr_1.java b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNodeNS_Attr_1.java index 6d6bc7062ac..4b890ff2474 100755 --- a/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNodeNS_Attr_1.java +++ b/mozilla/java/dom/tests/src/api/ElementImpl_setAttributeNodeNS_Attr_1.java @@ -82,23 +82,26 @@ public class ElementImpl_setAttributeNodeNS_Attr_1 extends BWBaseTest implements if (d != null) { try { - Element e = d.getDocumentElement(); - String nuri = "xmlns:edi='http://ecommerce.org/schema'"; - String lname = "dummyattr"; - String val = "1"; - Attr a = d.createAttribute(lname); - a.setValue(val); - if (e == null || a == null) { - TestLoader.logErrPrint("Document Element is NULL or can't create new attribute.."); - return BWBaseTest.FAILED; - } else { - e.setAttributeNodeNS(a); - Node n = e.getAttributeNodeNS(nuri, lname); - if (n == null || n.getNodeType() != Node.ATTRIBUTE_NODE || !((Attr)n).getValue().equals(val)) { - TestLoader.logErrPrint("Element 'getAttributeNS' returned incorrect value "); + Element e = d.getDocumentElement(); + + String uri = "http://www.foo.org/"; + String name = "*"; + NodeList nl = e.getElementsByTagNameNS(uri, name); + if (nl != null) { + Node n = (Node)nl.item(0); + e = (Element)n; + } + + String nuri = "http://www.foo.org/"; + String lname = "myattr"; + String val = "ATTRVAL"; + Attr getattr = e.getAttributeNodeNS(nuri, lname); + Attr retattr = (Attr)e.setAttributeNodeNS(getattr); + if (retattr != null) + { + TestLoader.logErrPrint("Element 'getAttributeNS' did not return null for an already existing Attribute myattr "); return BWBaseTest.FAILED; } - } } catch (Exception r) { String msg = "Caught Exception " + r ; TestLoader.logErrPrint(msg); diff --git a/mozilla/java/dom/tests/src/autorun.sh b/mozilla/java/dom/tests/src/autorun.sh index cfa98350196..bf698cf9468 100755 --- a/mozilla/java/dom/tests/src/autorun.sh +++ b/mozilla/java/dom/tests/src/autorun.sh @@ -68,7 +68,7 @@ title() echo "################################################" echo echo "NOTE: You need to copy files test.html and" - echo " testxml.html to DOCUMENT_ROOT dir. of" + echo " test.xml to DOCUMENT_ROOT dir. of" echo " your Web-Server on this machine." echo echo @@ -138,14 +138,14 @@ checkRun() ################################################################## # -# check Document Root and check if files test.html and testxml.html +# check Document Root and check if files test.html and test.xml # exists in thos directories # ################################################################## #checkDocRoot() #{ # echo -#echo "You need to copy files test.html and testxml.html to your DOCUMENT_ROOT" +#echo "You need to copy files test.html and test.xml to your DOCUMENT_ROOT" #echo "of your Web-Server" #echo #echo "This test assumes that you have set up you WebServer and copied the" @@ -172,7 +172,7 @@ checkRun() # # #echo -#echo "Checking if the files test.html and testxml.html exists in DOCUMENT_ROOT..." +#echo "Checking if the files test.html and test.xml exists in DOCUMENT_ROOT..." #if [ ! -f "$docroot/test.html" #then # echo "Could not find 'test.html' in DOCUMENT_ROOT directory" @@ -181,10 +181,10 @@ checkRun() # exit 1 #fi # -#if [ ! -f "$docroot/testxml.html" ] +#if [ ! -f "$docroot/test.xml" ] #then -# echo "Could not find 'testxml.html' in DOCUMENT_ROOT directory" -# echo "Please copy testxml.html to DOCUMENT_ROOT and rerun this script" +# echo "Could not find 'test.xml' in DOCUMENT_ROOT directory" +# echo "Please copy test.xml to DOCUMENT_ROOT and rerun this script" # echo # exit 1 #fi @@ -311,7 +311,7 @@ constructLogFooter() ################################################################## # -# check Document Root and check if files test.html and testxml.html +# check Document Root and check if files test.html and test.xml # exists in thos directories # ################################################################## @@ -492,10 +492,10 @@ fi if [ "$runtype" = "2" ] then - DOCFILE="$DOCROOT/testxml.html" + DOCFILE="$DOCROOT/test.xml" if [ -z "$appreg" ] then - DOCFILE="$DOCROOT/testxml.html"; + DOCFILE="$DOCROOT/test.xml"; else DOCFILE="$DOCROOT/TestLoaderXML.html"; fi @@ -641,7 +641,7 @@ do if [ "$runtype" = "3" ] then - DOCFILE="$DOCROOT/testxml.html" + DOCFILE="$DOCROOT/test.xml" filename="$curdir/BWTestClass.lst.xml.ORIG" constructHTML appendEntries diff --git a/mozilla/java/dom/tests/src/test.xml b/mozilla/java/dom/tests/src/test.xml index 111c84099d7..a3023fe7096 100755 --- a/mozilla/java/dom/tests/src/test.xml +++ b/mozilla/java/dom/tests/src/test.xml @@ -1,29 +1,17 @@ - - - - - - - - - - - - - - - - - -]> - - - + + + + + Virtual Library + + + + Hello + + + + diff --git a/mozilla/java/util/Makefile.in b/mozilla/java/util/Makefile.in index 9c8f109aac5..2786aecb529 100644 --- a/mozilla/java/util/Makefile.in +++ b/mozilla/java/util/Makefile.in @@ -32,6 +32,16 @@ DIRS= \ classes \ $(NULL) + +rm_java: +ifeq ($(PACKAGE_BUILD),) + rm -Rf $(topsrcdir)/dist/classes/org/mozilla/util +endif # PACKAGE_BUILD + + +clobber_all::rm_java + + include $(topsrcdir)/config/rules.mk diff --git a/mozilla/java/webclient/classes_spec/Makefile.in b/mozilla/java/webclient/classes_spec/Makefile.in index 5d772039fba..38b64f62f58 100644 --- a/mozilla/java/webclient/classes_spec/Makefile.in +++ b/mozilla/java/webclient/classes_spec/Makefile.in @@ -64,13 +64,44 @@ PACKAGE_DIR=$(topsrcdir)/dist/javadev PACKAGE_LIB=$(PACKAGE_DIR)/lib endif # PACKAGE_BUILD +ifneq ($(WEBCLIENT_PACKAGE_BUILD),) +PACKAGE_VER = 1_0 +PACKAGE_DIR = $(DIST)/javadev +PACKAGE_LIB = $(PACKAGE_DIR)/lib +PACKAGE_EXAMPLE = $(PACKAGE_DIR)/example +endif # WEBCLIENT_PACKAGE_BUILD + JAVA_SOURCEPATH=$(topsrcdir)/java/webclient/classes_spec JAVAC_FLAGS=-classpath $(CLASSPATH):$(JAVA_DESTPATH) -d $(JAVA_DESTPATH) +rm_java: +ifeq ($(PACKAGE_BUILD),) + rm -Rf $(topsrcdir)/dist/classes/org/mozilla/webclient +else + rm -Rf $(topsrcdir)/dist/javadev +endif # PACKAGE_BUILD +ifneq ($(WEBCLIENT_PACKAGE_BUILD),) + rm -Rf $(topsrcdir)/dist/javadev +endif + + +clobber_all::rm_java + install:: jarEmUp jarEmUp: +ifneq ($(WEBCLIENT_PACKAGE_BUILD),) + if test ! -d $(PACKAGE_DIR) ; then mkdir $(PACKAGE_DIR) ; else true ; fi ; + if test ! -d $(PACKAGE_LIB) ; then mkdir $(PACKAGE_LIB) ; else true ; fi ; + if test ! -d $(PACKAGE_LIB)/webclient_$(PACKAGE_VER).jar ; then rm -f $(PACKAGE_LIB)/webclient_$(PACKAGE_VER).jar ; else true ; fi ; + if test ! -d $(PACKAGE_LIB)/webclient.jar ; then rm -f $(PACKAGE_LIB)/webclient.jar ; else true ; fi ; + cd $(topsrcdir)/dist/classes ; \ + jar -cvfM0 webclient_$(PACKAGE_VER).jar org ; \ + mv webclient_$(PACKAGE_VER).jar ../javadev/lib ; + cd $(topsrcdir)/dist/javadev/lib ; \ + ln -s webclient_$(PACKAGE_VER).jar $(PACKAGE_LIB)/webclient.jar ; +endif ifneq ($(PACKAGE_BUILD),) if test ! -d $(PACKAGE_DIR) ; then mkdir $(PACKAGE_DIR) ; else true ; fi ; if test ! -d $(PACKAGE_LIB) ; then mkdir $(PACKAGE_LIB) ; else true ; fi ; diff --git a/mozilla/java/webclient/classes_spec/Makefile.win b/mozilla/java/webclient/classes_spec/Makefile.win index 984ae16f72e..f1b7a6c470e 100644 --- a/mozilla/java/webclient/classes_spec/Makefile.win +++ b/mozilla/java/webclient/classes_spec/Makefile.win @@ -23,6 +23,8 @@ IGNORE_MANIFEST=1 #//------------------------------------------------------------------------ #// #// Makefile to build the java portion of the java wrapper to mozilla +#// Assumes that all necesssary classes for webclient have already been +#// compiled into $(DIST)\classes #// #//------------------------------------------------------------------------ @@ -57,7 +59,13 @@ JAR_WEBCLIENT_CLASSES = \ JDIRS = $(JAR_WEBCLIENT_CLASSES) !endif -WEBCLIENT_JAR_NAME=webclient(VERSION_NUMBER).jar +!ifdef PACKAGE_BUILD +PACKAGE_VER = 1_0 +#PENDING(edburns): jar name should be defined elewhere! +WEBCLIENT_JAR_NAME=webclient_$(PACKAGE_VER).jar +PACKAGE_DIR = $(DIST)\javadev +PACKAGE_LIB = $(PACKAGE_DIR)\lib +!endif JAVAC_PROG=$(JDKHOME)\bin\javac @@ -81,3 +89,19 @@ JAVAC_CLASSPATH=$(JAVAC_CLASSPATH);$(CLASSPATH) include <$(DEPTH)\config\javarules.mak> include <$(DEPTH)\config\rules.mak> +install:: jarEmUp + +jarEmup: +!ifdef PACKAGE_BUILD + -mkdir $(DIST)\javadev + chmod 775 $(DIST)\javadev + -mkdir $(DIST)\javadev\lib + chmod 775 $(DIST)\javadev\lib + rm -f $(PACKAGE_LIB)\$(WEBCLIENT_JAR_NAME) + jar -cvfM0 $(PACKAGE_LIB)\$(WEBCLIENT_JAR_NAME) -C $(DIST)\..\classes org +!endif + +clobber_all:: +!ifdef PACKAGE_BUILD + rm -f $(PACKAGE_LIB)\$(WEBCLIENT_JAR_NAME) +!endif diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/BookmarkEntry.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/BookmarkEntry.java index 82798de5d11..72f7425fc3b 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/BookmarkEntry.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/BookmarkEntry.java @@ -40,6 +40,7 @@ public final static String LAST_VISIT_DATE = "LastVisitDate"; public final static String NAME = "Name"; public final static String URL = "URL"; public final static String DESCRIPTION = "Description"; +public final static String IS_FOLDER = "IsFolder"; public Properties getProperties(); diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/BrowserControlImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/BrowserControlImpl.java index 2fe1bf1ce8a..59e18e413de 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/BrowserControlImpl.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/BrowserControlImpl.java @@ -70,6 +70,7 @@ private WindowControl windowControl = null; private Navigation navigation = null; private History history = null; private static Bookmarks bookmarks = null; +private static Preferences prefs = null; // // Constructors and Initializers @@ -126,8 +127,8 @@ void delete() ((ImplObject)windowControl).delete(); windowControl = null; - // since bookmarks is static, we must not deallocate it here. That - // is done in the static method appTerminate + // since bookmarks and prefs are static, we must not deallocate them + // here. That is done in the static method appTerminate } @@ -152,6 +153,10 @@ static void appTerminate() throws Exception ((ImplObject)bookmarks).delete(); bookmarks = null; } + if (null != prefs) { + ((ImplObject)prefs).delete(); + prefs = null; + } wrapperFactory.terminate(); } @@ -269,6 +274,13 @@ public Object queryInterface(String interfaceName) throws ClassNotFoundException } return bookmarks; } + if (PREFERENCES_NAME.equals(interfaceName)) { + if (null == prefs) { + prefs = (Preferences) + wrapperFactory.newImpl(PREFERENCES_NAME, this); + } + return prefs; + } // extensibility mechanism: just see if wrapperFactory can make one! return wrapperFactory.newImpl(interfaceName, this); } @@ -284,7 +296,7 @@ public static void main(String [] args) Assert.setEnabled(true); Log.setApplicationName("BrowserControlImpl"); Log.setApplicationVersion("0.0"); - Log.setApplicationVersionDate("$Id: BrowserControlImpl.java,v 1.3 2000-07-22 02:48:23 edburns%acm.org Exp $"); + Log.setApplicationVersionDate("$Id: BrowserControlImpl.java,v 1.4 2001-04-02 21:13:43 ashuk%eng.sun.com Exp $"); } diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/CurrentPage.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/CurrentPage.java index 703e1bc3b76..d8e6aa3e724 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/CurrentPage.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/CurrentPage.java @@ -87,7 +87,7 @@ public void copyCurrentSelectionToSystemClipboard(); public void findInPage(String stringToFind, boolean forward, boolean matchCase); -public void findNextInPage(boolean forward); +public void findNextInPage(); public String getCurrentURL(); @@ -97,7 +97,7 @@ public Properties getPageInfo(); public String getSource(); -public byte [] getSourceBytes(boolean viewMode); +public byte [] getSourceBytes(); public void resetFind(); diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Navigation.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Navigation.java index ccaa9373ef5..15588f31342 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Navigation.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Navigation.java @@ -27,6 +27,9 @@ package org.mozilla.webclient; +import java.io.InputStream; +import java.util.Properties; + public interface Navigation { @@ -40,8 +43,22 @@ public static int LOAD_NORMAL = 0; public static int LOAD_FORCE_RELOAD = 1 << 9; public void loadURL(String absoluteURL); +public void loadFromStream(InputStream stream, String uri, + String contentType, int contentLength, + Properties loadInfo); public void refresh(long loadFlags); public void stop(); +/** + + * Gives this Navigation instance the ability to call back the custom + * app when a site with basic authentication, cookies, etc, is + * encountered. The custom app can choose to put up appropriate modal + * UI. + + */ + +public void setPrompt(Prompt yourPrompt); + } // end of interface CurrentPage diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/PrefChangedCallback.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/PrefChangedCallback.java new file mode 100644 index 00000000000..64c8b618d67 --- /dev/null +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/PrefChangedCallback.java @@ -0,0 +1,30 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Ed Burns + */ + +package org.mozilla.webclient; + +public interface PrefChangedCallback +{ + public int prefChanged(String prefName, Object closure); +} +// end of interface PrefChangedCallback + diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Preferences.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Preferences.java new file mode 100644 index 00000000000..79ddb8458c2 --- /dev/null +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Preferences.java @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Ed Burns + */ + +package org.mozilla.webclient; + +import java.util.Properties; + +public interface Preferences +{ + public void setPref(String prefName, String prefValue); + public Properties getPrefs(); + public void registerPrefChangedCallback(PrefChangedCallback cb, + String prefName, Object closure); +} +// end of interface Preferences + diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Prompt.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Prompt.java new file mode 100644 index 00000000000..5803f97588b --- /dev/null +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Prompt.java @@ -0,0 +1,136 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Ed Burns + */ + +package org.mozilla.webclient; + +import java.util.Properties; + + +/** + + * The custom app must implement this interface in order to supply the + * underlying browser with basic authentication behavior. The custom + * app must tell webclient about its Prompt implementation by calling + * Navigation.setPrompt(). This must be done FOR EACH BrowserControl + * instance! + + */ + +public interface Prompt +{ + +public static final String USER_NAME_KEY = "userName"; +public static final String PASSWORD_KEY = "password"; +public static final String EDIT_FIELD_1_KEY = "editfield1Value"; +public static final String EDIT_FIELD_2_KEY = "editfield2Value"; +public static final String CHECKBOX_STATE_KEY = "checkboxState"; +public static final String BUTTON_PRESSED_KEY = "buttonPressed"; + +/** + + * Puts up a username/password dialog with OK and Cancel buttons. + + * @param fillThis a pre-allocated properties object + * that the callee fills in. + + * keys: userName, password + + * @return true for OK, false for Cancel + + */ + +public boolean promptUsernameAndPassword(String dialogTitle, + String text, + String passwordRealm, + int savePassword, + Properties fillThis); + +/** + + * Tells the custom app to put up a modal dialog using the information + * in the params for the dialog ui.

+ + * keys:

+ + *

+ + *
editfield1Value
+ *
initial and final value for first edit field
+ + *
editfield2Value
+ *
initial and final value for second edit field
+ + *
checkboxState
+ *
initial and final state of checkbox: true or false
+ + *
buttonPressed
+ *
number of button that was pressed (0 to 3)
+ + *

+ + * @param titleMessage + + * @param dialogTitle e.g., alert, confirm, prompt, prompt password + + * @param text main message for dialog + + * @param checkboxMsg message for checkbox + + * @param button0Text text for first button + + * @param button1Text text for second button + + * @param button2Text text for third button + + * @param button3Text text for fourth button + + * @param editfield1Msg message for first edit field + + * @param editfield2Msg message for second edit field + + * @param numberButtons total number of buttons (0 to 4) + + * @param numberEditfields total number of edit fields (0 to 2) + + * @param editField1Password whether or not editField1 is a password + + * @param fillThis the properties object to be filled with the above + * keys + + */ + +public boolean universalDialog(String titleMessage, + String dialogTitle, + String text, + String checkboxMsg, + String button0Text, + String button1Text, + String button2Text, + String button3Text, + String editfield1Msg, + String editfield2Msg, + int numberButtons, + int numberEditfields, + boolean editField1Password, + Properties fillThis); + +} // end of interface History diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java index 92eb7234b62..84ad698baee 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java @@ -48,19 +48,22 @@ import org.mozilla.util.Assert; import org.w3c.dom.Document; +import java.io.File; +import java.io.FileInputStream; + /** * * This is a test application for using the BrowserControl. * - * @version $Id: EMWindow.java,v 1.24 2000-11-03 03:16:46 edburns%acm.org Exp $ + * @version $Id: EMWindow.java,v 1.25 2001-04-02 21:13:48 ashuk%eng.sun.com Exp $ * * @see org.mozilla.webclient.BrowserControlFactory */ -public class EMWindow extends Frame implements DialogClient, ActionListener, DocumentLoadListener, MouseListener { +public class EMWindow extends Frame implements DialogClient, ActionListener, DocumentLoadListener, MouseListener, Prompt, PrefChangedCallback { static final int defaultWidth = 640; static final int defaultHeight = 480; @@ -73,6 +76,7 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc private Navigation navigation = null; private CurrentPage currentPage; private History history; + private static Preferences prefs; private Bookmarks bookmarks; private BookmarksFrame bookmarksFrame = null; private TreeModel bookmarksTree; @@ -81,14 +85,20 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc private Panel statusPanel; private Panel buttonsPanel; private FindDialog findDialog = null; +private PasswordDialog passDialog = null; +private UniversalDialog uniDialog = null; private MenuBar menuBar; + private Menu historyMenu; + private MenuItem backMenuItem; + private MenuItem forwardMenuItem; + private HistoryActionListener historyActionListener = null; + private Menu bookmarksMenu; private Label statusLabel; private String currentURL; private Document currentDocument = null; private EmbeddedMozilla creator; - private boolean viewMode = true; private Component forwardButton; private Component backButton; @@ -127,7 +137,7 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc MenuItem closeItem = new MenuItem("Close"); MenuItem findItem = new MenuItem("Find"); MenuItem findNextItem = new MenuItem("Find Next"); - MenuItem sourceItem = new MenuItem("View Page Source"); + MenuItem sourceItem = new MenuItem("View Page Source as String"); MenuItem pageInfoItem = new MenuItem("View Page Info"); MenuItem selectAllItem = new MenuItem("Select All"); MenuItem copyItem = new MenuItem("Copy"); @@ -143,6 +153,39 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc findItem.addActionListener(this); searchMenu.add(findNextItem); findNextItem.addActionListener(this); + + historyMenu = new Menu("History"); + backMenuItem = new MenuItem("Back"); + backMenuItem.addActionListener(this); + historyMenu.add(backMenuItem); + forwardMenuItem = new MenuItem("Forward"); + forwardMenuItem.addActionListener(this); + historyMenu.add(forwardMenuItem); + menuBar.add(historyMenu); + + bookmarksMenu = new Menu("Bookmarks"); + MenuItem addBookmark = new MenuItem("Add Current Page"); + addBookmark.addActionListener(this); + bookmarksMenu.add(addBookmark); + + addBookmark = new MenuItem("Add Current Page In New Folder"); + addBookmark.addActionListener(this); + bookmarksMenu.add(addBookmark); + + MenuItem manageBookmarks = new MenuItem("Manage Bookmarks..."); + manageBookmarks.addActionListener(this); + bookmarksMenu.add(manageBookmarks); + menuBar.add(bookmarksMenu); + + Menu streamMenu = new Menu("Stream"); + MenuItem streamFromFile = new MenuItem("Load Stream From File..."); + streamFromFile.addActionListener(this); + streamMenu.add(streamFromFile); + MenuItem randomStream = new MenuItem("Load Random HTML InputStream"); + randomStream.addActionListener(this); + streamMenu.add(randomStream); + menuBar.add(streamMenu); + viewMenu.add(sourceItem); sourceItem.addActionListener(this); viewMenu.add(pageInfoItem); @@ -171,15 +214,19 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc stopButton.setEnabled(false); refreshButton = makeItem(buttonsPanel, "Refresh", 3, 0, 1, 1, 0.0, 0.0); refreshButton.setEnabled(false); - makeItem(buttonsPanel, "Bookmarks", 4, 0, 1, 1, 0.0, 0.0); - // makeItem(buttonsPanel, "DOMViewer", 5, 0, 1, 1, 0.0, 0.0); + makeItem(buttonsPanel, "DOMViewer", 4, 0, 1, 1, 0.0, 0.0); // Create the control panel controlPanel = new Panel(); controlPanel.setLayout(new BorderLayout()); // Add the URL field, and the buttons panel - controlPanel.add(urlField, BorderLayout.CENTER); + Panel centerPanel = new Panel(); + centerPanel.setLayout(new BorderLayout()); + centerPanel.add(urlField, BorderLayout.NORTH); + + // controlPanel.add(urlField, BorderLayout.CENTER); + controlPanel.add(centerPanel, BorderLayout.CENTER); controlPanel.add(buttonsPanel, BorderLayout.WEST); // create the status panel @@ -229,7 +276,7 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc // Create the Context Menus add(popup); - popup.add(popup_ViewSource = new MenuItem("View Source")); + popup.add(popup_ViewSource = new MenuItem("View Source as ByteArray")); popup.add(popup_SelectAll = new MenuItem("Select All")); contextListener = new PopupActionListener(); @@ -243,11 +290,30 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc try { navigation = (Navigation) browserControl.queryInterface(BrowserControl.NAVIGATION_NAME); + navigation.setPrompt(this); currentPage = (CurrentPage) browserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME); history = (History) browserControl.queryInterface(BrowserControl.HISTORY_NAME); - + prefs = (Preferences) + browserControl.queryInterface(BrowserControl.PREFERENCES_NAME); + prefs.registerPrefChangedCallback(this, + "network.cookie.warnAboutCookies", + "This IS the Closure!"); + prefs.setPref("network.cookie.warnAboutCookies", "true"); + prefs.setPref("browser.cache.disk_cache_size", "0"); + + // pull out the proxies, and make java aware of them + Properties prefsProps = prefs.getPrefs(); + String proxyHost = (String) prefsProps.get("network.proxy.http"); + String proxyPort = (String) prefsProps.get("network.proxy.http_port"); + if (null != proxyHost && null != proxyPort) { + System.setProperty("http.proxyHost", proxyHost); + System.setProperty("http.proxyPort", proxyPort); + } + + //prefsProps = prefs.getPrefs(); + //prefsProps.list(System.out); // This works, try it! } catch (Exception e) { System.out.println(e.toString()); @@ -267,6 +333,7 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc System.out.println("debug: edburns: got Bookmarks instance"); bookmarksTree = bookmarks.getBookmarks(); + /********* TreeNode bookmarksRoot = (TreeNode) bookmarksTree.getRoot(); @@ -295,11 +362,8 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc *****/ /********** - BookmarkEntry folder = bookmarks.newBookmarkFolder("newFolder"); - bookmarks.addBookmark(null, folder); - BookmarkEntry entry = bookmarks.newBookmarkEntry("http://yoyo.com"); System.out.println("debug: edburns: got new entry"); Properties entryProps = entry.getProperties(); @@ -352,55 +416,69 @@ public void actionPerformed (ActionEvent evt) try { - // deal with the menu item commands - if (evt.getSource() instanceof MenuItem) { - if (command.equals("New Window")) { - creator.CreateEMWindow(); + if (command.equals("New Window")) { + creator.CreateEMWindow(); + } + else if (command.equals("Close")) { + System.out.println("Got windowClosing"); + System.out.println("destroying the BrowserControl"); + EMWindow.this.delete(); + // should close the BrowserControlCanvas + creator.DestroyEMWindow(winNum); + } + else if (command.equals("Find")) { + if (null == findDialog) { + Frame f = new Frame(); + f.setSize(350,150); + findDialog = new FindDialog(this, this, + "Find in Page", "Find ", + "", 20, false); + findDialog.setModal(false); } - else if (command.equals("Close")) { - System.out.println("Got windowClosing"); - System.out.println("destroying the BrowserControl"); - EMWindow.this.delete(); - // should close the BrowserControlCanvas - creator.DestroyEMWindow(winNum); - } - else if (command.equals("Find")) { - if (null == findDialog) { - Frame f = new Frame(); - f.setSize(350,150); - findDialog = new FindDialog(this, this, - "Find in Page", "Find ", - "", 20, false); - findDialog.setModal(false); - } - findDialog.setVisible(true); - // currentPage.findInPage("Sun", true, true); - } - else if (command.equals("Find Next")) { - currentPage.findNextInPage(false); - } - else if (command.equals("View Page Source")) { - currentPage.getSourceBytes(viewMode); - viewMode = !viewMode; - } - else if (command.equals("View Page Info")) { - currentPage.getPageInfo(); - } - else if (command.equals("Select All")) { - currentPage.selectAll(); - } - else if (command.equals("Copy")) { - currentPage.copyCurrentSelectionToSystemClipboard(); - } - } - // deal with the button bar commands + findDialog.setVisible(true); + // currentPage.findInPage("Sun", true, true); + } + else if (command.equals("Find Next")) { + currentPage.findNextInPage(); + } + else if (command.equals("View Page Source as String")) { + String sou = currentPage.getSource(); + System.out.println("+++++++++++ Page Source is +++++++++++\n\n" + sou); + } + else if (command.equals("View Page Info")) { + currentPage.getPageInfo(); + } + else if (command.equals("Select All")) { + currentPage.selectAll(); + } + else if (command.equals("Copy")) { + currentPage.copyCurrentSelectionToSystemClipboard(); + } else if(command.equals("Stop")) { navigation.stop(); } else if (command.equals("Refresh")) { navigation.refresh(Navigation.LOAD_NORMAL); } - else if (command.equals("Bookmarks")) { + else if (command.equals("Add Current Page")) { + if (null == bookmarksTree) { + bookmarksTree = bookmarks.getBookmarks(); + } + BookmarkEntry entry = + bookmarks.newBookmarkEntry(urlField.getText()); + bookmarks.addBookmark(null, entry); + } + else if (command.equals("Add Current Page In New Folder")) { + if (null == bookmarksTree) { + bookmarksTree = bookmarks.getBookmarks(); + } + BookmarkEntry folder = bookmarks.newBookmarkFolder("newFolder"); + bookmarks.addBookmark(null, folder); + BookmarkEntry entry = + bookmarks.newBookmarkEntry(urlField.getText()); + bookmarks.addBookmark(folder, entry); + } + else if (command.equals("Manage Bookmarks...")) { if (null == bookmarksTree) { bookmarksTree = bookmarks.getBookmarks(); } @@ -413,6 +491,33 @@ public void actionPerformed (ActionEvent evt) } bookmarksFrame.setVisible(true); } + else if (command.equals("Load Stream From File...")) { + FileDialog fileDialog = new FileDialog(this, "Pick an HTML file", + FileDialog.LOAD); + fileDialog.show(); + String file = fileDialog.getFile(); + String directory = fileDialog.getDirectory(); + + if ((null != file) && (null != directory) && + (0 < file.length()) && (0 < directory.length())) { + String absPath = directory + file; + + FileInputStream fis = new FileInputStream(absPath); + File tFile = new File(absPath); + + System.out.println("debug: edburns: file: " + absPath); + + navigation.loadFromStream(fis, "file:///hello.html", + "text/html", (int) tFile.length(), + null); + } + } + else if (command.equals("Load Random HTML InputStream")) { + RandomHTMLInputStream rhis = new RandomHTMLInputStream(3); + System.out.println("debug: edburns: created RandomHTMLInputStream"); + navigation.loadFromStream(rhis, "http://randomstream.com/", + "text/html", -1, null); + } else if (command.equals("DOMViewer")) { if (null == domViewer) { domViewer = new DOMViewerFrame("DOM Viewer", creator); @@ -434,6 +539,8 @@ public void actionPerformed (ActionEvent evt) history.forward(); } } + else if (command.equals(" ")) { + } else { navigation.loadURL(urlField.getText()); } @@ -445,6 +552,9 @@ public void actionPerformed (ActionEvent evt) public void dialogDismissed(Dialog d) { + if (d == passDialog || d == uniDialog) { + return; + } if(findDialog.wasClosed()) { System.out.println("Find Dialog Closed"); } @@ -508,6 +618,10 @@ private Component makeItem (Panel p, Object arg, int x, int y, int w, int h, dou p.add(comp); gbl.setConstraints(comp, c); + + if (((String)arg).equals(" ")) { + b.setEnabled(false); + } } return comp; } // makeItem() @@ -543,7 +657,10 @@ public void eventDispatched(WebclientEvent event) case ((int) DocumentLoadEvent.END_DOCUMENT_LOAD_EVENT_MASK): stopButton.setEnabled(false); backButton.setEnabled(history.canBack()); + backMenuItem.setEnabled(history.canBack()); forwardButton.setEnabled(history.canForward()); + forwardMenuItem.setEnabled(history.canForward()); + populateHistoryMenu(); statusLabel.setText("Done."); currentDocument = currentPage.getDOM(); // add the new document to the domViewer @@ -556,6 +673,55 @@ public void eventDispatched(WebclientEvent event) } } +/** + + * This method exercises the rest of the history API that isn't + * exercised elsewhere in the browser. + + */ + +private void populateHistoryMenu() +{ + int i = 0; + int histLen = 0; + int curIndex = 0; + String curUrl; + MenuItem curItem; + historyMenu.removeAll(); + + if (null == historyActionListener) { + historyActionListener = new HistoryActionListener(); + if (null == historyActionListener) { + return; + } + } + + // add back these MenuItems + historyMenu.add(backMenuItem); + historyMenu.add(forwardMenuItem); + + // now populate the menu with history items + histLen = history.getHistoryLength(); + curIndex = history.getCurrentHistoryIndex(); + for (i = 0; i < histLen; i++) { + // PENDING(put in code to truncate unruly long URLs) + curUrl = history.getURLForIndex(i); + + // It's important that we prepend the index. This is used in + // the actionListener to load by index. + + if (i == curIndex) { + curUrl = Integer.toString(i) + " * " + curUrl; + } + else { + curUrl = Integer.toString(i) + " " + curUrl; + } + curItem = new MenuItem(curUrl); + curItem.addActionListener(historyActionListener); + historyMenu.add(curItem); + } +} + // // From MouseListener // @@ -626,14 +792,134 @@ public void mouseReleased(java.awt.event.MouseEvent e) { } +// +// Prompt methods +// + +public boolean promptUsernameAndPassword(String dialogTitle, + String text, + String passwordRealm, + int savePassword, + Properties fillThis) +{ + if (null == fillThis) { + return false; + } + if (null == passDialog) { + if (dialogTitle.equals("")) { + dialogTitle = "Basic Authentication Test"; + } + passDialog = new PasswordDialog(this, this, + dialogTitle, text, passwordRealm, + 20, true, fillThis); + if (null == passDialog) { + return false; + } + passDialog.setModal(true); + } + passDialog.setVisible(true); + + return passDialog.wasOk(); +} + +public boolean universalDialog(String titleMessage, + String dialogTitle, + String text, + String checkboxMsg, + String button0Text, + String button1Text, + String button2Text, + String button3Text, + String editfield1Msg, + String editfield2Msg, + int numButtons, + int numEditfields, + boolean editfield1Password, + Properties fillThis) +{ + System.out.println("titleMessage " + titleMessage); + System.out.println("dialogTitle " + dialogTitle); + System.out.println("text " + text); + System.out.println("checkboxMsg " + checkboxMsg); + System.out.println("button0Text " + button0Text); + System.out.println("button1Text " + button1Text); + System.out.println("button2Text " + button2Text); + System.out.println("button3Text " + button3Text); + System.out.println("editfield1Msg " + editfield1Msg); + System.out.println("editfield2Msg " + editfield2Msg); + System.out.println("numButtons " + numButtons); + System.out.println("numEditfields " + numEditfields); + System.out.println("editfield1Password " + editfield1Password); + + fillThis.put("editfield1Value", "edit1"); + fillThis.put("editfield2Value", "edit2"); + fillThis.put("checkboxState", "true"); + if (null == fillThis) { + return false; + } + if (null == uniDialog) { + if (dialogTitle.equals("")) { + dialogTitle = "Universal Dialog"; + } + uniDialog = new UniversalDialog(this, this, dialogTitle); + if (null == uniDialog) { + return false; + } + uniDialog.setParms(titleMessage, dialogTitle, text, checkboxMsg, + button0Text, button1Text, button2Text, + editfield1Msg, editfield2Msg, numButtons, + numEditfields, editfield1Password, fillThis); + uniDialog.setModal(true); + } + + uniDialog.setVisible(true); + + return true; +} + +// +// PrefChangedCallback +// +public int prefChanged(String prefName, Object closure) +{ + System.out.println("prefChanged: " + prefName + " closure: " + closure); + return 0; +} + +class HistoryActionListener implements ActionListener +{ + +public void actionPerformed(ActionEvent event) +{ + String command = event.getActionCommand(); + + if (null == command) { + return; + } + + // pull out the leading integer + Integer index; + int space = command.indexOf((int)' '); + if (-1 == space) { + return; + } + + index = new Integer(command.substring(0, space)); + + EMWindow.this.history.setCurrentHistoryIndex(index.intValue()); +} + +} + class PopupActionListener implements ActionListener { public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); - if (command.equals("View Source")) + if (command.equals("View Source as ByteArray")) { - System.out.println("I will now View Soure"); - EMWindow.this.currentPage.getSourceBytes(EMWindow.this.viewMode); - EMWindow.this.viewMode = !EMWindow.this.viewMode; + System.out.println("I will now View Source"); + byte source[] = EMWindow.this.currentPage.getSourceBytes(); + String sou = new String(source); + System.out.println("+++++++++++ Page Source is +++++++++++\n\n" + sou); } else if (command.equals("Select All")) { diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EmbeddedMozilla.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EmbeddedMozilla.java index 2e3a5668355..49bc20c0c75 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EmbeddedMozilla.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EmbeddedMozilla.java @@ -38,7 +38,7 @@ import org.mozilla.util.Assert; * This is a test application for using the BrowserControl. * - * @version $Id: EmbeddedMozilla.java,v 1.4 2000-04-20 18:15:42 edburns%acm.org Exp $ + * @version $Id: EmbeddedMozilla.java,v 1.5 2001-04-02 21:13:48 ashuk%eng.sun.com Exp $ * * @see org.mozilla.webclient.BrowserControlFactory @@ -68,7 +68,7 @@ public void CreateEMWindow() { System.out.println("Creating new EmbeddedMozilla window"); EMWindow aEMWindow ; - aEMWindow = new EMWindow("EmbeddedMozila#" + count+1, + aEMWindow = new EMWindow("EmbeddedMozila#" + (int)(count+1), binDir, url, count, this); count++; } @@ -93,7 +93,7 @@ public static void main(String [] arg) printUsage(); System.exit(-1); } - String urlArg =(2 == arg.length) ? arg[1] : "file:///E|/Projects/tmp/5105.html"; + String urlArg =(2 == arg.length) ? arg[1] : "http://www.mozilla.org/projects/blackwood/webclient/"; // set class vars used in EmbeddedMozilla ctor binDir = arg[0]; diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/PasswordDialog.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/PasswordDialog.java new file mode 100644 index 00000000000..ab391b0d294 --- /dev/null +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/PasswordDialog.java @@ -0,0 +1,194 @@ +/** Ashu -- this is the Find Dialog Class + instantiated within the EMWindow class, this + will act as the Modal dialog for calling Find/Find Next + functions for CurrentPage +*/ + +package org.mozilla.webclient.test; + +import java.awt.*; +import java.awt.event.*; + +import org.mozilla.webclient.Prompt; + +import java.util.Properties; + +public class PasswordDialog extends WorkDialog implements ActionListener, ItemListener{ + static private int _defaultTextFieldSize = 20; + private Button okButton; + private Button cancelButton; + private String realm; + private TextField userField; + private TextField passField; + private boolean wasOk; + private boolean wasCanceled; + private ButtonPanel buttonPanel = new ButtonPanel(); + private Properties props; + + + public PasswordDialog(Frame frame, DialogClient client, String title, + String text, String realm, + int userFieldSize, boolean modal, + Properties passwordProperties) { + super(frame, client, title, modal); + RealmPanel realmPanel; + okButton = addButton("Ok"); + cancelButton = addButton("Cancel"); + props = passwordProperties; + + okButton.addActionListener(this); + cancelButton.addActionListener(this); + + realmPanel = new RealmPanel(this, text, realm, + userFieldSize); + userField = realmPanel.getUserField(); + passField = realmPanel.getPassField(); + setWorkPanel(realmPanel); + } + + public void actionPerformed(ActionEvent ae) { + if(ae.getSource() == cancelButton) { + wasOk = false; + wasCanceled = true; + dispose(true); + } + else if(ae.getSource() == okButton) { + wasCanceled = false; + wasOk = true; + props.setProperty(Prompt.USER_NAME_KEY, userField.getText()); + props.setProperty(Prompt.PASSWORD_KEY, passField.getText()); + setUserField(""); + setPassField(""); + dispose(true); + } + } + + + public void itemStateChanged(ItemEvent e) { + } + + public void setVisible(boolean b) { + userField.requestFocus(); + super.setVisible(b); + } + + public void returnInTextField() { + okButton.requestFocus(); + } + + public TextField getUserField() { + return userField; + } + + public void setUserField(String string) { + // realmPanel.setUserField(string); + userField.setText(string); + } + + public void setPassField(String string) { + passField.setText(string); + } + + public String getAnswer() { + return userField.getText(); + } + + public boolean wasOk() { + return wasOk; + } + + public boolean wasCanceled() { + return wasCanceled; + } + + private void setRealm(String realm) { + this.realm = realm; + } +} + + +class RealmPanel extends Postcard { + private TextField userField; + private TextField passField; + private PasswordDialog dialog; + +public RealmPanel(PasswordDialog myDialog, String text, + String realm, int cols) +{ + super(new Panel()); + Panel panel = getPanel(); + this.dialog = myDialog; + + // set up the stuff on top of the text fields + Panel northPanel = new Panel(); + northPanel.setLayout(new BorderLayout()); + Label textLabel = new Label(text); + textLabel.setBackground(Color.lightGray); + Label realmLabel = new Label("Realm: " + realm); + realmLabel.setBackground(Color.lightGray); + northPanel.add(textLabel, BorderLayout.NORTH); + northPanel.add(realmLabel, BorderLayout.CENTER); + + panel.setLayout(new BorderLayout()); + panel.add(northPanel, BorderLayout.NORTH); + + // set up the text fields + + // set up the user name label and field + Panel centerPanel = new Panel(); + centerPanel.setLayout(new BorderLayout()); + + Panel userPanel = new Panel(); + userPanel.setLayout(new BorderLayout()); + Label nameLabel = new Label("User Name: "); + nameLabel.setBackground(Color.lightGray); + userPanel.add(nameLabel, BorderLayout.WEST); + if (cols != 0) { + userField = new TextField("", cols); + } + else { + userField = new TextField(); + } + userPanel.add(userField, BorderLayout.CENTER); + centerPanel.add(userPanel, BorderLayout.NORTH); + + // set up the password label and field + Panel passPanel = new Panel(); + passPanel.setLayout(new BorderLayout()); + Label passLabel = new Label("Password: "); + passLabel.setBackground(Color.lightGray); + passPanel.add(passLabel, BorderLayout.WEST); + if (cols != 0) { + passField = new TextField("", cols); + } + else { + passField = new TextField(); + } + passField.setEchoChar('*'); + passPanel.add(passField, BorderLayout.CENTER); + centerPanel.add(passPanel, BorderLayout.CENTER); + // + + // add the center panel to the main panel + panel.add(centerPanel, BorderLayout.CENTER); +} + +public TextField getUserField() +{ + return userField; +} + + public void setUserField(String string) { + userField.setText(string); + } + + public TextField getPassField() { + return passField; + } + + public void setPassField(String string) { + passField.setText(string); + } + +} + diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/RandomHTMLInputStream.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/RandomHTMLInputStream.java new file mode 100644 index 00000000000..d3d13397adf --- /dev/null +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/RandomHTMLInputStream.java @@ -0,0 +1,268 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Ed Burns + */ + +package org.mozilla.webclient.test; + +/* + * RandomHTMLInputStream.java + */ + +import org.mozilla.util.Assert; +import org.mozilla.util.ParameterCheck; + +import java.io.InputStream; +import java.io.IOException; +import java.util.Random; + +/** + + * This class simulates a nasty, misbehavin' InputStream. + + * It randomly throws IOExceptions, blocks on read, and is bursty. + + */ + +public class RandomHTMLInputStream extends InputStream +{ + +// +// Class variables +// + +private static final int MAX_AVAILABLE = 4096; + +/** + + * This makes it so only when we get a random between 0 and 100 number + * that evenly divides by three do we throw an IOException + + */ + +private static final int EXCEPTION_DIVISOR = 179; + +private static final byte [] CHARSET; + +// +// relationship ivars +// + +private Random random; + +// +// attribute ivars +// + +private boolean isClosed; + +private boolean firstRead; + +/** + + * the number of times that read(bytearray) can be called and still get + * data. + + */ + +private int numReads; + +private int available; + +/** + + * @param yourNumReads must be at least 2 + + */ + +static { + String charSet = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890[]{}"; + CHARSET = charSet.getBytes(); +} + +public RandomHTMLInputStream(int yourNumReads) +{ + ParameterCheck.greaterThan(yourNumReads, 1); + + random = new Random(); + Assert.assert(null != random); + + isClosed = false; + firstRead = true; + numReads = yourNumReads; + available = random.nextInt(MAX_AVAILABLE); +} + +public int available() throws IOException +{ + int result; + if (shouldThrowException()) { + throw new IOException("It's time for an IOException!"); + } + if (isClosed) { + result = -1; + } + else { + result = available; + } + return result; +} + +public int read() throws IOException +{ + int result = 0; + if (shouldThrowException()) { + throw new IOException("It's time for an IOException!"); + } + + if (0 < available) { + result = (int) 'a'; + available--; + } + else { + result = -1; + } + return result; +} + +public int read(byte[] b, int off, int len) throws IOException +{ + if (shouldThrowException()) { + throw new IOException("It's time for an IOException!"); + } + + byte [] bytes; + int i = 0; + int max = 0; + int numRead = -1; + + // write case 0, no more reads left + if (0 == numReads || isClosed) { + return -1; + } + if (len <= available) { + max = len; + } + else { + max = available; + } + + + if (firstRead) { + String htmlHead = "

START Random Data";
+        numRead = htmlHead.length();
+
+        // write case 1, yes enough length to write htmlHead
+        if (numRead < len && len <= available) {
+            bytes = htmlHead.getBytes();
+            for (i = 0; i < numRead; i++) {
+                b[off+i] = bytes[i];
+            }
+            available -= numRead;
+        }
+        else {
+            // write case 2, not enough length to write htmlHead
+            for (i = 0; i < max; i++) {
+                b[off+i] = (byte) random.nextInt(8);
+            }
+            numRead = max;
+            available -= max;
+        }
+        firstRead = false;
+    }
+    else {
+        // if this is the last read
+        if (1 == numReads) {
+            String htmlTail = "\nEND Random Data
"; + numRead = htmlTail.length(); + // write case 3, yes enough length to write htmlTail + if (numRead < len && len <= available) { + bytes = htmlTail.getBytes(); + for (i = 0; i < numRead; i++) { + b[off+i] = bytes[i]; + } + available -= numRead; + } + else { + // write case 4, not enough length to write htmlTail + for (i = 0; i < max; i++) { + b[off+i] = (byte) random.nextInt(8); + } + numRead = max; + available -= max; + } + } + else { + + // if it's time to block + if (random.nextBoolean()) { + try { + System.out.println("RandomHTMLInputStream:: sleeping"); + Thread.sleep(3000); + } + catch (Exception e) { + throw new IOException(e.getMessage()); + } + } + + // write case 5, write some random bytes to fit length + + // this is not the first or the last read, just cough up + // some random bytes. + + bytes = new byte[max]; + for (i = 0; i < max; i++) { + if (0 == (i % 78)) { + b[off+i] = (byte) '\n'; + } + else { + b[off+i] = CHARSET[random.nextInt(CHARSET.length)]; + } + } + numRead = max; + available -= max; + } + } + available = random.nextInt(MAX_AVAILABLE); + numReads--; + return numRead; +} + +public void close() throws IOException +{ + if (shouldThrowException()) { + throw new IOException("It's time for an IOException!"); + } + isClosed = true; +} + +private boolean shouldThrowException() +{ + int nextInt = random.nextInt(10000); + + boolean result = false; + + if (nextInt > EXCEPTION_DIVISOR) { + result = (0 == (nextInt % EXCEPTION_DIVISOR)); + } + return result; +} + +} diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/UniversalDialog.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/UniversalDialog.java new file mode 100644 index 00000000000..36beb7c6f76 --- /dev/null +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/UniversalDialog.java @@ -0,0 +1,217 @@ +/** Ashu -- this is the Find Dialog Class + instantiated within the EMWindow class, this + will act as the Modal dialog for calling Find/Find Next + functions for CurrentPage +*/ + +package org.mozilla.webclient.test; + +import org.mozilla.util.Assert; +import org.mozilla.webclient.Prompt; + +import java.awt.*; +import java.awt.event.*; + +import java.util.Properties; + +// PENDING(edburns): Apply uniform formatting throughout webclient + +public class UniversalDialog extends WorkDialog implements ActionListener, ItemListener +{ +static private int _defaultTextFieldSize = 20; +public Button [] buttons; +public TextField [] fields; + +public String mTitleMsg; +public String mText; +public String mCheckboxMsg; +public Checkbox mCheckbox; +public String mField1Label; +public String mField2Label; +public boolean mField1IsPasswd; +public Properties mProps; + +public UniversalDialog(Frame frame, DialogClient client, String dialogTitle) +{ + super(frame, client, dialogTitle, /* isModal */ true); +} + +public void setParms(String titleMsg, + String dialogTitle, String text, String checkboxMsg, + String button0Text, String button1Text, + String button2Text, String editfield1Msg, + String editfield2Msg, + int numButtons, int numEditfields, + boolean editfield1Password, + Properties props) +{ + DialogPanel dialogPanel; + int i = 0; + buttons = null; + fields = null; + mTitleMsg = titleMsg; + this.setTitle(dialogTitle); + mText = text; + mCheckboxMsg = checkboxMsg; + mField1Label = editfield1Msg; + mField2Label = editfield2Msg; + mField1IsPasswd = editfield1Password; + mProps = props; + + if (0 < numButtons) { + buttons = new Button[numButtons]; + String label; + + for (i = 0; i < numButtons; i++) { + // figure out which String to use; + if (0 == i) { + label = button0Text; + } + else if (1 == i) { + label = button1Text; + } + else { + label = button2Text; + } + buttons[i] = addButton(label); + buttons[i].addActionListener(this); + } + } + + if (0 < numEditfields) { + fields = new TextField[numEditfields]; + + for (i = 0; i < numEditfields; i++) { + fields[i] = new TextField("", _defaultTextFieldSize); + if (mField1IsPasswd && i == 0) { + fields[i].setEchoChar('*'); + } + } + } + + dialogPanel = new DialogPanel(this); + setWorkPanel(dialogPanel); +} + +public void actionPerformed(ActionEvent ae) +{ + Assert.assert(null != buttons); + int i = 0; + for (i = 0; i < buttons.length; i++) { + if (ae.getSource() == buttons[i]) { + mProps.put(Prompt.BUTTON_PRESSED_KEY, Integer.toString(i)); + // pull out the values from the TextFields + break; + } + } + if (null != fields) { + String curString; + for (i = 0; i < fields.length; i++) { + curString = fields[i].getText(); + if (0 == i) { + mProps.put(Prompt.EDIT_FIELD_1_KEY, curString); + } + else { + mProps.put(Prompt.EDIT_FIELD_2_KEY, curString); + } + } + } + + if (null != mCheckbox) { + Boolean bool = new Boolean(mCheckbox.getState()); + mProps.put(Prompt.CHECKBOX_STATE_KEY, bool.toString()); + } + dispose(true); +} + + +public void itemStateChanged(ItemEvent e) +{ +} + +public void setVisible(boolean b) +{ + if (null != fields) { + fields[0].requestFocus(); + } + super.setVisible(b); +} + +} + + +class DialogPanel extends Postcard +{ +private UniversalDialog dialog; + +public DialogPanel(UniversalDialog myDialog) +{ + super(new Panel()); + Panel panel = getPanel(); + panel.setLayout(new BorderLayout()); + this.dialog = myDialog; + int i = 0; + + if (null != dialog.mTitleMsg || null != dialog.mText) { + Panel northPanel = new Panel(); + northPanel.setLayout(new BorderLayout()); + + // set up the stuff on top of the text fields + if (null != dialog.mTitleMsg) { + Label titleLabel = new Label(dialog.mTitleMsg); + titleLabel.setBackground(Color.lightGray); + northPanel.add(titleLabel, BorderLayout.NORTH); + } + if (null != dialog.mText) { + Label textLabel = new Label(dialog.mText); + textLabel.setBackground(Color.lightGray); + northPanel.add(textLabel, BorderLayout.CENTER); + } + panel.add(northPanel, BorderLayout.NORTH); + } + + Panel centerPanel = new Panel(); + centerPanel.setLayout(new BorderLayout()); + + if (null != dialog.fields) { + Panel fieldPanel = new Panel(); + fieldPanel.setLayout(new BorderLayout()); + // set up the text fields + Panel curPanel; + Label curLabel; + for (i = 0; i < dialog.fields.length; i++) { + // set up the label and field + curPanel = new Panel(); + curPanel.setLayout(new BorderLayout()); + + if (0 == i) { + curLabel = new Label(dialog.mField1Label); + } + else { + curLabel = new Label(dialog.mField2Label); + } + curLabel.setBackground(Color.lightGray); + curPanel.add(curLabel, BorderLayout.WEST); + + curPanel.add(dialog.fields[i], BorderLayout.CENTER); + if (0 == i) { + fieldPanel.add(curPanel, BorderLayout.NORTH); + } + else { + fieldPanel.add(curPanel, BorderLayout.CENTER); + } + } + centerPanel.add(fieldPanel, BorderLayout.NORTH); + } + + if (null != dialog.mCheckboxMsg) { + dialog.mCheckbox = new Checkbox(dialog.mCheckboxMsg); + dialog.mCheckbox.setBackground(Color.lightGray); + centerPanel.add(dialog.mCheckbox, BorderLayout.CENTER); + } + // add the center panel to the main panel + panel.add(centerPanel, BorderLayout.CENTER); +} + +} + diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/BookmarkEntryImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/BookmarkEntryImpl.java index 7413475d33b..abf38170924 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/BookmarkEntryImpl.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/BookmarkEntryImpl.java @@ -30,9 +30,8 @@ import org.mozilla.webclient.Bookmarks; import org.mozilla.webclient.BookmarkEntry; import org.mozilla.webclient.UnimplementedException; -import java.util.Properties; - import javax.swing.tree.MutableTreeNode; +import java.util.Properties; public class BookmarkEntryImpl extends RDFTreeNode implements BookmarkEntry { @@ -52,9 +51,6 @@ public class BookmarkEntryImpl extends RDFTreeNode implements BookmarkEntry // Relationship Instance Variables -Properties properties = null; - - // // Constructors and Initializers // @@ -114,17 +110,12 @@ public void setUserObject(Object object) public Properties getProperties() { - if ((null == properties) && - (null == (properties = new Properties()))) { - throw new IllegalStateException("Can't create properties table"); - } - - return properties; + return super.getProperties(); } public boolean isFolder() { - return nativeIsContainer(nativeWebShell, getNativeRDFNode()); + return super.isFolder(); } // ----VERTIGO_TEST_START @@ -139,7 +130,7 @@ public static void main(String [] args) Log.setApplicationName("BookmarkEntryImpl"); Log.setApplicationVersion("0.0"); - Log.setApplicationVersionDate("$Id: BookmarkEntryImpl.java,v 1.3 2000-11-03 03:16:48 edburns%acm.org Exp $"); + Log.setApplicationVersionDate("$Id: BookmarkEntryImpl.java,v 1.4 2001-04-02 21:13:56 ashuk%eng.sun.com Exp $"); } diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/BookmarksImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/BookmarksImpl.java index f97796d5482..236fe566a4a 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/BookmarksImpl.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/BookmarksImpl.java @@ -44,6 +44,7 @@ public class BookmarksImpl extends ImplObjectNative implements Bookmarks // // Constants // +private static final String NC_NS = "http://home.netscape.com/NC-rdf#"; // // Class Variables @@ -176,29 +177,40 @@ public BookmarkEntry newBookmarkEntry(String url) getBookmarks(); int newNode; - System.out.println("debug: edburns: BookmarksImpl.newBookmarkEntry: url:" + url); if (-1 != (newNode = nativeNewRDFNode(nativeWebShell, url, false))) { result = new BookmarkEntryImpl(nativeWebShell, newNode, null); // use put instead of setProperty for jdk1.1.x compatibility. + result.getProperties().put(BookmarkEntry.NAME, url); result.getProperties().put(BookmarkEntry.URL, url); } return result; } +/** + + * Due to the vagaries of the mozilla RDF implementation, folders and + * bookmark entries are handled differently. For Folders, we don't + * create a nativeRDFNode at the outset. Rather, we just create the + * properties table and stock it with the known keys, then wait for the + * nativeRDFNode to be created en addBookmark. + + */ + public BookmarkEntry newBookmarkFolder(String name) { ParameterCheck.nonNull(name); BookmarkEntry result = null; getBookmarks(); - int newNode; - - System.out.println("debug: edburns: BookmarksImpl.newBookmarkFolder: name:" + name); - if (-1 != (newNode = nativeNewRDFNode(nativeWebShell, name, true))) { - result = new BookmarkEntryImpl(nativeWebShell, newNode, null); - result.getProperties().put(BookmarkEntry.NAME, name); + + if (null == (result = new BookmarkEntryImpl(nativeWebShell, -1, null))) { + throw new NullPointerException("Can't create bookmark folder for: " + + name); } + result.getProperties().put(BookmarkEntry.NAME, name); + result.getProperties().put(BookmarkEntry.URL, NC_NS + "$" + name); + result.getProperties().put(BookmarkEntry.IS_FOLDER, name); return result; } @@ -230,7 +242,7 @@ public static void main(String [] args) Log.setApplicationName("BookmarksImpl"); Log.setApplicationVersion("0.0"); - Log.setApplicationVersionDate("$Id: BookmarksImpl.java,v 1.7 2000-11-03 03:16:49 edburns%acm.org Exp $"); + Log.setApplicationVersionDate("$Id: BookmarksImpl.java,v 1.8 2001-04-02 21:13:56 ashuk%eng.sun.com Exp $"); try { org.mozilla.webclient.BrowserControlFactory.setAppData(args[0]); diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/CurrentPageImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/CurrentPageImpl.java index 35eab3ca3da..10b2e0eb109 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/CurrentPageImpl.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/CurrentPageImpl.java @@ -108,12 +108,12 @@ public void findInPage(String stringToFind, boolean forward, boolean matchCase) } } -public void findNextInPage(boolean forward) +public void findNextInPage() { myFactory.throwExceptionIfNotInitialized(); synchronized(myBrowserControl) { - nativeFindNextInPage(nativeWebShell, forward); + nativeFindNextInPage(nativeWebShell); } } @@ -151,62 +151,67 @@ public Properties getPageInfo() public String getSource() { - String result = null; myFactory.throwExceptionIfNotInitialized(); - - /* synchronized(myBrowserControl) { - result = nativeGetSource(); + String HTMLContent = null; + String currURL = getCurrentURL(); + System.out.println("\nThe Current URL is -- " + currURL); + try { + URL aURL = new URL(currURL); + URLConnection connection = aURL.openConnection(); + connection.connect(); + BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); + boolean more = true; + while (more) + { + String line = in.readLine(); + if (line == null) more = false; + else + { + HTMLContent = HTMLContent + line; + } + } } - */ - throw new UnimplementedException("\nUnimplementedException -----\n API Function CurrentPage::getSource has not yet been implemented.\n"); - - // return result; + catch (Throwable e) + { + System.out.println("Error occurred while establishing connection -- \n ERROR - " + e); + } + + return HTMLContent; } -public byte [] getSourceBytes(boolean viewMode) +public byte [] getSourceBytes() { byte [] result = null; myFactory.throwExceptionIfNotInitialized(); - synchronized(myBrowserControl) { - result = nativeGetSourceBytes(nativeWebShell, viewMode); - } - - //throw new UnimplementedException("\nUnimplementedException -----\n API Function CurrentPage::getSourceBytes has not yet been implemented.\n Will be available after Webclient M3 Release\n"); - - // PENDING (Ashu) - This should work - but it does not get anything from URl - // and hangs up from time to time. Have to Debug. In M15, other native solution - // will also be available using DocShell::viewMode - - /* String HTMLContent = null; - String URL = getCurrentURL(); - System.out.println("\nThe Current URL is -- " + URL); + String currURL = getCurrentURL(); + System.out.println("\nThe Current URL is -- " + currURL); try { - Socket s = new Socket("sunweb.central",80); - BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); - boolean more = true; - while (more) - { - String line = in.readLine(); - if (line == null) more = false; - else - { - HTMLContent = HTMLContent + line; - System.out.println(line); - } - } + URL aURL = new URL(currURL); + URLConnection connection = aURL.openConnection(); + connection.connect(); + BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); + boolean more = true; + while (more) + { + String line = in.readLine(); + if (line == null) more = false; + else + { + HTMLContent = HTMLContent + line; + } + } } - catch (Throwable e) - { - System.out.println("Error occurred while establishing connection -- \n ERROR - " + e); - } - */ + catch (Throwable e) + { + System.out.println("Error occurred while establishing connection -- \n ERROR - " + e); + } + result = HTMLContent.getBytes(); return result; - } - + public void resetFind() { myFactory.throwExceptionIfNotInitialized(); @@ -233,17 +238,19 @@ native public void nativeCopyCurrentSelectionToSystemClipboard(int webShellPtr); native public void nativeFindInPage(int webShellPtr, String stringToFind, boolean forward, boolean matchCase); -native public void nativeFindNextInPage(int webShellPtr, boolean forward); +native public void nativeFindNextInPage(int webShellPtr); native public String nativeGetCurrentURL(int webShellPtr); native public Document nativeGetDOM(int webShellPtr); // webclient.PageInfo getPageInfo(); - -native public String nativeGetSource(); + +/* PENDING(ashuk): remove this from here and in the motif directory + * native public String nativeGetSource(); -native public byte [] nativeGetSourceBytes(int webShellPtr, boolean viewMode); + * native public byte [] nativeGetSourceBytes(int webShellPtr, boolean viewMode); + */ native public void nativeResetFind(int webShellPtr); @@ -261,7 +268,7 @@ public static void main(String [] args) Assert.setEnabled(true); Log.setApplicationName("CurrentPageImpl"); Log.setApplicationVersion("0.0"); - Log.setApplicationVersionDate("$Id: CurrentPageImpl.java,v 1.10 2000-11-03 01:26:59 ashuk%eng.sun.com Exp $"); + Log.setApplicationVersionDate("$Id: CurrentPageImpl.java,v 1.11 2001-04-02 21:13:57 ashuk%eng.sun.com Exp $"); } diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NativeEventThread.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NativeEventThread.java index ae1400b5792..a5842686832 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NativeEventThread.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NativeEventThread.java @@ -45,6 +45,13 @@ import org.mozilla.webclient.UnimplementedException; public class NativeEventThread extends Thread { +// +// Class variables +// + +private static Object firstThread = null; + + // // Attribute ivars // @@ -111,6 +118,10 @@ public NativeEventThread(String threadName, BrowserControl yourBrowserControl) super(threadName); ParameterCheck.nonNull(yourBrowserControl); + if (null == firstThread) { + firstThread = this; + } + browserControl = yourBrowserControl; try { @@ -206,6 +217,13 @@ public void run() } while (true) { + try { + Thread.sleep(1); + } + catch (Exception e) { + System.out.println("NativeEventThread.run(): Exception: " + e + + " while sleeping: " + e.getMessage()); + } synchronized (this) { // this has to be inside the synchronized block! @@ -222,7 +240,9 @@ public void run() return; } - nativeProcessEvents(nativeWebShell); + if (this == firstThread) { + nativeProcessEvents(nativeWebShell); + } if (null != listenersToAdd && !listenersToAdd.isEmpty()) { tempEnum = listenersToAdd.elements(); diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NavigationImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NavigationImpl.java index 78566645d17..547ce8a64e8 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NavigationImpl.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NavigationImpl.java @@ -25,13 +25,16 @@ package org.mozilla.webclient.wrapper_native; import org.mozilla.util.Assert; import org.mozilla.util.Log; import org.mozilla.util.ParameterCheck; +import org.mozilla.util.RangeException; import org.mozilla.webclient.BrowserControl; import org.mozilla.webclient.Navigation; import org.mozilla.webclient.WindowControl; import org.mozilla.webclient.WrapperFactory; +import org.mozilla.webclient.Prompt; -import java.awt.Rectangle; +import java.io.InputStream; +import java.util.Properties; public class NavigationImpl extends ImplObjectNative implements Navigation { @@ -84,6 +87,29 @@ public void loadURL(String absoluteURL) } } +public void loadFromStream(InputStream stream, String uri, + String contentType, int contentLength, + Properties loadInfo) +{ + ParameterCheck.nonNull(stream); + ParameterCheck.nonNull(uri); + ParameterCheck.nonNull(contentType); + if (contentLength < -1 || contentLength == 0) { + throw new RangeException("contentLength value " + contentLength + + " is out of range. It is should be either -1 or greater than 0."); + } + + myFactory.throwExceptionIfNotInitialized(); + Assert.assert(-1 != nativeWebShell); + + synchronized(myBrowserControl) { + nativeLoadFromStream(nativeWebShell, stream, + uri, contentType, contentLength, + loadInfo); + } +} + + public void refresh(long loadFlags) { ParameterCheck.noLessThan(loadFlags, 0); @@ -105,16 +131,36 @@ public void stop() } } +public void setPrompt(Prompt yourPrompt) +{ + ParameterCheck.nonNull(yourPrompt); + myFactory.throwExceptionIfNotInitialized(); + Assert.assert(-1 != nativeWebShell); + + synchronized(myBrowserControl) { + nativeSetPrompt(nativeWebShell, yourPrompt); + } + +} + // // Native methods // public native void nativeLoadURL(int webShellPtr, String absoluteURL); +public native void nativeLoadFromStream(int webShellPtr, InputStream stream, + String uri, + String contentType, + int contentLength, + Properties loadInfo); + public native void nativeRefresh(int webShellPtr, long loadFlags); public native void nativeStop(int webShellPtr); +public native void nativeSetPrompt(int webShellPtr, Prompt yourPrompt); + // ----VERTIGO_TEST_START // @@ -127,7 +173,7 @@ public static void main(String [] args) Log.setApplicationName("NavigationImpl"); Log.setApplicationVersion("0.0"); - Log.setApplicationVersionDate("$Id: NavigationImpl.java,v 1.3 2000-07-22 02:48:26 edburns%acm.org Exp $"); + Log.setApplicationVersionDate("$Id: NavigationImpl.java,v 1.4 2001-04-02 21:13:59 ashuk%eng.sun.com Exp $"); try { org.mozilla.webclient.BrowserControlFactory.setAppData(args[0]); diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/PreferencesImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/PreferencesImpl.java new file mode 100644 index 00000000000..ea2041799da --- /dev/null +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/PreferencesImpl.java @@ -0,0 +1,186 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Ed Burns + */ + +package org.mozilla.webclient.wrapper_native; + +import org.mozilla.util.Assert; +import org.mozilla.util.Log; +import org.mozilla.util.ParameterCheck; + +import org.mozilla.webclient.BrowserControl; +import org.mozilla.webclient.WrapperFactory; +import org.mozilla.webclient.Preferences; +import org.mozilla.webclient.PrefChangedCallback; + +import java.util.Properties; + +import org.mozilla.webclient.UnimplementedException; + +public class PreferencesImpl extends ImplObjectNative implements Preferences +{ +// +// Constants +// + +// +// Class Variables +// + +// +// Instance Variables +// + +// Attribute Instance Variables + +// Relationship Instance Variables + +private Properties props; + +// +// Constructors and Initializers +// + +public PreferencesImpl(WrapperFactory yourFactory, + BrowserControl yourBrowserControl) +{ + super(yourFactory, yourBrowserControl); + props = null; +} + +/** + + * Since this class is a singleton, we don't expect this method to be + * called until the app is done with bookmarks for a considerable amount + * of time. + +// PENDING(): Write test case to see that a cycle of Preferences +// allocation/destruction/new instance allocation works correctly. + + */ + +public void delete() +{ +} + +// +// Class methods +// + +// +// General Methods +// + +// +// Methods from Preferences +// + +public void setPref(String prefName, String prefValue) +{ + if (null == prefName) { + return; + } + if (null == prefValue) { + return; + } + // determine the type of pref value: String, boolean, integer + try { + Integer intVal = Integer.valueOf(prefValue); + nativeSetIntPref(nativeWebShell, prefName, intVal.intValue()); + } + catch (NumberFormatException e) { + // it's not an integer + if (prefValue.equals("true") || prefValue.equals("false")) { + Boolean boolVal = Boolean.valueOf(prefValue); + nativeSetBoolPref(nativeWebShell, prefName, + boolVal.booleanValue()); + } + else { + // it must be a string + nativeSetUnicharPref(nativeWebShell, prefName, prefValue); + } + } +} + +public Properties getPrefs() +{ + props = nativeGetPrefs(nativeWebShell, props); + return props; +} + +public void registerPrefChangedCallback(PrefChangedCallback cb, + String prefName, Object closure) +{ + ParameterCheck.nonNull(cb); + ParameterCheck.nonNull(prefName); + + nativeRegisterPrefChangedCallback(nativeWebShell, cb, prefName, closure); +} + + +// +// native methods +// + +public native void nativeSetUnicharPref(int nativeWebShell, + String prefName, String prefValue); +public native void nativeSetIntPref(int nativeWebShell, + String prefName, int prefValue); +public native void nativeSetBoolPref(int nativeWebShell, + String prefName, boolean prefValue); +public native Properties nativeGetPrefs(int nativeWebShell, Properties props); +public native void nativeRegisterPrefChangedCallback(int nativeWebShell, + PrefChangedCallback cb, + String prefName, + Object closure); + +// ----VERTIGO_TEST_START + +// +// Test methods +// + +public static void main(String [] args) +{ + Assert.setEnabled(true); + + Log.setApplicationName("PreferencesImpl"); + Log.setApplicationVersion("0.0"); + Log.setApplicationVersionDate("$Id: PreferencesImpl.java,v 1.2 2001-04-02 21:13:59 ashuk%eng.sun.com Exp $"); + + try { + org.mozilla.webclient.BrowserControlFactory.setAppData(args[0]); + org.mozilla.webclient.BrowserControl control = + org.mozilla.webclient.BrowserControlFactory.newBrowserControl(); + Assert.assert(control != null); + + Preferences wc = (Preferences) + control.queryInterface(org.mozilla.webclient.BrowserControl.WINDOW_CONTROL_NAME); + Assert.assert(wc != null); + } + catch (Exception e) { + System.out.println("got exception: " + e.getMessage()); + } +} + +// ----VERTIGO_TEST_END + +} // end of class PreferencesImpl diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/RDFTreeNode.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/RDFTreeNode.java index 63e11940c63..53f34eac21a 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/RDFTreeNode.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/RDFTreeNode.java @@ -27,9 +27,13 @@ import org.mozilla.util.Log; import org.mozilla.util.ParameterCheck; import java.util.Enumeration; +import java.util.Properties; + import javax.swing.tree.TreeNode; import javax.swing.tree.MutableTreeNode; +import org.mozilla.webclient.BookmarkEntry; + public abstract class RDFTreeNode extends ISupportsPeer implements MutableTreeNode { // @@ -48,10 +52,11 @@ public abstract class RDFTreeNode extends ISupportsPeer implements MutableTreeNo // Relationship Instance Variables -private int nativeRDFNode = -1; +protected int nativeRDFNode = -1; private RDFTreeNode parent; +Properties properties = null; /** @@ -84,6 +89,16 @@ protected RDFTreeNode(int yourNativeWebShell, // General Methods // +public Properties getProperties() +{ + if ((null == properties) && + (null == (properties = new Properties()))) { + throw new IllegalStateException("Can't create properties table"); + } + + return properties; +} + // // Abstract Methods // @@ -111,7 +126,9 @@ private void setNativeRDFNode(int yourNativeRDFNode) protected void finalize() throws Throwable { - nativeRelease(nativeRDFNode); + if (-1 != nativeRDFNode) { + nativeRelease(nativeRDFNode); + } super.finalize(); } @@ -199,12 +216,17 @@ public boolean isLeaf() return nativeIsLeaf(nativeWebShell, nativeRDFNode); } - // // Methods from MutableTreeNode // +/** + + * Unfortunately, we have to handle folders and bookmarks differently. + + */ + public void insert(MutableTreeNode child, int index) { if (!(child instanceof RDFTreeNode)) { @@ -212,13 +234,29 @@ public void insert(MutableTreeNode child, int index) } Assert.assert(-1 != nativeRDFNode); RDFTreeNode childNode = (RDFTreeNode) child; - Assert.assert(-1 != childNode.getNativeRDFNode()); - int childNativeRDFNode = childNode.getNativeRDFNode(); - - // hook up the child to its native peer - nativeInsertElementAt(nativeWebShell, nativeRDFNode, - childNativeRDFNode, index); - + + if (childNode.isFolder()) { + Assert.assert(-1 == childNode.getNativeRDFNode()); + Assert.assert(null != childNode.getProperties()); + int childNativeRDFNode; + + // hook up the child to its native peer + childNativeRDFNode = nativeNewFolder(nativeWebShell, nativeRDFNode, + childNode.getProperties()); + + // hook up the child to its native peer + childNode.setNativeRDFNode(childNativeRDFNode); + } + else { + Assert.assert(-1 != childNode.getNativeRDFNode()); + int childNativeRDFNode = childNode.getNativeRDFNode(); + + // hook up the child to its native peer + nativeInsertElementAt(nativeWebShell, nativeRDFNode, + childNativeRDFNode, childNode.getProperties(), + index); + } + // hook up the child to its java parent childNode.setParent(this); @@ -251,6 +289,24 @@ public void setUserObject(Object object) } +// +// methods on this +// +public boolean isFolder() +{ + boolean result = false; + if (-1 == nativeRDFNode) { + if (null != getProperties()) { + result = (null != getProperties().get(BookmarkEntry.IS_FOLDER)); + } + } + else { + result = nativeIsContainer(nativeWebShell, getNativeRDFNode()); + } + return result; +} + + // // Native methods // @@ -272,7 +328,11 @@ public native int nativeGetIndex(int webShellPtr, int nativeRDFNode, public native String nativeToString(int webShellPtr, int nativeRDFNode); public native void nativeInsertElementAt(int webShellPtr, int parentNativeRDFNode, - int childNativeRDFNode, int index); + int childNativeRDFNode, + Properties childProps, int index); +public native int nativeNewFolder(int webShellPtr, int parentRDFNode, + Properties childProps); + // ----VERTIGO_TEST_START @@ -286,7 +346,7 @@ public static void main(String [] args) Log.setApplicationName("RDFTreeNode"); Log.setApplicationVersion("0.0"); - Log.setApplicationVersionDate("$Id: RDFTreeNode.java,v 1.2 2000-11-03 03:16:50 edburns%acm.org Exp $"); + Log.setApplicationVersionDate("$Id: RDFTreeNode.java,v 1.3 2001-04-02 21:13:59 ashuk%eng.sun.com Exp $"); } diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/WrapperFactoryImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/WrapperFactoryImpl.java index 88e689f1cd4..209633265df 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/WrapperFactoryImpl.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/WrapperFactoryImpl.java @@ -140,6 +140,10 @@ public Object newImpl(String interfaceName, result = new BookmarksImpl(this, browserControl); return result; } + if (BrowserControl.PREFERENCES_NAME == interfaceName) { + result = new PreferencesImpl(this, browserControl); + return result; + } } return result; @@ -222,7 +226,7 @@ public static void main(String [] args) WrapperFactory me = new WrapperFactoryImpl(); Log.setApplicationName("WrapperFactoryImpl"); Log.setApplicationVersion("0.0"); - Log.setApplicationVersionDate("$Id: WrapperFactoryImpl.java,v 1.3 2000-11-02 23:33:13 edburns%acm.org Exp $"); + Log.setApplicationVersionDate("$Id: WrapperFactoryImpl.java,v 1.4 2001-04-02 21:13:59 ashuk%eng.sun.com Exp $"); } diff --git a/mozilla/java/webclient/src_ie/CMyDialog.cpp b/mozilla/java/webclient/src_ie/CMyDialog.cpp index c6453bb2c87..6917477ef24 100644 --- a/mozilla/java/webclient/src_ie/CMyDialog.cpp +++ b/mozilla/java/webclient/src_ie/CMyDialog.cpp @@ -27,7 +27,7 @@ CMyDialog::CMyDialog(WebShellInitContext *yourInitContext) : m_initContext(yourI { // initialize the string constants (including properties keys) if (!util_StringConstantsAreInitialized()) { - util_InitStringConstants(m_initContext->env); + util_InitStringConstants(); } } diff --git a/mozilla/java/webclient/src_moz/BookmarksImpl.cpp b/mozilla/java/webclient/src_moz/BookmarksImpl.cpp index c20cc9d6c17..c367673fca9 100644 --- a/mozilla/java/webclient/src_moz/BookmarksImpl.cpp +++ b/mozilla/java/webclient/src_moz/BookmarksImpl.cpp @@ -22,10 +22,10 @@ #include "BookmarksImpl.h" +#include "RDFActionEvents.h" + #include "rdf_util.h" #include "ns_util.h" -#include "nsActions.h" - #include "nsCOMPtr.h" #include "nsISimpleEnumerator.h" diff --git a/mozilla/java/webclient/src_moz/CBrowserContainer.cpp b/mozilla/java/webclient/src_moz/CBrowserContainer.cpp index 9ea2a4f7d5f..c400f632470 100644 --- a/mozilla/java/webclient/src_moz/CBrowserContainer.cpp +++ b/mozilla/java/webclient/src_moz/CBrowserContainer.cpp @@ -24,8 +24,6 @@ * Louis-Philippe Gagnon */ - - #include #include "CBrowserContainer.h" #include "nsCWebBrowser.h" @@ -38,27 +36,27 @@ #include "dom_util.h" +#include "PromptActionEvents.h" + static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -#if defined(XP_UNIX) || defined(XP_MAC) || defined(XP_BEOS) - -#define WC_ITOA(intVal, buf, radix) sprintf(buf, "%d", intVal) -#else -#define WC_ITOA(intVal, buf, radix) itoa(intVal, buf, radix) -#endif +jobject gPromptProperties = nsnull; +PRInt32 CBrowserContainer::mInstanceCount = 0; CBrowserContainer::CBrowserContainer(nsIWebBrowser *pOwner, JNIEnv *env, WebShellInitContext *yourInitContext) : m_pOwner(pOwner), mJNIEnv(env), mInitContext(yourInitContext), - mDocTarget(nsnull), mMouseTarget(nsnull), mDomEventTarget(nsnull), - inverseDepth(-1), properties(nsnull), currentDOMEvent(nsnull) + mDocTarget(nsnull), mMouseTarget(nsnull), mPrompt(nsnull), + mDomEventTarget(nsnull), inverseDepth(-1), + properties(nsnull), currentDOMEvent(nsnull) { NS_INIT_REFCNT(); // initialize the string constants (including properties keys) if (!util_StringConstantsAreInitialized()) { - util_InitStringConstants(env); + util_InitStringConstants(); } + mInstanceCount++; } @@ -77,6 +75,7 @@ CBrowserContainer::~CBrowserContainer() } properties = nsnull; currentDOMEvent = nsnull; + mInstanceCount--; } @@ -171,7 +170,65 @@ NS_IMETHODIMP CBrowserContainer::PromptUsernameAndPassword(const PRUnichar *dial PRUnichar **pwd, PRBool *_retval) { - return NS_ERROR_NOT_IMPLEMENTED; + nsresult rv = NS_ERROR_FAILURE; + + // if the user hasn't given us a prompt, oh well + if (!mPrompt) { + return NS_OK; + } + + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + wsPromptUsernameAndPasswordEvent *actionEvent = nsnull; + + wsStringStruct strings[3] = { + {dialogTitle, nsnull}, + {text, nsnull}, + {passwordRealm, nsnull} }; + + rv = ::util_CreateJstringsFromUnichars(strings, 3); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: PromptUserNameAndPassword: can't create jstrings from Unichars"); + goto PUAP_CLEANUP; + } + + + // PENDING(edburns): uniformly apply checks for this throughout the + // code + PR_ASSERT(mInitContext); + PR_ASSERT(mInitContext->initComplete); + + // try to initialize the properties object for basic auth and cookies + if (!gPromptProperties) { + gPromptProperties = + ::util_CreatePropertiesObject(env, (jobject) + &(mInitContext->shareContext)); + if (!gPromptProperties) { + printf("Error: can't create properties object for authentitication"); + rv = NS_ERROR_NULL_POINTER; + goto PUAP_CLEANUP; + } + } + else { + ::util_ClearPropertiesObject(env, gPromptProperties, (jobject) + &(mInitContext->shareContext)); + } + + if (!(actionEvent = new wsPromptUsernameAndPasswordEvent(mInitContext, mPrompt, + strings, savePassword, + user, pwd, _retval))) { + ::util_ThrowExceptionToJava(env, "Exception: PromptUserNameAndPassword: can't create wsPromptUsernameAndPasswordEvent"); + rv = NS_ERROR_NULL_POINTER; + goto PUAP_CLEANUP; + } + // the out params to this method are set in wsPromptUsernameAndPasswordEvent::handleEvent() + ::util_PostSynchronousEvent(mInitContext, + (PLEvent *) *actionEvent); + rv = NS_OK; + PUAP_CLEANUP: + + ::util_DeleteJstringsFromUnichars(strings, 3); + + return rv; } /* boolean promptPassword (in wstring text, in wstring title, out wstring pwd); */ @@ -191,10 +248,101 @@ NS_IMETHODIMP CBrowserContainer::Select(const PRUnichar *inDialogTitle, const PR return NS_ERROR_NOT_IMPLEMENTED; } -/* void universalDialog (in wstring inTitleMessage, in wstring inDialogTitle, in wstring inMsg, in wstring inCheckboxMsg, in wstring inButton0Text, in wstring inButton1Text, in wstring inButton2Text, in wstring inButton3Text, in wstring inEditfield1Msg, in wstring inEditfield2Msg, inout wstring inoutEditfield1Value, inout wstring inoutEditfield2Value, in wstring inIConURL, inout boolean inoutCheckboxState, in PRInt32 inNumberButtons, in PRInt32 inNumberEditfields, in PRInt32 inEditField1Password, out PRInt32 outButtonPressed); */ -NS_IMETHODIMP CBrowserContainer::UniversalDialog(const PRUnichar *inTitleMessage, const PRUnichar *inDialogTitle, const PRUnichar *inMsg, const PRUnichar *inCheckboxMsg, const PRUnichar *inButton0Text, const PRUnichar *inButton1Text, const PRUnichar *inButton2Text, const PRUnichar *inButton3Text, const PRUnichar *inEditfield1Msg, const PRUnichar *inEditfield2Msg, PRUnichar **inoutEditfield1Value, PRUnichar **inoutEditfield2Value, const PRUnichar *inIConURL, PRBool *inoutCheckboxState, PRInt32 inNumberButtons, PRInt32 inNumberEditfields, PRInt32 inEditField1Password, PRInt32 *outButtonPressed) +NS_IMETHODIMP +CBrowserContainer::UniversalDialog(const PRUnichar *inTitleMessage, + const PRUnichar *inDialogTitle, + const PRUnichar *inMsg, + const PRUnichar *inCheckboxMsg, + const PRUnichar *inButton0Text, + const PRUnichar *inButton1Text, + const PRUnichar *inButton2Text, + const PRUnichar *inButton3Text, + const PRUnichar *inEditfield1Msg, + const PRUnichar *inEditfield2Msg, + PRUnichar **inoutEditfield1Value, + PRUnichar **inoutEditfield2Value, + const PRUnichar *inIConURL, + PRBool *inoutCheckboxState, + PRInt32 inNumberButtons, + PRInt32 inNumberEditfields, + PRInt32 inEditField1Password, + PRInt32 *outButtonPressed) { - return NS_ERROR_NOT_IMPLEMENTED; + printf("debug: edburns: CBrowserContainer::UniversalDialog()\n"); + nsresult rv = NS_ERROR_FAILURE; + + // if the user hasn't given us a prompt, oh well + if (!mPrompt) { + return NS_OK; + } + + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + wsPromptUniversalDialogEvent *actionEvent = nsnull; + + wsStringStruct strings[10] = { + {inTitleMessage, nsnull}, + {inDialogTitle, nsnull}, + {inMsg, nsnull}, + {inCheckboxMsg, nsnull}, + {inButton0Text, nsnull}, + {inButton1Text, nsnull}, + {inButton2Text, nsnull}, + {inButton3Text, nsnull}, + {inEditfield1Msg, nsnull}, + {inEditfield2Msg, nsnull} }; + + rv = ::util_CreateJstringsFromUnichars(strings, 10); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: UniversalDialog: can't create jstrings from Unichars"); + goto UD_CLEANUP; + } + + + // PENDING(edburns): uniformly apply checks for this throughout the + // code + PR_ASSERT(mInitContext); + PR_ASSERT(mInitContext->initComplete); + + // try to initialize the properties object for basic auth and cookies + if (!gPromptProperties) { + gPromptProperties = + ::util_CreatePropertiesObject(env, (jobject) + &(mInitContext->shareContext)); + if (!gPromptProperties) { + printf("Error: can't create properties object for authentitication"); + rv = NS_ERROR_NULL_POINTER; + goto UD_CLEANUP; + } + } + else { + ::util_ClearPropertiesObject(env, gPromptProperties, (jobject) + &(mInitContext->shareContext)); + } + + if (!(actionEvent = new wsPromptUniversalDialogEvent(mInitContext, + mPrompt, + strings, + inoutEditfield1Value, + inoutEditfield2Value, + inoutCheckboxState, + inNumberButtons, + inNumberEditfields, + inEditField1Password, + outButtonPressed))) { + ::util_ThrowExceptionToJava(env, "Exception: UniversalDialog: can't create wsPromptUniversalDialogEvent"); + rv = NS_ERROR_NULL_POINTER; + goto UD_CLEANUP; + } + // the out params to this method are set in wsPromptUsernameAndPasswordEvent::handleEvent() + ::util_PostSynchronousEvent(mInitContext, (PLEvent *) *actionEvent); + + rv = NS_OK; + UD_CLEANUP: + + ::util_DeleteJstringsFromUnichars(strings, 10); + + return rv; + } @@ -1020,6 +1168,24 @@ NS_IMETHODIMP CBrowserContainer::AddDocumentLoadListener(jobject target) return rv; } +NS_IMETHODIMP CBrowserContainer::SetPrompt(jobject target) +{ + nsresult rv = NS_OK; + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + + if (mPrompt) { + ::util_DeleteGlobalRef(env, mPrompt); + mPrompt = nsnull; + } + if (nsnull == (mPrompt = ::util_NewGlobalRef(env, target))) { + ::util_ThrowExceptionToJava(env, "Exception: Navigation.nativeSetPrompt(): can't create NewGlobalRef\n\tfor argument"); + rv = NS_ERROR_NULL_POINTER; + } + + return rv; +} + + NS_IMETHODIMP CBrowserContainer::RemoveMouseListener() { nsresult rv = NS_OK; @@ -1045,7 +1211,12 @@ NS_IMETHODIMP CBrowserContainer::RemoveDocumentLoadListener() return rv; } - +NS_IMETHODIMP CBrowserContainer::GetInstanceCount(PRInt32 *outCount) +{ + PR_ASSERT(outCount); + *outCount = mInstanceCount; + return NS_OK; +} NS_IMETHODIMP CBrowserContainer::RemoveAllListeners() { diff --git a/mozilla/java/webclient/src_moz/CBrowserContainer.h b/mozilla/java/webclient/src_moz/CBrowserContainer.h index f92a41fa2d5..0d3521f6f94 100644 --- a/mozilla/java/webclient/src_moz/CBrowserContainer.h +++ b/mozilla/java/webclient/src_moz/CBrowserContainer.h @@ -88,7 +88,9 @@ protected: WebShellInitContext *mInitContext; jobject mDocTarget; jobject mMouseTarget; + jobject mPrompt; nsCOMPtr mDomEventTarget; + static PRInt32 mInstanceCount; // // The following arguments are used in the takeActionOnNode method. diff --git a/mozilla/java/webclient/src_moz/CurrentPageActionEvents.cpp b/mozilla/java/webclient/src_moz/CurrentPageActionEvents.cpp new file mode 100644 index 00000000000..b0fba0ed2bb --- /dev/null +++ b/mozilla/java/webclient/src_moz/CurrentPageActionEvents.cpp @@ -0,0 +1,334 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Kirk Baker + * Ian Wilkinson + * Ashutosh Kulkarni + * Mark Lin + * Mark Goddard + * Ed Burns + * Jason Mawdsley + * Louis-Philippe Gagnon + */ + +/* + * CurrentPageActionEvents.cpp + */ + +#include "CurrentPageActionEvents.h" +#include "nsIDOMWindowInternal.h" +#include "nsIFindComponent.h" +#include "nsISearchContext.h" +#include "nsIDocShell.h" +#include "nsIContentViewer.h" +#include "nsIContentViewer.h" +#include "nsIContentViewerEdit.h" +#include "nsIInterfaceRequestor.h" + + +wsCopySelectionEvent::wsCopySelectionEvent(WebShellInitContext *yourInitContext) : + nsActionEvent(), + mInitContext(yourInitContext) +{ +} + +void * +wsCopySelectionEvent::handleEvent () +{ + void *result = nsnull; + + if (mInitContext) { + nsIContentViewer* contentViewer ; + nsresult rv = nsnull; + + rv = mInitContext->docShell->GetContentViewer(&contentViewer); + if (NS_FAILED(rv) || contentViewer==nsnull ) { + return (void *) rv; + } + + nsCOMPtr contentViewerEdit(do_QueryInterface(contentViewer)); + + rv = contentViewerEdit->CopySelection(); + result = (void *) rv; + } + return result; +} + +wsFindEvent::wsFindEvent(WebShellInitContext *yourInitContext) : + nsActionEvent(), + mInitContext(yourInitContext), + mSearchString(nsnull), + mForward(JNI_FALSE), + mMatchCase(JNI_FALSE) +{ +} + +wsFindEvent::wsFindEvent(WebShellInitContext *yourInitContext, jstring searchString, + jboolean forward, jboolean matchCase) : + nsActionEvent(), + mInitContext(yourInitContext), + mSearchString(searchString), + mForward(forward), + mMatchCase(matchCase) +{ +} + +void * +wsFindEvent::handleEvent () +{ + void *result = nsnull; + nsresult rv = NS_ERROR_FAILURE; + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + + if (mInitContext) { + //First get the FindComponent object + NS_WITH_SERVICE(nsIFindComponent, findComponent, NS_IFINDCOMPONENT_CONTRACTID, &rv); + + if (NS_FAILED(rv) || nsnull == findComponent) { + return (void *) rv; + } + + nsCOMPtr searchContext; + // get the nsISearchContext + // No seachString means this is Find, not FindNext. + if (mSearchString) { + + nsCOMPtr domWindowInternal; + if (mInitContext->docShell != nsnull) { + nsCOMPtr interfaceRequestor(do_QueryInterface(mInitContext->docShell)); + nsCOMPtr url = nsnull; + + rv = mInitContext->webNavigation->GetCurrentURI(getter_AddRefs(url)); + if (NS_FAILED(rv) || nsnull == url) { + return (void *) rv; + } + + if (interfaceRequestor != nsnull) { + rv = interfaceRequestor->GetInterface(NS_GET_IID(nsIDOMWindowInternal), + getter_AddRefs(domWindowInternal)); + if (NS_FAILED(rv) || nsnull == domWindowInternal) { + return (void *) rv; + } + } + else + { + mInitContext->initFailCode = kFindComponentError; + return (void *) rv; + } + } + else { + mInitContext->initFailCode = kFindComponentError; + return (void *) rv; + } + + // if we get here, we have a domWindowInternal + + rv = findComponent->CreateContext(domWindowInternal, nsnull, getter_AddRefs(searchContext)); + if (NS_FAILED(rv)) { + mInitContext->initFailCode = kSearchContextError; + return (void *) rv; + } + } + else { + // this is findNext + searchContext = mInitContext->searchContext; + } + if (!searchContext) { + mInitContext->initFailCode = kSearchContextError; + return (void *) NS_ERROR_FAILURE; + } + + nsCOMPtr srchcontext; + rv = searchContext->QueryInterface(NS_GET_IID(nsISearchContext), getter_AddRefs(srchcontext)); + if (NS_FAILED(rv)) { + mInitContext->initFailCode = kSearchContextError; + return (void *) rv; + } + + PRUnichar * aString; + srchcontext->GetSearchString(& aString); + + PRUnichar * srchString = nsnull; + if (mSearchString) { + srchString = (PRUnichar *) ::util_GetStringChars(env, mSearchString); + + // Check if String is NULL + if (nsnull == srchString) { + return (void *) NS_ERROR_NULL_POINTER; + } + + srchcontext->SetSearchString(srchString); + srchcontext->SetSearchBackwards(!mForward); + srchcontext->SetCaseSensitive(mMatchCase); + } + + PRBool found = PR_TRUE; + rv = findComponent->FindNext(srchcontext, &found); + result = (void *) rv; + if (mSearchString) { + ::util_ReleaseStringChars(env, mSearchString, srchString); + ::util_DeleteGlobalRef(env, mSearchString); + mSearchString = nsnull; + } + // Save in initContext struct for future findNextInPage calls + mInitContext->searchContext = srchcontext; + + } + return result; +} + +/* + * wsGetURLEvent + */ + +wsGetURLEvent::wsGetURLEvent(WebShellInitContext *yourInitContext) : + nsActionEvent(), + mInitContext(yourInitContext) +{ +} + + +void * +wsGetURLEvent::handleEvent () +{ + void *result = nsnull; + if (mInitContext) { + nsISHistory* mHistory; + nsresult rv; + PRInt32 currentIndex; + char *currentURL = nsnull; + + + rv = mInitContext->webNavigation->GetSessionHistory(&mHistory); + if (NS_FAILED(rv)) { + return (void *) rv; + } + + rv = mHistory->GetIndex(¤tIndex); + + if (NS_FAILED(rv)) { + return result; + } + + nsISHEntry * Entry; + rv = mHistory->GetEntryAtIndex(currentIndex, PR_FALSE, &Entry); + + if (NS_FAILED(rv)) { + return result; + } + + nsIURI * URI; + rv = Entry->GetURI(&URI); + + if (NS_FAILED(rv)) { + return result; + } + + rv = URI->GetSpec(¤tURL); + if (NS_FAILED(rv)) { + return result; + } + + result = (void *) currentURL; + } + return result; +} // handleEvent() + + +wsSelectAllEvent::wsSelectAllEvent(WebShellInitContext *yourInitContext) : + nsActionEvent(), + mInitContext(yourInitContext) +{ +} + +void * +wsSelectAllEvent::handleEvent () +{ + void *result = nsnull; + + if (mInitContext) { + nsIContentViewer* contentViewer; + nsresult rv = nsnull; + rv = mInitContext->docShell->GetContentViewer(&contentViewer); + if (NS_FAILED(rv) || contentViewer==nsnull) { + mInitContext->initFailCode = kGetContentViewerError; + return (void *) rv; + } + + nsCOMPtr contentViewerEdit(do_QueryInterface(contentViewer)); + + rv = contentViewerEdit->SelectAll(); + result = (void *) rv; + } + return result; +} + +/* PENDING(ashuk): remove this from here and in the motif directory +wsViewSourceEvent::wsViewSourceEvent(nsIDocShell* docShell, PRBool viewMode) : + nsActionEvent(), + mDocShell(docShell), + mViewMode(viewMode) +{ +} + +void * +wsViewSourceEvent::handleEvent () +{ + if(mDocShell) { + if(mViewMode) { + nsresult rv = mDocShell->SetViewMode(nsIDocShell::viewSource); + return (void *) rv; + } + else + { + nsresult rv = mDocShell->SetViewMode(nsIDocShell::viewNormal); + return (void *) rv; + } + } + return nsnull; +} +*/ + + +wsGetDOMEvent::wsGetDOMEvent(JNIEnv *yourEnv, jclass clz, + jmethodID yourID, jlong yourDoc) : + nsActionEvent(), + mEnv(yourEnv), + mClazz(clz), + mID(yourID), + mDoc(yourDoc) +{ +} + +void * +wsGetDOMEvent::handleEvent () +{ + + void * result = nsnull; + if (mEnv != nsnull && mClazz != nsnull && + mID != nsnull && mDoc != nsnull) + result = (void *) util_CallStaticObjectMethodlongArg(mEnv, mClazz, mID, mDoc); + + return result; +} + + + + + diff --git a/mozilla/java/webclient/src_moz/CurrentPageActionEvents.h b/mozilla/java/webclient/src_moz/CurrentPageActionEvents.h new file mode 100644 index 00000000000..2b0d8f23946 --- /dev/null +++ b/mozilla/java/webclient/src_moz/CurrentPageActionEvents.h @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Kirk Baker + * Ian Wilkinson + * Ashutosh Kulkarni + * Mark Lin + * Mark Goddard + * Ed Burns + */ + +/* + * nsActions.h + */ + +#ifndef CurrentPageActionEvents_h___ +#define CurrentPageActionEvents_h___ + +#include "nsActions.h" + +#include "nsIContentViewerEdit.h" +#include "nsIFindComponent.h" +#include "nsISearchContext.h" +#include "nsISHistory.h" +#include "ns_util.h" + +class wsCopySelectionEvent : public nsActionEvent { +public: + wsCopySelectionEvent(WebShellInitContext *yourInitContext); + void * handleEvent (void); + +protected: + WebShellInitContext *mInitContext; +}; + +class wsFindEvent : public nsActionEvent { +public: + wsFindEvent(WebShellInitContext *yourInitContext, jstring searchString, + jboolean forward, jboolean matchCase); + wsFindEvent(WebShellInitContext *yourInitContext); + void * handleEvent (void); + +protected: + WebShellInitContext *mInitContext; + jstring mSearchString; + jboolean mForward; + jboolean mMatchCase; +}; + +class wsGetURLEvent : public nsActionEvent { +public: + wsGetURLEvent (WebShellInitContext *yourInitContext); + void * handleEvent (void); +protected: + WebShellInitContext *mInitContext; +}; + +class wsSelectAllEvent : public nsActionEvent { +public: + wsSelectAllEvent(WebShellInitContext *yourInitContext); + void * handleEvent (void); + +protected: + WebShellInitContext *mInitContext; +}; + +/* PENDING(ashuk): remove this from here and in the motif directory +class wsViewSourceEvent : public nsActionEvent { +public: + wsViewSourceEvent (nsIDocShell * docShell, PRBool viewMode); + void * handleEvent (void); + +protected: + nsIDocShell * mDocShell; + PRBool mViewMode; +}; +*/ + +class wsGetDOMEvent : public nsActionEvent { +public: + wsGetDOMEvent (JNIEnv *env, jclass clz, jmethodID yourID, jlong yourDoc); + void * handleEvent (void); + +protected: + JNIEnv * mEnv; + jclass mClazz; + jmethodID mID; + jlong mDoc; +}; + +#endif /* CurrentPageActionEvents_h___ */ + + +// EOF diff --git a/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp b/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp index 5428b408920..d7cb660a9a8 100644 --- a/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp +++ b/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp @@ -31,56 +31,22 @@ #include "CurrentPageImpl.h" +#include "CurrentPageActionEvents.h" + #include "ns_util.h" #include "rdf_util.h" -#include "nsActions.h" -#include "nsLayoutCID.h" #include "nsCRT.h" -#include "nsIPresShell.h" -#include "nsCOMPtr.h" -#include "nsISupports.h" -#include "nsIFindComponent.h" -#include "nsISearchContext.h" -#include "nsIDocShell.h" -#include "nsIDocumentViewer.h" -#include "nsIDocument.h" -#include "nsIDOMHTMLDocument.h" -#include "nsIDOMHTMLElement.h" -#include "nsIDOMNode.h" -#include "nsIDOMRange.h" -#include "nsIContentViewer.h" -#include "nsIServiceManager.h" -#include "nsIContentViewer.h" -#include "nsIContentViewerEdit.h" -#include "nsIDOMWindowInternal.h" -#include "nsIScriptGlobalObject.h" -#include "nsIInterfaceRequestor.h" - -static NS_DEFINE_CID(kCDOMRangeCID, NS_RANGE_CID); -static NS_DEFINE_IID(kIDOMHTMLDocumentIID, NS_IDOMHTMLDOCUMENT_IID); -static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID); - JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeCopyCurrentSelectionToSystemClipboard (JNIEnv *env, jobject obj, jint webShellPtr) { WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; - nsIContentViewer* contentViewer ; - nsresult rv = nsnull; - rv = initContext->docShell->GetContentViewer(&contentViewer); - if (NS_FAILED(rv) || contentViewer==nsnull ) { - initContext->initFailCode = kGetContentViewerError; - ::util_ThrowExceptionToJava(env, "Exception: cant get ContentViewer from DocShell"); - return; - } - nsCOMPtr contentViewerEdit(do_QueryInterface(contentViewer)); - if (initContext->initComplete) { - wsCopySelectionEvent * actionEvent = new wsCopySelectionEvent(contentViewerEdit); - PLEvent * event = (PLEvent*) *actionEvent; - ::util_PostEvent(initContext, event); + wsCopySelectionEvent * actionEvent = new wsCopySelectionEvent(initContext); + PLEvent * event = (PLEvent*) *actionEvent; + ::util_PostEvent(initContext, event); } } @@ -97,92 +63,20 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImp WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; - //First get the FindComponent object - nsresult rv; - - NS_WITH_SERVICE(nsIFindComponent, findComponent, NS_IFINDCOMPONENT_CONTRACTID, &rv); - - if (NS_FAILED(rv) || nsnull == findComponent) { - initContext->initFailCode = kFindComponentError; - ::util_ThrowExceptionToJava(env, "Exception: can't access FindComponent Service"); - return; - } - - nsCOMPtr domWindowInternal; - if (initContext->docShell != nsnull) { - nsCOMPtr interfaceRequestor(do_QueryInterface(initContext->docShell)); - nsCOMPtr url = nsnull; - - rv = initContext->webNavigation->GetCurrentURI(getter_AddRefs(url)); - if (NS_FAILED(rv) || nsnull == url) { - ::util_ThrowExceptionToJava(env, "Exception: NULL URL passed to Find call"); - return; - } - - if (interfaceRequestor != nsnull) { - rv = interfaceRequestor->GetInterface(NS_GET_IID(nsIDOMWindowInternal), getter_AddRefs(domWindowInternal)); - if (NS_FAILED(rv) || nsnull == domWindowInternal) { - initContext->initFailCode = kGetDOMWindowError; - ::util_ThrowExceptionToJava(env, "Exception: cant get DOMWindow from DocShell"); - return; - } - } - else - { - initContext->initFailCode = kFindComponentError; - ::util_ThrowExceptionToJava(env, "Exception: cant get InterfaceRequestor from DocShell"); - return; - } - } - else - { - initContext->initFailCode = kFindComponentError; - ::util_ThrowExceptionToJava(env, "Exception: DocShell is not initialized"); - return; - } - - nsCOMPtr searchContext; - rv = findComponent->CreateContext(domWindowInternal, nsnull, getter_AddRefs(searchContext)); - if (NS_FAILED(rv)) { - initContext->initFailCode = kSearchContextError; - ::util_ThrowExceptionToJava(env, "Exception: can't create SearchContext for Find"); - return; - } - - nsCOMPtr srchcontext; - rv = searchContext->QueryInterface(NS_GET_IID(nsISearchContext), getter_AddRefs(srchcontext)); - if (NS_FAILED(rv)) { - initContext->initFailCode = kSearchContextError; - ::util_ThrowExceptionToJava(env, "Exception: can't create SearchContext for Find"); - return; - } - - PRUnichar * aString; - srchcontext->GetSearchString(& aString); - - PRUnichar * srchString = (PRUnichar *) ::util_GetStringChars(env, searchString); - - // Check if String is NULL - if (nsnull == srchString) { - ::util_ThrowExceptionToJava(env, "Exception: NULL String passed to Find call"); + jstring searchStringGlobalRef = (jstring) ::util_NewGlobalRef(env, searchString); + if (!searchStringGlobalRef) { + initContext->initFailCode = kFindComponentError; + ::util_ThrowExceptionToJava(env, "Exception: Can't create global ref for search string"); return; } - srchcontext->SetSearchString(srchString); - srchcontext->SetSearchBackwards(!forward); - srchcontext->SetCaseSensitive(matchCase); - - // Pass searchContext to findComponent for the actual find call - PRBool found = PR_TRUE; - if (initContext->initComplete) { - wsFindEvent * actionEvent = new wsFindEvent(findComponent, srchcontext); + wsFindEvent * actionEvent = new wsFindEvent(initContext, searchStringGlobalRef, + forward, matchCase); PLEvent * event = (PLEvent*) *actionEvent; ::util_PostEvent(initContext, event); } - // Save in initContext struct for future findNextInPage calls - initContext->searchContext = srchcontext; } @@ -194,40 +88,20 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImp * Signature: (Z)V */ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeFindNextInPage -(JNIEnv *env, jobject obj, jint webShellPtr, jboolean forward) +(JNIEnv *env, jobject obj, jint webShellPtr) { WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; //First get the FindComponent object - nsresult rv; - NS_WITH_SERVICE(nsIFindComponent, findComponent, NS_IFINDCOMPONENT_CONTRACTID, &rv); - if (NS_FAILED(rv)) { - initContext->initFailCode = kFindComponentError; - ::util_ThrowExceptionToJava(env, "Exception: can't access FindComponent Service"); - return; - } - - // Get the searchContext from the initContext struct - nsCOMPtr searchContext = initContext->searchContext; - - if (nsnull == searchContext) { - initContext->initFailCode = kSearchContextError; - ::util_ThrowExceptionToJava(env, "Exception: NULL SearchContext received for FindNext"); - return; - } - - // Set the forward flag as per input parameter - searchContext->SetSearchBackwards(!forward); - // Pass searchContext to findComponent for the actual find call PRBool found = PR_TRUE; - if (initContext->initComplete) { - wsFindEvent * actionEvent = new wsFindEvent(findComponent, searchContext); + if (initContext->initComplete && initContext->searchContext) { + wsFindEvent * actionEvent = new wsFindEvent(initContext); PLEvent * event = (PLEvent*) *actionEvent; ::util_PostEvent(initContext, event); - } + } } @@ -252,22 +126,11 @@ JNIEXPORT jstring JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPage } if (initContext->initComplete) { - // nsISessionHistory *yourHistory; - nsISHistory* yourHistory; - nsresult rv; - - rv = initContext->webNavigation->GetSessionHistory(&yourHistory); - - if (NS_FAILED(rv)) { - ::util_ThrowExceptionToJava(env, "Exception: can't get SessionHistory from webNavigation"); - return urlString; - } - - wsGetURLEvent * actionEvent = new wsGetURLEvent(yourHistory); + wsGetURLEvent * actionEvent = new wsGetURLEvent(initContext); PLEvent * event = (PLEvent*) *actionEvent; - + charResult = (char *) ::util_PostSynchronousEvent(initContext, event); - + if (charResult != nsnull) { urlString = ::util_NewStringUTF(env, (const char *) charResult); } @@ -275,10 +138,10 @@ JNIEXPORT jstring JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPage ::util_ThrowExceptionToJava(env, "raptorWebShellGetURL Exception: GetURL() returned NULL"); return nsnull; } - + nsCRT::free(charResult); } - + return urlString; } @@ -310,7 +173,11 @@ JNIEXPORT jobject JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPage ::util_ThrowExceptionToJava(env, "Exception: Can't get DOM Node."); return nsnull; } - result = env->CallStaticObjectMethod(clazz, mid, documentLong); + + wsGetDOMEvent * actionEvent = new wsGetDOMEvent(env, clazz, mid, documentLong); + PLEvent * event = (PLEvent*) *actionEvent; + result = (jobject) ::util_PostSynchronousEvent(initContext, event); + return result; } @@ -321,6 +188,8 @@ JNIEXPORT jobject JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPage * Method: nativeGetSource * Signature: ()Ljava/lang/String; */ + +/* PENDING(ashuk): remove this from here and in the motif directory JNIEXPORT jstring JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeGetSource (JNIEnv * env, jobject jobj) { @@ -328,12 +197,16 @@ JNIEXPORT jstring JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPage return result; } +*/ + /* * Class: org_mozilla_webclient_wrapper_0005fnative_CurrentPageImpl * Method: nativeGetSourceBytes * Signature: ()[B */ + +/* PENDING(ashuk): remove this from here and in the motif directory JNIEXPORT jbyteArray JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeGetSourceBytes (JNIEnv * env, jobject jobj, jint webShellPtr, jboolean viewMode) { @@ -346,12 +219,14 @@ JNIEXPORT jbyteArray JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentP new wsViewSourceEvent(initContext->docShell, ((JNI_TRUE == viewMode)? PR_TRUE : PR_FALSE)); PLEvent * event = (PLEvent*) *actionEvent; - ::util_PostSynchronousEvent(initContext, event); + ::util_PostEvent(initContext, event); } jbyteArray result = nsnull; return result; } +*/ + /* * Class: org_mozilla_webclient_wrapper_0005fnative_CurrentPageImpl @@ -376,21 +251,10 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImp JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeSelectAll (JNIEnv * env, jobject obj, jint webShellPtr) { - WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; - nsIContentViewer* contentViewer ; - nsresult rv = nsnull; - rv = initContext->docShell->GetContentViewer(&contentViewer); - if (NS_FAILED(rv) || contentViewer==nsnull) { - initContext->initFailCode = kGetContentViewerError; - ::util_ThrowExceptionToJava(env, "Exception: cant get ContentViewer from DocShell"); - return; - } - - nsCOMPtr contentViewerEdit(do_QueryInterface(contentViewer)); - + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; if (initContext->initComplete) { - wsSelectAllEvent * actionEvent = new wsSelectAllEvent(contentViewerEdit); - PLEvent * event = (PLEvent*) *actionEvent; - ::util_PostEvent(initContext, event); - } + wsSelectAllEvent * actionEvent = new wsSelectAllEvent(initContext); + PLEvent * event = (PLEvent*) *actionEvent; + ::util_PostEvent(initContext, event); + } } diff --git a/mozilla/java/webclient/src_moz/HistoryActionEvents.cpp b/mozilla/java/webclient/src_moz/HistoryActionEvents.cpp new file mode 100644 index 00000000000..b9098bc8618 --- /dev/null +++ b/mozilla/java/webclient/src_moz/HistoryActionEvents.cpp @@ -0,0 +1,282 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Kirk Baker + * Ian Wilkinson + * Ashutosh Kulkarni + * Mark Lin + * Mark Goddard + * Ed Burns + * Jason Mawdsley + * Louis-Philippe Gagnon + */ + +/* + * HistoryActionEvents.cpp + */ + +#include "HistoryActionEvents.h" +#include "ns_util.h" + +/* + * wsCanBackEvent + */ + +wsCanBackEvent::wsCanBackEvent(nsIWebNavigation* webNavigation) : + nsActionEvent(), + mWebNavigation(webNavigation) +{ + +} + +void * +wsCanBackEvent::handleEvent () +{ + void *result = nsnull; + if (mWebNavigation) { + nsresult rv; + PRBool canGoBack; + + rv = mWebNavigation->GetCanGoBack(&canGoBack); + + if (NS_FAILED(rv)) { + return result; + } + + result = (void *)canGoBack; + } + return result; +} // handleEvent() + +/* + * wsCanForwardEvent + */ + +wsCanForwardEvent::wsCanForwardEvent(nsIWebNavigation* webNavigation) : + nsActionEvent(), + mWebNavigation(webNavigation) +{ + +} + + +void * +wsCanForwardEvent::handleEvent () +{ + void *result = nsnull; + if (mWebNavigation) { + nsresult rv; + PRBool canGoForward; + + rv = mWebNavigation->GetCanGoForward(&canGoForward); + + if (NS_FAILED(rv)) { + return result; + } + + result = (void *)canGoForward; + + } + return result; +} // handleEvent() + + +/* + * wsBackEvent + */ + +wsBackEvent::wsBackEvent(nsIWebNavigation* webNavigation) : + nsActionEvent(), + mWebNavigation(webNavigation) +{ +} + + +void * +wsBackEvent::handleEvent () +{ + void *result = nsnull; + if (mWebNavigation) { + nsresult rv = mWebNavigation->GoBack(); + + result = (void *) rv; + } + return result; +} // handleEvent() + + + +/* + * wsForwardEvent + */ + +wsForwardEvent::wsForwardEvent(nsIWebNavigation* webNavigation) : + nsActionEvent(), + mWebNavigation(webNavigation) +{ +} + + +void * +wsForwardEvent::handleEvent () +{ + void *result = nsnull; + if (mWebNavigation) { + + nsresult rv = mWebNavigation->GoForward(); + result = (void *) rv; + } + return result; +} // handleEvent() + + +/* + * wsGoToEvent + */ + +wsGoToEvent::wsGoToEvent(nsIWebNavigation* webNavigation, PRInt32 historyIndex) : + nsActionEvent(), + mWebNavigation(webNavigation), mHistoryIndex(historyIndex) +{ +} + + +void * +wsGoToEvent::handleEvent () +{ + void *result = nsnull; + nsresult rv = nsnull; + if (mWebNavigation) { + nsresult rv = mWebNavigation->GotoIndex(mHistoryIndex); + result = (void *) rv; + } + return result; +} // handleEvent() + + + +/* + * wsGetHistoryLengthEvent + */ + +wsGetHistoryLengthEvent::wsGetHistoryLengthEvent(WebShellInitContext + *yourInitContext) : + nsActionEvent(), + mInitContext(yourInitContext) +{ +} + + +void * +wsGetHistoryLengthEvent::handleEvent () +{ + void *result = nsnull; + + if (mInitContext) { + nsISHistory* sHistory; + PRInt32 historyLength = 0; + nsresult rv = mInitContext->webNavigation-> + GetSessionHistory(&sHistory); + + if ( NS_FAILED(rv)) { + return result; + } + rv = sHistory->GetCount(&historyLength); + result = (void *) historyLength; + } + return result; +} // handleEvent() + + +/* + * wsGetHistoryIndexEvent + */ + +wsGetHistoryIndexEvent::wsGetHistoryIndexEvent(WebShellInitContext *yourInitContext) : + nsActionEvent(), + mInitContext(yourInitContext) +{ +} + + +void * +wsGetHistoryIndexEvent::handleEvent () +{ + void *result = nsnull; + if (mInitContext) { + PRInt32 historyIndex = 0; + nsISHistory* sHistory; + nsresult rv = mInitContext->webNavigation->GetSessionHistory(&sHistory); + + rv = sHistory->GetIndex(&historyIndex); + result = (void *) historyIndex; + } + return result; +} // handleEvent() + + + + +/* + * wsGetURLForIndexEvent + */ + +wsGetURLForIndexEvent::wsGetURLForIndexEvent(WebShellInitContext *yourInitContext, + PRInt32 historyIndex) : + nsActionEvent(), + mInitContext(yourInitContext), + mHistoryIndex(historyIndex) +{ +} + + +void * +wsGetURLForIndexEvent::handleEvent () +{ + void *result = nsnull; + if (mInitContext) { + nsresult rv; + nsISHistory* sHistory; + rv = mInitContext->webNavigation->GetSessionHistory(&sHistory); + char *indexURL = nsnull; + + nsISHEntry * Entry; + rv = sHistory->GetEntryAtIndex(mHistoryIndex, PR_FALSE, &Entry); + if (NS_FAILED(rv)) { + return result; + } + + nsIURI * URI; + rv = Entry->GetURI(&URI); + + if (NS_FAILED(rv)) { + return result; + } + + rv = URI->GetSpec(&indexURL); + if (NS_FAILED(rv)) { + return result; + } + + result = (void *) indexURL; + } + return result; +} // handleEvent() + + diff --git a/mozilla/java/webclient/src_moz/HistoryActionEvents.h b/mozilla/java/webclient/src_moz/HistoryActionEvents.h new file mode 100644 index 00000000000..2aa7d7ea0d5 --- /dev/null +++ b/mozilla/java/webclient/src_moz/HistoryActionEvents.h @@ -0,0 +1,117 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Kirk Baker + * Ian Wilkinson + * Ashutosh Kulkarni + * Mark Lin + * Mark Goddard + * Ed Burns + */ + +/* + * nsActions.h + */ + +#ifndef HistoryActionEvents_h___ +#define HistoryActionEvents_h___ + +#include "nsActions.h" +#include "nsIWebNavigation.h" +#include "nsISHistory.h" + +struct WebShellInitContext; + +class wsCanBackEvent : public nsActionEvent { +public: + wsCanBackEvent (nsIWebNavigation* webNavigation); + void * handleEvent (void); +protected: + nsIWebNavigation * mWebNavigation; +}; + +class wsCanForwardEvent : public nsActionEvent { +public: + wsCanForwardEvent(nsIWebNavigation* webNavigation); + void * handleEvent (void); +protected: + nsIWebNavigation * mWebNavigation; +}; + +class wsBackEvent : public nsActionEvent { +public: + wsBackEvent (nsIWebNavigation* webNavigation); + void * handleEvent (void); + +protected: + nsIWebNavigation * mWebNavigation; +}; + +class wsForwardEvent : public nsActionEvent { +public: + wsForwardEvent (nsIWebNavigation* webNavigation); + void * handleEvent (void); + +protected: + nsIWebNavigation * mWebNavigation; +}; + +class wsGoToEvent : public nsActionEvent { +public: + wsGoToEvent (nsIWebNavigation* webNavigation, + PRInt32 historyIndex); + void * handleEvent (void); + +protected: + nsIWebNavigation * mWebNavigation; + PRInt32 mHistoryIndex; +}; + +class wsGetHistoryLengthEvent : public nsActionEvent { +public: + wsGetHistoryLengthEvent(WebShellInitContext *yourInitContext); + void * handleEvent (void); + +protected: + WebShellInitContext *mInitContext; +}; + +class wsGetHistoryIndexEvent : public nsActionEvent { +public: + wsGetHistoryIndexEvent (WebShellInitContext *yourInitContext); + void * handleEvent (void); +protected: + WebShellInitContext *mInitContext; +}; + +class wsGetURLForIndexEvent : public nsActionEvent { +public: + wsGetURLForIndexEvent(WebShellInitContext *yourInitContext, + PRInt32 historyIndex); + void * handleEvent (void); + +protected: + WebShellInitContext *mInitContext; + PRInt32 mHistoryIndex; +}; + +#endif /* HistoryActionEvents_h___ */ + + +// EOF diff --git a/mozilla/java/webclient/src_moz/HistoryImpl.cpp b/mozilla/java/webclient/src_moz/HistoryImpl.cpp index 124ab337726..df6c93b8188 100644 --- a/mozilla/java/webclient/src_moz/HistoryImpl.cpp +++ b/mozilla/java/webclient/src_moz/HistoryImpl.cpp @@ -27,9 +27,10 @@ #include "HistoryImpl.h" +#include "HistoryActionEvents.h" + #include "ns_util.h" -#include "nsActions.h" JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_HistoryImpl_nativeBack @@ -50,7 +51,7 @@ Java_org_mozilla_webclient_wrapper_1native_HistoryImpl_nativeBack new wsBackEvent(initContext->webNavigation); PLEvent * event = (PLEvent*) *actionEvent; - ::util_PostSynchronousEvent(initContext, event); + ::util_PostEvent(initContext, event); } return; @@ -119,7 +120,7 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_HistoryImpl_na new wsForwardEvent(initContext->webNavigation); PLEvent * event = (PLEvent*) *actionEvent; - ::util_PostSynchronousEvent(initContext, event); + ::util_PostEvent(initContext, event); } return; @@ -195,16 +196,8 @@ Java_org_mozilla_webclient_wrapper_1native_HistoryImpl_nativeGetCurrentHistoryIn } if (initContext->initComplete) { - nsISHistory* sHistory; - nsresult rv = initContext->webNavigation->GetSessionHistory(&sHistory); - - if ( NS_FAILED(rv)) { - ::util_ThrowExceptionToJava(env, "Exception: couldn't get History for passing to raptorWebShellGetHistoryIndex"); - return result; - } - wsGetHistoryIndexEvent * actionEvent = - new wsGetHistoryIndexEvent(sHistory); + new wsGetHistoryIndexEvent(initContext); PLEvent * event = (PLEvent*) *actionEvent; voidResult = ::util_PostSynchronousEvent(initContext, event); @@ -221,7 +214,6 @@ Java_org_mozilla_webclient_wrapper_1native_HistoryImpl_nativeSetCurrentHistoryIn { JNIEnv * pEnv = env; jobject jobj = obj; - void * voidResult = nsnull; WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; @@ -235,7 +227,7 @@ Java_org_mozilla_webclient_wrapper_1native_HistoryImpl_nativeSetCurrentHistoryIn new wsGoToEvent(initContext->webNavigation, historyIndex); PLEvent * event = (PLEvent*) *actionEvent; - voidResult = ::util_PostSynchronousEvent(initContext, event); + ::util_PostEvent(initContext, event); } return; @@ -258,16 +250,8 @@ Java_org_mozilla_webclient_wrapper_1native_HistoryImpl_nativeGetHistoryLength } if (initContext->initComplete) { - nsISHistory* sHistory; - nsresult rv = initContext->webNavigation->GetSessionHistory(&sHistory); - - if ( NS_FAILED(rv)) { - ::util_ThrowExceptionToJava(env, "Exception: couldn't get History for passing to raptorWebShellGetHistoryIndex"); - return result; - } - wsGetHistoryLengthEvent * actionEvent = - new wsGetHistoryLengthEvent(sHistory); + new wsGetHistoryLengthEvent(initContext); PLEvent * event = (PLEvent*) *actionEvent; voidResult = ::util_PostSynchronousEvent(initContext, event); @@ -294,30 +278,21 @@ JNIEXPORT jstring JNICALL Java_org_mozilla_webclient_wrapper_1native_HistoryImpl } if (initContext->initComplete) { - nsISHistory* sHistory; - nsresult rv = initContext->webNavigation->GetSessionHistory(&sHistory); - - if ( NS_FAILED(rv)) { - ::util_ThrowExceptionToJava(env, "Exception: couldn't get History for passing to raptorWebShellGetHistoryIndex"); - return nsnull; - } - - wsGetURLForIndexEvent * actionEvent = - new wsGetURLForIndexEvent(initContext->sHistory, - historyIndex); - PLEvent * event = (PLEvent*) *actionEvent; - - charResult = (char *) ::util_PostSynchronousEvent(initContext, event); - - if (charResult != nsnull) { - urlString = ::util_NewStringUTF(env, (const char *) charResult); - } - else { - ::util_ThrowExceptionToJava(env, "raptorWebShellGetURL Exception: GetURL() returned nsnull"); - return nsnull; - } - - nsCRT::free(charResult); + wsGetURLForIndexEvent * actionEvent = + new wsGetURLForIndexEvent(initContext, historyIndex); + PLEvent * event = (PLEvent*) *actionEvent; + + charResult = (char *) ::util_PostSynchronousEvent(initContext, event); + + if (charResult != nsnull) { + urlString = ::util_NewStringUTF(env, (const char *) charResult); + } + else { + ::util_ThrowExceptionToJava(env, "raptorWebShellGetURL Exception: GetURL() returned nsnull"); + return nsnull; + } + + nsCRT::free(charResult); } return urlString; diff --git a/mozilla/java/webclient/src_moz/InputStreamShim.cpp b/mozilla/java/webclient/src_moz/InputStreamShim.cpp new file mode 100644 index 00000000000..5a7f96b7a44 --- /dev/null +++ b/mozilla/java/webclient/src_moz/InputStreamShim.cpp @@ -0,0 +1,414 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 Communicator client code, released + * March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998-1999 Netscape Communications Corporation. All + * Rights Reserved. + * + */ + +#include "InputStreamShim.h" + +#include "jni_util.h" + +#include "nsCRT.h" +#include "prlock.h" +#include "prlog.h" +#include "prthread.h" + +static const PRInt32 buffer_increment = 1024; +static const PRInt32 do_close_code = -524; + +InputStreamShim::InputStreamShim(jobject yourJavaStreamRef, + PRInt32 yourContentLength) : + mJavaStream(yourJavaStreamRef), mContentLength(yourContentLength), + mBuffer(nsnull), mBufferLength(0), mCountFromJava(0), + mCountFromMozilla(0), mAvailable(0), mAvailableForMozilla(0), mNumRead(0), + mDoClose(PR_FALSE), mDidClose(PR_FALSE), mLock(nsnull) +{ + NS_INIT_REFCNT(); + mLock = PR_NewLock(); + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); +} + +InputStreamShim::~InputStreamShim() +{ + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + ::util_DeleteGlobalRef(env, mJavaStream); + mJavaStream = nsnull; + + mContentLength = -1; + + delete [] mBuffer; + mBuffer = nsnull; + mBufferLength = 0; + + mAvailable = 0; + mAvailableForMozilla = 0; + mNumRead = 0; + mDoClose = PR_TRUE; + mDidClose = PR_TRUE; + PR_DestroyLock(mLock); + mLock = nsnull; +} + +//NS_IMPL_ISUPPORTS(InputStreamShim, NS_GET_IID(nsIInputStream)) +NS_IMETHODIMP_(nsrefcnt) InputStreamShim::AddRef(void) +{ + NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt"); + NS_ASSERT_OWNINGTHREAD(InputStreamShim); + ++mRefCnt; + NS_LOG_ADDREF(this, mRefCnt, "InputStreamShim", sizeof(*this)); + return mRefCnt; +} + +NS_IMETHODIMP_(nsrefcnt) InputStreamShim::Release(void) +{ + NS_PRECONDITION(0 != mRefCnt, "dup release"); + NS_ASSERT_OWNINGTHREAD(_class); + --mRefCnt; + NS_LOG_RELEASE(this, mRefCnt, "InputStreamShim"); + if (mRefCnt == 0) { + mRefCnt = 1; /* stabilize */ + NS_DELETEXPCOM(this); + return 0; + } + return mRefCnt; +} + +NS_IMPL_QUERY_INTERFACE(InputStreamShim, NS_GET_IID(nsIInputStream)) + +nsresult InputStreamShim::doReadFromJava() +{ + nsresult rv = NS_ERROR_FAILURE; + PR_ASSERT(mLock); + + PR_Lock(mLock); + + // first, see how much data is available + if (NS_FAILED(rv = doAvailable())) { + goto DRFJ_CLEANUP; + } + + // if we have all our data, give the error appropriate result + if (0 == mAvailable || + (0 != mCountFromJava && + (((PRUint32)mContentLength) == mCountFromJava))) { + mDoClose = PR_TRUE; + doClose(); + rv = NS_ERROR_NOT_AVAILABLE; + goto DRFJ_CLEANUP; + } + + if (NS_FAILED(doRead())) { + rv = NS_ERROR_FAILURE; + goto DRFJ_CLEANUP; + } + rv = NS_OK; + + // finally, do another check for available bytes + if (NS_FAILED(doAvailable())) { + rv = NS_ERROR_FAILURE; + goto DRFJ_CLEANUP; + } + if (0 == mAvailable || + (0 != mCountFromJava && + (((PRUint32)mContentLength) == mCountFromJava))) { + mDoClose = PR_TRUE; + doClose(); + rv = NS_ERROR_NOT_AVAILABLE; + goto DRFJ_CLEANUP; + } + + DRFJ_CLEANUP: + + PR_Unlock(mLock); + return rv; +} + +// +// Helper methods called from doReadFromJava +// + +nsresult +InputStreamShim::doAvailable(void) +{ + nsresult rv = NS_ERROR_FAILURE; + if (mDidClose) { + mAvailable = 0; + return NS_OK; + } +#ifdef BAL_INTERFACE +#else + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + jclass streamClass = nsnull; + jmethodID mid = nsnull; + + if (!(streamClass = env->GetObjectClass(mJavaStream))) { + return rv; + } + if (!(mid = env->GetMethodID(streamClass, "available", "()I"))) { + return rv; + } + mAvailable = (PRUint32) env->CallIntMethod(mJavaStream, mid); + if (env->ExceptionOccurred()) { + env->ExceptionDescribe(); + env->ExceptionClear(); + return NS_ERROR_FAILURE; + } + rv = NS_OK; +#endif + + return rv; +} + +nsresult +InputStreamShim::doRead(void) +{ + nsresult rv = NS_ERROR_FAILURE; + if (mDoClose) { + doClose(); + return NS_ERROR_NOT_AVAILABLE; + } + + PR_ASSERT(0 != mAvailable); + + // if we don't have a buffer, create one + if (!mBuffer) { + if (0 < mContentLength) { + mBuffer = new char[mContentLength]; + mBufferLength = mContentLength; + } + else { + + // make sure we allocate enough buffer to store what is + // currently available. + if (mAvailable < buffer_increment) { + mBufferLength = buffer_increment; + } + else { + PRInt32 bufLengthCalc = mAvailable / buffer_increment; + mBufferLength = buffer_increment + + (bufLengthCalc * buffer_increment); + } + mBuffer = new char[mBufferLength]; + + } + if (!mBuffer) { + mBufferLength = 0; + return NS_ERROR_FAILURE; + } + } + else { + + // See if we need to grow our buffer. If what we have plus what + // we're about to get is greater than the current buffer size... + + if (mBufferLength < (mCountFromJava + mAvailable)) { + // create the new buffer + char *tBuffer = new char[mBufferLength + buffer_increment]; + if (!tBuffer) { + return NS_ERROR_FAILURE; + } + // copy the old buffer into the new buffer + nsCRT::memcpy(tBuffer, mBuffer, mBufferLength); + // delete the old buffer + delete [] mBuffer; + // update mBuffer; + mBuffer = tBuffer; + // update our bufferLength + mBufferLength += buffer_increment; + } + } + +#ifdef BAL_INTERFACE +#else + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + jmethodID mid = nsnull; + jclass streamClass = nsnull; + jbyteArray javaByteArray = nsnull; + + if (!(streamClass = env->GetObjectClass(mJavaStream))) { + return rv; + } + if (!(mid = env->GetMethodID(streamClass, "read", "([BII)I"))) { + return rv; + } + + if (!(javaByteArray = env->NewByteArray((jsize) mAvailable))) { + return rv; + } + + mNumRead = env->CallIntMethod(mJavaStream, mid, javaByteArray, (jint) 0, + (jint) mAvailable); + if (env->ExceptionOccurred()) { + env->ExceptionDescribe(); + env->ExceptionClear(); + return NS_ERROR_FAILURE; + } + if (0 < mNumRead) { + // copy the bytes from java into our buffer + env->GetByteArrayRegion(javaByteArray, 0, (jint) mNumRead, + (jbyte *) (mBuffer + mCountFromJava)); + mCountFromJava += mNumRead; + mAvailableForMozilla = mCountFromJava - mCountFromMozilla; + } + rv = NS_OK; +#endif + return rv; +} + +nsresult +InputStreamShim::doClose(void) +{ + nsresult rv = NS_ERROR_FAILURE; + PR_ASSERT(mDoClose); + if (mDidClose) { + return NS_OK; + } + +#ifdef BAL_INTERFACE +#else + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + jclass streamClass = nsnull; + jmethodID mid = nsnull; + + if (!(streamClass = env->GetObjectClass(mJavaStream))) { + return rv; + } + if (!(mid = env->GetMethodID(streamClass, "close", "()V"))) { + return rv; + } + env->CallVoidMethod(mJavaStream, mid); + if (env->ExceptionOccurred()) { + env->ExceptionDescribe(); + env->ExceptionClear(); + return NS_ERROR_FAILURE; + } + rv = NS_OK; +#endif + mDidClose = PR_TRUE; + return rv; +} + +// +// nsIInputStream methods +// + +NS_IMETHODIMP +InputStreamShim::Available(PRUint32* aResult) +{ + nsresult rv = NS_ERROR_FAILURE; + if (!aResult) { + return NS_ERROR_NULL_POINTER; + } + PR_ASSERT(mLock); + PR_Lock(mLock); + *aResult = mAvailableForMozilla; + rv = NS_OK; + PR_Unlock(mLock); + + return rv; +} + +NS_IMETHODIMP +InputStreamShim::Close() +{ + nsresult rv = NS_ERROR_FAILURE; + PR_ASSERT(mLock); + PR_Lock(mLock); + mDoClose = PR_TRUE; + rv = NS_OK; + PR_Unlock(mLock); + + return rv; +} + +NS_IMETHODIMP +InputStreamShim::Read(char* aBuffer, PRUint32 aCount, PRUint32 *aNumRead) +{ + nsresult rv = NS_ERROR_FAILURE; + if (!aBuffer || !aNumRead) { + return NS_ERROR_NULL_POINTER; + } + *aNumRead = 0; + PR_ASSERT(mLock); + PR_ASSERT(mCountFromMozilla <= mCountFromJava); + + PR_Lock(mLock); + + // wait for java to load the buffer with some data + do { + if (mAvailableForMozilla == 0) { + PR_Unlock(mLock); + PR_Sleep(PR_INTERVAL_MIN); + PR_Lock(mLock); + } + else { + break; + } + } while ((!mDidClose) && (-1 != mNumRead)); + + if (mAvailableForMozilla) { + if (aCount <= (mCountFromJava - mCountFromMozilla)) { + // what she's asking for is less than or equal to what we have + nsCRT::memcpy(aBuffer, (mBuffer + mCountFromMozilla), aCount); + mCountFromMozilla += aCount; + *aNumRead = aCount; + } + else { + // what she's asking for is more than what we have + nsCRT::memcpy(aBuffer, (mBuffer + mCountFromMozilla), + (mCountFromJava - mCountFromMozilla)); + *aNumRead = (mCountFromJava - mCountFromMozilla); + + mCountFromMozilla += (mCountFromJava - mCountFromMozilla); + } + mAvailableForMozilla -= *aNumRead; + } + + rv = NS_OK; + PR_Unlock(mLock); + + return rv; +} + +NS_IMETHODIMP +InputStreamShim::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("ReadSegments"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +InputStreamShim::GetNonBlocking(PRBool *aNonBlocking) +{ + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +InputStreamShim::GetObserver(nsIInputStreamObserver * *aObserver) +{ + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +InputStreamShim::SetObserver(nsIInputStreamObserver * aObserver) +{ + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} diff --git a/mozilla/java/webclient/src_moz/InputStreamShim.h b/mozilla/java/webclient/src_moz/InputStreamShim.h new file mode 100644 index 00000000000..5539d62f999 --- /dev/null +++ b/mozilla/java/webclient/src_moz/InputStreamShim.h @@ -0,0 +1,179 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 Communicator client code, released + * March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998-1999 Netscape Communications Corporation. All + * Rights Reserved. + * + */ + +#ifndef InputStreamShim_h +#define InputStreamShim_h + +#include "nsIInputStream.h" + +#include + +class InputStreamShimActionEvent; +struct PRLock; + +class InputStreamShim : public nsIInputStream +{ +public: + InputStreamShim(jobject yourJavaStreamRef, + PRInt32 contentLength); + virtual ~InputStreamShim(); + + /** + + * Called on NativeEventThread from + * wsLoadFromStreamEvent::handleEvent() + + * When called, this method will read as up to mContentLength data + * from the Java input stream. Each read will update the number of + * bytes available on the stream. + + * if the ivar mDoClose's value is PR_TRUE, the java + * InputStream should be closed. + + * @return NS_ERROR_NOT_AVAILABLE when there is no more data. + + * @return NS_OK when there is more data + + * @return NS_ERROR_FAILURE when there has been an unrecoverable + * error + + + */ + + nsresult doReadFromJava(void); + PRInt32 getContentLength() const { return mContentLength; }; + +private: + + // called from doReadFromJava. These methods assume they execute + // within PR_Lock(mLock) + + nsresult doAvailable(void); + nsresult doRead(void); + nsresult doClose(void); + +private: + // nsISupports methods + NS_DECL_ISUPPORTS + + // nsIInputStream methods + NS_DECL_NSIINPUTSTREAM + +protected: + + /** + + * A global jobject reference for the java InputStream + + * MUST be ::util_deleteGlobalRef'd in destructor. + + */ + + jobject mJavaStream; + + /** + + * the number of bytes we expect to read. + + */ + + PRInt32 mContentLength; + + + /** + + * a dynamically allocated buffer, written by NativeEventThread + * calling out doReadFromJava(), read by Mozilla calling our Read(). + + * deleting this buffer signifies the java InputStream should be + * closed. + + * MUST be deallocated in the destructor. + + */ + + char *mBuffer; + + /** + + * the length of the buffer + + */ + + PRUint32 mBufferLength; + + + /** + + * Running sum of the total number of bytes read so far from java. + + */ + + PRUint32 mCountFromJava; + + /** + + * Running sum of the total number of bytes read so far by mozilla + + */ + + PRUint32 mCountFromMozilla; + + /** + + * The number of bytes available on the java InputStream + + */ + + PRUint32 mAvailable; + + /** + + * The number of bytes available in the buffer that haven't yet been + * read from Mozilla. + + */ + + PRUint32 mAvailableForMozilla; + + /** + + * The number of bytes read on the last read from the java + * InputStream + + */ + + PRInt32 mNumRead; + + PRBool mDoClose; + + PRBool mDidClose; + + /** + + * Provides mutex + + */ + + PRLock *mLock; +}; + +#endif // InputStreamShim_h diff --git a/mozilla/java/webclient/src_moz/Makefile.in b/mozilla/java/webclient/src_moz/Makefile.in index 154c13b5a6b..942c0613fd5 100644 --- a/mozilla/java/webclient/src_moz/Makefile.in +++ b/mozilla/java/webclient/src_moz/Makefile.in @@ -22,6 +22,30 @@ topsrcdir = $(DEPTH) srcdir = $(topsrcdir)/java/webclient/src_moz VPATH = $(topsrcdir)/java/webclient/src_moz +# IMPORTANT: on Linux, if building webclient with a non-debug mozilla +# tree, the libwidget_gtk.so binary produced will not work with +# webclient. Namely, the symbol handle_gdk_event__FP9_GdkEventPv will +# be defined locally, not globaly, as is required. For the webclient +# 1.0 release, we're going to bundle a libwidget_gtk.so with the xpi. +# If you want to do a non-debug build of your own, you must make sure +# yor libwidget_gtk.so is linked without these options: + +# -DNDEBUG -DTRIMMED + +# and with these options + +# -DNDEBUG -DDEBUG_edburns + +# If your libwidget_gtk.so has this symbol: + +# 0003b2d0 T handle_gdk_event__FP9_GdkEventPv + +# with the capital T, you're ok. The version of libwidget_gtk.so used +# in the webclient 1.0 bundle is available at: +# . +# to build WEBCLIENT_PACKAGE_BUILD on linux, grab libwidget_gtk.so from +# the above URL and put it in the same directory as this file. + # We don't need to build the stubs in the BAL case. ifeq ($(BAL_INTERFACE),) DIRS = motif @@ -45,14 +69,25 @@ CPPSRCS = \ rdf_util.cpp \ BookmarksImpl.cpp \ CBrowserContainer.cpp \ + PromptActionEvents.cpp \ CurrentPageImpl.cpp \ + CurrentPageActionEvents.cpp \ HistoryImpl.cpp \ + HistoryActionEvents.cpp \ ISupportsPeer.cpp \ NativeEventThread.cpp \ + NativeEventThreadActionEvents.cpp \ NavigationImpl.cpp \ + NavigationActionEvents.cpp \ + InputStreamShim.cpp \ RDFEnumeration.cpp \ RDFTreeNode.cpp \ + RDFActionEvents.cpp \ + wsRDFObserver.cpp \ WindowControlImpl.cpp \ + WindowControlActionEvents.cpp \ + PreferencesImpl.cpp \ + PreferencesActionEvents.cpp \ WrapperFactoryImpl.cpp \ motif/MotifBrowserControlCanvas.cpp \ motif/gtkmozilla.cpp \ @@ -103,10 +138,51 @@ PACKAGE_LIB=$(PACKAGE_DIR)/lib PACKAGE_EXAMPLE=$(PACKAGE_DIR)/example endif # PACKAGE_BUILD -clobber_all:: +ifneq ($(WEBCLIENT_PACKAGE_BUILD),) +PACKAGE_VER = 1_0 +PACKAGE_DIR = $(DIST)/javadev +PACKAGE_LIB = $(PACKAGE_DIR)/lib +PACKAGE_EXAMPLE = $(PACKAGE_DIR)/example +endif # WEBCLIENT_PACKAGE_BUILD + + buildRunems: ifeq ($(BAL_INTERFACE),) +ifneq ($(WEBCLIENT_PACKAGE_BUILD),) + @echo +++ Creating Commercial Package. Use runem to run the test browser. + @echo +++ Checking for special libwidget_gtk.so. +ifeq ($(OS_ARCH),Linux) + @if test ! -f libwidget_gtk.so ; then echo "You don't have libwidget_gtk.so, see the IMPORTANT section in Makefile.in!!!"; stopbuild; else echo "Found libwidget_gtk.so, continuing."; fi ; + chmod 775 libwidget_gtk.so + cp -f libwidget_gtk.so $(PACKAGE_LIB) +endif + rm -f runem_unix_commercial + @echo "#!/bin/csh -x" >> runem_unix_commercial + @echo ln -s -f "$$"MOZILLA_FIVE_HOME/javadev/lib/libjavadom.so "$$"MOZILLA_FIVE_HOME/components/libjavadom.so >> runem_unix_commercial + @echo setenv CLASSPATH "$$"MOZILLA_FIVE_HOME/javadev/lib/$(LIBRARY_NAME)_$(PACKAGE_VER).jar>> runem_unix_commercial + @echo setenv LD_LIBRARY_PATH "$$"MOZILLA_FIVE_HOME'"':'"'"$$"MOZILLA_FIVE_HOME/components'"':'"'"$$"MOZILLA_FIVE_HOME/javadev/lib'"':'"'"$$"LD_LIBRARY_PATH>> runem_unix_commercial + @echo "$$"JDKHOME/bin/java org.mozilla.webclient.test.EmbeddedMozilla "$$"MOZILLA_FIVE_HOME "$$"1 >> runem_unix_commercial + mkdir -p $(PACKAGE_EXAMPLE) + chmod 775 $(PACKAGE_EXAMPLE) + cp -f $(DIST)/bin/lib$(LIBRARY_NAME).so $(PACKAGE_LIB) + cp -f $(DIST)/bin/lib$(LIBRARY_NAME)stub.so $(PACKAGE_LIB) + cp -f $(DIST)/bin/libjavadomjni.so $(PACKAGE_LIB) + cp -f $(DIST)/bin/components/libjavadom.so $(PACKAGE_LIB) + chmod 775 $(PACKAGE_LIB)/lib$(LIBRARY_NAME).so + chmod 775 $(PACKAGE_LIB)/lib$(LIBRARY_NAME)stub.so + chmod 775 $(PACKAGE_LIB)/libjavadomjni.so + chmod 775 $(PACKAGE_LIB)/libjavadom.so + cp -f $(DEPTH)/java/webclient/src_moz/runem_unix_commercial $(PACKAGE_EXAMPLE)/runem + + chmod 775 $(PACKAGE_EXAMPLE)/runem + cp -f $(DEPTH)/java/webclient/src_moz/install_win32.js $(DIST)/install.js +ifeq ($(OS_ARCH),Linux) + cd $(DIST); zip -r $(LIBRARY_NAME)_$(PACKAGE_VER)_linux.xpi install.js javadev +else + cd $(DIST); zip -r $(LIBRARY_NAME)_$(PACKAGE_VER)_solaris.xpi install.js javadev +endif +endif ifeq ($(PACKAGE_BUILD),) @echo +++ Creating runem. Use this to run the test browser. rm -f runem @@ -123,6 +199,12 @@ else cp $(topsrcdir)/dist/bin/libplugletjni.so $(PACKAGE_LIB)/libplugletjni.so.$(VERSION_NUMBER) cp $(topsrcdir)/dist/bin/components/libpluglet.so $(PACKAGE_LIB)/libpluglet.so.$(VERSION_NUMBER) cp $(topsrcdir)/dist/bin/components/libjavadom.so $(PACKAGE_LIB)/libjavadom.so.$(VERSION_NUMBER) + cp $(topsrcdir)/dist/bin/components/libbcorb.so $(PACKAGE_LIB)/libbcorb.so.$(VERSION_NUMBER) + cp $(topsrcdir)/dist/bin/components/libbcjavastubs.so $(PACKAGE_LIB)/libbcjavastubs.so.$(VERSION_NUMBER) + cp $(topsrcdir)/dist/bin/components/libjavaloader.so $(PACKAGE_LIB)/libjavaloader.so.$(VERSION_NUMBER) + cp $(topsrcdir)/dist/bin/components/libjavaSample.so $(PACKAGE_LIB)/libjavaSample.so.$(VERSION_NUMBER) + cp $(topsrcdir)/dist/bin/components/libbcTest.so $(PACKAGE_LIB)/libbcTest.so.$(VERSION_NUMBER) + cp $(topsrcdir)/dist/bin/components/libbcxpcomstubs.so $(PACKAGE_LIB)/libbcxpcomstubs.so.$(VERSION_NUMBER) rm -f $(topsrcdir)/dist/bin/libwebclientstub.so rm -f $(topsrcdir)/dist/lib/libwebclientstub.so rm -f $(topsrcdir)/dist/bin/libwebclient.so @@ -136,6 +218,12 @@ else rm -f $(topsrcdir)/dist/lib/components/libpluglet.so rm -f $(topsrcdir)/dist/bin/components/libjavadom.so rm -f $(topsrcdir)/dist/lib/components/libjavadom.so + rm -f $(topsrcdir)/dist/bin/components/libbcorb.so + rm -f $(topsrcdir)/dist/bin/components/libbcjavastubs.so + rm -f $(topsrcdir)/dist/bin/components/libjavaloader.so + rm -f $(topsrcdir)/dist/bin/components/libjavaSample.so + rm -f $(topsrcdir)/dist/bin/components/libbcTest.so + rm -f $(topsrcdir)/dist/bin/components/libbcxpcomstubs.so chmod 555 $(PACKAGE_LIB)/libwebclientstub.so.$(VERSION_NUMBER) chmod 555 $(PACKAGE_LIB)/libwebclient.so.$(VERSION_NUMBER) chmod 555 $(PACKAGE_LIB)/libwc_share.a.$(VERSION_NUMBER) @@ -143,6 +231,18 @@ else chmod 555 $(PACKAGE_LIB)/libplugletjni.so.$(VERSION_NUMBER) chmod 555 $(PACKAGE_LIB)/libpluglet.so.$(VERSION_NUMBER) chmod 555 $(PACKAGE_LIB)/libjavadom.so.$(VERSION_NUMBER) + chmod 555 $(PACKAGE_LIB)/libbcorb.so.$(VERSION_NUMBER) + chmod 555 $(PACKAGE_LIB)/libbcjavastubs.so.$(VERSION_NUMBER) + chmod 555 $(PACKAGE_LIB)/libjavaloader.so.$(VERSION_NUMBER) + chmod 555 $(PACKAGE_LIB)/libjavaSample.so.$(VERSION_NUMBER) + chmod 555 $(PACKAGE_LIB)/libbcTest.so.$(VERSION_NUMBER) + chmod 555 $(PACKAGE_LIB)/libbcxpcomstubs.so.$(VERSION_NUMBER) + if test ! -d $(PACKAGE_LIB)/libbcorb.so ; then ln -s libbcorb.so.$(VERSION_NUMBER) $(PACKAGE_LIB)/libbcorb.so ; else true ; fi ; + if test ! -d $(PACKAGE_LIB)/libbcjavastubs.so ; then ln -s libbcjavastubs.so.$(VERSION_NUMBER) $(PACKAGE_LIB)/libbcjavastubs.so ; else true ; fi ; + if test ! -d $(PACKAGE_LIB)/libjavaloader.so ; then ln -s libjavaloader.so.$(VERSION_NUMBER) $(PACKAGE_LIB)/libjavaloader.so ; else true ; fi ; + if test ! -d $(PACKAGE_LIB)/libjavaSample.so ; then ln -s libjavaSample.so.$(VERSION_NUMBER) $(PACKAGE_LIB)/libjavaSample.so ; else true ; fi ; + if test ! -d $(PACKAGE_LIB)/libbcTest.so ; then ln -s libbcTest.so.$(VERSION_NUMBER) $(PACKAGE_LIB)/libbcTest.so ; else true ; fi ; + if test ! -d $(PACKAGE_LIB)/libbcxpcomstubs.so ; then ln -s libbcxpcomstubs.so.$(VERSION_NUMBER) $(PACKAGE_LIB)/libbcxpcomstubs.so ; else true ; fi ; if test ! -d $(PACKAGE_LIB)/libwc_share.a ; then ln -s libwc_share.a.$(VERSION_NUMBER) $(PACKAGE_LIB)/libwc_share.a ; else true ; fi ; if test ! -d $(PACKAGE_LIB)/libwebclientstub.so ; then ln -s libwebclientstub.so.$(VERSION_NUMBER) $(PACKAGE_LIB)/libwebclientstub.so ; else true ; fi ; if test ! -d $(PACKAGE_LIB)/libwebclient.so ; then ln -s libwebclient.so.$(VERSION_NUMBER) $(PACKAGE_LIB)/libwebclient.so ; else true ; fi ; @@ -158,3 +258,11 @@ endif # BAL_INTERFACE install:: buildRunems + +clobber_all:: clobber +ifneq ($(WEBCLIENT_PACKAGE_BUILD),) + rm -f runem_unix_commercial + rm -rf $(DIST)/javadev + rm -f $(DIST)/$(LIBRARY_NAME)_$(PACKAGE_VER)*.xpi + rm -f $(DIST)/install.js +endif diff --git a/mozilla/java/webclient/src_moz/Makefile.win b/mozilla/java/webclient/src_moz/Makefile.win index 8ac36631d45..c4fe3b4c21b 100644 --- a/mozilla/java/webclient/src_moz/Makefile.win +++ b/mozilla/java/webclient/src_moz/Makefile.win @@ -34,15 +34,26 @@ OBJS = \ .\$(OBJDIR)\dom_util.obj \ .\$(OBJDIR)\nsActions.obj \ .\$(OBJDIR)\CurrentPageImpl.obj \ + .\$(OBJDIR)\CurrentPageActionEvents.obj \ .\$(OBJDIR)\HistoryImpl.obj \ + .\$(OBJDIR)\HistoryActionEvents.obj \ .\$(OBJDIR)\BookmarksImpl.obj \ .\$(OBJDIR)\WrapperFactoryImpl.obj \ .\$(OBJDIR)\WindowControlImpl.obj \ + .\$(OBJDIR)\WindowControlActionEvents.obj \ + .\$(OBJDIR)\InputStreamShim.obj \ .\$(OBJDIR)\NavigationImpl.obj \ + .\$(OBJDIR)\NavigationActionEvents.obj \ .\$(OBJDIR)\CBrowserContainer.obj \ + .\$(OBJDIR)\PromptActionEvents.obj \ + .\$(OBJDIR)\NativeEventThreadActionEvents.obj \ .\$(OBJDIR)\NativeEventThread.obj \ .\$(OBJDIR)\RDFEnumeration.obj \ .\$(OBJDIR)\RDFTreeNode.obj \ + .\$(OBJDIR)\RDFActionEvents.obj \ + .\$(OBJDIR)\wsRDFObserver.obj \ + .\$(OBJDIR)\PreferencesImpl.obj \ + .\$(OBJDIR)\PreferencesActionEvents.obj \ .\$(OBJDIR)\ISupportsPeer.obj \ $(NULL) @@ -120,21 +131,68 @@ INCS = \ # generate the jni header +!ifdef PACKAGE_BUILD +PERCENT=% +PACKAGE_VER = 1_0 +#PENDING(edburns): jar name should be defined elewhere! +WEBCLIENT_JAR_NAME=webclient_$(PACKAGE_VER).jar +PACKAGE_DIR = $(DIST)\javadev +PACKAGE_LIB = $(PACKAGE_DIR)\lib +PACKAGE_EXAMPLE = $(PACKAGE_DIR)\example +!endif + +PATH_SAVE=$(PATH) + buildRunems: + $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin + $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib !ifdef BAL_INTERFACE !else +!ifndef PACKAGE_BUILD @echo +++ Creating runem.bat. Use this to run the test browser. rm -f runem.bat @echo $(PERL) ..\src_share\runem.pl org.mozilla.webclient.test.EmbeddedMozilla $(DEPTH) %1% >> runem.bat +!else + @echo +++ Creating Commercial Package. Use runem.bat to run the test browser. + @rm -f runem_win_commercial.bat + @set MOZILLA_FIVE_HOME= + @set PATH= + @set JDKHOME= + @echo copy %MOZILLA_FIVE_HOME%\javadev\lib\javadom.dll %MOZILLA_FIVE_HOME%\components>> runem_win_commercial.bat + @echo set PATH=%MOZILLA_FIVE_HOME%\javadev\lib;%MOZILLA_FIVE_HOME%;%MOZILLA_FIVE_HOME%\components;%PATH%>> runem_win_commercial.bat + @echo set CLASSPATH=%MOZILLA_FIVE_HOME%\javadev\lib\$(WEBCLIENT_JAR_NAME)>> runem_win_commercial.bat + @echo %JDKHOME%\bin\java org.mozilla.webclient.test.EmbeddedMozilla %MOZILLA_FIVE_HOME% %1% >> runem_win_commercial.bat + @set PATH=$(PATH_SAVE) + -mkdir $(PACKAGE_EXAMPLE) + chmod 775 $(PACKAGE_EXAMPLE) + cp $(DIST)\bin\webclient.dll $(PACKAGE_LIB)\webclient.dll + cp $(DIST)\bin\javadomjni.dll $(PACKAGE_LIB)\javadomjni.dll + cp $(DIST)\bin\components\javadom.dll $(PACKAGE_LIB)\javadom.dll + chmod 775 $(PACKAGE_LIB)\webclient.dll + chmod 775 $(PACKAGE_LIB)\javadomjni.dll + chmod 775 $(PACKAGE_LIB)\javadom.dll + cp -f $(DEPTH)\java\webclient\src_moz\runem_win_commercial.bat $(PACKAGE_EXAMPLE)\runem.bat + chmod 775 $(PACKAGE_EXAMPLE)\runem.bat + cp -f $(DEPTH)\java\webclient\src_moz\install_win32.js $(DIST)\install.js + cd $(DIST) + zip -r $(DLLNAME)_$(PACKAGE_VER)_win32.xpi install.js javadev +!endif !endif -install:: $(DLL) buildRunems - $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin - $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib +install:: $(DLL) buildRunems + clobber_all:: clobber +!ifdef PACKAGE_BUILD + rm -rf $(DIST)\javadev + rm -f $(DIST)\$(DLLNAME)_$(PACKAGE_VER).xpi + rm -f $(DIST)\install.js +!endif clobber:: rm -f $(DIST)\bin\$(DLLNAME).dll +!ifdef PACKAGE_BUILD + rm -f runem_win_commercial.bat +!else rm -f runem.bat - +!endif diff --git a/mozilla/java/webclient/src_moz/NativeEventThread.cpp b/mozilla/java/webclient/src_moz/NativeEventThread.cpp index 47f30a0896f..ca07a32ba0a 100644 --- a/mozilla/java/webclient/src_moz/NativeEventThread.cpp +++ b/mozilla/java/webclient/src_moz/NativeEventThread.cpp @@ -53,6 +53,7 @@ #include "nsIEventQueueService.h" // for PLEventQueue #include "nsRepository.h" #include "nsIServiceManager.h" // for do_GetService +#include "nsISHistory.h" // for sHistory #include "nsIPref.h" // for preferences #include "nsIThread.h" // for PRThread #include "nsIDocShell.h" @@ -62,7 +63,7 @@ #include "nsIEventQueueService.h" #include "nsIThread.h" //nsIWebShell is included in ns_util.h - +#include "NativeEventThreadActionEvents.h" #include "prlog.h" // for PR_ASSERT @@ -70,6 +71,12 @@ #include #include "gdksuperwin.h" #include "gtkmozarea.h" + +extern "C" { + static int wc_x_error (Display *display, + XErrorEvent *error); +} + #endif static NS_DEFINE_IID(kWebShellCID, NS_WEB_SHELL_CID); @@ -117,6 +124,29 @@ extern const char * gBinDir; // defined in WrapperFactoryImpl.cpp // Local functions // +#ifdef XP_UNIX +static int +wc_x_error (Display *display, + XErrorEvent *error) +{ + if (error->error_code) + { + char buf[64]; + + XGetErrorText (display, error->error_code, buf, 63); + + fprintf (stderr, "Webclient-Gdk-ERROR **: %s\n serial %ld error_code %d request_code %d minor_code %d\n", + buf, + error->serial, + error->error_code, + error->request_code, + error->minor_code); + } + + return 0; +} +#endif + /** * Called from InitMozillaStuff(). @@ -127,7 +157,7 @@ int processEventLoop(WebShellInitContext * initContext); /** - * Called from Java nativeInitialize to create the webshell, history + * Called from Java nativeInitialize to create the webshell * and other mozilla things, then start the event loop. */ @@ -138,11 +168,11 @@ nsresult InitMozillaStuff (WebShellInitContext * arg); // Local data // -nsISHistory *gHistory = nsnull; nsIComponentManager *gComponentManager = nsnull; static PRBool gFirstTime = PR_TRUE; - - +PLEventQueue * gActionQueue = nsnull; +PRThread * gEmbeddedThread = nsnull; +nsISHistory *gHistory = nsnull; char * errorMessages[] = { "No Error", @@ -199,7 +229,12 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThr "NULL webShellPtr passed to nativeProcessEvents."); return; } - processEventLoop(initContext); + + void* threadId = PR_GetCurrentThread(); + if (threadId == (void *) gEmbeddedThread) { + // printf("--------- Thread ID ---- %p\n",gEmbeddedThread); + processEventLoop(initContext); + } } /** @@ -378,20 +413,20 @@ int processEventLoop(WebShellInitContext * initContext) #endif ::PR_Sleep(PR_INTERVAL_NO_WAIT); - if ((initContext->initComplete) && (initContext->actionQueue)) { + if ((initContext->initComplete) && (gActionQueue)) { - PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + PL_ENTER_EVENT_QUEUE_MONITOR(gActionQueue); - if (::PL_EventAvailable(initContext->actionQueue)) { + if (::PL_EventAvailable(gActionQueue)) { - PLEvent * event = ::PL_GetEvent(initContext->actionQueue); + PLEvent * event = ::PL_GetEvent(gActionQueue); if (event != nsnull) { ::PL_HandleEvent(event); } } - PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + PL_EXIT_EVENT_QUEUE_MONITOR(gActionQueue); } if (initContext->stopThread) { @@ -437,13 +472,13 @@ void DoMozInitialization(WebShellInitContext * initContext) nsresult rv = nsnull; JNIEnv * env = initContext->env; const char * BinDir = gBinDir; - + rv = NS_NewLocalFile(BinDir, PR_TRUE, &pathFile); if (NS_FAILED(rv)) { ::util_ThrowExceptionToJava(env, "call to NS_NewLocalFile failed."); return; } - + // It is vitally important to call NS_InitEmbedding before calling // anything else. NS_InitEmbedding(pathFile, nsnull); @@ -458,7 +493,7 @@ void DoMozInitialization(WebShellInitContext * initContext) PR_SetLogFile(webclientLogFile); // If this fails, it just goes to stdout/stderr } - + gComponentManager->RegisterComponentLib(kSHistoryCID, nsnull, nsnull, APPSHELL_DLL, PR_FALSE, PR_FALSE); @@ -469,10 +504,40 @@ void DoMozInitialization(WebShellInitContext * initContext) ::util_ThrowExceptionToJava(env, "Can't get the profile manager."); return; } - char *argv[1]; + PRInt32 numProfiles=0; + rv = profile->GetProfileCount(&numProfiles); + char *argv[3]; + int i, argc = 0; argv[0] = strdup(gBinDir); - rv = cmdLine->Initialize(1, argv); - nsCRT::free(argv[0]); + if (numProfiles > 1) { + PRUnichar * Names; + rv = profile->GetProfileList(&Names); + // PENDING(edburns): fix for 70656. Really we should have a way + // for the embedding app to specify which profile to use. + // For now we just get the name of the first profile. + argv[1] = strdup("-p"); + char * temp = new char[100]; // de-allocated in following for loop + for (i = 0; i<100; i++) { + if ((char) Names[i] != ',') + temp[i] = (char) Names[i]; + else { + temp[i] = '\0'; + break; + } + } + nsCRT::free(Names); + argv[2] = temp; + argc = 3; + printf("debug: edburns: argv[1]: %s argv[2]: %s\n", argv[1], + argv[2]); + } + else { + argc = 1; + } + rv = cmdLine->Initialize(argc, argv); + for (i = 0; i < argc; i++) { + nsCRT::free(argv[i]); + } if (NS_FAILED(rv)) { ::util_ThrowExceptionToJava(env, "Can't initialize nsICmdLineService."); return; @@ -495,69 +560,70 @@ nsresult InitMozillaStuff (WebShellInitContext * initContext) PR_ASSERT(gComponentManager); - nsCOMPtr - aEventQService = do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID); + if (gFirstTime) { + printf ("\n\nCreating Event Queue \n\n"); + nsCOMPtr + aEventQService = do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID); - // if we get here, we know that aEventQService is not null. - if (!aEventQService) { - rv = NS_ERROR_FAILURE; - return rv; - } + // if we get here, we know that aEventQService is not null. + if (!aEventQService) { + rv = NS_ERROR_FAILURE; + return rv; + } //TODO Add tracing from nspr. #if DEBUG_RAPTOR_CANVAS - if (prLogModuleInfo) { - PR_LOG(prLogModuleInfo, 3, - ("InitMozillaStuff(%lx): Create the Event Queue for the UI thread...\n", - initContext)); - } + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, ("InitMozillaStuff(%lx): Create the Event Queue for the UI thread...\n", initContext)); + } #endif - // Create the Event Queue for the UI thread... - if (!aEventQService) { - initContext->initFailCode = kEventQueueError; - return rv; - } + // Create the Event Queue for the UI thread... + if (!aEventQService) { + initContext->initFailCode = kEventQueueError; + return rv; + } - // Create the event queue. - rv = aEventQService->CreateThreadEventQueue(); - initContext->embeddedThread = PR_GetCurrentThread(); + // Create the event queue. + rv = aEventQService->CreateThreadEventQueue(); + gEmbeddedThread = PR_GetCurrentThread(); - // Create the action queue - if (initContext->embeddedThread) { - - if (initContext->actionQueue == nsnull) { - printf("InitMozillaStuff(%lx): Create the action queue\n", initContext); + // Create the action queue + if (gEmbeddedThread) { - // We need to do something different for Unix - nsIEventQueue * EQueue = nsnull; + if (gActionQueue == nsnull) { + printf("InitMozillaStuff(%lx): Create the action queue\n", initContext); - rv = aEventQService->GetThreadEventQueue(initContext->embeddedThread, + // We need to do something different for Unix + nsIEventQueue * EQueue = nsnull; + + rv = aEventQService->GetThreadEventQueue(gEmbeddedThread, &EQueue); - if (NS_FAILED(rv)) { - initContext->initFailCode = kCreateWebShellError; - return rv; - } + if (NS_FAILED(rv)) { + initContext->initFailCode = kCreateWebShellError; + return rv; + } #ifdef XP_UNIX - gdk_input_add(EQueue->GetEventQueueSelectFD(), - GDK_INPUT_READ, - event_processor_callback, - EQueue); + gdk_input_add(EQueue->GetEventQueueSelectFD(), + GDK_INPUT_READ, + event_processor_callback, + EQueue); #endif - PLEventQueue * plEventQueue = nsnull; + PLEventQueue * plEventQueue = nsnull; - EQueue->GetPLEventQueue(&plEventQueue); - initContext->actionQueue = plEventQueue; + EQueue->GetPLEventQueue(&plEventQueue); + gActionQueue = plEventQueue; + } + } + else { + initContext->initFailCode = kCreateWebShellError; + return NS_ERROR_UNEXPECTED; } } - else { - initContext->initFailCode = kCreateWebShellError; - return NS_ERROR_UNEXPECTED; - } - + // Setup Prefs obj and read default prefs if (gFirstTime) { nsCOMPtr mPrefs(do_GetService(kPrefCID)); @@ -570,7 +636,9 @@ nsresult InitMozillaStuff (WebShellInitContext * initContext) gFirstTime = PR_FALSE; } PRBool allowPlugins = PR_TRUE; - + + + /* // Create the WebBrowser. nsCOMPtr webBrowser = nsnull; webBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID); @@ -641,27 +709,11 @@ nsresult InitMozillaStuff (WebShellInitContext * initContext) nsCOMPtr observer(do_QueryInterface(initContext->browserContainer)); initContext->docShell->SetDocLoaderObserver(observer); - if (nsnull == gHistory) { - rv = gComponentManager->CreateInstance(kSHistoryCID, nsnull, - kISHistoryIID, - (void**)&gHistory); - if (NS_FAILED(rv)) { - initContext->initFailCode = kHistoryWebShellError; - return rv; - } - } - printf("Creation Done.....\n"); // Get the WebNavigation Object from the DocShell nsCOMPtr webNav(do_QueryInterface(initContext->docShell)); initContext->webNavigation = webNav; - // Set the History - // initContext->webNavigation->SetSessionHistory(gHistory); - - // Save the sessionHistory in the initContext - // initContext->sHistory = gHistory; - printf("Show the webBrowser\n"); // Show the webBrowser rv = initContext->baseWindow->SetVisibility(PR_TRUE); @@ -672,12 +724,27 @@ nsresult InitMozillaStuff (WebShellInitContext * initContext) initContext->initComplete = TRUE; + */ + + wsRealizeBrowserEvent * actionEvent = new wsRealizeBrowserEvent(initContext); + PLEvent * event = (PLEvent*) *actionEvent; + ::util_PostSynchronousEvent(initContext, event); + + #if DEBUG_RAPTOR_CANVAS if (prLogModuleInfo) { PR_LOG(prLogModuleInfo, 3, ("InitMozillaStuff(%lx): enter event loop\n", initContext)); } #endif + +#ifdef XP_UNIX + + // The gdk_x_error function exits in some cases, we don't + // want that. + XSetErrorHandler(wc_x_error); +#endif + // Just need to loop once to clear out events before returning processEventLoop(initContext); diff --git a/mozilla/java/webclient/src_moz/NativeEventThreadActionEvents.cpp b/mozilla/java/webclient/src_moz/NativeEventThreadActionEvents.cpp new file mode 100644 index 00000000000..e3e5c8a044c --- /dev/null +++ b/mozilla/java/webclient/src_moz/NativeEventThreadActionEvents.cpp @@ -0,0 +1,160 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Kirk Baker + * Ian Wilkinson + * Ashutosh Kulkarni + * Ed Burns + */ + +/* + * NativeEventThreadActionEvents.cpp + */ + +#include "NativeEventThreadActionEvents.h" + +static NS_DEFINE_IID(kWebShellCID, NS_WEB_SHELL_CID); +static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID); + +static NS_DEFINE_IID(kISHistoryIID, NS_ISHISTORY_IID); +static NS_DEFINE_CID(kSHistoryCID, NS_SHISTORY_CID); + + +/* + * wsRealizeBrowserEvent + */ + +wsRealizeBrowserEvent::wsRealizeBrowserEvent(WebShellInitContext * yourInitContext) : + nsActionEvent(), + mInitContext(yourInitContext) +{ +} + +void * +wsRealizeBrowserEvent::handleEvent () +{ + nsresult rv = nsnull; + + nsCOMPtr webBrowser = nsnull; + webBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID); + + mInitContext->webBrowser = webBrowser; + + // Get the BaseWindow from the DocShell - upcast + // nsCOMPtr docShellAsWin(do_QueryInterface(webBrowser)); + nsCOMPtr docShellAsWin; + rv = webBrowser->QueryInterface(NS_GET_IID(nsIBaseWindow), getter_AddRefs(docShellAsWin)); + + mInitContext->baseWindow = docShellAsWin; + + printf ("Init the baseWindow\n"); + +#ifdef XP_UNIX + GtkWidget * bin; + bin = (GtkWidget *) mInitContext->gtkWinPtr; + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, ("Ashu Debugs - Inside InitMozillaStuff(%lx): - before Init Call...\n", mInitContext)); + } + rv = mInitContext->baseWindow->InitWindow((nativeWindow) bin, nsnull, mInitContext->x, mInitContext->y, mInitContext->w, mInitContext->h); + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, ("Ashu Debugs - Inside InitMozillaStuff(%lx): - after Init Call...\n", mInitContext)); + } +#else + rv = mInitContext->baseWindow->InitWindow((nativeWindow) mInitContext->parentHWnd, nsnull, + mInitContext->x, mInitContext->y, mInitContext->w, mInitContext->h); +#endif + + printf("Create the BaseWindow...\n"); + + rv = mInitContext->baseWindow->Create(); + + if (NS_FAILED(rv)) { + mInitContext->initFailCode = kInitWebShellError; + return (void *) rv; + } + + // Create the DocShell + + mInitContext->docShell = do_GetInterface(mInitContext->webBrowser); + + if (!mInitContext->docShell) { + mInitContext->initFailCode = kCreateDocShellError; + return (void *) rv; + } + + // create our BrowserContainer, which implements many many things. + + mInitContext->browserContainer = + new CBrowserContainer(mInitContext->webBrowser, mInitContext->env, + mInitContext); + + // set the WebShellContainer. This is a pain. It's necessary + // because nsWebShell.cpp still checks for mContainer all over the + // place. + nsCOMPtr wsContainer(do_QueryInterface(mInitContext->browserContainer)); + nsCOMPtr webShell(do_QueryInterface(mInitContext->docShell)); + webShell->SetContainer(wsContainer); + + // set the TreeOwner + nsCOMPtr docShellAsItem(do_QueryInterface(mInitContext->docShell)); + nsCOMPtr treeOwner(do_QueryInterface(mInitContext->browserContainer)); + docShellAsItem->SetTreeOwner(treeOwner); + + // set the docloaderobserver + nsCOMPtr observer(do_QueryInterface(mInitContext->browserContainer)); + mInitContext->docShell->SetDocLoaderObserver(observer); + + if (nsnull == gHistory) { + rv = gComponentManager->CreateInstance(kSHistoryCID, nsnull, + kISHistoryIID, + (void**)&gHistory); + if (NS_FAILED(rv)) { + mInitContext->initFailCode = kHistoryWebShellError; + return (void *) rv; + } + } + + printf("Creation Done.....\n"); + // Get the WebNavigation Object from the DocShell + nsCOMPtr webNav(do_QueryInterface(mInitContext->docShell)); + mInitContext->webNavigation = webNav; + + // Set the History + // mInitContext->webNavigation->SetSessionHistory(gHistory); + + // Save the sessionHistory in the initContext + // mInitContext->sHistory = gHistory; + + printf("Show the webBrowser\n"); + // Show the webBrowser + rv = mInitContext->baseWindow->SetVisibility(PR_TRUE); + if (NS_FAILED(rv)) { + mInitContext->initFailCode = kShowWebShellError; + return (void *) rv; + } + + mInitContext->initComplete = TRUE; + + return (void *) nsnull; + +} // handleEvent() + +wsRealizeBrowserEvent::~wsRealizeBrowserEvent () +{ +} diff --git a/mozilla/java/webclient/src_moz/NativeEventThreadActionEvents.h b/mozilla/java/webclient/src_moz/NativeEventThreadActionEvents.h new file mode 100644 index 00000000000..45886ea24d8 --- /dev/null +++ b/mozilla/java/webclient/src_moz/NativeEventThreadActionEvents.h @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Kirk Baker + * Ian Wilkinson + * Ashutosh Kulkarni + * Ed Burns + */ + +/* + * nsActions.h + */ + +#ifndef NativeEventThreadActionEvents_h___ +#define NativeEventThreadActionEvents_h___ + +#include "NativeEventThread.h" +#include "CBrowserContainer.h" + +#include "nsIServiceManager.h" +#include "nsCOMPtr.h" +#include "nsActions.h" +#include "nsIDocShell.h" +#include "nsIBaseWindow.h" +#include "nsIDocShellTreeItem.h" +#include "nsCWebBrowser.h" +#include "nsISHistory.h" + +#ifdef XP_UNIX +#include +#include "gdksuperwin.h" +#include "gtkmozarea.h" +#endif + +#ifdef XP_PC +#include +#endif + +struct WebShellInitContext; + +class wsRealizeBrowserEvent : public nsActionEvent { +public: + wsRealizeBrowserEvent (WebShellInitContext * yourInitContext); + ~wsRealizeBrowserEvent (); + void * handleEvent (void); + +protected: + WebShellInitContext * mInitContext; +}; + +#endif /* NativeEventThreadActionEvents_h___ */ + +// EOF diff --git a/mozilla/java/webclient/src_moz/NavigationActionEvents.cpp b/mozilla/java/webclient/src_moz/NavigationActionEvents.cpp new file mode 100644 index 00000000000..bc7fcaac12f --- /dev/null +++ b/mozilla/java/webclient/src_moz/NavigationActionEvents.cpp @@ -0,0 +1,258 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Kirk Baker + * Ian Wilkinson + * Ashutosh Kulkarni + * Mark Lin + * Mark Goddard + * Ed Burns + * Jason Mawdsley + * Louis-Philippe Gagnon + */ + +/* + * NavigationActionEvents.cpp + */ + +#include "NavigationActionEvents.h" + +#include "ns_util.h" +#include "InputStreamShim.h" +#include "nsNetUtil.h" + +/* + * wsLoadURLEvent + */ + +wsLoadURLEvent::wsLoadURLEvent(nsIWebNavigation* webNavigation, PRUnichar * urlString, PRInt32 urlLength) : + nsActionEvent(), + mWebNavigation(webNavigation), + mURL(nsnull) +{ + mURL = new nsString(urlString, urlLength); +} + + +void * +wsLoadURLEvent::handleEvent () +{ + void* threadId = PR_GetCurrentThread(); + printf ("+++++++++++++++++++++ Thread Id ---- %p\n\n", threadId); + + if (mWebNavigation && mURL) { + nsresult rv = mWebNavigation->LoadURI(mURL->GetUnicode(), nsIWebNavigation::LOAD_FLAGS_NONE); + } + return nsnull; +} // handleEvent() + +wsLoadURLEvent::~wsLoadURLEvent () +{ + if (mURL != nsnull) + delete mURL; +} + + +wsLoadFromStreamEvent::wsLoadFromStreamEvent(WebShellInitContext *yourInitCx, + void *globalStream, + nsString &uriToCopy, + const char *contentTypeToCopy, + PRInt32 contentLength, + void *globalLoadProperties) : + nsActionEvent(), mInitContext(yourInitCx), mUriString(uriToCopy), + mContentType(PL_strdup(contentTypeToCopy)), + mProperties(globalLoadProperties), mShim(nsnull) +{ + mShim = new InputStreamShim((jobject) globalStream, contentLength); + NS_IF_ADDREF(mShim); +} + +wsLoadFromStreamEvent::wsLoadFromStreamEvent(WebShellInitContext *yourInitCx, + InputStreamShim *yourShim) : + nsActionEvent(), mInitContext(yourInitCx), mUriString(nsnull), + mContentType(nsnull), mProperties(nsnull), mShim(yourShim) +{ +} + +/** + + * This funky handleEvent allows the java InputStream to be read from + * the correct thread (the NativeEventThread), while, on a separate + * thread, mozilla's LoadFromStream reads from our nsIInputStream. This + * is accomplished using a "shim" class, InputStreamShim. + * InputStreamShim is an nsIInputStream, but it also maintains + * information on how to read from the java InputStream. The important + * thing is that InputStreamShim::doReadFromJava() is called on + * NativeEventThread() until all the data is read. This is accomplished + * by having this wsLoadFromStream instance copy itself and re-enqueue + * itself, if there is more data to read. + + */ + +void * +wsLoadFromStreamEvent::handleEvent () +{ + nsresult rv = NS_ERROR_FAILURE; + nsresult readFromJavaStatus = NS_ERROR_FAILURE; + nsCOMPtr uri; + wsLoadFromStreamEvent *repeatEvent = nsnull; + + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + + // we must have both mInitContext and mShim to do anything + if (!mInitContext || !mShim) { + return (void *) rv; + } + + // Try to read as much as possible off the java InputStream + // into the shim's internal buffer. + + // see InputShimStream::doReadFromJava() for the meaning of the + // return values. They are very important. + readFromJavaStatus = mShim->doReadFromJava(); + if (NS_ERROR_FAILURE == readFromJavaStatus) { + NS_IF_RELEASE(mShim); + return (void *) readFromJavaStatus; + } + + // if this is the first time handleEvent has been called for this + // InputStreamShim instance. + + if (mContentType) { + rv = NS_NewURI(getter_AddRefs(uri), mUriString); + if (!uri) { + return (void *) rv; + } + + // PENDING(edburns): turn the mProperties jobject into an + // nsIDocShellLoadInfo instance. + + // Kick off a LoadStream. This will cause + // InputStreamShim::Read() to be called, + + rv = mInitContext->docShell->LoadStream(mShim, uri, mContentType, + mShim->getContentLength(), + nsnull); + if (mProperties) { + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + ::util_DeleteGlobalRef(env, (jobject) mProperties); + mProperties = nsnull; + } + + // make it so we don't issue multiple LoadStream calls + // for this InputStreamShim instance. + + nsCRT::free(mContentType); + mContentType = nsnull; + } + + // if there is more data + if (NS_OK == readFromJavaStatus){ + // and we can create a copy of ourselves + if (repeatEvent = new wsLoadFromStreamEvent(mInitContext, mShim)) { + // do the loop + ::util_PostEvent(mInitContext, (PLEvent *) *repeatEvent); + rv = NS_OK; + } + else { + NS_IF_RELEASE(mShim); + rv = NS_ERROR_OUT_OF_MEMORY; + } + } + if (NS_ERROR_NOT_AVAILABLE == readFromJavaStatus) { + NS_IF_RELEASE(mShim); + rv = NS_OK; + } + + return (void *) rv; +} // handleEvent() + +wsLoadFromStreamEvent::~wsLoadFromStreamEvent () +{ + nsCRT::free(mContentType); + mContentType = nsnull; +} + + +/* + * wsStopEvent + */ + +wsStopEvent::wsStopEvent(nsIWebNavigation* webNavigation) : + nsActionEvent(), + mWebNavigation(webNavigation) +{ +} + + +void * +wsStopEvent::handleEvent () +{ + if (mWebNavigation) { + nsresult rv = mWebNavigation->Stop(); + } + return nsnull; +} // handleEvent() + + + +// Added by Mark Goddard OTMP 9/2/1999 + +/* + * wsRefreshEvent + */ + +wsRefreshEvent::wsRefreshEvent(nsIWebNavigation* webNavigation, PRInt32 reloadType) : + nsActionEvent(), + mWebNavigation(webNavigation), + mReloadType(reloadType) +{ + +} + + +void * +wsRefreshEvent::handleEvent () +{ + if (mWebNavigation) { + nsresult rv = mWebNavigation->Reload(mReloadType); + return (void *) rv; + } + return nsnull; +} // handleEvent() + + + +wsSetPromptEvent::wsSetPromptEvent(wcIBrowserContainer* aBrowserContainer, + jobject aUserPrompt) : + nsActionEvent(), + mBrowserContainer(aBrowserContainer), + mUserPrompt(aUserPrompt) +{ + +} + +void * +wsSetPromptEvent::handleEvent () +{ + if (mBrowserContainer && mUserPrompt) { + mBrowserContainer->SetPrompt(mUserPrompt); + } + return nsnull; +} // handleEvent() diff --git a/mozilla/java/webclient/src_moz/NavigationActionEvents.h b/mozilla/java/webclient/src_moz/NavigationActionEvents.h new file mode 100644 index 00000000000..947b86436f6 --- /dev/null +++ b/mozilla/java/webclient/src_moz/NavigationActionEvents.h @@ -0,0 +1,116 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Kirk Baker + * Ian Wilkinson + * Ashutosh Kulkarni + * Mark Lin + * Mark Goddard + * Ed Burns + */ + +/* + * nsActions.h + */ + +#ifndef NavigationActionEvents_h___ +#define NavigationActionEvents_h___ + +#include "nsActions.h" +#include "nsIWebNavigation.h" +#include "nsString.h" +#include "ns_util.h" + +struct WebShellInitContext; +class InputStreamShim; + + +class wsLoadURLEvent : public nsActionEvent { +public: + wsLoadURLEvent (nsIWebNavigation* webNavigation, PRUnichar * urlString, PRInt32 urlLength); + ~wsLoadURLEvent (); + void * handleEvent (void); + +protected: + nsIWebNavigation * mWebNavigation; + nsString * mURL; +}; + +class wsLoadFromStreamEvent : public nsActionEvent { +public: + wsLoadFromStreamEvent(WebShellInitContext *yourInitContext, + void *globalStream, + nsString &uriToCopy, + const char *contentTypeToCopy, + PRInt32 contentLength, void *globalLoadProperties); + virtual ~wsLoadFromStreamEvent(); + void * handleEvent(void); + +private: + wsLoadFromStreamEvent(WebShellInitContext *yourDocShell, + InputStreamShim *yourShim); + +protected: + + WebShellInitContext *mInitContext; + nsString mUriString; + char *mContentType; // MUST be delete'd in destructor + void * mProperties; // MUST be util_deleteGlobalRef'd in destructor. + InputStreamShim *mShim; // DO NOT delete this in the destructor +}; + + +class wsStopEvent : public nsActionEvent { +public: + wsStopEvent (nsIWebNavigation* webNavigation); + void * handleEvent (void); + +protected: + nsIWebNavigation * mWebNavigation; +}; + +// added by Mark Goddard OTMP 9/2/1999 +class wsRefreshEvent : public nsActionEvent { +public: + wsRefreshEvent (nsIWebNavigation* webNavigation, + PRInt32 reloadType); + void * handleEvent (void); + +protected: + nsIWebNavigation * mWebNavigation; + PRInt32 mReloadType; +}; + + +class wsSetPromptEvent : public nsActionEvent { +public: + wsSetPromptEvent (wcIBrowserContainer* aBrowserContainer, jobject aUserPrompt); + void * handleEvent (void); + +protected: + wcIBrowserContainer * mBrowserContainer; + jobject mUserPrompt; +}; + + + +#endif /* NavigationActionEvents_h___ */ + + +// EOF diff --git a/mozilla/java/webclient/src_moz/NavigationImpl.cpp b/mozilla/java/webclient/src_moz/NavigationImpl.cpp index 8cef9d8f582..e55ce287573 100644 --- a/mozilla/java/webclient/src_moz/NavigationImpl.cpp +++ b/mozilla/java/webclient/src_moz/NavigationImpl.cpp @@ -28,9 +28,9 @@ #include "NavigationImpl.h" -#include "ns_util.h" +#include "NavigationActionEvents.h" -#include "nsActions.h" +#include "ns_util.h" JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl_nativeLoadURL (JNIEnv *env, jobject obj, jint webShellPtr, jstring urlString) @@ -77,12 +77,79 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl ::util_ReleaseStringChars(env, urlString, (const jchar *) urlStringChars); } +JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl_nativeLoadFromStream +(JNIEnv *env, jobject obj, jint webShellPtr, jobject stream, jstring uri, + jstring contentType, jint contentLength, jobject loadProperties) +{ + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + PRUnichar *uriStringUniChars = nsnull; + PRInt32 uriStringUniCharsLength = -1; + const char *contentTypeChars = nsnull; + jobject globalStream = nsnull; + jobject globalLoadProperties = nsnull; + nsString *uriNsString = nsnull; + wsLoadFromStreamEvent *actionEvent = nsnull; + + if (initContext == nsnull || !initContext->initComplete) { + ::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeLoadFromStream"); + return; + } + uriStringUniChars = (PRUnichar *) ::util_GetStringChars(env, uri); + uriStringUniCharsLength = (PRInt32) ::util_GetStringLength(env, uri); + contentTypeChars = (char *) ::util_GetStringUTFChars(env, contentType); + if (!uriStringUniChars || !contentTypeChars) { + ::util_ThrowExceptionToJava(env, "Exception: nativeLoadFromStream: unable to convert java string to native format"); + goto NLFS_CLEANUP; + } + + if (!(uriNsString = + new nsString(uriStringUniChars, uriStringUniCharsLength))) { + ::util_ThrowExceptionToJava(env, "Exception: nativeLoadFromStream: unable to convert native string to nsString"); + goto NLFS_CLEANUP; + } + + // the deleteGlobalRef is done in the wsLoadFromStream destructor + if (!(globalStream = ::util_NewGlobalRef(env, stream))) { + ::util_ThrowExceptionToJava(env, "Exception: nativeLoadFromStream: unable to create gloabal ref to stream"); + goto NLFS_CLEANUP; + } + + if (loadProperties) { + // the deleteGlobalRef is done in the wsLoadFromStream destructor + if (!(globalLoadProperties = + ::util_NewGlobalRef(env, loadProperties))) { + ::util_ThrowExceptionToJava(env, "Exception: nativeLoadFromStream: unable to create gloabal ref to properties"); + goto NLFS_CLEANUP; + } + } + + if (!(actionEvent = new wsLoadFromStreamEvent(initContext, + (void *) globalStream, + *uriNsString, + contentTypeChars, + (PRInt32) contentLength, + (void *) + globalLoadProperties))) { + ::util_ThrowExceptionToJava(env, "Exception: nativeLoadFromStream: can't create wsLoadFromStreamEvent"); + goto NLFS_CLEANUP; + } + ::util_PostSynchronousEvent(initContext, (PLEvent *) *actionEvent); + + NLFS_CLEANUP: + ::util_ReleaseStringChars(env, uri, (const jchar *) uriStringUniChars); + ::util_ReleaseStringUTFChars(env, contentType, contentTypeChars); + delete uriNsString; + + // note, the deleteGlobalRef for loadProperties happens in the + // wsLoadFromStreamEvent destructor. +} + + JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl_nativeRefresh (JNIEnv *env, jobject obj, jint webShellPtr, jlong loadFlags) { JNIEnv * pEnv = env; jobject jobj = obj; - void * voidResult = nsnull; WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; @@ -95,7 +162,7 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl wsRefreshEvent * actionEvent = new wsRefreshEvent(initContext->webNavigation, (PRInt32) loadFlags); PLEvent * event = (PLEvent*) *actionEvent; - voidResult = ::util_PostSynchronousEvent(initContext, event); + ::util_PostEvent(initContext, event); return; } @@ -123,3 +190,38 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl ::util_PostEvent(initContext, event); } } + +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_wrapper_1native_NavigationImpl_nativeSetPrompt +(JNIEnv *env, jobject obj, jint webShellPtr, jobject userPrompt) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeSetPrompt"); + return; + } + + if (userPrompt == nsnull) { + ::util_ThrowExceptionToJava(env, "Exception: null properties passed to nativeSetPrompt"); + return; + } + + if (!initContext->initComplete) { + return; + } + + // IMPORTANT: do the DeleteGlobalRef when we set a new prompt! + + PR_ASSERT(initContext->browserContainer); + + + wsSetPromptEvent * actionEvent = new wsSetPromptEvent(initContext->browserContainer, userPrompt); + PLEvent * event = (PLEvent*) *actionEvent; + ::util_PostSynchronousEvent(initContext, event); + +} + diff --git a/mozilla/java/webclient/src_moz/PreferencesActionEvents.cpp b/mozilla/java/webclient/src_moz/PreferencesActionEvents.cpp new file mode 100644 index 00000000000..277dd902617 --- /dev/null +++ b/mozilla/java/webclient/src_moz/PreferencesActionEvents.cpp @@ -0,0 +1,283 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Ed Burns + */ + +/* + * PreferencesActionEvents.cpp + */ + +#include "PreferencesActionEvents.h" + +#include "nsIPref.h" +#include "nsCRT.h" // for memset + + +static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); + +// +// Local functions +// + +void prefEnumerator(const char *name, void *closure); + +static int PR_CALLBACK prefChanged(const char *name, void *closure); + +void prefEnumerator(const char *name, void *closure) +{ + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + if (nsnull == closure) { + return; + } + peStruct *pes = (peStruct *) closure; + WebShellInitContext *mInitContext = pes->cx; + jobject props = pes->obj; + PRInt32 prefType, intVal; + PRBool boolVal; + nsresult rv = NS_ERROR_FAILURE; + jstring prefName = nsnull; + jstring prefValue = nsnull; + PRUnichar *prefValueUni = nsnull; + nsAutoString prefValueAuto; + const PRInt32 bufLen = 20; + char buf[bufLen]; + nsCRT::memset(buf, 0, bufLen); + nsCOMPtr prefs(do_GetService(kPrefServiceCID)); + + if (nsnull == props || !prefs) { + return; + } + if (NS_FAILED(prefs->GetPrefType(name, &prefType))) { + return; + } + + if (nsnull == (prefName = ::util_NewStringUTF(env, name))) { + return; + } + + switch(prefType) { + case nsIPref::ePrefInt: + if (NS_SUCCEEDED(prefs->GetIntPref(name, &intVal))) { + WC_ITOA(intVal, buf, 10); + prefValue = ::util_NewStringUTF(env, buf); + } + break; + case nsIPref::ePrefBool: + if (NS_SUCCEEDED(prefs->GetBoolPref(name, &boolVal))) { + if (boolVal) { + prefValue = ::util_NewStringUTF(env, "true"); + } + else { + prefValue = ::util_NewStringUTF(env, "false"); + } + } + break; + case nsIPref::ePrefString: + if (NS_SUCCEEDED(prefs->CopyUnicharPref(name, &prefValueUni))) { + prefValueAuto = prefValueUni; + prefValue = ::util_NewString(env, (const jchar *) prefValueUni, + prefValueAuto.Length()); + delete [] prefValueUni; + } + break; + default: + PR_ASSERT(PR_TRUE); + break; + } + if (nsnull == prefValue) { + prefValue = ::util_NewStringUTF(env, ""); + } + ::util_StoreIntoPropertiesObject(env, props, prefName, prefValue, + (jobject) &(mInitContext->shareContext)); +} + +static int PR_CALLBACK prefChanged(const char *name, void *closure) +{ + if (nsnull == name || nsnull == closure) { + return NS_ERROR_NULL_POINTER; + } + nsresult rv; + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + wsPrefChangedEvent *actionEvent = nsnull; + peStruct *pes = (peStruct *) closure; + void *voidResult = nsnull; + jstring prefName; + + if (!(prefName = ::util_NewStringUTF(env, name))) { + rv = NS_ERROR_NULL_POINTER; + goto PC_CLEANUP; + } + + if (!(actionEvent = new wsPrefChangedEvent(name, (peStruct *) closure))) { + rv = NS_ERROR_NULL_POINTER; + goto PC_CLEANUP; + } + + voidResult = ::util_PostSynchronousEvent(pes->cx,(PLEvent *) *actionEvent); + rv = (nsresult) voidResult; + PC_CLEANUP: + + return rv; +} + +wsPrefChangedEvent::wsPrefChangedEvent(const char *prefName, + peStruct *yourPeStruct) : + mPrefName(prefName), mPeStruct(yourPeStruct) +{ + +} + +void *wsPrefChangedEvent::handleEvent() +{ + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + jint result; + jstring prefName; +#ifdef BAL_INTERFACE +#else + jclass pcClass = nsnull; + jmethodID pcMID = nsnull; + + if (!(pcClass = env->GetObjectClass(mPeStruct->callback))) { + return (void*) NS_ERROR_FAILURE; + } + if (!(pcMID =env->GetMethodID(pcClass, "prefChanged", + "(Ljava/lang/String;Ljava/lang/Object;)I"))){ + return (void*) NS_ERROR_FAILURE; + } + if (!(prefName = ::util_NewStringUTF(env, mPrefName))) { + return (void*) NS_ERROR_FAILURE; + } + result = env->CallIntMethod(mPeStruct->callback, pcMID, prefName, + mPeStruct->obj); + +#endif + return (void *) result; +} + +wsSetUnicharPrefEvent::wsSetUnicharPrefEvent(const char *prefName, + const jchar *yourPrefValue) : + mPrefName(prefName), mPrefValue(yourPrefValue) +{ + +} + +void *wsSetUnicharPrefEvent::handleEvent() +{ + nsCOMPtr prefs(do_GetService(kPrefServiceCID)); + + nsresult rv = NS_ERROR_FAILURE; + + if (!prefs) { + return (void *) rv; + } + + rv = prefs->SetUnicharPref(mPrefName, (const PRUnichar *) mPrefValue); + + return (void *) rv; +} + + +wsSetIntPrefEvent::wsSetIntPrefEvent(const char *prefName, + PRInt32 yourPrefValue) : + mPrefName(prefName), mPrefValue(yourPrefValue) +{ + +} + +void *wsSetIntPrefEvent::handleEvent() +{ + nsCOMPtr prefs(do_GetService(kPrefServiceCID)); + + nsresult rv = NS_ERROR_FAILURE; + + if (!prefs) { + return (void *) rv; + } + + rv = prefs->SetIntPref(mPrefName, mPrefValue); + + return (void *) rv; +} + +wsSetBoolPrefEvent::wsSetBoolPrefEvent(const char *prefName, + PRBool yourPrefValue) : + mPrefName(prefName), mPrefValue(yourPrefValue) +{ + +} + +void *wsSetBoolPrefEvent::handleEvent() +{ + nsCOMPtr prefs(do_GetService(kPrefServiceCID)); + + nsresult rv = NS_ERROR_FAILURE; + + if (!prefs) { + return (void *) rv; + } + + rv = prefs->SetBoolPref(mPrefName, mPrefValue); + + return (void *) rv; +} + +wsGetPrefsEvent::wsGetPrefsEvent(peStruct *yourPeStruct) : + mPeStruct(yourPeStruct) +{ + +} + +void *wsGetPrefsEvent::handleEvent() +{ + nsCOMPtr prefs(do_GetService(kPrefServiceCID)); + + nsresult rv = NS_ERROR_FAILURE; + + if (!prefs) { + return (void *) rv; + } + + rv = prefs->EnumerateChildren("", prefEnumerator, mPeStruct); + + return (void *) rv; +} + + +wsRegisterPrefCallbackEvent::wsRegisterPrefCallbackEvent(const char *yourPrefName, + peStruct *yourPeStruct) : + mPrefName(yourPrefName), mPeStruct(yourPeStruct) +{ + +} + +void *wsRegisterPrefCallbackEvent::handleEvent() +{ + nsCOMPtr prefs(do_GetService(kPrefServiceCID)); + + nsresult rv = NS_ERROR_FAILURE; + + if (!prefs) { + return (void *) rv; + } + + rv = prefs->RegisterCallback(mPrefName, prefChanged, mPeStruct); + + return (void *) rv; +} diff --git a/mozilla/java/webclient/src_moz/PreferencesActionEvents.h b/mozilla/java/webclient/src_moz/PreferencesActionEvents.h new file mode 100644 index 00000000000..aa287e996ec --- /dev/null +++ b/mozilla/java/webclient/src_moz/PreferencesActionEvents.h @@ -0,0 +1,113 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Kirk Baker + * Ian Wilkinson + * Ashutosh Kulkarni + * Mark Lin + * Mark Goddard + * Ed Burns + */ + +/* + * nsActions.h + */ + +#ifndef PreferencesActionEvents_h___ +#define PreferencesActionEvents_h___ + +#include "nsActions.h" + +#include "ns_util.h" + +typedef struct _peStruct { + WebShellInitContext *cx; + jobject obj; + jobject callback; +} peStruct; + +// +// ActionEvent class definitions +// + +class wsPrefChangedEvent : public nsActionEvent { +public: + wsPrefChangedEvent (const char *prefName, peStruct *yourPeStruct); + void * handleEvent (void); + +protected: + const char *mPrefName; + peStruct *mPeStruct; +}; + +class wsSetUnicharPrefEvent : public nsActionEvent { +public: + wsSetUnicharPrefEvent (const char *prefName, const jchar *yourPrefValue); + void * handleEvent (void); + +protected: + const char *mPrefName; + const jchar *mPrefValue; +}; + +class wsSetIntPrefEvent : public nsActionEvent { +public: + wsSetIntPrefEvent (const char *prefName, PRInt32 yourPrefValue); + void * handleEvent (void); + +protected: + const char *mPrefName; + PRInt32 mPrefValue; +}; + +class wsSetBoolPrefEvent : public nsActionEvent { +public: + wsSetBoolPrefEvent (const char *prefName, PRBool yourPrefValue); + void * handleEvent (void); + +protected: + const char *mPrefName; + PRBool mPrefValue; +}; + +class wsGetPrefsEvent : public nsActionEvent { +public: + wsGetPrefsEvent (peStruct *yourPeStruct); + void * handleEvent (void); + +protected: + peStruct *mPeStruct; +}; + +class wsRegisterPrefCallbackEvent : public nsActionEvent { +public: + wsRegisterPrefCallbackEvent (const char * prefName, + peStruct *yourPeStruct); + void * handleEvent (void); + +protected: + const char *mPrefName; + peStruct *mPeStruct; +}; + + +#endif /* PreferencesActionEvents_h___ */ + + +// EOF diff --git a/mozilla/java/webclient/src_moz/PreferencesImpl.cpp b/mozilla/java/webclient/src_moz/PreferencesImpl.cpp new file mode 100644 index 00000000000..e6cf17b858e --- /dev/null +++ b/mozilla/java/webclient/src_moz/PreferencesImpl.cpp @@ -0,0 +1,298 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Ed Burns + */ + +#include "PreferencesImpl.h" +#include "PreferencesActionEvents.h" + +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_wrapper_1native_PreferencesImpl_nativeSetUnicharPref +(JNIEnv *env, jobject obj, jint webShellPtr, jstring prefName, + jstring prefValue) +{ + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to netiveSetPref"); + return; + } + + const char * prefNameChars = (char *) ::util_GetStringUTFChars(env, + prefName); + const jchar * prefValueChars = (jchar *) ::util_GetStringChars(env, + prefValue); + nsresult rv = NS_ERROR_FAILURE; + wsSetUnicharPrefEvent *actionEvent = nsnull; + void *voidResult = nsnull; + + if (nsnull == prefNameChars) { + ::util_ThrowExceptionToJava(env, "nativeSetUnicharPref: unable to extract Java string for pref name"); + rv = NS_ERROR_NULL_POINTER; + goto NSUP_CLEANUP; + } + if (nsnull == prefValueChars) { + ::util_ThrowExceptionToJava(env, "nativeSetUnicharPref: unable to extract Java string for pref value"); + rv = NS_ERROR_NULL_POINTER; + goto NSUP_CLEANUP; + } + + if (!(actionEvent = new wsSetUnicharPrefEvent(prefNameChars, + prefValueChars))) { + ::util_ThrowExceptionToJava(env, "nativeSetPref: unable to create actionEvent"); + rv = NS_ERROR_NULL_POINTER; + goto NSUP_CLEANUP; + } + + voidResult = ::util_PostSynchronousEvent(initContext, + (PLEvent *) *actionEvent); + rv = (nsresult) voidResult; + + NSUP_CLEANUP: + + ::util_ReleaseStringUTFChars(env, prefName, prefNameChars); + ::util_ReleaseStringChars(env, prefName, prefValueChars); + + if (NS_FAILED(rv)) { + // PENDING(edburns): set a more specific kind of pref + ::util_ThrowExceptionToJava(env, "nativeSetUnicharPref: can't set pref"); + } + + return; +} + + +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_wrapper_1native_PreferencesImpl_nativeSetIntPref +(JNIEnv *env, jobject obj, jint webShellPtr, jstring prefName, + jint prefValue) +{ + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to netiveSetPref"); + return; + } + const char * prefNameChars = (char *) ::util_GetStringUTFChars(env, + prefName); + nsresult rv = NS_ERROR_FAILURE; + wsSetIntPrefEvent *actionEvent = nsnull; + void *voidResult = nsnull; + + if (nsnull == prefNameChars) { + ::util_ThrowExceptionToJava(env, "nativeSetIntPref: unable to extract Java string"); + return; + } + + if (!(actionEvent = new wsSetIntPrefEvent(prefNameChars, + (PRInt32) prefValue))) { + ::util_ThrowExceptionToJava(env, "nativeSetPref: unable to create actionEvent"); + rv = NS_ERROR_NULL_POINTER; + goto NSIP_CLEANUP; + } + + voidResult = ::util_PostSynchronousEvent(initContext, + (PLEvent *) *actionEvent); + rv = (nsresult) voidResult; + + NSIP_CLEANUP: + + ::util_ReleaseStringUTFChars(env, prefName, prefNameChars); + + if (NS_FAILED(rv)) { + // PENDING(edburns): set a more specific kind of pref + ::util_ThrowExceptionToJava(env, "nativeSetIntPref: can't set pref"); + } + + return; +} + + +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_wrapper_1native_PreferencesImpl_nativeSetBoolPref +(JNIEnv *env, jobject obj, jint webShellPtr, jstring prefName, + jboolean prefValue) +{ + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to netiveSetPref"); + return; + } + + const char * prefNameChars = (char *) ::util_GetStringUTFChars(env, + prefName); + nsresult rv = NS_ERROR_FAILURE; + wsSetBoolPrefEvent *actionEvent = nsnull; + void *voidResult = nsnull; + + if (nsnull == prefNameChars) { + ::util_ThrowExceptionToJava(env, "nativeSetBoolPref: unable to extract Java string"); + return; + } + + if (!(actionEvent = new wsSetBoolPrefEvent(prefNameChars, + prefValue))) { + ::util_ThrowExceptionToJava(env, "nativeSetPref: unable to create actionEvent"); + rv = NS_ERROR_NULL_POINTER; + goto NSBP_CLEANUP; + } + + voidResult = ::util_PostSynchronousEvent(initContext, + (PLEvent *) *actionEvent); + rv = (nsresult) voidResult; + + NSBP_CLEANUP: + + ::util_ReleaseStringUTFChars(env, prefName, prefNameChars); + + if (NS_FAILED(rv)) { + // PENDING(edburns): set a more specific kind of pref + ::util_ThrowExceptionToJava(env, "nativeSetBoolPref: can't set pref"); + } + + return; +} + +JNIEXPORT jobject JNICALL +Java_org_mozilla_webclient_wrapper_1native_PreferencesImpl_nativeGetPrefs +(JNIEnv *env, jobject obj, jint webShellPtr, jobject props) +{ + nsresult rv = NS_ERROR_FAILURE; + jobject newProps; + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + wsGetPrefsEvent *actionEvent = nsnull; + void *voidResult = nsnull; + + if (initContext == nsnull) { + ::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to netiveGetPrefs"); + return props; + } + + PR_ASSERT(initContext->initComplete); + + // step one: create or clear props + if (nsnull == props) { + if (nsnull == + (newProps = + ::util_CreatePropertiesObject(env, (jobject) + &(initContext->shareContext)))) { + ::util_ThrowExceptionToJava(env, "Exception: nativeGetPrefs: can't create prefs."); + return props; + } + if (nsnull == (props = ::util_NewGlobalRef(env, newProps))) { + ::util_ThrowExceptionToJava(env, "Exception: nativeGetPrefs: can't create global ref for prefs."); + return props; + } + } + else { + ::util_ClearPropertiesObject(env, props, (jobject) + &(initContext->shareContext)); + + } + PR_ASSERT(props); + + // step two, call the magic enumeration function, to populate the + // properties + peStruct pes; + pes.cx = initContext; + pes.obj = props; + if (!(actionEvent = new wsGetPrefsEvent(&pes))) { + ::util_ThrowExceptionToJava(env, "nativeSetPref: unable to create actionEvent"); + return props; + } + + voidResult = ::util_PostSynchronousEvent(initContext, + (PLEvent *) *actionEvent); + rv = (nsresult) voidResult; + + if (NS_FAILED(rv)) { + // PENDING(edburns): set a more specific kind of pref + ::util_ThrowExceptionToJava(env, "nativeGetPrefs: can't get prefs"); + } + + return props; +} + +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_wrapper_1native_PreferencesImpl_nativeRegisterPrefChangedCallback +(JNIEnv *env, jobject obj, jint webShellPtr, + jobject callback, jstring prefName, jobject closure) +{ + nsresult rv = NS_ERROR_FAILURE; + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + const char *prefNameChars; + wsRegisterPrefCallbackEvent *actionEvent = nsnull; + void *voidResult = nsnull; + + if (initContext == nsnull) { + ::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeRegisterPrefChangedCallback"); + return; + } + + PR_ASSERT(initContext->initComplete); + + if (nsnull == (callback = ::util_NewGlobalRef(env, callback))) { + ::util_ThrowExceptionToJava(env, "Exception: nativeRegisterPrefChangedCallback: can't global ref for callback"); + return; + } + + if (nsnull == (closure = ::util_NewGlobalRef(env, closure))) { + ::util_ThrowExceptionToJava(env, "Exception: nativeRegisterPrefChangedCallback: can't global ref for closure"); + return; + } + + // step one, set up our struct + peStruct *pes; + + if (nsnull == (pes = new peStruct())) { + ::util_ThrowExceptionToJava(env, "Exception: nativeRegisterPrefChangedCallback: can't get peStruct"); + return; + } + + pes->cx = initContext; + pes->obj = closure; + pes->callback = callback; + + // step two: create a const char * from the prefName + if (nsnull == (prefNameChars = ::util_GetStringUTFChars(env, prefName))) { + ::util_ThrowExceptionToJava(env, "Exception: nativeRegisterPrefChangedCallback: can't get string for prefName"); + return; + } + + if (!(actionEvent = new wsRegisterPrefCallbackEvent(prefNameChars, pes))) { + ::util_ThrowExceptionToJava(env, "nativeSetPref: unable to create actionEvent"); + rv = NS_ERROR_NULL_POINTER; + return; + } + + voidResult = ::util_PostSynchronousEvent(initContext, + (PLEvent *) *actionEvent); + rv = (nsresult) voidResult; + + if (NS_FAILED(rv)) { + // PENDING(edburns): set a more specific kind of pref + ::util_ThrowExceptionToJava(env, "nativeRegisterPrefChangedCallback: can't set callback"); + } + + ::util_ReleaseStringUTFChars(env, prefName, prefNameChars); + + return; +} diff --git a/mozilla/java/webclient/src_moz/PromptActionEvents.cpp b/mozilla/java/webclient/src_moz/PromptActionEvents.cpp new file mode 100644 index 00000000000..892f7918644 --- /dev/null +++ b/mozilla/java/webclient/src_moz/PromptActionEvents.cpp @@ -0,0 +1,211 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Ed Burns + */ + +/* + * RDFActionEvents.cpp + */ + +#include "PromptActionEvents.h" + +#include "ns_util.h" + + +wsPromptUsernameAndPasswordEvent::wsPromptUsernameAndPasswordEvent(WebShellInitContext *yourInitContext, + jobject yourPromptGlobalRef, + wsStringStruct *inStrings, + PRUint32 savePassword, + PRUnichar **outUser, + PRUnichar **outPwd, + PRBool *_retval) : + mInitContext(yourInitContext), mPromptGlobalRef(yourPromptGlobalRef), + mInStrings(inStrings), mOutUser(outUser), + mOutPwd(outPwd), mRetVal(_retval) +{ + +} + +void *wsPromptUsernameAndPasswordEvent::handleEvent() +{ + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + jboolean result = JNI_FALSE; + jstring user = nsnull; + jstring password = nsnull; + const jchar *userJchar = nsnull; + const jchar *passwordJchar = nsnull; + jclass promptClass = nsnull; + jmethodID mid = nsnull; + nsAutoString autoUser; + nsAutoString autoPassword; + if (!gPromptProperties) { + return (void *) NS_ERROR_FAILURE; + } + +#ifdef BAL_INTERFACE +#else + // step two, call the java method. + if (!(promptClass = env->GetObjectClass(mPromptGlobalRef))) { + return (void *) NS_ERROR_FAILURE; + } + if (!(mid = env->GetMethodID(promptClass, "promptUsernameAndPassword", + "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/util/Properties;)Z"))) { + return (void *) NS_ERROR_FAILURE; + } + result = env->CallBooleanMethod(mPromptGlobalRef, mid, + mInStrings[0].jStr, mInStrings[1].jStr, + mInStrings[2].jStr, (jint) mSavePassword, + gPromptProperties); +#endif + + // pull userName and password entries out of the properties table + + user = (jstring) ::util_GetFromPropertiesObject(env, gPromptProperties, + USER_NAME_KEY, (jobject) + &(mInitContext->shareContext)); + userJchar = ::util_GetStringChars(env, user); + autoUser = (PRUnichar *) userJchar; + *mOutUser = autoUser.ToNewUnicode(); + ::util_ReleaseStringChars(env, user, userJchar); + + password = (jstring) ::util_GetFromPropertiesObject(env, gPromptProperties, + PASSWORD_KEY, (jobject) + &(mInitContext->shareContext)); + passwordJchar = ::util_GetStringChars(env, password); + autoPassword = (PRUnichar *) passwordJchar; + *mOutPwd = autoPassword.ToNewUnicode(); + ::util_ReleaseStringChars(env, password, passwordJchar); + + *mRetVal = (result == JNI_TRUE) ? PR_TRUE : PR_FALSE; + + return (void *) NS_OK; +} + +wsPromptUniversalDialogEvent::wsPromptUniversalDialogEvent(WebShellInitContext *yourInitContext, + jobject yourPromptGlobalRef, + wsStringStruct *inStrings, + PRUnichar **fieldOne, + PRUnichar **fieldTwo, + PRBool *checkboxState, + PRInt32 numButtons, + PRInt32 numFields, + PRInt32 fieldIsPasswd, + PRInt32 *buttonPressed) : + mInitContext(yourInitContext), mPromptGlobalRef(yourPromptGlobalRef), + mInStrings(inStrings), mFieldOne(fieldOne), mFieldTwo(fieldTwo), + mCheckboxState(checkboxState), mNumButtons(numButtons), + mNumFields(numFields), mFieldIsPasswd(fieldIsPasswd), + mButtonPressed(buttonPressed) +{ + +} + +void *wsPromptUniversalDialogEvent::handleEvent() +{ + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + jboolean result = JNI_FALSE; + jclass promptClass = nsnull; + jmethodID mid = nsnull; + + jstring edit1 = nsnull; + jstring edit2 = nsnull; + const jchar *edit1Jchar = nsnull; + const jchar *edit2Jchar = nsnull; + nsAutoString autoEdit1; + nsAutoString autoEdit2; + + if (!gPromptProperties) { + return (void *) NS_ERROR_FAILURE; + } + +#ifdef BAL_INTERFACE +#else + // step two, call the java method. + if (!(promptClass = env->GetObjectClass(mPromptGlobalRef))) { + return (void *) NS_ERROR_FAILURE; + } + if (!(mid = env->GetMethodID(promptClass, "universalDialog", + "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IIZLjava/util/Properties;)Z"))) { + return (void *) NS_ERROR_FAILURE; + } + result = env->CallBooleanMethod(mPromptGlobalRef, mid, + mInStrings[0].jStr, + mInStrings[1].jStr, + mInStrings[2].jStr, + mInStrings[3].jStr, + mInStrings[4].jStr, + mInStrings[5].jStr, + mInStrings[6].jStr, + mInStrings[7].jStr, + mInStrings[8].jStr, + mInStrings[9].jStr, + (jint) mNumButtons, + (jint) mNumFields, + (jboolean) mFieldIsPasswd, + gPromptProperties); +#endif + + // pull entries out of the properties table + // editfield1Value, editfield2Value, checkboxState, buttonPressed + + if (mFieldOne) { + edit1 = (jstring) ::util_GetFromPropertiesObject(env, + gPromptProperties, + EDIT_FIELD_1_KEY, + (jobject) + &(mInitContext->shareContext)); + edit1Jchar = ::util_GetStringChars(env, edit1); + autoEdit1 = (PRUnichar *) edit1Jchar; + *mFieldOne = autoEdit1.ToNewUnicode(); + ::util_ReleaseStringChars(env, edit1, edit1Jchar); + } + + if (mFieldTwo) { + edit2 = (jstring) ::util_GetFromPropertiesObject(env, + gPromptProperties, + EDIT_FIELD_2_KEY, + (jobject) + &(mInitContext->shareContext)); + edit2Jchar = ::util_GetStringChars(env, edit2); + autoEdit2 = (PRUnichar *) edit2Jchar; + *mFieldTwo = autoEdit2.ToNewUnicode(); + ::util_ReleaseStringChars(env, edit2, edit2Jchar); + } + + if (mCheckboxState) { + *mCheckboxState = + (JNI_TRUE == ::util_GetBoolFromPropertiesObject(env, + gPromptProperties, + CHECKBOX_STATE_KEY, + (jobject) + &(mInitContext->shareContext))) + ? PR_TRUE : PR_FALSE; + } + + if (mButtonPressed) { + *mButtonPressed = (PRInt32) + ::util_GetIntFromPropertiesObject(env, gPromptProperties, + BUTTON_PRESSED_KEY, + (jobject) + &(mInitContext->shareContext)); + } + + return (void *) NS_OK; +} diff --git a/mozilla/java/webclient/src_moz/PromptActionEvents.h b/mozilla/java/webclient/src_moz/PromptActionEvents.h new file mode 100644 index 00000000000..7874e8d38e1 --- /dev/null +++ b/mozilla/java/webclient/src_moz/PromptActionEvents.h @@ -0,0 +1,89 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Ed Burns + */ + +/* + * nsActions.h + */ + +#ifndef PromptActionEvents_h___ +#define PromptActionEvents_h___ + +#include "nsActions.h" +#include "ns_util.h" + +struct WebShellInitContext; + +extern jobject gPromptProperties; // declared, defined in CBrowserContainer.cpp + +class wsPromptUsernameAndPasswordEvent : public nsActionEvent { +public: + wsPromptUsernameAndPasswordEvent (WebShellInitContext *yourInitContext, + jobject yourPromptGlobalRef, + wsStringStruct *inStrings, + PRUint32 savePassword, + PRUnichar **outUser, + PRUnichar **outPwd, + PRBool *_retval); + void * handleEvent (void); + +protected: + WebShellInitContext *mInitContext; + jobject mPromptGlobalRef; + wsStringStruct *mInStrings; + PRUint32 mSavePassword; + PRUnichar **mOutUser; + PRUnichar **mOutPwd; + PRBool *mRetVal; +}; + +class wsPromptUniversalDialogEvent : public nsActionEvent { +public: + wsPromptUniversalDialogEvent (WebShellInitContext *yourInitContext, + jobject yourPromptGlobalRef, + wsStringStruct *inStrings, + PRUnichar **fieldOne, + PRUnichar **fieldTwo, + PRBool *checkboxState, + PRInt32 numButtons, + PRInt32 numFields, + PRInt32 fieldIsPasswd, + PRInt32 *buttonPressed); + void * handleEvent (void); + +protected: + WebShellInitContext *mInitContext; + jobject mPromptGlobalRef; + wsStringStruct *mInStrings; + PRUnichar **mFieldOne; + PRUnichar **mFieldTwo; + PRBool *mCheckboxState; + PRInt32 mNumButtons; + PRInt32 mNumFields; + PRInt32 mFieldIsPasswd; + PRInt32 *mButtonPressed; +}; + + +#endif /* PromptActionEvents_h___ */ + + +// EOF diff --git a/mozilla/java/webclient/src_moz/RDFActionEvents.cpp b/mozilla/java/webclient/src_moz/RDFActionEvents.cpp new file mode 100644 index 00000000000..934ba33b7da --- /dev/null +++ b/mozilla/java/webclient/src_moz/RDFActionEvents.cpp @@ -0,0 +1,934 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Kirk Baker + * Ian Wilkinson + * Ashutosh Kulkarni + * Mark Lin + * Mark Goddard + * Ed Burns + * Jason Mawdsley + * Louis-Philippe Gagnon + */ + +/* + * RDFActionEvents.cpp + */ + +#include "RDFActionEvents.h" + +#include "rdf_util.h" +#include "ns_util.h" +#include "ns_globals.h" + +#include "prlog.h" + +#include "nsIComponentManager.h" +#include "nsISupportsArray.h" + +#include "nsRDFCID.h" // for NS_RDFCONTAINER_CID + +#include "wsRDFObserver.h" + +static NS_DEFINE_CID(kRDFContainerCID, NS_RDFCONTAINER_CID); +static NS_DEFINE_CID(kSupportsArrayCID, NS_SUPPORTSARRAY_CID); + +// +// Local function prototypes +// + +/** + + * pull the int for the field nativeEnum from the java object obj. + + */ + +jint getNativeEnumFromJava(JNIEnv *env, jobject obj, jint nativeRDFNode); + +wsInitBookmarksEvent::wsInitBookmarksEvent(WebShellInitContext* yourInitContext) : + nsActionEvent(), + mInitContext(yourInitContext) +{ +} + +void * +wsInitBookmarksEvent::handleEvent () +{ + void *result = nsnull; + if (!mInitContext) { + return (void *) NS_ERROR_UNEXPECTED; + } + nsresult rv; + rv = rdf_InitRDFUtils(); + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: can't initialize RDF Utils"); + return (void *) result; + } + result = (void *) kNC_BookmarksRoot.get(); + + return result; +} // handleEvent() + + +wsNewRDFNodeEvent::wsNewRDFNodeEvent(WebShellInitContext* yourInitContext, + const char * yourUrlString, + PRBool yourIsFolder) : + nsActionEvent(), + mInitContext(yourInitContext), mUrlString(yourUrlString), + mIsFolder(yourIsFolder) +{ +} + +void * +wsNewRDFNodeEvent::handleEvent () +{ + void *result = nsnull; + if (!mInitContext) { + return (void *) NS_ERROR_UNEXPECTED; + } + nsresult rv; + nsCOMPtr newNode; + nsCAutoString uri(mUrlString); + JNIEnv *env = (JNIEnv*) JNU_GetEnv(gVm, JNI_VERSION); + + // PENDING(edburns): does this leak? + PRUnichar *uriUni = uri.ToNewUnicode(); + + rv = gRDF->GetUnicodeResource(uriUni, getter_AddRefs(newNode)); + nsCRT::free(uriUni); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeNewRDFNode: can't create new nsIRDFResource."); + return result; + } + + if (mIsFolder) { + rv = gRDFCU->MakeSeq(gBookmarksDataSource, newNode, nsnull); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: unable to make new folder as a sequence."); + return result; + } + rv = gBookmarksDataSource->Assert(newNode, kRDF_type, + kNC_Folder, PR_TRUE); + if (rv != NS_OK) { + ::util_ThrowExceptionToJava(env, "Exception: unable to mark new folder as folder."); + + return result; + } + } + + /* + + * Do the AddRef here. + + */ + + result = (void *)newNode.get(); + ((nsISupports *)result)->AddRef(); + + return result; +} // handleEvent() + +wsRDFIsContainerEvent::wsRDFIsContainerEvent(WebShellInitContext* yourInitContext, + PRUint32 yourNativeRDFNode) : + nsActionEvent(), + mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode) +{ +} + +void * +wsRDFIsContainerEvent::handleEvent () +{ + if (!mInitContext) { + return (void *) NS_ERROR_UNEXPECTED; + } + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + nsCOMPtr node = (nsIRDFNode *) mNativeRDFNode; + nsCOMPtr nodeResource; + nsresult rv; + jboolean result = JNI_FALSE; + PRBool prBool; + + rv = node->QueryInterface(NS_GET_IID(nsIRDFResource), + getter_AddRefs(nodeResource)); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeIsContainer: nativeRDFNode is not an RDFResource."); + return nsnull; + } + rv = gRDFCU->IsContainer(gBookmarksDataSource, nodeResource, + &prBool); + result = (prBool == PR_FALSE) ? JNI_FALSE : JNI_TRUE; + + return (void *) result; +} // handleEvent() + +wsRDFGetChildAtEvent::wsRDFGetChildAtEvent(WebShellInitContext* yourInitContext, + PRUint32 yourNativeRDFNode, + PRUint32 yourChildIndex) : + nsActionEvent(), + mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode), + mChildIndex(yourChildIndex) +{ +} + +void * +wsRDFGetChildAtEvent::handleEvent () +{ + if (!mInitContext) { + return (void *) NS_ERROR_UNEXPECTED; + } + jint result = -1; + nsresult rv; + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + // PENDING(edburns): assert rdf_InitRDFUtils() + nsCOMPtr parent = (nsIRDFResource *) mNativeRDFNode; + nsCOMPtr child; + + rv = rdf_getChildAt(mChildIndex, parent, getter_AddRefs(child)); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeGetChildAt: Can't get child."); + return nsnull; + } + result = (jint)child.get(); + ((nsISupports *)result)->AddRef(); + return (void *) result; +} // handleEvent() + +wsRDFGetChildCountEvent::wsRDFGetChildCountEvent(WebShellInitContext* yourInitContext, + PRUint32 yourNativeRDFNode) : + nsActionEvent(), + mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode) +{ +} + +void * +wsRDFGetChildCountEvent::handleEvent () +{ + if (!mInitContext) { + return (void *) NS_ERROR_UNEXPECTED; + } + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + jint result = -1; + PRInt32 count; + nsresult rv; + // PENDING(edburns): assert rdf_InitRDFUtils() + nsCOMPtr parent = (nsIRDFResource *) mNativeRDFNode; + + rv = rdf_getChildCount(parent, &count); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeGetChildCount: Can't get child count."); + return nsnull; + } + result = (jint)count; + return (void *) result; +} // handleEvent() + +wsRDFGetChildIndexEvent::wsRDFGetChildIndexEvent(WebShellInitContext* yourInitContext, + PRUint32 yourNativeRDFNode, + PRUint32 yourChildRDFNode) : + nsActionEvent(), + mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode), + mChildRDFNode(yourChildRDFNode) +{ +} + +void * +wsRDFGetChildIndexEvent::handleEvent () +{ + if (!mInitContext) { + return (void *) NS_ERROR_UNEXPECTED; + } + jint result = -1; + PRInt32 index; + nsresult rv; + // PENDING(edburns): assert rdf_InitRDFUtils() + nsCOMPtr parent = (nsIRDFResource *) mNativeRDFNode; + nsCOMPtr child = (nsIRDFResource *) mChildRDFNode; + + rv = rdf_getIndexOfChild(parent, child, &index); + result = (jint) index; + + return (void *) result; +} // handleEvent() + +wsRDFToStringEvent::wsRDFToStringEvent(WebShellInitContext* yourInitContext, + PRUint32 yourNativeRDFNode) : + nsActionEvent(), + mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode) +{ +} + +void * +wsRDFToStringEvent::handleEvent () +{ + if (!mInitContext) { + return (void *) NS_ERROR_UNEXPECTED; + } + nsCOMPtr currentResource = + (nsIRDFResource *) mNativeRDFNode; + nsCOMPtr node; + nsCOMPtr literal; + jstring result = nsnull; + PRBool isContainer = PR_FALSE; + nsresult rv; + const PRUnichar *textForNode = nsnull; + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + + rv = gRDFCU->IsContainer(gBookmarksDataSource, currentResource, + &isContainer); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeToString: Can't tell if RDFResource is container."); + return nsnull; + } + + if (isContainer) { + // It's a bookmarks folder + rv = gBookmarksDataSource->GetTarget(currentResource, + kNC_Name, PR_TRUE, + getter_AddRefs(node)); + // get the name of the folder + if (rv == 0) { + // if so, make sure it's an nsIRDFLiteral + rv = node->QueryInterface(NS_GET_IID(nsIRDFLiteral), + getter_AddRefs(literal)); + if (NS_SUCCEEDED(rv)) { + rv = literal->GetValueConst(&textForNode); + } + else { + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("nativeToString: node is not an nsIRDFLiteral.\n")); + } + } + } + } + else { + // It's a bookmark or a Separator + rv = gBookmarksDataSource->GetTarget(currentResource, + kNC_URL, PR_TRUE, + getter_AddRefs(node)); + // See if it has a Name + if (0 != rv) { + rv = gBookmarksDataSource->GetTarget(currentResource, + kNC_Name, PR_TRUE, + getter_AddRefs(node)); + } + + if (0 == rv) { + rv = node->QueryInterface(NS_GET_IID(nsIRDFLiteral), + getter_AddRefs(literal)); + if (NS_SUCCEEDED(rv)) { + // get the value of the literal + rv = literal->GetValueConst(&textForNode); + if (NS_FAILED(rv)) { + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("nativeToString: node doesn't have a value.\n")); + } + } + } + else { + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("nativeToString: node is not an nsIRDFLiteral.\n")); + } + } + } + else { + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("nativeToString: node doesn't have a URL.\n")); + } + } + } + + if (nsnull != textForNode) { + nsString * string = new nsString(textForNode); + int length = 0; + if (nsnull != string) { + length = string->Length(); + } + + result = ::util_NewString(env, (const jchar *) textForNode, length); + } + else { + result = ::util_NewStringUTF(env, ""); + } + + return (void *) result; +} // handleEvent() + +wsRDFInsertElementAtEvent::wsRDFInsertElementAtEvent(WebShellInitContext* yourInitContext, + PRUint32 yourParentRDFNode, + PRUint32 yourChildRDFNode, + void *yourChildProperties, + PRUint32 yourChildIndex) : + nsActionEvent(), + mInitContext(yourInitContext), mParentRDFNode(yourParentRDFNode), + mChildRDFNode(yourChildRDFNode), + mChildPropsJobject(yourChildProperties), mChildIndex(yourChildIndex) +{ +} + +void * +wsRDFInsertElementAtEvent::handleEvent () +{ + if (!mInitContext) { + return (void *) NS_ERROR_UNEXPECTED; + } + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + nsCOMPtr parent = (nsIRDFResource *) mParentRDFNode; + nsCOMPtr newChild = (nsIRDFResource *) mChildRDFNode; + nsCOMPtr container; + nsCOMPtr nameLiteral; + nsCOMPtr urlLiteral; + + jstring name; + const jchar *nameJchar; + + jstring url; + const jchar *urlJchar; + + jobject childProps = (jobject) mChildPropsJobject; + PR_ASSERT(childProps); + + nsresult rv; + PRBool isContainer; + + rv = gRDFCU->IsContainer(gBookmarksDataSource, parent, + &isContainer); + + // PENDING(edburns): I don't think we can throw exceptions from + // here, no? + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeInsertElementAt: RDFResource is not a container."); + rv = NS_ERROR_UNEXPECTED; + goto RIEAEHE_CLEANUP; + } + + PR_ASSERT(gComponentManager); + + // get a container in order to create a child + rv = gComponentManager->CreateInstance(kRDFContainerCID, + nsnull, + NS_GET_IID(nsIRDFContainer), + getter_AddRefs(container)); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeInsertElementAt: can't create container."); + rv = NS_ERROR_UNEXPECTED; + goto RIEAEHE_CLEANUP; + } + rv = container->Init(gBookmarksDataSource, parent); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeInsertElementAt: can't create container."); + rv = NS_ERROR_UNEXPECTED; + goto RIEAEHE_CLEANUP; + } + + // pull the info from the properties object and add it to the new + // node. + if (nsnull == (name = (jstring) ::util_GetFromPropertiesObject(env, + childProps, + BM_NAME_VALUE, + (jobject) + &(mInitContext->shareContext)))) { + rv = NS_ERROR_UNEXPECTED; + goto RIEAEHE_CLEANUP; + } + + if (nsnull == (nameJchar = ::util_GetStringChars(env, name))) { + rv = NS_ERROR_UNEXPECTED; + goto RIEAEHE_CLEANUP; + } + + if (nsnull == (url = (jstring) ::util_GetFromPropertiesObject(env, childProps, + BM_URL_VALUE, + (jobject) + &(mInitContext->shareContext)))) { + rv = NS_ERROR_UNEXPECTED; + goto RIEAEHE_CLEANUP; + } + + if (nsnull == (urlJchar = ::util_GetStringChars(env, url))) { + rv = NS_ERROR_UNEXPECTED; + goto RIEAEHE_CLEANUP; + } + // if we get here, we have valid nameJchar and urlJchar strings. + + // create literals for the name and url + rv = gRDF->GetLiteral((const PRUnichar *) nameJchar, + getter_AddRefs(nameLiteral)); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeInsertElementAt: can't arguments nsISupportsArray."); + rv = NS_ERROR_UNEXPECTED; + goto RIEAEHE_CLEANUP; + } + + rv = gRDF->GetLiteral((const PRUnichar *) urlJchar, + getter_AddRefs(urlLiteral)); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeInsertElementAt: can't create arguments nsISupportsArray."); + rv = NS_ERROR_UNEXPECTED; + goto RIEAEHE_CLEANUP; + } + + // now Assert them to add the to the newChild + rv = gBookmarksDataSource->Assert(newChild, kNC_Name, nameLiteral, + PR_TRUE); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeInsertElementAt: can't add name literal to new node."); + rv = NS_ERROR_UNEXPECTED; + goto RIEAEHE_CLEANUP; + } + + // + 1 because for some reason the 1 is the first, not 0. + rv = container->InsertElementAt(newChild, mChildIndex + 1, PR_TRUE); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeInsertElementAt: can't insert element into parent container."); + rv = NS_ERROR_UNEXPECTED; + goto RIEAEHE_CLEANUP; + } + + RIEAEHE_CLEANUP: + ::util_ReleaseStringChars(env, name, nameJchar); + ::util_ReleaseStringChars(env, url, urlJchar); + + return (void *) rv; +} // handleEvent() + +wsRDFNewFolderEvent::wsRDFNewFolderEvent(WebShellInitContext* yourInitContext, + PRUint32 yourParentRDFNode, + void *yourChildPropsJobject, + PRUint32 *yourRetVal) : + nsActionEvent(), + mInitContext(yourInitContext), mParentRDFNode(yourParentRDFNode), + mChildPropsJobject(yourChildPropsJobject), mRetVal(yourRetVal) +{ +} + +/** + + * The adding of bookmark folders is done through the RDF DoCommand + * interface. The DoCommand interface creates the nsIRDFResource on + * your behalf. We use an nsIRDFObserver to obtain the created resource + * as the DoCommand executes. + + */ + +void * +wsRDFNewFolderEvent::handleEvent () +{ + if (!mInitContext) { + return (void *) NS_ERROR_UNEXPECTED; + } + PR_ASSERT(gComponentManager); + PR_ASSERT(mRetVal); + *mRetVal = -1; + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + nsCOMPtr parent = (nsIRDFResource *) mParentRDFNode; + nsCOMPtr newChildFromObserver; + nsCOMPtr selectionArray; + nsCOMPtr argumentsArray; + nsCOMPtr nameLiteral; + nsCOMPtr urlLiteral; + nsresult rv = NS_ERROR_UNEXPECTED; + PRBool isContainer; + nsCOMPtr o = new wsRDFObserver(); + wsRDFObserver *wsO = nsnull; + + jstring name; + const jchar *nameJchar; + + jstring url; + const jchar *urlJchar; + + jobject childProps = (jobject) mChildPropsJobject; + PR_ASSERT(childProps); + + + rv = gRDFCU->IsContainer(gBookmarksDataSource, parent, + &isContainer); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeNewFolder: RDFResource is not a container."); + rv = NS_ERROR_UNEXPECTED; + goto RNFEHE_CLEANUP; + } + + // pull out the necessary keys from the properties table + if (nsnull == (name = (jstring) ::util_GetFromPropertiesObject(env, + childProps, + BM_NAME_VALUE, + (jobject) + &(mInitContext->shareContext)))) { + rv = NS_ERROR_UNEXPECTED; + goto RNFEHE_CLEANUP; + } + + if (nsnull == (nameJchar = ::util_GetStringChars(env, name))) { + rv = NS_ERROR_UNEXPECTED; + goto RNFEHE_CLEANUP; + } + + if (nsnull == (url = (jstring) ::util_GetFromPropertiesObject(env, childProps, + BM_URL_VALUE, + (jobject) + &(mInitContext->shareContext)))) { + rv = NS_ERROR_UNEXPECTED; + goto RNFEHE_CLEANUP; + } + + if (nsnull == (urlJchar = ::util_GetStringChars(env, url))) { + rv = NS_ERROR_UNEXPECTED; + goto RNFEHE_CLEANUP; + } + // if we get here, we have valid nameJchar and urlJchar strings. + + // use the magic "command interface" as in bookmarks.js + // http://lxr.mozilla.org/mozilla/source/xpfe/components/bookmarks/resources/bookmarks.js#1190 + + // set up selection nsISupportsArray + rv = gComponentManager->CreateInstance(kSupportsArrayCID, + nsnull, + NS_GET_IID(nsISupportsArray), + getter_AddRefs(selectionArray)); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeNewFolder: can't create selection nsISupportsArray."); + rv = NS_ERROR_UNEXPECTED; + goto RNFEHE_CLEANUP; + } + + // set up arguments nsISupportsArray + rv = gComponentManager->CreateInstance(kSupportsArrayCID, + nsnull, + NS_GET_IID(nsISupportsArray), + getter_AddRefs(argumentsArray)); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeNewFolder: can't create arguments nsISupportsArray."); + rv = NS_ERROR_UNEXPECTED; + goto RNFEHE_CLEANUP; + } + // get various arguments (parent, name) + // kNC_parent + // kNC_Name + // kNC_URL + + // add parent into selection array + selectionArray->AppendElement(parent); + + // add multiple arguments into arguments array + argumentsArray->AppendElement(kNC_parent); + argumentsArray->AppendElement(parent); + + rv = gRDF->GetLiteral((const PRUnichar *) nameJchar, + getter_AddRefs(nameLiteral)); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeNewFolder: can't arguments nsISupportsArray."); + rv = NS_ERROR_UNEXPECTED; + goto RNFEHE_CLEANUP; + } + argumentsArray->AppendElement(kNC_Name); + argumentsArray->AppendElement(nameLiteral); + + rv = gRDF->GetLiteral((const PRUnichar *) urlJchar, + getter_AddRefs(urlLiteral)); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeNewFolder: can't create arguments nsISupportsArray."); + rv = NS_ERROR_UNEXPECTED; + goto RNFEHE_CLEANUP; + } + argumentsArray->AppendElement(kNC_URL); + argumentsArray->AppendElement(urlLiteral); + + // at this point, selectionArray contains the parent + // and argumentsArray contains arcs and literals for the name and the + // url of the node to be inserted. + + if (o) { + gBookmarksDataSource->AddObserver(o); + } + + // find out if it's a folder + if (nsnull != ::util_GetFromPropertiesObject(env, childProps, + BM_IS_FOLDER_VALUE, (jobject) + &(mInitContext->shareContext))){ + // do the command + rv = gBookmarksDataSource->DoCommand(selectionArray, + kNewFolderCommand, + argumentsArray); + } + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeInsertElementAt: can't execute bookmarks command to add folder."); + rv = NS_ERROR_UNEXPECTED; + goto RNFEHE_CLEANUP; + } + + if (o) { + gBookmarksDataSource->RemoveObserver(o); + wsO = (wsRDFObserver *) o.get(); + newChildFromObserver = wsO->getFolder(); + if (newChildFromObserver) { + *mRetVal = (PRUint32) newChildFromObserver.get(); + ((nsISupports *)*mRetVal)->AddRef(); + } + } + + RNFEHE_CLEANUP: + ::util_ReleaseStringChars(env, name, nameJchar); + ::util_ReleaseStringChars(env, url, urlJchar); + + return (void *) rv; +} // handleEvent() + + +wsRDFHasMoreElementsEvent::wsRDFHasMoreElementsEvent(WebShellInitContext* yourInitContext, + PRUint32 yourNativeRDFNode, + void *yourJobject) : + nsActionEvent(), + mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode), + mJobject(yourJobject) +{ +} + +void * +wsRDFHasMoreElementsEvent::handleEvent () +{ + if (!mInitContext) { + return (void *) NS_ERROR_UNEXPECTED; + } + nsresult rv; + jboolean result = JNI_FALSE; + PRBool prResult = PR_FALSE; + // assert -1 != nativeRDFNode + jint nativeEnum; + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + + if (-1 == (nativeEnum = getNativeEnumFromJava(env, (jobject) mJobject, + mNativeRDFNode))) { + ::util_ThrowExceptionToJava(env, "Exception: nativeHasMoreElements: Can't get nativeEnum from nativeRDFNode."); + return (void *) NS_ERROR_UNEXPECTED; + } + + nsCOMPtr enumerator = (nsISimpleEnumerator *)nativeEnum; + rv = enumerator->HasMoreElements(&prResult); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeHasMoreElements: Can't ask nsISimpleEnumerator->HasMoreElements()."); + return (void *) NS_ERROR_UNEXPECTED; + } + result = (PR_FALSE == prResult) ? JNI_FALSE : JNI_TRUE; + + return (void *) result; + +} // handleEvent() + +wsRDFNextElementEvent::wsRDFNextElementEvent(WebShellInitContext* yourInitContext, + PRUint32 yourNativeRDFNode, + void *yourJobject) : + nsActionEvent(), + mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode), + mJobject(yourJobject) +{ +} + +void * +wsRDFNextElementEvent::handleEvent () +{ + if (!mInitContext) { + return (void *) NS_ERROR_UNEXPECTED; + } + nsresult rv; + jint result = -1; + PRBool hasMoreElements = PR_FALSE; + // assert -1 != nativeRDFNode + jint nativeEnum; + nsCOMPtr supportsResult; + nsCOMPtr nodeResult; + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + + if (-1 == (nativeEnum = getNativeEnumFromJava(env, (jobject) mJobject, + mNativeRDFNode))) { + ::util_ThrowExceptionToJava(env, "Exception: nativeNextElement: Can't get nativeEnum from nativeRDFNode."); + return (void *) NS_ERROR_UNEXPECTED; + } + + nsCOMPtr enumerator = (nsISimpleEnumerator *)nativeEnum; + rv = enumerator->HasMoreElements(&hasMoreElements); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeNextElement: Can't ask nsISimpleEnumerator->HasMoreElements()."); + return (void *) NS_ERROR_UNEXPECTED; + } + + if (!hasMoreElements) { + return (void *) NS_ERROR_UNEXPECTED; + } + + rv = enumerator->GetNext(getter_AddRefs(supportsResult)); + if (NS_FAILED(rv)) { + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("Exception: nativeNextElement: Can't get next from enumerator.\n")); + } + return (void *) NS_ERROR_UNEXPECTED; + } + + // make sure it's an RDFNode + rv = supportsResult->QueryInterface(NS_GET_IID(nsIRDFNode), + getter_AddRefs(nodeResult)); + if (NS_FAILED(rv)) { + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("Exception: nativeNextElement: next from enumerator is not an nsIRDFNode.\n")); + } + return (void *) NS_ERROR_UNEXPECTED; + } + + result = (jint)nodeResult.get(); + ((nsISupports *)result)->AddRef(); + return (void *) result; +} // handleEvent() + +wsRDFFinalizeEvent::wsRDFFinalizeEvent(void *yourJobject) : + nsActionEvent(), + mJobject(yourJobject) +{ +} + +void * +wsRDFFinalizeEvent::handleEvent () +{ + if (!mJobject) { + return (void *) NS_ERROR_UNEXPECTED; + } + jint nativeEnum, nativeContainer; + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + + // release the nsISimpleEnumerator + if (-1 == (nativeEnum = + ::util_GetIntValueFromInstance(env, (jobject) mJobject, + "nativeEnum"))) { + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("nativeFinalize: Can't get fieldID for nativeEnum.\n")); + } + return (void *) NS_ERROR_UNEXPECTED; + } + nsCOMPtr enumerator = + (nsISimpleEnumerator *) nativeEnum; + ((nsISupports *)enumerator.get())->Release(); + + // release the nsIRDFContainer + if (-1 == (nativeContainer = + ::util_GetIntValueFromInstance(env, (jobject) mJobject, + "nativeContainer"))) { + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("nativeFinalize: Can't get fieldID for nativeContainerFieldID.\n")); + } + return (void *) NS_ERROR_UNEXPECTED; + } + nsCOMPtr container = + (nsIRDFContainer *) nativeContainer; + ((nsISupports *)container.get())->Release(); + + return (void *) NS_OK; +} // handleEvent() + +// +// Local functions +// + +jint getNativeEnumFromJava(JNIEnv *env, jobject obj, jint nativeRDFNode) +{ + nsresult rv; + jint result = -1; + + result = ::util_GetIntValueFromInstance(env, obj, "nativeEnum"); + + // if the field has been initialized, just return the value + if (-1 != result) { + // NORMAL EXIT 1 + return result; + } + + // else, we need to create the enum + nsCOMPtr node = (nsIRDFNode *) nativeRDFNode; + nsCOMPtr nodeResource; + nsCOMPtr container; + nsCOMPtr enumerator; + + rv = node->QueryInterface(NS_GET_IID(nsIRDFResource), + getter_AddRefs(nodeResource)); + if (NS_FAILED(rv)) { + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("getNativeEnumFromJava: Argument nativeRDFNode isn't an nsIRDFResource.\n")); + } + return -1; + } + + PR_ASSERT(gComponentManager); + + // get a container in order to get the enum + rv = gComponentManager->CreateInstance(kRDFContainerCID, + nsnull, + NS_GET_IID(nsIRDFContainer), + getter_AddRefs(container)); + if (NS_FAILED(rv)) { + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("recursiveResourceTraversal: can't get a new container\n")); + } + return -1; + } + + rv = container->Init(gBookmarksDataSource, nodeResource); + if (NS_FAILED(rv)) { + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("getNativeEnumFromJava: Can't Init container.\n")); + } + return -1; + } + + rv = container->GetElements(getter_AddRefs(enumerator)); + if (NS_FAILED(rv)) { + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("getNativeEnumFromJava: Can't get enumeration from container.\n")); + } + return -1; + } + + // IMPORTANT: Store the enum back into java + ::util_SetIntValueForInstance(env,obj,"nativeEnum",(jint)enumerator.get()); + // IMPORTANT: make sure it doesn't get deleted when it goes out of scope + ((nsISupports *)enumerator.get())->AddRef(); + + // PENDING(edburns): I'm not sure if we need to keep the + // nsIRDFContainer from being destructed in order to maintain the + // validity of the nsISimpleEnumerator that came from the container. + // Just to be safe, I'm doing so. + ::util_SetIntValueForInstance(env, obj, "nativeContainer", + (jint) container.get()); + ((nsISupports *)container.get())->AddRef(); + + // NORMAL EXIT 2 + result = (jint)enumerator.get(); + return result; +} diff --git a/mozilla/java/webclient/src_moz/RDFActionEvents.h b/mozilla/java/webclient/src_moz/RDFActionEvents.h new file mode 100644 index 00000000000..397835695d5 --- /dev/null +++ b/mozilla/java/webclient/src_moz/RDFActionEvents.h @@ -0,0 +1,188 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Kirk Baker + * Ian Wilkinson + * Ashutosh Kulkarni + * Mark Lin + * Mark Goddard + * Ed Burns + */ + +/* + * nsActions.h + */ + +#ifndef RDFActionEvents_h___ +#define RDFActionEvents_h___ + +#include "nsActions.h" + +struct WebShellInitContext; + +class wsInitBookmarksEvent : public nsActionEvent { +public: + wsInitBookmarksEvent(WebShellInitContext *yourInitContext); + void * handleEvent(void); + +protected: + WebShellInitContext *mInitContext; +}; + +class wsNewRDFNodeEvent : public nsActionEvent { +public: + wsNewRDFNodeEvent(WebShellInitContext *yourInitContext, + const char *yourUrlString, PRBool yourIsFolder); + void * handleEvent(void); + +protected: + WebShellInitContext *mInitContext; + const char *mUrlString; + PRBool mIsFolder; +}; + +class wsRDFIsContainerEvent : public nsActionEvent { +public: + wsRDFIsContainerEvent(WebShellInitContext *yourInitContext, + PRUint32 yourNativeRDFNode); + void * handleEvent(void); + +protected: + WebShellInitContext *mInitContext; + PRUint32 mNativeRDFNode; +}; + +class wsRDFGetChildAtEvent : public nsActionEvent { +public: + wsRDFGetChildAtEvent(WebShellInitContext *yourInitContext, + PRUint32 yourNativeRDFNode, PRUint32 childIndex); + void * handleEvent(void); + +protected: + WebShellInitContext *mInitContext; + PRUint32 mNativeRDFNode; + PRUint32 mChildIndex; +}; + +class wsRDFGetChildCountEvent : public nsActionEvent { +public: + wsRDFGetChildCountEvent(WebShellInitContext *yourInitContext, + PRUint32 yourNativeRDFNode); + void * handleEvent(void); + +protected: + WebShellInitContext *mInitContext; + PRUint32 mNativeRDFNode; +}; + +class wsRDFGetChildIndexEvent : public nsActionEvent { +public: + wsRDFGetChildIndexEvent(WebShellInitContext *yourInitContext, + PRUint32 yourNativeRDFNode, + PRUint32 yourChildRDFNode); + void * handleEvent(void); + +protected: + WebShellInitContext *mInitContext; + PRUint32 mNativeRDFNode; + PRUint32 mChildRDFNode; +}; + +class wsRDFToStringEvent : public nsActionEvent { +public: + wsRDFToStringEvent(WebShellInitContext *yourInitContext, + PRUint32 yourNativeRDFNode); + void * handleEvent(void); + +protected: + WebShellInitContext *mInitContext; + PRUint32 mNativeRDFNode; +}; + +class wsRDFInsertElementAtEvent : public nsActionEvent { +public: + wsRDFInsertElementAtEvent(WebShellInitContext *yourInitContext, + PRUint32 yourParentRDFNode, + PRUint32 yourChildRDFNode, + void *yourChildProperties, + PRUint32 yourChildIndex); + void * handleEvent(void); + +protected: + WebShellInitContext *mInitContext; + PRUint32 mParentRDFNode; + PRUint32 mChildRDFNode; + void *mChildPropsJobject; + PRUint32 mChildIndex; +}; + +class wsRDFNewFolderEvent : public nsActionEvent { +public: + wsRDFNewFolderEvent(WebShellInitContext* yourInitContext, + PRUint32 yourParentRDFNode, + void *yourChildPropsJobject, + PRUint32 *yourRetVal); + void * handleEvent(void); + +protected: + WebShellInitContext *mInitContext; + PRUint32 mParentRDFNode; + void *mChildPropsJobject; + PRUint32 *mRetVal; +}; + +class wsRDFHasMoreElementsEvent : public nsActionEvent { +public: + wsRDFHasMoreElementsEvent(WebShellInitContext *yourInitContext, + PRUint32 mNativeRDFNode, + void *yourJobject); + void * handleEvent(void); + +protected: + WebShellInitContext *mInitContext; + PRUint32 mNativeRDFNode; + void *mJobject; +}; + +class wsRDFNextElementEvent : public nsActionEvent { +public: + wsRDFNextElementEvent(WebShellInitContext *yourInitContext, + PRUint32 mNativeRDFNode, + void *yourJobject); + void * handleEvent(void); + +protected: + WebShellInitContext *mInitContext; + PRUint32 mNativeRDFNode; + void *mJobject; +}; + +class wsRDFFinalizeEvent : public nsActionEvent { +public: + wsRDFFinalizeEvent(void *yourJobject); + void * handleEvent(void); + +protected: + void *mJobject; +}; + +#endif /* RDFActionEvents_h___ */ + + +// EOF diff --git a/mozilla/java/webclient/src_moz/RDFEnumeration.cpp b/mozilla/java/webclient/src_moz/RDFEnumeration.cpp index cc446f8d962..79f9acc619e 100644 --- a/mozilla/java/webclient/src_moz/RDFEnumeration.cpp +++ b/mozilla/java/webclient/src_moz/RDFEnumeration.cpp @@ -22,10 +22,11 @@ #include "RDFEnumeration.h" +#include "RDFActionEvents.h" + #include "rdf_util.h" #include "rdf_progids.h" #include "ns_util.h" -#include "nsActions.h" #include "nsIRDFContainer.h" #include "nsIServiceManager.h" diff --git a/mozilla/java/webclient/src_moz/RDFTreeNode.cpp b/mozilla/java/webclient/src_moz/RDFTreeNode.cpp index 97507047807..44ca0f50c9d 100644 --- a/mozilla/java/webclient/src_moz/RDFTreeNode.cpp +++ b/mozilla/java/webclient/src_moz/RDFTreeNode.cpp @@ -22,10 +22,11 @@ #include "RDFTreeNode.h" +#include "RDFActionEvents.h" + #include "rdf_util.h" #include "rdf_progids.h" #include "ns_util.h" -#include "nsActions.h" #include "nsIServiceManager.h" @@ -216,10 +217,11 @@ Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeToString JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeInsertElementAt (JNIEnv *env, jobject obj, jint webShellPtr, jint parentRDFNode, - jint childRDFNode, jint childIndex) + jint childRDFNode, jobject childProps, jint childIndex) { WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; void * voidResult = nsnull; + jobject propsGlobalRef; if (initContext == nsnull) { ::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeInsertElementAt"); @@ -228,20 +230,60 @@ Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeInsertElementAt if (!initContext->initComplete) { ::util_ThrowExceptionToJava(env, "Exception: can't InsertElementAt"); } + propsGlobalRef = ::util_NewGlobalRef(env, childProps); wsRDFInsertElementAtEvent *actionEvent = new wsRDFInsertElementAtEvent(initContext, (PRUint32) parentRDFNode, (PRUint32) childRDFNode, + (void *) propsGlobalRef, (PRUint32) childIndex); PLEvent * event = (PLEvent*) *actionEvent; voidResult = ::util_PostSynchronousEvent(initContext, event); + ::util_DeleteGlobalRef(env, propsGlobalRef); if (NS_FAILED((nsresult) voidResult)) { ::util_ThrowExceptionToJava(env, "Exception: Can't InsertElementAt"); } return; } +JNIEXPORT jint JNICALL +Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeNewFolder +(JNIEnv *env, jobject obj, jint webShellPtr, jint parentRDFNode, + jobject childProps) +{ + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + void * voidResult = nsnull; + jobject propsGlobalRef; + jint retVal = 0; + + if (initContext == nsnull) { + ::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeNewFolder"); + } + + if (!initContext->initComplete || !childProps) { + ::util_ThrowExceptionToJava(env, "Exception: can't NewFolder"); + } + propsGlobalRef = ::util_NewGlobalRef(env, childProps); + if (!propsGlobalRef) { + ::util_ThrowExceptionToJava(env, "Exception: can't NewFolder"); + } + + wsRDFNewFolderEvent *actionEvent = + new wsRDFNewFolderEvent(initContext, + (PRUint32) parentRDFNode, + (void *) propsGlobalRef, + (PRUint32 *) &retVal); + PLEvent * event = (PLEvent*) *actionEvent; + + voidResult = ::util_PostSynchronousEvent(initContext, event); + ::util_DeleteGlobalRef(env, propsGlobalRef); + if (NS_FAILED((nsresult) voidResult)) { + ::util_ThrowExceptionToJava(env, "Exception: Can't do NewFolder"); + } + return retVal; +} + diff --git a/mozilla/java/webclient/src_moz/WindowControlActionEvents.cpp b/mozilla/java/webclient/src_moz/WindowControlActionEvents.cpp new file mode 100644 index 00000000000..5ddaac39381 --- /dev/null +++ b/mozilla/java/webclient/src_moz/WindowControlActionEvents.cpp @@ -0,0 +1,299 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Kirk Baker + * Ian Wilkinson + * Ashutosh Kulkarni + * Mark Lin + * Mark Goddard + * Ed Burns + * Jason Mawdsley + * Louis-Philippe Gagnon + */ + +/* + * WindowControlActionEvents.cpp + */ + +#include "WindowControlActionEvents.h" + +#include "ns_util.h" +#include "nsIDocShellTreeItem.h" +#include "nsEmbedAPI.h" // for NS_TermEmbedding + + + +/* + * wsResizeEvent + */ + +wsResizeEvent::wsResizeEvent(nsIBaseWindow* baseWindow, PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h) : + nsActionEvent(), + mBaseWindow(baseWindow), + mLeft(x), + mBottom(y), + mWidth(w), + mHeight(h) +{ +} + + +void * +wsResizeEvent::handleEvent () +{ + nsresult rv = NS_ERROR_FAILURE; + if (mBaseWindow) { + + rv = mBaseWindow->SetPositionAndSize(mLeft, mBottom, mWidth, mHeight, + PR_TRUE); + + + return (void *) rv; + } + return nsnull; +} // handleEvent() + + +wsDeallocateInitContextEvent::wsDeallocateInitContextEvent(WebShellInitContext* yourInitContext) : + nsActionEvent(), + mInitContext(yourInitContext) +{ +} + +void * +wsDeallocateInitContextEvent::handleEvent () +{ + void *result = nsnull; + if (!mInitContext) { + return (void *) NS_ERROR_UNEXPECTED; + } + PRBool isLastWindow = PR_TRUE; + PRInt32 winCount; + if (NS_SUCCEEDED(mInitContext->browserContainer-> + GetInstanceCount(&winCount))) { + isLastWindow = (1 == winCount); + } + + mInitContext->parentHWnd = nsnull; + + // make sure the webBrowser's contentListener doesn't have a ref to + // CBrowserContainer + mInitContext->webBrowser->SetParentURIContentListener(nsnull); + mInitContext->webBrowser = nsnull; + + // make sure the webShell's container is set to null. + // get the webShell from the docShell + nsCOMPtr webShell(do_QueryInterface(mInitContext->docShell)); + if (webShell) { + webShell->SetContainer(nsnull); + } + + // make sure the docShell's TreeOwner is set to null + // get the docShellTreeItem from the docShell + nsCOMPtr docShellAsItem(do_QueryInterface(mInitContext->docShell)); + if (docShellAsItem) { + docShellAsItem->SetTreeOwner(nsnull); + } + + mInitContext->docShell->SetDocLoaderObserver(nsnull); + + mInitContext->docShell = nsnull; + + // PENDING(edburns): this is a leak. For some reason, webShell's + // refcount is two. I believe it should be one. + // see http://bugzilla.mozilla.org/show_bug.cgi?id=38271 + + mInitContext->webShell = nsnull; + mInitContext->webNavigation = nsnull; + mInitContext->presShell = nsnull; + mInitContext->baseWindow = nsnull; + + // mInitContext->embeddedThread = nsnull; + mInitContext->env = nsnull; + if (nsnull != mInitContext->nativeEventThread) { + ::util_DeleteGlobalRef((JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION), + mInitContext->nativeEventThread); + mInitContext->nativeEventThread = nsnull; + } + mInitContext->stopThread = -1; + mInitContext->initComplete = FALSE; + mInitContext->initFailCode = 0; + mInitContext->x = -1; + mInitContext->y = -1; + mInitContext->w = -1; + mInitContext->h = -1; + mInitContext->gtkWinPtr = nsnull; + mInitContext->searchContext = nsnull; + + // make sure we aren't listening anymore. This needs to be done + // before currentDocument = nsnull + mInitContext->browserContainer->RemoveAllListeners(); + + mInitContext->currentDocument = nsnull; + mInitContext->browserContainer = nsnull; + util_DeallocateShareInitContext(&(mInitContext->shareContext)); + + // delete mInitContext; + if (isLastWindow) { + NS_TermEmbedding(); +#ifdef _WIN32 + _exit(0); +#endif + } + return (void *) NS_OK; +} // handleEvent() + + +/* + * wsMoveToEvent + */ + +wsMoveToEvent::wsMoveToEvent(nsIBaseWindow* baseWindow, PRInt32 x, PRInt32 y) : + nsActionEvent(), + mBaseWindow(baseWindow), + mX(x), + mY(y) +{ +} + + +void * +wsMoveToEvent::handleEvent () +{ + if (mBaseWindow) { + nsresult rv = mBaseWindow->SetPosition(mX, mY); + } + return nsnull; +} // handleEvent() + + +/* + * wsSetFocusEvent + */ + +wsSetFocusEvent::wsSetFocusEvent(nsIBaseWindow* baseWindow) : + nsActionEvent(), + mBaseWindow(baseWindow) +{ +} + + +void * +wsSetFocusEvent::handleEvent () +{ + if (mBaseWindow) { + nsresult rv = mBaseWindow->SetFocus(); + } + return nsnull; +} // handleEvent() + + + +/* + * wsRemoveFocusEvent + */ + +wsRemoveFocusEvent::wsRemoveFocusEvent(nsIBaseWindow* baseWindow) : + nsActionEvent(), + mBaseWindow(baseWindow) +{ +} + + +void * +wsRemoveFocusEvent::handleEvent () +{ + if (mBaseWindow) { + //PENDING (Ashu) : No removeFocus functionality provided in M15 + // nsresult rv = mWebShell->RemoveFocus(); + } + return nsnull; +} // handleEvent() + + + +/* + * wsRepaintEvent + */ + +wsRepaintEvent::wsRepaintEvent(nsIBaseWindow* baseWindow, PRBool forceRepaint) : + nsActionEvent(), + mBaseWindow(baseWindow), + mForceRepaint(forceRepaint) +{ +} + + +void * +wsRepaintEvent::handleEvent () +{ + if (mBaseWindow) { + nsresult rv = mBaseWindow->Repaint(mForceRepaint); + } + return nsnull; +} // handleEvent() + + + + +/* + * wsShowEvent + */ + +wsShowEvent::wsShowEvent(nsIBaseWindow* baseWindow, PRBool state) : + nsActionEvent(), + mBaseWindow(baseWindow), + mState(state) +{ +} + + +void * +wsShowEvent::handleEvent () +{ + if (mBaseWindow) { + mBaseWindow->SetVisibility(mState); + } + return nsnull; +} // handleEvent() + + + + +/* + * wsHideEvent + */ + +wsHideEvent::wsHideEvent(nsIBaseWindow* baseWindow) : + nsActionEvent(), + mBaseWindow(baseWindow) +{ +} + + +void * +wsHideEvent::handleEvent () +{ + if (mBaseWindow) { + mBaseWindow->SetVisibility(PR_FALSE); + } + return nsnull; +} // handleEvent() + + diff --git a/mozilla/java/webclient/src_moz/WindowControlActionEvents.h b/mozilla/java/webclient/src_moz/WindowControlActionEvents.h new file mode 100644 index 00000000000..e924bb17a3f --- /dev/null +++ b/mozilla/java/webclient/src_moz/WindowControlActionEvents.h @@ -0,0 +1,128 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.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 RaptorCanvas. + * + * The Initial Developer of the Original Code is Kirk Baker and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Kirk Baker + * Ian Wilkinson + * Ashutosh Kulkarni + * Mark Lin + * Mark Goddard + * Ed Burns + */ + +/* + * nsActions.h + */ + +#ifndef WindowControlActionEvents_h___ +#define WindowControlActionEvents_h___ + +#include "nsActions.h" + +#include "nsIBaseWindow.h" + +struct WebShellInitContext; + +class wsResizeEvent : public nsActionEvent { +public: + wsResizeEvent (nsIBaseWindow* baseWindow, PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h); + void * handleEvent (void); + +protected: + nsIBaseWindow * mBaseWindow; + PRInt32 mLeft; + PRInt32 mBottom; + PRInt32 mWidth; + PRInt32 mHeight; +}; + +class wsDeallocateInitContextEvent : public nsActionEvent { +public: + wsDeallocateInitContextEvent(WebShellInitContext *yourInitContext); + + void * handleEvent (void); + +protected: + WebShellInitContext *mInitContext; +}; + +class wsMoveToEvent : public nsActionEvent { +public: + wsMoveToEvent (nsIBaseWindow* baseWindow, PRInt32 x, PRInt32 y); + void * handleEvent (void); + +protected: + nsIBaseWindow * mBaseWindow; + PRInt32 mX; + PRInt32 mY; +}; + +class wsSetFocusEvent : public nsActionEvent { +public: + wsSetFocusEvent(nsIBaseWindow* baseWindow); + void * handleEvent (void); + +protected: + nsIBaseWindow * mBaseWindow; +}; + + + +class wsRemoveFocusEvent : public nsActionEvent { +public: + wsRemoveFocusEvent(nsIBaseWindow* baseWindow); + void * handleEvent (void); + +protected: + nsIBaseWindow * mBaseWindow; +}; + +class wsRepaintEvent : public nsActionEvent { +public: + wsRepaintEvent (nsIBaseWindow* baseWindow, PRBool forceRepaint); + void * handleEvent (void); + +protected: + nsIBaseWindow * mBaseWindow; + PRBool mForceRepaint; +}; + +class wsShowEvent : public nsActionEvent { +public: + wsShowEvent (nsIBaseWindow* baseWindow, PRBool state); + void * handleEvent (void); + +protected: + nsIBaseWindow * mBaseWindow; + PRBool mState; +}; + +class wsHideEvent : public nsActionEvent { +public: + wsHideEvent (nsIBaseWindow* baseWindow); + void * handleEvent (void); + +protected: + nsIBaseWindow * mBaseWindow; +}; + + +#endif /* WindowControlActionEvents_h___ */ + + +// EOF diff --git a/mozilla/java/webclient/src_moz/WindowControlImpl.cpp b/mozilla/java/webclient/src_moz/WindowControlImpl.cpp index 8c5b5a238c5..f3c70d0e756 100644 --- a/mozilla/java/webclient/src_moz/WindowControlImpl.cpp +++ b/mozilla/java/webclient/src_moz/WindowControlImpl.cpp @@ -27,8 +27,10 @@ */ #include "WindowControlImpl.h" + +#include "WindowControlActionEvents.h" + #include "ns_util.h" -#include "nsActions.h" #include "nsIThread.h" // for PRThread @@ -85,11 +87,10 @@ JNIEXPORT jint JNICALL Java_org_mozilla_webclient_wrapper_1native_WindowControlI initContext->webShell = nsnull; initContext->docShell = nsnull; initContext->baseWindow = nsnull; - initContext->sHistory = nsnull; initContext->webNavigation = nsnull; initContext->presShell = nsnull; - initContext->embeddedThread = nsnull; - initContext->actionQueue = nsnull; + // initContext->embeddedThread = nsnull; + // initContext->actionQueue = nsnull; initContext->env = env; initContext->nativeEventThread = nsnull; initContext->stopThread = FALSE; @@ -103,6 +104,12 @@ JNIEXPORT jint JNICALL Java_org_mozilla_webclient_wrapper_1native_WindowControlI util_InitializeShareInitContext(&(initContext->shareContext)); #ifdef XP_UNIX + /***** Uncomment this to debug on unix + pid_t pid = getpid(); + printf("++++++++++++++++debug: edburns: pid is: %d\n", pid); + sleep(7); + **************/ + initContext->gtkWinPtr = (int)::util_GetGTKWinPtrFromCanvas(env, aBrowserControlImpl); #else @@ -132,7 +139,7 @@ Java_org_mozilla_webclient_wrapper_1native_WindowControlImpl_nativeDestroyInitCo ::util_ThrowExceptionToJava(env, "Exception: Can't destroy initContext"); return; } - initContext->actionQueue = nsnull; + // initContext->actionQueue = nsnull; delete initContext; } diff --git a/mozilla/java/webclient/src_moz/WrapperFactoryImpl.cpp b/mozilla/java/webclient/src_moz/WrapperFactoryImpl.cpp index 7ab62795c6b..68561cf5cbe 100644 --- a/mozilla/java/webclient/src_moz/WrapperFactoryImpl.cpp +++ b/mozilla/java/webclient/src_moz/WrapperFactoryImpl.cpp @@ -43,6 +43,7 @@ const char *gImplementedInterfaces[] = { "webclient.History", "webclient.EventRegistration", "webclient.Bookmarks", + "webclient.Preferences", nsnull }; @@ -71,7 +72,6 @@ Java_org_mozilla_webclient_wrapper_1native_WrapperFactoryImpl_nativeTerminate (JNIEnv *env, jobject obj) { gComponentManager = nsnull; - gHistory = nsnull; nsCRT::free((char *) gBinDir); gBinDir = nsnull; } diff --git a/mozilla/java/webclient/src_moz/install_win32.js b/mozilla/java/webclient/src_moz/install_win32.js new file mode 100644 index 00000000000..6042c1faacb --- /dev/null +++ b/mozilla/java/webclient/src_moz/install_win32.js @@ -0,0 +1,64 @@ +// Installation guide for Webclient.xpi + // this function verifies disk space in kilobytes + function verifyDiskSpace(dirPath, spaceRequired) + { + var spaceAvailable; + + // Get the available disk space on the given path + spaceAvailable = fileGetDiskSpaceAvailable(dirPath); + + // Convert the available disk space into kilobytes + spaceAvailable = parseInt(spaceAvailable / 1024); + + // do the verification + if(spaceAvailable < spaceRequired) + { + logComment("Insufficient disk space: " + dirPath); + logComment(" required : " + spaceRequired + " K"); + logComment(" available: " + spaceAvailable + " K"); + return(false); + } + + return(true); + } + + + + // main + var srDest; + var err; + var fProgram; + + srDest = 1000; +logComment("Starting Install Process"); + err = initInstall("Webclient", "Webclient", "1.0"); + logComment("initInstall: " + err); + + fProgram = getFolder("Program"); + logComment("fProgram: " + fProgram); + + if(verifyDiskSpace(fProgram, srDest)) + { + setPackageFolder(fProgram); + err = addDirectory("", + "1.0", + "javadev", // dir name in jar to extract + fProgram, // Where to put this file + // (Returned from GetFolder) + "javadev", // subdir name to create relative to fProgram + true); // Force Flag + logComment("addDirectory() returned: " + err); + + // check return value + if(err == SUCCESS) + { + err = performInstall(); + logComment("performInstall() returned: " + err); + } + else + cancelInstall(err); + } + else + cancelInstall(INSUFFICIENT_DISK_SPACE); + + // end main diff --git a/mozilla/java/webclient/src_moz/motif/NativeLoaderStub.cpp b/mozilla/java/webclient/src_moz/motif/NativeLoaderStub.cpp index 47783672c22..106864bad37 100644 --- a/mozilla/java/webclient/src_moz/motif/NativeLoaderStub.cpp +++ b/mozilla/java/webclient/src_moz/motif/NativeLoaderStub.cpp @@ -39,6 +39,7 @@ #include // JNI Headers #include "BookmarksImpl.h" +#include "PreferencesImpl.h" #include "CurrentPageImpl.h" #include "HistoryImpl.h" #include "ISupportsPeer.h" @@ -111,13 +112,17 @@ void (* nativeProcessEvents) (JNIEnv *, jobject, jint); // from BookmarksImpl.h jint (* nativeGetBookmarks) (JNIEnv *, jobject, jint); jint (* nativeNewRDFNode) (JNIEnv *, jobject, jint, jstring, jboolean); +// from PreferencesImpl.h +void (* nativeSetUnicharPref) (JNIEnv *, jobject, jint, jstring, jstring); +void (* nativeSetIntPref) (JNIEnv *, jobject, jint, jstring, jint); +void (* nativeSetBoolPref) (JNIEnv *, jobject, jint, jstring, jboolean); +jobject (* nativeGetPrefs) (JNIEnv *env, jobject obj, jint webShellPtr, jobject props); +void (* nativeRegisterPrefChangedCallback) (JNIEnv *env, jobject obj, jint webShellPtr, jobject callback, jstring prefName, jobject closure); // from CurrentPageImpl.h void (* nativeCopyCurrentSelectionToSystemClipboard) (JNIEnv *, jobject, jint); void (* nativeFindInPage) (JNIEnv *, jobject, jint, jstring, jboolean, jboolean); -void (* nativeFindNextInPage) (JNIEnv *, jobject, jint, jboolean); +void (* nativeFindNextInPage) (JNIEnv *, jobject, jint); jstring (* nativeGetCurrentURL) (JNIEnv *, jobject, jint); -jstring (* nativeGetSource) (JNIEnv *, jobject); -jbyteArray (* nativeGetSourceBytes) (JNIEnv *, jobject, jint, jboolean); void (* nativeResetFind) (JNIEnv *, jobject, jint); void (* nativeSelectAll) (JNIEnv *, jobject, jint); jobject (* nativeGetDOM) (JNIEnv *, jobject, jint); @@ -140,8 +145,10 @@ void (* nativeAddRef) (JNIEnv *, jobject, jint); void (* nativeRelease) (JNIEnv *, jobject, jint); // from NavigationImpl.h void (* nativeLoadURL) (JNIEnv *, jobject, jint, jstring); +void (* nativeLoadFromStream) (JNIEnv *, jobject, jint, jobject, jstring, jstring, jint, jobject); void (* nativeRefresh) (JNIEnv *, jobject, jint, jlong); void (* nativeStop) (JNIEnv *, jobject, jint); +void (* nativeSetPrompt) (JNIEnv *, jobject, jint, jobject); // from RDFEnumeration.h void (* nativeFinalize) (JNIEnv *, jobject, jint); jboolean (* nativeHasMoreElements) (JNIEnv *, jobject, jint, jint); @@ -150,7 +157,8 @@ jint (* nativeNextElement) (JNIEnv *, jobject, jint, jint); jint (* nativeGetChildAt) (JNIEnv *, jobject, jint, jint, jint); jint (* nativeGetChildCount) (JNIEnv *, jobject, jint, jint); jint (* nativeGetIndex) (JNIEnv *, jobject, jint, jint, jint); -void (* nativeInsertElementAt) (JNIEnv *, jobject, jint, jint, jint, jint); +void (* nativeInsertElementAt) (JNIEnv *, jobject, jint, jint, jint, jobject, jint); +jint (* nativeNewFolder) (JNIEnv *, jobject, jint, jint, jobject); jboolean (* nativeIsContainer) (JNIEnv *, jobject, jint, jint); jboolean (* nativeIsLeaf) (JNIEnv *, jobject, jint, jint); jstring (* nativeToString) (JNIEnv *, jobject, jint, jint); @@ -228,10 +236,14 @@ void locateBrowserControlStubFunctions(void * dll) { if (!nativeGetIndex) { printf("got dlsym error %s\n", dlerror()); } - nativeInsertElementAt = (void (*) (JNIEnv *, jobject, jint, jint, jint, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeInsertElementAt"); + nativeInsertElementAt = (void (*) (JNIEnv *, jobject, jint, jint, jint, jobject, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeInsertElementAt"); if (!nativeInsertElementAt) { printf("got dlsym error %s\n", dlerror()); } + nativeNewFolder = (jint (*) (JNIEnv *, jobject, jint, jint, jobject)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeNewFolder"); + if (!nativeNewFolder) { + printf("got dlsym error %s\n", dlerror()); + } nativeIsContainer = (jboolean (*) (JNIEnv *, jobject, jint, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeIsContainer"); if (!nativeIsContainer) { printf("got dlsym error %s\n", dlerror()); @@ -262,6 +274,10 @@ void locateBrowserControlStubFunctions(void * dll) { if (!nativeLoadURL) { printf("got dlsym error %s\n", dlerror()); } + nativeLoadFromStream = (void (*) (JNIEnv *, jobject, jint, jobject, jstring, jstring, jint, jobject)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_NavigationImpl_nativeLoadFromStream"); + if (!nativeLoadFromStream) { + printf("got dlsym error %s\n", dlerror()); + } nativeRefresh = (void (*) (JNIEnv *, jobject, jint, jlong)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_NavigationImpl_nativeRefresh"); if (!nativeRefresh) { printf("got dlsym error %s\n", dlerror()); @@ -270,6 +286,10 @@ void locateBrowserControlStubFunctions(void * dll) { if (!nativeStop) { printf("got dlsym error %s\n", dlerror()); } + nativeSetPrompt = (void (*) (JNIEnv *, jobject, jint, jobject)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_NavigationImpl_nativeSetPrompt"); + if (!nativeSetPrompt) { + printf("got dlsym error %s\n", dlerror()); + } nativeAddRef = (void (*) (JNIEnv *, jobject, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_ISupportsPeer_nativeAddRef"); if (!nativeAddRef) { @@ -341,7 +361,7 @@ void locateBrowserControlStubFunctions(void * dll) { if (!nativeFindInPage) { printf("got dlsym error %s\n", dlerror()); } - nativeFindNextInPage = (void (*) (JNIEnv *, jobject, jint, jboolean)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeFindNextInPage"); + nativeFindNextInPage = (void (*) (JNIEnv *, jobject, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeFindNextInPage"); if (!nativeFindNextInPage) { printf("got dlsym error %s\n", dlerror()); } @@ -349,14 +369,6 @@ void locateBrowserControlStubFunctions(void * dll) { if (!nativeGetCurrentURL) { printf("got dlsym error %s\n", dlerror()); } - nativeGetSource = (jstring (*) (JNIEnv *, jobject)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeGetSource"); - if (!nativeGetSource) { - printf("got dlsym error %s\n", dlerror()); - } - nativeGetSourceBytes = (jbyteArray (*) (JNIEnv *, jobject, jint, jboolean)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeGetSourceBytes"); - if (!nativeGetSourceBytes) { - printf("got dlsym error %s\n", dlerror()); - } nativeResetFind = (void (*) (JNIEnv *, jobject, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeResetFind"); if (!nativeResetFind) { printf("got dlsym error %s\n", dlerror()); @@ -379,7 +391,26 @@ void locateBrowserControlStubFunctions(void * dll) { if (!nativeNewRDFNode) { printf("got dlsym error %s\n", dlerror()); } - + nativeSetUnicharPref = (void (*) (JNIEnv *, jobject, jint, jstring, jstring)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_PreferencesImpl_nativeSetUnicharPref"); + if (!nativeSetUnicharPref) { + printf("got dlsym error %s\n", dlerror()); + } + nativeSetIntPref = (void (*) (JNIEnv *, jobject, jint, jstring, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_PreferencesImpl_nativeSetIntPref"); + if (!nativeSetIntPref) { + printf("got dlsym error %s\n", dlerror()); + } + nativeSetBoolPref = (void (*) (JNIEnv *, jobject, jint, jstring, jboolean)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_PreferencesImpl_nativeSetBoolPref"); + if (!nativeSetBoolPref) { + printf("got dlsym error %s\n", dlerror()); + } + nativeGetPrefs = (jobject (*) (JNIEnv *env, jobject obj, jint webShellPtr, jobject props)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_PreferencesImpl_nativeGetPrefs"); + if (!nativeGetPrefs) { + printf("got dlsym error %s\n", dlerror()); + } + nativeRegisterPrefChangedCallback = (void (*) (JNIEnv *env, jobject obj, jint webShellPtr, jobject callback, jstring prefName, jobject closure)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_PreferencesImpl_nativeRegisterPrefChangedCallback"); + if (!nativeRegisterPrefChangedCallback) { + printf("got dlsym error %s\n", dlerror()); + } nativeAddListener = (void (*) (JNIEnv *, jobject, jint, jobject, jstring)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeAddListener"); if (!nativeAddListener) { printf("got dlsym error %s\n", dlerror()); @@ -488,6 +519,48 @@ JNIEXPORT jint JNICALL Java_org_mozilla_webclient_wrapper_1native_BookmarksImpl_ return (* nativeNewRDFNode) (env, obj, webShellPtr, url, isFolder); } +// PreferencesImpl.h + +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_wrapper_1native_PreferencesImpl_nativeSetUnicharPref +(JNIEnv *env, jobject obj, jint webShellPtr, jstring prefName, + jstring prefValue) +{ + (* nativeSetUnicharPref) (env, obj, webShellPtr, prefName, prefValue); +} + + +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_wrapper_1native_PreferencesImpl_nativeSetIntPref +(JNIEnv *env, jobject obj, jint webShellPtr, jstring prefName, jint prefValue) +{ + (* nativeSetIntPref) (env, obj, webShellPtr, prefName, prefValue); +} + + +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_wrapper_1native_PreferencesImpl_nativeSetBoolPref +(JNIEnv *env, jobject obj, jint webShellPtr, jstring prefName, + jboolean prefValue) +{ + (* nativeSetBoolPref) (env, obj, webShellPtr, prefName, prefValue); +} + +JNIEXPORT jobject JNICALL +Java_org_mozilla_webclient_wrapper_1native_PreferencesImpl_nativeGetPrefs +(JNIEnv *env, jobject obj, jint webShellPtr, jobject props) +{ + return (* nativeGetPrefs) (env, obj, webShellPtr, props); +} + +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_wrapper_1native_PreferencesImpl_nativeRegisterPrefChangedCallback +(JNIEnv *env, jobject obj, jint webShellPtr, + jobject callback, jstring prefName, jobject closure) +{ + (* nativeRegisterPrefChangedCallback) (env, obj, webShellPtr, callback, + prefName, closure); +} // CurrentPageImpl /* @@ -516,8 +589,8 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImp * Signature: (Z)V */ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeFindNextInPage -(JNIEnv * env, jobject obj, jint webShellPtr, jboolean myboolean) { - (* nativeFindNextInPage) (env, obj, webShellPtr, myboolean); +(JNIEnv * env, jobject obj, jint webShellPtr) { + (* nativeFindNextInPage) (env, obj, webShellPtr); } /* @@ -530,26 +603,6 @@ JNIEXPORT jstring JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPage return (* nativeGetCurrentURL) (env, obj, webShellPtr); } -/* - * Class: org_mozilla_webclient_wrapper_0005fnative_CurrentPageImpl - * Method: nativeGetSource - * Signature: ()Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeGetSource -(JNIEnv * env, jobject obj) { - return (* nativeGetSource) (env, obj); -} - -/* - * Class: org_mozilla_webclient_wrapper_0005fnative_CurrentPageImpl - * Method: nativeGetSourceBytes - * Signature: ()[B - */ -JNIEXPORT jbyteArray JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeGetSourceBytes -(JNIEnv * env, jobject obj, jint webShellPtr, jboolean mode) { - return (* nativeGetSourceBytes) (env, obj, webShellPtr, mode); -} - /* * Class: org_mozilla_webclient_wrapper_0005fnative_CurrentPageImpl * Method: nativeResetFind @@ -753,6 +806,19 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl (* nativeLoadURL) (env, obj, webShellPtr, urlString); } +/* + * Class: org_mozilla_webclient_wrapper_0005fnative_NavigationImpl + * Method: nativeLoadFromStream + * Signature: (ILjava/io/InputStream;Ljava/lang/String;Ljava/lang/String;ILjava/util/Properties;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl_nativeLoadFromStream + (JNIEnv *env, jobject obj, jint webShellPtr, jobject javaStream, + jstring absoluteUrl, jstring contentType, jint contentLength, + jobject loadProperties) +{ + (* nativeLoadFromStream) (env, obj, webShellPtr, javaStream, absoluteUrl, + contentType, contentLength, loadProperties); +} /* * Class: org_mozilla_webclient_wrapper_0005fnative_NavigationImpl * Method: nativeRefresh @@ -773,6 +839,12 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl (* nativeStop) (env, obj, webShellPtr); } +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_wrapper_1native_NavigationImpl_nativeSetPrompt +(JNIEnv *env, jobject obj, jint webShellPtr, jobject userPrompt) +{ + (* nativeSetPrompt) (env, obj, webShellPtr, userPrompt); +} // RDFEnumeration @@ -857,11 +929,21 @@ Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeGetIndex JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeInsertElementAt (JNIEnv *env, jobject obj, jint webShellPtr, jint parentRDFNode, - jint childRDFNode, jint childIndex) { + jint childRDFNode, jobject childProps, jint childIndex) { (* nativeInsertElementAt) (env, obj, webShellPtr, parentRDFNode, - childRDFNode, childIndex); + childRDFNode, childProps, childIndex); } +JNIEXPORT jint JNICALL +Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeNewFolder +(JNIEnv *env, jobject obj, jint webShellPtr, jint parentRDFNode, + jobject childProps) +{ + return (* nativeNewFolder) (env, obj, webShellPtr, + parentRDFNode, childProps); +} + + /* * Class: org_mozilla_webclient_wrapper_0005fnative_RDFTreeNode * Method: nativeIsContainer diff --git a/mozilla/java/webclient/src_moz/nsActions.cpp b/mozilla/java/webclient/src_moz/nsActions.cpp index 5162e596798..a9606a90926 100644 --- a/mozilla/java/webclient/src_moz/nsActions.cpp +++ b/mozilla/java/webclient/src_moz/nsActions.cpp @@ -32,37 +32,8 @@ */ #include "nsActions.h" -#include "nsCOMPtr.h" -#include "nsIContentViewer.h" -#include "nsIBaseWindow.h" -#include "nsISHEntry.h" -#include "nsIURI.h" -#include "nsIDocShellTreeItem.h" -#include "nsIWebNavigation.h" -#include "nsIFindComponent.h" -#include "nsISearchContext.h" -#include "nsIContentViewerEdit.h" -#include "ns_util.h" -#include "rdf_util.h" - -#include "nsEmbedAPI.h" // for NS_TermEmbedding - -#include "nsRDFCID.h" // for NS_RDFCONTAINER_CID - -static NS_DEFINE_CID(kRDFContainerCID, NS_RDFCONTAINER_CID); - -// -// Local function prototypes -// - -/** - - * pull the int for the field nativeEnum from the java object obj. - - */ - -jint getNativeEnumFromJava(JNIEnv *env, jobject obj, jint nativeRDFNode); +#include "nscore.h" void * handleEvent (PLEvent * event); void destroyEvent (PLEvent * event); @@ -103,1333 +74,4 @@ nsActionEvent::nsActionEvent () (PLDestroyEventProc) ::destroyEvent); } -wsHistoryActionEvent::wsHistoryActionEvent(nsISHistory *yourHistory) -{ - mHistory = yourHistory; -} -/* - * wsResizeEvent - */ - -wsResizeEvent::wsResizeEvent(nsIBaseWindow* baseWindow, PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h) : - nsActionEvent(), - mBaseWindow(baseWindow), - mLeft(x), - mBottom(y), - mWidth(w), - mHeight(h) -{ -} - - -void * -wsResizeEvent::handleEvent () -{ - nsresult rv = NS_ERROR_FAILURE; - if (mBaseWindow) { - - rv = mBaseWindow->SetPositionAndSize(mLeft, mBottom, mWidth, mHeight, - PR_TRUE); - - - return (void *) rv; - } - return nsnull; -} // handleEvent() - - - - -/* - * wsLoadURLEvent - */ - -wsLoadURLEvent::wsLoadURLEvent(nsIWebNavigation* webNavigation, PRUnichar * urlString, PRInt32 urlLength) : - nsActionEvent(), - mWebNavigation(webNavigation), - mURL(nsnull) -{ - mURL = new nsString(urlString, urlLength); -} - - -void * -wsLoadURLEvent::handleEvent () -{ - if (mWebNavigation && mURL) { - nsresult rv = mWebNavigation->LoadURI(mURL->GetUnicode(), nsIWebNavigation::LOAD_FLAGS_NONE); - } - return nsnull; -} // handleEvent() - - -wsLoadURLEvent::~wsLoadURLEvent () -{ - if (mURL != nsnull) - delete mURL; -} - - - -/* - * wsStopEvent - */ - -wsStopEvent::wsStopEvent(nsIWebNavigation* webNavigation) : - nsActionEvent(), - mWebNavigation(webNavigation) -{ -} - - -void * -wsStopEvent::handleEvent () -{ - if (mWebNavigation) { - nsresult rv = mWebNavigation->Stop(); - } - return nsnull; -} // handleEvent() - - - -/* - * wsShowEvent - */ - -wsShowEvent::wsShowEvent(nsIBaseWindow* baseWindow, PRBool state) : - nsActionEvent(), - mBaseWindow(baseWindow), - mState(state) -{ -} - - -void * -wsShowEvent::handleEvent () -{ - if (mBaseWindow) { - mBaseWindow->SetVisibility(mState); - } - return nsnull; -} // handleEvent() - - - -/* - * wsHideEvent - */ - -wsHideEvent::wsHideEvent(nsIBaseWindow* baseWindow) : - nsActionEvent(), - mBaseWindow(baseWindow) -{ -} - - -void * -wsHideEvent::handleEvent () -{ - if (mBaseWindow) { - mBaseWindow->SetVisibility(PR_FALSE); - } - return nsnull; -} // handleEvent() - - - -/* - * wsMoveToEvent - */ - -wsMoveToEvent::wsMoveToEvent(nsIBaseWindow* baseWindow, PRInt32 x, PRInt32 y) : - nsActionEvent(), - mBaseWindow(baseWindow), - mX(x), - mY(y) -{ -} - - -void * -wsMoveToEvent::handleEvent () -{ - if (mBaseWindow) { - nsresult rv = mBaseWindow->SetPosition(mX, mY); - } - return nsnull; -} // handleEvent() - - -/* - * wsSetFocusEvent - */ - -wsSetFocusEvent::wsSetFocusEvent(nsIBaseWindow* baseWindow) : - nsActionEvent(), - mBaseWindow(baseWindow) -{ -} - - -void * -wsSetFocusEvent::handleEvent () -{ - if (mBaseWindow) { - nsresult rv = mBaseWindow->SetFocus(); - } - return nsnull; -} // handleEvent() - - - -/* - * wsRemoveFocusEvent - */ - -wsRemoveFocusEvent::wsRemoveFocusEvent(nsIBaseWindow* baseWindow) : - nsActionEvent(), - mBaseWindow(baseWindow) -{ -} - - -void * -wsRemoveFocusEvent::handleEvent () -{ - if (mBaseWindow) { - //PENDING (Ashu) : No removeFocus functionality provided in M15 - // nsresult rv = mWebShell->RemoveFocus(); - } - return nsnull; -} // handleEvent() - - - -/* - * wsRepaintEvent - */ - -wsRepaintEvent::wsRepaintEvent(nsIBaseWindow* baseWindow, PRBool forceRepaint) : - nsActionEvent(), - mBaseWindow(baseWindow), - mForceRepaint(forceRepaint) -{ -} - - -void * -wsRepaintEvent::handleEvent () -{ - if (mBaseWindow) { - nsresult rv = mBaseWindow->Repaint(mForceRepaint); - } - return nsnull; -} // handleEvent() - - - -/* - * wsCanBackEvent - */ - -wsCanBackEvent::wsCanBackEvent(nsIWebNavigation* webNavigation) : - nsActionEvent(), - mWebNavigation(webNavigation) -{ - -} - -void * -wsCanBackEvent::handleEvent () -{ - void *result = nsnull; - if (mWebNavigation) { - nsresult rv; - PRBool canGoBack; - - rv = mWebNavigation->GetCanGoBack(&canGoBack); - - if (NS_FAILED(rv)) { - return result; - } - - result = (void *)canGoBack; - } - return result; -} // handleEvent() - -/* - * wsCanForwardEvent - */ - -wsCanForwardEvent::wsCanForwardEvent(nsIWebNavigation* webNavigation) : - nsActionEvent(), - mWebNavigation(webNavigation) -{ - -} - - -void * -wsCanForwardEvent::handleEvent () -{ - void *result = nsnull; - if (mWebNavigation) { - nsresult rv; - PRBool canGoForward; - - rv = mWebNavigation->GetCanGoForward(&canGoForward); - - if (NS_FAILED(rv)) { - return result; - } - - result = (void *)canGoForward; - - } - return result; -} // handleEvent() - - - -/* - * wsBackEvent - */ - -wsBackEvent::wsBackEvent(nsIWebNavigation* webNavigation) : - nsActionEvent(), - mWebNavigation(webNavigation) -{ -} - - -void * -wsBackEvent::handleEvent () -{ - void *result = nsnull; - if (mWebNavigation) { - nsresult rv = mWebNavigation->GoBack(); - - result = (void *) rv; - } - return result; -} // handleEvent() - - - -/* - * wsForwardEvent - */ - -wsForwardEvent::wsForwardEvent(nsIWebNavigation* webNavigation) : - nsActionEvent(), - mWebNavigation(webNavigation) -{ -} - - -void * -wsForwardEvent::handleEvent () -{ - void *result = nsnull; - if (mWebNavigation) { - - nsresult rv = mWebNavigation->GoForward(); - result = (void *) rv; - } - return result; -} // handleEvent() - - - -/* - * wsGoToEvent - */ - -wsGoToEvent::wsGoToEvent(nsIWebNavigation* webNavigation, PRInt32 historyIndex) : - nsActionEvent(), - mWebNavigation(webNavigation), mHistoryIndex(historyIndex) -{ -} - - -void * -wsGoToEvent::handleEvent () -{ - void *result = nsnull; - nsresult rv = nsnull; - if (mWebNavigation) { - //PENDING (Ashu) : GoTo Functionality seems to be missing in M15 - // nsresult rv = mHistory->Goto(mHistoryIndex, mWebShell, PR_TRUE); - result = (void *) rv; - } - return result; -} // handleEvent() - - - -/* - * wsGetHistoryLengthEvent - */ - -wsGetHistoryLengthEvent::wsGetHistoryLengthEvent(nsISHistory * sHistory) : - nsActionEvent(), - mHistory(sHistory) -{ -} - - -void * -wsGetHistoryLengthEvent::handleEvent () -{ - void *result = nsnull; - if (mHistory) { - PRInt32 historyLength = 0; - - nsresult rv = mHistory->GetCount(&historyLength); - result = (void *) historyLength; - } - return result; -} // handleEvent() - - - -/* - * wsGetHistoryIndexEvent - */ - -wsGetHistoryIndexEvent::wsGetHistoryIndexEvent(nsISHistory * sHistory) : - nsActionEvent(), - mHistory(sHistory) -{ -} - - -void * -wsGetHistoryIndexEvent::handleEvent () -{ - void *result = nsnull; - if (mHistory) { - PRInt32 historyIndex = 0; - - nsresult rv = mHistory->GetIndex(&historyIndex); - result = (void *) historyIndex; - } - return result; -} // handleEvent() - - - -/* - * wsGetURLEvent - */ - -wsGetURLEvent::wsGetURLEvent(nsISHistory * sHistory) : - nsActionEvent(), - mHistory(sHistory) -{ -} - - -void * -wsGetURLEvent::handleEvent () -{ - void *result = nsnull; - if (mHistory) { - - - PRInt32 currentIndex; - char *currentURL = nsnull; - nsresult rv; - - rv = mHistory->GetIndex(¤tIndex); - - if (NS_FAILED(rv)) { - return result; - } - - nsISHEntry * Entry; - rv = mHistory->GetEntryAtIndex(currentIndex, PR_FALSE, &Entry); - - if (NS_FAILED(rv)) { - return result; - } - - nsIURI * URI; - rv = Entry->GetURI(&URI); - - if (NS_FAILED(rv)) { - return result; - } - - rv = URI->GetSpec(¤tURL); - if (NS_FAILED(rv)) { - return result; - } - - result = (void *) currentURL; - } - return result; -} // handleEvent() - -/* - * wsGetURLForIndexEvent - */ - -wsGetURLForIndexEvent::wsGetURLForIndexEvent(nsISHistory * sHistory, - PRInt32 historyIndex) : - nsActionEvent(), - mHistory(sHistory), - mHistoryIndex(historyIndex) -{ -} - - -void * -wsGetURLForIndexEvent::handleEvent () -{ - void *result = nsnull; - if (mHistory) { - nsresult rv; - char *indexURL = nsnull; - - nsISHEntry * Entry; - rv = mHistory->GetEntryAtIndex(mHistoryIndex, PR_FALSE, &Entry); - if (NS_FAILED(rv)) { - return result; - } - - nsIURI * URI; - rv = Entry->GetURI(&URI); - - if (NS_FAILED(rv)) { - return result; - } - - rv = URI->GetSpec(&indexURL); - if (NS_FAILED(rv)) { - return result; - } - - result = (void *) indexURL; - } - return result; -} // handleEvent() - - - -// Added by Mark Goddard OTMP 9/2/1999 - -/* - * wsRefreshEvent - */ - -wsRefreshEvent::wsRefreshEvent(nsIWebNavigation* webNavigation, PRInt32 reloadType) : - nsActionEvent(), - mWebNavigation(webNavigation), - mReloadType(reloadType) -{ - -} - - -void * -wsRefreshEvent::handleEvent () -{ - if (mWebNavigation) { - nsresult rv = mWebNavigation->Reload(mReloadType); - return (void *) rv; - } - return nsnull; -} // handleEvent() - - - -wsViewSourceEvent::wsViewSourceEvent(nsIDocShell* docShell, PRBool viewMode) : - nsActionEvent(), - mDocShell(docShell), - mViewMode(viewMode) -{ -} - -void * -wsViewSourceEvent::handleEvent () -{ - if(mDocShell) { - if(mViewMode) { - nsresult rv = mDocShell->SetViewMode(nsIDocShell::viewSource); - return (void *) rv; - } - else - { - nsresult rv = mDocShell->SetViewMode(nsIDocShell::viewNormal); - return (void *) rv; - } - } - return nsnull; -} - -wsAddDocLoaderObserverEvent::wsAddDocLoaderObserverEvent(nsIDocShell* yourDocShell, - nsIDocumentLoaderObserver *yourObserver) : - nsActionEvent(), - mDocShell(yourDocShell), mDocObserver(yourObserver) -{ -} - -void * -wsAddDocLoaderObserverEvent::handleEvent () -{ - void *result = nsnull; - - if (mDocShell && mDocObserver) { - - nsresult rv = mDocShell->SetDocLoaderObserver(mDocObserver); - result = (void *) rv; - } - return result; -} // handleEvent() - -wsDeallocateInitContextEvent::wsDeallocateInitContextEvent(WebShellInitContext* yourInitContext) : - nsActionEvent(), - mInitContext(yourInitContext) -{ -} - -void * -wsDeallocateInitContextEvent::handleEvent () -{ - void *result = nsnull; - if (!mInitContext) { - return (void *) NS_ERROR_UNEXPECTED; - } - - mInitContext->parentHWnd = nsnull; - - // make sure the webBrowser's contentListener doesn't have a ref to - // CBrowserContainer - mInitContext->webBrowser->SetParentURIContentListener(nsnull); - mInitContext->webBrowser = nsnull; - - // make sure the webShell's container is set to null. - // get the webShell from the docShell - nsCOMPtr webShell(do_QueryInterface(mInitContext->docShell)); - if (webShell) { - webShell->SetContainer(nsnull); - } - - // make sure the docShell's TreeOwner is set to null - // get the docShellTreeItem from the docShell - nsCOMPtr docShellAsItem(do_QueryInterface(mInitContext->docShell)); - if (docShellAsItem) { - docShellAsItem->SetTreeOwner(nsnull); - } - - mInitContext->docShell->SetDocLoaderObserver(nsnull); - - mInitContext->docShell = nsnull; - - // PENDING(edburns): this is a leak. For some reason, webShell's - // refcount is two. I believe it should be one. - // see http://bugzilla.mozilla.org/show_bug.cgi?id=38271 - - mInitContext->webShell = nsnull; - mInitContext->webNavigation = nsnull; - mInitContext->presShell = nsnull; - mInitContext->sHistory = nsnull; - mInitContext->baseWindow = nsnull; - - mInitContext->embeddedThread = nsnull; - mInitContext->env = nsnull; - if (nsnull != mInitContext->nativeEventThread) { - ::util_DeleteGlobalRef((JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION), - mInitContext->nativeEventThread); - mInitContext->nativeEventThread = nsnull; - } - mInitContext->stopThread = -1; - mInitContext->initComplete = FALSE; - mInitContext->initFailCode = 0; - mInitContext->x = -1; - mInitContext->y = -1; - mInitContext->w = -1; - mInitContext->h = -1; - mInitContext->gtkWinPtr = nsnull; - mInitContext->searchContext = nsnull; - - // make sure we aren't listening anymore. This needs to be done - // before currentDocument = nsnull - mInitContext->browserContainer->RemoveAllListeners(); - - mInitContext->currentDocument = nsnull; - mInitContext->browserContainer = nsnull; - util_DeallocateShareInitContext(&(mInitContext->shareContext)); - - // delete mInitContext; - NS_TermEmbedding(); - return (void *) NS_OK; -} // handleEvent() - -wsInitBookmarksEvent::wsInitBookmarksEvent(WebShellInitContext* yourInitContext) : - nsActionEvent(), - mInitContext(yourInitContext) -{ -} - -void * -wsInitBookmarksEvent::handleEvent () -{ - void *result = nsnull; - if (!mInitContext) { - return (void *) NS_ERROR_UNEXPECTED; - } - nsresult rv; - rv = rdf_InitRDFUtils(); - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); - - if (NS_FAILED(rv)) { - ::util_ThrowExceptionToJava(env, "Exception: can't initialize RDF Utils"); - return (void *) result; - } - result = (void *) kNC_BookmarksRoot.get(); - - return result; -} // handleEvent() - - -wsNewRDFNodeEvent::wsNewRDFNodeEvent(WebShellInitContext* yourInitContext, - const char * yourUrlString, - PRBool yourIsFolder) : - nsActionEvent(), - mInitContext(yourInitContext), mUrlString(yourUrlString), - mIsFolder(yourIsFolder) -{ -} - -void * -wsNewRDFNodeEvent::handleEvent () -{ - void *result = nsnull; - if (!mInitContext) { - return (void *) NS_ERROR_UNEXPECTED; - } - nsresult rv; - nsCOMPtr newNode; - nsCAutoString uri("NC:BookmarksRoot"); - JNIEnv *env = (JNIEnv*) JNU_GetEnv(gVm, JNI_VERSION); - - const char *url = mUrlString; - uri.Append("#$"); - uri.Append(url); - PRUnichar *uriUni = uri.ToNewUnicode(); - - rv = gRDF->GetUnicodeResource(uriUni, getter_AddRefs(newNode)); - nsCRT::free(uriUni); - if (NS_FAILED(rv)) { - ::util_ThrowExceptionToJava(env, "Exception: nativeNewRDFNode: can't create new nsIRDFResource."); - return result; - } - - if (mIsFolder) { - rv = gRDFCU->MakeSeq(gBookmarksDataSource, newNode, nsnull); - if (NS_FAILED(rv)) { - ::util_ThrowExceptionToJava(env, "Exception: unable to make new folder as a sequence."); - return result; - } - rv = gBookmarksDataSource->Assert(newNode, kRDF_type, - kNC_Folder, PR_TRUE); - if (rv != NS_OK) { - ::util_ThrowExceptionToJava(env, "Exception: unable to mark new folder as folder."); - - return result; - } - } - - /* - - * Do the AddRef here. - - */ - - result = (void *)newNode.get(); - ((nsISupports *)result)->AddRef(); - - return result; -} // handleEvent() - -wsRDFIsContainerEvent::wsRDFIsContainerEvent(WebShellInitContext* yourInitContext, - PRUint32 yourNativeRDFNode) : - nsActionEvent(), - mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode) -{ -} - -void * -wsRDFIsContainerEvent::handleEvent () -{ - if (!mInitContext) { - return (void *) NS_ERROR_UNEXPECTED; - } - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); - nsCOMPtr node = (nsIRDFNode *) mNativeRDFNode; - nsCOMPtr nodeResource; - nsresult rv; - jboolean result = JNI_FALSE; - PRBool prBool; - - rv = node->QueryInterface(NS_GET_IID(nsIRDFResource), - getter_AddRefs(nodeResource)); - if (NS_FAILED(rv)) { - ::util_ThrowExceptionToJava(env, "Exception: nativeIsContainer: nativeRDFNode is not an RDFResource."); - return nsnull; - } - rv = gRDFCU->IsContainer(gBookmarksDataSource, nodeResource, - &prBool); - result = (prBool == PR_FALSE) ? JNI_FALSE : JNI_TRUE; - - return (void *) result; -} // handleEvent() - -void * -wsFindEvent::handleEvent () -{ - void *result = nsnull; - - if (mFindComponent && mSearchContext) { - PRBool found = PR_TRUE; - nsresult rv = mFindComponent->FindNext(mSearchContext, &found); - result = (void *) rv; - } - return result; -} - -wsFindEvent::wsFindEvent(nsIFindComponent * findcomponent, nsISearchContext * srchcontext) : - nsActionEvent(), - mFindComponent(findcomponent), - mSearchContext(srchcontext) -{ -} - -wsRDFGetChildAtEvent::wsRDFGetChildAtEvent(WebShellInitContext* yourInitContext, - PRUint32 yourNativeRDFNode, - PRUint32 yourChildIndex) : - nsActionEvent(), - mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode), - mChildIndex(yourChildIndex) -{ -} - -void * -wsRDFGetChildAtEvent::handleEvent () -{ - if (!mInitContext) { - return (void *) NS_ERROR_UNEXPECTED; - } - jint result = -1; - nsresult rv; - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); - // PENDING(edburns): assert rdf_InitRDFUtils() - nsCOMPtr parent = (nsIRDFResource *) mNativeRDFNode; - nsCOMPtr child; - - rv = rdf_getChildAt(mChildIndex, parent, getter_AddRefs(child)); - if (NS_FAILED(rv)) { - ::util_ThrowExceptionToJava(env, "Exception: nativeGetChildAt: Can't get child."); - return nsnull; - } - result = (jint)child.get(); - ((nsISupports *)result)->AddRef(); - return (void *) result; -} // handleEvent() - -wsRDFGetChildCountEvent::wsRDFGetChildCountEvent(WebShellInitContext* yourInitContext, - PRUint32 yourNativeRDFNode) : - nsActionEvent(), - mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode) -{ -} - -void * -wsRDFGetChildCountEvent::handleEvent () -{ - if (!mInitContext) { - return (void *) NS_ERROR_UNEXPECTED; - } - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); - jint result = -1; - PRInt32 count; - nsresult rv; - // PENDING(edburns): assert rdf_InitRDFUtils() - nsCOMPtr parent = (nsIRDFResource *) mNativeRDFNode; - - rv = rdf_getChildCount(parent, &count); - if (NS_FAILED(rv)) { - ::util_ThrowExceptionToJava(env, "Exception: nativeGetChildCount: Can't get child count."); - return nsnull; - } - result = (jint)count; - return (void *) result; -} // handleEvent() - -wsRDFGetChildIndexEvent::wsRDFGetChildIndexEvent(WebShellInitContext* yourInitContext, - PRUint32 yourNativeRDFNode, - PRUint32 yourChildRDFNode) : - nsActionEvent(), - mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode), - mChildRDFNode(yourChildRDFNode) -{ -} - -void * -wsRDFGetChildIndexEvent::handleEvent () -{ - if (!mInitContext) { - return (void *) NS_ERROR_UNEXPECTED; - } - jint result = -1; - PRInt32 index; - nsresult rv; - // PENDING(edburns): assert rdf_InitRDFUtils() - nsCOMPtr parent = (nsIRDFResource *) mNativeRDFNode; - nsCOMPtr child = (nsIRDFResource *) mChildRDFNode; - - rv = rdf_getIndexOfChild(parent, child, &index); - result = (jint) index; - - return (void *) result; -} // handleEvent() - -void * -wsSelectAllEvent::handleEvent () -{ - void *result = nsnull; - - if (mContentViewerEdit) { - nsresult rv = mContentViewerEdit->SelectAll(); - result = (void *) rv; - } - return result; -} - -wsSelectAllEvent::wsSelectAllEvent(nsIContentViewerEdit * contentViewerEdit) : - nsActionEvent(), - mContentViewerEdit(contentViewerEdit) -{ -} - -wsRDFToStringEvent::wsRDFToStringEvent(WebShellInitContext* yourInitContext, - PRUint32 yourNativeRDFNode) : - nsActionEvent(), - mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode) -{ -} - -void * -wsRDFToStringEvent::handleEvent () -{ - if (!mInitContext) { - return (void *) NS_ERROR_UNEXPECTED; - } - nsCOMPtr currentResource = - (nsIRDFResource *) mNativeRDFNode; - nsCOMPtr node; - nsCOMPtr literal; - jstring result = nsnull; - PRBool isContainer = PR_FALSE; - nsresult rv; - const PRUnichar *textForNode = nsnull; - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); - - rv = gRDFCU->IsContainer(gBookmarksDataSource, currentResource, - &isContainer); - if (NS_FAILED(rv)) { - ::util_ThrowExceptionToJava(env, "Exception: nativeToString: Can't tell if RDFResource is container."); - return nsnull; - } - - if (isContainer) { - // It's a bookmarks folder - rv = gBookmarksDataSource->GetTarget(currentResource, - kNC_Name, PR_TRUE, - getter_AddRefs(node)); - // get the name of the folder - if (rv == 0) { - // if so, make sure it's an nsIRDFLiteral - rv = node->QueryInterface(NS_GET_IID(nsIRDFLiteral), - getter_AddRefs(literal)); - if (NS_SUCCEEDED(rv)) { - rv = literal->GetValueConst(&textForNode); - } - else { - if (prLogModuleInfo) { - PR_LOG(prLogModuleInfo, 3, - ("nativeToString: node is not an nsIRDFLiteral.\n")); - } - } - } - } - else { - // It's a bookmark or a Separator - rv = gBookmarksDataSource->GetTarget(currentResource, - kNC_URL, PR_TRUE, - getter_AddRefs(node)); - // See if it has a Name - if (0 != rv) { - rv = gBookmarksDataSource->GetTarget(currentResource, - kNC_Name, PR_TRUE, - getter_AddRefs(node)); - } - - if (0 == rv) { - rv = node->QueryInterface(NS_GET_IID(nsIRDFLiteral), - getter_AddRefs(literal)); - if (NS_SUCCEEDED(rv)) { - // get the value of the literal - rv = literal->GetValueConst(&textForNode); - if (NS_FAILED(rv)) { - if (prLogModuleInfo) { - PR_LOG(prLogModuleInfo, 3, - ("nativeToString: node doesn't have a value.\n")); - } - } - } - else { - if (prLogModuleInfo) { - PR_LOG(prLogModuleInfo, 3, - ("nativeToString: node is not an nsIRDFLiteral.\n")); - } - } - } - else { - if (prLogModuleInfo) { - PR_LOG(prLogModuleInfo, 3, - ("nativeToString: node doesn't have a URL.\n")); - } - } - } - - if (nsnull != textForNode) { - nsString * string = new nsString(textForNode); - int length = 0; - if (nsnull != string) { - length = string->Length(); - } - - result = ::util_NewString(env, (const jchar *) textForNode, length); - } - else { - result = ::util_NewStringUTF(env, ""); - } - - return (void *) result; -} // handleEvent() - -wsRDFInsertElementAtEvent::wsRDFInsertElementAtEvent(WebShellInitContext* yourInitContext, - PRUint32 yourParentRDFNode, - PRUint32 yourChildRDFNode, - PRUint32 yourChildIndex) : - nsActionEvent(), - mInitContext(yourInitContext), mParentRDFNode(yourParentRDFNode), - mChildRDFNode(yourChildRDFNode), mChildIndex(yourChildIndex) -{ -} - -void * -wsRDFInsertElementAtEvent::handleEvent () -{ - if (!mInitContext) { - return (void *) NS_ERROR_UNEXPECTED; - } - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); - nsCOMPtr parent = (nsIRDFResource *) mParentRDFNode; - nsCOMPtr newChild = (nsIRDFResource *) mChildRDFNode; - nsCOMPtr container; - nsresult rv; - PRBool isContainer; - - rv = gRDFCU->IsContainer(gBookmarksDataSource, parent, - &isContainer); - if (NS_FAILED(rv)) { - ::util_ThrowExceptionToJava(env, "Exception: nativeNewRDFNode: RDFResource is not a container."); - return (void *) NS_ERROR_UNEXPECTED; - } - - PR_ASSERT(gComponentManager); - - // get a container in order to create a child - rv = gComponentManager->CreateInstance(kRDFContainerCID, - nsnull, - NS_GET_IID(nsIRDFContainer), - getter_AddRefs(container)); - if (NS_FAILED(rv)) { - ::util_ThrowExceptionToJava(env, "Exception: nativeNewRDFNode: can't create container."); - return (void *) NS_ERROR_UNEXPECTED; - } - rv = container->Init(gBookmarksDataSource, parent); - if (NS_FAILED(rv)) { - ::util_ThrowExceptionToJava(env, "Exception: nativeNewRDFNode: can't create container."); - return (void *) NS_ERROR_UNEXPECTED; - } - - rv = container->InsertElementAt(newChild, mChildIndex, PR_TRUE); - if (NS_FAILED(rv)) { - ::util_ThrowExceptionToJava(env, "Exception: nativeNewRDFNode: can't insert element into parent container."); - return (void *) NS_ERROR_UNEXPECTED; - } - - return (void *) NS_OK; -} // handleEvent() - -wsRDFHasMoreElementsEvent::wsRDFHasMoreElementsEvent(WebShellInitContext* yourInitContext, - PRUint32 yourNativeRDFNode, - void *yourJobject) : - nsActionEvent(), - mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode), - mJobject(yourJobject) -{ -} - -void * -wsRDFHasMoreElementsEvent::handleEvent () -{ - if (!mInitContext) { - return (void *) NS_ERROR_UNEXPECTED; - } - nsresult rv; - jboolean result = JNI_FALSE; - PRBool prResult = PR_FALSE; - // assert -1 != nativeRDFNode - jint nativeEnum; - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); - - if (-1 == (nativeEnum = getNativeEnumFromJava(env, (jobject) mJobject, - mNativeRDFNode))) { - ::util_ThrowExceptionToJava(env, "Exception: nativeHasMoreElements: Can't get nativeEnum from nativeRDFNode."); - return (void *) NS_ERROR_UNEXPECTED; - } - - nsCOMPtr enumerator = (nsISimpleEnumerator *)nativeEnum; - rv = enumerator->HasMoreElements(&prResult); - if (NS_FAILED(rv)) { - ::util_ThrowExceptionToJava(env, "Exception: nativeHasMoreElements: Can't ask nsISimpleEnumerator->HasMoreElements()."); - return (void *) NS_ERROR_UNEXPECTED; - } - result = (PR_FALSE == prResult) ? JNI_FALSE : JNI_TRUE; - - return (void *) result; - -} // handleEvent() - -wsRDFNextElementEvent::wsRDFNextElementEvent(WebShellInitContext* yourInitContext, - PRUint32 yourNativeRDFNode, - void *yourJobject) : - nsActionEvent(), - mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode), - mJobject(yourJobject) -{ -} - -void * -wsRDFNextElementEvent::handleEvent () -{ - if (!mInitContext) { - return (void *) NS_ERROR_UNEXPECTED; - } - nsresult rv; - jint result = -1; - PRBool hasMoreElements = PR_FALSE; - // assert -1 != nativeRDFNode - jint nativeEnum; - nsCOMPtr supportsResult; - nsCOMPtr nodeResult; - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); - - if (-1 == (nativeEnum = getNativeEnumFromJava(env, (jobject) mJobject, - mNativeRDFNode))) { - ::util_ThrowExceptionToJava(env, "Exception: nativeNextElement: Can't get nativeEnum from nativeRDFNode."); - return (void *) NS_ERROR_UNEXPECTED; - } - - nsCOMPtr enumerator = (nsISimpleEnumerator *)nativeEnum; - rv = enumerator->HasMoreElements(&hasMoreElements); - if (NS_FAILED(rv)) { - ::util_ThrowExceptionToJava(env, "Exception: nativeNextElement: Can't ask nsISimpleEnumerator->HasMoreElements()."); - return (void *) NS_ERROR_UNEXPECTED; - } - - if (!hasMoreElements) { - return (void *) NS_ERROR_UNEXPECTED; - } - - rv = enumerator->GetNext(getter_AddRefs(supportsResult)); - if (NS_FAILED(rv)) { - if (prLogModuleInfo) { - PR_LOG(prLogModuleInfo, 3, - ("Exception: nativeNextElement: Can't get next from enumerator.\n")); - } - return (void *) NS_ERROR_UNEXPECTED; - } - - // make sure it's an RDFNode - rv = supportsResult->QueryInterface(NS_GET_IID(nsIRDFNode), - getter_AddRefs(nodeResult)); - if (NS_FAILED(rv)) { - if (prLogModuleInfo) { - PR_LOG(prLogModuleInfo, 3, - ("Exception: nativeNextElement: next from enumerator is not an nsIRDFNode.\n")); - } - return (void *) NS_ERROR_UNEXPECTED; - } - - result = (jint)nodeResult.get(); - ((nsISupports *)result)->AddRef(); - return (void *) result; -} // handleEvent() - -void * -wsCopySelectionEvent::handleEvent () -{ - void *result = nsnull; - - if (mContentViewerEdit) { - nsresult rv = mContentViewerEdit->CopySelection(); - result = (void *) rv; - } - return result; -} - -wsCopySelectionEvent::wsCopySelectionEvent(nsIContentViewerEdit * contentViewerEdit) : - nsActionEvent(), - mContentViewerEdit(contentViewerEdit) -{ -} - -wsRDFFinalizeEvent::wsRDFFinalizeEvent(void *yourJobject) : - nsActionEvent(), - mJobject(yourJobject) -{ -} - -void * -wsRDFFinalizeEvent::handleEvent () -{ - if (!mJobject) { - return (void *) NS_ERROR_UNEXPECTED; - } - jint nativeEnum, nativeContainer; - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); - - // release the nsISimpleEnumerator - if (-1 == (nativeEnum = - ::util_GetIntValueFromInstance(env, (jobject) mJobject, - "nativeEnum"))) { - if (prLogModuleInfo) { - PR_LOG(prLogModuleInfo, 3, - ("nativeFinalize: Can't get fieldID for nativeEnum.\n")); - } - return (void *) NS_ERROR_UNEXPECTED; - } - nsCOMPtr enumerator = - (nsISimpleEnumerator *) nativeEnum; - ((nsISupports *)enumerator.get())->Release(); - - // release the nsIRDFContainer - if (-1 == (nativeContainer = - ::util_GetIntValueFromInstance(env, (jobject) mJobject, - "nativeContainer"))) { - if (prLogModuleInfo) { - PR_LOG(prLogModuleInfo, 3, - ("nativeFinalize: Can't get fieldID for nativeContainerFieldID.\n")); - } - return (void *) NS_ERROR_UNEXPECTED; - } - nsCOMPtr container = - (nsIRDFContainer *) nativeContainer; - ((nsISupports *)container.get())->Release(); - - return (void *) NS_OK; -} // handleEvent() - -// -// Local functions -// - -jint getNativeEnumFromJava(JNIEnv *env, jobject obj, jint nativeRDFNode) -{ - nsresult rv; - jint result = -1; - - result = ::util_GetIntValueFromInstance(env, obj, "nativeEnum"); - - // if the field has been initialized, just return the value - if (-1 != result) { - // NORMAL EXIT 1 - return result; - } - - // else, we need to create the enum - nsCOMPtr node = (nsIRDFNode *) nativeRDFNode; - nsCOMPtr nodeResource; - nsCOMPtr container; - nsCOMPtr enumerator; - - rv = node->QueryInterface(NS_GET_IID(nsIRDFResource), - getter_AddRefs(nodeResource)); - if (NS_FAILED(rv)) { - if (prLogModuleInfo) { - PR_LOG(prLogModuleInfo, 3, - ("getNativeEnumFromJava: Argument nativeRDFNode isn't an nsIRDFResource.\n")); - } - return -1; - } - - PR_ASSERT(gComponentManager); - - // get a container in order to get the enum - rv = gComponentManager->CreateInstance(kRDFContainerCID, - nsnull, - NS_GET_IID(nsIRDFContainer), - getter_AddRefs(container)); - if (NS_FAILED(rv)) { - if (prLogModuleInfo) { - PR_LOG(prLogModuleInfo, 3, - ("recursiveResourceTraversal: can't get a new container\n")); - } - return -1; - } - - rv = container->Init(gBookmarksDataSource, nodeResource); - if (NS_FAILED(rv)) { - if (prLogModuleInfo) { - PR_LOG(prLogModuleInfo, 3, - ("getNativeEnumFromJava: Can't Init container.\n")); - } - return -1; - } - - rv = container->GetElements(getter_AddRefs(enumerator)); - if (NS_FAILED(rv)) { - if (prLogModuleInfo) { - PR_LOG(prLogModuleInfo, 3, - ("getNativeEnumFromJava: Can't get enumeration from container.\n")); - } - return -1; - } - - // IMPORTANT: Store the enum back into java - ::util_SetIntValueForInstance(env,obj,"nativeEnum",(jint)enumerator.get()); - // IMPORTANT: make sure it doesn't get deleted when it goes out of scope - ((nsISupports *)enumerator.get())->AddRef(); - - // PENDING(edburns): I'm not sure if we need to keep the - // nsIRDFContainer from being destructed in order to maintain the - // validity of the nsISimpleEnumerator that came from the container. - // Just to be safe, I'm doing so. - ::util_SetIntValueForInstance(env, obj, "nativeContainer", - (jint) container.get()); - ((nsISupports *)container.get())->AddRef(); - - // NORMAL EXIT 2 - result = (jint)enumerator.get(); - return result; -} diff --git a/mozilla/java/webclient/src_moz/nsActions.h b/mozilla/java/webclient/src_moz/nsActions.h index 62b7e90fa56..e51c6c2b4c7 100644 --- a/mozilla/java/webclient/src_moz/nsActions.h +++ b/mozilla/java/webclient/src_moz/nsActions.h @@ -32,23 +32,8 @@ #ifndef nsActions_h___ #define nsActions_h___ -#ifndef XP_UNIX -#include -#endif -#include "nsIDocShell.h" -#include "nsIDocumentLoaderObserver.h" -#include "nsIWebShell.h" -#include "nsISHistory.h" -#include "nsIBaseWindow.h" -#include "nsIWebNavigation.h" -#include "nsIFindComponent.h" -#include "nsISearchContext.h" -#include "nsIContentViewerEdit.h" -#include "nsString.h" #include "plevent.h" - - /** * Concrete subclasses of nsActionEvent are used to safely convey an @@ -99,423 +84,8 @@ protected: PLEvent mEvent; }; -class wsHistoryActionEvent : public nsActionEvent { -public: - wsHistoryActionEvent(nsISHistory *yourHistory); - virtual ~wsHistoryActionEvent() {}; -protected: - nsISHistory *mHistory; -}; -class wsResizeEvent : public nsActionEvent { -public: - wsResizeEvent (nsIBaseWindow* baseWindow, PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h); - void * handleEvent (void); - -protected: - nsIBaseWindow * mBaseWindow; - PRInt32 mLeft; - PRInt32 mBottom; - PRInt32 mWidth; - PRInt32 mHeight; -}; - - -class wsLoadURLEvent : public nsActionEvent { -public: - wsLoadURLEvent (nsIWebNavigation* webNavigation, PRUnichar * urlString, PRInt32 urlLength); - ~wsLoadURLEvent (); - void * handleEvent (void); - -protected: - nsIWebNavigation * mWebNavigation; - nsString * mURL; -}; - - -class wsStopEvent : public nsActionEvent { -public: - wsStopEvent (nsIWebNavigation* webNavigation); - void * handleEvent (void); - -protected: - nsIWebNavigation * mWebNavigation; -}; - - - -class wsShowEvent : public nsActionEvent { -public: - wsShowEvent (nsIBaseWindow* baseWindow, PRBool state); - void * handleEvent (void); - -protected: - nsIBaseWindow * mBaseWindow; - PRBool mState; -}; - - - -class wsHideEvent : public nsActionEvent { -public: - wsHideEvent (nsIBaseWindow* baseWindow); - void * handleEvent (void); - -protected: - nsIBaseWindow * mBaseWindow; -}; - - - -class wsMoveToEvent : public nsActionEvent { -public: - wsMoveToEvent (nsIBaseWindow* baseWindow, PRInt32 x, PRInt32 y); - void * handleEvent (void); - -protected: - nsIBaseWindow * mBaseWindow; - PRInt32 mX; - PRInt32 mY; -}; - - - -class wsSetFocusEvent : public nsActionEvent { -public: - wsSetFocusEvent(nsIBaseWindow* baseWindow); - void * handleEvent (void); - -protected: - nsIBaseWindow * mBaseWindow; -}; - - - -class wsRemoveFocusEvent : public nsActionEvent { -public: - wsRemoveFocusEvent(nsIBaseWindow* baseWindow); - void * handleEvent (void); - -protected: - nsIBaseWindow * mBaseWindow; -}; - - - -class wsRepaintEvent : public nsActionEvent { -public: - wsRepaintEvent (nsIBaseWindow* baseWindow, PRBool forceRepaint); - void * handleEvent (void); - -protected: - nsIBaseWindow * mBaseWindow; - PRBool mForceRepaint; -}; - - - -//class wsCanBackEvent : public wsHistoryActionEvent { -class wsCanBackEvent : public nsActionEvent { -public: - wsCanBackEvent (nsIWebNavigation* webNavigation); - void * handleEvent (void); -protected: - nsIWebNavigation * mWebNavigation; -}; - - - -//class wsCanForwardEvent : public wsHistoryActionEvent { -class wsCanForwardEvent : public nsActionEvent { -public: - wsCanForwardEvent(nsIWebNavigation* webNavigation); - void * handleEvent (void); -protected: - nsIWebNavigation * mWebNavigation; -}; - - -class wsBackEvent : public nsActionEvent { -public: - wsBackEvent (nsIWebNavigation* webNavigation); - void * handleEvent (void); - -protected: - nsIWebNavigation * mWebNavigation; -}; - - -class wsForwardEvent : public nsActionEvent { -public: - wsForwardEvent (nsIWebNavigation* webNavigation); - void * handleEvent (void); - -protected: - nsIWebNavigation * mWebNavigation; -}; - - -class wsGoToEvent : public nsActionEvent { -public: - wsGoToEvent (nsIWebNavigation* webNavigation, - PRInt32 historyIndex); - void * handleEvent (void); - -protected: - nsIWebNavigation * mWebNavigation; - PRInt32 mHistoryIndex; -}; - - - -class wsGetHistoryLengthEvent : public nsActionEvent { -public: - wsGetHistoryLengthEvent(nsISHistory * sHistory); - void * handleEvent (void); - -protected: - nsISHistory * mHistory; -}; - - - -class wsGetHistoryIndexEvent : public nsActionEvent { -public: - wsGetHistoryIndexEvent (nsISHistory * sHistory); - void * handleEvent (void); -protected: - nsISHistory * mHistory; -}; - - - -class wsGetURLEvent : public nsActionEvent { -public: - wsGetURLEvent (nsISHistory * sHistory); - void * handleEvent (void); -protected: - nsISHistory * mHistory; -}; - - -class wsGetURLForIndexEvent : public nsActionEvent { -public: - wsGetURLForIndexEvent(nsISHistory * sHistory, - PRInt32 historyIndex); - void * handleEvent (void); - -protected: - nsISHistory * mHistory; - PRInt32 mHistoryIndex; -}; - - - -// added by Mark Goddard OTMP 9/2/1999 -class wsRefreshEvent : public nsActionEvent { -public: - wsRefreshEvent (nsIWebNavigation* webNavigation, - PRInt32 reloadType); - void * handleEvent (void); - -protected: - nsIWebNavigation * mWebNavigation; - PRInt32 mReloadType; -}; - -class wsViewSourceEvent : public nsActionEvent { -public: - wsViewSourceEvent (nsIDocShell * docShell, PRBool viewMode); - void * handleEvent (void); - -protected: - nsIDocShell * mDocShell; - PRBool mViewMode; -}; - - -class wsAddDocLoaderObserverEvent : public nsActionEvent { -public: - wsAddDocLoaderObserverEvent(nsIDocShell *yourDocShell, - nsIDocumentLoaderObserver *yourObserver); - - void * handleEvent (void); - -protected: - nsIDocShell *mDocShell; - nsIDocumentLoaderObserver *mDocObserver; -}; - -struct WebShellInitContext; - -class wsDeallocateInitContextEvent : public nsActionEvent { -public: - wsDeallocateInitContextEvent(WebShellInitContext *yourInitContext); - - void * handleEvent (void); - -protected: - WebShellInitContext *mInitContext; -}; - -class wsInitBookmarksEvent : public nsActionEvent { -public: - wsInitBookmarksEvent(WebShellInitContext *yourInitContext); - void * handleEvent(void); - -protected: - WebShellInitContext *mInitContext; -}; - -class wsFindEvent : public nsActionEvent { -public: - wsFindEvent(nsIFindComponent *findComponent, - nsISearchContext * srchcontext); - void * handleEvent (void); - -protected: - nsIFindComponent * mFindComponent; - nsISearchContext * mSearchContext; -}; - -class wsNewRDFNodeEvent : public nsActionEvent { -public: - wsNewRDFNodeEvent(WebShellInitContext *yourInitContext, - const char *yourUrlString, PRBool yourIsFolder); - void * handleEvent(void); - -protected: - WebShellInitContext *mInitContext; - const char *mUrlString; - PRBool mIsFolder; -}; - -class wsRDFIsContainerEvent : public nsActionEvent { -public: - wsRDFIsContainerEvent(WebShellInitContext *yourInitContext, - PRUint32 yourNativeRDFNode); - void * handleEvent(void); - -protected: - WebShellInitContext *mInitContext; - PRUint32 mNativeRDFNode; -}; - -class wsSelectAllEvent : public nsActionEvent { -public: - wsSelectAllEvent(nsIContentViewerEdit * contentViewerEdit); - void * handleEvent (void); - -protected: - nsIContentViewerEdit * mContentViewerEdit; -}; - -class wsRDFGetChildAtEvent : public nsActionEvent { -public: - wsRDFGetChildAtEvent(WebShellInitContext *yourInitContext, - PRUint32 yourNativeRDFNode, PRUint32 childIndex); - void * handleEvent(void); - -protected: - WebShellInitContext *mInitContext; - PRUint32 mNativeRDFNode; - PRUint32 mChildIndex; -}; - -class wsRDFGetChildCountEvent : public nsActionEvent { -public: - wsRDFGetChildCountEvent(WebShellInitContext *yourInitContext, - PRUint32 yourNativeRDFNode); - void * handleEvent(void); - -protected: - WebShellInitContext *mInitContext; - PRUint32 mNativeRDFNode; -}; - -class wsCopySelectionEvent : public nsActionEvent { -public: - wsCopySelectionEvent(nsIContentViewerEdit * contentViewerEdit); - void * handleEvent (void); - -protected: - nsIContentViewerEdit * mContentViewerEdit; -}; - -class wsRDFGetChildIndexEvent : public nsActionEvent { -public: - wsRDFGetChildIndexEvent(WebShellInitContext *yourInitContext, - PRUint32 yourNativeRDFNode, - PRUint32 yourChildRDFNode); - void * handleEvent(void); - -protected: - WebShellInitContext *mInitContext; - PRUint32 mNativeRDFNode; - PRUint32 mChildRDFNode; -}; - -class wsRDFToStringEvent : public nsActionEvent { -public: - wsRDFToStringEvent(WebShellInitContext *yourInitContext, - PRUint32 yourNativeRDFNode); - void * handleEvent(void); - -protected: - WebShellInitContext *mInitContext; - PRUint32 mNativeRDFNode; -}; - -class wsRDFInsertElementAtEvent : public nsActionEvent { -public: - wsRDFInsertElementAtEvent(WebShellInitContext *yourInitContext, - PRUint32 yourParentRDFNode, - PRUint32 yourChildRDFNode, - PRUint32 yourChildIndex); - void * handleEvent(void); - -protected: - WebShellInitContext *mInitContext; - PRUint32 mParentRDFNode; - PRUint32 mChildRDFNode; - PRUint32 mChildIndex; -}; - -class wsRDFHasMoreElementsEvent : public nsActionEvent { -public: - wsRDFHasMoreElementsEvent(WebShellInitContext *yourInitContext, - PRUint32 mNativeRDFNode, - void *yourJobject); - void * handleEvent(void); - -protected: - WebShellInitContext *mInitContext; - PRUint32 mNativeRDFNode; - void *mJobject; -}; - -class wsRDFNextElementEvent : public nsActionEvent { -public: - wsRDFNextElementEvent(WebShellInitContext *yourInitContext, - PRUint32 mNativeRDFNode, - void *yourJobject); - void * handleEvent(void); - -protected: - WebShellInitContext *mInitContext; - PRUint32 mNativeRDFNode; - void *mJobject; -}; - -class wsRDFFinalizeEvent : public nsActionEvent { -public: - wsRDFFinalizeEvent(void *yourJobject); - void * handleEvent(void); - -protected: - void *mJobject; -}; #endif /* nsActions_h___ */ diff --git a/mozilla/java/webclient/src_moz/ns_util.cpp b/mozilla/java/webclient/src_moz/ns_util.cpp index fad80865fa1..b29848c8481 100644 --- a/mozilla/java/webclient/src_moz/ns_util.cpp +++ b/mozilla/java/webclient/src_moz/ns_util.cpp @@ -46,11 +46,11 @@ const char *gSupportedListenerInterfaces[] = { void util_PostEvent(WebShellInitContext * initContext, PLEvent * event) { - PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + PL_ENTER_EVENT_QUEUE_MONITOR(gActionQueue); - ::PL_PostEvent(initContext->actionQueue, event); + ::PL_PostEvent(gActionQueue, event); - PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + PL_EXIT_EVENT_QUEUE_MONITOR(gActionQueue); } // PostEvent() @@ -58,15 +58,54 @@ void *util_PostSynchronousEvent(WebShellInitContext * initContext, PLEvent * eve { void * voidResult = nsnull; - PL_ENTER_EVENT_QUEUE_MONITOR(initContext->actionQueue); + PL_ENTER_EVENT_QUEUE_MONITOR(gActionQueue); - voidResult = ::PL_PostSynchronousEvent(initContext->actionQueue, event); + voidResult = ::PL_PostSynchronousEvent(gActionQueue, event); - PL_EXIT_EVENT_QUEUE_MONITOR(initContext->actionQueue); + PL_EXIT_EVENT_QUEUE_MONITOR(gActionQueue); return voidResult; } // PostSynchronousEvent() +nsresult util_CreateJstringsFromUnichars(wsStringStruct *strings, + PRInt32 arrayLen) +{ + PR_ASSERT(strings); + int i = 0; + nsAutoString autoStr; + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + + for (i = 0; i < arrayLen; i++) { + autoStr = strings[i].uniStr; + strings[i].jStr = nsnull; + if (autoStr.GetUnicode()) { + strings[i].jStr = ::util_NewString(env, (const jchar *) + autoStr.GetUnicode(), + autoStr.Length()); + if (nsnull == strings[i].jStr) { + return NS_ERROR_NULL_POINTER; + } + } + } + return NS_OK; +} + +nsresult util_DeleteJstringsFromUnichars(wsStringStruct *strings, + PRInt32 arrayLen) +{ + PR_ASSERT(strings); + int i = 0; + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + + for (i = 0; i < arrayLen; i++) { + if (nsnull != strings[i].jStr) { + ::util_DeleteString(env, strings[i].jStr); + strings[i].jStr = nsnull; + } + } + return NS_OK; +} + #ifdef XP_UNIX jint util_GetGTKWinPtrFromCanvas(JNIEnv *env, jobject browserControlCanvas) { diff --git a/mozilla/java/webclient/src_moz/ns_util.h b/mozilla/java/webclient/src_moz/ns_util.h index b3bdce48f06..bbe44882ba3 100644 --- a/mozilla/java/webclient/src_moz/ns_util.h +++ b/mozilla/java/webclient/src_moz/ns_util.h @@ -44,7 +44,6 @@ #include "nsIDocShell.h" // so we can save our nsIDocShell #include "nsIBaseWindow.h" // to get methods like SetVisibility #include "nsIWebNavigation.h" // for all Navigation commands -#include "nsISHistory.h" // for session history #include "nsIPresShell.h" #include "nsIThread.h" // for PRThread #include "nsIWebShell.h" // for nsIWebShell @@ -63,6 +62,13 @@ #endif // +#if defined(XP_UNIX) || defined(XP_MAC) || defined(XP_BEOS) + +#define WC_ITOA(intVal, buf, radix) sprintf(buf, "%d", intVal) +#else +#define WC_ITOA(intVal, buf, radix) itoa(intVal, buf, radix) +#endif + // // local classes // @@ -80,12 +86,11 @@ struct WebShellInitContext { nsCOMPtr webShell; nsCOMPtr docShell; nsCOMPtr baseWindow; - nsCOMPtr sHistory; nsCOMPtr webNavigation; nsCOMPtr presShell; nsCOMPtr webBrowser; - PLEventQueue * actionQueue; - PRThread * embeddedThread; + // PLEventQueue * actionQueue; + // PRThread * embeddedThread; JNIEnv * env; jobject nativeEventThread; int stopThread; @@ -153,6 +158,25 @@ void util_PostEvent (WebShellInitContext * initContext, PLEvent * event); void * util_PostSynchronousEvent (WebShellInitContext * initContext, PLEvent * event); +typedef struct _wsStringStruct { + const PRUnichar *uniStr; + jstring jStr; +} wsStringStruct; + +/** + + * @param strings wsStringStruct []. A null terminated array of + * wsStringStruct instances. On return, the jStr of each element is the + * new jstring. Call util_DeleteJstringsFromUnichars to deallocate. + + */ + +nsresult util_CreateJstringsFromUnichars(wsStringStruct *strings, + PRInt32 arrayLen); + +nsresult util_DeleteJstringsFromUnichars(wsStringStruct *strings, + PRInt32 arrayLen); + // hack functions to get around mozilla oddities #ifdef XP_UNIX jint util_GetGTKWinPtrFromCanvas(JNIEnv *env, jobject browserControlCanvas); diff --git a/mozilla/java/webclient/src_moz/rdf_util.cpp b/mozilla/java/webclient/src_moz/rdf_util.cpp index 160eaeaa36a..bcc6d6e6753 100644 --- a/mozilla/java/webclient/src_moz/rdf_util.cpp +++ b/mozilla/java/webclient/src_moz/rdf_util.cpp @@ -40,9 +40,13 @@ nsCOMPtr gBookmarksDataSource = nsnull; nsCOMPtr kNC_BookmarksRoot = nsnull; nsCOMPtr kNC_Name = nsnull; nsCOMPtr kNC_URL = nsnull; +nsCOMPtr kNC_parent = nsnull; nsCOMPtr kNC_Folder = nsnull; nsCOMPtr kRDF_type = nsnull; +nsCOMPtr kNewFolderCommand; +nsCOMPtr kNewBookmarkCommand; + static NS_DEFINE_CID(kRDFContainerCID, NS_RDFCONTAINER_CID); static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID); @@ -63,6 +67,17 @@ nsresult rdf_InitRDFUtils() if (NS_FAILED(rv)) { return rv; } +#ifdef _WIN32 + + // PENDING(edburns): HACK workaround for bug 59530. This + // workaround forces the nsBookmarksService to leak so that it + // never gets destructed, thus the timer never gets canceled and + // thus the fact that the static nsCOMPtr instance has gone away + // doesn't matter. + + nsIBookmarksService *raw = (nsIBookmarksService *) gBookmarks.get(); + raw->AddRef(); +#endif } if (nsnull == gBookmarksDataSource) { @@ -115,6 +130,13 @@ nsresult rdf_InitRDFUtils() return rv; } } + if (nsnull == kNC_parent) { + rv = gRDF->GetResource("http://home.netscape.com/NC-rdf#parent", + getter_AddRefs(kNC_parent)); + if (NS_FAILED(rv)) { + return rv; + } + } if (nsnull == kNC_Folder) { rv = gRDF->GetResource("http://home.netscape.com/NC-rdf#Folder", getter_AddRefs(kNC_Folder)); @@ -130,6 +152,20 @@ nsresult rdf_InitRDFUtils() return rv; } } + if (nsnull == kNewFolderCommand) { + rv = gRDF->GetResource("http://home.netscape.com/NC-rdf#command?cmd=newfolder", + getter_AddRefs(kNewFolderCommand)); + if (NS_FAILED(rv)) { + return rv; + } + } + if (nsnull == kNewBookmarkCommand) { + rv = gRDF->GetResource("http://home.netscape.com/NC-rdf#command?cmd=newbookmark", + getter_AddRefs(kNewBookmarkCommand)); + if (NS_FAILED(rv)) { + return rv; + } + } rdf_inited = PR_TRUE; return rv; diff --git a/mozilla/java/webclient/src_moz/rdf_util.h b/mozilla/java/webclient/src_moz/rdf_util.h index c0dd4b8db09..f9958163bc1 100644 --- a/mozilla/java/webclient/src_moz/rdf_util.h +++ b/mozilla/java/webclient/src_moz/rdf_util.h @@ -46,9 +46,13 @@ extern nsCOMPtr gBookmarksDataSource; extern nsCOMPtr kNC_BookmarksRoot; extern nsCOMPtr kNC_Name; extern nsCOMPtr kNC_URL; +extern nsCOMPtr kNC_parent; extern nsCOMPtr kNC_Folder; extern nsCOMPtr kRDF_type; +extern nsCOMPtr kNewFolderCommand; +extern nsCOMPtr kNewBookmarkCommand; + nsresult rdf_InitRDFUtils(); void rdf_recursiveResourceTraversal(nsCOMPtr currentResource); void rdf_printArcLabels(nsCOMPtr currentResource); diff --git a/mozilla/java/webclient/src_moz/wcIBrowserContainer.h b/mozilla/java/webclient/src_moz/wcIBrowserContainer.h index 94764aebf2f..a84235bac87 100644 --- a/mozilla/java/webclient/src_moz/wcIBrowserContainer.h +++ b/mozilla/java/webclient/src_moz/wcIBrowserContainer.h @@ -46,18 +46,22 @@ public: NS_IMETHOD AddMouseListener(jobject target) = 0; NS_IMETHOD AddDocumentLoadListener(jobject target) = 0; + NS_IMETHOD SetPrompt(jobject target) = 0; NS_IMETHOD RemoveAllListeners() = 0; NS_IMETHOD RemoveMouseListener() = 0; NS_IMETHOD RemoveDocumentLoadListener() = 0; + NS_IMETHOD GetInstanceCount(PRInt32 *outCount) = 0; }; #define NS_DECL_WCIBROWSERCONTAINER \ NS_IMETHOD AddMouseListener(jobject target); \ NS_IMETHOD AddDocumentLoadListener(jobject target); \ + NS_IMETHOD SetPrompt(jobject target); \ NS_IMETHOD RemoveAllListeners(); \ NS_IMETHOD RemoveMouseListener(); \ - NS_IMETHOD RemoveDocumentLoadListener(); + NS_IMETHOD RemoveDocumentLoadListener(); \ + NS_IMETHOD GetInstanceCount(PRInt32 *outCount); #endif diff --git a/mozilla/java/webclient/src_moz/wsRDFObserver.cpp b/mozilla/java/webclient/src_moz/wsRDFObserver.cpp new file mode 100644 index 00000000000..68c04428728 --- /dev/null +++ b/mozilla/java/webclient/src_moz/wsRDFObserver.cpp @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * + * Contributor(s): Ed Burns + */ + +#include "wsRDFObserver.h" + +#include "rdf_util.h" + +#include "plstr.h" // for PL_strstr + +/////////////////////////////////////////////////////////////////////////////// +// nsISupports implementation + +NS_IMPL_ADDREF(wsRDFObserver) +NS_IMPL_RELEASE(wsRDFObserver) + +NS_INTERFACE_MAP_BEGIN(wsRDFObserver) + NS_INTERFACE_MAP_ENTRY(nsISupports) + NS_INTERFACE_MAP_ENTRY(nsIRDFObserver) +NS_INTERFACE_MAP_END + +wsRDFObserver::wsRDFObserver() +{ + NS_INIT_REFCNT(); +} + +wsRDFObserver::~wsRDFObserver() {} + +// nsIRDFObserver implementation + +NS_IMETHODIMP wsRDFObserver::OnAssert(nsIRDFDataSource *aDataSource, + nsIRDFResource *aSource, + nsIRDFResource *aProperty, + nsIRDFNode *aTarget) +{ + nsresult rv; + nsCOMPtr nodeResource; + PRBool isContainer; + + nodeResource = do_QueryInterface(aTarget); + if (nodeResource) { + rv = gRDFCU->IsContainer(gBookmarksDataSource, nodeResource, + &isContainer); + if (isContainer) { + folder = nodeResource; + } + } + + return NS_OK; +} + +nsIRDFResource *wsRDFObserver::getFolder() +{ + return folder; +} + +NS_IMETHODIMP wsRDFObserver::OnUnassert(nsIRDFDataSource *aDataSource, + nsIRDFResource *aSource, + nsIRDFResource *aProperty, + nsIRDFNode *aTarget) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP wsRDFObserver::OnChange(nsIRDFDataSource *aDataSource, + nsIRDFResource *aSource, + nsIRDFResource *aProperty, + nsIRDFNode *aOldTarget, + nsIRDFNode *aNewTarget) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP wsRDFObserver::OnMove(nsIRDFDataSource *aDataSource, + nsIRDFResource *aOldSource, + nsIRDFResource *aNewSource, + nsIRDFResource *aProperty, + nsIRDFNode *aTarget) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP wsRDFObserver::BeginUpdateBatch(nsIRDFDataSource *aDataSource) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP wsRDFObserver::EndUpdateBatch(nsIRDFDataSource *aDataSource) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + diff --git a/mozilla/java/webclient/src_moz/wsRDFObserver.h b/mozilla/java/webclient/src_moz/wsRDFObserver.h new file mode 100644 index 00000000000..21f839ee4c0 --- /dev/null +++ b/mozilla/java/webclient/src_moz/wsRDFObserver.h @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): Ed Burns + * + */ + +#ifndef wsRDFObserver_h +#define wsRDFObserver_h + +#include "nsIRDFObserver.h" +#include "nsCOMPtr.h" + +class wsRDFObserver : + public nsIRDFObserver +{ + +public: + +nsIRDFResource *getFolder(); + + +public: + wsRDFObserver(); + +public: + virtual ~wsRDFObserver(); + +// Protected members +protected: + +nsCOMPtr folder; + +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIRDFOBSERVER + +protected: +// +// Local methods +// + +}; + +#endif + diff --git a/mozilla/java/webclient/src_share/Makefile.in b/mozilla/java/webclient/src_share/Makefile.in index 4b71da46797..35bb5b7153e 100644 --- a/mozilla/java/webclient/src_share/Makefile.in +++ b/mozilla/java/webclient/src_share/Makefile.in @@ -60,6 +60,7 @@ endif JAVAH_CLS= \ "-o BookmarksImpl.h org.mozilla.webclient.wrapper_native.BookmarksImpl" \ + "-o PreferencesImpl.h org.mozilla.webclient.wrapper_native.PreferencesImpl" \ "-o CurrentPageImpl.h org.mozilla.webclient.wrapper_native.CurrentPageImpl" \ "-o HistoryImpl.h org.mozilla.webclient.wrapper_native.HistoryImpl" \ "-o WrapperFactoryImpl.h org.mozilla.webclient.wrapper_native.WrapperFactoryImpl" \ @@ -73,6 +74,7 @@ JAVAH_CLS= \ JAVAH_FILES=\ BookmarksImpl.h \ + PreferencesImpl.h \ CurrentPageImpl.h \ HistoryImpl.h \ WrapperFactoryImpl.h \ diff --git a/mozilla/java/webclient/src_share/Makefile.win b/mozilla/java/webclient/src_share/Makefile.win index d025e8c5a13..8edc772b7a7 100644 --- a/mozilla/java/webclient/src_share/Makefile.win +++ b/mozilla/java/webclient/src_share/Makefile.win @@ -82,12 +82,16 @@ JAVAC_CLASSPATH=$(JAVAC_CLASSPATH);$(CLASSPATH) !CMDSWITCHES -S # generate the jni header -export:: BookmarksImpl.h CurrentPageImpl.h HistoryImpl.h WrapperFactoryImpl.h WindowControlImpl.h NavigationImpl.h NativeEventThread.h RDFEnumeration.h RDFTreeNode.h ISupportsPeer.h +export:: BookmarksImpl.h PreferencesImpl.h CurrentPageImpl.h HistoryImpl.h WrapperFactoryImpl.h WindowControlImpl.h NavigationImpl.h NativeEventThread.h RDFEnumeration.h RDFTreeNode.h ISupportsPeer.h BookmarksImpl.h: @echo Assuming class org.mozilla.webclient.wrapper_native.BookmarksImpl is in $(JAVAH_FLAGS) $(JAVAH) $(JAVAH_FLAGS) -o $@ org.mozilla.webclient.wrapper_native.BookmarksImpl +PreferencesImpl.h: + @echo Assuming class org.mozilla.webclient.wrapper_native.PreferencesImpl is in $(JAVAH_FLAGS) + $(JAVAH) $(JAVAH_FLAGS) -o $@ org.mozilla.webclient.wrapper_native.PreferencesImpl + CurrentPageImpl.h: @echo Assuming class org.mozilla.webclient.wrapper_native.CurrentPageImpl is in $(JAVAH_FLAGS) @@ -132,6 +136,7 @@ install:: $(LIBRARY) clobber_all:: clobber rm -f BookmarksImpl.h + rm -f PreferencesImpl.h rm -f CurrentPageImpl.h rm -f HistoryImpl.h rm -f WrapperFactoryImpl.h diff --git a/mozilla/java/webclient/src_share/jni_util.cpp b/mozilla/java/webclient/src_share/jni_util.cpp index 7512256c675..b2bd9b8d6e0 100644 --- a/mozilla/java/webclient/src_share/jni_util.cpp +++ b/mozilla/java/webclient/src_share/jni_util.cpp @@ -41,6 +41,7 @@ JavaVM *gVm = nsnull; // declared in ns_globals.h, which is included in static jmethodID gPropertiesInitMethodID = nsnull; static jmethodID gPropertiesSetPropertyMethodID = nsnull; +static jmethodID gPropertiesGetPropertyMethodID = nsnull; static jmethodID gPropertiesClearMethodID = nsnull; @@ -60,10 +61,24 @@ jobject SHIFT_KEY; jobject META_KEY; jobject BUTTON_KEY; jobject CLICK_COUNT_KEY; +jobject USER_NAME_KEY; +jobject PASSWORD_KEY; +jobject EDIT_FIELD_1_KEY; +jobject EDIT_FIELD_2_KEY; +jobject CHECKBOX_STATE_KEY; +jobject BUTTON_PRESSED_KEY; jobject TRUE_VALUE; jobject FALSE_VALUE; jobject ONE_VALUE; jobject TWO_VALUE; +jobject BM_ADD_DATE_VALUE; +jobject BM_LAST_MODIFIED_DATE_VALUE; +jobject BM_LAST_VISIT_DATE_VALUE; +jobject BM_NAME_VALUE; +jobject BM_URL_VALUE; +jobject BM_DESCRIPTION_VALUE; +jobject BM_IS_FOLDER_VALUE; + jstring DOCUMENT_LOAD_LISTENER_CLASSNAME; jstring MOUSE_LISTENER_CLASSNAME; @@ -103,11 +118,10 @@ void util_DeallocateShareInitContext(void *yourInitContext) // right now there is nothing to deallocate } -jboolean util_InitStringConstants(JNIEnv *env) +jboolean util_InitStringConstants() { - if (nsnull == gVm) { // declared in jni_util.h - ::util_GetJavaVM(env, &gVm); // save this vm reference away for the callback! - } + util_Assert(gVm); + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); if (nsnull == (SCREEN_X_KEY = ::util_NewGlobalRef(env, (jobject) @@ -160,6 +174,42 @@ jboolean util_InitStringConstants(JNIEnv *env) "ClickCount")))) { return JNI_FALSE; } + if (nsnull == (USER_NAME_KEY = + ::util_NewGlobalRef(env, (jobject) + ::util_NewStringUTF(env, + "userName")))) { + return JNI_FALSE; + } + if (nsnull == (PASSWORD_KEY = + ::util_NewGlobalRef(env, (jobject) + ::util_NewStringUTF(env, + "password")))) { + return JNI_FALSE; + } + if (nsnull == (EDIT_FIELD_1_KEY = + ::util_NewGlobalRef(env, (jobject) + ::util_NewStringUTF(env, + "editfield1Value")))) { + return JNI_FALSE; + } + if (nsnull == (EDIT_FIELD_2_KEY = + ::util_NewGlobalRef(env, (jobject) + ::util_NewStringUTF(env, + "editfield12Value")))) { + return JNI_FALSE; + } + if (nsnull == (CHECKBOX_STATE_KEY = + ::util_NewGlobalRef(env, (jobject) + ::util_NewStringUTF(env, + "checkboxState")))) { + return JNI_FALSE; + } + if (nsnull == (BUTTON_PRESSED_KEY = + ::util_NewGlobalRef(env, (jobject) + ::util_NewStringUTF(env, + "buttonPressed")))) { + return JNI_FALSE; + } if (nsnull == (TRUE_VALUE = ::util_NewGlobalRef(env, (jobject) ::util_NewStringUTF(env, "true")))) { @@ -180,6 +230,48 @@ jboolean util_InitStringConstants(JNIEnv *env) ::util_NewStringUTF(env, "2")))) { return JNI_FALSE; } + if (nsnull == (BM_ADD_DATE_VALUE = + ::util_NewGlobalRef(env, (jobject) + ::util_NewStringUTF(env, + BM_ADD_DATE)))) { + return JNI_FALSE; + } + if (nsnull == (BM_LAST_MODIFIED_DATE_VALUE = + ::util_NewGlobalRef(env, (jobject) + ::util_NewStringUTF(env, + BM_LAST_MODIFIED_DATE)))) { + return JNI_FALSE; + } + if (nsnull == (BM_LAST_VISIT_DATE_VALUE = + ::util_NewGlobalRef(env, (jobject) + ::util_NewStringUTF(env, + BM_LAST_VISIT_DATE)))) { + return JNI_FALSE; + } + if (nsnull == (BM_NAME_VALUE = + ::util_NewGlobalRef(env, (jobject) + ::util_NewStringUTF(env, + BM_NAME)))) { + return JNI_FALSE; + } + if (nsnull == (BM_URL_VALUE = + ::util_NewGlobalRef(env, (jobject) + ::util_NewStringUTF(env, + BM_URL)))) { + return JNI_FALSE; + } + if (nsnull == (BM_DESCRIPTION_VALUE = + ::util_NewGlobalRef(env, (jobject) + ::util_NewStringUTF(env, + BM_DESCRIPTION)))) { + return JNI_FALSE; + } + if (nsnull == (BM_IS_FOLDER_VALUE = + ::util_NewGlobalRef(env, (jobject) + ::util_NewStringUTF(env, + BM_IS_FOLDER)))) { + return JNI_FALSE; + } if (nsnull == (DOCUMENT_LOAD_LISTENER_CLASSNAME = (jstring) ::util_NewGlobalRef(env, (jobject) ::util_NewStringUTF(env, @@ -373,6 +465,19 @@ jclass util_FindClass(JNIEnv *env, const char *fullyQualifiedClassName) return result; } + +jobject util_CallStaticObjectMethodlongArg(JNIEnv *env, jclass clazz, + jmethodID methodID, jlong longArg) +{ + jobject result = nsnull; +#ifdef BAL_INTERFACE +#else + result = env->CallStaticObjectMethod(clazz, methodID, longArg); +#endif + return result; +} + + jfieldID util_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *fieldName, const char *signature) @@ -466,18 +571,17 @@ jobject util_CreatePropertiesObject(JNIEnv *env, jobject initContextObj) #else util_Assert(initContextObj); ShareInitContext *initContext = (ShareInitContext *) initContextObj; + jclass propertiesClass = nsnull; - if (nsnull == initContext->propertiesClass) { - if (nsnull == (initContext->propertiesClass = - ::util_FindClass(env, "java/util/Properties"))) { - return result; - } + if (nsnull == (propertiesClass = + ::util_FindClass(env, "java/util/Properties"))) { + return result; } if (nsnull == gPropertiesInitMethodID) { - util_Assert(initContext->propertiesClass); + util_Assert(propertiesClass); if (nsnull == (gPropertiesInitMethodID = - env->GetMethodID(initContext->propertiesClass, + env->GetMethodID(propertiesClass, "", "()V"))) { return result; } @@ -485,7 +589,7 @@ jobject util_CreatePropertiesObject(JNIEnv *env, jobject initContextObj) util_Assert(gPropertiesInitMethodID); result = ::util_NewGlobalRef(env, - env->NewObject(initContext->propertiesClass, + env->NewObject(propertiesClass, gPropertiesInitMethodID)); #endif @@ -515,11 +619,16 @@ void util_ClearPropertiesObject(JNIEnv *env, jobject propertiesObject, #else util_Assert(initContextObj); ShareInitContext *initContext = (ShareInitContext *) initContextObj; + jclass propertiesClass = nsnull; + + if (nsnull == (propertiesClass = + ::util_FindClass(env, "java/util/Properties"))) { + return; + } if (nsnull == gPropertiesClearMethodID) { - util_Assert(initContext->propertiesClass); if (nsnull == (gPropertiesClearMethodID = - env->GetMethodID(initContext->propertiesClass, "clear", "()V"))) { + env->GetMethodID(propertiesClass, "clear", "()V"))) { return; } } @@ -542,11 +651,16 @@ void util_StoreIntoPropertiesObject(JNIEnv *env, jobject propertiesObject, #else util_Assert(initContextObj); ShareInitContext *initContext = (ShareInitContext *) initContextObj; + jclass propertiesClass = nsnull; + + if (nsnull == (propertiesClass = + ::util_FindClass(env, "java/util/Properties"))) { + return; + } if (nsnull == gPropertiesSetPropertyMethodID) { - util_Assert(initContext->propertiesClass); if (nsnull == (gPropertiesSetPropertyMethodID = - env->GetMethodID(initContext->propertiesClass, + env->GetMethodID(propertiesClass, "setProperty", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;"))) { return; @@ -562,6 +676,128 @@ void util_StoreIntoPropertiesObject(JNIEnv *env, jobject propertiesObject, #endif } +jobject util_GetFromPropertiesObject(JNIEnv *env, jobject propertiesObject, + jobject name, jobject initContextObj) +{ + jobject result = nsnull; +#ifdef BAL_INTERFACE + if (nsnull != externalGetFromPropertiesObject) { + result = externalGetFromPropertiesObject(env, propertiesObject, name, + initContextObj); + } +#else + util_Assert(initContextObj); + ShareInitContext *initContext = (ShareInitContext *) initContextObj; + jclass propertiesClass = nsnull; + + if (nsnull == (propertiesClass = + ::util_FindClass(env, "java/util/Properties"))) { + return result; + } + + if (nsnull == gPropertiesGetPropertyMethodID) { + if (nsnull == (gPropertiesGetPropertyMethodID = + env->GetMethodID(propertiesClass, + "getProperty", + "(Ljava/lang/String;)Ljava/lang/String;"))) { + return result; + } + } + util_Assert(gPropertiesGetPropertyMethodID); + + result = env->CallObjectMethod(propertiesObject, + gPropertiesGetPropertyMethodID, name); +#endif + return result; +} + +jboolean util_GetBoolFromPropertiesObject(JNIEnv *env, + jobject propertiesObject, + jobject name, jobject reserved) +{ + jboolean result = JNI_FALSE; + jstring stringResult = nsnull; + + if (nsnull == (stringResult = (jstring) + util_GetFromPropertiesObject(env, propertiesObject, + name, reserved))) { + return result; + } +#ifdef BAL_INTERFACE + // PENDING(edburns): make it so there is a way to convert from + // string to boolean +#else + jclass clazz; + jmethodID valueOfMethodID; + jmethodID booleanValueMethodID; + jobject boolInstance; + if (nsnull == (clazz = ::util_FindClass(env, "java/lang/Boolean"))) { + return result; + } + if (nsnull == (valueOfMethodID = + env->GetStaticMethodID(clazz,"valueOf", + "(Ljava/lang/String;)Ljava/lang/Boolean;"))) { + return result; + } + if (nsnull == (boolInstance = env->CallStaticObjectMethod(clazz, + valueOfMethodID, + stringResult))) { + return result; + } + // now call booleanValue + if (nsnull == (booleanValueMethodID = env->GetMethodID(clazz, + "booleanValue", + "()Z"))) { + return result; + } + result = env->CallBooleanMethod(boolInstance, booleanValueMethodID); +#endif + + return result; +} + +jint util_GetIntFromPropertiesObject(JNIEnv *env, jobject propertiesObject, + jobject name, jobject reserved) +{ + jint result = -1; + jstring stringResult = nsnull; + + if (nsnull == (stringResult = (jstring) + util_GetFromPropertiesObject(env, propertiesObject, name, + reserved))) { + return result; + } +#ifdef BAL_INTERFACE + // PENDING(edburns): make it so there is a way to convert from + // string to int +#else + jclass clazz; + jmethodID valueOfMethodID, intValueMethodID; + jobject integer; + if (nsnull == (clazz = ::util_FindClass(env, "java/lang/Integer"))) { + return result; + } + if (nsnull == (valueOfMethodID = + env->GetStaticMethodID(clazz, "valueOf", + "(Ljava/lang/String;)Ljava/lang/Integer;"))) { + return result; + } + if (nsnull == (integer = env->CallStaticObjectMethod(clazz, + valueOfMethodID, + stringResult))) { + return result; + } + // now call intValue + if (nsnull == (intValueMethodID = env->GetMethodID(clazz, "intValue", + "()I"))) { + return result; + } + result = env->CallIntMethod(integer, intValueMethodID); +#endif + + return result; +} + JNIEXPORT jvalue JNICALL JNU_CallMethodByName(JNIEnv *env, jboolean *hasException, diff --git a/mozilla/java/webclient/src_share/jni_util.h b/mozilla/java/webclient/src_share/jni_util.h index 1fb38f23fe4..4e5db24239c 100644 --- a/mozilla/java/webclient/src_share/jni_util.h +++ b/mozilla/java/webclient/src_share/jni_util.h @@ -76,10 +76,24 @@ extern jobject SHIFT_KEY; extern jobject META_KEY; extern jobject BUTTON_KEY; extern jobject CLICK_COUNT_KEY; +extern jobject USER_NAME_KEY; +extern jobject PASSWORD_KEY; +extern jobject EDIT_FIELD_1_KEY; +extern jobject EDIT_FIELD_2_KEY; +extern jobject CHECKBOX_STATE_KEY; +extern jobject BUTTON_PRESSED_KEY; extern jobject TRUE_VALUE; extern jobject FALSE_VALUE; extern jobject ONE_VALUE; extern jobject TWO_VALUE; +extern jobject BM_ADD_DATE_VALUE; +extern jobject BM_LAST_MODIFIED_DATE_VALUE; +extern jobject BM_LAST_VISIT_DATE_VALUE; +extern jobject BM_NAME_VALUE; +extern jobject BM_URL_VALUE; +extern jobject BM_DESCRIPTION_VALUE; +extern jobject BM_IS_FOLDER_VALUE; + /** @@ -168,6 +182,15 @@ typedef enum { NUMBER_OF_DOM_MOUSE_LISTENER_MASK_NAMES } DOM_MOUSE_LISTENER_EVENT_MASK_NAMES; +// BookmarkEntry string constants, must coincide with java +#define BM_ADD_DATE "AddDate" +#define BM_LAST_MODIFIED_DATE "LastModifiedDate" +#define BM_LAST_VISIT_DATE "LastVisitDate" +#define BM_NAME "Name" +#define BM_URL "URL" +#define BM_DESCRIPTION "Description" +#define BM_IS_FOLDER "IsFolder" + extern jlong DocumentLoader_maskValues [NUMBER_OF_DOCUMENT_LOADER_MASK_NAMES]; extern char *DocumentLoader_maskNames [NUMBER_OF_DOCUMENT_LOADER_MASK_NAMES + 1]; @@ -201,7 +224,7 @@ void util_DeallocateShareInitContext(void *initContext); */ -jboolean util_InitStringConstants(JNIEnv *env); +jboolean util_InitStringConstants(); jboolean util_StringConstantsAreInitialized(); void util_ThrowExceptionToJava (JNIEnv * env, const char * message); @@ -240,6 +263,9 @@ jint util_GetJavaVM(JNIEnv *env, JavaVM **vm); jclass util_FindClass(JNIEnv *env, const char *fullyQualifiedClassName); +jobject util_CallStaticObjectMethodlongArg(JNIEnv *env, jclass clazz, + jmethodID methodID, jlong longArg); + jfieldID util_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *fieldName, const char *signature); @@ -292,6 +318,35 @@ void util_StoreIntoPropertiesObject(JNIEnv *env, jobject propertiesObject, jobject name, jobject value, jobject reserved); +/** + + * A JNI wrapper to get a value for a name out of a PropertiesObject + * created by CreatePropertiesObject + + */ + +jobject util_GetFromPropertiesObject(JNIEnv *, jobject propertiesObject, + jobject name, jobject reserved); + +/** + + * A JNI wrapper to get a boolean value for a name out of a PropertiesObject + * created by CreatePropertiesObject + + */ + +jboolean util_GetBoolFromPropertiesObject(JNIEnv *, jobject propertiesObject, + jobject name, jobject reserved); + +/** + + * A JNI wrapper to get an int value for a name out of a PropertiesObject + * created by CreatePropertiesObject + + */ + +jint util_GetIntFromPropertiesObject(JNIEnv *, jobject propertiesObject, + jobject name, jobject reserved); // // Functions provided by the browser specific native code diff --git a/mozilla/java/webclient/src_share/jni_util_export.cpp b/mozilla/java/webclient/src_share/jni_util_export.cpp index 0efccab7bbe..7be4c00112e 100644 --- a/mozilla/java/webclient/src_share/jni_util_export.cpp +++ b/mozilla/java/webclient/src_share/jni_util_export.cpp @@ -42,6 +42,8 @@ fpClearPropertiesObjectType externalClearPropertiesObject = nsnull; // jni_util_ fpStoreIntoPropertiesObjectType externalStoreIntoPropertiesObject = nsnull; // jni_util_export.h +fpGetFromPropertiesObjectType externalGetFromPropertiesObject = nsnull; // jni_util_export.h + JNIEXPORT const char * JNICALL util_GetStringUTFChars(JNIEnv *env, jstring inString) { @@ -191,6 +193,11 @@ JNIEXPORT void JNICALL util_SetStoreIntoPropertiesObjectFunction(fpStoreIntoProp externalStoreIntoPropertiesObject = fp; } +JNIEXPORT void JNICALL util_SetGetFromPropertiesObjectFunction(fpGetFromPropertiesObjectType fp) +{ + externalGetFromPropertiesObject = fp; +} + JNIEXPORT void JNICALL util_InitializeEventMaskValuesFromClass(const char *className, char *maskNames[], diff --git a/mozilla/java/webclient/src_share/jni_util_export.h b/mozilla/java/webclient/src_share/jni_util_export.h index 73e50b7c6bc..24e192888d2 100644 --- a/mozilla/java/webclient/src_share/jni_util_export.h +++ b/mozilla/java/webclient/src_share/jni_util_export.h @@ -188,6 +188,26 @@ typedef JNIEXPORT void (JNICALL * fpStoreIntoPropertiesObjectType) (JNIEnv *env, jobject propertiesObject, jobject name, jobject value, jobject reserved); +/** + + * Called after webclient has called fpCreatePropertiesObjectType when + * webclient wants to get values from the properties object. + + * @param env not used + + * @param propertiesObject obtained from fpCreatePropertiesObjectType + + * @param name the name of the property + + * @returns the return value from the properties object + + */ + + +typedef JNIEXPORT jobject (JNICALL * fpGetFromPropertiesObjectType) + (JNIEnv *env, jobject propertiesObject, jobject name, jobject reserved); + + /** * This function must be called at app initialization. @@ -258,6 +278,16 @@ JNIEXPORT void JNICALL util_SetClearPropertiesObjectFunction(fpDestroyProperties JNIEXPORT void JNICALL util_SetStoreIntoPropertiesObjectFunction(fpStoreIntoPropertiesObjectType fp); +/** + + * This function must be called at app initialization. + + * @see fpGetFromPropertiesObjectType + + */ + +JNIEXPORT void JNICALL util_SetGetFromPropertiesObjectFunction(fpGetFromPropertiesObjectType fp); + /** @@ -330,6 +360,17 @@ extern fpClearPropertiesObjectType externalClearPropertiesObject; extern fpStoreIntoPropertiesObjectType externalStoreIntoPropertiesObject; +/** + + * defined in jni_util_export.cpp + + * The function pointer set with util_SetGetFromPropertiesObjectFunction + + */ + +extern fpGetFromPropertiesObjectType externalGetFromPropertiesObject; + + /** * Called by the mozilla event listener implementation class at diff --git a/mozilla/java/webclient/src_share/runem.pl b/mozilla/java/webclient/src_share/runem.pl index b4056f826e4..74d8f0fb9ce 100644 --- a/mozilla/java/webclient/src_share/runem.pl +++ b/mozilla/java/webclient/src_share/runem.pl @@ -115,6 +115,11 @@ $cmd = $JAVA_CMD; if ($SEP eq "/") { $cmd = $cmd . " -native"; } +else { + # workaround bug 64332 on Win32, turn off hotspot and JIT + $cmd = $cmd . " -classic -Djava.compiler=NONE"; +} + #tack on the java library path $cmd = $cmd . " -Djava.library.path=" . $BINDIR; #tack on the classpath, class name, and bin dir diff --git a/mozilla/java/webclient/test/index.html b/mozilla/java/webclient/test/index.html new file mode 100644 index 00000000000..21977a4cb64 --- /dev/null +++ b/mozilla/java/webclient/test/index.html @@ -0,0 +1,3 @@ + +This page is empty. +