gdi32: Glyph advances should be measured for unrotated characters.
[wine/hacks.git] / dlls / shdocvw / navigate.c
blob7ca0b0f56b357e6f3efabba53ed661b44de93ef5
1 /*
2 * Copyright 2006-2007 Jacek Caban for CodeWeavers
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.
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.
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
19 #define NONAMELESSUNION
20 #define NONAMELESSSTRUCT
22 #include "wine/debug.h"
24 #include "shdocvw.h"
25 #include "mshtml.h"
26 #include "exdispid.h"
27 #include "shellapi.h"
28 #include "winreg.h"
29 #include "shlwapi.h"
30 #include "wininet.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
34 static const WCHAR emptyW[] = {0};
36 typedef struct {
37 const IBindStatusCallbackVtbl *lpBindStatusCallbackVtbl;
38 const IHttpNegotiateVtbl *lpHttpNegotiateVtbl;
40 LONG ref;
42 DocHost *doc_host;
44 LPWSTR url;
45 HGLOBAL post_data;
46 BSTR headers;
47 ULONG post_data_len;
48 } BindStatusCallback;
50 #define BINDSC(x) ((IBindStatusCallback*) &(x)->lpBindStatusCallbackVtbl)
51 #define HTTPNEG(x) ((IHttpNegotiate*) &(x)->lpHttpNegotiateVtbl)
53 static void dump_BINDINFO(BINDINFO *bi)
55 static const char * const BINDINFOF_str[] = {
56 "#0",
57 "BINDINFOF_URLENCODESTGMEDDATA",
58 "BINDINFOF_URLENCODEDEXTRAINFO"
61 static const char * const BINDVERB_str[] = {
62 "BINDVERB_GET",
63 "BINDVERB_POST",
64 "BINDVERB_PUT",
65 "BINDVERB_CUSTOM"
68 TRACE("\n"
69 "BINDINFO = {\n"
70 " %d, %s,\n"
71 " {%d, %p, %p},\n"
72 " %s,\n"
73 " %s,\n"
74 " %s,\n"
75 " %d, %08x, %d, %d\n"
76 " {%d %p %x},\n"
77 " %s\n"
78 " %p, %d\n"
79 "}\n",
81 bi->cbSize, debugstr_w(bi->szExtraInfo),
82 bi->stgmedData.tymed, bi->stgmedData.u.hGlobal, bi->stgmedData.pUnkForRelease,
83 bi->grfBindInfoF > BINDINFOF_URLENCODEDEXTRAINFO
84 ? "unknown" : BINDINFOF_str[bi->grfBindInfoF],
85 bi->dwBindVerb > BINDVERB_CUSTOM
86 ? "unknown" : BINDVERB_str[bi->dwBindVerb],
87 debugstr_w(bi->szCustomVerb),
88 bi->cbstgmedData, bi->dwOptions, bi->dwOptionsFlags, bi->dwCodePage,
89 bi->securityAttributes.nLength,
90 bi->securityAttributes.lpSecurityDescriptor,
91 bi->securityAttributes.bInheritHandle,
92 debugstr_guid(&bi->iid),
93 bi->pUnk, bi->dwReserved
97 static void set_status_text(BindStatusCallback *This, LPCWSTR str)
99 VARIANTARG arg;
100 DISPPARAMS dispparams = {&arg, NULL, 1, 0};
102 if(!This->doc_host)
103 return;
105 V_VT(&arg) = VT_BSTR;
106 V_BSTR(&arg) = str ? SysAllocString(str) : NULL;
107 call_sink(This->doc_host->cps.wbe2, DISPID_STATUSTEXTCHANGE, &dispparams);
108 VariantClear(&arg);
110 if(This->doc_host->frame)
111 IOleInPlaceFrame_SetStatusText(This->doc_host->frame, str);
114 #define BINDSC_THIS(iface) DEFINE_THIS(BindStatusCallback, BindStatusCallback, iface)
116 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallback *iface,
117 REFIID riid, void **ppv)
119 BindStatusCallback *This = BINDSC_THIS(iface);
121 *ppv = NULL;
123 if(IsEqualGUID(&IID_IUnknown, riid)) {
124 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
125 *ppv = BINDSC(This);
126 }else if(IsEqualGUID(&IID_IBindStatusCallback, riid)) {
127 TRACE("(%p)->(IID_IBindStatusCallback %p)\n", This, ppv);
128 *ppv = BINDSC(This);
129 }else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) {
130 TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This, ppv);
131 *ppv = HTTPNEG(This);
134 if(*ppv) {
135 IBindStatusCallback_AddRef(BINDSC(This));
136 return S_OK;
139 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
140 return E_NOINTERFACE;
143 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallback *iface)
145 BindStatusCallback *This = BINDSC_THIS(iface);
146 LONG ref = InterlockedIncrement(&This->ref);
148 TRACE("(%p) ref=%d\n", This, ref);
150 return ref;
153 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallback *iface)
155 BindStatusCallback *This = BINDSC_THIS(iface);
156 LONG ref = InterlockedDecrement(&This->ref);
158 TRACE("(%p) ref=%d\n", This, ref);
160 if(!ref) {
161 if(This->doc_host)
162 IOleClientSite_Release(CLIENTSITE(This->doc_host));
163 if(This->post_data)
164 GlobalFree(This->post_data);
165 if(This->headers)
166 SysFreeString(This->headers);
167 heap_free(This->url);
168 heap_free(This);
171 return ref;
174 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallback *iface,
175 DWORD dwReserved, IBinding *pbind)
177 BindStatusCallback *This = BINDSC_THIS(iface);
179 TRACE("(%p)->(%d %p)\n", This, dwReserved, pbind);
181 return S_OK;
184 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface,
185 LONG *pnPriority)
187 BindStatusCallback *This = BINDSC_THIS(iface);
188 FIXME("(%p)->(%p)\n", This, pnPriority);
189 return E_NOTIMPL;
192 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface,
193 DWORD reserved)
195 BindStatusCallback *This = BINDSC_THIS(iface);
196 FIXME("(%p)->(%d)\n", This, reserved);
197 return E_NOTIMPL;
200 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallback *iface,
201 ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
203 BindStatusCallback *This = BINDSC_THIS(iface);
205 TRACE("(%p)->(%d %d %d %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
206 debugstr_w(szStatusText));
208 switch(ulStatusCode) {
209 case BINDSTATUS_BEGINDOWNLOADDATA:
210 set_status_text(This, szStatusText); /* FIXME: "Start downloading from site: %s" */
211 return S_OK;
212 case BINDSTATUS_ENDDOWNLOADDATA:
213 set_status_text(This, szStatusText); /* FIXME: "Downloading from site: %s" */
214 return S_OK;
215 case BINDSTATUS_CLASSIDAVAILABLE:
216 case BINDSTATUS_MIMETYPEAVAILABLE:
217 case BINDSTATUS_BEGINSYNCOPERATION:
218 case BINDSTATUS_ENDSYNCOPERATION:
219 return S_OK;
220 default:
221 FIXME("status code %u\n", ulStatusCode);
224 return E_NOTIMPL;
227 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
228 HRESULT hresult, LPCWSTR szError)
230 BindStatusCallback *This = BINDSC_THIS(iface);
232 TRACE("(%p)->(%08x %s)\n", This, hresult, debugstr_w(szError));
234 set_status_text(This, emptyW);
236 if(This->doc_host) {
237 IOleClientSite_Release(CLIENTSITE(This->doc_host));
238 This->doc_host = NULL;
241 return S_OK;
244 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
245 DWORD *grfBINDF, BINDINFO *pbindinfo)
247 BindStatusCallback *This = BINDSC_THIS(iface);
249 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
251 *grfBINDF = BINDF_ASYNCHRONOUS;
253 if(This->post_data) {
254 pbindinfo->dwBindVerb = BINDVERB_POST;
256 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
257 pbindinfo->stgmedData.u.hGlobal = This->post_data;
258 pbindinfo->cbstgmedData = This->post_data_len;
259 pbindinfo->stgmedData.pUnkForRelease = (IUnknown*)BINDSC(This);
260 IBindStatusCallback_AddRef(BINDSC(This));
263 return S_OK;
266 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
267 DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
269 BindStatusCallback *This = BINDSC_THIS(iface);
270 FIXME("(%p)->(%08x %d %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed);
271 return E_NOTIMPL;
274 static void object_available_proc(DocHost *This, task_header_t *task)
276 object_available(This);
279 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
280 REFIID riid, IUnknown *punk)
282 BindStatusCallback *This = BINDSC_THIS(iface);
283 task_header_t *task;
284 IOleObject *oleobj;
285 HRESULT hres;
287 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), punk);
289 IUnknown_AddRef(punk);
290 This->doc_host->document = punk;
292 hres = IUnknown_QueryInterface(punk, &IID_IOleObject, (void**)&oleobj);
293 if(SUCCEEDED(hres)) {
294 CLSID clsid;
296 hres = IOleObject_GetUserClassID(oleobj, &clsid);
297 if(SUCCEEDED(hres))
298 TRACE("Got clsid %s\n",
299 IsEqualGUID(&clsid, &CLSID_HTMLDocument) ? "CLSID_HTMLDocument" : debugstr_guid(&clsid));
301 hres = IOleObject_SetClientSite(oleobj, CLIENTSITE(This->doc_host));
302 if(FAILED(hres))
303 FIXME("SetClientSite failed: %08x\n", hres);
305 IOleObject_Release(oleobj);
306 }else {
307 FIXME("Could not get IOleObject iface: %08x\n", hres);
310 /* FIXME: Call SetAdvise */
311 /* FIXME: Call Invoke(DISPID_READYSTATE) */
313 task = heap_alloc(sizeof(*task));
314 push_dochost_task(This->doc_host, task, object_available_proc, FALSE);
316 return S_OK;
319 #undef BSC_THIS
321 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
322 BindStatusCallback_QueryInterface,
323 BindStatusCallback_AddRef,
324 BindStatusCallback_Release,
325 BindStatusCallback_OnStartBinding,
326 BindStatusCallback_GetPriority,
327 BindStatusCallback_OnLowResource,
328 BindStatusCallback_OnProgress,
329 BindStatusCallback_OnStopBinding,
330 BindStatusCallback_GetBindInfo,
331 BindStatusCallback_OnDataAvailable,
332 BindStatusCallback_OnObjectAvailable
335 #define HTTPNEG_THIS(iface) DEFINE_THIS(BindStatusCallback, HttpNegotiate, iface)
337 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate *iface,
338 REFIID riid, void **ppv)
340 BindStatusCallback *This = HTTPNEG_THIS(iface);
341 return IBindStatusCallback_QueryInterface(BINDSC(This), riid, ppv);
344 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate *iface)
346 BindStatusCallback *This = HTTPNEG_THIS(iface);
347 return IBindStatusCallback_AddRef(BINDSC(This));
350 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate *iface)
352 BindStatusCallback *This = HTTPNEG_THIS(iface);
353 return IBindStatusCallback_Release(BINDSC(This));
356 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate *iface,
357 LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
359 BindStatusCallback *This = HTTPNEG_THIS(iface);
361 FIXME("(%p)->(%s %s %d %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders),
362 dwReserved, pszAdditionalHeaders);
364 if(This->headers) {
365 int size = (strlenW(This->headers)+1)*sizeof(WCHAR);
366 *pszAdditionalHeaders = CoTaskMemAlloc(size);
367 memcpy(*pszAdditionalHeaders, This->headers, size);
370 return S_OK;
373 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate *iface,
374 DWORD dwResponseCode, LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders,
375 LPWSTR *pszAdditionalRequestHeaders)
377 BindStatusCallback *This = HTTPNEG_THIS(iface);
378 FIXME("(%p)->(%d %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
379 debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
380 return E_NOTIMPL;
383 #undef HTTPNEG_THIS
385 static const IHttpNegotiateVtbl HttpNegotiateVtbl = {
386 HttpNegotiate_QueryInterface,
387 HttpNegotiate_AddRef,
388 HttpNegotiate_Release,
389 HttpNegotiate_BeginningTransaction,
390 HttpNegotiate_OnResponse
393 static BindStatusCallback *create_callback(DocHost *doc_host, LPCWSTR url, PBYTE post_data,
394 ULONG post_data_len, LPCWSTR headers)
396 BindStatusCallback *ret = heap_alloc(sizeof(BindStatusCallback));
398 ret->lpBindStatusCallbackVtbl = &BindStatusCallbackVtbl;
399 ret->lpHttpNegotiateVtbl = &HttpNegotiateVtbl;
401 ret->ref = 1;
402 ret->url = heap_strdupW(url);
403 ret->post_data = NULL;
404 ret->post_data_len = post_data_len;
405 ret->headers = headers ? SysAllocString(headers) : NULL;
407 ret->doc_host = doc_host;
408 IOleClientSite_AddRef(CLIENTSITE(doc_host));
410 if(post_data) {
411 ret->post_data = GlobalAlloc(0, post_data_len);
412 memcpy(ret->post_data, post_data, post_data_len);
415 return ret;
418 static void on_before_navigate2(DocHost *This, LPCWSTR url, const BYTE *post_data,
419 ULONG post_data_len, LPWSTR headers, VARIANT_BOOL *cancel)
421 VARIANT var_url, var_flags, var_frame_name, var_post_data, var_post_data2, var_headers;
422 DISPPARAMS dispparams;
423 VARIANTARG params[7];
425 dispparams.cArgs = 7;
426 dispparams.cNamedArgs = 0;
427 dispparams.rgdispidNamedArgs = NULL;
428 dispparams.rgvarg = params;
430 This->busy = VARIANT_TRUE;
432 V_VT(params) = VT_BOOL|VT_BYREF;
433 V_BOOLREF(params) = cancel;
435 V_VT(params+1) = (VT_BYREF|VT_VARIANT);
436 V_VARIANTREF(params+1) = &var_headers;
437 V_VT(&var_headers) = VT_BSTR;
438 V_BSTR(&var_headers) = headers;
440 V_VT(params+2) = (VT_BYREF|VT_VARIANT);
441 V_VARIANTREF(params+2) = &var_post_data2;
442 V_VT(&var_post_data2) = (VT_BYREF|VT_VARIANT);
443 V_VARIANTREF(&var_post_data2) = &var_post_data;
444 VariantInit(&var_post_data);
446 if(post_data_len) {
447 SAFEARRAYBOUND bound = {post_data_len, 0};
448 void *data;
450 V_VT(&var_post_data) = VT_UI1|VT_ARRAY;
451 V_ARRAY(&var_post_data) = SafeArrayCreate(VT_UI1, 1, &bound);
453 SafeArrayAccessData(V_ARRAY(&var_post_data), &data);
454 memcpy(data, post_data, post_data_len);
455 SafeArrayUnaccessData(V_ARRAY(&var_post_data));
458 V_VT(params+3) = (VT_BYREF|VT_VARIANT);
459 V_VARIANTREF(params+3) = &var_frame_name;
460 V_VT(&var_frame_name) = VT_BSTR;
461 V_BSTR(&var_frame_name) = NULL;
463 V_VT(params+4) = (VT_BYREF|VT_VARIANT);
464 V_VARIANTREF(params+4) = &var_flags;
465 V_VT(&var_flags) = VT_I4;
466 V_I4(&var_flags) = 0;
468 V_VT(params+5) = (VT_BYREF|VT_VARIANT);
469 V_VARIANTREF(params+5) = &var_url;
470 V_VT(&var_url) = VT_BSTR;
471 V_BSTR(&var_url) = SysAllocString(url);
473 V_VT(params+6) = (VT_DISPATCH);
474 V_DISPATCH(params+6) = This->disp;
476 call_sink(This->cps.wbe2, DISPID_BEFORENAVIGATE2, &dispparams);
478 SysFreeString(V_BSTR(&var_url));
479 if(post_data_len)
480 SafeArrayDestroy(V_ARRAY(&var_post_data));
483 /* FIXME: urlmon should handle it */
484 static BOOL try_application_url(LPCWSTR url)
486 SHELLEXECUTEINFOW exec_info;
487 WCHAR app[64];
488 HKEY hkey;
489 DWORD res, type;
490 HRESULT hres;
492 static const WCHAR wszURLProtocol[] = {'U','R','L',' ','P','r','o','t','o','c','o','l',0};
494 hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, app, sizeof(app)/sizeof(WCHAR), NULL, 0);
495 if(FAILED(hres))
496 return FALSE;
498 res = RegOpenKeyW(HKEY_CLASSES_ROOT, app, &hkey);
499 if(res != ERROR_SUCCESS)
500 return FALSE;
502 res = RegQueryValueExW(hkey, wszURLProtocol, NULL, &type, NULL, NULL);
503 RegCloseKey(hkey);
504 if(res != ERROR_SUCCESS || type != REG_SZ)
505 return FALSE;
507 TRACE("openning application %s\n", debugstr_w(app));
509 memset(&exec_info, 0, sizeof(exec_info));
510 exec_info.cbSize = sizeof(exec_info);
511 exec_info.lpFile = url;
512 exec_info.nShow = SW_SHOW;
514 return ShellExecuteExW(&exec_info);
517 static HRESULT http_load_hack(DocHost *This, IMoniker *mon, IBindStatusCallback *callback, IBindCtx *bindctx)
519 IPersistMoniker *persist;
520 IUnknown *doc;
521 HRESULT hres;
524 * FIXME:
525 * We should use URLMoniker's BindToObject instead creating HTMLDocument here.
526 * This should be fixed when mshtml.dll and urlmon.dll will be good enough.
529 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL,
530 CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
531 &IID_IUnknown, (void**)&doc);
533 if(FAILED(hres)) {
534 ERR("Could not create HTMLDocument: %08x\n", hres);
535 return hres;
538 hres = IUnknown_QueryInterface(doc, &IID_IPersistMoniker, (void**)&persist);
539 if(FAILED(hres)) {
540 IUnknown_Release(doc);
541 return hres;
544 hres = IPersistMoniker_Load(persist, FALSE, mon, bindctx, 0);
545 IPersistMoniker_Release(persist);
547 if(SUCCEEDED(hres))
548 hres = IBindStatusCallback_OnObjectAvailable(callback, &IID_IUnknown, doc);
549 else
550 WARN("Load failed: %08x\n", hres);
552 IUnknown_Release(doc);
554 return IBindStatusCallback_OnStopBinding(callback, hres, NULL);
557 static HRESULT create_moniker(LPCWSTR url, IMoniker **mon)
559 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
560 DWORD size;
561 HRESULT hres;
563 if(PathIsURLW(url))
564 return CreateURLMoniker(NULL, url, mon);
566 if(url[1] == ':') {
567 size = sizeof(new_url);
568 hres = UrlCreateFromPathW(url, new_url, &size, 0);
569 if(FAILED(hres)) {
570 WARN("UrlCreateFromPathW failed: %08x\n", hres);
571 return hres;
573 }else {
574 size = sizeof(new_url);
575 hres = UrlApplySchemeW(url, new_url, &size, URL_APPLY_GUESSSCHEME);
576 TRACE("got %s\n", debugstr_w(new_url));
577 if(FAILED(hres)) {
578 WARN("UrlApplyScheme failed: %08x\n", hres);
579 return hres;
583 return CreateURLMoniker(NULL, new_url, mon);
586 static HRESULT bind_to_object(DocHost *This, IMoniker *mon, LPCWSTR url, IBindCtx *bindctx,
587 IBindStatusCallback *callback)
589 WCHAR schema[30];
590 DWORD schema_len;
591 HRESULT hres;
593 static const WCHAR httpW[] = {'h','t','t','p',0};
594 static const WCHAR httpsW[] = {'h','t','t','p','s',0};
595 static const WCHAR ftpW[]= {'f','t','p',0};
597 if(mon) {
598 IMoniker_AddRef(mon);
599 }else {
600 hres = create_moniker(url, &mon);
601 if(FAILED(hres))
602 return hres;
605 CoTaskMemFree(This->url);
606 hres = IMoniker_GetDisplayName(mon, 0, NULL, &This->url);
607 if(FAILED(hres))
608 FIXME("GetDisplayName failed: %08x\n", hres);
610 IBindCtx_RegisterObjectParam(bindctx, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM,
611 (IUnknown*)CLIENTSITE(This));
613 hres = CoInternetParseUrl(This->url, PARSE_SCHEMA, 0, schema, sizeof(schema)/sizeof(schema[0]),
614 &schema_len, 0);
615 if(SUCCEEDED(hres) &&
616 (!strcmpW(schema, httpW) || !strcmpW(schema, httpsW) || !strcmpW(schema, ftpW))) {
617 hres = http_load_hack(This, mon, callback, bindctx);
618 }else {
619 IUnknown *unk = NULL;
621 hres = IMoniker_BindToObject(mon, bindctx, NULL, &IID_IUnknown, (void**)&unk);
622 if(SUCCEEDED(hres)) {
623 hres = S_OK;
624 if(unk)
625 IUnknown_Release(unk);
626 }else if(try_application_url(url)) {
627 hres = S_OK;
628 }else {
629 FIXME("BindToObject failed: %08x\n", hres);
633 IMoniker_Release(mon);
634 return S_OK;
637 static HRESULT navigate_bsc(DocHost *This, BindStatusCallback *bsc, IMoniker *mon)
639 IBindCtx *bindctx;
640 VARIANT_BOOL cancel = VARIANT_FALSE;
641 HRESULT hres;
643 on_before_navigate2(This, bsc->url, bsc->post_data, bsc->post_data_len, bsc->headers, &cancel);
644 if(cancel) {
645 FIXME("Navigation canceled\n");
646 return S_OK;
649 if(This->document)
650 deactivate_document(This);
652 CreateAsyncBindCtx(0, BINDSC(bsc), 0, &bindctx);
654 if(This->frame)
655 IOleInPlaceFrame_EnableModeless(This->frame, FALSE);
657 hres = bind_to_object(This, mon, bsc->url, bindctx, BINDSC(bsc));
659 if(This->frame)
660 IOleInPlaceFrame_EnableModeless(This->frame, TRUE);
662 IBindCtx_Release(bindctx);
664 return hres;
667 typedef struct {
668 task_header_t header;
669 BindStatusCallback *bsc;
670 } task_navigate_bsc_t;
672 static void navigate_bsc_proc(DocHost *This, task_header_t *t)
674 task_navigate_bsc_t *task = (task_navigate_bsc_t*)t;
676 if(!This->hwnd)
677 create_doc_view_hwnd(This);
679 navigate_bsc(This, task->bsc, NULL);
681 IBindStatusCallback_Release(BINDSC(task->bsc));
685 HRESULT navigate_url(DocHost *This, LPCWSTR url, const VARIANT *Flags,
686 const VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers)
688 task_navigate_bsc_t *task;
689 PBYTE post_data = NULL;
690 ULONG post_data_len = 0;
691 LPWSTR headers = NULL;
693 TRACE("navigating to %s\n", debugstr_w(url));
695 if((Flags && V_VT(Flags) != VT_EMPTY)
696 || (TargetFrameName && V_VT(TargetFrameName) != VT_EMPTY))
697 FIXME("Unsupported args (Flags %p:%d; TargetFrameName %p:%d)\n",
698 Flags, Flags ? V_VT(Flags) : -1, TargetFrameName,
699 TargetFrameName ? V_VT(TargetFrameName) : -1);
701 if(PostData) {
702 TRACE("PostData vt=%d\n", V_VT(PostData));
704 if(V_VT(PostData) == (VT_ARRAY | VT_UI1)) {
705 SafeArrayAccessData(V_ARRAY(PostData), (void**)&post_data);
706 post_data_len = V_ARRAY(PostData)->rgsabound[0].cElements;
710 if(Headers && V_VT(Headers) != VT_EMPTY && V_VT(Headers) != VT_ERROR) {
711 if(V_VT(Headers) != VT_BSTR)
712 return E_INVALIDARG;
714 headers = V_BSTR(Headers);
715 TRACE("Headers: %s\n", debugstr_w(headers));
718 task = heap_alloc(sizeof(*task));
719 task->bsc = create_callback(This, url, post_data, post_data_len, headers);
721 if(post_data)
722 SafeArrayUnaccessData(V_ARRAY(PostData));
724 push_dochost_task(This, &task->header, navigate_bsc_proc, This->url == NULL);
726 return S_OK;
729 static HRESULT navigate_hlink(DocHost *This, IMoniker *mon, IBindCtx *bindctx,
730 IBindStatusCallback *callback)
732 IHttpNegotiate *http_negotiate;
733 BindStatusCallback *bsc;
734 PBYTE post_data = NULL;
735 ULONG post_data_len = 0;
736 LPWSTR headers = NULL, url;
737 BINDINFO bindinfo;
738 DWORD bindf = 0;
739 HRESULT hres;
741 hres = IBindStatusCallback_QueryInterface(callback, &IID_IHttpNegotiate,
742 (void**)&http_negotiate);
743 if(SUCCEEDED(hres)) {
744 static const WCHAR null_string[] = {0};
746 IHttpNegotiate_BeginningTransaction(http_negotiate, null_string, null_string, 0,
747 &headers);
748 IHttpNegotiate_Release(http_negotiate);
751 memset(&bindinfo, 0, sizeof(bindinfo));
752 bindinfo.cbSize = sizeof(bindinfo);
754 hres = IBindStatusCallback_GetBindInfo(callback, &bindf, &bindinfo);
755 dump_BINDINFO(&bindinfo);
756 if(bindinfo.dwBindVerb == BINDVERB_POST) {
757 post_data_len = bindinfo.cbstgmedData;
758 if(post_data_len)
759 post_data = bindinfo.stgmedData.u.hGlobal;
762 hres = IMoniker_GetDisplayName(mon, 0, NULL, &url);
763 if(FAILED(hres))
764 FIXME("GetDisplayName failed: %08x\n", hres);
766 bsc = create_callback(This, url, post_data, post_data_len, headers);
767 CoTaskMemFree(url);
769 hres = navigate_bsc(This, bsc, mon);
771 IBindStatusCallback_Release(BINDSC(bsc));
772 CoTaskMemFree(headers);
773 ReleaseBindInfo(&bindinfo);
775 return hres;
778 HRESULT go_home(DocHost *This)
780 static const WCHAR wszAboutBlank[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
782 FIXME("stub\n");
784 return navigate_url(This, wszAboutBlank, NULL, NULL, NULL, NULL);
787 #define HLINKFRAME_THIS(iface) DEFINE_THIS(WebBrowser, HlinkFrame, iface)
789 static HRESULT WINAPI HlinkFrame_QueryInterface(IHlinkFrame *iface, REFIID riid, void **ppv)
791 WebBrowser *This = HLINKFRAME_THIS(iface);
792 return IWebBrowser2_QueryInterface(WEBBROWSER2(This), riid, ppv);
795 static ULONG WINAPI HlinkFrame_AddRef(IHlinkFrame *iface)
797 WebBrowser *This = HLINKFRAME_THIS(iface);
798 return IWebBrowser2_AddRef(WEBBROWSER2(This));
801 static ULONG WINAPI HlinkFrame_Release(IHlinkFrame *iface)
803 WebBrowser *This = HLINKFRAME_THIS(iface);
804 return IWebBrowser2_Release(WEBBROWSER2(This));
807 static HRESULT WINAPI HlinkFrame_SetBrowseContext(IHlinkFrame *iface,
808 IHlinkBrowseContext *pihlbc)
810 WebBrowser *This = HLINKFRAME_THIS(iface);
811 FIXME("(%p)->(%p)\n", This, pihlbc);
812 return E_NOTIMPL;
815 static HRESULT WINAPI HlinkFrame_GetBrowseContext(IHlinkFrame *iface,
816 IHlinkBrowseContext **ppihlbc)
818 WebBrowser *This = HLINKFRAME_THIS(iface);
819 FIXME("(%p)->(%p)\n", This, ppihlbc);
820 return E_NOTIMPL;
823 static HRESULT WINAPI HlinkFrame_Navigate(IHlinkFrame *iface, DWORD grfHLNF, LPBC pbc,
824 IBindStatusCallback *pibsc, IHlink *pihlNavigate)
826 WebBrowser *This = HLINKFRAME_THIS(iface);
827 IMoniker *mon;
828 LPWSTR location = NULL;
830 TRACE("(%p)->(%08x %p %p %p)\n", This, grfHLNF, pbc, pibsc, pihlNavigate);
832 if(grfHLNF)
833 FIXME("unsupported grfHLNF=%08x\n", grfHLNF);
835 /* Windows calls GetTargetFrameName here. */
837 IHlink_GetMonikerReference(pihlNavigate, 1, &mon, &location);
839 if(location) {
840 FIXME("location = %s\n", debugstr_w(location));
841 CoTaskMemFree(location);
844 /* Windows calls GetHlinkSite here */
846 if(grfHLNF & HLNF_OPENINNEWWINDOW) {
847 FIXME("Not supported HLNF_OPENINNEWWINDOW\n");
848 return E_NOTIMPL;
851 return navigate_hlink(&This->doc_host, mon, pbc, pibsc);
854 static HRESULT WINAPI HlinkFrame_OnNavigate(IHlinkFrame *iface, DWORD grfHLNF,
855 IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName, DWORD dwreserved)
857 WebBrowser *This = HLINKFRAME_THIS(iface);
858 FIXME("(%p)->(%08x %p %s %s %d)\n", This, grfHLNF, pimkTarget, debugstr_w(pwzLocation),
859 debugstr_w(pwzFriendlyName), dwreserved);
860 return E_NOTIMPL;
863 static HRESULT WINAPI HlinkFrame_UpdateHlink(IHlinkFrame *iface, ULONG uHLID,
864 IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName)
866 WebBrowser *This = HLINKFRAME_THIS(iface);
867 FIXME("(%p)->(%u %p %s %s)\n", This, uHLID, pimkTarget, debugstr_w(pwzLocation),
868 debugstr_w(pwzFriendlyName));
869 return E_NOTIMPL;
872 #undef HLINKFRAME_THIS
874 static const IHlinkFrameVtbl HlinkFrameVtbl = {
875 HlinkFrame_QueryInterface,
876 HlinkFrame_AddRef,
877 HlinkFrame_Release,
878 HlinkFrame_SetBrowseContext,
879 HlinkFrame_GetBrowseContext,
880 HlinkFrame_Navigate,
881 HlinkFrame_OnNavigate,
882 HlinkFrame_UpdateHlink
885 void WebBrowser_HlinkFrame_Init(WebBrowser *This)
887 This->lpHlinkFrameVtbl = &HlinkFrameVtbl;