mshtml: Added noscript tag handling tests.
[wine] / dlls / mshtml / htmlframebase.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 #include <assert.h>
21
22 #define COBJMACROS
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
28
29 #include "mshtml_private.h"
30
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34
35 static const WCHAR autoW[] = {'a','u','t','o',0};
36 static const WCHAR yesW[] = {'y','e','s',0};
37 static const WCHAR noW[] = {'n','o',0};
38
39 HRESULT set_frame_doc(HTMLFrameBase *frame, nsIDOMDocument *nsdoc)
40 {
41     nsIDOMWindow *nswindow;
42     HTMLOuterWindow *window;
43     nsresult nsres;
44     HRESULT hres = S_OK;
45
46     if(frame->content_window)
47         return S_OK;
48
49     nsres = nsIDOMDocument_GetDefaultView(nsdoc, &nswindow);
50     if(NS_FAILED(nsres) || !nswindow)
51         return E_FAIL;
52
53     window = nswindow_to_window(nswindow);
54     if(!window)
55         hres = HTMLOuterWindow_Create(frame->element.node.doc->basedoc.doc_obj, nswindow,
56                 frame->element.node.doc->basedoc.window, &window);
57     nsIDOMWindow_Release(nswindow);
58     if(FAILED(hres))
59         return hres;
60
61     frame->content_window = window;
62     window->frame_element = frame;
63     return S_OK;
64 }
65
66 static inline HTMLFrameBase *impl_from_IHTMLFrameBase(IHTMLFrameBase *iface)
67 {
68     return CONTAINING_RECORD(iface, HTMLFrameBase, IHTMLFrameBase_iface);
69 }
70
71 static HRESULT WINAPI HTMLFrameBase_QueryInterface(IHTMLFrameBase *iface, REFIID riid, void **ppv)
72 {
73     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
74
75     return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
76 }
77
78 static ULONG WINAPI HTMLFrameBase_AddRef(IHTMLFrameBase *iface)
79 {
80     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
81
82     return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
83 }
84
85 static ULONG WINAPI HTMLFrameBase_Release(IHTMLFrameBase *iface)
86 {
87     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
88
89     return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
90 }
91
92 static HRESULT WINAPI HTMLFrameBase_GetTypeInfoCount(IHTMLFrameBase *iface, UINT *pctinfo)
93 {
94     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
95
96     return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
97 }
98
99 static HRESULT WINAPI HTMLFrameBase_GetTypeInfo(IHTMLFrameBase *iface, UINT iTInfo,
100         LCID lcid, ITypeInfo **ppTInfo)
101 {
102     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
103
104     return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
105             ppTInfo);
106 }
107
108 static HRESULT WINAPI HTMLFrameBase_GetIDsOfNames(IHTMLFrameBase *iface, REFIID riid,
109         LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
110 {
111     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
112
113     return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
114             cNames, lcid, rgDispId);
115 }
116
117 static HRESULT WINAPI HTMLFrameBase_Invoke(IHTMLFrameBase *iface, DISPID dispIdMember,
118         REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
119         VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
120 {
121     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
122
123     return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
124             lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
125 }
126
127 static HRESULT WINAPI HTMLFrameBase_put_src(IHTMLFrameBase *iface, BSTR v)
128 {
129     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
130
131     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
132
133     if(!This->content_window || !This->element.node.doc || !This->element.node.doc->basedoc.window) {
134         FIXME("detached element\n");
135         return E_FAIL;
136     }
137
138     return navigate_url(This->content_window, v, This->element.node.doc->basedoc.window->uri);
139 }
140
141 static HRESULT WINAPI HTMLFrameBase_get_src(IHTMLFrameBase *iface, BSTR *p)
142 {
143     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
144     FIXME("(%p)->(%p)\n", This, p);
145     return E_NOTIMPL;
146 }
147
148 static HRESULT WINAPI HTMLFrameBase_put_name(IHTMLFrameBase *iface, BSTR v)
149 {
150     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
151     nsAString name_str;
152     nsresult nsres;
153
154     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
155
156     if(!This->nsframe && !This->nsiframe) {
157         ERR("No attached ns frame object\n");
158         return E_UNEXPECTED;
159     }
160
161     nsAString_InitDepend(&name_str, v);
162     if(This->nsframe)
163         nsres = nsIDOMHTMLFrameElement_SetName(This->nsframe, &name_str);
164     else
165         nsres = nsIDOMHTMLIFrameElement_SetName(This->nsiframe, &name_str);
166     nsAString_Finish(&name_str);
167     if(NS_FAILED(nsres)) {
168         ERR("SetName failed: %08x\n", nsres);
169         return E_FAIL;
170     }
171
172     return S_OK;
173 }
174
175 static HRESULT WINAPI HTMLFrameBase_get_name(IHTMLFrameBase *iface, BSTR *p)
176 {
177     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
178     nsAString nsstr;
179     nsresult nsres;
180
181     TRACE("(%p)->(%p)\n", This, p);
182
183     if(!This->nsframe && !This->nsiframe) {
184         ERR("No attached ns frame object\n");
185         return E_UNEXPECTED;
186     }
187
188     nsAString_Init(&nsstr, NULL);
189     if(This->nsframe)
190         nsres = nsIDOMHTMLFrameElement_GetName(This->nsframe, &nsstr);
191     else
192         nsres = nsIDOMHTMLIFrameElement_GetName(This->nsiframe, &nsstr);
193     return return_nsstr(nsres, &nsstr, p);
194 }
195
196 static HRESULT WINAPI HTMLFrameBase_put_border(IHTMLFrameBase *iface, VARIANT v)
197 {
198     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
199     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
200     return E_NOTIMPL;
201 }
202
203 static HRESULT WINAPI HTMLFrameBase_get_border(IHTMLFrameBase *iface, VARIANT *p)
204 {
205     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
206     FIXME("(%p)->(%p)\n", This, p);
207     return E_NOTIMPL;
208 }
209
210 static HRESULT WINAPI HTMLFrameBase_put_frameBorder(IHTMLFrameBase *iface, BSTR v)
211 {
212     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
213     nsAString nsstr;
214     nsresult nsres;
215
216     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
217
218     if(!This->nsframe && !This->nsiframe) {
219         ERR("No attached ns frame object\n");
220         return E_UNEXPECTED;
221     }
222
223     nsAString_InitDepend(&nsstr, v);
224     if(This->nsframe)
225         nsres = nsIDOMHTMLFrameElement_SetFrameBorder(This->nsframe, &nsstr);
226     else
227         nsres = nsIDOMHTMLIFrameElement_SetFrameBorder(This->nsiframe, &nsstr);
228     nsAString_Finish(&nsstr);
229     if(NS_FAILED(nsres)) {
230         ERR("SetFrameBorder failed: %08x\n", nsres);
231         return E_FAIL;
232     }
233
234     return S_OK;
235 }
236
237 static HRESULT WINAPI HTMLFrameBase_get_frameBorder(IHTMLFrameBase *iface, BSTR *p)
238 {
239     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
240     nsAString nsstr;
241     nsresult nsres;
242
243     TRACE("(%p)->(%p)\n", This, p);
244
245     if(!This->nsframe && !This->nsiframe) {
246         ERR("No attached ns frame object\n");
247         return E_UNEXPECTED;
248     }
249
250     nsAString_Init(&nsstr, NULL);
251     if(This->nsframe)
252         nsres = nsIDOMHTMLFrameElement_GetFrameBorder(This->nsframe, &nsstr);
253     else
254         nsres = nsIDOMHTMLIFrameElement_GetFrameBorder(This->nsiframe, &nsstr);
255     return return_nsstr(nsres, &nsstr, p);
256 }
257
258 static HRESULT WINAPI HTMLFrameBase_put_frameSpacing(IHTMLFrameBase *iface, VARIANT v)
259 {
260     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
261     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
262     return E_NOTIMPL;
263 }
264
265 static HRESULT WINAPI HTMLFrameBase_get_frameSpacing(IHTMLFrameBase *iface, VARIANT *p)
266 {
267     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
268     FIXME("(%p)->(%p)\n", This, p);
269     return E_NOTIMPL;
270 }
271
272 static HRESULT WINAPI HTMLFrameBase_put_marginWidth(IHTMLFrameBase *iface, VARIANT v)
273 {
274     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
275     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
276     return E_NOTIMPL;
277 }
278
279 static HRESULT WINAPI HTMLFrameBase_get_marginWidth(IHTMLFrameBase *iface, VARIANT *p)
280 {
281     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
282     FIXME("(%p)->(%p)\n", This, p);
283     return E_NOTIMPL;
284 }
285
286 static HRESULT WINAPI HTMLFrameBase_put_marginHeight(IHTMLFrameBase *iface, VARIANT v)
287 {
288     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
289     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
290     return E_NOTIMPL;
291 }
292
293 static HRESULT WINAPI HTMLFrameBase_get_marginHeight(IHTMLFrameBase *iface, VARIANT *p)
294 {
295     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
296     FIXME("(%p)->(%p)\n", This, p);
297     return E_NOTIMPL;
298 }
299
300 static HRESULT WINAPI HTMLFrameBase_put_noResize(IHTMLFrameBase *iface, VARIANT_BOOL v)
301 {
302     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
303     FIXME("(%p)->(%x)\n", This, v);
304     return E_NOTIMPL;
305 }
306
307 static HRESULT WINAPI HTMLFrameBase_get_noResize(IHTMLFrameBase *iface, VARIANT_BOOL *p)
308 {
309     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
310     FIXME("(%p)->(%p)\n", This, p);
311     return E_NOTIMPL;
312 }
313
314 static HRESULT WINAPI HTMLFrameBase_put_scrolling(IHTMLFrameBase *iface, BSTR v)
315 {
316     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
317     nsAString nsstr;
318     nsresult nsres;
319
320     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
321
322     if(!(!strcmpiW(v, yesW) || !strcmpiW(v, noW) || !strcmpiW(v, autoW)))
323         return E_INVALIDARG;
324
325     if(This->nsframe) {
326         nsAString_InitDepend(&nsstr, v);
327         nsres = nsIDOMHTMLFrameElement_SetScrolling(This->nsframe, &nsstr);
328     }else if(This->nsiframe) {
329         nsAString_InitDepend(&nsstr, v);
330         nsres = nsIDOMHTMLIFrameElement_SetScrolling(This->nsiframe, &nsstr);
331     }else {
332         ERR("No attached ns frame object\n");
333         return E_UNEXPECTED;
334     }
335     nsAString_Finish(&nsstr);
336
337     if(NS_FAILED(nsres)) {
338         ERR("SetScrolling failed: 0x%08x\n", nsres);
339         return E_FAIL;
340     }
341
342     return S_OK;
343 }
344
345 static HRESULT WINAPI HTMLFrameBase_get_scrolling(IHTMLFrameBase *iface, BSTR *p)
346 {
347     HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
348     nsAString nsstr;
349     const PRUnichar *strdata;
350     nsresult nsres;
351
352     TRACE("(%p)->(%p)\n", This, p);
353
354     if(This->nsframe) {
355         nsAString_Init(&nsstr, NULL);
356         nsres = nsIDOMHTMLFrameElement_GetScrolling(This->nsframe, &nsstr);
357     }else if(This->nsiframe) {
358         nsAString_Init(&nsstr, NULL);
359         nsres = nsIDOMHTMLIFrameElement_GetScrolling(This->nsiframe, &nsstr);
360     }else {
361         ERR("No attached ns frame object\n");
362         return E_UNEXPECTED;
363     }
364
365     if(NS_FAILED(nsres)) {
366         ERR("GetScrolling failed: 0x%08x\n", nsres);
367         nsAString_Finish(&nsstr);
368         return E_FAIL;
369     }
370
371     nsAString_GetData(&nsstr, &strdata);
372
373     if(*strdata)
374         *p = SysAllocString(strdata);
375     else
376         *p = SysAllocString(autoW);
377
378     nsAString_Finish(&nsstr);
379
380     return *p ? S_OK : E_OUTOFMEMORY;
381 }
382
383 static const IHTMLFrameBaseVtbl HTMLFrameBaseVtbl = {
384     HTMLFrameBase_QueryInterface,
385     HTMLFrameBase_AddRef,
386     HTMLFrameBase_Release,
387     HTMLFrameBase_GetTypeInfoCount,
388     HTMLFrameBase_GetTypeInfo,
389     HTMLFrameBase_GetIDsOfNames,
390     HTMLFrameBase_Invoke,
391     HTMLFrameBase_put_src,
392     HTMLFrameBase_get_src,
393     HTMLFrameBase_put_name,
394     HTMLFrameBase_get_name,
395     HTMLFrameBase_put_border,
396     HTMLFrameBase_get_border,
397     HTMLFrameBase_put_frameBorder,
398     HTMLFrameBase_get_frameBorder,
399     HTMLFrameBase_put_frameSpacing,
400     HTMLFrameBase_get_frameSpacing,
401     HTMLFrameBase_put_marginWidth,
402     HTMLFrameBase_get_marginWidth,
403     HTMLFrameBase_put_marginHeight,
404     HTMLFrameBase_get_marginHeight,
405     HTMLFrameBase_put_noResize,
406     HTMLFrameBase_get_noResize,
407     HTMLFrameBase_put_scrolling,
408     HTMLFrameBase_get_scrolling
409 };
410
411 static inline HTMLFrameBase *impl_from_IHTMLFrameBase2(IHTMLFrameBase2 *iface)
412 {
413     return CONTAINING_RECORD(iface, HTMLFrameBase, IHTMLFrameBase2_iface);
414 }
415
416 static HRESULT WINAPI HTMLFrameBase2_QueryInterface(IHTMLFrameBase2 *iface, REFIID riid, void **ppv)
417 {
418     HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
419
420     return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
421 }
422
423 static ULONG WINAPI HTMLFrameBase2_AddRef(IHTMLFrameBase2 *iface)
424 {
425     HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
426
427     return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
428 }
429
430 static ULONG WINAPI HTMLFrameBase2_Release(IHTMLFrameBase2 *iface)
431 {
432     HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
433
434     return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
435 }
436
437 static HRESULT WINAPI HTMLFrameBase2_GetTypeInfoCount(IHTMLFrameBase2 *iface, UINT *pctinfo)
438 {
439     HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
440     FIXME("(%p)\n", This);
441     return E_NOTIMPL;
442 }
443
444 static HRESULT WINAPI HTMLFrameBase2_GetTypeInfo(IHTMLFrameBase2 *iface, UINT iTInfo,
445         LCID lcid, ITypeInfo **ppTInfo)
446 {
447     HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
448     FIXME("(%p)\n", This);
449     return E_NOTIMPL;
450 }
451
452 static HRESULT WINAPI HTMLFrameBase2_GetIDsOfNames(IHTMLFrameBase2 *iface, REFIID riid,
453         LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
454 {
455     HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
456     FIXME("(%p)\n", This);
457     return E_NOTIMPL;
458 }
459
460 static HRESULT WINAPI HTMLFrameBase2_Invoke(IHTMLFrameBase2 *iface, DISPID dispIdMember,
461         REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
462         VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
463 {
464     HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
465     FIXME("(%p)\n", This);
466     return E_NOTIMPL;
467 }
468
469 static HRESULT WINAPI HTMLFrameBase2_get_contentWindow(IHTMLFrameBase2 *iface, IHTMLWindow2 **p)
470 {
471     HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
472
473     TRACE("(%p)->(%p)\n", This, p);
474
475     if(This->content_window) {
476         IHTMLWindow2_AddRef(&This->content_window->base.IHTMLWindow2_iface);
477         *p = &This->content_window->base.IHTMLWindow2_iface;
478     }else {
479         WARN("NULL content window\n");
480         *p = NULL;
481     }
482     return S_OK;
483 }
484
485 static HRESULT WINAPI HTMLFrameBase2_put_onload(IHTMLFrameBase2 *iface, VARIANT v)
486 {
487     HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
488     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
489     return E_NOTIMPL;
490 }
491
492 static HRESULT WINAPI HTMLFrameBase2_get_onload(IHTMLFrameBase2 *iface, VARIANT *p)
493 {
494     HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
495     FIXME("(%p)->(%p)\n", This, p);
496     return E_NOTIMPL;
497 }
498
499 static HRESULT WINAPI HTMLFrameBase2_put_onreadystatechange(IHTMLFrameBase2 *iface, VARIANT v)
500 {
501     HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
502     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
503     return E_NOTIMPL;
504 }
505
506 static HRESULT WINAPI HTMLFrameBase2_get_onreadystatechange(IHTMLFrameBase2 *iface, VARIANT *p)
507 {
508     HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
509     FIXME("(%p)->(%p)\n", This, p);
510     return E_NOTIMPL;
511 }
512
513 static HRESULT WINAPI HTMLFrameBase2_get_readyState(IHTMLFrameBase2 *iface, BSTR *p)
514 {
515     HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
516
517     TRACE("(%p)->(%p)\n", This, p);
518
519     if(!This->content_window || !This->content_window->base.inner_window->doc) {
520         FIXME("no document associated\n");
521         return E_FAIL;
522     }
523
524     return IHTMLDocument2_get_readyState(&This->content_window->base.inner_window->doc->basedoc.IHTMLDocument2_iface, p);
525 }
526
527 static HRESULT WINAPI HTMLFrameBase2_put_allowTransparency(IHTMLFrameBase2 *iface, VARIANT_BOOL v)
528 {
529     HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
530     FIXME("(%p)->(%x)\n", This, v);
531     return E_NOTIMPL;
532 }
533
534 static HRESULT WINAPI HTMLFrameBase2_get_allowTransparency(IHTMLFrameBase2 *iface, VARIANT_BOOL *p)
535 {
536     HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
537     FIXME("(%p)->(%p)\n", This, p);
538     return E_NOTIMPL;
539 }
540
541 static const IHTMLFrameBase2Vtbl HTMLFrameBase2Vtbl = {
542     HTMLFrameBase2_QueryInterface,
543     HTMLFrameBase2_AddRef,
544     HTMLFrameBase2_Release,
545     HTMLFrameBase2_GetTypeInfoCount,
546     HTMLFrameBase2_GetTypeInfo,
547     HTMLFrameBase2_GetIDsOfNames,
548     HTMLFrameBase2_Invoke,
549     HTMLFrameBase2_get_contentWindow,
550     HTMLFrameBase2_put_onload,
551     HTMLFrameBase2_get_onload,
552     HTMLFrameBase2_put_onreadystatechange,
553     HTMLFrameBase2_get_onreadystatechange,
554     HTMLFrameBase2_get_readyState,
555     HTMLFrameBase2_put_allowTransparency,
556     HTMLFrameBase2_get_allowTransparency
557 };
558
559 HRESULT HTMLFrameBase_QI(HTMLFrameBase *This, REFIID riid, void **ppv)
560 {
561     if(IsEqualGUID(&IID_IHTMLFrameBase, riid)) {
562         TRACE("(%p)->(IID_IHTMLFrameBase %p)\n", This, ppv);
563         *ppv = &This->IHTMLFrameBase_iface;
564     }else if(IsEqualGUID(&IID_IHTMLFrameBase2, riid)) {
565         TRACE("(%p)->(IID_IHTMLFrameBase2 %p)\n", This, ppv);
566         *ppv = &This->IHTMLFrameBase2_iface;
567     }else {
568         return HTMLElement_QI(&This->element.node, riid, ppv);
569     }
570
571     IUnknown_AddRef((IUnknown*)*ppv);
572     return S_OK;
573 }
574
575 void HTMLFrameBase_destructor(HTMLFrameBase *This)
576 {
577     if(This->content_window)
578         This->content_window->frame_element = NULL;
579
580     HTMLElement_destructor(&This->element.node);
581 }
582
583 void HTMLFrameBase_Init(HTMLFrameBase *This, HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem,
584         dispex_static_data_t *dispex_data)
585 {
586     nsresult nsres;
587
588     This->IHTMLFrameBase_iface.lpVtbl = &HTMLFrameBaseVtbl;
589     This->IHTMLFrameBase2_iface.lpVtbl = &HTMLFrameBase2Vtbl;
590
591     HTMLElement_Init(&This->element, doc, nselem, dispex_data);
592
593     nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLFrameElement, (void**)&This->nsframe);
594     if(NS_FAILED(nsres)) {
595         This->nsframe = NULL;
596         nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLIFrameElement, (void**)&This->nsiframe);
597         assert(nsres == NS_OK && (nsIDOMNode*)This->nsiframe == This->element.node.nsnode);
598     }else {
599         assert((nsIDOMNode*)This->nsframe == This->element.node.nsnode);
600         This->nsiframe = NULL;
601     }
602
603     /* Share the reference with nsnode */
604     nsIDOMNode_Release(This->element.node.nsnode);
605 }