2 * SHDOCVW - Internet Explorer Web Control
4 * Copyright 2001 John R. Sheets (for CodeWeavers)
5 * Copyright 2004 Mike McCormack (for CodeWeavers)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #define COM_NO_WINDOWS_H
43 #include "wine/unicode.h"
44 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw
);
50 static const WCHAR szMozDlPath
[] = {
51 'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
52 's','h','d','o','c','v','w',0
55 DEFINE_GUID( CLSID_MozillaBrowser
, 0x1339B54C,0x3453,0x11D2,0x93,0xB9,0x00,0x00,0x00,0x00,0x00,0x00);
57 typedef HRESULT (WINAPI
*fnGetClassObject
)(REFCLSID rclsid
, REFIID iid
, LPVOID
*ppv
);
59 HINSTANCE shdocvw_hinstance
= 0;
60 static HMODULE SHDOCVW_hshell32
= 0;
61 static HMODULE hMozCtl
= (HMODULE
)~0UL;
64 /* convert a guid to a wide character string */
65 static void SHDOCVW_guid2wstr( const GUID
*guid
, LPWSTR wstr
)
69 sprintf(str
, "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
70 guid
->Data1
, guid
->Data2
, guid
->Data3
,
71 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
72 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7] );
73 MultiByteToWideChar( CP_ACP
, 0, str
, -1, wstr
, 40 );
76 static BOOL
SHDOCVW_GetMozctlPath( LPWSTR szPath
, DWORD sz
)
81 static const WCHAR szPre
[] = {
82 'S','o','f','t','w','a','r','e','\\',
83 'C','l','a','s','s','e','s','\\',
84 'C','L','S','I','D','\\',0 };
85 static const WCHAR szPost
[] = {
86 '\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2',0 };
87 WCHAR szRegPath
[(sizeof(szPre
)+sizeof(szPost
))/sizeof(WCHAR
)+40];
89 strcpyW( szRegPath
, szPre
);
90 SHDOCVW_guid2wstr( &CLSID_MozillaBrowser
, &szRegPath
[strlenW(szRegPath
)] );
91 strcatW( szRegPath
, szPost
);
93 TRACE("key = %s\n", debugstr_w( szRegPath
) );
95 r
= RegOpenKeyW( HKEY_LOCAL_MACHINE
, szRegPath
, &hkey
);
96 if( r
!= ERROR_SUCCESS
)
99 r
= RegQueryValueExW( hkey
, NULL
, NULL
, &type
, (LPBYTE
)szPath
, &sz
);
100 ret
= ( r
== ERROR_SUCCESS
) && ( type
== REG_SZ
);
106 /*************************************************************************
109 BOOL WINAPI
DllMain(HINSTANCE hinst
, DWORD fdwReason
, LPVOID fImpLoad
)
111 TRACE("%p 0x%lx %p\n", hinst
, fdwReason
, fImpLoad
);
114 case DLL_PROCESS_ATTACH
:
115 shdocvw_hinstance
= hinst
;
117 case DLL_PROCESS_DETACH
:
118 if (SHDOCVW_hshell32
) FreeLibrary(SHDOCVW_hshell32
);
119 if (hMozCtl
&& hMozCtl
!= (HMODULE
)~0UL) FreeLibrary(hMozCtl
);
125 /*************************************************************************
126 * DllCanUnloadNow (SHDOCVW.@)
128 HRESULT WINAPI
SHDOCVW_DllCanUnloadNow(void)
130 FIXME("(void): stub\n");
135 /*************************************************************************
136 * SHDOCVW_TryDownloadMozillaControl
138 typedef struct _IBindStatusCallbackImpl
{
139 IBindStatusCallbackVtbl
*vtbl
;
143 } IBindStatusCallbackImpl
;
145 static HRESULT WINAPI
146 dlQueryInterface( IBindStatusCallback
* This
, REFIID riid
, void** ppvObject
)
148 if( IsEqualIID(riid
, &IID_IUnknown
) ||
149 IsEqualIID(riid
, &IID_IBindStatusCallback
))
151 IBindStatusCallback_AddRef( This
);
155 return E_NOINTERFACE
;
158 static ULONG WINAPI
dlAddRef( IBindStatusCallback
* iface
)
160 IBindStatusCallbackImpl
*This
= (IBindStatusCallbackImpl
*) iface
;
161 return InterlockedIncrement( &This
->ref
);
164 static ULONG WINAPI
dlRelease( IBindStatusCallback
* iface
)
166 IBindStatusCallbackImpl
*This
= (IBindStatusCallbackImpl
*) iface
;
167 DWORD ref
= InterlockedDecrement( &This
->ref
);
170 DestroyWindow( This
->hDialog
);
171 HeapFree( GetProcessHeap(), 0, This
);
176 static HRESULT WINAPI
177 dlOnStartBinding( IBindStatusCallback
* iface
, DWORD dwReserved
, IBinding
* pib
)
183 static HRESULT WINAPI
184 dlGetPriority( IBindStatusCallback
* iface
, LONG
* pnPriority
)
190 static HRESULT WINAPI
191 dlOnLowResource( IBindStatusCallback
* iface
, DWORD reserved
)
197 static HRESULT WINAPI
198 dlOnProgress( IBindStatusCallback
* iface
, ULONG ulProgress
,
199 ULONG ulProgressMax
, ULONG ulStatusCode
, LPCWSTR szStatusText
)
201 IBindStatusCallbackImpl
*This
= (IBindStatusCallbackImpl
*) iface
;
205 hItem
= GetDlgItem( This
->hDialog
, 1000 );
206 if( hItem
&& ulProgressMax
)
207 SendMessageW(hItem
,PBM_SETPOS
,(ulProgress
*100)/ulProgressMax
,0);
209 hItem
= GetDlgItem(This
->hDialog
, 104);
211 SendMessageW(hItem
,WM_SETTEXT
, 0, (LPARAM
) szStatusText
);
214 r
= GetWindowLongPtrW( This
->hDialog
, GWLP_USERDATA
);
215 if( r
|| GetLastError() )
217 *This
->pbCancelled
= TRUE
;
225 static HRESULT WINAPI
226 dlOnStopBinding( IBindStatusCallback
* iface
, HRESULT hresult
, LPCWSTR szError
)
232 static HRESULT WINAPI
233 dlGetBindInfo( IBindStatusCallback
* iface
, DWORD
* grfBINDF
, BINDINFO
* pbindinfo
)
239 static HRESULT WINAPI
240 dlOnDataAvailable( IBindStatusCallback
* iface
, DWORD grfBSCF
,
241 DWORD dwSize
, FORMATETC
* pformatetc
, STGMEDIUM
* pstgmed
)
247 static HRESULT WINAPI
248 dlOnObjectAvailable( IBindStatusCallback
* iface
, REFIID riid
, IUnknown
* punk
)
254 struct IBindStatusCallbackVtbl dlVtbl
=
269 static IBindStatusCallback
* create_dl(HWND dlg
, BOOL
*pbCancelled
)
271 IBindStatusCallbackImpl
*This
;
273 This
= HeapAlloc( GetProcessHeap(), 0, sizeof *This
);
274 This
->vtbl
= &dlVtbl
;
277 This
->pbCancelled
= pbCancelled
;
279 return (IBindStatusCallback
*) This
;
282 static DWORD WINAPI
ThreadFunc( LPVOID info
)
284 IBindStatusCallback
*dl
;
285 static const WCHAR szUrlVal
[] = {'M','o','z','i','l','l','a','U','r','l',0};
286 WCHAR path
[MAX_PATH
], szUrl
[MAX_PATH
];
289 PROCESS_INFORMATION pi
;
293 BOOL bCancelled
= FALSE
;
295 /* find the name of the thing to download */
297 r
= RegOpenKeyW( HKEY_LOCAL_MACHINE
, szMozDlPath
, &hkey
);
298 if( r
== ERROR_SUCCESS
)
301 r
= RegQueryValueExW( hkey
, szUrlVal
, NULL
, &type
, (LPBYTE
)szUrl
, &sz
);
304 if( r
!= ERROR_SUCCESS
)
307 /* built the path for the download */
308 p
= strrchrW( szUrl
, '/' );
311 if (!GetTempPathW( MAX_PATH
, path
))
313 strcatW( path
, p
+1 );
316 dl
= create_dl(info
, &bCancelled
);
317 r
= URLDownloadToFileW( NULL
, szUrl
, path
, 0, dl
);
319 IBindStatusCallback_Release( dl
);
320 if( (r
!= S_OK
) || bCancelled
)
324 memset( &si
, 0, sizeof si
);
326 r
= CreateProcessW( path
, NULL
, NULL
, NULL
, 0, 0, NULL
, NULL
, &si
, &pi
);
329 WaitForSingleObject( pi
.hProcess
, INFINITE
);
332 EndDialog( hDlg
, 0 );
336 static INT_PTR CALLBACK
337 dlProc ( HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
346 SetWindowLongPtrW( hwndDlg
, GWLP_USERDATA
, 0 );
347 hItem
= GetDlgItem(hwndDlg
, 1000);
350 SendMessageW(hItem
,PBM_SETRANGE
,0,MAKELPARAM(0,100));
351 SendMessageW(hItem
,PBM_SETPOS
,0,0);
353 hThread
= CreateThread(NULL
,0,ThreadFunc
,hwndDlg
,0,&ThreadId
);
358 if( wParam
== IDCANCEL
)
359 SetWindowLongPtrW( hwndDlg
, GWLP_USERDATA
, 1 );
366 static BOOL
SHDOCVW_TryDownloadMozillaControl()
370 static const WCHAR szWine
[] = { 'W','i','n','e',0 };
373 SetLastError( ERROR_SUCCESS
);
374 hsem
= CreateSemaphoreA( NULL
, 0, 1, "mozctl_install_semaphore");
375 if( GetLastError() != ERROR_ALREADY_EXISTS
)
377 LoadStringW( shdocvw_hinstance
, 1001, buf
, sizeof buf
/sizeof(WCHAR
) );
378 r
= MessageBoxW(NULL
, buf
, szWine
, MB_YESNO
| MB_ICONQUESTION
);
382 DialogBoxW(shdocvw_hinstance
, MAKEINTRESOURCEW(100), 0, dlProc
);
385 WaitForSingleObject( hsem
, INFINITE
);
386 ReleaseSemaphore( hsem
, 1, NULL
);
392 static BOOL
SHDOCVW_TryLoadMozillaControl()
394 WCHAR szPath
[MAX_PATH
];
397 if( hMozCtl
!= (HMODULE
)~0UL )
398 return hMozCtl
? TRUE
: FALSE
;
402 if( SHDOCVW_GetMozctlPath( szPath
, sizeof szPath
) )
404 hMozCtl
= LoadLibraryExW(szPath
, NULL
, LOAD_WITH_ALTERED_SEARCH_PATH
);
410 MESSAGE("You need to install the Mozilla ActiveX control to\n");
411 MESSAGE("use Wine's builtin CLSID_WebBrowser from SHDOCVW.DLL\n");
414 SHDOCVW_TryDownloadMozillaControl();
420 /*************************************************************************
421 * DllGetClassObject (SHDOCVW.@)
423 HRESULT WINAPI
SHDOCVW_DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
427 if( IsEqualGUID( &CLSID_WebBrowser
, rclsid
) &&
428 SHDOCVW_TryLoadMozillaControl() )
431 fnGetClassObject pGetClassObject
;
433 TRACE("WebBrowser class %s\n", debugstr_guid(rclsid
) );
435 pGetClassObject
= (fnGetClassObject
)
436 GetProcAddress( hMozCtl
, "DllGetClassObject" );
438 if( !pGetClassObject
)
439 return CLASS_E_CLASSNOTAVAILABLE
;
440 r
= pGetClassObject( &CLSID_MozillaBrowser
, riid
, ppv
);
442 TRACE("r = %08lx *ppv = %p\n", r
, *ppv
);
447 if (IsEqualGUID(&IID_IClassFactory
, riid
))
449 /* Pass back our shdocvw class factory */
450 *ppv
= (LPVOID
)&SHDOCVW_ClassFactory
;
451 IClassFactory_AddRef((IClassFactory
*)&SHDOCVW_ClassFactory
);
456 return CLASS_E_CLASSNOTAVAILABLE
;
459 /***********************************************************************
460 * DllGetVersion (SHDOCVW.@)
462 HRESULT WINAPI
SHDOCVW_DllGetVersion(DLLVERSIONINFO
*info
)
464 if (info
->cbSize
!= sizeof(DLLVERSIONINFO
)) FIXME("support DLLVERSIONINFO2\n");
466 /* this is what IE6 on Windows 98 reports */
467 info
->dwMajorVersion
= 6;
468 info
->dwMinorVersion
= 0;
469 info
->dwBuildNumber
= 2600;
470 info
->dwPlatformID
= DLLVER_PLATFORM_WINDOWS
;
475 /*************************************************************************
476 * DllInstall (SHDOCVW.@)
478 HRESULT WINAPI
SHDOCVW_DllInstall(BOOL bInstall
, LPCWSTR cmdline
)
480 FIXME("(%s, %s): stub!\n", bInstall
? "TRUE":"FALSE", debugstr_w(cmdline
));
485 /*************************************************************************
486 * SHDOCVW_LoadShell32
488 * makes sure the handle to shell32 is valid
490 BOOL
SHDOCVW_LoadShell32(void)
492 if (SHDOCVW_hshell32
)
494 return ((SHDOCVW_hshell32
= LoadLibraryA("shell32.dll")) != NULL
);
497 /***********************************************************************
500 * Called by Win98 explorer.exe main binary, definitely has 0
503 DWORD WINAPI
WinList_Init(void)
505 FIXME("(), stub!\n");
509 /***********************************************************************
512 * Called by Win98 explorer.exe main binary, definitely has only one
515 static BOOL (WINAPI
*pShellDDEInit
)(BOOL start
) = NULL
;
517 BOOL WINAPI
ShellDDEInit(BOOL start
)
519 TRACE("(%d)\n", start
);
523 if (!SHDOCVW_LoadShell32())
525 pShellDDEInit
= GetProcAddress(SHDOCVW_hshell32
, (LPCSTR
)188);
529 return pShellDDEInit(start
);
534 /***********************************************************************
537 * Called by Win98 explorer.exe main binary, definitely has 0
540 DWORD WINAPI
RunInstallUninstallStubs(void)
542 FIXME("(), stub!\n");
546 /***********************************************************************
547 * SetQueryNetSessionCount (SHDOCVW.@)
549 DWORD WINAPI
SetQueryNetSessionCount(DWORD arg
)
551 FIXME("(%lu), stub!\n", arg
);