This checkin enables finding out the request method and response status

of a URL_LOAD event.  I'm still working on getting the request body via
the nsIUploadChannel interface.  Next step will be to get that working.
I'm currently running into problems where the END_URL event for a POST
doesn't have a status.  I think this is because I'm using the
Navigation.post() method rather than simulating a user post by pressing
a form submit button.

A classes_spec/org/mozilla/webclient/impl/wrapper_native/NativeInputStream.java
A src_moz/NativeInputStreamImpl.cpp

- Class to enable reading the post body from the request.

M build.xml

- add NativeInputStream to JNI generation

M classes_spec/org/mozilla/webclient/PageInfoListener.java

 * <p>This {@link DocumentLoadListener} subclass adds the ability to get
 * detailed information on each event. </p>
 *
 * <p>The <code>eventData</code> property of the
 * <code>DocumentLoadEvent</code> instance will be a
 * <code>java.util.Map</code>.  The following entries may be present in
 * this map for the following <code>*_EVENT_MASK</code> types in
 * <code>DocumentLoadEvent</code>.</p>
 *
 * <dl>
 *
 * <dt>For all <code>*_EVENT_MASK</code> types</dt>
 *
 * <dd><p>the map will contain an entry under the key "<code>URI</code>"
 * without the quotes.  This will be the fully qualified URI for the
 * event. </p></dd>
 *
 * <dt>For <code>START_URL_LOAD</code> type</dt>
 *
 * <dd><p>The map will contain an entry under the key
 * "<code>method</code>" without the quotes.  This will be the request
 * method for this event.  The map will also contain an entry under the
 * key "<code>headers</code>".  This entry will be a
 * <code>java.util.Map</code> of all the request headers.</p></dd>
 *
 * <dt>For <code>END_URL_LOAD</code> type</dt>
 *
 * <dd><p>The map will contain an entry under the key
 * "<code>method</code>" without the quotes.  This will be the request
 * method for this event.  The map will contain an entry under the key
 * "<code>status</code>" without the quotes.  This will be the response
 * status string from the server, such as "<code>200 OK</code>".  The
 * map will also contain an entry under the key "<code>headers</code>".
 * This entry will be a <code>java.util.Map</code> of all the response
 * headers.</p></dd>
 *
 * </dl>

M src_moz/EmbedProgress.cpp

- leverage nsIHttpChannel methods to get request method, response
  status, and post body.

M src_moz/Makefile.in

- add NativeInputStream

M src_share/jni_util.cpp
M src_share/jni_util.h

- new constants

- add variant of ThrowExceptionToJava that takes the exception class name.

M test/automated/src/classes/org/mozilla/webclient/DocumentLoadListenerTest.java

- new test content.  Post related content commented out.


git-svn-id: svn://10.0.0.236/trunk@169991 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
edburns%acm.org
2005-02-28 17:15:45 +00:00
parent 16c226445f
commit 140d778e14
9 changed files with 479 additions and 19 deletions

View File

