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 #define DISPATCHEX_THIS(iface) DEFINE_THIS(DispatchEx, IDispatchEx, iface)
734 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
736 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
738 return IUnknown_QueryInterface(This
->outer
, riid
, ppv
);
741 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
743 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
745 return IUnknown_AddRef(This
->outer
);
748 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
750 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
752 return IUnknown_Release(This
->outer
);
755 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
757 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
759 TRACE("(%p)->(%p)\n", This
, pctinfo
);
765 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
766 LCID lcid
, ITypeInfo
**ppTInfo
)
768 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
771 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
773 hres
= get_typeinfo(This
->data
->disp_tid
, ppTInfo
);
777 ITypeInfo_AddRef(*ppTInfo
);
781 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
782 LPOLESTR
*rgszNames
, UINT cNames
,
783 LCID lcid
, DISPID
*rgDispId
)
785 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
789 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
792 for(i
=0; i
< cNames
; i
++) {
793 hres
= IDispatchEx_GetDispID(DISPATCHEX(This
), rgszNames
[i
], 0, rgDispId
+i
);
801 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
802 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
803 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
805 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
807 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
808 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
810 return IDispatchEx_InvokeEx(DISPATCHEX(This
), dispIdMember
, lcid
, wFlags
,
811 pDispParams
, pVarResult
, pExcepInfo
, NULL
);
814 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
816 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
817 dynamic_prop_t
*dprop
;
822 TRACE("(%p)->(%s %x %p)\n", This
, debugstr_w(bstrName
), grfdex
, pid
);
824 if(grfdex
& ~(fdexNameCaseSensitive
|fdexNameCaseInsensitive
|fdexNameEnsure
|fdexNameImplicit
|FDEX_VERSION_MASK
))
825 FIXME("Unsupported grfdex %x\n", grfdex
);
827 data
= get_dispex_data(This
);
832 max
= data
->func_cnt
-1;
837 c
= strcmpiW(data
->name_table
[n
]->name
, bstrName
);
839 if((grfdex
& fdexNameCaseSensitive
) && strcmpW(data
->name_table
[n
]->name
, bstrName
))
842 *pid
= data
->name_table
[n
]->id
;
852 if(This
->data
->vtbl
&& This
->data
->vtbl
->get_dispid
) {
855 hres
= This
->data
->vtbl
->get_dispid(This
->outer
, bstrName
, grfdex
, pid
);
856 if(hres
!= DISP_E_UNKNOWNNAME
)
860 hres
= get_dynamic_prop(This
, bstrName
, grfdex
, &dprop
);
864 *pid
= DISPID_DYNPROP_0
+ (dprop
- This
->dynamic_data
->props
);
868 static HRESULT WINAPI
DispatchEx_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
869 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
871 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
876 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
878 if(is_custom_dispid(id
) && This
->data
->vtbl
&& This
->data
->vtbl
->invoke
)
879 return This
->data
->vtbl
->invoke(This
->outer
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
881 if(wFlags
== DISPATCH_CONSTRUCT
) {
882 if(id
== DISPID_VALUE
) {
883 if(This
->data
->vtbl
&& This
->data
->vtbl
->value
) {
884 return This
->data
->vtbl
->value(This
->outer
, lcid
, wFlags
, pdp
,
885 pvarRes
, pei
, pspCaller
);
887 FIXME("DISPATCH_CONSTRUCT flag but missing value function\n");
890 FIXME("DISPATCH_CONSTRUCT flag without DISPID_VALUE\n");
894 if(is_dynamic_dispid(id
)) {
895 DWORD idx
= id
- DISPID_DYNPROP_0
;
898 if(!This
->dynamic_data
|| This
->dynamic_data
->prop_cnt
<= idx
)
899 return DISP_E_UNKNOWNNAME
;
901 var
= &This
->dynamic_data
->props
[idx
].var
;
904 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
907 case DISPATCH_METHOD
: {
908 DISPID named_arg
= DISPID_THIS
;
909 DISPPARAMS dp
= {NULL
, &named_arg
, 0, 1};
912 if(V_VT(var
) != VT_DISPATCH
) {
913 FIXME("invoke vt %d\n", V_VT(var
));
917 if(pdp
->cNamedArgs
) {
918 FIXME("named args not supported\n");
922 dp
.rgvarg
= heap_alloc((pdp
->cArgs
+1)*sizeof(VARIANTARG
));
924 return E_OUTOFMEMORY
;
926 dp
.cArgs
= pdp
->cArgs
+1;
927 memcpy(dp
.rgvarg
+1, pdp
->rgvarg
, pdp
->cArgs
*sizeof(VARIANTARG
));
929 V_VT(dp
.rgvarg
) = VT_DISPATCH
;
930 V_DISPATCH(dp
.rgvarg
) = (IDispatch
*)DISPATCHEX(This
);
932 hres
= IDispatch_QueryInterface(V_DISPATCH(var
), &IID_IDispatchEx
, (void**)&dispex
);
933 TRACE("%s call\n", debugstr_w(This
->dynamic_data
->props
[idx
].name
));
934 if(SUCCEEDED(hres
)) {
935 hres
= IDispatchEx_InvokeEx(dispex
, DISPID_VALUE
, lcid
, wFlags
, &dp
, pvarRes
, pei
, pspCaller
);
936 IDispatchEx_Release(dispex
);
939 hres
= IDispatch_Invoke(V_DISPATCH(var
), DISPID_VALUE
, &IID_NULL
, lcid
, wFlags
, pdp
, pvarRes
, pei
, &err
);
941 TRACE("%s ret %08x\n", debugstr_w(This
->dynamic_data
->props
[idx
].name
), hres
);
943 heap_free(dp
.rgvarg
);
946 case DISPATCH_PROPERTYGET
:
947 return VariantCopy(pvarRes
, var
);
948 case DISPATCH_PROPERTYPUT
|DISPATCH_PROPERTYPUTREF
:
949 case DISPATCH_PROPERTYPUT
:
950 if(pdp
->cArgs
!= 1 || (pdp
->cNamedArgs
== 1 && *pdp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
951 || pdp
->cNamedArgs
> 1) {
952 FIXME("invalid args\n");
956 TRACE("put %s\n", debugstr_variant(pdp
->rgvarg
));
958 return VariantCopy(var
, pdp
->rgvarg
);
960 FIXME("unhandled wFlags %x\n", wFlags
);
965 data
= get_dispex_data(This
);
969 hres
= get_builtin_func(data
, id
, &func
);
970 if(id
== DISPID_VALUE
&& hres
== DISP_E_UNKNOWNNAME
)
971 return dispex_value(This
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
975 if(func
->func_disp_idx
== -1)
976 hres
= typeinfo_invoke(This
, func
, wFlags
, pdp
, pvarRes
, pei
);
978 hres
= function_invoke(This
, func
, wFlags
, pdp
, pvarRes
, pei
);
983 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
985 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
987 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(bstrName
), grfdex
);
989 /* Not implemented by IE */
993 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
995 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
996 FIXME("(%p)->(%x)\n", This
, id
);
1000 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
1002 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
1003 FIXME("(%p)->(%x %x %p)\n", This
, id
, grfdexFetch
, pgrfdex
);
1007 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
1009 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
1010 dispex_data_t
*data
;
1014 TRACE("(%p)->(%x %p)\n", This
, id
, pbstrName
);
1016 if(is_dynamic_dispid(id
)) {
1017 DWORD idx
= id
- DISPID_DYNPROP_0
;
1019 if(!This
->dynamic_data
|| This
->dynamic_data
->prop_cnt
<= idx
)
1020 return DISP_E_UNKNOWNNAME
;
1022 *pbstrName
= SysAllocString(This
->dynamic_data
->props
[idx
].name
);
1024 return E_OUTOFMEMORY
;
1029 data
= get_dispex_data(This
);
1033 hres
= get_builtin_func(data
, id
, &func
);
1037 *pbstrName
= SysAllocString(func
->name
);
1039 return E_OUTOFMEMORY
;
1043 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
1045 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
1046 dispex_data_t
*data
;
1050 TRACE("(%p)->(%x %x %p)\n", This
, grfdex
, id
, pid
);
1052 if(is_dynamic_dispid(id
)) {
1053 DWORD idx
= id
- DISPID_DYNPROP_0
;
1055 if(!This
->dynamic_data
|| This
->dynamic_data
->prop_cnt
<= idx
)
1056 return DISP_E_UNKNOWNNAME
;
1058 if(idx
+1 == This
->dynamic_data
->prop_cnt
) {
1059 *pid
= DISPID_STARTENUM
;
1067 data
= get_dispex_data(This
);
1071 if(id
== DISPID_STARTENUM
) {
1074 hres
= get_builtin_func(data
, id
, &func
);
1080 while(func
< data
->funcs
+data
->func_cnt
) {
1081 /* FIXME: Skip hidden properties */
1082 if(func
->func_disp_idx
== -1) {
1089 if(This
->dynamic_data
&& This
->dynamic_data
->prop_cnt
) {
1090 *pid
= DISPID_DYNPROP_0
;
1094 *pid
= DISPID_STARTENUM
;
1098 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
1100 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
1101 FIXME("(%p)->(%p)\n", This
, ppunk
);
1105 #undef DISPATCHEX_THIS
1107 static IDispatchExVtbl DispatchExVtbl
= {
1108 DispatchEx_QueryInterface
,
1111 DispatchEx_GetTypeInfoCount
,
1112 DispatchEx_GetTypeInfo
,
1113 DispatchEx_GetIDsOfNames
,
1115 DispatchEx_GetDispID
,
1116 DispatchEx_InvokeEx
,
1117 DispatchEx_DeleteMemberByName
,
1118 DispatchEx_DeleteMemberByDispID
,
1119 DispatchEx_GetMemberProperties
,
1120 DispatchEx_GetMemberName
,
1121 DispatchEx_GetNextDispID
,
1122 DispatchEx_GetNameSpaceParent
1125 BOOL
dispex_query_interface(DispatchEx
*This
, REFIID riid
, void **ppv
)
1127 static const IID IID_UndocumentedScriptIface
=
1128 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa0}};
1129 static const IID IID_IDispatchJS
=
1130 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa6}};
1132 if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1133 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1134 *ppv
= DISPATCHEX(This
);
1135 }else if(IsEqualGUID(&IID_IDispatchEx
, riid
)) {
1136 TRACE("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
1137 *ppv
= DISPATCHEX(This
);
1138 }else if(IsEqualGUID(&IID_IDispatchJS
, riid
)) {
1139 TRACE("(%p)->(IID_IDispatchJS %p) returning NULL\n", This
, ppv
);
1141 }else if(IsEqualGUID(&IID_UndocumentedScriptIface
, riid
)) {
1142 TRACE("(%p)->(IID_UndocumentedScriptIface %p) returning NULL\n", This
, ppv
);
1149 IUnknown_AddRef((IUnknown
*)*ppv
);
1153 void release_dispex(DispatchEx
*This
)
1155 dynamic_prop_t
*prop
;
1157 if(!This
->dynamic_data
)
1160 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
1161 VariantClear(&prop
->var
);
1162 heap_free(prop
->name
);
1165 heap_free(This
->dynamic_data
->props
);
1167 if(This
->dynamic_data
->func_disps
) {
1170 for(i
=0; i
< This
->data
->data
->func_disp_cnt
; i
++) {
1171 if(This
->dynamic_data
->func_disps
[i
]) {
1172 release_dispex(&This
->dynamic_data
->func_disps
[i
]->dispex
);
1173 heap_free(This
->dynamic_data
->func_disps
[i
]);
1177 heap_free(This
->dynamic_data
->func_disps
);
1180 heap_free(This
->dynamic_data
);
1183 void init_dispex(DispatchEx
*dispex
, IUnknown
*outer
, dispex_static_data_t
*data
)
1185 dispex
->lpIDispatchExVtbl
= &DispatchExVtbl
;
1186 dispex
->outer
= outer
;
1187 dispex
->data
= data
;
1188 dispex
->dynamic_data
= NULL
;