2 * Copyright 2008 Jacek Caban for CodeWeavers
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.
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.
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
29 #include "mshtml_private.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
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 static const WCHAR pxW[] = {'p','x',0};
40 HRESULT set_frame_doc(HTMLFrameBase *frame, nsIDOMDocument *nsdoc)
42 nsIDOMWindow *nswindow;
43 HTMLOuterWindow *window;
47 if(frame->content_window)
50 nsres = nsIDOMDocument_GetDefaultView(nsdoc, &nswindow);
51 if(NS_FAILED(nsres) || !nswindow)
54 window = nswindow_to_window(nswindow);
56 hres = HTMLOuterWindow_Create(frame->element.node.doc->basedoc.doc_obj, nswindow,
57 frame->element.node.doc->basedoc.window, &window);
58 nsIDOMWindow_Release(nswindow);
62 frame->content_window = window;
63 window->frame_element = frame;
67 static inline HTMLFrameBase *impl_from_IHTMLFrameBase(IHTMLFrameBase *iface)
69 return CONTAINING_RECORD(iface, HTMLFrameBase, IHTMLFrameBase_iface);
72 static HRESULT WINAPI HTMLFrameBase_QueryInterface(IHTMLFrameBase *iface, REFIID riid, void **ppv)
74 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
76 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
79 static ULONG WINAPI HTMLFrameBase_AddRef(IHTMLFrameBase *iface)
81 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
83 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
86 static ULONG WINAPI HTMLFrameBase_Release(IHTMLFrameBase *iface)
88 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
90 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
93 static HRESULT WINAPI HTMLFrameBase_GetTypeInfoCount(IHTMLFrameBase *iface, UINT *pctinfo)
95 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
97 return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
100 static HRESULT WINAPI HTMLFrameBase_GetTypeInfo(IHTMLFrameBase *iface, UINT iTInfo,
101 LCID lcid, ITypeInfo **ppTInfo)
103 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
105 return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
109 static HRESULT WINAPI HTMLFrameBase_GetIDsOfNames(IHTMLFrameBase *iface, REFIID riid,
110 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
112 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
114 return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
115 cNames, lcid, rgDispId);
118 static HRESULT WINAPI HTMLFrameBase_Invoke(IHTMLFrameBase *iface, DISPID dispIdMember,
119 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
120 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
122 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
124 return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
125 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
128 static HRESULT WINAPI HTMLFrameBase_put_src(IHTMLFrameBase *iface, BSTR v)
130 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
132 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
134 if(!This->content_window || !This->element.node.doc || !This->element.node.doc->basedoc.window) {
135 FIXME("detached element\n");
139 return navigate_url(This->content_window, v, This->element.node.doc->basedoc.window->uri);
142 static HRESULT WINAPI HTMLFrameBase_get_src(IHTMLFrameBase *iface, BSTR *p)
144 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
145 FIXME("(%p)->(%p)\n", This, p);
149 static HRESULT WINAPI HTMLFrameBase_put_name(IHTMLFrameBase *iface, BSTR v)
151 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
155 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
157 if(!This->nsframe && !This->nsiframe) {
158 ERR("No attached ns frame object\n");
162 nsAString_InitDepend(&name_str, v);
164 nsres = nsIDOMHTMLFrameElement_SetName(This->nsframe, &name_str);
166 nsres = nsIDOMHTMLIFrameElement_SetName(This->nsiframe, &name_str);
167 nsAString_Finish(&name_str);
168 if(NS_FAILED(nsres)) {
169 ERR("SetName failed: %08x\n", nsres);
176 static HRESULT WINAPI HTMLFrameBase_get_name(IHTMLFrameBase *iface, BSTR *p)
178 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
182 TRACE("(%p)->(%p)\n", This, p);
184 if(!This->nsframe && !This->nsiframe) {
185 ERR("No attached ns frame object\n");
189 nsAString_Init(&nsstr, NULL);
191 nsres = nsIDOMHTMLFrameElement_GetName(This->nsframe, &nsstr);
193 nsres = nsIDOMHTMLIFrameElement_GetName(This->nsiframe, &nsstr);
194 return return_nsstr(nsres, &nsstr, p);
197 static HRESULT WINAPI HTMLFrameBase_put_border(IHTMLFrameBase *iface, VARIANT v)
199 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
200 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
204 static HRESULT WINAPI HTMLFrameBase_get_border(IHTMLFrameBase *iface, VARIANT *p)
206 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
207 FIXME("(%p)->(%p)\n", This, p);
211 static HRESULT WINAPI HTMLFrameBase_put_frameBorder(IHTMLFrameBase *iface, BSTR v)
213 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
217 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
219 if(!This->nsframe && !This->nsiframe) {
220 ERR("No attached ns frame object\n");
224 nsAString_InitDepend(&nsstr, v);
226 nsres = nsIDOMHTMLFrameElement_SetFrameBorder(This->nsframe, &nsstr);
228 nsres = nsIDOMHTMLIFrameElement_SetFrameBorder(This->nsiframe, &nsstr);
229 nsAString_Finish(&nsstr);
230 if(NS_FAILED(nsres)) {
231 ERR("SetFrameBorder failed: %08x\n", nsres);
238 static HRESULT WINAPI HTMLFrameBase_get_frameBorder(IHTMLFrameBase *iface, BSTR *p)
240 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
244 TRACE("(%p)->(%p)\n", This, p);
246 if(!This->nsframe && !This->nsiframe) {
247 ERR("No attached ns frame object\n");
251 nsAString_Init(&nsstr, NULL);
253 nsres = nsIDOMHTMLFrameElement_GetFrameBorder(This->nsframe, &nsstr);
255 nsres = nsIDOMHTMLIFrameElement_GetFrameBorder(This->nsiframe, &nsstr);
256 return return_nsstr(nsres, &nsstr, p);
259 static HRESULT WINAPI HTMLFrameBase_put_frameSpacing(IHTMLFrameBase *iface, VARIANT v)
261 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
262 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
266 static HRESULT WINAPI HTMLFrameBase_get_frameSpacing(IHTMLFrameBase *iface, VARIANT *p)
268 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
269 FIXME("(%p)->(%p)\n", This, p);
273 static HRESULT WINAPI HTMLFrameBase_put_marginWidth(IHTMLFrameBase *iface, VARIANT v)
275 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
276 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
280 static HRESULT WINAPI HTMLFrameBase_get_marginWidth(IHTMLFrameBase *iface, VARIANT *p)
282 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
283 FIXME("(%p)->(%p)\n", This, p);
287 static HRESULT WINAPI HTMLFrameBase_put_marginHeight(IHTMLFrameBase *iface, VARIANT v)
289 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
293 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
295 if(V_VT(&v) != VT_BSTR) {
296 FIXME("unsupported %s\n", debugstr_variant(&v));
300 nsAString_InitDepend(&nsstr, V_BSTR(&v));
302 nsres = nsIDOMHTMLFrameElement_SetMarginHeight(This->nsframe, &nsstr);
304 nsres = nsIDOMHTMLIFrameElement_SetMarginHeight(This->nsiframe, &nsstr);
305 nsAString_Finish(&nsstr);
306 return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
309 static HRESULT WINAPI HTMLFrameBase_get_marginHeight(IHTMLFrameBase *iface, VARIANT *p)
311 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
316 TRACE("(%p)->(%p)\n", This, p);
318 nsAString_Init(&nsstr, NULL);
320 nsres = nsIDOMHTMLFrameElement_GetMarginHeight(This->nsframe, &nsstr);
322 nsres = nsIDOMHTMLIFrameElement_GetMarginHeight(This->nsiframe, &nsstr);
323 if(NS_SUCCEEDED(nsres)) {
324 const PRUnichar *str, *end;
326 nsAString_GetData(&nsstr, &str);
331 end = strstrW(str, pxW);
333 end = str+strlenW(str);
334 ret = SysAllocStringLen(str, end-str);
339 hres = E_OUTOFMEMORY;
346 ERR("SetMarginHeight failed: %08x\n", nsres);
350 nsAString_Finish(&nsstr);
354 static HRESULT WINAPI HTMLFrameBase_put_noResize(IHTMLFrameBase *iface, VARIANT_BOOL v)
356 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
357 FIXME("(%p)->(%x)\n", This, v);
361 static HRESULT WINAPI HTMLFrameBase_get_noResize(IHTMLFrameBase *iface, VARIANT_BOOL *p)
363 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
364 FIXME("(%p)->(%p)\n", This, p);
368 static HRESULT WINAPI HTMLFrameBase_put_scrolling(IHTMLFrameBase *iface, BSTR v)
370 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
374 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
376 if(!(!strcmpiW(v, yesW) || !strcmpiW(v, noW) || !strcmpiW(v, autoW)))
380 nsAString_InitDepend(&nsstr, v);
381 nsres = nsIDOMHTMLFrameElement_SetScrolling(This->nsframe, &nsstr);
382 }else if(This->nsiframe) {
383 nsAString_InitDepend(&nsstr, v);
384 nsres = nsIDOMHTMLIFrameElement_SetScrolling(This->nsiframe, &nsstr);
386 ERR("No attached ns frame object\n");
389 nsAString_Finish(&nsstr);
391 if(NS_FAILED(nsres)) {
392 ERR("SetScrolling failed: 0x%08x\n", nsres);
399 static HRESULT WINAPI HTMLFrameBase_get_scrolling(IHTMLFrameBase *iface, BSTR *p)
401 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
403 const PRUnichar *strdata;
406 TRACE("(%p)->(%p)\n", This, p);
409 nsAString_Init(&nsstr, NULL);
410 nsres = nsIDOMHTMLFrameElement_GetScrolling(This->nsframe, &nsstr);
411 }else if(This->nsiframe) {
412 nsAString_Init(&nsstr, NULL);
413 nsres = nsIDOMHTMLIFrameElement_GetScrolling(This->nsiframe, &nsstr);
415 ERR("No attached ns frame object\n");
419 if(NS_FAILED(nsres)) {
420 ERR("GetScrolling failed: 0x%08x\n", nsres);
421 nsAString_Finish(&nsstr);
425 nsAString_GetData(&nsstr, &strdata);
428 *p = SysAllocString(strdata);
430 *p = SysAllocString(autoW);
432 nsAString_Finish(&nsstr);
434 return *p ? S_OK : E_OUTOFMEMORY;
437 static const IHTMLFrameBaseVtbl HTMLFrameBaseVtbl = {
438 HTMLFrameBase_QueryInterface,
439 HTMLFrameBase_AddRef,
440 HTMLFrameBase_Release,
441 HTMLFrameBase_GetTypeInfoCount,
442 HTMLFrameBase_GetTypeInfo,
443 HTMLFrameBase_GetIDsOfNames,
444 HTMLFrameBase_Invoke,
445 HTMLFrameBase_put_src,
446 HTMLFrameBase_get_src,
447 HTMLFrameBase_put_name,
448 HTMLFrameBase_get_name,
449 HTMLFrameBase_put_border,
450 HTMLFrameBase_get_border,
451 HTMLFrameBase_put_frameBorder,
452 HTMLFrameBase_get_frameBorder,
453 HTMLFrameBase_put_frameSpacing,
454 HTMLFrameBase_get_frameSpacing,
455 HTMLFrameBase_put_marginWidth,
456 HTMLFrameBase_get_marginWidth,
457 HTMLFrameBase_put_marginHeight,
458 HTMLFrameBase_get_marginHeight,
459 HTMLFrameBase_put_noResize,
460 HTMLFrameBase_get_noResize,
461 HTMLFrameBase_put_scrolling,
462 HTMLFrameBase_get_scrolling
465 static inline HTMLFrameBase *impl_from_IHTMLFrameBase2(IHTMLFrameBase2 *iface)
467 return CONTAINING_RECORD(iface, HTMLFrameBase, IHTMLFrameBase2_iface);
470 static HRESULT WINAPI HTMLFrameBase2_QueryInterface(IHTMLFrameBase2 *iface, REFIID riid, void **ppv)
472 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
474 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
477 static ULONG WINAPI HTMLFrameBase2_AddRef(IHTMLFrameBase2 *iface)
479 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
481 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
484 static ULONG WINAPI HTMLFrameBase2_Release(IHTMLFrameBase2 *iface)
486 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
488 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
491 static HRESULT WINAPI HTMLFrameBase2_GetTypeInfoCount(IHTMLFrameBase2 *iface, UINT *pctinfo)
493 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
494 FIXME("(%p)\n", This);
498 static HRESULT WINAPI HTMLFrameBase2_GetTypeInfo(IHTMLFrameBase2 *iface, UINT iTInfo,
499 LCID lcid, ITypeInfo **ppTInfo)
501 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
502 FIXME("(%p)\n", This);
506 static HRESULT WINAPI HTMLFrameBase2_GetIDsOfNames(IHTMLFrameBase2 *iface, REFIID riid,
507 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
509 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
510 FIXME("(%p)\n", This);
514 static HRESULT WINAPI HTMLFrameBase2_Invoke(IHTMLFrameBase2 *iface, DISPID dispIdMember,
515 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
516 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
518 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
519 FIXME("(%p)\n", This);
523 static HRESULT WINAPI HTMLFrameBase2_get_contentWindow(IHTMLFrameBase2 *iface, IHTMLWindow2 **p)
525 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
527 TRACE("(%p)->(%p)\n", This, p);
529 if(This->content_window) {
530 IHTMLWindow2_AddRef(&This->content_window->base.IHTMLWindow2_iface);
531 *p = &This->content_window->base.IHTMLWindow2_iface;
533 WARN("NULL content window\n");
539 static HRESULT WINAPI HTMLFrameBase2_put_onload(IHTMLFrameBase2 *iface, VARIANT v)
541 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
542 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
546 static HRESULT WINAPI HTMLFrameBase2_get_onload(IHTMLFrameBase2 *iface, VARIANT *p)
548 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
549 FIXME("(%p)->(%p)\n", This, p);
553 static HRESULT WINAPI HTMLFrameBase2_put_onreadystatechange(IHTMLFrameBase2 *iface, VARIANT v)
555 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
556 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
560 static HRESULT WINAPI HTMLFrameBase2_get_onreadystatechange(IHTMLFrameBase2 *iface, VARIANT *p)
562 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
563 FIXME("(%p)->(%p)\n", This, p);
567 static HRESULT WINAPI HTMLFrameBase2_get_readyState(IHTMLFrameBase2 *iface, BSTR *p)
569 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
571 TRACE("(%p)->(%p)\n", This, p);
573 if(!This->content_window || !This->content_window->base.inner_window->doc) {
574 FIXME("no document associated\n");
578 return IHTMLDocument2_get_readyState(&This->content_window->base.inner_window->doc->basedoc.IHTMLDocument2_iface, p);
581 static HRESULT WINAPI HTMLFrameBase2_put_allowTransparency(IHTMLFrameBase2 *iface, VARIANT_BOOL v)
583 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
584 FIXME("(%p)->(%x)\n", This, v);
588 static HRESULT WINAPI HTMLFrameBase2_get_allowTransparency(IHTMLFrameBase2 *iface, VARIANT_BOOL *p)
590 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
591 FIXME("(%p)->(%p)\n", This, p);
595 static const IHTMLFrameBase2Vtbl HTMLFrameBase2Vtbl = {
596 HTMLFrameBase2_QueryInterface,
597 HTMLFrameBase2_AddRef,
598 HTMLFrameBase2_Release,
599 HTMLFrameBase2_GetTypeInfoCount,
600 HTMLFrameBase2_GetTypeInfo,
601 HTMLFrameBase2_GetIDsOfNames,
602 HTMLFrameBase2_Invoke,
603 HTMLFrameBase2_get_contentWindow,
604 HTMLFrameBase2_put_onload,
605 HTMLFrameBase2_get_onload,
606 HTMLFrameBase2_put_onreadystatechange,
607 HTMLFrameBase2_get_onreadystatechange,
608 HTMLFrameBase2_get_readyState,
609 HTMLFrameBase2_put_allowTransparency,
610 HTMLFrameBase2_get_allowTransparency
613 HRESULT HTMLFrameBase_QI(HTMLFrameBase *This, REFIID riid, void **ppv)
615 if(IsEqualGUID(&IID_IHTMLFrameBase, riid)) {
616 TRACE("(%p)->(IID_IHTMLFrameBase %p)\n", This, ppv);
617 *ppv = &This->IHTMLFrameBase_iface;
618 }else if(IsEqualGUID(&IID_IHTMLFrameBase2, riid)) {
619 TRACE("(%p)->(IID_IHTMLFrameBase2 %p)\n", This, ppv);
620 *ppv = &This->IHTMLFrameBase2_iface;
622 return HTMLElement_QI(&This->element.node, riid, ppv);
625 IUnknown_AddRef((IUnknown*)*ppv);
629 void HTMLFrameBase_destructor(HTMLFrameBase *This)
631 if(This->content_window)
632 This->content_window->frame_element = NULL;
634 HTMLElement_destructor(&This->element.node);
637 void HTMLFrameBase_Init(HTMLFrameBase *This, HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem,
638 dispex_static_data_t *dispex_data)
642 This->IHTMLFrameBase_iface.lpVtbl = &HTMLFrameBaseVtbl;
643 This->IHTMLFrameBase2_iface.lpVtbl = &HTMLFrameBase2Vtbl;
645 HTMLElement_Init(&This->element, doc, nselem, dispex_data);
647 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLFrameElement, (void**)&This->nsframe);
648 if(NS_FAILED(nsres)) {
649 This->nsframe = NULL;
650 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLIFrameElement, (void**)&This->nsiframe);
651 assert(nsres == NS_OK && (nsIDOMNode*)This->nsiframe == This->element.node.nsnode);
653 assert((nsIDOMNode*)This->nsframe == This->element.node.nsnode);
654 This->nsiframe = NULL;
657 /* Share the reference with nsnode */
658 nsIDOMNode_Release(This->element.node.nsnode);