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"
32 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
34 static const WCHAR emptyW[] = {0};
37 const IBindStatusCallbackVtbl *lpBindStatusCallbackVtbl;
38 const IHttpNegotiateVtbl *lpHttpNegotiateVtbl;
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[] = {
57 "BINDINFOF_URLENCODESTGMEDDATA",
58 "BINDINFOF_URLENCODEDEXTRAINFO"
61 static const char * const BINDVERB_str[] = {
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)
100 DISPPARAMS dispparams = {&arg, NULL, 1, 0};
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);
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)
119 new_url = heap_strdupW(url);
121 return E_OUTOFMEMORY;
126 heap_free(This->url);
129 This->container_vtbl->SetURL(This, This->url);
133 #define BINDSC_THIS(iface) DEFINE_THIS(BindStatusCallback, BindStatusCallback, iface)
135 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallback *iface,
136 REFIID riid, void **ppv)
138 BindStatusCallback *This = BINDSC_THIS(iface);
142 if(IsEqualGUID(&IID_IUnknown, riid)) {
143 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
145 }else if(IsEqualGUID(&IID_IBindStatusCallback, riid)) {
146 TRACE("(%p)->(IID_IBindStatusCallback %p)\n", This, ppv);
148 }else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) {
149 TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This, ppv);
150 *ppv = HTTPNEG(This);
154 IBindStatusCallback_AddRef(BINDSC(This));
158 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
159 return E_NOINTERFACE;
162 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallback *iface)
164 BindStatusCallback *This = BINDSC_THIS(iface);
165 LONG ref = InterlockedIncrement(&This->ref);
167 TRACE("(%p) ref=%d\n", This, ref);
172 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallback *iface)
174 BindStatusCallback *This = BINDSC_THIS(iface);
175 LONG ref = InterlockedDecrement(&This->ref);
177 TRACE("(%p) ref=%d\n", This, ref);
181 IOleClientSite_Release(&This->doc_host->IOleClientSite_iface);
183 GlobalFree(This->post_data);
184 SysFreeString(This->headers);
185 heap_free(This->url);
192 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallback *iface,
193 DWORD dwReserved, IBinding *pbind)
195 BindStatusCallback *This = BINDSC_THIS(iface);
197 TRACE("(%p)->(%d %p)\n", This, dwReserved, pbind);
202 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface,
205 BindStatusCallback *This = BINDSC_THIS(iface);
206 FIXME("(%p)->(%p)\n", This, pnPriority);
210 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface,
213 BindStatusCallback *This = BINDSC_THIS(iface);
214 FIXME("(%p)->(%d)\n", This, reserved);
218 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallback *iface,
219 ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
221 BindStatusCallback *This = BINDSC_THIS(iface);
223 TRACE("(%p)->(%d %d %d %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
224 debugstr_w(szStatusText));
226 switch(ulStatusCode) {
227 case BINDSTATUS_REDIRECTING:
228 return set_dochost_url(This->doc_host, szStatusText);
229 case BINDSTATUS_BEGINDOWNLOADDATA:
230 set_status_text(This, szStatusText); /* FIXME: "Start downloading from site: %s" */
232 case BINDSTATUS_ENDDOWNLOADDATA:
233 set_status_text(This, szStatusText); /* FIXME: "Downloading from site: %s" */
235 case BINDSTATUS_CLASSIDAVAILABLE:
236 case BINDSTATUS_MIMETYPEAVAILABLE:
237 case BINDSTATUS_BEGINSYNCOPERATION:
238 case BINDSTATUS_ENDSYNCOPERATION:
241 FIXME("status code %u\n", ulStatusCode);
247 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
248 HRESULT hresult, LPCWSTR szError)
250 BindStatusCallback *This = BINDSC_THIS(iface);
252 TRACE("(%p)->(%08x %s)\n", This, hresult, debugstr_w(szError));
254 set_status_text(This, emptyW);
257 IOleClientSite_Release(&This->doc_host->IOleClientSite_iface);
258 This->doc_host = NULL;
264 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
265 DWORD *grfBINDF, BINDINFO *pbindinfo)
267 BindStatusCallback *This = BINDSC_THIS(iface);
269 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
271 *grfBINDF = BINDF_ASYNCHRONOUS;
273 if(This->post_data) {
274 pbindinfo->dwBindVerb = BINDVERB_POST;
276 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
277 pbindinfo->stgmedData.u.hGlobal = This->post_data;
278 pbindinfo->cbstgmedData = This->post_data_len;
279 pbindinfo->stgmedData.pUnkForRelease = (IUnknown*)BINDSC(This);
280 IBindStatusCallback_AddRef(BINDSC(This));
286 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
287 DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
289 BindStatusCallback *This = BINDSC_THIS(iface);
290 FIXME("(%p)->(%08x %d %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed);
294 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
295 REFIID riid, IUnknown *punk)
297 BindStatusCallback *This = BINDSC_THIS(iface);
299 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), punk);
301 return dochost_object_available(This->doc_host, punk);
306 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
307 BindStatusCallback_QueryInterface,
308 BindStatusCallback_AddRef,
309 BindStatusCallback_Release,
310 BindStatusCallback_OnStartBinding,
311 BindStatusCallback_GetPriority,
312 BindStatusCallback_OnLowResource,
313 BindStatusCallback_OnProgress,
314 BindStatusCallback_OnStopBinding,
315 BindStatusCallback_GetBindInfo,
316 BindStatusCallback_OnDataAvailable,
317 BindStatusCallback_OnObjectAvailable
320 #define HTTPNEG_THIS(iface) DEFINE_THIS(BindStatusCallback, HttpNegotiate, iface)
322 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate *iface,
323 REFIID riid, void **ppv)
325 BindStatusCallback *This = HTTPNEG_THIS(iface);
326 return IBindStatusCallback_QueryInterface(BINDSC(This), riid, ppv);
329 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate *iface)
331 BindStatusCallback *This = HTTPNEG_THIS(iface);
332 return IBindStatusCallback_AddRef(BINDSC(This));
335 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate *iface)
337 BindStatusCallback *This = HTTPNEG_THIS(iface);
338 return IBindStatusCallback_Release(BINDSC(This));
341 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate *iface,
342 LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
344 BindStatusCallback *This = HTTPNEG_THIS(iface);
346 TRACE("(%p)->(%s %s %d %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders),
347 dwReserved, pszAdditionalHeaders);
350 int size = (strlenW(This->headers)+1)*sizeof(WCHAR);
351 *pszAdditionalHeaders = CoTaskMemAlloc(size);
352 memcpy(*pszAdditionalHeaders, This->headers, size);
358 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate *iface,
359 DWORD dwResponseCode, LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders,
360 LPWSTR *pszAdditionalRequestHeaders)
362 BindStatusCallback *This = HTTPNEG_THIS(iface);
363 TRACE("(%p)->(%d %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
364 debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
370 static const IHttpNegotiateVtbl HttpNegotiateVtbl = {
371 HttpNegotiate_QueryInterface,
372 HttpNegotiate_AddRef,
373 HttpNegotiate_Release,
374 HttpNegotiate_BeginningTransaction,
375 HttpNegotiate_OnResponse
378 static BindStatusCallback *create_callback(DocHost *doc_host, LPCWSTR url, PBYTE post_data,
379 ULONG post_data_len, LPCWSTR headers)
381 BindStatusCallback *ret = heap_alloc(sizeof(BindStatusCallback));
383 ret->lpBindStatusCallbackVtbl = &BindStatusCallbackVtbl;
384 ret->lpHttpNegotiateVtbl = &HttpNegotiateVtbl;
387 ret->url = heap_strdupW(url);
388 ret->post_data = NULL;
389 ret->post_data_len = post_data_len;
390 ret->headers = headers ? SysAllocString(headers) : NULL;
392 ret->doc_host = doc_host;
393 IOleClientSite_AddRef(&doc_host->IOleClientSite_iface);
396 ret->post_data = GlobalAlloc(0, post_data_len);
397 memcpy(ret->post_data, post_data, post_data_len);
403 static void on_before_navigate2(DocHost *This, LPCWSTR url, SAFEARRAY *post_data, LPWSTR headers, VARIANT_BOOL *cancel)
405 VARIANT var_url, var_flags, var_frame_name, var_post_data, var_post_data2, var_headers;
406 DISPPARAMS dispparams;
407 VARIANTARG params[7];
409 dispparams.cArgs = 7;
410 dispparams.cNamedArgs = 0;
411 dispparams.rgdispidNamedArgs = NULL;
412 dispparams.rgvarg = params;
414 This->busy = VARIANT_TRUE;
416 V_VT(params) = VT_BOOL|VT_BYREF;
417 V_BOOLREF(params) = cancel;
419 V_VT(params+1) = (VT_BYREF|VT_VARIANT);
420 V_VARIANTREF(params+1) = &var_headers;
421 V_VT(&var_headers) = VT_BSTR;
422 V_BSTR(&var_headers) = headers;
424 V_VT(params+2) = (VT_BYREF|VT_VARIANT);
425 V_VARIANTREF(params+2) = &var_post_data2;
426 V_VT(&var_post_data2) = (VT_BYREF|VT_VARIANT);
427 V_VARIANTREF(&var_post_data2) = &var_post_data;
430 V_VT(&var_post_data) = VT_UI1|VT_ARRAY;
431 V_ARRAY(&var_post_data) = post_data;
433 V_VT(&var_post_data) = VT_EMPTY;
436 V_VT(params+3) = (VT_BYREF|VT_VARIANT);
437 V_VARIANTREF(params+3) = &var_frame_name;
438 V_VT(&var_frame_name) = VT_BSTR;
439 V_BSTR(&var_frame_name) = NULL;
441 V_VT(params+4) = (VT_BYREF|VT_VARIANT);
442 V_VARIANTREF(params+4) = &var_flags;
443 V_VT(&var_flags) = VT_I4;
444 V_I4(&var_flags) = 0;
446 V_VT(params+5) = (VT_BYREF|VT_VARIANT);
447 V_VARIANTREF(params+5) = &var_url;
448 V_VT(&var_url) = VT_BSTR;
449 V_BSTR(&var_url) = SysAllocString(url);
451 V_VT(params+6) = (VT_DISPATCH);
452 V_DISPATCH(params+6) = This->disp;
454 call_sink(This->cps.wbe2, DISPID_BEFORENAVIGATE2, &dispparams);
456 SysFreeString(V_BSTR(&var_url));
459 /* FIXME: urlmon should handle it */
460 static BOOL try_application_url(LPCWSTR url)
462 SHELLEXECUTEINFOW exec_info;
468 static const WCHAR wszURLProtocol[] = {'U','R','L',' ','P','r','o','t','o','c','o','l',0};
470 hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, app, sizeof(app)/sizeof(WCHAR), NULL, 0);
474 res = RegOpenKeyW(HKEY_CLASSES_ROOT, app, &hkey);
475 if(res != ERROR_SUCCESS)
478 res = RegQueryValueExW(hkey, wszURLProtocol, NULL, &type, NULL, NULL);
480 if(res != ERROR_SUCCESS || type != REG_SZ)
483 TRACE("openning application %s\n", debugstr_w(app));
485 memset(&exec_info, 0, sizeof(exec_info));
486 exec_info.cbSize = sizeof(exec_info);
487 exec_info.lpFile = url;
488 exec_info.nShow = SW_SHOW;
490 return ShellExecuteExW(&exec_info);
493 static HRESULT create_moniker(LPCWSTR url, IMoniker **mon)
495 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
500 return CreateURLMoniker(NULL, url, mon);
503 size = sizeof(new_url);
504 hres = UrlCreateFromPathW(url, new_url, &size, 0);
506 WARN("UrlCreateFromPathW failed: %08x\n", hres);
510 size = sizeof(new_url)/sizeof(WCHAR);
511 hres = UrlApplySchemeW(url, new_url, &size, URL_APPLY_GUESSSCHEME);
512 TRACE("got %s\n", debugstr_w(new_url));
514 WARN("UrlApplyScheme failed: %08x\n", hres);
519 return CreateURLMoniker(NULL, new_url, mon);
522 static HRESULT bind_to_object(DocHost *This, IMoniker *mon, LPCWSTR url, IBindCtx *bindctx,
523 IBindStatusCallback *callback)
525 IUnknown *unk = NULL;
530 IMoniker_AddRef(mon);
532 hres = create_moniker(url, &mon);
537 hres = IMoniker_GetDisplayName(mon, 0, NULL, &display_name);
539 FIXME("GetDisplayName failed: %08x\n", hres);
543 hres = set_dochost_url(This, display_name);
544 CoTaskMemFree(display_name);
548 IBindCtx_RegisterObjectParam(bindctx, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM,
549 (IUnknown*)&This->IOleClientSite_iface);
551 hres = IMoniker_BindToObject(mon, bindctx, NULL, &IID_IUnknown, (void**)&unk);
552 if(SUCCEEDED(hres)) {
555 IUnknown_Release(unk);
556 }else if(try_application_url(url)) {
559 FIXME("BindToObject failed: %08x\n", hres);
562 IMoniker_Release(mon);
566 static void html_window_navigate(DocHost *This, IHTMLPrivateWindow *window, BSTR url, BSTR headers, SAFEARRAY *post_data)
568 VARIANT headers_var, post_data_var;
572 hres = set_dochost_url(This, url);
576 empty_str = SysAllocStringLen(NULL, 0);
579 V_VT(&headers_var) = VT_BSTR;
580 V_BSTR(&headers_var) = headers;
582 V_VT(&headers_var) = VT_EMPTY;
586 V_VT(&post_data_var) = VT_UI1|VT_ARRAY;
587 V_ARRAY(&post_data_var) = post_data;
589 V_VT(&post_data_var) = VT_EMPTY;
592 set_doc_state(This, READYSTATE_LOADING);
593 hres = IHTMLPrivateWindow_SuperNavigate(window, url, empty_str, NULL, NULL, &post_data_var, &headers_var, 0);
594 SysFreeString(empty_str);
596 WARN("SuprtNavigate failed: %08x\n", hres);
600 task_header_t header;
603 SAFEARRAY *post_data;
605 } task_doc_navigate_t;
607 static HRESULT free_doc_navigate_task(task_doc_navigate_t *task, BOOL free_task)
609 SysFreeString(task->url);
610 SysFreeString(task->headers);
612 SafeArrayDestroy(task->post_data);
615 return E_OUTOFMEMORY;
618 static void doc_navigate_proc(DocHost *This, task_header_t *t)
620 task_doc_navigate_t *task = (task_doc_navigate_t*)t;
621 IHTMLPrivateWindow *priv_window;
624 if(!This->doc_navigate)
627 if(task->async_notif) {
628 VARIANT_BOOL cancel = VARIANT_FALSE;
629 on_before_navigate2(This, task->url, task->post_data, task->headers, &cancel);
631 TRACE("Navigation calnceled\n");
632 free_doc_navigate_task(task, FALSE);
637 hres = IUnknown_QueryInterface(This->doc_navigate, &IID_IHTMLPrivateWindow, (void**)&priv_window);
638 if(SUCCEEDED(hres)) {
639 html_window_navigate(This, priv_window, task->url, task->headers, task->post_data);
640 IHTMLPrivateWindow_Release(priv_window);
642 WARN("Could not get IHTMLPrivateWindow iface: %08x\n", hres);
645 free_doc_navigate_task(task, FALSE);
648 static HRESULT async_doc_navigate(DocHost *This, LPCWSTR url, LPCWSTR headers, PBYTE post_data, ULONG post_data_size,
651 task_doc_navigate_t *task;
653 task = heap_alloc_zero(sizeof(*task));
655 return E_OUTOFMEMORY;
657 task->url = SysAllocString(url);
659 return free_doc_navigate_task(task, TRUE);
662 task->headers = SysAllocString(headers);
664 return free_doc_navigate_task(task, TRUE);
668 task->post_data = SafeArrayCreateVector(VT_UI1, 0, post_data_size);
670 return free_doc_navigate_task(task, TRUE);
671 memcpy(task->post_data->pvData, post_data, post_data_size);
675 VARIANT_BOOL cancel = VARIANT_FALSE;
677 on_before_navigate2(This, task->url, task->post_data, task->headers, &cancel);
679 TRACE("Navigation calnceled\n");
680 free_doc_navigate_task(task, TRUE);
685 task->async_notif = async_notif;
686 push_dochost_task(This, &task->header, doc_navigate_proc, FALSE);
690 static HRESULT navigate_bsc(DocHost *This, BindStatusCallback *bsc, IMoniker *mon)
692 VARIANT_BOOL cancel = VARIANT_FALSE;
693 SAFEARRAY *post_data = NULL;
697 set_doc_state(This, READYSTATE_LOADING);
700 post_data = SafeArrayCreateVector(VT_UI1, 0, bsc->post_data_len);
701 memcpy(post_data->pvData, post_data, bsc->post_data_len);
704 on_before_navigate2(This, bsc->url, post_data, bsc->headers, &cancel);
706 SafeArrayDestroy(post_data);
708 FIXME("Navigation canceled\n");
713 deactivate_document(This);
715 CreateAsyncBindCtx(0, BINDSC(bsc), 0, &bindctx);
718 IOleInPlaceFrame_EnableModeless(This->frame, FALSE);
720 hres = bind_to_object(This, mon, bsc->url, bindctx, BINDSC(bsc));
723 IOleInPlaceFrame_EnableModeless(This->frame, TRUE);
725 IBindCtx_Release(bindctx);
731 task_header_t header;
732 BindStatusCallback *bsc;
733 } task_navigate_bsc_t;
735 static void navigate_bsc_proc(DocHost *This, task_header_t *t)
737 task_navigate_bsc_t *task = (task_navigate_bsc_t*)t;
740 create_doc_view_hwnd(This);
742 navigate_bsc(This, task->bsc, NULL);
744 IBindStatusCallback_Release(BINDSC(task->bsc));
748 HRESULT navigate_url(DocHost *This, LPCWSTR url, const VARIANT *Flags,
749 const VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers)
751 PBYTE post_data = NULL;
752 ULONG post_data_len = 0;
753 LPWSTR headers = NULL;
756 TRACE("navigating to %s\n", debugstr_w(url));
758 if((Flags && V_VT(Flags) != VT_EMPTY)
759 || (TargetFrameName && V_VT(TargetFrameName) != VT_EMPTY))
760 FIXME("Unsupported args (Flags %p:%d; TargetFrameName %p:%d)\n",
761 Flags, Flags ? V_VT(Flags) : -1, TargetFrameName,
762 TargetFrameName ? V_VT(TargetFrameName) : -1);
764 if(PostData && V_VT(PostData) == (VT_ARRAY | VT_UI1) && V_ARRAY(PostData)) {
765 SafeArrayAccessData(V_ARRAY(PostData), (void**)&post_data);
766 post_data_len = V_ARRAY(PostData)->rgsabound[0].cElements;
769 if(Headers && V_VT(Headers) == VT_BSTR) {
770 headers = V_BSTR(Headers);
771 TRACE("Headers: %s\n", debugstr_w(headers));
774 set_doc_state(This, READYSTATE_LOADING);
775 This->ready_state = READYSTATE_LOADING;
777 if(This->doc_navigate) {
778 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
780 if(PathIsURLW(url)) {
785 size = sizeof(new_url)/sizeof(WCHAR);
786 hres = UrlApplySchemeW(url, new_url, &size,
787 URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT);
789 WARN("UrlApplyScheme failed: %08x\n", hres);
794 hres = async_doc_navigate(This, *new_url ? new_url : url, headers, post_data,
795 post_data_len, TRUE);
797 task_navigate_bsc_t *task;
799 task = heap_alloc(sizeof(*task));
800 task->bsc = create_callback(This, url, post_data, post_data_len, headers);
801 push_dochost_task(This, &task->header, navigate_bsc_proc, This->url == NULL);
805 SafeArrayUnaccessData(V_ARRAY(PostData));
810 static HRESULT navigate_hlink(DocHost *This, IMoniker *mon, IBindCtx *bindctx,
811 IBindStatusCallback *callback)
813 IHttpNegotiate *http_negotiate;
814 BindStatusCallback *bsc;
815 PBYTE post_data = NULL;
816 ULONG post_data_len = 0;
817 LPWSTR headers = NULL, url;
822 hres = IMoniker_GetDisplayName(mon, 0, NULL, &url);
824 FIXME("GetDisplayName failed: %08x\n", hres);
826 hres = IBindStatusCallback_QueryInterface(callback, &IID_IHttpNegotiate,
827 (void**)&http_negotiate);
828 if(SUCCEEDED(hres)) {
829 static const WCHAR null_string[] = {0};
831 IHttpNegotiate_BeginningTransaction(http_negotiate, null_string, null_string, 0,
833 IHttpNegotiate_Release(http_negotiate);
836 memset(&bindinfo, 0, sizeof(bindinfo));
837 bindinfo.cbSize = sizeof(bindinfo);
839 hres = IBindStatusCallback_GetBindInfo(callback, &bindf, &bindinfo);
840 dump_BINDINFO(&bindinfo);
841 if(bindinfo.dwBindVerb == BINDVERB_POST) {
842 post_data_len = bindinfo.cbstgmedData;
844 post_data = bindinfo.stgmedData.u.hGlobal;
847 if(This->doc_navigate) {
848 hres = async_doc_navigate(This, url, headers, post_data, post_data_len, FALSE);
850 bsc = create_callback(This, url, post_data, post_data_len, headers);
851 hres = navigate_bsc(This, bsc, mon);
852 IBindStatusCallback_Release(BINDSC(bsc));
856 CoTaskMemFree(headers);
857 ReleaseBindInfo(&bindinfo);
862 HRESULT go_home(DocHost *This)
865 DWORD res, type, size;
866 WCHAR wszPageName[MAX_PATH];
867 static const WCHAR wszAboutBlank[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
868 static const WCHAR wszStartPage[] = {'S','t','a','r','t',' ','P','a','g','e',0};
869 static const WCHAR wszSubKey[] = {'S','o','f','t','w','a','r','e','\\',
870 'M','i','c','r','o','s','o','f','t','\\',
871 'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\',
874 res = RegOpenKeyW(HKEY_CURRENT_USER, wszSubKey, &hkey);
875 if (res != ERROR_SUCCESS)
876 return navigate_url(This, wszAboutBlank, NULL, NULL, NULL, NULL);
878 size = sizeof(wszPageName);
879 res = RegQueryValueExW(hkey, wszStartPage, NULL, &type, (LPBYTE)wszPageName, &size);
881 if (res != ERROR_SUCCESS || type != REG_SZ)
882 return navigate_url(This, wszAboutBlank, NULL, NULL, NULL, NULL);
884 return navigate_url(This, wszPageName, NULL, NULL, NULL, NULL);
887 #define HLINKFRAME_THIS(iface) DEFINE_THIS(HlinkFrame, IHlinkFrame, iface)
889 static HRESULT WINAPI HlinkFrame_QueryInterface(IHlinkFrame *iface, REFIID riid, void **ppv)
891 HlinkFrame *This = HLINKFRAME_THIS(iface);
892 return IUnknown_QueryInterface(This->outer, riid, ppv);
895 static ULONG WINAPI HlinkFrame_AddRef(IHlinkFrame *iface)
897 HlinkFrame *This = HLINKFRAME_THIS(iface);
898 return IUnknown_AddRef(This->outer);
901 static ULONG WINAPI HlinkFrame_Release(IHlinkFrame *iface)
903 HlinkFrame *This = HLINKFRAME_THIS(iface);
904 return IUnknown_Release(This->outer);
907 static HRESULT WINAPI HlinkFrame_SetBrowseContext(IHlinkFrame *iface,
908 IHlinkBrowseContext *pihlbc)
910 HlinkFrame *This = HLINKFRAME_THIS(iface);
911 FIXME("(%p)->(%p)\n", This, pihlbc);
915 static HRESULT WINAPI HlinkFrame_GetBrowseContext(IHlinkFrame *iface,
916 IHlinkBrowseContext **ppihlbc)
918 HlinkFrame *This = HLINKFRAME_THIS(iface);
919 FIXME("(%p)->(%p)\n", This, ppihlbc);
923 static HRESULT WINAPI HlinkFrame_Navigate(IHlinkFrame *iface, DWORD grfHLNF, LPBC pbc,
924 IBindStatusCallback *pibsc, IHlink *pihlNavigate)
926 HlinkFrame *This = HLINKFRAME_THIS(iface);
928 LPWSTR location = NULL;
930 TRACE("(%p)->(%08x %p %p %p)\n", This, grfHLNF, pbc, pibsc, pihlNavigate);
933 FIXME("unsupported grfHLNF=%08x\n", grfHLNF);
935 /* Windows calls GetTargetFrameName here. */
937 IHlink_GetMonikerReference(pihlNavigate, 1, &mon, &location);
940 FIXME("location = %s\n", debugstr_w(location));
941 CoTaskMemFree(location);
944 /* Windows calls GetHlinkSite here */
946 if(grfHLNF & HLNF_OPENINNEWWINDOW) {
947 FIXME("Not supported HLNF_OPENINNEWWINDOW\n");
951 return navigate_hlink(This->doc_host, mon, pbc, pibsc);
954 static HRESULT WINAPI HlinkFrame_OnNavigate(IHlinkFrame *iface, DWORD grfHLNF,
955 IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName, DWORD dwreserved)
957 HlinkFrame *This = HLINKFRAME_THIS(iface);
958 FIXME("(%p)->(%08x %p %s %s %d)\n", This, grfHLNF, pimkTarget, debugstr_w(pwzLocation),
959 debugstr_w(pwzFriendlyName), dwreserved);
963 static HRESULT WINAPI HlinkFrame_UpdateHlink(IHlinkFrame *iface, ULONG uHLID,
964 IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName)
966 HlinkFrame *This = HLINKFRAME_THIS(iface);
967 FIXME("(%p)->(%u %p %s %s)\n", This, uHLID, pimkTarget, debugstr_w(pwzLocation),
968 debugstr_w(pwzFriendlyName));
972 #undef HLINKFRAME_THIS
974 static const IHlinkFrameVtbl HlinkFrameVtbl = {
975 HlinkFrame_QueryInterface,
978 HlinkFrame_SetBrowseContext,
979 HlinkFrame_GetBrowseContext,
981 HlinkFrame_OnNavigate,
982 HlinkFrame_UpdateHlink
985 #define TARGETFRAME2_THIS(iface) DEFINE_THIS(HlinkFrame, ITargetFrame2, iface)
987 static HRESULT WINAPI TargetFrame2_QueryInterface(ITargetFrame2 *iface, REFIID riid, void **ppv)
989 HlinkFrame *This = TARGETFRAME2_THIS(iface);
990 return IUnknown_QueryInterface(This->outer, riid, ppv);
993 static ULONG WINAPI TargetFrame2_AddRef(ITargetFrame2 *iface)
995 HlinkFrame *This = TARGETFRAME2_THIS(iface);
996 return IUnknown_AddRef(This->outer);
999 static ULONG WINAPI TargetFrame2_Release(ITargetFrame2 *iface)
1001 HlinkFrame *This = TARGETFRAME2_THIS(iface);
1002 return IUnknown_Release(This->outer);
1005 static HRESULT WINAPI TargetFrame2_SetFrameName(ITargetFrame2 *iface, LPCWSTR pszFrameName)
1007 HlinkFrame *This = TARGETFRAME2_THIS(iface);
1008 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFrameName));
1012 static HRESULT WINAPI TargetFrame2_GetFrameName(ITargetFrame2 *iface, LPWSTR *ppszFrameName)
1014 HlinkFrame *This = TARGETFRAME2_THIS(iface);
1015 FIXME("(%p)->(%p)\n", This, ppszFrameName);
1019 static HRESULT WINAPI TargetFrame2_GetParentFrame(ITargetFrame2 *iface, IUnknown **ppunkParent)
1021 HlinkFrame *This = TARGETFRAME2_THIS(iface);
1022 FIXME("(%p)->(%p)\n", This, ppunkParent);
1026 static HRESULT WINAPI TargetFrame2_SetFrameSrc(ITargetFrame2 *iface, LPCWSTR pszFrameSrc)
1028 HlinkFrame *This = TARGETFRAME2_THIS(iface);
1029 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFrameSrc));
1033 static HRESULT WINAPI TargetFrame2_GetFrameSrc(ITargetFrame2 *iface, LPWSTR *ppszFrameSrc)
1035 HlinkFrame *This = TARGETFRAME2_THIS(iface);
1036 FIXME("(%p)->()\n", This);
1040 static HRESULT WINAPI TargetFrame2_GetFramesContainer(ITargetFrame2 *iface, IOleContainer **ppContainer)
1042 HlinkFrame *This = TARGETFRAME2_THIS(iface);
1043 FIXME("(%p)->(%p)\n", This, ppContainer);
1047 static HRESULT WINAPI TargetFrame2_SetFrameOptions(ITargetFrame2 *iface, DWORD dwFlags)
1049 HlinkFrame *This = TARGETFRAME2_THIS(iface);
1050 FIXME("(%p)->(%x)\n", This, dwFlags);
1054 static HRESULT WINAPI TargetFrame2_GetFrameOptions(ITargetFrame2 *iface, DWORD *pdwFlags)
1056 HlinkFrame *This = TARGETFRAME2_THIS(iface);
1057 FIXME("(%p)->(%p)\n", This, pdwFlags);
1061 static HRESULT WINAPI TargetFrame2_SetFrameMargins(ITargetFrame2 *iface, DWORD dwWidth, DWORD dwHeight)
1063 HlinkFrame *This = TARGETFRAME2_THIS(iface);
1064 FIXME("(%p)->(%d %d)\n", This, dwWidth, dwHeight);
1068 static HRESULT WINAPI TargetFrame2_GetFrameMargins(ITargetFrame2 *iface, DWORD *pdwWidth, DWORD *pdwHeight)
1070 HlinkFrame *This = TARGETFRAME2_THIS(iface);
1071 FIXME("(%p)->(%p %p)\n", This, pdwWidth, pdwHeight);
1075 static HRESULT WINAPI TargetFrame2_FindFrame(ITargetFrame2 *iface, LPCWSTR pszTargetName, DWORD dwFlags, IUnknown **ppunkTargetFrame)
1077 HlinkFrame *This = TARGETFRAME2_THIS(iface);
1078 FIXME("(%p)->(%s %x %p)\n", This, debugstr_w(pszTargetName), dwFlags, ppunkTargetFrame);
1082 static HRESULT WINAPI TargetFrame2_GetTargetAlias(ITargetFrame2 *iface, LPCWSTR pszTargetName, LPWSTR *ppszTargetAlias)
1084 HlinkFrame *This = TARGETFRAME2_THIS(iface);
1085 FIXME("(%p)->(%s %p)\n", This, debugstr_w(pszTargetName), ppszTargetAlias);
1089 #undef TARGETFRAME2_THIS
1091 static const ITargetFrame2Vtbl TargetFrame2Vtbl = {
1092 TargetFrame2_QueryInterface,
1093 TargetFrame2_AddRef,
1094 TargetFrame2_Release,
1095 TargetFrame2_SetFrameName,
1096 TargetFrame2_GetFrameName,
1097 TargetFrame2_GetParentFrame,
1098 TargetFrame2_SetFrameSrc,
1099 TargetFrame2_GetFrameSrc,
1100 TargetFrame2_GetFramesContainer,
1101 TargetFrame2_SetFrameOptions,
1102 TargetFrame2_GetFrameOptions,
1103 TargetFrame2_SetFrameMargins,
1104 TargetFrame2_GetFrameMargins,
1105 TargetFrame2_FindFrame,
1106 TargetFrame2_GetTargetAlias
1109 BOOL HlinkFrame_QI(HlinkFrame *This, REFIID riid, void **ppv)
1111 if(IsEqualGUID(&IID_IHlinkFrame, riid)) {
1112 TRACE("(%p)->(IID_IHlinkFrame %p)\n", This, ppv);
1113 *ppv = HLINKFRAME(This);
1114 }else if(IsEqualGUID(&IID_ITargetFrame2, riid)) {
1115 TRACE("(%p)->(IID_ITargetFrame2 %p)\n", This, ppv);
1116 *ppv = TARGETFRAME2(This);
1121 IUnknown_AddRef((IUnknown*)*ppv);
1125 void HlinkFrame_Init(HlinkFrame *This, IUnknown *outer, DocHost *doc_host)
1127 This->lpIHlinkFrameVtbl = &HlinkFrameVtbl;
1128 This->lpITargetFrame2Vtbl = &TargetFrame2Vtbl;
1130 This->outer = outer;
1131 This->doc_host = doc_host;