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"
47 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
50 DWORD mshtml_tls
= TLS_OUT_OF_INDEXES
;
52 static HINSTANCE shdoclc
= NULL
;
53 static HDC display_dc
;
54 static WCHAR
*status_strings
[IDS_STATUS_LAST
-IDS_STATUS_FIRST
+1];
55 static IMultiLanguage2
*mlang
;
57 static BOOL
ensure_mlang(void)
59 IMultiLanguage2
*new_mlang
;
65 hres
= CoCreateInstance(&CLSID_CMultiLanguage
, NULL
, CLSCTX_INPROC_SERVER
,
66 &IID_IMultiLanguage2
, (void**)&new_mlang
);
68 ERR("Could not create CMultiLanguage instance\n");
72 if(InterlockedCompareExchangePointer((void**)&mlang
, new_mlang
, NULL
))
73 IMultiLanguage2_Release(new_mlang
);
78 UINT
cp_from_charset_string(BSTR charset
)
86 hres
= IMultiLanguage2_GetCharsetInfo(mlang
, charset
, &info
);
88 FIXME("GetCharsetInfo failed: %08x\n", hres
);
92 return info
.uiInternetEncoding
;
95 BSTR
charset_string_from_cp(UINT cp
)
101 return SysAllocString(NULL
);
103 hres
= IMultiLanguage2_GetCodePageInfo(mlang
, cp
, GetUserDefaultUILanguage(), &info
);
105 ERR("GetCodePageInfo failed: %08x\n", hres
);
106 return SysAllocString(NULL
);
109 return SysAllocString(info
.wszWebCharset
);
112 static void thread_detach(void)
114 thread_data_t
*thread_data
;
116 thread_data
= get_thread_data(FALSE
);
120 if(thread_data
->thread_hwnd
)
121 DestroyWindow(thread_data
->thread_hwnd
);
123 heap_free(thread_data
);
126 static void free_strings(void)
129 for(i
= 0; i
< sizeof(status_strings
)/sizeof(*status_strings
); i
++)
130 heap_free(status_strings
[i
]);
133 static void process_detach(void)
139 FreeLibrary(shdoclc
);
140 if(mshtml_tls
!= TLS_OUT_OF_INDEXES
)
143 DeleteObject(display_dc
);
145 IMultiLanguage2_Release(mlang
);
150 void set_statustext(HTMLDocumentObj
* doc
, INT id
, LPCWSTR arg
)
152 int index
= id
- IDS_STATUS_FIRST
;
153 WCHAR
*p
= status_strings
[index
];
161 p
= heap_alloc(len
* sizeof(WCHAR
));
162 len
= LoadStringW(hInst
, id
, p
, len
) + 1;
163 p
= heap_realloc(p
, len
* sizeof(WCHAR
));
164 if(InterlockedCompareExchangePointer((void**)&status_strings
[index
], p
, NULL
)) {
166 p
= status_strings
[index
];
173 len
= lstrlenW(p
) + lstrlenW(arg
) - 1;
174 buf
= heap_alloc(len
* sizeof(WCHAR
));
176 snprintfW(buf
, len
, p
, arg
);
181 IOleInPlaceFrame_SetStatusText(doc
->frame
, p
);
187 HRESULT
do_query_service(IUnknown
*unk
, REFGUID guid_service
, REFIID riid
, void **ppv
)
189 IServiceProvider
*sp
;
192 hres
= IUnknown_QueryInterface(unk
, &IID_IServiceProvider
, (void**)&sp
);
196 hres
= IServiceProvider_QueryService(sp
, guid_service
, riid
, ppv
);
197 IServiceProvider_Release(sp
);
201 HINSTANCE
get_shdoclc(void)
203 static const WCHAR wszShdoclc
[] =
204 {'s','h','d','o','c','l','c','.','d','l','l',0};
209 return shdoclc
= LoadLibraryExW(wszShdoclc
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
212 HDC
get_display_dc(void)
214 static const WCHAR displayW
[] = {'D','I','S','P','L','A','Y',0};
219 hdc
= CreateICW(displayW
, NULL
, NULL
, NULL
);
220 if(InterlockedCompareExchangePointer((void**)&display_dc
, hdc
, NULL
))
227 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID reserved
)
230 case DLL_PROCESS_ATTACH
:
233 case DLL_PROCESS_DETACH
:
237 case DLL_THREAD_DETACH
:
244 /***********************************************************
245 * ClassFactory implementation
247 typedef HRESULT (*CreateInstanceFunc
)(IUnknown
*,REFIID
,void**);
249 IClassFactory IClassFactory_iface
;
251 CreateInstanceFunc fnCreateInstance
;
254 static inline ClassFactory
*impl_from_IClassFactory(IClassFactory
*iface
)
256 return CONTAINING_RECORD(iface
, ClassFactory
, IClassFactory_iface
);
259 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFGUID riid
, void **ppvObject
)
261 if(IsEqualGUID(&IID_IClassFactory
, riid
) || IsEqualGUID(&IID_IUnknown
, riid
)) {
262 IClassFactory_AddRef(iface
);
267 WARN("not supported iid %s\n", debugstr_mshtml_guid(riid
));
269 return E_NOINTERFACE
;
272 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
274 ClassFactory
*This
= impl_from_IClassFactory(iface
);
275 ULONG ref
= InterlockedIncrement(&This
->ref
);
276 TRACE("(%p) ref = %u\n", This
, ref
);
280 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
282 ClassFactory
*This
= impl_from_IClassFactory(iface
);
283 ULONG ref
= InterlockedDecrement(&This
->ref
);
285 TRACE("(%p) ref = %u\n", This
, ref
);
294 static HRESULT WINAPI
ClassFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pUnkOuter
,
295 REFIID riid
, void **ppvObject
)
297 ClassFactory
*This
= impl_from_IClassFactory(iface
);
298 return This
->fnCreateInstance(pUnkOuter
, riid
, ppvObject
);
301 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL dolock
)
303 TRACE("(%p)->(%x)\n", iface
, dolock
);
305 /* We never unload the DLL. See DllCanUnloadNow(). */
309 static const IClassFactoryVtbl HTMLClassFactoryVtbl
= {
310 ClassFactory_QueryInterface
,
312 ClassFactory_Release
,
313 ClassFactory_CreateInstance
,
314 ClassFactory_LockServer
317 static HRESULT
ClassFactory_Create(REFIID riid
, void **ppv
, CreateInstanceFunc fnCreateInstance
)
319 ClassFactory
*ret
= heap_alloc(sizeof(ClassFactory
));
322 ret
->IClassFactory_iface
.lpVtbl
= &HTMLClassFactoryVtbl
;
324 ret
->fnCreateInstance
= fnCreateInstance
;
326 hres
= IClassFactory_QueryInterface(&ret
->IClassFactory_iface
, riid
, ppv
);
334 /******************************************************************
335 * DllGetClassObject (MSHTML.@)
337 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
339 if(IsEqualGUID(&CLSID_HTMLDocument
, rclsid
)) {
340 TRACE("(CLSID_HTMLDocument %s %p)\n", debugstr_mshtml_guid(riid
), ppv
);
341 return ClassFactory_Create(riid
, ppv
, HTMLDocument_Create
);
342 }else if(IsEqualGUID(&CLSID_MHTMLDocument
, rclsid
)) {
343 TRACE("(CLSID_MHTMLDocument %s %p)\n", debugstr_mshtml_guid(riid
), ppv
);
344 return ClassFactory_Create(riid
, ppv
, MHTMLDocument_Create
);
345 }else if(IsEqualGUID(&CLSID_AboutProtocol
, rclsid
)) {
346 TRACE("(CLSID_AboutProtocol %s %p)\n", debugstr_mshtml_guid(riid
), ppv
);
347 return ProtocolFactory_Create(rclsid
, riid
, ppv
);
348 }else if(IsEqualGUID(&CLSID_JSProtocol
, rclsid
)) {
349 TRACE("(CLSID_JSProtocol %s %p)\n", debugstr_mshtml_guid(riid
), ppv
);
350 return ProtocolFactory_Create(rclsid
, riid
, ppv
);
351 }else if(IsEqualGUID(&CLSID_MailtoProtocol
, rclsid
)) {
352 TRACE("(CLSID_MailtoProtocol %s %p)\n", debugstr_mshtml_guid(riid
), ppv
);
353 return ProtocolFactory_Create(rclsid
, riid
, ppv
);
354 }else if(IsEqualGUID(&CLSID_ResProtocol
, rclsid
)) {
355 TRACE("(CLSID_ResProtocol %s %p)\n", debugstr_mshtml_guid(riid
), ppv
);
356 return ProtocolFactory_Create(rclsid
, riid
, ppv
);
357 }else if(IsEqualGUID(&CLSID_SysimageProtocol
, rclsid
)) {
358 TRACE("(CLSID_SysimageProtocol %s %p)\n", debugstr_mshtml_guid(riid
), ppv
);
359 return ProtocolFactory_Create(rclsid
, riid
, ppv
);
360 }else if(IsEqualGUID(&CLSID_HTMLLoadOptions
, rclsid
)) {
361 TRACE("(CLSID_HTMLLoadOptions %s %p)\n", debugstr_mshtml_guid(riid
), ppv
);
362 return ClassFactory_Create(riid
, ppv
, HTMLLoadOptions_Create
);
365 FIXME("Unknown class %s\n", debugstr_guid(rclsid
));
366 return CLASS_E_CLASSNOTAVAILABLE
;
369 /******************************************************************
370 * DllCanUnloadNow (MSHTML.@)
372 HRESULT WINAPI
DllCanUnloadNow(void)
375 /* The cost of keeping this DLL in memory is small. */
379 /***********************************************************************
380 * RunHTMLApplication (MSHTML.@)
382 * Appears to have the same prototype as WinMain.
384 HRESULT WINAPI
RunHTMLApplication( HINSTANCE hinst
, HINSTANCE hPrevInst
,
385 LPSTR szCmdLine
, INT nCmdShow
)
387 FIXME("%p %p %s %d\n", hinst
, hPrevInst
, debugstr_a(szCmdLine
), nCmdShow
);
391 /***********************************************************************
392 * RNIGetCompatibleVersion (MSHTML.@)
394 DWORD WINAPI
RNIGetCompatibleVersion(void)
400 /***********************************************************************
401 * DllInstall (MSHTML.@)
403 HRESULT WINAPI
DllInstall(BOOL bInstall
, LPCWSTR cmdline
)
405 FIXME("stub %d %s: returning S_OK\n", bInstall
, debugstr_w(cmdline
));
409 /***********************************************************************
410 * ShowHTMLDialog (MSHTML.@)
412 HRESULT WINAPI
ShowHTMLDialog(HWND hwndParent
, IMoniker
*pMk
, VARIANT
*pvarArgIn
,
413 WCHAR
*pchOptions
, VARIANT
*pvarArgOut
)
415 FIXME("(%p %p %p %s %p)\n", hwndParent
, pMk
, pvarArgIn
, debugstr_w(pchOptions
), pvarArgOut
);
419 /***********************************************************************
420 * PrintHTML (MSHTML.@)
422 void WINAPI
PrintHTML(HWND hwnd
, HINSTANCE handle
, LPCSTR cmdline
, INT show
)
424 FIXME("(%p %p %s %x)\n", hwnd
, handle
, debugstr_a(cmdline
), show
);
427 DEFINE_GUID(CLSID_CBackgroundPropertyPage
, 0x3050F232, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
428 DEFINE_GUID(CLSID_CCDAnchorPropertyPage
, 0x3050F1FC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
429 DEFINE_GUID(CLSID_CCDGenericPropertyPage
, 0x3050F17F, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
430 DEFINE_GUID(CLSID_CDwnBindInfo
, 0x3050F3C2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
431 DEFINE_GUID(CLSID_CHiFiUses
, 0x5AAF51B3, 0xB1F0, 0x11D1, 0xB6,0xAB, 0x00,0xA0,0xC9,0x08,0x33,0xE9);
432 DEFINE_GUID(CLSID_CHtmlComponentConstructor
, 0x3050F4F8, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
433 DEFINE_GUID(CLSID_CInlineStylePropertyPage
, 0x3050F296, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
434 DEFINE_GUID(CLSID_CPeerHandler
, 0x5AAF51B2, 0xB1F0, 0x11D1, 0xB6,0xAB, 0x00,0xA0,0xC9,0x08,0x33,0xE9);
435 DEFINE_GUID(CLSID_CRecalcEngine
, 0x3050F499, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
436 DEFINE_GUID(CLSID_CSvrOMUses
, 0x3050F4F0, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
437 DEFINE_GUID(CLSID_CrSource
, 0x65014010, 0x9F62, 0x11D1, 0xA6,0x51, 0x00,0x60,0x08,0x11,0xD5,0xCE);
438 DEFINE_GUID(CLSID_ExternalFrameworkSite
, 0x3050F163, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
439 DEFINE_GUID(CLSID_HTADocument
, 0x3050F5C8, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
440 DEFINE_GUID(CLSID_HTMLPluginDocument
, 0x25336921, 0x03F9, 0x11CF, 0x8F,0xD0, 0x00,0xAA,0x00,0x68,0x6F,0x13);
441 DEFINE_GUID(CLSID_HTMLPopup
, 0x3050F667, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
442 DEFINE_GUID(CLSID_HTMLPopupDoc
, 0x3050F67D, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
443 DEFINE_GUID(CLSID_HTMLServerDoc
, 0x3050F4E7, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
444 DEFINE_GUID(CLSID_IImageDecodeFilter
, 0x607FD4E8, 0x0A03, 0x11D1, 0xAB,0x1D, 0x00,0xC0,0x4F,0xC9,0xB3,0x04);
445 DEFINE_GUID(CLSID_IImgCtx
, 0x3050F3D6, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
446 DEFINE_GUID(CLSID_IntDitherer
, 0x05F6FE1A, 0xECEF, 0x11D0, 0xAA,0xE7, 0x00,0xC0,0x4F,0xC9,0xB3,0x04);
447 DEFINE_GUID(CLSID_TridentAPI
, 0x429AF92C, 0xA51F, 0x11D2, 0x86,0x1E, 0x00,0xC0,0x4F,0xA3,0x5C,0x89);
449 #define INF_SET_ID(id) \
452 static CHAR name[] = #id; \
454 pse[i].pszName = name; \
458 #define INF_SET_CLSID(clsid) INF_SET_ID(CLSID_ ## clsid)
460 static HRESULT
register_server(BOOL do_register
)
464 HRESULT (WINAPI
*pRegInstall
)(HMODULE hm
, LPCSTR pszSection
, const STRTABLEA
* pstTable
);
467 static CLSID
const *clsids
[35];
470 static const WCHAR wszAdvpack
[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
472 TRACE("(%x)\n", do_register
);
474 INF_SET_CLSID(AboutProtocol
);
475 INF_SET_CLSID(CAnchorBrowsePropertyPage
);
476 INF_SET_CLSID(CBackgroundPropertyPage
);
477 INF_SET_CLSID(CCDAnchorPropertyPage
);
478 INF_SET_CLSID(CCDGenericPropertyPage
);
479 INF_SET_CLSID(CDocBrowsePropertyPage
);
480 INF_SET_CLSID(CDwnBindInfo
);
481 INF_SET_CLSID(CHiFiUses
);
482 INF_SET_CLSID(CHtmlComponentConstructor
);
483 INF_SET_CLSID(CImageBrowsePropertyPage
);
484 INF_SET_CLSID(CInlineStylePropertyPage
);
485 INF_SET_CLSID(CPeerHandler
);
486 INF_SET_CLSID(CRecalcEngine
);
487 INF_SET_CLSID(CSvrOMUses
);
488 INF_SET_CLSID(CrSource
);
489 INF_SET_CLSID(ExternalFrameworkSite
);
490 INF_SET_CLSID(HTADocument
);
491 INF_SET_CLSID(HTMLDocument
);
492 INF_SET_CLSID(HTMLLoadOptions
);
493 INF_SET_CLSID(HTMLPluginDocument
);
494 INF_SET_CLSID(HTMLPopup
);
495 INF_SET_CLSID(HTMLPopupDoc
);
496 INF_SET_CLSID(HTMLServerDoc
);
497 INF_SET_CLSID(HTMLWindowProxy
);
498 INF_SET_CLSID(IImageDecodeFilter
);
499 INF_SET_CLSID(IImgCtx
);
500 INF_SET_CLSID(IntDitherer
);
501 INF_SET_CLSID(JSProtocol
);
502 INF_SET_CLSID(MHTMLDocument
);
503 INF_SET_CLSID(MailtoProtocol
);
504 INF_SET_CLSID(ResProtocol
);
505 INF_SET_CLSID(Scriptlet
);
506 INF_SET_CLSID(SysimageProtocol
);
507 INF_SET_CLSID(TridentAPI
);
508 INF_SET_ID(LIBID_MSHTML
);
510 for(i
=0; i
< sizeof(pse
)/sizeof(pse
[0]); i
++) {
511 pse
[i
].pszValue
= heap_alloc(39);
512 sprintf(pse
[i
].pszValue
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
513 clsids
[i
]->Data1
, clsids
[i
]->Data2
, clsids
[i
]->Data3
, clsids
[i
]->Data4
[0],
514 clsids
[i
]->Data4
[1], clsids
[i
]->Data4
[2], clsids
[i
]->Data4
[3], clsids
[i
]->Data4
[4],
515 clsids
[i
]->Data4
[5], clsids
[i
]->Data4
[6], clsids
[i
]->Data4
[7]);
518 strtable
.cEntries
= sizeof(pse
)/sizeof(pse
[0]);
521 hAdvpack
= LoadLibraryW(wszAdvpack
);
522 pRegInstall
= (void *)GetProcAddress(hAdvpack
, "RegInstall");
524 hres
= pRegInstall(hInst
, do_register
? "RegisterDll" : "UnregisterDll", &strtable
);
526 FreeLibrary(hAdvpack
);
528 for(i
=0; i
< sizeof(pse
)/sizeof(pse
[0]); i
++)
529 heap_free(pse
[i
].pszValue
);
532 ERR("RegInstall failed: %08x\n", hres
);
540 /***********************************************************************
541 * DllRegisterServer (MSHTML.@)
543 HRESULT WINAPI
DllRegisterServer(void)
547 hres
= __wine_register_resources( hInst
);
549 hres
= register_server(TRUE
);
556 /***********************************************************************
557 * DllUnregisterServer (MSHTML.@)
559 HRESULT WINAPI
DllUnregisterServer(void)
561 HRESULT hres
= __wine_unregister_resources( hInst
);
562 if(SUCCEEDED(hres
)) hres
= register_server(FALSE
);
566 const char *debugstr_mshtml_guid(const GUID
*iid
)
568 #define X(x) if(IsEqualGUID(iid, &x)) return #x
569 X(DIID_HTMLDocumentEvents
);
570 X(DIID_HTMLDocumentEvents2
);
571 X(DIID_HTMLTableEvents
);
572 X(DIID_HTMLTextContainerEvents
);
573 X(IID_HTMLPluginContainer
);
574 X(IID_IConnectionPoint
);
575 X(IID_IConnectionPointContainer
);
580 X(IID_UndocumentedScriptIface
);
581 X(IID_IEnumConnections
);
584 X(IID_IHTMLDocument6
);
585 X(IID_IHTMLDocument7
);
586 X(IID_IHTMLEditServices
);
587 X(IID_IHTMLFramesCollection2
);
588 X(IID_IHTMLPrivateWindow
);
589 X(IID_IHtmlLoadOptions
);
590 X(IID_IInternetHostSecurityManager
);
592 X(IID_IObjectIdentity
);
593 X(IID_IObjectSafety
);
594 X(IID_IObjectWithSite
);
595 X(IID_IOleContainer
);
596 X(IID_IOleCommandTarget
);
599 X(IID_IOleDocumentView
);
600 X(IID_IOleInPlaceActiveObject
);
601 X(IID_IOleInPlaceFrame
);
602 X(IID_IOleInPlaceObject
);
603 X(IID_IOleInPlaceObjectWindowless
);
604 X(IID_IOleInPlaceUIWindow
);
610 X(IID_IPersistHistory
);
611 X(IID_IPersistMoniker
);
612 X(IID_IPersistStreamInit
);
613 X(IID_IPropertyNotifySink
);
614 X(IID_IProvideClassInfo
);
615 X(IID_IServiceProvider
);
616 X(IID_ISupportErrorInfo
);
617 X(IID_ITargetContainer
);
618 X(IID_ITravelLogClient
);
622 X(IID_IViewObjectEx
);
623 X(IID_nsCycleCollectionISupports
);
624 X(IID_nsXPCOMCycleCollectionParticipant
);
625 #define XIID(x) X(IID_##x);
626 #define XDIID(x) X(DIID_##x);
632 return debugstr_guid(iid
);