[SHDOCVW] Sync with Wine 3.0. CORE-14225
[reactos.git] / dll / win32 / shdocvw / shdocvw_main.c
1 /*
2 * SHDOCVW - Internet Explorer Web Control
3 *
4 * Copyright 2001 John R. Sheets (for CodeWeavers)
5 * Copyright 2004 Mike McCormack (for CodeWeavers)
6 * Copyright 2008 Detlef Riekenberg
7 *
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.
12 *
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.
17 *
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
21 */
22
23 #include "shdocvw.h"
24
25 #include <shlwapi.h>
26 #include <wininet.h>
27
28 LONG SHDOCVW_refCount = 0;
29
30 static HMODULE SHDOCVW_hshell32 = 0;
31 static HINSTANCE ieframe_instance;
32
33 static HINSTANCE get_ieframe_instance(void)
34 {
35 static const WCHAR ieframe_dllW[] = {'i','e','f','r','a','m','e','.','d','l','l',0};
36
37 if(!ieframe_instance)
38 ieframe_instance = LoadLibraryW(ieframe_dllW);
39
40 return ieframe_instance;
41 }
42
43 static HRESULT get_ieframe_object(REFCLSID rclsid, REFIID riid, void **ppv)
44 {
45 HINSTANCE ieframe_instance;
46
47 static HRESULT (WINAPI *ieframe_DllGetClassObject)(REFCLSID,REFIID,void**);
48
49 if(!ieframe_DllGetClassObject) {
50 ieframe_instance = get_ieframe_instance();
51 if(!ieframe_instance)
52 return CLASS_E_CLASSNOTAVAILABLE;
53
54 ieframe_DllGetClassObject = (void*)GetProcAddress(ieframe_instance, "DllGetClassObject");
55 if(!ieframe_DllGetClassObject)
56 return CLASS_E_CLASSNOTAVAILABLE;
57 }
58
59 return ieframe_DllGetClassObject(rclsid, riid, ppv);
60 }
61
62 /*************************************************************************
63 * DllGetClassObject (SHDOCVW.@)
64 */
65 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
66 {
67 TRACE("(%s %s %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
68
69 if(IsEqualGUID(&CLSID_WebBrowser, rclsid)
70 || IsEqualGUID(&CLSID_WebBrowser_V1, rclsid)
71 || IsEqualGUID(&CLSID_InternetShortcut, rclsid)
72 || IsEqualGUID(&CLSID_CUrlHistory, rclsid)
73 || IsEqualGUID(&CLSID_TaskbarList, rclsid))
74 return get_ieframe_object(rclsid, riid, ppv);
75
76 /* As a last resort, figure if the CLSID belongs to a 'Shell Instance Object' */
77 return SHDOCVW_GetShellInstanceObjectClassObject(rclsid, riid, ppv);
78 }
79
80 /***********************************************************************
81 * DllRegisterServer (shdocvw.@)
82 */
83 HRESULT WINAPI DllRegisterServer(void)
84 {
85 TRACE("\n");
86 return S_OK;
87 }
88
89 /***********************************************************************
90 * DllUnregisterServer (shdocvw.@)
91 */
92 HRESULT WINAPI DllUnregisterServer(void)
93 {
94 TRACE("\n");
95 return S_OK;
96 }
97
98 /******************************************************************
99 * IEWinMain (SHDOCVW.101)
100 *
101 * Only returns on error.
102 */
103 DWORD WINAPI IEWinMain(LPSTR szCommandLine, int nShowWindow)
104 {
105 DWORD (WINAPI *pIEWinMain)(const WCHAR*,int);
106 WCHAR *cmdline;
107 DWORD ret, len;
108
109 TRACE("%s %d\n", debugstr_a(szCommandLine), nShowWindow);
110
111 pIEWinMain = (void*)GetProcAddress(get_ieframe_instance(), MAKEINTRESOURCEA(101));
112 if(!pIEWinMain)
113 ExitProcess(1);
114
115 len = MultiByteToWideChar(CP_ACP, 0, szCommandLine, -1, NULL, 0);
116 cmdline = heap_alloc(len*sizeof(WCHAR));
117 if(!cmdline)
118 ExitProcess(1);
119 MultiByteToWideChar(CP_ACP, 0, szCommandLine, -1, cmdline, len);
120
121 ret = pIEWinMain(cmdline, nShowWindow);
122
123 heap_free(cmdline);
124 return ret;
125 }
126
127 /*************************************************************************
128 * SHDOCVW DllMain
129 */
130 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
131 {
132 TRACE("%p 0x%x %p\n", hinst, fdwReason, fImpLoad);
133 switch (fdwReason)
134 {
135 case DLL_PROCESS_ATTACH:
136 DisableThreadLibraryCalls(hinst);
137 break;
138 case DLL_PROCESS_DETACH:
139 if (fImpLoad) break;
140 if (SHDOCVW_hshell32) FreeLibrary(SHDOCVW_hshell32);
141 if (ieframe_instance) FreeLibrary(ieframe_instance);
142 break;
143 }
144 return TRUE;
145 }
146
147 /*************************************************************************
148 * DllCanUnloadNow (SHDOCVW.@)
149 */
150 HRESULT WINAPI DllCanUnloadNow(void)
151 {
152 return SHDOCVW_refCount ? S_FALSE : S_OK;
153 }
154
155 /***********************************************************************
156 * DllGetVersion (SHDOCVW.@)
157 */
158 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
159 {
160 if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
161
162 /* this is what IE6 on Windows 98 reports */
163 info->dwMajorVersion = 6;
164 info->dwMinorVersion = 0;
165 info->dwBuildNumber = 2600;
166 info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
167
168 return NOERROR;
169 }
170
171 /*************************************************************************
172 * DllInstall (SHDOCVW.@)
173 */
174 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
175 {
176 FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
177
178 return S_OK;
179 }
180
181 /*************************************************************************
182 * SHDOCVW_LoadShell32
183 *
184 * makes sure the handle to shell32 is valid
185 */
186 static BOOL SHDOCVW_LoadShell32(void)
187 {
188 if (SHDOCVW_hshell32)
189 return TRUE;
190 return ((SHDOCVW_hshell32 = LoadLibraryA("shell32.dll")) != NULL);
191 }
192
193 /***********************************************************************
194 * @ (SHDOCVW.110)
195 *
196 * Called by Win98 explorer.exe main binary, definitely has 0
197 * parameters.
198 */
199 DWORD WINAPI WinList_Init(void)
200 {
201 FIXME("(), stub!\n");
202 return 0x0deadfeed;
203 }
204
205 /***********************************************************************
206 * @ (SHDOCVW.118)
207 *
208 * Called by Win98 explorer.exe main binary, definitely has only one
209 * parameter.
210 */
211 static BOOL (WINAPI *pShellDDEInit)(BOOL start) = NULL;
212
213 BOOL WINAPI ShellDDEInit(BOOL start)
214 {
215 TRACE("(%d)\n", start);
216
217 if (!pShellDDEInit)
218 {
219 if (!SHDOCVW_LoadShell32())
220 return FALSE;
221 pShellDDEInit = (void *)GetProcAddress(SHDOCVW_hshell32, (LPCSTR)188);
222 }
223
224 if (pShellDDEInit)
225 return pShellDDEInit(start);
226 else
227 return FALSE;
228 }
229
230 /***********************************************************************
231 * @ (SHDOCVW.125)
232 *
233 * Called by Win98 explorer.exe main binary, definitely has 0
234 * parameters.
235 */
236 DWORD WINAPI RunInstallUninstallStubs(void)
237 {
238 FIXME("(), stub!\n");
239 return 0x0deadbee;
240 }
241
242 /***********************************************************************
243 * @ (SHDOCVW.130)
244 *
245 * Called by Emerge Desktop (alternative Windows Shell).
246 */
247 DWORD WINAPI RunInstallUninstallStubs2(int arg)
248 {
249 FIXME("(%d), stub!\n", arg);
250 return 0x0deadbee;
251 }
252
253 /***********************************************************************
254 * SetQueryNetSessionCount (SHDOCVW.@)
255 */
256 DWORD WINAPI SetQueryNetSessionCount(DWORD arg)
257 {
258 FIXME("(%u), stub!\n", arg);
259 return 0;
260 }
261
262 /**********************************************************************
263 * Some forwards (by ordinal) to SHLWAPI
264 */
265
266 static void* fetch_shlwapi_ordinal(UINT_PTR ord)
267 {
268 static const WCHAR shlwapiW[] = {'s','h','l','w','a','p','i','.','d','l','l','\0'};
269 static HANDLE h;
270
271 if (!h && !(h = GetModuleHandleW(shlwapiW))) return NULL;
272 return (void*)GetProcAddress(h, (const char*)ord);
273 }
274
275 /******************************************************************
276 * WhichPlatformFORWARD (SHDOCVW.@)
277 */
278 DWORD WINAPI WhichPlatformFORWARD(void)
279 {
280 static DWORD (WINAPI *p)(void);
281
282 if (p || (p = fetch_shlwapi_ordinal(276))) return p();
283 return 1; /* not integrated, see shlwapi.WhichPlatform */
284 }
285
286 /******************************************************************
287 * StopWatchModeFORWARD (SHDOCVW.@)
288 */
289 void WINAPI StopWatchModeFORWARD(void)
290 {
291 static void (WINAPI *p)(void);
292
293 if (p || (p = fetch_shlwapi_ordinal(241))) p();
294 }
295
296 /******************************************************************
297 * StopWatchFlushFORWARD (SHDOCVW.@)
298 */
299 void WINAPI StopWatchFlushFORWARD(void)
300 {
301 static void (WINAPI *p)(void);
302
303 if (p || (p = fetch_shlwapi_ordinal(242))) p();
304 }
305
306 /******************************************************************
307 * StopWatchAFORWARD (SHDOCVW.@)
308 */
309 DWORD WINAPI StopWatchAFORWARD(DWORD dwClass, LPCSTR lpszStr, DWORD dwUnknown,
310 DWORD dwMode, DWORD dwTimeStamp)
311 {
312 static DWORD (WINAPI *p)(DWORD, LPCSTR, DWORD, DWORD, DWORD);
313
314 if (p || (p = fetch_shlwapi_ordinal(243)))
315 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
316 return ERROR_CALL_NOT_IMPLEMENTED;
317 }
318
319 /******************************************************************
320 * StopWatchWFORWARD (SHDOCVW.@)
321 */
322 DWORD WINAPI StopWatchWFORWARD(DWORD dwClass, LPCWSTR lpszStr, DWORD dwUnknown,
323 DWORD dwMode, DWORD dwTimeStamp)
324 {
325 static DWORD (WINAPI *p)(DWORD, LPCWSTR, DWORD, DWORD, DWORD);
326
327 if (p || (p = fetch_shlwapi_ordinal(244)))
328 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
329 return ERROR_CALL_NOT_IMPLEMENTED;
330 }
331
332 /******************************************************************
333 * URLSubRegQueryA (SHDOCVW.151)
334 */
335 HRESULT WINAPI URLSubRegQueryA(LPCSTR regpath, LPCSTR name, DWORD type,
336 LPSTR out, DWORD outlen, DWORD unknown)
337 {
338 CHAR buffer[INTERNET_MAX_URL_LENGTH];
339 DWORD len;
340 LONG res;
341
342 TRACE("(%s, %s, %d, %p, %d, %d)\n", debugstr_a(regpath), debugstr_a(name),
343 type, out, outlen, unknown);
344
345 if (!out) return S_OK;
346
347 len = sizeof(buffer);
348 res = SHRegGetUSValueA(regpath, name, NULL, buffer, &len, FALSE, NULL, 0);
349 if (!res) {
350 lstrcpynA(out, buffer, outlen);
351 return S_OK;
352 }
353
354 return E_FAIL;
355 }
356
357 /******************************************************************
358 * ParseURLFromOutsideSourceW (SHDOCVW.170)
359 */
360 DWORD WINAPI ParseURLFromOutsideSourceW(LPCWSTR url, LPWSTR out, LPDWORD plen, LPDWORD unknown)
361 {
362 WCHAR buffer_in[INTERNET_MAX_URL_LENGTH];
363 WCHAR buffer_out[INTERNET_MAX_URL_LENGTH];
364 LPCWSTR ptr = url;
365 HRESULT hr;
366 DWORD needed;
367 DWORD len;
368 DWORD res = 0;
369
370
371 TRACE("(%s, %p, %p, %p) len: %d, unknown: 0x%x\n", debugstr_w(url), out, plen, unknown,
372 plen ? *plen : 0, unknown ? *unknown : 0);
373
374 if (!PathIsURLW(ptr)) {
375 len = sizeof(buffer_in) / sizeof(buffer_in[0]);
376 buffer_in[0] = 0;
377 hr = UrlApplySchemeW(ptr, buffer_in, &len, URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT);
378 TRACE("got 0x%x with %s\n", hr, debugstr_w(buffer_in));
379 if (hr == S_OK) {
380 /* we parsed the url to buffer_in */
381 ptr = buffer_in;
382 }
383 else
384 {
385 FIXME("call search hook for %s\n", debugstr_w(ptr));
386 }
387 }
388
389 len = sizeof(buffer_out) / sizeof(buffer_out[0]);
390 buffer_out[0] = '\0';
391 hr = UrlCanonicalizeW(ptr, buffer_out, &len, URL_ESCAPE_SPACES_ONLY);
392 needed = lstrlenW(buffer_out)+1;
393 TRACE("got 0x%x with %s (need %d)\n", hr, debugstr_w(buffer_out), needed);
394
395 if (*plen >= needed) {
396 if (out != NULL) {
397 lstrcpyW(out, buffer_out);
398 res++;
399 }
400 needed--;
401 }
402
403 *plen = needed;
404
405 TRACE("=> %d\n", res);
406 return res;
407 }
408
409 /******************************************************************
410 * ParseURLFromOutsideSourceA (SHDOCVW.169)
411 *
412 * See ParseURLFromOutsideSourceW
413 */
414 DWORD WINAPI ParseURLFromOutsideSourceA(LPCSTR url, LPSTR out, LPDWORD plen, LPDWORD unknown)
415 {
416 WCHAR buffer[INTERNET_MAX_URL_LENGTH];
417 LPWSTR urlW = NULL;
418 DWORD needed;
419 DWORD res;
420 DWORD len;
421
422 TRACE("(%s, %p, %p, %p) len: %d, unknown: 0x%x\n", debugstr_a(url), out, plen, unknown,
423 plen ? *plen : 0, unknown ? *unknown : 0);
424
425 if (url) {
426 len = MultiByteToWideChar(CP_ACP, 0, url, -1, NULL, 0);
427 urlW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
428 MultiByteToWideChar(CP_ACP, 0, url, -1, urlW, len);
429 }
430
431 len = sizeof(buffer) / sizeof(buffer[0]);
432 ParseURLFromOutsideSourceW(urlW, buffer, &len, unknown);
433 HeapFree(GetProcessHeap(), 0, urlW);
434
435 needed = WideCharToMultiByte(CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL);
436
437 res = 0;
438 if (*plen >= needed) {
439 if (out != NULL) {
440 WideCharToMultiByte(CP_ACP, 0, buffer, -1, out, *plen, NULL, NULL);
441 res = needed;
442 }
443 needed--;
444 }
445
446 *plen = needed;
447
448 TRACE("=> %d\n", res);
449 return res;
450 }
451
452 /******************************************************************
453 * IEParseDisplayNameWithBCW (SHDOCVW.218)
454 */
455 HRESULT WINAPI IEParseDisplayNameWithBCW(DWORD codepage, LPCWSTR lpszDisplayName, LPBC pbc, LPITEMIDLIST *ppidl)
456 {
457 /* Guessing at parameter 3 based on IShellFolder's ParseDisplayName */
458 FIXME("stub: 0x%x %s %p %p\n",codepage,debugstr_w(lpszDisplayName),pbc,ppidl);
459 return E_FAIL;
460 }
461
462 /******************************************************************
463 * SHRestricted2W (SHDOCVW.159)
464 */
465 DWORD WINAPI SHRestricted2W(DWORD res, LPCWSTR url, DWORD reserved)
466 {
467 FIXME("(%d %s %d) stub\n", res, debugstr_w(url), reserved);
468 return 0;
469 }
470
471 /******************************************************************
472 * SHRestricted2A (SHDOCVW.158)
473 *
474 * See SHRestricted2W
475 */
476 DWORD WINAPI SHRestricted2A(DWORD restriction, LPCSTR url, DWORD reserved)
477 {
478 LPWSTR urlW = NULL;
479 DWORD res;
480
481 TRACE("(%d, %s, %d)\n", restriction, debugstr_a(url), reserved);
482 if (url) {
483 DWORD len = MultiByteToWideChar(CP_ACP, 0, url, -1, NULL, 0);
484 urlW = heap_alloc(len * sizeof(WCHAR));
485 MultiByteToWideChar(CP_ACP, 0, url, -1, urlW, len);
486 }
487 res = SHRestricted2W(restriction, urlW, reserved);
488 heap_free(urlW);
489 return res;
490 }
491
492 /******************************************************************
493 * ImportPrivacySettings (SHDOCVW.@)
494 *
495 * Import global and/or per site privacy preferences from an xml file
496 *
497 * PARAMS
498 * filename [I] XML file to use
499 * pGlobalPrefs [IO] PTR to a usage flag for the global privacy preferences
500 * pPerSitePrefs [IO] PTR to a usage flag for the per site privacy preferences
501 *
502 * RETURNS
503 * Success: TRUE (the privacy preferences where updated)
504 * Failure: FALSE (the privacy preferences are unchanged)
505 *
506 * NOTES
507 * Set the flag to TRUE, when the related privacy preferences in the xml file
508 * should be used (parsed and overwrite the current settings).
509 * On return, the flag is TRUE, when the related privacy settings where used
510 *
511 */
512 BOOL WINAPI ImportPrivacySettings(LPCWSTR filename, BOOL *pGlobalPrefs, BOOL * pPerSitePrefs)
513 {
514 FIXME("(%s, %p->%d, %p->%d): stub\n", debugstr_w(filename),
515 pGlobalPrefs, pGlobalPrefs ? *pGlobalPrefs : 0,
516 pPerSitePrefs, pPerSitePrefs ? *pPerSitePrefs : 0);
517
518 if (pGlobalPrefs) *pGlobalPrefs = FALSE;
519 if (pPerSitePrefs) *pPerSitePrefs = FALSE;
520
521 return TRUE;
522 }
523
524 /******************************************************************
525 * ResetProfileSharing (SHDOCVW.164)
526 */
527 HRESULT WINAPI ResetProfileSharing(HWND hwnd)
528 {
529 FIXME("(%p) stub\n", hwnd);
530 return E_NOTIMPL;
531 }
532
533 /******************************************************************
534 * InstallReg_RunDLL (SHDOCVW.@)
535 */
536 void WINAPI InstallReg_RunDLL(HWND hwnd, HINSTANCE handle, LPCSTR cmdline, INT show)
537 {
538 FIXME("(%p %p %s %x)\n", hwnd, handle, debugstr_a(cmdline), show);
539 }
540
541 /******************************************************************
542 * DoFileDownload (SHDOCVW.@)
543 */
544 BOOL WINAPI DoFileDownload(LPWSTR filename)
545 {
546 FIXME("(%s) stub\n", debugstr_w(filename));
547 return FALSE;
548 }