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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
40 #include "wine/debug.h"
43 #include "mshtml_private.h"
45 #include "pluginhost.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
51 DWORD mshtml_tls
= TLS_OUT_OF_INDEXES
;
53 static HINSTANCE shdoclc
= NULL
;
54 static HDC display_dc
;
55 static WCHAR
*status_strings
[IDS_STATUS_LAST
-IDS_STATUS_FIRST
+1];
56 static IMultiLanguage2
*mlang
;
58 static BOOL
ensure_mlang(void)
60 IMultiLanguage2
*new_mlang
;
66 hres
= CoCreateInstance(&CLSID_CMultiLanguage
, NULL
, CLSCTX_INPROC_SERVER
,
67 &IID_IMultiLanguage2
, (void**)&new_mlang
);
69 ERR("Could not create CMultiLanguage instance\n");
73 if(InterlockedCompareExchangePointer((void**)&mlang
, new_mlang
, NULL
))
74 IMultiLanguage2_Release(new_mlang
);
79 UINT
cp_from_charset_string(BSTR charset
)
87 hres
= IMultiLanguage2_GetCharsetInfo(mlang
, charset
, &info
);
89 FIXME("GetCharsetInfo failed: %08x\n", hres
);
93 return info
.uiInternetEncoding
;
96 BSTR
charset_string_from_cp(UINT cp
)
102 return SysAllocString(NULL
);
104 hres
= IMultiLanguage2_GetCodePageInfo(mlang
, cp
, GetUserDefaultUILanguage(), &info
);
106 ERR("GetCodePageInfo failed: %08x\n", hres
);
107 return SysAllocString(NULL
);
110 return SysAllocString(info
.wszWebCharset
);
113 static void thread_detach(void)
115 thread_data_t
*thread_data
;
117 thread_data
= get_thread_data(FALSE
);
121 if(thread_data
->thread_hwnd
)
122 DestroyWindow(thread_data
->thread_hwnd
);
124 heap_free(thread_data
);
127 static void free_strings(void)
130 for(i
= 0; i
< sizeof(status_strings
)/sizeof(*status_strings
); i
++)
131 heap_free(status_strings
[i
]);
134 static void process_detach(void)
140 FreeLibrary(shdoclc
);
141 if(mshtml_tls
!= TLS_OUT_OF_INDEXES
)
144 DeleteObject(display_dc
);
146 IMultiLanguage2_Release(mlang
);
151 void set_statustext(HTMLDocumentObj
* doc
, INT id
, LPCWSTR arg
)
153 int index
= id
- IDS_STATUS_FIRST
;
154 WCHAR
*p
= status_strings
[index
];
162 p
= heap_alloc(len
* sizeof(WCHAR
));
163 len
= LoadStringW(hInst
, id
, p
, len
) + 1;
164 p
= heap_realloc(p
, len
* sizeof(WCHAR
));
165 if(InterlockedCompareExchangePointer((void**)&status_strings
[index
], p
, NULL
)) {
167 p
= status_strings
[index
];
174 len
= lstrlenW(p
) + lstrlenW(arg
) - 1;
175 buf
= heap_alloc(len
* sizeof(WCHAR
));
177 snprintfW(buf
, len
, p
, arg
);
182 IOleInPlaceFrame_SetStatusText(doc
->frame
, p
);
188 HRESULT
do_query_service(IUnknown
*unk
, REFGUID guid_service
, REFIID riid
, void **ppv
)
190 IServiceProvider
*sp
;
193 hres
= IUnknown_QueryInterface(unk
, &IID_IServiceProvider
, (void**)&sp
);
197 hres
= IServiceProvider_QueryService(sp
, guid_service
, riid
, ppv
);
198 IServiceProvider_Release(sp
);
202 HINSTANCE
get_shdoclc(void)
204 static const WCHAR wszShdoclc
[] =
205 {'s','h','d','o','c','l','c','.','d','l','l',0};
210 return shdoclc
= LoadLibraryExW(wszShdoclc
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
213 HDC
get_display_dc(void)
215 static const WCHAR displayW
[] = {'D','I','S','P','L','A','Y',0};
220 hdc
= CreateICW(displayW
, NULL
, NULL
, NULL
);
221 if(InterlockedCompareExchangePointer((void**)&display_dc
, hdc
, NULL
))
228 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID reserved
)
231 case DLL_PROCESS_ATTACH
:
234 case DLL_PROCESS_DETACH
:
238 case DLL_THREAD_DETACH
:
245 /***********************************************************
246 * ClassFactory implementation
248 typedef HRESULT (*CreateInstanceFunc
)(IUnknown
*,REFIID
,void**);
250 IClassFactory IClassFactory_iface
;
252 CreateInstanceFunc fnCreateInstance
;
255 static inline ClassFactory
*impl_from_IClassFactory(IClassFactory
*iface
)
257 return CONTAINING_RECORD(iface
, ClassFactory
, IClassFactory_iface
);
260 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFGUID riid
, void **ppvObject
)
262 if(IsEqualGUID(&IID_IClassFactory
, riid
) || IsEqualGUID(&IID_IUnknown
, riid
)) {
263 IClassFactory_AddRef(iface
);
268 WARN("not supported iid %s\n", debugstr_mshtml_guid(riid
));
270 return E_NOINTERFACE
;
273 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
275 ClassFactory
*This
= impl_from_IClassFactory(iface
);
276 ULONG ref
= InterlockedIncrement(&This
->ref
);
277 TRACE("(%p) ref = %u\n", This
, ref
);
281 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
283 ClassFactory
*This
= impl_from_IClassFactory(iface
);
284 ULONG ref
= InterlockedDecrement(&This
->ref
);
286 TRACE("(%p) ref = %u\n", This
, ref
);
295 static HRESULT WINAPI
ClassFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pUnkOuter
,
296 REFIID riid
, void **ppvObject
)
298 ClassFactory
*This
= impl_from_IClassFactory(iface
);
299 return This
->fnCreateInstance(pUnkOuter
, riid
, ppvObject
);
302 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL dolock
)
304 TRACE("(%p)->(%x)\n", iface
, dolock
);
306 /* We never unload the DLL. See DllCanUnloadNow(). */
310 static const IClassFactoryVtbl HTMLClassFactoryVtbl
= {
311 ClassFactory_QueryInterface
,
313 ClassFactory_Release
,
314 ClassFactory_CreateInstance
,
315 ClassFactory_LockServer
318 static HRESULT
ClassFactory_Create(REFIID riid
, void **ppv
, CreateInstanceFunc fnCreateInstance
)
320 ClassFactory
*ret
= heap_alloc(sizeof(ClassFactory
));
323 ret
->IClassFactory_iface
.lpVtbl
= &HTMLClassFactoryVtbl
;
325 ret
->fnCreateInstance
= fnCreateInstance
;
327 hres
= IClassFactory_QueryInterface(&ret
->IClassFactory_iface
, riid
, ppv
);
335 /******************************************************************
336 * DllGetClassObject (MSHTML.@)
338 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
340 if(IsEqualGUID(&CLSID_HTMLDocument
, rclsid
)) {
341 TRACE("(CLSID_HTMLDocument %s %p)\n", debugstr_mshtml_guid(riid
), ppv
);
342 return ClassFactory_Create(riid
, ppv
, HTMLDocument_Create
);
343 }else if(IsEqualGUID(&CLSID_MHTMLDocument
, rclsid
)) {
344 TRACE("(CLSID_MHTMLDocument %s %p)\n", debugstr_mshtml_guid(riid
), ppv
);
345 return ClassFactory_Create(riid
, ppv
, MHTMLDocument_Create
);
346 }else if(IsEqualGUID(&CLSID_AboutProtocol
, rclsid
)) {
347 TRACE("(CLSID_AboutProtocol %s %p)\n", debugstr_mshtml_guid(riid
), ppv
);
348 return ProtocolFactory_Create(rclsid
, riid
, ppv
);
349 }else if(IsEqualGUID(&CLSID_JSProtocol
, rclsid
)) {
350 TRACE("(CLSID_JSProtocol %s %p)\n", debugstr_mshtml_guid(riid
), ppv
);
351 return ProtocolFactory_Create(rclsid
, riid
, ppv
);
352 }else if(IsEqualGUID(&CLSID_MailtoProtocol
, rclsid
)) {
353 TRACE("(CLSID_MailtoProtocol %s %p)\n", debugstr_mshtml_guid(riid
), ppv
);
354 return ProtocolFactory_Create(rclsid
, riid
, ppv
);
355 }else if(IsEqualGUID(&CLSID_ResProtocol
, rclsid
)) {
356 TRACE("(CLSID_ResProtocol %s %p)\n", debugstr_mshtml_guid(riid
), ppv
);
357 return ProtocolFactory_Create(rclsid
, riid
, ppv
);
358 }else if(IsEqualGUID(&CLSID_SysimageProtocol
, rclsid
)) {
359 TRACE("(CLSID_SysimageProtocol %s %p)\n", debugstr_mshtml_guid(riid
), ppv
);
360 return ProtocolFactory_Create(rclsid
, riid
, ppv
);
361 }else if(IsEqualGUID(&CLSID_HTMLLoadOptions
, rclsid
)) {
362 TRACE("(CLSID_HTMLLoadOptions %s %p)\n", debugstr_mshtml_guid(riid
), ppv
);
363 return ClassFactory_Create(riid
, ppv
, HTMLLoadOptions_Create
);
366 FIXME("Unknown class %s\n", debugstr_guid(rclsid
));
367 return CLASS_E_CLASSNOTAVAILABLE
;
370 /******************************************************************
371 * DllCanUnloadNow (MSHTML.@)
373 HRESULT WINAPI
DllCanUnloadNow(void)
376 /* The cost of keeping this DLL in memory is small. */
380 /***********************************************************************
381 * RunHTMLApplication (MSHTML.@)
383 * Appears to have the same prototype as WinMain.
385 HRESULT WINAPI
RunHTMLApplication( HINSTANCE hinst
, HINSTANCE hPrevInst
,
386 LPSTR szCmdLine
, INT nCmdShow
)
388 FIXME("%p %p %s %d\n", hinst
, hPrevInst
, debugstr_a(szCmdLine
), nCmdShow
);
392 /***********************************************************************
393 * RNIGetCompatibleVersion (MSHTML.@)
395 DWORD WINAPI
RNIGetCompatibleVersion(void)
401 /***********************************************************************
402 * DllInstall (MSHTML.@)
404 HRESULT WINAPI
DllInstall(BOOL bInstall
, LPCWSTR cmdline
)
406 FIXME("stub %d %s: returning S_OK\n", bInstall
, debugstr_w(cmdline
));
410 /***********************************************************************
411 * ShowHTMLDialog (MSHTML.@)
413 HRESULT WINAPI
ShowHTMLDialog(HWND hwndParent
, IMoniker
*pMk
, VARIANT
*pvarArgIn
,
414 WCHAR
*pchOptions
, VARIANT
*pvarArgOut
)
416 FIXME("(%p %p %p %s %p)\n", hwndParent
, pMk
, pvarArgIn
, debugstr_w(pchOptions
), pvarArgOut
);
420 /***********************************************************************
421 * PrintHTML (MSHTML.@)
423 void WINAPI
PrintHTML(HWND hwnd
, HINSTANCE handle
, LPCSTR cmdline
, INT show
)
425 FIXME("(%p %p %s %x)\n", hwnd
, handle
, debugstr_a(cmdline
), show
);
428 DEFINE_GUID(CLSID_CBackgroundPropertyPage
, 0x3050F232, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
429 DEFINE_GUID(CLSID_CCDAnchorPropertyPage
, 0x3050F1FC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
430 DEFINE_GUID(CLSID_CCDGenericPropertyPage
, 0x3050F17F, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
431 DEFINE_GUID(CLSID_CDwnBindInfo
, 0x3050F3C2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
432 DEFINE_GUID(CLSID_CHiFiUses
, 0x5AAF51B3, 0xB1F0, 0x11D1, 0xB6,0xAB, 0x00,0xA0,0xC9,0x08,0x33,0xE9);
433 DEFINE_GUID(CLSID_CHtmlComponentConstructor
, 0x3050F4F8, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
434 DEFINE_GUID(CLSID_CInlineStylePropertyPage
, 0x3050F296, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
435 DEFINE_GUID(CLSID_CPeerHandler
, 0x5AAF51B2, 0xB1F0, 0x11D1, 0xB6,0xAB, 0x00,0xA0,0xC9,0x08,0x33,0xE9);
436 DEFINE_GUID(CLSID_CRecalcEngine
, 0x3050F499, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
437 DEFINE_GUID(CLSID_CSvrOMUses
, 0x3050F4F0, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
438 DEFINE_GUID(CLSID_CrSource
, 0x65014010, 0x9F62, 0x11D1, 0xA6,0x51, 0x00,0x60,0x08,0x11,0xD5,0xCE);
439 DEFINE_GUID(CLSID_ExternalFrameworkSite
, 0x3050F163, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
440 DEFINE_GUID(CLSID_HTADocument
, 0x3050F5C8, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
441 DEFINE_GUID(CLSID_HTMLPluginDocument
, 0x25336921, 0x03F9, 0x11CF, 0x8F,0xD0, 0x00,0xAA,0x00,0x68,0x6F,0x13);
442 DEFINE_GUID(CLSID_HTMLPopup
, 0x3050F667, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
443 DEFINE_GUID(CLSID_HTMLPopupDoc
, 0x3050F67D, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
444 DEFINE_GUID(CLSID_HTMLServerDoc
, 0x3050F4E7, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
445 DEFINE_GUID(CLSID_IImageDecodeFilter
, 0x607FD4E8, 0x0A03, 0x11D1, 0xAB,0x1D, 0x00,0xC0,0x4F,0xC9,0xB3,0x04);
446 DEFINE_GUID(CLSID_IImgCtx
, 0x3050F3D6, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
447 DEFINE_GUID(CLSID_IntDitherer
, 0x05F6FE1A, 0xECEF, 0x11D0, 0xAA,0xE7, 0x00,0xC0,0x4F,0xC9,0xB3,0x04);
448 DEFINE_GUID(CLSID_TridentAPI
, 0x429AF92C, 0xA51F, 0x11D2, 0x86,0x1E, 0x00,0xC0,0x4F,0xA3,0x5C,0x89);
450 #define INF_SET_ID(id) \
453 static CHAR name[] = #id; \
455 pse[i].pszName = name; \
459 #define INF_SET_CLSID(clsid) INF_SET_ID(CLSID_ ## clsid)
461 static HRESULT
register_server(BOOL do_register
)
465 HRESULT (WINAPI
*pRegInstall
)(HMODULE hm
, LPCSTR pszSection
, const STRTABLEA
* pstTable
);
468 static CLSID
const *clsids
[35];
471 static const WCHAR wszAdvpack
[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
473 TRACE("(%x)\n", do_register
);
475 INF_SET_CLSID(AboutProtocol
);
476 INF_SET_CLSID(CAnchorBrowsePropertyPage
);
477 INF_SET_CLSID(CBackgroundPropertyPage
);
478 INF_SET_CLSID(CCDAnchorPropertyPage
);
479 INF_SET_CLSID(CCDGenericPropertyPage
);
480 INF_SET_CLSID(CDocBrowsePropertyPage
);
481 INF_SET_CLSID(CDwnBindInfo
);
482 INF_SET_CLSID(CHiFiUses
);
483 INF_SET_CLSID(CHtmlComponentConstructor
);
484 INF_SET_CLSID(CImageBrowsePropertyPage
);
485 INF_SET_CLSID(CInlineStylePropertyPage
);
486 INF_SET_CLSID(CPeerHandler
);
487 INF_SET_CLSID(CRecalcEngine
);
488 INF_SET_CLSID(CSvrOMUses
);
489 INF_SET_CLSID(CrSource
);
490 INF_SET_CLSID(ExternalFrameworkSite
);
491 INF_SET_CLSID(HTADocument
);
492 INF_SET_CLSID(HTMLDocument
);
493 INF_SET_CLSID(HTMLLoadOptions
);
494 INF_SET_CLSID(HTMLPluginDocument
);
495 INF_SET_CLSID(HTMLPopup
);
496 INF_SET_CLSID(HTMLPopupDoc
);
497 INF_SET_CLSID(HTMLServerDoc
);
498 INF_SET_CLSID(HTMLWindowProxy
);
499 INF_SET_CLSID(IImageDecodeFilter
);
500 INF_SET_CLSID(IImgCtx
);
501 INF_SET_CLSID(IntDitherer
);
502 INF_SET_CLSID(JSProtocol
);
503 INF_SET_CLSID(MHTMLDocument
);
504 INF_SET_CLSID(MailtoProtocol
);
505 INF_SET_CLSID(ResProtocol
);
506 INF_SET_CLSID(Scriptlet
);
507 INF_SET_CLSID(SysimageProtocol
);
508 INF_SET_CLSID(TridentAPI
);
509 INF_SET_ID(LIBID_MSHTML
);
511 for(i
=0; i
< sizeof(pse
)/sizeof(pse
[0]); i
++) {
512 pse
[i
].pszValue
= heap_alloc(39);
513 sprintf(pse
[i
].pszValue
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
514 clsids
[i
]->Data1
, clsids
[i
]->Data2
, clsids
[i
]->Data3
, clsids
[i
]->Data4
[0],
515 clsids
[i
]->Data4
[1], clsids
[i
]->Data4
[2], clsids
[i
]->Data4
[3], clsids
[i
]->Data4
[4],
516 clsids
[i
]->Data4
[5], clsids
[i
]->Data4
[6], clsids
[i
]->Data4
[7]);
519 strtable
.cEntries
= sizeof(pse
)/sizeof(pse
[0]);
522 hAdvpack
= LoadLibraryW(wszAdvpack
);
523 pRegInstall
= (void *)GetProcAddress(hAdvpack
, "RegInstall");
525 hres
= pRegInstall(hInst
, do_register
? "RegisterDll" : "UnregisterDll", &strtable
);
527 FreeLibrary(hAdvpack
);
529 for(i
=0; i
< sizeof(pse
)/sizeof(pse
[0]); i
++)
530 heap_free(pse
[i
].pszValue
);
533 ERR("RegInstall failed: %08x\n", hres
);
541 /***********************************************************************
542 * DllRegisterServer (MSHTML.@)
544 HRESULT WINAPI
DllRegisterServer(void)
548 hres
= __wine_register_resources( hInst
);
550 hres
= register_server(TRUE
);
557 /***********************************************************************
558 * DllUnregisterServer (MSHTML.@)
560 HRESULT WINAPI
DllUnregisterServer(void)
562 HRESULT hres
= __wine_unregister_resources( hInst
);
563 if(SUCCEEDED(hres
)) hres
= register_server(FALSE
);
567 const char *debugstr_mshtml_guid(const GUID
*iid
)
569 #define X(x) if(IsEqualGUID(iid, &x)) return #x
570 X(DIID_HTMLDocumentEvents
);
571 X(DIID_HTMLDocumentEvents2
);
572 X(DIID_HTMLTableEvents
);
573 X(DIID_HTMLTextContainerEvents
);
574 X(IID_HTMLPluginContainer
);
575 X(IID_IConnectionPoint
);
576 X(IID_IConnectionPointContainer
);
581 X(IID_UndocumentedScriptIface
);
582 X(IID_IEnumConnections
);
585 X(IID_IHTMLDocument6
);
586 X(IID_IHTMLDocument7
);
587 X(IID_IHTMLEditServices
);
588 X(IID_IHTMLFramesCollection2
);
589 X(IID_IHTMLPrivateWindow
);
590 X(IID_IHtmlLoadOptions
);
591 X(IID_IInternetHostSecurityManager
);
592 X(IID_IManagedObject
);
595 X(IID_IObjectIdentity
);
596 X(IID_IObjectSafety
);
597 X(IID_IObjectWithSite
);
598 X(IID_IOleContainer
);
599 X(IID_IOleCommandTarget
);
602 X(IID_IOleDocumentView
);
603 X(IID_IOleInPlaceActiveObject
);
604 X(IID_IOleInPlaceFrame
);
605 X(IID_IOleInPlaceObject
);
606 X(IID_IOleInPlaceObjectWindowless
);
607 X(IID_IOleInPlaceUIWindow
);
613 X(IID_IPersistHistory
);
614 X(IID_IPersistMoniker
);
615 X(IID_IPersistStreamInit
);
616 X(IID_IPropertyNotifySink
);
617 X(IID_IProvideClassInfo
);
618 X(IID_IProvideClassInfo2
);
619 X(IID_IProvideMultipleClassInfo
);
620 X(IID_IServiceProvider
);
621 X(IID_ISupportErrorInfo
);
622 X(IID_ITargetContainer
);
623 X(IID_ITravelLogClient
);
627 X(IID_IViewObjectEx
);
628 X(IID_nsCycleCollectionISupports
);
629 X(IID_nsXPCOMCycleCollectionParticipant
);
630 #define XIID(x) X(IID_##x);
631 #define XDIID(x) X(DIID_##x);
637 return debugstr_guid(iid
);