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};
39 HRESULT set_frame_doc(HTMLFrameBase *frame, nsIDOMDocument *nsdoc)
41 nsIDOMWindow *nswindow;
42 HTMLOuterWindow *window;
46 if(frame->content_window)
49 nsres = nsIDOMDocument_GetDefaultView(nsdoc, &nswindow);
50 if(NS_FAILED(nsres) || !nswindow)
53 window = nswindow_to_window(nswindow);
55 hres = HTMLOuterWindow_Create(frame->element.node.doc->basedoc.doc_obj, nswindow,
56 frame->element.node.doc->basedoc.window, &window);
57 nsIDOMWindow_Release(nswindow);
61 frame->content_window = window;
62 window->frame_element = frame;
66 static inline HTMLFrameBase *impl_from_IHTMLFrameBase(IHTMLFrameBase *iface)
68 return CONTAINING_RECORD(iface, HTMLFrameBase, IHTMLFrameBase_iface);
71 static HRESULT WINAPI HTMLFrameBase_QueryInterface(IHTMLFrameBase *iface, REFIID riid, void **ppv)
73 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
75 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
78 static ULONG WINAPI HTMLFrameBase_AddRef(IHTMLFrameBase *iface)
80 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
82 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
85 static ULONG WINAPI HTMLFrameBase_Release(IHTMLFrameBase *iface)
87 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
89 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
92 static HRESULT WINAPI HTMLFrameBase_GetTypeInfoCount(IHTMLFrameBase *iface, UINT *pctinfo)
94 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
96 return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
99 static HRESULT WINAPI HTMLFrameBase_GetTypeInfo(IHTMLFrameBase *iface, UINT iTInfo,
100 LCID lcid, ITypeInfo **ppTInfo)
102 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
104 return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
108 static HRESULT WINAPI HTMLFrameBase_GetIDsOfNames(IHTMLFrameBase *iface, REFIID riid,
109 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
111 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
113 return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
114 cNames, lcid, rgDispId);
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)
121 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
123 return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
124 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
127 static HRESULT WINAPI HTMLFrameBase_put_src(IHTMLFrameBase *iface, BSTR v)
129 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
131 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
133 if(!This->content_window || !This->element.node.doc || !This->element.node.doc->basedoc.window) {
134 FIXME("detached element\n");
138 return navigate_url(This->content_window, v, This->element.node.doc->basedoc.window->uri);
141 static HRESULT WINAPI HTMLFrameBase_get_src(IHTMLFrameBase *iface, BSTR *p)
143 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
144 FIXME("(%p)->(%p)\n", This, p);
148 static HRESULT WINAPI HTMLFrameBase_put_name(IHTMLFrameBase *iface, BSTR v)
150 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
154 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
156 if(!This->nsframe && !This->nsiframe) {
157 ERR("No attached ns frame object\n");
161 nsAString_InitDepend(&name_str, v);
163 nsres = nsIDOMHTMLFrameElement_SetName(This->nsframe, &name_str);
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);
175 static HRESULT WINAPI HTMLFrameBase_get_name(IHTMLFrameBase *iface, BSTR *p)
177 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
181 TRACE("(%p)->(%p)\n", This, p);
183 if(!This->nsframe && !This->nsiframe) {
184 ERR("No attached ns frame object\n");
188 nsAString_Init(&nsstr, NULL);
190 nsres = nsIDOMHTMLFrameElement_GetName(This->nsframe, &nsstr);
192 nsres = nsIDOMHTMLIFrameElement_GetName(This->nsiframe, &nsstr);
193 return return_nsstr(nsres, &nsstr, p);
196 static HRESULT WINAPI HTMLFrameBase_put_border(IHTMLFrameBase *iface, VARIANT v)
198 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
199 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
203 static HRESULT WINAPI HTMLFrameBase_get_border(IHTMLFrameBase *iface, VARIANT *p)
205 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
206 FIXME("(%p)->(%p)\n", This, p);
210 static HRESULT WINAPI HTMLFrameBase_put_frameBorder(IHTMLFrameBase *iface, BSTR v)
212 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
216 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
218 if(!This->nsframe && !This->nsiframe) {
219 ERR("No attached ns frame object\n");
223 nsAString_InitDepend(&nsstr, v);
225 nsres = nsIDOMHTMLFrameElement_SetFrameBorder(This->nsframe, &nsstr);
227 nsres = nsIDOMHTMLIFrameElement_SetFrameBorder(This->nsiframe, &nsstr);
228 nsAString_Finish(&nsstr);
229 if(NS_FAILED(nsres)) {
230 ERR("SetFrameBorder failed: %08x\n", nsres);
237 static HRESULT WINAPI HTMLFrameBase_get_frameBorder(IHTMLFrameBase *iface, BSTR *p)
239 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
243 TRACE("(%p)->(%p)\n", This, p);
245 if(!This->nsframe && !This->nsiframe) {
246 ERR("No attached ns frame object\n");
250 nsAString_Init(&nsstr, NULL);
252 nsres = nsIDOMHTMLFrameElement_GetFrameBorder(This->nsframe, &nsstr);
254 nsres = nsIDOMHTMLIFrameElement_GetFrameBorder(This->nsiframe, &nsstr);
255 return return_nsstr(nsres, &nsstr, p);
258 static HRESULT WINAPI HTMLFrameBase_put_frameSpacing(IHTMLFrameBase *iface, VARIANT v)
260 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
261 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
265 static HRESULT WINAPI HTMLFrameBase_get_frameSpacing(IHTMLFrameBase *iface, VARIANT *p)
267 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
268 FIXME("(%p)->(%p)\n", This, p);
272 static HRESULT WINAPI HTMLFrameBase_put_marginWidth(IHTMLFrameBase *iface, VARIANT v)
274 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
275 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
279 static HRESULT WINAPI HTMLFrameBase_get_marginWidth(IHTMLFrameBase *iface, VARIANT *p)
281 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
282 FIXME("(%p)->(%p)\n", This, p);
286 static HRESULT WINAPI HTMLFrameBase_put_marginHeight(IHTMLFrameBase *iface, VARIANT v)
288 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
289 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
293 static HRESULT WINAPI HTMLFrameBase_get_marginHeight(IHTMLFrameBase *iface, VARIANT *p)
295 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
296 FIXME("(%p)->(%p)\n", This, p);
300 static HRESULT WINAPI HTMLFrameBase_put_noResize(IHTMLFrameBase *iface, VARIANT_BOOL v)
302 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
303 FIXME("(%p)->(%x)\n", This, v);
307 static HRESULT WINAPI HTMLFrameBase_get_noResize(IHTMLFrameBase *iface, VARIANT_BOOL *p)
309 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
310 FIXME("(%p)->(%p)\n", This, p);
314 static HRESULT WINAPI HTMLFrameBase_put_scrolling(IHTMLFrameBase *iface, BSTR v)
316 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
320 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
322 if(!(!strcmpiW(v, yesW) || !strcmpiW(v, noW) || !strcmpiW(v, autoW)))
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);
332 ERR("No attached ns frame object\n");
335 nsAString_Finish(&nsstr);
337 if(NS_FAILED(nsres)) {
338 ERR("SetScrolling failed: 0x%08x\n", nsres);
345 static HRESULT WINAPI HTMLFrameBase_get_scrolling(IHTMLFrameBase *iface, BSTR *p)
347 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
349 const PRUnichar *strdata;
352 TRACE("(%p)->(%p)\n", This, p);
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);
361 ERR("No attached ns frame object\n");
365 if(NS_FAILED(nsres)) {
366 ERR("GetScrolling failed: 0x%08x\n", nsres);
367 nsAString_Finish(&nsstr);
371 nsAString_GetData(&nsstr, &strdata);
374 *p = SysAllocString(strdata);
376 *p = SysAllocString(autoW);
378 nsAString_Finish(&nsstr);
380 return *p ? S_OK : E_OUTOFMEMORY;
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
411 static inline HTMLFrameBase *impl_from_IHTMLFrameBase2(IHTMLFrameBase2 *iface)
413 return CONTAINING_RECORD(iface, HTMLFrameBase, IHTMLFrameBase2_iface);
416 static HRESULT WINAPI HTMLFrameBase2_QueryInterface(IHTMLFrameBase2 *iface, REFIID riid, void **ppv)
418 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
420 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
423 static ULONG WINAPI HTMLFrameBase2_AddRef(IHTMLFrameBase2 *iface)
425 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
427 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
430 static ULONG WINAPI HTMLFrameBase2_Release(IHTMLFrameBase2 *iface)
432 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
434 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
437 static HRESULT WINAPI HTMLFrameBase2_GetTypeInfoCount(IHTMLFrameBase2 *iface, UINT *pctinfo)
439 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
440 FIXME("(%p)\n", This);
444 static HRESULT WINAPI HTMLFrameBase2_GetTypeInfo(IHTMLFrameBase2 *iface, UINT iTInfo,
445 LCID lcid, ITypeInfo **ppTInfo)
447 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
448 FIXME("(%p)\n", This);
452 static HRESULT WINAPI HTMLFrameBase2_GetIDsOfNames(IHTMLFrameBase2 *iface, REFIID riid,
453 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
455 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
456 FIXME("(%p)\n", This);
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)
464 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
465 FIXME("(%p)\n", This);
469 static HRESULT WINAPI HTMLFrameBase2_get_contentWindow(IHTMLFrameBase2 *iface, IHTMLWindow2 **p)
471 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
473 TRACE("(%p)->(%p)\n", This, p);
475 if(This->content_window) {
476 IHTMLWindow2_AddRef(&This->content_window->base.IHTMLWindow2_iface);
477 *p = &This->content_window->base.IHTMLWindow2_iface;
479 WARN("NULL content window\n");
485 static HRESULT WINAPI HTMLFrameBase2_put_onload(IHTMLFrameBase2 *iface, VARIANT v)
487 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
488 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
492 static HRESULT WINAPI HTMLFrameBase2_get_onload(IHTMLFrameBase2 *iface, VARIANT *p)
494 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
495 FIXME("(%p)->(%p)\n", This, p);
499 static HRESULT WINAPI HTMLFrameBase2_put_onreadystatechange(IHTMLFrameBase2 *iface, VARIANT v)
501 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
502 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
506 static HRESULT WINAPI HTMLFrameBase2_get_onreadystatechange(IHTMLFrameBase2 *iface, VARIANT *p)
508 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
509 FIXME("(%p)->(%p)\n", This, p);
513 static HRESULT WINAPI HTMLFrameBase2_get_readyState(IHTMLFrameBase2 *iface, BSTR *p)
515 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
517 TRACE("(%p)->(%p)\n", This, p);
519 if(!This->content_window || !This->content_window->base.inner_window->doc) {
520 FIXME("no document associated\n");
524 return IHTMLDocument2_get_readyState(&This->content_window->base.inner_window->doc->basedoc.IHTMLDocument2_iface, p);
527 static HRESULT WINAPI HTMLFrameBase2_put_allowTransparency(IHTMLFrameBase2 *iface, VARIANT_BOOL v)
529 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
530 FIXME("(%p)->(%x)\n", This, v);
534 static HRESULT WINAPI HTMLFrameBase2_get_allowTransparency(IHTMLFrameBase2 *iface, VARIANT_BOOL *p)
536 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
537 FIXME("(%p)->(%p)\n", This, p);
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
559 HRESULT HTMLFrameBase_QI(HTMLFrameBase *This, REFIID riid, void **ppv)
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;
568 return HTMLElement_QI(&This->element.node, riid, ppv);
571 IUnknown_AddRef((IUnknown*)*ppv);
575 void HTMLFrameBase_destructor(HTMLFrameBase *This)
577 if(This->content_window)
578 This->content_window->frame_element = NULL;
580 HTMLElement_destructor(&This->element.node);
583 void HTMLFrameBase_Init(HTMLFrameBase *This, HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem,
584 dispex_static_data_t *dispex_data)
588 This->IHTMLFrameBase_iface.lpVtbl = &HTMLFrameBaseVtbl;
589 This->IHTMLFrameBase2_iface.lpVtbl = &HTMLFrameBase2Vtbl;
591 HTMLElement_Init(&This->element, doc, nselem, dispex_data);
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);
599 assert((nsIDOMNode*)This->nsframe == This->element.node.nsnode);
600 This->nsiframe = NULL;
603 /* Share the reference with nsnode */
604 nsIDOMNode_Release(This->element.node.nsnode);