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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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;
108 register_iewindow_class();
110 case DLL_PROCESS_DETACH:
111 if (SHDOCVW_hshell32) FreeLibrary(SHDOCVW_hshell32);
112 if (hMozCtl && hMozCtl != (HMODULE)~0UL) FreeLibrary(hMozCtl);
113 unregister_iewindow_class();
119 /*************************************************************************
120 * DllCanUnloadNow (SHDOCVW.@)
122 HRESULT WINAPI DllCanUnloadNow(void)
124 HRESULT moz_can_unload = S_OK;
125 fnCanUnloadNow pCanUnloadNow;
129 pCanUnloadNow = (fnCanUnloadNow)
130 GetProcAddress(hMozCtl, "DllCanUnloadNow");
132 moz_can_unload = pCanUnloadNow();
135 if (moz_can_unload == S_OK && SHDOCVW_refCount == 0)
141 /*************************************************************************
142 * SHDOCVW_TryDownloadMozillaControl
144 typedef struct _IBindStatusCallbackImpl {
145 const IBindStatusCallbackVtbl *vtbl;
149 } IBindStatusCallbackImpl;
151 static HRESULT WINAPI
152 dlQueryInterface( IBindStatusCallback* This, REFIID riid, void** ppvObject )
154 if (ppvObject == NULL) return E_POINTER;
156 if( IsEqualIID(riid, &IID_IUnknown) ||
157 IsEqualIID(riid, &IID_IBindStatusCallback))
159 IBindStatusCallback_AddRef( This );
163 return E_NOINTERFACE;
166 static ULONG WINAPI dlAddRef( IBindStatusCallback* iface )
168 IBindStatusCallbackImpl *This = (IBindStatusCallbackImpl *) iface;
170 SHDOCVW_LockModule();
172 return InterlockedIncrement( &This->ref );
175 static ULONG WINAPI dlRelease( IBindStatusCallback* iface )
177 IBindStatusCallbackImpl *This = (IBindStatusCallbackImpl *) iface;
178 DWORD ref = InterlockedDecrement( &This->ref );
182 DestroyWindow( This->hDialog );
186 SHDOCVW_UnlockModule();
191 static HRESULT WINAPI
192 dlOnStartBinding( IBindStatusCallback* iface, DWORD dwReserved, IBinding* pib)
198 static HRESULT WINAPI
199 dlGetPriority( IBindStatusCallback* iface, LONG* pnPriority)
205 static HRESULT WINAPI
206 dlOnLowResource( IBindStatusCallback* iface, DWORD reserved)
212 static HRESULT WINAPI
213 dlOnProgress( IBindStatusCallback* iface, ULONG ulProgress,
214 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
216 IBindStatusCallbackImpl *This = (IBindStatusCallbackImpl *) iface;
220 hItem = GetDlgItem( This->hDialog, 1000 );
221 if( hItem && ulProgressMax )
222 SendMessageW(hItem,PBM_SETPOS,(ulProgress*100)/ulProgressMax,0);
224 hItem = GetDlgItem(This->hDialog, 104);
226 SendMessageW(hItem,WM_SETTEXT, 0, (LPARAM) szStatusText);
229 r = GetWindowLongPtrW( This->hDialog, GWLP_USERDATA );
230 if( r || GetLastError() )
232 *This->pbCancelled = TRUE;
240 static HRESULT WINAPI
241 dlOnStopBinding( IBindStatusCallback* iface, HRESULT hresult, LPCWSTR szError)
247 static HRESULT WINAPI
248 dlGetBindInfo( IBindStatusCallback* iface, DWORD* grfBINDF, BINDINFO* pbindinfo)
254 static HRESULT WINAPI
255 dlOnDataAvailable( IBindStatusCallback* iface, DWORD grfBSCF,
256 DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
262 static HRESULT WINAPI
263 dlOnObjectAvailable( IBindStatusCallback* iface, REFIID riid, IUnknown* punk)
269 static const IBindStatusCallbackVtbl dlVtbl =
284 static IBindStatusCallback* create_dl(HWND dlg, BOOL *pbCancelled)
286 IBindStatusCallbackImpl *This;
288 This = shdocvw_alloc(sizeof(*This));
289 This->vtbl = &dlVtbl;
292 This->pbCancelled = pbCancelled;
294 return (IBindStatusCallback*) This;
297 static DWORD WINAPI ThreadFunc( LPVOID info )
299 IBindStatusCallback *dl;
300 static const WCHAR szUrlVal[] = {'M','o','z','i','l','l','a','U','r','l',0};
301 static const WCHAR szFileProtocol[] = {'f','i','l','e',':','/','/','/',0};
302 static const WCHAR szSilentParameter[] = {' ','/','S',0};
303 WCHAR path[MAX_PATH], szUrl[MAX_PATH];
304 WCHAR szCommandLine[MAX_PATH+(sizeof( szSilentParameter )/sizeof( WCHAR ))];
307 PROCESS_INFORMATION pi;
311 BOOL bCancelled = FALSE;
312 BOOL bTempfile = FALSE;
314 /* find the name of the thing to download */
316 /* @@ Wine registry key: HKCU\Software\Wine\shdocvw */
317 r = RegOpenKeyW( HKEY_CURRENT_USER, szMozDlPath, &hkey );
318 if( r == ERROR_SUCCESS )
321 r = RegQueryValueExW( hkey, szUrlVal, NULL, &type, (LPBYTE)szUrl, &sz );
324 if( r != ERROR_SUCCESS )
327 if( !strncmpW(szUrl, szFileProtocol, strlenW(szFileProtocol)) )
328 lstrcpynW( path, szUrl+strlenW(szFileProtocol), MAX_PATH );
331 /* built the path for the download */
332 p = strrchrW( szUrl, '/' );
335 if (!GetTempPathW( MAX_PATH, path ))
337 strcatW( path, p+1 );
341 dl = create_dl(info, &bCancelled);
342 r = URLDownloadToFileW( NULL, szUrl, path, 0, dl );
344 IBindStatusCallback_Release( dl );
345 if( (r != S_OK) || bCancelled )
350 memset( &si, 0, sizeof si );
352 strcpyW( szCommandLine, path );
353 strcatW( szCommandLine, szSilentParameter );
354 r = CreateProcessW( path, szCommandLine, NULL, NULL, 0, 0, NULL, NULL, &si, &pi );
357 WaitForSingleObject( pi.hProcess, INFINITE );
358 CloseHandle( pi.hProcess );
359 CloseHandle( pi.hThread );
364 EndDialog( hDlg, 0 );
368 static INT_PTR CALLBACK
369 dlProc ( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
378 SetWindowLongPtrW( hwndDlg, GWLP_USERDATA, 0 );
379 hItem = GetDlgItem(hwndDlg, 1000);
382 SendMessageW(hItem,PBM_SETRANGE,0,MAKELPARAM(0,100));
383 SendMessageW(hItem,PBM_SETPOS,0,0);
385 hThread = CreateThread(NULL,0,ThreadFunc,hwndDlg,0,&ThreadId);
390 if( wParam == IDCANCEL )
391 SetWindowLongPtrW( hwndDlg, GWLP_USERDATA, 1 );
398 static BOOL SHDOCVW_TryDownloadMozillaControl(void)
402 static const WCHAR szWine[] = { 'W','i','n','e',0 };
405 SetLastError( ERROR_SUCCESS );
406 hsem = CreateSemaphoreA( NULL, 0, 1, "mozctl_install_semaphore");
407 if( GetLastError() != ERROR_ALREADY_EXISTS )
409 LoadStringW( shdocvw_hinstance, 1001, buf, sizeof buf/sizeof(WCHAR) );
410 r = MessageBoxW(NULL, buf, szWine, MB_YESNO | MB_ICONQUESTION);
414 DialogBoxW(shdocvw_hinstance, MAKEINTRESOURCEW(100), 0, dlProc);
417 WaitForSingleObject( hsem, INFINITE );
418 ReleaseSemaphore( hsem, 1, NULL );
424 static BOOL SHDOCVW_TryLoadMozillaControl(void)
426 WCHAR szPath[MAX_PATH];
429 if( hMozCtl != (HMODULE)~0UL )
430 return hMozCtl ? TRUE : FALSE;
434 if( SHDOCVW_GetMozctlPath( szPath, sizeof szPath ) )
436 hMozCtl = LoadLibraryExW(szPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
442 MESSAGE("You need to install the Mozilla ActiveX control to\n");
443 MESSAGE("use Wine's builtin CLSID_WebBrowser from SHDOCVW.DLL\n");
446 SHDOCVW_TryDownloadMozillaControl();
451 HRESULT create_mozctl(REFIID riid, void **ppv)
453 fnGetClassObject pGetClassObject;
456 if(!SHDOCVW_TryLoadMozillaControl())
457 return CLASS_E_CLASSNOTAVAILABLE;
459 pGetClassObject = (fnGetClassObject)GetProcAddress( hMozCtl, "DllGetClassObject" );
461 if( !pGetClassObject )
462 return CLASS_E_CLASSNOTAVAILABLE;
464 hres = pGetClassObject( &CLSID_MozillaBrowser, riid, ppv );
466 TRACE("hres = %08lx *ppv = %p\n", hres, *ppv );
471 /***********************************************************************
472 * DllGetVersion (SHDOCVW.@)
474 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
476 if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
478 /* this is what IE6 on Windows 98 reports */
479 info->dwMajorVersion = 6;
480 info->dwMinorVersion = 0;
481 info->dwBuildNumber = 2600;
482 info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
487 /*************************************************************************
488 * DllInstall (SHDOCVW.@)
490 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
492 FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
497 /*************************************************************************
498 * SHDOCVW_LoadShell32
500 * makes sure the handle to shell32 is valid
502 BOOL SHDOCVW_LoadShell32(void)
504 if (SHDOCVW_hshell32)
506 return ((SHDOCVW_hshell32 = LoadLibraryA("shell32.dll")) != NULL);
509 /***********************************************************************
512 * Called by Win98 explorer.exe main binary, definitely has 0
515 DWORD WINAPI WinList_Init(void)
517 FIXME("(), stub!\n");
521 /***********************************************************************
524 * Called by Win98 explorer.exe main binary, definitely has only one
527 static BOOL (WINAPI *pShellDDEInit)(BOOL start) = NULL;
529 BOOL WINAPI ShellDDEInit(BOOL start)
531 TRACE("(%d)\n", start);
535 if (!SHDOCVW_LoadShell32())
537 pShellDDEInit = GetProcAddress(SHDOCVW_hshell32, (LPCSTR)188);
541 return pShellDDEInit(start);
546 /***********************************************************************
549 * Called by Win98 explorer.exe main binary, definitely has 0
552 DWORD WINAPI RunInstallUninstallStubs(void)
554 FIXME("(), stub!\n");
558 /***********************************************************************
559 * SetQueryNetSessionCount (SHDOCVW.@)
561 DWORD WINAPI SetQueryNetSessionCount(DWORD arg)
563 FIXME("(%lu), stub!\n", arg);
567 /**********************************************************************
568 * OpenURL (SHDOCVW.@)
570 void WINAPI OpenURL(HWND hWnd, HINSTANCE hInst, LPCSTR lpcstrUrl, int nShowCmd)
572 FIXME("%p %p %s %d\n", hWnd, hInst, debugstr_a(lpcstrUrl), nShowCmd);
575 /**********************************************************************
576 * Some forwards (by ordinal) to SHLWAPI
579 static void* fetch_shlwapi_ordinal(unsigned ord)
581 static const WCHAR shlwapiW[] = {'s','h','l','w','a','p','i','.','d','l','l','\0'};
584 if (!h && !(h = GetModuleHandleW(shlwapiW))) return NULL;
585 return (void*)GetProcAddress(h, (const char*)ord);
588 /******************************************************************
589 * WhichPlatformFORWARD (SHDOCVW.@)
591 DWORD WINAPI WhichPlatformFORWARD(void)
593 static DWORD (*WINAPI p)(void);
595 if (p || (p = fetch_shlwapi_ordinal(276))) return p();
596 return 1; /* not integrated, see shlwapi.WhichPlatform */
599 /******************************************************************
600 * StopWatchModeFORWARD (SHDOCVW.@)
602 void WINAPI StopWatchModeFORWARD(void)
604 static void (*WINAPI p)(void);
606 if (p || (p = fetch_shlwapi_ordinal(241))) p();
609 /******************************************************************
610 * StopWatchFlushFORWARD (SHDOCVW.@)
612 void WINAPI StopWatchFlushFORWARD(void)
614 static void (*WINAPI p)(void);
616 if (p || (p = fetch_shlwapi_ordinal(242))) p();
619 /******************************************************************
620 * StopWatchWFORWARD (SHDOCVW.@)
622 DWORD WINAPI StopWatchWFORWARD(DWORD dwClass, LPCWSTR lpszStr, DWORD dwUnknown,
623 DWORD dwMode, DWORD dwTimeStamp)
625 static DWORD (*WINAPI p)(DWORD, LPCWSTR, DWORD, DWORD, DWORD);
627 if (p || (p = fetch_shlwapi_ordinal(243)))
628 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
629 return ERROR_CALL_NOT_IMPLEMENTED;
632 /******************************************************************
633 * StopWatchAFORWARD (SHDOCVW.@)
635 DWORD WINAPI StopWatchAFORWARD(DWORD dwClass, LPCSTR lpszStr, DWORD dwUnknown,
636 DWORD dwMode, DWORD dwTimeStamp)
638 static DWORD (*WINAPI p)(DWORD, LPCSTR, DWORD, DWORD, DWORD);
640 if (p || (p = fetch_shlwapi_ordinal(244)))
641 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
642 return ERROR_CALL_NOT_IMPLEMENTED;