Release 1.1.37.
[wine/gsoc-2012-control.git] / dlls / shdocvw / navigate.c
blobec23fcc7b382393568895003e6f4f8208c80ba30
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 "exdispid.h"
26 #include "shellapi.h"
27 #include "winreg.h"
28 #include "shlwapi.h"
29 #include "wininet.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
33 static const WCHAR emptyW[] = {0};
35 typedef struct {
36 const IBindStatusCallbackVtbl *lpBindStatusCallbackVtbl;
37 const IHttpNegotiateVtbl *lpHttpNegotiateVtbl;
39 LONG ref;
41 DocHost *doc_host;
43 LPWSTR url;
44 HGLOBAL post_data;
45 BSTR headers;
46 ULONG post_data_len;
47 } BindStatusCallback;
49 #define BINDSC(x) ((IBindStatusCallback*) &(x)->lpBindStatusCallbackVtbl)
50 #define HTTPNEG(x) ((IHttpNegotiate*) &(x)->lpHttpNegotiateVtbl)
52 static void dump_BINDINFO(BINDINFO *bi)
54 static const char * const BINDINFOF_str[] = {
55 "#0",
56 "BINDINFOF_URLENCODESTGMEDDATA",
57 "BINDINFOF_URLENCODEDEXTRAINFO"
60 static const char * const BINDVERB_str[] = {
61 "BINDVERB_GET",
62 "BINDVERB_POST",
63 "BINDVERB_PUT",
64 "BINDVERB_CUSTOM"
67 TRACE("\n"
68 "BINDINFO = {\n"
69 " %d, %s,\n"
70 " {%d, %p, %p},\n"
71 " %s,\n"
72 " %s,\n"
73 " %s,\n"
74 " %d, %08x, %d, %d\n"
75 " {%d %p %x},\n"
76 " %s\n"
77 " %p, %d\n"
78 "}\n",
80 bi->cbSize, debugstr_w(bi->szExtraInfo),
81 bi->stgmedData.tymed, bi->stgmedData.u.hGlobal, bi->stgmedData.pUnkForRelease,
82 bi->grfBindInfoF > BINDINFOF_URLENCODEDEXTRAINFO
83 ? "unknown" : BINDINFOF_str[bi->grfBindInfoF],
84 bi->dwBindVerb > BINDVERB_CUSTOM
85 ? "unknown" : BINDVERB_str[bi->dwBindVerb],
86 debugstr_w(bi->szCustomVerb),
87 bi->cbstgmedData, bi->dwOptions, bi->dwOptionsFlags, bi->dwCodePage,
88 bi->securityAttributes.nLength,
89 bi->securityAttributes.lpSecurityDescriptor,
90 bi->securityAttributes.bInheritHandle,
91 debugstr_guid(&bi->iid),
92 bi->pUnk, bi->dwReserved
96 static void set_status_text(BindStatusCallback *This, LPCWSTR str)
98 VARIANTARG arg;
99 DISPPARAMS dispparams = {&arg, NULL, 1, 0};
101 if(!This->doc_host)
102 return;
104 V_VT(&arg) = VT_BSTR;
105 V_BSTR(&arg) = str ? SysAllocString(str) : NULL;
106 call_sink(This->doc_host->cps.wbe2, DISPID_STATUSTEXTCHANGE, &dispparams);
107 VariantClear(&arg);
109 if(This->doc_host->frame)
110 IOleInPlaceFrame_SetStatusText(This->doc_host->frame, str);
113 #define BINDSC_THIS(iface) DEFINE_THIS(BindStatusCallback, BindStatusCallback, iface)
115 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallback *iface,
116 REFIID riid, void **ppv)
118 BindStatusCallback *This = BINDSC_THIS(iface);
120 *ppv = NULL;
122 if(IsEqualGUID(&IID_IUnknown, riid)) {
123 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
124 *ppv = BINDSC(This);
125 }else if(IsEqualGUID(&IID_IBindStatusCallback, riid)) {
126 TRACE("(%p)->(IID_IBindStatusCallback %p)\n", This, ppv);
127 *ppv = BINDSC(This);
128 }else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) {
129 TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This, ppv);
130 *ppv = HTTPNEG(This);
133 if(*ppv) {
134 IBindStatusCallback_AddRef(BINDSC(This));
135 return S_OK;
138 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
139 return E_NOINTERFACE;
142 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallback *iface)
144 BindStatusCallback *This = BINDSC_THIS(iface);
145 LONG ref = InterlockedIncrement(&This->ref);
147 TRACE("(%p) ref=%d\n", This, ref);
149 return ref;
152 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallback *iface)
154 BindStatusCallback *This = BINDSC_THIS(iface);
155 LONG ref = InterlockedDecrement(&This->ref);
157 TRACE("(%p) ref=%d\n", This, ref);
159 if(!ref) {
160 if(This->doc_host)
161 IOleClientSite_Release(CLIENTSITE(This->doc_host));
162 if(This->post_data)
163 GlobalFree(This->post_data);
164 SysFreeString(This->headers);
165 heap_free(This->url);
166 heap_free(This);
169 return ref;
172 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallback *iface,
173 DWORD dwReserved, IBinding *pbind)
175 BindStatusCallback *This = BINDSC_THIS(iface);
177 TRACE("(%p)->(%d %p)\n", This, dwReserved, pbind);
179 return S_OK;
182 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface,
183 LONG *pnPriority)
185 BindStatusCallback *This = BINDSC_THIS(iface);
186 FIXME("(%p)->(%p)\n", This, pnPriority);
187 return E_NOTIMPL;
190 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface,
191 DWORD reserved)
193 BindStatusCallback *This = BINDSC_THIS(iface);
194 FIXME("(%p)->(%d)\n", This, reserved);
195 return E_NOTIMPL;
198 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallback *iface,
199 ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
201 BindStatusCallback *This = BINDSC_THIS(iface);
203 TRACE("(%p)->(%d %d %d %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
204 debugstr_w(szStatusText));
206 switch(ulStatusCode) {
207 case BINDSTATUS_BEGINDOWNLOADDATA:
208 set_status_text(This, szStatusText); /* FIXME: "Start downloading from site: %s" */
209 return S_OK;
210 case BINDSTATUS_ENDDOWNLOADDATA:
211 set_status_text(This, szStatusText); /* FIXME: "Downloading from site: %s" */
212 return S_OK;
213 case BINDSTATUS_CLASSIDAVAILABLE:
214 case BINDSTATUS_MIMETYPEAVAILABLE:
215 case BINDSTATUS_BEGINSYNCOPERATION:
216 case BINDSTATUS_ENDSYNCOPERATION:
217 return S_OK;
218 default:
219 FIXME("status code %u\n", ulStatusCode);
222 return S_OK;
225 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
226 HRESULT hresult, LPCWSTR szError)
228 BindStatusCallback *This = BINDSC_THIS(iface);
230 TRACE("(%p)->(%08x %s)\n", This, hresult, debugstr_w(szError));
232 set_status_text(This, emptyW);
234 if(This->doc_host) {
235 IOleClientSite_Release(CLIENTSITE(This->doc_host));
236 This->doc_host = NULL;
239 return S_OK;
242 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
243 DWORD *grfBINDF, BINDINFO *pbindinfo)
245 BindStatusCallback *This = BINDSC_THIS(iface);
247 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
249 *grfBINDF = BINDF_ASYNCHRONOUS;
251 if(This->post_data) {
252 pbindinfo->dwBindVerb = BINDVERB_POST;
254 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
255 pbindinfo->stgmedData.u.hGlobal = This->post_data;
256 pbindinfo->cbstgmedData = This->post_data_len;
257 pbindinfo->stgmedData.pUnkForRelease = (IUnknown*)BINDSC(This);
258 IBindStatusCallback_AddRef(BINDSC(This));
261 return S_OK;
264 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
265 DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
267 BindStatusCallback *This = BINDSC_THIS(iface);
268 FIXME("(%p)->(%08x %d %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed);
269 return E_NOTIMPL;
272 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
273 REFIID riid, IUnknown *punk)
275 BindStatusCallback *This = BINDSC_THIS(iface);
277 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), punk);
279 return dochost_object_available(This->doc_host, punk);
282 #undef BSC_THIS
284 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
285 BindStatusCallback_QueryInterface,
286 BindStatusCallback_AddRef,
287 BindStatusCallback_Release,
288 BindStatusCallback_OnStartBinding,
289 BindStatusCallback_GetPriority,
290 BindStatusCallback_OnLowResource,
291 BindStatusCallback_OnProgress,
292 BindStatusCallback_OnStopBinding,
293 BindStatusCallback_GetBindInfo,
294 BindStatusCallback_OnDataAvailable,
295 BindStatusCallback_OnObjectAvailable
298 #define HTTPNEG_THIS(iface) DEFINE_THIS(BindStatusCallback, HttpNegotiate, iface)
300 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate *iface,
301 REFIID riid, void **ppv)
303 BindStatusCallback *This = HTTPNEG_THIS(iface);
304 return IBindStatusCallback_QueryInterface(BINDSC(This), riid, ppv);
307 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate *iface)
309 BindStatusCallback *This = HTTPNEG_THIS(iface);
310 return IBindStatusCallback_AddRef(BINDSC(This));
313 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate *iface)
315 BindStatusCallback *This = HTTPNEG_THIS(iface);
316 return IBindStatusCallback_Release(BINDSC(This));
319 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate *iface,
320 LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
322 BindStatusCallback *This = HTTPNEG_THIS(iface);
324 TRACE("(%p)->(%s %s %d %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders),
325 dwReserved, pszAdditionalHeaders);
327 if(This->headers) {
328 int size = (strlenW(This->headers)+1)*sizeof(WCHAR);
329 *pszAdditionalHeaders = CoTaskMemAlloc(size);
330 memcpy(*pszAdditionalHeaders, This->headers, size);
333 return S_OK;
336 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate *iface,
337 DWORD dwResponseCode, LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders,
338 LPWSTR *pszAdditionalRequestHeaders)
340 BindStatusCallback *This = HTTPNEG_THIS(iface);
341 TRACE("(%p)->(%d %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
342 debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
343 return S_OK;
346 #undef HTTPNEG_THIS
348 static const IHttpNegotiateVtbl HttpNegotiateVtbl = {
349 HttpNegotiate_QueryInterface,
350 HttpNegotiate_AddRef,
351 HttpNegotiate_Release,
352 HttpNegotiate_BeginningTransaction,
353 HttpNegotiate_OnResponse
356 static BindStatusCallback *create_callback(DocHost *doc_host, LPCWSTR url, PBYTE post_data,
357 ULONG post_data_len, LPCWSTR headers)
359 BindStatusCallback *ret = heap_alloc(sizeof(BindStatusCallback));
361 ret->lpBindStatusCallbackVtbl = &BindStatusCallbackVtbl;
362 ret->lpHttpNegotiateVtbl = &HttpNegotiateVtbl;
364 ret->ref = 1;
365 ret->url = heap_strdupW(url);
366 ret->post_data = NULL;
367 ret->post_data_len = post_data_len;
368 ret->headers = headers ? SysAllocString(headers) : NULL;
370 ret->doc_host = doc_host;
371 IOleClientSite_AddRef(CLIENTSITE(doc_host));
373 if(post_data) {
374 ret->post_data = GlobalAlloc(0, post_data_len);
375 memcpy(ret->post_data, post_data, post_data_len);
378 return ret;
381 static void on_before_navigate2(DocHost *This, LPCWSTR url, const BYTE *post_data,
382 ULONG post_data_len, LPWSTR headers, VARIANT_BOOL *cancel)
384 VARIANT var_url, var_flags, var_frame_name, var_post_data, var_post_data2, var_headers;
385 DISPPARAMS dispparams;
386 VARIANTARG params[7];
388 dispparams.cArgs = 7;
389 dispparams.cNamedArgs = 0;
390 dispparams.rgdispidNamedArgs = NULL;
391 dispparams.rgvarg = params;
393 This->busy = VARIANT_TRUE;
395 V_VT(params) = VT_BOOL|VT_BYREF;
396 V_BOOLREF(params) = cancel;
398 V_VT(params+1) = (VT_BYREF|VT_VARIANT);
399 V_VARIANTREF(params+1) = &var_headers;
400 V_VT(&var_headers) = VT_BSTR;
401 V_BSTR(&var_headers) = headers;
403 V_VT(params+2) = (VT_BYREF|VT_VARIANT);
404 V_VARIANTREF(params+2) = &var_post_data2;
405 V_VT(&var_post_data2) = (VT_BYREF|VT_VARIANT);
406 V_VARIANTREF(&var_post_data2) = &var_post_data;
407 VariantInit(&var_post_data);
409 if(post_data_len) {
410 SAFEARRAYBOUND bound = {post_data_len, 0};
411 void *data;
413 V_VT(&var_post_data) = VT_UI1|VT_ARRAY;
414 V_ARRAY(&var_post_data) = SafeArrayCreate(VT_UI1, 1, &bound);
416 SafeArrayAccessData(V_ARRAY(&var_post_data), &data);
417 memcpy(data, post_data, post_data_len);
418 SafeArrayUnaccessData(V_ARRAY(&var_post_data));
421 V_VT(params+3) = (VT_BYREF|VT_VARIANT);
422 V_VARIANTREF(params+3) = &var_frame_name;
423 V_VT(&var_frame_name) = VT_BSTR;
424 V_BSTR(&var_frame_name) = NULL;
426 V_VT(params+4) = (VT_BYREF|VT_VARIANT);
427 V_VARIANTREF(params+4) = &var_flags;
428 V_VT(&var_flags) = VT_I4;
429 V_I4(&var_flags) = 0;
431 V_VT(params+5) = (VT_BYREF|VT_VARIANT);
432 V_VARIANTREF(params+5) = &var_url;
433 V_VT(&var_url) = VT_BSTR;
434 V_BSTR(&var_url) = SysAllocString(url);
436 V_VT(params+6) = (VT_DISPATCH);
437 V_DISPATCH(params+6) = This->disp;
439 call_sink(This->cps.wbe2, DISPID_BEFORENAVIGATE2, &dispparams);
441 SysFreeString(V_BSTR(&var_url));
442 if(post_data_len)
443 SafeArrayDestroy(V_ARRAY(&var_post_data));
446 /* FIXME: urlmon should handle it */
447 static BOOL try_application_url(LPCWSTR url)
449 SHELLEXECUTEINFOW exec_info;
450 WCHAR app[64];
451 HKEY hkey;
452 DWORD res, type;
453 HRESULT hres;
455 static const WCHAR wszURLProtocol[] = {'U','R','L',' ','P','r','o','t','o','c','o','l',0};
457 hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, app, sizeof(app)/sizeof(WCHAR), NULL, 0);
458 if(FAILED(hres))
459 return FALSE;
461 res = RegOpenKeyW(HKEY_CLASSES_ROOT, app, &hkey);
462 if(res != ERROR_SUCCESS)
463 return FALSE;
465 res = RegQueryValueExW(hkey, wszURLProtocol, NULL, &type, NULL, NULL);
466 RegCloseKey(hkey);
467 if(res != ERROR_SUCCESS || type != REG_SZ)
468 return FALSE;
470 TRACE("openning application %s\n", debugstr_w(app));
472 memset(&exec_info, 0, sizeof(exec_info));
473 exec_info.cbSize = sizeof(exec_info);
474 exec_info.lpFile = url;
475 exec_info.nShow = SW_SHOW;
477 return ShellExecuteExW(&exec_info);
480 static HRESULT create_moniker(LPCWSTR url, IMoniker **mon)
482 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
483 DWORD size;
484 HRESULT hres;
486 if(PathIsURLW(url))
487 return CreateURLMoniker(NULL, url, mon);
489 if(url[1] == ':') {
490 size = sizeof(new_url);
491 hres = UrlCreateFromPathW(url, new_url, &size, 0);
492 if(FAILED(hres)) {
493 WARN("UrlCreateFromPathW failed: %08x\n", hres);
494 return hres;
496 }else {
497 size = sizeof(new_url);
498 hres = UrlApplySchemeW(url, new_url, &size, URL_APPLY_GUESSSCHEME);
499 TRACE("got %s\n", debugstr_w(new_url));
500 if(FAILED(hres)) {
501 WARN("UrlApplyScheme failed: %08x\n", hres);
502 return hres;
506 return CreateURLMoniker(NULL, new_url, mon);
509 static HRESULT bind_to_object(DocHost *This, IMoniker *mon, LPCWSTR url, IBindCtx *bindctx,
510 IBindStatusCallback *callback)
512 IUnknown *unk = NULL;
513 HRESULT hres;
515 if(mon) {
516 IMoniker_AddRef(mon);
517 }else {
518 hres = create_moniker(url, &mon);
519 if(FAILED(hres))
520 return hres;
523 CoTaskMemFree(This->url);
524 hres = IMoniker_GetDisplayName(mon, 0, NULL, &This->url);
525 if(FAILED(hres))
526 FIXME("GetDisplayName failed: %08x\n", hres);
528 IBindCtx_RegisterObjectParam(bindctx, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM,
529 (IUnknown*)CLIENTSITE(This));
531 hres = IMoniker_BindToObject(mon, bindctx, NULL, &IID_IUnknown, (void**)&unk);
532 if(SUCCEEDED(hres)) {
533 hres = S_OK;
534 if(unk)
535 IUnknown_Release(unk);
536 }else if(try_application_url(url)) {
537 hres = S_OK;
538 }else {
539 FIXME("BindToObject failed: %08x\n", hres);
542 IMoniker_Release(mon);
543 return S_OK;
546 static HRESULT navigate_bsc(DocHost *This, BindStatusCallback *bsc, IMoniker *mon)
548 IBindCtx *bindctx;
549 VARIANT_BOOL cancel = VARIANT_FALSE;
550 HRESULT hres;
552 This->ready_state = READYSTATE_LOADING;
554 on_before_navigate2(This, bsc->url, bsc->post_data, bsc->post_data_len, bsc->headers, &cancel);
555 if(cancel) {
556 FIXME("Navigation canceled\n");
557 return S_OK;
560 if(This->document)
561 deactivate_document(This);
563 CreateAsyncBindCtx(0, BINDSC(bsc), 0, &bindctx);
565 if(This->frame)
566 IOleInPlaceFrame_EnableModeless(This->frame, FALSE);
568 hres = bind_to_object(This, mon, bsc->url, bindctx, BINDSC(bsc));
570 if(This->frame)
571 IOleInPlaceFrame_EnableModeless(This->frame, TRUE);
573 IBindCtx_Release(bindctx);
575 return hres;
578 typedef struct {
579 task_header_t header;
580 BindStatusCallback *bsc;
581 } task_navigate_bsc_t;
583 static void navigate_bsc_proc(DocHost *This, task_header_t *t)
585 task_navigate_bsc_t *task = (task_navigate_bsc_t*)t;
587 if(!This->hwnd)
588 create_doc_view_hwnd(This);
590 navigate_bsc(This, task->bsc, NULL);
592 IBindStatusCallback_Release(BINDSC(task->bsc));
596 HRESULT navigate_url(DocHost *This, LPCWSTR url, const VARIANT *Flags,
597 const VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers)
599 task_navigate_bsc_t *task;
600 PBYTE post_data = NULL;
601 ULONG post_data_len = 0;
602 LPWSTR headers = NULL;
604 TRACE("navigating to %s\n", debugstr_w(url));
606 if((Flags && V_VT(Flags) != VT_EMPTY)
607 || (TargetFrameName && V_VT(TargetFrameName) != VT_EMPTY))
608 FIXME("Unsupported args (Flags %p:%d; TargetFrameName %p:%d)\n",
609 Flags, Flags ? V_VT(Flags) : -1, TargetFrameName,
610 TargetFrameName ? V_VT(TargetFrameName) : -1);
612 if(PostData) {
613 TRACE("PostData vt=%d\n", V_VT(PostData));
615 if(V_VT(PostData) == (VT_ARRAY | VT_UI1)) {
616 SafeArrayAccessData(V_ARRAY(PostData), (void**)&post_data);
617 post_data_len = V_ARRAY(PostData)->rgsabound[0].cElements;
621 if(Headers && V_VT(Headers) != VT_EMPTY && V_VT(Headers) != VT_ERROR) {
622 if(V_VT(Headers) != VT_BSTR)
623 return E_INVALIDARG;
625 headers = V_BSTR(Headers);
626 TRACE("Headers: %s\n", debugstr_w(headers));
629 task = heap_alloc(sizeof(*task));
630 task->bsc = create_callback(This, url, post_data, post_data_len, headers);
632 if(post_data)
633 SafeArrayUnaccessData(V_ARRAY(PostData));
635 push_dochost_task(This, &task->header, navigate_bsc_proc, This->url == NULL);
637 return S_OK;
640 static HRESULT navigate_hlink(DocHost *This, IMoniker *mon, IBindCtx *bindctx,
641 IBindStatusCallback *callback)
643 IHttpNegotiate *http_negotiate;
644 BindStatusCallback *bsc;
645 PBYTE post_data = NULL;
646 ULONG post_data_len = 0;
647 LPWSTR headers = NULL, url;
648 BINDINFO bindinfo;
649 DWORD bindf = 0;
650 HRESULT hres;
652 hres = IBindStatusCallback_QueryInterface(callback, &IID_IHttpNegotiate,
653 (void**)&http_negotiate);
654 if(SUCCEEDED(hres)) {
655 static const WCHAR null_string[] = {0};
657 IHttpNegotiate_BeginningTransaction(http_negotiate, null_string, null_string, 0,
658 &headers);
659 IHttpNegotiate_Release(http_negotiate);
662 memset(&bindinfo, 0, sizeof(bindinfo));
663 bindinfo.cbSize = sizeof(bindinfo);
665 hres = IBindStatusCallback_GetBindInfo(callback, &bindf, &bindinfo);
666 dump_BINDINFO(&bindinfo);
667 if(bindinfo.dwBindVerb == BINDVERB_POST) {
668 post_data_len = bindinfo.cbstgmedData;
669 if(post_data_len)
670 post_data = bindinfo.stgmedData.u.hGlobal;
673 hres = IMoniker_GetDisplayName(mon, 0, NULL, &url);
674 if(FAILED(hres))
675 FIXME("GetDisplayName failed: %08x\n", hres);
677 bsc = create_callback(This, url, post_data, post_data_len, headers);
678 CoTaskMemFree(url);
680 hres = navigate_bsc(This, bsc, mon);
682 IBindStatusCallback_Release(BINDSC(bsc));
683 CoTaskMemFree(headers);
684 ReleaseBindInfo(&bindinfo);
686 return hres;
689 HRESULT go_home(DocHost *This)
691 HKEY hkey;
692 DWORD res, type, size;
693 WCHAR wszPageName[MAX_PATH];
694 static const WCHAR wszAboutBlank[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
695 static const WCHAR wszStartPage[] = {'S','t','a','r','t',' ','P','a','g','e',0};
696 static const WCHAR wszSubKey[] = {'S','o','f','t','w','a','r','e','\\',
697 'M','i','c','r','o','s','o','f','t','\\',
698 'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\',
699 'M','a','i','n',0};
701 res = RegOpenKeyW(HKEY_CURRENT_USER, wszSubKey, &hkey);
702 if (res != ERROR_SUCCESS)
703 return navigate_url(This, wszAboutBlank, NULL, NULL, NULL, NULL);
705 size = sizeof(wszPageName);
706 res = RegQueryValueExW(hkey, wszStartPage, NULL, &type, (LPBYTE)wszPageName, &size);
707 RegCloseKey(hkey);
708 if (res != ERROR_SUCCESS || type != REG_SZ)
709 return navigate_url(This, wszAboutBlank, NULL, NULL, NULL, NULL);
711 return navigate_url(This, wszPageName, NULL, NULL, NULL, NULL);
714 #define HLINKFRAME_THIS(iface) DEFINE_THIS(WebBrowser, HlinkFrame, iface)
716 static HRESULT WINAPI HlinkFrame_QueryInterface(IHlinkFrame *iface, REFIID riid, void **ppv)
718 WebBrowser *This = HLINKFRAME_THIS(iface);
719 return IWebBrowser2_QueryInterface(WEBBROWSER2(This), riid, ppv);
722 static ULONG WINAPI HlinkFrame_AddRef(IHlinkFrame *iface)
724 WebBrowser *This = HLINKFRAME_THIS(iface);
725 return IWebBrowser2_AddRef(WEBBROWSER2(This));
728 static ULONG WINAPI HlinkFrame_Release(IHlinkFrame *iface)
730 WebBrowser *This = HLINKFRAME_THIS(iface);
731 return IWebBrowser2_Release(WEBBROWSER2(This));
734 static HRESULT WINAPI HlinkFrame_SetBrowseContext(IHlinkFrame *iface,
735 IHlinkBrowseContext *pihlbc)
737 WebBrowser *This = HLINKFRAME_THIS(iface);
738 FIXME("(%p)->(%p)\n", This, pihlbc);
739 return E_NOTIMPL;
742 static HRESULT WINAPI HlinkFrame_GetBrowseContext(IHlinkFrame *iface,
743 IHlinkBrowseContext **ppihlbc)
745 WebBrowser *This = HLINKFRAME_THIS(iface);
746 FIXME("(%p)->(%p)\n", This, ppihlbc);
747 return E_NOTIMPL;
750 static HRESULT WINAPI HlinkFrame_Navigate(IHlinkFrame *iface, DWORD grfHLNF, LPBC pbc,
751 IBindStatusCallback *pibsc, IHlink *pihlNavigate)
753 WebBrowser *This = HLINKFRAME_THIS(iface);
754 IMoniker *mon;
755 LPWSTR location = NULL;
757 TRACE("(%p)->(%08x %p %p %p)\n", This, grfHLNF, pbc, pibsc, pihlNavigate);
759 if(grfHLNF)
760 FIXME("unsupported grfHLNF=%08x\n", grfHLNF);
762 /* Windows calls GetTargetFrameName here. */
764 IHlink_GetMonikerReference(pihlNavigate, 1, &mon, &location);
766 if(location) {
767 FIXME("location = %s\n", debugstr_w(location));
768 CoTaskMemFree(location);
771 /* Windows calls GetHlinkSite here */
773 if(grfHLNF & HLNF_OPENINNEWWINDOW) {
774 FIXME("Not supported HLNF_OPENINNEWWINDOW\n");
775 return E_NOTIMPL;
778 return navigate_hlink(&This->doc_host, mon, pbc, pibsc);
781 static HRESULT WINAPI HlinkFrame_OnNavigate(IHlinkFrame *iface, DWORD grfHLNF,
782 IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName, DWORD dwreserved)
784 WebBrowser *This = HLINKFRAME_THIS(iface);
785 FIXME("(%p)->(%08x %p %s %s %d)\n", This, grfHLNF, pimkTarget, debugstr_w(pwzLocation),
786 debugstr_w(pwzFriendlyName), dwreserved);
787 return E_NOTIMPL;
790 static HRESULT WINAPI HlinkFrame_UpdateHlink(IHlinkFrame *iface, ULONG uHLID,
791 IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName)
793 WebBrowser *This = HLINKFRAME_THIS(iface);
794 FIXME("(%p)->(%u %p %s %s)\n", This, uHLID, pimkTarget, debugstr_w(pwzLocation),
795 debugstr_w(pwzFriendlyName));
796 return E_NOTIMPL;
799 #undef HLINKFRAME_THIS
801 static const IHlinkFrameVtbl HlinkFrameVtbl = {
802 HlinkFrame_QueryInterface,
803 HlinkFrame_AddRef,
804 HlinkFrame_Release,
805 HlinkFrame_SetBrowseContext,
806 HlinkFrame_GetBrowseContext,
807 HlinkFrame_Navigate,
808 HlinkFrame_OnNavigate,
809 HlinkFrame_UpdateHlink
812 void WebBrowser_HlinkFrame_Init(WebBrowser *This)
814 This->lpHlinkFrameVtbl = &HlinkFrameVtbl;