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;
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 );
183 HeapFree( GetProcessHeap(), 0, This );
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 = HeapAlloc( GetProcessHeap(), 0, 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 WCHAR path[MAX_PATH], szUrl[MAX_PATH];
305 PROCESS_INFORMATION pi;
309 BOOL bCancelled = FALSE;
310 BOOL bTempfile = FALSE;
312 /* find the name of the thing to download */
314 /* @@ Wine registry key: HKCU\Software\Wine\shdocvw */
315 r = RegOpenKeyW( HKEY_CURRENT_USER, szMozDlPath, &hkey );
316 if( r == ERROR_SUCCESS )
319 r = RegQueryValueExW( hkey, szUrlVal, NULL, &type, (LPBYTE)szUrl, &sz );
322 if( r != ERROR_SUCCESS )
325 if( !strncmpW(szUrl, szFileProtocol, strlenW(szFileProtocol)) )
326 lstrcpynW( path, szUrl+strlenW(szFileProtocol), MAX_PATH );
329 /* built the path for the download */
330 p = strrchrW( szUrl, '/' );
333 if (!GetTempPathW( MAX_PATH, path ))
335 strcatW( path, p+1 );
339 dl = create_dl(info, &bCancelled);
340 r = URLDownloadToFileW( NULL, szUrl, path, 0, dl );
342 IBindStatusCallback_Release( dl );
343 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 );
354 CloseHandle( pi.hProcess );
355 CloseHandle( pi.hThread );
360 EndDialog( hDlg, 0 );
364 static INT_PTR CALLBACK
365 dlProc ( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
374 SetWindowLongPtrW( hwndDlg, GWLP_USERDATA, 0 );
375 hItem = GetDlgItem(hwndDlg, 1000);
378 SendMessageW(hItem,PBM_SETRANGE,0,MAKELPARAM(0,100));
379 SendMessageW(hItem,PBM_SETPOS,0,0);
381 hThread = CreateThread(NULL,0,ThreadFunc,hwndDlg,0,&ThreadId);
386 if( wParam == IDCANCEL )
387 SetWindowLongPtrW( hwndDlg, GWLP_USERDATA, 1 );
394 static BOOL SHDOCVW_TryDownloadMozillaControl(void)
398 static const WCHAR szWine[] = { 'W','i','n','e',0 };
401 SetLastError( ERROR_SUCCESS );
402 hsem = CreateSemaphoreA( NULL, 0, 1, "mozctl_install_semaphore");
403 if( GetLastError() != ERROR_ALREADY_EXISTS )
405 LoadStringW( shdocvw_hinstance, 1001, buf, sizeof buf/sizeof(WCHAR) );
406 r = MessageBoxW(NULL, buf, szWine, MB_YESNO | MB_ICONQUESTION);
410 DialogBoxW(shdocvw_hinstance, MAKEINTRESOURCEW(100), 0, dlProc);
413 WaitForSingleObject( hsem, INFINITE );
414 ReleaseSemaphore( hsem, 1, NULL );
420 static BOOL SHDOCVW_TryLoadMozillaControl(void)
422 WCHAR szPath[MAX_PATH];
425 if( hMozCtl != (HMODULE)~0UL )
426 return hMozCtl ? TRUE : FALSE;
430 if( SHDOCVW_GetMozctlPath( szPath, sizeof szPath ) )
432 hMozCtl = LoadLibraryExW(szPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
438 MESSAGE("You need to install the Mozilla ActiveX control to\n");
439 MESSAGE("use Wine's builtin CLSID_WebBrowser from SHDOCVW.DLL\n");
442 SHDOCVW_TryDownloadMozillaControl();
447 HRESULT create_mozctl(REFIID riid, void **ppv)
449 fnGetClassObject pGetClassObject;
452 if(!SHDOCVW_TryLoadMozillaControl())
453 return CLASS_E_CLASSNOTAVAILABLE;
455 pGetClassObject = (fnGetClassObject)GetProcAddress( hMozCtl, "DllGetClassObject" );
457 if( !pGetClassObject )
458 return CLASS_E_CLASSNOTAVAILABLE;
460 hres = pGetClassObject( &CLSID_MozillaBrowser, riid, ppv );
462 TRACE("hres = %08lx *ppv = %p\n", hres, *ppv );
467 /***********************************************************************
468 * DllGetVersion (SHDOCVW.@)
470 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
472 if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
474 /* this is what IE6 on Windows 98 reports */
475 info->dwMajorVersion = 6;
476 info->dwMinorVersion = 0;
477 info->dwBuildNumber = 2600;
478 info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
483 /*************************************************************************
484 * DllInstall (SHDOCVW.@)
486 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
488 FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
493 /*************************************************************************
494 * SHDOCVW_LoadShell32
496 * makes sure the handle to shell32 is valid
498 BOOL SHDOCVW_LoadShell32(void)
500 if (SHDOCVW_hshell32)
502 return ((SHDOCVW_hshell32 = LoadLibraryA("shell32.dll")) != NULL);
505 /***********************************************************************
508 * Called by Win98 explorer.exe main binary, definitely has 0
511 DWORD WINAPI WinList_Init(void)
513 FIXME("(), stub!\n");
517 /***********************************************************************
520 * Called by Win98 explorer.exe main binary, definitely has only one
523 static BOOL (WINAPI *pShellDDEInit)(BOOL start) = NULL;
525 BOOL WINAPI ShellDDEInit(BOOL start)
527 TRACE("(%d)\n", start);
531 if (!SHDOCVW_LoadShell32())
533 pShellDDEInit = GetProcAddress(SHDOCVW_hshell32, (LPCSTR)188);
537 return pShellDDEInit(start);
542 /***********************************************************************
545 * Called by Win98 explorer.exe main binary, definitely has 0
548 DWORD WINAPI RunInstallUninstallStubs(void)
550 FIXME("(), stub!\n");
554 /***********************************************************************
555 * SetQueryNetSessionCount (SHDOCVW.@)
557 DWORD WINAPI SetQueryNetSessionCount(DWORD arg)
559 FIXME("(%lu), stub!\n", arg);
563 /**********************************************************************
564 * OpenURL (SHDOCVW.@)
566 void WINAPI OpenURL(HWND hWnd, HINSTANCE hInst, LPCSTR lpcstrUrl, int nShowCmd)
568 FIXME("%p %p %s %d\n", hWnd, hInst, debugstr_a(lpcstrUrl), nShowCmd);
571 /**********************************************************************
572 * Some forwards (by ordinal) to SHLWAPI
575 static void* fetch_shlwapi_ordinal(unsigned ord)
577 static const WCHAR shlwapiW[] = {'s','h','l','w','a','p','i','.','d','l','l','\0'};
580 if (!h && !(h = GetModuleHandleW(shlwapiW))) return NULL;
581 return (void*)GetProcAddress(h, (const char*)ord);
584 /******************************************************************
585 * WhichPlatformFORWARD (SHDOCVW.@)
587 DWORD WINAPI WhichPlatformFORWARD(void)
589 static DWORD (*WINAPI p)(void);
591 if (p || (p = fetch_shlwapi_ordinal(276))) return p();
592 return 1; /* not integrated, see shlwapi.WhichPlatform */
595 /******************************************************************
596 * StopWatchModeFORWARD (SHDOCVW.@)
598 void WINAPI StopWatchModeFORWARD(void)
600 static void (*WINAPI p)(void);
602 if (p || (p = fetch_shlwapi_ordinal(241))) p();
605 /******************************************************************
606 * StopWatchFlushFORWARD (SHDOCVW.@)
608 void WINAPI StopWatchFlushFORWARD(void)
610 static void (*WINAPI p)(void);
612 if (p || (p = fetch_shlwapi_ordinal(242))) p();
615 /******************************************************************
616 * StopWatchWFORWARD (SHDOCVW.@)
618 DWORD WINAPI StopWatchWFORWARD(DWORD dwClass, LPCWSTR lpszStr, DWORD dwUnknown,
619 DWORD dwMode, DWORD dwTimeStamp)
621 static DWORD (*WINAPI p)(DWORD, LPCWSTR, DWORD, DWORD, DWORD);
623 if (p || (p = fetch_shlwapi_ordinal(243)))
624 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
625 return ERROR_CALL_NOT_IMPLEMENTED;
628 /******************************************************************
629 * StopWatchAFORWARD (SHDOCVW.@)
631 DWORD WINAPI StopWatchAFORWARD(DWORD dwClass, LPCSTR lpszStr, DWORD dwUnknown,
632 DWORD dwMode, DWORD dwTimeStamp)
634 static DWORD (*WINAPI p)(DWORD, LPCSTR, DWORD, DWORD, DWORD);
636 if (p || (p = fetch_shlwapi_ordinal(244)))
637 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
638 return ERROR_CALL_NOT_IMPLEMENTED;