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 LONG SHDOCVW_refCount = 0;
52 static const WCHAR szMozDlPath[] = {
53 'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
54 's','h','d','o','c','v','w',0
57 DEFINE_GUID( CLSID_MozillaBrowser, 0x1339B54C,0x3453,0x11D2,0x93,0xB9,0x00,0x00,0x00,0x00,0x00,0x00);
59 typedef HRESULT (WINAPI *fnGetClassObject)(REFCLSID rclsid, REFIID iid, LPVOID *ppv);
60 typedef HRESULT (WINAPI *fnCanUnloadNow)(void);
62 HINSTANCE shdocvw_hinstance = 0;
63 static HMODULE SHDOCVW_hshell32 = 0;
64 static HMODULE hMozCtl = (HMODULE)~0UL;
67 /* convert a guid to a wide character string */
68 static void SHDOCVW_guid2wstr( const GUID *guid, LPWSTR wstr )
72 sprintf(str, "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
73 guid->Data1, guid->Data2, guid->Data3,
74 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
75 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
76 MultiByteToWideChar( CP_ACP, 0, str, -1, wstr, 40 );
79 static BOOL SHDOCVW_GetMozctlPath( LPWSTR szPath, DWORD sz )
84 static const WCHAR szPre[] = {
85 'S','o','f','t','w','a','r','e','\\',
86 'C','l','a','s','s','e','s','\\',
87 'C','L','S','I','D','\\',0 };
88 static const WCHAR szPost[] = {
89 '\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2',0 };
90 WCHAR szRegPath[(sizeof(szPre)+sizeof(szPost))/sizeof(WCHAR)+40];
92 strcpyW( szRegPath, szPre );
93 SHDOCVW_guid2wstr( &CLSID_MozillaBrowser, &szRegPath[strlenW(szRegPath)] );
94 strcatW( szRegPath, szPost );
96 TRACE("key = %s\n", debugstr_w( szRegPath ) );
98 r = RegOpenKeyW( HKEY_LOCAL_MACHINE, szRegPath, &hkey );
99 if( r != ERROR_SUCCESS )
102 r = RegQueryValueExW( hkey, NULL, NULL, &type, (LPBYTE)szPath, &sz );
103 ret = ( r == ERROR_SUCCESS ) && ( type == REG_SZ );
109 /*************************************************************************
112 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
114 TRACE("%p 0x%lx %p\n", hinst, fdwReason, fImpLoad);
117 case DLL_PROCESS_ATTACH:
118 shdocvw_hinstance = hinst;
120 case DLL_PROCESS_DETACH:
121 if (SHDOCVW_hshell32) FreeLibrary(SHDOCVW_hshell32);
122 if (hMozCtl && hMozCtl != (HMODULE)~0UL) FreeLibrary(hMozCtl);
128 /*************************************************************************
129 * DllCanUnloadNow (SHDOCVW.@)
131 HRESULT WINAPI SHDOCVW_DllCanUnloadNow(void)
133 HRESULT moz_can_unload = S_OK;
134 fnCanUnloadNow pCanUnloadNow;
138 pCanUnloadNow = (fnCanUnloadNow)
139 GetProcAddress(hMozCtl, "DllCanUnloadNow");
141 moz_can_unload = pCanUnloadNow();
144 if (moz_can_unload == S_OK && SHDOCVW_refCount == 0)
150 /*************************************************************************
151 * SHDOCVW_TryDownloadMozillaControl
153 typedef struct _IBindStatusCallbackImpl {
154 IBindStatusCallbackVtbl *vtbl;
158 } IBindStatusCallbackImpl;
160 static HRESULT WINAPI
161 dlQueryInterface( IBindStatusCallback* This, REFIID riid, void** ppvObject )
163 if (ppvObject == NULL) return E_POINTER;
165 if( IsEqualIID(riid, &IID_IUnknown) ||
166 IsEqualIID(riid, &IID_IBindStatusCallback))
168 IBindStatusCallback_AddRef( This );
172 return E_NOINTERFACE;
175 static ULONG WINAPI dlAddRef( IBindStatusCallback* iface )
177 IBindStatusCallbackImpl *This = (IBindStatusCallbackImpl *) iface;
179 SHDOCVW_LockModule();
181 return InterlockedIncrement( &This->ref );
184 static ULONG WINAPI dlRelease( IBindStatusCallback* iface )
186 IBindStatusCallbackImpl *This = (IBindStatusCallbackImpl *) iface;
187 DWORD ref = InterlockedDecrement( &This->ref );
191 DestroyWindow( This->hDialog );
192 HeapFree( GetProcessHeap(), 0, This );
195 SHDOCVW_UnlockModule();
200 static HRESULT WINAPI
201 dlOnStartBinding( IBindStatusCallback* iface, DWORD dwReserved, IBinding* pib)
207 static HRESULT WINAPI
208 dlGetPriority( IBindStatusCallback* iface, LONG* pnPriority)
214 static HRESULT WINAPI
215 dlOnLowResource( IBindStatusCallback* iface, DWORD reserved)
221 static HRESULT WINAPI
222 dlOnProgress( IBindStatusCallback* iface, ULONG ulProgress,
223 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
225 IBindStatusCallbackImpl *This = (IBindStatusCallbackImpl *) iface;
229 hItem = GetDlgItem( This->hDialog, 1000 );
230 if( hItem && ulProgressMax )
231 SendMessageW(hItem,PBM_SETPOS,(ulProgress*100)/ulProgressMax,0);
233 hItem = GetDlgItem(This->hDialog, 104);
235 SendMessageW(hItem,WM_SETTEXT, 0, (LPARAM) szStatusText);
238 r = GetWindowLongPtrW( This->hDialog, GWLP_USERDATA );
239 if( r || GetLastError() )
241 *This->pbCancelled = TRUE;
249 static HRESULT WINAPI
250 dlOnStopBinding( IBindStatusCallback* iface, HRESULT hresult, LPCWSTR szError)
256 static HRESULT WINAPI
257 dlGetBindInfo( IBindStatusCallback* iface, DWORD* grfBINDF, BINDINFO* pbindinfo)
263 static HRESULT WINAPI
264 dlOnDataAvailable( IBindStatusCallback* iface, DWORD grfBSCF,
265 DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
271 static HRESULT WINAPI
272 dlOnObjectAvailable( IBindStatusCallback* iface, REFIID riid, IUnknown* punk)
278 struct IBindStatusCallbackVtbl dlVtbl =
293 static IBindStatusCallback* create_dl(HWND dlg, BOOL *pbCancelled)
295 IBindStatusCallbackImpl *This;
297 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
298 This->vtbl = &dlVtbl;
301 This->pbCancelled = pbCancelled;
303 return (IBindStatusCallback*) This;
306 static DWORD WINAPI ThreadFunc( LPVOID info )
308 IBindStatusCallback *dl;
309 static const WCHAR szUrlVal[] = {'M','o','z','i','l','l','a','U','r','l',0};
310 WCHAR path[MAX_PATH], szUrl[MAX_PATH];
313 PROCESS_INFORMATION pi;
317 BOOL bCancelled = FALSE;
319 /* find the name of the thing to download */
321 r = RegOpenKeyW( HKEY_LOCAL_MACHINE, szMozDlPath, &hkey );
322 if( r == ERROR_SUCCESS )
325 r = RegQueryValueExW( hkey, szUrlVal, NULL, &type, (LPBYTE)szUrl, &sz );
328 if( r != ERROR_SUCCESS )
331 /* built the path for the download */
332 p = strrchrW( szUrl, '/' );
335 if (!GetTempPathW( MAX_PATH, path ))
337 strcatW( path, p+1 );
340 dl = create_dl(info, &bCancelled);
341 r = URLDownloadToFileW( NULL, szUrl, path, 0, dl );
343 IBindStatusCallback_Release( dl );
344 if( (r != S_OK) || bCancelled )
348 memset( &si, 0, sizeof si );
350 r = CreateProcessW( path, NULL, NULL, NULL, 0, 0, NULL, NULL, &si, &pi );
353 WaitForSingleObject( pi.hProcess, INFINITE );
356 EndDialog( hDlg, 0 );
360 static INT_PTR CALLBACK
361 dlProc ( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
370 SetWindowLongPtrW( hwndDlg, GWLP_USERDATA, 0 );
371 hItem = GetDlgItem(hwndDlg, 1000);
374 SendMessageW(hItem,PBM_SETRANGE,0,MAKELPARAM(0,100));
375 SendMessageW(hItem,PBM_SETPOS,0,0);
377 hThread = CreateThread(NULL,0,ThreadFunc,hwndDlg,0,&ThreadId);
382 if( wParam == IDCANCEL )
383 SetWindowLongPtrW( hwndDlg, GWLP_USERDATA, 1 );
390 static BOOL SHDOCVW_TryDownloadMozillaControl()
394 static const WCHAR szWine[] = { 'W','i','n','e',0 };
397 SetLastError( ERROR_SUCCESS );
398 hsem = CreateSemaphoreA( NULL, 0, 1, "mozctl_install_semaphore");
399 if( GetLastError() != ERROR_ALREADY_EXISTS )
401 LoadStringW( shdocvw_hinstance, 1001, buf, sizeof buf/sizeof(WCHAR) );
402 r = MessageBoxW(NULL, buf, szWine, MB_YESNO | MB_ICONQUESTION);
406 DialogBoxW(shdocvw_hinstance, MAKEINTRESOURCEW(100), 0, dlProc);
409 WaitForSingleObject( hsem, INFINITE );
410 ReleaseSemaphore( hsem, 1, NULL );
416 static BOOL SHDOCVW_TryLoadMozillaControl()
418 WCHAR szPath[MAX_PATH];
421 if( hMozCtl != (HMODULE)~0UL )
422 return hMozCtl ? TRUE : FALSE;
426 if( SHDOCVW_GetMozctlPath( szPath, sizeof szPath ) )
428 hMozCtl = LoadLibraryExW(szPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
434 MESSAGE("You need to install the Mozilla ActiveX control to\n");
435 MESSAGE("use Wine's builtin CLSID_WebBrowser from SHDOCVW.DLL\n");
438 SHDOCVW_TryDownloadMozillaControl();
443 /*************************************************************************
444 * DllGetClassObject (SHDOCVW.@)
446 HRESULT WINAPI SHDOCVW_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
450 if( IsEqualGUID( &CLSID_WebBrowser, rclsid ) &&
451 SHDOCVW_TryLoadMozillaControl() )
454 fnGetClassObject pGetClassObject;
456 TRACE("WebBrowser class %s\n", debugstr_guid(rclsid) );
458 pGetClassObject = (fnGetClassObject)
459 GetProcAddress( hMozCtl, "DllGetClassObject" );
461 if( !pGetClassObject )
462 return CLASS_E_CLASSNOTAVAILABLE;
463 r = pGetClassObject( &CLSID_MozillaBrowser, riid, ppv );
465 TRACE("r = %08lx *ppv = %p\n", r, *ppv );
470 if (IsEqualGUID(&IID_IClassFactory, riid))
472 /* Pass back our shdocvw class factory */
473 *ppv = (LPVOID)&SHDOCVW_ClassFactory;
474 IClassFactory_AddRef((IClassFactory*)&SHDOCVW_ClassFactory);
479 return CLASS_E_CLASSNOTAVAILABLE;
482 /***********************************************************************
483 * DllGetVersion (SHDOCVW.@)
485 HRESULT WINAPI SHDOCVW_DllGetVersion(DLLVERSIONINFO *info)
487 if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
489 /* this is what IE6 on Windows 98 reports */
490 info->dwMajorVersion = 6;
491 info->dwMinorVersion = 0;
492 info->dwBuildNumber = 2600;
493 info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
498 /*************************************************************************
499 * DllInstall (SHDOCVW.@)
501 HRESULT WINAPI SHDOCVW_DllInstall(BOOL bInstall, LPCWSTR cmdline)
503 FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
508 /*************************************************************************
509 * SHDOCVW_LoadShell32
511 * makes sure the handle to shell32 is valid
513 BOOL SHDOCVW_LoadShell32(void)
515 if (SHDOCVW_hshell32)
517 return ((SHDOCVW_hshell32 = LoadLibraryA("shell32.dll")) != NULL);
520 /***********************************************************************
523 * Called by Win98 explorer.exe main binary, definitely has 0
526 DWORD WINAPI WinList_Init(void)
528 FIXME("(), stub!\n");
532 /***********************************************************************
535 * Called by Win98 explorer.exe main binary, definitely has only one
538 static BOOL (WINAPI *pShellDDEInit)(BOOL start) = NULL;
540 BOOL WINAPI ShellDDEInit(BOOL start)
542 TRACE("(%d)\n", start);
546 if (!SHDOCVW_LoadShell32())
548 pShellDDEInit = GetProcAddress(SHDOCVW_hshell32, (LPCSTR)188);
552 return pShellDDEInit(start);
557 /***********************************************************************
560 * Called by Win98 explorer.exe main binary, definitely has 0
563 DWORD WINAPI RunInstallUninstallStubs(void)
565 FIXME("(), stub!\n");
569 /***********************************************************************
570 * SetQueryNetSessionCount (SHDOCVW.@)
572 DWORD WINAPI SetQueryNetSessionCount(DWORD arg)
574 FIXME("(%lu), stub!\n", arg);