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