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 #define BINDSC_THIS(iface) DEFINE_THIS(BindStatusCallback, BindStatusCallback, iface)
116 static HRESULT WINAPI
BindStatusCallback_QueryInterface(IBindStatusCallback
*iface
,
117 REFIID riid
, void **ppv
)
119 BindStatusCallback
*This
= BINDSC_THIS(iface
);
123 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
124 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
126 }else if(IsEqualGUID(&IID_IBindStatusCallback
, riid
)) {
127 TRACE("(%p)->(IID_IBindStatusCallback %p)\n", This
, ppv
);
129 }else if(IsEqualGUID(&IID_IHttpNegotiate
, riid
)) {
130 TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This
, ppv
);
131 *ppv
= HTTPNEG(This
);
135 IBindStatusCallback_AddRef(BINDSC(This
));
139 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
140 return E_NOINTERFACE
;
143 static ULONG WINAPI
BindStatusCallback_AddRef(IBindStatusCallback
*iface
)
145 BindStatusCallback
*This
= BINDSC_THIS(iface
);
146 LONG ref
= InterlockedIncrement(&This
->ref
);
148 TRACE("(%p) ref=%d\n", This
, ref
);
153 static ULONG WINAPI
BindStatusCallback_Release(IBindStatusCallback
*iface
)
155 BindStatusCallback
*This
= BINDSC_THIS(iface
);
156 LONG ref
= InterlockedDecrement(&This
->ref
);
158 TRACE("(%p) ref=%d\n", This
, ref
);
162 IOleClientSite_Release(CLIENTSITE(This
->doc_host
));
164 GlobalFree(This
->post_data
);
165 SysFreeString(This
->headers
);
166 heap_free(This
->url
);
173 static HRESULT WINAPI
BindStatusCallback_OnStartBinding(IBindStatusCallback
*iface
,
174 DWORD dwReserved
, IBinding
*pbind
)
176 BindStatusCallback
*This
= BINDSC_THIS(iface
);
178 TRACE("(%p)->(%d %p)\n", This
, dwReserved
, pbind
);
183 static HRESULT WINAPI
BindStatusCallback_GetPriority(IBindStatusCallback
*iface
,
186 BindStatusCallback
*This
= BINDSC_THIS(iface
);
187 FIXME("(%p)->(%p)\n", This
, pnPriority
);
191 static HRESULT WINAPI
BindStatusCallback_OnLowResource(IBindStatusCallback
*iface
,
194 BindStatusCallback
*This
= BINDSC_THIS(iface
);
195 FIXME("(%p)->(%d)\n", This
, reserved
);
199 static HRESULT WINAPI
BindStatusCallback_OnProgress(IBindStatusCallback
*iface
,
200 ULONG ulProgress
, ULONG ulProgressMax
, ULONG ulStatusCode
, LPCWSTR szStatusText
)
202 BindStatusCallback
*This
= BINDSC_THIS(iface
);
204 TRACE("(%p)->(%d %d %d %s)\n", This
, ulProgress
, ulProgressMax
, ulStatusCode
,
205 debugstr_w(szStatusText
));
207 switch(ulStatusCode
) {
208 case BINDSTATUS_BEGINDOWNLOADDATA
:
209 set_status_text(This
, szStatusText
); /* FIXME: "Start downloading from site: %s" */
211 case BINDSTATUS_ENDDOWNLOADDATA
:
212 set_status_text(This
, szStatusText
); /* FIXME: "Downloading from site: %s" */
214 case BINDSTATUS_CLASSIDAVAILABLE
:
215 case BINDSTATUS_MIMETYPEAVAILABLE
:
216 case BINDSTATUS_BEGINSYNCOPERATION
:
217 case BINDSTATUS_ENDSYNCOPERATION
:
220 FIXME("status code %u\n", ulStatusCode
);
226 static HRESULT WINAPI
BindStatusCallback_OnStopBinding(IBindStatusCallback
*iface
,
227 HRESULT hresult
, LPCWSTR szError
)
229 BindStatusCallback
*This
= BINDSC_THIS(iface
);
231 TRACE("(%p)->(%08x %s)\n", This
, hresult
, debugstr_w(szError
));
233 set_status_text(This
, emptyW
);
236 IOleClientSite_Release(CLIENTSITE(This
->doc_host
));
237 This
->doc_host
= NULL
;
243 static HRESULT WINAPI
BindStatusCallback_GetBindInfo(IBindStatusCallback
*iface
,
244 DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
246 BindStatusCallback
*This
= BINDSC_THIS(iface
);
248 TRACE("(%p)->(%p %p)\n", This
, grfBINDF
, pbindinfo
);
250 *grfBINDF
= BINDF_ASYNCHRONOUS
;
252 if(This
->post_data
) {
253 pbindinfo
->dwBindVerb
= BINDVERB_POST
;
255 pbindinfo
->stgmedData
.tymed
= TYMED_HGLOBAL
;
256 pbindinfo
->stgmedData
.u
.hGlobal
= This
->post_data
;
257 pbindinfo
->cbstgmedData
= This
->post_data_len
;
258 pbindinfo
->stgmedData
.pUnkForRelease
= (IUnknown
*)BINDSC(This
);
259 IBindStatusCallback_AddRef(BINDSC(This
));
265 static HRESULT WINAPI
BindStatusCallback_OnDataAvailable(IBindStatusCallback
*iface
,
266 DWORD grfBSCF
, DWORD dwSize
, FORMATETC
*pformatetc
, STGMEDIUM
*pstgmed
)
268 BindStatusCallback
*This
= BINDSC_THIS(iface
);
269 FIXME("(%p)->(%08x %d %p %p)\n", This
, grfBSCF
, dwSize
, pformatetc
, pstgmed
);
273 static HRESULT WINAPI
BindStatusCallback_OnObjectAvailable(IBindStatusCallback
*iface
,
274 REFIID riid
, IUnknown
*punk
)
276 BindStatusCallback
*This
= BINDSC_THIS(iface
);
278 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), punk
);
280 return dochost_object_available(This
->doc_host
, punk
);
285 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl
= {
286 BindStatusCallback_QueryInterface
,
287 BindStatusCallback_AddRef
,
288 BindStatusCallback_Release
,
289 BindStatusCallback_OnStartBinding
,
290 BindStatusCallback_GetPriority
,
291 BindStatusCallback_OnLowResource
,
292 BindStatusCallback_OnProgress
,
293 BindStatusCallback_OnStopBinding
,
294 BindStatusCallback_GetBindInfo
,
295 BindStatusCallback_OnDataAvailable
,
296 BindStatusCallback_OnObjectAvailable
299 #define HTTPNEG_THIS(iface) DEFINE_THIS(BindStatusCallback, HttpNegotiate, iface)
301 static HRESULT WINAPI
HttpNegotiate_QueryInterface(IHttpNegotiate
*iface
,
302 REFIID riid
, void **ppv
)
304 BindStatusCallback
*This
= HTTPNEG_THIS(iface
);
305 return IBindStatusCallback_QueryInterface(BINDSC(This
), riid
, ppv
);
308 static ULONG WINAPI
HttpNegotiate_AddRef(IHttpNegotiate
*iface
)
310 BindStatusCallback
*This
= HTTPNEG_THIS(iface
);
311 return IBindStatusCallback_AddRef(BINDSC(This
));
314 static ULONG WINAPI
HttpNegotiate_Release(IHttpNegotiate
*iface
)
316 BindStatusCallback
*This
= HTTPNEG_THIS(iface
);
317 return IBindStatusCallback_Release(BINDSC(This
));
320 static HRESULT WINAPI
HttpNegotiate_BeginningTransaction(IHttpNegotiate
*iface
,
321 LPCWSTR szURL
, LPCWSTR szHeaders
, DWORD dwReserved
, LPWSTR
*pszAdditionalHeaders
)
323 BindStatusCallback
*This
= HTTPNEG_THIS(iface
);
325 TRACE("(%p)->(%s %s %d %p)\n", This
, debugstr_w(szURL
), debugstr_w(szHeaders
),
326 dwReserved
, pszAdditionalHeaders
);
329 int size
= (strlenW(This
->headers
)+1)*sizeof(WCHAR
);
330 *pszAdditionalHeaders
= CoTaskMemAlloc(size
);
331 memcpy(*pszAdditionalHeaders
, This
->headers
, size
);
337 static HRESULT WINAPI
HttpNegotiate_OnResponse(IHttpNegotiate
*iface
,
338 DWORD dwResponseCode
, LPCWSTR szResponseHeaders
, LPCWSTR szRequestHeaders
,
339 LPWSTR
*pszAdditionalRequestHeaders
)
341 BindStatusCallback
*This
= HTTPNEG_THIS(iface
);
342 TRACE("(%p)->(%d %s %s %p)\n", This
, dwResponseCode
, debugstr_w(szResponseHeaders
),
343 debugstr_w(szRequestHeaders
), pszAdditionalRequestHeaders
);
349 static const IHttpNegotiateVtbl HttpNegotiateVtbl
= {
350 HttpNegotiate_QueryInterface
,
351 HttpNegotiate_AddRef
,
352 HttpNegotiate_Release
,
353 HttpNegotiate_BeginningTransaction
,
354 HttpNegotiate_OnResponse
357 static BindStatusCallback
*create_callback(DocHost
*doc_host
, LPCWSTR url
, PBYTE post_data
,
358 ULONG post_data_len
, LPCWSTR headers
)
360 BindStatusCallback
*ret
= heap_alloc(sizeof(BindStatusCallback
));
362 ret
->lpBindStatusCallbackVtbl
= &BindStatusCallbackVtbl
;
363 ret
->lpHttpNegotiateVtbl
= &HttpNegotiateVtbl
;
366 ret
->url
= heap_strdupW(url
);
367 ret
->post_data
= NULL
;
368 ret
->post_data_len
= post_data_len
;
369 ret
->headers
= headers
? SysAllocString(headers
) : NULL
;
371 ret
->doc_host
= doc_host
;
372 IOleClientSite_AddRef(CLIENTSITE(doc_host
));
375 ret
->post_data
= GlobalAlloc(0, post_data_len
);
376 memcpy(ret
->post_data
, post_data
, post_data_len
);
382 static void on_before_navigate2(DocHost
*This
, LPCWSTR url
, SAFEARRAY
*post_data
, 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
;
409 V_VT(&var_post_data
) = VT_UI1
|VT_ARRAY
;
410 V_ARRAY(&var_post_data
) = post_data
;
412 V_VT(&var_post_data
) = VT_EMPTY
;
415 V_VT(params
+3) = (VT_BYREF
|VT_VARIANT
);
416 V_VARIANTREF(params
+3) = &var_frame_name
;
417 V_VT(&var_frame_name
) = VT_BSTR
;
418 V_BSTR(&var_frame_name
) = NULL
;
420 V_VT(params
+4) = (VT_BYREF
|VT_VARIANT
);
421 V_VARIANTREF(params
+4) = &var_flags
;
422 V_VT(&var_flags
) = VT_I4
;
423 V_I4(&var_flags
) = 0;
425 V_VT(params
+5) = (VT_BYREF
|VT_VARIANT
);
426 V_VARIANTREF(params
+5) = &var_url
;
427 V_VT(&var_url
) = VT_BSTR
;
428 V_BSTR(&var_url
) = SysAllocString(url
);
430 V_VT(params
+6) = (VT_DISPATCH
);
431 V_DISPATCH(params
+6) = This
->disp
;
433 call_sink(This
->cps
.wbe2
, DISPID_BEFORENAVIGATE2
, &dispparams
);
435 SysFreeString(V_BSTR(&var_url
));
438 /* FIXME: urlmon should handle it */
439 static BOOL
try_application_url(LPCWSTR url
)
441 SHELLEXECUTEINFOW exec_info
;
447 static const WCHAR wszURLProtocol
[] = {'U','R','L',' ','P','r','o','t','o','c','o','l',0};
449 hres
= CoInternetParseUrl(url
, PARSE_SCHEMA
, 0, app
, sizeof(app
)/sizeof(WCHAR
), NULL
, 0);
453 res
= RegOpenKeyW(HKEY_CLASSES_ROOT
, app
, &hkey
);
454 if(res
!= ERROR_SUCCESS
)
457 res
= RegQueryValueExW(hkey
, wszURLProtocol
, NULL
, &type
, NULL
, NULL
);
459 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
462 TRACE("openning application %s\n", debugstr_w(app
));
464 memset(&exec_info
, 0, sizeof(exec_info
));
465 exec_info
.cbSize
= sizeof(exec_info
);
466 exec_info
.lpFile
= url
;
467 exec_info
.nShow
= SW_SHOW
;
469 return ShellExecuteExW(&exec_info
);
472 static HRESULT
create_moniker(LPCWSTR url
, IMoniker
**mon
)
474 WCHAR new_url
[INTERNET_MAX_URL_LENGTH
];
479 return CreateURLMoniker(NULL
, url
, mon
);
482 size
= sizeof(new_url
);
483 hres
= UrlCreateFromPathW(url
, new_url
, &size
, 0);
485 WARN("UrlCreateFromPathW failed: %08x\n", hres
);
489 size
= sizeof(new_url
);
490 hres
= UrlApplySchemeW(url
, new_url
, &size
, URL_APPLY_GUESSSCHEME
);
491 TRACE("got %s\n", debugstr_w(new_url
));
493 WARN("UrlApplyScheme failed: %08x\n", hres
);
498 return CreateURLMoniker(NULL
, new_url
, mon
);
501 static HRESULT
bind_to_object(DocHost
*This
, IMoniker
*mon
, LPCWSTR url
, IBindCtx
*bindctx
,
502 IBindStatusCallback
*callback
)
504 IUnknown
*unk
= NULL
;
508 IMoniker_AddRef(mon
);
510 hres
= create_moniker(url
, &mon
);
515 CoTaskMemFree(This
->url
);
516 hres
= IMoniker_GetDisplayName(mon
, 0, NULL
, &This
->url
);
518 FIXME("GetDisplayName failed: %08x\n", hres
);
520 IBindCtx_RegisterObjectParam(bindctx
, (LPOLESTR
)SZ_HTML_CLIENTSITE_OBJECTPARAM
,
521 (IUnknown
*)CLIENTSITE(This
));
523 hres
= IMoniker_BindToObject(mon
, bindctx
, NULL
, &IID_IUnknown
, (void**)&unk
);
524 if(SUCCEEDED(hres
)) {
527 IUnknown_Release(unk
);
528 }else if(try_application_url(url
)) {
531 FIXME("BindToObject failed: %08x\n", hres
);
534 IMoniker_Release(mon
);
538 static void html_window_navigate(DocHost
*This
, IHTMLPrivateWindow
*window
, BSTR url
, BSTR headers
, SAFEARRAY
*post_data
)
540 VARIANT headers_var
, post_data_var
;
546 size
= (strlenW(url
)+1)*sizeof(WCHAR
);
547 new_url
= CoTaskMemAlloc(size
);
550 memcpy(new_url
, url
, size
);
551 CoTaskMemFree(This
->url
);
554 empty_str
= SysAllocStringLen(NULL
, 0);
557 V_VT(&headers_var
) = VT_BSTR
;
558 V_BSTR(&headers_var
) = headers
;
560 V_VT(&headers_var
) = VT_EMPTY
;
564 V_VT(&post_data_var
) = VT_UI1
|VT_ARRAY
;
565 V_ARRAY(&post_data_var
) = post_data
;
567 V_VT(&post_data_var
) = VT_EMPTY
;
570 set_doc_state(This
, READYSTATE_LOADING
);
571 hres
= IHTMLPrivateWindow_SuperNavigate(window
, url
, empty_str
, NULL
, NULL
, &post_data_var
, &headers_var
, 0);
572 SysFreeString(empty_str
);
574 WARN("SuprtNavigate failed: %08x\n", hres
);
578 task_header_t header
;
581 SAFEARRAY
*post_data
;
583 } task_doc_navigate_t
;
585 static HRESULT
free_doc_navigate_task(task_doc_navigate_t
*task
, BOOL free_task
)
587 SysFreeString(task
->url
);
588 SysFreeString(task
->headers
);
590 SafeArrayDestroy(task
->post_data
);
593 return E_OUTOFMEMORY
;
596 static void doc_navigate_proc(DocHost
*This
, task_header_t
*t
)
598 task_doc_navigate_t
*task
= (task_doc_navigate_t
*)t
;
599 IHTMLPrivateWindow
*priv_window
;
602 if(!This
->doc_navigate
)
605 if(task
->async_notif
) {
606 VARIANT_BOOL cancel
= VARIANT_FALSE
;
607 on_before_navigate2(This
, task
->url
, task
->post_data
, task
->headers
, &cancel
);
609 TRACE("Navigation calnceled\n");
610 free_doc_navigate_task(task
, FALSE
);
615 hres
= IUnknown_QueryInterface(This
->doc_navigate
, &IID_IHTMLPrivateWindow
, (void**)&priv_window
);
616 if(SUCCEEDED(hres
)) {
617 html_window_navigate(This
, priv_window
, task
->url
, task
->headers
, task
->post_data
);
618 IHTMLPrivateWindow_Release(priv_window
);
620 WARN("Could not get IHTMLPrivateWindow iface: %08x\n", hres
);
623 free_doc_navigate_task(task
, FALSE
);
626 static HRESULT
async_doc_navigate(DocHost
*This
, LPCWSTR url
, LPCWSTR headers
, PBYTE post_data
, ULONG post_data_size
,
629 task_doc_navigate_t
*task
;
631 task
= heap_alloc_zero(sizeof(*task
));
633 return E_OUTOFMEMORY
;
635 task
->url
= SysAllocString(url
);
637 return free_doc_navigate_task(task
, TRUE
);
640 task
->headers
= SysAllocString(headers
);
642 return free_doc_navigate_task(task
, TRUE
);
645 if(task
->post_data
) {
646 task
->post_data
= SafeArrayCreateVector(VT_UI1
, 0, post_data_size
);
648 return free_doc_navigate_task(task
, TRUE
);
649 memcpy(task
->post_data
->pvData
, post_data
, post_data_size
);
653 VARIANT_BOOL cancel
= VARIANT_FALSE
;
655 on_before_navigate2(This
, task
->url
, task
->post_data
, task
->headers
, &cancel
);
657 TRACE("Navigation calnceled\n");
658 free_doc_navigate_task(task
, TRUE
);
663 task
->async_notif
= async_notif
;
664 push_dochost_task(This
, &task
->header
, doc_navigate_proc
, FALSE
);
668 static HRESULT
navigate_bsc(DocHost
*This
, BindStatusCallback
*bsc
, IMoniker
*mon
)
670 VARIANT_BOOL cancel
= VARIANT_FALSE
;
671 SAFEARRAY
*post_data
= NULL
;
675 set_doc_state(This
, READYSTATE_LOADING
);
678 post_data
= SafeArrayCreateVector(VT_UI1
, 0, bsc
->post_data_len
);
679 memcpy(post_data
->pvData
, post_data
, bsc
->post_data_len
);
682 on_before_navigate2(This
, bsc
->url
, post_data
, bsc
->headers
, &cancel
);
684 SafeArrayDestroy(post_data
);
686 FIXME("Navigation canceled\n");
691 deactivate_document(This
);
693 CreateAsyncBindCtx(0, BINDSC(bsc
), 0, &bindctx
);
696 IOleInPlaceFrame_EnableModeless(This
->frame
, FALSE
);
698 hres
= bind_to_object(This
, mon
, bsc
->url
, bindctx
, BINDSC(bsc
));
701 IOleInPlaceFrame_EnableModeless(This
->frame
, TRUE
);
703 IBindCtx_Release(bindctx
);
709 task_header_t header
;
710 BindStatusCallback
*bsc
;
711 } task_navigate_bsc_t
;
713 static void navigate_bsc_proc(DocHost
*This
, task_header_t
*t
)
715 task_navigate_bsc_t
*task
= (task_navigate_bsc_t
*)t
;
718 create_doc_view_hwnd(This
);
720 navigate_bsc(This
, task
->bsc
, NULL
);
722 IBindStatusCallback_Release(BINDSC(task
->bsc
));
726 HRESULT
navigate_url(DocHost
*This
, LPCWSTR url
, const VARIANT
*Flags
,
727 const VARIANT
*TargetFrameName
, VARIANT
*PostData
, VARIANT
*Headers
)
729 PBYTE post_data
= NULL
;
730 ULONG post_data_len
= 0;
731 LPWSTR headers
= NULL
;
734 TRACE("navigating to %s\n", debugstr_w(url
));
736 if((Flags
&& V_VT(Flags
) != VT_EMPTY
)
737 || (TargetFrameName
&& V_VT(TargetFrameName
) != VT_EMPTY
))
738 FIXME("Unsupported args (Flags %p:%d; TargetFrameName %p:%d)\n",
739 Flags
, Flags
? V_VT(Flags
) : -1, TargetFrameName
,
740 TargetFrameName
? V_VT(TargetFrameName
) : -1);
743 TRACE("PostData vt=%d\n", V_VT(PostData
));
745 if(V_VT(PostData
) == (VT_ARRAY
| VT_UI1
)) {
746 SafeArrayAccessData(V_ARRAY(PostData
), (void**)&post_data
);
747 post_data_len
= V_ARRAY(PostData
)->rgsabound
[0].cElements
;
751 if(Headers
&& V_VT(Headers
) != VT_EMPTY
&& V_VT(Headers
) != VT_ERROR
) {
752 if(V_VT(Headers
) != VT_BSTR
)
755 headers
= V_BSTR(Headers
);
756 TRACE("Headers: %s\n", debugstr_w(headers
));
759 set_doc_state(This
, READYSTATE_LOADING
);
760 This
->ready_state
= READYSTATE_LOADING
;
762 if(This
->doc_navigate
) {
763 hres
= async_doc_navigate(This
, url
, headers
, post_data
, post_data_len
, TRUE
);
765 task_navigate_bsc_t
*task
;
767 task
= heap_alloc(sizeof(*task
));
768 task
->bsc
= create_callback(This
, url
, post_data
, post_data_len
, headers
);
769 push_dochost_task(This
, &task
->header
, navigate_bsc_proc
, This
->url
== NULL
);
773 SafeArrayUnaccessData(V_ARRAY(PostData
));
778 static HRESULT
navigate_hlink(DocHost
*This
, IMoniker
*mon
, IBindCtx
*bindctx
,
779 IBindStatusCallback
*callback
)
781 IHttpNegotiate
*http_negotiate
;
782 BindStatusCallback
*bsc
;
783 PBYTE post_data
= NULL
;
784 ULONG post_data_len
= 0;
785 LPWSTR headers
= NULL
, url
;
790 hres
= IMoniker_GetDisplayName(mon
, 0, NULL
, &url
);
792 FIXME("GetDisplayName failed: %08x\n", hres
);
794 hres
= IBindStatusCallback_QueryInterface(callback
, &IID_IHttpNegotiate
,
795 (void**)&http_negotiate
);
796 if(SUCCEEDED(hres
)) {
797 static const WCHAR null_string
[] = {0};
799 IHttpNegotiate_BeginningTransaction(http_negotiate
, null_string
, null_string
, 0,
801 IHttpNegotiate_Release(http_negotiate
);
804 memset(&bindinfo
, 0, sizeof(bindinfo
));
805 bindinfo
.cbSize
= sizeof(bindinfo
);
807 hres
= IBindStatusCallback_GetBindInfo(callback
, &bindf
, &bindinfo
);
808 dump_BINDINFO(&bindinfo
);
809 if(bindinfo
.dwBindVerb
== BINDVERB_POST
) {
810 post_data_len
= bindinfo
.cbstgmedData
;
812 post_data
= bindinfo
.stgmedData
.u
.hGlobal
;
815 if(This
->doc_navigate
) {
816 hres
= async_doc_navigate(This
, url
, headers
, post_data
, post_data_len
, FALSE
);
818 bsc
= create_callback(This
, url
, post_data
, post_data_len
, headers
);
819 hres
= navigate_bsc(This
, bsc
, mon
);
820 IBindStatusCallback_Release(BINDSC(bsc
));
824 CoTaskMemFree(headers
);
825 ReleaseBindInfo(&bindinfo
);
830 HRESULT
go_home(DocHost
*This
)
833 DWORD res
, type
, size
;
834 WCHAR wszPageName
[MAX_PATH
];
835 static const WCHAR wszAboutBlank
[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
836 static const WCHAR wszStartPage
[] = {'S','t','a','r','t',' ','P','a','g','e',0};
837 static const WCHAR wszSubKey
[] = {'S','o','f','t','w','a','r','e','\\',
838 'M','i','c','r','o','s','o','f','t','\\',
839 'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\',
842 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszSubKey
, &hkey
);
843 if (res
!= ERROR_SUCCESS
)
844 return navigate_url(This
, wszAboutBlank
, NULL
, NULL
, NULL
, NULL
);
846 size
= sizeof(wszPageName
);
847 res
= RegQueryValueExW(hkey
, wszStartPage
, NULL
, &type
, (LPBYTE
)wszPageName
, &size
);
849 if (res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
850 return navigate_url(This
, wszAboutBlank
, NULL
, NULL
, NULL
, NULL
);
852 return navigate_url(This
, wszPageName
, NULL
, NULL
, NULL
, NULL
);
855 #define HLINKFRAME_THIS(iface) DEFINE_THIS(WebBrowser, HlinkFrame, iface)
857 static HRESULT WINAPI
HlinkFrame_QueryInterface(IHlinkFrame
*iface
, REFIID riid
, void **ppv
)
859 WebBrowser
*This
= HLINKFRAME_THIS(iface
);
860 return IWebBrowser2_QueryInterface(WEBBROWSER2(This
), riid
, ppv
);
863 static ULONG WINAPI
HlinkFrame_AddRef(IHlinkFrame
*iface
)
865 WebBrowser
*This
= HLINKFRAME_THIS(iface
);
866 return IWebBrowser2_AddRef(WEBBROWSER2(This
));
869 static ULONG WINAPI
HlinkFrame_Release(IHlinkFrame
*iface
)
871 WebBrowser
*This
= HLINKFRAME_THIS(iface
);
872 return IWebBrowser2_Release(WEBBROWSER2(This
));
875 static HRESULT WINAPI
HlinkFrame_SetBrowseContext(IHlinkFrame
*iface
,
876 IHlinkBrowseContext
*pihlbc
)
878 WebBrowser
*This
= HLINKFRAME_THIS(iface
);
879 FIXME("(%p)->(%p)\n", This
, pihlbc
);
883 static HRESULT WINAPI
HlinkFrame_GetBrowseContext(IHlinkFrame
*iface
,
884 IHlinkBrowseContext
**ppihlbc
)
886 WebBrowser
*This
= HLINKFRAME_THIS(iface
);
887 FIXME("(%p)->(%p)\n", This
, ppihlbc
);
891 static HRESULT WINAPI
HlinkFrame_Navigate(IHlinkFrame
*iface
, DWORD grfHLNF
, LPBC pbc
,
892 IBindStatusCallback
*pibsc
, IHlink
*pihlNavigate
)
894 WebBrowser
*This
= HLINKFRAME_THIS(iface
);
896 LPWSTR location
= NULL
;
898 TRACE("(%p)->(%08x %p %p %p)\n", This
, grfHLNF
, pbc
, pibsc
, pihlNavigate
);
901 FIXME("unsupported grfHLNF=%08x\n", grfHLNF
);
903 /* Windows calls GetTargetFrameName here. */
905 IHlink_GetMonikerReference(pihlNavigate
, 1, &mon
, &location
);
908 FIXME("location = %s\n", debugstr_w(location
));
909 CoTaskMemFree(location
);
912 /* Windows calls GetHlinkSite here */
914 if(grfHLNF
& HLNF_OPENINNEWWINDOW
) {
915 FIXME("Not supported HLNF_OPENINNEWWINDOW\n");
919 return navigate_hlink(&This
->doc_host
, mon
, pbc
, pibsc
);
922 static HRESULT WINAPI
HlinkFrame_OnNavigate(IHlinkFrame
*iface
, DWORD grfHLNF
,
923 IMoniker
*pimkTarget
, LPCWSTR pwzLocation
, LPCWSTR pwzFriendlyName
, DWORD dwreserved
)
925 WebBrowser
*This
= HLINKFRAME_THIS(iface
);
926 FIXME("(%p)->(%08x %p %s %s %d)\n", This
, grfHLNF
, pimkTarget
, debugstr_w(pwzLocation
),
927 debugstr_w(pwzFriendlyName
), dwreserved
);
931 static HRESULT WINAPI
HlinkFrame_UpdateHlink(IHlinkFrame
*iface
, ULONG uHLID
,
932 IMoniker
*pimkTarget
, LPCWSTR pwzLocation
, LPCWSTR pwzFriendlyName
)
934 WebBrowser
*This
= HLINKFRAME_THIS(iface
);
935 FIXME("(%p)->(%u %p %s %s)\n", This
, uHLID
, pimkTarget
, debugstr_w(pwzLocation
),
936 debugstr_w(pwzFriendlyName
));
940 #undef HLINKFRAME_THIS
942 static const IHlinkFrameVtbl HlinkFrameVtbl
= {
943 HlinkFrame_QueryInterface
,
946 HlinkFrame_SetBrowseContext
,
947 HlinkFrame_GetBrowseContext
,
949 HlinkFrame_OnNavigate
,
950 HlinkFrame_UpdateHlink
953 void WebBrowser_HlinkFrame_Init(WebBrowser
*This
)
955 This
->lpHlinkFrameVtbl
= &HlinkFrameVtbl
;