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
27 #include "wine/unicode.h"
28 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
39 LONG SHDOCVW_refCount = 0;
41 static const WCHAR szMozDlPath[] = {
42 'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
43 's','h','d','o','c','v','w',0
46 DEFINE_GUID( CLSID_MozillaBrowser, 0x1339B54C,0x3453,0x11D2,0x93,0xB9,0x00,0x00,0x00,0x00,0x00,0x00);
48 typedef HRESULT (WINAPI *fnGetClassObject)(REFCLSID rclsid, REFIID iid, LPVOID *ppv);
49 typedef HRESULT (WINAPI *fnCanUnloadNow)(void);
51 HINSTANCE shdocvw_hinstance = 0;
52 static HMODULE SHDOCVW_hshell32 = 0;
53 static HMODULE hMozCtl = (HMODULE)~0UL;
56 /* convert a guid to a wide character string */
57 static void SHDOCVW_guid2wstr( const GUID *guid, LPWSTR wstr )
61 sprintf(str, "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
62 guid->Data1, guid->Data2, guid->Data3,
63 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
64 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
65 MultiByteToWideChar( CP_ACP, 0, str, -1, wstr, 40 );
68 static BOOL SHDOCVW_GetMozctlPath( LPWSTR szPath, DWORD sz )
73 static const WCHAR szPre[] = {
74 'S','o','f','t','w','a','r','e','\\',
75 'C','l','a','s','s','e','s','\\',
76 'C','L','S','I','D','\\',0 };
77 static const WCHAR szPost[] = {
78 '\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2',0 };
79 WCHAR szRegPath[(sizeof(szPre)+sizeof(szPost))/sizeof(WCHAR)+40];
81 strcpyW( szRegPath, szPre );
82 SHDOCVW_guid2wstr( &CLSID_MozillaBrowser, &szRegPath[strlenW(szRegPath)] );
83 strcatW( szRegPath, szPost );
85 TRACE("key = %s\n", debugstr_w( szRegPath ) );
87 r = RegOpenKeyW( HKEY_LOCAL_MACHINE, szRegPath, &hkey );
88 if( r != ERROR_SUCCESS )
91 r = RegQueryValueExW( hkey, NULL, NULL, &type, (LPBYTE)szPath, &sz );
92 ret = ( r == ERROR_SUCCESS ) && ( type == REG_SZ );
98 /*************************************************************************
101 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
103 TRACE("%p 0x%lx %p\n", hinst, fdwReason, fImpLoad);
106 case DLL_PROCESS_ATTACH:
107 shdocvw_hinstance = hinst;
109 case DLL_PROCESS_DETACH:
110 if (SHDOCVW_hshell32) FreeLibrary(SHDOCVW_hshell32);
111 if (hMozCtl && hMozCtl != (HMODULE)~0UL) FreeLibrary(hMozCtl);
117 /*************************************************************************
118 * DllCanUnloadNow (SHDOCVW.@)
120 HRESULT WINAPI DllCanUnloadNow(void)
122 HRESULT moz_can_unload = S_OK;
123 fnCanUnloadNow pCanUnloadNow;
127 pCanUnloadNow = (fnCanUnloadNow)
128 GetProcAddress(hMozCtl, "DllCanUnloadNow");
130 moz_can_unload = pCanUnloadNow();
133 if (moz_can_unload == S_OK && SHDOCVW_refCount == 0)
139 /*************************************************************************
140 * SHDOCVW_TryDownloadMozillaControl
142 typedef struct _IBindStatusCallbackImpl {
143 const IBindStatusCallbackVtbl *vtbl;
147 } IBindStatusCallbackImpl;
149 static HRESULT WINAPI
150 dlQueryInterface( IBindStatusCallback* This, REFIID riid, void** ppvObject )
152 if (ppvObject == NULL) return E_POINTER;
154 if( IsEqualIID(riid, &IID_IUnknown) ||
155 IsEqualIID(riid, &IID_IBindStatusCallback))
157 IBindStatusCallback_AddRef( This );
161 return E_NOINTERFACE;
164 static ULONG WINAPI dlAddRef( IBindStatusCallback* iface )
166 IBindStatusCallbackImpl *This = (IBindStatusCallbackImpl *) iface;
168 SHDOCVW_LockModule();
170 return InterlockedIncrement( &This->ref );
173 static ULONG WINAPI dlRelease( IBindStatusCallback* iface )
175 IBindStatusCallbackImpl *This = (IBindStatusCallbackImpl *) iface;
176 DWORD ref = InterlockedDecrement( &This->ref );
180 DestroyWindow( This->hDialog );
181 HeapFree( GetProcessHeap(), 0, This );
184 SHDOCVW_UnlockModule();
189 static HRESULT WINAPI
190 dlOnStartBinding( IBindStatusCallback* iface, DWORD dwReserved, IBinding* pib)
196 static HRESULT WINAPI
197 dlGetPriority( IBindStatusCallback* iface, LONG* pnPriority)
203 static HRESULT WINAPI
204 dlOnLowResource( IBindStatusCallback* iface, DWORD reserved)
210 static HRESULT WINAPI
211 dlOnProgress( IBindStatusCallback* iface, ULONG ulProgress,
212 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
214 IBindStatusCallbackImpl *This = (IBindStatusCallbackImpl *) iface;
218 hItem = GetDlgItem( This->hDialog, 1000 );
219 if( hItem && ulProgressMax )
220 SendMessageW(hItem,PBM_SETPOS,(ulProgress*100)/ulProgressMax,0);
222 hItem = GetDlgItem(This->hDialog, 104);
224 SendMessageW(hItem,WM_SETTEXT, 0, (LPARAM) szStatusText);
227 r = GetWindowLongPtrW( This->hDialog, GWLP_USERDATA );
228 if( r || GetLastError() )
230 *This->pbCancelled = TRUE;
238 static HRESULT WINAPI
239 dlOnStopBinding( IBindStatusCallback* iface, HRESULT hresult, LPCWSTR szError)
245 static HRESULT WINAPI
246 dlGetBindInfo( IBindStatusCallback* iface, DWORD* grfBINDF, BINDINFO* pbindinfo)
252 static HRESULT WINAPI
253 dlOnDataAvailable( IBindStatusCallback* iface, DWORD grfBSCF,
254 DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
260 static HRESULT WINAPI
261 dlOnObjectAvailable( IBindStatusCallback* iface, REFIID riid, IUnknown* punk)
267 static const IBindStatusCallbackVtbl dlVtbl =
282 static IBindStatusCallback* create_dl(HWND dlg, BOOL *pbCancelled)
284 IBindStatusCallbackImpl *This;
286 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
287 This->vtbl = &dlVtbl;
290 This->pbCancelled = pbCancelled;
292 return (IBindStatusCallback*) This;
295 static DWORD WINAPI ThreadFunc( LPVOID info )
297 IBindStatusCallback *dl;
298 static const WCHAR szUrlVal[] = {'M','o','z','i','l','l','a','U','r','l',0};
299 static const WCHAR szFileProtocol[] = {'f','i','l','e',':','/','/','/',0};
300 WCHAR path[MAX_PATH], szUrl[MAX_PATH];
303 PROCESS_INFORMATION pi;
307 BOOL bCancelled = FALSE;
308 BOOL bTempfile = FALSE;
310 /* find the name of the thing to download */
312 /* @@ Wine registry key: HKCU\Software\Wine\shdocvw */
313 r = RegOpenKeyW( HKEY_CURRENT_USER, szMozDlPath, &hkey );
314 if( r == ERROR_SUCCESS )
317 r = RegQueryValueExW( hkey, szUrlVal, NULL, &type, (LPBYTE)szUrl, &sz );
320 if( r != ERROR_SUCCESS )
323 if( !strncmpW(szUrl, szFileProtocol, strlenW(szFileProtocol)) )
324 lstrcpynW( path, szUrl+strlenW(szFileProtocol), MAX_PATH );
327 /* built the path for the download */
328 p = strrchrW( szUrl, '/' );
331 if (!GetTempPathW( MAX_PATH, path ))
333 strcatW( path, p+1 );
337 dl = create_dl(info, &bCancelled);
338 r = URLDownloadToFileW( NULL, szUrl, path, 0, dl );
340 IBindStatusCallback_Release( dl );
341 if( (r != S_OK) || bCancelled )
346 memset( &si, 0, sizeof si );
348 r = CreateProcessW( path, NULL, NULL, NULL, 0, 0, NULL, NULL, &si, &pi );
351 WaitForSingleObject( pi.hProcess, INFINITE );
352 CloseHandle( pi.hProcess );
353 CloseHandle( pi.hThread );
358 EndDialog( hDlg, 0 );
362 static INT_PTR CALLBACK
363 dlProc ( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
372 SetWindowLongPtrW( hwndDlg, GWLP_USERDATA, 0 );
373 hItem = GetDlgItem(hwndDlg, 1000);
376 SendMessageW(hItem,PBM_SETRANGE,0,MAKELPARAM(0,100));
377 SendMessageW(hItem,PBM_SETPOS,0,0);
379 hThread = CreateThread(NULL,0,ThreadFunc,hwndDlg,0,&ThreadId);
384 if( wParam == IDCANCEL )
385 SetWindowLongPtrW( hwndDlg, GWLP_USERDATA, 1 );
392 static BOOL SHDOCVW_TryDownloadMozillaControl(void)
396 static const WCHAR szWine[] = { 'W','i','n','e',0 };
399 SetLastError( ERROR_SUCCESS );
400 hsem = CreateSemaphoreA( NULL, 0, 1, "mozctl_install_semaphore");
401 if( GetLastError() != ERROR_ALREADY_EXISTS )
403 LoadStringW( shdocvw_hinstance, 1001, buf, sizeof buf/sizeof(WCHAR) );
404 r = MessageBoxW(NULL, buf, szWine, MB_YESNO | MB_ICONQUESTION);
408 DialogBoxW(shdocvw_hinstance, MAKEINTRESOURCEW(100), 0, dlProc);
411 WaitForSingleObject( hsem, INFINITE );
412 ReleaseSemaphore( hsem, 1, NULL );
418 static BOOL SHDOCVW_TryLoadMozillaControl(void)
420 WCHAR szPath[MAX_PATH];
423 if( hMozCtl != (HMODULE)~0UL )
424 return hMozCtl ? TRUE : FALSE;
428 if( SHDOCVW_GetMozctlPath( szPath, sizeof szPath ) )
430 hMozCtl = LoadLibraryExW(szPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
436 MESSAGE("You need to install the Mozilla ActiveX control to\n");
437 MESSAGE("use Wine's builtin CLSID_WebBrowser from SHDOCVW.DLL\n");
440 SHDOCVW_TryDownloadMozillaControl();
445 /*************************************************************************
446 * DllGetClassObject (SHDOCVW.@)
448 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
452 if( IsEqualGUID( &CLSID_WebBrowser, rclsid ) &&
453 SHDOCVW_TryLoadMozillaControl() )
456 fnGetClassObject pGetClassObject;
458 TRACE("WebBrowser class %s\n", debugstr_guid(rclsid) );
460 pGetClassObject = (fnGetClassObject)
461 GetProcAddress( hMozCtl, "DllGetClassObject" );
463 if( !pGetClassObject )
464 return CLASS_E_CLASSNOTAVAILABLE;
465 r = pGetClassObject( &CLSID_MozillaBrowser, riid, ppv );
467 TRACE("r = %08lx *ppv = %p\n", r, *ppv );
472 if (IsEqualCLSID(&CLSID_WebBrowser, rclsid) &&
473 IsEqualIID(&IID_IClassFactory, riid))
475 /* Pass back our shdocvw class factory */
476 *ppv = (LPVOID)&SHDOCVW_ClassFactory;
477 IClassFactory_AddRef((IClassFactory*)&SHDOCVW_ClassFactory);
482 /* As a last resort, figure if the CLSID belongs to a 'Shell Instance Object' */
483 return SHDOCVW_GetShellInstanceObjectClassObject(rclsid, riid, ppv);
486 /***********************************************************************
487 * DllGetVersion (SHDOCVW.@)
489 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
491 if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
493 /* this is what IE6 on Windows 98 reports */
494 info->dwMajorVersion = 6;
495 info->dwMinorVersion = 0;
496 info->dwBuildNumber = 2600;
497 info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
502 /*************************************************************************
503 * DllInstall (SHDOCVW.@)
505 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
507 FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
512 /*************************************************************************
513 * SHDOCVW_LoadShell32
515 * makes sure the handle to shell32 is valid
517 BOOL SHDOCVW_LoadShell32(void)
519 if (SHDOCVW_hshell32)
521 return ((SHDOCVW_hshell32 = LoadLibraryA("shell32.dll")) != NULL);
524 /***********************************************************************
527 * Called by Win98 explorer.exe main binary, definitely has 0
530 DWORD WINAPI WinList_Init(void)
532 FIXME("(), stub!\n");
536 /***********************************************************************
539 * Called by Win98 explorer.exe main binary, definitely has only one
542 static BOOL (WINAPI *pShellDDEInit)(BOOL start) = NULL;
544 BOOL WINAPI ShellDDEInit(BOOL start)
546 TRACE("(%d)\n", start);
550 if (!SHDOCVW_LoadShell32())
552 pShellDDEInit = GetProcAddress(SHDOCVW_hshell32, (LPCSTR)188);
556 return pShellDDEInit(start);
561 /***********************************************************************
564 * Called by Win98 explorer.exe main binary, definitely has 0
567 DWORD WINAPI RunInstallUninstallStubs(void)
569 FIXME("(), stub!\n");
573 /***********************************************************************
574 * SetQueryNetSessionCount (SHDOCVW.@)
576 DWORD WINAPI SetQueryNetSessionCount(DWORD arg)
578 FIXME("(%lu), stub!\n", arg);
582 /**********************************************************************
583 * OpenURL (SHDOCVW.@)
585 void WINAPI OpenURL(HWND hWnd, HINSTANCE hInst, LPCSTR lpcstrUrl, int nShowCmd)
587 FIXME("%p %p %s %d\n", hWnd, hInst, debugstr_a(lpcstrUrl), nShowCmd);
590 /**********************************************************************
591 * Some forwards (by ordinal) to SHLWAPI
594 static void* fetch_shlwapi_ordinal(unsigned ord)
596 static const WCHAR shlwapiW[] = {'s','h','l','w','a','p','i','.','d','l','l','\0'};
599 if (!h && !(h = GetModuleHandleW(shlwapiW))) return NULL;
600 return (void*)GetProcAddress(h, (const char*)ord);
603 /******************************************************************
604 * WhichPlatformFORWARD (SHDOCVW.@)
606 DWORD WINAPI WhichPlatformFORWARD(void)
608 static DWORD (*WINAPI p)(void);
610 if (p || (p = fetch_shlwapi_ordinal(276))) return p();
611 return 1; /* not integrated, see shlwapi.WhichPlatform */
614 /******************************************************************
615 * StopWatchModeFORWARD (SHDOCVW.@)
617 void WINAPI StopWatchModeFORWARD(void)
619 static void (*WINAPI p)(void);
621 if (p || (p = fetch_shlwapi_ordinal(241))) p();
624 /******************************************************************
625 * StopWatchFlushFORWARD (SHDOCVW.@)
627 void WINAPI StopWatchFlushFORWARD(void)
629 static void (*WINAPI p)(void);
631 if (p || (p = fetch_shlwapi_ordinal(242))) p();
634 /******************************************************************
635 * StopWatchWFORWARD (SHDOCVW.@)
637 DWORD WINAPI StopWatchWFORWARD(DWORD dwClass, LPCWSTR lpszStr, DWORD dwUnknown,
638 DWORD dwMode, DWORD dwTimeStamp)
640 static DWORD (*WINAPI p)(DWORD, LPCWSTR, DWORD, DWORD, DWORD);
642 if (p || (p = fetch_shlwapi_ordinal(243)))
643 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
644 return ERROR_CALL_NOT_IMPLEMENTED;
647 /******************************************************************
648 * StopWatchAFORWARD (SHDOCVW.@)
650 DWORD WINAPI StopWatchAFORWARD(DWORD dwClass, LPCSTR lpszStr, DWORD dwUnknown,
651 DWORD dwMode, DWORD dwTimeStamp)
653 static DWORD (*WINAPI p)(DWORD, LPCSTR, DWORD, DWORD, DWORD);
655 if (p || (p = fetch_shlwapi_ordinal(244)))
656 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
657 return ERROR_CALL_NOT_IMPLEMENTED;