htmlscript.c 11.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright 2008 Jacek Caban for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include <stdarg.h>
20
#include <assert.h>
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

#define COBJMACROS

#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "ole2.h"

#include "wine/debug.h"

#include "mshtml_private.h"

WINE_DEFAULT_DEBUG_CHANNEL(mshtml);

typedef struct {
    HTMLElement element;

38
    IHTMLScriptElement IHTMLScriptElement_iface;
39 40

    nsIDOMHTMLScriptElement *nsscript;
41 42
} HTMLScriptElement;

43 44 45 46
static inline HTMLScriptElement *impl_from_IHTMLScriptElement(IHTMLScriptElement *iface)
{
    return CONTAINING_RECORD(iface, HTMLScriptElement, IHTMLScriptElement_iface);
}
47 48 49 50

static HRESULT WINAPI HTMLScriptElement_QueryInterface(IHTMLScriptElement *iface,
        REFIID riid, void **ppv)
{
51
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
52

53
    return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
54 55 56 57
}

static ULONG WINAPI HTMLScriptElement_AddRef(IHTMLScriptElement *iface)
{
58
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
59

60
    return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
61 62 63 64
}

static ULONG WINAPI HTMLScriptElement_Release(IHTMLScriptElement *iface)
{
65
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
66

67
    return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
68 69 70 71
}

static HRESULT WINAPI HTMLScriptElement_GetTypeInfoCount(IHTMLScriptElement *iface, UINT *pctinfo)
{
72
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
73
    return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
74 75 76 77 78
}

static HRESULT WINAPI HTMLScriptElement_GetTypeInfo(IHTMLScriptElement *iface, UINT iTInfo,
                                              LCID lcid, ITypeInfo **ppTInfo)
{
79
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
80 81
    return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
            ppTInfo);
82 83 84 85 86 87
}

static HRESULT WINAPI HTMLScriptElement_GetIDsOfNames(IHTMLScriptElement *iface, REFIID riid,
                                                LPOLESTR *rgszNames, UINT cNames,
                                                LCID lcid, DISPID *rgDispId)
{
88
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
89 90
    return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
            cNames, lcid, rgDispId);
91 92 93 94 95 96
}

static HRESULT WINAPI HTMLScriptElement_Invoke(IHTMLScriptElement *iface, DISPID dispIdMember,
                            REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
                            VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
97
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
98 99
    return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
            lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
100 101 102 103
}

