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
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(ieframe
);
35 static const WCHAR emptyW
[] = {0};
38 IBindStatusCallback IBindStatusCallback_iface
;
39 IHttpNegotiate IHttpNegotiate_iface
;
52 static void dump_BINDINFO(BINDINFO
*bi
)
54 static const char * const BINDINFOF_str
[] = {
56 "BINDINFOF_URLENCODESTGMEDDATA",
57 "BINDINFOF_URLENCODEDEXTRAINFO"
60 static const char * const BINDVERB_str
[] = {
80 bi
->cbSize
, debugstr_w(bi
->szExtraInfo
),
81 bi
->stgmedData
.tymed
, bi
->stgmedData
.u
.hGlobal
, bi
->stgmedData
.pUnkForRelease
,
82 bi
->grfBindInfoF
> BINDINFOF_URLENCODEDEXTRAINFO
83 ? "unknown" : BINDINFOF_str
[bi
->grfBindInfoF
],
84 bi
->dwBindVerb
> BINDVERB_CUSTOM
85 ? "unknown" : BINDVERB_str
[bi
->dwBindVerb
],
86 debugstr_w(bi
->szCustomVerb
),
87 bi
->cbstgmedData
, bi
->dwOptions
, bi
->dwOptionsFlags
, bi
->dwCodePage
,
88 bi
->securityAttributes
.nLength
,
89 bi
->securityAttributes
.lpSecurityDescriptor
,
90 bi
->securityAttributes
.bInheritHandle
,
91 debugstr_guid(&bi
->iid
),
92 bi
->pUnk
, bi
->dwReserved
96 static void set_status_text(BindStatusCallback
*This
, LPCWSTR str
)
99 DISPPARAMS dispparams
= {&arg
, NULL
, 1, 0};
104 V_VT(&arg
) = VT_BSTR
;
105 V_BSTR(&arg
) = str
? SysAllocString(str
) : NULL
;
106 call_sink(This
->doc_host
->cps
.wbe2
, DISPID_STATUSTEXTCHANGE
, &dispparams
);
109 if(This
->doc_host
->frame
)
110 IOleInPlaceFrame_SetStatusText(This
->doc_host
->frame
, str
);
113 HRESULT
set_dochost_url(DocHost
*This
, const WCHAR
*url
)
118 new_url
= heap_strdupW(url
);
120 return E_OUTOFMEMORY
;
125 heap_free(This
->url
);
128 This
->container_vtbl
->SetURL(This
, This
->url
);
132 static inline BindStatusCallback
*impl_from_IBindStatusCallback(IBindStatusCallback
*iface
)
134 return CONTAINING_RECORD(iface
, BindStatusCallback
, IBindStatusCallback_iface
);
137 static HRESULT WINAPI
BindStatusCallback_QueryInterface(IBindStatusCallback
*iface
,
138 REFIID riid
, void **ppv
)
140 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
142 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
143 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
144 *ppv
= &This
->IBindStatusCallback_iface
;
145 }else if(IsEqualGUID(&IID_IBindStatusCallback
, riid
)) {
146 TRACE("(%p)->(IID_IBindStatusCallback %p)\n", This
, ppv
);
147 *ppv
= &This
->IBindStatusCallback_iface
;
148 }else if(IsEqualGUID(&IID_IHttpNegotiate
, riid
)) {
149 TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This
, ppv
);
150 *ppv
= &This
->IHttpNegotiate_iface
;
153 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
154 return E_NOINTERFACE
;
157 IUnknown_AddRef((IUnknown
*)*ppv
);
161 static ULONG WINAPI
BindStatusCallback_AddRef(IBindStatusCallback
*iface
)
163 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
164 LONG ref
= InterlockedIncrement(&This
->ref
);
166 TRACE("(%p) ref=%d\n", This
, ref
);
171 static ULONG WINAPI
BindStatusCallback_Release(IBindStatusCallback
*iface
)
173 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
174 LONG ref
= InterlockedDecrement(&This
->ref
);
176 TRACE("(%p) ref=%d\n", This
, ref
);
180 IOleClientSite_Release(&This
->doc_host
->IOleClientSite_iface
);
182 IBinding_Release(This
->binding
);
184 GlobalFree(This
->post_data
);
185 SysFreeString(This
->headers
);
186 heap_free(This
->url
);
193 static HRESULT WINAPI
BindStatusCallback_OnStartBinding(IBindStatusCallback
*iface
,
194 DWORD dwReserved
, IBinding
*pbind
)
196 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
198 TRACE("(%p)->(%d %p)\n", This
, dwReserved
, pbind
);
200 This
->binding
= pbind
;
201 IBinding_AddRef(This
->binding
);
206 static HRESULT WINAPI
BindStatusCallback_GetPriority(IBindStatusCallback
*iface
,
209 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
210 FIXME("(%p)->(%p)\n", This
, pnPriority
);
214 static HRESULT WINAPI
BindStatusCallback_OnLowResource(IBindStatusCallback
*iface
,
217 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
218 FIXME("(%p)->(%d)\n", This
, reserved
);
222 static DWORD
get_http_status_code(IBinding
*binding
)
224 IWinInetHttpInfo
*http_info
;
225 DWORD status
, size
= sizeof(DWORD
);
228 hres
= IBinding_QueryInterface(binding
, &IID_IWinInetHttpInfo
, (void**)&http_info
);
230 return HTTP_STATUS_OK
;
232 hres
= IWinInetHttpInfo_QueryInfo(http_info
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
,
233 &status
, &size
, NULL
, NULL
);
234 IWinInetHttpInfo_Release(http_info
);
237 return HTTP_STATUS_OK
;
241 static HRESULT WINAPI
BindStatusCallback_OnProgress(IBindStatusCallback
*iface
,
242 ULONG ulProgress
, ULONG ulProgressMax
, ULONG ulStatusCode
, LPCWSTR szStatusText
)
244 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
247 TRACE("(%p)->(%d %d %d %s)\n", This
, ulProgress
, ulProgressMax
, ulStatusCode
,
248 debugstr_w(szStatusText
));
250 switch(ulStatusCode
) {
251 case BINDSTATUS_REDIRECTING
:
252 return set_dochost_url(This
->doc_host
, szStatusText
);
253 case BINDSTATUS_BEGINDOWNLOADDATA
:
254 set_status_text(This
, szStatusText
); /* FIXME: "Start downloading from site: %s" */
255 status_code
= get_http_status_code(This
->binding
);
256 if(status_code
!= HTTP_STATUS_OK
)
257 handle_navigation_error(This
->doc_host
, status_code
, This
->url
, NULL
);
259 case BINDSTATUS_ENDDOWNLOADDATA
:
260 set_status_text(This
, szStatusText
); /* FIXME: "Downloading from site: %s" */
262 case BINDSTATUS_CLASSIDAVAILABLE
:
263 case BINDSTATUS_MIMETYPEAVAILABLE
:
264 case BINDSTATUS_BEGINSYNCOPERATION
:
265 case BINDSTATUS_ENDSYNCOPERATION
:
268 FIXME("status code %u\n", ulStatusCode
);
274 void handle_navigation_error(DocHost
* doc_host
, HRESULT hres
, BSTR url
, IHTMLWindow2
*win2
)
276 VARIANT var_status_code
, var_frame_name
, var_url
;
277 DISPPARAMS dispparams
;
278 VARIANTARG params
[5];
279 VARIANT_BOOL cancel
= VARIANT_FALSE
;
281 dispparams
.cArgs
= 5;
282 dispparams
.cNamedArgs
= 0;
283 dispparams
.rgdispidNamedArgs
= NULL
;
284 dispparams
.rgvarg
= params
;
286 V_VT(params
) = VT_BOOL
|VT_BYREF
;
287 V_BOOLREF(params
) = &cancel
;
289 V_VT(params
+1) = VT_VARIANT
|VT_BYREF
;
290 V_VARIANTREF(params
+1) = &var_status_code
;
291 V_VT(&var_status_code
) = VT_I4
;
292 V_I4(&var_status_code
) = hres
;
294 V_VT(params
+2) = VT_VARIANT
|VT_BYREF
;
295 V_VARIANTREF(params
+2) = &var_frame_name
;
296 V_VT(&var_frame_name
) = VT_BSTR
;
298 hres
= IHTMLWindow2_get_name(win2
, &V_BSTR(&var_frame_name
));
300 V_BSTR(&var_frame_name
) = NULL
;
302 V_BSTR(&var_frame_name
) = NULL
;
304 V_VT(params
+3) = VT_VARIANT
|VT_BYREF
;
305 V_VARIANTREF(params
+3) = &var_url
;
306 V_VT(&var_url
) = VT_BSTR
;
307 V_BSTR(&var_url
) = url
;
309 V_VT(params
+4) = VT_DISPATCH
;
310 V_DISPATCH(params
+4) = doc_host
->disp
;
312 call_sink(doc_host
->cps
.wbe2
, DISPID_NAVIGATEERROR
, &dispparams
);
313 SysFreeString(V_BSTR(&var_frame_name
));
316 FIXME("Navigate to error page\n");
319 static HRESULT WINAPI
BindStatusCallback_OnStopBinding(IBindStatusCallback
*iface
,
320 HRESULT hresult
, LPCWSTR szError
)
322 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
324 TRACE("(%p)->(%08x %s)\n", This
, hresult
, debugstr_w(szError
));
326 set_status_text(This
, emptyW
);
332 handle_navigation_error(This
->doc_host
, hresult
, This
->url
, NULL
);
334 IOleClientSite_Release(&This
->doc_host
->IOleClientSite_iface
);
335 This
->doc_host
= NULL
;
337 IBinding_Release(This
->binding
);
338 This
->binding
= NULL
;
343 static HRESULT WINAPI
BindStatusCallback_GetBindInfo(IBindStatusCallback
*iface
,
344 DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
346 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
348 TRACE("(%p)->(%p %p)\n", This
, grfBINDF
, pbindinfo
);
350 *grfBINDF
= BINDF_ASYNCHRONOUS
;
352 if(This
->post_data
) {
353 pbindinfo
->dwBindVerb
= BINDVERB_POST
;
355 pbindinfo
->stgmedData
.tymed
= TYMED_HGLOBAL
;
356 pbindinfo
->stgmedData
.u
.hGlobal
= This
->post_data
;
357 pbindinfo
->cbstgmedData
= This
->post_data_len
;
358 pbindinfo
->stgmedData
.pUnkForRelease
= (IUnknown
*)&This
->IBindStatusCallback_iface
;
359 IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
365 static HRESULT WINAPI
BindStatusCallback_OnDataAvailable(IBindStatusCallback
*iface
,
366 DWORD grfBSCF
, DWORD dwSize
, FORMATETC
*pformatetc
, STGMEDIUM
*pstgmed
)
368 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
369 FIXME("(%p)->(%08x %d %p %p)\n", This
, grfBSCF
, dwSize
, pformatetc
, pstgmed
);
373 static HRESULT WINAPI
BindStatusCallback_OnObjectAvailable(IBindStatusCallback
*iface
,
374 REFIID riid
, IUnknown
*punk
)
376 BindStatusCallback
*This
= impl_from_IBindStatusCallback(iface
);
378 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), punk
);
380 return dochost_object_available(This
->doc_host
, punk
);
383 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl
= {
384 BindStatusCallback_QueryInterface
,
385 BindStatusCallback_AddRef
,
386 BindStatusCallback_Release
,
387 BindStatusCallback_OnStartBinding
,
388 BindStatusCallback_GetPriority
,
389 BindStatusCallback_OnLowResource
,
390 BindStatusCallback_OnProgress
,
391 BindStatusCallback_OnStopBinding
,
392 BindStatusCallback_GetBindInfo
,
393 BindStatusCallback_OnDataAvailable
,
394 BindStatusCallback_OnObjectAvailable
397 static inline BindStatusCallback
*impl_from_IHttpNegotiate(IHttpNegotiate
*iface
)
399 return CONTAINING_RECORD(iface
, BindStatusCallback
, IHttpNegotiate_iface
);
402 static HRESULT WINAPI
HttpNegotiate_QueryInterface(IHttpNegotiate
*iface
,
403 REFIID riid
, void **ppv
)
405 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
406 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
409 static ULONG WINAPI
HttpNegotiate_AddRef(IHttpNegotiate
*iface
)
411 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
412 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
415 static ULONG WINAPI
HttpNegotiate_Release(IHttpNegotiate
*iface
)
417 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
418 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
421 static HRESULT WINAPI
HttpNegotiate_BeginningTransaction(IHttpNegotiate
*iface
,
422 LPCWSTR szURL
, LPCWSTR szHeaders
, DWORD dwReserved
, LPWSTR
*pszAdditionalHeaders
)
424 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
426 TRACE("(%p)->(%s %s %d %p)\n", This
, debugstr_w(szURL
), debugstr_w(szHeaders
),
427 dwReserved
, pszAdditionalHeaders
);
430 int size
= (strlenW(This
->headers
)+1)*sizeof(WCHAR
);
431 *pszAdditionalHeaders
= CoTaskMemAlloc(size
);
432 memcpy(*pszAdditionalHeaders
, This
->headers
, size
);
438 static HRESULT WINAPI
HttpNegotiate_OnResponse(IHttpNegotiate
*iface
,
439 DWORD dwResponseCode
, LPCWSTR szResponseHeaders
, LPCWSTR szRequestHeaders
,
440 LPWSTR
*pszAdditionalRequestHeaders
)
442 BindStatusCallback
*This
= impl_from_IHttpNegotiate(iface
);
443 TRACE("(%p)->(%d %s %s %p)\n", This
, dwResponseCode
, debugstr_w(szResponseHeaders
),
444 debugstr_w(szRequestHeaders
), pszAdditionalRequestHeaders
);
448 static const IHttpNegotiateVtbl HttpNegotiateVtbl
= {
449 HttpNegotiate_QueryInterface
,
450 HttpNegotiate_AddRef
,
451 HttpNegotiate_Release
,
452 HttpNegotiate_BeginningTransaction
,
453 HttpNegotiate_OnResponse
456 static BindStatusCallback
*create_callback(DocHost
*doc_host
, LPCWSTR url
, PBYTE post_data
,
457 ULONG post_data_len
, LPCWSTR headers
)
459 BindStatusCallback
*ret
= heap_alloc(sizeof(BindStatusCallback
));
461 ret
->IBindStatusCallback_iface
.lpVtbl
= &BindStatusCallbackVtbl
;
462 ret
->IHttpNegotiate_iface
.lpVtbl
= &HttpNegotiateVtbl
;
465 ret
->url
= heap_strdupW(url
);
466 ret
->post_data
= NULL
;
467 ret
->post_data_len
= post_data_len
;
468 ret
->headers
= headers
? SysAllocString(headers
) : NULL
;
470 ret
->doc_host
= doc_host
;
471 IOleClientSite_AddRef(&doc_host
->IOleClientSite_iface
);
476 ret
->post_data
= GlobalAlloc(0, post_data_len
);
477 memcpy(ret
->post_data
, post_data
, post_data_len
);
483 static void on_before_navigate2(DocHost
*This
, LPCWSTR url
, SAFEARRAY
*post_data
, LPWSTR headers
, VARIANT_BOOL
*cancel
)
485 VARIANT var_url
, var_flags
, var_frame_name
, var_post_data
, var_post_data2
, var_headers
;
486 DISPPARAMS dispparams
;
487 VARIANTARG params
[7];
489 dispparams
.cArgs
= 7;
490 dispparams
.cNamedArgs
= 0;
491 dispparams
.rgdispidNamedArgs
= NULL
;
492 dispparams
.rgvarg
= params
;
494 This
->busy
= VARIANT_TRUE
;
496 V_VT(params
) = VT_BOOL
|VT_BYREF
;
497 V_BOOLREF(params
) = cancel
;
499 V_VT(params
+1) = (VT_BYREF
|VT_VARIANT
);
500 V_VARIANTREF(params
+1) = &var_headers
;
501 V_VT(&var_headers
) = VT_BSTR
;
502 V_BSTR(&var_headers
) = headers
;
504 V_VT(params
+2) = (VT_BYREF
|VT_VARIANT
);
505 V_VARIANTREF(params
+2) = &var_post_data2
;
506 V_VT(&var_post_data2
) = (VT_BYREF
|VT_VARIANT
);
507 V_VARIANTREF(&var_post_data2
) = &var_post_data
;
510 V_VT(&var_post_data
) = VT_UI1
|VT_ARRAY
;
511 V_ARRAY(&var_post_data
) = post_data
;
513 V_VT(&var_post_data
) = VT_EMPTY
;
516 V_VT(params
+3) = (VT_BYREF
|VT_VARIANT
);
517 V_VARIANTREF(params
+3) = &var_frame_name
;
518 V_VT(&var_frame_name
) = VT_BSTR
;
519 V_BSTR(&var_frame_name
) = NULL
;
521 V_VT(params
+4) = (VT_BYREF
|VT_VARIANT
);
522 V_VARIANTREF(params
+4) = &var_flags
;
523 V_VT(&var_flags
) = VT_I4
;
524 V_I4(&var_flags
) = 0;
526 V_VT(params
+5) = (VT_BYREF
|VT_VARIANT
);
527 V_VARIANTREF(params
+5) = &var_url
;
528 V_VT(&var_url
) = VT_BSTR
;
529 V_BSTR(&var_url
) = SysAllocString(url
);
531 V_VT(params
+6) = (VT_DISPATCH
);
532 V_DISPATCH(params
+6) = This
->disp
;
534 call_sink(This
->cps
.wbe2
, DISPID_BEFORENAVIGATE2
, &dispparams
);
536 SysFreeString(V_BSTR(&var_url
));
539 /* FIXME: urlmon should handle it */
540 static BOOL
try_application_url(LPCWSTR url
)
542 SHELLEXECUTEINFOW exec_info
;
548 static const WCHAR wszURLProtocol
[] = {'U','R','L',' ','P','r','o','t','o','c','o','l',0};
550 hres
= CoInternetParseUrl(url
, PARSE_SCHEMA
, 0, app
, sizeof(app
)/sizeof(WCHAR
), NULL
, 0);
554 res
= RegOpenKeyW(HKEY_CLASSES_ROOT
, app
, &hkey
);
555 if(res
!= ERROR_SUCCESS
)
558 res
= RegQueryValueExW(hkey
, wszURLProtocol
, NULL
, &type
, NULL
, NULL
);
560 if(res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
563 TRACE("opening application %s\n", debugstr_w(app
));
565 memset(&exec_info
, 0, sizeof(exec_info
));
566 exec_info
.cbSize
= sizeof(exec_info
);
567 exec_info
.lpFile
= url
;
568 exec_info
.nShow
= SW_SHOW
;
570 return ShellExecuteExW(&exec_info
);
573 static HRESULT
create_moniker(LPCWSTR url
, IMoniker
**mon
)
575 WCHAR new_url
[INTERNET_MAX_URL_LENGTH
];
580 return CreateURLMoniker(NULL
, url
, mon
);
582 size
= sizeof(new_url
)/sizeof(WCHAR
);
583 hres
= UrlApplySchemeW(url
, new_url
, &size
, URL_APPLY_GUESSSCHEME
| URL_APPLY_GUESSFILE
);
584 TRACE("was %s got %s\n", debugstr_w(url
), debugstr_w(new_url
));
586 WARN("UrlApplyScheme failed: %08x\n", hres
);
590 return CreateURLMoniker(NULL
, new_url
, mon
);
593 static HRESULT
bind_to_object(DocHost
*This
, IMoniker
*mon
, LPCWSTR url
, IBindCtx
*bindctx
,
594 IBindStatusCallback
*callback
)
596 IUnknown
*unk
= NULL
;
601 IMoniker_AddRef(mon
);
603 hres
= create_moniker(url
, &mon
);
608 hres
= IMoniker_GetDisplayName(mon
, 0, NULL
, &display_name
);
610 FIXME("GetDisplayName failed: %08x\n", hres
);
614 hres
= set_dochost_url(This
, display_name
);
615 CoTaskMemFree(display_name
);
619 IBindCtx_RegisterObjectParam(bindctx
, (LPOLESTR
)SZ_HTML_CLIENTSITE_OBJECTPARAM
,
620 (IUnknown
*)&This
->IOleClientSite_iface
);
622 hres
= IMoniker_BindToObject(mon
, bindctx
, NULL
, &IID_IUnknown
, (void**)&unk
);
623 if(SUCCEEDED(hres
)) {
626 IUnknown_Release(unk
);
627 }else if(try_application_url(url
)) {
630 FIXME("BindToObject failed: %08x\n", hres
);
633 IMoniker_Release(mon
);
637 static void html_window_navigate(DocHost
*This
, IHTMLPrivateWindow
*window
, BSTR url
, BSTR headers
, SAFEARRAY
*post_data
)
639 VARIANT headers_var
, post_data_var
;
643 hres
= set_dochost_url(This
, url
);
647 empty_str
= SysAllocStringLen(NULL
, 0);
650 V_VT(&headers_var
) = VT_BSTR
;
651 V_BSTR(&headers_var
) = headers
;
653 V_VT(&headers_var
) = VT_EMPTY
;
657 V_VT(&post_data_var
) = VT_UI1
|VT_ARRAY
;
658 V_ARRAY(&post_data_var
) = post_data
;
660 V_VT(&post_data_var
) = VT_EMPTY
;
663 set_doc_state(This
, READYSTATE_LOADING
);
664 hres
= IHTMLPrivateWindow_SuperNavigate(window
, url
, empty_str
, NULL
, NULL
, &post_data_var
, &headers_var
, 0);
665 SysFreeString(empty_str
);
667 WARN("SuprtNavigate failed: %08x\n", hres
);
671 task_header_t header
;
674 SAFEARRAY
*post_data
;
676 } task_doc_navigate_t
;
678 static void doc_navigate_task_destr(task_header_t
*t
)
680 task_doc_navigate_t
*task
= (task_doc_navigate_t
*)t
;
682 SysFreeString(task
->url
);
683 SysFreeString(task
->headers
);
685 SafeArrayDestroy(task
->post_data
);
689 static void doc_navigate_proc(DocHost
*This
, task_header_t
*t
)
691 task_doc_navigate_t
*task
= (task_doc_navigate_t
*)t
;
692 IHTMLPrivateWindow
*priv_window
;
695 if(!This
->doc_navigate
) {
700 if(task
->async_notif
) {
701 VARIANT_BOOL cancel
= VARIANT_FALSE
;
702 on_before_navigate2(This
, task
->url
, task
->post_data
, task
->headers
, &cancel
);
704 TRACE("Navigation canceled\n");
709 hres
= IUnknown_QueryInterface(This
->doc_navigate
, &IID_IHTMLPrivateWindow
, (void**)&priv_window
);
710 if(SUCCEEDED(hres
)) {
711 html_window_navigate(This
, priv_window
, task
->url
, task
->headers
, task
->post_data
);
712 IHTMLPrivateWindow_Release(priv_window
);
714 WARN("Could not get IHTMLPrivateWindow iface: %08x\n", hres
);
718 static HRESULT
async_doc_navigate(DocHost
*This
, LPCWSTR url
, LPCWSTR headers
, PBYTE post_data
, ULONG post_data_size
,
721 task_doc_navigate_t
*task
;
723 TRACE("%s\n", debugstr_w(url
));
725 task
= heap_alloc_zero(sizeof(*task
));
727 return E_OUTOFMEMORY
;
729 task
->url
= SysAllocString(url
);
731 doc_navigate_task_destr(&task
->header
);
732 return E_OUTOFMEMORY
;
736 task
->headers
= SysAllocString(headers
);
738 doc_navigate_task_destr(&task
->header
);
739 return E_OUTOFMEMORY
;
744 task
->post_data
= SafeArrayCreateVector(VT_UI1
, 0, post_data_size
);
745 if(!task
->post_data
) {
746 doc_navigate_task_destr(&task
->header
);
747 return E_OUTOFMEMORY
;
750 memcpy(task
->post_data
->pvData
, post_data
, post_data_size
);
754 VARIANT_BOOL cancel
= VARIANT_FALSE
;
756 on_before_navigate2(This
, task
->url
, task
->post_data
, task
->headers
, &cancel
);
758 TRACE("Navigation canceled\n");
759 doc_navigate_task_destr(&task
->header
);
764 task
->async_notif
= async_notif
;
765 abort_dochost_tasks(This
, doc_navigate_proc
);
766 push_dochost_task(This
, &task
->header
, doc_navigate_proc
, doc_navigate_task_destr
, FALSE
);
770 static HRESULT
navigate_bsc(DocHost
*This
, BindStatusCallback
*bsc
, IMoniker
*mon
)
772 VARIANT_BOOL cancel
= VARIANT_FALSE
;
773 SAFEARRAY
*post_data
= NULL
;
777 set_doc_state(This
, READYSTATE_LOADING
);
780 post_data
= SafeArrayCreateVector(VT_UI1
, 0, bsc
->post_data_len
);
781 memcpy(post_data
->pvData
, post_data
, bsc
->post_data_len
);
784 on_before_navigate2(This
, bsc
->url
, post_data
, bsc
->headers
, &cancel
);
786 SafeArrayDestroy(post_data
);
788 FIXME("Navigation canceled\n");
793 deactivate_document(This
);
795 CreateAsyncBindCtx(0, &bsc
->IBindStatusCallback_iface
, 0, &bindctx
);
798 IOleInPlaceFrame_EnableModeless(This
->frame
, FALSE
);
800 hres
= bind_to_object(This
, mon
, bsc
->url
, bindctx
, &bsc
->IBindStatusCallback_iface
);
803 IOleInPlaceFrame_EnableModeless(This
->frame
, TRUE
);
805 IBindCtx_Release(bindctx
);
811 task_header_t header
;
812 BindStatusCallback
*bsc
;
813 } task_navigate_bsc_t
;
815 static void navigate_bsc_task_destr(task_header_t
*t
)
817 task_navigate_bsc_t
*task
= (task_navigate_bsc_t
*)t
;
819 IBindStatusCallback_Release(&task
->bsc
->IBindStatusCallback_iface
);
823 static void navigate_bsc_proc(DocHost
*This
, task_header_t
*t
)
825 task_navigate_bsc_t
*task
= (task_navigate_bsc_t
*)t
;
828 create_doc_view_hwnd(This
);
830 navigate_bsc(This
, task
->bsc
, NULL
);
834 HRESULT
navigate_url(DocHost
*This
, LPCWSTR url
, const VARIANT
*Flags
,
835 const VARIANT
*TargetFrameName
, VARIANT
*PostData
, VARIANT
*Headers
)
837 PBYTE post_data
= NULL
;
838 ULONG post_data_len
= 0;
839 LPWSTR headers
= NULL
;
842 TRACE("navigating to %s\n", debugstr_w(url
));
844 if((Flags
&& V_VT(Flags
) != VT_EMPTY
)
845 || (TargetFrameName
&& V_VT(TargetFrameName
) != VT_EMPTY
))
846 FIXME("Unsupported args (Flags %p:%d; TargetFrameName %p:%d)\n",
847 Flags
, Flags
? V_VT(Flags
) : -1, TargetFrameName
,
848 TargetFrameName
? V_VT(TargetFrameName
) : -1);
850 if(PostData
&& V_VT(PostData
) == (VT_ARRAY
| VT_UI1
) && V_ARRAY(PostData
)) {
851 SafeArrayAccessData(V_ARRAY(PostData
), (void**)&post_data
);
852 post_data_len
= V_ARRAY(PostData
)->rgsabound
[0].cElements
;
855 if(Headers
&& V_VT(Headers
) == VT_BSTR
) {
856 headers
= V_BSTR(Headers
);
857 TRACE("Headers: %s\n", debugstr_w(headers
));
860 set_doc_state(This
, READYSTATE_LOADING
);
861 This
->ready_state
= READYSTATE_LOADING
;
863 if(This
->doc_navigate
) {
864 WCHAR new_url
[INTERNET_MAX_URL_LENGTH
];
866 if(PathIsURLW(url
)) {
871 size
= sizeof(new_url
)/sizeof(WCHAR
);
872 hres
= UrlApplySchemeW(url
, new_url
, &size
,
873 URL_APPLY_GUESSSCHEME
| URL_APPLY_GUESSFILE
| URL_APPLY_DEFAULT
);
875 WARN("UrlApplyScheme failed: %08x\n", hres
);
880 hres
= async_doc_navigate(This
, *new_url
? new_url
: url
, headers
, post_data
,
881 post_data_len
, TRUE
);
883 task_navigate_bsc_t
*task
;
885 task
= heap_alloc(sizeof(*task
));
886 task
->bsc
= create_callback(This
, url
, post_data
, post_data_len
, headers
);
887 push_dochost_task(This
, &task
->header
, navigate_bsc_proc
, navigate_bsc_task_destr
, This
->url
== NULL
);
891 SafeArrayUnaccessData(V_ARRAY(PostData
));
896 static HRESULT
navigate_hlink(DocHost
*This
, IMoniker
*mon
, IBindCtx
*bindctx
,
897 IBindStatusCallback
*callback
)
899 IHttpNegotiate
*http_negotiate
;
900 BindStatusCallback
*bsc
;
901 PBYTE post_data
= NULL
;
902 ULONG post_data_len
= 0;
903 LPWSTR headers
= NULL
, url
;
910 hres
= IMoniker_GetDisplayName(mon
, 0, NULL
, &url
);
912 FIXME("GetDisplayName failed: %08x\n", hres
);
914 hres
= IBindStatusCallback_QueryInterface(callback
, &IID_IHttpNegotiate
,
915 (void**)&http_negotiate
);
916 if(SUCCEEDED(hres
)) {
917 static const WCHAR null_string
[] = {0};
919 IHttpNegotiate_BeginningTransaction(http_negotiate
, null_string
, null_string
, 0,
921 IHttpNegotiate_Release(http_negotiate
);
924 memset(&bindinfo
, 0, sizeof(bindinfo
));
925 bindinfo
.cbSize
= sizeof(bindinfo
);
927 hres
= IBindStatusCallback_GetBindInfo(callback
, &bindf
, &bindinfo
);
928 dump_BINDINFO(&bindinfo
);
929 if(bindinfo
.dwBindVerb
== BINDVERB_POST
) {
930 post_data_len
= bindinfo
.cbstgmedData
;
932 post_data
= bindinfo
.stgmedData
.u
.hGlobal
;
935 if(This
->doc_navigate
) {
936 hres
= async_doc_navigate(This
, url
, headers
, post_data
, post_data_len
, FALSE
);
938 bsc
= create_callback(This
, url
, post_data
, post_data_len
, headers
);
939 hres
= navigate_bsc(This
, bsc
, mon
);
940 IBindStatusCallback_Release(&bsc
->IBindStatusCallback_iface
);
944 CoTaskMemFree(headers
);
945 ReleaseBindInfo(&bindinfo
);
950 HRESULT
go_home(DocHost
*This
)
953 DWORD res
, type
, size
;
954 WCHAR wszPageName
[MAX_PATH
];
955 static const WCHAR wszAboutBlank
[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
956 static const WCHAR wszStartPage
[] = {'S','t','a','r','t',' ','P','a','g','e',0};
957 static const WCHAR wszSubKey
[] = {'S','o','f','t','w','a','r','e','\\',
958 'M','i','c','r','o','s','o','f','t','\\',
959 'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\',
962 res
= RegOpenKeyW(HKEY_CURRENT_USER
, wszSubKey
, &hkey
);
963 if (res
!= ERROR_SUCCESS
)
964 return navigate_url(This
, wszAboutBlank
, NULL
, NULL
, NULL
, NULL
);
966 size
= sizeof(wszPageName
);
967 res
= RegQueryValueExW(hkey
, wszStartPage
, NULL
, &type
, (LPBYTE
)wszPageName
, &size
);
969 if (res
!= ERROR_SUCCESS
|| type
!= REG_SZ
)
970 return navigate_url(This
, wszAboutBlank
, NULL
, NULL
, NULL
, NULL
);
972 return navigate_url(This
, wszPageName
, NULL
, NULL
, NULL
, NULL
);
975 HRESULT
get_location_url(DocHost
*This
, BSTR
*ret
)
977 FIXME("semi-stub\n");
979 *ret
= This
->url
? SysAllocString(This
->url
) : SysAllocStringLen(NULL
, 0);
981 return E_OUTOFMEMORY
;
983 return This
->url
? S_OK
: S_FALSE
;
986 static inline HlinkFrame
*impl_from_IHlinkFrame(IHlinkFrame
*iface
)
988 return CONTAINING_RECORD(iface
, HlinkFrame
, IHlinkFrame_iface
);
991 static HRESULT WINAPI
HlinkFrame_QueryInterface(IHlinkFrame
*iface
, REFIID riid
, void **ppv
)
993 HlinkFrame
*This
= impl_from_IHlinkFrame(iface
);
994 return IUnknown_QueryInterface(This
->outer
, riid
, ppv
);
997 static ULONG WINAPI
HlinkFrame_AddRef(IHlinkFrame
*iface
)
999 HlinkFrame
*This
= impl_from_IHlinkFrame(iface
);
1000 return IUnknown_AddRef(This
->outer
);
1003 static ULONG WINAPI
HlinkFrame_Release(IHlinkFrame
*iface
)
1005 HlinkFrame
*This
= impl_from_IHlinkFrame(iface
);
1006 return IUnknown_Release(This
->outer
);
1009 static HRESULT WINAPI
HlinkFrame_SetBrowseContext(IHlinkFrame
*iface
,
1010 IHlinkBrowseContext
*pihlbc
)
1012 HlinkFrame
*This
= impl_from_IHlinkFrame(iface
);
1013 FIXME("(%p)->(%p)\n", This
, pihlbc
);
1017 static HRESULT WINAPI
HlinkFrame_GetBrowseContext(IHlinkFrame
*iface
,
1018 IHlinkBrowseContext
**ppihlbc
)
1020 HlinkFrame
*This
= impl_from_IHlinkFrame(iface
);
1021 FIXME("(%p)->(%p)\n", This
, ppihlbc
);
1025 static HRESULT WINAPI
HlinkFrame_Navigate(IHlinkFrame
*iface
, DWORD grfHLNF
, LPBC pbc
,
1026 IBindStatusCallback
*pibsc
, IHlink
*pihlNavigate
)
1028 HlinkFrame
*This
= impl_from_IHlinkFrame(iface
);
1030 LPWSTR location
= NULL
;
1032 TRACE("(%p)->(%08x %p %p %p)\n", This
, grfHLNF
, pbc
, pibsc
, pihlNavigate
);
1035 FIXME("unsupported grfHLNF=%08x\n", grfHLNF
);
1037 /* Windows calls GetTargetFrameName here. */
1039 IHlink_GetMonikerReference(pihlNavigate
, 1, &mon
, &location
);
1042 FIXME("location = %s\n", debugstr_w(location
));
1043 CoTaskMemFree(location
);
1046 /* Windows calls GetHlinkSite here */
1048 if(grfHLNF
& HLNF_OPENINNEWWINDOW
) {
1049 FIXME("Not supported HLNF_OPENINNEWWINDOW\n");
1053 return navigate_hlink(This
->doc_host
, mon
, pbc
, pibsc
);
1056 static HRESULT WINAPI
HlinkFrame_OnNavigate(IHlinkFrame
*iface
, DWORD grfHLNF
,
1057 IMoniker
*pimkTarget
, LPCWSTR pwzLocation
, LPCWSTR pwzFriendlyName
, DWORD dwreserved
)
1059 HlinkFrame
*This
= impl_from_IHlinkFrame(iface
);
1060 FIXME("(%p)->(%08x %p %s %s %d)\n", This
, grfHLNF
, pimkTarget
, debugstr_w(pwzLocation
),
1061 debugstr_w(pwzFriendlyName
), dwreserved
);
1065 static HRESULT WINAPI
HlinkFrame_UpdateHlink(IHlinkFrame
*iface
, ULONG uHLID
,
1066 IMoniker
*pimkTarget
, LPCWSTR pwzLocation
, LPCWSTR pwzFriendlyName
)
1068 HlinkFrame
*This
= impl_from_IHlinkFrame(iface
);
1069 FIXME("(%p)->(%u %p %s %s)\n", This
, uHLID
, pimkTarget
, debugstr_w(pwzLocation
),
1070 debugstr_w(pwzFriendlyName
));
1074 static const IHlinkFrameVtbl HlinkFrameVtbl
= {
1075 HlinkFrame_QueryInterface
,
1078 HlinkFrame_SetBrowseContext
,
1079 HlinkFrame_GetBrowseContext
,
1080 HlinkFrame_Navigate
,
1081 HlinkFrame_OnNavigate
,
1082 HlinkFrame_UpdateHlink
1085 static inline HlinkFrame
*impl_from_ITargetFrame2(ITargetFrame2
*iface
)
1087 return CONTAINING_RECORD(iface
, HlinkFrame
, IHlinkFrame_iface
);
1090 static HRESULT WINAPI
TargetFrame2_QueryInterface(ITargetFrame2
*iface
, REFIID riid
, void **ppv
)
1092 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1093 return IUnknown_QueryInterface(This
->outer
, riid
, ppv
);
1096 static ULONG WINAPI
TargetFrame2_AddRef(ITargetFrame2
*iface
)
1098 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1099 return IUnknown_AddRef(This
->outer
);
1102 static ULONG WINAPI
TargetFrame2_Release(ITargetFrame2
*iface
)
1104 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1105 return IUnknown_Release(This
->outer
);
1108 static HRESULT WINAPI
TargetFrame2_SetFrameName(ITargetFrame2
*iface
, LPCWSTR pszFrameName
)
1110 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1111 FIXME("(%p)->(%s)\n", This
, debugstr_w(pszFrameName
));
1115 static HRESULT WINAPI
TargetFrame2_GetFrameName(ITargetFrame2
*iface
, LPWSTR
*ppszFrameName
)
1117 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1118 FIXME("(%p)->(%p)\n", This
, ppszFrameName
);
1122 static HRESULT WINAPI
TargetFrame2_GetParentFrame(ITargetFrame2
*iface
, IUnknown
**ppunkParent
)
1124 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1125 FIXME("(%p)->(%p)\n", This
, ppunkParent
);
1129 static HRESULT WINAPI
TargetFrame2_SetFrameSrc(ITargetFrame2
*iface
, LPCWSTR pszFrameSrc
)
1131 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1132 FIXME("(%p)->(%s)\n", This
, debugstr_w(pszFrameSrc
));
1136 static HRESULT WINAPI
TargetFrame2_GetFrameSrc(ITargetFrame2
*iface
, LPWSTR
*ppszFrameSrc
)
1138 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1139 FIXME("(%p)->()\n", This
);
1143 static HRESULT WINAPI
TargetFrame2_GetFramesContainer(ITargetFrame2
*iface
, IOleContainer
**ppContainer
)
1145 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1146 FIXME("(%p)->(%p)\n", This
, ppContainer
);
1150 static HRESULT WINAPI
TargetFrame2_SetFrameOptions(ITargetFrame2
*iface
, DWORD dwFlags
)
1152 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1153 FIXME("(%p)->(%x)\n", This
, dwFlags
);
1157 static HRESULT WINAPI
TargetFrame2_GetFrameOptions(ITargetFrame2
*iface
, DWORD
*pdwFlags
)
1159 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1160 FIXME("(%p)->(%p)\n", This
, pdwFlags
);
1164 static HRESULT WINAPI
TargetFrame2_SetFrameMargins(ITargetFrame2
*iface
, DWORD dwWidth
, DWORD dwHeight
)
1166 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1167 FIXME("(%p)->(%d %d)\n", This
, dwWidth
, dwHeight
);
1171 static HRESULT WINAPI
TargetFrame2_GetFrameMargins(ITargetFrame2
*iface
, DWORD
*pdwWidth
, DWORD
*pdwHeight
)
1173 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1174 FIXME("(%p)->(%p %p)\n", This
, pdwWidth
, pdwHeight
);
1178 static HRESULT WINAPI
TargetFrame2_FindFrame(ITargetFrame2
*iface
, LPCWSTR pszTargetName
, DWORD dwFlags
, IUnknown
**ppunkTargetFrame
)
1180 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1181 FIXME("(%p)->(%s %x %p)\n", This
, debugstr_w(pszTargetName
), dwFlags
, ppunkTargetFrame
);
1185 static HRESULT WINAPI
TargetFrame2_GetTargetAlias(ITargetFrame2
*iface
, LPCWSTR pszTargetName
, LPWSTR
*ppszTargetAlias
)
1187 HlinkFrame
*This
= impl_from_ITargetFrame2(iface
);
1188 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(pszTargetName
), ppszTargetAlias
);
1192 static const ITargetFrame2Vtbl TargetFrame2Vtbl
= {
1193 TargetFrame2_QueryInterface
,
1194 TargetFrame2_AddRef
,
1195 TargetFrame2_Release
,
1196 TargetFrame2_SetFrameName
,
1197 TargetFrame2_GetFrameName
,
1198 TargetFrame2_GetParentFrame
,
1199 TargetFrame2_SetFrameSrc
,
1200 TargetFrame2_GetFrameSrc
,
1201 TargetFrame2_GetFramesContainer
,
1202 TargetFrame2_SetFrameOptions
,
1203 TargetFrame2_GetFrameOptions
,
1204 TargetFrame2_SetFrameMargins
,
1205 TargetFrame2_GetFrameMargins
,
1206 TargetFrame2_FindFrame
,
1207 TargetFrame2_GetTargetAlias
1210 BOOL
HlinkFrame_QI(HlinkFrame
*This
, REFIID riid
, void **ppv
)
1212 if(IsEqualGUID(&IID_IHlinkFrame
, riid
)) {
1213 TRACE("(%p)->(IID_IHlinkFrame %p)\n", This
, ppv
);
1214 *ppv
= &This
->IHlinkFrame_iface
;
1215 }else if(IsEqualGUID(&IID_ITargetFrame2
, riid
)) {
1216 TRACE("(%p)->(IID_ITargetFrame2 %p)\n", This
, ppv
);
1217 *ppv
= &This
->ITargetFrame2_iface
;
1222 IUnknown_AddRef((IUnknown
*)*ppv
);
1226 void HlinkFrame_Init(HlinkFrame
*This
, IUnknown
*outer
, DocHost
*doc_host
)
1228 This
->IHlinkFrame_iface
.lpVtbl
= &HlinkFrameVtbl
;
1229 This
->ITargetFrame2_iface
.lpVtbl
= &TargetFrame2Vtbl
;
1231 This
->outer
= outer
;
1232 This
->doc_host
= doc_host
;