kernel32/tests: Change to a win_skip() because we don't want to skip the GetConsoleCu...
[wine/multimedia.git] / dlls / shdocvw / factory.c
blob9111300226f785c523bccd85f5d3cac2903de703
1 /*
2 * Implementation of class factory for IE Web Browser
4 * Copyright 2001 John R. Sheets (for CodeWeavers)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <string.h>
22 #include <stdio.h>
24 #include "shdocvw.h"
25 #include "winreg.h"
26 #include "advpub.h"
27 #include "isguids.h"
29 #include "winver.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
35 /**********************************************************************
36 * Implement the WebBrowser class factory
38 * (Based on implementation in ddraw/main.c)
41 #define FACTORY(x) ((IClassFactory*) &(x)->lpClassFactoryVtbl)
43 typedef struct
45 /* IUnknown fields */
46 const IClassFactoryVtbl *lpClassFactoryVtbl;
47 HRESULT (*cf)(LPUNKNOWN, REFIID, LPVOID *);
48 LONG ref;
49 } IClassFactoryImpl;
52 /**********************************************************************
53 * WBCF_QueryInterface (IUnknown)
55 static HRESULT WINAPI WBCF_QueryInterface(LPCLASSFACTORY iface,
56 REFIID riid, LPVOID *ppobj)
58 TRACE("(%s %p)\n", debugstr_guid(riid), ppobj);
60 if (!ppobj)
61 return E_POINTER;
63 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
64 *ppobj = iface;
65 IClassFactory_AddRef(iface);
66 return S_OK;
69 WARN("Not supported interface %s\n", debugstr_guid(riid));
71 *ppobj = NULL;
72 return E_NOINTERFACE;
75 /************************************************************************
76 * WBCF_AddRef (IUnknown)
78 static ULONG WINAPI WBCF_AddRef(LPCLASSFACTORY iface)
80 SHDOCVW_LockModule();
82 return 2; /* non-heap based object */
85 /************************************************************************
86 * WBCF_Release (IUnknown)
88 static ULONG WINAPI WBCF_Release(LPCLASSFACTORY iface)
90 SHDOCVW_UnlockModule();
92 return 1; /* non-heap based object */
95 /************************************************************************
96 * WBCF_CreateInstance (IClassFactory)
98 static HRESULT WINAPI WBCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
99 REFIID riid, LPVOID *ppobj)
101 IClassFactoryImpl *This = (IClassFactoryImpl *) iface;
102 return This->cf(pOuter, riid, ppobj);
105 /************************************************************************
106 * WBCF_LockServer (IClassFactory)
108 static HRESULT WINAPI WBCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
110 TRACE("(%d)\n", dolock);
112 if (dolock)
113 SHDOCVW_LockModule();
114 else
115 SHDOCVW_UnlockModule();
117 return S_OK;
120 static const IClassFactoryVtbl WBCF_Vtbl =
122 WBCF_QueryInterface,
123 WBCF_AddRef,
124 WBCF_Release,
125 WBCF_CreateInstance,
126 WBCF_LockServer
129 /*************************************************************************
130 * DllGetClassObject (SHDOCVW.@)
132 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
134 static IClassFactoryImpl WB1ClassFactory = {&WBCF_Vtbl, WebBrowserV1_Create};
135 static IClassFactoryImpl WB2ClassFactory = {&WBCF_Vtbl, WebBrowserV2_Create};
136 static IClassFactoryImpl CUHClassFactory = {&WBCF_Vtbl, CUrlHistory_Create};
137 static IClassFactoryImpl ISCClassFactory = {&WBCF_Vtbl, InternetShortcut_Create};
139 TRACE("\n");
141 if(IsEqualGUID(&CLSID_WebBrowser, rclsid))
142 return IClassFactory_QueryInterface(FACTORY(&WB2ClassFactory), riid, ppv);
144 if(IsEqualGUID(&CLSID_WebBrowser_V1, rclsid))
145 return IClassFactory_QueryInterface(FACTORY(&WB1ClassFactory), riid, ppv);
147 if(IsEqualGUID(&CLSID_CUrlHistory, rclsid))
148 return IClassFactory_QueryInterface(FACTORY(&CUHClassFactory), riid, ppv);
150 if(IsEqualGUID(&CLSID_InternetShortcut, rclsid))
151 return IClassFactory_QueryInterface(FACTORY(&ISCClassFactory), riid, ppv);
153 /* As a last resort, figure if the CLSID belongs to a 'Shell Instance Object' */
154 return SHDOCVW_GetShellInstanceObjectClassObject(rclsid, riid, ppv);
157 HRESULT register_class_object(BOOL do_reg)
159 HRESULT hres;
161 static DWORD cookie;
162 static IClassFactoryImpl IEClassFactory = {&WBCF_Vtbl, InternetExplorer_Create};
164 if(do_reg) {
165 hres = CoRegisterClassObject(&CLSID_InternetExplorer, (IUnknown*)FACTORY(&IEClassFactory),
166 CLSCTX_SERVER, REGCLS_MULTIPLEUSE|REGCLS_SUSPENDED, &cookie);
167 if (FAILED(hres)) {
168 ERR("failed to register object %08x\n", hres);
169 return hres;
172 hres = CoResumeClassObjects();
173 if(SUCCEEDED(hres))
174 return hres;
176 ERR("failed to resume object %08x\n", hres);
179 return CoRevokeClassObject(cookie);
182 static HRESULT reg_install(LPCSTR section, STRTABLEA *strtable)
184 HRESULT (WINAPI *pRegInstall)(HMODULE hm, LPCSTR pszSection, const STRTABLEA* pstTable);
185 HMODULE hadvpack;
186 HRESULT hres;
188 static const WCHAR advpackW[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
190 hadvpack = LoadLibraryW(advpackW);
191 pRegInstall = (void *)GetProcAddress(hadvpack, "RegInstall");
193 hres = pRegInstall(shdocvw_hinstance, section, strtable);
195 FreeLibrary(hadvpack);
196 return hres;
199 static const GUID CLSID_MicrosoftBrowserArchitecture =
200 {0xa5e46e3a, 0x8849, 0x11d1, {0x9d, 0x8c, 0x00, 0xc0, 0x4f, 0xc9, 0x9d, 0x61}};
201 static const GUID CLSID_MruLongList =
202 {0x53bd6b4e, 0x3780, 0x4693, {0xaf, 0xc3, 0x71, 0x61, 0xc2, 0xf3, 0xee, 0x9c}};
204 #define INF_SET_CLSID(clsid) \
205 do \
207 static CHAR name[] = "CLSID_" #clsid; \
209 pse[i].pszName = name; \
210 clsids[i++] = &CLSID_ ## clsid; \
211 } while (0)
213 static HRESULT register_server(BOOL doregister)
215 STRTABLEA strtable;
216 STRENTRYA pse[14];
217 static CLSID const *clsids[14];
218 unsigned int i = 0;
219 HRESULT hres;
221 INF_SET_CLSID(CUrlHistory);
222 INF_SET_CLSID(Internet);
223 INF_SET_CLSID(InternetExplorer);
224 INF_SET_CLSID(InternetShortcut);
225 INF_SET_CLSID(MicrosoftBrowserArchitecture);
226 INF_SET_CLSID(MruLongList);
227 INF_SET_CLSID(SearchAssistantOC);
228 INF_SET_CLSID(ShellNameSpace);
229 INF_SET_CLSID(ShellSearchAssistantOC);
230 INF_SET_CLSID(ShellShellNameSpace);
231 INF_SET_CLSID(ShellUIHelper);
232 INF_SET_CLSID(ShellWindows);
233 INF_SET_CLSID(WebBrowser);
234 INF_SET_CLSID(WebBrowser_V1);
236 for(i = 0; i < sizeof(pse)/sizeof(pse[0]); i++) {
237 pse[i].pszValue = HeapAlloc(GetProcessHeap(), 0, 39);
238 sprintf(pse[i].pszValue, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
239 clsids[i]->Data1, clsids[i]->Data2, clsids[i]->Data3, clsids[i]->Data4[0],
240 clsids[i]->Data4[1], clsids[i]->Data4[2], clsids[i]->Data4[3], clsids[i]->Data4[4],
241 clsids[i]->Data4[5], clsids[i]->Data4[6], clsids[i]->Data4[7]);
244 strtable.cEntries = sizeof(pse)/sizeof(pse[0]);
245 strtable.pse = pse;
247 hres = reg_install(doregister ? "RegisterDll" : "UnregisterDll", &strtable);
249 for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++)
250 HeapFree(GetProcessHeap(), 0, pse[i].pszValue);
252 return hres;
255 #undef INF_SET_CLSID
257 /***********************************************************************
258 * DllRegisterServer (shdocvw.@)
260 HRESULT WINAPI DllRegisterServer(void)
262 ITypeLib *typelib;
263 HRESULT hres;
265 static const WCHAR shdocvwW[] = {'s','h','d','o','c','v','w','.','d','l','l',0};
267 hres = register_server(TRUE);
268 if(FAILED(hres))
269 return hres;
271 hres = LoadTypeLibEx(shdocvwW, REGKIND_REGISTER, &typelib);
272 if(FAILED(hres)) {
273 ERR("Could not load typelib: %08x\n", hres);
274 return hres;
277 ITypeLib_Release(typelib);
279 return hres;
282 /***********************************************************************
283 * DllUnregisterServer (shdocvw.@)
285 HRESULT WINAPI DllUnregisterServer(void)
287 HRESULT hres;
289 hres = register_server(FALSE);
290 if(FAILED(hres))
291 return hres;
293 return UnRegisterTypeLib(&LIBID_SHDocVw, 1, 1, LOCALE_SYSTEM_DEFAULT, SYS_WIN32);
296 static BOOL check_native_ie(void)
298 static const WCHAR cszPath[] = {'b','r','o','w','s','e','u','i','.','d','l','l',0};
299 DWORD handle,size;
300 BOOL ret = TRUE;
302 size = GetFileVersionInfoSizeW(cszPath,&handle);
303 if (size)
305 LPVOID buf;
306 LPWSTR lpFileDescription;
307 UINT dwBytes;
308 static const WCHAR cszFD[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\','0','4','0','9','0','4','e','4','\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n',0};
309 static const WCHAR cszWine[] = {'W','i','n','e',0};
311 buf = HeapAlloc(GetProcessHeap(),0,size);
312 GetFileVersionInfoW(cszPath,0,size,buf);
314 if (VerQueryValueW(buf, cszFD, (LPVOID*)&lpFileDescription, &dwBytes) &&
315 strstrW(lpFileDescription,cszWine))
316 ret = FALSE;
318 HeapFree(GetProcessHeap(), 0, buf);
321 return ret;
324 DWORD register_iexplore(BOOL doregister)
326 HRESULT hres;
327 if (check_native_ie())
329 TRACE("Native IE detected, not doing registration\n");
330 return S_OK;
332 hres = reg_install(doregister ? "RegisterIE" : "UnregisterIE", NULL);
333 return FAILED(hres);