winepulse.drv: add a pulseaudio driver
[wine/hacks.git] / dlls / shdocvw / navigate.c
blob6f05cf2da2873044ad81b20f655e923d8f1beb6d
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"
30 #include "mshtml.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 static HRESULT set_dochost_url(DocHost *This, const WCHAR *url)
116 WCHAR *new_url;
118 if(url) {
119 new_url = heap_strdupW(url);
120 if(!new_url)
121 return E_OUTOFMEMORY;
122 }else {
123 new_url = NULL;
126 heap_free(This->url);
127 This->url = new_url;
128 return S_OK;
131 #define BINDSC_THIS(iface) DEFINE_THIS(BindStatusCallback, BindStatusCallback, iface)
133 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallback *iface,
134 REFIID riid, void **ppv)
136 BindStatusCallback *This = BINDSC_THIS(iface);
138 *ppv = NULL;
140 if(IsEqualGUID(&IID_IUnknown, riid)) {
141 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
142 *ppv = BINDSC(This);
143 }else if(IsEqualGUID(&IID_IBindStatusCallback, riid)) {
144 TRACE("(%p)->(IID_IBindStatusCallback %p)\n", This, ppv);
145 *ppv = BINDSC(This);
146 }else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) {
147 TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This, ppv);
148 *ppv = HTTPNEG(This);
151 if(*ppv) {
152 IBindStatusCallback_AddRef(BINDSC(This));
153 return S_OK;
156 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
157 return E_NOINTERFACE;
160 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallback *iface)
162 BindStatusCallback *This = BINDSC_THIS(iface);
163 LONG ref = InterlockedIncrement(&This->ref);
165 TRACE("(%p) ref=%d\n", This, ref);
167 return ref;
170 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallback *iface)
172 BindStatusCallback *This = BINDSC_THIS(iface);
173 LONG ref = InterlockedDecrement(&This->ref);
175 TRACE("(%p) ref=%d\n", This, ref);
177 if(!ref) {
178 if(This->doc_host)
179 IOleClientSite_Release(CLIENTSITE(This->doc_host));
180 if(This->post_data)
181 GlobalFree(This->post_data);
182 SysFreeString(This->headers);
183 heap_free(This->url);
184 heap_free(This);
187 return ref;
190 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallback *iface,
191 DWORD dwReserved, IBinding *pbind)
193 BindStatusCallback *This = BINDSC_THIS(iface);
195 TRACE("(%p)->(%d %p)\n", This, dwReserved, pbind);
197 return S_OK;
200 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface,
201 LONG *pnPriority)
203 BindStatusCallback *This = BINDSC_THIS(iface);
204 FIXME("(%p)->(%p)\n", This, pnPriority);
205 return E_NOTIMPL;
208 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface,
209 DWORD reserved)
211 BindStatusCallback *This = BINDSC_THIS(iface);
212 FIXME("(%p)->(%d)\n", This, reserved);
213 return E_NOTIMPL;
216 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallback *iface,
217 ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
219 BindStatusCallback *This = BINDSC_THIS(iface);
221 TRACE("(%p)->(%d %d %d %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
222 debugstr_w(szStatusText));
224 switch(ulStatusCode) {
225 case BINDSTATUS_REDIRECTING:
226 return set_dochost_url(This->doc_host, szStatusText);
227 case BINDSTATUS_BEGINDOWNLOADDATA:
228 set_status_text(This, szStatusText); /* FIXME: "Start downloading from site: %s" */
229 return S_OK;
230 case BINDSTATUS_ENDDOWNLOADDATA:
231 set_status_text(This, szStatusText); /* FIXME: "Downloading from site: %s" */
232 return S_OK;
233 case BINDSTATUS_CLASSIDAVAILABLE:
234 case BINDSTATUS_MIMETYPEAVAILABLE:
235 case BINDSTATUS_BEGINSYNCOPERATION:
236 case BINDSTATUS_ENDSYNCOPERATION:
237 return S_OK;
238 default:
239 FIXME("status code %u\n", ulStatusCode);
242 return S_OK;
245 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
246 HRESULT hresult, LPCWSTR szError)
248 BindStatusCallback *This = BINDSC_THIS(iface);
250 TRACE("(%p)->(%08x %s)\n", This, hresult, debugstr_w(szError));
252 set_status_text(This, emptyW);
254 if(This->doc_host) {
255 IOleClientSite_Release(CLIENTSITE(This->doc_host));
256 This->doc_host = NULL;
259 return S_OK;
262 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
263 DWORD *grfBINDF, BINDINFO *pbindinfo)
265 BindStatusCallback *This = BINDSC_THIS(iface);
267 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
269 *grfBINDF = BINDF_ASYNCHRONOUS;
271 if(This->post_data) {
272 pbindinfo->dwBindVerb = BINDVERB_POST;
274 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
275 pbindinfo->stgmedData.u.hGlobal = This->post_data;
276 pbindinfo->cbstgmedData = This->post_data_len;
277 pbindinfo->stgmedData.pUnkForRelease = (IUnknown*)BINDSC(This);
278 IBindStatusCallback_AddRef(BINDSC(This));
281 return S_OK;
284 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
285 DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
287 BindStatusCallback *This = BINDSC_THIS(iface);
288 FIXME("(%p)->(%08x %d %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed);
289 return E_NOTIMPL;
292 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
293 REFIID riid, IUnknown *punk)
295 BindStatusCallback *This = BINDSC_THIS(iface);
297 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), punk);
299 return dochost_object_available(This->doc_host, punk);
302 #undef BSC_THIS
304 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
305 BindStatusCallback_QueryInterface,
306 BindStatusCallback_AddRef,
307 BindStatusCallback_Release,
308 BindStatusCallback_OnStartBinding,
309 BindStatusCallback_GetPriority,
310 BindStatusCallback_OnLowResource,
311 BindStatusCallback_OnProgress,
312 BindStatusCallback_OnStopBinding,
313 BindStatusCallback_GetBindInfo,
314 BindStatusCallback_OnDataAvailable,
315 BindStatusCallback_OnObjectAvailable
318 #define HTTPNEG_THIS(iface) DEFINE_THIS(BindStatusCallback, HttpNegotiate, iface)
320 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate *iface,
321 REFIID riid, void **ppv)
323 BindStatusCallback *This = HTTPNEG_THIS(iface);
324 return IBindStatusCallback_QueryInterface(BINDSC(This), riid, ppv);
327 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate *iface)
329 BindStatusCallback *This = HTTPNEG_THIS(iface);
330 return IBindStatusCallback_AddRef(BINDSC(This));
333 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate *iface)
335 BindStatusCallback *This = HTTPNEG_THIS(iface);
336 return IBindStatusCallback_Release(BINDSC(This));
339 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate *iface,
340 LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
342 BindStatusCallback *This = HTTPNEG_THIS(iface);
344 TRACE("(%p)->(%s %s %d %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders),
345 dwReserved, pszAdditionalHeaders);
347 if(This->headers) {
348 int size = (strlenW(This->headers)+1)*sizeof(WCHAR);
349 *pszAdditionalHeaders = CoTaskMemAlloc(size);
350 memcpy(*pszAdditionalHeaders, This->headers, size);
353 return S_OK;
356 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate *iface,
357 DWORD dwResponseCode, LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders,
358 LPWSTR *pszAdditionalRequestHeaders)
360 BindStatusCallback *This = HTTPNEG_THIS(iface);
361 TRACE("(%p)->(%d %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
362 debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
363 return S_OK;
366 #undef HTTPNEG_THIS
368 static const IHttpNegotiateVtbl HttpNegotiateVtbl = {
369 HttpNegotiate_QueryInterface,
370 HttpNegotiate_AddRef,
371 HttpNegotiate_Release,
372 HttpNegotiate_BeginningTransaction,
373 HttpNegotiate_OnResponse
376 static BindStatusCallback *create_callback(DocHost *doc_host, LPCWSTR url, PBYTE post_data,
377 ULONG post_data_len, LPCWSTR headers)
379 BindStatusCallback *ret = heap_alloc(sizeof(BindStatusCallback));
381 ret->lpBindStatusCallbackVtbl = &BindStatusCallbackVtbl;
382 ret->lpHttpNegotiateVtbl = &HttpNegotiateVtbl;
384 ret->ref = 1;
385 ret->url = heap_strdupW(url);
386 ret->post_data = NULL;
387 ret->post_data_len = post_data_len;
388 ret->headers = headers ? SysAllocString(headers) : NULL;
390 ret->doc_host = doc_host;
391 IOleClientSite_AddRef(CLIENTSITE(doc_host));
393 if(post_data) {
394 ret->post_data = GlobalAlloc(0, post_data_len);
395 memcpy(ret->post_data, post_data, post_data_len);
398 return ret;
401 static void on_before_navigate2(DocHost *This, LPCWSTR url, SAFEARRAY *post_data, LPWSTR headers, VARIANT_BOOL *cancel)
403 VARIANT var_url, var_flags, var_frame_name, var_post_data, var_post_data2, var_headers;
404 DISPPARAMS dispparams;
405 VARIANTARG params[7];
407 dispparams.cArgs = 7;
408 dispparams.cNamedArgs = 0;
409 dispparams.rgdispidNamedArgs = NULL;
410 dispparams.rgvarg = params;
412 This->busy = VARIANT_TRUE;
414 V_VT(params) = VT_BOOL|VT_BYREF;
415 V_BOOLREF(params) = cancel;
417 V_VT(params+1) = (VT_BYREF|VT_VARIANT);
418 V_VARIANTREF(params+1) = &var_headers;
419 V_VT(&var_headers) = VT_BSTR;
420 V_BSTR(&var_headers) = headers;
422 V_VT(params+2) = (VT_BYREF|VT_VARIANT);
423 V_VARIANTREF(params+2) = &var_post_data2;
424 V_VT(&var_post_data2) = (VT_BYREF|VT_VARIANT);
425 V_VARIANTREF(&var_post_data2) = &var_post_data;
427 if(post_data) {
428 V_VT(&var_post_data) = VT_UI1|VT_ARRAY;
429 V_ARRAY(&var_post_data) = post_data;
430 }else {
431 V_VT(&var_post_data) = VT_EMPTY;
434 V_VT(params+3) = (VT_BYREF|VT_VARIANT);
435 V_VARIANTREF(params+3) = &var_frame_name;
436 V_VT(&var_frame_name) = VT_BSTR;
437 V_BSTR(&var_frame_name) = NULL;
439 V_VT(params+4) = (VT_BYREF|VT_VARIANT);
440 V_VARIANTREF(params+4) = &var_flags;
441 V_VT(&var_flags) = VT_I4;
442 V_I4(&var_flags) = 0;
444 V_VT(params+5) = (VT_BYREF|VT_VARIANT);
445 V_VARIANTREF(params+5) = &var_url;
446 V_VT(&var_url) = VT_BSTR;
447 V_BSTR(&var_url) = SysAllocString(url);
449 V_VT(params+6) = (VT_DISPATCH);
450 V_DISPATCH(params+6) = This->disp;
452 call_sink(This->cps.wbe2, DISPID_BEFORENAVIGATE2, &dispparams);
454 SysFreeString(V_BSTR(&var_url));
457 /* FIXME: urlmon should handle it */
458 static BOOL try_application_url(LPCWSTR url)
460 SHELLEXECUTEINFOW exec_info;
461 WCHAR app[64];
462 HKEY hkey;
463 DWORD res, type;
464 HRESULT hres;
466 static const WCHAR wszURLProtocol[] = {'U','R','L',' ','P','r','o','t','o','c','o','l',0};
468 hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, app, sizeof(app)/sizeof(WCHAR), NULL, 0);
469 if(FAILED(hres))
470 return FALSE;
472 res = RegOpenKeyW(HKEY_CLASSES_ROOT, app, &hkey);
473 if(res != ERROR_SUCCESS)
474 return FALSE;
476 res = RegQueryValueExW(hkey, wszURLProtocol, NULL, &type, NULL, NULL);
477 RegCloseKey(hkey);
478 if(res != ERROR_SUCCESS || type != REG_SZ)
479 return FALSE;
481 TRACE("openning application %s\n", debugstr_w(app));
483 memset(&exec_info, 0, sizeof(exec_info));
484 exec_info.cbSize = sizeof(exec_info);
485 exec_info.lpFile = url;
486 exec_info.nShow = SW_SHOW;
488 return ShellExecuteExW(&exec_info);
491 static HRESULT create_moniker(LPCWSTR url, IMoniker **mon)
493 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
494 DWORD size;
495 HRESULT hres;
497 if(PathIsURLW(url))
498 return CreateURLMoniker(NULL, url, mon);
500 if(url[1] == ':') {
501 size = sizeof(new_url);
502 hres = UrlCreateFromPathW(url, new_url, &size, 0);
503 if(FAILED(hres)) {
504 WARN("UrlCreateFromPathW failed: %08x\n", hres);
505 return hres;
507 }else {
508 size = sizeof(new_url)/sizeof(WCHAR);
509 hres = UrlApplySchemeW(url, new_url, &size, URL_APPLY_GUESSSCHEME);
510 TRACE("got %s\n", debugstr_w(new_url));
511 if(FAILED(hres)) {
512 WARN("UrlApplyScheme failed: %08x\n", hres);
513 return hres;
517 return CreateURLMoniker(NULL, new_url, mon);
520 static HRESULT bind_to_object(DocHost *This, IMoniker *mon, LPCWSTR url, IBindCtx *bindctx,
521 IBindStatusCallback *callback)
523 IUnknown *unk = NULL;
524 WCHAR *display_name;
525 HRESULT hres;
527 if(mon) {
528 IMoniker_AddRef(mon);
529 }else {
530 hres = create_moniker(url, &mon);
531 if(FAILED(hres))
532 return hres;
535 hres = IMoniker_GetDisplayName(mon, 0, NULL, &display_name);
536 if(FAILED(hres)) {
537 FIXME("GetDisplayName failed: %08x\n", hres);
538 return hres;
541 hres = set_dochost_url(This, display_name);
542 CoTaskMemFree(display_name);
543 if(FAILED(hres))
544 return hres;
546 IBindCtx_RegisterObjectParam(bindctx, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM,
547 (IUnknown*)CLIENTSITE(This));
549 hres = IMoniker_BindToObject(mon, bindctx, NULL, &IID_IUnknown, (void**)&unk);
550 if(SUCCEEDED(hres)) {
551 hres = S_OK;
552 if(unk)
553 IUnknown_Release(unk);
554 }else if(try_application_url(url)) {
555 hres = S_OK;
556 }else {
557 FIXME("BindToObject failed: %08x\n", hres);
560 IMoniker_Release(mon);
561 return S_OK;
564 static void html_window_navigate(DocHost *This, IHTMLPrivateWindow *window, BSTR url, BSTR headers, SAFEARRAY *post_data)
566 VARIANT headers_var, post_data_var;
567 BSTR empty_str;
568 HRESULT hres;
570 hres = set_dochost_url(This, url);
571 if(FAILED(hres))
572 return;
574 empty_str = SysAllocStringLen(NULL, 0);
576 if(headers) {
577 V_VT(&headers_var) = VT_BSTR;
578 V_BSTR(&headers_var) = headers;
579 }else {
580 V_VT(&headers_var) = VT_EMPTY;
583 if(post_data) {
584 V_VT(&post_data_var) = VT_UI1|VT_ARRAY;
585 V_ARRAY(&post_data_var) = post_data;
586 }else {
587 V_VT(&post_data_var) = VT_EMPTY;
590 set_doc_state(This, READYSTATE_LOADING);
591 hres = IHTMLPrivateWindow_SuperNavigate(window, url, empty_str, NULL, NULL, &post_data_var, &headers_var, 0);
592 SysFreeString(empty_str);
593 if(FAILED(hres))
594 WARN("SuprtNavigate failed: %08x\n", hres);
597 typedef struct {
598 task_header_t header;
599 BSTR url;
600 BSTR headers;
601 SAFEARRAY *post_data;
602 BOOL async_notif;
603 } task_doc_navigate_t;
605 static HRESULT free_doc_navigate_task(task_doc_navigate_t *task, BOOL free_task)
607 SysFreeString(task->url);
608 SysFreeString(task->headers);
609 if(task->post_data)
610 SafeArrayDestroy(task->post_data);
611 if(free_task)
612 heap_free(task);
613 return E_OUTOFMEMORY;
616 static void doc_navigate_proc(DocHost *This, task_header_t *t)
618 task_doc_navigate_t *task = (task_doc_navigate_t*)t;
619 IHTMLPrivateWindow *priv_window;
620 HRESULT hres;
622 if(!This->doc_navigate)
623 return;
625 if(task->async_notif) {
626 VARIANT_BOOL cancel = VARIANT_FALSE;
627 on_before_navigate2(This, task->url, task->post_data, task->headers, &cancel);
628 if(cancel) {
629 TRACE("Navigation calnceled\n");
630 free_doc_navigate_task(task, FALSE);
631 return;
635 hres = IUnknown_QueryInterface(This->doc_navigate, &IID_IHTMLPrivateWindow, (void**)&priv_window);
636 if(SUCCEEDED(hres)) {
637 html_window_navigate(This, priv_window, task->url, task->headers, task->post_data);
638 IHTMLPrivateWindow_Release(priv_window);
639 }else {
640 WARN("Could not get IHTMLPrivateWindow iface: %08x\n", hres);
643 free_doc_navigate_task(task, FALSE);
646 static HRESULT async_doc_navigate(DocHost *This, LPCWSTR url, LPCWSTR headers, PBYTE post_data, ULONG post_data_size,
647 BOOL async_notif)
649 task_doc_navigate_t *task;
651 task = heap_alloc_zero(sizeof(*task));
652 if(!task)
653 return E_OUTOFMEMORY;
655 task->url = SysAllocString(url);
656 if(!task->url)
657 return free_doc_navigate_task(task, TRUE);
659 if(headers) {
660 task->headers = SysAllocString(headers);
661 if(!task->headers)
662 return free_doc_navigate_task(task, TRUE);
665 if(post_data) {
666 task->post_data = SafeArrayCreateVector(VT_UI1, 0, post_data_size);
667 if(!task->post_data)
668 return free_doc_navigate_task(task, TRUE);
669 memcpy(task->post_data->pvData, post_data, post_data_size);
672 if(!async_notif) {
673 VARIANT_BOOL cancel = VARIANT_FALSE;
675 on_before_navigate2(This, task->url, task->post_data, task->headers, &cancel);
676 if(cancel) {
677 TRACE("Navigation calnceled\n");
678 free_doc_navigate_task(task, TRUE);
679 return S_OK;
683 task->async_notif = async_notif;
684 push_dochost_task(This, &task->header, doc_navigate_proc, FALSE);
685 return S_OK;
688 static HRESULT navigate_bsc(DocHost *This, BindStatusCallback *bsc, IMoniker *mon)
690 VARIANT_BOOL cancel = VARIANT_FALSE;
691 SAFEARRAY *post_data = NULL;
692 IBindCtx *bindctx;
693 HRESULT hres;
695 set_doc_state(This, READYSTATE_LOADING);
697 if(bsc->post_data) {
698 post_data = SafeArrayCreateVector(VT_UI1, 0, bsc->post_data_len);
699 memcpy(post_data->pvData, post_data, bsc->post_data_len);
702 on_before_navigate2(This, bsc->url, post_data, bsc->headers, &cancel);
703 if(post_data)
704 SafeArrayDestroy(post_data);
705 if(cancel) {
706 FIXME("Navigation canceled\n");
707 return S_OK;
710 if(This->document)
711 deactivate_document(This);
713 CreateAsyncBindCtx(0, BINDSC(bsc), 0, &bindctx);
715 if(This->frame)
716 IOleInPlaceFrame_EnableModeless(This->frame, FALSE);
718 hres = bind_to_object(This, mon, bsc->url, bindctx, BINDSC(bsc));
720 if(This->frame)
721 IOleInPlaceFrame_EnableModeless(This->frame, TRUE);
723 IBindCtx_Release(bindctx);
725 return hres;
728 typedef struct {
729 task_header_t header;
730 BindStatusCallback *bsc;
731 } task_navigate_bsc_t;
733 static void navigate_bsc_proc(DocHost *This, task_header_t *t)
735 task_navigate_bsc_t *task = (task_navigate_bsc_t*)t;
737 if(!This->hwnd)
738 create_doc_view_hwnd(This);
740 navigate_bsc(This, task->bsc, NULL);
742 IBindStatusCallback_Release(BINDSC(task->bsc));
746 HRESULT navigate_url(DocHost *This, LPCWSTR url, const VARIANT *Flags,
747 const VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers)
749 PBYTE post_data = NULL;
750 ULONG post_data_len = 0;
751 LPWSTR headers = NULL;
752 HRESULT hres = S_OK;
754 TRACE("navigating to %s\n", debugstr_w(url));
756 if((Flags && V_VT(Flags) != VT_EMPTY)
757 || (TargetFrameName && V_VT(TargetFrameName) != VT_EMPTY))
758 FIXME("Unsupported args (Flags %p:%d; TargetFrameName %p:%d)\n",
759 Flags, Flags ? V_VT(Flags) : -1, TargetFrameName,
760 TargetFrameName ? V_VT(TargetFrameName) : -1);
762 if(PostData) {
763 TRACE("PostData vt=%d\n", V_VT(PostData));
765 if(V_VT(PostData) == (VT_ARRAY | VT_UI1)) {
766 SafeArrayAccessData(V_ARRAY(PostData), (void**)&post_data);
767 post_data_len = V_ARRAY(PostData)->rgsabound[0].cElements;
771 if(Headers && V_VT(Headers) != VT_EMPTY && V_VT(Headers) != VT_ERROR) {
772 if(V_VT(Headers) != VT_BSTR)
773 return E_INVALIDARG;
775 headers = V_BSTR(Headers);
776 TRACE("Headers: %s\n", debugstr_w(headers));
779 set_doc_state(This, READYSTATE_LOADING);
780 This->ready_state = READYSTATE_LOADING;
782 if(This->doc_navigate) {
783 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
785 if(PathIsURLW(url)) {
786 new_url[0] = 0;
787 }else {
788 DWORD size;
790 size = sizeof(new_url)/sizeof(WCHAR);
791 hres = UrlApplySchemeW(url, new_url, &size, URL_APPLY_GUESSSCHEME);
792 if(FAILED(hres)) {
793 WARN("UrlApplyScheme failed: %08x\n", hres);
794 new_url[0] = 0;
798 hres = async_doc_navigate(This, *new_url ? new_url : url, headers, post_data,
799 post_data_len, TRUE);
800 }else {
801 task_navigate_bsc_t *task;
803 task = heap_alloc(sizeof(*task));
804 task->bsc = create_callback(This, url, post_data, post_data_len, headers);
805 push_dochost_task(This, &task->header, navigate_bsc_proc, This->url == NULL);
808 if(post_data)
809 SafeArrayUnaccessData(V_ARRAY(PostData));
811 return hres;
814 static HRESULT navigate_hlink(DocHost *This, IMoniker *mon, IBindCtx *bindctx,
815 IBindStatusCallback *callback)
817 IHttpNegotiate *http_negotiate;
818 BindStatusCallback *bsc;
819 PBYTE post_data = NULL;
820 ULONG post_data_len = 0;
821 LPWSTR headers = NULL, url;
822 BINDINFO bindinfo;
823 DWORD bindf = 0;
824 HRESULT hres;
826 hres = IMoniker_GetDisplayName(mon, 0, NULL, &url);
827 if(FAILED(hres))
828 FIXME("GetDisplayName failed: %08x\n", hres);
830 hres = IBindStatusCallback_QueryInterface(callback, &IID_IHttpNegotiate,
831 (void**)&http_negotiate);
832 if(SUCCEEDED(hres)) {
833 static const WCHAR null_string[] = {0};
835 IHttpNegotiate_BeginningTransaction(http_negotiate, null_string, null_string, 0,
836 &headers);
837 IHttpNegotiate_Release(http_negotiate);
840 memset(&bindinfo, 0, sizeof(bindinfo));
841 bindinfo.cbSize = sizeof(bindinfo);
843 hres = IBindStatusCallback_GetBindInfo(callback, &bindf, &bindinfo);
844 dump_BINDINFO(&bindinfo);
845 if(bindinfo.dwBindVerb == BINDVERB_POST) {
846 post_data_len = bindinfo.cbstgmedData;
847 if(post_data_len)
848 post_data = bindinfo.stgmedData.u.hGlobal;
851 if(This->doc_navigate) {
852 hres = async_doc_navigate(This, url, headers, post_data, post_data_len, FALSE);
853 }else {
854 bsc = create_callback(This, url, post_data, post_data_len, headers);
855 hres = navigate_bsc(This, bsc, mon);
856 IBindStatusCallback_Release(BINDSC(bsc));
859 CoTaskMemFree(url);
860 CoTaskMemFree(headers);
861 ReleaseBindInfo(&bindinfo);
863 return hres;
866 HRESULT go_home(DocHost *This)
868 HKEY hkey;
869 DWORD res, type, size;
870 WCHAR wszPageName[MAX_PATH];
871 static const WCHAR wszAboutBlank[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
872 static const WCHAR wszStartPage[] = {'S','t','a','r','t',' ','P','a','g','e',0};
873 static const WCHAR wszSubKey[] = {'S','o','f','t','w','a','r','e','\\',
874 'M','i','c','r','o','s','o','f','t','\\',
875 'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\',
876 'M','a','i','n',0};
878 res = RegOpenKeyW(HKEY_CURRENT_USER, wszSubKey, &hkey);
879 if (res != ERROR_SUCCESS)
880 return navigate_url(This, wszAboutBlank, NULL, NULL, NULL, NULL);
882 size = sizeof(wszPageName);
883 res = RegQueryValueExW(hkey, wszStartPage, NULL, &type, (LPBYTE)wszPageName, &size);
884 RegCloseKey(hkey);
885 if (res != ERROR_SUCCESS || type != REG_SZ)
886 return navigate_url(This, wszAboutBlank, NULL, NULL, NULL, NULL);
888 return navigate_url(This, wszPageName, NULL, NULL, NULL, NULL);
891 #define HLINKFRAME_THIS(iface) DEFINE_THIS(WebBrowser, HlinkFrame, iface)
893 static HRESULT WINAPI HlinkFrame_QueryInterface(IHlinkFrame *iface, REFIID riid, void **ppv)
895 WebBrowser *This = HLINKFRAME_THIS(iface);
896 return IWebBrowser2_QueryInterface(WEBBROWSER2(This), riid, ppv);
899 static ULONG WINAPI HlinkFrame_AddRef(IHlinkFrame *iface)
901 WebBrowser *This = HLINKFRAME_THIS(iface);
902 return IWebBrowser2_AddRef(WEBBROWSER2(This));
905 static ULONG WINAPI HlinkFrame_Release(IHlinkFrame *iface)
907 WebBrowser *This = HLINKFRAME_THIS(iface);
908 return IWebBrowser2_Release(WEBBROWSER2(This));
911 static HRESULT WINAPI HlinkFrame_SetBrowseContext(IHlinkFrame *iface,
912 IHlinkBrowseContext *pihlbc)
914 WebBrowser *This = HLINKFRAME_THIS(iface);
915 FIXME("(%p)->(%p)\n", This, pihlbc);
916 return E_NOTIMPL;
919 static HRESULT WINAPI HlinkFrame_GetBrowseContext(IHlinkFrame *iface,
920 IHlinkBrowseContext **ppihlbc)
922 WebBrowser *This = HLINKFRAME_THIS(iface);
923 FIXME("(%p)->(%p)\n", This, ppihlbc);
924 return E_NOTIMPL;
927 static HRESULT WINAPI HlinkFrame_Navigate(IHlinkFrame *iface, DWORD grfHLNF, LPBC pbc,
928 IBindStatusCallback *pibsc, IHlink *pihlNavigate)
930 WebBrowser *This = HLINKFRAME_THIS(iface);
931 IMoniker *mon;
932 LPWSTR location = NULL;
934 TRACE("(%p)->(%08x %p %p %p)\n", This, grfHLNF, pbc, pibsc, pihlNavigate);
936 if(grfHLNF)
937 FIXME("unsupported grfHLNF=%08x\n", grfHLNF);
939 /* Windows calls GetTargetFrameName here. */
941 IHlink_GetMonikerReference(pihlNavigate, 1, &mon, &location);
943 if(location) {
944 FIXME("location = %s\n", debugstr_w(location));
945 CoTaskMemFree(location);
948 /* Windows calls GetHlinkSite here */
950 if(grfHLNF & HLNF_OPENINNEWWINDOW) {
951 FIXME("Not supported HLNF_OPENINNEWWINDOW\n");
952 return E_NOTIMPL;
955 return navigate_hlink(&This->doc_host, mon, pbc, pibsc);
958 static HRESULT WINAPI HlinkFrame_OnNavigate(IHlinkFrame *iface, DWORD grfHLNF,
959 IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName, DWORD dwreserved)
961 WebBrowser *This = HLINKFRAME_THIS(iface);
962 FIXME("(%p)->(%08x %p %s %s %d)\n", This, grfHLNF, pimkTarget, debugstr_w(pwzLocation),
963 debugstr_w(pwzFriendlyName), dwreserved);
964 return E_NOTIMPL;
967 static HRESULT WINAPI HlinkFrame_UpdateHlink(IHlinkFrame *iface, ULONG uHLID,
968 IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName)
970 WebBrowser *This = HLINKFRAME_THIS(iface);
971 FIXME("(%p)->(%u %p %s %s)\n", This, uHLID, pimkTarget, debugstr_w(pwzLocation),
972 debugstr_w(pwzFriendlyName));
973 return E_NOTIMPL;
976 #undef HLINKFRAME_THIS
978 static const IHlinkFrameVtbl HlinkFrameVtbl = {
979 HlinkFrame_QueryInterface,
980 HlinkFrame_AddRef,
981 HlinkFrame_Release,
982 HlinkFrame_SetBrowseContext,
983 HlinkFrame_GetBrowseContext,
984 HlinkFrame_Navigate,
985 HlinkFrame_OnNavigate,
986 HlinkFrame_UpdateHlink
989 #define TARGETFRAME2_THIS(iface) DEFINE_THIS(WebBrowser, ITargetFrame2, iface)
991 static HRESULT WINAPI TargetFrame2_QueryInterface(ITargetFrame2 *iface, REFIID riid, void **ppv)
993 WebBrowser *This = TARGETFRAME2_THIS(iface);
994 return IWebBrowser2_QueryInterface(WEBBROWSER2(This), riid, ppv);
997 static ULONG WINAPI TargetFrame2_AddRef(ITargetFrame2 *iface)
999 WebBrowser *This = TARGETFRAME2_THIS(iface);
1000 return IWebBrowser2_AddRef(WEBBROWSER2(This));
1003 static ULONG WINAPI TargetFrame2_Release(ITargetFrame2 *iface)
1005 WebBrowser *This = TARGETFRAME2_THIS(iface);
1006 return IWebBrowser2_Release(WEBBROWSER2(This));
1009 static HRESULT WINAPI TargetFrame2_SetFrameName(ITargetFrame2 *iface, LPCWSTR pszFrameName)
1011 WebBrowser *This = TARGETFRAME2_THIS(iface);
1012 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFrameName));
1013 return E_NOTIMPL;
1016 static HRESULT WINAPI TargetFrame2_GetFrameName(ITargetFrame2 *iface, LPWSTR *ppszFrameName)
1018 WebBrowser *This = TARGETFRAME2_THIS(iface);
1019 FIXME("(%p)->(%p)\n", This, ppszFrameName);
1020 return E_NOTIMPL;
1023 static HRESULT WINAPI TargetFrame2_GetParentFrame(ITargetFrame2 *iface, IUnknown **ppunkParent)
1025 WebBrowser *This = TARGETFRAME2_THIS(iface);
1026 FIXME("(%p)->(%p)\n", This, ppunkParent);
1027 return E_NOTIMPL;
1030 static HRESULT WINAPI TargetFrame2_SetFrameSrc(ITargetFrame2 *iface, LPCWSTR pszFrameSrc)
1032 WebBrowser *This = TARGETFRAME2_THIS(iface);
1033 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFrameSrc));
1034 return E_NOTIMPL;
1037 static HRESULT WINAPI TargetFrame2_GetFrameSrc(ITargetFrame2 *iface, LPWSTR *ppszFrameSrc)
1039 WebBrowser *This = TARGETFRAME2_THIS(iface);
1040 FIXME("(%p)->()\n", This);
1041 return E_NOTIMPL;
1044 static HRESULT WINAPI TargetFrame2_GetFramesContainer(ITargetFrame2 *iface, IOleContainer **ppContainer)
1046 WebBrowser *This = TARGETFRAME2_THIS(iface);
1047 FIXME("(%p)->(%p)\n", This, ppContainer);
1048 return E_NOTIMPL;
1051 static HRESULT WINAPI TargetFrame2_SetFrameOptions(ITargetFrame2 *iface, DWORD dwFlags)
1053 WebBrowser *This = TARGETFRAME2_THIS(iface);
1054 FIXME("(%p)->(%x)\n", This, dwFlags);
1055 return E_NOTIMPL;
1058 static HRESULT WINAPI TargetFrame2_GetFrameOptions(ITargetFrame2 *iface, DWORD *pdwFlags)
1060 WebBrowser *This = TARGETFRAME2_THIS(iface);
1061 FIXME("(%p)->(%p)\n", This, pdwFlags);
1062 return E_NOTIMPL;
1065 static HRESULT WINAPI TargetFrame2_SetFrameMargins(ITargetFrame2 *iface, DWORD dwWidth, DWORD dwHeight)
1067 WebBrowser *This = TARGETFRAME2_THIS(iface);
1068 FIXME("(%p)->(%d %d)\n", This, dwWidth, dwHeight);
1069 return E_NOTIMPL;
1072 static HRESULT WINAPI TargetFrame2_GetFrameMargins(ITargetFrame2 *iface, DWORD *pdwWidth, DWORD *pdwHeight)
1074 WebBrowser *This = TARGETFRAME2_THIS(iface);
1075 FIXME("(%p)->(%p %p)\n", This, pdwWidth, pdwHeight);
1076 return E_NOTIMPL;
1079 static HRESULT WINAPI TargetFrame2_FindFrame(ITargetFrame2 *iface, LPCWSTR pszTargetName, DWORD dwFlags, IUnknown **ppunkTargetFrame)
1081 WebBrowser *This = TARGETFRAME2_THIS(iface);
1082 FIXME("(%p)->(%s %x %p)\n", This, debugstr_w(pszTargetName), dwFlags, ppunkTargetFrame);
1083 return E_NOTIMPL;
1086 static HRESULT WINAPI TargetFrame2_GetTargetAlias(ITargetFrame2 *iface, LPCWSTR pszTargetName, LPWSTR *ppszTargetAlias)
1088 WebBrowser *This = TARGETFRAME2_THIS(iface);
1089 FIXME("(%p)->(%s %p)\n", This, debugstr_w(pszTargetName), ppszTargetAlias);
1090 return E_NOTIMPL;
1093 #undef TARGETFRAME2_THIS
1095 static const ITargetFrame2Vtbl TargetFrame2Vtbl = {
1096 TargetFrame2_QueryInterface,
1097 TargetFrame2_AddRef,
1098 TargetFrame2_Release,
1099 TargetFrame2_SetFrameName,
1100 TargetFrame2_GetFrameName,
1101 TargetFrame2_GetParentFrame,
1102 TargetFrame2_SetFrameSrc,
1103 TargetFrame2_GetFrameSrc,
1104 TargetFrame2_GetFramesContainer,
1105 TargetFrame2_SetFrameOptions,
1106 TargetFrame2_GetFrameOptions,
1107 TargetFrame2_SetFrameMargins,
1108 TargetFrame2_GetFrameMargins,
1109 TargetFrame2_FindFrame,
1110 TargetFrame2_GetTargetAlias
1113 void WebBrowser_HlinkFrame_Init(WebBrowser *This)
1115 This->lpHlinkFrameVtbl = &HlinkFrameVtbl;
1116 This->lpITargetFrame2Vtbl = &TargetFrame2Vtbl;