From d583fe5e1f481dba0345d6aa9f30b832fc82e575 Mon Sep 17 00:00:00 2001 From: "edburns%acm.org" Date: Thu, 9 Sep 2004 20:17:18 +0000 Subject: [PATCH] This checkin implements a response header listener feature. I have changed the usage contract of the DocumentLoadListener slightly. Prior to this checkin, calling getEventData() on the DocumentLoadEvent passed in to your eventDispatched() method returned the URI to which the event applies. Now the getEventData() returns a Map. You must look up the "URI" key to find the URI to which the event applies. If your listener is an instance of PageInfoListener, and your event mask is END_URL_LOAD_EVENT_MASK, your Map will have an additional entry under the key "headers". This entry is another Map representing the response headers. DocumentLoadListener: *

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.

PageInfoListener: *

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.

The next step will be to allow the same procedure to work to discover the request headers. Ed A classes_spec/org/mozilla/webclient/PageInfoListener.java - marker class for listenening for high fidelity page information. A src_moz/EventRegistrationImpl.cpp - add boolean property, capturePageInfo to turn on or off high fidelity page information collection. M build-tests.xml - add new test, DocumentLoadListenerTest M build.xml - added new JNI class, EventRegistrationImpl M classes_spec/org/mozilla/webclient/CurrentPage2.java M classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java - rollback previous API for headers discovery M classes_spec/org/mozilla/webclient/impl/wrapper_native/EventRegistrationImpl.java - pass thru the capturePageInfo property - add URIToStringMap, currently not working. M classes_spec/org/mozilla/webclient/test/EMWindow.java - call toString() on the eventData, don't cast it to a String. M src_moz/EmbedProgress.cpp M src_moz/EmbedProgress.h - leverage the nsIHttpHeaderVisitor interface to discover the response headers. - add boolean property capturePageInfo A src_moz/HttpHeaderVisitorImpl.cpp A src_moz/HttpHeaderVisitorImpl.h - copy the headers to a Properties object. M src_moz/Makefile.in - compile two new files: + EventRegistrationImpl.cpp \ + HttpHeaderVisitorImpl.cpp \ M src_moz/NativeBrowserControl.cpp M src_moz/NativeBrowserControl.h - pass the NativeWrapperFactory to our Init() method - add wrapperFactory getter. M src_moz/WrapperFactoryImpl.cpp - pass the nativeWrapperFactory to the NativeBrowserControl's Init method. M src_share/jni_util.cpp M src_share/jni_util.h - new constants: URI, headers R test/automated/src/classes/org/mozilla/webclient/CurrentPageTest.java - not yet time for this one A test/automated/src/classes/org/mozilla/webclient/DocumentLoadListenerTest.java - exercise bare minimum functionality of PageInfoListener M test/manual/src/classes/org/mozilla/webclient/test/TestBrowser.java - print out headers. git-svn-id: svn://10.0.0.236/trunk@162011 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/java/webclient/build-tests.xml | 2 +- mozilla/java/webclient/build.xml | 2 +- .../org/mozilla/webclient/CurrentPage2.java | 8 +- .../webclient/DocumentLoadListener.java | 19 ++ .../mozilla/webclient/PageInfoListener.java | 46 +++++ .../impl/wrapper_native/CurrentPageImpl.java | 29 +-- .../wrapper_native/EventRegistrationImpl.java | 107 +++++++++- .../org/mozilla/webclient/test/EMWindow.java | 8 +- .../java/webclient/src_moz/EmbedProgress.cpp | 142 ++++++++++--- .../java/webclient/src_moz/EmbedProgress.h | 4 + .../src_moz/EventRegistrationImpl.cpp | 42 ++++ .../src_moz/HttpHeaderVisitorImpl.cpp | 79 ++++++++ .../webclient/src_moz/HttpHeaderVisitorImpl.h | 40 ++++ mozilla/java/webclient/src_moz/Makefile.in | 2 + .../src_moz/NativeBrowserControl.cpp | 9 +- .../webclient/src_moz/NativeBrowserControl.h | 7 +- .../webclient/src_moz/WrapperFactoryImpl.cpp | 2 +- mozilla/java/webclient/src_share/jni_util.cpp | 18 ++ mozilla/java/webclient/src_share/jni_util.h | 3 + ...est.java => DocumentLoadListenerTest.java} | 187 +++++++++--------- .../mozilla/webclient/test/TestBrowser.java | 20 +- 21 files changed, 624 insertions(+), 152 deletions(-) create mode 100644 mozilla/java/webclient/classes_spec/org/mozilla/webclient/PageInfoListener.java create mode 100644 mozilla/java/webclient/src_moz/EventRegistrationImpl.cpp create mode 100644 mozilla/java/webclient/src_moz/HttpHeaderVisitorImpl.cpp create mode 100644 mozilla/java/webclient/src_moz/HttpHeaderVisitorImpl.h rename mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/{CurrentPageTest.java => DocumentLoadListenerTest.java} (60%) 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 @@ - + diff --git a/mozilla/java/webclient/build.xml b/mozilla/java/webclient/build.xml index 1ca3b8e6b37..15be9c66833 100644 --- a/mozilla/java/webclient/build.xml +++ b/mozilla/java/webclient/build.xml @@ -124,7 +124,7 @@ + class="org.mozilla.webclient.impl.wrapper_native.BookmarksImpl,org.mozilla.webclient.impl.wrapper_native.ProfileManagerImpl,org.mozilla.webclient.impl.wrapper_native.PreferencesImpl,org.mozilla.webclient.impl.wrapper_native.CurrentPageImpl,org.mozilla.webclient.impl.wrapper_native.HistoryImpl,org.mozilla.webclient.impl.wrapper_native.WrapperFactoryImpl,org.mozilla.webclient.impl.wrapper_native.NavigationImpl,org.mozilla.webclient.impl.wrapper_native.RDFEnumeration,org.mozilla.webclient.impl.wrapper_native.RDFTreeNode,org.mozilla.webclient.impl.wrapper_native.ISupportsPeer,org.mozilla.webclient.impl.wrapper_native.WindowControlImpl,org.mozilla.webclient.impl.wrapper_native.NativeEventThread,org.mozilla.webclient.impl.wrapper_native.EventRegistrationImpl"> diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/CurrentPage2.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/CurrentPage2.java index 2ce729754ef..576f7b14895 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/CurrentPage2.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/CurrentPage2.java @@ -1,4 +1,4 @@ -/* -*- Mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +/* -*- 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 @@ -23,8 +23,6 @@ package org.mozilla.webclient; -import java.util.Map; - public interface CurrentPage2 extends CurrentPage { @@ -37,9 +35,5 @@ public interface CurrentPage2 extends CurrentPage public void print(); public void printPreview(boolean preview); - - public Map getRequestHeaders(); - - public Map getResponseHeaders(); } // end of interface CurrentPage2 diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/DocumentLoadListener.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/DocumentLoadListener.java index 1ced4944ada..8fbbd35d2a0 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/DocumentLoadListener.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/DocumentLoadListener.java @@ -22,6 +22,25 @@ package org.mozilla.webclient; +/** + *

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.

