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
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw
);
32 /**********************************************************************
33 * Implement the WebBrowser class factory
35 * (Based on implementation in ddraw/main.c)
38 #define FACTORY(x) ((IClassFactory*) &(x)->lpClassFactoryVtbl)
43 const IClassFactoryVtbl
*lpClassFactoryVtbl
;
44 HRESULT (*cf
)(LPUNKNOWN
, REFIID
, LPVOID
*);
49 /**********************************************************************
50 * WBCF_QueryInterface (IUnknown)
52 static HRESULT WINAPI
WBCF_QueryInterface(LPCLASSFACTORY iface
,
53 REFIID riid
, LPVOID
*ppobj
)
55 TRACE("(%s %p)\n", debugstr_guid(riid
), ppobj
);
60 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IClassFactory
, riid
)) {
62 IClassFactory_AddRef(iface
);
66 WARN("Not supported interface %s\n", debugstr_guid(riid
));
72 /************************************************************************
73 * WBCF_AddRef (IUnknown)
75 static ULONG WINAPI
WBCF_AddRef(LPCLASSFACTORY iface
)
79 return 2; /* non-heap based object */
82 /************************************************************************
83 * WBCF_Release (IUnknown)
85 static ULONG WINAPI
WBCF_Release(LPCLASSFACTORY iface
)
87 SHDOCVW_UnlockModule();
89 return 1; /* non-heap based object */
92 /************************************************************************
93 * WBCF_CreateInstance (IClassFactory)
95 static HRESULT WINAPI
WBCF_CreateInstance(LPCLASSFACTORY iface
, LPUNKNOWN pOuter
,
96 REFIID riid
, LPVOID
*ppobj
)
98 IClassFactoryImpl
*This
= (IClassFactoryImpl
*) iface
;
99 return This
->cf(pOuter
, riid
, ppobj
);
102 /************************************************************************
103 * WBCF_LockServer (IClassFactory)
105 static HRESULT WINAPI
WBCF_LockServer(LPCLASSFACTORY iface
, BOOL dolock
)
107 TRACE("(%d)\n", dolock
);
110 SHDOCVW_LockModule();
112 SHDOCVW_UnlockModule();
117 static const IClassFactoryVtbl WBCF_Vtbl
=
126 /*************************************************************************
127 * DllGetClassObject (SHDOCVW.@)
129 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, void **ppv
)
131 static IClassFactoryImpl WB1ClassFactory
= {&WBCF_Vtbl
, WebBrowserV1_Create
};
132 static IClassFactoryImpl WB2ClassFactory
= {&WBCF_Vtbl
, WebBrowserV2_Create
};
133 static IClassFactoryImpl CUHClassFactory
= {&WBCF_Vtbl
, CUrlHistory_Create
};
137 if(IsEqualGUID(&CLSID_WebBrowser
, rclsid
))
138 return IClassFactory_QueryInterface(FACTORY(&WB2ClassFactory
), riid
, ppv
);
140 if(IsEqualGUID(&CLSID_WebBrowser_V1
, rclsid
))
141 return IClassFactory_QueryInterface(FACTORY(&WB1ClassFactory
), riid
, ppv
);
143 if(IsEqualGUID(&CLSID_CUrlHistory
, rclsid
))
144 return IClassFactory_QueryInterface(FACTORY(&CUHClassFactory
), riid
, ppv
);
146 /* As a last resort, figure if the CLSID belongs to a 'Shell Instance Object' */
147 return SHDOCVW_GetShellInstanceObjectClassObject(rclsid
, riid
, ppv
);
150 HRESULT
register_class_object(BOOL do_reg
)
155 static IClassFactoryImpl IEClassFactory
= {&WBCF_Vtbl
, InternetExplorer_Create
};
158 hres
= CoRegisterClassObject(&CLSID_InternetExplorer
, (IUnknown
*)FACTORY(&IEClassFactory
),
159 CLSCTX_SERVER
, REGCLS_MULTIPLEUSE
|REGCLS_SUSPENDED
, &cookie
);
161 ERR("failed to register object %08x\n", hres
);
165 hres
= CoResumeClassObjects();
169 ERR("failed to resume object %08x\n", hres
);
172 return CoRevokeClassObject(cookie
);
175 static const GUID CLSID_MicrosoftBrowserArchitecture
=
176 {0xa5e46e3a, 0x8849, 0x11d1, {0x9d, 0x8c, 0x00, 0xc0, 0x4f, 0xc9, 0x9d, 0x61}};
177 static const GUID CLSID_MruLongList
=
178 {0x53bd6b4e, 0x3780, 0x4693, {0xaf, 0xc3, 0x71, 0x61, 0xc2, 0xf3, 0xee, 0x9c}};
180 #define INF_SET_CLSID(clsid) \
183 static CHAR name[] = "CLSID_" #clsid; \
185 pse[i].pszName = name; \
186 clsids[i++] = &CLSID_ ## clsid; \
189 static HRESULT
register_server(BOOL doregister
)
193 typeof(RegInstallA
) *pRegInstall
;
196 static CLSID
const *clsids
[13];
199 static const WCHAR wszAdvpack
[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
201 INF_SET_CLSID(CUrlHistory
);
202 INF_SET_CLSID(Internet
);
203 INF_SET_CLSID(InternetExplorer
);
204 INF_SET_CLSID(MicrosoftBrowserArchitecture
);
205 INF_SET_CLSID(MruLongList
);
206 INF_SET_CLSID(SearchAssistantOC
);
207 INF_SET_CLSID(ShellNameSpace
);
208 INF_SET_CLSID(ShellSearchAssistantOC
);
209 INF_SET_CLSID(ShellShellNameSpace
);
210 INF_SET_CLSID(ShellUIHelper
);
211 INF_SET_CLSID(ShellWindows
);
212 INF_SET_CLSID(WebBrowser
);
213 INF_SET_CLSID(WebBrowser_V1
);
215 for(i
= 0; i
< sizeof(pse
)/sizeof(pse
[0]); i
++) {
216 pse
[i
].pszValue
= HeapAlloc(GetProcessHeap(), 0, 39);
217 sprintf(pse
[i
].pszValue
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
218 clsids
[i
]->Data1
, clsids
[i
]->Data2
, clsids
[i
]->Data3
, clsids
[i
]->Data4
[0],
219 clsids
[i
]->Data4
[1], clsids
[i
]->Data4
[2], clsids
[i
]->Data4
[3], clsids
[i
]->Data4
[4],
220 clsids
[i
]->Data4
[5], clsids
[i
]->Data4
[6], clsids
[i
]->Data4
[7]);
223 strtable
.cEntries
= sizeof(pse
)/sizeof(pse
[0]);
226 hAdvpack
= LoadLibraryW(wszAdvpack
);
227 pRegInstall
= (typeof(RegInstallA
)*)GetProcAddress(hAdvpack
, "RegInstall");
229 hres
= pRegInstall(shdocvw_hinstance
, doregister
? "RegisterDll" : "UnregisterDll", &strtable
);
231 for(i
=0; i
< sizeof(pse
)/sizeof(pse
[0]); i
++)
232 HeapFree(GetProcessHeap(), 0, pse
[i
].pszValue
);
239 /***********************************************************************
240 * DllRegisterServer (msimtf.@)
242 HRESULT WINAPI
DllRegisterServer(void)
247 static const WCHAR shdocvwW
[] = {'s','h','d','o','c','v','w','.','d','l','l',0};
249 hres
= register_server(TRUE
);
253 hres
= LoadTypeLibEx(shdocvwW
, REGKIND_REGISTER
, &typelib
);
255 ERR("Could not load typelib: %08x\n", hres
);
259 ITypeLib_Release(typelib
);
264 /***********************************************************************
265 * DllUnregisterServer (msimtf.@)
267 HRESULT WINAPI
DllUnregisterServer(void)
271 hres
= register_server(FALSE
);
275 return UnRegisterTypeLib(&LIBID_SHDocVw
, 1, 1, LOCALE_SYSTEM_DEFAULT
, SYS_WIN32
);