2000-08-10 05:33:35 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2003-04-13 01:40:35 +04:00
|
|
|
*
|
2000-08-10 05:33:35 +04:00
|
|
|
* 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): Glenn Barney <gbarney@uiuc.edu>
|
2003-04-13 01:40:35 +04:00
|
|
|
* Ron Capelli <capelli@us.ibm.com>
|
2000-08-10 05:33:35 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define IDD_MYDIALOG 128
|
|
|
|
#define _WIN32_WINNT 0x0400
|
2003-04-13 01:40:35 +04:00
|
|
|
#define _WIN32_IE 0x0400
|
2000-08-10 05:33:35 +04:00
|
|
|
|
|
|
|
#include "NativeEventThread.h"
|
|
|
|
|
|
|
|
#include "ie_globals.h"
|
|
|
|
#include "ie_util.h"
|
|
|
|
|
2000-08-17 23:54:43 +04:00
|
|
|
#include "CMyDialog.h"
|
|
|
|
|
2000-08-10 05:33:35 +04:00
|
|
|
#include <atlbase.h> //for CComPtr
|
|
|
|
|
2003-04-13 01:40:35 +04:00
|
|
|
CComModule _Module;
|
|
|
|
|
2000-08-10 05:33:35 +04:00
|
|
|
|
|
|
|
#include <Atlwin.h> // for AtlWin
|
|
|
|
#include <Atlcom.h>
|
|
|
|
|
|
|
|
#include <Exdisp.h> //for IWebBrowser2
|
|
|
|
#include <exdispid.h>
|
|
|
|
|
|
|
|
#include <atlhost.h>
|
2000-08-17 23:54:43 +04:00
|
|
|
//#include <atlframe.h>//WTL
|
2003-04-13 01:40:35 +04:00
|
|
|
//#include <atlctrls.h>//WTL
|
2000-08-17 23:54:43 +04:00
|
|
|
//#include <atlctrlw.h>//WTL
|
|
|
|
//#include <atlmisc.h>//WTL
|
|
|
|
//#include <atlimpl.cpp>
|
2000-08-10 05:33:35 +04:00
|
|
|
#include <objbase.h>
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Local functions
|
|
|
|
//
|
|
|
|
|
|
|
|
//initializes IE stuff
|
|
|
|
HRESULT InitIEStuff (WebShellInitContext * arg);
|
|
|
|
int processEventLoop(WebShellInitContext *initContext);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Local data
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
extern void util_ThrowExceptionToJava (JNIEnv * , const char * );
|
|
|
|
|
|
|
|
char * errorMessages[] = {
|
|
|
|
"No Error",
|
|
|
|
"Could not obtain the event queue service.",
|
|
|
|
"Unable to create the WebShell instance.",
|
|
|
|
"Unable to initialize the WebShell instance.",
|
|
|
|
"Unable to show the WebShell."
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// JNI methods
|
|
|
|
//
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeInitialize
|
|
|
|
(JNIEnv *env, jobject obj, jint webShellPtr)
|
|
|
|
{
|
2003-04-13 01:40:35 +04:00
|
|
|
WebShellInitContext * initContext = (WebShellInitContext *) webShellPtr;
|
|
|
|
if (NULL == initContext) {
|
|
|
|
::util_ThrowExceptionToJava (env,
|
|
|
|
"NULL webShellPtr passed to nativeInitialize.");
|
|
|
|
return;
|
|
|
|
}
|
2000-08-10 05:33:35 +04:00
|
|
|
|
2003-04-13 01:40:35 +04:00
|
|
|
InitIEStuff (initContext);
|
|
|
|
}
|
2000-08-10 05:33:35 +04:00
|
|
|
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeProcessEvents
|
|
|
|
(JNIEnv *env, jobject obj, jint webShellPtr)
|
|
|
|
{
|
|
|
|
WebShellInitContext * initContext = (WebShellInitContext *) webShellPtr;
|
2003-04-13 01:40:35 +04:00
|
|
|
|
2000-08-10 05:33:35 +04:00
|
|
|
if (nsnull == initContext) {
|
2003-04-13 01:40:35 +04:00
|
|
|
::util_ThrowExceptionToJava(env,
|
2000-08-10 05:33:35 +04:00
|
|
|
"NULL webShellPtr passed to nativeProcessEvents.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-04-13 01:40:35 +04:00
|
|
|
processEventLoop(initContext);
|
2000-08-10 05:33:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <P> This method takes the typedListener, which is a
|
|
|
|
* WebclientEventListener java subclass, figures out what type of
|
|
|
|
* subclass it is, using the gSupportedListenerInterfaces array, and
|
|
|
|
* calls the appropriate add*Listener local function. </P>
|
|
|
|
|
|
|
|
*<P> PENDING(): we could do away with the switch statement using
|
|
|
|
* function pointers, or some other mechanism. </P>
|
|
|
|
|
|
|
|
* <P>the NewGlobalRef call is very important, since the argument
|
|
|
|
* typedListener is used to call back into java, at another time, as a
|
|
|
|
* result of the a mozilla event being fired.</P>
|
|
|
|
|
|
|
|
* PENDING(): implement nativeRemoveListener, which must call
|
|
|
|
* RemoveGlobalRef.
|
|
|
|
|
|
|
|
* See the comments for EventRegistration.h:addDocumentLoadListener
|
|
|
|
*/
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeAddListener
|
2003-04-13 01:40:35 +04:00
|
|
|
(JNIEnv *env, jobject obj, jint webShellPtr, jobject typedListener,
|
2000-08-17 23:54:43 +04:00
|
|
|
jstring listenerString)
|
2000-08-10 05:33:35 +04:00
|
|
|
{
|
2000-08-17 23:54:43 +04:00
|
|
|
WebShellInitContext *initContext = (WebShellInitContext *)webShellPtr;
|
2003-04-13 01:40:35 +04:00
|
|
|
|
2000-08-17 23:54:43 +04:00
|
|
|
if (initContext == nsnull) {
|
2003-04-13 01:40:35 +04:00
|
|
|
::util_ThrowExceptionToJava(env, "Exception: null initContext passed tonativeAddListener");
|
|
|
|
return;
|
2000-08-17 23:54:43 +04:00
|
|
|
}
|
2003-04-13 01:40:35 +04:00
|
|
|
|
2000-08-17 23:54:43 +04:00
|
|
|
if (nsnull == initContext->nativeEventThread) {
|
|
|
|
// store the java EventRegistrationImpl class in the initContext
|
2003-04-13 01:40:35 +04:00
|
|
|
initContext->nativeEventThread =
|
2000-08-17 23:54:43 +04:00
|
|
|
::util_NewGlobalRef(env, obj); // VERY IMPORTANT!!
|
2003-04-13 01:40:35 +04:00
|
|
|
|
|
|
|
// This enables the listener to call back into java
|
2000-08-17 23:54:43 +04:00
|
|
|
}
|
2003-04-13 01:40:35 +04:00
|
|
|
|
2000-08-17 23:54:43 +04:00
|
|
|
jclass clazz = nsnull;
|
|
|
|
int listenerType = 0;
|
2003-04-13 01:40:35 +04:00
|
|
|
const char *listenerStringChars = ::util_GetStringUTFChars(env,
|
2000-08-17 23:54:43 +04:00
|
|
|
listenerString);
|
|
|
|
if (listenerStringChars == nsnull) {
|
|
|
|
::util_ThrowExceptionToJava(env, "Exception: nativeAddListener: Can't get className for listener.");
|
|
|
|
return;
|
|
|
|
}
|
2003-04-13 01:40:35 +04:00
|
|
|
|
2000-08-17 23:54:43 +04:00
|
|
|
while (nsnull != gSupportedListenerInterfaces[listenerType]) {
|
2003-04-13 01:40:35 +04:00
|
|
|
if (0 == strcmp(gSupportedListenerInterfaces[listenerType],
|
2000-08-17 23:54:43 +04:00
|
|
|
listenerStringChars)) {
|
|
|
|
// We've got a winner!
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
listenerType++;
|
|
|
|
}
|
|
|
|
::util_ReleaseStringUTFChars(env, listenerString, listenerStringChars);
|
|
|
|
listenerStringChars = nsnull;
|
2003-04-13 01:40:35 +04:00
|
|
|
|
2000-08-17 23:54:43 +04:00
|
|
|
if (LISTENER_NOT_FOUND == (LISTENER_CLASSES) listenerType) {
|
|
|
|
::util_ThrowExceptionToJava(env, "Exception: NativeEventThread.nativeAddListener(): can't find listener \n\tclass for argument");
|
|
|
|
return;
|
|
|
|
}
|
2003-04-13 01:40:35 +04:00
|
|
|
|
2000-08-17 23:54:43 +04:00
|
|
|
jobject globalRef = nsnull;
|
2003-04-13 01:40:35 +04:00
|
|
|
|
2000-08-17 23:54:43 +04:00
|
|
|
// PENDING(edburns): make sure do DeleteGlobalRef on the removeListener
|
|
|
|
if (nsnull == (globalRef = ::util_NewGlobalRef(env, typedListener))) {
|
|
|
|
::util_ThrowExceptionToJava(env, "Exception: NativeEventThread.nativeAddListener(): can't create NewGlobalRef\n\tfor argument");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
util_Assert(initContext->browserObject);
|
2003-04-13 01:40:35 +04:00
|
|
|
|
2000-08-17 23:54:43 +04:00
|
|
|
switch(listenerType) {
|
|
|
|
case DOCUMENT_LOAD_LISTENER:
|
2003-04-13 01:40:35 +04:00
|
|
|
initContext->browserObject->AddDocumentLoadListener(globalRef);
|
2000-08-17 23:54:43 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-04-13 01:40:35 +04:00
|
|
|
JNIEXPORT void JNICALL
|
2000-08-17 23:54:43 +04:00
|
|
|
Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeRemoveListener
|
|
|
|
(JNIEnv *env, jobject obj, jint webShellPtr, jobject typedListener,
|
|
|
|
jstring listenerString)
|
|
|
|
{
|
|
|
|
printf("debug: glenn: nativeRemoveListener\n");
|
2000-08-10 05:33:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeCleanUp
|
|
|
|
(JNIEnv *env, jobject obj, jint webShellPtr)
|
|
|
|
{
|
2003-04-13 01:40:35 +04:00
|
|
|
WebShellInitContext * initContext = (WebShellInitContext *) webShellPtr;
|
2000-08-10 05:33:35 +04:00
|
|
|
|
2003-04-13 01:40:35 +04:00
|
|
|
//AtlAdviseSinkMap(&browserHome, false)
|
|
|
|
|
|
|
|
//_Module.RemoveMessageLoop();
|
2000-08-17 23:54:43 +04:00
|
|
|
initContext->browserObject->DispEventUnadvise(initContext->browserObject->spUnk);
|
2003-04-13 01:40:35 +04:00
|
|
|
_Module.Term();
|
2000-08-10 05:33:35 +04:00
|
|
|
::CoUninitialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int processEventLoop(WebShellInitContext * initContext)
|
|
|
|
{
|
2003-04-13 01:40:35 +04:00
|
|
|
HRESULT hr;
|
2000-08-10 05:33:35 +04:00
|
|
|
MSG msg;
|
2000-08-17 23:54:43 +04:00
|
|
|
|
2000-08-10 05:33:35 +04:00
|
|
|
if (::PeekMessage(&msg, nsnull, 0, 0, PM_NOREMOVE)) {
|
2003-04-13 01:40:35 +04:00
|
|
|
if (::GetMessage(&msg, nsnull, 0, 0)) {
|
|
|
|
|
|
|
|
switch (msg.message)
|
|
|
|
{
|
|
|
|
case WM_REFRESH:
|
|
|
|
hr = (initContext->browserObject->m_pWB)->Refresh();
|
|
|
|
break;
|
|
|
|
case WM_NAVIGATE:
|
|
|
|
hr = (initContext->browserObject->m_pWB)->Navigate(CComBSTR(initContext->wcharURL), NULL, NULL, NULL, NULL);
|
|
|
|
free((void *) initContext->wcharURL);
|
|
|
|
initContext->wcharURL = NULL;
|
|
|
|
break;
|
|
|
|
case WM_BACK:
|
|
|
|
hr = (initContext->browserObject->m_pWB)->GoBack();
|
|
|
|
break;
|
|
|
|
case WM_FORWARD:
|
|
|
|
hr = (initContext->browserObject->m_pWB)->GoForward();
|
|
|
|
break;
|
2003-06-10 22:53:00 +04:00
|
|
|
case WM_TRAVELTO:
|
|
|
|
{
|
|
|
|
// printf("src_ie/NativeEventThread processEventLoop case WM_TRAVELTO %d\n", msg.lParam);
|
|
|
|
ITravelLogEntry *pTLEntry = NULL;
|
|
|
|
hr = (initContext->browserObject->m_pTLStg)->GetRelativeEntry(msg.lParam, &pTLEntry);
|
|
|
|
if (SUCCEEDED(hr) && pTLEntry) {
|
|
|
|
hr = (initContext->browserObject->m_pTLStg)->TravelTo(pTLEntry);
|
|
|
|
pTLEntry->Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2003-04-13 01:40:35 +04:00
|
|
|
case WM_STOP:
|
|
|
|
hr = (initContext->browserObject->m_pWB)->Stop();
|
|
|
|
break;
|
|
|
|
case WM_RESIZE :
|
|
|
|
hr = MoveWindow(initContext->browserHost, initContext->x, initContext->y, initContext->w, initContext->h, TRUE);
|
|
|
|
break;
|
|
|
|
case WM_BIGTEST:
|
|
|
|
hr = ::MessageBox(initContext->browserHost, "command state changed", "youknow", MB_OK);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
::TranslateMessage(&msg);
|
2000-08-10 05:33:35 +04:00
|
|
|
::DispatchMessage(&msg);
|
2003-04-13 01:40:35 +04:00
|
|
|
}
|
2000-08-17 23:54:43 +04:00
|
|
|
}
|
2003-04-13 01:40:35 +04:00
|
|
|
|
2000-08-10 05:33:35 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT InitIEStuff (WebShellInitContext * initContext)
|
|
|
|
{
|
2003-04-13 01:40:35 +04:00
|
|
|
HRESULT hr;
|
2000-08-10 05:33:35 +04:00
|
|
|
HWND m_hWndClient;
|
|
|
|
RECT rect;
|
|
|
|
|
2003-06-10 22:53:00 +04:00
|
|
|
CMyDialog *bObj = initContext->browserObject;
|
2003-04-13 01:40:35 +04:00
|
|
|
|
|
|
|
HRESULT hRes = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
ATLASSERT(SUCCEEDED(hRes));
|
2000-08-10 05:33:35 +04:00
|
|
|
|
|
|
|
/*if (_WIN32_IE >= 0x0300)
|
|
|
|
INITCOMMONCONTROLSEX iccx;
|
|
|
|
iccx.dwSize = sizeof(iccx);
|
|
|
|
iccx.dwICC = ICC_COOL_CLASSES | ICC_BAR_CLASSES;
|
|
|
|
BOOL bRet = ::InitCommonControlsEx(&iccx);
|
|
|
|
bRet;
|
|
|
|
ATLASSERT(bRet);
|
|
|
|
#else
|
|
|
|
*/
|
2003-04-13 01:40:35 +04:00
|
|
|
// ::InitCommonControls();
|
2000-08-10 05:33:35 +04:00
|
|
|
//#endif
|
|
|
|
|
|
|
|
GetClientRect(initContext->parentHWnd, &rect);
|
2003-04-13 01:40:35 +04:00
|
|
|
|
2000-08-10 05:33:35 +04:00
|
|
|
HINSTANCE newInst = GetModuleHandleA(NULL);
|
2003-04-13 01:40:35 +04:00
|
|
|
hRes = _Module.Init(NULL, newInst);
|
|
|
|
ATLASSERT(SUCCEEDED(hRes));
|
|
|
|
|
2000-08-17 23:54:43 +04:00
|
|
|
AtlAxWinInit();
|
2000-08-10 05:33:35 +04:00
|
|
|
|
2003-06-10 22:53:00 +04:00
|
|
|
m_hWndClient = bObj->Create(initContext->parentHWnd,
|
2003-04-13 01:40:35 +04:00
|
|
|
rect,
|
|
|
|
_T("about:blank"),
|
2003-06-10 22:53:00 +04:00
|
|
|
WS_CHILD | WS_VISIBLE |
|
|
|
|
WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
|
|
|
|
WS_VSCROLL | WS_HSCROLL,
|
2003-04-13 01:40:35 +04:00
|
|
|
WS_EX_CLIENTEDGE,
|
|
|
|
ID_WEBBROWSER);
|
|
|
|
|
2003-06-10 22:53:00 +04:00
|
|
|
hr = bObj->QueryControl(&(initContext->browserObject->m_pWB));
|
2003-04-13 01:40:35 +04:00
|
|
|
|
|
|
|
if FAILED(hr)
|
|
|
|
{
|
|
|
|
ATLTRACE(_T("Couldn't retrieve webbrowser"));
|
|
|
|
return (-1);
|
|
|
|
}
|
2000-08-10 05:33:35 +04:00
|
|
|
|
2003-04-13 01:40:35 +04:00
|
|
|
if SUCCEEDED(hr)
|
|
|
|
{
|
2005-11-25 11:16:51 +03:00
|
|
|
ATLTRACE(_T("Browser successfully retrieved"));
|
2003-04-13 01:40:35 +04:00
|
|
|
}
|
2000-08-10 05:33:35 +04:00
|
|
|
|
2003-06-10 22:53:00 +04:00
|
|
|
initContext->browserHost = m_hWndClient;
|
2000-08-17 23:54:43 +04:00
|
|
|
|
2003-06-10 22:53:00 +04:00
|
|
|
if (!bObj->spUnk) {
|
|
|
|
hr = bObj->QueryControl(&(bObj->spUnk));
|
|
|
|
hr = bObj->DispEventAdvise(bObj->spUnk);
|
2003-04-13 01:40:35 +04:00
|
|
|
}
|
2000-08-10 05:33:35 +04:00
|
|
|
|
2003-04-13 01:40:35 +04:00
|
|
|
if FAILED(hr)
|
|
|
|
{
|
|
|
|
ATLTRACE(_T("Couldn't establish connection points"));
|
|
|
|
return -1;
|
|
|
|
}
|
2000-08-10 05:33:35 +04:00
|
|
|
|
2003-06-10 22:53:00 +04:00
|
|
|
hr = bObj->m_pWB->QueryInterface(IID_IServiceProvider,
|
|
|
|
(void**)&(bObj->m_pISP));
|
|
|
|
|
|
|
|
if (FAILED(hr) || (bObj->m_pISP == NULL))
|
|
|
|
{
|
|
|
|
ATLTRACE(_T("Couldn't obtain COM IServiceProvider"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = bObj->m_pISP->QueryService(SID_STravelLogCursor,
|
|
|
|
IID_ITravelLogStg,
|
|
|
|
(void**)&(bObj->m_pTLStg));
|
|
|
|
|
|
|
|
if (FAILED(hr) || (bObj->m_pTLStg == NULL))
|
|
|
|
{
|
|
|
|
ATLTRACE(_T("Couldn't obtain ITravelLog interface"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2000-08-17 23:54:43 +04:00
|
|
|
processEventLoop(initContext);
|
2000-08-10 05:33:35 +04:00
|
|
|
|
2003-04-13 01:40:35 +04:00
|
|
|
return 0;
|
2000-08-10 05:33:35 +04:00
|
|
|
}
|
|
|
|
|