mshtml: Added separated types for outer and inner HTML windows.
[wine/multimedia.git] / dlls / mshtml / htmlframebase.c
blobfd6e2e6cedfa33da97ca1e91380212ca2db4215c
1 /*
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
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
28 #include "mshtml_private.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34 static const WCHAR autoW[] = {'a','u','t','o',0};
35 static const WCHAR yesW[] = {'y','e','s',0};
36 static const WCHAR noW[] = {'n','o',0};
38 HRESULT set_frame_doc(HTMLFrameBase *frame, nsIDOMDocument *nsdoc)
40 nsIDOMWindow *nswindow;
41 HTMLOuterWindow *window;
42 nsresult nsres;
43 HRESULT hres = S_OK;
45 if(frame->content_window)
46 return S_OK;
48 nsres = nsIDOMDocument_GetDefaultView(nsdoc, &nswindow);
49 if(NS_FAILED(nsres) || !nswindow)
50 return E_FAIL;
52 window = nswindow_to_window(nswindow);
53 if(!window)
54 hres = HTMLOuterWindow_Create(frame->element.node.doc->basedoc.doc_obj, nswindow,
55 frame->element.node.doc->basedoc.window, &window);
56 nsIDOMWindow_Release(nswindow);
57 if(FAILED(hres))
58 return hres;
60 frame->content_window = window;
61 window->frame_element = frame;
62 return S_OK;
65 static inline HTMLFrameBase *impl_from_IHTMLFrameBase(IHTMLFrameBase *iface)
67 return CONTAINING_RECORD(iface, HTMLFrameBase, IHTMLFrameBase_iface);
70 static HRESULT WINAPI HTMLFrameBase_QueryInterface(IHTMLFrameBase *iface, REFIID riid, void **ppv)
72 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
74 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
77 static ULONG WINAPI HTMLFrameBase_AddRef(IHTMLFrameBase *iface)
79 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
81 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
84 static ULONG WINAPI HTMLFrameBase_Release(IHTMLFrameBase *iface)
86 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
88 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
91 static HRESULT WINAPI HTMLFrameBase_GetTypeInfoCount(IHTMLFrameBase *iface, UINT *pctinfo)
93 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
95 return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
98 static HRESULT WINAPI HTMLFrameBase_GetTypeInfo(IHTMLFrameBase *iface, UINT iTInfo,
99 LCID lcid, ITypeInfo **ppTInfo)
101 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
103 return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
104 ppTInfo);
107 static HRESULT WINAPI HTMLFrameBase_GetIDsOfNames(IHTMLFrameBase *iface, REFIID riid,
108 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
110 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
112 return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
113 cNames, lcid, rgDispId);
116 static HRESULT WINAPI HTMLFrameBase_Invoke(IHTMLFrameBase *iface, DISPID dispIdMember,
117 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
118 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
120 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
122 return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
123 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
126 static HRESULT WINAPI HTMLFrameBase_put_src(IHTMLFrameBase *iface, BSTR v)
128 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
130 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
132 if(!This->content_window || !This->element.node.doc || !This->element.node.doc->basedoc.window) {
133 FIXME("detached element\n");
134 return E_FAIL;
137 return navigate_url(This->content_window, v, This->element.node.doc->basedoc.window->url);
140 static HRESULT WINAPI HTMLFrameBase_get_src(IHTMLFrameBase *iface, BSTR *p)
142 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
143 FIXME("(%p)->(%p)\n", This, p);
144 return E_NOTIMPL;
147 static HRESULT WINAPI HTMLFrameBase_put_name(IHTMLFrameBase *iface, BSTR v)
149 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
150 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
151 return E_NOTIMPL;
154 static HRESULT WINAPI HTMLFrameBase_get_name(IHTMLFrameBase *iface, BSTR *p)
156 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
157 nsAString nsstr;
158 nsresult nsres;
160 TRACE("(%p)->(%p)\n", This, p);
162 if(!This->nsframe && !This->nsiframe) {
163 ERR("No attached ns frame object\n");
164 return E_UNEXPECTED;
167 nsAString_Init(&nsstr, NULL);
168 if(This->nsframe)
169 nsres = nsIDOMHTMLFrameElement_GetName(This->nsframe, &nsstr);
170 else
171 nsres = nsIDOMHTMLIFrameElement_GetName(This->nsiframe, &nsstr);
172 return return_nsstr(nsres, &nsstr, p);
175 static HRESULT WINAPI HTMLFrameBase_put_border(IHTMLFrameBase *iface, VARIANT v)
177 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
178 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
179 return E_NOTIMPL;
182 static HRESULT WINAPI HTMLFrameBase_get_border(IHTMLFrameBase *iface, VARIANT *p)
184 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
185 FIXME("(%p)->(%p)\n", This, p);
186 return E_NOTIMPL;
189 static HRESULT WINAPI HTMLFrameBase_put_frameBorder(IHTMLFrameBase *iface, BSTR v)
191 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
192 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
193 return E_NOTIMPL;
196 static HRESULT WINAPI HTMLFrameBase_get_frameBorder(IHTMLFrameBase *iface, BSTR *p)
198 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
199 FIXME("(%p)->(%p)\n", This, p);
200 return E_NOTIMPL;
203 static HRESULT WINAPI HTMLFrameBase_put_frameSpacing(IHTMLFrameBase *iface, VARIANT v)
205 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
206 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
207 return E_NOTIMPL;
210 static HRESULT WINAPI HTMLFrameBase_get_frameSpacing(IHTMLFrameBase *iface, VARIANT *p)
212 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
213 FIXME("(%p)->(%p)\n", This, p);
214 return E_NOTIMPL;
217 static HRESULT WINAPI HTMLFrameBase_put_marginWidth(IHTMLFrameBase *iface, VARIANT v)
219 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
220 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
221 return E_NOTIMPL;
224 static HRESULT WINAPI HTMLFrameBase_get_marginWidth(IHTMLFrameBase *iface, VARIANT *p)
226 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
227 FIXME("(%p)->(%p)\n", This, p);
228 return E_NOTIMPL;
231 static HRESULT WINAPI HTMLFrameBase_put_marginHeight(IHTMLFrameBase *iface, VARIANT v)
233 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
234 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
235 return E_NOTIMPL;
238 static HRESULT WINAPI HTMLFrameBase_get_marginHeight(IHTMLFrameBase *iface, VARIANT *p)
240 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
241 FIXME("(%p)->(%p)\n", This, p);
242 return E_NOTIMPL;
245 static HRESULT WINAPI HTMLFrameBase_put_noResize(IHTMLFrameBase *iface, VARIANT_BOOL v)
247 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
248 FIXME("(%p)->(%x)\n", This, v);
249 return E_NOTIMPL;
252 static HRESULT WINAPI HTMLFrameBase_get_noResize(IHTMLFrameBase *iface, VARIANT_BOOL *p)
254 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
255 FIXME("(%p)->(%p)\n", This, p);
256 return E_NOTIMPL;
259 static HRESULT WINAPI HTMLFrameBase_put_scrolling(IHTMLFrameBase *iface, BSTR v)
261 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
262 nsAString nsstr;
263 nsresult nsres;
265 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
267 if(!(!strcmpiW(v, yesW) || !strcmpiW(v, noW) || !strcmpiW(v, autoW)))
268 return E_INVALIDARG;
270 if(This->nsframe) {
271 nsAString_InitDepend(&nsstr, v);
272 nsres = nsIDOMHTMLFrameElement_SetScrolling(This->nsframe, &nsstr);
273 }else if(This->nsiframe) {
274 nsAString_InitDepend(&nsstr, v);
275 nsres = nsIDOMHTMLIFrameElement_SetScrolling(This->nsiframe, &nsstr);
276 }else {
277 ERR("No attached ns frame object\n");
278 return E_UNEXPECTED;
280 nsAString_Finish(&nsstr);
282 if(NS_FAILED(nsres)) {
283 ERR("SetScrolling failed: 0x%08x\n", nsres);
284 return E_FAIL;
287 return S_OK;
290 static HRESULT WINAPI HTMLFrameBase_get_scrolling(IHTMLFrameBase *iface, BSTR *p)
292 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
293 nsAString nsstr;
294 const PRUnichar *strdata;
295 nsresult nsres;
297 TRACE("(%p)->(%p)\n", This, p);
299 if(This->nsframe) {
300 nsAString_Init(&nsstr, NULL);
301 nsres = nsIDOMHTMLFrameElement_GetScrolling(This->nsframe, &nsstr);
302 }else if(This->nsiframe) {
303 nsAString_Init(&nsstr, NULL);
304 nsres = nsIDOMHTMLIFrameElement_GetScrolling(This->nsiframe, &nsstr);
305 }else {
306 ERR("No attached ns frame object\n");
307 return E_UNEXPECTED;
310 if(NS_FAILED(nsres)) {
311 ERR("GetScrolling failed: 0x%08x\n", nsres);
312 nsAString_Finish(&nsstr);
313 return E_FAIL;
316 nsAString_GetData(&nsstr, &strdata);
318 if(*strdata)
319 *p = SysAllocString(strdata);
320 else
321 *p = SysAllocString(autoW);
323 nsAString_Finish(&nsstr);
325 return *p ? S_OK : E_OUTOFMEMORY;
328 static const IHTMLFrameBaseVtbl HTMLFrameBaseVtbl = {
329 HTMLFrameBase_QueryInterface,
330 HTMLFrameBase_AddRef,
331 HTMLFrameBase_Release,
332 HTMLFrameBase_GetTypeInfoCount,
333 HTMLFrameBase_GetTypeInfo,
334 HTMLFrameBase_GetIDsOfNames,
335 HTMLFrameBase_Invoke,
336 HTMLFrameBase_put_src,
337 HTMLFrameBase_get_src,
338 HTMLFrameBase_put_name,
339 HTMLFrameBase_get_name,
340 HTMLFrameBase_put_border,
341 HTMLFrameBase_get_border,
342 HTMLFrameBase_put_frameBorder,
343 HTMLFrameBase_get_frameBorder,
344 HTMLFrameBase_put_frameSpacing,
345 HTMLFrameBase_get_frameSpacing,
346 HTMLFrameBase_put_marginWidth,
347 HTMLFrameBase_get_marginWidth,
348 HTMLFrameBase_put_marginHeight,
349 HTMLFrameBase_get_marginHeight,
350 HTMLFrameBase_put_noResize,
351 HTMLFrameBase_get_noResize,
352 HTMLFrameBase_put_scrolling,
353 HTMLFrameBase_get_scrolling
356 static inline HTMLFrameBase *impl_from_IHTMLFrameBase2(IHTMLFrameBase2 *iface)
358 return CONTAINING_RECORD(iface, HTMLFrameBase, IHTMLFrameBase2_iface);
361 static HRESULT WINAPI HTMLFrameBase2_QueryInterface(IHTMLFrameBase2 *iface, REFIID riid, void **ppv)
363 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
365 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
368 static ULONG WINAPI HTMLFrameBase2_AddRef(IHTMLFrameBase2 *iface)
370 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
372 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
375 static ULONG WINAPI HTMLFrameBase2_Release(IHTMLFrameBase2 *iface)
377 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
379 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
382 static HRESULT WINAPI HTMLFrameBase2_GetTypeInfoCount(IHTMLFrameBase2 *iface, UINT *pctinfo)
384 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
385 FIXME("(%p)\n", This);
386 return E_NOTIMPL;
389 static HRESULT WINAPI HTMLFrameBase2_GetTypeInfo(IHTMLFrameBase2 *iface, UINT iTInfo,
390 LCID lcid, ITypeInfo **ppTInfo)
392 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
393 FIXME("(%p)\n", This);
394 return E_NOTIMPL;
397 static HRESULT WINAPI HTMLFrameBase2_GetIDsOfNames(IHTMLFrameBase2 *iface, REFIID riid,
398 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
400 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
401 FIXME("(%p)\n", This);
402 return E_NOTIMPL;
405 static HRESULT WINAPI HTMLFrameBase2_Invoke(IHTMLFrameBase2 *iface, DISPID dispIdMember,
406 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
407 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
409 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
410 FIXME("(%p)\n", This);
411 return E_NOTIMPL;
414 static HRESULT WINAPI HTMLFrameBase2_get_contentWindow(IHTMLFrameBase2 *iface, IHTMLWindow2 **p)
416 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
418 TRACE("(%p)->(%p)\n", This, p);
420 if(This->content_window) {
421 IHTMLWindow2_AddRef(&This->content_window->base.IHTMLWindow2_iface);
422 *p = &This->content_window->base.IHTMLWindow2_iface;
423 }else {
424 WARN("NULL content window\n");
425 *p = NULL;
427 return S_OK;
430 static HRESULT WINAPI HTMLFrameBase2_put_onload(IHTMLFrameBase2 *iface, VARIANT v)
432 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
433 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
434 return E_NOTIMPL;
437 static HRESULT WINAPI HTMLFrameBase2_get_onload(IHTMLFrameBase2 *iface, VARIANT *p)
439 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
440 FIXME("(%p)->(%p)\n", This, p);
441 return E_NOTIMPL;
444 static HRESULT WINAPI HTMLFrameBase2_put_onreadystatechange(IHTMLFrameBase2 *iface, VARIANT v)
446 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
447 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
448 return E_NOTIMPL;
451 static HRESULT WINAPI HTMLFrameBase2_get_onreadystatechange(IHTMLFrameBase2 *iface, VARIANT *p)
453 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
454 FIXME("(%p)->(%p)\n", This, p);
455 return E_NOTIMPL;
458 static HRESULT WINAPI HTMLFrameBase2_get_readyState(IHTMLFrameBase2 *iface, BSTR *p)
460 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
462 TRACE("(%p)->(%p)\n", This, p);
464 if(!This->content_window || !This->content_window->doc) {
465 FIXME("no document associated\n");
466 return E_FAIL;
469 return IHTMLDocument2_get_readyState(&This->content_window->doc->basedoc.IHTMLDocument2_iface, p);
472 static HRESULT WINAPI HTMLFrameBase2_put_allowTransparency(IHTMLFrameBase2 *iface, VARIANT_BOOL v)
474 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
475 FIXME("(%p)->(%x)\n", This, v);
476 return E_NOTIMPL;
479 static HRESULT WINAPI HTMLFrameBase2_get_allowTransparency(IHTMLFrameBase2 *iface, VARIANT_BOOL *p)
481 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
482 FIXME("(%p)->(%p)\n", This, p);
483 return E_NOTIMPL;
486 static const IHTMLFrameBase2Vtbl HTMLFrameBase2Vtbl = {
487 HTMLFrameBase2_QueryInterface,
488 HTMLFrameBase2_AddRef,
489 HTMLFrameBase2_Release,
490 HTMLFrameBase2_GetTypeInfoCount,
491 HTMLFrameBase2_GetTypeInfo,
492 HTMLFrameBase2_GetIDsOfNames,
493 HTMLFrameBase2_Invoke,
494 HTMLFrameBase2_get_contentWindow,
495 HTMLFrameBase2_put_onload,
496 HTMLFrameBase2_get_onload,
497 HTMLFrameBase2_put_onreadystatechange,
498 HTMLFrameBase2_get_onreadystatechange,
499 HTMLFrameBase2_get_readyState,
500 HTMLFrameBase2_put_allowTransparency,
501 HTMLFrameBase2_get_allowTransparency
504 HRESULT HTMLFrameBase_QI(HTMLFrameBase *This, REFIID riid, void **ppv)
506 if(IsEqualGUID(&IID_IHTMLFrameBase, riid)) {
507 TRACE("(%p)->(IID_IHTMLFrameBase %p)\n", This, ppv);
508 *ppv = &This->IHTMLFrameBase_iface;
509 }else if(IsEqualGUID(&IID_IHTMLFrameBase2, riid)) {
510 TRACE("(%p)->(IID_IHTMLFrameBase2 %p)\n", This, ppv);
511 *ppv = &This->IHTMLFrameBase2_iface;
512 }else {
513 return HTMLElement_QI(&This->element.node, riid, ppv);
516 IUnknown_AddRef((IUnknown*)*ppv);
517 return S_OK;
520 void HTMLFrameBase_destructor(HTMLFrameBase *This)
522 if(This->content_window)
523 This->content_window->frame_element = NULL;
525 if(This->nsframe)
526 nsIDOMHTMLFrameElement_Release(This->nsframe);
527 if(This->nsiframe)
528 nsIDOMHTMLIFrameElement_Release(This->nsiframe);
530 HTMLElement_destructor(&This->element.node);
533 void HTMLFrameBase_Init(HTMLFrameBase *This, HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem,
534 dispex_static_data_t *dispex_data)
536 nsresult nsres;
538 This->IHTMLFrameBase_iface.lpVtbl = &HTMLFrameBaseVtbl;
539 This->IHTMLFrameBase2_iface.lpVtbl = &HTMLFrameBase2Vtbl;
541 HTMLElement_Init(&This->element, doc, nselem, dispex_data);
543 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLFrameElement, (void**)&This->nsframe);
544 if(NS_FAILED(nsres)) {
545 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLIFrameElement, (void**)&This->nsiframe);
546 if(NS_FAILED(nsres))
547 ERR("Could not get nsIDOMHTML[I]Frame interface\n");
548 }else
549 This->nsiframe = NULL;