gdiplus/tests: Added GdipAddPathLineI test.
[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         shdocvw_free(This->headers);
141         shdocvw_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 #undef BSC_THIS
221
222 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
223     BindStatusCallback_QueryInterface,
224     BindStatusCallback_AddRef,
225     BindStatusCallback_Release,
226     BindStatusCallback_OnStartBinding,
227     BindStatusCallback_GetPriority,
228     BindStatusCallback_OnLowResource,
229     BindStatusCallback_OnProgress,
230     BindStatusCallback_OnStopBinding,
231     BindStatusCallback_GetBindInfo,
232     BindStatusCallback_OnDataAvailable
233 };
234
235 #define HTTPNEG_THIS(iface) DEFINE_THIS(BindStatusCallback, HttpNegotiate, iface)
236
237 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate *iface,
238                                                    REFIID riid, void **ppv)
239 {
240     BindStatusCallback *This = HTTPNEG_THIS(iface);
241     return IBindStatusCallback_QueryInterface(BINDSC(This), riid, ppv);
242 }
243
244 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate *iface)
245 {
246     BindStatusCallback *This = HTTPNEG_THIS(iface);
247     return IBindStatusCallback_AddRef(BINDSC(This));
248 }
249
250 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate *iface)
251 {
252     BindStatusCallback *This = HTTPNEG_THIS(iface);
253     return IBindStatusCallback_Release(BINDSC(This));
254 }
255
256 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate *iface,
257         LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
258 {
259     BindStatusCallback *This = HTTPNEG_THIS(iface);
260
261     FIXME("(%p)->(%s %s %d %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders),
262           dwReserved, pszAdditionalHeaders);
263
264     if(This->headers) {
265         int size = (strlenW(This->headers)+1)*sizeof(WCHAR);
266         *pszAdditionalHeaders = CoTaskMemAlloc(size);
267         memcpy(*pszAdditionalHeaders, This->headers, size);
268     }
269
270     return S_OK;
271 }
272
273 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate *iface,
274         DWORD dwResponseCode, LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders,
275         LPWSTR *pszAdditionalRequestHeaders)
276 {
277     BindStatusCallback *This = HTTPNEG_THIS(iface);
278     FIXME("(%p)->(%d %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
279           debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
280     return E_NOTIMPL;
281 }
282
283 #undef HTTPNEG_THIS
284
285 static const IHttpNegotiateVtbl HttpNegotiateVtbl = {
286     HttpNegotiate_QueryInterface,
287     HttpNegotiate_AddRef,
288     HttpNegotiate_Release,
289     HttpNegotiate_BeginningTransaction,
290     HttpNegotiate_OnResponse
291 };
292
293 static IBindStatusCallback *create_callback(DocHost *This, PBYTE post_data,
294         ULONG post_data_len, LPWSTR headers, VARIANT_BOOL *cancel)
295 {
296     BindStatusCallback *ret = shdocvw_alloc(sizeof(BindStatusCallback));
297
298     ret->lpBindStatusCallbackVtbl = &BindStatusCallbackVtbl;
299     ret->lpHttpNegotiateVtbl      = &HttpNegotiateVtbl;
300
301     ret->ref = 1;
302     ret->post_data = NULL;
303     ret->post_data_len = post_data_len;
304     ret->headers = NULL;
305
306     if(post_data) {
307         ret->post_data = GlobalAlloc(0, post_data_len);
308         memcpy(ret->post_data, post_data, post_data_len);
309     }
310
311     if(headers) {
312         int size = (strlenW(headers)+1)*sizeof(WCHAR);
313         ret->headers = shdocvw_alloc(size);
314         memcpy(ret->headers, headers, size);
315     }
316
317     return BINDSC(ret);
318 }
319
320 static void on_before_navigate2(DocHost *This, LPWSTR url, PBYTE post_data, ULONG post_data_len,
321                                 LPWSTR headers, VARIANT_BOOL *cancel)
322 {
323     VARIANT var_url, var_flags, var_frame_name, var_post_data, var_post_data2, var_headers;
324     DISPPARAMS dispparams;
325     VARIANTARG params[7];
326
327     dispparams.cArgs = 7;
328     dispparams.cNamedArgs = 0;
329     dispparams.rgdispidNamedArgs = NULL;
330     dispparams.rgvarg = params;
331
332     V_VT(params) = VT_BOOL|VT_BYREF;
333     V_BOOLREF(params) = cancel;
334
335     V_VT(params+1) = (VT_BYREF|VT_VARIANT);
336     V_VARIANTREF(params+1) = &var_headers;
337     V_VT(&var_headers) = VT_BSTR;
338     V_BSTR(&var_headers) = headers;
339
340     V_VT(params+2) = (VT_BYREF|VT_VARIANT);
341     V_VARIANTREF(params+2) = &var_post_data2;
342     V_VT(&var_post_data2) = (VT_BYREF|VT_VARIANT);
343     V_VARIANTREF(&var_post_data2) = &var_post_data;
344     VariantInit(&var_post_data);
345
346     if(post_data_len) {
347         SAFEARRAYBOUND bound = {post_data_len, 0};
348         void *data;
349
350         V_VT(&var_post_data) = VT_UI1|VT_ARRAY;
351         V_ARRAY(&var_post_data) = SafeArrayCreate(VT_UI1, 1, &bound);
352
353         SafeArrayAccessData(V_ARRAY(&var_post_data), &data);
354         memcpy(data, post_data, post_data_len);
355         SafeArrayUnaccessData(V_ARRAY(&var_post_data));
356     }
357
358     V_VT(params+3) = (VT_BYREF|VT_VARIANT);
359     V_VARIANTREF(params+3) = &var_frame_name;
360     V_VT(&var_frame_name) = VT_BSTR;
361     V_BSTR(&var_frame_name) = NULL;
362
363     V_VT(params+4) = (VT_BYREF|VT_VARIANT);
364     V_VARIANTREF(params+4) = &var_flags;
365     V_VT(&var_flags) = VT_I4;
366     V_I4(&var_flags) = 0;
367
368     V_VT(params+5) = (VT_BYREF|VT_VARIANT);
369     V_VARIANTREF(params+5) = &var_url;
370     V_VT(&var_url) = VT_BSTR;
371     V_BSTR(&var_url) = SysAllocString(url);
372
373     V_VT(params+6) = (VT_DISPATCH);
374     V_DISPATCH(params+6) = This->disp;
375
376     call_sink(This->cps.wbe2, DISPID_BEFORENAVIGATE2, &dispparams);
377
378     SysFreeString(V_BSTR(&var_url));
379     if(post_data_len)
380         SafeArrayDestroy(V_ARRAY(&var_post_data));
381 }
382
383 static BOOL try_application_url(LPCWSTR url)
384 {
385     SHELLEXECUTEINFOW exec_info;
386     WCHAR app[64];
387     HKEY hkey;
388     DWORD res, type;
389     HRESULT hres;
390
391     static const WCHAR wszURLProtocol[] = {'U','R','L',' ','P','r','o','t','o','c','o','l',0};
392
393     hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, app, sizeof(app)/sizeof(WCHAR), NULL, 0);
394     if(FAILED(hres))
395         return FALSE;
396
397     res = RegOpenKeyW(HKEY_CLASSES_ROOT, app, &hkey);
398     if(res != ERROR_SUCCESS)
399         return FALSE;
400
401     res = RegQueryValueExW(hkey, wszURLProtocol, NULL, &type, NULL, NULL);
402     RegCloseKey(hkey);
403     if(res != ERROR_SUCCESS || type != REG_SZ)
404         return FALSE;
405
406     TRACE("openning application %s\n", debugstr_w(app));
407  
408     memset(&exec_info, 0, sizeof(exec_info));
409     exec_info.cbSize = sizeof(exec_info);
410     exec_info.lpFile = url;
411     exec_info.nShow = SW_SHOW;
412
413     return ShellExecuteExW(&exec_info);
414 }
415
416 static HRESULT navigate(DocHost *This, IMoniker *mon, IBindCtx *bindctx)
417 {
418     IOleObject *oleobj;
419     IPersistMoniker *persist;
420     VARIANT_BOOL cancel = VARIANT_FALSE;
421     HRESULT hres;
422
423     if(cancel) {
424         FIXME("Cancel\n");
425         return S_OK;
426     }
427
428     IBindCtx_RegisterObjectParam(bindctx, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM,
429                                  (IUnknown*)CLIENTSITE(This));
430
431     /*
432      * FIXME:
433      * We should use URLMoniker's BindToObject instead creating HTMLDocument here.
434      * This should be fixed when mshtml.dll and urlmon.dll will be good enough.
435      */
436
437     if(This->document)
438         deactivate_document(This);
439
440     hres = CoCreateInstance(&CLSID_HTMLDocument, NULL,
441                             CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
442                             &IID_IUnknown, (void**)&This->document);
443
444     if(FAILED(hres)) {
445         ERR("Could not create HTMLDocument: %08x\n", hres);
446         return hres;
447     }
448
449     hres = IUnknown_QueryInterface(This->document, &IID_IPersistMoniker, (void**)&persist);
450     if(FAILED(hres))
451         return hres;
452
453     if(This->frame)
454         IOleInPlaceFrame_EnableModeless(This->frame, FALSE); /* FIXME */
455
456     hres = IPersistMoniker_Load(persist, FALSE, mon, bindctx, 0);
457     IPersistMoniker_Release(persist);
458
459     if(This->frame) {
460         static const WCHAR empty[] = {0};
461
462         IOleInPlaceFrame_SetStatusText(This->frame, empty); /* FIXME */
463         IOleInPlaceFrame_EnableModeless(This->frame, TRUE); /* FIXME */
464     }
465
466     if(FAILED(hres)) {
467         WARN("Load failed: %08x\n", hres);
468         return hres;
469     }
470
471     hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&oleobj);
472     if(FAILED(hres))
473         return hres;
474
475     hres = IOleObject_SetClientSite(oleobj, CLIENTSITE(This));
476     IOleObject_Release(oleobj);
477
478     PostMessageW(This->hwnd, WB_WM_NAVIGATE2, 0, 0);
479
480     return hres;
481
482 }
483
484 static HRESULT bind_url_to_object(DocHost *This, LPCWSTR url, PBYTE post_data, ULONG post_data_len,
485                      LPWSTR headers)
486 {
487     IBindStatusCallback *callback;
488     IMoniker *mon;
489     IBindCtx *bindctx;
490     VARIANT_BOOL cancel = VARIANT_FALSE;
491     HRESULT hres;
492
493     if(!This->hwnd)
494         create_doc_view_hwnd(This);
495
496     hres = CreateURLMoniker(NULL, url, &mon);
497     if(FAILED(hres)) {
498         WARN("CreateURLMoniker failed: %08x\n", hres);
499         return hres;
500     }
501
502     IMoniker_GetDisplayName(mon, NULL, NULL, &This->url);
503     TRACE("navigating to %s\n", debugstr_w(This->url));
504
505     callback = create_callback(This, post_data, post_data_len, (LPWSTR)headers, &cancel);
506     CreateAsyncBindCtx(0, callback, 0, &bindctx);
507     IBindStatusCallback_Release(callback);
508
509     hres = navigate(This, mon, bindctx);
510
511     IBindCtx_Release(bindctx);
512     IMoniker_Release(mon);
513
514     return hres;
515 }
516
517 HRESULT navigate_url(DocHost *This, BSTR url, VARIANT *Flags, VARIANT *TargetFrameName,
518         VARIANT *PostData, VARIANT *Headers)
519 {
520     PBYTE post_data = NULL;
521     ULONG post_data_len = 0;
522     LPWSTR headers = NULL;
523     HRESULT hres;
524
525     TRACE("navigating to %s\n", debugstr_w(url));
526
527     if((Flags && V_VT(Flags) != VT_EMPTY) 
528        || (TargetFrameName && V_VT(TargetFrameName) != VT_EMPTY))
529         FIXME("Unsupported arguments\n");
530
531     if(PostData) {
532         TRACE("PostData vt=%d\n", V_VT(PostData));
533
534         if(V_VT(PostData) == (VT_ARRAY | VT_UI1)) {
535             SafeArrayAccessData(V_ARRAY(PostData), (void**)&post_data);
536             post_data_len = V_ARRAY(PostData)->rgsabound[0].cElements;
537         }
538     }
539
540     if(Headers && V_VT(Headers) != VT_EMPTY && V_VT(Headers) != VT_ERROR) {
541         if(V_VT(Headers) != VT_BSTR)
542             return E_INVALIDARG;
543
544         headers = V_BSTR(Headers);
545         TRACE("Headers: %s\n", debugstr_w(headers));
546     }
547
548     hres = bind_url_to_object(This, url, post_data, post_data_len, headers);
549
550     if(post_data)
551         SafeArrayUnaccessData(V_ARRAY(PostData));
552
553     return hres;
554 }
555
556 static HRESULT navigate_hlink(DocHost *This, IMoniker *mon, IBindCtx *bindctx,
557                               IBindStatusCallback *callback)
558 {
559     IHttpNegotiate *http_negotiate;
560     LPWSTR url = NULL;
561     PBYTE post_data = NULL;
562     ULONG post_data_len = 0;
563     LPWSTR headers = NULL;
564     VARIANT_BOOL cancel = VARIANT_FALSE;
565     BINDINFO bindinfo;
566     DWORD bindf = 0;
567     HRESULT hres;
568
569     IMoniker_GetDisplayName(mon, NULL, NULL, &url);
570     TRACE("navigating to %s\n", debugstr_w(url));
571
572     hres = IBindStatusCallback_QueryInterface(callback, &IID_IHttpNegotiate,
573                                               (void**)&http_negotiate);
574     if(SUCCEEDED(hres)) {
575         static const WCHAR null_string[] = {0};
576
577         IHttpNegotiate_BeginningTransaction(http_negotiate, null_string, null_string, 0,
578                                             &headers);
579         IHttpNegotiate_Release(http_negotiate);
580     }
581
582     memset(&bindinfo, 0, sizeof(bindinfo));
583     bindinfo.cbSize = sizeof(bindinfo);
584
585     hres = IBindStatusCallback_GetBindInfo(callback, &bindf, &bindinfo);
586     dump_BINDINFO(&bindinfo);
587     if(bindinfo.dwBindVerb == BINDVERB_POST) {
588         post_data_len = bindinfo.cbstgmedData;
589         if(post_data_len)
590             post_data = bindinfo.stgmedData.u.hGlobal;
591     }
592
593     on_before_navigate2(This, url, post_data, post_data_len, headers, &cancel);
594
595     CoTaskMemFree(headers);
596     ReleaseBindInfo(&bindinfo);
597
598     if(cancel) {
599         FIXME("navigation canceled\n");
600         CoTaskMemFree(url);
601         return S_OK;
602     }
603
604     /* FIXME: We should do it after BindToObject call */
605     if(try_application_url(url))
606         return S_OK;
607
608     This->url = url;
609
610     return navigate(This, mon, bindctx);
611 }
612
613 #define HLINKFRAME_THIS(iface) DEFINE_THIS(WebBrowser, HlinkFrame, iface)
614
615 static HRESULT WINAPI HlinkFrame_QueryInterface(IHlinkFrame *iface, REFIID riid, void **ppv)
616 {
617     WebBrowser *This = HLINKFRAME_THIS(iface);
618     return IWebBrowser2_QueryInterface(WEBBROWSER2(This), riid, ppv);
619 }
620
621 static ULONG WINAPI HlinkFrame_AddRef(IHlinkFrame *iface)
622 {
623     WebBrowser *This = HLINKFRAME_THIS(iface);
624     return IWebBrowser2_AddRef(WEBBROWSER2(This));
625 }
626
627 static ULONG WINAPI HlinkFrame_Release(IHlinkFrame *iface)
628 {
629     WebBrowser *This = HLINKFRAME_THIS(iface);
630     return IWebBrowser2_Release(WEBBROWSER2(This));
631 }
632
633 static HRESULT WINAPI HlinkFrame_SetBrowseContext(IHlinkFrame *iface,
634                                                   IHlinkBrowseContext *pihlbc)
635 {
636     WebBrowser *This = HLINKFRAME_THIS(iface);
637     FIXME("(%p)->(%p)\n", This, pihlbc);
638     return E_NOTIMPL;
639 }
640
641 static HRESULT WINAPI HlinkFrame_GetBrowseContext(IHlinkFrame *iface,
642                                                   IHlinkBrowseContext **ppihlbc)
643 {
644     WebBrowser *This = HLINKFRAME_THIS(iface);
645     FIXME("(%p)->(%p)\n", This, ppihlbc);
646     return E_NOTIMPL;
647 }
648
649 static HRESULT WINAPI HlinkFrame_Navigate(IHlinkFrame *iface, DWORD grfHLNF, LPBC pbc,
650                                           IBindStatusCallback *pibsc, IHlink *pihlNavigate)
651 {
652     WebBrowser *This = HLINKFRAME_THIS(iface);
653     IMoniker *mon;
654     LPWSTR location = NULL;
655
656     TRACE("(%p)->(%08x %p %p %p)\n", This, grfHLNF, pbc, pibsc, pihlNavigate);
657
658     if(grfHLNF)
659         FIXME("unsupported grfHLNF=%08x\n", grfHLNF);
660
661     /* Windows calls GetTargetFrameName here. */
662
663     IHlink_GetMonikerReference(pihlNavigate, 1, &mon, &location);
664
665     if(location) {
666         FIXME("location = %s\n", debugstr_w(location));
667         CoTaskMemFree(location);
668     }
669
670     /* Windows calls GetHlinkSite here */
671
672     if(grfHLNF & HLNF_OPENINNEWWINDOW) {
673         FIXME("Not supported HLNF_OPENINNEWWINDOW\n");
674         return E_NOTIMPL;
675     }
676
677     return navigate_hlink(&This->doc_host, mon, pbc, pibsc);
678 }
679
680 static HRESULT WINAPI HlinkFrame_OnNavigate(IHlinkFrame *iface, DWORD grfHLNF,
681         IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName, DWORD dwreserved)
682 {
683     WebBrowser *This = HLINKFRAME_THIS(iface);
684     FIXME("(%p)->(%08x %p %s %s %d)\n", This, grfHLNF, pimkTarget, debugstr_w(pwzLocation),
685           debugstr_w(pwzFriendlyName), dwreserved);
686     return E_NOTIMPL;
687 }
688
689 static HRESULT WINAPI HlinkFrame_UpdateHlink(IHlinkFrame *iface, ULONG uHLID,
690         IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName)
691 {
692     WebBrowser *This = HLINKFRAME_THIS(iface);
693     FIXME("(%p)->(%u %p %s %s)\n", This, uHLID, pimkTarget, debugstr_w(pwzLocation),
694           debugstr_w(pwzFriendlyName));
695     return E_NOTIMPL;
696 }
697
698 #undef HLINKFRAME_THIS
699
700 static const IHlinkFrameVtbl HlinkFrameVtbl = {
701     HlinkFrame_QueryInterface,
702     HlinkFrame_AddRef,
703     HlinkFrame_Release,
704     HlinkFrame_SetBrowseContext,
705     HlinkFrame_GetBrowseContext,
706     HlinkFrame_Navigate,
707     HlinkFrame_OnNavigate,
708     HlinkFrame_UpdateHlink
709 };
710
711 void WebBrowser_HlinkFrame_Init(WebBrowser *This)
712 {
713     This->lpHlinkFrameVtbl = &HlinkFrameVtbl;
714 }