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 IBindStatusCallback IBindStatusCallback_iface;
38 IHttpNegotiate IHttpNegotiate_iface;
50 static void dump_BINDINFO(BINDINFO *bi)
52 static const char * const BINDINFOF_str[] = {
54 "BINDINFOF_URLENCODESTGMEDDATA",
55 "BINDINFOF_URLENCODEDEXTRAINFO"
58 static const char * const BINDVERB_str[] = {
78 bi->cbSize, debugstr_w(bi->szExtraInfo),
79 bi->stgmedData.tymed, bi->stgmedData.u.hGlobal, bi->stgmedData.pUnkForRelease,
80 bi->grfBindInfoF > BINDINFOF_URLENCODEDEXTRAINFO
81 ? "unknown" : BINDINFOF_str[bi->grfBindInfoF],
82 bi->dwBindVerb > BINDVERB_CUSTOM
83 ? "unknown" : BINDVERB_str[bi->dwBindVerb],
84 debugstr_w(bi->szCustomVerb),
85 bi->cbstgmedData, bi->dwOptions, bi->dwOptionsFlags, bi->dwCodePage,
86 bi->securityAttributes.nLength,
87 bi->securityAttributes.lpSecurityDescriptor,
88 bi->securityAttributes.bInheritHandle,
89 debugstr_guid(&bi->iid),
90 bi->pUnk, bi->dwReserved
94 static void set_status_text(BindStatusCallback *This, LPCWSTR str)
97 DISPPARAMS dispparams = {&arg, NULL, 1, 0};
102 V_VT(&arg) = VT_BSTR;
103 V_BSTR(&arg) = str ? SysAllocString(str) : NULL;
104 call_sink(This->doc_host->cps.wbe2, DISPID_STATUSTEXTCHANGE, &dispparams);
107 if(This->doc_host->frame)
108 IOleInPlaceFrame_SetStatusText(This->doc_host->frame, str);
111 static HRESULT set_dochost_url(DocHost *This, const WCHAR *url)
116 new_url = heap_strdupW(url);
118 return E_OUTOFMEMORY;
123 heap_free(This->url);
126 This->container_vtbl->SetURL(This, This->url);
130 static inline BindStatusCallback *impl_from_IBindStatusCallback(IBindStatusCallback *iface)
132 return CONTAINING_RECORD(iface, BindStatusCallback, IBindStatusCallback_iface);
135 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallback *iface,
136 REFIID riid, void **ppv)
138 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
140 if(IsEqualGUID(&IID_IUnknown, riid)) {
141 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
142 *ppv = &This->IBindStatusCallback_iface;
143 }else if(IsEqualGUID(&IID_IBindStatusCallback, riid)) {
144 TRACE("(%p)->(IID_IBindStatusCallback %p)\n", This, ppv);
145 *ppv = &This->IBindStatusCallback_iface;
146 }else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) {
147 TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This, ppv);
148 *ppv = &This->IHttpNegotiate_iface;
151 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
152 return E_NOINTERFACE;
155 IUnknown_AddRef((IUnknown*)*ppv);
159 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallback *iface)
161 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
162 LONG ref = InterlockedIncrement(&This->ref);
164 TRACE("(%p) ref=%d\n", This, ref);
169 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallback *iface)
171 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
172 LONG ref = InterlockedDecrement(&This->ref);
174 TRACE("(%p) ref=%d\n", This, ref);
178 IOleClientSite_Release(&This->doc_host->IOleClientSite_iface);
180 GlobalFree(This->post_data);
181 SysFreeString(This->headers);
182 heap_free(This->url);
189 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallback *iface,
190 DWORD dwReserved, IBinding *pbind)
192 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
194 TRACE("(%p)->(%d %p)\n", This, dwReserved, pbind);
199 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface,
202 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
203 FIXME("(%p)->(%p)\n", This, pnPriority);
207 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface,
210 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
211 FIXME("(%p)->(%d)\n", This, reserved);
215 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallback *iface,
216 ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
218 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
220 TRACE("(%p)->(%d %d %d %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
221 debugstr_w(szStatusText));
223 switch(ulStatusCode) {
224 case BINDSTATUS_REDIRECTING:
225 return set_dochost_url(This->doc_host, szStatusText);
226 case BINDSTATUS_BEGINDOWNLOADDATA:
227 set_status_text(This, szStatusText); /* FIXME: "Start downloading from site: %s" */
229 case BINDSTATUS_ENDDOWNLOADDATA:
230 set_status_text(This, szStatusText); /* FIXME: "Downloading from site: %s" */
232 case BINDSTATUS_CLASSIDAVAILABLE:
233 case BINDSTATUS_MIMETYPEAVAILABLE:
234 case BINDSTATUS_BEGINSYNCOPERATION:
235 case BINDSTATUS_ENDSYNCOPERATION:
238 FIXME("status code %u\n", ulStatusCode);
244 void handle_navigation_error(DocHost* doc_host, HRESULT hres, BSTR url, IHTMLWindow2 *win2)
246 VARIANT var_status_code, var_frame_name, var_url;
247 DISPPARAMS dispparams;
248 VARIANTARG params[5];
249 VARIANT_BOOL cancel = VARIANT_FALSE;
251 dispparams.cArgs = 5;
252 dispparams.cNamedArgs = 0;
253 dispparams.rgdispidNamedArgs = NULL;
254 dispparams.rgvarg = params;
256 V_VT(params) = VT_BOOL|VT_BYREF;
257 V_BOOLREF(params) = &cancel;
259 V_VT(params+1) = VT_VARIANT|VT_BYREF;
260 V_VARIANTREF(params+1) = &var_status_code;
261 V_VT(&var_status_code) = VT_I4;
262 V_I4(&var_status_code) = hres;
264 V_VT(params+2) = VT_VARIANT|VT_BYREF;
265 V_VARIANTREF(params+2) = &var_frame_name;
266 V_VT(&var_frame_name) = VT_BSTR;
268 hres = IHTMLWindow2_get_name(win2, &V_BSTR(&var_frame_name));
270 V_BSTR(&var_frame_name) = NULL;
272 V_BSTR(&var_frame_name) = NULL;
274 V_VT(params+3) = VT_VARIANT|VT_BYREF;
275 V_VARIANTREF(params+3) = &var_url;
276 V_VT(&var_url) = VT_BSTR;
277 V_BSTR(&var_url) = url;
279 V_VT(params+4) = VT_DISPATCH;
280 V_DISPATCH(params+4) = doc_host->disp;
282 call_sink(doc_host->cps.wbe2, DISPID_NAVIGATEERROR, &dispparams);
283 SysFreeString(V_BSTR(&var_frame_name));
286 FIXME("Navigate to error page\n");
289 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
290 HRESULT hresult, LPCWSTR szError)
292 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
294 TRACE("(%p)->(%08x %s)\n", This, hresult, debugstr_w(szError));
296 set_status_text(This, emptyW);
301 /* FIXME: Check HTTP status code */
303 handle_navigation_error(This->doc_host, hresult, This->url, NULL);
305 IOleClientSite_Release(&This->doc_host->IOleClientSite_iface);
306 This->doc_host = NULL;
311 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
312 DWORD *grfBINDF, BINDINFO *pbindinfo)
314 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
316 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
318 *grfBINDF = BINDF_ASYNCHRONOUS;
320 if(This->post_data) {
321 pbindinfo->dwBindVerb = BINDVERB_POST;
323 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
324 pbindinfo->stgmedData.u.hGlobal = This->post_data;
325 pbindinfo->cbstgmedData = This->post_data_len;
326 pbindinfo->stgmedData.pUnkForRelease = (IUnknown*)&This->IBindStatusCallback_iface;
327 IBindStatusCallback_AddRef(&This->IBindStatusCallback_iface);
333 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
334 DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
336 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
337 FIXME("(%p)->(%08x %d %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed);
341 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
342 REFIID riid, IUnknown *punk)
344 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
346 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), punk);
348 return dochost_object_available(This->doc_host, punk);
351 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
352 BindStatusCallback_QueryInterface,
353 BindStatusCallback_AddRef,
354 BindStatusCallback_Release,
355 BindStatusCallback_OnStartBinding,
356 BindStatusCallback_GetPriority,
357 BindStatusCallback_OnLowResource,
358 BindStatusCallback_OnProgress,
359 BindStatusCallback_OnStopBinding,
360 BindStatusCallback_GetBindInfo,
361 BindStatusCallback_OnDataAvailable,
362 BindStatusCallback_OnObjectAvailable
365 static inline BindStatusCallback *impl_from_IHttpNegotiate(IHttpNegotiate *iface)
367 return CONTAINING_RECORD(iface, BindStatusCallback, IHttpNegotiate_iface);
370 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate *iface,
371 REFIID riid, void **ppv)
373 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
374 return IBindStatusCallback_QueryInterface(&This->IBindStatusCallback_iface, riid, ppv);
377 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate *iface)
379 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
380 return IBindStatusCallback_AddRef(&This->IBindStatusCallback_iface);
383 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate *iface)
385 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
386 return IBindStatusCallback_Release(&This->IBindStatusCallback_iface);
389 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate *iface,
390 LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
392 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
394 TRACE("(%p)->(%s %s %d %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders),
395 dwReserved, pszAdditionalHeaders);
398 int size = (strlenW(This->headers)+1)*sizeof(WCHAR);
399 *pszAdditionalHeaders = CoTaskMemAlloc(size);
400 memcpy(*pszAdditionalHeaders, This->headers, size);
406 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate *iface,
407 DWORD dwResponseCode, LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders,
408 LPWSTR *pszAdditionalRequestHeaders)
410 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
411 TRACE("(%p)->(%d %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
412 debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
416 static const IHttpNegotiateVtbl HttpNegotiateVtbl = {
417 HttpNegotiate_QueryInterface,
418 HttpNegotiate_AddRef,
419 HttpNegotiate_Release,
420 HttpNegotiate_BeginningTransaction,
421 HttpNegotiate_OnResponse
424 static BindStatusCallback *create_callback(DocHost *doc_host, LPCWSTR url, PBYTE post_data,
425 ULONG post_data_len, LPCWSTR headers)
427 BindStatusCallback *ret = heap_alloc(sizeof(BindStatusCallback));
429 ret->IBindStatusCallback_iface.lpVtbl = &BindStatusCallbackVtbl;
430 ret->IHttpNegotiate_iface.lpVtbl = &HttpNegotiateVtbl;
433 ret->url = heap_strdupW(url);
434 ret->post_data = NULL;
435 ret->post_data_len = post_data_len;
436 ret->headers = headers ? SysAllocString(headers) : NULL;
438 ret->doc_host = doc_host;
439 IOleClientSite_AddRef(&doc_host->IOleClientSite_iface);
442 ret->post_data = GlobalAlloc(0, post_data_len);
443 memcpy(ret->post_data, post_data, post_data_len);
449 static void on_before_navigate2(DocHost *This, LPCWSTR url, SAFEARRAY *post_data, LPWSTR headers, VARIANT_BOOL *cancel)
451 VARIANT var_url, var_flags, var_frame_name, var_post_data, var_post_data2, var_headers;
452 DISPPARAMS dispparams;
453 VARIANTARG params[7];
455 dispparams.cArgs = 7;
456 dispparams.cNamedArgs = 0;
457 dispparams.rgdispidNamedArgs = NULL;
458 dispparams.rgvarg = params;
460 This->busy = VARIANT_TRUE;
462 V_VT(params) = VT_BOOL|VT_BYREF;
463 V_BOOLREF(params) = cancel;
465 V_VT(params+1) = (VT_BYREF|VT_VARIANT);
466 V_VARIANTREF(params+1) = &var_headers;
467 V_VT(&var_headers) = VT_BSTR;
468 V_BSTR(&var_headers) = headers;
470 V_VT(params+2) = (VT_BYREF|VT_VARIANT);
471 V_VARIANTREF(params+2) = &var_post_data2;
472 V_VT(&var_post_data2) = (VT_BYREF|VT_VARIANT);
473 V_VARIANTREF(&var_post_data2) = &var_post_data;
476 V_VT(&var_post_data) = VT_UI1|VT_ARRAY;
477 V_ARRAY(&var_post_data) = post_data;
479 V_VT(&var_post_data) = VT_EMPTY;
482 V_VT(params+3) = (VT_BYREF|VT_VARIANT);
483 V_VARIANTREF(params+3) = &var_frame_name;
484 V_VT(&var_frame_name) = VT_BSTR;
485 V_BSTR(&var_frame_name) = NULL;
487 V_VT(params+4) = (VT_BYREF|VT_VARIANT);
488 V_VARIANTREF(params+4) = &var_flags;
489 V_VT(&var_flags) = VT_I4;
490 V_I4(&var_flags) = 0;
492 V_VT(params+5) = (VT_BYREF|VT_VARIANT);
493 V_VARIANTREF(params+5) = &var_url;
494 V_VT(&var_url) = VT_BSTR;
495 V_BSTR(&var_url) = SysAllocString(url);
497 V_VT(params+6) = (VT_DISPATCH);
498 V_DISPATCH(params+6) = This->disp;
500 call_sink(This->cps.wbe2, DISPID_BEFORENAVIGATE2, &dispparams);
502 SysFreeString(V_BSTR(&var_url));
505 /* FIXME: urlmon should handle it */
506 static BOOL try_application_url(LPCWSTR url)
508 SHELLEXECUTEINFOW exec_info;
514 static const WCHAR wszURLProtocol[] = {'U','R','L',' ','P','r','o','t','o','c','o','l',0};
516 hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, app, sizeof(app)/sizeof(WCHAR), NULL, 0);
520 res = RegOpenKeyW(HKEY_CLASSES_ROOT, app, &hkey);
521 if(res != ERROR_SUCCESS)
524 res = RegQueryValueExW(hkey, wszURLProtocol, NULL, &type, NULL, NULL);
526 if(res != ERROR_SUCCESS || type != REG_SZ)
529 TRACE("openning application %s\n", debugstr_w(app));
531 memset(&exec_info, 0, sizeof(exec_info));
532 exec_info.cbSize = sizeof(exec_info);
533 exec_info.lpFile = url;
534 exec_info.nShow = SW_SHOW;
536 return ShellExecuteExW(&exec_info);
539 static HRESULT create_moniker(LPCWSTR url, IMoniker **mon)
541 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
546 return CreateURLMoniker(NULL, url, mon);
549 size = sizeof(new_url);
550 hres = UrlCreateFromPathW(url, new_url, &size, 0);
552 WARN("UrlCreateFromPathW failed: %08x\n", hres);
556 size = sizeof(new_url)/sizeof(WCHAR);
557 hres = UrlApplySchemeW(url, new_url, &size, URL_APPLY_GUESSSCHEME);
558 TRACE("got %s\n", debugstr_w(new_url));
560 WARN("UrlApplyScheme failed: %08x\n", hres);
565 return CreateURLMoniker(NULL, new_url, mon);
568 static HRESULT bind_to_object(DocHost *This, IMoniker *mon, LPCWSTR url, IBindCtx *bindctx,
569 IBindStatusCallback *callback)
571 IUnknown *unk = NULL;
576 IMoniker_AddRef(mon);
578 hres = create_moniker(url, &mon);
583 hres = IMoniker_GetDisplayName(mon, 0, NULL, &display_name);
585 FIXME("GetDisplayName failed: %08x\n", hres);
589 hres = set_dochost_url(This, display_name);
590 CoTaskMemFree(display_name);
594 IBindCtx_RegisterObjectParam(bindctx, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM,
595 (IUnknown*)&This->IOleClientSite_iface);
597 hres = IMoniker_BindToObject(mon, bindctx, NULL, &IID_IUnknown, (void**)&unk);
598 if(SUCCEEDED(hres)) {
601 IUnknown_Release(unk);
602 }else if(try_application_url(url)) {
605 FIXME("BindToObject failed: %08x\n", hres);
608 IMoniker_Release(mon);
612 static void html_window_navigate(DocHost *This, IHTMLPrivateWindow *window, BSTR url, BSTR headers, SAFEARRAY *post_data)
614 VARIANT headers_var, post_data_var;
618 hres = set_dochost_url(This, url);
622 empty_str = SysAllocStringLen(NULL, 0);
625 V_VT(&headers_var) = VT_BSTR;
626 V_BSTR(&headers_var) = headers;
628 V_VT(&headers_var) = VT_EMPTY;
632 V_VT(&post_data_var) = VT_UI1|VT_ARRAY;
633 V_ARRAY(&post_data_var) = post_data;
635 V_VT(&post_data_var) = VT_EMPTY;
638 set_doc_state(This, READYSTATE_LOADING);
639 hres = IHTMLPrivateWindow_SuperNavigate(window, url, empty_str, NULL, NULL, &post_data_var, &headers_var, 0);
640 SysFreeString(empty_str);
642 WARN("SuprtNavigate failed: %08x\n", hres);
646 task_header_t header;
649 SAFEARRAY *post_data;
651 } task_doc_navigate_t;
653 static HRESULT free_doc_navigate_task(task_doc_navigate_t *task, BOOL free_task)
655 SysFreeString(task->url);
656 SysFreeString(task->headers);
658 SafeArrayDestroy(task->post_data);
661 return E_OUTOFMEMORY;
664 static void doc_navigate_proc(DocHost *This, task_header_t *t)
666 task_doc_navigate_t *task = (task_doc_navigate_t*)t;
667 IHTMLPrivateWindow *priv_window;
670 if(!This->doc_navigate)
673 if(task->async_notif) {
674 VARIANT_BOOL cancel = VARIANT_FALSE;
675 on_before_navigate2(This, task->url, task->post_data, task->headers, &cancel);
677 TRACE("Navigation calnceled\n");
678 free_doc_navigate_task(task, FALSE);
683 hres = IUnknown_QueryInterface(This->doc_navigate, &IID_IHTMLPrivateWindow, (void**)&priv_window);
684 if(SUCCEEDED(hres)) {
685 html_window_navigate(This, priv_window, task->url, task->headers, task->post_data);
686 IHTMLPrivateWindow_Release(priv_window);
688 WARN("Could not get IHTMLPrivateWindow iface: %08x\n", hres);
691 free_doc_navigate_task(task, FALSE);
694 static HRESULT async_doc_navigate(DocHost *This, LPCWSTR url, LPCWSTR headers, PBYTE post_data, ULONG post_data_size,
697 task_doc_navigate_t *task;
699 task = heap_alloc_zero(sizeof(*task));
701 return E_OUTOFMEMORY;
703 task->url = SysAllocString(url);
705 return free_doc_navigate_task(task, TRUE);
708 task->headers = SysAllocString(headers);
710 return free_doc_navigate_task(task, TRUE);
714 task->post_data = SafeArrayCreateVector(VT_UI1, 0, post_data_size);
716 return free_doc_navigate_task(task, TRUE);
717 memcpy(task->post_data->pvData, post_data, post_data_size);
721 VARIANT_BOOL cancel = VARIANT_FALSE;
723 on_before_navigate2(This, task->url, task->post_data, task->headers, &cancel);
725 TRACE("Navigation calnceled\n");
726 free_doc_navigate_task(task, TRUE);
731 task->async_notif = async_notif;
732 push_dochost_task(This, &task->header, doc_navigate_proc, FALSE);
736 static HRESULT navigate_bsc(DocHost *This, BindStatusCallback *bsc, IMoniker *mon)
738 VARIANT_BOOL cancel = VARIANT_FALSE;
739 SAFEARRAY *post_data = NULL;
743 set_doc_state(This, READYSTATE_LOADING);
746 post_data = SafeArrayCreateVector(VT_UI1, 0, bsc->post_data_len);
747 memcpy(post_data->pvData, post_data, bsc->post_data_len);
750 on_before_navigate2(This, bsc->url, post_data, bsc->headers, &cancel);
752 SafeArrayDestroy(post_data);
754 FIXME("Navigation canceled\n");
759 deactivate_document(This);
761 CreateAsyncBindCtx(0, &bsc->IBindStatusCallback_iface, 0, &bindctx);
764 IOleInPlaceFrame_EnableModeless(This->frame, FALSE);
766 hres = bind_to_object(This, mon, bsc->url, bindctx, &bsc->IBindStatusCallback_iface);
769 IOleInPlaceFrame_EnableModeless(This->frame, TRUE);
771 IBindCtx_Release(bindctx);
777 task_header_t header;
778 BindStatusCallback *bsc;
779 } task_navigate_bsc_t;
781 static void navigate_bsc_proc(DocHost *This, task_header_t *t)
783 task_navigate_bsc_t *task = (task_navigate_bsc_t*)t;
786 create_doc_view_hwnd(This);
788 navigate_bsc(This, task->bsc, NULL);
790 IBindStatusCallback_Release(&task->bsc->IBindStatusCallback_iface);
794 HRESULT navigate_url(DocHost *This, LPCWSTR url, const VARIANT *Flags,
795 const VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers)
797 PBYTE post_data = NULL;
798 ULONG post_data_len = 0;
799 LPWSTR headers = NULL;
802 TRACE("navigating to %s\n", debugstr_w(url));
804 if((Flags && V_VT(Flags) != VT_EMPTY)
805 || (TargetFrameName && V_VT(TargetFrameName) != VT_EMPTY))
806 FIXME("Unsupported args (Flags %p:%d; TargetFrameName %p:%d)\n",
807 Flags, Flags ? V_VT(Flags) : -1, TargetFrameName,
808 TargetFrameName ? V_VT(TargetFrameName) : -1);
810 if(PostData && V_VT(PostData) == (VT_ARRAY | VT_UI1) && V_ARRAY(PostData)) {
811 SafeArrayAccessData(V_ARRAY(PostData), (void**)&post_data);
812 post_data_len = V_ARRAY(PostData)->rgsabound[0].cElements;
815 if(Headers && V_VT(Headers) == VT_BSTR) {
816 headers = V_BSTR(Headers);
817 TRACE("Headers: %s\n", debugstr_w(headers));
820 set_doc_state(This, READYSTATE_LOADING);
821 This->ready_state = READYSTATE_LOADING;
823 if(This->doc_navigate) {
824 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
826 if(PathIsURLW(url)) {
831 size = sizeof(new_url)/sizeof(WCHAR);
832 hres = UrlApplySchemeW(url, new_url, &size,
833 URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT);
835 WARN("UrlApplyScheme failed: %08x\n", hres);
840 hres = async_doc_navigate(This, *new_url ? new_url : url, headers, post_data,
841 post_data_len, TRUE);
843 task_navigate_bsc_t *task;
845 task = heap_alloc(sizeof(*task));
846 task->bsc = create_callback(This, url, post_data, post_data_len, headers);
847 push_dochost_task(This, &task->header, navigate_bsc_proc, This->url == NULL);
851 SafeArrayUnaccessData(V_ARRAY(PostData));
856 static HRESULT navigate_hlink(DocHost *This, IMoniker *mon, IBindCtx *bindctx,
857 IBindStatusCallback *callback)
859 IHttpNegotiate *http_negotiate;
860 BindStatusCallback *bsc;
861 PBYTE post_data = NULL;
862 ULONG post_data_len = 0;
863 LPWSTR headers = NULL, url;
868 hres = IMoniker_GetDisplayName(mon, 0, NULL, &url);
870 FIXME("GetDisplayName failed: %08x\n", hres);
872 hres = IBindStatusCallback_QueryInterface(callback, &IID_IHttpNegotiate,
873 (void**)&http_negotiate);
874 if(SUCCEEDED(hres)) {
875 static const WCHAR null_string[] = {0};
877 IHttpNegotiate_BeginningTransaction(http_negotiate, null_string, null_string, 0,
879 IHttpNegotiate_Release(http_negotiate);
882 memset(&bindinfo, 0, sizeof(bindinfo));
883 bindinfo.cbSize = sizeof(bindinfo);
885 hres = IBindStatusCallback_GetBindInfo(callback, &bindf, &bindinfo);
886 dump_BINDINFO(&bindinfo);
887 if(bindinfo.dwBindVerb == BINDVERB_POST) {
888 post_data_len = bindinfo.cbstgmedData;
890 post_data = bindinfo.stgmedData.u.hGlobal;
893 if(This->doc_navigate) {
894 hres = async_doc_navigate(This, url, headers, post_data, post_data_len, FALSE);
896 bsc = create_callback(This, url, post_data, post_data_len, headers);
897 hres = navigate_bsc(This, bsc, mon);
898 IBindStatusCallback_Release(&bsc->IBindStatusCallback_iface);
902 CoTaskMemFree(headers);
903 ReleaseBindInfo(&bindinfo);
908 HRESULT go_home(DocHost *This)
911 DWORD res, type, size;
912 WCHAR wszPageName[MAX_PATH];
913 static const WCHAR wszAboutBlank[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
914 static const WCHAR wszStartPage[] = {'S','t','a','r','t',' ','P','a','g','e',0};
915 static const WCHAR wszSubKey[] = {'S','o','f','t','w','a','r','e','\\',
916 'M','i','c','r','o','s','o','f','t','\\',
917 'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\',
920 res = RegOpenKeyW(HKEY_CURRENT_USER, wszSubKey, &hkey);
921 if (res != ERROR_SUCCESS)
922 return navigate_url(This, wszAboutBlank, NULL, NULL, NULL, NULL);
924 size = sizeof(wszPageName);
925 res = RegQueryValueExW(hkey, wszStartPage, NULL, &type, (LPBYTE)wszPageName, &size);
927 if (res != ERROR_SUCCESS || type != REG_SZ)
928 return navigate_url(This, wszAboutBlank, NULL, NULL, NULL, NULL);
930 return navigate_url(This, wszPageName, NULL, NULL, NULL, NULL);
933 HRESULT get_location_url(DocHost *This, BSTR *ret)
935 FIXME("semi-stub\n");
937 *ret = This->url ? SysAllocString(This->url) : SysAllocStringLen(NULL, 0);
939 return E_OUTOFMEMORY;
941 return This->url ? S_OK : S_FALSE;
944 static inline HlinkFrame *impl_from_IHlinkFrame(IHlinkFrame *iface)
946 return CONTAINING_RECORD(iface, HlinkFrame, IHlinkFrame_iface);
949 static HRESULT WINAPI HlinkFrame_QueryInterface(IHlinkFrame *iface, REFIID riid, void **ppv)
951 HlinkFrame *This = impl_from_IHlinkFrame(iface);
952 return IUnknown_QueryInterface(This->outer, riid, ppv);
955 static ULONG WINAPI HlinkFrame_AddRef(IHlinkFrame *iface)
957 HlinkFrame *This = impl_from_IHlinkFrame(iface);
958 return IUnknown_AddRef(This->outer);
961 static ULONG WINAPI HlinkFrame_Release(IHlinkFrame *iface)
963 HlinkFrame *This = impl_from_IHlinkFrame(iface);
964 return IUnknown_Release(This->outer);
967 static HRESULT WINAPI HlinkFrame_SetBrowseContext(IHlinkFrame *iface,
968 IHlinkBrowseContext *pihlbc)
970 HlinkFrame *This = impl_from_IHlinkFrame(iface);
971 FIXME("(%p)->(%p)\n", This, pihlbc);
975 static HRESULT WINAPI HlinkFrame_GetBrowseContext(IHlinkFrame *iface,
976 IHlinkBrowseContext **ppihlbc)
978 HlinkFrame *This = impl_from_IHlinkFrame(iface);
979 FIXME("(%p)->(%p)\n", This, ppihlbc);
983 static HRESULT WINAPI HlinkFrame_Navigate(IHlinkFrame *iface, DWORD grfHLNF, LPBC pbc,
984 IBindStatusCallback *pibsc, IHlink *pihlNavigate)
986 HlinkFrame *This = impl_from_IHlinkFrame(iface);
988 LPWSTR location = NULL;
990 TRACE("(%p)->(%08x %p %p %p)\n", This, grfHLNF, pbc, pibsc, pihlNavigate);
993 FIXME("unsupported grfHLNF=%08x\n", grfHLNF);
995 /* Windows calls GetTargetFrameName here. */
997 IHlink_GetMonikerReference(pihlNavigate, 1, &mon, &location);
1000 FIXME("location = %s\n", debugstr_w(location));
1001 CoTaskMemFree(location);
1004 /* Windows calls GetHlinkSite here */
1006 if(grfHLNF & HLNF_OPENINNEWWINDOW) {
1007 FIXME("Not supported HLNF_OPENINNEWWINDOW\n");
1011 return navigate_hlink(This->doc_host, mon, pbc, pibsc);
1014 static HRESULT WINAPI HlinkFrame_OnNavigate(IHlinkFrame *iface, DWORD grfHLNF,
1015 IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName, DWORD dwreserved)
1017 HlinkFrame *This = impl_from_IHlinkFrame(iface);
1018 FIXME("(%p)->(%08x %p %s %s %d)\n", This, grfHLNF, pimkTarget, debugstr_w(pwzLocation),
1019 debugstr_w(pwzFriendlyName), dwreserved);
1023 static HRESULT WINAPI HlinkFrame_UpdateHlink(IHlinkFrame *iface, ULONG uHLID,
1024 IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName)
1026 HlinkFrame *This = impl_from_IHlinkFrame(iface);
1027 FIXME("(%p)->(%u %p %s %s)\n", This, uHLID, pimkTarget, debugstr_w(pwzLocation),
1028 debugstr_w(pwzFriendlyName));
1032 static const IHlinkFrameVtbl HlinkFrameVtbl = {
1033 HlinkFrame_QueryInterface,
1036 HlinkFrame_SetBrowseContext,
1037 HlinkFrame_GetBrowseContext,
1038 HlinkFrame_Navigate,
1039 HlinkFrame_OnNavigate,
1040 HlinkFrame_UpdateHlink
1043 static inline HlinkFrame *impl_from_ITargetFrame2(ITargetFrame2 *iface)
1045 return CONTAINING_RECORD(iface, HlinkFrame, IHlinkFrame_iface);
1048 static HRESULT WINAPI TargetFrame2_QueryInterface(ITargetFrame2 *iface, REFIID riid, void **ppv)
1050 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1051 return IUnknown_QueryInterface(This->outer, riid, ppv);
1054 static ULONG WINAPI TargetFrame2_AddRef(ITargetFrame2 *iface)
1056 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1057 return IUnknown_AddRef(This->outer);
1060 static ULONG WINAPI TargetFrame2_Release(ITargetFrame2 *iface)
1062 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1063 return IUnknown_Release(This->outer);
1066 static HRESULT WINAPI TargetFrame2_SetFrameName(ITargetFrame2 *iface, LPCWSTR pszFrameName)
1068 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1069 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFrameName));
1073 static HRESULT WINAPI TargetFrame2_GetFrameName(ITargetFrame2 *iface, LPWSTR *ppszFrameName)
1075 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1076 FIXME("(%p)->(%p)\n", This, ppszFrameName);
1080 static HRESULT WINAPI TargetFrame2_GetParentFrame(ITargetFrame2 *iface, IUnknown **ppunkParent)
1082 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1083 FIXME("(%p)->(%p)\n", This, ppunkParent);
1087 static HRESULT WINAPI TargetFrame2_SetFrameSrc(ITargetFrame2 *iface, LPCWSTR pszFrameSrc)
1089 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1090 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFrameSrc));
1094 static HRESULT WINAPI TargetFrame2_GetFrameSrc(ITargetFrame2 *iface, LPWSTR *ppszFrameSrc)
1096 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1097 FIXME("(%p)->()\n", This);
1101 static HRESULT WINAPI TargetFrame2_GetFramesContainer(ITargetFrame2 *iface, IOleContainer **ppContainer)
1103 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1104 FIXME("(%p)->(%p)\n", This, ppContainer);
1108 static HRESULT WINAPI TargetFrame2_SetFrameOptions(ITargetFrame2 *iface, DWORD dwFlags)
1110 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1111 FIXME("(%p)->(%x)\n", This, dwFlags);
1115 static HRESULT WINAPI TargetFrame2_GetFrameOptions(ITargetFrame2 *iface, DWORD *pdwFlags)
1117 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1118 FIXME("(%p)->(%p)\n", This, pdwFlags);
1122 static HRESULT WINAPI TargetFrame2_SetFrameMargins(ITargetFrame2 *iface, DWORD dwWidth, DWORD dwHeight)
1124 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1125 FIXME("(%p)->(%d %d)\n", This, dwWidth, dwHeight);
1129 static HRESULT WINAPI TargetFrame2_GetFrameMargins(ITargetFrame2 *iface, DWORD *pdwWidth, DWORD *pdwHeight)
1131 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1132 FIXME("(%p)->(%p %p)\n", This, pdwWidth, pdwHeight);
1136 static HRESULT WINAPI TargetFrame2_FindFrame(ITargetFrame2 *iface, LPCWSTR pszTargetName, DWORD dwFlags, IUnknown **ppunkTargetFrame)
1138 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1139 FIXME("(%p)->(%s %x %p)\n", This, debugstr_w(pszTargetName), dwFlags, ppunkTargetFrame);
1143 static HRESULT WINAPI TargetFrame2_GetTargetAlias(ITargetFrame2 *iface, LPCWSTR pszTargetName, LPWSTR *ppszTargetAlias)
1145 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1146 FIXME("(%p)->(%s %p)\n", This, debugstr_w(pszTargetName), ppszTargetAlias);
1150 static const ITargetFrame2Vtbl TargetFrame2Vtbl = {
1151 TargetFrame2_QueryInterface,
1152 TargetFrame2_AddRef,
1153 TargetFrame2_Release,
1154 TargetFrame2_SetFrameName,
1155 TargetFrame2_GetFrameName,
1156 TargetFrame2_GetParentFrame,
1157 TargetFrame2_SetFrameSrc,
1158 TargetFrame2_GetFrameSrc,
1159 TargetFrame2_GetFramesContainer,
1160 TargetFrame2_SetFrameOptions,
1161 TargetFrame2_GetFrameOptions,
1162 TargetFrame2_SetFrameMargins,
1163 TargetFrame2_GetFrameMargins,
1164 TargetFrame2_FindFrame,
1165 TargetFrame2_GetTargetAlias
1168 BOOL HlinkFrame_QI(HlinkFrame *This, REFIID riid, void **ppv)
1170 if(IsEqualGUID(&IID_IHlinkFrame, riid)) {
1171 TRACE("(%p)->(IID_IHlinkFrame %p)\n", This, ppv);
1172 *ppv = &This->IHlinkFrame_iface;
1173 }else if(IsEqualGUID(&IID_ITargetFrame2, riid)) {
1174 TRACE("(%p)->(IID_ITargetFrame2 %p)\n", This, ppv);
1175 *ppv = &This->ITargetFrame2_iface;
1180 IUnknown_AddRef((IUnknown*)*ppv);
1184 void HlinkFrame_Init(HlinkFrame *This, IUnknown *outer, DocHost *doc_host)
1186 This->IHlinkFrame_iface.lpVtbl = &HlinkFrameVtbl;
1187 This->ITargetFrame2_iface.lpVtbl = &TargetFrame2Vtbl;
1189 This->outer = outer;
1190 This->doc_host = doc_host;