shdocvw: Added missing OnObjectAvailable function.
[wine] / dlls / shdocvw / navigate.c
1 /*
2  * Copyright 2006 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 #define NONAMELESSUNION
20 #define NONAMELESSSTRUCT
21
22 #include "wine/debug.h"
23 #include "wine/unicode.h"
24
25 #include "shdocvw.h"
26 #include "mshtml.h"
27 #include "exdispid.h"
28 #include "shellapi.h"
29 #include "winreg.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
32
33 typedef struct {
34     const IBindStatusCallbackVtbl  *lpBindStatusCallbackVtbl;
35     const IHttpNegotiateVtbl       *lpHttpNegotiateVtbl;
36
37     LONG ref;
38
39     HGLOBAL post_data;
40     LPWSTR headers;
41     ULONG post_data_len;
42 } BindStatusCallback;
43
44 #define BINDSC(x)  ((IBindStatusCallback*) &(x)->lpBindStatusCallbackVtbl)
45 #define HTTPNEG(x) ((IHttpNegotiate*)      &(x)->lpHttpNegotiateVtbl)
46
47 static void dump_BINDINFO(BINDINFO *bi)
48 {
49     static const char * const BINDINFOF_str[] = {
50         "#0",
51         "BINDINFOF_URLENCODESTGMEDDATA",
52         "BINDINFOF_URLENCODEDEXTRAINFO"
53     };
54
55     static const char * const BINDVERB_str[] = {
56         "BINDVERB_GET",
57         "BINDVERB_POST",
58         "BINDVERB_PUT",
59         "BINDVERB_CUSTOM"
60     };
61
62     TRACE("\n"
63             "BINDINFO = {\n"
64             "    %d, %s,\n"
65             "    {%d, %p, %p},\n"
66             "    %s,\n"
67             "    %s,\n"
68             "    %s,\n"
69             "    %d, %08x, %d, %d\n"
70             "    {%d %p %x},\n"
71             "    %s\n"
72             "    %p, %d\n"
73             "}\n",
74
75             bi->cbSize, debugstr_w(bi->szExtraInfo),
76             bi->stgmedData.tymed, bi->stgmedData.u.hGlobal, bi->stgmedData.pUnkForRelease,
77             bi->grfBindInfoF > BINDINFOF_URLENCODEDEXTRAINFO
78                 ? "unknown" : BINDINFOF_str[bi->grfBindInfoF],
79             bi->dwBindVerb > BINDVERB_CUSTOM
80                 ? "unknown" : BINDVERB_str[bi->dwBindVerb],
81             debugstr_w(bi->szCustomVerb),
82             bi->cbstgmedData, bi->dwOptions, bi->dwOptionsFlags, bi->dwCodePage,
83             bi->securityAttributes.nLength,
84             bi->securityAttributes.lpSecurityDescriptor,
85             bi->securityAttributes.bInheritHandle,
86             debugstr_guid(&bi->iid),
87             bi->pUnk, bi->dwReserved
88             );
89 }
90
91 #define BINDSC_THIS(iface) DEFINE_THIS(BindStatusCallback, BindStatusCallback, iface)
92
93 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallback *iface,
94                                                         REFIID riid, void **ppv)
95 {
96     BindStatusCallback *This = BINDSC_THIS(iface);
97
98     *ppv = NULL;
99
100     if(IsEqualGUID(&IID_IUnknown, riid)) {
101         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
102         *ppv = BINDSC(This);
103     }else if(IsEqualGUID(&IID_IBindStatusCallback, riid)) {
104         TRACE("(%p)->(IID_IBindStatusCallback %p)\n", This, ppv);
105         *ppv = BINDSC(This);
106     }else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) {
107         TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This, ppv);
108         *ppv = HTTPNEG(This);
109     }
110
111     if(*ppv) {
112         IBindStatusCallback_AddRef(BINDSC(This));
113         return S_OK;
114     }
115
116     WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
117     return E_NOINTERFACE;
118 }
119
120 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallback *iface)
121 {
122     BindStatusCallback *This = BINDSC_THIS(iface);
123     LONG ref = InterlockedIncrement(&This->ref);
124
125     TRACE("(%p) ref=%d\n", This, ref);
126
127     return ref;
128 }
129
130 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallback *iface)
131 {
132     BindStatusCallback *This = BINDSC_THIS(iface);
133     LONG ref = InterlockedDecrement(&This->ref);
134
135     TRACE("(%p) ref=%d\n", This, ref);
136
137     if(!ref) {
138         if(This->post_data)
139             GlobalFree(This->post_data);
140         heap_free(This->headers);
141         heap_free(This);
142     }
143
144     return ref;
145 }
146
147 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallback *iface,
148        DWORD dwReserved, IBinding *pbind)
149 {
150     BindStatusCallback *This = BINDSC_THIS(iface);
151     FIXME("(%p)->(%d %p)\n", This, dwReserved, pbind);
152     return E_NOTIMPL;
153 }
154
155 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface,
156        LONG *pnPriority)
157 {
158     BindStatusCallback *This = BINDSC_THIS(iface);
159     FIXME("(%p)->(%p)\n", This, pnPriority);
160     return E_NOTIMPL;
161 }
162
163 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface,
164        DWORD reserved)
165 {
166     BindStatusCallback *This = BINDSC_THIS(iface);
167     FIXME("(%p)->(%d)\n", This, reserved);
168     return E_NOTIMPL;
169 }
170
171 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallback *iface,
172         ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
173 {
174     BindStatusCallback *This = BINDSC_THIS(iface);
175     FIXME("(%p)->(%d %d %d %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
176           debugstr_w(szStatusText));
177     return E_NOTIMPL;
178 }
179
180 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
181         HRESULT hresult, LPCWSTR szError)
182 {
183     BindStatusCallback *This = BINDSC_THIS(iface);
184     FIXME("(%p)->(%08x %s)\n", This, hresult, debugstr_w(szError));
185     return E_NOTIMPL;
186 }
187
188 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
189         DWORD *grfBINDF, BINDINFO *pbindinfo)
190 {
191     BindStatusCallback *This = BINDSC_THIS(iface);
192
193     FIXME("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
194
195     memset(pbindinfo, 0, sizeof(BINDINFO));
196     pbindinfo->cbSize = sizeof(BINDINFO);
197
198     pbindinfo->cbstgmedData = This->post_data_len;
199
200     if(This->post_data) {
201         pbindinfo->dwBindVerb = BINDVERB_POST;
202
203         pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
204         pbindinfo->stgmedData.u.hGlobal = This->post_data;
205         pbindinfo->stgmedData.pUnkForRelease = (IUnknown*)BINDSC(This);
206         IBindStatusCallback_AddRef(BINDSC(This));
207     }
208
209     return S_OK;
210 }
211
212 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
213         DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
214 {
215     BindStatusCallback *This = BINDSC_THIS(iface);
216     FIXME("(%p)->(%08x %d %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed);
217     return E_NOTIMPL;
218 }
219
220 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
221         REFIID riid, IUnknown *punk)
222 {
223     BindStatusCallback *This = BINDSC_THIS(iface);
224     FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), punk);
225     return E_NOTIMPL;
226 }
227
228 #undef BSC_THIS
229
230 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
231     BindStatusCallback_QueryInterface,
232     BindStatusCallback_AddRef,
233     BindStatusCallback_Release,
234     BindStatusCallback_OnStartBinding,
235     BindStatusCallback_GetPriority,
236     BindStatusCallback_OnLowResource,
237     BindStatusCallback_OnProgress,
238     BindStatusCallback_OnStopBinding,
239     BindStatusCallback_GetBindInfo,
240     BindStatusCallback_OnDataAvailable,
241     BindStatusCallback_OnObjectAvailable
242 };
243
244 #define HTTPNEG_THIS(iface) DEFINE_THIS(BindStatusCallback, HttpNegotiate, iface)
245
246 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate *iface,
247                                                    REFIID riid, void **ppv)
248 {
249     BindStatusCallback *This = HTTPNEG_THIS(iface);
250     return IBindStatusCallback_QueryInterface(BINDSC(This), riid, ppv);
251 }
252
253 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate *iface)
254 {
255     BindStatusCallback *This = HTTPNEG_THIS(iface);
256     return IBindStatusCallback_AddRef(BINDSC(This));
257 }
258
259 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate *iface)
260 {
261     BindStatusCallback *This = HTTPNEG_THIS(iface);
262     return IBindStatusCallback_Release(BINDSC(This));
263 }
264
265 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate *iface,
266         LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
267 {
268     BindStatusCallback *This = HTTPNEG_THIS(iface);
269
270     FIXME("(%p)->(%s %s %d %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders),
271           dwReserved, pszAdditionalHeaders);
272
273     if(This->headers) {
274         int size = (strlenW(This->headers)+1)*sizeof(WCHAR);
275         *pszAdditionalHeaders = CoTaskMemAlloc(size);
276         memcpy(*pszAdditionalHeaders, This->headers, size);
277     }
278
279     return S_OK;
280 }
281
282 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate *iface,
283         DWORD dwResponseCode, LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders,
284         LPWSTR *pszAdditionalRequestHeaders)
285 {
286     BindStatusCallback *This = HTTPNEG_THIS(iface);
287     FIXME("(%p)->(%d %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
288           debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
289     return E_NOTIMPL;
290 }
291
292 #undef HTTPNEG_THIS
293
294 static const IHttpNegotiateVtbl HttpNegotiateVtbl = {
295     HttpNegotiate_QueryInterface,
296     HttpNegotiate_AddRef,
297     HttpNegotiate_Release,
298     HttpNegotiate_BeginningTransaction,
299     HttpNegotiate_OnResponse
300 };
301
302 static IBindStatusCallback *create_callback(DocHost *This, PBYTE post_data,
303         ULONG post_data_len, LPWSTR headers, VARIANT_BOOL *cancel)
304 {
305     BindStatusCallback *ret = heap_alloc(sizeof(BindStatusCallback));
306
307     ret->lpBindStatusCallbackVtbl = &BindStatusCallbackVtbl;
308     ret->lpHttpNegotiateVtbl      = &HttpNegotiateVtbl;
309
310     ret->ref = 1;
311     ret->post_data = NULL;
312     ret->post_data_len = post_data_len;
313     ret->headers = NULL;
314
315     if(post_data) {
316         ret->post_data = GlobalAlloc(0, post_data_len);
317         memcpy(ret->post_data, post_data, post_data_len);
318     }
319
320     if(headers) {
321         int size = (strlenW(headers)+1)*sizeof(WCHAR);
322         ret->headers = heap_alloc(size);
323         memcpy(ret->headers, headers, size);
324     }
325
326     return BINDSC(ret);
327 }
328
329 static void on_before_navigate2(DocHost *This, LPCWSTR url, const BYTE *post_data,
330                                 ULONG post_data_len, LPWSTR headers, VARIANT_BOOL *cancel)
331 {
332     VARIANT var_url, var_flags, var_frame_name, var_post_data, var_post_data2, var_headers;
333     DISPPARAMS dispparams;
334     VARIANTARG params[7];
335
336     dispparams.cArgs = 7;
337     dispparams.cNamedArgs = 0;
338     dispparams.rgdispidNamedArgs = NULL;
339     dispparams.rgvarg = params;
340
341     V_VT(params) = VT_BOOL|VT_BYREF;
342     V_BOOLREF(params) = cancel;
343
344     V_VT(params+1) = (VT_BYREF|VT_VARIANT);
345     V_VARIANTREF(params+1) = &var_headers;
346     V_VT(&var_headers) = VT_BSTR;
347     V_BSTR(&var_headers) = headers;
348
349     V_VT(params+2) = (VT_BYREF|VT_VARIANT);
350     V_VARIANTREF(params+2) = &var_post_data2;
351     V_VT(&var_post_data2) = (VT_BYREF|VT_VARIANT);
352     V_VARIANTREF(&var_post_data2) = &var_post_data;
353     VariantInit(&var_post_data);
354
355     if(post_data_len) {
356         SAFEARRAYBOUND bound = {post_data_len, 0};
357         void *data;
358
359         V_VT(&var_post_data) = VT_UI1|VT_ARRAY;
360         V_ARRAY(&var_post_data) = SafeArrayCreate(VT_UI1, 1, &bound);
361
362         SafeArrayAccessData(V_ARRAY(&var_post_data), &data);
363         memcpy(data, post_data, post_data_len);
364         SafeArrayUnaccessData(V_ARRAY(&var_post_data));
365     }
366
367     V_VT(params+3) = (VT_BYREF|VT_VARIANT);
368     V_VARIANTREF(params+3) = &var_frame_name;
369     V_VT(&var_frame_name) = VT_BSTR;
370     V_BSTR(&var_frame_name) = NULL;
371
372     V_VT(params+4) = (VT_BYREF|VT_VARIANT);
373     V_VARIANTREF(params+4) = &var_flags;
374     V_VT(&var_flags) = VT_I4;
375     V_I4(&var_flags) = 0;
376
377     V_VT(params+5) = (VT_BYREF|VT_VARIANT);
378     V_VARIANTREF(params+5) = &var_url;
379     V_VT(&var_url) = VT_BSTR;
380     V_BSTR(&var_url) = SysAllocString(url);
381
382     V_VT(params+6) = (VT_DISPATCH);
383     V_DISPATCH(params+6) = This->disp;
384
385     call_sink(This->cps.wbe2, DISPID_BEFORENAVIGATE2, &dispparams);
386
387     SysFreeString(V_BSTR(&var_url));
388     if(post_data_len)
389         SafeArrayDestroy(V_ARRAY(&var_post_data));
390 }
391
392 static BOOL try_application_url(LPCWSTR url)
393 {
394     SHELLEXECUTEINFOW exec_info;
395     WCHAR app[64];
396     HKEY hkey;
397     DWORD res, type;
398     HRESULT hres;
399
400     static const WCHAR wszURLProtocol[] = {'U','R','L',' ','P','r','o','t','o','c','o','l',0};
401
402     hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, app, sizeof(app)/sizeof(WCHAR), NULL, 0);
403     if(FAILED(hres))
404         return FALSE;
405
406     res = RegOpenKeyW(HKEY_CLASSES_ROOT, app, &hkey);
407     if(res != ERROR_SUCCESS)
408         return FALSE;
409
410     res = RegQueryValueExW(hkey, wszURLProtocol, NULL, &type, NULL, NULL);
411     RegCloseKey(hkey);
412     if(res != ERROR_SUCCESS || type != REG_SZ)
413         return FALSE;
414
415     TRACE("openning application %s\n", debugstr_w(app));
416  
417     memset(&exec_info, 0, sizeof(exec_info));
418     exec_info.cbSize = sizeof(exec_info);
419     exec_info.lpFile = url;
420     exec_info.nShow = SW_SHOW;
421
422     return ShellExecuteExW(&exec_info);
423 }
424
425 static HRESULT navigate(DocHost *This, IMoniker *mon, IBindCtx *bindctx)
426 {
427     IOleObject *oleobj;
428     IPersistMoniker *persist;
429     VARIANT_BOOL cancel = VARIANT_FALSE;
430     HRESULT hres;
431
432     if(cancel) {
433         FIXME("Cancel\n");
434         return S_OK;
435     }
436
437     IBindCtx_RegisterObjectParam(bindctx, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM,
438                                  (IUnknown*)CLIENTSITE(This));
439
440     /*
441      * FIXME:
442      * We should use URLMoniker's BindToObject instead creating HTMLDocument here.
443      * This should be fixed when mshtml.dll and urlmon.dll will be good enough.
444      */
445
446     if(This->document)
447         deactivate_document(This);
448
449     hres = CoCreateInstance(&CLSID_HTMLDocument, NULL,
450                             CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
451                             &IID_IUnknown, (void**)&This->document);
452
453     if(FAILED(hres)) {
454         ERR("Could not create HTMLDocument: %08x\n", hres);
455         return hres;
456     }
457
458     hres = IUnknown_QueryInterface(This->document, &IID_IPersistMoniker, (void**)&persist);
459     if(FAILED(hres))
460         return hres;
461
462     if(This->frame)
463         IOleInPlaceFrame_EnableModeless(This->frame, FALSE); /* FIXME */
464
465     hres = IPersistMoniker_Load(persist, FALSE, mon, bindctx, 0);
466     IPersistMoniker_Release(persist);
467
468     if(This->frame) {
469         static const WCHAR empty[] = {0};
470
471         IOleInPlaceFrame_SetStatusText(This->frame, empty); /* FIXME */
472         IOleInPlaceFrame_EnableModeless(This->frame, TRUE); /* FIXME */
473     }
474
475     if(FAILED(hres)) {
476         WARN("Load failed: %08x\n", hres);
477         return hres;
478     }
479
480     hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&oleobj);
481     if(FAILED(hres))
482         return hres;
483
484     hres = IOleObject_SetClientSite(oleobj, CLIENTSITE(This));
485     IOleObject_Release(oleobj);
486
487     PostMessageW(This->hwnd, WB_WM_NAVIGATE2, 0, 0);
488
489     return hres;
490
491 }
492
493 static HRESULT bind_url_to_object(DocHost *This, LPCWSTR url, PBYTE post_data, ULONG post_data_len,
494                      LPWSTR headers)
495 {
496     IBindStatusCallback *callback;
497     IMoniker *mon;
498     IBindCtx *bindctx;
499     VARIANT_BOOL cancel = VARIANT_FALSE;
500     HRESULT hres;
501
502     if(!This->hwnd)
503         create_doc_view_hwnd(This);
504
505     hres = CreateURLMoniker(NULL, url, &mon);
506     if(FAILED(hres)) {
507         WARN("CreateURLMoniker failed: %08x\n", hres);
508         return hres;
509     }
510
511     IMoniker_GetDisplayName(mon, NULL, NULL, &This->url);
512     TRACE("navigating to %s\n", debugstr_w(This->url));
513
514     callback = create_callback(This, post_data, post_data_len, (LPWSTR)headers, &cancel);
515     CreateAsyncBindCtx(0, callback, 0, &bindctx);
516     IBindStatusCallback_Release(callback);
517
518     hres = navigate(This, mon, bindctx);
519
520     IBindCtx_Release(bindctx);
521     IMoniker_Release(mon);
522
523     return hres;
524 }
525
526 HRESULT navigate_url(DocHost *This, LPCWSTR url, const VARIANT *Flags,
527                      const VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers)
528 {
529     PBYTE post_data = NULL;
530     ULONG post_data_len = 0;
531     LPWSTR headers = NULL;
532     HRESULT hres;
533
534     TRACE("navigating to %s\n", debugstr_w(url));
535
536     if((Flags && V_VT(Flags) != VT_EMPTY) 
537        || (TargetFrameName && V_VT(TargetFrameName) != VT_EMPTY))
538         FIXME("Unsupported args (Flags %p:%d; TargetFrameName %p:%d)\n",
539                 Flags, Flags ? V_VT(Flags) : -1, TargetFrameName,
540                 TargetFrameName ? V_VT(TargetFrameName) : -1);
541
542     if(PostData) {
543         TRACE("PostData vt=%d\n", V_VT(PostData));
544
545         if(V_VT(PostData) == (VT_ARRAY | VT_UI1)) {
546             SafeArrayAccessData(V_ARRAY(PostData), (void**)&post_data);
547             post_data_len = V_ARRAY(PostData)->rgsabound[0].cElements;
548         }
549     }
550
551     if(Headers && V_VT(Headers) != VT_EMPTY && V_VT(Headers) != VT_ERROR) {
552         if(V_VT(Headers) != VT_BSTR)
553             return E_INVALIDARG;
554
555         headers = V_BSTR(Headers);
556         TRACE("Headers: %s\n", debugstr_w(headers));
557     }
558
559     hres = bind_url_to_object(This, url, post_data, post_data_len, headers);
560
561     if(post_data)
562         SafeArrayUnaccessData(V_ARRAY(PostData));
563
564     return hres;
565 }
566
567 static HRESULT navigate_hlink(DocHost *This, IMoniker *mon, IBindCtx *bindctx,
568                               IBindStatusCallback *callback)
569 {
570     IHttpNegotiate *http_negotiate;
571     LPWSTR url = NULL;
572     PBYTE post_data = NULL;
573     ULONG post_data_len = 0;
574     LPWSTR headers = NULL;
575     VARIANT_BOOL cancel = VARIANT_FALSE;
576     BINDINFO bindinfo;
577     DWORD bindf = 0;
578     HRESULT hres;
579
580     IMoniker_GetDisplayName(mon, NULL, NULL, &url);
581     TRACE("navigating to %s\n", debugstr_w(url));
582
583     hres = IBindStatusCallback_QueryInterface(callback, &IID_IHttpNegotiate,
584                                               (void**)&http_negotiate);
585     if(SUCCEEDED(hres)) {
586         static const WCHAR null_string[] = {0};
587
588         IHttpNegotiate_BeginningTransaction(http_negotiate, null_string, null_string, 0,
589                                             &headers);
590         IHttpNegotiate_Release(http_negotiate);
591     }
592
593     memset(&bindinfo, 0, sizeof(bindinfo));
594     bindinfo.cbSize = sizeof(bindinfo);
595
596     hres = IBindStatusCallback_GetBindInfo(callback, &bindf, &bindinfo);
597     dump_BINDINFO(&bindinfo);
598     if(bindinfo.dwBindVerb == BINDVERB_POST) {
599         post_data_len = bindinfo.cbstgmedData;
600         if(post_data_len)
601             post_data = bindinfo.stgmedData.u.hGlobal;
602     }
603
604     on_before_navigate2(This, url, post_data, post_data_len, headers, &cancel);
605
606     CoTaskMemFree(headers);
607     ReleaseBindInfo(&bindinfo);
608
609     if(cancel) {
610         FIXME("navigation canceled\n");
611         CoTaskMemFree(url);
612         return S_OK;
613     }
614
615     /* FIXME: We should do it after BindToObject call */
616     if(try_application_url(url))
617         return S_OK;
618
619     This->url = url;
620
621     return navigate(This, mon, bindctx);
622 }
623
624 HRESULT go_home(DocHost *This)
625 {
626     static const WCHAR wszAboutBlank[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
627
628     FIXME("stub\n");
629
630     return navigate_url(This, wszAboutBlank, NULL, NULL, NULL, NULL);
631 }
632
633 #define HLINKFRAME_THIS(iface) DEFINE_THIS(WebBrowser, HlinkFrame, iface)
634
635 static HRESULT WINAPI HlinkFrame_QueryInterface(IHlinkFrame *iface, REFIID riid, void **ppv)
636 {
637     WebBrowser *This = HLINKFRAME_THIS(iface);
638     return IWebBrowser2_QueryInterface(WEBBROWSER2(This), riid, ppv);
639 }
640
641 static ULONG WINAPI HlinkFrame_AddRef(IHlinkFrame *iface)
642 {
643     WebBrowser *This = HLINKFRAME_THIS(iface);
644     return IWebBrowser2_AddRef(WEBBROWSER2(This));
645 }
646
647 static ULONG WINAPI HlinkFrame_Release(IHlinkFrame *iface)
648 {
649     WebBrowser *This = HLINKFRAME_THIS(iface);
650     return IWebBrowser2_Release(WEBBROWSER2(This));
651 }
652
653 static HRESULT WINAPI HlinkFrame_SetBrowseContext(IHlinkFrame *iface,
654                                                   IHlinkBrowseContext *pihlbc)
655 {
656     WebBrowser *This = HLINKFRAME_THIS(iface);
657     FIXME("(%p)->(%p)\n", This, pihlbc);
658     return E_NOTIMPL;
659 }
660
661 static HRESULT WINAPI HlinkFrame_GetBrowseContext(IHlinkFrame *iface,
662                                                   IHlinkBrowseContext **ppihlbc)
663 {
664     WebBrowser *This = HLINKFRAME_THIS(iface);
665     FIXME("(%p)->(%p)\n", This, ppihlbc);
666     return E_NOTIMPL;
667 }
668
669 static HRESULT WINAPI HlinkFrame_Navigate(IHlinkFrame *iface, DWORD grfHLNF, LPBC pbc,
670                                           IBindStatusCallback *pibsc, IHlink *pihlNavigate)
671 {
672     WebBrowser *This = HLINKFRAME_THIS(iface);
673     IMoniker *mon;
674     LPWSTR location = NULL;
675
676     TRACE("(%p)->(%08x %p %p %p)\n", This, grfHLNF, pbc, pibsc, pihlNavigate);
677
678     if(grfHLNF)
679         FIXME("unsupported grfHLNF=%08x\n", grfHLNF);
680
681     /* Windows calls GetTargetFrameName here. */
682
683     IHlink_GetMonikerReference(pihlNavigate, 1, &mon, &location);
684
685     if(location) {
686         FIXME("location = %s\n", debugstr_w(location));
687         CoTaskMemFree(location);
688     }
689
690     /* Windows calls GetHlinkSite here */
691
692     if(grfHLNF & HLNF_OPENINNEWWINDOW) {
693         FIXME("Not supported HLNF_OPENINNEWWINDOW\n");
694         return E_NOTIMPL;
695     }
696
697     return navigate_hlink(&This->doc_host, mon, pbc, pibsc);
698 }
699
700 static HRESULT WINAPI HlinkFrame_OnNavigate(IHlinkFrame *iface, DWORD grfHLNF,
701         IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName, DWORD dwreserved)
702 {
703     WebBrowser *This = HLINKFRAME_THIS(iface);
704     FIXME("(%p)->(%08x %p %s %s %d)\n", This, grfHLNF, pimkTarget, debugstr_w(pwzLocation),
705           debugstr_w(pwzFriendlyName), dwreserved);
706     return E_NOTIMPL;
707 }
708
709 static HRESULT WINAPI HlinkFrame_UpdateHlink(IHlinkFrame *iface, ULONG uHLID,
710         IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName)
711 {
712     WebBrowser *This = HLINKFRAME_THIS(iface);
713     FIXME("(%p)->(%u %p %s %s)\n", This, uHLID, pimkTarget, debugstr_w(pwzLocation),
714           debugstr_w(pwzFriendlyName));
715     return E_NOTIMPL;
716 }
717
718 #undef HLINKFRAME_THIS
719
720 static const IHlinkFrameVtbl HlinkFrameVtbl = {
721     HlinkFrame_QueryInterface,
722     HlinkFrame_AddRef,
723     HlinkFrame_Release,
724     HlinkFrame_SetBrowseContext,
725     HlinkFrame_GetBrowseContext,
726     HlinkFrame_Navigate,
727     HlinkFrame_OnNavigate,
728     HlinkFrame_UpdateHlink
729 };
730
731 void WebBrowser_HlinkFrame_Init(WebBrowser *This)
732 {
733     This->lpHlinkFrameVtbl = &HlinkFrameVtbl;
734 }