mshtml: Fix typo in WARN.
[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     HTMLElement element;
36     const IHTMLFrameBase2Vtbl  *lpIHTMLFrameBase2Vtbl;
37
38     LONG ref;
39
40     nsIDOMHTMLIFrameElement *nsiframe;
41     HTMLWindow *content_window;
42 } HTMLIFrame;
43
44 #define HTMLFRAMEBASE2(x)  (&(x)->lpIHTMLFrameBase2Vtbl)
45
46 static HRESULT create_content_window(HTMLIFrame *This, nsIDOMHTMLDocument *nsdoc, HTMLWindow **ret)
47 {
48     nsIDOMDocumentView *nsdocview;
49     nsIDOMAbstractView *nsview;
50     nsIDOMWindow *nswindow;
51     nsresult nsres;
52     HRESULT hres;
53
54     nsres = nsIDOMHTMLDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentView, (void**)&nsdocview);
55     if(NS_FAILED(nsres)) {
56         ERR("Could not get nsIDOMDocumentView: %08x\n", nsres);
57         return E_FAIL;
58     }
59
60     nsres = nsIDOMDocumentView_GetDefaultView(nsdocview, &nsview);
61     nsIDOMDocumentView_Release(nsdocview);
62     if(NS_FAILED(nsres)) {
63         ERR("GetDefaultView failed: %08x\n", nsres);
64         return E_FAIL;
65     }
66
67     nsres = nsIDOMAbstractView_QueryInterface(nsview, &IID_nsIDOMWindow, (void**)&nswindow);
68     nsIDOMAbstractView_Release(nsview);
69     if(NS_FAILED(nsres)) {
70         ERR("Coult not get nsIDOMWindow iface: %08x\n", nsres);
71         return E_FAIL;
72     }
73
74     hres = HTMLWindow_Create(This->element.node.doc->basedoc.doc_obj, nswindow, ret);
75
76     nsIDOMWindow_Release(nswindow);
77     return hres;
78 }
79
80 #define HTMLFRAMEBASE2_THIS(iface) DEFINE_THIS(HTMLIFrame, IHTMLFrameBase2, iface)
81
82 static HRESULT WINAPI HTMLIFrameBase2_QueryInterface(IHTMLFrameBase2 *iface, REFIID riid, void **ppv)
83 {
84     HTMLIFrame *This = HTMLFRAMEBASE2_THIS(iface);
85
86     return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This->element.node), riid, ppv);
87 }
88
89 static ULONG WINAPI HTMLIFrameBase2_AddRef(IHTMLFrameBase2 *iface)
90 {
91     HTMLIFrame *This = HTMLFRAMEBASE2_THIS(iface);
92
93     return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->element.node));
94 }
95
96 static ULONG WINAPI HTMLIFrameBase2_Release(IHTMLFrameBase2 *iface)
97 {
98     HTMLIFrame *This = HTMLFRAMEBASE2_THIS(iface);
99
100     return IHTMLDOMNode_Release(HTMLDOMNODE(&This->element.node));
101 }
102
103 static HRESULT WINAPI HTMLIFrameBase2_GetTypeInfoCount(IHTMLFrameBase2 *iface, UINT *pctinfo)
104 {
105     HTMLIFrame *This = HTMLFRAMEBASE2_THIS(iface);
106     FIXME("(%p)\n", This);
107     return E_NOTIMPL;
108 }
109
110 static HRESULT WINAPI HTMLIFrameBase2_GetTypeInfo(IHTMLFrameBase2 *iface, UINT iTInfo,
111         LCID lcid, ITypeInfo **ppTInfo)
112 {
113     HTMLIFrame *This = HTMLFRAMEBASE2_THIS(iface);
114     FIXME("(%p)\n", This);
115     return E_NOTIMPL;
116 }
117
118 static HRESULT WINAPI HTMLIFrameBase2_GetIDsOfNames(IHTMLFrameBase2 *iface, REFIID riid,
119         LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
120 {
121     HTMLIFrame *This = HTMLFRAMEBASE2_THIS(iface);
122     FIXME("(%p)\n", This);
123     return E_NOTIMPL;
124 }
125
126 static HRESULT WINAPI HTMLIFrameBase2_Invoke(IHTMLFrameBase2 *iface, DISPID dispIdMember,
127         REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
128         VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
129 {
130     HTMLIFrame *This = HTMLFRAMEBASE2_THIS(iface);
131     FIXME("(%p)\n", This);
132     return E_NOTIMPL;
133 }
134
135 static HRESULT WINAPI HTMLIFrameBase2_get_contentWindow(IHTMLFrameBase2 *iface, IHTMLWindow2 **p)
136 {
137     HTMLIFrame *This = HTMLFRAMEBASE2_THIS(iface);
138
139     TRACE("(%p)->(%p)\n", This, p);
140
141     if(!This->content_window) {
142         nsIDOMHTMLDocument *nshtmldoc;
143         HTMLDocumentNode *content_doc;
144         nsIDOMDocument *nsdoc;
145         HTMLWindow *window;
146         nsresult nsres;
147         HRESULT hres;
148
149         nsres = nsIDOMHTMLIFrameElement_GetContentDocument(This->nsiframe, &nsdoc);
150         if(NS_FAILED(nsres)) {
151             ERR("GetContentDocument failed: %08x\n", nsres);
152             return E_FAIL;
153         }
154
155         if(!nsdoc) {
156             FIXME("NULL contentDocument\n");
157             return E_FAIL;
158         }
159
160         nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
161         nsIDOMDocument_Release(nsdoc);
162         if(NS_FAILED(nsres)) {
163             ERR("Could not get nsIDOMHTMLDocument iface: %08x\n", nsres);
164             return E_FAIL;
165         }
166
167         hres = create_content_window(This, nshtmldoc, &window);
168         if(FAILED(hres)) {
169             nsIDOMHTMLDocument_Release(nshtmldoc);
170             return E_FAIL;
171         }
172
173         hres = create_doc_from_nsdoc(nshtmldoc, This->element.node.doc->basedoc.doc_obj, window, &content_doc);
174         nsIDOMHTMLDocument_Release(nshtmldoc);
175         if(SUCCEEDED(hres))
176             window_set_docnode(window, content_doc);
177         else
178             IHTMLWindow2_Release(HTMLWINDOW2(window));
179         htmldoc_release(&content_doc->basedoc);
180         if(FAILED(hres))
181             return hres;
182
183         This->content_window = window;
184     }
185
186     IHTMLWindow2_AddRef(HTMLWINDOW2(This->content_window));
187     *p = HTMLWINDOW2(This->content_window);
188     return S_OK;
189 }
190
191 static HRESULT WINAPI HTMLIFrameBase2_put_onload(IHTMLFrameBase2 *iface, VARIANT v)
192 {
193     HTMLIFrame *This = HTMLFRAMEBASE2_THIS(iface);
194     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
195     return E_NOTIMPL;
196 }
197
198 static HRESULT WINAPI HTMLIFrameBase2_get_onload(IHTMLFrameBase2 *iface, VARIANT *p)
199 {
200     HTMLIFrame *This = HTMLFRAMEBASE2_THIS(iface);
201     FIXME("(%p)->(%p)\n", This, p);
202     return E_NOTIMPL;
203 }
204
205 static HRESULT WINAPI HTMLIFrameBase2_put_onreadystatechange(IHTMLFrameBase2 *iface, VARIANT v)
206 {
207     HTMLIFrame *This = HTMLFRAMEBASE2_THIS(iface);
208     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
209     return E_NOTIMPL;
210 }
211
212 static HRESULT WINAPI HTMLIFrameBase2_get_onreadystatechange(IHTMLFrameBase2 *iface, VARIANT *p)
213 {
214     HTMLIFrame *This = HTMLFRAMEBASE2_THIS(iface);
215     FIXME("(%p)->(%p)\n", This, p);
216     return E_NOTIMPL;
217 }
218
219 static HRESULT WINAPI HTMLIFrameBase2_get_readyState(IHTMLFrameBase2 *iface, BSTR *p)
220 {
221     HTMLIFrame *This = HTMLFRAMEBASE2_THIS(iface);
222     FIXME("(%p)->(%p)\n", This, p);
223     return E_NOTIMPL;
224 }
225
226 static HRESULT WINAPI HTMLIFrameBase2_put_allowTransparency(IHTMLFrameBase2 *iface, VARIANT_BOOL v)
227 {
228     HTMLIFrame *This = HTMLFRAMEBASE2_THIS(iface);
229     FIXME("(%p)->(%x)\n", This, v);
230     return E_NOTIMPL;
231 }
232
233 static HRESULT WINAPI HTMLIFrameBase2_get_allowTransparency(IHTMLFrameBase2 *iface, VARIANT_BOOL *p)
234 {
235     HTMLIFrame *This = HTMLFRAMEBASE2_THIS(iface);
236     FIXME("(%p)->(%p)\n", This, p);
237     return E_NOTIMPL;
238 }
239
240 #undef HTMLFRAMEBASE2_THIS
241
242 static const IHTMLFrameBase2Vtbl HTMLIFrameBase2Vtbl = {
243     HTMLIFrameBase2_QueryInterface,
244     HTMLIFrameBase2_AddRef,
245     HTMLIFrameBase2_Release,
246     HTMLIFrameBase2_GetTypeInfoCount,
247     HTMLIFrameBase2_GetTypeInfo,
248     HTMLIFrameBase2_GetIDsOfNames,
249     HTMLIFrameBase2_Invoke,
250     HTMLIFrameBase2_get_contentWindow,
251     HTMLIFrameBase2_put_onload,
252     HTMLIFrameBase2_get_onload,
253     HTMLIFrameBase2_put_onreadystatechange,
254     HTMLIFrameBase2_get_onreadystatechange,
255     HTMLIFrameBase2_get_readyState,
256     HTMLIFrameBase2_put_allowTransparency,
257     HTMLIFrameBase2_get_allowTransparency
258 };
259
260 #define HTMLIFRAME_NODE_THIS(iface) DEFINE_THIS2(HTMLIFrame, element.node, iface)
261
262 static HRESULT HTMLIFrame_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
263 {
264     HTMLIFrame *This = HTMLIFRAME_NODE_THIS(iface);
265
266     *ppv = NULL;
267
268     if(IsEqualGUID(&IID_IHTMLFrameBase2, riid)) {
269         TRACE("(%p)->(IID_IHTMLFrameBase2 %p)\n", This, ppv);
270         *ppv = HTMLFRAMEBASE2(This);
271     }else {
272         return HTMLElement_QI(&This->element.node, riid, ppv);
273     }
274
275     IUnknown_AddRef((IUnknown*)*ppv);
276     return S_OK;
277 }
278
279 static void HTMLIFrame_destructor(HTMLDOMNode *iface)
280 {
281     HTMLIFrame *This = HTMLIFRAME_NODE_THIS(iface);
282
283     if(This->content_window)
284         IHTMLWindow2_Release(HTMLWINDOW2(This->content_window));
285     if(This->nsiframe)
286         nsIDOMHTMLIFrameElement_Release(This->nsiframe);
287
288     HTMLElement_destructor(&This->element.node);
289 }
290
291 #undef HTMLIFRAME_NODE_THIS
292
293 static const NodeImplVtbl HTMLIFrameImplVtbl = {
294     HTMLIFrame_QI,
295     HTMLIFrame_destructor
296 };
297
298 static const tid_t HTMLIFrame_iface_tids[] = {
299     IHTMLDOMNode_tid,
300     IHTMLDOMNode2_tid,
301     IHTMLElement_tid,
302     IHTMLElement2_tid,
303     IHTMLElement3_tid,
304     IHTMLFrameBase2_tid,
305     0
306 };
307
308 static dispex_static_data_t HTMLIFrame_dispex = {
309     NULL,
310     DispHTMLIFrame_tid,
311     NULL,
312     HTMLIFrame_iface_tids
313 };
314
315 HTMLElement *HTMLIFrame_Create(nsIDOMHTMLElement *nselem)
316 {
317     HTMLIFrame *ret;
318     nsresult nsres;
319
320     ret = heap_alloc_zero(sizeof(HTMLIFrame));
321
322     ret->lpIHTMLFrameBase2Vtbl = &HTMLIFrameBase2Vtbl;
323     ret->element.node.vtbl = &HTMLIFrameImplVtbl;
324
325     HTMLElement_Init(&ret->element, &HTMLIFrame_dispex);
326
327     nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLIFrameElement, (void**)&ret->nsiframe);
328     if(NS_FAILED(nsres))
329         ERR("Could not get nsIDOMHTMLIFrameElement iface: %08x\n", nsres);
330
331     return &ret->element;
332 }