dmime: Implement band track IDirectMusicTrack_Play.
[wine.git] / dlls / ieframe / navigate.c
blob48cd59979396bf0fa1f1d8ef1c4785a04af6e131
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 #include "ieframe.h"
21 #include "exdispid.h"
22 #include "shellapi.h"
23 #include "winreg.h"
24 #include "shlwapi.h"
25 #include "wininet.h"
26 #include "mshtml.h"
27 #include "perhist.h"
28 #include "resource.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(ieframe);
34 static const WCHAR emptyW[] = {0};
36 typedef struct {
37 IBindStatusCallback IBindStatusCallback_iface;
38 IHttpNegotiate IHttpNegotiate_iface;
39 IHttpSecurity IHttpSecurity_iface;
41 LONG ref;
43 DocHost *doc_host;
44 IBinding *binding;
46 BSTR url;
47 HGLOBAL post_data;
48 BSTR headers;
49 ULONG post_data_len;
50 } BindStatusCallback;
52 static void dump_BINDINFO(BINDINFO *bi)
54 static const char * const BINDINFOF_str[] = {
55 "#0",
56 "BINDINFOF_URLENCODESTGMEDDATA",
57 "BINDINFOF_URLENCODEDEXTRAINFO"
60 static const char * const BINDVERB_str[] = {
61 "BINDVERB_GET",
62 "BINDVERB_POST",
63 "BINDVERB_PUT",
64 "BINDVERB_CUSTOM"
67 TRACE("\n"
68 "BINDINFO = {\n"
69 " %ld, %s,\n"
70 " {%ld, %p, %p},\n"
71 " %s,\n"
72 " %s,\n"
73 " %s,\n"
74 " %ld, %08lx, %ld, %ld\n"
75 " {%ld %p %x},\n"
76 " %s\n"
77 " %p, %ld\n"
78 "}\n",
80 bi->cbSize, debugstr_w(bi->szExtraInfo),
81 bi->stgmedData.tymed, bi->stgmedData.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, ULONG statuscode, LPCWSTR str)
98 VARIANTARG arg;
99 DISPPARAMS dispparams = {&arg, NULL, 1, 0};
100 WCHAR fmt[IDS_STATUSFMT_MAXLEN];
101 WCHAR buffer[IDS_STATUSFMT_MAXLEN + INTERNET_MAX_URL_LENGTH];
103 if(!This->doc_host)
104 return;
106 TRACE("(%p, %ld, %s)\n", This, statuscode, debugstr_w(str));
107 buffer[0] = 0;
108 if (statuscode && str && *str) {
109 fmt[0] = 0;
110 /* the format string must have one "%s" for the str */
111 LoadStringW(ieframe_instance, IDS_STATUSFMT_FIRST + statuscode, fmt, IDS_STATUSFMT_MAXLEN);
112 swprintf(buffer, ARRAY_SIZE(buffer), fmt, str);
115 V_VT(&arg) = VT_BSTR;
116 V_BSTR(&arg) = str ? SysAllocString(buffer) : SysAllocString(emptyW);
117 TRACE("=> %s\n", debugstr_w(V_BSTR(&arg)));
119 call_sink(This->doc_host->cps.wbe2, DISPID_STATUSTEXTCHANGE, &dispparams);
121 if(This->doc_host->frame)
122 IOleInPlaceFrame_SetStatusText(This->doc_host->frame, buffer);
124 VariantClear(&arg);
128 HRESULT set_dochost_url(DocHost *This, const WCHAR *url)
130 WCHAR *new_url;
132 if(url) {
133 new_url = wcsdup(url);
134 if(!new_url)
135 return E_OUTOFMEMORY;
136 }else {
137 new_url = NULL;
140 free(This->url);
141 This->url = new_url;
143 This->container_vtbl->set_url(This, This->url);
144 return S_OK;
147 void notify_download_state(DocHost *dochost, BOOL is_downloading)
149 DISPPARAMS dwl_dp = {NULL};
150 TRACE("(%x)\n", is_downloading);
151 dochost->busy = is_downloading ? VARIANT_TRUE : VARIANT_FALSE;
152 call_sink(dochost->cps.wbe2, is_downloading ? DISPID_DOWNLOADBEGIN : DISPID_DOWNLOADCOMPLETE, &dwl_dp);
155 static inline BindStatusCallback *impl_from_IBindStatusCallback(IBindStatusCallback *iface)
157 return CONTAINING_RECORD(iface, BindStatusCallback, IBindStatusCallback_iface);
160 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallback *iface,
161 REFIID riid, void **ppv)
163 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
165 if(IsEqualGUID(&IID_IUnknown, riid)) {
166 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
167 *ppv = &This->IBindStatusCallback_iface;
168 }else if(IsEqualGUID(&IID_IBindStatusCallback, riid)) {
169 TRACE("(%p)->(IID_IBindStatusCallback %p)\n", This, ppv);
170 *ppv = &This->IBindStatusCallback_iface;
171 }else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) {
172 TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This, ppv);
173 *ppv = &This->IHttpNegotiate_iface;
174 }else if(IsEqualGUID(&IID_IWindowForBindingUI, riid)) {
175 TRACE("(%p)->(IID_IWindowForBindingUI %p)\n", This, ppv);
176 *ppv = &This->IHttpSecurity_iface;
177 }else if(IsEqualGUID(&IID_IHttpSecurity, riid)) {
178 TRACE("(%p)->(IID_IHttpSecurity %p)\n", This, ppv);
179 *ppv = &This->IHttpSecurity_iface;
180 }else {
181 *ppv = NULL;
182 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
183 return E_NOINTERFACE;
186 IUnknown_AddRef((IUnknown*)*ppv);
187 return S_OK;
190 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallback *iface)
192 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
193 LONG ref = InterlockedIncrement(&This->ref);
195 TRACE("(%p) ref=%ld\n", This, ref);
197 return ref;
200 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallback *iface)
202 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
203 LONG ref = InterlockedDecrement(&This->ref);
205 TRACE("(%p) ref=%ld\n", This, ref);
207 if(!ref) {
208 if(This->doc_host)
209 IOleClientSite_Release(&This->doc_host->IOleClientSite_iface);
210 if(This->binding)
211 IBinding_Release(This->binding);
212 if(This->post_data)
213 GlobalFree(This->post_data);
214 SysFreeString(This->headers);
215 SysFreeString(This->url);
216 free(This);
219 return ref;
222 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallback *iface,
223 DWORD dwReserved, IBinding *pbind)
225 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
227 TRACE("(%p)->(%ld %p)\n", This, dwReserved, pbind);
229 This->binding = pbind;
230 IBinding_AddRef(This->binding);
232 return S_OK;
235 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface,
236 LONG *pnPriority)
238 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
239 FIXME("(%p)->(%p)\n", This, pnPriority);
240 return E_NOTIMPL;
243 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface,
244 DWORD reserved)
246 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
247 FIXME("(%p)->(%ld)\n", This, reserved);
248 return E_NOTIMPL;
251 static DWORD get_http_status_code(IBinding *binding)
253 IWinInetHttpInfo *http_info;
254 DWORD status, size = sizeof(DWORD);
255 HRESULT hres;
257 hres = IBinding_QueryInterface(binding, &IID_IWinInetHttpInfo, (void**)&http_info);
258 if(FAILED(hres))
259 return HTTP_STATUS_OK;
261 hres = IWinInetHttpInfo_QueryInfo(http_info, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER,
262 &status, &size, NULL, NULL);
263 IWinInetHttpInfo_Release(http_info);
265 if(FAILED(hres))
266 return HTTP_STATUS_OK;
267 return status;
270 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallback *iface,
271 ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
273 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
274 DWORD status_code;
276 TRACE("(%p)->(%ld %ld %ld %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
277 debugstr_w(szStatusText));
279 switch(ulStatusCode) {
280 case BINDSTATUS_REDIRECTING:
281 return set_dochost_url(This->doc_host, szStatusText);
282 case BINDSTATUS_BEGINDOWNLOADDATA:
283 set_status_text(This, ulStatusCode, szStatusText);
284 status_code = get_http_status_code(This->binding);
285 if(status_code != HTTP_STATUS_OK)
286 handle_navigation_error(This->doc_host, status_code, This->url, NULL);
287 return S_OK;
289 case BINDSTATUS_FINDINGRESOURCE:
290 case BINDSTATUS_ENDDOWNLOADDATA:
291 case BINDSTATUS_SENDINGREQUEST:
292 set_status_text(This, ulStatusCode, szStatusText);
293 return S_OK;
295 case BINDSTATUS_CONNECTING:
296 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
297 case BINDSTATUS_CLASSIDAVAILABLE:
298 case BINDSTATUS_MIMETYPEAVAILABLE:
299 case BINDSTATUS_BEGINSYNCOPERATION:
300 case BINDSTATUS_ENDSYNCOPERATION:
301 return S_OK;
302 default:
303 FIXME("status code %lu\n", ulStatusCode);
306 return S_OK;
309 void handle_navigation_error(DocHost* doc_host, HRESULT status_code, BSTR url, IHTMLWindow2 *win2)
311 VARIANT var_status_code, var_frame_name, var_url;
312 DISPPARAMS dispparams;
313 VARIANTARG params[5];
314 VARIANT_BOOL cancel = VARIANT_FALSE;
315 HRESULT hres;
317 dispparams.cArgs = 5;
318 dispparams.cNamedArgs = 0;
319 dispparams.rgdispidNamedArgs = NULL;
320 dispparams.rgvarg = params;
322 V_VT(params) = VT_BOOL|VT_BYREF;
323 V_BOOLREF(params) = &cancel;
325 V_VT(params+1) = VT_VARIANT|VT_BYREF;
326 V_VARIANTREF(params+1) = &var_status_code;
327 V_VT(&var_status_code) = VT_I4;
328 V_I4(&var_status_code) = status_code;
330 V_VT(params+2) = VT_VARIANT|VT_BYREF;
331 V_VARIANTREF(params+2) = &var_frame_name;
332 V_VT(&var_frame_name) = VT_BSTR;
333 if(win2) {
334 hres = IHTMLWindow2_get_name(win2, &V_BSTR(&var_frame_name));
335 if(FAILED(hres))
336 V_BSTR(&var_frame_name) = NULL;
337 } else
338 V_BSTR(&var_frame_name) = NULL;
340 V_VT(params+3) = VT_VARIANT|VT_BYREF;
341 V_VARIANTREF(params+3) = &var_url;
342 V_VT(&var_url) = VT_BSTR;
343 V_BSTR(&var_url) = url;
345 V_VT(params+4) = VT_DISPATCH;
346 V_DISPATCH(params+4) = (IDispatch*)doc_host->wb;
348 call_sink(doc_host->cps.wbe2, DISPID_NAVIGATEERROR, &dispparams);
349 SysFreeString(V_BSTR(&var_frame_name));
351 if(!cancel) {
352 IHTMLPrivateWindow *priv_window;
353 IHTMLWindow2 *tmp;
355 if(win2)
356 hres = IHTMLWindow2_QueryInterface(win2, &IID_IHTMLPrivateWindow, (void**)&priv_window);
357 else {
358 hres = get_window(doc_host, &tmp);
359 if(SUCCEEDED(hres)) {
360 if(!tmp)
361 hres = E_UNEXPECTED;
362 else {
363 hres = IHTMLWindow2_QueryInterface(tmp, &IID_IHTMLPrivateWindow, (void**)&priv_window);
364 IHTMLWindow2_Release(tmp);
368 if(SUCCEEDED(hres)) {
369 /* Error page navigation URL is a local resource (varies on native, also depending on error),
370 * with the fragment being the original URL of the page that failed to load. We add a query
371 * with the error code so the generic error page can display the actual error code there. */
372 WCHAR buf[32], sysdirbuf[MAX_PATH];
373 BSTR nav_url;
374 UINT len;
376 if(SUCCEEDED(status_code))
377 len = swprintf(buf, ARRAY_SIZE(buf), L"ERROR.HTM?HTTP %u", status_code);
378 else
379 len = swprintf(buf, ARRAY_SIZE(buf), L"ERROR.HTM?0x%08x", status_code);
381 len = 6 /* res:// */ + GetSystemDirectoryW(sysdirbuf, ARRAY_SIZE(sysdirbuf)) +
382 ARRAY_SIZE(L"\\shdoclc.dll/")-1 + len + 1 /* # */ + wcslen(url);
384 nav_url = SysAllocStringLen(NULL, len);
385 if(nav_url) {
386 swprintf(nav_url, len + 1, L"res://%s\\shdoclc.dll/%s#%s", sysdirbuf, buf, url);
387 IHTMLPrivateWindow_SuperNavigate(priv_window, nav_url, NULL, NULL, NULL, NULL, NULL, 2);
388 SysFreeString(nav_url);
390 IHTMLPrivateWindow_Release(priv_window);
395 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
396 HRESULT hresult, LPCWSTR szError)
398 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
400 TRACE("(%p)->(%08lx %s)\n", This, hresult, debugstr_w(szError));
402 set_status_text(This, 0, emptyW);
404 if(!This->doc_host)
405 return S_OK;
407 if(!This->doc_host->olecmd)
408 notify_download_state(This->doc_host, FALSE);
409 if(FAILED(hresult))
410 handle_navigation_error(This->doc_host, hresult, This->url, NULL);
412 IOleClientSite_Release(&This->doc_host->IOleClientSite_iface);
413 This->doc_host = NULL;
415 IBinding_Release(This->binding);
416 This->binding = NULL;
418 return S_OK;
421 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
422 DWORD *grfBINDF, BINDINFO *pbindinfo)
424 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
426 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
428 *grfBINDF = BINDF_ASYNCHRONOUS;
430 if(This->post_data) {
431 pbindinfo->dwBindVerb = BINDVERB_POST;
433 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
434 pbindinfo->stgmedData.hGlobal = This->post_data;
435 pbindinfo->cbstgmedData = This->post_data_len;
436 pbindinfo->stgmedData.pUnkForRelease = (IUnknown*)&This->IBindStatusCallback_iface;
437 IBindStatusCallback_AddRef(&This->IBindStatusCallback_iface);
440 return S_OK;
443 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
444 DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
446 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
447 FIXME("(%p)->(%08lx %ld %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed);
448 return E_NOTIMPL;
451 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
452 REFIID riid, IUnknown *punk)
454 BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
456 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), punk);
458 return dochost_object_available(This->doc_host, punk);
461 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
462 BindStatusCallback_QueryInterface,
463 BindStatusCallback_AddRef,
464 BindStatusCallback_Release,
465 BindStatusCallback_OnStartBinding,
466 BindStatusCallback_GetPriority,
467 BindStatusCallback_OnLowResource,
468 BindStatusCallback_OnProgress,
469 BindStatusCallback_OnStopBinding,
470 BindStatusCallback_GetBindInfo,
471 BindStatusCallback_OnDataAvailable,
472 BindStatusCallback_OnObjectAvailable
475 static inline BindStatusCallback *impl_from_IHttpNegotiate(IHttpNegotiate *iface)
477 return CONTAINING_RECORD(iface, BindStatusCallback, IHttpNegotiate_iface);
480 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate *iface,
481 REFIID riid, void **ppv)
483 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
484 return IBindStatusCallback_QueryInterface(&This->IBindStatusCallback_iface, riid, ppv);
487 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate *iface)
489 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
490 return IBindStatusCallback_AddRef(&This->IBindStatusCallback_iface);
493 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate *iface)
495 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
496 return IBindStatusCallback_Release(&This->IBindStatusCallback_iface);
499 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate *iface,
500 LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
502 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
504 TRACE("(%p)->(%s %s %ld %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders),
505 dwReserved, pszAdditionalHeaders);
507 if(This->headers) {
508 int size = (lstrlenW(This->headers)+1)*sizeof(WCHAR);
509 *pszAdditionalHeaders = CoTaskMemAlloc(size);
510 memcpy(*pszAdditionalHeaders, This->headers, size);
513 return S_OK;
516 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate *iface,
517 DWORD dwResponseCode, LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders,
518 LPWSTR *pszAdditionalRequestHeaders)
520 BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
521 TRACE("(%p)->(%ld %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
522 debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
523 return S_OK;
526 static const IHttpNegotiateVtbl HttpNegotiateVtbl = {
527 HttpNegotiate_QueryInterface,
528 HttpNegotiate_AddRef,
529 HttpNegotiate_Release,
530 HttpNegotiate_BeginningTransaction,
531 HttpNegotiate_OnResponse
534 static inline BindStatusCallback *impl_from_IHttpSecurity(IHttpSecurity *iface)
536 return CONTAINING_RECORD(iface, BindStatusCallback, IHttpSecurity_iface);
539 static HRESULT WINAPI HttpSecurity_QueryInterface(IHttpSecurity *iface, REFIID riid, void **ppv)
541 BindStatusCallback *This = impl_from_IHttpSecurity(iface);
542 return IBindStatusCallback_QueryInterface(&This->IBindStatusCallback_iface, riid, ppv);
545 static ULONG WINAPI HttpSecurity_AddRef(IHttpSecurity *iface)
547 BindStatusCallback *This = impl_from_IHttpSecurity(iface);
548 return IBindStatusCallback_AddRef(&This->IBindStatusCallback_iface);
551 static ULONG WINAPI HttpSecurity_Release(IHttpSecurity *iface)
553 BindStatusCallback *This = impl_from_IHttpSecurity(iface);
554 return IBindStatusCallback_Release(&This->IBindStatusCallback_iface);
557 static HRESULT WINAPI HttpSecurity_GetWindow(IHttpSecurity *iface, REFGUID rguidReason, HWND *phwnd)
559 BindStatusCallback *This = impl_from_IHttpSecurity(iface);
561 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(rguidReason), phwnd);
563 if(!This->doc_host)
564 return E_FAIL;
566 *phwnd = This->doc_host->frame_hwnd;
567 return S_OK;
570 static HRESULT WINAPI HttpSecurity_OnSecurityProblem(IHttpSecurity *iface, DWORD dwProblem)
572 BindStatusCallback *This = impl_from_IHttpSecurity(iface);
573 FIXME("(%p)->(%lu)\n", This, dwProblem);
574 return S_FALSE;
577 static const IHttpSecurityVtbl HttpSecurityVtbl = {
578 HttpSecurity_QueryInterface,
579 HttpSecurity_AddRef,
580 HttpSecurity_Release,
581 HttpSecurity_GetWindow,
582 HttpSecurity_OnSecurityProblem
585 static BindStatusCallback *create_callback(DocHost *doc_host, LPCWSTR url, PBYTE post_data,
586 ULONG post_data_len, LPCWSTR headers)
588 BindStatusCallback *ret = malloc(sizeof(BindStatusCallback));
590 ret->IBindStatusCallback_iface.lpVtbl = &BindStatusCallbackVtbl;
591 ret->IHttpNegotiate_iface.lpVtbl = &HttpNegotiateVtbl;
592 ret->IHttpSecurity_iface.lpVtbl = &HttpSecurityVtbl;
594 ret->ref = 1;
595 ret->url = SysAllocString(url);
596 ret->post_data = NULL;
597 ret->post_data_len = post_data_len;
598 ret->headers = headers ? SysAllocString(headers) : NULL;
600 ret->doc_host = doc_host;
601 IOleClientSite_AddRef(&doc_host->IOleClientSite_iface);
603 ret->binding = NULL;
605 if(post_data) {
606 ret->post_data = GlobalAlloc(0, post_data_len);
607 memcpy(ret->post_data, post_data, post_data_len);
610 return ret;
613 static void on_before_navigate2(DocHost *This, LPCWSTR url, SAFEARRAY *post_data, LPWSTR headers, VARIANT_BOOL *cancel)
615 VARIANT var_url, var_flags, var_frame_name, var_post_data, var_post_data2, var_headers;
616 DISPPARAMS dispparams;
617 VARIANTARG params[7];
618 WCHAR file_path[MAX_PATH];
619 DWORD file_path_len = ARRAY_SIZE(file_path);
621 dispparams.cArgs = 7;
622 dispparams.cNamedArgs = 0;
623 dispparams.rgdispidNamedArgs = NULL;
624 dispparams.rgvarg = params;
626 V_VT(params) = VT_BOOL|VT_BYREF;
627 V_BOOLREF(params) = cancel;
629 V_VT(params+1) = (VT_BYREF|VT_VARIANT);
630 V_VARIANTREF(params+1) = &var_headers;
631 V_VT(&var_headers) = VT_BSTR;
632 V_BSTR(&var_headers) = headers;
634 V_VT(params+2) = (VT_BYREF|VT_VARIANT);
635 V_VARIANTREF(params+2) = &var_post_data2;
636 V_VT(&var_post_data2) = (VT_BYREF|VT_VARIANT);
637 V_VARIANTREF(&var_post_data2) = &var_post_data;
639 if(post_data) {
640 V_VT(&var_post_data) = VT_UI1|VT_ARRAY;
641 V_ARRAY(&var_post_data) = post_data;
642 }else {
643 V_VT(&var_post_data) = VT_EMPTY;
646 V_VT(params+3) = (VT_BYREF|VT_VARIANT);
647 V_VARIANTREF(params+3) = &var_frame_name;
648 V_VT(&var_frame_name) = VT_BSTR;
649 V_BSTR(&var_frame_name) = NULL;
651 V_VT(params+4) = (VT_BYREF|VT_VARIANT);
652 V_VARIANTREF(params+4) = &var_flags;
653 V_VT(&var_flags) = VT_I4;
654 V_I4(&var_flags) = 0;
656 V_VT(params+5) = (VT_BYREF|VT_VARIANT);
657 V_VARIANTREF(params+5) = &var_url;
658 V_VT(&var_url) = VT_BSTR;
659 if(PathCreateFromUrlW(url, file_path, &file_path_len, 0) == S_OK)
660 V_BSTR(&var_url) = SysAllocString(file_path);
661 else
662 V_BSTR(&var_url) = SysAllocString(url);
664 V_VT(params+6) = (VT_DISPATCH);
665 V_DISPATCH(params+6) = (IDispatch*)This->wb;
667 call_sink(This->cps.wbe2, DISPID_BEFORENAVIGATE2, &dispparams);
669 SysFreeString(V_BSTR(&var_url));
672 /* FIXME: urlmon should handle it */
673 static BOOL try_application_url(LPCWSTR url)
675 SHELLEXECUTEINFOW exec_info;
676 WCHAR app[64];
677 HKEY hkey;
678 DWORD res, type;
679 HRESULT hres;
681 static const WCHAR wszURLProtocol[] = {'U','R','L',' ','P','r','o','t','o','c','o','l',0};
683 hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, app, ARRAY_SIZE(app), NULL, 0);
684 if(FAILED(hres))
685 return FALSE;
687 res = RegOpenKeyW(HKEY_CLASSES_ROOT, app, &hkey);
688 if(res != ERROR_SUCCESS)
689 return FALSE;
691 res = RegQueryValueExW(hkey, wszURLProtocol, NULL, &type, NULL, NULL);
692 RegCloseKey(hkey);
693 if(res != ERROR_SUCCESS || type != REG_SZ)
694 return FALSE;
696 TRACE("opening application %s\n", debugstr_w(app));
698 memset(&exec_info, 0, sizeof(exec_info));
699 exec_info.cbSize = sizeof(exec_info);
700 exec_info.lpFile = url;
701 exec_info.nShow = SW_SHOW;
703 return ShellExecuteExW(&exec_info);
706 static HRESULT create_moniker(LPCWSTR url, IMoniker **mon)
708 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
709 DWORD size;
710 HRESULT hres;
712 if(PathIsURLW(url))
713 return CreateURLMoniker(NULL, url, mon);
715 size = ARRAY_SIZE(new_url);
716 hres = UrlApplySchemeW(url, new_url, &size, URL_APPLY_GUESSSCHEME | URL_APPLY_GUESSFILE | URL_APPLY_DEFAULT);
717 TRACE("was %s got %s\n", debugstr_w(url), debugstr_w(new_url));
718 if(FAILED(hres)) {
719 WARN("UrlApplyScheme failed: %08lx\n", hres);
720 return hres;
723 return CreateURLMoniker(NULL, new_url, mon);
726 static HRESULT bind_to_object(DocHost *This, IMoniker *mon, LPCWSTR url, IBindCtx *bindctx,
727 IBindStatusCallback *callback)
729 IUnknown *unk = NULL;
730 WCHAR *display_name;
731 HRESULT hres;
733 if(mon) {
734 IMoniker_AddRef(mon);
735 }else {
736 hres = create_moniker(url, &mon);
737 if(FAILED(hres))
738 return hres;
741 hres = IMoniker_GetDisplayName(mon, 0, NULL, &display_name);
742 if(FAILED(hres)) {
743 FIXME("GetDisplayName failed: %08lx\n", hres);
744 IMoniker_Release(mon);
745 return hres;
748 hres = set_dochost_url(This, display_name);
749 CoTaskMemFree(display_name);
750 if(FAILED(hres)) {
751 IMoniker_Release(mon);
752 return hres;
755 IBindCtx_RegisterObjectParam(bindctx, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM,
756 (IUnknown*)&This->IOleClientSite_iface);
758 hres = IMoniker_BindToObject(mon, bindctx, NULL, &IID_IUnknown, (void**)&unk);
759 if(SUCCEEDED(hres)) {
760 hres = S_OK;
761 if(unk)
762 IUnknown_Release(unk);
763 }else if(try_application_url(url)) {
764 hres = S_OK;
765 }else {
766 FIXME("BindToObject failed: %08lx\n", hres);
769 IMoniker_Release(mon);
770 return S_OK;
773 static void html_window_navigate(DocHost *This, IHTMLPrivateWindow *window, BSTR url, BSTR headers, SAFEARRAY *post_data)
775 VARIANT headers_var, post_data_var;
776 BSTR empty_str;
777 HRESULT hres;
779 hres = set_dochost_url(This, url);
780 if(FAILED(hres))
781 return;
783 empty_str = SysAllocStringLen(NULL, 0);
785 if(headers) {
786 V_VT(&headers_var) = VT_BSTR;
787 V_BSTR(&headers_var) = headers;
788 }else {
789 V_VT(&headers_var) = VT_EMPTY;
792 if(post_data) {
793 V_VT(&post_data_var) = VT_UI1|VT_ARRAY;
794 V_ARRAY(&post_data_var) = post_data;
795 }else {
796 V_VT(&post_data_var) = VT_EMPTY;
799 set_doc_state(This, READYSTATE_LOADING);
800 hres = IHTMLPrivateWindow_SuperNavigate(window, url, empty_str, NULL, NULL, &post_data_var, &headers_var, 0);
801 SysFreeString(empty_str);
802 if(FAILED(hres))
803 WARN("SuprtNavigate failed: %08lx\n", hres);
806 typedef struct {
807 task_header_t header;
808 BSTR url;
809 BSTR headers;
810 SAFEARRAY *post_data;
811 BOOL async_notif;
812 } task_doc_navigate_t;
814 static void doc_navigate_task_destr(task_header_t *t)
816 task_doc_navigate_t *task = (task_doc_navigate_t*)t;
818 SysFreeString(task->url);
819 SysFreeString(task->headers);
820 if(task->post_data)
821 SafeArrayDestroy(task->post_data);
822 free(task);
825 static void doc_navigate_proc(DocHost *This, task_header_t *t)
827 task_doc_navigate_t *task = (task_doc_navigate_t*)t;
828 IHTMLPrivateWindow *priv_window;
829 HRESULT hres;
831 if(!This->doc_navigate) {
832 ERR("Skip nav\n");
833 return;
836 if(task->async_notif) {
837 VARIANT_BOOL cancel = VARIANT_FALSE;
838 on_before_navigate2(This, task->url, task->post_data, task->headers, &cancel);
839 if(cancel) {
840 TRACE("Navigation canceled\n");
841 return;
845 hres = IUnknown_QueryInterface(This->doc_navigate, &IID_IHTMLPrivateWindow, (void**)&priv_window);
846 if(SUCCEEDED(hres)) {
847 html_window_navigate(This, priv_window, task->url, task->headers, task->post_data);
848 IHTMLPrivateWindow_Release(priv_window);
849 }else {
850 WARN("Could not get IHTMLPrivateWindow iface: %08lx\n", hres);
854 static HRESULT async_doc_navigate(DocHost *This, LPCWSTR url, LPCWSTR headers, PBYTE post_data, ULONG post_data_size,
855 BOOL async_notif)
857 task_doc_navigate_t *task;
859 TRACE("%s\n", debugstr_w(url));
861 task = calloc(1, sizeof(*task));
862 if(!task)
863 return E_OUTOFMEMORY;
865 task->url = SysAllocString(url);
866 if(!task->url) {
867 doc_navigate_task_destr(&task->header);
868 return E_OUTOFMEMORY;
871 if(headers) {
872 task->headers = SysAllocString(headers);
873 if(!task->headers) {
874 doc_navigate_task_destr(&task->header);
875 return E_OUTOFMEMORY;
879 if(post_data) {
880 task->post_data = SafeArrayCreateVector(VT_UI1, 0, post_data_size);
881 if(!task->post_data) {
882 doc_navigate_task_destr(&task->header);
883 return E_OUTOFMEMORY;
886 memcpy(task->post_data->pvData, post_data, post_data_size);
889 if(!async_notif) {
890 VARIANT_BOOL cancel = VARIANT_FALSE;
892 on_before_navigate2(This, task->url, task->post_data, task->headers, &cancel);
893 if(cancel) {
894 TRACE("Navigation canceled\n");
895 doc_navigate_task_destr(&task->header);
896 return S_OK;
900 task->async_notif = async_notif;
901 abort_dochost_tasks(This, doc_navigate_proc);
902 push_dochost_task(This, &task->header, doc_navigate_proc, doc_navigate_task_destr, FALSE);
903 return S_OK;
906 static HRESULT navigate_bsc(DocHost *This, BindStatusCallback *bsc, IMoniker *mon)
908 VARIANT_BOOL cancel = VARIANT_FALSE;
909 SAFEARRAY *post_data = NULL;
910 IBindCtx *bindctx;
911 HRESULT hres;
913 set_doc_state(This, READYSTATE_LOADING);
915 if(bsc->post_data) {
916 post_data = SafeArrayCreateVector(VT_UI1, 0, bsc->post_data_len);
917 memcpy(post_data->pvData, post_data, bsc->post_data_len);
920 on_before_navigate2(This, bsc->url, post_data, bsc->headers, &cancel);
921 if(post_data)
922 SafeArrayDestroy(post_data);
923 if(cancel) {
924 FIXME("Navigation canceled\n");
925 return S_OK;
928 notify_download_state(This, TRUE);
929 This->busy = VARIANT_FALSE;
931 on_commandstate_change(This, CSC_NAVIGATEBACK, FALSE);
932 on_commandstate_change(This, CSC_NAVIGATEFORWARD, FALSE);
934 if(This->document)
935 deactivate_document(This);
937 CreateAsyncBindCtx(0, &bsc->IBindStatusCallback_iface, 0, &bindctx);
939 if(This->frame)
940 IOleInPlaceFrame_EnableModeless(This->frame, FALSE);
942 hres = bind_to_object(This, mon, bsc->url, bindctx, &bsc->IBindStatusCallback_iface);
944 if(This->frame)
945 IOleInPlaceFrame_EnableModeless(This->frame, TRUE);
947 IBindCtx_Release(bindctx);
949 return hres;
952 typedef struct {
953 task_header_t header;
954 BindStatusCallback *bsc;
955 } task_navigate_bsc_t;
957 static void navigate_bsc_task_destr(task_header_t *t)
959 task_navigate_bsc_t *task = (task_navigate_bsc_t*)t;
961 IBindStatusCallback_Release(&task->bsc->IBindStatusCallback_iface);
962 free(task);
965 static void navigate_bsc_proc(DocHost *This, task_header_t *t)
967 task_navigate_bsc_t *task = (task_navigate_bsc_t*)t;
969 if(!This->hwnd)
970 create_doc_view_hwnd(This);
972 navigate_bsc(This, task->bsc, NULL);
976 HRESULT navigate_url(DocHost *This, LPCWSTR url, const VARIANT *Flags,
977 const VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers)
979 SAFEARRAY *post_array = NULL;
980 PBYTE post_data = NULL;
981 ULONG post_data_len = 0;
982 LPWSTR headers = NULL;
983 HRESULT hres = S_OK;
985 TRACE("navigating to %s\n", debugstr_w(url));
987 if((Flags && V_VT(Flags) != VT_EMPTY && V_VT(Flags) != VT_ERROR)
988 || (TargetFrameName && V_VT(TargetFrameName) != VT_EMPTY && V_VT(TargetFrameName) != VT_ERROR))
989 FIXME("Unsupported args (Flags %s; TargetFrameName %s)\n", debugstr_variant(Flags), debugstr_variant(TargetFrameName));
991 if(PostData) {
992 if(V_VT(PostData) & VT_ARRAY)
993 post_array = V_ISBYREF(PostData) ? *V_ARRAYREF(PostData) : V_ARRAY(PostData);
994 else
995 WARN("Invalid post data %s\n", debugstr_variant(PostData));
998 if(post_array) {
999 LONG elem_max;
1000 SafeArrayAccessData(post_array, (void**)&post_data);
1001 SafeArrayGetUBound(post_array, 1, &elem_max);
1002 post_data_len = (elem_max+1) * SafeArrayGetElemsize(post_array);
1005 if(Headers && V_VT(Headers) == VT_BSTR) {
1006 headers = V_BSTR(Headers);
1007 TRACE("Headers: %s\n", debugstr_w(headers));
1010 set_doc_state(This, READYSTATE_LOADING);
1011 This->ready_state = READYSTATE_LOADING;
1013 if(This->doc_navigate) {
1014 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
1016 if(PathIsURLW(url)) {
1017 new_url[0] = 0;
1018 }else {
1019 DWORD size;
1021 size = ARRAY_SIZE(new_url);
1022 hres = UrlApplySchemeW(url, new_url, &size,
1023 URL_APPLY_GUESSSCHEME | URL_APPLY_GUESSFILE | URL_APPLY_DEFAULT);
1024 if(FAILED(hres)) {
1025 WARN("UrlApplyScheme failed: %08lx\n", hres);
1026 new_url[0] = 0;
1030 hres = async_doc_navigate(This, *new_url ? new_url : url, headers, post_data,
1031 post_data_len, TRUE);
1032 }else {
1033 task_navigate_bsc_t *task;
1035 task = malloc(sizeof(*task));
1036 task->bsc = create_callback(This, url, post_data, post_data_len, headers);
1037 push_dochost_task(This, &task->header, navigate_bsc_proc, navigate_bsc_task_destr, This->url == NULL);
1040 if(post_data)
1041 SafeArrayUnaccessData(post_array);
1043 return hres;
1046 static HRESULT navigate_hlink(DocHost *This, IMoniker *mon, IBindCtx *bindctx,
1047 IBindStatusCallback *callback)
1049 IHttpNegotiate *http_negotiate;
1050 BindStatusCallback *bsc;
1051 PBYTE post_data = NULL;
1052 ULONG post_data_len = 0;
1053 LPWSTR headers = NULL, url;
1054 BINDINFO bindinfo;
1055 DWORD bindf = 0;
1056 HRESULT hres;
1058 TRACE("\n");
1060 hres = IMoniker_GetDisplayName(mon, 0, NULL, &url);
1061 if(FAILED(hres))
1062 FIXME("GetDisplayName failed: %08lx\n", hres);
1064 hres = IBindStatusCallback_QueryInterface(callback, &IID_IHttpNegotiate,
1065 (void**)&http_negotiate);
1066 if(SUCCEEDED(hres)) {
1067 static const WCHAR null_string[] = {0};
1069 IHttpNegotiate_BeginningTransaction(http_negotiate, null_string, null_string, 0,
1070 &headers);
1071 IHttpNegotiate_Release(http_negotiate);
1074 memset(&bindinfo, 0, sizeof(bindinfo));
1075 bindinfo.cbSize = sizeof(bindinfo);
1077 hres = IBindStatusCallback_GetBindInfo(callback, &bindf, &bindinfo);
1078 dump_BINDINFO(&bindinfo);
1079 if(bindinfo.dwBindVerb == BINDVERB_POST) {
1080 post_data_len = bindinfo.cbstgmedData;
1081 if(post_data_len)
1082 post_data = bindinfo.stgmedData.hGlobal;
1085 if(This->doc_navigate) {
1086 hres = async_doc_navigate(This, url, headers, post_data, post_data_len, FALSE);
1087 }else {
1088 bsc = create_callback(This, url, post_data, post_data_len, headers);
1089 hres = navigate_bsc(This, bsc, mon);
1090 IBindStatusCallback_Release(&bsc->IBindStatusCallback_iface);
1093 CoTaskMemFree(url);
1094 CoTaskMemFree(headers);
1095 ReleaseBindInfo(&bindinfo);
1097 return hres;
1100 HRESULT go_home(DocHost *This)
1102 HKEY hkey;
1103 DWORD res, type, size;
1104 WCHAR wszPageName[MAX_PATH];
1105 static const WCHAR wszAboutBlank[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
1106 static const WCHAR wszStartPage[] = {'S','t','a','r','t',' ','P','a','g','e',0};
1107 static const WCHAR wszSubKey[] = {'S','o','f','t','w','a','r','e','\\',
1108 'M','i','c','r','o','s','o','f','t','\\',
1109 'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\',
1110 'M','a','i','n',0};
1112 res = RegOpenKeyW(HKEY_CURRENT_USER, wszSubKey, &hkey);
1113 if (res != ERROR_SUCCESS)
1114 return navigate_url(This, wszAboutBlank, NULL, NULL, NULL, NULL);
1116 size = sizeof(wszPageName);
1117 res = RegQueryValueExW(hkey, wszStartPage, NULL, &type, (LPBYTE)wszPageName, &size);
1118 RegCloseKey(hkey);
1119 if (res != ERROR_SUCCESS || type != REG_SZ)
1120 return navigate_url(This, wszAboutBlank, NULL, NULL, NULL, NULL);
1122 return navigate_url(This, wszPageName, NULL, NULL, NULL, NULL);
1125 static HRESULT navigate_history(DocHost *This, unsigned travellog_pos)
1127 IPersistHistory *persist_history;
1128 travellog_entry_t *entry;
1129 LARGE_INTEGER li;
1130 HRESULT hres;
1132 if(!This->doc_navigate) {
1133 FIXME("unsupported doc_navigate FALSE\n");
1134 return E_NOTIMPL;
1137 This->travellog.loading_pos = travellog_pos;
1138 entry = This->travellog.log + This->travellog.loading_pos;
1140 update_navigation_commands(This);
1142 if(!entry->stream)
1143 return async_doc_navigate(This, entry->url, NULL, NULL, 0, FALSE);
1145 hres = IUnknown_QueryInterface(This->document, &IID_IPersistHistory, (void**)&persist_history);
1146 if(FAILED(hres))
1147 return hres;
1149 li.QuadPart = 0;
1150 IStream_Seek(entry->stream, li, STREAM_SEEK_SET, NULL);
1152 hres = IPersistHistory_LoadHistory(persist_history, entry->stream, NULL);
1153 IPersistHistory_Release(persist_history);
1154 return hres;
1157 HRESULT go_back(DocHost *This)
1159 if(!This->travellog.position) {
1160 WARN("No history available\n");
1161 return E_FAIL;
1164 return navigate_history(This, This->travellog.position-1);
1167 HRESULT go_forward(DocHost *This)
1169 if(This->travellog.position >= This->travellog.length) {
1170 WARN("No history available\n");
1171 return E_FAIL;
1174 return navigate_history(This, This->travellog.position+1);
1177 HRESULT get_location_url(DocHost *This, BSTR *ret)
1179 FIXME("semi-stub\n");
1181 *ret = This->url ? SysAllocString(This->url) : SysAllocStringLen(NULL, 0);
1182 if(!*ret)
1183 return E_OUTOFMEMORY;
1185 return This->url ? S_OK : S_FALSE;
1188 static inline HlinkFrame *impl_from_IHlinkFrame(IHlinkFrame *iface)
1190 return CONTAINING_RECORD(iface, HlinkFrame, IHlinkFrame_iface);
1193 static HRESULT WINAPI HlinkFrame_QueryInterface(IHlinkFrame *iface, REFIID riid, void **ppv)
1195 HlinkFrame *This = impl_from_IHlinkFrame(iface);
1196 return IUnknown_QueryInterface(This->outer, riid, ppv);
1199 static ULONG WINAPI HlinkFrame_AddRef(IHlinkFrame *iface)
1201 HlinkFrame *This = impl_from_IHlinkFrame(iface);
1202 return IUnknown_AddRef(This->outer);
1205 static ULONG WINAPI HlinkFrame_Release(IHlinkFrame *iface)
1207 HlinkFrame *This = impl_from_IHlinkFrame(iface);
1208 return IUnknown_Release(This->outer);
1211 static HRESULT WINAPI HlinkFrame_SetBrowseContext(IHlinkFrame *iface,
1212 IHlinkBrowseContext *pihlbc)
1214 HlinkFrame *This = impl_from_IHlinkFrame(iface);
1215 FIXME("(%p)->(%p)\n", This, pihlbc);
1216 return E_NOTIMPL;
1219 static HRESULT WINAPI HlinkFrame_GetBrowseContext(IHlinkFrame *iface,
1220 IHlinkBrowseContext **ppihlbc)
1222 HlinkFrame *This = impl_from_IHlinkFrame(iface);
1223 FIXME("(%p)->(%p)\n", This, ppihlbc);
1224 return E_NOTIMPL;
1227 static HRESULT WINAPI HlinkFrame_Navigate(IHlinkFrame *iface, DWORD grfHLNF, LPBC pbc,
1228 IBindStatusCallback *pibsc, IHlink *pihlNavigate)
1230 HlinkFrame *This = impl_from_IHlinkFrame(iface);
1231 IMoniker *mon;
1232 LPWSTR location = NULL;
1234 TRACE("(%p)->(%08lx %p %p %p)\n", This, grfHLNF, pbc, pibsc, pihlNavigate);
1236 if(grfHLNF)
1237 FIXME("unsupported grfHLNF=%08lx\n", grfHLNF);
1239 /* Windows calls GetTargetFrameName here. */
1241 IHlink_GetMonikerReference(pihlNavigate, 1, &mon, &location);
1243 if(location) {
1244 FIXME("location = %s\n", debugstr_w(location));
1245 CoTaskMemFree(location);
1248 /* Windows calls GetHlinkSite here */
1250 if(grfHLNF & HLNF_OPENINNEWWINDOW) {
1251 FIXME("Not supported HLNF_OPENINNEWWINDOW\n");
1252 return E_NOTIMPL;
1255 return navigate_hlink(This->doc_host, mon, pbc, pibsc);
1258 static HRESULT WINAPI HlinkFrame_OnNavigate(IHlinkFrame *iface, DWORD grfHLNF,
1259 IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName, DWORD dwreserved)
1261 HlinkFrame *This = impl_from_IHlinkFrame(iface);
1262 FIXME("(%p)->(%08lx %p %s %s %ld)\n", This, grfHLNF, pimkTarget, debugstr_w(pwzLocation),
1263 debugstr_w(pwzFriendlyName), dwreserved);
1264 return E_NOTIMPL;
1267 static HRESULT WINAPI HlinkFrame_UpdateHlink(IHlinkFrame *iface, ULONG uHLID,
1268 IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName)
1270 HlinkFrame *This = impl_from_IHlinkFrame(iface);
1271 FIXME("(%p)->(%lu %p %s %s)\n", This, uHLID, pimkTarget, debugstr_w(pwzLocation),
1272 debugstr_w(pwzFriendlyName));
1273 return E_NOTIMPL;
1276 static const IHlinkFrameVtbl HlinkFrameVtbl = {
1277 HlinkFrame_QueryInterface,
1278 HlinkFrame_AddRef,
1279 HlinkFrame_Release,
1280 HlinkFrame_SetBrowseContext,
1281 HlinkFrame_GetBrowseContext,
1282 HlinkFrame_Navigate,
1283 HlinkFrame_OnNavigate,
1284 HlinkFrame_UpdateHlink
1287 static inline HlinkFrame *impl_from_ITargetFrame(ITargetFrame *iface)
1289 return CONTAINING_RECORD(iface, HlinkFrame, ITargetFrame_iface);
1292 static HRESULT WINAPI TargetFrame_QueryInterface(ITargetFrame *iface, REFIID riid, void **ppv)
1294 HlinkFrame *This = impl_from_ITargetFrame(iface);
1295 return IUnknown_QueryInterface(This->outer, riid, ppv);
1298 static ULONG WINAPI TargetFrame_AddRef(ITargetFrame *iface)
1300 HlinkFrame *This = impl_from_ITargetFrame(iface);
1301 return IUnknown_AddRef(This->outer);
1304 static ULONG WINAPI TargetFrame_Release(ITargetFrame *iface)
1306 HlinkFrame *This = impl_from_ITargetFrame(iface);
1307 return IUnknown_Release(This->outer);
1310 static HRESULT WINAPI TargetFrame_SetFrameName(ITargetFrame *iface, LPCWSTR pszFrameName)
1312 HlinkFrame *This = impl_from_ITargetFrame(iface);
1313 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFrameName));
1314 return E_NOTIMPL;
1317 static HRESULT WINAPI TargetFrame_GetFrameName(ITargetFrame *iface, LPWSTR *ppszFrameName)
1319 HlinkFrame *This = impl_from_ITargetFrame(iface);
1320 FIXME("(%p)->(%p)\n", This, ppszFrameName);
1321 return E_NOTIMPL;
1324 static HRESULT WINAPI TargetFrame_GetParentFrame(ITargetFrame *iface, IUnknown **ppunkParent)
1326 HlinkFrame *This = impl_from_ITargetFrame(iface);
1327 FIXME("(%p)->(%p)\n", This, ppunkParent);
1328 return E_NOTIMPL;
1331 static HRESULT WINAPI TargetFrame_FindFrame(ITargetFrame *iface, LPCWSTR pszTargetName,
1332 IUnknown *ppunkContextFrame, DWORD dwFlags, IUnknown **ppunkTargetFrame)
1334 HlinkFrame *This = impl_from_ITargetFrame(iface);
1335 FIXME("(%p)->(%s %p %lx %p)\n", This, debugstr_w(pszTargetName),
1336 ppunkContextFrame, dwFlags, ppunkTargetFrame);
1337 return E_NOTIMPL;
1340 static HRESULT WINAPI TargetFrame_SetFrameSrc(ITargetFrame *iface, LPCWSTR pszFrameSrc)
1342 HlinkFrame *This = impl_from_ITargetFrame(iface);
1343 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFrameSrc));
1344 return E_NOTIMPL;
1347 static HRESULT WINAPI TargetFrame_GetFrameSrc(ITargetFrame *iface, LPWSTR *ppszFrameSrc)
1349 HlinkFrame *This = impl_from_ITargetFrame(iface);
1350 FIXME("(%p)->(%p)\n", This, ppszFrameSrc);
1351 return E_NOTIMPL;
1354 static HRESULT WINAPI TargetFrame_GetFramesContainer(ITargetFrame *iface, IOleContainer **ppContainer)
1356 HlinkFrame *This = impl_from_ITargetFrame(iface);
1357 FIXME("(%p)->(%p)\n", This, ppContainer);
1358 return E_NOTIMPL;
1361 static HRESULT WINAPI TargetFrame_SetFrameOptions(ITargetFrame *iface, DWORD dwFlags)
1363 HlinkFrame *This = impl_from_ITargetFrame(iface);
1364 FIXME("(%p)->(%lx)\n", This, dwFlags);
1365 return E_NOTIMPL;
1368 static HRESULT WINAPI TargetFrame_GetFrameOptions(ITargetFrame *iface, DWORD *pdwFlags)
1370 HlinkFrame *This = impl_from_ITargetFrame(iface);
1371 FIXME("(%p)->(%p)\n", This, pdwFlags);
1372 return E_NOTIMPL;
1375 static HRESULT WINAPI TargetFrame_SetFrameMargins(ITargetFrame *iface, DWORD dwWidth, DWORD dwHeight)
1377 HlinkFrame *This = impl_from_ITargetFrame(iface);
1378 FIXME("(%p)->(%ld %ld)\n", This, dwWidth, dwHeight);
1379 return E_NOTIMPL;
1382 static HRESULT WINAPI TargetFrame_GetFrameMargins(ITargetFrame *iface, DWORD *pdwWidth, DWORD *pdwHeight)
1384 HlinkFrame *This = impl_from_ITargetFrame(iface);
1385 FIXME("(%p)->(%p %p)\n", This, pdwWidth, pdwHeight);
1386 return E_NOTIMPL;
1389 static HRESULT WINAPI TargetFrame_RemoteNavigate(ITargetFrame *iface, ULONG cLength, ULONG *pulData)
1391 HlinkFrame *This = impl_from_ITargetFrame(iface);
1392 FIXME("(%p)->(%lu %p)\n", This, cLength, pulData);
1393 return E_NOTIMPL;
1396 static HRESULT WINAPI TargetFrame_OnChildFrameActivate(ITargetFrame *iface, IUnknown *pUnkChildFrame)
1398 HlinkFrame *This = impl_from_ITargetFrame(iface);
1399 FIXME("(%p)->(%p)\n", This, pUnkChildFrame);
1400 return E_NOTIMPL;
1403 static HRESULT WINAPI TargetFrame_OnChildFrameDeactivate(ITargetFrame *iface, IUnknown *pUnkChildFrame)
1405 HlinkFrame *This = impl_from_ITargetFrame(iface);
1406 FIXME("(%p)->(%p)\n", This, pUnkChildFrame);
1407 return E_NOTIMPL;
1410 static const ITargetFrameVtbl TargetFrameVtbl = {
1411 TargetFrame_QueryInterface,
1412 TargetFrame_AddRef,
1413 TargetFrame_Release,
1414 TargetFrame_SetFrameName,
1415 TargetFrame_GetFrameName,
1416 TargetFrame_GetParentFrame,
1417 TargetFrame_FindFrame,
1418 TargetFrame_SetFrameSrc,
1419 TargetFrame_GetFrameSrc,
1420 TargetFrame_GetFramesContainer,
1421 TargetFrame_SetFrameOptions,
1422 TargetFrame_GetFrameOptions,
1423 TargetFrame_SetFrameMargins,
1424 TargetFrame_GetFrameMargins,
1425 TargetFrame_RemoteNavigate,
1426 TargetFrame_OnChildFrameActivate,
1427 TargetFrame_OnChildFrameDeactivate
1430 static inline HlinkFrame *impl_from_ITargetFrame2(ITargetFrame2 *iface)
1432 return CONTAINING_RECORD(iface, HlinkFrame, ITargetFrame2_iface);
1435 static HRESULT WINAPI TargetFrame2_QueryInterface(ITargetFrame2 *iface, REFIID riid, void **ppv)
1437 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1438 return IUnknown_QueryInterface(This->outer, riid, ppv);
1441 static ULONG WINAPI TargetFrame2_AddRef(ITargetFrame2 *iface)
1443 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1444 return IUnknown_AddRef(This->outer);
1447 static ULONG WINAPI TargetFrame2_Release(ITargetFrame2 *iface)
1449 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1450 return IUnknown_Release(This->outer);
1453 static HRESULT WINAPI TargetFrame2_SetFrameName(ITargetFrame2 *iface, LPCWSTR pszFrameName)
1455 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1456 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFrameName));
1457 return E_NOTIMPL;
1460 static HRESULT WINAPI TargetFrame2_GetFrameName(ITargetFrame2 *iface, LPWSTR *ppszFrameName)
1462 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1463 FIXME("(%p)->(%p)\n", This, ppszFrameName);
1464 return E_NOTIMPL;
1467 static HRESULT WINAPI TargetFrame2_GetParentFrame(ITargetFrame2 *iface, IUnknown **ppunkParent)
1469 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1470 FIXME("(%p)->(%p)\n", This, ppunkParent);
1471 return E_NOTIMPL;
1474 static HRESULT WINAPI TargetFrame2_SetFrameSrc(ITargetFrame2 *iface, LPCWSTR pszFrameSrc)
1476 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1477 FIXME("(%p)->(%s)\n", This, debugstr_w(pszFrameSrc));
1478 return E_NOTIMPL;
1481 static HRESULT WINAPI TargetFrame2_GetFrameSrc(ITargetFrame2 *iface, LPWSTR *ppszFrameSrc)
1483 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1484 FIXME("(%p)->()\n", This);
1485 return E_NOTIMPL;
1488 static HRESULT WINAPI TargetFrame2_GetFramesContainer(ITargetFrame2 *iface, IOleContainer **ppContainer)
1490 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1491 FIXME("(%p)->(%p)\n", This, ppContainer);
1492 return E_NOTIMPL;
1495 static HRESULT WINAPI TargetFrame2_SetFrameOptions(ITargetFrame2 *iface, DWORD dwFlags)
1497 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1498 FIXME("(%p)->(%lx)\n", This, dwFlags);
1499 return E_NOTIMPL;
1502 static HRESULT WINAPI TargetFrame2_GetFrameOptions(ITargetFrame2 *iface, DWORD *pdwFlags)
1504 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1505 FIXME("(%p)->(%p)\n", This, pdwFlags);
1506 return E_NOTIMPL;
1509 static HRESULT WINAPI TargetFrame2_SetFrameMargins(ITargetFrame2 *iface, DWORD dwWidth, DWORD dwHeight)
1511 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1512 FIXME("(%p)->(%ld %ld)\n", This, dwWidth, dwHeight);
1513 return E_NOTIMPL;
1516 static HRESULT WINAPI TargetFrame2_GetFrameMargins(ITargetFrame2 *iface, DWORD *pdwWidth, DWORD *pdwHeight)
1518 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1519 FIXME("(%p)->(%p %p)\n", This, pdwWidth, pdwHeight);
1520 return E_NOTIMPL;
1523 static HRESULT WINAPI TargetFrame2_FindFrame(ITargetFrame2 *iface, LPCWSTR pszTargetName, DWORD dwFlags, IUnknown **ppunkTargetFrame)
1525 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1526 FIXME("(%p)->(%s %lx %p)\n", This, debugstr_w(pszTargetName), dwFlags, ppunkTargetFrame);
1527 return E_NOTIMPL;
1530 static HRESULT WINAPI TargetFrame2_GetTargetAlias(ITargetFrame2 *iface, LPCWSTR pszTargetName, LPWSTR *ppszTargetAlias)
1532 HlinkFrame *This = impl_from_ITargetFrame2(iface);
1533 FIXME("(%p)->(%s %p)\n", This, debugstr_w(pszTargetName), ppszTargetAlias);
1534 return E_NOTIMPL;
1537 static const ITargetFrame2Vtbl TargetFrame2Vtbl = {
1538 TargetFrame2_QueryInterface,
1539 TargetFrame2_AddRef,
1540 TargetFrame2_Release,
1541 TargetFrame2_SetFrameName,
1542 TargetFrame2_GetFrameName,
1543 TargetFrame2_GetParentFrame,
1544 TargetFrame2_SetFrameSrc,
1545 TargetFrame2_GetFrameSrc,
1546 TargetFrame2_GetFramesContainer,
1547 TargetFrame2_SetFrameOptions,
1548 TargetFrame2_GetFrameOptions,
1549 TargetFrame2_SetFrameMargins,
1550 TargetFrame2_GetFrameMargins,
1551 TargetFrame2_FindFrame,
1552 TargetFrame2_GetTargetAlias
1555 static inline HlinkFrame *impl_from_ITargetFramePriv2(ITargetFramePriv2 *iface)
1557 return CONTAINING_RECORD(iface, HlinkFrame, ITargetFramePriv2_iface);
1560 static HRESULT WINAPI TargetFramePriv2_QueryInterface(ITargetFramePriv2 *iface, REFIID riid, void **ppv)
1562 HlinkFrame *This = impl_from_ITargetFramePriv2(iface);
1563 return IUnknown_QueryInterface(This->outer, riid, ppv);
1566 static ULONG WINAPI TargetFramePriv2_AddRef(ITargetFramePriv2 *iface)
1568 HlinkFrame *This = impl_from_ITargetFramePriv2(iface);
1569 return IUnknown_AddRef(This->outer);
1572 static ULONG WINAPI TargetFramePriv2_Release(ITargetFramePriv2 *iface)
1574 HlinkFrame *This = impl_from_ITargetFramePriv2(iface);
1575 return IUnknown_Release(This->outer);
1578 static HRESULT WINAPI TargetFramePriv2_FindFrameDownwards(ITargetFramePriv2 *iface,
1579 LPCWSTR pszTargetName, DWORD dwFlags, IUnknown **ppunkTargetFrame)
1581 HlinkFrame *This = impl_from_ITargetFramePriv2(iface);
1582 FIXME("(%p)->(%s %lx %p)\n", This, debugstr_w(pszTargetName), dwFlags, ppunkTargetFrame);
1583 return E_NOTIMPL;
1586 static HRESULT WINAPI TargetFramePriv2_FindFrameInContext(ITargetFramePriv2 *iface,
1587 LPCWSTR pszTargetName, IUnknown *punkContextFrame, DWORD dwFlags, IUnknown **ppunkTargetFrame)
1589 HlinkFrame *This = impl_from_ITargetFramePriv2(iface);
1590 FIXME("(%p)->(%s %p %lx %p)\n", This, debugstr_w(pszTargetName), punkContextFrame, dwFlags, ppunkTargetFrame);
1591 return E_NOTIMPL;
1594 static HRESULT WINAPI TargetFramePriv2_OnChildFrameActivate(ITargetFramePriv2 *iface, IUnknown *pUnkChildFrame)
1596 HlinkFrame *This = impl_from_ITargetFramePriv2(iface);
1597 FIXME("(%p)->(%p)\n", This, pUnkChildFrame);
1598 return E_NOTIMPL;
1601 static HRESULT WINAPI TargetFramePriv2_OnChildFrameDeactivate(ITargetFramePriv2 *iface, IUnknown *pUnkChildFrame)
1603 HlinkFrame *This = impl_from_ITargetFramePriv2(iface);
1604 FIXME("(%p)->(%p)\n", This, pUnkChildFrame);
1605 return E_NOTIMPL;
1608 static HRESULT WINAPI TargetFramePriv2_NavigateHack(ITargetFramePriv2 *iface, DWORD grfHLNF, LPBC pbc,
1609 IBindStatusCallback *pibsc, LPCWSTR pszTargetName, LPCWSTR pszUrl, LPCWSTR pszLocation)
1611 HlinkFrame *This = impl_from_ITargetFramePriv2(iface);
1612 FIXME("(%p)->(%lx %p %p %s %s %s)\n", This, grfHLNF, pbc, pibsc, debugstr_w(pszTargetName),
1613 debugstr_w(pszUrl), debugstr_w(pszLocation));
1614 return E_NOTIMPL;
1617 static HRESULT WINAPI TargetFramePriv2_FindBrowserByIndex(ITargetFramePriv2 *iface, DWORD dwID, IUnknown **ppunkBrowser)
1619 HlinkFrame *This = impl_from_ITargetFramePriv2(iface);
1620 FIXME("(%p)->(%ld %p)\n", This, dwID, ppunkBrowser);
1621 return E_NOTIMPL;
1624 static HRESULT WINAPI TargetFramePriv2_AggregatedNavigation2(ITargetFramePriv2 *iface, DWORD grfHLNF, LPBC pbc,
1625 IBindStatusCallback *pibsc, LPCWSTR pszTargetName, IUri *pUri, LPCWSTR pszLocation)
1627 HlinkFrame *This = impl_from_ITargetFramePriv2(iface);
1628 IMoniker *mon;
1629 HRESULT hres;
1631 TRACE("(%p)->(%lx %p %p %s %p %s)\n", This, grfHLNF, pbc, pibsc, debugstr_w(pszTargetName),
1632 pUri, debugstr_w(pszLocation));
1635 * NOTE: This is an undocumented function. It seems to be working the way it's implemented,
1636 * but I couldn't get its tests working. It's used by mshtml to load content in a new
1637 * instance of browser.
1640 hres = CreateURLMonikerEx2(NULL, pUri, &mon, 0);
1641 if(FAILED(hres))
1642 return hres;
1644 hres = navigate_hlink(This->doc_host, mon, pbc, pibsc);
1645 IMoniker_Release(mon);
1646 return hres;
1649 static const ITargetFramePriv2Vtbl TargetFramePriv2Vtbl = {
1650 TargetFramePriv2_QueryInterface,
1651 TargetFramePriv2_AddRef,
1652 TargetFramePriv2_Release,
1653 TargetFramePriv2_FindFrameDownwards,
1654 TargetFramePriv2_FindFrameInContext,
1655 TargetFramePriv2_OnChildFrameActivate,
1656 TargetFramePriv2_OnChildFrameDeactivate,
1657 TargetFramePriv2_NavigateHack,
1658 TargetFramePriv2_FindBrowserByIndex,
1659 TargetFramePriv2_AggregatedNavigation2
1662 static inline HlinkFrame *impl_from_IWebBrowserPriv2IE9(IWebBrowserPriv2IE9 *iface)
1664 return CONTAINING_RECORD(iface, HlinkFrame, IWebBrowserPriv2IE9_iface);
1667 static HRESULT WINAPI WebBrowserPriv2IE9_QueryInterface(IWebBrowserPriv2IE9 *iface, REFIID riid, void **ppv)
1669 HlinkFrame *This = impl_from_IWebBrowserPriv2IE9(iface);
1670 return IUnknown_QueryInterface(This->outer, riid, ppv);
1673 static ULONG WINAPI WebBrowserPriv2IE9_AddRef(IWebBrowserPriv2IE9 *iface)
1675 HlinkFrame *This = impl_from_IWebBrowserPriv2IE9(iface);
1676 return IUnknown_AddRef(This->outer);
1679 static ULONG WINAPI WebBrowserPriv2IE9_Release(IWebBrowserPriv2IE9 *iface)
1681 HlinkFrame *This = impl_from_IWebBrowserPriv2IE9(iface);
1682 return IUnknown_Release(This->outer);
1685 static HRESULT WINAPI WebBrowserPriv2IE9_NavigateWithBindCtx2(IWebBrowserPriv2IE9 *iface, IUri *uri, VARIANT *flags,
1686 VARIANT *target_frame, VARIANT *post_data, VARIANT *headers, IBindCtx *bind_ctx, LPOLESTR url_fragment, DWORD unused)
1688 HlinkFrame *This = impl_from_IWebBrowserPriv2IE9(iface);
1689 FIXME("(%p)->(%p %s %s %s %s %p %s)\n", This, uri, debugstr_variant(flags), debugstr_variant(target_frame),
1690 debugstr_variant(post_data), debugstr_variant(headers), bind_ctx, debugstr_w(url_fragment));
1691 return E_NOTIMPL;
1694 static const IWebBrowserPriv2IE9Vtbl WebBrowserPriv2IE9Vtbl = {
1695 WebBrowserPriv2IE9_QueryInterface,
1696 WebBrowserPriv2IE9_AddRef,
1697 WebBrowserPriv2IE9_Release,
1698 WebBrowserPriv2IE9_NavigateWithBindCtx2
1701 BOOL HlinkFrame_QI(HlinkFrame *This, REFIID riid, void **ppv)
1703 if(IsEqualGUID(&IID_IHlinkFrame, riid)) {
1704 TRACE("(%p)->(IID_IHlinkFrame %p)\n", This, ppv);
1705 *ppv = &This->IHlinkFrame_iface;
1706 }else if(IsEqualGUID(&IID_ITargetFrame, riid)) {
1707 TRACE("(%p)->(IID_ITargetFrame %p)\n", This, ppv);
1708 *ppv = &This->ITargetFrame_iface;
1709 }else if(IsEqualGUID(&IID_ITargetFrame2, riid)) {
1710 TRACE("(%p)->(IID_ITargetFrame2 %p)\n", This, ppv);
1711 *ppv = &This->ITargetFrame2_iface;
1712 }else if(IsEqualGUID(&IID_ITargetFramePriv, riid)) {
1713 TRACE("(%p)->(IID_ITargetFramePriv %p)\n", This, ppv);
1714 *ppv = &This->ITargetFramePriv2_iface;
1715 }else if(IsEqualGUID(&IID_ITargetFramePriv2, riid)) {
1716 TRACE("(%p)->(IID_ITargetFramePriv2 %p)\n", This, ppv);
1717 *ppv = &This->ITargetFramePriv2_iface;
1718 }else if(IsEqualGUID(&IID_IWebBrowserPriv2IE9, riid)) {
1719 TRACE("(%p)->(IID_IWebBrowserPriv2IE9 %p)\n", This, ppv);
1720 *ppv = &This->IWebBrowserPriv2IE9_iface;
1721 }else {
1722 return FALSE;
1725 IUnknown_AddRef((IUnknown*)*ppv);
1726 return TRUE;
1729 void HlinkFrame_Init(HlinkFrame *This, IUnknown *outer, DocHost *doc_host)
1731 This->IHlinkFrame_iface.lpVtbl = &HlinkFrameVtbl;
1732 This->ITargetFrame_iface.lpVtbl = &TargetFrameVtbl;
1733 This->ITargetFrame2_iface.lpVtbl = &TargetFrame2Vtbl;
1734 This->ITargetFramePriv2_iface.lpVtbl = &TargetFramePriv2Vtbl;
1735 This->IWebBrowserPriv2IE9_iface.lpVtbl = &WebBrowserPriv2IE9Vtbl;
1737 This->outer = outer;
1738 This->doc_host = doc_host;