wininet: Support the Cache-Control max-age directive for setting url cache entry...
[wine/testsucceed.git] / dlls / mshtml / htmlframebase.c
blob850d1a9b754b764091779d36de0153f28959096c
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 HTMLWindow *window;
42 HRESULT hres = S_OK;
44 if(frame->content_window)
45 return S_OK;
47 nswindow = get_nsdoc_window(nsdoc);
48 if(!nswindow)
49 return E_FAIL;
51 window = nswindow_to_window(nswindow);
52 if(!window)
53 hres = HTMLWindow_Create(frame->element.node.doc->basedoc.doc_obj, nswindow,
54 frame->element.node.doc->basedoc.window, &window);
55 nsIDOMWindow_Release(nswindow);
56 if(FAILED(hres))
57 return hres;
59 frame->content_window = window;
60 window->frame_element = frame;
61 return S_OK;
64 static inline HTMLFrameBase *impl_from_IHTMLFrameBase(IHTMLFrameBase *iface)
66 return CONTAINING_RECORD(iface, HTMLFrameBase, IHTMLFrameBase_iface);
69 static HRESULT WINAPI HTMLFrameBase_QueryInterface(IHTMLFrameBase *iface, REFIID riid, void **ppv)
71 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
73 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
76 static ULONG WINAPI HTMLFrameBase_AddRef(IHTMLFrameBase *iface)
78 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
80 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
83 static ULONG WINAPI HTMLFrameBase_Release(IHTMLFrameBase *iface)
85 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
87 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
90 static HRESULT WINAPI HTMLFrameBase_GetTypeInfoCount(IHTMLFrameBase *iface, UINT *pctinfo)
92 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
94 return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
97 static HRESULT WINAPI HTMLFrameBase_GetTypeInfo(IHTMLFrameBase *iface, UINT iTInfo,
98 LCID lcid, ITypeInfo **ppTInfo)
100 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
102 return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
103 ppTInfo);
106 static HRESULT WINAPI HTMLFrameBase_GetIDsOfNames(IHTMLFrameBase *iface, REFIID riid,
107 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
109 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
111 return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
112 cNames, lcid, rgDispId);
115 static HRESULT WINAPI HTMLFrameBase_Invoke(IHTMLFrameBase *iface, DISPID dispIdMember,
116 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
117 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
119 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
121 return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
122 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
125 static HRESULT WINAPI HTMLFrameBase_put_src(IHTMLFrameBase *iface, BSTR v)
127 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
129 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
131 if(!This->content_window || !This->element.node.doc || !This->element.node.doc->basedoc.window) {
132 FIXME("detached element\n");
133 return E_FAIL;
136 return navigate_url(This->content_window, v, This->element.node.doc->basedoc.window->url);
139 static HRESULT WINAPI HTMLFrameBase_get_src(IHTMLFrameBase *iface, BSTR *p)
141 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
142 FIXME("(%p)->(%p)\n", This, p);
143 return E_NOTIMPL;
146 static HRESULT WINAPI HTMLFrameBase_put_name(IHTMLFrameBase *iface, BSTR v)
148 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
149 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
150 return E_NOTIMPL;
153 static HRESULT WINAPI HTMLFrameBase_get_name(IHTMLFrameBase *iface, BSTR *p)
155 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
156 nsAString nsstr;
157 const PRUnichar *strdata;
158 nsresult nsres;
160 TRACE("(%p)->(%p)\n", This, p);
162 if(This->nsframe) {
163 nsAString_Init(&nsstr, NULL);
164 nsres = nsIDOMHTMLFrameElement_GetName(This->nsframe, &nsstr);
165 }else if(This->nsiframe) {
166 nsAString_Init(&nsstr, NULL);
167 nsres = nsIDOMHTMLIFrameElement_GetName(This->nsiframe, &nsstr);
168 }else {
169 ERR("No attached ns frame object\n");
170 return E_UNEXPECTED;
173 if(NS_FAILED(nsres)) {
174 ERR("GetName failed: 0x%08x\n", nsres);
175 nsAString_Finish(&nsstr);
176 return E_FAIL;
179 nsAString_GetData(&nsstr, &strdata);
180 if(*strdata) {
181 *p = SysAllocString(strdata);
182 if(!*p) {
183 nsAString_Finish(&nsstr);
184 return E_OUTOFMEMORY;
186 }else
187 *p = NULL;
189 nsAString_Finish(&nsstr);
191 return S_OK;
194 static HRESULT WINAPI HTMLFrameBase_put_border(IHTMLFrameBase *iface, VARIANT v)
196 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
197 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
198 return E_NOTIMPL;
201 static HRESULT WINAPI HTMLFrameBase_get_border(IHTMLFrameBase *iface, VARIANT *p)
203 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
204 FIXME("(%p)->(%p)\n", This, p);
205 return E_NOTIMPL;
208 static HRESULT WINAPI HTMLFrameBase_put_frameBorder(IHTMLFrameBase *iface, BSTR v)
210 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
211 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
212 return E_NOTIMPL;
215 static HRESULT WINAPI HTMLFrameBase_get_frameBorder(IHTMLFrameBase *iface, BSTR *p)
217 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
218 FIXME("(%p)->(%p)\n", This, p);
219 return E_NOTIMPL;
222 static HRESULT WINAPI HTMLFrameBase_put_frameSpacing(IHTMLFrameBase *iface, VARIANT v)
224 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
225 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
226 return E_NOTIMPL;
229 static HRESULT WINAPI HTMLFrameBase_get_frameSpacing(IHTMLFrameBase *iface, VARIANT *p)
231 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
232 FIXME("(%p)->(%p)\n", This, p);
233 return E_NOTIMPL;
236 static HRESULT WINAPI HTMLFrameBase_put_marginWidth(IHTMLFrameBase *iface, VARIANT v)
238 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
239 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
240 return E_NOTIMPL;
243 static HRESULT WINAPI HTMLFrameBase_get_marginWidth(IHTMLFrameBase *iface, VARIANT *p)
245 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
246 FIXME("(%p)->(%p)\n", This, p);
247 return E_NOTIMPL;
250 static HRESULT WINAPI HTMLFrameBase_put_marginHeight(IHTMLFrameBase *iface, VARIANT v)
252 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
253 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
254 return E_NOTIMPL;
257 static HRESULT WINAPI HTMLFrameBase_get_marginHeight(IHTMLFrameBase *iface, VARIANT *p)
259 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
260 FIXME("(%p)->(%p)\n", This, p);
261 return E_NOTIMPL;
264 static HRESULT WINAPI HTMLFrameBase_put_noResize(IHTMLFrameBase *iface, VARIANT_BOOL v)
266 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
267 FIXME("(%p)->(%x)\n", This, v);
268 return E_NOTIMPL;
271 static HRESULT WINAPI HTMLFrameBase_get_noResize(IHTMLFrameBase *iface, VARIANT_BOOL *p)
273 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
274 FIXME("(%p)->(%p)\n", This, p);
275 return E_NOTIMPL;
278 static HRESULT WINAPI HTMLFrameBase_put_scrolling(IHTMLFrameBase *iface, BSTR v)
280 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
281 nsAString nsstr;
282 nsresult nsres;
284 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
286 if(!(!strcmpiW(v, yesW) || !strcmpiW(v, noW) || !strcmpiW(v, autoW)))
287 return E_INVALIDARG;
289 if(This->nsframe) {
290 nsAString_InitDepend(&nsstr, v);
291 nsres = nsIDOMHTMLFrameElement_SetScrolling(This->nsframe, &nsstr);
292 }else if(This->nsiframe) {
293 nsAString_InitDepend(&nsstr, v);
294 nsres = nsIDOMHTMLIFrameElement_SetScrolling(This->nsiframe, &nsstr);
295 }else {
296 ERR("No attached ns frame object\n");
297 return E_UNEXPECTED;
299 nsAString_Finish(&nsstr);
301 if(NS_FAILED(nsres)) {
302 ERR("SetScrolling failed: 0x%08x\n", nsres);
303 return E_FAIL;
306 return S_OK;
309 static HRESULT WINAPI HTMLFrameBase_get_scrolling(IHTMLFrameBase *iface, BSTR *p)
311 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
312 nsAString nsstr;
313 const PRUnichar *strdata;
314 nsresult nsres;
316 TRACE("(%p)->(%p)\n", This, p);
318 if(This->nsframe) {
319 nsAString_Init(&nsstr, NULL);
320 nsres = nsIDOMHTMLFrameElement_GetScrolling(This->nsframe, &nsstr);
321 }else if(This->nsiframe) {
322 nsAString_Init(&nsstr, NULL);
323 nsres = nsIDOMHTMLIFrameElement_GetScrolling(This->nsiframe, &nsstr);
324 }else {
325 ERR("No attached ns frame object\n");
326 return E_UNEXPECTED;
329 if(NS_FAILED(nsres)) {
330 ERR("GetScrolling failed: 0x%08x\n", nsres);
331 nsAString_Finish(&nsstr);
332 return E_FAIL;
335 nsAString_GetData(&nsstr, &strdata);
337 if(*strdata)
338 *p = SysAllocString(strdata);
339 else
340 *p = SysAllocString(autoW);
342 nsAString_Finish(&nsstr);
344 return *p ? S_OK : E_OUTOFMEMORY;
347 static const IHTMLFrameBaseVtbl HTMLFrameBaseVtbl = {
348 HTMLFrameBase_QueryInterface,
349 HTMLFrameBase_AddRef,
350 HTMLFrameBase_Release,
351 HTMLFrameBase_GetTypeInfoCount,
352 HTMLFrameBase_GetTypeInfo,
353 HTMLFrameBase_GetIDsOfNames,
354 HTMLFrameBase_Invoke,
355 HTMLFrameBase_put_src,
356 HTMLFrameBase_get_src,
357 HTMLFrameBase_put_name,
358 HTMLFrameBase_get_name,
359 HTMLFrameBase_put_border,
360 HTMLFrameBase_get_border,
361 HTMLFrameBase_put_frameBorder,
362 HTMLFrameBase_get_frameBorder,
363 HTMLFrameBase_put_frameSpacing,
364 HTMLFrameBase_get_frameSpacing,
365 HTMLFrameBase_put_marginWidth,
366 HTMLFrameBase_get_marginWidth,
367 HTMLFrameBase_put_marginHeight,
368 HTMLFrameBase_get_marginHeight,
369 HTMLFrameBase_put_noResize,
370 HTMLFrameBase_get_noResize,
371 HTMLFrameBase_put_scrolling,
372 HTMLFrameBase_get_scrolling
375 static inline HTMLFrameBase *impl_from_IHTMLFrameBase2(IHTMLFrameBase2 *iface)
377 return CONTAINING_RECORD(iface, HTMLFrameBase, IHTMLFrameBase2_iface);
380 static HRESULT WINAPI HTMLFrameBase2_QueryInterface(IHTMLFrameBase2 *iface, REFIID riid, void **ppv)
382 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
384 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
387 static ULONG WINAPI HTMLFrameBase2_AddRef(IHTMLFrameBase2 *iface)
389 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
391 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
394 static ULONG WINAPI HTMLFrameBase2_Release(IHTMLFrameBase2 *iface)
396 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
398 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
401 static HRESULT WINAPI HTMLFrameBase2_GetTypeInfoCount(IHTMLFrameBase2 *iface, UINT *pctinfo)
403 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
404 FIXME("(%p)\n", This);
405 return E_NOTIMPL;
408 static HRESULT WINAPI HTMLFrameBase2_GetTypeInfo(IHTMLFrameBase2 *iface, UINT iTInfo,
409 LCID lcid, ITypeInfo **ppTInfo)
411 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
412 FIXME("(%p)\n", This);
413 return E_NOTIMPL;
416 static HRESULT WINAPI HTMLFrameBase2_GetIDsOfNames(IHTMLFrameBase2 *iface, REFIID riid,
417 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
419 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
420 FIXME("(%p)\n", This);
421 return E_NOTIMPL;
424 static HRESULT WINAPI HTMLFrameBase2_Invoke(IHTMLFrameBase2 *iface, DISPID dispIdMember,
425 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
426 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
428 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
429 FIXME("(%p)\n", This);
430 return E_NOTIMPL;
433 static HRESULT WINAPI HTMLFrameBase2_get_contentWindow(IHTMLFrameBase2 *iface, IHTMLWindow2 **p)
435 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
437 TRACE("(%p)->(%p)\n", This, p);
439 if(This->content_window) {
440 IHTMLWindow2_AddRef(&This->content_window->IHTMLWindow2_iface);
441 *p = &This->content_window->IHTMLWindow2_iface;
442 }else {
443 WARN("NULL content window\n");
444 *p = NULL;
446 return S_OK;
449 static HRESULT WINAPI HTMLFrameBase2_put_onload(IHTMLFrameBase2 *iface, VARIANT v)
451 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
452 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
453 return E_NOTIMPL;
456 static HRESULT WINAPI HTMLFrameBase2_get_onload(IHTMLFrameBase2 *iface, VARIANT *p)
458 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
459 FIXME("(%p)->(%p)\n", This, p);
460 return E_NOTIMPL;
463 static HRESULT WINAPI HTMLFrameBase2_put_onreadystatechange(IHTMLFrameBase2 *iface, VARIANT v)
465 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
466 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
467 return E_NOTIMPL;
470 static HRESULT WINAPI HTMLFrameBase2_get_onreadystatechange(IHTMLFrameBase2 *iface, VARIANT *p)
472 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
473 FIXME("(%p)->(%p)\n", This, p);
474 return E_NOTIMPL;
477 static HRESULT WINAPI HTMLFrameBase2_get_readyState(IHTMLFrameBase2 *iface, BSTR *p)
479 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
481 TRACE("(%p)->(%p)\n", This, p);
483 if(!This->content_window || !This->content_window->doc) {
484 FIXME("no document associated\n");
485 return E_FAIL;
488 return IHTMLDocument2_get_readyState(&This->content_window->doc->basedoc.IHTMLDocument2_iface, p);
491 static HRESULT WINAPI HTMLFrameBase2_put_allowTransparency(IHTMLFrameBase2 *iface, VARIANT_BOOL v)
493 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
494 FIXME("(%p)->(%x)\n", This, v);
495 return E_NOTIMPL;
498 static HRESULT WINAPI HTMLFrameBase2_get_allowTransparency(IHTMLFrameBase2 *iface, VARIANT_BOOL *p)
500 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
501 FIXME("(%p)->(%p)\n", This, p);
502 return E_NOTIMPL;
505 static const IHTMLFrameBase2Vtbl HTMLFrameBase2Vtbl = {
506 HTMLFrameBase2_QueryInterface,
507 HTMLFrameBase2_AddRef,
508 HTMLFrameBase2_Release,
509 HTMLFrameBase2_GetTypeInfoCount,
510 HTMLFrameBase2_GetTypeInfo,
511 HTMLFrameBase2_GetIDsOfNames,
512 HTMLFrameBase2_Invoke,
513 HTMLFrameBase2_get_contentWindow,
514 HTMLFrameBase2_put_onload,
515 HTMLFrameBase2_get_onload,
516 HTMLFrameBase2_put_onreadystatechange,
517 HTMLFrameBase2_get_onreadystatechange,
518 HTMLFrameBase2_get_readyState,
519 HTMLFrameBase2_put_allowTransparency,
520 HTMLFrameBase2_get_allowTransparency
523 HRESULT HTMLFrameBase_QI(HTMLFrameBase *This, REFIID riid, void **ppv)
525 if(IsEqualGUID(&IID_IHTMLFrameBase, riid)) {
526 TRACE("(%p)->(IID_IHTMLFrameBase %p)\n", This, ppv);
527 *ppv = &This->IHTMLFrameBase_iface;
528 }else if(IsEqualGUID(&IID_IHTMLFrameBase2, riid)) {
529 TRACE("(%p)->(IID_IHTMLFrameBase2 %p)\n", This, ppv);
530 *ppv = &This->IHTMLFrameBase2_iface;
531 }else {
532 return HTMLElement_QI(&This->element.node, riid, ppv);
535 IUnknown_AddRef((IUnknown*)*ppv);
536 return S_OK;
539 void HTMLFrameBase_destructor(HTMLFrameBase *This)
541 if(This->content_window)
542 This->content_window->frame_element = NULL;
544 if(This->nsframe)
545 nsIDOMHTMLFrameElement_Release(This->nsframe);
546 if(This->nsiframe)
547 nsIDOMHTMLIFrameElement_Release(This->nsiframe);
549 HTMLElement_destructor(&This->element.node);
552 void HTMLFrameBase_Init(HTMLFrameBase *This, HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem,
553 dispex_static_data_t *dispex_data)
555 nsresult nsres;
557 This->IHTMLFrameBase_iface.lpVtbl = &HTMLFrameBaseVtbl;
558 This->IHTMLFrameBase2_iface.lpVtbl = &HTMLFrameBase2Vtbl;
560 HTMLElement_Init(&This->element, doc, nselem, dispex_data);
562 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLFrameElement, (void**)&This->nsframe);
563 if(NS_FAILED(nsres)) {
564 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLIFrameElement, (void**)&This->nsiframe);
565 if(NS_FAILED(nsres))
566 ERR("Could not get nsIDOMHTML[I]Frame interface\n");
567 }else
568 This->nsiframe = NULL;