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 static HRESULT
get_ieframe_object(REFCLSID rclsid
, REFIID riid
, void **ppv
)
133 HINSTANCE ieframe_instance
;
135 static HRESULT (WINAPI
*ieframe_DllGetClassObject
)(REFCLSID
,REFIID
,void**);
137 if(!ieframe_DllGetClassObject
) {
138 ieframe_instance
= get_ieframe_instance();
139 if(!ieframe_instance
)
140 return CLASS_E_CLASSNOTAVAILABLE
;
142 ieframe_DllGetClassObject
= (void*)GetProcAddress(ieframe_instance
, "DllGetClassObject");
143 if(!ieframe_DllGetClassObject
)
144 return CLASS_E_CLASSNOTAVAILABLE
;
147 return ieframe_DllGetClassObject(rclsid
, riid
, ppv
);
150 /*************************************************************************
151 * DllGetClassObject (SHDOCVW.@)
153 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, void **ppv
)
155 static IClassFactoryImpl WB1ClassFactory
= {{&WBCF_Vtbl
}, WebBrowserV1_Create
};
156 static IClassFactoryImpl WB2ClassFactory
= {{&WBCF_Vtbl
}, WebBrowserV2_Create
};
160 if(IsEqualGUID(&CLSID_WebBrowser
, rclsid
))
161 return IClassFactory_QueryInterface(&WB2ClassFactory
.IClassFactory_iface
, riid
, ppv
);
163 if(IsEqualGUID(&CLSID_WebBrowser_V1
, rclsid
))
164 return IClassFactory_QueryInterface(&WB1ClassFactory
.IClassFactory_iface
, riid
, ppv
);
166 if(IsEqualGUID(&CLSID_InternetShortcut
, rclsid
)
167 || IsEqualGUID(&CLSID_CUrlHistory
, rclsid
)
168 || IsEqualGUID(&CLSID_TaskbarList
, rclsid
))
169 return get_ieframe_object(rclsid
, riid
, ppv
);
171 /* As a last resort, figure if the CLSID belongs to a 'Shell Instance Object' */
172 return SHDOCVW_GetShellInstanceObjectClassObject(rclsid
, riid
, ppv
);
175 HRESULT
register_class_object(BOOL do_reg
)
180 static IClassFactoryImpl IEClassFactory
= {{&WBCF_Vtbl
}, InternetExplorer_Create
};
183 hres
= CoRegisterClassObject(&CLSID_InternetExplorer
,
184 (IUnknown
*)&IEClassFactory
.IClassFactory_iface
, CLSCTX_SERVER
,
185 REGCLS_MULTIPLEUSE
|REGCLS_SUSPENDED
, &cookie
);
187 ERR("failed to register object %08x\n", hres
);
191 hres
= CoResumeClassObjects();
195 ERR("failed to resume object %08x\n", hres
);
198 return CoRevokeClassObject(cookie
);
201 static HRESULT
reg_install(LPCSTR section
, STRTABLEA
*strtable
)
203 HRESULT (WINAPI
*pRegInstall
)(HMODULE hm
, LPCSTR pszSection
, const STRTABLEA
* pstTable
);
207 static const WCHAR advpackW
[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
209 hadvpack
= LoadLibraryW(advpackW
);
210 pRegInstall
= (void *)GetProcAddress(hadvpack
, "RegInstall");
212 hres
= pRegInstall(shdocvw_hinstance
, section
, strtable
);
214 FreeLibrary(hadvpack
);
218 #define INF_SET_CLSID(clsid) \
221 static CHAR name[] = "CLSID_" #clsid; \
223 pse[i].pszName = name; \
224 clsids[i++] = &CLSID_ ## clsid; \
227 static HRESULT
register_server(BOOL doregister
)
231 static CLSID
const *clsids
[3];
235 INF_SET_CLSID(Internet
);
236 INF_SET_CLSID(InternetExplorer
);
237 INF_SET_CLSID(InternetShortcut
);
239 for(i
= 0; i
< sizeof(pse
)/sizeof(pse
[0]); i
++) {
240 pse
[i
].pszValue
= HeapAlloc(GetProcessHeap(), 0, 39);
241 sprintf(pse
[i
].pszValue
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
242 clsids
[i
]->Data1
, clsids
[i
]->Data2
, clsids
[i
]->Data3
, clsids
[i
]->Data4
[0],
243 clsids
[i
]->Data4
[1], clsids
[i
]->Data4
[2], clsids
[i
]->Data4
[3], clsids
[i
]->Data4
[4],
244 clsids
[i
]->Data4
[5], clsids
[i
]->Data4
[6], clsids
[i
]->Data4
[7]);
247 strtable
.cEntries
= sizeof(pse
)/sizeof(pse
[0]);
250 hres
= reg_install(doregister
? "RegisterDll" : "UnregisterDll", &strtable
);
252 for(i
=0; i
< sizeof(pse
)/sizeof(pse
[0]); i
++)
253 HeapFree(GetProcessHeap(), 0, pse
[i
].pszValue
);
260 /***********************************************************************
261 * DllRegisterServer (shdocvw.@)
263 HRESULT WINAPI
DllRegisterServer(void)
267 hres
= __wine_register_resources( shdocvw_hinstance
, NULL
);
271 return register_server(TRUE
);
274 /***********************************************************************
275 * DllUnregisterServer (shdocvw.@)
277 HRESULT WINAPI
DllUnregisterServer(void)
281 hres
= register_server(FALSE
);
285 return __wine_unregister_resources( shdocvw_hinstance
, NULL
);
288 static BOOL
check_native_ie(void)
290 static const WCHAR cszPath
[] = {'b','r','o','w','s','e','u','i','.','d','l','l',0};
294 size
= GetFileVersionInfoSizeW(cszPath
,&handle
);
298 LPWSTR lpFileDescription
;
300 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};
301 static const WCHAR cszWine
[] = {'W','i','n','e',0};
303 buf
= HeapAlloc(GetProcessHeap(),0,size
);
304 GetFileVersionInfoW(cszPath
,0,size
,buf
);
306 if (VerQueryValueW(buf
, cszFD
, (LPVOID
*)&lpFileDescription
, &dwBytes
) &&
307 strstrW(lpFileDescription
,cszWine
))
310 HeapFree(GetProcessHeap(), 0, buf
);
316 DWORD
register_iexplore(BOOL doregister
)
319 if (check_native_ie())
321 TRACE("Native IE detected, not doing registration\n");
324 hres
= reg_install(doregister
? "RegisterIE" : "UnregisterIE", NULL
);