+ * + */ + public interface DocumentLoadListener extends WebclientEventListener { } diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/PageInfoListener.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/PageInfoListener.java new file mode 100644 index 00000000000..5129c6dd487 --- /dev/null +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/PageInfoListener.java @@ -0,0 +1,46 @@ +/* -*- Mode: java; 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; + +/** + *

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.

+ * + */ + +public interface PageInfoListener extends DocumentLoadListener { + +} diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java index 297599494dd..ec8ff73be86 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java @@ -32,7 +32,6 @@ import org.mozilla.webclient.WindowControl; import org.mozilla.webclient.impl.WrapperFactory; import java.util.Properties; -import java.util.Map; import java.io.*; import java.net.*; @@ -293,17 +292,6 @@ public void printPreview(boolean preview) } } -public Map getRequestHeaders() -{ - return null; -} - -public Map getResponseHeaders() -{ - return null; -} - - // // Native methods // @@ -340,4 +328,21 @@ native public void nativePrint(int webShellPtr); native public void nativePrintPreview(int webShellPtr, boolean preview); +// ----VERTIGO_TEST_START + +// +// Test methods +// + +public static void main(String [] args) +{ + Assert.setEnabled(true); + Log.setApplicationName("CurrentPageImpl"); + Log.setApplicationVersion("0.0"); + Log.setApplicationVersionDate("$Id: CurrentPageImpl.java,v 1.7 2004-09-09 20:17:16 edburns%acm.org Exp $"); + +} + +// ----VERTIGO_TEST_END + } // end of class CurrentPageImpl diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/EventRegistrationImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/EventRegistrationImpl.java index 9c1b89d7416..54e0646e5c4 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/EventRegistrationImpl.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/EventRegistrationImpl.java @@ -29,7 +29,10 @@ import org.mozilla.util.ParameterCheck; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Iterator; +import java.util.Set; +import java.util.Collection; import org.mozilla.webclient.BrowserControl; import org.mozilla.webclient.BrowserControlCanvas; @@ -37,6 +40,7 @@ import org.mozilla.webclient.EventRegistration2; import org.mozilla.webclient.impl.WrapperFactory; import org.mozilla.webclient.DocumentLoadEvent; import org.mozilla.webclient.DocumentLoadListener; +import org.mozilla.webclient.PageInfoListener; import org.mozilla.webclient.NewWindowEvent; import org.mozilla.webclient.NewWindowListener; import java.awt.event.MouseListener; @@ -116,6 +120,16 @@ public void addDocumentLoadListener(DocumentLoadListener listener) getWrapperFactory().verifyInitialized(); synchronized(documentLoadListeners) { + if (listener instanceof PageInfoListener) { + NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable(){ + public Object run() { + nativeSetCapturePageInfo(getNativeBrowserControl(), + true); + return null; + } + }); + } + documentLoadListeners.add(listener); } } @@ -124,9 +138,20 @@ public void removeDocumentLoadListener(DocumentLoadListener listener) { ParameterCheck.nonNull(listener); getWrapperFactory().verifyInitialized(); - + synchronized(documentLoadListeners) { documentLoadListeners.remove(listener); + + if (0 == documentLoadListeners.size()) { + NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable(){ + public Object run() { + nativeSetCapturePageInfo(getNativeBrowserControl(), + false); + return null; + } + }); + } + } } @@ -244,7 +269,9 @@ void nativeEventOccurred(String targetClassName, long eventType, WebclientEvent event = null; if (DocumentLoadListener.class.getName().equals(targetClassName)) { - event = new DocumentLoadEvent(this, eventType, eventData); + event = new DocumentLoadEvent(this, eventType, + // PENDING(edburns: new URIToStringMap((Map)eventData)); + eventData); } else if (MouseListener.class.getName().equals(targetClassName)) { // We create a plain vanilla WebclientEvent, which the @@ -265,6 +292,9 @@ void nativeEventOccurred(String targetClassName, long eventType, eventPump.V(); } +private native void nativeSetCapturePageInfo(int webShellPtr, + boolean newState); + public class BrowserToJavaEventPump extends Thread { private boolean keepRunning = false; @@ -349,5 +379,78 @@ public class BrowserToJavaEventPump extends Thread { } // end of class BrowserToJavaEventPump +class URIToStringMap extends Object implements Map { + private Map map = null; + + URIToStringMap(Map yourMap) { + map = yourMap; + } + + public String toString() { + Object result = null; + if (null == map || null == (result = map.get("URI"))) { + result = ""; + } + return result.toString(); + } + + public void clear() { + throw new UnsupportedOperationException(); + } + + public boolean containsKey(Object key) { + return map.containsKey(key); + } + + public boolean containsValue(Object value) { + return map.containsValue(value); + } + + public Set entrySet() { + return map.entrySet(); + } + + public boolean equals(Object o) { + return map.equals(o); + } + + public Object get(Object key) { + return map.get(key); + } + + public int hashCode() { + return map.hashCode(); + } + + public boolean isEmpty() { + return map.isEmpty(); + } + + public Set keySet() { + return map.keySet(); + } + + public Object put(Object key, Object value) { + return map.put(key, value); + } + + public void putAll(Map t) { + map.putAll(t); + } + + public Object remove(Object key) { + return map.remove(key); + } + + public int size() { + return map.size(); + } + + public Collection values() { + return map.values(); + } + +} + } // end of class EventRegistrationImpl 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 383647da843..7ac6c6e6a9e 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 @@ -59,7 +59,7 @@ import java.io.FileInputStream; * This is a test application for using the BrowserControl. * - * @version $Id: EMWindow.java,v 1.44 2003-06-09 20:05:36 edburns%acm.org Exp $ + * @version $Id: EMWindow.java,v 1.45 2004-09-09 20:17:16 edburns%acm.org Exp $ * * @see org.mozilla.webclient.BrowserControlFactory @@ -719,7 +719,7 @@ public void eventDispatched(WebclientEvent event) case ((int) DocumentLoadEvent.START_DOCUMENT_LOAD_EVENT_MASK): stopButton.setEnabled(true); refreshButton.setEnabled(true); - currentURL = (String) event.getEventData(); + currentURL = event.getEventData().toString(); System.out.println("debug: edburns: Currently Viewing: " + currentURL); statusLabel.setText("Starting to load " + currentURL); @@ -754,11 +754,11 @@ public void eventDispatched(WebclientEvent event) statusLabel.setText(status); break; case ((int) DocumentLoadEvent.START_URL_LOAD_EVENT_MASK): - status = (String) event.getEventData(); + status = event.getEventData().toString(); urlStatusLabel.setText("startURL: " + status); break; case ((int) DocumentLoadEvent.END_URL_LOAD_EVENT_MASK): - status = (String) event.getEventData(); + status = event.getEventData().toString(); urlStatusLabel.setText(" endURL: " + status); break; } diff --git a/mozilla/java/webclient/src_moz/EmbedProgress.cpp b/mozilla/java/webclient/src_moz/EmbedProgress.cpp index 516f4033295..16f99bfee63 100644 --- a/mozilla/java/webclient/src_moz/EmbedProgress.cpp +++ b/mozilla/java/webclient/src_moz/EmbedProgress.cpp @@ -33,9 +33,11 @@ #include "NativeBrowserControl.h" +#include "HttpHeaderVisitorImpl.h" + #include "ns_globals.h" // for prLogModuleInfo -EmbedProgress::EmbedProgress(void) +EmbedProgress::EmbedProgress(void) : mCapturePageInfo(JNI_FALSE) { mOwner = nsnull; mEventRegistration = nsnull; @@ -84,6 +86,13 @@ EmbedProgress::SetEventRegistration(jobject yourEventRegistration) return rv; } +nsresult +EmbedProgress::SetCapturePageInfo(jboolean newState) +{ + mCapturePageInfo = newState; + return NS_OK; +} + NS_IMETHODIMP EmbedProgress::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, @@ -91,12 +100,26 @@ EmbedProgress::OnStateChange(nsIWebProgress *aWebProgress, nsresult aStatus) { JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); - nsXPIDLCString uriString; RequestToURIString(aRequest, getter_Copies(uriString)); const char * uriCStr = (const char *) uriString; - jstring uriJstr = ::util_NewStringUTF(env, (nsnull != uriCStr - ? uriCStr : "")); + // don't report "about:" URL events. + if (uriString && 5 < uriString.Length() && + 0 == strncmp("about:", uriCStr, 6)) { + return NS_OK; + } + + jstring uriJstr = (jstring) ::util_NewGlobalRef(env, + ::util_NewStringUTF(env, (nsnull != uriCStr + ? uriCStr : ""))); + + jobject properties = ::util_NewGlobalRef(env, + ::util_CreatePropertiesObject(env, + (jobject) + &(mOwner->GetWrapperFactory()->shareContext))); + ::util_StoreIntoPropertiesObject(env, properties, URI_VALUE, uriJstr, + (jobject) + &(mOwner->GetWrapperFactory()->shareContext)); PR_LOG(prLogModuleInfo, PR_LOG_DEBUG, ("EmbedProgress::OnStateChange: URI: %s\n", @@ -111,31 +134,27 @@ EmbedProgress::OnStateChange(nsIWebProgress *aWebProgress, if ((aStateFlags & STATE_IS_NETWORK) && (aStateFlags & STATE_START)) { - if (channel) { - PR_LOG(prLogModuleInfo, PR_LOG_DEBUG, - ("EmbedProgress::OnStateChange: have nsIHttpChannel at START_DOCUMENT_LOAD\n")); - } + PR_LOG(prLogModuleInfo, PR_LOG_DEBUG, + ("EmbedProgress::OnStateChange: START_DOCUMENT_LOAD\n")); util_SendEventToJava(nsnull, mEventRegistration, DOCUMENT_LOAD_LISTENER_CLASSNAME, DocumentLoader_maskValues[START_DOCUMENT_LOAD_EVENT_MASK], - uriJstr); + properties); } // and for stop, too if ((aStateFlags & STATE_IS_NETWORK) && (aStateFlags & STATE_STOP)) { - if (channel) { - PR_LOG(prLogModuleInfo, PR_LOG_DEBUG, - ("EmbedProgress::OnStateChange: have nsIHttpChannel at END_DOCUMENT_LOAD\n")); - } + PR_LOG(prLogModuleInfo, PR_LOG_DEBUG, + ("EmbedProgress::OnStateChange: END_DOCUMENT_LOAD\n")); util_SendEventToJava(nsnull, mEventRegistration, DOCUMENT_LOAD_LISTENER_CLASSNAME, DocumentLoader_maskValues[END_DOCUMENT_LOAD_EVENT_MASK], - uriJstr); + properties); } @@ -143,22 +162,39 @@ EmbedProgress::OnStateChange(nsIWebProgress *aWebProgress, // request states // if ((aStateFlags & STATE_START) && (aStateFlags & STATE_IS_REQUEST)) { + PR_LOG(prLogModuleInfo, PR_LOG_DEBUG, + ("EmbedProgress::OnStateChange: START_URL_LOAD\n")); + util_SendEventToJava(nsnull, mEventRegistration, DOCUMENT_LOAD_LISTENER_CLASSNAME, DocumentLoader_maskValues[START_URL_LOAD_EVENT_MASK], - uriJstr); + properties); } if ((aStateFlags & STATE_STOP) && (aStateFlags & STATE_IS_REQUEST)) { + PR_LOG(prLogModuleInfo, PR_LOG_DEBUG, + ("EmbedProgress::OnStateChange: END_URL_LOAD\n")); + + if (channel && mCapturePageInfo) { + HttpHeaderVisitorImpl *visitor = + new HttpHeaderVisitorImpl(env, + properties, (jobject) + &(mOwner->GetWrapperFactory()->shareContext)); + channel->VisitResponseHeaders(visitor); + delete visitor; + } + util_SendEventToJava(nsnull, mEventRegistration, DOCUMENT_LOAD_LISTENER_CLASSNAME, DocumentLoader_maskValues[END_URL_LOAD_EVENT_MASK], - uriJstr); + properties); } - ::util_DeleteStringUTF(env, uriJstr); + // ::util_DestroyPropertiesObject(env, properties, nsnull); + + // ::util_DeleteStringUTF(env, uriJstr); return NS_OK; } @@ -174,10 +210,31 @@ EmbedProgress::OnProgressChange(nsIWebProgress *aWebProgress, nsXPIDLCString uriString; RequestToURIString(aRequest, getter_Copies(uriString)); + const char * uriCStr = (const char *) uriString; PRInt32 percentComplete = 0; nsCAutoString name; nsAutoString autoName; nsresult rv = NS_OK; + + // don't report "about:" URL events. + if (uriString && 5 < uriString.Length() && + 0 == strncmp("about:", (const char *) uriString, 6)) { + return NS_OK; + } + + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + + jstring uriJstr = (jstring) ::util_NewGlobalRef(env, + ::util_NewStringUTF(env, (nsnull != uriCStr + ? uriCStr : ""))); + + jobject properties = ::util_NewGlobalRef(env, + ::util_CreatePropertiesObject(env, + (jobject) + &(mOwner->GetWrapperFactory()->shareContext))); + ::util_StoreIntoPropertiesObject(env, properties, URI_VALUE, uriJstr, + (jobject) + &(mOwner->GetWrapperFactory()->shareContext)); PR_LOG(prLogModuleInfo, PR_LOG_DEBUG, ("EmbedProgress::OnProgressChange: URI: %s\n\taCurSelfProgress: %d\n\taMaxSelfProgress: %d\n\taCurTotalProgress: %d\n\taMaxTotalProgress: %d\n", @@ -199,19 +256,19 @@ EmbedProgress::OnProgressChange(nsIWebProgress *aWebProgress, autoName.AppendInt(percentComplete); autoName.AppendWithConversion("%"); - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + jstring msgJStr = (jstring) ::util_NewGlobalRef(env, + ::util_NewString(env, autoName.get(), autoName.Length())); - jstring msgJStr = ::util_NewString(env, autoName.get(), autoName.Length()); + ::util_StoreIntoPropertiesObject(env, properties, MESSAGE_VALUE, msgJStr, + (jobject) + &(mOwner->GetWrapperFactory()->shareContext)); + util_SendEventToJava(nsnull, mEventRegistration, DOCUMENT_LOAD_LISTENER_CLASSNAME, DocumentLoader_maskValues[PROGRESS_URL_LOAD_EVENT_MASK], - msgJStr); + properties); - if (msgJStr) { - ::util_DeleteString(env, msgJStr); - } - return NS_OK; } @@ -247,8 +304,29 @@ EmbedProgress::OnStatusChange(nsIWebProgress *aWebProgress, nsXPIDLCString uriString; RequestToURIString(aRequest, getter_Copies(uriString)); - jstring msgJstr = ::util_NewString(env, aMessage, - nsCRT::strlen(aMessage)); + const char * uriCStr = (const char *) uriString; + + // don't report "about:" URL events. + if (uriString && 5 < uriString.Length() && + 0 == strncmp("about:", uriString, 6)) { + return NS_OK; + } + + jstring uriJstr = (jstring) ::util_NewGlobalRef(env, + ::util_NewStringUTF(env, (nsnull != uriCStr + ? uriCStr : ""))); + + jobject properties = ::util_NewGlobalRef(env, + ::util_CreatePropertiesObject(env, + (jobject) + &(mOwner->GetWrapperFactory()->shareContext))); + ::util_StoreIntoPropertiesObject(env, properties, URI_VALUE, uriJstr, + (jobject) + &(mOwner->GetWrapperFactory()->shareContext)); + + jstring msgJstr = (jstring) ::util_NewGlobalRef(env, + ::util_NewString(env, aMessage, + nsCRT::strlen(aMessage))); PR_LOG(prLogModuleInfo, PR_LOG_DEBUG, ("EmbedProgress::OnStatusChange: URI: %s\n", @@ -258,11 +336,7 @@ EmbedProgress::OnStatusChange(nsIWebProgress *aWebProgress, mEventRegistration, DOCUMENT_LOAD_LISTENER_CLASSNAME, DocumentLoader_maskValues[STATUS_URL_LOAD_EVENT_MASK], - msgJstr); - - if (msgJstr) { - ::util_DeleteString(env, msgJstr); - } + properties); return NS_OK; } @@ -274,6 +348,12 @@ EmbedProgress::OnSecurityChange(nsIWebProgress *aWebProgress, { nsXPIDLCString uriString; RequestToURIString(aRequest, getter_Copies(uriString)); + + // don't report "about:" URL events. + if (uriString && 5 < uriString.Length() && + 0 == strncmp("about:", (const char *) uriString, 6)) { + return NS_OK; + } PR_LOG(prLogModuleInfo, PR_LOG_DEBUG, ("EmbedProgress::OnSecurityChange: URI: %s\n", diff --git a/mozilla/java/webclient/src_moz/EmbedProgress.h b/mozilla/java/webclient/src_moz/EmbedProgress.h index 9926bda06bb..1e576b14546 100644 --- a/mozilla/java/webclient/src_moz/EmbedProgress.h +++ b/mozilla/java/webclient/src_moz/EmbedProgress.h @@ -40,6 +40,8 @@ class EmbedProgress : public nsIWebProgressListener, nsresult SetEventRegistration(jobject eventRegistration); + nsresult SetCapturePageInfo(jboolean newState); + NS_DECL_ISUPPORTS NS_DECL_NSIWEBPROGRESSLISTENER @@ -51,6 +53,8 @@ class EmbedProgress : public nsIWebProgressListener, NativeBrowserControl *mOwner; jobject mEventRegistration; + + jboolean mCapturePageInfo; }; #endif /* __EmbedProgress_h */ diff --git a/mozilla/java/webclient/src_moz/EventRegistrationImpl.cpp b/mozilla/java/webclient/src_moz/EventRegistrationImpl.cpp new file mode 100644 index 00000000000..1ee5511bef7 --- /dev/null +++ b/mozilla/java/webclient/src_moz/EventRegistrationImpl.cpp @@ -0,0 +1,42 @@ +/* -*- 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 + * Mark Lin + * Mark Goddard + * Ed Burns + * Ashutosh Kulkarni + */ + +#include "org_mozilla_webclient_impl_wrapper_0005fnative_EventRegistrationImpl.h" + +#include "ns_util.h" +#include "NativeBrowserControl.h" +#include "EmbedProgress.h" + +JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_EventRegistrationImpl_nativeSetCapturePageInfo +(JNIEnv *env, jobject obj, jint nativeBCPtr, jboolean newState) +{ + + NativeBrowserControl* nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr; + nativeBrowserControl->mProgress->SetCapturePageInfo(newState); + +} + diff --git a/mozilla/java/webclient/src_moz/HttpHeaderVisitorImpl.cpp b/mozilla/java/webclient/src_moz/HttpHeaderVisitorImpl.cpp new file mode 100644 index 00000000000..10540a470fa --- /dev/null +++ b/mozilla/java/webclient/src_moz/HttpHeaderVisitorImpl.cpp @@ -0,0 +1,79 @@ +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Christopher Blizzard. + * Portions created by Christopher Blizzard are Copyright (C) + * Christopher Blizzard. All Rights Reserved. + * + * Contributor(s): + * Ed Burns + */ + +#include "HttpHeaderVisitorImpl.h" + +#include +#include + +#include "ns_globals.h" // for prLogModuleInfo +#include "jni_util.h" + +NS_IMPL_ISUPPORTS1(HttpHeaderVisitorImpl, nsIHttpHeaderVisitor) + +HttpHeaderVisitorImpl::HttpHeaderVisitorImpl(JNIEnv * yourEnv, + jobject yourProperties, + jobject yourInitContext) : + mJNIEnv(yourEnv), + mInitContext(yourInitContext) +{ + // create the inner properties object, into which we'll store our + // headers + mProperties = ::util_NewGlobalRef(mJNIEnv, + ::util_CreatePropertiesObject(mJNIEnv, mInitContext)); + + // store it under the key "headers" in the outer properties object + ::util_StoreIntoPropertiesObject(mJNIEnv, yourProperties, HEADERS_VALUE, + mProperties, mInitContext); +} + +HttpHeaderVisitorImpl::~HttpHeaderVisitorImpl() +{ + mJNIEnv = nsnull; + mProperties = nsnull; + mInitContext = nsnull; +} + +NS_IMETHODIMP +HttpHeaderVisitorImpl::VisitHeader(const nsACString &header, + const nsACString &value) +{ + jstring + headerName = (jstring) + ::util_NewGlobalRef(mJNIEnv, + ::util_NewStringUTF(mJNIEnv, + PromiseFlatCString(header).get())), + headerValue = (jstring) + ::util_NewGlobalRef(mJNIEnv, + ::util_NewStringUTF(mJNIEnv, + PromiseFlatCString(value).get())); + + ::util_StoreIntoPropertiesObject(mJNIEnv, mProperties, headerName, + headerValue, mInitContext); + PR_LOG(prLogModuleInfo, PR_LOG_DEBUG, + ("HttpHeaderVisitorImpl::VisitHeader: name: %s value: %s\n", + PromiseFlatCString(header).get(), + PromiseFlatCString(value).get())); + // ::util_DeleteLocalRef(mJNIEnv, headerName); + // ::util_DeleteLocalRef(mJNIEnv, headerValue); + + return NS_OK; +} diff --git a/mozilla/java/webclient/src_moz/HttpHeaderVisitorImpl.h b/mozilla/java/webclient/src_moz/HttpHeaderVisitorImpl.h new file mode 100644 index 00000000000..bfd9747acc1 --- /dev/null +++ b/mozilla/java/webclient/src_moz/HttpHeaderVisitorImpl.h @@ -0,0 +1,40 @@ +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Christopher Blizzard. + * Portions created by Christopher Blizzard are Copyright (C) + * Christopher Blizzard. All Rights Reserved. + * + * Contributor(s): + * Ed Burns + */ + +#include "nsIHttpHeaderVisitor.h" + +#include "jni.h" + +class HttpHeaderVisitorImpl : public nsIHttpHeaderVisitor +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIHTTPHEADERVISITOR + + HttpHeaderVisitorImpl(JNIEnv *myEnv, jobject myProperties, + jobject myInitContext); + virtual ~HttpHeaderVisitorImpl(); + +private: + JNIEnv *mJNIEnv; + jobject mProperties; + jobject mInitContext; + }; diff --git a/mozilla/java/webclient/src_moz/Makefile.in b/mozilla/java/webclient/src_moz/Makefile.in index 9a11849270d..070234e8276 100644 --- a/mozilla/java/webclient/src_moz/Makefile.in +++ b/mozilla/java/webclient/src_moz/Makefile.in @@ -105,6 +105,8 @@ CPPSRCS = \ NativeWrapperFactory.cpp \ EmbedWindow.cpp \ EmbedProgress.cpp \ + EventRegistrationImpl.cpp \ + HttpHeaderVisitorImpl.cpp \ NativeEventThread.cpp \ NavigationImpl.cpp \ ns_util.cpp \ diff --git a/mozilla/java/webclient/src_moz/NativeBrowserControl.cpp b/mozilla/java/webclient/src_moz/NativeBrowserControl.cpp index 32109b466d5..560378f4505 100644 --- a/mozilla/java/webclient/src_moz/NativeBrowserControl.cpp +++ b/mozilla/java/webclient/src_moz/NativeBrowserControl.cpp @@ -61,13 +61,15 @@ NativeBrowserControl::~NativeBrowserControl() } nsresult -NativeBrowserControl::Init() +NativeBrowserControl::Init(NativeWrapperFactory *yourWrapperFactory) { if (!util_StringConstantsAreInitialized()) { util_InitStringConstants(); } + wrapperFactory = yourWrapperFactory; + // Create our embed window, and create an owning reference to it and // initialize it. It is assumed that this window will be destroyed // when we go out of scope. @@ -234,6 +236,11 @@ NativeBrowserControl::Destroy(void) parentHWnd = nsnull; } +NativeWrapperFactory *NativeBrowserControl::GetWrapperFactory() +{ + return wrapperFactory; +} + jobject NativeBrowserControl::QueryInterfaceJava(WEBCLIENT_INTERFACES interface) { PR_ASSERT(nsnull != mJavaBrowserControl); diff --git a/mozilla/java/webclient/src_moz/NativeBrowserControl.h b/mozilla/java/webclient/src_moz/NativeBrowserControl.h index d39276df9fc..e70d99313ca 100644 --- a/mozilla/java/webclient/src_moz/NativeBrowserControl.h +++ b/mozilla/java/webclient/src_moz/NativeBrowserControl.h @@ -42,6 +42,7 @@ class EmbedProgress; class EmbedWindow; +class NativeWrapperFactory; /** *

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.");