htmlframe.c 10.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
/*
 * Copyright 2010 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>

#define COBJMACROS

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

#include "mshtml_private.h"

#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(mshtml);

typedef struct {
    HTMLFrameBase framebase;
36
    IHTMLFrameElement3 IHTMLFrameElement3_iface;
37 38
} HTMLFrameElement;

39 40 41 42
static inline HTMLFrameElement *impl_from_IHTMLFrameElement3(IHTMLFrameElement3 *iface)
{
    return CONTAINING_RECORD(iface, HTMLFrameElement, IHTMLFrameElement3_iface);
}
43 44 45 46

static HRESULT WINAPI HTMLFrameElement3_QueryInterface(IHTMLFrameElement3 *iface,
        REFIID riid, void **ppv)
{
47
    HTMLFrameElement *This = impl_from_IHTMLFrameElement3(iface);
48

49
    return IHTMLDOMNode_QueryInterface(&This->framebase.element.node.IHTMLDOMNode_iface, riid, ppv);
50 51 52 53
}

static ULONG WINAPI HTMLFrameElement3_AddRef(IHTMLFrameElement3 *iface)
{
54
    HTMLFrameElement *This = impl_from_IHTMLFrameElement3(iface);
55

56
    return IHTMLDOMNode_AddRef(&This->framebase.element.node.IHTMLDOMNode_iface);
57 58 59 60
}

static ULONG WINAPI HTMLFrameElement3_Release(IHTMLFrameElement3 *iface)
{
61
    HTMLFrameElement *This = impl_from_IHTMLFrameElement3(iface);
62

63
    return IHTMLDOMNode_Release(&This->framebase.element.node.IHTMLDOMNode_iface);
64 65 66 67
}

static HRESULT WINAPI HTMLFrameElement3_GetTypeInfoCount(IHTMLFrameElement3 *iface, UINT *pctinfo)
{
68
    HTMLFrameElement *This = impl_from_IHTMLFrameElement3(iface);
69
    return IDispatchEx_GetTypeInfoCount(&This->framebase.element.node.event_target.dispex.IDispatchEx_iface,
70
            pctinfo);
71 72 73 74 75
}

static HRESULT WINAPI HTMLFrameElement3_GetTypeInfo(IHTMLFrameElement3 *iface, UINT iTInfo,
        LCID lcid, ITypeInfo **ppTInfo)
{
76
    HTMLFrameElement *This = impl_from_IHTMLFrameElement3(iface);
77
    return IDispatchEx_GetTypeInfo(&This->framebase.element.node.event_target.dispex.IDispatchEx_iface, iTInfo,
78
            lcid, ppTInfo);
79 80 81 82 83
}

static HRESULT WINAPI HTMLFrameElement3_GetIDsOfNames(IHTMLFrameElement3 *iface, REFIID riid,
        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
84
    HTMLFrameElement *This = impl_from_IHTMLFrameElement3(iface);
85
    return IDispatchEx_GetIDsOfNames(&This->framebase.element.node.event_target.dispex.IDispatchEx_iface, riid,
86
            rgszNames, cNames, lcid, rgDispId);
87 88 89 90 91 92
}

static HRESULT WINAPI HTMLFrameElement3_Invoke(IHTMLFrameElement3 *iface, DISPID dispIdMember,
        REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
        VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
93
    HTMLFrameElement *This = impl_from_IHTMLFrameElement3(iface);
94
    return IDispatchEx_Invoke(&This->framebase.element.node.event_target.dispex.IDispatchEx_iface, dispIdMember,
95
            riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
96 97 98 99
}

static HRESULT WINAPI HTMLFrameElement3_get_contentDocument(IHTMLFrameElement3 *iface, IDispatch **p)
{
100
    HTMLFrameElement *This = impl_from_IHTMLFrameElement3(iface);
101 102 103 104 105 106 107 108 109 110
    IHTMLDocument2 *doc;
    HRESULT hres;

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

    if(!This->framebase.content_window) {
        FIXME("NULL window\n");
        return E_FAIL;
    }

111
    hres = IHTMLWindow2_get_document(&This->framebase.content_window->base.IHTMLWindow2_iface, &doc);
112 113 114 115 116
    if(FAILED(hres))
        return hres;

    *p = doc ? (IDispatch*)doc : NULL;
    return S_OK;
117 118 119 120
}

static HRESULT WINAPI HTMLFrameElement3_put_src(IHTMLFrameElement3 *iface, BSTR v)
{
121
    HTMLFrameElement *This = impl_from_IHTMLFrameElement3(iface);
122 123 124 125 126 127
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLFrameElement3_get_src(IHTMLFrameElement3 *iface, BSTR *p)
{
128
    HTMLFrameElement *This = impl_from_IHTMLFrameElement3(iface);
129 130 131 132 133 134
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLFrameElement3_put_longDesc(IHTMLFrameElement3 *iface, BSTR v)
{
135
    HTMLFrameElement *This = impl_from_IHTMLFrameElement3(iface);
136 137 138 139 140 141
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLFrameElement3_get_longDesc(IHTMLFrameElement3 *iface, BSTR *p)
{
142
    HTMLFrameElement *This = impl_from_IHTMLFrameElement3(iface);
143 144 145 146 147 148
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLFrameElement3_put_frameBorder(IHTMLFrameElement3 *iface, BSTR v)
{
149
    HTMLFrameElement *This = impl_from_IHTMLFrameElement3(iface);
150 151 152 153 154 155
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLFrameElement3_get_frameBorder(IHTMLFrameElement3 *iface, BSTR *p)
{
156
    HTMLFrameElement *This = impl_from_IHTMLFrameElement3(iface);
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static const IHTMLFrameElement3Vtbl HTMLFrameElement3Vtbl = {
    HTMLFrameElement3_QueryInterface,
    HTMLFrameElement3_AddRef,
    HTMLFrameElement3_Release,
    HTMLFrameElement3_GetTypeInfoCount,
    HTMLFrameElement3_GetTypeInfo,
    HTMLFrameElement3_GetIDsOfNames,
    HTMLFrameElement3_Invoke,
    HTMLFrameElement3_get_contentDocument,
    HTMLFrameElement3_put_src,
    HTMLFrameElement3_get_src,
    HTMLFrameElement3_put_longDesc,
    HTMLFrameElement3_get_longDesc,
    HTMLFrameElement3_put_frameBorder,
    HTMLFrameElement3_get_frameBorder
};

178 179 180 181
static inline HTMLFrameElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
{
    return CONTAINING_RECORD(iface, HTMLFrameElement, framebase.element.node);
}
182 183 184

static HRESULT HTMLFrameElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
{
185
    HTMLFrameElement *This = impl_from_HTMLDOMNode(iface);
186 187 188

    if(IsEqualGUID(&IID_IHTMLFrameElement3, riid)) {
        TRACE("(%p)->(IID_IHTMLFrameElement3 %p)\n", This, ppv);
189
        *ppv = &This->IHTMLFrameElement3_iface;
190 191 192 193 194 195 196 197 198 199
    }else {
        return HTMLFrameBase_QI(&This->framebase, riid, ppv);
    }

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

static void HTMLFrameElement_destructor(HTMLDOMNode *iface)
{
200
    HTMLFrameElement *This = impl_from_HTMLDOMNode(iface);
201 202 203 204 205 206

    HTMLFrameBase_destructor(&This->framebase);
}

static HRESULT HTMLFrameElement_get_document(HTMLDOMNode *iface, IDispatch **p)
{
207
    HTMLFrameElement *This = impl_from_HTMLDOMNode(iface);
208

209
    if(!This->framebase.content_window || !This->framebase.content_window->base.inner_window->doc) {
210 211 212 213
        *p = NULL;
        return S_OK;
    }

214
    *p = (IDispatch*)&This->framebase.content_window->base.inner_window->doc->basedoc.IHTMLDocument2_iface;
215 216 217 218
    IDispatch_AddRef(*p);
    return S_OK;
}

219 220
static HRESULT HTMLFrameElement_get_readystate(HTMLDOMNode *iface, BSTR *p)
{
221
    HTMLFrameElement *This = impl_from_HTMLDOMNode(iface);
222

223
    return IHTMLFrameBase2_get_readyState(&This->framebase.IHTMLFrameBase2_iface, p);
224 225
}

226 227 228
static HRESULT HTMLFrameElement_get_dispid(HTMLDOMNode *iface, BSTR name,
        DWORD grfdex, DISPID *pid)
{
229
    HTMLFrameElement *This = impl_from_HTMLDOMNode(iface);
230 231 232 233

    if(!This->framebase.content_window)
        return DISP_E_UNKNOWNNAME;

234
    return search_window_props(This->framebase.content_window->base.inner_window, name, grfdex, pid);
235 236 237 238 239
}

static HRESULT HTMLFrameElement_invoke(HTMLDOMNode *iface, DISPID id, LCID lcid,
        WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
{
240
    HTMLFrameElement *This = impl_from_HTMLDOMNode(iface);
241 242 243 244 245 246

    if(!This->framebase.content_window) {
        ERR("no content window to invoke on\n");
        return E_FAIL;
    }

247
    return IDispatchEx_InvokeEx(&This->framebase.content_window->base.IDispatchEx_iface, id, lcid,
248
            flags, params, res, ei, caller);
249 250 251 252
}

static HRESULT HTMLFrameElement_bind_to_tree(HTMLDOMNode *iface)
{
253
    HTMLFrameElement *This = impl_from_HTMLDOMNode(iface);
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
    nsIDOMDocument *nsdoc;
    nsresult nsres;
    HRESULT hres;

    nsres = nsIDOMHTMLFrameElement_GetContentDocument(This->framebase.nsframe, &nsdoc);
    if(NS_FAILED(nsres) || !nsdoc) {
        ERR("GetContentDocument failed: %08x\n", nsres);
        return E_FAIL;
    }

    hres = set_frame_doc(&This->framebase, nsdoc);
    nsIDOMDocument_Release(nsdoc);
    return hres;
}

269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
static void HTMLFrameElement_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
{
    HTMLFrameElement *This = impl_from_HTMLDOMNode(iface);

    if(This->framebase.nsframe)
        note_cc_edge((nsISupports*)This->framebase.nsframe, "This->nsframe", cb);
}

static void HTMLFrameElement_unlink(HTMLDOMNode *iface)
{
    HTMLFrameElement *This = impl_from_HTMLDOMNode(iface);

    if(This->framebase.nsframe) {
        nsIDOMHTMLFrameElement *nsframe = This->framebase.nsframe;

        This->framebase.nsframe = NULL;
        nsIDOMHTMLFrameElement_Release(nsframe);
    }
}

289 290 291
static const NodeImplVtbl HTMLFrameElementImplVtbl = {
    HTMLFrameElement_QI,
    HTMLFrameElement_destructor,
292
    HTMLElement_cpc,
293
    HTMLElement_clone,
294
    HTMLElement_handle_event,
295
    HTMLElement_get_attr_col,
296 297 298 299 300
    NULL,
    NULL,
    NULL,
    NULL,
    HTMLFrameElement_get_document,
301
    HTMLFrameElement_get_readystate,
302 303
    HTMLFrameElement_get_dispid,
    HTMLFrameElement_invoke,
304 305 306
    HTMLFrameElement_bind_to_tree,
    HTMLFrameElement_traverse,
    HTMLFrameElement_unlink
307 308
};

309
static const tid_t HTMLFrameElement_iface_tids[] = {
310
    HTMLELEMENT_TIDS,
311 312 313 314 315 316 317 318 319 320 321 322 323
    IHTMLFrameBase_tid,
    IHTMLFrameBase2_tid,
    IHTMLFrameElement3_tid,
    0
};

static dispex_static_data_t HTMLFrameElement_dispex = {
    NULL,
    DispHTMLFrameElement_tid,
    NULL,
    HTMLFrameElement_iface_tids
};

324
HRESULT HTMLFrameElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
325 326 327 328
{
    HTMLFrameElement *ret;

    ret = heap_alloc_zero(sizeof(HTMLFrameElement));
329 330
    if(!ret)
        return E_OUTOFMEMORY;
331 332

    ret->framebase.element.node.vtbl = &HTMLFrameElementImplVtbl;
333
    ret->IHTMLFrameElement3_iface.lpVtbl = &HTMLFrameElement3Vtbl;
334

335
    HTMLFrameBase_Init(&ret->framebase, doc, nselem, &HTMLFrameElement_dispex);
336

337 338
    *elem = &ret->framebase.element;
    return S_OK;
339
}