2 * Copyright 2008-2009 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
34 static const WCHAR objectW
[] = {'[','o','b','j','e','c','t',']',0};
43 struct dispex_data_t
{
46 func_info_t
**name_table
;
59 const IUnknownVtbl
*lpIUnknownVtbl
;
64 #define FUNCUNKNOWN(x) ((IUnknown*) &(x)->lpIUnknownVtbl)
66 struct dispex_dynamic_data_t
{
69 dynamic_prop_t
*props
;
70 func_disp_t
**func_disps
;
73 #define DISPID_DYNPROP_0 0x50000000
74 #define DISPID_DYNPROP_MAX 0x5fffffff
76 #define FDEX_VERSION_MASK 0xf0000000
78 static ITypeLib
*typelib
;
79 static ITypeInfo
*typeinfos
[LAST_tid
];
80 static struct list dispex_data_list
= LIST_INIT(dispex_data_list
);
82 static REFIID tid_ids
[] = {
85 &DIID_DispDOMChildrenCollection
,
86 &DIID_DispHTMLAnchorElement
,
88 &DIID_DispHTMLCommentElement
,
89 &DIID_DispHTMLCurrentStyle
,
90 &DIID_DispHTMLDocument
,
91 &DIID_DispHTMLDOMTextNode
,
92 &DIID_DispHTMLElementCollection
,
93 &DIID_DispHTMLFormElement
,
94 &DIID_DispHTMLGenericElement
,
95 &DIID_DispHTMLFrameElement
,
98 &DIID_DispHTMLInputElement
,
99 &DIID_DispHTMLLocation
,
100 &DIID_DispHTMLNavigator
,
101 &DIID_DispHTMLOptionElement
,
102 &DIID_DispHTMLScreen
,
103 &DIID_DispHTMLScriptElement
,
104 &DIID_DispHTMLSelectElement
,
107 &DIID_DispHTMLTableRow
,
108 &DIID_DispHTMLTextAreaElement
,
109 &DIID_DispHTMLUnknownElement
,
110 &DIID_DispHTMLWindow2
,
111 &DIID_HTMLDocumentEvents
,
112 &IID_IHTMLAnchorElement
,
113 &IID_IHTMLBodyElement
,
114 &IID_IHTMLBodyElement2
,
115 &IID_IHTMLCommentElement
,
116 &IID_IHTMLCurrentStyle
,
117 &IID_IHTMLCurrentStyle2
,
118 &IID_IHTMLCurrentStyle3
,
119 &IID_IHTMLCurrentStyle4
,
124 &IID_IHTMLDOMChildrenCollection
,
127 &IID_IHTMLDOMTextNode
,
132 &IID_IHTMLElementCollection
,
134 &IID_IHTMLFiltersCollection
,
135 &IID_IHTMLFormElement
,
137 &IID_IHTMLFrameBase2
,
138 &IID_IHTMLGenericElement
,
139 &IID_IHTMLFrameElement3
,
140 &IID_IHTMLIFrameElement
,
141 &IID_IHTMLImageElementFactory
,
142 &IID_IHTMLImgElement
,
143 &IID_IHTMLInputElement
,
145 &IID_IHTMLOptionElement
,
147 &IID_IHTMLScriptElement
,
148 &IID_IHTMLSelectElement
,
155 &IID_IHTMLTextAreaElement
,
156 &IID_IHTMLTextContainer
,
157 &IID_IHTMLUniqueName
,
164 static HRESULT
get_typeinfo(tid_t tid
, ITypeInfo
**typeinfo
)
171 hres
= LoadRegTypeLib(&LIBID_MSHTML
, 4, 0, LOCALE_SYSTEM_DEFAULT
, &tl
);
173 ERR("LoadRegTypeLib failed: %08x\n", hres
);
177 if(InterlockedCompareExchangePointer((void**)&typelib
, tl
, NULL
))
178 ITypeLib_Release(tl
);
181 if(!typeinfos
[tid
]) {
184 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, tid_ids
[tid
], &typeinfo
);
186 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids
[tid
]), hres
);
190 if(InterlockedCompareExchangePointer((void**)(typeinfos
+tid
), typeinfo
, NULL
))
191 ITypeInfo_Release(typeinfo
);
194 *typeinfo
= typeinfos
[tid
];
198 void release_typelib(void)
203 while(!list_empty(&dispex_data_list
)) {
204 iter
= LIST_ENTRY(list_head(&dispex_data_list
), dispex_data_t
, entry
);
205 list_remove(&iter
->entry
);
207 for(i
=0; i
< iter
->func_cnt
; i
++)
208 SysFreeString(iter
->funcs
[i
].name
);
210 heap_free(iter
->funcs
);
211 heap_free(iter
->name_table
);
218 for(i
=0; i
< sizeof(typeinfos
)/sizeof(*typeinfos
); i
++)
220 ITypeInfo_Release(typeinfos
[i
]);
222 ITypeLib_Release(typelib
);
225 static void add_func_info(dispex_data_t
*data
, DWORD
*size
, tid_t tid
, const FUNCDESC
*desc
, ITypeInfo
*dti
)
229 if(data
->func_cnt
&& data
->funcs
[data
->func_cnt
-1].id
== desc
->memid
)
232 if(data
->func_cnt
== *size
)
233 data
->funcs
= heap_realloc(data
->funcs
, (*size
<<= 1)*sizeof(func_info_t
));
235 hres
= ITypeInfo_GetDocumentation(dti
, desc
->memid
, &data
->funcs
[data
->func_cnt
].name
, NULL
, NULL
, NULL
);
239 data
->funcs
[data
->func_cnt
].id
= desc
->memid
;
240 data
->funcs
[data
->func_cnt
].tid
= tid
;
241 data
->funcs
[data
->func_cnt
].func_disp_idx
= (desc
->invkind
& DISPATCH_METHOD
) ? data
->func_disp_cnt
++ : -1;
246 static int dispid_cmp(const void *p1
, const void *p2
)
248 return ((func_info_t
*)p1
)->id
- ((func_info_t
*)p2
)->id
;
251 static int func_name_cmp(const void *p1
, const void *p2
)
253 return strcmpiW((*(func_info_t
**)p1
)->name
, (*(func_info_t
**)p2
)->name
);
256 static dispex_data_t
*preprocess_dispex_data(DispatchEx
*This
)
258 const tid_t
*tid
= This
->data
->iface_tids
;
265 TRACE("(%p)\n", This
);
267 if(This
->data
->disp_tid
) {
268 hres
= get_typeinfo(This
->data
->disp_tid
, &dti
);
270 ERR("Could not get disp type info: %08x\n", hres
);
275 data
= heap_alloc(sizeof(dispex_data_t
));
277 data
->func_disp_cnt
= 0;
278 data
->funcs
= heap_alloc(size
*sizeof(func_info_t
));
279 list_add_tail(&dispex_data_list
, &data
->entry
);
282 hres
= get_typeinfo(*tid
, &ti
);
288 hres
= ITypeInfo_GetFuncDesc(ti
, i
++, &funcdesc
);
292 add_func_info(data
, &size
, *tid
, funcdesc
, dti
);
293 ITypeInfo_ReleaseFuncDesc(ti
, funcdesc
);
299 if(!data
->func_cnt
) {
300 heap_free(data
->funcs
);
302 }else if(data
->func_cnt
!= size
) {
303 data
->funcs
= heap_realloc(data
->funcs
, data
->func_cnt
* sizeof(func_info_t
));
306 qsort(data
->funcs
, data
->func_cnt
, sizeof(func_info_t
), dispid_cmp
);
309 data
->name_table
= heap_alloc(data
->func_cnt
* sizeof(func_info_t
*));
310 for(i
=0; i
< data
->func_cnt
; i
++)
311 data
->name_table
[i
] = data
->funcs
+i
;
312 qsort(data
->name_table
, data
->func_cnt
, sizeof(func_info_t
*), func_name_cmp
);
314 data
->name_table
= NULL
;
320 static int id_cmp(const void *p1
, const void *p2
)
322 return *(DISPID
*)p1
- *(DISPID
*)p2
;
325 HRESULT
get_dispids(tid_t tid
, DWORD
*ret_size
, DISPID
**ret
)
327 unsigned i
, func_cnt
;
334 hres
= get_typeinfo(tid
, &ti
);
338 hres
= ITypeInfo_GetTypeAttr(ti
, &attr
);
340 ITypeInfo_Release(ti
);
344 func_cnt
= attr
->cFuncs
;
345 ITypeInfo_ReleaseTypeAttr(ti
, attr
);
347 ids
= heap_alloc(func_cnt
*sizeof(DISPID
));
349 ITypeInfo_Release(ti
);
350 return E_OUTOFMEMORY
;
353 for(i
=0; i
< func_cnt
; i
++) {
354 hres
= ITypeInfo_GetFuncDesc(ti
, i
, &funcdesc
);
358 ids
[i
] = funcdesc
->memid
;
359 ITypeInfo_ReleaseFuncDesc(ti
, funcdesc
);
362 ITypeInfo_Release(ti
);
368 qsort(ids
, func_cnt
, sizeof(DISPID
), id_cmp
);
370 *ret_size
= func_cnt
;
375 static CRITICAL_SECTION cs_dispex_static_data
;
376 static CRITICAL_SECTION_DEBUG cs_dispex_static_data_dbg
=
378 0, 0, &cs_dispex_static_data
,
379 { &cs_dispex_static_data_dbg
.ProcessLocksList
, &cs_dispex_static_data_dbg
.ProcessLocksList
},
380 0, 0, { (DWORD_PTR
)(__FILE__
": dispex_static_data") }
382 static CRITICAL_SECTION cs_dispex_static_data
= { &cs_dispex_static_data_dbg
, -1, 0, 0, 0, 0 };
385 static dispex_data_t
*get_dispex_data(DispatchEx
*This
)
388 return This
->data
->data
;
390 EnterCriticalSection(&cs_dispex_static_data
);
392 if(!This
->data
->data
)
393 This
->data
->data
= preprocess_dispex_data(This
);
395 LeaveCriticalSection(&cs_dispex_static_data
);
397 return This
->data
->data
;
400 HRESULT
call_disp_func(IDispatch
*disp
, DISPPARAMS
*dp
)
408 memset(&ei
, 0, sizeof(ei
));
410 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
411 if(SUCCEEDED(hres
)) {
412 hres
= IDispatchEx_InvokeEx(dispex
, 0, GetUserDefaultLCID(), DISPATCH_METHOD
, dp
, &res
, &ei
, NULL
);
413 IDispatchEx_Release(dispex
);
415 TRACE("Could not get IDispatchEx interface: %08x\n", hres
);
416 hres
= IDispatch_Invoke(disp
, 0, &IID_NULL
, GetUserDefaultLCID(), DISPATCH_METHOD
,
417 dp
, &res
, &ei
, NULL
);
424 static inline BOOL
is_custom_dispid(DISPID id
)
426 return MSHTML_DISPID_CUSTOM_MIN
<= id
&& id
<= MSHTML_DISPID_CUSTOM_MAX
;
429 static inline BOOL
is_dynamic_dispid(DISPID id
)
431 return DISPID_DYNPROP_0
<= id
&& id
<= DISPID_DYNPROP_MAX
;
434 static inline dispex_dynamic_data_t
*get_dynamic_data(DispatchEx
*This
, BOOL alloc
)
436 return !alloc
|| This
->dynamic_data
438 : (This
->dynamic_data
= heap_alloc_zero(sizeof(dispex_dynamic_data_t
)));
441 static HRESULT
get_dynamic_prop(DispatchEx
*This
, const WCHAR
*name
, DWORD flags
, dynamic_prop_t
**ret
)
443 const BOOL alloc
= flags
& fdexNameEnsure
;
444 dispex_dynamic_data_t
*data
;
447 data
= get_dynamic_data(This
, alloc
);
450 return E_OUTOFMEMORY
;
452 TRACE("not found %s\n", debugstr_w(name
));
453 return DISP_E_UNKNOWNNAME
;
456 for(i
=0; i
< data
->prop_cnt
; i
++) {
457 if(flags
& fdexNameCaseInsensitive
? !strcmpiW(data
->props
[i
].name
, name
) : !strcmpW(data
->props
[i
].name
, name
)) {
458 *ret
= data
->props
+i
;
464 return DISP_E_UNKNOWNNAME
;
466 TRACE("creating dynamic prop %s\n", debugstr_w(name
));
468 if(!data
->buf_size
) {
469 data
->props
= heap_alloc(sizeof(dynamic_prop_t
)*4);
471 return E_OUTOFMEMORY
;
473 }else if(data
->buf_size
== data
->prop_cnt
) {
474 dynamic_prop_t
*new_props
;
476 new_props
= heap_realloc(data
->props
, sizeof(dynamic_prop_t
)*(data
->buf_size
<<1));
478 return E_OUTOFMEMORY
;
480 data
->props
= new_props
;
481 data
->buf_size
<<= 1;
484 data
->props
[data
->prop_cnt
].name
= heap_strdupW(name
);
485 VariantInit(&data
->props
[data
->prop_cnt
].var
);
486 *ret
= data
->props
+ data
->prop_cnt
++;
491 HRESULT
dispex_get_dprop_ref(DispatchEx
*This
, const WCHAR
*name
, BOOL alloc
, VARIANT
**ret
)
493 dynamic_prop_t
*prop
;
496 hres
= get_dynamic_prop(This
, name
, alloc
? fdexNameEnsure
: 0, &prop
);
504 static HRESULT
dispex_value(DispatchEx
*This
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
505 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
507 if(This
->data
->vtbl
&& This
->data
->vtbl
->value
)
508 return This
->data
->vtbl
->value(This
->outer
, lcid
, flags
, params
, res
, ei
, caller
);
511 case DISPATCH_PROPERTYGET
:
513 V_BSTR(res
) = SysAllocString(objectW
);
515 return E_OUTOFMEMORY
;
518 FIXME("Unimplemented flags %x\n", flags
);
525 static HRESULT
typeinfo_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
533 hres
= get_typeinfo(func
->tid
, &ti
);
535 ERR("Could not get type info: %08x\n", hres
);
539 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&unk
);
541 ERR("Could not get iface %s: %08x\n", debugstr_guid(tid_ids
[func
->tid
]), hres
);
545 hres
= ITypeInfo_Invoke(ti
, unk
, func
->id
, flags
, dp
, res
, ei
, &argerr
);
547 IUnknown_Release(unk
);
551 #define FUNCTION_THIS(iface) DEFINE_THIS(func_disp_t, IUnknown, iface)
553 static HRESULT WINAPI
Function_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
555 func_disp_t
*This
= FUNCTION_THIS(iface
);
557 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
558 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
559 *ppv
= FUNCUNKNOWN(This
);
560 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
561 return *ppv
? S_OK
: E_NOINTERFACE
;
564 return E_NOINTERFACE
;
567 IUnknown_AddRef((IUnknown
*)*ppv
);
571 static ULONG WINAPI
Function_AddRef(IUnknown
*iface
)
573 func_disp_t
*This
= FUNCTION_THIS(iface
);
575 TRACE("(%p)\n", This
);
577 return IDispatchEx_AddRef(DISPATCHEX(This
->obj
));
580 static ULONG WINAPI
Function_Release(IUnknown
*iface
)
582 func_disp_t
*This
= FUNCTION_THIS(iface
);
584 TRACE("(%p)\n", This
);
586 return IDispatchEx_Release(DISPATCHEX(This
->obj
));
589 static HRESULT
function_value(IUnknown
*iface
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
590 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
592 func_disp_t
*This
= FUNCTION_THIS(iface
);
596 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
599 case DISPATCH_METHOD
:
600 hres
= typeinfo_invoke(This
->obj
, This
->info
, flags
, params
, res
, ei
);
603 FIXME("Unimplemented flags %x\n", flags
);
612 static const IUnknownVtbl FunctionUnkVtbl
= {
613 Function_QueryInterface
,
618 static const dispex_static_data_vtbl_t function_dispex_vtbl
= {
624 static const tid_t function_iface_tids
[] = {0};
626 static dispex_static_data_t function_dispex
= {
627 &function_dispex_vtbl
,
633 static func_disp_t
*create_func_disp(DispatchEx
*obj
, func_info_t
*info
)
637 ret
= heap_alloc_zero(sizeof(func_disp_t
));
641 ret
->lpIUnknownVtbl
= &FunctionUnkVtbl
;
642 init_dispex(&ret
->dispex
, FUNCUNKNOWN(ret
), &function_dispex
);
649 static HRESULT
function_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
655 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
658 case DISPATCH_METHOD
:
659 hres
= typeinfo_invoke(This
, func
, flags
, dp
, res
, ei
);
661 case DISPATCH_PROPERTYGET
: {
662 dispex_dynamic_data_t
*dynamic_data
;
664 if(func
->id
== DISPID_VALUE
) {
667 ret
= SysAllocString(objectW
);
669 return E_OUTOFMEMORY
;
676 dynamic_data
= get_dynamic_data(This
, TRUE
);
678 return E_OUTOFMEMORY
;
680 if(!dynamic_data
->func_disps
) {
681 dynamic_data
->func_disps
= heap_alloc_zero(This
->data
->data
->func_disp_cnt
* sizeof(func_disp_t
*));
682 if(!dynamic_data
->func_disps
)
683 return E_OUTOFMEMORY
;
686 if(!dynamic_data
->func_disps
[func
->func_disp_idx
]) {
687 dynamic_data
->func_disps
[func
->func_disp_idx
] = create_func_disp(This
, func
);
688 if(!dynamic_data
->func_disps
[func
->func_disp_idx
])
689 return E_OUTOFMEMORY
;
692 V_VT(res
) = VT_DISPATCH
;
693 V_DISPATCH(res
) = (IDispatch
*)DISPATCHEX(&dynamic_data
->func_disps
[func
->func_disp_idx
]->dispex
);
694 IDispatch_AddRef(V_DISPATCH(res
));
699 FIXME("Unimplemented flags %x\n", flags
);
700 case DISPATCH_PROPERTYPUT
:
707 static HRESULT
get_builtin_func(dispex_data_t
*data
, DISPID id
, func_info_t
**ret
)
712 max
= data
->func_cnt
-1;
717 if(data
->funcs
[n
].id
== id
) {
718 *ret
= data
->funcs
+n
;
722 if(data
->funcs
[n
].id
< id
)
728 WARN("invalid id %x\n", id
);
729 return DISP_E_UNKNOWNNAME
;
732 static HRESULT
get_builtin_id(DispatchEx
*This
, BSTR name
, DWORD grfdex
, DISPID
*ret
)
737 data
= get_dispex_data(This
);
742 max
= data
->func_cnt
-1;
747 c
= strcmpiW(data
->name_table
[n
]->name
, name
);
749 if((grfdex
& fdexNameCaseSensitive
) && strcmpW(data
->name_table
[n
]->name
, name
))
752 *ret
= data
->name_table
[n
]->id
;
762 if(This
->data
->vtbl
&& This
->data
->vtbl
->get_dispid
) {
765 hres
= This
->data
->vtbl
->get_dispid(This
->outer
, name
, grfdex
, ret
);
766 if(hres
!= DISP_E_UNKNOWNNAME
)
770 return DISP_E_UNKNOWNNAME
;
773 static HRESULT
invoke_builtin_prop(DispatchEx
*This
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
774 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
780 data
= get_dispex_data(This
);
784 hres
= get_builtin_func(data
, id
, &func
);
785 if(id
== DISPID_VALUE
&& hres
== DISP_E_UNKNOWNNAME
)
786 return dispex_value(This
, lcid
, flags
, dp
, res
, ei
, caller
);
790 if(func
->func_disp_idx
== -1)
791 hres
= typeinfo_invoke(This
, func
, flags
, dp
, res
, ei
);
793 hres
= function_invoke(This
, func
, flags
, dp
, res
, ei
);
798 #define DISPATCHEX_THIS(iface) DEFINE_THIS(DispatchEx, IDispatchEx, iface)
800 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
802 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
804 return IUnknown_QueryInterface(This
->outer
, riid
, ppv
);
807 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
809 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
811 return IUnknown_AddRef(This
->outer
);
814 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
816 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
818 return IUnknown_Release(This
->outer
);
821 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
823 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
825 TRACE("(%p)->(%p)\n", This
, pctinfo
);
831 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
832 LCID lcid
, ITypeInfo
**ppTInfo
)
834 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
837 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
839 hres
= get_typeinfo(This
->data
->disp_tid
, ppTInfo
);
843 ITypeInfo_AddRef(*ppTInfo
);
847 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
848 LPOLESTR
*rgszNames
, UINT cNames
,
849 LCID lcid
, DISPID
*rgDispId
)
851 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
855 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
858 for(i
=0; i
< cNames
; i
++) {
859 hres
= IDispatchEx_GetDispID(DISPATCHEX(This
), rgszNames
[i
], 0, rgDispId
+i
);
867 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
868 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
869 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
871 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
873 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
874 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
876 return IDispatchEx_InvokeEx(DISPATCHEX(This
), dispIdMember
, lcid
, wFlags
,
877 pDispParams
, pVarResult
, pExcepInfo
, NULL
);
880 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
882 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
883 dynamic_prop_t
*dprop
;
886 TRACE("(%p)->(%s %x %p)\n", This
, debugstr_w(bstrName
), grfdex
, pid
);
888 if(grfdex
& ~(fdexNameCaseSensitive
|fdexNameCaseInsensitive
|fdexNameEnsure
|fdexNameImplicit
|FDEX_VERSION_MASK
))
889 FIXME("Unsupported grfdex %x\n", grfdex
);
891 hres
= get_builtin_id(This
, bstrName
, grfdex
, pid
);
892 if(hres
!= DISP_E_UNKNOWNNAME
)
895 hres
= get_dynamic_prop(This
, bstrName
, grfdex
, &dprop
);
899 *pid
= DISPID_DYNPROP_0
+ (dprop
- This
->dynamic_data
->props
);
903 static HRESULT WINAPI
DispatchEx_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
904 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
906 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
909 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
911 if(is_custom_dispid(id
) && This
->data
->vtbl
&& This
->data
->vtbl
->invoke
)
912 return This
->data
->vtbl
->invoke(This
->outer
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
914 if(wFlags
== DISPATCH_CONSTRUCT
) {
915 if(id
== DISPID_VALUE
) {
916 if(This
->data
->vtbl
&& This
->data
->vtbl
->value
) {
917 return This
->data
->vtbl
->value(This
->outer
, lcid
, wFlags
, pdp
,
918 pvarRes
, pei
, pspCaller
);
920 FIXME("DISPATCH_CONSTRUCT flag but missing value function\n");
923 FIXME("DISPATCH_CONSTRUCT flag without DISPID_VALUE\n");
927 if(is_dynamic_dispid(id
)) {
928 DWORD idx
= id
- DISPID_DYNPROP_0
;
931 if(!This
->dynamic_data
|| This
->dynamic_data
->prop_cnt
<= idx
)
932 return DISP_E_UNKNOWNNAME
;
934 var
= &This
->dynamic_data
->props
[idx
].var
;
937 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
940 case DISPATCH_METHOD
: {
941 DISPID named_arg
= DISPID_THIS
;
942 DISPPARAMS dp
= {NULL
, &named_arg
, 0, 1};
945 if(V_VT(var
) != VT_DISPATCH
) {
946 FIXME("invoke vt %d\n", V_VT(var
));
950 if(pdp
->cNamedArgs
) {
951 FIXME("named args not supported\n");
955 dp
.rgvarg
= heap_alloc((pdp
->cArgs
+1)*sizeof(VARIANTARG
));
957 return E_OUTOFMEMORY
;
959 dp
.cArgs
= pdp
->cArgs
+1;
960 memcpy(dp
.rgvarg
+1, pdp
->rgvarg
, pdp
->cArgs
*sizeof(VARIANTARG
));
962 V_VT(dp
.rgvarg
) = VT_DISPATCH
;
963 V_DISPATCH(dp
.rgvarg
) = (IDispatch
*)DISPATCHEX(This
);
965 hres
= IDispatch_QueryInterface(V_DISPATCH(var
), &IID_IDispatchEx
, (void**)&dispex
);
966 TRACE("%s call\n", debugstr_w(This
->dynamic_data
->props
[idx
].name
));
967 if(SUCCEEDED(hres
)) {
968 hres
= IDispatchEx_InvokeEx(dispex
, DISPID_VALUE
, lcid
, wFlags
, &dp
, pvarRes
, pei
, pspCaller
);
969 IDispatchEx_Release(dispex
);
972 hres
= IDispatch_Invoke(V_DISPATCH(var
), DISPID_VALUE
, &IID_NULL
, lcid
, wFlags
, pdp
, pvarRes
, pei
, &err
);
974 TRACE("%s ret %08x\n", debugstr_w(This
->dynamic_data
->props
[idx
].name
), hres
);
976 heap_free(dp
.rgvarg
);
979 case DISPATCH_PROPERTYGET
:
980 return VariantCopy(pvarRes
, var
);
981 case DISPATCH_PROPERTYPUT
|DISPATCH_PROPERTYPUTREF
:
982 case DISPATCH_PROPERTYPUT
:
983 if(pdp
->cArgs
!= 1 || (pdp
->cNamedArgs
== 1 && *pdp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
984 || pdp
->cNamedArgs
> 1) {
985 FIXME("invalid args\n");
989 TRACE("put %s\n", debugstr_variant(pdp
->rgvarg
));
991 return VariantCopy(var
, pdp
->rgvarg
);
993 FIXME("unhandled wFlags %x\n", wFlags
);
998 return invoke_builtin_prop(This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1001 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
1003 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
1005 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(bstrName
), grfdex
);
1007 /* Not implemented by IE */
1011 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
1013 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
1014 FIXME("(%p)->(%x)\n", This
, id
);
1018 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
1020 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
1021 FIXME("(%p)->(%x %x %p)\n", This
, id
, grfdexFetch
, pgrfdex
);
1025 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
1027 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
1028 dispex_data_t
*data
;
1032 TRACE("(%p)->(%x %p)\n", This
, id
, pbstrName
);
1034 if(is_dynamic_dispid(id
)) {
1035 DWORD idx
= id
- DISPID_DYNPROP_0
;
1037 if(!This
->dynamic_data
|| This
->dynamic_data
->prop_cnt
<= idx
)
1038 return DISP_E_UNKNOWNNAME
;
1040 *pbstrName
= SysAllocString(This
->dynamic_data
->props
[idx
].name
);
1042 return E_OUTOFMEMORY
;
1047 data
= get_dispex_data(This
);
1051 hres
= get_builtin_func(data
, id
, &func
);
1055 *pbstrName
= SysAllocString(func
->name
);
1057 return E_OUTOFMEMORY
;
1061 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
1063 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
1064 dispex_data_t
*data
;
1068 TRACE("(%p)->(%x %x %p)\n", This
, grfdex
, id
, pid
);
1070 if(is_dynamic_dispid(id
)) {
1071 DWORD idx
= id
- DISPID_DYNPROP_0
;
1073 if(!This
->dynamic_data
|| This
->dynamic_data
->prop_cnt
<= idx
)
1074 return DISP_E_UNKNOWNNAME
;
1076 if(idx
+1 == This
->dynamic_data
->prop_cnt
) {
1077 *pid
= DISPID_STARTENUM
;
1085 data
= get_dispex_data(This
);
1089 if(id
== DISPID_STARTENUM
) {
1092 hres
= get_builtin_func(data
, id
, &func
);
1098 while(func
< data
->funcs
+data
->func_cnt
) {
1099 /* FIXME: Skip hidden properties */
1100 if(func
->func_disp_idx
== -1) {
1107 if(This
->dynamic_data
&& This
->dynamic_data
->prop_cnt
) {
1108 *pid
= DISPID_DYNPROP_0
;
1112 *pid
= DISPID_STARTENUM
;
1116 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
1118 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
1119 FIXME("(%p)->(%p)\n", This
, ppunk
);
1123 #undef DISPATCHEX_THIS
1125 static IDispatchExVtbl DispatchExVtbl
= {
1126 DispatchEx_QueryInterface
,
1129 DispatchEx_GetTypeInfoCount
,
1130 DispatchEx_GetTypeInfo
,
1131 DispatchEx_GetIDsOfNames
,
1133 DispatchEx_GetDispID
,
1134 DispatchEx_InvokeEx
,
1135 DispatchEx_DeleteMemberByName
,
1136 DispatchEx_DeleteMemberByDispID
,
1137 DispatchEx_GetMemberProperties
,
1138 DispatchEx_GetMemberName
,
1139 DispatchEx_GetNextDispID
,
1140 DispatchEx_GetNameSpaceParent
1143 BOOL
dispex_query_interface(DispatchEx
*This
, REFIID riid
, void **ppv
)
1145 static const IID IID_UndocumentedScriptIface
=
1146 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa0}};
1147 static const IID IID_IDispatchJS
=
1148 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa6}};
1150 if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1151 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1152 *ppv
= DISPATCHEX(This
);
1153 }else if(IsEqualGUID(&IID_IDispatchEx
, riid
)) {
1154 TRACE("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
1155 *ppv
= DISPATCHEX(This
);
1156 }else if(IsEqualGUID(&IID_IDispatchJS
, riid
)) {
1157 TRACE("(%p)->(IID_IDispatchJS %p) returning NULL\n", This
, ppv
);
1159 }else if(IsEqualGUID(&IID_UndocumentedScriptIface
, riid
)) {
1160 TRACE("(%p)->(IID_UndocumentedScriptIface %p) returning NULL\n", This
, ppv
);
1167 IUnknown_AddRef((IUnknown
*)*ppv
);
1171 void release_dispex(DispatchEx
*This
)
1173 dynamic_prop_t
*prop
;
1175 if(!This
->dynamic_data
)
1178 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
1179 VariantClear(&prop
->var
);
1180 heap_free(prop
->name
);
1183 heap_free(This
->dynamic_data
->props
);
1185 if(This
->dynamic_data
->func_disps
) {
1188 for(i
=0; i
< This
->data
->data
->func_disp_cnt
; i
++) {
1189 if(This
->dynamic_data
->func_disps
[i
]) {
1190 release_dispex(&This
->dynamic_data
->func_disps
[i
]->dispex
);
1191 heap_free(This
->dynamic_data
->func_disps
[i
]);
1195 heap_free(This
->dynamic_data
->func_disps
);
1198 heap_free(This
->dynamic_data
);
1201 void init_dispex(DispatchEx
*dispex
, IUnknown
*outer
, dispex_static_data_t
*data
)
1203 dispex
->lpIDispatchExVtbl
= &DispatchExVtbl
;
1204 dispex
->outer
= outer
;
1205 dispex
->data
= data
;
1206 dispex
->dynamic_data
= NULL
;