d3d11: Use wined3d_device_context_draw().
[wine.git] / dlls / shdocvw / shdocvw_main.c
blob8c5dd8279c79e5bb61c231378090c0a3f99d8018
1 /*
2 * SHDOCVW - Internet Explorer Web Control
4 * Copyright 2001 John R. Sheets (for CodeWeavers)
5 * Copyright 2004 Mike McCormack (for CodeWeavers)
6 * Copyright 2008 Detlef Riekenberg
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <stdarg.h>
24 #include <stdio.h>
26 #include "wine/debug.h"
28 #include "shdocvw.h"
30 #include "winreg.h"
31 #include "shlwapi.h"
32 #include "wininet.h"
33 #include "isguids.h"
35 #include "initguid.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
39 LONG SHDOCVW_refCount = 0;
41 static HMODULE SHDOCVW_hshell32 = 0;
42 static HINSTANCE ieframe_instance;
44 static HINSTANCE get_ieframe_instance(void)
46 if(!ieframe_instance)
47 ieframe_instance = LoadLibraryW(L"ieframe.dll");
49 return ieframe_instance;
52 static HRESULT get_ieframe_object(REFCLSID rclsid, REFIID riid, void **ppv)
54 HINSTANCE ieframe_instance;
56 static HRESULT (WINAPI *ieframe_DllGetClassObject)(REFCLSID,REFIID,void**);
58 if(!ieframe_DllGetClassObject) {
59 ieframe_instance = get_ieframe_instance();
60 if(!ieframe_instance)
61 return CLASS_E_CLASSNOTAVAILABLE;
63 ieframe_DllGetClassObject = (void*)GetProcAddress(ieframe_instance, "DllGetClassObject");
64 if(!ieframe_DllGetClassObject)
65 return CLASS_E_CLASSNOTAVAILABLE;
68 return ieframe_DllGetClassObject(rclsid, riid, ppv);
71 /*************************************************************************
72 * DllGetClassObject (SHDOCVW.@)
74 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
76 TRACE("(%s %s %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
78 if(IsEqualGUID(&CLSID_WebBrowser, rclsid)
79 || IsEqualGUID(&CLSID_WebBrowser_V1, rclsid)
80 || IsEqualGUID(&CLSID_InternetShortcut, rclsid)
81 || IsEqualGUID(&CLSID_CUrlHistory, rclsid)
82 || IsEqualGUID(&CLSID_TaskbarList, rclsid))
83 return get_ieframe_object(rclsid, riid, ppv);
85 /* As a last resort, figure if the CLSID belongs to a 'Shell Instance Object' */
86 return SHDOCVW_GetShellInstanceObjectClassObject(rclsid, riid, ppv);
89 /***********************************************************************
90 * DllRegisterServer (shdocvw.@)
92 HRESULT WINAPI DllRegisterServer(void)
94 TRACE("\n");
95 return S_OK;
98 /***********************************************************************
99 * DllUnregisterServer (shdocvw.@)
101 HRESULT WINAPI DllUnregisterServer(void)
103 TRACE("\n");
104 return S_OK;
107 /******************************************************************
108 * IEWinMain (SHDOCVW.101)
110 * Only returns on error.
112 DWORD WINAPI IEWinMain(LPSTR szCommandLine, int nShowWindow)
114 DWORD (WINAPI *pIEWinMain)(const WCHAR*,int);
115 WCHAR *cmdline;
116 DWORD ret, len;
118 TRACE("%s %d\n", debugstr_a(szCommandLine), nShowWindow);
120 pIEWinMain = (void*)GetProcAddress(get_ieframe_instance(), MAKEINTRESOURCEA(101));
121 if(!pIEWinMain)
122 ExitProcess(1);
124 len = MultiByteToWideChar(CP_ACP, 0, szCommandLine, -1, NULL, 0);
125 cmdline = heap_alloc(len*sizeof(WCHAR));
126 if(!cmdline)
127 ExitProcess(1);
128 MultiByteToWideChar(CP_ACP, 0, szCommandLine, -1, cmdline, len);
130 ret = pIEWinMain(cmdline, nShowWindow);
132 heap_free(cmdline);
133 return ret;
136 /*************************************************************************
137 * SHDOCVW DllMain
139 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
141 TRACE("%p 0x%x %p\n", hinst, fdwReason, fImpLoad);
142 switch (fdwReason)
144 case DLL_PROCESS_ATTACH:
145 DisableThreadLibraryCalls(hinst);
146 break;
147 case DLL_PROCESS_DETACH:
148 if (fImpLoad) break;
149 if (SHDOCVW_hshell32) FreeLibrary(SHDOCVW_hshell32);
150 if (ieframe_instance) FreeLibrary(ieframe_instance);
151 break;
153 return TRUE;
156 /*************************************************************************
157 * DllCanUnloadNow (SHDOCVW.@)
159 HRESULT WINAPI DllCanUnloadNow(void)
161 return SHDOCVW_refCount ? S_FALSE : S_OK;
164 /***********************************************************************
165 * DllGetVersion (SHDOCVW.@)
167 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
169 if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
171 /* this is what IE6 on Windows 98 reports */
172 info->dwMajorVersion = 6;
173 info->dwMinorVersion = 0;
174 info->dwBuildNumber = 2600;
175 info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
177 return NOERROR;
180 /*************************************************************************
181 * DllInstall (SHDOCVW.@)
183 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
185 FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
187 return S_OK;
190 /*************************************************************************
191 * SHDOCVW_LoadShell32
193 * makes sure the handle to shell32 is valid
195 static BOOL SHDOCVW_LoadShell32(void)
197 if (SHDOCVW_hshell32)
198 return TRUE;
199 return ((SHDOCVW_hshell32 = LoadLibraryA("shell32.dll")) != NULL);
202 /***********************************************************************
203 * @ (SHDOCVW.110)
205 * Called by Win98 explorer.exe main binary, definitely has 0
206 * parameters.
208 DWORD WINAPI WinList_Init(void)
210 FIXME("(), stub!\n");
211 return 0x0deadfeed;
214 /***********************************************************************
215 * @ (SHDOCVW.118)
217 * Called by Win98 explorer.exe main binary, definitely has only one
218 * parameter.
220 static BOOL (WINAPI *pShellDDEInit)(BOOL start) = NULL;
222 BOOL WINAPI ShellDDEInit(BOOL start)
224 TRACE("(%d)\n", start);
226 if (!pShellDDEInit)
228 if (!SHDOCVW_LoadShell32())
229 return FALSE;
230 pShellDDEInit = (void *)GetProcAddress(SHDOCVW_hshell32, (LPCSTR)188);
233 if (pShellDDEInit)
234 return pShellDDEInit(start);
235 else
236 return FALSE;
239 /***********************************************************************
240 * @ (SHDOCVW.125)
242 * Called by Win98 explorer.exe main binary, definitely has 0
243 * parameters.
245 DWORD WINAPI RunInstallUninstallStubs(void)
247 FIXME("(), stub!\n");
248 return 0x0deadbee;
251 /***********************************************************************
252 * @ (SHDOCVW.130)
254 * Called by Emerge Desktop (alternative Windows Shell).
256 DWORD WINAPI RunInstallUninstallStubs2(int arg)
258 FIXME("(%d), stub!\n", arg);
259 return 0x0deadbee;
262 /***********************************************************************
263 * SetQueryNetSessionCount (SHDOCVW.@)
265 DWORD WINAPI SetQueryNetSessionCount(DWORD arg)
267 FIXME("(%u), stub!\n", arg);
268 return 0;
271 /**********************************************************************
272 * Some forwards (by ordinal) to SHLWAPI
275 static void* fetch_shlwapi_ordinal(UINT_PTR ord)
277 static HANDLE h;
279 if (!h && !(h = GetModuleHandleW(L"shlwapi.dll"))) return NULL;
280 return (void*)GetProcAddress(h, (const char*)ord);
283 /******************************************************************
284 * StopWatchModeFORWARD (SHDOCVW.@)
286 void WINAPI StopWatchModeFORWARD(void)
288 static void (WINAPI *p)(void);
290 if (p || (p = fetch_shlwapi_ordinal(241))) p();
293 /******************************************************************
294 * StopWatchFlushFORWARD (SHDOCVW.@)
296 void WINAPI StopWatchFlushFORWARD(void)
298 static void (WINAPI *p)(void);
300 if (p || (p = fetch_shlwapi_ordinal(242))) p();
303 /******************************************************************
304 * StopWatchAFORWARD (SHDOCVW.@)
306 DWORD WINAPI StopWatchAFORWARD(DWORD dwClass, LPCSTR lpszStr, DWORD dwUnknown,
307 DWORD dwMode, DWORD dwTimeStamp)
309 static DWORD (WINAPI *p)(DWORD, LPCSTR, DWORD, DWORD, DWORD);
311 if (p || (p = fetch_shlwapi_ordinal(243)))
312 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
313 return ERROR_CALL_NOT_IMPLEMENTED;
316 /******************************************************************
317 * StopWatchWFORWARD (SHDOCVW.@)
319 DWORD WINAPI StopWatchWFORWARD(DWORD dwClass, LPCWSTR lpszStr, DWORD dwUnknown,
320 DWORD dwMode, DWORD dwTimeStamp)
322 static DWORD (WINAPI *p)(DWORD, LPCWSTR, DWORD, DWORD, DWORD);
324 if (p || (p = fetch_shlwapi_ordinal(244)))
325 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
326 return ERROR_CALL_NOT_IMPLEMENTED;
329 /******************************************************************
330 * URLSubRegQueryA (SHDOCVW.151)
332 HRESULT WINAPI URLSubRegQueryA(LPCSTR regpath, LPCSTR name, DWORD type,
333 LPSTR out, DWORD outlen, DWORD unknown)
335 CHAR buffer[INTERNET_MAX_URL_LENGTH];
336 DWORD len;
337 LONG res;
339 TRACE("(%s, %s, %d, %p, %d, %d)\n", debugstr_a(regpath), debugstr_a(name),
340 type, out, outlen, unknown);
342 if (!out) return S_OK;
344 len = sizeof(buffer);
345 res = SHRegGetUSValueA(regpath, name, NULL, buffer, &len, FALSE, NULL, 0);
346 if (!res) {
347 lstrcpynA(out, buffer, outlen);
348 return S_OK;
351 return E_FAIL;
354 /******************************************************************
355 * ParseURLFromOutsideSourceW (SHDOCVW.170)
357 DWORD WINAPI ParseURLFromOutsideSourceW(LPCWSTR url, LPWSTR out, LPDWORD plen, LPDWORD unknown)
359 WCHAR buffer_in[INTERNET_MAX_URL_LENGTH];
360 WCHAR buffer_out[INTERNET_MAX_URL_LENGTH];
361 LPCWSTR ptr = url;
362 HRESULT hr;
363 DWORD needed;
364 DWORD len;
365 DWORD res = 0;
368 TRACE("(%s, %p, %p, %p) len: %d, unknown: 0x%x\n", debugstr_w(url), out, plen, unknown,
369 plen ? *plen : 0, unknown ? *unknown : 0);
371 if (!PathIsURLW(ptr)) {
372 len = ARRAY_SIZE(buffer_in);
373 buffer_in[0] = 0;
374 hr = UrlApplySchemeW(ptr, buffer_in, &len, URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT);
375 TRACE("got 0x%x with %s\n", hr, debugstr_w(buffer_in));
376 if (hr == S_OK) {
377 /* we parsed the url to buffer_in */
378 ptr = buffer_in;
380 else
382 FIXME("call search hook for %s\n", debugstr_w(ptr));
386 len = ARRAY_SIZE(buffer_out);
387 buffer_out[0] = '\0';
388 hr = UrlCanonicalizeW(ptr, buffer_out, &len, URL_ESCAPE_SPACES_ONLY);
389 needed = lstrlenW(buffer_out)+1;
390 TRACE("got 0x%x with %s (need %d)\n", hr, debugstr_w(buffer_out), needed);
392 if (*plen >= needed) {
393 if (out != NULL) {
394 lstrcpyW(out, buffer_out);
395 res++;
397 needed--;
400 *plen = needed;
402 TRACE("=> %d\n", res);
403 return res;
406 /******************************************************************
407 * ParseURLFromOutsideSourceA (SHDOCVW.169)
409 * See ParseURLFromOutsideSourceW
411 DWORD WINAPI ParseURLFromOutsideSourceA(LPCSTR url, LPSTR out, LPDWORD plen, LPDWORD unknown)
413 WCHAR buffer[INTERNET_MAX_URL_LENGTH];
414 LPWSTR urlW = NULL;
415 DWORD needed;
416 DWORD res;
417 DWORD len;
419 TRACE("(%s, %p, %p, %p) len: %d, unknown: 0x%x\n", debugstr_a(url), out, plen, unknown,
420 plen ? *plen : 0, unknown ? *unknown : 0);
422 if (url) {
423 len = MultiByteToWideChar(CP_ACP, 0, url, -1, NULL, 0);
424 urlW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
425 MultiByteToWideChar(CP_ACP, 0, url, -1, urlW, len);
428 len = ARRAY_SIZE(buffer);
429 ParseURLFromOutsideSourceW(urlW, buffer, &len, unknown);
430 HeapFree(GetProcessHeap(), 0, urlW);
432 needed = WideCharToMultiByte(CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL);
434 res = 0;
435 if (*plen >= needed) {
436 if (out != NULL) {
437 WideCharToMultiByte(CP_ACP, 0, buffer, -1, out, *plen, NULL, NULL);
438 res = needed;
440 needed--;
443 *plen = needed;
445 TRACE("=> %d\n", res);
446 return res;
449 /******************************************************************
450 * IEParseDisplayNameWithBCW (SHDOCVW.218)
452 HRESULT WINAPI IEParseDisplayNameWithBCW(DWORD codepage, LPCWSTR lpszDisplayName, LPBC pbc, LPITEMIDLIST *ppidl)
454 /* Guessing at parameter 3 based on IShellFolder's ParseDisplayName */
455 FIXME("stub: 0x%x %s %p %p\n",codepage,debugstr_w(lpszDisplayName),pbc,ppidl);
456 return E_FAIL;
459 /******************************************************************
460 * SHRestricted2W (SHDOCVW.159)
462 DWORD WINAPI SHRestricted2W(DWORD res, LPCWSTR url, DWORD reserved)
464 FIXME("(%d %s %d) stub\n", res, debugstr_w(url), reserved);
465 return 0;
468 /******************************************************************
469 * SHRestricted2A (SHDOCVW.158)
471 * See SHRestricted2W
473 DWORD WINAPI SHRestricted2A(DWORD restriction, LPCSTR url, DWORD reserved)
475 LPWSTR urlW = NULL;
476 DWORD res;
478 TRACE("(%d, %s, %d)\n", restriction, debugstr_a(url), reserved);
479 if (url) {
480 DWORD len = MultiByteToWideChar(CP_ACP, 0, url, -1, NULL, 0);
481 urlW = heap_alloc(len * sizeof(WCHAR));
482 MultiByteToWideChar(CP_ACP, 0, url, -1, urlW, len);
484 res = SHRestricted2W(restriction, urlW, reserved);
485 heap_free(urlW);
486 return res;
489 /******************************************************************
490 * ImportPrivacySettings (SHDOCVW.@)
492 * Import global and/or per site privacy preferences from an xml file
494 * PARAMS
495 * filename [I] XML file to use
496 * pGlobalPrefs [IO] PTR to a usage flag for the global privacy preferences
497 * pPerSitePrefs [IO] PTR to a usage flag for the per site privacy preferences
499 * RETURNS
500 * Success: TRUE (the privacy preferences where updated)
501 * Failure: FALSE (the privacy preferences are unchanged)
503 * NOTES
504 * Set the flag to TRUE, when the related privacy preferences in the xml file
505 * should be used (parsed and overwrite the current settings).
506 * On return, the flag is TRUE, when the related privacy settings where used
509 BOOL WINAPI ImportPrivacySettings(LPCWSTR filename, BOOL *pGlobalPrefs, BOOL * pPerSitePrefs)
511 FIXME("(%s, %p->%d, %p->%d): stub\n", debugstr_w(filename),
512 pGlobalPrefs, pGlobalPrefs ? *pGlobalPrefs : 0,
513 pPerSitePrefs, pPerSitePrefs ? *pPerSitePrefs : 0);
515 if (pGlobalPrefs) *pGlobalPrefs = FALSE;
516 if (pPerSitePrefs) *pPerSitePrefs = FALSE;
518 return TRUE;
521 /******************************************************************
522 * ResetProfileSharing (SHDOCVW.164)
524 HRESULT WINAPI ResetProfileSharing(HWND hwnd)
526 FIXME("(%p) stub\n", hwnd);
527 return E_NOTIMPL;
530 /******************************************************************
531 * InstallReg_RunDLL (SHDOCVW.@)
533 void WINAPI InstallReg_RunDLL(HWND hwnd, HINSTANCE handle, LPCSTR cmdline, INT show)
535 FIXME("(%p %p %s %x)\n", hwnd, handle, debugstr_a(cmdline), show);
538 /******************************************************************
539 * DoFileDownload (SHDOCVW.@)
541 BOOL WINAPI DoFileDownload(LPWSTR filename)
543 FIXME("(%s) stub\n", debugstr_w(filename));
544 return FALSE;
547 /******************************************************************
548 * DoOrganizeFavDlgW (SHDOCVW.@)
550 BOOL WINAPI DoOrganizeFavDlgW(HWND hwnd, LPCWSTR initDir)
552 FIXME("(%p %s) stub\n", hwnd, debugstr_w(initDir));
553 return FALSE;
556 /******************************************************************
557 * DoOrganizeFavDlg (SHDOCVW.@)
559 BOOL WINAPI DoOrganizeFavDlg(HWND hwnd, LPCSTR initDir)
561 LPWSTR initDirW = NULL;
562 BOOL res;
564 TRACE("(%p %s)\n", hwnd, debugstr_a(initDir));
566 if (initDir) {
567 DWORD len = MultiByteToWideChar(CP_ACP, 0, initDir, -1, NULL, 0);
568 initDirW = heap_alloc(len * sizeof(WCHAR));
569 MultiByteToWideChar(CP_ACP, 0, initDir, -1, initDirW, len);
571 res = DoOrganizeFavDlgW(hwnd, initDirW);
572 heap_free(initDirW);
573 return res;