@@ -24,6 +24,8 @@
#include <nsXPIDLString.h>
#include <nsIChannel.h>
#include <nsIHttpChannel.h>
#include <nsIUploadChannel.h>
#include <nsIInputStream.h>
#include <nsIHttpHeaderVisitor.h>
#include "nsIURI.h"
@@ -104,6 +106,8 @@ EmbedProgress::OnStateChange(nsIWebProgress *aWebProgress,
mOwner->ContentStateChange();
JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION);
nsXPIDLCString uriString;
nsCAutoString cstr;
nsresult rv;
RequestToURIString(aRequest, getter_Copies(uriString));
const char * uriCStr = (const char *) uriString;
// don't report "about:" URL events.
@@ -154,6 +158,67 @@ EmbedProgress::OnStateChange(nsIWebProgress *aWebProgress,
(aStateFlags & STATE_STOP)) {
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("EmbedProgress::OnStateChange: END_DOCUMENT_LOAD\n"));
if (channel && mCapturePageInfo) {
// store the request method
if (NS_SUCCEEDED(rv = channel->GetRequestMethod(cstr))) {
jstring methodJStr = (jstring) ::util_NewGlobalRef(env,
::util_NewStringUTF(env, cstr.get()));
::util_StoreIntoPropertiesObject(env, properties,
METHOD_VALUE, methodJStr,
(jobject)
&(mOwner->GetWrapperFactory()->shareContext));
}
// store the response status
PRUint32 responseStatus;
if (NS_SUCCEEDED(rv =channel->GetResponseStatus(&responseStatus))){
if (NS_SUCCEEDED(rv=channel->GetResponseStatusText(cstr))) {
nsAutoString autoStatus;
autoStatus.AppendInt(responseStatus);
autoStatus.AppendWithConversion(" ");
autoStatus.AppendWithConversion(cstr.get());
jstring statusJStr = (jstring) ::util_NewGlobalRef(env,
::util_NewString(env, autoStatus.get(), autoStatus.Length()));
::util_StoreIntoPropertiesObject(env, properties,
STATUS_VALUE, statusJStr,
(jobject)
&(mOwner->GetWrapperFactory()->shareContext));
}
}
// If there is an upload stream, store it as well
nsCOMPtr<nsIUploadChannel> upload = do_QueryInterface(channel);
if (upload) {
nsIInputStream *uploadStream = nsnull;
if (NS_SUCCEEDED(rv = upload->GetUploadStream(&uploadStream))
&& uploadStream) {
jint pStream;
jclass clazz;
jobject streamObj;
jmethodID jID;
pStream = (jint) uploadStream;
uploadStream->AddRef();
if (clazz = env->FindClass("org/mozilla/webclient/impl/wrapper_native/NativeInputStream")) {
if (jID = env->GetMethodID(clazz, "<init>", "(I)V")) {
if (streamObj = env->NewObject(clazz,jID,pStream)){
if (streamObj = ::util_NewGlobalRef(env,
streamObj)){
::util_StoreIntoPropertiesObject(env,
properties,
REQUEST_BODY_VALUE,
streamObj,
(jobject)
&(mOwner->GetWrapperFactory()->shareContext));
}
}
}
}
}
}
}
util_SendEventToJava(nsnull,
mEventRegistration,
@@ -176,6 +241,17 @@ EmbedProgress::OnStateChange(nsIWebProgress *aWebProgress,
&(mOwner->GetWrapperFactory()->shareContext));
channel->VisitRequestHeaders(visitor);
delete visitor;
// store the request method
if (NS_SUCCEEDED(rv = channel->GetRequestMethod(cstr))) {
jstring methodJStr = (jstring) ::util_NewGlobalRef(env,
::util_NewStringUTF(env, cstr.get()));
::util_StoreIntoPropertiesObject(env, properties,
METHOD_VALUE, methodJStr,
(jobject)
&(mOwner->GetWrapperFactory()->shareContext));
}
}
util_SendEventToJava(nsnull,
@@ -190,12 +266,44 @@ EmbedProgress::OnStateChange(nsIWebProgress *aWebProgress,
("EmbedProgress::OnStateChange: END_URL_LOAD\n"));
if (channel && mCapturePageInfo) {
// store the response headers
HttpHeaderVisitorImpl *visitor =
new HttpHeaderVisitorImpl(env,
properties, (jobject)
&(mOwner->GetWrapperFactory()->shareContext));
channel->VisitResponseHeaders(visitor);
delete visitor;
// store the request method
if (NS_SUCCEEDED(rv = channel->GetRequestMethod(cstr))) {
jstring methodJStr = (jstring) ::util_NewGlobalRef(env,
::util_NewStringUTF(env, cstr.get()));
::util_StoreIntoPropertiesObject(env, properties,
METHOD_VALUE, methodJStr,
(jobject)
&(mOwner->GetWrapperFactory()->shareContext));
}
// store the response status
PRUint32 responseStatus;
if (NS_SUCCEEDED(rv =channel->GetResponseStatus(&responseStatus))){
if (NS_SUCCEEDED(rv=channel->GetResponseStatusText(cstr))) {
nsAutoString autoStatus;
autoStatus.AppendInt(responseStatus);
autoStatus.AppendWithConversion(" ");
autoStatus.AppendWithConversion(cstr.get());
jstring statusJStr = (jstring) ::util_NewGlobalRef(env,
::util_NewString(env, autoStatus.get(), autoStatus.Length()));
::util_StoreIntoPropertiesObject(env, properties,
STATUS_VALUE, statusJStr,
(jobject)
&(mOwner->GetWrapperFactory()->shareContext));
}
}
}
util_SendEventToJava(nsnull,