Add AppDefaults app selection to control panel
[wine/gsoc-2012-control.git] / dlls / shdocvw / shdocvw_main.c
blobdb9034c7132eeb9a17cd2160f4f067bff5196ef7
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 "config.h"
25 #include <stdarg.h>
26 #include <stdio.h>
28 #include "wine/unicode.h"
29 #include "wine/debug.h"
31 #include "shdocvw.h"
33 #include "winreg.h"
34 #include "shlwapi.h"
35 #include "wininet.h"
36 #include "isguids.h"
38 #include "initguid.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
42 LONG SHDOCVW_refCount = 0;
44 HINSTANCE shdocvw_hinstance = 0;
45 static HMODULE SHDOCVW_hshell32 = 0;
46 static HINSTANCE ieframe_instance;
48 static HINSTANCE get_ieframe_instance(void)
50 static const WCHAR ieframe_dllW[] = {'i','e','f','r','a','m','e','.','d','l','l',0};
52 if(!ieframe_instance)
53 ieframe_instance = LoadLibraryW(ieframe_dllW);
55 return ieframe_instance;
58 static HRESULT get_ieframe_object(REFCLSID rclsid, REFIID riid, void **ppv)
60 HINSTANCE ieframe_instance;
62 static HRESULT (WINAPI *ieframe_DllGetClassObject)(REFCLSID,REFIID,void**);
64 if(!ieframe_DllGetClassObject) {
65 ieframe_instance = get_ieframe_instance();
66 if(!ieframe_instance)
67 return CLASS_E_CLASSNOTAVAILABLE;
69 ieframe_DllGetClassObject = (void*)GetProcAddress(ieframe_instance, "DllGetClassObject");
70 if(!ieframe_DllGetClassObject)
71 return CLASS_E_CLASSNOTAVAILABLE;
74 return ieframe_DllGetClassObject(rclsid, riid, ppv);
77 /*************************************************************************
78 * DllGetClassObject (SHDOCVW.@)
80 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
82 TRACE("\n");
84 if(IsEqualGUID(&CLSID_WebBrowser, rclsid)
85 || IsEqualGUID(&CLSID_WebBrowser_V1, rclsid)
86 || IsEqualGUID(&CLSID_InternetShortcut, rclsid)
87 || IsEqualGUID(&CLSID_CUrlHistory, rclsid)
88 || IsEqualGUID(&CLSID_TaskbarList, rclsid))
89 return get_ieframe_object(rclsid, riid, ppv);
91 /* As a last resort, figure if the CLSID belongs to a 'Shell Instance Object' */
92 return SHDOCVW_GetShellInstanceObjectClassObject(rclsid, riid, ppv);
95 /***********************************************************************
96 * DllRegisterServer (shdocvw.@)
98 HRESULT WINAPI DllRegisterServer(void)
100 TRACE("\n");
101 return S_OK;
104 /***********************************************************************
105 * DllUnregisterServer (shdocvw.@)
107 HRESULT WINAPI DllUnregisterServer(void)
109 TRACE("\n");
110 return S_OK;
113 /******************************************************************
114 * IEWinMain (SHDOCVW.101)
116 * Only returns on error.
118 DWORD WINAPI IEWinMain(LPSTR szCommandLine, int nShowWindow)
120 DWORD (WINAPI *pIEWinMain)(const WCHAR*,int);
121 WCHAR *cmdline;
122 DWORD ret, len;
124 TRACE("%s %d\n", debugstr_a(szCommandLine), nShowWindow);
126 pIEWinMain = (void*)GetProcAddress(get_ieframe_instance(), MAKEINTRESOURCEA(101));
127 if(!pIEWinMain)
128 ExitProcess(1);
130 len = MultiByteToWideChar(CP_ACP, 0, szCommandLine, -1, NULL, 0);
131 cmdline = heap_alloc(len*sizeof(WCHAR));
132 if(!cmdline)
133 ExitProcess(1);
134 MultiByteToWideChar(CP_ACP, 0, szCommandLine, -1, cmdline, len);
136 ret = pIEWinMain(cmdline, nShowWindow);
138 heap_free(cmdline);
139 return ret;
142 /*************************************************************************
143 * SHDOCVW DllMain
145 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
147 TRACE("%p 0x%x %p\n", hinst, fdwReason, fImpLoad);
148 switch (fdwReason)
150 case DLL_PROCESS_ATTACH:
151 shdocvw_hinstance = hinst;
152 break;
153 case DLL_PROCESS_DETACH:
154 if (SHDOCVW_hshell32) FreeLibrary(SHDOCVW_hshell32);
155 if(ieframe_instance)
156 FreeLibrary(ieframe_instance);
157 break;
159 return TRUE;
162 /*************************************************************************
163 * DllCanUnloadNow (SHDOCVW.@)
165 HRESULT WINAPI DllCanUnloadNow(void)
167 return SHDOCVW_refCount ? S_FALSE : S_OK;
170 /***********************************************************************
171 * DllGetVersion (SHDOCVW.@)
173 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
175 if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
177 /* this is what IE6 on Windows 98 reports */
178 info->dwMajorVersion = 6;
179 info->dwMinorVersion = 0;
180 info->dwBuildNumber = 2600;
181 info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
183 return NOERROR;
186 /*************************************************************************
187 * DllInstall (SHDOCVW.@)
189 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
191 FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
193 return S_OK;
196 /*************************************************************************
197 * SHDOCVW_LoadShell32
199 * makes sure the handle to shell32 is valid
201 static BOOL SHDOCVW_LoadShell32(void)
203 if (SHDOCVW_hshell32)
204 return TRUE;
205 return ((SHDOCVW_hshell32 = LoadLibraryA("shell32.dll")) != NULL);
208 /***********************************************************************
209 * @ (SHDOCVW.110)
211 * Called by Win98 explorer.exe main binary, definitely has 0
212 * parameters.
214 DWORD WINAPI WinList_Init(void)
216 FIXME("(), stub!\n");
217 return 0x0deadfeed;
220 /***********************************************************************
221 * @ (SHDOCVW.118)
223 * Called by Win98 explorer.exe main binary, definitely has only one
224 * parameter.
226 static BOOL (WINAPI *pShellDDEInit)(BOOL start) = NULL;
228 BOOL WINAPI ShellDDEInit(BOOL start)
230 TRACE("(%d)\n", start);
232 if (!pShellDDEInit)
234 if (!SHDOCVW_LoadShell32())
235 return FALSE;
236 pShellDDEInit = (void *)GetProcAddress(SHDOCVW_hshell32, (LPCSTR)188);
239 if (pShellDDEInit)
240 return pShellDDEInit(start);
241 else
242 return FALSE;
245 /***********************************************************************
246 * @ (SHDOCVW.125)
248 * Called by Win98 explorer.exe main binary, definitely has 0
249 * parameters.
251 DWORD WINAPI RunInstallUninstallStubs(void)
253 FIXME("(), stub!\n");
254 return 0x0deadbee;
257 /***********************************************************************
258 * @ (SHDOCVW.130)
260 * Called by Emerge Desktop (alternative Windows Shell).
262 DWORD WINAPI RunInstallUninstallStubs2(void)
264 FIXME("(), stub!\n");
265 return 0x0deadbee;
268 /***********************************************************************
269 * SetQueryNetSessionCount (SHDOCVW.@)
271 DWORD WINAPI SetQueryNetSessionCount(DWORD arg)
273 FIXME("(%u), stub!\n", arg);
274 return 0;
277 /**********************************************************************
278 * Some forwards (by ordinal) to SHLWAPI
281 static void* fetch_shlwapi_ordinal(UINT_PTR ord)
283 static const WCHAR shlwapiW[] = {'s','h','l','w','a','p','i','.','d','l','l','\0'};
284 static HANDLE h;
286 if (!h && !(h = GetModuleHandleW(shlwapiW))) return NULL;
287 return (void*)GetProcAddress(h, (const char*)ord);
290 /******************************************************************
291 * WhichPlatformFORWARD (SHDOCVW.@)
293 DWORD WINAPI WhichPlatformFORWARD(void)
295 static DWORD (WINAPI *p)(void);
297 if (p || (p = fetch_shlwapi_ordinal(276))) return p();
298 return 1; /* not integrated, see shlwapi.WhichPlatform */
301 /******************************************************************
302 * StopWatchModeFORWARD (SHDOCVW.@)
304 void WINAPI StopWatchModeFORWARD(void)
306 static void (WINAPI *p)(void);
308 if (p || (p = fetch_shlwapi_ordinal(241))) p();
311 /******************************************************************
312 * StopWatchFlushFORWARD (SHDOCVW.@)
314 void WINAPI StopWatchFlushFORWARD(void)
316 static void (WINAPI *p)(void);
318 if (p || (p = fetch_shlwapi_ordinal(242))) p();
321 /******************************************************************
322 * StopWatchWFORWARD (SHDOCVW.@)
324 DWORD WINAPI StopWatchWFORWARD(DWORD dwClass, LPCWSTR lpszStr, DWORD dwUnknown,
325 DWORD dwMode, DWORD dwTimeStamp)
327 static DWORD (WINAPI *p)(DWORD, LPCWSTR, DWORD, DWORD, DWORD);
329 if (p || (p = fetch_shlwapi_ordinal(243)))
330 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
331 return ERROR_CALL_NOT_IMPLEMENTED;
334 /******************************************************************
335 * StopWatchAFORWARD (SHDOCVW.@)
337 DWORD WINAPI StopWatchAFORWARD(DWORD dwClass, LPCSTR lpszStr, DWORD dwUnknown,
338 DWORD dwMode, DWORD dwTimeStamp)
340 static DWORD (WINAPI *p)(DWORD, LPCSTR, DWORD, DWORD, DWORD);
342 if (p || (p = fetch_shlwapi_ordinal(244)))
343 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
344 return ERROR_CALL_NOT_IMPLEMENTED;
347 /******************************************************************
348 * URLSubRegQueryA (SHDOCVW.151)
350 HRESULT WINAPI URLSubRegQueryA(LPCSTR regpath, LPCSTR name, DWORD type,
351 LPSTR out, DWORD outlen, DWORD unknown)
353 CHAR buffer[INTERNET_MAX_URL_LENGTH];
354 DWORD len;
355 LONG res;
357 TRACE("(%s, %s, %d, %p, %d, %d)\n", debugstr_a(regpath), debugstr_a(name),
358 type, out, outlen, unknown);
360 if (!out) return S_OK;
362 len = sizeof(buffer);
363 res = SHRegGetUSValueA(regpath, name, NULL, buffer, &len, FALSE, NULL, 0);
364 if (!res) {
365 lstrcpynA(out, buffer, outlen);
366 return S_OK;
369 return E_FAIL;
372 /******************************************************************
373 * ParseURLFromOutsideSourceW (SHDOCVW.170)
375 DWORD WINAPI ParseURLFromOutsideSourceW(LPCWSTR url, LPWSTR out, LPDWORD plen, LPDWORD unknown)
377 WCHAR buffer_in[INTERNET_MAX_URL_LENGTH];
378 WCHAR buffer_out[INTERNET_MAX_URL_LENGTH];
379 LPCWSTR ptr = url;
380 HRESULT hr;
381 DWORD needed;
382 DWORD len;
383 DWORD res = 0;
386 TRACE("(%s, %p, %p, %p) len: %d, unknown: 0x%x\n", debugstr_w(url), out, plen, unknown,
387 plen ? *plen : 0, unknown ? *unknown : 0);
389 if (!PathIsURLW(ptr)) {
390 len = sizeof(buffer_in) / sizeof(buffer_in[0]);
391 buffer_in[0] = 0;
392 hr = UrlApplySchemeW(ptr, buffer_in, &len, URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT);
393 TRACE("got 0x%x with %s\n", hr, debugstr_w(buffer_in));
394 if (hr == S_OK) {
395 /* we parsed the url to buffer_in */
396 ptr = buffer_in;
398 else
400 FIXME("call search hook for %s\n", debugstr_w(ptr));
404 len = sizeof(buffer_out) / sizeof(buffer_out[0]);
405 buffer_out[0] = '\0';
406 hr = UrlCanonicalizeW(ptr, buffer_out, &len, URL_ESCAPE_SPACES_ONLY);
407 needed = lstrlenW(buffer_out)+1;
408 TRACE("got 0x%x with %s (need %d)\n", hr, debugstr_w(buffer_out), needed);
410 if (*plen >= needed) {
411 if (out != NULL) {
412 lstrcpyW(out, buffer_out);
413 res++;
415 needed--;
418 *plen = needed;
420 TRACE("=> %d\n", res);
421 return res;
424 /******************************************************************
425 * ParseURLFromOutsideSourceA (SHDOCVW.169)
427 * See ParseURLFromOutsideSourceW
429 DWORD WINAPI ParseURLFromOutsideSourceA(LPCSTR url, LPSTR out, LPDWORD plen, LPDWORD unknown)
431 WCHAR buffer[INTERNET_MAX_URL_LENGTH];
432 LPWSTR urlW = NULL;
433 DWORD needed;
434 DWORD res;
435 DWORD len;
437 TRACE("(%s, %p, %p, %p) len: %d, unknown: 0x%x\n", debugstr_a(url), out, plen, unknown,
438 plen ? *plen : 0, unknown ? *unknown : 0);
440 if (url) {
441 len = MultiByteToWideChar(CP_ACP, 0, url, -1, NULL, 0);
442 urlW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
443 MultiByteToWideChar(CP_ACP, 0, url, -1, urlW, len);
446 len = sizeof(buffer) / sizeof(buffer[0]);
447 res = ParseURLFromOutsideSourceW(urlW, buffer, &len, unknown);
448 HeapFree(GetProcessHeap(), 0, urlW);
450 needed = WideCharToMultiByte(CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL);
452 res = 0;
453 if (*plen >= needed) {
454 if (out != NULL) {
455 WideCharToMultiByte(CP_ACP, 0, buffer, -1, out, *plen, NULL, NULL);
456 res = needed;
458 needed--;
461 *plen = needed;
463 TRACE("=> %d\n", res);
464 return res;
467 /******************************************************************
468 * IEParseDisplayNameWithBCW (SHDOCVW.218)
470 HRESULT WINAPI IEParseDisplayNameWithBCW(DWORD codepage, LPCWSTR lpszDisplayName, LPBC pbc, LPITEMIDLIST *ppidl)
472 /* Guessing at parameter 3 based on IShellFolder's ParseDisplayName */
473 FIXME("stub: 0x%x %s %p %p\n",codepage,debugstr_w(lpszDisplayName),pbc,ppidl);
474 return E_FAIL;
477 /******************************************************************
478 * SHRestricted2W (SHDOCVW.159)
480 DWORD WINAPI SHRestricted2W(DWORD res, LPCWSTR url, DWORD reserved)
482 FIXME("(%d %s %d) stub\n", res, debugstr_w(url), reserved);
483 return 0;
486 /******************************************************************
487 * SHRestricted2A (SHDOCVW.158)
489 * See SHRestricted2W
491 DWORD WINAPI SHRestricted2A(DWORD restriction, LPCSTR url, DWORD reserved)
493 LPWSTR urlW = NULL;
494 DWORD res;
496 TRACE("(%d, %s, %d)\n", restriction, debugstr_a(url), reserved);
497 if (url) {
498 DWORD len = MultiByteToWideChar(CP_ACP, 0, url, -1, NULL, 0);
499 urlW = heap_alloc(len * sizeof(WCHAR));
500 MultiByteToWideChar(CP_ACP, 0, url, -1, urlW, len);
502 res = SHRestricted2W(restriction, urlW, reserved);
503 heap_free(urlW);
504 return res;
507 /******************************************************************
508 * ImportPrivacySettings (SHDOCVW.@)
510 * Import global and/or per site privacy preferences from an xml file
512 * PARAMS
513 * filename [I] XML file to use
514 * pGlobalPrefs [IO] PTR to a usage flag for the global privacy preferences
515 * pPerSitePrefs [IO] PTR to a usage flag for the per site privacy preferences
517 * RETURNS
518 * Success: TRUE (the privacy preferences where updated)
519 * Failure: FALSE (the privacy preferences are unchanged)
521 * NOTES
522 * Set the flag to TRUE, when the related privacy preferences in the xml file
523 * should be used (parsed and overwrite the current settings).
524 * On return, the flag is TRUE, when the related privacy settings where used
527 BOOL WINAPI ImportPrivacySettings(LPCWSTR filename, BOOL *pGlobalPrefs, BOOL * pPerSitePrefs)
529 FIXME("(%s, %p->%d, %p->%d): stub\n", debugstr_w(filename),
530 pGlobalPrefs, pGlobalPrefs ? *pGlobalPrefs : 0,
531 pPerSitePrefs, pPerSitePrefs ? *pPerSitePrefs : 0);
533 if (pGlobalPrefs) *pGlobalPrefs = FALSE;
534 if (pPerSitePrefs) *pPerSitePrefs = FALSE;
536 return TRUE;