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 static HRESULT WINAPI
BindStatusCallback_OnStopBinding(IBindStatusCallback
*iface
,
245 HRESULT hresult
, LPCWSTR szError
)
247 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
249 TRACE("(%p)->(%08x %s)\n", This
, hresult
, debugstr_w(szError
));
251 set_status_text(This
, emptyW
);
254 IOleClientSite_Release(&This
->doc_host
->IOleClientSite_iface
);
255 This
->doc_host
= NULL
;
261 static HRESULT WINAPI
BindStatusCallback_GetBindInfo(IBindStatusCallback
*iface
,
262 DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
264 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
266 TRACE("(%p)->(%p %p)\n", This
, grfBINDF
, pbindinfo
);
268 *grfBINDF
= BINDF_ASYNCHRONOUS
;
270 if(This
->post_data
) {
271 pbindinfo
->dwBindVerb
= BINDVERB_POST
;
273 pbindinfo
->stgmedData
.tymed
= TYMED_HGLOBAL
;
274 pbindinfo
->stgmedData
.u
.hGlobal
= This
->post_data
;
275 pbindinfo
->cbstgmedData
= This
->post_data_len
;
276 pbindinfo
->stgmedData
.pUnkForRelease
= (IUnknown
*)&This
->IBindStatusCallback_iface
;
277 IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
283 static HRESULT WINAPI
BindStatusCallback_OnDataAvailable(IBindStatusCallback
*iface
,
284 DWORD grfBSCF
, DWORD dwSize
, FORMATETC
*pformatetc
, STGMEDIUM
*pstgmed
)
286 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
287 FIXME("(%p)->(%08x %d %p %p)\n", This
, grfBSCF
, dwSize
, pformatetc
, pstgmed
);
291 static HRESULT WINAPI
BindStatusCallback_OnObjectAvailable(IBindStatusCallback
*iface
,
292 REFIID riid
, IUnknown
*punk
)
294 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
296 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), punk
);
298 return dochost_object_available(This
->doc_host
, punk
);
301 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl
= {
302 BindStatusCallback_QueryInterface
,
303 BindStatusCallback_AddRef
,
304 BindStatusCallback_Release
,
305 BindStatusCallback_OnStartBinding
,
306 BindStatusCallback_GetPriority
,
307 BindStatusCallback_OnLowResource
,
308 BindStatusCallback_OnProgress
,
309 BindStatusCallback_OnStopBinding
,
310 BindStatusCallback_GetBindInfo
,
311 BindStatusCallback_OnDataAvailable
,
312 BindStatusCallback_OnObjectAvailable
315 static inline BindStatusCallback
*impl_from_IHttpNegotiate(IHttpNegotiate
*iface
)
317 return CONTAINING_RECORD(iface
, BindStatusCallback
, IHttpNegotiate_iface
);
320 static HRESULT WINAPI
HttpNegotiate_QueryInterface(IHttpNegotiate
*iface
,
321 REFIID riid
, void **ppv
)
323 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
324 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
327 static ULONG WINAPI
HttpNegotiate_AddRef(IHttpNegotiate
*iface
)
329 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
330 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
333 static ULONG WINAPI
HttpNegotiate_Release(IHttpNegotiate
*iface
)
335 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
336 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
339 static HRESULT WINAPI
HttpNegotiate_BeginningTransaction(IHttpNegotiate
*iface
,
340 LPCWSTR szURL
, LPCWSTR szHeaders
, DWORD dwReserved
, LPWSTR
*pszAdditionalHeaders
)
342 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
344 TRACE("(%p)->(%s %s %d %p)\n", This
, debugstr_w(szURL
), debugstr_w(szHeaders
),
345 dwReserved
, pszAdditionalHeaders
);
348 int size
= (strlenW(This
->headers
)+1)*sizeof(WCHAR
);
349 *pszAdditionalHeaders
= CoTaskMemAlloc(size
);
350 memcpy(*pszAdditionalHeaders
, This
->headers
, size
);
356 static HRESULT WINAPI
HttpNegotiate_OnResponse(IHttpNegotiate
*iface
,
357 DWORD dwResponseCode
, LPCWSTR szResponseHeaders
, LPCWSTR szRequestHeaders
,
358 LPWSTR
*pszAdditionalRequestHeaders
)
360 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
361 TRACE("(%p)->(%d %s %s %p)\n", This
, dwResponseCode
, debugstr_w(szResponseHeaders
),
362 debugstr_w(szRequestHeaders
), pszAdditionalRequestHeaders
);
366 static const IHttpNegotiateVtbl HttpNegotiateVtbl
= {
367 HttpNegotiate_QueryInterface
,
368 HttpNegotiate_AddRef
,
369 HttpNegotiate_Release
,
370 HttpNegotiate_BeginningTransaction
,
371 HttpNegotiate_OnResponse
374 static BindStatusCallback
*create_callback(DocHost
*doc_host
, LPCWSTR url
, PBYTE post_data
,
375 ULONG post_data_len
, LPCWSTR headers
)
377 BindStatusCallback
*ret
= heap_alloc(sizeof(BindStatusCallback
));
379 ret
->IBindStatusCallback_iface
.lpVtbl
= &BindStatusCallbackVtbl
;
380 ret
->IHttpNegotiate_iface
.lpVtbl
= &HttpNegotiateVtbl
;
383 ret
->url
= heap_strdupW(url
);
384 ret
->post_data
= NULL
;
385 ret
->post_data_len
= post_data_len
;
386 ret
->headers
= headers
? SysAllocString(headers
) : NULL
;
388 ret
->doc_host
= doc_host
;
389 IOleClientSite_AddRef(&doc_host
->IOleClientSite_iface
);
392 ret
->post_data
= GlobalAlloc(0, post_data_len
);
393 memcpy(ret
->post_data
, post_data
, post_data_len
);
399 static void on_before_navigate2(DocHost
*This
, LPCWSTR url
, SAFEARRAY
*post_data
, LPWSTR headers
, VARIANT_BOOL
*cancel
)
401 VARIANT var_url
, var_flags
, var_frame_name
, var_post_data
, var_post_data2
, var_headers
;
402 DISPPARAMS dispparams
;
403 VARIANTARG params
[7];
405 dispparams
.cArgs
= 7;
406 dispparams
.cNamedArgs
= 0;
407 dispparams
.rgdispidNamedArgs
= NULL
;
408 dispparams
.rgvarg
= params
;
410 This
->busy
= VARIANT_TRUE
;
412 V_VT(params
) = VT_BOOL
|VT_BYREF
;
413 V_BOOLREF(params
) = cancel
;
415 V_VT(params
+1) = (VT_BYREF
|VT_VARIANT
);
416 V_VARIANTREF(params
+1) = &var_headers
;
417 V_VT(&var_headers
) = VT_BSTR
;
418 V_BSTR(&var_headers
) = headers
;
420 V_VT(params
+2) = (VT_BYREF
|VT_VARIANT
);
421 V_VARIANTREF(params
+2) = &var_post_data2
;
422 V_VT(&var_post_data2
) = (VT_BYREF
|VT_VARIANT
);
423 V_VARIANTREF(&var_post_data2
) = &var_post_data
;
426 V_VT(&var_post_data
) = VT_UI1
|VT_ARRAY
;
427 V_ARRAY(&var_post_data
) = post_data
;
429 V_VT(&var_post_data
) = VT_EMPTY
;
432 V_VT(params
+3) = (VT_BYREF
|VT_VARIANT
);
433 V_VARIANTREF(params
+3) = &var_frame_name
;
434 V_VT(&var_frame_name
) = VT_BSTR
;
435 V_BSTR(&var_frame_name
) = NULL
;
437 V_VT(params
+4) = (VT_BYREF
|VT_VARIANT
);
438 V_VARIANTREF(params
+4) = &var_flags
;
439 V_VT(&var_flags
) = VT_I4
;
440 V_I4(&var_flags
) = 0;
442 V_VT(params
+5) = (VT_BYREF
|VT_VARIANT
);
443 V_VARIANTREF(params
+5) = &var_url
;
444 V_VT(&var_url
) = VT_BSTR
;
445 V_BSTR(&var_url
) = SysAllocString(url
);
447 V_VT(params
+6) = (VT_DISPATCH
);
448 V_DISPATCH(params
+6) = This
->disp
;
450 call_sink(This
->cps
.wbe2
, DISPID_BEFORENAVIGATE2
, &dispparams
);
452 SysFreeString(V_BSTR(&var_url
));
455 /* FIXME: urlmon should handle it */
456 static BOOL
try_application_url(LPCWSTR url
)
458 SHELLEXECUTEINFOW exec_info
;
464 static const WCHAR wszURLProtocol
[] = {'U','R','L',' ','P','r','o','t','o','c','o','l',0};
466 hres
= CoInternetParseUrl(url
, PARSE_SCHEMA
, 0, app
, sizeof(app
)/sizeof(WCHAR
), NULL
, 0);
470 res
= RegOpenKeyW(HKEY_CLASSES_ROOT
, app
, &hkey
);
471 if(res
!= ERROR_SUCCESS
)
474 res
= RegQueryValueExW(hkey
, wszURLProtocol
, NULL
, &type
, NULL
, NULL
);
476 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
479 TRACE("openning application %s\n", debugstr_w(app
));
481 memset(&exec_info
, 0, sizeof(exec_info
));
482 exec_info
.cbSize
= sizeof(exec_info
);
483 exec_info
.lpFile
= url
;
484 exec_info
.nShow
= SW_SHOW
;
486 return ShellExecuteExW(&exec_info
);
489 static HRESULT
create_moniker(LPCWSTR url
, IMoniker
**mon
)
491 WCHAR new_url
[INTERNET_MAX_URL_LENGTH
];
496 return CreateURLMoniker(NULL
, url
, mon
);
499 size
= sizeof(new_url
);
500 hres
= UrlCreateFromPathW(url
, new_url
, &size
, 0);
502 WARN("UrlCreateFromPathW failed: %08x\n", hres
);
506 size
= sizeof(new_url
)/sizeof(WCHAR
);
507 hres
= UrlApplySchemeW(url
, new_url
, &size
, URL_APPLY_GUESSSCHEME
);
508 TRACE("got %s\n", debugstr_w(new_url
));
510 WARN("UrlApplyScheme failed: %08x\n", hres
);
515 return CreateURLMoniker(NULL
, new_url
, mon
);
518 static HRESULT
bind_to_object(DocHost
*This
, IMoniker
*mon
, LPCWSTR url
, IBindCtx
*bindctx
,
519 IBindStatusCallback
*callback
)
521 IUnknown
*unk
= NULL
;
526 IMoniker_AddRef(mon
);
528 hres
= create_moniker(url
, &mon
);
533 hres
= IMoniker_GetDisplayName(mon
, 0, NULL
, &display_name
);
535 FIXME("GetDisplayName failed: %08x\n", hres
);
539 hres
= set_dochost_url(This
, display_name
);
540 CoTaskMemFree(display_name
);
544 IBindCtx_RegisterObjectParam(bindctx
, (LPOLESTR
)SZ_HTML_CLIENTSITE_OBJECTPARAM
,
545 (IUnknown
*)&This
->IOleClientSite_iface
);
547 hres
= IMoniker_BindToObject(mon
, bindctx
, NULL
, &IID_IUnknown
, (void**)&unk
);
548 if(SUCCEEDED(hres
)) {
551 IUnknown_Release(unk
);
552 }else if(try_application_url(url
)) {
555 FIXME("BindToObject failed: %08x\n", hres
);
558 IMoniker_Release(mon
);
562 static void html_window_navigate(DocHost
*This
, IHTMLPrivateWindow
*window
, BSTR url
, BSTR headers
, SAFEARRAY
*post_data
)
564 VARIANT headers_var
, post_data_var
;
568 hres
= set_dochost_url(This
, url
);
572 empty_str
= SysAllocStringLen(NULL
, 0);
575 V_VT(&headers_var
) = VT_BSTR
;
576 V_BSTR(&headers_var
) = headers
;
578 V_VT(&headers_var
) = VT_EMPTY
;
582 V_VT(&post_data_var
) = VT_UI1
|VT_ARRAY
;
583 V_ARRAY(&post_data_var
) = post_data
;
585 V_VT(&post_data_var
) = VT_EMPTY
;
588 set_doc_state(This
, READYSTATE_LOADING
);
589 hres
= IHTMLPrivateWindow_SuperNavigate(window
, url
, empty_str
, NULL
, NULL
, &post_data_var
, &headers_var
, 0);
590 SysFreeString(empty_str
);
592 WARN("SuprtNavigate failed: %08x\n", hres
);
596 task_header_t header
;
599 SAFEARRAY
*post_data
;
601 } task_doc_navigate_t
;
603 static HRESULT
free_doc_navigate_task(task_doc_navigate_t
*task
, BOOL free_task
)
605 SysFreeString(task
->url
);
606 SysFreeString(task
->headers
);
608 SafeArrayDestroy(task
->post_data
);
611 return E_OUTOFMEMORY
;
614 static void doc_navigate_proc(DocHost
*This
, task_header_t
*t
)
616 task_doc_navigate_t
*task
= (task_doc_navigate_t
*)t
;
617 IHTMLPrivateWindow
*priv_window
;
620 if(!This
->doc_navigate
)
623 if(task
->async_notif
) {
624 VARIANT_BOOL cancel
= VARIANT_FALSE
;
625 on_before_navigate2(This
, task
->url
, task
->post_data
, task
->headers
, &cancel
);
627 TRACE("Navigation calnceled\n");
628 free_doc_navigate_task(task
, FALSE
);
633 hres
= IUnknown_QueryInterface(This
->doc_navigate
, &IID_IHTMLPrivateWindow
, (void**)&priv_window
);
634 if(SUCCEEDED(hres
)) {
635 html_window_navigate(This
, priv_window
, task
->url
, task
->headers
, task
->post_data
);
636 IHTMLPrivateWindow_Release(priv_window
);
638 WARN("Could not get IHTMLPrivateWindow iface: %08x\n", hres
);
641 free_doc_navigate_task(task
, FALSE
);
644 static HRESULT
async_doc_navigate(DocHost
*This
, LPCWSTR url
, LPCWSTR headers
, PBYTE post_data
, ULONG post_data_size
,
647 task_doc_navigate_t
*task
;
649 task
= heap_alloc_zero(sizeof(*task
));
651 return E_OUTOFMEMORY
;
653 task
->url
= SysAllocString(url
);
655 return free_doc_navigate_task(task
, TRUE
);
658 task
->headers
= SysAllocString(headers
);
660 return free_doc_navigate_task(task
, TRUE
);
664 task
->post_data
= SafeArrayCreateVector(VT_UI1
, 0, post_data_size
);
666 return free_doc_navigate_task(task
, TRUE
);
667 memcpy(task
->post_data
->pvData
, post_data
, post_data_size
);
671 VARIANT_BOOL cancel
= VARIANT_FALSE
;
673 on_before_navigate2(This
, task
->url
, task
->post_data
, task
->headers
, &cancel
);
675 TRACE("Navigation calnceled\n");
676 free_doc_navigate_task(task
, TRUE
);
681 task
->async_notif
= async_notif
;
682 push_dochost_task(This
, &task
->header
, doc_navigate_proc
, FALSE
);
686 static HRESULT
navigate_bsc(DocHost
*This
, BindStatusCallback
*bsc
, IMoniker
*mon
)
688 VARIANT_BOOL cancel
= VARIANT_FALSE
;
689 SAFEARRAY
*post_data
= NULL
;
693 set_doc_state(This
, READYSTATE_LOADING
);
696 post_data
= SafeArrayCreateVector(VT_UI1
, 0, bsc
->post_data_len
);
697 memcpy(post_data
->pvData
, post_data
, bsc
->post_data_len
);
700 on_before_navigate2(This
, bsc
->url
, post_data
, bsc
->headers
, &cancel
);
702 SafeArrayDestroy(post_data
);
704 FIXME("Navigation canceled\n");
709 deactivate_document(This
);
711 CreateAsyncBindCtx(0, &bsc
->IBindStatusCallback_iface
, 0, &bindctx
);
714 IOleInPlaceFrame_EnableModeless(This
->frame
, FALSE
);
716 hres
= bind_to_object(This
, mon
, bsc
->url
, bindctx
, &bsc
->IBindStatusCallback_iface
);
719 IOleInPlaceFrame_EnableModeless(This
->frame
, TRUE
);
721 IBindCtx_Release(bindctx
);
727 task_header_t header
;
728 BindStatusCallback
*bsc
;
729 } task_navigate_bsc_t
;
731 static void navigate_bsc_proc(DocHost
*This
, task_header_t
*t
)
733 task_navigate_bsc_t
*task
= (task_navigate_bsc_t
*)t
;
736 create_doc_view_hwnd(This
);
738 navigate_bsc(This
, task
->bsc
, NULL
);
740 IBindStatusCallback_Release(&task
->bsc
->IBindStatusCallback_iface
);
744 HRESULT
navigate_url(DocHost
*This
, LPCWSTR url
, const VARIANT
*Flags
,
745 const VARIANT
*TargetFrameName
, VARIANT
*PostData
, VARIANT
*Headers
)
747 PBYTE post_data
= NULL
;
748 ULONG post_data_len
= 0;
749 LPWSTR headers
= NULL
;
752 TRACE("navigating to %s\n", debugstr_w(url
));
754 if((Flags
&& V_VT(Flags
) != VT_EMPTY
)
755 || (TargetFrameName
&& V_VT(TargetFrameName
) != VT_EMPTY
))
756 FIXME("Unsupported args (Flags %p:%d; TargetFrameName %p:%d)\n",
757 Flags
, Flags
? V_VT(Flags
) : -1, TargetFrameName
,
758 TargetFrameName
? V_VT(TargetFrameName
) : -1);
760 if(PostData
&& V_VT(PostData
) == (VT_ARRAY
| VT_UI1
) && V_ARRAY(PostData
)) {
761 SafeArrayAccessData(V_ARRAY(PostData
), (void**)&post_data
);
762 post_data_len
= V_ARRAY(PostData
)->rgsabound
[0].cElements
;
765 if(Headers
&& V_VT(Headers
) == VT_BSTR
) {
766 headers
= V_BSTR(Headers
);
767 TRACE("Headers: %s\n", debugstr_w(headers
));
770 set_doc_state(This
, READYSTATE_LOADING
);
771 This
->ready_state
= READYSTATE_LOADING
;
773 if(This
->doc_navigate
) {
774 WCHAR new_url
[INTERNET_MAX_URL_LENGTH
];
776 if(PathIsURLW(url
)) {
781 size
= sizeof(new_url
)/sizeof(WCHAR
);
782 hres
= UrlApplySchemeW(url
, new_url
, &size
,
783 URL_APPLY_GUESSSCHEME
| URL_APPLY_DEFAULT
);
785 WARN("UrlApplyScheme failed: %08x\n", hres
);
790 hres
= async_doc_navigate(This
, *new_url
? new_url
: url
, headers
, post_data
,
791 post_data_len
, TRUE
);
793 task_navigate_bsc_t
*task
;
795 task
= heap_alloc(sizeof(*task
));
796 task
->bsc
= create_callback(This
, url
, post_data
, post_data_len
, headers
);
797 push_dochost_task(This
, &task
->header
, navigate_bsc_proc
, This
->url
== NULL
);
801 SafeArrayUnaccessData(V_ARRAY(PostData
));
806 static HRESULT
navigate_hlink(DocHost
*This
, IMoniker
*mon
, IBindCtx
*bindctx
,
807 IBindStatusCallback
*callback
)
809 IHttpNegotiate
*http_negotiate
;
810 BindStatusCallback
*bsc
;
811 PBYTE post_data
= NULL
;
812 ULONG post_data_len
= 0;
813 LPWSTR headers
= NULL
, url
;
818 hres
= IMoniker_GetDisplayName(mon
, 0, NULL
, &url
);
820 FIXME("GetDisplayName failed: %08x\n", hres
);
822 hres
= IBindStatusCallback_QueryInterface(callback
, &IID_IHttpNegotiate
,
823 (void**)&http_negotiate
);
824 if(SUCCEEDED(hres
)) {
825 static const WCHAR null_string
[] = {0};
827 IHttpNegotiate_BeginningTransaction(http_negotiate
, null_string
, null_string
, 0,
829 IHttpNegotiate_Release(http_negotiate
);
832 memset(&bindinfo
, 0, sizeof(bindinfo
));
833 bindinfo
.cbSize
= sizeof(bindinfo
);
835 hres
= IBindStatusCallback_GetBindInfo(callback
, &bindf
, &bindinfo
);
836 dump_BINDINFO(&bindinfo
);
837 if(bindinfo
.dwBindVerb
== BINDVERB_POST
) {
838 post_data_len
= bindinfo
.cbstgmedData
;
840 post_data
= bindinfo
.stgmedData
.u
.hGlobal
;
843 if(This
->doc_navigate
) {
844 hres
= async_doc_navigate(This
, url
, headers
, post_data
, post_data_len
, FALSE
);
846 bsc
= create_callback(This
, url
, post_data
, post_data_len
, headers
);
847 hres
= navigate_bsc(This
, bsc
, mon
);
848 IBindStatusCallback_Release(&bsc
->IBindStatusCallback_iface
);
852 CoTaskMemFree(headers
);
853 ReleaseBindInfo(&bindinfo
);
858 HRESULT
go_home(DocHost
*This
)
861 DWORD res
, type
, size
;
862 WCHAR wszPageName
[MAX_PATH
];
863 static const WCHAR wszAboutBlank
[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
864 static const WCHAR wszStartPage
[] = {'S','t','a','r','t',' ','P','a','g','e',0};
865 static const WCHAR wszSubKey
[] = {'S','o','f','t','w','a','r','e','\\',
866 'M','i','c','r','o','s','o','f','t','\\',
867 'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\',
870 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszSubKey
, &hkey
);
871 if (res
!= ERROR_SUCCESS
)
872 return navigate_url(This
, wszAboutBlank
, NULL
, NULL
, NULL
, NULL
);
874 size
= sizeof(wszPageName
);
875 res
= RegQueryValueExW(hkey
, wszStartPage
, NULL
, &type
, (LPBYTE
)wszPageName
, &size
);
877 if (res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
878 return navigate_url(This
, wszAboutBlank
, NULL
, NULL
, NULL
, NULL
);
880 return navigate_url(This
, wszPageName
, NULL
, NULL
, NULL
, NULL
);
883 HRESULT
get_location_url(DocHost
*This
, BSTR
*ret
)
885 FIXME("semi-stub\n");
887 *ret
= This
->url
? SysAllocString(This
->url
) : SysAllocStringLen(NULL
, 0);
889 return E_OUTOFMEMORY
;
891 return This
->url
? S_OK
: S_FALSE
;
894 static inline HlinkFrame
*impl_from_IHlinkFrame(IHlinkFrame
*iface
)
896 return CONTAINING_RECORD(iface
, HlinkFrame
, IHlinkFrame_iface
);
899 static HRESULT WINAPI
HlinkFrame_QueryInterface(IHlinkFrame
*iface
, REFIID riid
, void **ppv
)
901 HlinkFrame
*This
= impl_from_IHlinkFrame(iface
);
902 return IUnknown_QueryInterface(This
->outer
, riid
, ppv
);
905 static ULONG WINAPI
HlinkFrame_AddRef(IHlinkFrame
*iface
)
907 HlinkFrame
*This
= impl_from_IHlinkFrame(iface
);
908 return IUnknown_AddRef(This
->outer
);
911 static ULONG WINAPI
HlinkFrame_Release(IHlinkFrame
*iface
)
913 HlinkFrame
*This
= impl_from_IHlinkFrame(iface
);
914 return IUnknown_Release(This
->outer
);
917 static HRESULT WINAPI
HlinkFrame_SetBrowseContext(IHlinkFrame
*iface
,
918 IHlinkBrowseContext
*pihlbc
)
920 HlinkFrame
*This
= impl_from_IHlinkFrame(iface
);
921 FIXME("(%p)->(%p)\n", This
, pihlbc
);
925 static HRESULT WINAPI
HlinkFrame_GetBrowseContext(IHlinkFrame
*iface
,
926 IHlinkBrowseContext
**ppihlbc
)
928 HlinkFrame
*This
= impl_from_IHlinkFrame(iface
);
929 FIXME("(%p)->(%p)\n", This
, ppihlbc
);
933 static HRESULT WINAPI
HlinkFrame_Navigate(IHlinkFrame
*iface
, DWORD grfHLNF
, LPBC pbc
,
934 IBindStatusCallback
*pibsc
, IHlink
*pihlNavigate
)
936 HlinkFrame
*This
= impl_from_IHlinkFrame(iface
);
938 LPWSTR location
= NULL
;
940 TRACE("(%p)->(%08x %p %p %p)\n", This
, grfHLNF
, pbc
, pibsc
, pihlNavigate
);
943 FIXME("unsupported grfHLNF=%08x\n", grfHLNF
);
945 /* Windows calls GetTargetFrameName here. */
947 IHlink_GetMonikerReference(pihlNavigate
, 1, &mon
, &location
);
950 FIXME("location = %s\n", debugstr_w(location
));
951 CoTaskMemFree(location
);
954 /* Windows calls GetHlinkSite here */
956 if(grfHLNF
& HLNF_OPENINNEWWINDOW
) {
957 FIXME("Not supported HLNF_OPENINNEWWINDOW\n");
961 return navigate_hlink(This
->doc_host
, mon
, pbc
, pibsc
);
964 static HRESULT WINAPI
HlinkFrame_OnNavigate(IHlinkFrame
*iface
, DWORD grfHLNF
,
965 IMoniker
*pimkTarget
, LPCWSTR pwzLocation
, LPCWSTR pwzFriendlyName
, DWORD dwreserved
)
967 HlinkFrame
*This
= impl_from_IHlinkFrame(iface
);
968 FIXME("(%p)->(%08x %p %s %s %d)\n", This
, grfHLNF
, pimkTarget
, debugstr_w(pwzLocation
),
969 debugstr_w(pwzFriendlyName
), dwreserved
);
973 static HRESULT WINAPI
HlinkFrame_UpdateHlink(IHlinkFrame
*iface
, ULONG uHLID
,
974 IMoniker
*pimkTarget
, LPCWSTR pwzLocation
, LPCWSTR pwzFriendlyName
)
976 HlinkFrame
*This
= impl_from_IHlinkFrame(iface
);
977 FIXME("(%p)->(%u %p %s %s)\n", This
, uHLID
, pimkTarget
, debugstr_w(pwzLocation
),
978 debugstr_w(pwzFriendlyName
));
982 static const IHlinkFrameVtbl HlinkFrameVtbl
= {
983 HlinkFrame_QueryInterface
,
986 HlinkFrame_SetBrowseContext
,
987 HlinkFrame_GetBrowseContext
,
989 HlinkFrame_OnNavigate
,
990 HlinkFrame_UpdateHlink
993 static inline HlinkFrame
*impl_from_ITargetFrame2(ITargetFrame2
*iface
)
995 return CONTAINING_RECORD(iface
, HlinkFrame
, IHlinkFrame_iface
);
998 static HRESULT WINAPI
TargetFrame2_QueryInterface(ITargetFrame2
*iface
, REFIID riid
, void **ppv
)
1000 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1001 return IUnknown_QueryInterface(This
->outer
, riid
, ppv
);
1004 static ULONG WINAPI
TargetFrame2_AddRef(ITargetFrame2
*iface
)
1006 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1007 return IUnknown_AddRef(This
->outer
);
1010 static ULONG WINAPI
TargetFrame2_Release(ITargetFrame2
*iface
)
1012 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1013 return IUnknown_Release(This
->outer
);
1016 static HRESULT WINAPI
TargetFrame2_SetFrameName(ITargetFrame2
*iface
, LPCWSTR pszFrameName
)
1018 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1019 FIXME("(%p)->(%s)\n", This
, debugstr_w(pszFrameName
));
1023 static HRESULT WINAPI
TargetFrame2_GetFrameName(ITargetFrame2
*iface
, LPWSTR
*ppszFrameName
)
1025 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1026 FIXME("(%p)->(%p)\n", This
, ppszFrameName
);
1030 static HRESULT WINAPI
TargetFrame2_GetParentFrame(ITargetFrame2
*iface
, IUnknown
**ppunkParent
)
1032 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1033 FIXME("(%p)->(%p)\n", This
, ppunkParent
);
1037 static HRESULT WINAPI
TargetFrame2_SetFrameSrc(ITargetFrame2
*iface
, LPCWSTR pszFrameSrc
)
1039 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1040 FIXME("(%p)->(%s)\n", This
, debugstr_w(pszFrameSrc
));
1044 static HRESULT WINAPI
TargetFrame2_GetFrameSrc(ITargetFrame2
*iface
, LPWSTR
*ppszFrameSrc
)
1046 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1047 FIXME("(%p)->()\n", This
);
1051 static HRESULT WINAPI
TargetFrame2_GetFramesContainer(ITargetFrame2
*iface
, IOleContainer
**ppContainer
)
1053 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1054 FIXME("(%p)->(%p)\n", This
, ppContainer
);
1058 static HRESULT WINAPI
TargetFrame2_SetFrameOptions(ITargetFrame2
*iface
, DWORD dwFlags
)
1060 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1061 FIXME("(%p)->(%x)\n", This
, dwFlags
);
1065 static HRESULT WINAPI
TargetFrame2_GetFrameOptions(ITargetFrame2
*iface
, DWORD
*pdwFlags
)
1067 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1068 FIXME("(%p)->(%p)\n", This
, pdwFlags
);
1072 static HRESULT WINAPI
TargetFrame2_SetFrameMargins(ITargetFrame2
*iface
, DWORD dwWidth
, DWORD dwHeight
)
1074 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1075 FIXME("(%p)->(%d %d)\n", This
, dwWidth
, dwHeight
);
1079 static HRESULT WINAPI
TargetFrame2_GetFrameMargins(ITargetFrame2
*iface
, DWORD
*pdwWidth
, DWORD
*pdwHeight
)
1081 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1082 FIXME("(%p)->(%p %p)\n", This
, pdwWidth
, pdwHeight
);
1086 static HRESULT WINAPI
TargetFrame2_FindFrame(ITargetFrame2
*iface
, LPCWSTR pszTargetName
, DWORD dwFlags
, IUnknown
**ppunkTargetFrame
)
1088 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1089 FIXME("(%p)->(%s %x %p)\n", This
, debugstr_w(pszTargetName
), dwFlags
, ppunkTargetFrame
);
1093 static HRESULT WINAPI
TargetFrame2_GetTargetAlias(ITargetFrame2
*iface
, LPCWSTR pszTargetName
, LPWSTR
*ppszTargetAlias
)
1095 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1096 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(pszTargetName
), ppszTargetAlias
);
1100 static const ITargetFrame2Vtbl TargetFrame2Vtbl
= {
1101 TargetFrame2_QueryInterface
,
1102 TargetFrame2_AddRef
,
1103 TargetFrame2_Release
,
1104 TargetFrame2_SetFrameName
,
1105 TargetFrame2_GetFrameName
,
1106 TargetFrame2_GetParentFrame
,
1107 TargetFrame2_SetFrameSrc
,
1108 TargetFrame2_GetFrameSrc
,
1109 TargetFrame2_GetFramesContainer
,
1110 TargetFrame2_SetFrameOptions
,
1111 TargetFrame2_GetFrameOptions
,
1112 TargetFrame2_SetFrameMargins
,
1113 TargetFrame2_GetFrameMargins
,
1114 TargetFrame2_FindFrame
,
1115 TargetFrame2_GetTargetAlias
1118 BOOL
HlinkFrame_QI(HlinkFrame
*This
, REFIID riid
, void **ppv
)
1120 if(IsEqualGUID(&IID_IHlinkFrame
, riid
)) {
1121 TRACE("(%p)->(IID_IHlinkFrame %p)\n", This
, ppv
);
1122 *ppv
= &This
->IHlinkFrame_iface
;
1123 }else if(IsEqualGUID(&IID_ITargetFrame2
, riid
)) {
1124 TRACE("(%p)->(IID_ITargetFrame2 %p)\n", This
, ppv
);
1125 *ppv
= &This
->ITargetFrame2_iface
;
1130 IUnknown_AddRef((IUnknown
*)*ppv
);
1134 void HlinkFrame_Init(HlinkFrame
*This
, IUnknown
*outer
, DocHost
*doc_host
)
1136 This
->IHlinkFrame_iface
.lpVtbl
= &HlinkFrameVtbl
;
1137 This
->ITargetFrame2_iface
.lpVtbl
= &TargetFrame2Vtbl
;
1139 This
->outer
= outer
;
1140 This
->doc_host
= doc_host
;