ddraw: Fail surface creation if the cooperative level isn't set yet.
[wine] / dlls / ieframe / shellbrowser.c
1 /*
2  * Implementation of IShellBrowser interface
3  *
4  * Copyright 2011 Piotr Caban for CodeWeavers
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <assert.h>
22
23 #include "ieframe.h"
24 #include "exdispid.h"
25
26 #include "wine/debug.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(ieframe);
29
30 static inline ShellBrowser *impl_from_IShellBrowser(IShellBrowser *iface)
31 {
32     return CONTAINING_RECORD(iface, ShellBrowser, IShellBrowser_iface);
33 }
34
35 static HRESULT WINAPI ShellBrowser_QueryInterface(IShellBrowser* iface, REFIID riid, void **ppv)
36 {
37     ShellBrowser *This = impl_from_IShellBrowser(iface);
38
39     if(IsEqualGUID(&IID_IUnknown, riid)) {
40         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
41         *ppv = &This->IShellBrowser_iface;
42     }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
43         TRACE("(%p)->(IID_IOleWindow %p)\n", This, ppv);
44         *ppv = &This->IShellBrowser_iface;
45     }else if(IsEqualGUID(&IID_IShellBrowser, riid)) {
46         TRACE("(%p)->(IID_IShellBrowser %p)\n", This, ppv);
47         *ppv = &This->IShellBrowser_iface;
48     }else if(IsEqualGUID(&IID_IBrowserService, riid)) {
49         TRACE("(%p)->(IID_IBrowserService %p)\n", This, ppv);
50         *ppv = &This->IBrowserService_iface;
51     }else if(IsEqualGUID(&IID_IDocObjectService, riid)) {
52         TRACE("(%p)->(IID_IDocObjectService %p)\n", This, ppv);
53         *ppv = &This->IDocObjectService_iface;
54     }else {
55         FIXME("%p %s %p\n", This, debugstr_guid(riid), ppv);
56         *ppv = NULL;
57         return E_NOINTERFACE;
58     }
59
60     IUnknown_AddRef((IUnknown*)*ppv);
61     return S_OK;
62 }
63
64 static ULONG WINAPI ShellBrowser_AddRef(
65         IShellBrowser* iface)
66 {
67     ShellBrowser *This = impl_from_IShellBrowser(iface);
68     LONG ref = InterlockedIncrement(&This->ref);
69
70     TRACE("(%p) ref=%d\n", This, ref);
71
72     return ref;
73 }
74
75 static ULONG WINAPI ShellBrowser_Release(IShellBrowser* iface)
76 {
77     ShellBrowser *This = impl_from_IShellBrowser(iface);
78     LONG ref = InterlockedDecrement(&This->ref);
79
80     TRACE("(%p) ref=%d\n", This, ref);
81
82     if(!ref) {
83         assert(!This->doc_host);
84         heap_free(This);
85     }
86
87     return ref;
88 }
89
90 static HRESULT WINAPI ShellBrowser_GetWindow(
91         IShellBrowser* iface,
92         HWND *phwnd)
93 {
94     ShellBrowser *This = impl_from_IShellBrowser(iface);
95     FIXME("%p %p\n", This, phwnd);
96     return E_NOTIMPL;
97 }
98
99 static HRESULT WINAPI ShellBrowser_ContextSensitiveHelp(
100         IShellBrowser* iface,
101         BOOL fEnterMode)
102 {
103     ShellBrowser *This = impl_from_IShellBrowser(iface);
104     FIXME("%p %d\n", This, fEnterMode);
105     return E_NOTIMPL;
106 }
107
108 static HRESULT WINAPI ShellBrowser_InsertMenusSB(
109         IShellBrowser* iface,
110         HMENU hmenuShared,
111         LPOLEMENUGROUPWIDTHS lpMenuWidths)
112 {
113     ShellBrowser *This = impl_from_IShellBrowser(iface);
114     FIXME("%p %p %p\n", This, hmenuShared, lpMenuWidths);
115     return E_NOTIMPL;
116 }
117
118 static HRESULT WINAPI ShellBrowser_SetMenuSB(
119         IShellBrowser* iface,
120         HMENU hmenuShared,
121         HOLEMENU holemenuReserved,
122         HWND hwndActiveObject)
123 {
124     ShellBrowser *This = impl_from_IShellBrowser(iface);
125     FIXME("%p %p %p %p\n", This, hmenuShared, holemenuReserved, hwndActiveObject);
126     return E_NOTIMPL;
127 }
128
129 static HRESULT WINAPI ShellBrowser_RemoveMenusSB(
130         IShellBrowser* iface,
131         HMENU hmenuShared)
132 {
133     ShellBrowser *This = impl_from_IShellBrowser(iface);
134     FIXME("%p %p\n", This, hmenuShared);
135     return E_NOTIMPL;
136 }
137
138 static HRESULT WINAPI ShellBrowser_SetStatusTextSB(
139         IShellBrowser* iface,
140         LPCOLESTR pszStatusText)
141 {
142     ShellBrowser *This = impl_from_IShellBrowser(iface);
143     FIXME("%p %s\n", This, debugstr_w(pszStatusText));
144     return E_NOTIMPL;
145 }
146
147 static HRESULT WINAPI ShellBrowser_EnableModelessSB(
148         IShellBrowser* iface,
149         BOOL fEnable)
150 {
151     ShellBrowser *This = impl_from_IShellBrowser(iface);
152     FIXME("%p %d\n", This, fEnable);
153     return E_NOTIMPL;
154 }
155
156 static HRESULT WINAPI ShellBrowser_TranslateAcceleratorSB(
157         IShellBrowser* iface,
158         MSG *pmsg,
159         WORD wID)
160 {
161     ShellBrowser *This = impl_from_IShellBrowser(iface);
162     FIXME("%p %p %d\n", This, pmsg, (int)wID);
163     return E_NOTIMPL;
164 }
165
166 static HRESULT WINAPI ShellBrowser_BrowseObject(
167         IShellBrowser* iface,
168         LPCITEMIDLIST pidl,
169         UINT wFlags)
170 {
171     ShellBrowser *This = impl_from_IShellBrowser(iface);
172     FIXME("%p %p %u\n", This, pidl, wFlags);
173     return E_NOTIMPL;
174 }
175
176 static HRESULT WINAPI ShellBrowser_GetViewStateStream(
177         IShellBrowser* iface,
178         DWORD grfMode,
179         IStream **ppStrm)
180 {
181     ShellBrowser *This = impl_from_IShellBrowser(iface);
182     FIXME("%p %x %p\n", This, grfMode, ppStrm);
183     return E_NOTIMPL;
184 }
185
186 static HRESULT WINAPI ShellBrowser_GetControlWindow(
187         IShellBrowser* iface,
188         UINT id,
189         HWND *phwnd)
190 {
191     ShellBrowser *This = impl_from_IShellBrowser(iface);
192     FIXME("%p %u %p\n", This, id, phwnd);
193     return E_NOTIMPL;
194 }
195
196 static HRESULT WINAPI ShellBrowser_SendControlMsg(
197         IShellBrowser* iface,
198         UINT id,
199         UINT uMsg,
200         WPARAM wParam,
201         LPARAM lParam,
202         LRESULT *pret)
203 {
204     ShellBrowser *This = impl_from_IShellBrowser(iface);
205     FIXME("%p %u %u %p\n", This, id, uMsg, pret);
206     return E_NOTIMPL;
207 }
208
209 static HRESULT WINAPI ShellBrowser_QueryActiveShellView(
210         IShellBrowser* iface,
211         IShellView **ppshv)
212 {
213     ShellBrowser *This = impl_from_IShellBrowser(iface);
214     FIXME("%p %p\n", This, ppshv);
215     return E_NOTIMPL;
216 }
217
218 static HRESULT WINAPI ShellBrowser_OnViewWindowActive(
219         IShellBrowser* iface,
220         IShellView *pshv)
221 {
222     ShellBrowser *This = impl_from_IShellBrowser(iface);
223     FIXME("%p %p\n", This, pshv);
224     return E_NOTIMPL;
225 }
226
227 static HRESULT WINAPI ShellBrowser_SetToolbarItems(
228         IShellBrowser* iface,
229         LPTBBUTTONSB lpButtons,
230         UINT nButtons,
231         UINT uFlags)
232 {
233     ShellBrowser *This = impl_from_IShellBrowser(iface);
234     FIXME("%p %p %u %u\n", This, lpButtons, nButtons, uFlags);
235     return E_NOTIMPL;
236 }
237
238 static const IShellBrowserVtbl ShellBrowserVtbl = {
239     ShellBrowser_QueryInterface,
240     ShellBrowser_AddRef,
241     ShellBrowser_Release,
242     ShellBrowser_GetWindow,
243     ShellBrowser_ContextSensitiveHelp,
244     ShellBrowser_InsertMenusSB,
245     ShellBrowser_SetMenuSB,
246     ShellBrowser_RemoveMenusSB,
247     ShellBrowser_SetStatusTextSB,
248     ShellBrowser_EnableModelessSB,
249     ShellBrowser_TranslateAcceleratorSB,
250     ShellBrowser_BrowseObject,
251     ShellBrowser_GetViewStateStream,
252     ShellBrowser_GetControlWindow,
253     ShellBrowser_SendControlMsg,
254     ShellBrowser_QueryActiveShellView,
255     ShellBrowser_OnViewWindowActive,
256     ShellBrowser_SetToolbarItems
257 };
258
259 static inline ShellBrowser *impl_from_IBrowserService(IBrowserService *iface)
260 {
261     return CONTAINING_RECORD(iface, ShellBrowser, IBrowserService_iface);
262 }
263
264 static HRESULT WINAPI BrowserService_QueryInterface(
265         IBrowserService* iface,
266         REFIID riid,
267         void **ppvObject)
268 {
269     ShellBrowser *This = impl_from_IBrowserService(iface);
270     return IShellBrowser_QueryInterface(&This->IShellBrowser_iface, riid, ppvObject);
271 }
272
273 static ULONG WINAPI BrowserService_AddRef(
274         IBrowserService *iface)
275 {
276     ShellBrowser *This = impl_from_IBrowserService(iface);
277     return IShellBrowser_AddRef(&This->IShellBrowser_iface);
278 }
279
280 static ULONG WINAPI BrowserService_Release(
281         IBrowserService* iface)
282 {
283     ShellBrowser *This = impl_from_IBrowserService(iface);
284     return IShellBrowser_Release(&This->IShellBrowser_iface);
285 }
286
287 static HRESULT WINAPI BrowserService_GetParentSite(
288         IBrowserService* iface,
289         IOleInPlaceSite **ppipsite)
290 {
291     ShellBrowser *This = impl_from_IBrowserService(iface);
292     FIXME("%p %p\n", This, ppipsite);
293     return E_NOTIMPL;
294 }
295
296 static HRESULT WINAPI BrowserService_SetTitle(
297         IBrowserService* iface,
298         IShellView *psv,
299         LPCWSTR pszName)
300 {
301     ShellBrowser *This = impl_from_IBrowserService(iface);
302     FIXME("%p %p %s\n", This, psv, debugstr_w(pszName));
303     return E_NOTIMPL;
304 }
305
306 static HRESULT WINAPI BrowserService_GetTitle(
307         IBrowserService* iface,
308         IShellView *psv,
309         LPWSTR pszName,
310         DWORD cchName)
311 {
312     ShellBrowser *This = impl_from_IBrowserService(iface);
313     FIXME("%p %p %p %d\n", This, psv, pszName, cchName);
314     return E_NOTIMPL;
315 }
316
317 static HRESULT WINAPI BrowserService_GetOleObject(
318         IBrowserService* iface,
319         IOleObject **ppobjv)
320 {
321     ShellBrowser *This = impl_from_IBrowserService(iface);
322     FIXME("%p %p\n", This, ppobjv);
323     return E_NOTIMPL;
324 }
325
326 static HRESULT WINAPI BrowserService_GetTravelLog(
327         IBrowserService* iface,
328         ITravelLog **pptl)
329 {
330     ShellBrowser *This = impl_from_IBrowserService(iface);
331     FIXME("%p %p\n", This, pptl);
332     return E_NOTIMPL;
333 }
334
335 static HRESULT WINAPI BrowserService_ShowControlWindow(
336         IBrowserService* iface,
337         UINT id,
338         BOOL fShow)
339 {
340     ShellBrowser *This = impl_from_IBrowserService(iface);
341     FIXME("%p %u %d\n", This, id, fShow);
342     return E_NOTIMPL;
343 }
344
345 static HRESULT WINAPI BrowserService_IsControlWindowShown(
346         IBrowserService* iface,
347         UINT id,
348         BOOL *pfShown)
349 {
350     ShellBrowser *This = impl_from_IBrowserService(iface);
351     FIXME("%p %u %p\n", This, id, pfShown);
352     return E_NOTIMPL;
353 }
354
355 static HRESULT WINAPI BrowserService_IEGetDisplayName(
356         IBrowserService* iface,
357         PCIDLIST_ABSOLUTE pidl,
358         LPWSTR pwszName,
359         UINT uFlags)
360 {
361     ShellBrowser *This = impl_from_IBrowserService(iface);
362     FIXME("%p %p %p %u\n", This, pidl, pwszName, uFlags);
363     return E_NOTIMPL;
364 }
365
366 static HRESULT WINAPI BrowserService_IEParseDisplayName(
367         IBrowserService* iface,
368         UINT uiCP,
369         LPCWSTR pwszPath,
370         PIDLIST_ABSOLUTE *ppidlOut)
371 {
372     ShellBrowser *This = impl_from_IBrowserService(iface);
373     FIXME("%p %u %s %p\n", This, uiCP, debugstr_w(pwszPath), ppidlOut);
374     return E_NOTIMPL;
375 }
376
377 static HRESULT WINAPI BrowserService_DisplayParseError(
378         IBrowserService* iface,
379         HRESULT hres,
380         LPCWSTR pwszPath)
381 {
382     ShellBrowser *This = impl_from_IBrowserService(iface);
383     FIXME("%p %x %s\n", This, hres, debugstr_w(pwszPath));
384     return E_NOTIMPL;
385 }
386
387 static HRESULT WINAPI BrowserService_NavigateToPidl(
388         IBrowserService* iface,
389         PCIDLIST_ABSOLUTE pidl,
390         DWORD grfHLNF)
391 {
392     ShellBrowser *This = impl_from_IBrowserService(iface);
393     FIXME("%p %p %d\n", This, pidl, grfHLNF);
394     return E_NOTIMPL;
395 }
396
397 static HRESULT WINAPI BrowserService_SetNavigateState(
398         IBrowserService* iface,
399         BNSTATE bnstate)
400 {
401     ShellBrowser *This = impl_from_IBrowserService(iface);
402     FIXME("%p %d\n", This, bnstate);
403     return E_NOTIMPL;
404 }
405
406 static HRESULT WINAPI BrowserService_GetNavigateState(
407         IBrowserService* iface,
408         BNSTATE *pbnstate)
409 {
410     ShellBrowser *This = impl_from_IBrowserService(iface);
411     FIXME("%p %p\n", This, pbnstate);
412     return E_NOTIMPL;
413 }
414
415 static HRESULT WINAPI BrowserService_NotifyRedirect(
416         IBrowserService* iface,
417         IShellView *psv,
418         PCIDLIST_ABSOLUTE pidl,
419         BOOL *pfDidBrowse)
420 {
421     ShellBrowser *This = impl_from_IBrowserService(iface);
422     FIXME("%p %p %p %p\n", This, psv, pidl, pfDidBrowse);
423     return E_NOTIMPL;
424 }
425
426 static HRESULT WINAPI BrowserService_UpdateWindowList(
427         IBrowserService* iface)
428 {
429     ShellBrowser *This = impl_from_IBrowserService(iface);
430     FIXME("%p\n", This);
431     return E_NOTIMPL;
432 }
433
434 static HRESULT WINAPI BrowserService_UpdateBackForwardState(
435         IBrowserService* iface)
436 {
437     ShellBrowser *This = impl_from_IBrowserService(iface);
438     FIXME("%p\n", This);
439     return E_NOTIMPL;
440 }
441
442 static HRESULT WINAPI BrowserService_SetFlags(
443         IBrowserService* iface,
444         DWORD dwFlags,
445         DWORD dwFlagMask)
446 {
447     ShellBrowser *This = impl_from_IBrowserService(iface);
448     FIXME("%p %x %x\n", This, dwFlags, dwFlagMask);
449     return E_NOTIMPL;
450 }
451
452 static HRESULT WINAPI BrowserService_GetFlags(
453         IBrowserService* iface,
454         DWORD *pdwFlags)
455 {
456     ShellBrowser *This = impl_from_IBrowserService(iface);
457     FIXME("%p %p\n", This, pdwFlags);
458     return E_NOTIMPL;
459 }
460
461 static HRESULT WINAPI BrowserService_CanNavigateNow(
462         IBrowserService* iface)
463 {
464     ShellBrowser *This = impl_from_IBrowserService(iface);
465     FIXME("%p\n", This);
466     return E_NOTIMPL;
467 }
468
469 static HRESULT WINAPI BrowserService_GetPidl(
470         IBrowserService* iface,
471         PIDLIST_ABSOLUTE *ppidl)
472 {
473     ShellBrowser *This = impl_from_IBrowserService(iface);
474     FIXME("%p %p\n", This, ppidl);
475     return E_NOTIMPL;
476 }
477
478 static HRESULT WINAPI BrowserService_SetReferrer(
479         IBrowserService* iface,
480         PCIDLIST_ABSOLUTE pidl)
481 {
482     ShellBrowser *This = impl_from_IBrowserService(iface);
483     FIXME("%p %p\n", This, pidl);
484     return E_NOTIMPL;
485 }
486
487 static DWORD WINAPI BrowserService_GetBrowserIndex(
488         IBrowserService* iface)
489 {
490     ShellBrowser *This = impl_from_IBrowserService(iface);
491     FIXME("%p\n", This);
492     return E_NOTIMPL;
493 }
494
495 static HRESULT WINAPI BrowserService_GetBrowserByIndex(
496         IBrowserService* iface,
497         DWORD dwID,
498         IUnknown **ppunk)
499 {
500     ShellBrowser *This = impl_from_IBrowserService(iface);
501     FIXME("%p %x %p\n", This, dwID, ppunk);
502     return E_NOTIMPL;
503 }
504
505 static HRESULT WINAPI BrowserService_GetHistoryObject(
506         IBrowserService* iface,
507         IOleObject **ppole,
508         IStream **pstm,
509         IBindCtx **ppbc)
510 {
511     ShellBrowser *This = impl_from_IBrowserService(iface);
512     FIXME("%p %p %p %p\n", This, ppole, pstm, ppbc);
513     return E_NOTIMPL;
514 }
515
516 static HRESULT WINAPI BrowserService_SetHistoryObject(
517         IBrowserService* iface,
518         IOleObject *pole,
519         BOOL fIsLocalAnchor)
520 {
521     ShellBrowser *This = impl_from_IBrowserService(iface);
522     FIXME("%p %p %d\n", This, pole, fIsLocalAnchor);
523     return E_NOTIMPL;
524 }
525
526 static HRESULT WINAPI BrowserService_CacheOLEServer(
527         IBrowserService* iface,
528         IOleObject *pole)
529 {
530     ShellBrowser *This = impl_from_IBrowserService(iface);
531     FIXME("%p %p\n", This, pole);
532     return E_NOTIMPL;
533 }
534
535 static HRESULT WINAPI BrowserService_GetSetCodePage(
536         IBrowserService* iface,
537         VARIANT *pvarIn,
538         VARIANT *pvarOut)
539 {
540     ShellBrowser *This = impl_from_IBrowserService(iface);
541     FIXME("%p %p %p\n", This, pvarIn, pvarOut);
542     return E_NOTIMPL;
543 }
544
545 static HRESULT WINAPI BrowserService_OnHttpEquiv(
546         IBrowserService* iface,
547         IShellView *psv,
548         BOOL fDone,
549         VARIANT *pvarargIn,
550         VARIANT *pvarargOut)
551 {
552     ShellBrowser *This = impl_from_IBrowserService(iface);
553     FIXME("%p %p %d %p %p\n", This, psv, fDone, pvarargIn, pvarargOut);
554     return E_NOTIMPL;
555 }
556
557 static HRESULT WINAPI BrowserService_GetPalette(
558         IBrowserService* iface,
559         HPALETTE *hpal)
560 {
561     ShellBrowser *This = impl_from_IBrowserService(iface);
562     FIXME("%p %p\n", This, hpal);
563     return E_NOTIMPL;
564 }
565
566 static HRESULT WINAPI BrowserService_RegisterWindow(
567         IBrowserService* iface,
568         BOOL fForceRegister,
569         int swc)
570 {
571     ShellBrowser *This = impl_from_IBrowserService(iface);
572     FIXME("%p %d %d\n", This, fForceRegister, swc);
573     return E_NOTIMPL;
574 }
575
576 static const IBrowserServiceVtbl BrowserServiceVtbl = {
577     BrowserService_QueryInterface,
578     BrowserService_AddRef,
579     BrowserService_Release,
580     BrowserService_GetParentSite,
581     BrowserService_SetTitle,
582     BrowserService_GetTitle,
583     BrowserService_GetOleObject,
584     BrowserService_GetTravelLog,
585     BrowserService_ShowControlWindow,
586     BrowserService_IsControlWindowShown,
587     BrowserService_IEGetDisplayName,
588     BrowserService_IEParseDisplayName,
589     BrowserService_DisplayParseError,
590     BrowserService_NavigateToPidl,
591     BrowserService_SetNavigateState,
592     BrowserService_GetNavigateState,
593     BrowserService_NotifyRedirect,
594     BrowserService_UpdateWindowList,
595     BrowserService_UpdateBackForwardState,
596     BrowserService_SetFlags,
597     BrowserService_GetFlags,
598     BrowserService_CanNavigateNow,
599     BrowserService_GetPidl,
600     BrowserService_SetReferrer,
601     BrowserService_GetBrowserIndex,
602     BrowserService_GetBrowserByIndex,
603     BrowserService_GetHistoryObject,
604     BrowserService_SetHistoryObject,
605     BrowserService_CacheOLEServer,
606     BrowserService_GetSetCodePage,
607     BrowserService_OnHttpEquiv,
608     BrowserService_GetPalette,
609     BrowserService_RegisterWindow
610 };
611
612 static inline ShellBrowser *impl_from_IDocObjectService(IDocObjectService *iface)
613 {
614     return CONTAINING_RECORD(iface, ShellBrowser, IDocObjectService_iface);
615 }
616
617 static HRESULT WINAPI DocObjectService_QueryInterface(
618         IDocObjectService* iface,
619         REFIID riid,
620         void **ppvObject)
621 {
622     ShellBrowser *This = impl_from_IDocObjectService(iface);
623     return IShellBrowser_QueryInterface(&This->IShellBrowser_iface, riid, ppvObject);
624 }
625
626 static ULONG WINAPI DocObjectService_AddRef(
627         IDocObjectService* iface)
628 {
629     ShellBrowser *This = impl_from_IDocObjectService(iface);
630     return IShellBrowser_AddRef(&This->IShellBrowser_iface);
631 }
632
633 static ULONG WINAPI DocObjectService_Release(
634         IDocObjectService* iface)
635 {
636     ShellBrowser *This = impl_from_IDocObjectService(iface);
637     return IShellBrowser_Release(&This->IShellBrowser_iface);
638 }
639
640 static HRESULT WINAPI DocObjectService_FireBeforeNavigate2(
641         IDocObjectService* iface,
642         IDispatch *pDispatch,
643         LPCWSTR lpszUrl,
644         DWORD dwFlags,
645         LPCWSTR lpszFrameName,
646         BYTE *pPostData,
647         DWORD cbPostData,
648         LPCWSTR lpszHeaders,
649         BOOL fPlayNavSound,
650         BOOL *pfCancel)
651 {
652     ShellBrowser *This = impl_from_IDocObjectService(iface);
653     VARIANT var_url, var_flags, var_frame_name, var_post_data, var_post_data2, var_headers;
654     VARIANTARG params[7];
655     DISPPARAMS dp = {params, NULL, 7, 0};
656     VARIANT_BOOL cancel = VARIANT_FALSE;
657     SAFEARRAY *post_data;
658
659     TRACE("%p %p %s %x %s %p %d %s %d %p\n", This, pDispatch, debugstr_w(lpszUrl),
660             dwFlags, debugstr_w(lpszFrameName), pPostData, cbPostData,
661             debugstr_w(lpszHeaders), fPlayNavSound, pfCancel);
662
663     if(cbPostData) {
664         post_data = SafeArrayCreateVector(VT_UI1, 0, cbPostData);
665         memcpy(post_data->pvData, pPostData, cbPostData);
666         if(!post_data)
667             return E_OUTOFMEMORY;
668     }else {
669         post_data = NULL;
670     }
671
672     V_VT(params) = VT_BOOL|VT_BYREF;
673     V_BOOLREF(params) = &cancel;
674
675     V_VT(params+1) = (VT_BYREF|VT_VARIANT);
676     V_VARIANTREF(params+1) = &var_headers;
677     V_VT(&var_headers) = VT_BSTR;
678     V_BSTR(&var_headers) = lpszHeaders ? SysAllocString(lpszHeaders) : NULL;
679
680     V_VT(params+2) = (VT_BYREF|VT_VARIANT);
681     V_VARIANTREF(params+2) = &var_post_data2;
682     V_VT(&var_post_data2) = (VT_BYREF|VT_VARIANT);
683     V_VARIANTREF(&var_post_data2) = &var_post_data;
684
685     if(post_data) {
686         V_VT(&var_post_data) = VT_UI1|VT_ARRAY;
687         V_ARRAY(&var_post_data) = post_data;
688     }else {
689         V_VT(&var_post_data) = VT_EMPTY;
690     }
691
692     V_VT(params+3) = (VT_BYREF|VT_VARIANT);
693     V_VARIANTREF(params+3) = &var_frame_name;
694     V_VT(&var_frame_name) = VT_BSTR;
695     V_BSTR(&var_frame_name) = NULL;
696
697     V_VT(params+4) = (VT_BYREF|VT_VARIANT);
698     V_VARIANTREF(params+4) = &var_flags;
699     V_VT(&var_flags) = VT_I4;
700     V_I4(&var_flags) = 0;
701
702     V_VT(params+5) = (VT_BYREF|VT_VARIANT);
703     V_VARIANTREF(params+5) = &var_url;
704     V_VT(&var_url) = VT_BSTR;
705     V_BSTR(&var_url) = SysAllocString(lpszUrl);
706
707     V_VT(params+6) = (VT_DISPATCH);
708     V_DISPATCH(params+6) = This->doc_host->disp;
709
710     TRACE(">>>\n");
711     call_sink(This->doc_host->cps.wbe2, DISPID_BEFORENAVIGATE2, &dp);
712     TRACE("<<<\n");
713
714     SysFreeString(V_BSTR(&var_url));
715     SysFreeString(V_BSTR(&var_headers));
716     SafeArrayDestroy(post_data);
717
718     *pfCancel = !!cancel;
719     return S_OK;
720 }
721
722 static HRESULT WINAPI DocObjectService_FireNavigateComplete2(
723         IDocObjectService* iface,
724         IHTMLWindow2 *pHTMLWindow2,
725         DWORD dwFlags)
726 {
727     ShellBrowser *This = impl_from_IDocObjectService(iface);
728     IHTMLPrivateWindow *priv_window;
729     VARIANTARG params[2];
730     DISPPARAMS dp = {params, NULL, 2, 0};
731     VARIANT url_var;
732     BSTR url;
733     HRESULT hres;
734
735     TRACE("%p %p %x\n", This, pHTMLWindow2, dwFlags);
736
737     hres = IHTMLWindow2_QueryInterface(pHTMLWindow2, &IID_IHTMLPrivateWindow, (void**)&priv_window);
738     if(FAILED(hres))
739         return hres;
740
741     hres = IHTMLPrivateWindow_GetAddressBarUrl(priv_window, &url);
742     IHTMLPrivateWindow_Release(priv_window);
743     if(FAILED(hres))
744         return hres;
745
746     TRACE("got URL %s\n", debugstr_w(url));
747     set_dochost_url(This->doc_host, url);
748
749     V_VT(params) = (VT_BYREF|VT_VARIANT);
750     V_BYREF(params) = &url;
751
752     V_VT(params+1) = VT_DISPATCH;
753     V_DISPATCH(params+1) = This->doc_host->disp;
754
755     V_VT(&url_var) = VT_BSTR;
756     V_BSTR(&url_var) = url;
757
758     TRACE(">>>\n");
759     call_sink(This->doc_host->cps.wbe2, DISPID_NAVIGATECOMPLETE2, &dp);
760     TRACE("<<<\n");
761
762     SysFreeString(url);
763
764     This->doc_host->busy = VARIANT_FALSE;
765     return S_OK;
766 }
767
768 static HRESULT WINAPI DocObjectService_FireDownloadBegin(
769         IDocObjectService* iface)
770 {
771     ShellBrowser *This = impl_from_IDocObjectService(iface);
772     FIXME("%p\n", This);
773     return E_NOTIMPL;
774 }
775
776 static HRESULT WINAPI DocObjectService_FireDownloadComplete(
777         IDocObjectService* iface)
778 {
779     ShellBrowser *This = impl_from_IDocObjectService(iface);
780     FIXME("%p\n", This);
781     return E_NOTIMPL;
782 }
783
784 static HRESULT WINAPI DocObjectService_FireDocumentComplete(
785         IDocObjectService* iface,
786         IHTMLWindow2 *pHTMLWindow,
787         DWORD dwFlags)
788 {
789     ShellBrowser *This = impl_from_IDocObjectService(iface);
790     IHTMLPrivateWindow *priv_window;
791     VARIANTARG params[2];
792     DISPPARAMS dp = {params, NULL, 2, 0};
793     VARIANT url_var;
794     BSTR url;
795     HRESULT hres;
796
797     TRACE("%p %p %x\n", This, pHTMLWindow, dwFlags);
798
799     hres = IHTMLWindow2_QueryInterface(pHTMLWindow, &IID_IHTMLPrivateWindow, (void**)&priv_window);
800     if(FAILED(hres))
801         return hres;
802
803     hres = IHTMLPrivateWindow_GetAddressBarUrl(priv_window, &url);
804     IHTMLPrivateWindow_Release(priv_window);
805     if(FAILED(hres))
806         return hres;
807
808     TRACE("got URL %s\n", debugstr_w(url));
809
810     V_VT(params) = (VT_BYREF|VT_VARIANT);
811     V_BYREF(params) = &url;
812
813     V_VT(params+1) = VT_DISPATCH;
814     V_DISPATCH(params+1) = This->doc_host->disp;
815
816     V_VT(&url_var) = VT_BSTR;
817     V_BSTR(&url_var) = url;
818
819     TRACE(">>>\n");
820     call_sink(This->doc_host->cps.wbe2, DISPID_DOCUMENTCOMPLETE, &dp);
821     TRACE("<<<\n");
822
823     SysFreeString(url);
824     This->doc_host->busy = VARIANT_FALSE;
825     return S_OK;
826 }
827
828 static HRESULT WINAPI DocObjectService_UpdateDesktopComponent(
829         IDocObjectService* iface,
830         IHTMLWindow2 *pHTMLWindow)
831 {
832     ShellBrowser *This = impl_from_IDocObjectService(iface);
833     FIXME("%p %p\n", This, pHTMLWindow);
834     return E_NOTIMPL;
835 }
836
837 static HRESULT WINAPI DocObjectService_GetPendingUrl(
838         IDocObjectService* iface,
839         BSTR *pbstrPendingUrl)
840 {
841     ShellBrowser *This = impl_from_IDocObjectService(iface);
842     FIXME("%p %p\n", This, pbstrPendingUrl);
843     return E_NOTIMPL;
844 }
845
846 static HRESULT WINAPI DocObjectService_ActiveElementChanged(
847         IDocObjectService* iface,
848         IHTMLElement *pHTMLElement)
849 {
850     ShellBrowser *This = impl_from_IDocObjectService(iface);
851     FIXME("%p %p\n", This, pHTMLElement);
852     return E_NOTIMPL;
853 }
854
855 static HRESULT WINAPI DocObjectService_GetUrlSearchComponent(
856         IDocObjectService* iface,
857         BSTR *pbstrSearch)
858 {
859     ShellBrowser *This = impl_from_IDocObjectService(iface);
860     FIXME("%p %p\n", This, pbstrSearch);
861     return E_NOTIMPL;
862 }
863
864 static HRESULT WINAPI DocObjectService_IsErrorUrl(
865         IDocObjectService* iface,
866         LPCWSTR lpszUrl,
867         BOOL *pfIsError)
868 {
869     ShellBrowser *This = impl_from_IDocObjectService(iface);
870     FIXME("%p %s %p\n", This, debugstr_w(lpszUrl), pfIsError);
871
872     *pfIsError = FALSE;
873     return S_OK;
874 }
875
876 static const IDocObjectServiceVtbl DocObjectServiceVtbl = {
877     DocObjectService_QueryInterface,
878     DocObjectService_AddRef,
879     DocObjectService_Release,
880     DocObjectService_FireBeforeNavigate2,
881     DocObjectService_FireNavigateComplete2,
882     DocObjectService_FireDownloadBegin,
883     DocObjectService_FireDownloadComplete,
884     DocObjectService_FireDocumentComplete,
885     DocObjectService_UpdateDesktopComponent,
886     DocObjectService_GetPendingUrl,
887     DocObjectService_ActiveElementChanged,
888     DocObjectService_GetUrlSearchComponent,
889     DocObjectService_IsErrorUrl
890 };
891
892 HRESULT create_browser_service(DocHost *doc_host, ShellBrowser **ret)
893 {
894     ShellBrowser *sb;
895
896     sb = heap_alloc(sizeof(ShellBrowser));
897     if(!sb)
898         return E_OUTOFMEMORY;
899
900     sb->IShellBrowser_iface.lpVtbl = &ShellBrowserVtbl;
901     sb->IBrowserService_iface.lpVtbl = &BrowserServiceVtbl;
902     sb->IDocObjectService_iface.lpVtbl = &DocObjectServiceVtbl;
903
904     sb->ref = 1;
905     sb->doc_host = doc_host;
906
907     *ret = sb;
908     return S_OK;
909 }
910
911 void detach_browser_service(ShellBrowser *sb)
912 {
913     sb->doc_host = NULL;
914     IShellBrowser_Release(&sb->IShellBrowser_iface);
915 }