shlwapi: Beginning implementation of IUnknown_QueryServiceForWebBrowserApp.
[wine] / dlls / mshtml / htmliframe.c
1 /*
2  * Copyright 2008 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <stdarg.h>
20
21 #define COBJMACROS
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
27
28 #include "mshtml_private.h"
29
30 #include "wine/debug.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
33
34 typedef struct {
35     HTMLFrameBase framebase;
36 } HTMLIFrame;
37
38 #define HTMLIFRAME_NODE_THIS(iface) DEFINE_THIS2(HTMLIFrame, framebase.element.node, iface)
39
40 static HRESULT HTMLIFrame_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
41 {
42     HTMLIFrame *This = HTMLIFRAME_NODE_THIS(iface);
43
44     return HTMLFrameBase_QI(&This->framebase, riid, ppv);
45 }
46
47 static void HTMLIFrame_destructor(HTMLDOMNode *iface)
48 {
49     HTMLIFrame *This = HTMLIFRAME_NODE_THIS(iface);
50
51     HTMLFrameBase_destructor(&This->framebase);
52 }
53
54 static HRESULT HTMLIFrame_get_document(HTMLDOMNode *iface, IDispatch **p)
55 {
56     HTMLIFrame *This = HTMLIFRAME_NODE_THIS(iface);
57
58     if(!This->framebase.content_window || !This->framebase.content_window->doc) {
59         *p = NULL;
60         return S_OK;
61     }
62
63     *p = (IDispatch*)HTMLDOC(&This->framebase.content_window->doc->basedoc);
64     IDispatch_AddRef(*p);
65     return S_OK;
66 }
67
68 static HRESULT HTMLIFrame_get_readystate(HTMLDOMNode *iface, BSTR *p)
69 {
70     HTMLIFrame *This = HTMLIFRAME_NODE_THIS(iface);
71
72     return IHTMLFrameBase2_get_readyState(HTMLFRAMEBASE2(&This->framebase), p);
73 }
74
75 static HRESULT HTMLIFrame_bind_to_tree(HTMLDOMNode *iface)
76 {
77     HTMLIFrame *This = HTMLIFRAME_NODE_THIS(iface);
78     nsIDOMDocument *nsdoc;
79     nsresult nsres;
80     HRESULT hres;
81
82     nsres = nsIDOMHTMLIFrameElement_GetContentDocument(This->framebase.nsiframe, &nsdoc);
83     if(NS_FAILED(nsres) || !nsdoc) {
84         ERR("GetContentDocument failed: %08x\n", nsres);
85         return E_FAIL;
86     }
87
88     hres = set_frame_doc(&This->framebase, nsdoc);
89     nsIDOMDocument_Release(nsdoc);
90     return hres;
91 }
92
93 #undef HTMLIFRAME_NODE_THIS
94
95 static const NodeImplVtbl HTMLIFrameImplVtbl = {
96     HTMLIFrame_QI,
97     HTMLIFrame_destructor,
98     NULL,
99     NULL,
100     NULL,
101     NULL,
102     HTMLIFrame_get_document,
103     HTMLIFrame_get_readystate,
104     NULL,
105     NULL,
106     HTMLIFrame_bind_to_tree
107 };
108
109 static const tid_t HTMLIFrame_iface_tids[] = {
110     IHTMLDOMNode_tid,
111     IHTMLDOMNode2_tid,
112     IHTMLElement_tid,
113     IHTMLElement2_tid,
114     IHTMLElement3_tid,
115     IHTMLFrameBase_tid,
116     IHTMLFrameBase2_tid,
117     0
118 };
119
120 static dispex_static_data_t HTMLIFrame_dispex = {
121     NULL,
122     DispHTMLIFrame_tid,
123     NULL,
124     HTMLIFrame_iface_tids
125 };
126
127 HTMLElement *HTMLIFrame_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem)
128 {
129     HTMLIFrame *ret;
130
131     ret = heap_alloc_zero(sizeof(HTMLIFrame));
132
133     ret->framebase.element.node.vtbl = &HTMLIFrameImplVtbl;
134
135     HTMLFrameBase_Init(&ret->framebase, doc, nselem, &HTMLIFrame_dispex);
136
137     return &ret->framebase.element;
138 }