diff --git a/mozilla/java/webclient/build-tests.xml b/mozilla/java/webclient/build-tests.xml
index f27e21e6bf4..e4dc224c7c5 100644
--- a/mozilla/java/webclient/build-tests.xml
+++ b/mozilla/java/webclient/build-tests.xml
@@ -160,8 +160,8 @@
The eventDispatched() method is passed a {@link
+ * DocumentLoadEvent} instance. The type property of the
+ * event will be one of the types defined as a public static final
+ * int in DocumentLoadEvent.
The eventData property of the
+ * DocumentLoadEvent instance will be a
+ * java.util.Map. For all EVENT_MASK types in
+ * DocumentLoadEvent the map will contain an entry under
+ * the key "URI" without the quotes. This will be the
+ * fully qualified URI for the event.
For the PROGRESS_URL_LOAD_EVENT_MASK there will be an
+ * entry in the map for the key "message". This will be
+ * the progress message from the browser.
This {@link DocumentLoadListener} subclass adds the ability to get + * detailed information on each event.
+ * + *The eventDispatched() method is passed the same thing
+ * as in the {@link DocumentLoadListener}.
The eventData property of the
+ * DocumentLoadEvent instance will be a
+ * java.util.Map. For the
+ * END_URL_LOAD_EVENT_MASK type in
+ * DocumentLoadEvent the map will contain an entry under
+ * the key "URI" without the quotes. This will be the
+ * fully qualified URI for the event. The map will also contain an
+ * entry under the key "headers". This entry will be a
+ * Map of all the response headers.
Native analog to BrowserControl. Hosts per-window things. Maps @@ -60,7 +61,7 @@ public: // public API // - nsresult Init (); + nsresult Init (NativeWrapperFactory *yourWrapperFactory); nsresult Realize (jobject javaBrowserControl, void* parentWinPtr, PRBool *aAlreadyRealized, @@ -72,6 +73,8 @@ public: PRUint32 aWidth, PRUint32 aHeight); void Destroy (void); + NativeWrapperFactory * GetWrapperFactory(); + jobject QueryInterfaceJava(WEBCLIENT_INTERFACES interface); @@ -105,6 +108,8 @@ public: jobject mJavaBrowserControl; + NativeWrapperFactory * wrapperFactory; + }; #endif // NativeBrowserControl_h diff --git a/mozilla/java/webclient/src_moz/WrapperFactoryImpl.cpp b/mozilla/java/webclient/src_moz/WrapperFactoryImpl.cpp index 9366066e7e3..e57ae1ac086 100644 --- a/mozilla/java/webclient/src_moz/WrapperFactoryImpl.cpp +++ b/mozilla/java/webclient/src_moz/WrapperFactoryImpl.cpp @@ -350,7 +350,7 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_WrapperFa "NULL nativeBCPtr passed to nativeInitBrowserControl."); return; } - rv = nativeBrowserControl->Init(); + rv = nativeBrowserControl->Init(nativeWrapperFactory); if (NS_FAILED(rv)) { ::util_ThrowExceptionToJava(env, errorMessages[3]); diff --git a/mozilla/java/webclient/src_share/jni_util.cpp b/mozilla/java/webclient/src_share/jni_util.cpp index fdb7a37da19..24ccb7f6a61 100644 --- a/mozilla/java/webclient/src_share/jni_util.cpp +++ b/mozilla/java/webclient/src_share/jni_util.cpp @@ -71,6 +71,9 @@ jobject TRUE_VALUE; jobject FALSE_VALUE; jobject ONE_VALUE; jobject TWO_VALUE; +jobject URI_VALUE; +jobject HEADERS_VALUE; +jobject MESSAGE_VALUE; jobject BM_ADD_DATE_VALUE; jobject BM_LAST_MODIFIED_DATE_VALUE; jobject BM_LAST_VISIT_DATE_VALUE; @@ -236,6 +239,21 @@ jboolean util_InitStringConstants() ::util_NewStringUTF(env, "2")))) { return JNI_FALSE; } + if (nsnull == (URI_VALUE = + ::util_NewGlobalRef(env, (jobject) + ::util_NewStringUTF(env, "URI")))) { + return JNI_FALSE; + } + if (nsnull == (HEADERS_VALUE = + ::util_NewGlobalRef(env, (jobject) + ::util_NewStringUTF(env, "headers")))) { + return JNI_FALSE; + } + if (nsnull == (MESSAGE_VALUE = + ::util_NewGlobalRef(env, (jobject) + ::util_NewStringUTF(env, "message")))) { + return JNI_FALSE; + } if (nsnull == (BM_ADD_DATE_VALUE = ::util_NewGlobalRef(env, (jobject) ::util_NewStringUTF(env, diff --git a/mozilla/java/webclient/src_share/jni_util.h b/mozilla/java/webclient/src_share/jni_util.h index 2920041b053..47c4f5d1517 100644 --- a/mozilla/java/webclient/src_share/jni_util.h +++ b/mozilla/java/webclient/src_share/jni_util.h @@ -86,6 +86,9 @@ extern jobject TRUE_VALUE; extern jobject FALSE_VALUE; extern jobject ONE_VALUE; extern jobject TWO_VALUE; +extern jobject URI_VALUE; +extern jobject HEADERS_VALUE; +extern jobject MESSAGE_VALUE; extern jobject BM_ADD_DATE_VALUE; extern jobject BM_LAST_MODIFIED_DATE_VALUE; extern jobject BM_LAST_VISIT_DATE_VALUE; diff --git a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/CurrentPageTest.java b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/DocumentLoadListenerTest.java similarity index 60% rename from mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/CurrentPageTest.java rename to mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/DocumentLoadListenerTest.java index 819a538c2e3..734de313315 100644 --- a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/CurrentPageTest.java +++ b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/DocumentLoadListenerTest.java @@ -1,5 +1,5 @@ /* - * $Id: CurrentPageTest.java,v 1.1 2004-09-03 19:04:22 edburns%acm.org Exp $ + * $Id: DocumentLoadListenerTest.java,v 1.1 2004-09-09 20:17:17 edburns%acm.org Exp $ */ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- @@ -38,11 +38,11 @@ import java.awt.BorderLayout; import java.io.File; import java.io.FileInputStream; -// CurrentPageTest.java +// DocumentLoadListenerTest.java -public class CurrentPageTest extends WebclientTestCase { +public class DocumentLoadListenerTest extends WebclientTestCase { - public CurrentPageTest(String name) { + public DocumentLoadListenerTest(String name) { super(name); try { BrowserControlFactory.setAppData(getBrowserBinDir()); @@ -54,7 +54,7 @@ public class CurrentPageTest extends WebclientTestCase { public static Test suite() { TestSuite result = createServerTestSuite(); - result.addTestSuite(CurrentPageTest.class); + result.addTestSuite(DocumentLoadListenerTest.class); return (result); } @@ -70,73 +70,9 @@ public class CurrentPageTest extends WebclientTestCase { // Testcases // - public void testHeadersGet() throws Exception { + public void testDocumentLoadListener() throws Exception { BrowserControl firstBrowserControl = null; - DocumentLoadListenerImpl listener = null; - firstBrowserControl = BrowserControlFactory.newBrowserControl(); - assertNotNull(firstBrowserControl); - BrowserControlCanvas canvas = (BrowserControlCanvas) - firstBrowserControl.queryInterface(BrowserControl.BROWSER_CONTROL_CANVAS_NAME); - eventRegistration = (EventRegistration2) - firstBrowserControl.queryInterface(BrowserControl.EVENT_REGISTRATION_NAME); - - assertNotNull(canvas); - Frame frame = new Frame(); - frame.setUndecorated(true); - frame.setBounds(0, 0, 640, 480); - frame.add(canvas, BorderLayout.CENTER); - frame.setVisible(true); - canvas.setVisible(true); - - Navigation2 nav = (Navigation2) - firstBrowserControl.queryInterface(BrowserControl.NAVIGATION_NAME); - assertNotNull(nav); - final CurrentPage2 currentPage = (CurrentPage2) - firstBrowserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME); - - assertNotNull(currentPage); - - // - // try loading a file over HTTP - // - - CurrentPageTest.keepWaiting = true; - - - eventRegistration.addDocumentLoadListener(listener = new DocumentLoadListenerImpl() { - public void doEndCheck() { - try { - Map responseHeaders = currentPage.getResponseHeaders(); - assertNotNull(responseHeaders); - String server = (String) responseHeaders.get("Server"); - assertNotNull(server); - assertEquals("THTTPD", server); - } - finally { - CurrentPageTest.keepWaiting = false; - } - } - }); - - String url = "http://www.jdocs.com/jsp/2.0/api/index.html"; //"http://localhost:5243/HttpNavigationTest.txt"; - - Thread.currentThread().sleep(3000); - - nav.loadURL(url); - - // keep waiting until the previous load completes - while (CurrentPageTest.keepWaiting) { - Thread.currentThread().sleep(1000); - } - eventRegistration.removeDocumentLoadListener(listener); - - frame.setVisible(false); - BrowserControlFactory.deleteBrowserControl(firstBrowserControl); - } - - public void NOTtestHttpPost() throws Exception { - BrowserControl firstBrowserControl = null; - DocumentLoadListenerImpl listener = null; + DocumentLoadListener listener = null; Selection selection = null; firstBrowserControl = BrowserControlFactory.newBrowserControl(); assertNotNull(firstBrowserControl); @@ -156,37 +92,112 @@ public class CurrentPageTest extends WebclientTestCase { Navigation2 nav = (Navigation2) firstBrowserControl.queryInterface(BrowserControl.NAVIGATION_NAME); assertNotNull(nav); - final CurrentPage2 currentPage = (CurrentPage2) - firstBrowserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME); - - assertNotNull(currentPage); // // try loading a file over HTTP // - CurrentPageTest.keepWaiting = true; - + DocumentLoadListenerTest.keepWaiting = true; + final String url = "http://localhost:5243/HttpNavigationTest.txt"; - eventRegistration.addDocumentLoadListener(listener = new DocumentLoadListenerImpl() { - public void doEndCheck() { - currentPage.selectAll(); - Selection selection = currentPage.getSelection(); - CurrentPageTest.keepWaiting = false; - assertTrue(-1 != selection.toString().indexOf("This file was downloaded over HTTP.")); - System.out.println("Selection is: " + - selection.toString()); + eventRegistration.addDocumentLoadListener(listener = new DocumentLoadListener() { + public void eventDispatched(WebclientEvent event) { + if (event instanceof DocumentLoadEvent) { + switch ((int) event.getType()) { + case ((int) DocumentLoadEvent.END_URL_LOAD_EVENT_MASK): + assertNotNull(event.getEventData()); + // PENDING(edburns): assertEquals(url, event.getEventData().toString()); + assertTrue(event.getEventData() instanceof Map); + Map map = (Map) event.getEventData(); + assertNull(map.get("headers")); + assertEquals(url, map.get("URI")); + break; + } + } + DocumentLoadListenerTest.keepWaiting = false; } }); - String url = "http://localhost:5243/HttpCurrentPageTest.txt"; + Thread.currentThread().sleep(3000); + + nav.loadURL(url); + + // keep waiting until the previous load completes + while (DocumentLoadListenerTest.keepWaiting) { + Thread.currentThread().sleep(1000); + } + eventRegistration.removeDocumentLoadListener(listener); + + frame.setVisible(false); + BrowserControlFactory.deleteBrowserControl(firstBrowserControl); + } + + public void testPageInfoListener() throws Exception { + BrowserControl firstBrowserControl = null; + DocumentLoadListener listener = null; + Selection selection = null; + firstBrowserControl = BrowserControlFactory.newBrowserControl(); + assertNotNull(firstBrowserControl); + BrowserControlCanvas canvas = (BrowserControlCanvas) + firstBrowserControl.queryInterface(BrowserControl.BROWSER_CONTROL_CANVAS_NAME); + eventRegistration = (EventRegistration2) + firstBrowserControl.queryInterface(BrowserControl.EVENT_REGISTRATION_NAME); + + assertNotNull(canvas); + Frame frame = new Frame(); + frame.setUndecorated(true); + frame.setBounds(0, 0, 640, 480); + frame.add(canvas, BorderLayout.CENTER); + frame.setVisible(true); + canvas.setVisible(true); + + Navigation2 nav = (Navigation2) + firstBrowserControl.queryInterface(BrowserControl.NAVIGATION_NAME); + assertNotNull(nav); + + // + // try loading a file over HTTP + // + + DocumentLoadListenerTest.keepWaiting = true; + final String url = "http://localhost:5243/HttpNavigationTest.txt"; + + eventRegistration.addDocumentLoadListener(listener = new PageInfoListener() { + public void eventDispatched(WebclientEvent event) { + if (event instanceof DocumentLoadEvent) { + switch ((int) event.getType()) { + case ((int) DocumentLoadEvent.END_URL_LOAD_EVENT_MASK): + assertNotNull(event.getEventData()); + assertTrue(event.getEventData() instanceof Map); + Map map = (Map) event.getEventData(); + assertEquals(url, map.get("URI")); + assertNotNull(map.get("headers")); + assertTrue(map.get("headers") instanceof Map); + Iterator iter = (map = (Map) map.get("headers")).keySet().iterator(); + boolean hadCorrectServerHeader = false; + while (iter.hasNext()) { + String curName = iter.next().toString(); + if (curName.equals("Server")) { + hadCorrectServerHeader = true; + } + System.out.println("\t" + curName + + ": " + + map.get(curName)); + } + assertTrue(hadCorrectServerHeader); + break; + } + } + DocumentLoadListenerTest.keepWaiting = false; + } + }); Thread.currentThread().sleep(3000); - nav.post(url, null, "PostData\r\n", "X-WakaWaka: true\r\n\r\n"); + nav.loadURL(url); // keep waiting until the previous load completes - while (CurrentPageTest.keepWaiting) { + while (DocumentLoadListenerTest.keepWaiting) { Thread.currentThread().sleep(1000); } eventRegistration.removeDocumentLoadListener(listener); diff --git a/mozilla/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/TestBrowser.java b/mozilla/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/TestBrowser.java index abde6fbb026..c080e7ddf14 100644 --- a/mozilla/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/TestBrowser.java +++ b/mozilla/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/TestBrowser.java @@ -28,6 +28,8 @@ import javax.swing.SwingConstants; import java.io.File; import java.net.URL; import java.net.MalformedURLException; +import java.util.Map; +import java.util.Iterator; import org.mozilla.webclient.*; @@ -216,8 +218,9 @@ public class TestBrowser extends JPanel { return; } - eventRegistration.addDocumentLoadListener(new DocumentLoadListener() { + eventRegistration.addDocumentLoadListener(new PageInfoListener() { public void eventDispatched(WebclientEvent event) { + Map map = (Map) event.getEventData(); if (event instanceof DocumentLoadEvent) { switch ((int) event.getType()) { case ((int) DocumentLoadEvent.START_DOCUMENT_LOAD_EVENT_MASK): @@ -229,11 +232,22 @@ public class TestBrowser extends JPanel { updateStatusInfo("Loading completed."); if (event.getEventData() != null) { - jAddressTextField.setText(event.getEventData().toString()); + jAddressTextField.setText(map.get("URI").toString()); + } + break; + case ((int) DocumentLoadEvent.END_URL_LOAD_EVENT_MASK): + if (map.get("headers") instanceof Map) { + Iterator iter = (map = (Map) map.get("headers")).keySet().iterator(); + while (iter.hasNext()) { + String curName = iter.next().toString(); + System.out.println("\t" + curName + + ": " + + map.get(curName)); + } } break; case ((int) DocumentLoadEvent.PROGRESS_URL_LOAD_EVENT_MASK): - // updateStatusInfo("Loading in progress..."); + updateStatusInfo(map.get("message").toString()); break; case ((int) DocumentLoadEvent.FETCH_INTERRUPT_EVENT_MASK): updateStatusInfo("Loading error.");