mshtml: Share nsscript reference with nsnode.
[wine/multimedia.git] / dlls / mshtml / htmlframebase.c
bloba5344ec7b8f640cefaf7e1c44155aaf049cd0dbb
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>
20 #include <assert.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
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;
43 nsresult nsres;
44 HRESULT hres = S_OK;
46 if(frame->content_window)
47 return S_OK;
49 nsres = nsIDOMDocument_GetDefaultView(nsdoc, &nswindow);
50 if(NS_FAILED(nsres) || !nswindow)
51 return E_FAIL;
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;
61 frame->content_window = window;
62 window->frame_element = frame;
63 return S_OK;
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,
105 ppTInfo);
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");
135 return E_FAIL;
138 return navigate_url(This->content_window, v, This->element.node.doc->basedoc.window->url);
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);
145 return E_NOTIMPL;
148 static HRESULT WINAPI HTMLFrameBase_put_name(IHTMLFrameBase *iface, BSTR v)
150 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
151 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
152 return E_NOTIMPL;
155 static HRESULT WINAPI HTMLFrameBase_get_name(IHTMLFrameBase *iface, BSTR *p)
157 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
158 nsAString nsstr;
159 nsresult nsres;
161 TRACE("(%p)->(%p)\n", This, p);
163 if(!This->nsframe && !This->nsiframe) {
164 ERR("No attached ns frame object\n");
165 return E_UNEXPECTED;
168 nsAString_Init(&nsstr, NULL);
169 if(This->nsframe)
170 nsres = nsIDOMHTMLFrameElement_GetName(This->nsframe, &nsstr);
171 else
172 nsres = nsIDOMHTMLIFrameElement_GetName(This->nsiframe, &nsstr);
173 return return_nsstr(nsres, &nsstr, p);
176 static HRESULT WINAPI HTMLFrameBase_put_border(IHTMLFrameBase *iface, VARIANT v)
178 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
179 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
180 return E_NOTIMPL;
183 static HRESULT WINAPI HTMLFrameBase_get_border(IHTMLFrameBase *iface, VARIANT *p)
185 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
186 FIXME("(%p)->(%p)\n", This, p);
187 return E_NOTIMPL;
190 static HRESULT WINAPI HTMLFrameBase_put_frameBorder(IHTMLFrameBase *iface, BSTR v)
192 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
193 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
194 return E_NOTIMPL;
197 static HRESULT WINAPI HTMLFrameBase_get_frameBorder(IHTMLFrameBase *iface, BSTR *p)
199 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
200 FIXME("(%p)->(%p)\n", This, p);
201 return E_NOTIMPL;
204 static HRESULT WINAPI HTMLFrameBase_put_frameSpacing(IHTMLFrameBase *iface, VARIANT v)
206 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
207 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
208 return E_NOTIMPL;
211 static HRESULT WINAPI HTMLFrameBase_get_frameSpacing(IHTMLFrameBase *iface, VARIANT *p)
213 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
214 FIXME("(%p)->(%p)\n", This, p);
215 return E_NOTIMPL;
218 static HRESULT WINAPI HTMLFrameBase_put_marginWidth(IHTMLFrameBase *iface, VARIANT v)
220 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
221 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
222 return E_NOTIMPL;
225 static HRESULT WINAPI HTMLFrameBase_get_marginWidth(IHTMLFrameBase *iface, VARIANT *p)
227 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
228 FIXME("(%p)->(%p)\n", This, p);
229 return E_NOTIMPL;
232 static HRESULT WINAPI HTMLFrameBase_put_marginHeight(IHTMLFrameBase *iface, VARIANT v)
234 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
235 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
236 return E_NOTIMPL;
239 static HRESULT WINAPI HTMLFrameBase_get_marginHeight(IHTMLFrameBase *iface, VARIANT *p)
241 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
242 FIXME("(%p)->(%p)\n", This, p);
243 return E_NOTIMPL;
246 static HRESULT WINAPI HTMLFrameBase_put_noResize(IHTMLFrameBase *iface, VARIANT_BOOL v)
248 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
249 FIXME("(%p)->(%x)\n", This, v);
250 return E_NOTIMPL;
253 static HRESULT WINAPI HTMLFrameBase_get_noResize(IHTMLFrameBase *iface, VARIANT_BOOL *p)
255 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
256 FIXME("(%p)->(%p)\n", This, p);
257 return E_NOTIMPL;
260 static HRESULT WINAPI HTMLFrameBase_put_scrolling(IHTMLFrameBase *iface, BSTR v)
262 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
263 nsAString nsstr;
264 nsresult nsres;
266 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
268 if(!(!strcmpiW(v, yesW) || !strcmpiW(v, noW) || !strcmpiW(v, autoW)))
269 return E_INVALIDARG;
271 if(This->nsframe) {
272 nsAString_InitDepend(&nsstr, v);
273 nsres = nsIDOMHTMLFrameElement_SetScrolling(This->nsframe, &nsstr);
274 }else if(This->nsiframe) {
275 nsAString_InitDepend(&nsstr, v);
276 nsres = nsIDOMHTMLIFrameElement_SetScrolling(This->nsiframe, &nsstr);
277 }else {
278 ERR("No attached ns frame object\n");
279 return E_UNEXPECTED;
281 nsAString_Finish(&nsstr);
283 if(NS_FAILED(nsres)) {
284 ERR("SetScrolling failed: 0x%08x\n", nsres);
285 return E_FAIL;
288 return S_OK;
291 static HRESULT WINAPI HTMLFrameBase_get_scrolling(IHTMLFrameBase *iface, BSTR *p)
293 HTMLFrameBase *This = impl_from_IHTMLFrameBase(iface);
294 nsAString nsstr;
295 const PRUnichar *strdata;
296 nsresult nsres;
298 TRACE("(%p)->(%p)\n", This, p);
300 if(This->nsframe) {
301 nsAString_Init(&nsstr, NULL);
302 nsres = nsIDOMHTMLFrameElement_GetScrolling(This->nsframe, &nsstr);
303 }else if(This->nsiframe) {
304 nsAString_Init(&nsstr, NULL);
305 nsres = nsIDOMHTMLIFrameElement_GetScrolling(This->nsiframe, &nsstr);
306 }else {
307 ERR("No attached ns frame object\n");
308 return E_UNEXPECTED;
311 if(NS_FAILED(nsres)) {
312 ERR("GetScrolling failed: 0x%08x\n", nsres);
313 nsAString_Finish(&nsstr);
314 return E_FAIL;
317 nsAString_GetData(&nsstr, &strdata);
319 if(*strdata)
320 *p = SysAllocString(strdata);
321 else
322 *p = SysAllocString(autoW);
324 nsAString_Finish(&nsstr);
326 return *p ? S_OK : E_OUTOFMEMORY;
329 static const IHTMLFrameBaseVtbl HTMLFrameBaseVtbl = {
330 HTMLFrameBase_QueryInterface,
331 HTMLFrameBase_AddRef,
332 HTMLFrameBase_Release,
333 HTMLFrameBase_GetTypeInfoCount,
334 HTMLFrameBase_GetTypeInfo,
335 HTMLFrameBase_GetIDsOfNames,
336 HTMLFrameBase_Invoke,
337 HTMLFrameBase_put_src,
338 HTMLFrameBase_get_src,
339 HTMLFrameBase_put_name,
340 HTMLFrameBase_get_name,
341 HTMLFrameBase_put_border,
342 HTMLFrameBase_get_border,
343 HTMLFrameBase_put_frameBorder,
344 HTMLFrameBase_get_frameBorder,
345 HTMLFrameBase_put_frameSpacing,
346 HTMLFrameBase_get_frameSpacing,
347 HTMLFrameBase_put_marginWidth,
348 HTMLFrameBase_get_marginWidth,
349 HTMLFrameBase_put_marginHeight,
350 HTMLFrameBase_get_marginHeight,
351 HTMLFrameBase_put_noResize,
352 HTMLFrameBase_get_noResize,
353 HTMLFrameBase_put_scrolling,
354 HTMLFrameBase_get_scrolling
357 static inline HTMLFrameBase *impl_from_IHTMLFrameBase2(IHTMLFrameBase2 *iface)
359 return CONTAINING_RECORD(iface, HTMLFrameBase, IHTMLFrameBase2_iface);
362 static HRESULT WINAPI HTMLFrameBase2_QueryInterface(IHTMLFrameBase2 *iface, REFIID riid, void **ppv)
364 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
366 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
369 static ULONG WINAPI HTMLFrameBase2_AddRef(IHTMLFrameBase2 *iface)
371 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
373 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
376 static ULONG WINAPI HTMLFrameBase2_Release(IHTMLFrameBase2 *iface)
378 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
380 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
383 static HRESULT WINAPI HTMLFrameBase2_GetTypeInfoCount(IHTMLFrameBase2 *iface, UINT *pctinfo)
385 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
386 FIXME("(%p)\n", This);
387 return E_NOTIMPL;
390 static HRESULT WINAPI HTMLFrameBase2_GetTypeInfo(IHTMLFrameBase2 *iface, UINT iTInfo,
391 LCID lcid, ITypeInfo **ppTInfo)
393 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
394 FIXME("(%p)\n", This);
395 return E_NOTIMPL;
398 static HRESULT WINAPI HTMLFrameBase2_GetIDsOfNames(IHTMLFrameBase2 *iface, REFIID riid,
399 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
401 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
402 FIXME("(%p)\n", This);
403 return E_NOTIMPL;
406 static HRESULT WINAPI HTMLFrameBase2_Invoke(IHTMLFrameBase2 *iface, DISPID dispIdMember,
407 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
408 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
410 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
411 FIXME("(%p)\n", This);
412 return E_NOTIMPL;
415 static HRESULT WINAPI HTMLFrameBase2_get_contentWindow(IHTMLFrameBase2 *iface, IHTMLWindow2 **p)
417 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
419 TRACE("(%p)->(%p)\n", This, p);
421 if(This->content_window) {
422 IHTMLWindow2_AddRef(&This->content_window->base.IHTMLWindow2_iface);
423 *p = &This->content_window->base.IHTMLWindow2_iface;
424 }else {
425 WARN("NULL content window\n");
426 *p = NULL;
428 return S_OK;
431 static HRESULT WINAPI HTMLFrameBase2_put_onload(IHTMLFrameBase2 *iface, VARIANT v)
433 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
434 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
435 return E_NOTIMPL;
438 static HRESULT WINAPI HTMLFrameBase2_get_onload(IHTMLFrameBase2 *iface, VARIANT *p)
440 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
441 FIXME("(%p)->(%p)\n", This, p);
442 return E_NOTIMPL;
445 static HRESULT WINAPI HTMLFrameBase2_put_onreadystatechange(IHTMLFrameBase2 *iface, VARIANT v)
447 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
448 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
449 return E_NOTIMPL;
452 static HRESULT WINAPI HTMLFrameBase2_get_onreadystatechange(IHTMLFrameBase2 *iface, VARIANT *p)
454 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
455 FIXME("(%p)->(%p)\n", This, p);
456 return E_NOTIMPL;
459 static HRESULT WINAPI HTMLFrameBase2_get_readyState(IHTMLFrameBase2 *iface, BSTR *p)
461 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
463 TRACE("(%p)->(%p)\n", This, p);
465 if(!This->content_window || !This->content_window->base.inner_window->doc) {
466 FIXME("no document associated\n");
467 return E_FAIL;
470 return IHTMLDocument2_get_readyState(&This->content_window->base.inner_window->doc->basedoc.IHTMLDocument2_iface, p);
473 static HRESULT WINAPI HTMLFrameBase2_put_allowTransparency(IHTMLFrameBase2 *iface, VARIANT_BOOL v)
475 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
476 FIXME("(%p)->(%x)\n", This, v);
477 return E_NOTIMPL;
480 static HRESULT WINAPI HTMLFrameBase2_get_allowTransparency(IHTMLFrameBase2 *iface, VARIANT_BOOL *p)
482 HTMLFrameBase *This = impl_from_IHTMLFrameBase2(iface);
483 FIXME("(%p)->(%p)\n", This, p);
484 return E_NOTIMPL;
487 static const IHTMLFrameBase2Vtbl HTMLFrameBase2Vtbl = {
488 HTMLFrameBase2_QueryInterface,
489 HTMLFrameBase2_AddRef,
490 HTMLFrameBase2_Release,
491 HTMLFrameBase2_GetTypeInfoCount,
492 HTMLFrameBase2_GetTypeInfo,
493 HTMLFrameBase2_GetIDsOfNames,
494 HTMLFrameBase2_Invoke,
495 HTMLFrameBase2_get_contentWindow,
496 HTMLFrameBase2_put_onload,
497 HTMLFrameBase2_get_onload,
498 HTMLFrameBase2_put_onreadystatechange,
499 HTMLFrameBase2_get_onreadystatechange,
500 HTMLFrameBase2_get_readyState,
501 HTMLFrameBase2_put_allowTransparency,
502 HTMLFrameBase2_get_allowTransparency
505 HRESULT HTMLFrameBase_QI(HTMLFrameBase *This, REFIID riid, void **ppv)
507 if(IsEqualGUID(&IID_IHTMLFrameBase, riid)) {
508 TRACE("(%p)->(IID_IHTMLFrameBase %p)\n", This, ppv);
509 *ppv = &This->IHTMLFrameBase_iface;
510 }else if(IsEqualGUID(&IID_IHTMLFrameBase2, riid)) {
511 TRACE("(%p)->(IID_IHTMLFrameBase2 %p)\n", This, ppv);
512 *ppv = &This->IHTMLFrameBase2_iface;
513 }else {
514 return HTMLElement_QI(&This->element.node, riid, ppv);
517 IUnknown_AddRef((IUnknown*)*ppv);
518 return S_OK;
521 void HTMLFrameBase_destructor(HTMLFrameBase *This)
523 if(This->content_window)
524 This->content_window->frame_element = NULL;
526 HTMLElement_destructor(&This->element.node);
529 void HTMLFrameBase_Init(HTMLFrameBase *This, HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem,
530 dispex_static_data_t *dispex_data)
532 nsresult nsres;
534 This->IHTMLFrameBase_iface.lpVtbl = &HTMLFrameBaseVtbl;
535 This->IHTMLFrameBase2_iface.lpVtbl = &HTMLFrameBase2Vtbl;
537 HTMLElement_Init(&This->element, doc, nselem, dispex_data);
539 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLFrameElement, (void**)&This->nsframe);
540 if(NS_FAILED(nsres)) {
541 This->nsframe = NULL;
542 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLIFrameElement, (void**)&This->nsiframe);
543 assert(nsres == NS_OK && (nsIDOMNode*)This->nsiframe == This->element.node.nsnode);
544 }else {
545 assert((nsIDOMNode*)This->nsframe == This->element.node.nsnode);
546 This->nsiframe = NULL;
549 /* Share the reference with nsnode */
550 nsIDOMNode_Release(This->element.node.nsnode);