4 * Copyright 2002 Lionel Ulmer
5 * Copyright 2003 Mike McCormack
6 * Copyright 2005 Jacek Caban
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
45 #include "mshtml_private.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
49 DEFINE_GUID( CLSID_MozillaBrowser
, 0x1339B54C,0x3453,0x11D2,0x93,0xB9,0x00,0x00,0x00,0x00,0x00,0x00);
51 typedef HRESULT (WINAPI
*fnGetClassObject
)(REFCLSID rclsid
, REFIID iid
, LPVOID
*ppv
);
52 typedef BOOL (WINAPI
*fnCanUnloadNow
)();
54 static HMODULE hMozCtl
;
58 /* convert a guid to a wide character string */
59 static void MSHTML_guid2wstr( const GUID
*guid
, LPWSTR wstr
)
63 sprintf(str
, "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
64 guid
->Data1
, guid
->Data2
, guid
->Data3
,
65 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
66 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7] );
67 MultiByteToWideChar( CP_ACP
, 0, str
, -1, wstr
, 40 );
70 static BOOL
MSHTML_GetMozctlPath( LPWSTR szPath
, DWORD sz
)
75 static const WCHAR szPre
[] = {
76 'S','o','f','t','w','a','r','e','\\',
77 'C','l','a','s','s','e','s','\\',
78 'C','L','S','I','D','\\',0 };
79 static const WCHAR szPost
[] = {
80 '\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2',0 };
81 WCHAR szRegPath
[(sizeof(szPre
)+sizeof(szPost
))/sizeof(WCHAR
)+40];
83 strcpyW( szRegPath
, szPre
);
84 MSHTML_guid2wstr( &CLSID_MozillaBrowser
, &szRegPath
[strlenW(szRegPath
)] );
85 strcatW( szRegPath
, szPost
);
87 TRACE("key = %s\n", debugstr_w( szRegPath
) );
89 r
= RegOpenKeyW( HKEY_LOCAL_MACHINE
, szRegPath
, &hkey
);
90 if( r
!= ERROR_SUCCESS
)
93 r
= RegQueryValueExW( hkey
, NULL
, NULL
, &type
, (LPBYTE
)szPath
, &sz
);
94 ret
= ( r
== ERROR_SUCCESS
) && ( type
== REG_SZ
);
100 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpv
)
102 WCHAR szPath
[MAX_PATH
];
105 case DLL_PROCESS_ATTACH
:
106 if(MSHTML_GetMozctlPath(szPath
, sizeof szPath
)) {
107 hMozCtl
= LoadLibraryExW(szPath
, NULL
, LOAD_WITH_ALTERED_SEARCH_PATH
);
109 ERR("Can't load the Mozilla ActiveX control\n");
111 TRACE("Not found Mozilla ActiveX Control. HTML rendering will be disabled.");
115 case DLL_PROCESS_DETACH
:
117 FreeLibrary( hMozCtl
);
123 /***********************************************************
124 * ClassFactory implementation
126 typedef HRESULT (*CreateInstanceFunc
)(IUnknown
*,REFIID
,void**);
128 const IClassFactoryVtbl
*lpVtbl
;
130 CreateInstanceFunc fnCreateInstance
;
133 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFGUID riid
, void **ppvObject
)
135 if(IsEqualGUID(&IID_IClassFactory
, riid
) || IsEqualGUID(&IID_IUnknown
, riid
)) {
136 IClassFactory_AddRef(iface
);
141 WARN("not supported iid %s\n", debugstr_guid(riid
));
143 return E_NOINTERFACE
;
146 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
148 ClassFactory
*This
= (ClassFactory
*)iface
;
149 ULONG ref
= InterlockedIncrement(&This
->ref
);
150 TRACE("(%p) ref = %lu\n", This
, ref
);
154 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
156 ClassFactory
*This
= (ClassFactory
*)iface
;
157 ULONG ref
= InterlockedDecrement(&This
->ref
);
159 TRACE("(%p) ref = %lu\n", This
, ref
);
162 HeapFree(GetProcessHeap(), 0, This
);
167 static HRESULT WINAPI
ClassFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pUnkOuter
,
168 REFIID riid
, void **ppvObject
)
170 ClassFactory
*This
= (ClassFactory
*)iface
;
171 return This
->fnCreateInstance(pUnkOuter
, riid
, ppvObject
);
174 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL dolock
)
176 FIXME("(%p)->(%x) stub\n", iface
, dolock
);
180 static const IClassFactoryVtbl HTMLClassFactoryVtbl
= {
181 ClassFactory_QueryInterface
,
183 ClassFactory_Release
,
184 ClassFactory_CreateInstance
,
185 ClassFactory_LockServer
188 static HRESULT
ClassFactory_Create(REFIID riid
, void **ppv
, CreateInstanceFunc fnCreateInstance
)
190 ClassFactory
*ret
= HeapAlloc(GetProcessHeap(), 0, sizeof(ClassFactory
));
193 ret
->lpVtbl
= &HTMLClassFactoryVtbl
;
195 ret
->fnCreateInstance
= fnCreateInstance
;
197 hres
= IClassFactory_QueryInterface((IClassFactory
*)ret
, riid
, ppv
);
199 HeapFree(GetProcessHeap(), 0, ret
);
205 HRESULT WINAPI
MSHTML_DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
208 fnGetClassObject pGetClassObject
;
210 if(hMozCtl
&& IsEqualGUID(&CLSID_HTMLDocument
, rclsid
)) {
211 pGetClassObject
= (fnGetClassObject
) GetProcAddress(hMozCtl
, "DllGetClassObject");
212 if(pGetClassObject
) {
213 hres
= pGetClassObject(&CLSID_MozillaBrowser
, riid
, ppv
);
214 if(SUCCEEDED(hres
)) {
215 TRACE("returning Mozilla ActiveX Control hres = %08lx *ppv = %p\n", hres
, *ppv
);
221 if(IsEqualGUID(&CLSID_HTMLDocument
, rclsid
)) {
222 TRACE("(CLSID_HTMLDocument %s %p)\n", debugstr_guid(riid
), ppv
);
223 return ClassFactory_Create(riid
, ppv
, HTMLDocument_Create
);
224 }else if(IsEqualGUID(&CLSID_AboutProtocol
, rclsid
)) {
225 TRACE("(CLSID_AboutProtocol %s %p)\n", debugstr_guid(riid
), ppv
);
226 return ProtocolFactory_Create(rclsid
, riid
, ppv
);
227 }else if(IsEqualGUID(&CLSID_JSProtocol
, rclsid
)) {
228 TRACE("(CLSID_JSProtocol %s %p)\n", debugstr_guid(riid
), ppv
);
229 return ProtocolFactory_Create(rclsid
, riid
, ppv
);
230 }else if(IsEqualGUID(&CLSID_MailtoProtocol
, rclsid
)) {
231 TRACE("(CLSID_MailtoProtocol %s %p)\n", debugstr_guid(riid
), ppv
);
232 return ProtocolFactory_Create(rclsid
, riid
, ppv
);
233 }else if(IsEqualGUID(&CLSID_ResProtocol
, rclsid
)) {
234 TRACE("(CLSID_ResProtocol %s %p)\n", debugstr_guid(riid
), ppv
);
235 return ProtocolFactory_Create(rclsid
, riid
, ppv
);
236 }else if(IsEqualGUID(&CLSID_SysimageProtocol
, rclsid
)) {
237 TRACE("(CLSID_SysimageProtocol %s %p)\n", debugstr_guid(riid
), ppv
);
238 return ProtocolFactory_Create(rclsid
, riid
, ppv
);
241 FIXME("Unknown class %s\n", debugstr_guid(rclsid
));
242 return CLASS_E_CLASSNOTAVAILABLE
;
245 HRESULT WINAPI
MSHTML_DllCanUnloadNow(void)
247 fnCanUnloadNow pCanUnloadNow
= NULL
;
253 pCanUnloadNow
= (fnCanUnloadNow
) GetProcAddress(hMozCtl
, "DllCanUnloadNow");
257 hres
= pCanUnloadNow();
259 TRACE("hres = %08lx\n", hres
);
264 /***********************************************************************
265 * RunHTMLApplication (MSHTML.@)
267 * Appears to have the same prototype as WinMain.
269 INT WINAPI
RunHTMLApplication( HINSTANCE hinst
, HINSTANCE hPrevInst
,
270 LPCSTR szCmdLine
, INT nCmdShow
)
272 FIXME("%p %p %s %d\n", hinst
, hPrevInst
, debugstr_a(szCmdLine
), nCmdShow
);
276 /***********************************************************************
277 * DllInstall (MSHTML.@)
279 HRESULT WINAPI
MSHTML_DllInstall(BOOL bInstall
, LPCWSTR cmdline
)
281 FIXME("stub %d %s: returning S_OK\n", bInstall
, debugstr_w(cmdline
));
285 DEFINE_GUID(CLSID_CAnchorBrowsePropertyPage
, 0x3050F3BB, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
286 DEFINE_GUID(CLSID_CBackgroundPropertyPage
, 0x3050F232, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
287 DEFINE_GUID(CLSID_CCDAnchorPropertyPage
, 0x3050F1FC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
288 DEFINE_GUID(CLSID_CCDGenericPropertyPage
, 0x3050F17F, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
289 DEFINE_GUID(CLSID_CDocBrowsePropertyPage
, 0x3050F3B4, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
290 DEFINE_GUID(CLSID_CDwnBindInfo
, 0x3050F3C2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
291 DEFINE_GUID(CLSID_CHiFiUses
, 0x5AAF51B3, 0xB1F0, 0x11D1, 0xB6,0xAB, 0x00,0xA0,0xC9,0x08,0x33,0xE9);
292 DEFINE_GUID(CLSID_CHtmlComponentConstructor
, 0x3050F4F8, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
293 DEFINE_GUID(CLSID_CImageBrowsePropertyPage
, 0x3050F3B3, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
294 DEFINE_GUID(CLSID_CInlineStylePropertyPage
, 0x3050F296, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
295 DEFINE_GUID(CLSID_CPeerHandler
, 0x5AAF51B2, 0xB1F0, 0x11D1, 0xB6,0xAB, 0x00,0xA0,0xC9,0x08,0x33,0xE9);
296 DEFINE_GUID(CLSID_CRecalcEngine
, 0x3050F499, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
297 DEFINE_GUID(CLSID_CSvrOMUses
, 0x3050F4F0, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
298 DEFINE_GUID(CLSID_CrSource
, 0x65014010, 0x9F62, 0x11D1, 0xA6,0x51, 0x00,0x60,0x08,0x11,0xD5,0xCE);
299 DEFINE_GUID(CLSID_ExternalFrameworkSite
, 0x3050F163, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
300 DEFINE_GUID(CLSID_HTADocument
, 0x3050F5C8, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
301 DEFINE_GUID(CLSID_HTMLLoadOptions
, 0x18845040, 0x0FA5, 0x11D1, 0xBA,0x19, 0x00,0xC0,0x4F,0xD9,0x12,0xD0);
302 DEFINE_GUID(CLSID_HTMLPluginDocument
, 0x25336921, 0x03F9, 0x11CF, 0x8F,0xD0, 0x00,0xAA,0x00,0x68,0x6F,0x13);
303 DEFINE_GUID(CLSID_HTMLPopup
, 0x3050F667, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
304 DEFINE_GUID(CLSID_HTMLPopupDoc
, 0x3050F67D, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
305 DEFINE_GUID(CLSID_HTMLServerDoc
, 0x3050F4E7, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
306 DEFINE_GUID(CLSID_HTMLWindowProxy
, 0x3050F391, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
307 DEFINE_GUID(CLSID_IImageDecodeFilter
, 0x607FD4E8, 0x0A03, 0x11D1, 0xAB,0x1D, 0x00,0xC0,0x4F,0xC9,0xB3,0x04);
308 DEFINE_GUID(CLSID_IImgCtx
, 0x3050F3D6, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
309 DEFINE_GUID(CLSID_IntDitherer
, 0x05F6FE1A, 0xECEF, 0x11D0, 0xAA,0xE7, 0x00,0xC0,0x4F,0xC9,0xB3,0x04);
310 DEFINE_GUID(CLSID_MHTMLDocument
, 0x3050F3D9, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
311 DEFINE_GUID(CLSID_Scriptlet
, 0xAE24FDAE, 0x03C6, 0x11D1, 0x8B,0x76, 0x00,0x80,0xC7,0x44,0xF3,0x89);
312 DEFINE_GUID(CLSID_TridentAPI
, 0x429AF92C, 0xA51F, 0x11D2, 0x86,0x1E, 0x00,0xC0,0x4F,0xA3,0x5C,0x89);
314 #define INF_SET_CLSID(clsid) \
315 pse[i].pszName = "CLSID_" #clsid; \
316 clsids[i++] = &CLSID_ ## clsid;
318 static HRESULT
register_server(BOOL do_register
)
322 typeof(RegInstall
) *pRegInstall
;
325 static CLSID
const *clsids
[34];
328 static const WCHAR wszAdvpack
[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
330 TRACE("(%x)\n", do_register
);
332 INF_SET_CLSID(AboutProtocol
);
333 INF_SET_CLSID(CAnchorBrowsePropertyPage
);
334 INF_SET_CLSID(CBackgroundPropertyPage
);
335 INF_SET_CLSID(CCDAnchorPropertyPage
);
336 INF_SET_CLSID(CCDGenericPropertyPage
);
337 INF_SET_CLSID(CDocBrowsePropertyPage
);
338 INF_SET_CLSID(CDwnBindInfo
);
339 INF_SET_CLSID(CHiFiUses
);
340 INF_SET_CLSID(CHtmlComponentConstructor
);
341 INF_SET_CLSID(CImageBrowsePropertyPage
);
342 INF_SET_CLSID(CInlineStylePropertyPage
);
343 INF_SET_CLSID(CPeerHandler
);
344 INF_SET_CLSID(CRecalcEngine
);
345 INF_SET_CLSID(CSvrOMUses
);
346 INF_SET_CLSID(CrSource
);
347 INF_SET_CLSID(ExternalFrameworkSite
);
348 INF_SET_CLSID(HTADocument
);
349 INF_SET_CLSID(HTMLDocument
);
350 INF_SET_CLSID(HTMLLoadOptions
);
351 INF_SET_CLSID(HTMLPluginDocument
);
352 INF_SET_CLSID(HTMLPopup
);
353 INF_SET_CLSID(HTMLPopupDoc
);
354 INF_SET_CLSID(HTMLServerDoc
);
355 INF_SET_CLSID(HTMLWindowProxy
);
356 INF_SET_CLSID(IImageDecodeFilter
);
357 INF_SET_CLSID(IImgCtx
);
358 INF_SET_CLSID(IntDitherer
);
359 INF_SET_CLSID(JSProtocol
);
360 INF_SET_CLSID(MHTMLDocument
);
361 INF_SET_CLSID(MailtoProtocol
);
362 INF_SET_CLSID(ResProtocol
);
363 INF_SET_CLSID(Scriptlet
);
364 INF_SET_CLSID(SysimageProtocol
);
365 INF_SET_CLSID(TridentAPI
);
367 for(i
=0; i
< sizeof(pse
)/sizeof(pse
[0]); i
++) {
368 pse
[i
].pszValue
= HeapAlloc(GetProcessHeap(), 0, 39);
369 sprintf(pse
[i
].pszValue
, "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
370 clsids
[i
]->Data1
, clsids
[i
]->Data2
, clsids
[i
]->Data3
, clsids
[i
]->Data4
[0],
371 clsids
[i
]->Data4
[1], clsids
[i
]->Data4
[2], clsids
[i
]->Data4
[3], clsids
[i
]->Data4
[4],
372 clsids
[i
]->Data4
[5], clsids
[i
]->Data4
[6], clsids
[i
]->Data4
[7]);
375 strtable
.cEntries
= sizeof(pse
)/sizeof(pse
[0]);
378 hAdvpack
= LoadLibraryW(wszAdvpack
);
379 pRegInstall
= (typeof(RegInstall
)*)GetProcAddress(hAdvpack
, "RegInstall");
381 hres
= pRegInstall(hInst
, do_register
? "RegisterDll" : "UnregisterDll", &strtable
);
383 for(i
=0; i
< sizeof(pse
)/sizeof(pse
[0]); i
++)
384 HeapFree(GetProcessHeap(), 0, pse
[i
].pszValue
);
391 /***********************************************************************
392 * DllRegisterServer (MSHTML.@)
394 HRESULT WINAPI
MSHTML_DllRegisterServer(void)
396 return register_server(TRUE
);
399 /***********************************************************************
400 * DllUnregisterServer (MSHTML.@)
402 HRESULT WINAPI
MSHTML_DllUnregisterServer(void)
404 return register_server(FALSE
);