From 51c33f1e5a54ccafe535c11d531fa8d5beacfdbe Mon Sep 17 00:00:00 2001 From: "edburns%acm.org" Date: Fri, 11 Jun 2004 15:55:48 +0000 Subject: [PATCH] This checkin is the next step for getting DocumentLoadListener to work. I now have the new architecture for pumping events from mozilla back into java. I've added a sequence diagram to and updated the private API class diagram. The next step will be to have the EmbedProgress::On* methods call back to EventRegistration.nativeEventOccured. M src_moz/EmbedProgress.cpp M src_moz/EmbedProgress.h - make this class maintain a reference to the java EventRegistration instance for this BrowserControl M src_moz/NativeBrowserControl.cpp M src_moz/NativeBrowserControl.h - make this class maintain a reference to the java BrowserControl instance. M src_moz/WindowControlImpl.cpp - push the java BrowserControl to the NativeBrowserControl on Realize(). M src_moz/WrapperFactoryImpl.cpp M src_moz/ns_globals.h - expose gImplementedInterfaces in ns_globals.h git-svn-id: svn://10.0.0.236/trunk@157781 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/java/webclient/build-tests.xml | 2 +- .../java/webclient/src_moz/EmbedProgress.cpp | 14 +++++++ .../java/webclient/src_moz/EmbedProgress.h | 7 +++- .../src_moz/NativeBrowserControl.cpp | 42 ++++++++++++++++++- .../webclient/src_moz/NativeBrowserControl.h | 8 +++- .../webclient/src_moz/WindowControlImpl.cpp | 3 +- .../webclient/src_moz/WrapperFactoryImpl.cpp | 2 +- mozilla/java/webclient/src_moz/ns_globals.h | 16 ++++++- 8 files changed, 87 insertions(+), 7 deletions(-) diff --git a/mozilla/java/webclient/build-tests.xml b/mozilla/java/webclient/build-tests.xml index 607fe7394f5..58abc77fc82 100644 --- a/mozilla/java/webclient/build-tests.xml +++ b/mozilla/java/webclient/build-tests.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/mozilla/java/webclient/src_moz/EmbedProgress.cpp b/mozilla/java/webclient/src_moz/EmbedProgress.cpp index a34a92fa2fe..ad130986c0c 100644 --- a/mozilla/java/webclient/src_moz/EmbedProgress.cpp +++ b/mozilla/java/webclient/src_moz/EmbedProgress.cpp @@ -50,9 +50,23 @@ nsresult EmbedProgress::Init(NativeBrowserControl *aOwner) { mOwner = aOwner; + + if (-1 == DocumentLoader_maskValues[0]) { + util_InitializeEventMaskValuesFromClass("org/mozilla/webclient/DocumentLoadEvent", + DocumentLoader_maskNames, + DocumentLoader_maskValues); + } + return NS_OK; } +nsresult +EmbedProgress::SetEventRegistration(jobject yourEventRegistration) +{ + mEventRegistration = yourEventRegistration; + return NS_OK; +} + NS_IMETHODIMP EmbedProgress::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, diff --git a/mozilla/java/webclient/src_moz/EmbedProgress.h b/mozilla/java/webclient/src_moz/EmbedProgress.h index e983ac79015..9926bda06bb 100644 --- a/mozilla/java/webclient/src_moz/EmbedProgress.h +++ b/mozilla/java/webclient/src_moz/EmbedProgress.h @@ -25,6 +25,8 @@ #include #include +#include "jni_util.h" + class NativeBrowserControl; class EmbedProgress : public nsIWebProgressListener, @@ -36,6 +38,8 @@ class EmbedProgress : public nsIWebProgressListener, nsresult Init(NativeBrowserControl *aOwner); + nsresult SetEventRegistration(jobject eventRegistration); + NS_DECL_ISUPPORTS NS_DECL_NSIWEBPROGRESSLISTENER @@ -45,7 +49,8 @@ class EmbedProgress : public nsIWebProgressListener, static void RequestToURIString (nsIRequest *aRequest, char **aString); NativeBrowserControl *mOwner; - + + jobject mEventRegistration; }; #endif /* __EmbedProgress_h */ diff --git a/mozilla/java/webclient/src_moz/NativeBrowserControl.cpp b/mozilla/java/webclient/src_moz/NativeBrowserControl.cpp index d22e5099ee4..9380c704bc7 100644 --- a/mozilla/java/webclient/src_moz/NativeBrowserControl.cpp +++ b/mozilla/java/webclient/src_moz/NativeBrowserControl.cpp @@ -42,6 +42,7 @@ NativeBrowserControl::NativeBrowserControl(void) mNavigation = nsnull; mSessionHistory = nsnull; mWindow = nsnull; + mJavaBrowserControl = nsnull; mChromeMask = 0; mIsChrome = PR_FALSE; mChromeLoaded = PR_FALSE; @@ -54,6 +55,7 @@ NativeBrowserControl::~NativeBrowserControl() mChromeMask = 0; mIsChrome = PR_FALSE; mChromeLoaded = PR_FALSE; + mJavaBrowserControl = nsnull; } nsresult @@ -93,9 +95,12 @@ NativeBrowserControl::Init() } nsresult -NativeBrowserControl::Realize(void *parentWinPtr, PRBool *aAlreadyRealized, +NativeBrowserControl::Realize(jobject javaBrowserControl, + void *parentWinPtr, PRBool *aAlreadyRealized, PRUint32 width, PRUint32 height) { + mJavaBrowserControl = javaBrowserControl; + // Create our session history object and tell the navigation object // to use it. We need to do this before we create the web browser // window. @@ -123,6 +128,18 @@ NativeBrowserControl::Realize(void *parentWinPtr, PRBool *aAlreadyRealized, mWindow->AddWebBrowserListener(weakRef, nsIWebProgressListener::GetIID()); + // set the eventRegistration into the progress listener + jobject eventRegistration = + this->QueryInterfaceJava(EVENT_REGISTRATION_INDEX); + if (nsnull != eventRegistration) { + mProgress->SetEventRegistration(eventRegistration); + } + else { + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + ::util_ThrowExceptionToJava(env, "Can't get EventRegistration from BrowserControl"); + } + + return NS_OK; } @@ -204,4 +221,27 @@ NativeBrowserControl::Destroy(void) parentHWnd = nsnull; } + +jobject NativeBrowserControl::QueryInterfaceJava(WEBCLIENT_INTERFACES interface) +{ + PR_ASSERT(nsnull != mJavaBrowserControl); + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + + jobject result = nsnull; + jstring interfaceJStr = ::util_NewStringUTF(env, + gImplementedInterfaces[interface]); + jclass clazz = env->GetObjectClass(mJavaBrowserControl); + jmethodID mid = env->GetMethodID(clazz, "queryInterface", + "(Ljava/lang/String;)Ljava/lang/Object;"); + if (nsnull != mid) { + result = env->CallObjectMethod(mJavaBrowserControl, mid, + interfaceJStr); + } + else { + ::util_ThrowExceptionToJava(env, "Can't QueryInterface BrowserControl"); + } + ::util_DeleteStringUTF(env, interfaceJStr); + + return result; +} diff --git a/mozilla/java/webclient/src_moz/NativeBrowserControl.h b/mozilla/java/webclient/src_moz/NativeBrowserControl.h index dc8155c785f..d39276df9fc 100644 --- a/mozilla/java/webclient/src_moz/NativeBrowserControl.h +++ b/mozilla/java/webclient/src_moz/NativeBrowserControl.h @@ -61,7 +61,8 @@ public: // nsresult Init (); - nsresult Realize (void* parentWinPtr, + nsresult Realize (jobject javaBrowserControl, + void* parentWinPtr, PRBool *aAlreadyRealized, PRUint32 width, PRUint32 height); void Unrealize (void); @@ -71,6 +72,9 @@ public: PRUint32 aWidth, PRUint32 aHeight); void Destroy (void); + jobject QueryInterfaceJava(WEBCLIENT_INTERFACES interface); + + // // Relationship ivars // @@ -99,6 +103,8 @@ public: // has someone called Destroy() on us? PRBool mIsDestroyed; + jobject mJavaBrowserControl; + }; #endif // NativeBrowserControl_h diff --git a/mozilla/java/webclient/src_moz/WindowControlImpl.cpp b/mozilla/java/webclient/src_moz/WindowControlImpl.cpp index be85963353c..22ed87d4337 100644 --- a/mozilla/java/webclient/src_moz/WindowControlImpl.cpp +++ b/mozilla/java/webclient/src_moz/WindowControlImpl.cpp @@ -50,7 +50,8 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_WindowCon // PENDING set this into the nativeBrowserControl for use later #endif - nativeBrowserControl->Realize((void *) windowPtr, &alreadyRealized, + nativeBrowserControl->Realize(aBrowserControlImpl, + (void *) windowPtr, &alreadyRealized, width, height); } diff --git a/mozilla/java/webclient/src_moz/WrapperFactoryImpl.cpp b/mozilla/java/webclient/src_moz/WrapperFactoryImpl.cpp index 809cf5b141a..34dd47feed2 100644 --- a/mozilla/java/webclient/src_moz/WrapperFactoryImpl.cpp +++ b/mozilla/java/webclient/src_moz/WrapperFactoryImpl.cpp @@ -59,7 +59,7 @@ static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID); PRLogModuleInfo *prLogModuleInfo = NULL; // declared in ns_globals.h -const char *gImplementedInterfaces[] = { +const char *gImplementedInterfaces[] = { // declared in ns_globals.h "webclient.WindowControl", "webclient.Navigation", "webclient.CurrentPage", diff --git a/mozilla/java/webclient/src_moz/ns_globals.h b/mozilla/java/webclient/src_moz/ns_globals.h index 59ba46f6ca9..05d1a9d8a2a 100644 --- a/mozilla/java/webclient/src_moz/ns_globals.h +++ b/mozilla/java/webclient/src_moz/ns_globals.h @@ -37,7 +37,21 @@ #define ns_globals_h #include "prlog.h" -extern PRLogModuleInfo *prLogModuleInfo; // defined in WrapperFactory.cpp +extern PRLogModuleInfo *prLogModuleInfo; // defined in WrapperFactoryImpl.cpp + +extern const char *gImplementedInterfaces[]; // defined in WrapperFactoryImpl.cpp + +typedef enum { + WINDOW_CONTROL_INDEX = 0, + NAVIGATION_INDEX, + CURRENT_PAGE_INDEX, + HISTORY_INDEX, + EVENT_REGISTRATION_INDEX, + BOOKMARKS_INDEX, + PREFERENCES_INDEX, + PROFILE_MANAGER_INDEX +} WEBCLIENT_INTERFACES; + /**