explorerframe: Implement expansion of nodes.
[wine] / dlls / mshtml / omnavigator.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 "wine/debug.h"
29
30 #include "mshtml_private.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
33
34 typedef struct {
35     DispatchEx dispex;
36     const IOmNavigatorVtbl  *lpIOmNavigatorVtbl;
37
38     LONG ref;
39 } OmNavigator;
40
41 #define OMNAVIGATOR(x)  ((IOmNavigator*) &(x)->lpIOmNavigatorVtbl)
42
43 #define OMNAVIGATOR_THIS(iface) DEFINE_THIS(OmNavigator, IOmNavigator, iface)
44
45 static HRESULT WINAPI OmNavigator_QueryInterface(IOmNavigator *iface, REFIID riid, void **ppv)
46 {
47     OmNavigator *This = OMNAVIGATOR_THIS(iface);
48
49     *ppv = NULL;
50
51     if(IsEqualGUID(&IID_IUnknown, riid)) {
52         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
53         *ppv = OMNAVIGATOR(This);
54     }else if(IsEqualGUID(&IID_IOmNavigator, riid)) {
55         TRACE("(%p)->(IID_IOmNavigator %p)\n", This, ppv);
56         *ppv = OMNAVIGATOR(This);
57     }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
58         return *ppv ? S_OK : E_NOINTERFACE;
59     }
60
61     if(*ppv) {
62         IUnknown_AddRef((IUnknown*)*ppv);
63         return S_OK;
64     }
65
66     WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
67     return E_NOINTERFACE;
68 }
69
70 static ULONG WINAPI OmNavigator_AddRef(IOmNavigator *iface)
71 {
72     OmNavigator *This = OMNAVIGATOR_THIS(iface);
73     LONG ref = InterlockedIncrement(&This->ref);
74
75     TRACE("(%p) ref=%d\n", This, ref);
76
77     return ref;
78 }
79
80 static ULONG WINAPI OmNavigator_Release(IOmNavigator *iface)
81 {
82     OmNavigator *This = OMNAVIGATOR_THIS(iface);
83     LONG ref = InterlockedDecrement(&This->ref);
84
85     TRACE("(%p) ref=%d\n", This, ref);
86
87     if(!ref) {
88         release_dispex(&This->dispex);
89         heap_free(This);
90     }
91
92     return ref;
93 }
94
95 static HRESULT WINAPI OmNavigator_GetTypeInfoCount(IOmNavigator *iface, UINT *pctinfo)
96 {
97     OmNavigator *This = OMNAVIGATOR_THIS(iface);
98     FIXME("(%p)->(%p)\n", This, pctinfo);
99     return E_NOTIMPL;
100 }
101
102 static HRESULT WINAPI OmNavigator_GetTypeInfo(IOmNavigator *iface, UINT iTInfo,
103                                               LCID lcid, ITypeInfo **ppTInfo)
104 {
105     OmNavigator *This = OMNAVIGATOR_THIS(iface);
106
107     return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
108 }
109
110 static HRESULT WINAPI OmNavigator_GetIDsOfNames(IOmNavigator *iface, REFIID riid,
111                                                 LPOLESTR *rgszNames, UINT cNames,
112                                                 LCID lcid, DISPID *rgDispId)
113 {
114     OmNavigator *This = OMNAVIGATOR_THIS(iface);
115
116     return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
117 }
118
119 static HRESULT WINAPI OmNavigator_Invoke(IOmNavigator *iface, DISPID dispIdMember,
120                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
121                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
122 {
123     OmNavigator *This = OMNAVIGATOR_THIS(iface);
124
125     return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
126             pVarResult, pExcepInfo, puArgErr);
127 }
128
129 static HRESULT WINAPI OmNavigator_get_appCodeName(IOmNavigator *iface, BSTR *p)
130 {
131     OmNavigator *This = OMNAVIGATOR_THIS(iface);
132
133     static const WCHAR mozillaW[] = {'M','o','z','i','l','l','a',0};
134
135     TRACE("(%p)->(%p)\n", This, p);
136
137     *p = SysAllocString(mozillaW);
138     return S_OK;
139 }
140
141 static HRESULT WINAPI OmNavigator_get_appName(IOmNavigator *iface, BSTR *p)
142 {
143     OmNavigator *This = OMNAVIGATOR_THIS(iface);
144
145     static const WCHAR app_nameW[] =
146         {'M','i','c','r','o','s','o','f','t',' ',
147          'I','n','t','e','r','n','e','t',' ',
148          'E','x','p','l','o','r','e','r',0};
149
150     TRACE("(%p)->(%p)\n", This, p);
151
152     *p = SysAllocString(app_nameW);
153     if(!*p)
154         return E_OUTOFMEMORY;
155
156     return S_OK;
157 }
158
159 static HRESULT WINAPI OmNavigator_get_appVersion(IOmNavigator *iface, BSTR *p)
160 {
161     OmNavigator *This = OMNAVIGATOR_THIS(iface);
162
163     char user_agent[512];
164     DWORD size;
165     HRESULT hres;
166
167     TRACE("(%p)->(%p)\n", This, p);
168
169     size = sizeof(user_agent);
170     hres = ObtainUserAgentString(0, user_agent, &size);
171     if(FAILED(hres))
172         return hres;
173
174     if(strncmp(user_agent, "Mozilla/", 8)) {
175         FIXME("Unsupported user agent\n");
176         return E_FAIL;
177     }
178
179     size = MultiByteToWideChar(CP_ACP, 0, user_agent+8, -1, NULL, 0);
180     *p = SysAllocStringLen(NULL, size-1);
181     if(!*p)
182         return E_OUTOFMEMORY;
183
184     MultiByteToWideChar(CP_ACP, 0, user_agent+8, -1, *p, size);
185     return S_OK;
186 }
187
188 static HRESULT WINAPI OmNavigator_get_userAgent(IOmNavigator *iface, BSTR *p)
189 {
190     OmNavigator *This = OMNAVIGATOR_THIS(iface);
191     char user_agent[512];
192     DWORD size;
193     HRESULT hres;
194
195     TRACE("(%p)->(%p)\n", This, p);
196
197     size = sizeof(user_agent);
198     hres = ObtainUserAgentString(0, user_agent, &size);
199     if(FAILED(hres))
200         return hres;
201
202     size = MultiByteToWideChar(CP_ACP, 0, user_agent, -1, NULL, 0);
203     *p = SysAllocStringLen(NULL, size-1);
204     if(!*p)
205         return E_OUTOFMEMORY;
206
207     MultiByteToWideChar(CP_ACP, 0, user_agent, -1, *p, size);
208     return S_OK;
209 }
210
211 static HRESULT WINAPI OmNavigator_javaEnabled(IOmNavigator *iface, VARIANT_BOOL *enabled)
212 {
213     OmNavigator *This = OMNAVIGATOR_THIS(iface);
214     FIXME("(%p)->(%p)\n", This, enabled);
215     return E_NOTIMPL;
216 }
217
218 static HRESULT WINAPI OmNavigator_taintEnabled(IOmNavigator *iface, VARIANT_BOOL *enabled)
219 {
220     OmNavigator *This = OMNAVIGATOR_THIS(iface);
221     FIXME("(%p)->(%p)\n", This, enabled);
222     return E_NOTIMPL;
223 }
224
225 static HRESULT WINAPI OmNavigator_get_mimeTypes(IOmNavigator *iface, IHTMLMimeTypesCollection **p)
226 {
227     OmNavigator *This = OMNAVIGATOR_THIS(iface);
228     FIXME("(%p)->(%p)\n", This, p);
229     return E_NOTIMPL;
230 }
231
232 static HRESULT WINAPI OmNavigator_get_plugins(IOmNavigator *iface, IHTMLPluginsCollection **p)
233 {
234     OmNavigator *This = OMNAVIGATOR_THIS(iface);
235     FIXME("(%p)->(%p)\n", This, p);
236     return E_NOTIMPL;
237 }
238
239 static HRESULT WINAPI OmNavigator_get_cookieEnabled(IOmNavigator *iface, VARIANT_BOOL *p)
240 {
241     OmNavigator *This = OMNAVIGATOR_THIS(iface);
242     FIXME("(%p)->(%p)\n", This, p);
243     return E_NOTIMPL;
244 }
245
246 static HRESULT WINAPI OmNavigator_get_opsProfile(IOmNavigator *iface, IHTMLOpsProfile **p)
247 {
248     OmNavigator *This = OMNAVIGATOR_THIS(iface);
249     FIXME("(%p)->(%p)\n", This, p);
250     return E_NOTIMPL;
251 }
252
253 static HRESULT WINAPI OmNavigator_toString(IOmNavigator *iface, BSTR *String)
254 {
255     OmNavigator *This = OMNAVIGATOR_THIS(iface);
256
257     static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};
258
259     TRACE("(%p)->(%p)\n", This, String);
260
261     if(!String)
262         return E_INVALIDARG;
263
264     *String = SysAllocString(objectW);
265     return *String ? S_OK : E_OUTOFMEMORY;
266 }
267
268 static HRESULT WINAPI OmNavigator_get_cpuClass(IOmNavigator *iface, BSTR *p)
269 {
270     OmNavigator *This = OMNAVIGATOR_THIS(iface);
271     FIXME("(%p)->(%p)\n", This, p);
272     return E_NOTIMPL;
273 }
274
275 static HRESULT WINAPI OmNavigator_get_systemLanguage(IOmNavigator *iface, BSTR *p)
276 {
277     OmNavigator *This = OMNAVIGATOR_THIS(iface);
278     FIXME("(%p)->(%p)\n", This, p);
279     return E_NOTIMPL;
280 }
281
282 static HRESULT WINAPI OmNavigator_get_browserLanguage(IOmNavigator *iface, BSTR *p)
283 {
284     OmNavigator *This = OMNAVIGATOR_THIS(iface);
285     FIXME("(%p)->(%p)\n", This, p);
286     return E_NOTIMPL;
287 }
288
289 static HRESULT WINAPI OmNavigator_get_userLanguage(IOmNavigator *iface, BSTR *p)
290 {
291     OmNavigator *This = OMNAVIGATOR_THIS(iface);
292     FIXME("(%p)->(%p)\n", This, p);
293     return E_NOTIMPL;
294 }
295
296 static HRESULT WINAPI OmNavigator_get_platform(IOmNavigator *iface, BSTR *p)
297 {
298     OmNavigator *This = OMNAVIGATOR_THIS(iface);
299
300 #ifdef _WIN64
301     static const WCHAR platformW[] = {'W','i','n','6','4',0};
302 #else
303     static const WCHAR platformW[] = {'W','i','n','3','2',0};
304 #endif
305
306     TRACE("(%p)->(%p)\n", This, p);
307
308     *p = SysAllocString(platformW);
309     return S_OK;
310 }
311
312 static HRESULT WINAPI OmNavigator_get_appMinorVersion(IOmNavigator *iface, BSTR *p)
313 {
314     OmNavigator *This = OMNAVIGATOR_THIS(iface);
315     FIXME("(%p)->(%p)\n", This, p);
316     return E_NOTIMPL;
317 }
318
319 static HRESULT WINAPI OmNavigator_get_connectionSpeed(IOmNavigator *iface, LONG *p)
320 {
321     OmNavigator *This = OMNAVIGATOR_THIS(iface);
322     FIXME("(%p)->(%p)\n", This, p);
323     return E_NOTIMPL;
324 }
325
326 static HRESULT WINAPI OmNavigator_get_onLine(IOmNavigator *iface, VARIANT_BOOL *p)
327 {
328     OmNavigator *This = OMNAVIGATOR_THIS(iface);
329     FIXME("(%p)->(%p)\n", This, p);
330     return E_NOTIMPL;
331 }
332
333 static HRESULT WINAPI OmNavigator_get_userProfile(IOmNavigator *iface, IHTMLOpsProfile **p)
334 {
335     OmNavigator *This = OMNAVIGATOR_THIS(iface);
336     FIXME("(%p)->(%p)\n", This, p);
337     return E_NOTIMPL;
338 }
339
340 #undef OMNAVIGATOR_THIS
341
342 static const IOmNavigatorVtbl OmNavigatorVtbl = {
343     OmNavigator_QueryInterface,
344     OmNavigator_AddRef,
345     OmNavigator_Release,
346     OmNavigator_GetTypeInfoCount,
347     OmNavigator_GetTypeInfo,
348     OmNavigator_GetIDsOfNames,
349     OmNavigator_Invoke,
350     OmNavigator_get_appCodeName,
351     OmNavigator_get_appName,
352     OmNavigator_get_appVersion,
353     OmNavigator_get_userAgent,
354     OmNavigator_javaEnabled,
355     OmNavigator_taintEnabled,
356     OmNavigator_get_mimeTypes,
357     OmNavigator_get_plugins,
358     OmNavigator_get_cookieEnabled,
359     OmNavigator_get_opsProfile,
360     OmNavigator_toString,
361     OmNavigator_get_cpuClass,
362     OmNavigator_get_systemLanguage,
363     OmNavigator_get_browserLanguage,
364     OmNavigator_get_userLanguage,
365     OmNavigator_get_platform,
366     OmNavigator_get_appMinorVersion,
367     OmNavigator_get_connectionSpeed,
368     OmNavigator_get_onLine,
369     OmNavigator_get_userProfile
370 };
371
372 static const tid_t OmNavigator_iface_tids[] = {
373     IOmNavigator_tid,
374     0
375 };
376 static dispex_static_data_t OmNavigator_dispex = {
377     NULL,
378     DispHTMLNavigator_tid,
379     NULL,
380     OmNavigator_iface_tids
381 };
382
383 IOmNavigator *OmNavigator_Create(void)
384 {
385     OmNavigator *ret;
386
387     ret = heap_alloc_zero(sizeof(*ret));
388     ret->lpIOmNavigatorVtbl = &OmNavigatorVtbl;
389     ret->ref = 1;
390
391     init_dispex(&ret->dispex, (IUnknown*)OMNAVIGATOR(ret), &OmNavigator_dispex);
392
393     return OMNAVIGATOR(ret);
394 }