static HRESULT WINAPI HTMLScriptElement_put_src(IHTMLScriptElement *iface, BSTR v)
{
104
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
105 106 107 108 109 110
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLScriptElement_get_src(IHTMLScriptElement *iface, BSTR *p)
{
111
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
112 113 114 115 116 117 118 119
    nsAString src_str;
    nsresult nsres;

    TRACE("(%p)->(%p)\n", This, p);

    nsAString_Init(&src_str, NULL);
    nsres = nsIDOMHTMLScriptElement_GetSrc(This->nsscript, &src_str);
    return return_nsstr(nsres, &src_str, p);
120 121 122 123
}

static HRESULT WINAPI HTMLScriptElement_put_htmlFor(IHTMLScriptElement *iface, BSTR v)
{
124
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
125 126 127 128 129 130
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLScriptElement_get_htmlFor(IHTMLScriptElement *iface, BSTR *p)
{
131
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
132 133 134 135 136 137
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLScriptElement_put_event(IHTMLScriptElement *iface, BSTR v)
{
138
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
139 140 141 142 143 144
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLScriptElement_get_event(IHTMLScriptElement *iface, BSTR *p)
{
145
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
146 147 148 149 150 151
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLScriptElement_put_text(IHTMLScriptElement *iface, BSTR v)
{
152
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
153 154 155 156 157 158
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLScriptElement_get_text(IHTMLScriptElement *iface, BSTR *p)
{
159
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
160 161 162 163 164 165
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLScriptElement_put_defer(IHTMLScriptElement *iface, VARIANT_BOOL v)
{
166
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
167 168 169 170 171 172 173 174 175 176 177 178
    HRESULT hr = S_OK;
    nsresult nsres;

    TRACE("(%p)->(%x)\n", This, v);

    nsres = nsIDOMHTMLScriptElement_SetDefer(This->nsscript, v != VARIANT_FALSE);
    if(NS_FAILED(nsres))
    {
        hr = E_FAIL;
    }

    return hr;
179 180 181 182
}

static HRESULT WINAPI HTMLScriptElement_get_defer(IHTMLScriptElement *iface, VARIANT_BOOL *p)
{
183
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
184
    cpp_bool defer = FALSE;
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
    nsresult nsres;

    TRACE("(%p)->(%p)\n", This, p);

    if(!p)
        return E_INVALIDARG;

    nsres = nsIDOMHTMLScriptElement_GetDefer(This->nsscript, &defer);
    if(NS_FAILED(nsres)) {
        ERR("GetSrc failed: %08x\n", nsres);
    }

    *p = defer ? VARIANT_TRUE : VARIANT_FALSE;

    TRACE("*p = %d\n", *p);
    return S_OK;
201 202 203 204
}

static HRESULT WINAPI HTMLScriptElement_get_readyState(IHTMLScriptElement *iface, BSTR *p)
{
205
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
206 207 208 209 210 211
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLScriptElement_put_onerror(IHTMLScriptElement *iface, VARIANT v)
{
212
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
213
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
214 215 216 217 218
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLScriptElement_get_onerror(IHTMLScriptElement *iface, VARIANT *p)
{
219
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
220 221 222 223 224 225
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLScriptElement_put_type(IHTMLScriptElement *iface, BSTR v)
{
226
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
227 228 229 230 231 232 233 234 235 236 237 238
    nsAString nstype_str;
    nsresult nsres;

    TRACE("(%p)->(%s)\n", This, debugstr_w(v));

    nsAString_Init(&nstype_str, v);
    nsres = nsIDOMHTMLScriptElement_SetType(This->nsscript, &nstype_str);
    if (NS_FAILED(nsres))
        ERR("SetType failed: %08x\n", nsres);
    nsAString_Finish (&nstype_str);

    return S_OK;
239 240 241 242
}

static HRESULT WINAPI HTMLScriptElement_get_type(IHTMLScriptElement *iface, BSTR *p)
{
243
    HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
244 245 246 247 248 249 250
    nsAString nstype_str;
    nsresult nsres;

    TRACE("(%p)->(%p)\n", This, p);

    nsAString_Init(&nstype_str, NULL);
    nsres = nsIDOMHTMLScriptElement_GetType(This->nsscript, &nstype_str);
251
    return return_nsstr(nsres, &nstype_str, p);
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
}

static const IHTMLScriptElementVtbl HTMLScriptElementVtbl = {
    HTMLScriptElement_QueryInterface,
    HTMLScriptElement_AddRef,
    HTMLScriptElement_Release,
    HTMLScriptElement_GetTypeInfoCount,
    HTMLScriptElement_GetTypeInfo,
    HTMLScriptElement_GetIDsOfNames,
    HTMLScriptElement_Invoke,
    HTMLScriptElement_put_src,
    HTMLScriptElement_get_src,
    HTMLScriptElement_put_htmlFor,
    HTMLScriptElement_get_htmlFor,
    HTMLScriptElement_put_event,
    HTMLScriptElement_get_event,
    HTMLScriptElement_put_text,
    HTMLScriptElement_get_text,
    HTMLScriptElement_put_defer,
    HTMLScriptElement_get_defer,
    HTMLScriptElement_get_readyState,
    HTMLScriptElement_put_onerror,
    HTMLScriptElement_get_onerror,
    HTMLScriptElement_put_type,
    HTMLScriptElement_get_type
};

279 280 281 282
static inline HTMLScriptElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
{
    return CONTAINING_RECORD(iface, HTMLScriptElement, element.node);
}
283 284 285

static HRESULT HTMLScriptElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
{
286
    HTMLScriptElement *This = impl_from_HTMLDOMNode(iface);
287 288 289 290 291

    *ppv = NULL;

    if(IsEqualGUID(&IID_IUnknown, riid)) {
        TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
292
        *ppv = &This->IHTMLScriptElement_iface;
293 294
    }else if(IsEqualGUID(&IID_IDispatch, riid)) {
        TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
295
        *ppv = &This->IHTMLScriptElement_iface;
296 297
    }else if(IsEqualGUID(&IID_IHTMLScriptElement, riid)) {
        TRACE("(%p)->(IID_IHTMLScriptElement %p)\n", This, ppv);
298
        *ppv = &This->IHTMLScriptElement_iface;
299 300 301 302 303 304 305 306 307 308
    }

    if(*ppv) {
        IUnknown_AddRef((IUnknown*)*ppv);
        return S_OK;
    }

    return HTMLElement_QI(&This->element.node, riid, ppv);
}

309 310
static HRESULT HTMLScriptElement_get_readystate(HTMLDOMNode *iface, BSTR *p)
{
311
    HTMLScriptElement *This = impl_from_HTMLDOMNode(iface);
312

313
    return IHTMLScriptElement_get_readyState(&This->IHTMLScriptElement_iface, p);
314 315
}

316 317
static const NodeImplVtbl HTMLScriptElementImplVtbl = {
    HTMLScriptElement_QI,
318
    HTMLElement_destructor,
319
    HTMLElement_clone,
320
    HTMLElement_get_attr_col,
321 322 323 324 325
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
326
    NULL,
327
    HTMLScriptElement_get_readystate
328 329
};

330 331 332 333 334 335 336 337 338 339 340 341 342
static const tid_t HTMLScriptElement_iface_tids[] = {
    HTMLELEMENT_TIDS,
    IHTMLScriptElement_tid,
    0
};

static dispex_static_data_t HTMLScriptElement_dispex = {
    NULL,
    DispHTMLScriptElement_tid,
    NULL,
    HTMLScriptElement_iface_tids
};

343
HRESULT HTMLScriptElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
344
{
345
    HTMLScriptElement *ret;
346
    nsresult nsres;
347

348 349 350 351
    ret = heap_alloc_zero(sizeof(HTMLScriptElement));
    if(!ret)
        return E_OUTOFMEMORY;

352
    ret->IHTMLScriptElement_iface.lpVtbl = &HTMLScriptElementVtbl;
353 354
    ret->element.node.vtbl = &HTMLScriptElementImplVtbl;

355 356
    HTMLElement_Init(&ret->element, doc, nselem, &HTMLScriptElement_dispex);

357
    nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLScriptElement, (void**)&ret->nsscript);
358

359 360 361
    /* Share nsscript reference with nsnode */
    assert(nsres == NS_OK && (nsIDOMNode*)ret->nsscript == ret->element.node.nsnode);
    nsIDOMNode_Release(ret->element.node.nsnode);
362

363 364
    *elem = &ret->element;
    return S_OK;
365
}