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:
* <p>The <code>eventDispatched()</code> method is passed a {@link
* DocumentLoadEvent} instance. The <code>type</code> property of the
* event will be one of the types defined as a <code>public static final
* int</code> in <code>DocumentLoadEvent</code>.</p>
*
* <p>The <code>eventData</code> property of the
* <code>DocumentLoadEvent</code> instance will be a
* <code>java.util.Map</code>. For all <code>EVENT_MASK</code> types in
* <code>DocumentLoadEvent</code> 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>
*
* <p>For the <code>PROGRESS_URL_LOAD_EVENT_MASK</code> there will be an
* entry in the map for the key "<code>message</code>". This will be
* the progress message from the browser.</p>
PageInfoListener:
* <p>This {@link DocumentLoadListener} subclass adds the ability to get
* detailed information on each event. </p>
*
* <p>The <code>eventDispatched()</code> method is passed the same thing
* as in the {@link DocumentLoadListener}.</p>
*
* <p>The <code>eventData</code> property of the
* <code>DocumentLoadEvent</code> instance will be a
* <code>java.util.Map</code>. For the
* <code>END_URL_LOAD_EVENT_MASK</code> type in
* <code>DocumentLoadEvent</code> 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. The map will also contain an
* entry under the key "<code>headers</code>". This entry will be a
* <code>Map</code> of all the response headers.</p>
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
267 lines
8.5 KiB
C++
267 lines
8.5 KiB
C++
/* -*- 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 <kbaker@eb.com>
|
|
* Ian Wilkinson <iw@ennoble.com>
|
|
* Mark Lin <mark.lin@eng.sun.com>
|
|
* Mark Goddard
|
|
* Ed Burns <edburns@acm.org>
|
|
* Ashutosh Kulkarni <ashuk@eng.sun.com>
|
|
* Ann Sunhachawee
|
|
*/
|
|
|
|
#include "nsIEventQueueService.h" // for PLEventQueue
|
|
#include "nsIServiceManager.h" // for do_GetService
|
|
#include "nsEmbedAPI.h" // for NS_HandleEmbeddingEvent
|
|
#include <nsIWindowWatcher.h> // for initializing our window watcher service
|
|
|
|
#include "EmbedWindow.h"
|
|
#include "WindowCreator.h"
|
|
#include "EmbedProgress.h"
|
|
#include "NativeBrowserControl.h"
|
|
#include "ns_util.h"
|
|
|
|
|
|
NativeBrowserControl::NativeBrowserControl(void)
|
|
{
|
|
parentHWnd = nsnull;
|
|
mNavigation = nsnull;
|
|
mSessionHistory = nsnull;
|
|
mWindow = nsnull;
|
|
mJavaBrowserControl = nsnull;
|
|
mChromeMask = 0;
|
|
mIsChrome = PR_FALSE;
|
|
mChromeLoaded = PR_FALSE;
|
|
mIsDestroyed = PR_FALSE;
|
|
}
|
|
|
|
NativeBrowserControl::~NativeBrowserControl()
|
|
{
|
|
// PENDING(edburns): assert that this widget has been destroyed
|
|
mChromeMask = 0;
|
|
mIsChrome = PR_FALSE;
|
|
mChromeLoaded = PR_FALSE;
|
|
mJavaBrowserControl = nsnull;
|
|
}
|
|
|
|
nsresult
|
|
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.
|
|
mWindow = new EmbedWindow();
|
|
mWindowGuard = NS_STATIC_CAST(nsIWebBrowserChrome *, mWindow);
|
|
mWindow->Init(this);
|
|
|
|
// Create our progress listener object, make an owning reference,
|
|
// and initialize it. It is assumed that this progress listener
|
|
// will be destroyed when we go out of scope.
|
|
mProgress = new EmbedProgress();
|
|
mProgressGuard = NS_STATIC_CAST(nsIWebProgressListener *,
|
|
mProgress);
|
|
mProgress->Init(this);
|
|
|
|
|
|
nsCOMPtr<nsIWebBrowser> webBrowser;
|
|
mWindow->GetWebBrowser(getter_AddRefs(webBrowser));
|
|
|
|
// get a handle on the navigation object
|
|
mNavigation = do_QueryInterface(webBrowser);
|
|
|
|
|
|
//
|
|
// create the WindowCreator: see
|
|
WindowCreator *creator = new WindowCreator(this);
|
|
nsCOMPtr<nsIWindowCreator> windowCreator;
|
|
windowCreator = NS_STATIC_CAST(nsIWindowCreator *, creator);
|
|
|
|
// Attach it via the watcher service
|
|
nsCOMPtr<nsIWindowWatcher> watcher = do_GetService(NS_WINDOWWATCHER_CONTRACTID);
|
|
if (watcher) {
|
|
watcher->SetWindowCreator(windowCreator);
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
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.
|
|
mSessionHistory = do_CreateInstance(NS_SHISTORY_CONTRACTID);
|
|
mNavigation->SetSessionHistory(mSessionHistory);
|
|
|
|
#ifdef XP_UNIX
|
|
PR_ASSERT(PR_FALSE);
|
|
GtkWidget *ownerAsWidget (GTK_WIDGET(parentWinPtr));
|
|
parentHWnd = ownerAsWidget;
|
|
width = ownerAsWidget->allocation.width;
|
|
height = ownerAsWidget->allocation.height;
|
|
#else
|
|
parentHWnd = (HWND) parentWinPtr;
|
|
#endif
|
|
|
|
// create the window
|
|
mWindow->CreateWindow_(width, height);
|
|
|
|
// bind the progress listener to the browser object
|
|
nsCOMPtr<nsISupportsWeakReference> supportsWeak;
|
|
supportsWeak = do_QueryInterface(mProgressGuard);
|
|
nsCOMPtr<nsIWeakReference> weakRef;
|
|
supportsWeak->GetWeakReference(getter_AddRefs(weakRef));
|
|
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;
|
|
}
|
|
|
|
void
|
|
NativeBrowserControl::Unrealize(void)
|
|
{
|
|
}
|
|
|
|
void
|
|
NativeBrowserControl::Show(void)
|
|
{
|
|
// Get the nsIWebBrowser object for our embedded window.
|
|
nsCOMPtr<nsIWebBrowser> webBrowser;
|
|
mWindow->GetWebBrowser(getter_AddRefs(webBrowser));
|
|
|
|
// and set the visibility on the thing
|
|
nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(webBrowser);
|
|
baseWindow->SetVisibility(PR_TRUE);
|
|
}
|
|
|
|
void
|
|
NativeBrowserControl::Hide(void)
|
|
{
|
|
// Get the nsIWebBrowser object for our embedded window.
|
|
nsCOMPtr<nsIWebBrowser> webBrowser;
|
|
mWindow->GetWebBrowser(getter_AddRefs(webBrowser));
|
|
|
|
// and set the visibility on the thing
|
|
nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(webBrowser);
|
|
baseWindow->SetVisibility(PR_FALSE);
|
|
}
|
|
|
|
void
|
|
NativeBrowserControl::Resize(PRUint32 x, PRUint32 y,
|
|
PRUint32 aWidth, PRUint32 aHeight)
|
|
{
|
|
mWindow->SetDimensions(nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION |
|
|
nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER,
|
|
x, y, aWidth, aHeight);
|
|
}
|
|
|
|
void
|
|
NativeBrowserControl::Destroy(void)
|
|
{
|
|
mIsDestroyed = PR_TRUE;
|
|
// PENDING(edburns): take over the stuff from
|
|
// WindowControlActionEvents
|
|
// wsDeallocateInitContextEvent::handleEvent()
|
|
|
|
// This flag might have been set from
|
|
// EmbedWindow::DestroyBrowserWindow() as well if someone used a
|
|
// window.close() or something or some other script action to close
|
|
// the window. No harm setting it again.
|
|
|
|
// Get the nsIWebBrowser object for our embedded window.
|
|
nsCOMPtr<nsIWebBrowser> webBrowser;
|
|
mWindow->GetWebBrowser(getter_AddRefs(webBrowser));
|
|
|
|
// destroy our child window
|
|
mWindow->ReleaseChildren();
|
|
|
|
// release navigation
|
|
mNavigation = nsnull;
|
|
|
|
// Release our progress listener
|
|
nsCOMPtr<nsISupportsWeakReference> supportsWeak;
|
|
supportsWeak = do_QueryInterface(mProgressGuard);
|
|
nsCOMPtr<nsIWeakReference> weakRef;
|
|
supportsWeak->GetWeakReference(getter_AddRefs(weakRef));
|
|
webBrowser->RemoveWebBrowserListener(weakRef,
|
|
nsIWebProgressListener::GetIID());
|
|
weakRef = nsnull;
|
|
supportsWeak = nsnull;
|
|
|
|
// Now that we have removed the listener, release our progress
|
|
// object
|
|
mProgressGuard = nsnull;
|
|
mProgress = nsnull;
|
|
|
|
parentHWnd = nsnull;
|
|
}
|
|
|
|
NativeWrapperFactory *NativeBrowserControl::GetWrapperFactory()
|
|
{
|
|
return wrapperFactory;
|
|
}
|
|
|
|
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;
|
|
}
|