strmbase: Add support for rendering algorithms to quality control.
[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 HTMLPluginsCollection HTMLPluginsCollection;
35
36 typedef struct {
37     DispatchEx dispex;
38     const IOmNavigatorVtbl  *lpIOmNavigatorVtbl;
39
40     LONG ref;
41
42     HTMLPluginsCollection *plugins;
43 } OmNavigator;
44
45
46 #define OMNAVIGATOR(x)  ((IOmNavigator*) &(x)->lpIOmNavigatorVtbl)
47
48 struct HTMLPluginsCollection {
49     DispatchEx dispex;
50     const IHTMLPluginsCollectionVtbl  *lpIHTMLPluginsCollectionVtbl;
51
52     LONG ref;
53
54     OmNavigator *navigator;
55 };
56
57 #define HTMLPLUGINSCOL(x)  ((IHTMLPluginsCollection*)  &(x)->lpIHTMLPluginsCollectionVtbl)
58
59 #define HTMLPLUGINCOL_THIS(iface) DEFINE_THIS(HTMLPluginsCollection, IHTMLPluginsCollection, iface)
60
61 static HRESULT WINAPI HTMLPluginsCollection_QueryInterface(IHTMLPluginsCollection *iface, REFIID riid, void **ppv)
62 {
63     HTMLPluginsCollection *This = HTMLPLUGINCOL_THIS(iface);
64
65     if(IsEqualGUID(&IID_IUnknown, riid)) {
66         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
67         *ppv = HTMLPLUGINSCOL(This);
68     }else if(IsEqualGUID(&IID_IHTMLPluginsCollection, riid)) {
69         TRACE("(%p)->(IID_IHTMLPluginCollection %p)\n", This, ppv);
70         *ppv = HTMLPLUGINSCOL(This);
71     }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
72         return *ppv ? S_OK : E_NOINTERFACE;
73     }else {
74         *ppv = NULL;
75         WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
76         return E_NOINTERFACE;
77     }
78
79     IUnknown_AddRef((IUnknown*)*ppv);
80     return S_OK;
81 }
82
83 static ULONG WINAPI HTMLPluginsCollection_AddRef(IHTMLPluginsCollection *iface)
84 {
85     HTMLPluginsCollection *This = HTMLPLUGINCOL_THIS(iface);
86     LONG ref = InterlockedIncrement(&This->ref);
87
88     TRACE("(%p) ref=%d\n", This, ref);
89
90     return ref;
91 }
92
93 static ULONG WINAPI HTMLPluginsCollection_Release(IHTMLPluginsCollection *iface)
94 {
95     HTMLPluginsCollection *This = HTMLPLUGINCOL_THIS(iface);
96     LONG ref = InterlockedDecrement(&This->ref);
97
98     TRACE("(%p) ref=%d\n", This, ref);
99
100     if(!ref) {
101         if(This->navigator)
102             This->navigator->plugins = NULL;
103         release_dispex(&This->dispex);
104         heap_free(This);
105     }
106
107     return ref;
108 }
109
110 static HRESULT WINAPI HTMLPluginsCollection_GetTypeInfoCount(IHTMLPluginsCollection *iface, UINT *pctinfo)
111 {
112     HTMLPluginsCollection *This = HTMLPLUGINCOL_THIS(iface);
113     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
114 }
115
116 static HRESULT WINAPI HTMLPluginsCollection_GetTypeInfo(IHTMLPluginsCollection *iface, UINT iTInfo,
117                                               LCID lcid, ITypeInfo **ppTInfo)
118 {
119     HTMLPluginsCollection *This = HTMLPLUGINCOL_THIS(iface);
120     return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
121 }
122
123 static HRESULT WINAPI HTMLPluginsCollection_GetIDsOfNames(IHTMLPluginsCollection *iface, REFIID riid,
124         LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
125 {
126     HTMLPluginsCollection *This = HTMLPLUGINCOL_THIS(iface);
127     return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
128 }
129
130 static HRESULT WINAPI HTMLPluginsCollection_Invoke(IHTMLPluginsCollection *iface, DISPID dispIdMember,
131         REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
132         EXCEPINFO *pExcepInfo, UINT *puArgErr)
133 {
134     HTMLPluginsCollection *This = HTMLPLUGINCOL_THIS(iface);
135     return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid,
136             wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
137 }
138
139 static HRESULT WINAPI HTMLPluginsCollection_get_length(IHTMLPluginsCollection *iface, LONG *p)
140 {
141     HTMLPluginsCollection *This = HTMLPLUGINCOL_THIS(iface);
142     FIXME("(%p)->(%p)\n", This, p);
143     return E_NOTIMPL;
144 }
145
146 static HRESULT WINAPI HTMLPluginsCollection_refresh(IHTMLPluginsCollection *iface, VARIANT_BOOL reload)
147 {
148     HTMLPluginsCollection *This = HTMLPLUGINCOL_THIS(iface);
149     FIXME("(%p)->(%x)\n", This, reload);
150     return E_NOTIMPL;
151 }
152
153 #undef HTMLPLUGINSCOL_THIS
154
155 static const IHTMLPluginsCollectionVtbl HTMLPluginsCollectionVtbl = {
156     HTMLPluginsCollection_QueryInterface,
157     HTMLPluginsCollection_AddRef,
158     HTMLPluginsCollection_Release,
159     HTMLPluginsCollection_GetTypeInfoCount,
160     HTMLPluginsCollection_GetTypeInfo,
161     HTMLPluginsCollection_GetIDsOfNames,
162     HTMLPluginsCollection_Invoke,
163     HTMLPluginsCollection_get_length,
164     HTMLPluginsCollection_refresh
165 };
166
167 static const tid_t HTMLPluginsCollection_iface_tids[] = {
168     IHTMLPluginsCollection_tid,
169     0
170 };
171 static dispex_static_data_t HTMLPluginsCollection_dispex = {
172     NULL,
173     DispCPlugins_tid,
174     NULL,
175     HTMLPluginsCollection_iface_tids
176 };
177
178 static HRESULT create_plugins_collection(OmNavigator *navigator, HTMLPluginsCollection **ret)
179 {
180     HTMLPluginsCollection *col;
181
182     col = heap_alloc_zero(sizeof(*col));
183     if(!col)
184         return E_OUTOFMEMORY;
185
186     col->lpIHTMLPluginsCollectionVtbl = &HTMLPluginsCollectionVtbl;
187     col->ref = 1;
188     col->navigator = navigator;
189
190     init_dispex(&col->dispex, (IUnknown*)HTMLPLUGINSCOL(col), &HTMLPluginsCollection_dispex);
191
192     *ret = col;
193     return S_OK;
194 }
195
196 #define OMNAVIGATOR_THIS(iface) DEFINE_THIS(OmNavigator, IOmNavigator, iface)
197
198 static HRESULT WINAPI OmNavigator_QueryInterface(IOmNavigator *iface, REFIID riid, void **ppv)
199 {
200     OmNavigator *This = OMNAVIGATOR_THIS(iface);
201
202     *ppv = NULL;
203
204     if(IsEqualGUID(&IID_IUnknown, riid)) {
205         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
206         *ppv = OMNAVIGATOR(This);
207     }else if(IsEqualGUID(&IID_IOmNavigator, riid)) {
208         TRACE("(%p)->(IID_IOmNavigator %p)\n", This, ppv);
209         *ppv = OMNAVIGATOR(This);
210     }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
211         return *ppv ? S_OK : E_NOINTERFACE;
212     }
213
214     if(*ppv) {
215         IUnknown_AddRef((IUnknown*)*ppv);
216         return S_OK;
217     }
218
219     WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
220     return E_NOINTERFACE;
221 }
222
223 static ULONG WINAPI OmNavigator_AddRef(IOmNavigator *iface)
224 {
225     OmNavigator *This = OMNAVIGATOR_THIS(iface);
226     LONG ref = InterlockedIncrement(&This->ref);
227
228     TRACE("(%p) ref=%d\n", This, ref);
229
230     return ref;
231 }
232
233 static ULONG WINAPI OmNavigator_Release(IOmNavigator *iface)
234 {
235     OmNavigator *This = OMNAVIGATOR_THIS(iface);
236     LONG ref = InterlockedDecrement(&This->ref);
237
238     TRACE("(%p) ref=%d\n", This, ref);
239
240     if(!ref) {
241         if(This->plugins) {
242             This->plugins->navigator = NULL;
243             IHTMLPluginsCollection_Release(HTMLPLUGINSCOL(This->plugins));
244         }
245         release_dispex(&This->dispex);
246         heap_free(This);
247     }
248
249     return ref;
250 }
251
252 static HRESULT WINAPI OmNavigator_GetTypeInfoCount(IOmNavigator *iface, UINT *pctinfo)
253 {
254     OmNavigator *This = OMNAVIGATOR_THIS(iface);
255     FIXME("(%p)->(%p)\n", This, pctinfo);
256     return E_NOTIMPL;
257 }
258
259 static HRESULT WINAPI OmNavigator_GetTypeInfo(IOmNavigator *iface, UINT iTInfo,
260                                               LCID lcid, ITypeInfo **ppTInfo)
261 {
262     OmNavigator *This = OMNAVIGATOR_THIS(iface);
263
264     return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
265 }
266
267 static HRESULT WINAPI OmNavigator_GetIDsOfNames(IOmNavigator *iface, REFIID riid,
268                                                 LPOLESTR *rgszNames, UINT cNames,
269                                                 LCID lcid, DISPID *rgDispId)
270 {
271     OmNavigator *This = OMNAVIGATOR_THIS(iface);
272
273     return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
274 }
275
276 static HRESULT WINAPI OmNavigator_Invoke(IOmNavigator *iface, DISPID dispIdMember,
277                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
278                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
279 {
280     OmNavigator *This = OMNAVIGATOR_THIS(iface);
281
282     return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
283             pVarResult, pExcepInfo, puArgErr);
284 }
285
286 static HRESULT WINAPI OmNavigator_get_appCodeName(IOmNavigator *iface, BSTR *p)
287 {
288     OmNavigator *This = OMNAVIGATOR_THIS(iface);
289
290     static const WCHAR mozillaW[] = {'M','o','z','i','l','l','a',0};
291
292     TRACE("(%p)->(%p)\n", This, p);
293
294     *p = SysAllocString(mozillaW);
295     return S_OK;
296 }
297
298 static HRESULT WINAPI OmNavigator_get_appName(IOmNavigator *iface, BSTR *p)
299 {
300     OmNavigator *This = OMNAVIGATOR_THIS(iface);
301
302     static const WCHAR app_nameW[] =
303         {'M','i','c','r','o','s','o','f','t',' ',
304          'I','n','t','e','r','n','e','t',' ',
305          'E','x','p','l','o','r','e','r',0};
306
307     TRACE("(%p)->(%p)\n", This, p);
308
309     *p = SysAllocString(app_nameW);
310     if(!*p)
311         return E_OUTOFMEMORY;
312
313     return S_OK;
314 }
315
316 static HRESULT WINAPI OmNavigator_get_appVersion(IOmNavigator *iface, BSTR *p)
317 {
318     OmNavigator *This = OMNAVIGATOR_THIS(iface);
319
320     char user_agent[512];
321     DWORD size;
322     HRESULT hres;
323
324     TRACE("(%p)->(%p)\n", This, p);
325
326     size = sizeof(user_agent);
327     hres = ObtainUserAgentString(0, user_agent, &size);
328     if(FAILED(hres))
329         return hres;
330
331     if(strncmp(user_agent, "Mozilla/", 8)) {
332         FIXME("Unsupported user agent\n");
333         return E_FAIL;
334     }
335
336     size = MultiByteToWideChar(CP_ACP, 0, user_agent+8, -1, NULL, 0);
337     *p = SysAllocStringLen(NULL, size-1);
338     if(!*p)
339         return E_OUTOFMEMORY;
340
341     MultiByteToWideChar(CP_ACP, 0, user_agent+8, -1, *p, size);
342     return S_OK;
343 }
344
345 static HRESULT WINAPI OmNavigator_get_userAgent(IOmNavigator *iface, BSTR *p)
346 {
347     OmNavigator *This = OMNAVIGATOR_THIS(iface);
348     char user_agent[512];
349     DWORD size;
350     HRESULT hres;
351
352     TRACE("(%p)->(%p)\n", This, p);
353
354     size = sizeof(user_agent);
355     hres = ObtainUserAgentString(0, user_agent, &size);
356     if(FAILED(hres))
357         return hres;
358
359     size = MultiByteToWideChar(CP_ACP, 0, user_agent, -1, NULL, 0);
360     *p = SysAllocStringLen(NULL, size-1);
361     if(!*p)
362         return E_OUTOFMEMORY;
363
364     MultiByteToWideChar(CP_ACP, 0, user_agent, -1, *p, size);
365     return S_OK;
366 }
367
368 static HRESULT WINAPI OmNavigator_javaEnabled(IOmNavigator *iface, VARIANT_BOOL *enabled)
369 {
370     OmNavigator *This = OMNAVIGATOR_THIS(iface);
371     FIXME("(%p)->(%p)\n", This, enabled);
372     return E_NOTIMPL;
373 }
374
375 static HRESULT WINAPI OmNavigator_taintEnabled(IOmNavigator *iface, VARIANT_BOOL *enabled)
376 {
377     OmNavigator *This = OMNAVIGATOR_THIS(iface);
378     FIXME("(%p)->(%p)\n", This, enabled);
379     return E_NOTIMPL;
380 }
381
382 static HRESULT WINAPI OmNavigator_get_mimeTypes(IOmNavigator *iface, IHTMLMimeTypesCollection **p)
383 {
384     OmNavigator *This = OMNAVIGATOR_THIS(iface);
385     FIXME("(%p)->(%p)\n", This, p);
386     return E_NOTIMPL;
387 }
388
389 static HRESULT WINAPI OmNavigator_get_plugins(IOmNavigator *iface, IHTMLPluginsCollection **p)
390 {
391     OmNavigator *This = OMNAVIGATOR_THIS(iface);
392
393     TRACE("(%p)->(%p)\n", This, p);
394
395     if(!This->plugins) {
396         HRESULT hres;
397
398         hres = create_plugins_collection(This, &This->plugins);
399         if(FAILED(hres))
400             return hres;
401     }else {
402         IHTMLPluginsCollection_AddRef(HTMLPLUGINSCOL(This->plugins));
403     }
404
405     *p = HTMLPLUGINSCOL(This->plugins);
406     return S_OK;
407 }
408
409 static HRESULT WINAPI OmNavigator_get_cookieEnabled(IOmNavigator *iface, VARIANT_BOOL *p)
410 {
411     OmNavigator *This = OMNAVIGATOR_THIS(iface);
412     FIXME("(%p)->(%p)\n", This, p);
413     return E_NOTIMPL;
414 }
415
416 static HRESULT WINAPI OmNavigator_get_opsProfile(IOmNavigator *iface, IHTMLOpsProfile **p)
417 {
418     OmNavigator *This = OMNAVIGATOR_THIS(iface);
419     FIXME("(%p)->(%p)\n", This, p);
420     return E_NOTIMPL;
421 }
422
423 static HRESULT WINAPI OmNavigator_toString(IOmNavigator *iface, BSTR *String)
424 {
425     OmNavigator *This = OMNAVIGATOR_THIS(iface);
426
427     static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};
428
429     TRACE("(%p)->(%p)\n", This, String);
430
431     if(!String)
432         return E_INVALIDARG;
433
434     *String = SysAllocString(objectW);
435     return *String ? S_OK : E_OUTOFMEMORY;
436 }
437
438 static HRESULT WINAPI OmNavigator_get_cpuClass(IOmNavigator *iface, BSTR *p)
439 {
440     OmNavigator *This = OMNAVIGATOR_THIS(iface);
441     FIXME("(%p)->(%p)\n", This, p);
442     return E_NOTIMPL;
443 }
444
445 static HRESULT WINAPI OmNavigator_get_systemLanguage(IOmNavigator *iface, BSTR *p)
446 {
447     OmNavigator *This = OMNAVIGATOR_THIS(iface);
448     FIXME("(%p)->(%p)\n", This, p);
449     return E_NOTIMPL;
450 }
451
452 static HRESULT WINAPI OmNavigator_get_browserLanguage(IOmNavigator *iface, BSTR *p)
453 {
454     OmNavigator *This = OMNAVIGATOR_THIS(iface);
455     FIXME("(%p)->(%p)\n", This, p);
456     return E_NOTIMPL;
457 }
458
459 static HRESULT WINAPI OmNavigator_get_userLanguage(IOmNavigator *iface, BSTR *p)
460 {
461     OmNavigator *This = OMNAVIGATOR_THIS(iface);
462     FIXME("(%p)->(%p)\n", This, p);
463     return E_NOTIMPL;
464 }
465
466 static HRESULT WINAPI OmNavigator_get_platform(IOmNavigator *iface, BSTR *p)
467 {
468     OmNavigator *This = OMNAVIGATOR_THIS(iface);
469
470 #ifdef _WIN64
471     static const WCHAR platformW[] = {'W','i','n','6','4',0};
472 #else
473     static const WCHAR platformW[] = {'W','i','n','3','2',0};
474 #endif
475
476     TRACE("(%p)->(%p)\n", This, p);
477
478     *p = SysAllocString(platformW);
479     return S_OK;
480 }
481
482 static HRESULT WINAPI OmNavigator_get_appMinorVersion(IOmNavigator *iface, BSTR *p)
483 {
484     OmNavigator *This = OMNAVIGATOR_THIS(iface);
485     FIXME("(%p)->(%p)\n", This, p);
486     return E_NOTIMPL;
487 }
488
489 static HRESULT WINAPI OmNavigator_get_connectionSpeed(IOmNavigator *iface, LONG *p)
490 {
491     OmNavigator *This = OMNAVIGATOR_THIS(iface);
492     FIXME("(%p)->(%p)\n", This, p);
493     return E_NOTIMPL;
494 }
495
496 static HRESULT WINAPI OmNavigator_get_onLine(IOmNavigator *iface, VARIANT_BOOL *p)
497 {
498     OmNavigator *This = OMNAVIGATOR_THIS(iface);
499     FIXME("(%p)->(%p)\n", This, p);
500     return E_NOTIMPL;
501 }
502
503 static HRESULT WINAPI OmNavigator_get_userProfile(IOmNavigator *iface, IHTMLOpsProfile **p)
504 {
505     OmNavigator *This = OMNAVIGATOR_THIS(iface);
506     FIXME("(%p)->(%p)\n", This, p);
507     return E_NOTIMPL;
508 }
509
510 #undef OMNAVIGATOR_THIS
511
512 static const IOmNavigatorVtbl OmNavigatorVtbl = {
513     OmNavigator_QueryInterface,
514     OmNavigator_AddRef,
515     OmNavigator_Release,
516     OmNavigator_GetTypeInfoCount,
517     OmNavigator_GetTypeInfo,
518     OmNavigator_GetIDsOfNames,
519     OmNavigator_Invoke,
520     OmNavigator_get_appCodeName,
521     OmNavigator_get_appName,
522     OmNavigator_get_appVersion,
523     OmNavigator_get_userAgent,
524     OmNavigator_javaEnabled,
525     OmNavigator_taintEnabled,
526     OmNavigator_get_mimeTypes,
527     OmNavigator_get_plugins,
528     OmNavigator_get_cookieEnabled,
529     OmNavigator_get_opsProfile,
530     OmNavigator_toString,
531     OmNavigator_get_cpuClass,
532     OmNavigator_get_systemLanguage,
533     OmNavigator_get_browserLanguage,
534     OmNavigator_get_userLanguage,
535     OmNavigator_get_platform,
536     OmNavigator_get_appMinorVersion,
537     OmNavigator_get_connectionSpeed,
538     OmNavigator_get_onLine,
539     OmNavigator_get_userProfile
540 };
541
542 static const tid_t OmNavigator_iface_tids[] = {
543     IOmNavigator_tid,
544     0
545 };
546 static dispex_static_data_t OmNavigator_dispex = {
547     NULL,
548     DispHTMLNavigator_tid,
549     NULL,
550     OmNavigator_iface_tids
551 };
552
553 IOmNavigator *OmNavigator_Create(void)
554 {
555     OmNavigator *ret;
556
557     ret = heap_alloc_zero(sizeof(*ret));
558     ret->lpIOmNavigatorVtbl = &OmNavigatorVtbl;
559     ret->ref = 1;
560
561     init_dispex(&ret->dispex, (IUnknown*)OMNAVIGATOR(ret), &OmNavigator_dispex);
562
563     return OMNAVIGATOR(ret);
564 }