2 * Copyright 2008 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
19 #include "mshtml_private.h"
21 static inline HTMLScriptElement
*impl_from_IHTMLScriptElement(IHTMLScriptElement
*iface
)
23 return CONTAINING_RECORD(iface
, HTMLScriptElement
, IHTMLScriptElement_iface
);
26 static HRESULT WINAPI
HTMLScriptElement_QueryInterface(IHTMLScriptElement
*iface
,
27 REFIID riid
, void **ppv
)
29 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
31 return IHTMLDOMNode_QueryInterface(&This
->element
.node
.IHTMLDOMNode_iface
, riid
, ppv
);
34 static ULONG WINAPI
HTMLScriptElement_AddRef(IHTMLScriptElement
*iface
)
36 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
38 return IHTMLDOMNode_AddRef(&This
->element
.node
.IHTMLDOMNode_iface
);
41 static ULONG WINAPI
HTMLScriptElement_Release(IHTMLScriptElement
*iface
)
43 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
45 return IHTMLDOMNode_Release(&This
->element
.node
.IHTMLDOMNode_iface
);
48 static HRESULT WINAPI
HTMLScriptElement_GetTypeInfoCount(IHTMLScriptElement
*iface
, UINT
*pctinfo
)
50 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
51 return IDispatchEx_GetTypeInfoCount(&This
->element
.node
.dispex
.IDispatchEx_iface
, pctinfo
);
54 static HRESULT WINAPI
HTMLScriptElement_GetTypeInfo(IHTMLScriptElement
*iface
, UINT iTInfo
,
55 LCID lcid
, ITypeInfo
**ppTInfo
)
57 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
58 return IDispatchEx_GetTypeInfo(&This
->element
.node
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
,
62 static HRESULT WINAPI
HTMLScriptElement_GetIDsOfNames(IHTMLScriptElement
*iface
, REFIID riid
,
63 LPOLESTR
*rgszNames
, UINT cNames
,
64 LCID lcid
, DISPID
*rgDispId
)
66 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
67 return IDispatchEx_GetIDsOfNames(&This
->element
.node
.dispex
.IDispatchEx_iface
, riid
, rgszNames
,
68 cNames
, lcid
, rgDispId
);
71 static HRESULT WINAPI
HTMLScriptElement_Invoke(IHTMLScriptElement
*iface
, DISPID dispIdMember
,
72 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
73 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
75 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
76 return IDispatchEx_Invoke(&This
->element
.node
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
,
77 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
80 static HRESULT WINAPI
HTMLScriptElement_put_src(IHTMLScriptElement
*iface
, BSTR v
)
82 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
83 HTMLInnerWindow
*window
;
88 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
90 if(!This
->element
.node
.doc
|| !This
->element
.node
.doc
->window
) {
95 window
= This
->element
.node
.doc
->window
;
97 nsAString_InitDepend(&src_str
, v
);
98 nsres
= nsIDOMHTMLScriptElement_SetSrc(This
->nsscript
, &src_str
);
99 nsAString_Finish(&src_str
);
100 if(NS_FAILED(nsres
)) {
101 ERR("SetSrc failed: %08x\n", nsres
);
106 WARN("already parsed\n");
110 if(window
->parser_callback_cnt
) {
111 script_queue_entry_t
*queue
;
113 queue
= heap_alloc(sizeof(*queue
));
115 return E_OUTOFMEMORY
;
117 IHTMLScriptElement_AddRef(&This
->IHTMLScriptElement_iface
);
118 queue
->script
= This
;
120 list_add_tail(&window
->script_queue
, &queue
->entry
);
124 nsres
= nsIDOMHTMLScriptElement_GetParentNode(This
->nsscript
, &parent
);
125 if(NS_FAILED(nsres
) || !parent
) {
126 TRACE("No parent, not executing\n");
127 This
->parse_on_bind
= TRUE
;
131 nsIDOMNode_Release(parent
);
132 doc_insert_script(window
, This
);
136 static HRESULT WINAPI
HTMLScriptElement_get_src(IHTMLScriptElement
*iface
, BSTR
*p
)
138 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
142 TRACE("(%p)->(%p)\n", This
, p
);
144 nsAString_Init(&src_str
, NULL
);
145 nsres
= nsIDOMHTMLScriptElement_GetSrc(This
->nsscript
, &src_str
);
146 return return_nsstr(nsres
, &src_str
, p
);
149 static HRESULT WINAPI
HTMLScriptElement_put_htmlFor(IHTMLScriptElement
*iface
, BSTR v
)
151 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
152 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
156 static HRESULT WINAPI
HTMLScriptElement_get_htmlFor(IHTMLScriptElement
*iface
, BSTR
*p
)
158 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
159 FIXME("(%p)->(%p)\n", This
, p
);
163 static HRESULT WINAPI
HTMLScriptElement_put_event(IHTMLScriptElement
*iface
, BSTR v
)
165 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
166 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
170 static HRESULT WINAPI
HTMLScriptElement_get_event(IHTMLScriptElement
*iface
, BSTR
*p
)
172 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
173 FIXME("(%p)->(%p)\n", This
, p
);
177 static HRESULT WINAPI
HTMLScriptElement_put_text(IHTMLScriptElement
*iface
, BSTR v
)
179 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
180 HTMLInnerWindow
*window
;
185 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
187 if(!This
->element
.node
.doc
|| !This
->element
.node
.doc
->window
) {
188 WARN("no windoow\n");
192 window
= This
->element
.node
.doc
->window
;
194 nsAString_InitDepend(&text_str
, v
);
195 nsres
= nsIDOMHTMLScriptElement_SetText(This
->nsscript
, &text_str
);
196 nsAString_Finish(&text_str
);
197 if(NS_FAILED(nsres
)) {
198 ERR("SetSrc failed: %08x\n", nsres
);
202 nsres
= nsIDOMHTMLScriptElement_GetParentNode(This
->nsscript
, &parent
);
203 if(NS_FAILED(nsres
) || !parent
) {
204 TRACE("No parent, not executing\n");
205 This
->parse_on_bind
= TRUE
;
209 nsIDOMNode_Release(parent
);
210 doc_insert_script(window
, This
);
214 static HRESULT WINAPI
HTMLScriptElement_get_text(IHTMLScriptElement
*iface
, BSTR
*p
)
216 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
220 TRACE("(%p)->(%p)\n", This
, p
);
222 nsAString_Init(&nsstr
, NULL
);
223 nsres
= nsIDOMHTMLScriptElement_GetText(This
->nsscript
, &nsstr
);
224 return return_nsstr(nsres
, &nsstr
, p
);
227 static HRESULT WINAPI
HTMLScriptElement_put_defer(IHTMLScriptElement
*iface
, VARIANT_BOOL v
)
229 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
233 TRACE("(%p)->(%x)\n", This
, v
);
235 nsres
= nsIDOMHTMLScriptElement_SetDefer(This
->nsscript
, v
!= VARIANT_FALSE
);
244 static HRESULT WINAPI
HTMLScriptElement_get_defer(IHTMLScriptElement
*iface
, VARIANT_BOOL
*p
)
246 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
247 cpp_bool defer
= FALSE
;
250 TRACE("(%p)->(%p)\n", This
, p
);
255 nsres
= nsIDOMHTMLScriptElement_GetDefer(This
->nsscript
, &defer
);
256 if(NS_FAILED(nsres
)) {
257 ERR("GetSrc failed: %08x\n", nsres
);
260 *p
= defer
? VARIANT_TRUE
: VARIANT_FALSE
;
262 TRACE("*p = %d\n", *p
);
266 static HRESULT WINAPI
HTMLScriptElement_get_readyState(IHTMLScriptElement
*iface
, BSTR
*p
)
268 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
269 FIXME("(%p)->(%p)\n", This
, p
);
273 static HRESULT WINAPI
HTMLScriptElement_put_onerror(IHTMLScriptElement
*iface
, VARIANT v
)
275 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
276 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&v
));
280 static HRESULT WINAPI
HTMLScriptElement_get_onerror(IHTMLScriptElement
*iface
, VARIANT
*p
)
282 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
283 FIXME("(%p)->(%p)\n", This
, p
);
287 static HRESULT WINAPI
HTMLScriptElement_put_type(IHTMLScriptElement
*iface
, BSTR v
)
289 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
290 nsAString nstype_str
;
293 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
295 nsAString_Init(&nstype_str
, v
);
296 nsres
= nsIDOMHTMLScriptElement_SetType(This
->nsscript
, &nstype_str
);
297 if (NS_FAILED(nsres
))
298 ERR("SetType failed: %08x\n", nsres
);
299 nsAString_Finish (&nstype_str
);
304 static HRESULT WINAPI
HTMLScriptElement_get_type(IHTMLScriptElement
*iface
, BSTR
*p
)
306 HTMLScriptElement
*This
= impl_from_IHTMLScriptElement(iface
);
307 nsAString nstype_str
;
310 TRACE("(%p)->(%p)\n", This
, p
);
312 nsAString_Init(&nstype_str
, NULL
);
313 nsres
= nsIDOMHTMLScriptElement_GetType(This
->nsscript
, &nstype_str
);
314 return return_nsstr(nsres
, &nstype_str
, p
);
317 static const IHTMLScriptElementVtbl HTMLScriptElementVtbl
= {
318 HTMLScriptElement_QueryInterface
,
319 HTMLScriptElement_AddRef
,
320 HTMLScriptElement_Release
,
321 HTMLScriptElement_GetTypeInfoCount
,
322 HTMLScriptElement_GetTypeInfo
,
323 HTMLScriptElement_GetIDsOfNames
,
324 HTMLScriptElement_Invoke
,
325 HTMLScriptElement_put_src
,
326 HTMLScriptElement_get_src
,
327 HTMLScriptElement_put_htmlFor
,
328 HTMLScriptElement_get_htmlFor
,
329 HTMLScriptElement_put_event
,
330 HTMLScriptElement_get_event
,
331 HTMLScriptElement_put_text
,
332 HTMLScriptElement_get_text
,
333 HTMLScriptElement_put_defer
,
334 HTMLScriptElement_get_defer
,
335 HTMLScriptElement_get_readyState
,
336 HTMLScriptElement_put_onerror
,
337 HTMLScriptElement_get_onerror
,
338 HTMLScriptElement_put_type
,
339 HTMLScriptElement_get_type
342 static inline HTMLScriptElement
*impl_from_HTMLDOMNode(HTMLDOMNode
*iface
)
344 return CONTAINING_RECORD(iface
, HTMLScriptElement
, element
.node
);
347 static HRESULT
HTMLScriptElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
349 HTMLScriptElement
*This
= impl_from_HTMLDOMNode(iface
);
353 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
354 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
355 *ppv
= &This
->IHTMLScriptElement_iface
;
356 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
357 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
358 *ppv
= &This
->IHTMLScriptElement_iface
;
359 }else if(IsEqualGUID(&IID_IHTMLScriptElement
, riid
)) {
360 TRACE("(%p)->(IID_IHTMLScriptElement %p)\n", This
, ppv
);
361 *ppv
= &This
->IHTMLScriptElement_iface
;
365 IUnknown_AddRef((IUnknown
*)*ppv
);
369 return HTMLElement_QI(&This
->element
.node
, riid
, ppv
);
372 static HRESULT
HTMLScriptElement_get_readystate(HTMLDOMNode
*iface
, BSTR
*p
)
374 HTMLScriptElement
*This
= impl_from_HTMLDOMNode(iface
);
376 return IHTMLScriptElement_get_readyState(&This
->IHTMLScriptElement_iface
, p
);
379 static const NodeImplVtbl HTMLScriptElementImplVtbl
= {
380 HTMLScriptElement_QI
,
381 HTMLElement_destructor
,
384 HTMLElement_handle_event
,
385 HTMLElement_get_attr_col
,
391 HTMLScriptElement_get_readystate
394 HRESULT
script_elem_from_nsscript(HTMLDocumentNode
*doc
, nsIDOMHTMLScriptElement
*nsscript
, HTMLScriptElement
**ret
)
399 hres
= get_node(doc
, (nsIDOMNode
*)nsscript
, TRUE
, &node
);
403 assert(node
->vtbl
== &HTMLScriptElementImplVtbl
);
404 *ret
= impl_from_HTMLDOMNode(node
);
408 static const tid_t HTMLScriptElement_iface_tids
[] = {
410 IHTMLScriptElement_tid
,
414 static dispex_static_data_t HTMLScriptElement_dispex
= {
416 DispHTMLScriptElement_tid
,
418 HTMLScriptElement_iface_tids
421 HRESULT
HTMLScriptElement_Create(HTMLDocumentNode
*doc
, nsIDOMHTMLElement
*nselem
, HTMLElement
**elem
)
423 HTMLScriptElement
*ret
;
426 ret
= heap_alloc_zero(sizeof(HTMLScriptElement
));
428 return E_OUTOFMEMORY
;
430 ret
->IHTMLScriptElement_iface
.lpVtbl
= &HTMLScriptElementVtbl
;
431 ret
->element
.node
.vtbl
= &HTMLScriptElementImplVtbl
;
433 HTMLElement_Init(&ret
->element
, doc
, nselem
, &HTMLScriptElement_dispex
);
435 nsres
= nsIDOMHTMLElement_QueryInterface(nselem
, &IID_nsIDOMHTMLScriptElement
, (void**)&ret
->nsscript
);
437 /* Share nsscript reference with nsnode */
438 assert(nsres
== NS_OK
&& (nsIDOMNode
*)ret
->nsscript
== ret
->element
.node
.nsnode
);
439 nsIDOMNode_Release(ret
->element
.node
.nsnode
);
441 *elem
= &ret
->element
;