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
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw
);
36 /**********************************************************************
37 * Implement the WebBrowser class factory
43 IClassFactory IClassFactory_iface
;
44 HRESULT (*cf
)(LPUNKNOWN
, REFIID
, LPVOID
*);
48 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
50 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
54 /**********************************************************************
55 * WBCF_QueryInterface (IUnknown)
57 static HRESULT WINAPI
WBCF_QueryInterface(LPCLASSFACTORY iface
,
58 REFIID riid
, LPVOID
*ppobj
)
60 TRACE("(%s %p)\n", debugstr_guid(riid
), ppobj
);
65 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IClassFactory
, riid
)) {
67 IClassFactory_AddRef(iface
);
71 WARN("Not supported interface %s\n", debugstr_guid(riid
));
77 /************************************************************************
78 * WBCF_AddRef (IUnknown)
80 static ULONG WINAPI
WBCF_AddRef(LPCLASSFACTORY iface
)
84 return 2; /* non-heap based object */
87 /************************************************************************
88 * WBCF_Release (IUnknown)
90 static ULONG WINAPI
WBCF_Release(LPCLASSFACTORY iface
)
92 SHDOCVW_UnlockModule();
94 return 1; /* non-heap based object */
97 /************************************************************************
98 * WBCF_CreateInstance (IClassFactory)
100 static HRESULT WINAPI
WBCF_CreateInstance(LPCLASSFACTORY iface
, LPUNKNOWN pOuter
,
101 REFIID riid
, LPVOID
*ppobj
)
103 IClassFactoryImpl
*This
= (IClassFactoryImpl
*) iface
;
104 return This
->cf(pOuter
, riid
, ppobj
);
107 /************************************************************************
108 * WBCF_LockServer (IClassFactory)
110 static HRESULT WINAPI
WBCF_LockServer(LPCLASSFACTORY iface
, BOOL dolock
)
112 TRACE("(%d)\n", dolock
);
115 SHDOCVW_LockModule();
117 SHDOCVW_UnlockModule();
122 static const IClassFactoryVtbl WBCF_Vtbl
=
131 /*************************************************************************
132 * DllGetClassObject (SHDOCVW.@)
134 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, void **ppv
)
136 static IClassFactoryImpl WB1ClassFactory
= {{&WBCF_Vtbl
}, WebBrowserV1_Create
};
137 static IClassFactoryImpl WB2ClassFactory
= {{&WBCF_Vtbl
}, WebBrowserV2_Create
};
138 static IClassFactoryImpl CUHClassFactory
= {{&WBCF_Vtbl
}, CUrlHistory_Create
};
139 static IClassFactoryImpl ISCClassFactory
= {{&WBCF_Vtbl
}, InternetShortcut_Create
};
140 static IClassFactoryImpl TBLClassFactory
= {{&WBCF_Vtbl
}, TaskbarList_Create
};
144 if(IsEqualGUID(&CLSID_WebBrowser
, rclsid
))
145 return IClassFactory_QueryInterface(&WB2ClassFactory
.IClassFactory_iface
, riid
, ppv
);
147 if(IsEqualGUID(&CLSID_WebBrowser_V1
, rclsid
))
148 return IClassFactory_QueryInterface(&WB1ClassFactory
.IClassFactory_iface
, riid
, ppv
);
150 if(IsEqualGUID(&CLSID_CUrlHistory
, rclsid
))
151 return IClassFactory_QueryInterface(&CUHClassFactory
.IClassFactory_iface
, riid
, ppv
);
153 if(IsEqualGUID(&CLSID_InternetShortcut
, rclsid
))
154 return IClassFactory_QueryInterface(&ISCClassFactory
.IClassFactory_iface
, riid
, ppv
);
156 if(IsEqualGUID(&CLSID_TaskbarList
, rclsid
))
157 return IClassFactory_QueryInterface(&TBLClassFactory
.IClassFactory_iface
, riid
, ppv
);
159 /* As a last resort, figure if the CLSID belongs to a 'Shell Instance Object' */
160 return SHDOCVW_GetShellInstanceObjectClassObject(rclsid
, riid
, ppv
);
163 HRESULT
register_class_object(BOOL do_reg
)
168 static IClassFactoryImpl IEClassFactory
= {{&WBCF_Vtbl
}, InternetExplorer_Create
};
171 hres
= CoRegisterClassObject(&CLSID_InternetExplorer
,
172 (IUnknown
*)&IEClassFactory
.IClassFactory_iface
, CLSCTX_SERVER
,
173 REGCLS_MULTIPLEUSE
|REGCLS_SUSPENDED
, &cookie
);
175 ERR("failed to register object %08x\n", hres
);
179 hres
= CoResumeClassObjects();
183 ERR("failed to resume object %08x\n", hres
);
186 return CoRevokeClassObject(cookie
);
189 static HRESULT
reg_install(LPCSTR section
, STRTABLEA
*strtable
)
191 HRESULT (WINAPI
*pRegInstall
)(HMODULE hm
, LPCSTR pszSection
, const STRTABLEA
* pstTable
);
195 static const WCHAR advpackW
[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
197 hadvpack
= LoadLibraryW(advpackW
);
198 pRegInstall
= (void *)GetProcAddress(hadvpack
, "RegInstall");
200 hres
= pRegInstall(shdocvw_hinstance
, section
, strtable
);
202 FreeLibrary(hadvpack
);
206 #define INF_SET_CLSID(clsid) \
209 static CHAR name[] = "CLSID_" #clsid; \
211 pse[i].pszName = name; \
212 clsids[i++] = &CLSID_ ## clsid; \
215 static HRESULT
register_server(BOOL doregister
)
219 static CLSID
const *clsids
[3];
223 INF_SET_CLSID(Internet
);
224 INF_SET_CLSID(InternetExplorer
);
225 INF_SET_CLSID(InternetShortcut
);
227 for(i
= 0; i
< sizeof(pse
)/sizeof(pse
[0]); i
++) {
228 pse
[i
].pszValue
= HeapAlloc(GetProcessHeap(), 0, 39);
229 sprintf(pse
[i
].pszValue
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
230 clsids
[i
]->Data1
, clsids
[i
]->Data2
, clsids
[i
]->Data3
, clsids
[i
]->Data4
[0],
231 clsids
[i
]->Data4
[1], clsids
[i
]->Data4
[2], clsids
[i
]->Data4
[3], clsids
[i
]->Data4
[4],
232 clsids
[i
]->Data4
[5], clsids
[i
]->Data4
[6], clsids
[i
]->Data4
[7]);
235 strtable
.cEntries
= sizeof(pse
)/sizeof(pse
[0]);
238 hres
= reg_install(doregister
? "RegisterDll" : "UnregisterDll", &strtable
);
240 for(i
=0; i
< sizeof(pse
)/sizeof(pse
[0]); i
++)
241 HeapFree(GetProcessHeap(), 0, pse
[i
].pszValue
);
248 /***********************************************************************
249 * DllRegisterServer (shdocvw.@)
251 HRESULT WINAPI
DllRegisterServer(void)
255 hres
= __wine_register_resources( shdocvw_hinstance
, NULL
);
259 return register_server(TRUE
);
262 /***********************************************************************
263 * DllUnregisterServer (shdocvw.@)
265 HRESULT WINAPI
DllUnregisterServer(void)
269 hres
= register_server(FALSE
);
273 return __wine_unregister_resources( shdocvw_hinstance
, NULL
);
276 static BOOL
check_native_ie(void)
278 static const WCHAR cszPath
[] = {'b','r','o','w','s','e','u','i','.','d','l','l',0};
282 size
= GetFileVersionInfoSizeW(cszPath
,&handle
);
286 LPWSTR lpFileDescription
;
288 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};
289 static const WCHAR cszWine
[] = {'W','i','n','e',0};
291 buf
= HeapAlloc(GetProcessHeap(),0,size
);
292 GetFileVersionInfoW(cszPath
,0,size
,buf
);
294 if (VerQueryValueW(buf
, cszFD
, (LPVOID
*)&lpFileDescription
, &dwBytes
) &&
295 strstrW(lpFileDescription
,cszWine
))
298 HeapFree(GetProcessHeap(), 0, buf
);
304 DWORD
register_iexplore(BOOL doregister
)
307 if (check_native_ie())
309 TRACE("Native IE detected, not doing registration\n");
312 hres
= reg_install(doregister
? "RegisterIE" : "UnregisterIE", NULL
);