a=edburns

bug: pressing BACK hangs webclient

Files touched

File: DocumentLoadEvent.java	Status: Locally Modified

Made the constants final so they can be used in a
switch statement

File: EMWindow.java    	Status: Locally Modified

Modified eventDispatched() so it doesn't call any webclient
events.  This was causing the hang.  Took advantage of
the newly implemented ability to pass a string from the
mozilla event handler into java.


File: DocumentLoaderObserverImpl.cpp	Status: Locally Modified

Create a jstring from the url in the OnStartDocumentLoad event.
Pass it on to java.

File: jni_util.cpp	Status: Locally Modified

Wrapped JNU_GetEnv in BAL stuff so it works from Star.

File: WebclinetEventListener.java	Status: Locally Modified

Added comment to eventDispatched.


git-svn-id: svn://10.0.0.236/trunk@66829 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
edburns%acm.org
2000-04-22 02:01:20 +00:00
parent c7c27b019e
commit 8f4e04f72f
5 changed files with 77 additions and 20 deletions

View File

@@ -25,14 +25,14 @@ package org.mozilla.webclient;
public class DocumentLoadEvent extends WebclientEvent
{
public static long START_DOCUMENT_LOAD_EVENT_MASK = 1;
public static long END_DOCUMENT_LOAD_EVENT_MASK = 1 << 2;
public static long START_URL_LOAD_EVENT_MASK = 1 << 3;
public static long END_URL_LOAD_EVENT_MASK = 1 << 4;
public static long PROGRESS_URL_LOAD_EVENT_MASK = 1 << 5;
public static long STATUS_URL_LOAD_EVENT_MASK = 1 << 6;
public static long UNKNOWN_CONTENT_EVENT_MASK = 1 << 7;
public static long FETCH_INTERRUPT_EVENT_MASK = 1 << 8;
public static final long START_DOCUMENT_LOAD_EVENT_MASK = 1;
public static final long END_DOCUMENT_LOAD_EVENT_MASK = 1 << 2;
public static final long START_URL_LOAD_EVENT_MASK = 1 << 3;
public static final long END_URL_LOAD_EVENT_MASK = 1 << 4;
public static final long PROGRESS_URL_LOAD_EVENT_MASK = 1 << 5;
public static final long STATUS_URL_LOAD_EVENT_MASK = 1 << 6;
public static final long UNKNOWN_CONTENT_EVENT_MASK = 1 << 7;
public static final long FETCH_INTERRUPT_EVENT_MASK = 1 << 8;
//
// Constructors

View File

@@ -25,6 +25,13 @@ package org.mozilla.webclient;
public interface WebclientEventListener
{
/**
* Important: do not call any webclient methods during this callback.
* It may caus your app to deadlock.
*/
public void eventDispatched(WebclientEvent event);
} // end of interface WebclientEventListener

View File

@@ -50,7 +50,7 @@ import org.mozilla.util.Assert;
* This is a test application for using the BrowserControl.
*
* @version $Id: EMWindow.java,v 1.4 2000-04-20 03:16:15 ashuk%eng.sun.com Exp $
* @version $Id: EMWindow.java,v 1.5 2000-04-22 02:00:57 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.BrowserControlFactory
@@ -120,6 +120,8 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc
// Create the URL field
urlField = new TextField("", 30);
urlField.addActionListener(this);
urlField.setText(url);
// Create the buttons sub panel
buttonsPanel = new Panel();
@@ -436,13 +438,24 @@ public void dialogCancelled(Dialog d) {
// From DocumentLoadListener
//
/**
* Important: do not call any webclient methods during this callback.
* It may caus your app to deadlock.
*/
public void eventDispatched(WebclientEvent event)
{
if (event instanceof DocumentLoadEvent) {
String currentURL = currentPage.getCurrentURL();
System.out.println("debug: edburns: Currently Viewing: " +
currentURL);
urlField.setText(currentURL);
switch ((int) event.getType()) {
case ((int) DocumentLoadEvent.START_DOCUMENT_LOAD_EVENT_MASK):
String currentURL = (String) event.getEventData();
System.out.println("debug: edburns: Currently Viewing: " +
currentURL);
urlField.setText(currentURL);
break;
}
}
}

View File

@@ -39,6 +39,8 @@
// end of take this out
#endif
#include "prlog.h" // for PR_ASSERT
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIDocumentLoaderObserverIID, NS_IDOCUMENT_LOADER_OBSERVER_IID);
@@ -80,6 +82,9 @@ DocumentLoaderObserverImpl::DocumentLoaderObserverImpl(JNIEnv *env,
if (nsnull == gVm) { // declared in jni_util.h
::util_GetJavaVM(env, &gVm); // save this vm reference away for the callback!
}
#ifndef BAL_INTERFACE
PR_ASSERT(gVm);
#endif
if (-1 == maskValues[0]) {
util_InitializeEventMaskValuesFromClass("org/mozilla/webclient/DocumentLoadEvent",
@@ -117,9 +122,35 @@ NS_IMETHODIMP DocumentLoaderObserverImpl::OnStartDocumentLoad(nsIDocumentLoader*
("DocumentLoaderObserverImpl.cpp: OnStartDocumentLoad\n"));
}
#endif
char *urlStr = nsnull;
jobject urlJStr = nsnull;
if (nsnull != aURL) {
// IMPORTANT: do not use initContext->env here since it comes
// from another thread. Use JNU_GetEnv instead.
JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2);
aURL->GetSpec(&urlStr);
if (nsnull != urlStr) {
urlJStr = (jobject) ::util_NewStringUTF(env, urlStr);
::Recycle(urlStr);
}
}
util_SendEventToJava(mInitContext->env,
mInitContext->nativeEventThread, mTarget,
maskValues[START_DOCUMENT_LOAD_EVENT_MASK], nsnull);
maskValues[START_DOCUMENT_LOAD_EVENT_MASK], urlJStr);
#ifdef BAL_INTERFACE
// This violates my goal of confining all #ifdef BAL_INTERFACE to
// jni_util files, but this is the only part of the code that knows
// that eventData is a jstring. In java, this will get garbage
// collected, but in non-java contexts, it will not. Thus, we have
// to manually de-allocate it.
if (urlJStr) {
::util_DeleteStringUTF(mInitContext->env, (jstring) urlJStr);
}
#endif
return NS_OK;
}
@@ -186,8 +217,12 @@ NS_IMETHODIMP DocumentLoaderObserverImpl::OnStatusURLLoad(nsIDocumentLoader* loa
}
#endif
int length = aMsg.Length();
jstring statusMessage = ::util_NewString(mInitContext->env,
aMsg.GetUnicode(), length);
// IMPORTANT: do not use initContext->env here since it comes
// from another thread. Use JNU_GetEnv instead.
JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2);
jstring statusMessage = ::util_NewString(env, aMsg.GetUnicode(), length);
util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mTarget,
maskValues[STATUS_URL_LOAD_EVENT_MASK], (jobject) statusMessage);
@@ -198,8 +233,9 @@ NS_IMETHODIMP DocumentLoaderObserverImpl::OnStatusURLLoad(nsIDocumentLoader* loa
// that eventData is a jstring. In java, this will get garbage
// collected, but in non-java contexts, it will not. Thus, we have
// to manually de-allocate it.
::util_DeleteString(mInitContext->env, statusMessage);
if (statusMessage) {
::util_DeleteString(mInitContext->env, statusMessage);
}
#endif
return NS_OK;

View File

@@ -453,10 +453,11 @@ JNU_GetEnv(JavaVM *vm, jint version)
{
// void *result;
//vm->GetEnv(&result, version);
JNIEnv *result = nsnull;
#ifdef BAL_INTERFACE
#else
vm->AttachCurrentThread((void **)&result, (void *) version);
#endif
return result;
}