include: Add event trace flags and guid to evntrace.h.
[wine.git] / dlls / ieframe / navigate.c
blob2eaf2007bdeab8704687f183c702fd539e0fdf10
1 /*
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
21 #include "ieframe.h"
23 #include "exdispid.h"
24 #include "shellapi.h"
25 #include "winreg.h"
26 #include "shlwapi.h"
27 #include "wininet.h"
28 #include "mshtml.h"
29 #include "perhist.h"
30 #include "resource.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(ieframe);
36 static const WCHAR emptyW[] = {0};
38 typedef struct {
39 IBindStatusCallback IBindStatusCallback_iface;
40 IHttpNegotiate IHttpNegotiate_iface;
41 IHttpSecurity IHttpSecurity_iface;
43 LONG ref;
45 DocHost *doc_host;
46 IBinding *binding;
48 BSTR url;
49 HGLOBAL post_data;
50 BSTR headers;
51 ULONG post_data_len;
52 } BindStatusCallback;
54 static void dump_BINDINFO(BINDINFO *bi)
56 static const char * const BINDINFOF_str[] = {
57 "#0",
58 "BINDINFOF_URLENCODESTGMEDDATA",
59 "BINDINFOF_URLENCODEDEXTRAINFO"
62 static const char * const BINDVERB_str[] = {
63 "BINDVERB_GET",
64 "BINDVERB_POST",
65 "BINDVERB_PUT",
66 "BINDVERB_CUSTOM"
69 TRACE("\n"
70 "BINDINFO = {\n"
71 " %d, %s,\n"
72 " {%d, %p, %p},\n"
73 " %s,\n"
74 " %s,\n"
75 " %s,\n"
76 " %d, %08x, %d, %d\n"
77 " {%d %p %x},\n"
78 " %s\n"
79 " %p, %d\n"
80 "}\n",
82 bi->cbSize, debugstr_w(bi->szExtraInfo),
83 bi->stgmedData.tymed, bi->stgmedData.u.hGlobal, bi->stgmedData.pUnkForRelease,
84 bi->grfBindInfoF > BINDINFOF_URLENCODEDEXTRAINFO
85 ? "unknown" : BINDINFOF_str[bi->grfBindInfoF],
86 bi->dwBindVerb > BINDVERB_CUSTOM
87 ? "unknown" : BINDVERB_str[bi->dwBindVerb],
88 debugstr_w(bi->szCustomVerb),
89 bi->cbstgmedData, bi->dwOptions, bi->dwOptionsFlags, bi->dwCodePage,
90 bi->securityAttributes.nLength,
91 bi->securityAttributes.lpSecurityDescriptor,
92 bi->securityAttributes.bInheritHandle,
93 debugstr_guid(&bi->iid),
94 bi->pUnk, bi->dwReserved
98 static void set_status_text(BindStatusCallback *This, ULONG statuscode, LPCWSTR str)
100 VARIANTARG arg;
101 DISPPARAMS dispparams = {&arg, NULL, 1, 0};
102 WCHAR fmt[IDS_STATUSFMT_MAXLEN];
103 WCHAR buffer[IDS_STATUSFMT_MAXLEN + INTERNET_MAX_URL_LENGTH];
105 if(!This->doc_host)
106 return;
108 TRACE("(%p, %d, %s)\n", This, statuscode, debugstr_w(str));
109 buffer[0] = 0;
110 if (statuscode && str && *str) {
111 fmt[0] = 0;
112 /* the format string must have one "%s" for the str */
113 LoadStringW(ieframe_instance, IDS_STATUSFMT_FIRST + statuscode, fmt, IDS_STATUSFMT_MAXLEN);
114 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), fmt, str);
117 V_VT(&arg) = VT_BSTR;
118 V_BSTR(&arg) = str ? SysAllocString(buffer) : NULL;
119 TRACE("=> %s\n", debugstr_w(V_BSTR(&arg)));
121 call_sink(This->doc_host->cps.wbe2, DISPID_STATUSTEXTCHANGE, &dispparams);
123 if(This->doc_host->frame)
124 IOleInPlaceFrame_SetStatusText(This->doc_host->frame, buffer);
126 VariantClear(&arg);
130 HRESULT set_dochost_url(DocHost *This, const WCHAR *url)
132 WCHAR *new_url;
134 if(url) {
135 new_url = heap_strdupW(url);
136 if(!new_url)
137 return E_OUTOFMEMORY;
138 }else {
139 new_url = NULL;
142 heap_free(This->url);
143 This->url = new_url;
145 This->container_vtbl->SetURL(This, This->url);
146 return S_OK;
149 static inline BindStatusCallback *impl_from_IBindStatusCallback(IBindStatusCallback *iface)
151 return CONTAINING_RECORD(iface, BindStatusCallback, IBindStatusCallback_iface);
154 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallback *iface,
155 REFIID riid, void **ppv)
157 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
159 if(IsEqualGUID(&IID_IUnknown, riid)) {
160 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
161 *ppv = &This->IBindStatusCallback_iface;
162 }else if(IsEqualGUID(&IID_IBindStatusCallback, riid)) {
163 TRACE("(%p)->(IID_IBindStatusCallback %p)\n", This, ppv);
164 *ppv = &This->IBindStatusCallback_iface;
165 }else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) {
166 TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This, ppv);
167 *ppv = &This->IHttpNegotiate_iface;
168 }else if(IsEqualGUID(&IID_IWindowForBindingUI, riid)) {
169 TRACE("(%p)->(IID_IWindowForBindingUI %p)\n", This, ppv);
170 *ppv = &This->IHttpSecurity_iface;
171 }else if(IsEqualGUID(&IID_IHttpSecurity, riid)) {
172 TRACE("(%p)->(IID_IHttpSecurity %p)\n", This, ppv);
173 *ppv = &This->IHttpSecurity_iface;
174 }else {
175 *ppv = NULL;
176 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
177 return E_NOINTERFACE;
180 IUnknown_AddRef((IUnknown*)*ppv);
181 return S_OK;
184 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallback *iface)
186 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
187 LONG ref = InterlockedIncrement(&This->ref);
189 TRACE("(%p) ref=%d\n", This, ref);
191 return ref;
194 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallback *iface)
196 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
197 LONG ref = InterlockedDecrement(&This->ref);
199 TRACE("(%p) ref=%d\n", This, ref);
201 if(!ref) {
202 if(This->doc_host)
203 IOleClientSite_Release(&This->doc_host->IOleClientSite_iface);
204 if(This->binding)
205 IBinding_Release(This->binding);
206 if(This->post_data)
207 GlobalFree(This->post_data);
208 SysFreeString(This->headers);
209 SysFreeString(This->url);
210 heap_free(This);
213 return ref;
216 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallback *iface,
217 DWORD dwReserved, IBinding *pbind)
219 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
221 TRACE("(%p)->(%d %p)\n", This, dwReserved, pbind);
223 This->binding = pbind;
224 IBinding_AddRef(This->binding);
226 return S_OK;
229 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface,
230 LONG *pnPriority)
232 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
233 FIXME("(%p)->(%p)\n", This, pnPriority);
234 return E_NOTIMPL;
237 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface,
238 DWORD reserved)
240 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
241 FIXME("(%p)->(%d)\n", This, reserved);
242 return E_NOTIMPL;
245 static DWORD get_http_status_code(IBinding *binding)
247 IWinInetHttpInfo *http_info;
248 DWORD status, size = sizeof(DWORD);
249 HRESULT hres;
251 hres = IBinding_QueryInterface(binding, &IID_IWinInetHttpInfo, (void**)&http_info);
252 if(FAILED(hres))
253 return HTTP_STATUS_OK;
255 hres = IWinInetHttpInfo_QueryInfo(http_info, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER,
256 &status, &size, NULL, NULL);
257 IWinInetHttpInfo_Release(http_info);
259 if(FAILED(hres))
260 return HTTP_STATUS_OK;
261 return status;
264 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallback *iface,
265 ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
267 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
268 DWORD status_code;
270 TRACE("(%p)->(%d %d %d %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
271 debugstr_w(szStatusText));
273 switch(ulStatusCode) {
274 case BINDSTATUS_REDIRECTING:
275 return set_dochost_url(This->doc_host, szStatusText);
276 case BINDSTATUS_BEGINDOWNLOADDATA:
277 set_status_text(This, ulStatusCode, szStatusText);
278 status_code = get_http_status_code(This->binding);
279 if(status_code != HTTP_STATUS_OK)
280 handle_navigation_error(This->doc_host, status_code, This->url, NULL);
281 return S_OK;
283 case BINDSTATUS_FINDINGRESOURCE:
284 case BINDSTATUS_ENDDOWNLOADDATA:
285 case BINDSTATUS_SENDINGREQUEST:
286 set_status_text(This, ulStatusCode, szStatusText);
287 return S_OK;
289 case BINDSTATUS_CONNECTING:
290 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
291 case BINDSTATUS_CLASSIDAVAILABLE:
292 case BINDSTATUS_MIMETYPEAVAILABLE:
293 case BINDSTATUS_BEGINSYNCOPERATION:
294 case BINDSTATUS_ENDSYNCOPERATION:
295 return S_OK;
296 default:
297 FIXME("status code %u\n", ulStatusCode);
300 return S_OK;
303 void handle_navigation_error(DocHost* doc_host, HRESULT hres, BSTR url, IHTMLWindow2 *win2)
305 VARIANT var_status_code, var_frame_name, var_url;
306 DISPPARAMS dispparams;
307 VARIANTARG params[5];
308 VARIANT_BOOL cancel = VARIANT_FALSE;
310 dispparams.cArgs = 5;
311 dispparams.cNamedArgs = 0;
312 dispparams.rgdispidNamedArgs = NULL;
313 dispparams.rgvarg = params;
315 V_VT(params) = VT_BOOL|VT_BYREF;
316 V_BOOLREF(params) = &cancel;
318 V_VT(params+1) = VT_VARIANT|VT_BYREF;
319 V_VARIANTREF(params+1) = &var_status_code;
320 V_VT(&var_status_code) = VT_I4;
321 V_I4(&var_status_code) = hres;
323 V_VT(params+2) = VT_VARIANT|VT_BYREF;
324 V_VARIANTREF(params+2) = &var_frame_name;
325 V_VT(&var_frame_name) = VT_BSTR;
326 if(win2) {
327 hres = IHTMLWindow2_get_name(win2, &V_BSTR(&var_frame_name));
328 if(FAILED(hres))
329 V_BSTR(&var_frame_name) = NULL;
330 } else
331 V_BSTR(&var_frame_name) = NULL;
333 V_VT(params+3) = VT_VARIANT|VT_BYREF;
334 V_VARIANTREF(params+3) = &var_url;
335 V_VT(&var_url) = VT_BSTR;
336 V_BSTR(&var_url) = url;
338 V_VT(params+4) = VT_DISPATCH;
339 V_DISPATCH(params+4) = (IDispatch*)doc_host->wb;
341 call_sink(doc_host->cps.wbe2, DISPID_NAVIGATEERROR, &dispparams);
342 SysFreeString(V_BSTR(&var_frame_name));
344 if(!cancel)
345 FIXME("Navigate to error page\n");
348 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
349 HRESULT hresult, LPCWSTR szError)
351 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
353 TRACE("(%p)->(%08x %s)\n", This, hresult, debugstr_w(szError));
355 set_status_text(This, 0, emptyW);
357 if(!This->doc_host)
358 return S_OK;
360 if(FAILED(hresult))
361 handle_navigation_error(This->doc_host, hresult, This->url, NULL);
363 IOleClientSite_Release(&This->doc_host->IOleClientSite_iface);
364 This->doc_host = NULL;
366 IBinding_Release(This->binding);
367 This->binding = NULL;
369 return S_OK;
372 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
373 DWORD *grfBINDF, BINDINFO *pbindinfo)
375 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
377 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
379 *grfBINDF = BINDF_ASYNCHRONOUS;
381 if(This->post_data) {
382 pbindinfo->dwBindVerb = BINDVERB_POST;
384 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
385 pbindinfo->stgmedData.u.hGlobal = This->post_data;
386 pbindinfo->cbstgmedData = This->post_data_len;
387 pbindinfo->stgmedData.pUnkForRelease = (IUnknown*)&This->IBindStatusCallback_iface;
388 IBindStatusCallback_AddRef(&This->IBindStatusCallback_iface);
391 return S_OK;
394 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
395 DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
397 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
398 FIXME("(%p)->(%08x %d %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed);
399 return E_NOTIMPL;
402 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
403 REFIID riid, IUnknown *punk)
405 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
407 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), punk);
409 return dochost_object_available(This->doc_host, punk);
412 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
413 BindStatusCallback_QueryInterface,
414 BindStatusCallback_AddRef,
415 BindStatusCallback_Release,
416 BindStatusCallback_OnStartBinding,
417 BindStatusCallback_GetPriority,
418 BindStatusCallback_OnLowResource,
419 BindStatusCallback_OnProgress,
420 BindStatusCallback_OnStopBinding,
421 BindStatusCallback_GetBindInfo,
422 BindStatusCallback_OnDataAvailable,
423 BindStatusCallback_OnObjectAvailable
426 static inline BindStatusCallback *impl_from_IHttpNegotiate(IHttpNegotiate *iface)
428 return CONTAINING_RECORD(iface, BindStatusCallback, IHttpNegotiate_iface);
431 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate *iface,
432 REFIID riid, void **ppv)
434 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
435 return IBindStatusCallback_QueryInterface(&This->IBindStatusCallback_iface, riid, ppv);
438 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate *iface)
440 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
441 return IBindStatusCallback_AddRef(&This->IBindStatusCallback_iface);
444 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate *iface)
446 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
447 return IBindStatusCallback_Release(&This->IBindStatusCallback_iface);
450 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate *iface,
451 LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
453 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
455 TRACE("(%p)->(%s %s %d %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders),
456 dwReserved, pszAdditionalHeaders);
458 if(This->headers) {
459 int size = (strlenW(This->headers)+1)*sizeof(WCHAR);
460 *pszAdditionalHeaders = CoTaskMemAlloc(size);
461 memcpy(*pszAdditionalHeaders, This->headers, size);
464 return S_OK;
467 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate *iface,
468 DWORD dwResponseCode, LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders,
469 LPWSTR *pszAdditionalRequestHeaders)
471 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
472 TRACE("(%p)->(%d %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
473 debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
474 return S_OK;
477 static const IHttpNegotiateVtbl HttpNegotiateVtbl = {
478 HttpNegotiate_QueryInterface,
479 HttpNegotiate_AddRef,
480 HttpNegotiate_Release,
481 HttpNegotiate_BeginningTransaction,
482 HttpNegotiate_OnResponse
485 static inline BindStatusCallback *impl_from_IHttpSecurity(IHttpSecurity *iface)
487 return CONTAINING_RECORD(iface, BindStatusCallback, IHttpSecurity_iface);
490 static HRESULT WINAPI HttpSecurity_QueryInterface(IHttpSecurity *iface, REFIID riid, void **ppv)
492 BindStatusCallback *This = impl_from_IHttpSecurity(iface);
493 return IBindStatusCallback_QueryInterface(&This->IBindStatusCallback_iface, riid, ppv);
496 static ULONG WINAPI HttpSecurity_AddRef(IHttpSecurity *iface)
498 BindStatusCallback *This = impl_from_IHttpSecurity(iface);
499 return IBindStatusCallback_AddRef(&This->IBindStatusCallback_iface);
502 static ULONG WINAPI HttpSecurity_Release(IHttpSecurity *iface)
504 BindStatusCallback *This = impl_from_IHttpSecurity(iface);
505 return IBindStatusCallback_Release(&This->IBindStatusCallback_iface);
508 static HRESULT WINAPI HttpSecurity_GetWindow(IHttpSecurity *iface, REFGUID rguidReason, HWND *phwnd)
510 BindStatusCallback *This = impl_from_IHttpSecurity(iface);
512 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(rguidReason), phwnd);
514 if(!This->doc_host)
515 return E_FAIL;
517 *phwnd = This->doc_host->frame_hwnd;
518 return S_OK;
521 static HRESULT WINAPI HttpSecurity_OnSecurityProblem(IHttpSecurity *iface, DWORD dwProblem)
523 BindStatusCallback *This = impl_from_IHttpSecurity(iface);
524 FIXME("(%p)->(%u)\n", This, dwProblem);
525 return S_FALSE;
528 static const IHttpSecurityVtbl HttpSecurityVtbl = {
529 HttpSecurity_QueryInterface,
530 HttpSecurity_AddRef,
531 HttpSecurity_Release,
532 HttpSecurity_GetWindow,
533 HttpSecurity_OnSecurityProblem
536 static BindStatusCallback *create_callback(DocHost *doc_host, LPCWSTR url, PBYTE post_data,
537 ULONG post_data_len, LPCWSTR headers)
539 BindStatusCallback *ret = heap_alloc(sizeof(BindStatusCallback));
541 ret->IBindStatusCallback_iface.lpVtbl = &BindStatusCallbackVtbl;
542 ret->IHttpNegotiate_iface.lpVtbl = &HttpNegotiateVtbl;
543 ret->IHttpSecurity_iface.lpVtbl = &HttpSecurityVtbl;
545 ret->ref = 1;
546 ret->url = SysAllocString(url);
547 ret->post_data = NULL;
548 ret->post_data_len = post_data_len;
549 ret->headers = headers ? SysAllocString(headers) : NULL;
551 ret->doc_host = doc_host;
552 IOleClientSite_AddRef(&doc_host->IOleClientSite_iface);
554 ret->binding = NULL;
556 if(post_data) {
557 ret->post_data = GlobalAlloc(0, post_data_len);
558 memcpy(ret->post_data, post_data, post_data_len);
561 return ret;
564 static void on_before_navigate2(DocHost *This, LPCWSTR url, SAFEARRAY *post_data, LPWSTR headers, VARIANT_BOOL *cancel)
566 VARIANT var_url, var_flags, var_frame_name, var_post_data, var_post_data2, var_headers;
567 DISPPARAMS dispparams;
568 VARIANTARG params[7];
569 WCHAR file_path[MAX_PATH];
570 DWORD file_path_len = sizeof(file_path) / sizeof(*file_path);
572 dispparams.cArgs = 7;
573 dispparams.cNamedArgs = 0;
574 dispparams.rgdispidNamedArgs = NULL;
575 dispparams.rgvarg = params;
577 This->busy = VARIANT_TRUE;
579 V_VT(params) = VT_BOOL|VT_BYREF;
580 V_BOOLREF(params) = cancel;
582 V_VT(params+1) = (VT_BYREF|VT_VARIANT);
583 V_VARIANTREF(params+1) = &var_headers;
584 V_VT(&var_headers) = VT_BSTR;
585 V_BSTR(&var_headers) = headers;
587 V_VT(params+2) = (VT_BYREF|VT_VARIANT);
588 V_VARIANTREF(params+2) = &var_post_data2;
589 V_VT(&var_post_data2) = (VT_BYREF|VT_VARIANT);
590 V_VARIANTREF(&var_post_data2) = &var_post_data;
592 if(post_data) {
593 V_VT(&var_post_data) = VT_UI1|VT_ARRAY;
594 V_ARRAY(&var_post_data) = post_data;
595 }else {
596 V_VT(&var_post_data) = VT_EMPTY;
599 V_VT(params+3) = (VT_BYREF|VT_VARIANT);
600 V_VARIANTREF(params+3) = &var_frame_name;
601 V_VT(&var_frame_name) = VT_BSTR;
602 V_BSTR(&var_frame_name) = NULL;
604 V_VT(params+4) = (VT_BYREF|VT_VARIANT);
605 V_VARIANTREF(params+4) = &var_flags;
606 V_VT(&var_flags) = VT_I4;
607 V_I4(&var_flags) = 0;
609 V_VT(params+5) = (VT_BYREF|VT_VARIANT);
610 V_VARIANTREF(params+5) = &var_url;
611 V_VT(&var_url) = VT_BSTR;
612 if(PathCreateFromUrlW(url, file_path, &file_path_len, 0) == S_OK)
613 V_BSTR(&var_url) = SysAllocString(file_path);
614 else
615 V_BSTR(&var_url) = SysAllocString(url);
617 V_VT(params+6) = (VT_DISPATCH);
618 V_DISPATCH(params+6) = (IDispatch*)This->wb;
620 call_sink(This->cps.wbe2, DISPID_BEFORENAVIGATE2, &dispparams);
622 SysFreeString(V_BSTR(&var_url));
625 /* FIXME: urlmon should handle it */
626 static BOOL try_application_url(LPCWSTR url)
628 SHELLEXECUTEINFOW exec_info;
629 WCHAR app[64];
630 HKEY hkey;
631 DWORD res, type;
632 HRESULT hres;
634 static const WCHAR wszURLProtocol[] = {'U','R','L',' ','P','r','o','t','o','c','o','l',0};
636 hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, app, sizeof(app)/sizeof(WCHAR), NULL, 0);
637 if(FAILED(hres))
638 return FALSE;
640 res = RegOpenKeyW(HKEY_CLASSES_ROOT, app, &hkey);
641 if(res != ERROR_SUCCESS)
642 return FALSE;
644 res = RegQueryValueExW(hkey, wszURLProtocol, NULL, &type, NULL, NULL);
645 RegCloseKey(hkey);
646 if(res != ERROR_SUCCESS || type != REG_SZ)
647 return FALSE;
649 TRACE("opening application %s\n", debugstr_w(app));
651 memset(&exec_info, 0, sizeof(exec_info));
652 exec_info.cbSize = sizeof(exec_info);
653 exec_info.lpFile = url;
654 exec_info.nShow = SW_SHOW;
656 return ShellExecuteExW(&exec_info);
659 static HRESULT create_moniker(LPCWSTR url, IMoniker **mon)
661 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
662 DWORD size;
663 HRESULT hres;
665 if(PathIsURLW(url))
666 return CreateURLMoniker(NULL, url, mon);
668 size = sizeof(new_url)/sizeof(WCHAR);
669 hres = UrlApplySchemeW(url, new_url, &size, URL_APPLY_GUESSSCHEME | URL_APPLY_GUESSFILE | URL_APPLY_DEFAULT);
670 TRACE("was %s got %s\n", debugstr_w(url), debugstr_w(new_url));
671 if(FAILED(hres)) {
672 WARN("UrlApplyScheme failed: %08x\n", hres);
673 return hres;
676 return CreateURLMoniker(NULL, new_url, mon);
679 static HRESULT bind_to_object(DocHost *This, IMoniker *mon, LPCWSTR url, IBindCtx *bindctx,
680 IBindStatusCallback *callback)
682 IUnknown *unk = NULL;
683 WCHAR *display_name;
684 HRESULT hres;
686 if(mon) {
687 IMoniker_AddRef(mon);
688 }else {
689 hres = create_moniker(url, &mon);
690 if(FAILED(hres))
691 return hres;
694 hres = IMoniker_GetDisplayName(mon, 0, NULL, &display_name);
695 if(FAILED(hres)) {
696 FIXME("GetDisplayName failed: %08x\n", hres);
697 return hres;
700 hres = set_dochost_url(This, display_name);
701 CoTaskMemFree(display_name);
702 if(FAILED(hres))
703 return hres;
705 IBindCtx_RegisterObjectParam(bindctx, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM,
706 (IUnknown*)&This->IOleClientSite_iface);
708 hres = IMoniker_BindToObject(mon, bindctx, NULL, &IID_IUnknown, (void**)&unk);
709 if(SUCCEEDED(hres)) {
710 hres = S_OK;
711 if(unk)
712 IUnknown_Release(unk);
713 }else if(try_application_url(url)) {
714 hres = S_OK;
715 }else {
716 FIXME("BindToObject failed: %08x\n", hres);
719 IMoniker_Release(mon);
720 return S_OK;
723 static void html_window_navigate(DocHost *This, IHTMLPrivateWindow *window, BSTR url, BSTR headers, SAFEARRAY *post_data)
725 VARIANT headers_var, post_data_var;
726 BSTR empty_str;
727 HRESULT hres;
729 hres = set_dochost_url(This, url);
730 if(FAILED(hres))
731 return;
733 empty_str = SysAllocStringLen(NULL, 0);
735 if(headers) {
736 V_VT(&headers_var) = VT_BSTR;
737 V_BSTR(&headers_var) = headers;
738 }else {
739 V_VT(&headers_var) = VT_EMPTY;
742 if(post_data) {
743 V_VT(&post_data_var) = VT_UI1|VT_ARRAY;
744 V_ARRAY(&post_data_var) = post_data;
745 }else {
746 V_VT(&post_data_var) = VT_EMPTY;
749 set_doc_state(This, READYSTATE_LOADING);
750 hres = IHTMLPrivateWindow_SuperNavigate(window, url, empty_str, NULL, NULL, &post_data_var, &headers_var, 0);
751 SysFreeString(empty_str);
752 if(FAILED(hres))
753 WARN("SuprtNavigate failed: %08x\n", hres);
756 typedef struct {
757 task_header_t header;
758 BSTR url;
759 BSTR headers;
760 SAFEARRAY *post_data;
761 BOOL async_notif;
762 } task_doc_navigate_t;
764 static void doc_navigate_task_destr(task_header_t *t)
766 task_doc_navigate_t *task = (task_doc_navigate_t*)t;
768 SysFreeString(task->url);
769 SysFreeString(task->headers);
770 if(task->post_data)
771 SafeArrayDestroy(task->post_data);
772 heap_free(task);
775 void on_commandstate_change(DocHost *doc_host, LONG command, VARIANT_BOOL enable)
777 DISPPARAMS dispparams;
778 VARIANTARG params[2];
780 TRACE("command=%d enable=%d\n", command, enable);
782 dispparams.cArgs = 2;
783 dispparams.cNamedArgs = 0;
784 dispparams.rgdispidNamedArgs = NULL;
785 dispparams.rgvarg = params;
787 V_VT(params) = VT_BOOL;
788 V_BOOL(params) = enable;
790 V_VT(params+1) = VT_I4;
791 V_I4(params+1) = command;
793 call_sink(doc_host->cps.wbe2, DISPID_COMMANDSTATECHANGE, &dispparams);
796 static void doc_navigate_proc(DocHost *This, task_header_t *t)
798 task_doc_navigate_t *task = (task_doc_navigate_t*)t;
799 IHTMLPrivateWindow *priv_window;
800 HRESULT hres;
802 if(!This->doc_navigate) {
803 ERR("Skip nav\n");
804 return;
807 if(task->async_notif) {
808 VARIANT_BOOL cancel = VARIANT_FALSE;
809 on_before_navigate2(This, task->url, task->post_data, task->headers, &cancel);
810 if(cancel) {
811 TRACE("Navigation canceled\n");
812 return;
816 hres = IUnknown_QueryInterface(This->doc_navigate, &IID_IHTMLPrivateWindow, (void**)&priv_window);
817 if(SUCCEEDED(hres)) {
818 html_window_navigate(This, priv_window, task->url, task->headers, task->post_data);
819 IHTMLPrivateWindow_Release(priv_window);
820 }else {
821 WARN("Could not get IHTMLPrivateWindow iface: %08x\n", hres);
825 static HRESULT async_doc_navigate(DocHost *This, LPCWSTR url, LPCWSTR headers, PBYTE post_data, ULONG post_data_size,
826 BOOL async_notif)
828 task_doc_navigate_t *task;
830 TRACE("%s\n", debugstr_w(url));
832 task = heap_alloc_zero(sizeof(*task));
833 if(!task)
834 return E_OUTOFMEMORY;
836 task->url = SysAllocString(url);
837 if(!task->url) {
838 doc_navigate_task_destr(&task->header);
839 return E_OUTOFMEMORY;
842 if(headers) {
843 task->headers = SysAllocString(headers);
844 if(!task->headers) {
845 doc_navigate_task_destr(&task->header);
846 return E_OUTOFMEMORY;
850 if(post_data) {
851 task->post_data = SafeArrayCreateVector(VT_UI1, 0, post_data_size);
852 if(!task->post_data) {
853 doc_navigate_task_destr(&task->header);
854 return E_OUTOFMEMORY;
857 memcpy(task->post_data->pvData, post_data, post_data_size);
860 if(!async_notif) {
861 VARIANT_BOOL cancel = VARIANT_FALSE;
863 on_before_navigate2(This, task->url, task->post_data, task->headers, &cancel);
864 if(cancel) {
865 TRACE("Navigation canceled\n");
866 doc_navigate_task_destr(&task->header);
867 return S_OK;
871 task->async_notif = async_notif;
872 abort_dochost_tasks(This, doc_navigate_proc);
873 push_dochost_task(This, &task->header, doc_navigate_proc, doc_navigate_task_destr, FALSE);
874 return S_OK;
877 static HRESULT navigate_bsc(DocHost *This, BindStatusCallback *bsc, IMoniker *mon)
879 VARIANT_BOOL cancel = VARIANT_FALSE;
880 SAFEARRAY *post_data = NULL;
881 IBindCtx *bindctx;
882 HRESULT hres;
884 set_doc_state(This, READYSTATE_LOADING);
886 if(bsc->post_data) {
887 post_data = SafeArrayCreateVector(VT_UI1, 0, bsc->post_data_len);
888 memcpy(post_data->pvData, post_data, bsc->post_data_len);
891 on_before_navigate2(This, bsc->url, post_data, bsc->headers, &cancel);
892 if(post_data)
893 SafeArrayDestroy(post_data);
894 if(cancel) {
895 FIXME("Navigation canceled\n");
896 return S_OK;
899 on_commandstate_change(This, CSC_NAVIGATEBACK, VARIANT_FALSE);
900 on_commandstate_change(This, CSC_NAVIGATEFORWARD, VARIANT_FALSE);
902 if(This->document)
903 deactivate_document(This);
905 CreateAsyncBindCtx(0, &bsc->IBindStatusCallback_iface, 0, &bindctx);
907 if(This->frame)
908 IOleInPlaceFrame_EnableModeless(This->frame, FALSE);
910 hres = bind_to_object(This, mon, bsc->url, bindctx, &bsc->IBindStatusCallback_iface);
912 if(This->frame)
913 IOleInPlaceFrame_EnableModeless(This->frame, TRUE);
915 IBindCtx_Release(bindctx);
917 return hres;
920 typedef struct {
921 task_header_t header;
922 BindStatusCallback *bsc;
923 } task_navigate_bsc_t;
925 static void navigate_bsc_task_destr(task_header_t *t)
927 task_navigate_bsc_t *task = (task_navigate_bsc_t*)t;
929 IBindStatusCallback_Release(&task->bsc->IBindStatusCallback_iface);
930 heap_free(task);
933 static void navigate_bsc_proc(DocHost *This, task_header_t *t)
935 task_navigate_bsc_t *task = (task_navigate_bsc_t*)t;
937 if(!This->hwnd)
938 create_doc_view_hwnd(This);
940 navigate_bsc(This, task->bsc, NULL);
944 HRESULT navigate_url(DocHost *This, LPCWSTR url, const VARIANT *Flags,
945 const VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers)
947 SAFEARRAY *post_array = NULL;
948 PBYTE post_data = NULL;
949 ULONG post_data_len = 0;
950 LPWSTR headers = NULL;
951 HRESULT hres = S_OK;
953 TRACE("navigating to %s\n", debugstr_w(url));
955 if((Flags && V_VT(Flags) != VT_EMPTY && V_VT(Flags) != VT_ERROR)
956 || (TargetFrameName && V_VT(TargetFrameName) != VT_EMPTY && V_VT(TargetFrameName) != VT_ERROR))
957 FIXME("Unsupported args (Flags %s; TargetFrameName %s)\n", debugstr_variant(Flags), debugstr_variant(TargetFrameName));
959 if(PostData) {
960 if(V_VT(PostData) & VT_ARRAY)
961 post_array = V_ISBYREF(PostData) ? *V_ARRAYREF(PostData) : V_ARRAY(PostData);
962 else
963 WARN("Invalid post data %s\n", debugstr_variant(PostData));
966 if(post_array) {
967 LONG elem_max;
968 SafeArrayAccessData(post_array, (void**)&post_data);
969 SafeArrayGetUBound(post_array, 1, &elem_max);
970 post_data_len = (elem_max+1) * SafeArrayGetElemsize(post_array);
973 if(Headers && V_VT(Headers) == VT_BSTR) {
974 headers = V_BSTR(Headers);
975 TRACE("Headers: %s\n", debugstr_w(headers));
978 set_doc_state(This, READYSTATE_LOADING);
979 This->ready_state = READYSTATE_LOADING;
981 if(This->doc_navigate) {
982 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
984 if(PathIsURLW(url)) {
985 new_url[0] = 0;
986 }else {
987 DWORD size;
989 size = sizeof(new_url)/sizeof(WCHAR);
990 hres = UrlApplySchemeW(url, new_url, &size,
991 URL_APPLY_GUESSSCHEME | URL_APPLY_GUESSFILE | URL_APPLY_DEFAULT);
992 if(FAILED(hres)) {
993 WARN("UrlApplyScheme failed: %08x\n", hres);
994 new_url[0] = 0;
998 hres = async_doc_navigate(This, *new_url ? new_url : url, headers, post_data,
999 post_data_len, TRUE);
1000 }else {
1001 task_navigate_bsc_t *task;
1003 task = heap_alloc(sizeof(*task));
1004 task->bsc = create_callback(This, url, post_data, post_data_len, headers);
1005 push_dochost_task(This, &task->header, navigate_bsc_proc, navigate_bsc_task_destr, This->url == NULL);
1008 if(post_data)
1009 SafeArrayUnaccessData(post_array);
1011 return hres;
1014 static HRESULT navigate_hlink(DocHost *This, IMoniker *mon, IBindCtx *bindctx,
1015 IBindStatusCallback *callback)
1017 IHttpNegotiate *http_negotiate;
1018 BindStatusCallback *bsc;
1019 PBYTE post_data = NULL;
1020 ULONG post_data_len = 0;
1021 LPWSTR headers = NULL, url;
1022 BINDINFO bindinfo;
1023 DWORD bindf = 0;
1024 HRESULT hres;
1026 TRACE("\n");
1028 hres = IMoniker_GetDisplayName(mon, 0, NULL, &url);
1029 if(FAILED(hres))
1030 FIXME("GetDisplayName failed: %08x\n", hres);
1032 hres = IBindStatusCallback_QueryInterface(callback, &IID_IHttpNegotiate,
1033 (void**)&http_negotiate);
1034 if(SUCCEEDED(hres)) {
1035 static const WCHAR null_string[] = {0};
1037 IHttpNegotiate_BeginningTransaction(http_negotiate, null_string, null_string, 0,
1038 &headers);
1039 IHttpNegotiate_Release(http_negotiate);
1042 memset(&bindinfo, 0, sizeof(bindinfo));
1043 bindinfo.cbSize = sizeof(bindinfo);
1045 hres = IBindStatusCallback_GetBindInfo(callback, &bindf, &bindinfo);
1046 dump_BINDINFO(&bindinfo);
1047 if(bindinfo.dwBindVerb == BINDVERB_POST) {
1048 post_data_len = bindinfo.cbstgmedData;
1049 if(post_data_len)
1050 post_data = bindinfo.stgmedData.u.hGlobal;
1053 if(This->doc_navigate) {
1054 hres = async_doc_navigate(This, url, headers, post_data, post_data_len, FALSE);
1055 }else {
1056 bsc = create_callback(This, url, post_data, post_data_len, headers);
1057 hres = navigate_bsc(This, bsc, mon);
1058 IBindStatusCallback_Release(&bsc->IBindStatusCallback_iface);
1061 CoTaskMemFree(url);
1062 CoTaskMemFree(headers);
1063 ReleaseBindInfo(&bindinfo);
1065 return hres;
1068 HRESULT go_home(DocHost *This)
1070 HKEY hkey;
1071 DWORD res, type, size;
1072 WCHAR wszPageName[MAX_PATH];
1073 static const WCHAR wszAboutBlank[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
1074 static const WCHAR wszStartPage[] = {'S','t','a','r','t',' ','P','a','g','e',0};
1075 static const WCHAR wszSubKey[] = {'S','o','f','t','w','a','r','e','\\',
1076 'M','i','c','r','o','s','o','f','t','\\',
1077 'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\',
1078 'M','a','i','n',0};
1080 res = RegOpenKeyW(HKEY_CURRENT_USER, wszSubKey, &hkey);
1081 if (res != ERROR_SUCCESS)
1082 return navigate_url(This, wszAboutBlank, NULL, NULL, NULL, NULL);
1084 size = sizeof(wszPageName);
1085 res = RegQueryValueExW(hkey, wszStartPage, NULL, &type, (LPBYTE)wszPageName, &size);
1086 RegCloseKey(hkey);
1087 if (res != ERROR_SUCCESS || type != REG_SZ)
1088 return navigate_url(This, wszAboutBlank, NULL, NULL, NULL, NULL);
1090 return navigate_url(This, wszPageName, NULL, NULL, NULL, NULL);
1093 static HRESULT navigate_history(DocHost *This, unsigned travellog_pos)
1095 IPersistHistory *persist_history;
1096 travellog_entry_t *entry;
1097 LARGE_INTEGER li;
1098 HRESULT hres;
1100 if(!This->doc_navigate) {
1101 FIXME("unsupported doc_navigate FALSE\n");
1102 return E_NOTIMPL;
1105 if (travellog_pos < This->travellog.position)
1107 on_commandstate_change(This, CSC_NAVIGATEBACK, VARIANT_FALSE);
1108 on_commandstate_change(This, CSC_NAVIGATEFORWARD, VARIANT_TRUE);
1110 else if (travellog_pos > This->travellog.position)
1112 on_commandstate_change(This, CSC_NAVIGATEBACK, VARIANT_TRUE);
1113 on_commandstate_change(This, CSC_NAVIGATEFORWARD, VARIANT_FALSE);
1116 This->travellog.loading_pos = travellog_pos;
1117 entry = This->travellog.log + This->travellog.loading_pos;
1119 if(!entry->stream)
1120 return async_doc_navigate(This, entry->url, NULL, NULL, 0, FALSE);
1122 hres = IUnknown_QueryInterface(This->document, &IID_IPersistHistory, (void**)&persist_history);
1123 if(FAILED(hres))
1124 return hres;
1126 li.QuadPart = 0;
1127 IStream_Seek(entry->stream, li, STREAM_SEEK_SET, NULL);
1129 hres = IPersistHistory_LoadHistory(persist_history, entry->stream, NULL);
1130 IPersistHistory_Release(persist_history);
1131 return hres;
1134 HRESULT go_back(DocHost *This)
1136 if(!This->travellog.position) {
1137 WARN("No history available\n");
1138 return E_FAIL;
1141 return navigate_history(This, This->travellog.position-1);
1144 HRESULT go_forward(DocHost *This)
1146 if(This->travellog.position >= This->travellog.length) {
1147 WARN("No history available\n");
1148 return E_FAIL;
1151 return navigate_history(This, This->travellog.position+1);
1154 HRESULT get_location_url(DocHost *This, BSTR *ret)
1156 FIXME("semi-stub\n");
1158 *ret = This->url ? SysAllocString(This->url) : SysAllocStringLen(NULL, 0);
1159 if(!*ret)
1160 return E_OUTOFMEMORY;
1162 return This->url ? S_OK : S_FALSE;
1165 static inline HlinkFrame *impl_from_IHlinkFrame(IHlinkFrame *iface)
1167 return CONTAINING_RECORD(iface, HlinkFrame, IHlinkFrame_iface);
1170 static HRESULT WINAPI HlinkFrame_QueryInterface(IHlinkFrame *iface, REFIID riid, void **ppv)
1172 HlinkFrame *This = impl_from_IHlinkFrame(iface);
1173 return IUnknown_QueryInterface(This->outer, riid, ppv);
1176 static ULONG WINAPI HlinkFrame_AddRef(IHlinkFrame *iface)
1178 HlinkFrame *This = impl_from_IHlinkFrame(iface);
1179 return IUnknown_AddRef(This->outer);
1182 static ULONG WINAPI HlinkFrame_Release(IHlinkFrame *iface)
1184 HlinkFrame *This = impl_from_IHlinkFrame(iface);
1185 return IUnknown_Release(This->outer);
1188 static HRESULT WINAPI HlinkFrame_SetBrowseContext(IHlinkFrame *iface,
1189 IHlinkBrowseContext *pihlbc)
1191 HlinkFrame *This = impl_from_IHlinkFrame(iface);
1192 FIXME("(%p)->(%p)\n", This, pihlbc);
1193 return E_NOTIMPL;
1196 static HRESULT WINAPI HlinkFrame_GetBrowseContext(IHlinkFrame *iface,
1197 IHlinkBrowseContext **ppihlbc)
1199 HlinkFrame *This = impl_from_IHlinkFrame(iface);
1200 FIXME("(%p)->(%p)\n", This, ppihlbc);
1201 return E_NOTIMPL;
1204 static HRESULT WINAPI HlinkFrame_Navigate(IHlinkFrame *iface, DWORD grfHLNF, LPBC pbc,
1205 IBindStatusCallback *pibsc, IHlink *pihlNavigate)
1207 HlinkFrame *This = impl_from_IHlinkFrame(iface);
1208 IMoniker *mon;
1209 LPWSTR location = NULL;
1211 TRACE("(%p)->(%08x %p %p %p)\n", This, grfHLNF, pbc, pibsc, pihlNavigate);
1213 if(grfHLNF)
1214 FIXME("unsupported grfHLNF=%08x\n", grfHLNF);
1216 /* Windows calls GetTargetFrameName here. */
1218 IHlink_GetMonikerReference(pihlNavigate, 1, &mon, &location);
1220 if(location) {
1221 FIXME("location = %s\n", debugstr_w(location));
1222 CoTaskMemFree(location);
1225 /* Windows calls GetHlinkSite here */
1227 if(grfHLNF & HLNF_OPENINNEWWINDOW) {
1228 FIXME("Not supported HLNF_OPENINNEWWINDOW\n");
1229 return E_NOTIMPL;
1232 return navigate_hlink(This->doc_host, mon, pbc, pibsc);
1235 static HRESULT WINAPI HlinkFrame_OnNavigate(IHlinkFrame *iface, DWORD grfHLNF,
1236 IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName, DWORD dwreserved)
1238 HlinkFrame *This = impl_from_IHlinkFrame(iface);
1239 FIXME("(%p)->(%08x %p %s %s %d)\n", This, grfHLNF, pimkTarget, debugstr_w(pwzLocation),
1240 debugstr_w(pwzFriendlyName), dwreserved);
1241 return E_NOTIMPL;
1244 static HRESULT WINAPI HlinkFrame_UpdateHlink(IHlinkFrame *iface, ULONG uHLID,
1245 IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName)
1247 HlinkFrame *This = impl_from_IHlinkFrame(iface);
1248 FIXME("(%p)->(%u %p %s %s)\n", This, uHLID, pimkTarget, debugstr_w(pwzLocation),
1249 debugstr_w(pwzFriendlyName));
1250 return E_NOTIMPL;
1253 static const IHlinkFrameVtbl HlinkFrameVtbl = {
1254 HlinkFrame_QueryInterface,
1255 HlinkFrame_AddRef,
1256 HlinkFrame_Release,
1257 HlinkFrame_SetBrowseContext,
1258 HlinkFrame_GetBrowseContext,
1259 HlinkFrame_Navigate,
1260 HlinkFrame_OnNavigate,
1261 HlinkFrame_UpdateHlink
1264 static inline HlinkFrame *impl_from_ITargetFrame2(ITargetFrame2 *iface)
1266 return CONTAINING_RECORD(iface, HlinkFrame, IHlinkFrame_iface);
1269 static HRESULT WINAPI TargetFrame2_QueryInterface(ITargetFrame2 *iface, REFIID riid, void **ppv)
1271 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1272 return IUnknown_QueryInterface(This->outer, riid, ppv);
1275 static ULONG WINAPI TargetFrame2_AddRef(ITargetFrame2 *iface)
1277 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1278 return IUnknown_AddRef(This->outer);
1281 static ULONG WINAPI TargetFrame2_Release(ITargetFrame2 *iface)
1283 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1284 return IUnknown_Release(This->outer);
1287 static HRESULT WINAPI TargetFrame2_SetFrameName(ITargetFrame2 *iface, LPCWSTR pszFrameName)
1289 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1290 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFrameName));
1291 return E_NOTIMPL;
1294 static HRESULT WINAPI TargetFrame2_GetFrameName(ITargetFrame2 *iface, LPWSTR *ppszFrameName)
1296 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1297 FIXME("(%p)->(%p)\n", This, ppszFrameName);
1298 return E_NOTIMPL;
1301 static HRESULT WINAPI TargetFrame2_GetParentFrame(ITargetFrame2 *iface, IUnknown **ppunkParent)
1303 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1304 FIXME("(%p)->(%p)\n", This, ppunkParent);
1305 return E_NOTIMPL;
1308 static HRESULT WINAPI TargetFrame2_SetFrameSrc(ITargetFrame2 *iface, LPCWSTR pszFrameSrc)
1310 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1311 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFrameSrc));
1312 return E_NOTIMPL;
1315 static HRESULT WINAPI TargetFrame2_GetFrameSrc(ITargetFrame2 *iface, LPWSTR *ppszFrameSrc)
1317 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1318 FIXME("(%p)->()\n", This);
1319 return E_NOTIMPL;
1322 static HRESULT WINAPI TargetFrame2_GetFramesContainer(ITargetFrame2 *iface, IOleContainer **ppContainer)
1324 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1325 FIXME("(%p)->(%p)\n", This, ppContainer);
1326 return E_NOTIMPL;
1329 static HRESULT WINAPI TargetFrame2_SetFrameOptions(ITargetFrame2 *iface, DWORD dwFlags)
1331 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1332 FIXME("(%p)->(%x)\n", This, dwFlags);
1333 return E_NOTIMPL;
1336 static HRESULT WINAPI TargetFrame2_GetFrameOptions(ITargetFrame2 *iface, DWORD *pdwFlags)
1338 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1339 FIXME("(%p)->(%p)\n", This, pdwFlags);
1340 return E_NOTIMPL;
1343 static HRESULT WINAPI TargetFrame2_SetFrameMargins(ITargetFrame2 *iface, DWORD dwWidth, DWORD dwHeight)
1345 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1346 FIXME("(%p)->(%d %d)\n", This, dwWidth, dwHeight);
1347 return E_NOTIMPL;
1350 static HRESULT WINAPI TargetFrame2_GetFrameMargins(ITargetFrame2 *iface, DWORD *pdwWidth, DWORD *pdwHeight)
1352 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1353 FIXME("(%p)->(%p %p)\n", This, pdwWidth, pdwHeight);
1354 return E_NOTIMPL;
1357 static HRESULT WINAPI TargetFrame2_FindFrame(ITargetFrame2 *iface, LPCWSTR pszTargetName, DWORD dwFlags, IUnknown **ppunkTargetFrame)
1359 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1360 FIXME("(%p)->(%s %x %p)\n", This, debugstr_w(pszTargetName), dwFlags, ppunkTargetFrame);
1361 return E_NOTIMPL;
1364 static HRESULT WINAPI TargetFrame2_GetTargetAlias(ITargetFrame2 *iface, LPCWSTR pszTargetName, LPWSTR *ppszTargetAlias)
1366 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1367 FIXME("(%p)->(%s %p)\n", This, debugstr_w(pszTargetName), ppszTargetAlias);
1368 return E_NOTIMPL;
1371 static const ITargetFrame2Vtbl TargetFrame2Vtbl = {
1372 TargetFrame2_QueryInterface,
1373 TargetFrame2_AddRef,
1374 TargetFrame2_Release,
1375 TargetFrame2_SetFrameName,
1376 TargetFrame2_GetFrameName,
1377 TargetFrame2_GetParentFrame,
1378 TargetFrame2_SetFrameSrc,
1379 TargetFrame2_GetFrameSrc,
1380 TargetFrame2_GetFramesContainer,
1381 TargetFrame2_SetFrameOptions,
1382 TargetFrame2_GetFrameOptions,
1383 TargetFrame2_SetFrameMargins,
1384 TargetFrame2_GetFrameMargins,
1385 TargetFrame2_FindFrame,
1386 TargetFrame2_GetTargetAlias
1389 static inline HlinkFrame *impl_from_ITargetFramePriv2(ITargetFramePriv2 *iface)
1391 return CONTAINING_RECORD(iface, HlinkFrame, ITargetFramePriv2_iface);
1394 static HRESULT WINAPI TargetFramePriv2_QueryInterface(ITargetFramePriv2 *iface, REFIID riid, void **ppv)
1396 HlinkFrame *This = impl_from_ITargetFramePriv2(iface);
1397 return IUnknown_QueryInterface(This->outer, riid, ppv);
1400 static ULONG WINAPI TargetFramePriv2_AddRef(ITargetFramePriv2 *iface)
1402 HlinkFrame *This = impl_from_ITargetFramePriv2(iface);
1403 return IUnknown_AddRef(This->outer);
1406 static ULONG WINAPI TargetFramePriv2_Release(ITargetFramePriv2 *iface)
1408 HlinkFrame *This = impl_from_ITargetFramePriv2(iface);
1409 return IUnknown_Release(This->outer);
1412 static HRESULT WINAPI TargetFramePriv2_FindFrameDownwards(ITargetFramePriv2 *iface,
1413 LPCWSTR pszTargetName, DWORD dwFlags, IUnknown **ppunkTargetFrame)
1415 HlinkFrame *This = impl_from_ITargetFramePriv2(iface);
1416 FIXME("(%p)->(%s %x %p)\n", This, debugstr_w(pszTargetName), dwFlags, ppunkTargetFrame);
1417 return E_NOTIMPL;
1420 static HRESULT WINAPI TargetFramePriv2_FindFrameInContext(ITargetFramePriv2 *iface,
1421 LPCWSTR pszTargetName, IUnknown *punkContextFrame, DWORD dwFlags, IUnknown **ppunkTargetFrame)
1423 HlinkFrame *This = impl_from_ITargetFramePriv2(iface);
1424 FIXME("(%p)->(%s %p %x %p)\n", This, debugstr_w(pszTargetName), punkContextFrame, dwFlags, ppunkTargetFrame);
1425 return E_NOTIMPL;
1428 static HRESULT WINAPI TargetFramePriv2_OnChildFrameActivate(ITargetFramePriv2 *iface, IUnknown *pUnkChildFrame)
1430 HlinkFrame *This = impl_from_ITargetFramePriv2(iface);
1431 FIXME("(%p)->(%p)\n", This, pUnkChildFrame);
1432 return E_NOTIMPL;
1435 static HRESULT WINAPI TargetFramePriv2_OnChildFrameDeactivate(ITargetFramePriv2 *iface, IUnknown *pUnkChildFrame)
1437 HlinkFrame *This = impl_from_ITargetFramePriv2(iface);
1438 FIXME("(%p)->(%p)\n", This, pUnkChildFrame);
1439 return E_NOTIMPL;
1442 static HRESULT WINAPI TargetFramePriv2_NavigateHack(ITargetFramePriv2 *iface, DWORD grfHLNF, LPBC pbc,
1443 IBindStatusCallback *pibsc, LPCWSTR pszTargetName, LPCWSTR pszUrl, LPCWSTR pszLocation)
1445 HlinkFrame *This = impl_from_ITargetFramePriv2(iface);
1446 FIXME("(%p)->(%x %p %p %s %s %s)\n", This, grfHLNF, pbc, pibsc, debugstr_w(pszTargetName),
1447 debugstr_w(pszUrl), debugstr_w(pszLocation));
1448 return E_NOTIMPL;
1451 static HRESULT WINAPI TargetFramePriv2_FindBrowserByIndex(ITargetFramePriv2 *iface, DWORD dwID, IUnknown **ppunkBrowser)
1453 HlinkFrame *This = impl_from_ITargetFramePriv2(iface);
1454 FIXME("(%p)->(%d %p)\n", This, dwID, ppunkBrowser);
1455 return E_NOTIMPL;
1458 static HRESULT WINAPI TargetFramePriv2_AggregatedNavigation2(ITargetFramePriv2 *iface, DWORD grfHLNF, LPBC pbc,
1459 IBindStatusCallback *pibsc, LPCWSTR pszTargetName, IUri *pUri, LPCWSTR pszLocation)
1461 HlinkFrame *This = impl_from_ITargetFramePriv2(iface);
1462 IMoniker *mon;
1463 HRESULT hres;
1465 TRACE("(%p)->(%x %p %p %s %p %s)\n", This, grfHLNF, pbc, pibsc, debugstr_w(pszTargetName),
1466 pUri, debugstr_w(pszLocation));
1469 * NOTE: This is an undocumented function. It seems to be working the way it's implemented,
1470 * but I couldn't get its tests working. It's used by mshtml to load content in a new
1471 * instance of browser.
1474 hres = CreateURLMonikerEx2(NULL, pUri, &mon, 0);
1475 if(FAILED(hres))
1476 return hres;
1478 hres = navigate_hlink(This->doc_host, mon, pbc, pibsc);
1479 IMoniker_Release(mon);
1480 return hres;
1483 static const ITargetFramePriv2Vtbl TargetFramePriv2Vtbl = {
1484 TargetFramePriv2_QueryInterface,
1485 TargetFramePriv2_AddRef,
1486 TargetFramePriv2_Release,
1487 TargetFramePriv2_FindFrameDownwards,
1488 TargetFramePriv2_FindFrameInContext,
1489 TargetFramePriv2_OnChildFrameActivate,
1490 TargetFramePriv2_OnChildFrameDeactivate,
1491 TargetFramePriv2_NavigateHack,
1492 TargetFramePriv2_FindBrowserByIndex,
1493 TargetFramePriv2_AggregatedNavigation2
1496 static inline HlinkFrame *impl_from_IWebBrowserPriv2IE9(IWebBrowserPriv2IE9 *iface)
1498 return CONTAINING_RECORD(iface, HlinkFrame, IWebBrowserPriv2IE9_iface);
1501 static HRESULT WINAPI WebBrowserPriv2IE9_QueryInterface(IWebBrowserPriv2IE9 *iface, REFIID riid, void **ppv)
1503 HlinkFrame *This = impl_from_IWebBrowserPriv2IE9(iface);
1504 return IUnknown_QueryInterface(This->outer, riid, ppv);
1507 static ULONG WINAPI WebBrowserPriv2IE9_AddRef(IWebBrowserPriv2IE9 *iface)
1509 HlinkFrame *This = impl_from_IWebBrowserPriv2IE9(iface);
1510 return IUnknown_AddRef(This->outer);
1513 static ULONG WINAPI WebBrowserPriv2IE9_Release(IWebBrowserPriv2IE9 *iface)
1515 HlinkFrame *This = impl_from_IWebBrowserPriv2IE9(iface);
1516 return IUnknown_Release(This->outer);
1519 static HRESULT WINAPI WebBrowserPriv2IE9_NavigateWithBindCtx2(IWebBrowserPriv2IE9 *iface, IUri *uri, VARIANT *flags,
1520 VARIANT *target_frame, VARIANT *post_data, VARIANT *headers, IBindCtx *bind_ctx, LPOLESTR url_fragment, DWORD unused)
1522 HlinkFrame *This = impl_from_IWebBrowserPriv2IE9(iface);
1523 FIXME("(%p)->(%p %s %s %s %s %p %s)\n", This, uri, debugstr_variant(flags), debugstr_variant(target_frame),
1524 debugstr_variant(post_data), debugstr_variant(headers), bind_ctx, debugstr_w(url_fragment));
1525 return E_NOTIMPL;
1528 static const IWebBrowserPriv2IE9Vtbl WebBrowserPriv2IE9Vtbl = {
1529 WebBrowserPriv2IE9_QueryInterface,
1530 WebBrowserPriv2IE9_AddRef,
1531 WebBrowserPriv2IE9_Release,
1532 WebBrowserPriv2IE9_NavigateWithBindCtx2
1535 BOOL HlinkFrame_QI(HlinkFrame *This, REFIID riid, void **ppv)
1537 if(IsEqualGUID(&IID_IHlinkFrame, riid)) {
1538 TRACE("(%p)->(IID_IHlinkFrame %p)\n", This, ppv);
1539 *ppv = &This->IHlinkFrame_iface;
1540 }else if(IsEqualGUID(&IID_ITargetFrame2, riid)) {
1541 TRACE("(%p)->(IID_ITargetFrame2 %p)\n", This, ppv);
1542 *ppv = &This->ITargetFrame2_iface;
1543 }else if(IsEqualGUID(&IID_ITargetFramePriv, riid)) {
1544 TRACE("(%p)->(IID_ITargetFramePriv %p)\n", This, ppv);
1545 *ppv = &This->ITargetFramePriv2_iface;
1546 }else if(IsEqualGUID(&IID_ITargetFramePriv2, riid)) {
1547 TRACE("(%p)->(IID_ITargetFramePriv2 %p)\n", This, ppv);
1548 *ppv = &This->ITargetFramePriv2_iface;
1549 }else if(IsEqualGUID(&IID_IWebBrowserPriv2IE9, riid)) {
1550 TRACE("(%p)->(IID_IWebBrowserPriv2IE9 %p)\n", This, ppv);
1551 *ppv = &This->IWebBrowserPriv2IE9_iface;
1552 }else {
1553 return FALSE;
1556 IUnknown_AddRef((IUnknown*)*ppv);
1557 return TRUE;
1560 void HlinkFrame_Init(HlinkFrame *This, IUnknown *outer, DocHost *doc_host)
1562 This->IHlinkFrame_iface.lpVtbl = &HlinkFrameVtbl;
1563 This->ITargetFrame2_iface.lpVtbl = &TargetFrame2Vtbl;
1564 This->ITargetFramePriv2_iface.lpVtbl = &TargetFramePriv2Vtbl;
1565 This->IWebBrowserPriv2IE9_iface.lpVtbl = &WebBrowserPriv2IE9Vtbl;
1567 This->outer = outer;
1568 This->doc_host = doc_host;