ole32: Fix memory leaks in the storage test.
[wine] / dlls / mshtml / htmliframe.c
1 /*
2  * Copyright 2008 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <stdarg.h>
20
21 #define COBJMACROS
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
27
28 #include "mshtml_private.h"
29
30 #include "wine/debug.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
33
34 typedef struct {
35     HTMLFrameBase framebase;
36 } HTMLIFrame;
37
38 #define HTMLIFRAME_NODE_THIS(iface) DEFINE_THIS2(HTMLIFrame, framebase.element.node, iface)
39
40 static HRESULT HTMLIFrame_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
41 {
42     HTMLIFrame *This = HTMLIFRAME_NODE_THIS(iface);
43
44     return HTMLFrameBase_QI(&This->framebase, riid, ppv);
45 }
46
47 static void HTMLIFrame_destructor(HTMLDOMNode *iface)
48 {
49     HTMLIFrame *This = HTMLIFRAME_NODE_THIS(iface);
50
51     HTMLFrameBase_destructor(&This->framebase);
52 }
53
54 static HRESULT HTMLIFrame_get_document(HTMLDOMNode *iface, IDispatch **p)
55 {
56     HTMLIFrame *This = HTMLIFRAME_NODE_THIS(iface);
57
58     if(!This->framebase.content_window || !This->framebase.content_window->doc) {
59         *p = NULL;
60         return S_OK;
61     }
62
63     *p = (IDispatch*)HTMLDOC(&This->framebase.content_window->doc->basedoc);
64     IDispatch_AddRef(*p);
65     return S_OK;
66 }
67
68 static HRESULT HTMLIFrame_get_dispid(HTMLDOMNode *iface, BSTR name,
69         DWORD grfdex, DISPID *pid)
70 {
71     HTMLIFrame *This = HTMLIFRAME_NODE_THIS(iface);
72
73     if(!This->framebase.content_window)
74         return DISP_E_UNKNOWNNAME;
75
76     return search_window_props(This->framebase.content_window, name, grfdex, pid);
77 }
78
79 static HRESULT HTMLIFrame_invoke(HTMLDOMNode *iface, DISPID id, LCID lcid,
80         WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
81 {
82     HTMLIFrame *This = HTMLIFRAME_NODE_THIS(iface);
83
84     if(!This->framebase.content_window) {
85         ERR("no content window to invoke on\n");
86         return E_FAIL;
87     }
88
89     return IDispatchEx_InvokeEx(DISPATCHEX(This->framebase.content_window), id, lcid, flags, params, res, ei, caller);
90 }
91
92 static HRESULT HTMLIFrame_get_readystate(HTMLDOMNode *iface, BSTR *p)
93 {
94     HTMLIFrame *This = HTMLIFRAME_NODE_THIS(iface);
95
96     return IHTMLFrameBase2_get_readyState(HTMLFRAMEBASE2(&This->framebase), p);
97 }
98
99 static HRESULT HTMLIFrame_bind_to_tree(HTMLDOMNode *iface)
100 {
101     HTMLIFrame *This = HTMLIFRAME_NODE_THIS(iface);
102     nsIDOMDocument *nsdoc;
103     nsresult nsres;
104     HRESULT hres;
105
106     nsres = nsIDOMHTMLIFrameElement_GetContentDocument(This->framebase.nsiframe, &nsdoc);
107     if(NS_FAILED(nsres) || !nsdoc) {
108         ERR("GetContentDocument failed: %08x\n", nsres);
109         return E_FAIL;
110     }
111
112     hres = set_frame_doc(&This->framebase, nsdoc);
113     nsIDOMDocument_Release(nsdoc);
114     return hres;
115 }
116
117 #undef HTMLIFRAME_NODE_THIS
118
119 static const NodeImplVtbl HTMLIFrameImplVtbl = {
120     HTMLIFrame_QI,
121     HTMLIFrame_destructor,
122     NULL,
123     NULL,
124     NULL,
125     NULL,
126     HTMLIFrame_get_document,
127     HTMLIFrame_get_readystate,
128     HTMLIFrame_get_dispid,
129     HTMLIFrame_invoke,
130     HTMLIFrame_bind_to_tree
131 };
132
133 static const tid_t HTMLIFrame_iface_tids[] = {
134     IHTMLDOMNode_tid,
135     IHTMLDOMNode2_tid,
136     IHTMLElement_tid,
137     IHTMLElement2_tid,
138     IHTMLElement3_tid,
139     IHTMLFrameBase_tid,
140     IHTMLFrameBase2_tid,
141     0
142 };
143
144 static dispex_static_data_t HTMLIFrame_dispex = {
145     NULL,
146     DispHTMLIFrame_tid,
147     NULL,
148     HTMLIFrame_iface_tids
149 };
150
151 HTMLElement *HTMLIFrame_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem)
152 {
153     HTMLIFrame *ret;
154
155     ret = heap_alloc_zero(sizeof(HTMLIFrame));
156
157     ret->framebase.element.node.vtbl = &HTMLIFrameImplVtbl;
158
159     HTMLFrameBase_Init(&ret->framebase, doc, nselem, &HTMLIFrame_dispex);
160
161     return &ret->framebase.element;
162 }