wined3d: Make the device parameter to wined3d_device_get_ps_consts_i() const.
[wine] / dlls / ieframe / navigate.c
1 /*
2  * Copyright 2006-2007 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #define NONAMELESSUNION
20 #define NONAMELESSSTRUCT
21
22 #include "ieframe.h"
23
24 #include "exdispid.h"
25 #include "shellapi.h"
26 #include "winreg.h"
27 #include "shlwapi.h"
28 #include "wininet.h"
29 #include "mshtml.h"
30
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(ieframe);
34
35 static const WCHAR emptyW[] = {0};
36
37 typedef struct {
38     IBindStatusCallback  IBindStatusCallback_iface;
39     IHttpNegotiate       IHttpNegotiate_iface;
40
41     LONG ref;
42
43     DocHost *doc_host;
44     IBinding *binding;
45
46     LPWSTR url;
47     HGLOBAL post_data;
48     BSTR headers;
49     ULONG post_data_len;
50 } BindStatusCallback;
51
52 static void dump_BINDINFO(BINDINFO *bi)
53 {
54     static const char * const BINDINFOF_str[] = {
55         "#0",
56         "BINDINFOF_URLENCODESTGMEDDATA",
57         "BINDINFOF_URLENCODEDEXTRAINFO"
58     };
59
60     static const char * const BINDVERB_str[] = {
61         "BINDVERB_GET",
62         "BINDVERB_POST",
63         "BINDVERB_PUT",
64         "BINDVERB_CUSTOM"
65     };
66
67     TRACE("\n"
68             "BINDINFO = {\n"
69             "    %d, %s,\n"
70             "    {%d, %p, %p},\n"
71             "    %s,\n"
72             "    %s,\n"
73             "    %s,\n"
74             "    %d, %08x, %d, %d\n"
75             "    {%d %p %x},\n"
76             "    %s\n"
77             "    %p, %d\n"
78             "}\n",
79
80             bi->cbSize, debugstr_w(bi->szExtraInfo),
81             bi->stgmedData.tymed, bi->stgmedData.u.hGlobal, bi->stgmedData.pUnkForRelease,
82             bi->grfBindInfoF > BINDINFOF_URLENCODEDEXTRAINFO
83                 ? "unknown" : BINDINFOF_str[bi->grfBindInfoF],
84             bi->dwBindVerb > BINDVERB_CUSTOM
85                 ? "unknown" : BINDVERB_str[bi->dwBindVerb],
86             debugstr_w(bi->szCustomVerb),
87             bi->cbstgmedData, bi->dwOptions, bi->dwOptionsFlags, bi->dwCodePage,
88             bi->securityAttributes.nLength,
89             bi->securityAttributes.lpSecurityDescriptor,
90             bi->securityAttributes.bInheritHandle,
91             debugstr_guid(&bi->iid),
92             bi->pUnk, bi->dwReserved
93             );
94 }
95
96 static void set_status_text(BindStatusCallback *This, LPCWSTR str)
97 {
98     VARIANTARG arg;
99     DISPPARAMS dispparams = {&arg, NULL, 1, 0};
100
101     if(!This->doc_host)
102         return;
103
104     V_VT(&arg) = VT_BSTR;
105     V_BSTR(&arg) = str ? SysAllocString(str) : NULL;
106     call_sink(This->doc_host->cps.wbe2, DISPID_STATUSTEXTCHANGE, &dispparams);
107     VariantClear(&arg);
108
109     if(This->doc_host->frame)
110         IOleInPlaceFrame_SetStatusText(This->doc_host->frame, str);
111 }
112
113 static HRESULT set_dochost_url(DocHost *This, const WCHAR *url)
114 {
115     WCHAR *new_url;
116
117     if(url) {
118         new_url = heap_strdupW(url);
119         if(!new_url)
120             return E_OUTOFMEMORY;
121     }else {
122         new_url = NULL;
123     }
124
125     heap_free(This->url);
126     This->url = new_url;
127
128     This->container_vtbl->SetURL(This, This->url);
129     return S_OK;
130 }
131
132 static inline BindStatusCallback *impl_from_IBindStatusCallback(IBindStatusCallback *iface)
133 {
134     return CONTAINING_RECORD(iface, BindStatusCallback, IBindStatusCallback_iface);
135 }
136
137 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallback *iface,
138                                                         REFIID riid, void **ppv)
139 {
140     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
141
142     if(IsEqualGUID(&IID_IUnknown, riid)) {
143         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
144         *ppv = &This->IBindStatusCallback_iface;
145     }else if(IsEqualGUID(&IID_IBindStatusCallback, riid)) {
146         TRACE("(%p)->(IID_IBindStatusCallback %p)\n", This, ppv);
147         *ppv = &This->IBindStatusCallback_iface;
148     }else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) {
149         TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This, ppv);
150         *ppv = &This->IHttpNegotiate_iface;
151     }else {
152         *ppv = NULL;
153         WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
154         return E_NOINTERFACE;
155     }
156
157     IUnknown_AddRef((IUnknown*)*ppv);
158     return S_OK;
159 }
160
161 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallback *iface)
162 {
163     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
164     LONG ref = InterlockedIncrement(&This->ref);
165
166     TRACE("(%p) ref=%d\n", This, ref);
167
168     return ref;
169 }
170
171 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallback *iface)
172 {
173     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
174     LONG ref = InterlockedDecrement(&This->ref);
175
176     TRACE("(%p) ref=%d\n", This, ref);
177
178     if(!ref) {
179         if(This->doc_host)
180             IOleClientSite_Release(&This->doc_host->IOleClientSite_iface);
181         if(This->binding)
182             IBinding_Release(This->binding);
183         if(This->post_data)
184             GlobalFree(This->post_data);
185         SysFreeString(This->headers);
186         heap_free(This->url);
187         heap_free(This);
188     }
189
190     return ref;
191 }
192
193 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallback *iface,
194        DWORD dwReserved, IBinding *pbind)
195 {
196     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
197
198     TRACE("(%p)->(%d %p)\n", This, dwReserved, pbind);
199
200     This->binding = pbind;
201     IBinding_AddRef(This->binding);
202
203     return S_OK;
204 }
205
206 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface,
207        LONG *pnPriority)
208 {
209     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
210     FIXME("(%p)->(%p)\n", This, pnPriority);
211     return E_NOTIMPL;
212 }
213
214 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface,
215        DWORD reserved)
216 {
217     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
218     FIXME("(%p)->(%d)\n", This, reserved);
219     return E_NOTIMPL;
220 }
221
222 static DWORD get_http_status_code(IBinding *binding)
223 {
224     IWinInetHttpInfo *http_info;
225     DWORD status, size = sizeof(DWORD);
226     HRESULT hres;
227
228     hres = IBinding_QueryInterface(binding, &IID_IWinInetHttpInfo, (void**)&http_info);
229     if(FAILED(hres))
230         return HTTP_STATUS_OK;
231
232     hres = IWinInetHttpInfo_QueryInfo(http_info, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER,
233             &status, &size, NULL, NULL);
234     IWinInetHttpInfo_Release(http_info);
235
236     if(FAILED(hres))
237         return HTTP_STATUS_OK;
238     return status;
239 }
240
241 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallback *iface,
242         ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
243 {
244     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
245     DWORD status_code;
246
247     TRACE("(%p)->(%d %d %d %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
248           debugstr_w(szStatusText));
249
250     switch(ulStatusCode) {
251     case BINDSTATUS_REDIRECTING:
252         return set_dochost_url(This->doc_host, szStatusText);
253     case BINDSTATUS_BEGINDOWNLOADDATA:
254         set_status_text(This, szStatusText); /* FIXME: "Start downloading from site: %s" */
255         status_code = get_http_status_code(This->binding);
256         if(status_code != HTTP_STATUS_OK)
257             handle_navigation_error(This->doc_host, status_code, This->url, NULL);
258         return S_OK;
259     case BINDSTATUS_ENDDOWNLOADDATA:
260         set_status_text(This, szStatusText); /* FIXME: "Downloading from site: %s" */
261         return S_OK;
262     case BINDSTATUS_CLASSIDAVAILABLE:
263     case BINDSTATUS_MIMETYPEAVAILABLE:
264     case BINDSTATUS_BEGINSYNCOPERATION:
265     case BINDSTATUS_ENDSYNCOPERATION:
266         return S_OK;
267     default:
268         FIXME("status code %u\n", ulStatusCode);
269     }
270
271     return S_OK;
272 }
273
274 void handle_navigation_error(DocHost* doc_host, HRESULT hres, BSTR url, IHTMLWindow2 *win2)
275 {
276     VARIANT var_status_code, var_frame_name, var_url;
277     DISPPARAMS dispparams;
278     VARIANTARG params[5];
279     VARIANT_BOOL cancel = VARIANT_FALSE;
280
281     dispparams.cArgs = 5;
282     dispparams.cNamedArgs = 0;
283     dispparams.rgdispidNamedArgs = NULL;
284     dispparams.rgvarg = params;
285
286     V_VT(params) = VT_BOOL|VT_BYREF;
287     V_BOOLREF(params) = &cancel;
288
289     V_VT(params+1) = VT_VARIANT|VT_BYREF;
290     V_VARIANTREF(params+1) = &var_status_code;
291     V_VT(&var_status_code) = VT_I4;
292     V_I4(&var_status_code) = hres;
293
294     V_VT(params+2) = VT_VARIANT|VT_BYREF;
295     V_VARIANTREF(params+2) = &var_frame_name;
296     V_VT(&var_frame_name) = VT_BSTR;
297     if(win2) {
298         hres = IHTMLWindow2_get_name(win2, &V_BSTR(&var_frame_name));
299         if(FAILED(hres))
300             V_BSTR(&var_frame_name) = NULL;
301     } else
302         V_BSTR(&var_frame_name) = NULL;
303
304     V_VT(params+3) = VT_VARIANT|VT_BYREF;
305     V_VARIANTREF(params+3) = &var_url;
306     V_VT(&var_url) = VT_BSTR;
307     V_BSTR(&var_url) = url;
308
309     V_VT(params+4) = VT_DISPATCH;
310     V_DISPATCH(params+4) = doc_host->disp;
311
312     call_sink(doc_host->cps.wbe2, DISPID_NAVIGATEERROR, &dispparams);
313     SysFreeString(V_BSTR(&var_frame_name));
314
315     if(!cancel)
316         FIXME("Navigate to error page\n");
317 }
318
319 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
320         HRESULT hresult, LPCWSTR szError)
321 {
322     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
323
324     TRACE("(%p)->(%08x %s)\n", This, hresult, debugstr_w(szError));
325
326     set_status_text(This, emptyW);
327
328     if(!This->doc_host)
329         return S_OK;
330
331     if(FAILED(hresult))
332         handle_navigation_error(This->doc_host, hresult, This->url, NULL);
333
334     IOleClientSite_Release(&This->doc_host->IOleClientSite_iface);
335     This->doc_host = NULL;
336
337     IBinding_Release(This->binding);
338     This->binding = NULL;
339
340     return S_OK;
341 }
342
343 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
344         DWORD *grfBINDF, BINDINFO *pbindinfo)
345 {
346     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
347
348     TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
349
350     *grfBINDF = BINDF_ASYNCHRONOUS;
351
352     if(This->post_data) {
353         pbindinfo->dwBindVerb = BINDVERB_POST;
354
355         pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
356         pbindinfo->stgmedData.u.hGlobal = This->post_data;
357         pbindinfo->cbstgmedData = This->post_data_len;
358         pbindinfo->stgmedData.pUnkForRelease = (IUnknown*)&This->IBindStatusCallback_iface;
359         IBindStatusCallback_AddRef(&This->IBindStatusCallback_iface);
360     }
361
362     return S_OK;
363 }
364
365 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
366         DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
367 {
368     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
369     FIXME("(%p)->(%08x %d %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed);
370     return E_NOTIMPL;
371 }
372
373 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
374         REFIID riid, IUnknown *punk)
375 {
376     BindStatusCallback *This = impl_from_IBindStatusCallback(iface);
377
378     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), punk);
379
380     return dochost_object_available(This->doc_host, punk);
381 }
382
383 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
384     BindStatusCallback_QueryInterface,
385     BindStatusCallback_AddRef,
386     BindStatusCallback_Release,
387     BindStatusCallback_OnStartBinding,
388     BindStatusCallback_GetPriority,
389     BindStatusCallback_OnLowResource,
390     BindStatusCallback_OnProgress,
391     BindStatusCallback_OnStopBinding,
392     BindStatusCallback_GetBindInfo,
393     BindStatusCallback_OnDataAvailable,
394     BindStatusCallback_OnObjectAvailable
395 };
396
397 static inline BindStatusCallback *impl_from_IHttpNegotiate(IHttpNegotiate *iface)
398 {
399     return CONTAINING_RECORD(iface, BindStatusCallback, IHttpNegotiate_iface);
400 }
401
402 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate *iface,
403                                                    REFIID riid, void **ppv)
404 {
405     BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
406     return IBindStatusCallback_QueryInterface(&This->IBindStatusCallback_iface, riid, ppv);
407 }
408
409 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate *iface)
410 {
411     BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
412     return IBindStatusCallback_AddRef(&This->IBindStatusCallback_iface);
413 }
414
415 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate *iface)
416 {
417     BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
418     return IBindStatusCallback_Release(&This->IBindStatusCallback_iface);
419 }
420
421 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate *iface,
422         LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
423 {
424     BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
425
426     TRACE("(%p)->(%s %s %d %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders),
427           dwReserved, pszAdditionalHeaders);
428
429     if(This->headers) {
430         int size = (strlenW(This->headers)+1)*sizeof(WCHAR);
431         *pszAdditionalHeaders = CoTaskMemAlloc(size);
432         memcpy(*pszAdditionalHeaders, This->headers, size);
433     }
434
435     return S_OK;
436 }
437
438 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate *iface,
439         DWORD dwResponseCode, LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders,
440         LPWSTR *pszAdditionalRequestHeaders)
441 {
442     BindStatusCallback *This = impl_from_IHttpNegotiate(iface);
443     TRACE("(%p)->(%d %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
444           debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
445     return S_OK;
446 }
447
448 static const IHttpNegotiateVtbl HttpNegotiateVtbl = {
449     HttpNegotiate_QueryInterface,
450     HttpNegotiate_AddRef,
451     HttpNegotiate_Release,
452     HttpNegotiate_BeginningTransaction,
453     HttpNegotiate_OnResponse
454 };
455
456 static BindStatusCallback *create_callback(DocHost *doc_host, LPCWSTR url, PBYTE post_data,
457         ULONG post_data_len, LPCWSTR headers)
458 {
459     BindStatusCallback *ret = heap_alloc(sizeof(BindStatusCallback));
460
461     ret->IBindStatusCallback_iface.lpVtbl = &BindStatusCallbackVtbl;
462     ret->IHttpNegotiate_iface.lpVtbl      = &HttpNegotiateVtbl;
463
464     ret->ref = 1;
465     ret->url = heap_strdupW(url);
466     ret->post_data = NULL;
467     ret->post_data_len = post_data_len;
468     ret->headers = headers ? SysAllocString(headers) : NULL;
469
470     ret->doc_host = doc_host;
471     IOleClientSite_AddRef(&doc_host->IOleClientSite_iface);
472
473     ret->binding = NULL;
474
475     if(post_data) {
476         ret->post_data = GlobalAlloc(0, post_data_len);
477         memcpy(ret->post_data, post_data, post_data_len);
478     }
479
480     return ret;
481 }
482
483 static void on_before_navigate2(DocHost *This, LPCWSTR url, SAFEARRAY *post_data, LPWSTR headers, VARIANT_BOOL *cancel)
484 {
485     VARIANT var_url, var_flags, var_frame_name, var_post_data, var_post_data2, var_headers;
486     DISPPARAMS dispparams;
487     VARIANTARG params[7];
488
489     dispparams.cArgs = 7;
490     dispparams.cNamedArgs = 0;
491     dispparams.rgdispidNamedArgs = NULL;
492     dispparams.rgvarg = params;
493
494     This->busy = VARIANT_TRUE;
495
496     V_VT(params) = VT_BOOL|VT_BYREF;
497     V_BOOLREF(params) = cancel;
498
499     V_VT(params+1) = (VT_BYREF|VT_VARIANT);
500     V_VARIANTREF(params+1) = &var_headers;
501     V_VT(&var_headers) = VT_BSTR;
502     V_BSTR(&var_headers) = headers;
503
504     V_VT(params+2) = (VT_BYREF|VT_VARIANT);
505     V_VARIANTREF(params+2) = &var_post_data2;
506     V_VT(&var_post_data2) = (VT_BYREF|VT_VARIANT);
507     V_VARIANTREF(&var_post_data2) = &var_post_data;
508
509     if(post_data) {
510         V_VT(&var_post_data) = VT_UI1|VT_ARRAY;
511         V_ARRAY(&var_post_data) = post_data;
512     }else {
513         V_VT(&var_post_data) = VT_EMPTY;
514     }
515
516     V_VT(params+3) = (VT_BYREF|VT_VARIANT);
517     V_VARIANTREF(params+3) = &var_frame_name;
518     V_VT(&var_frame_name) = VT_BSTR;
519     V_BSTR(&var_frame_name) = NULL;
520
521     V_VT(params+4) = (VT_BYREF|VT_VARIANT);
522     V_VARIANTREF(params+4) = &var_flags;
523     V_VT(&var_flags) = VT_I4;
524     V_I4(&var_flags) = 0;
525
526     V_VT(params+5) = (VT_BYREF|VT_VARIANT);
527     V_VARIANTREF(params+5) = &var_url;
528     V_VT(&var_url) = VT_BSTR;
529     V_BSTR(&var_url) = SysAllocString(url);
530
531     V_VT(params+6) = (VT_DISPATCH);
532     V_DISPATCH(params+6) = This->disp;
533
534     call_sink(This->cps.wbe2, DISPID_BEFORENAVIGATE2, &dispparams);
535
536     SysFreeString(V_BSTR(&var_url));
537 }
538
539 /* FIXME: urlmon should handle it */
540 static BOOL try_application_url(LPCWSTR url)
541 {
542     SHELLEXECUTEINFOW exec_info;
543     WCHAR app[64];
544     HKEY hkey;
545     DWORD res, type;
546     HRESULT hres;
547
548     static const WCHAR wszURLProtocol[] = {'U','R','L',' ','P','r','o','t','o','c','o','l',0};
549
550     hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, app, sizeof(app)/sizeof(WCHAR), NULL, 0);
551     if(FAILED(hres))
552         return FALSE;
553
554     res = RegOpenKeyW(HKEY_CLASSES_ROOT, app, &hkey);
555     if(res != ERROR_SUCCESS)
556         return FALSE;
557
558     res = RegQueryValueExW(hkey, wszURLProtocol, NULL, &type, NULL, NULL);
559     RegCloseKey(hkey);
560     if(res != ERROR_SUCCESS || type != REG_SZ)
561         return FALSE;
562
563     TRACE("opening application %s\n", debugstr_w(app));
564
565     memset(&exec_info, 0, sizeof(exec_info));
566     exec_info.cbSize = sizeof(exec_info);
567     exec_info.lpFile = url;
568     exec_info.nShow = SW_SHOW;
569
570     return ShellExecuteExW(&exec_info);
571 }
572
573 static HRESULT create_moniker(LPCWSTR url, IMoniker **mon)
574 {
575     WCHAR new_url[INTERNET_MAX_URL_LENGTH];
576     DWORD size;
577     HRESULT hres;
578
579     if(PathIsURLW(url))
580         return CreateURLMoniker(NULL, url, mon);
581
582     size = sizeof(new_url)/sizeof(WCHAR);
583     hres = UrlApplySchemeW(url, new_url, &size, URL_APPLY_GUESSSCHEME | URL_APPLY_GUESSFILE);
584     TRACE("was %s got %s\n", debugstr_w(url), debugstr_w(new_url));
585     if(FAILED(hres)) {
586         WARN("UrlApplyScheme failed: %08x\n", hres);
587         return hres;
588     }
589
590     return CreateURLMoniker(NULL, new_url, mon);
591 }
592
593 static HRESULT bind_to_object(DocHost *This, IMoniker *mon, LPCWSTR url, IBindCtx *bindctx,
594                               IBindStatusCallback *callback)
595 {
596     IUnknown *unk = NULL;
597     WCHAR *display_name;
598     HRESULT hres;
599
600     if(mon) {
601         IMoniker_AddRef(mon);
602     }else {
603         hres = create_moniker(url, &mon);
604         if(FAILED(hres))
605             return hres;
606     }
607
608     hres = IMoniker_GetDisplayName(mon, 0, NULL, &display_name);
609     if(FAILED(hres)) {
610         FIXME("GetDisplayName failed: %08x\n", hres);
611         return hres;
612     }
613
614     hres = set_dochost_url(This, display_name);
615     CoTaskMemFree(display_name);
616     if(FAILED(hres))
617         return hres;
618
619     IBindCtx_RegisterObjectParam(bindctx, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM,
620                                  (IUnknown*)&This->IOleClientSite_iface);
621
622     hres = IMoniker_BindToObject(mon, bindctx, NULL, &IID_IUnknown, (void**)&unk);
623     if(SUCCEEDED(hres)) {
624         hres = S_OK;
625         if(unk)
626             IUnknown_Release(unk);
627     }else if(try_application_url(url)) {
628         hres = S_OK;
629     }else {
630         FIXME("BindToObject failed: %08x\n", hres);
631     }
632
633     IMoniker_Release(mon);
634     return S_OK;
635 }
636
637 static void html_window_navigate(DocHost *This, IHTMLPrivateWindow *window, BSTR url, BSTR headers, SAFEARRAY *post_data)
638 {
639     VARIANT headers_var, post_data_var;
640     BSTR empty_str;
641     HRESULT hres;
642
643     hres = set_dochost_url(This, url);
644     if(FAILED(hres))
645         return;
646
647     empty_str = SysAllocStringLen(NULL, 0);
648
649     if(headers) {
650         V_VT(&headers_var) = VT_BSTR;
651         V_BSTR(&headers_var) = headers;
652     }else {
653         V_VT(&headers_var) = VT_EMPTY;
654     }
655
656     if(post_data) {
657         V_VT(&post_data_var) = VT_UI1|VT_ARRAY;
658         V_ARRAY(&post_data_var) = post_data;
659     }else {
660         V_VT(&post_data_var) = VT_EMPTY;
661     }
662
663     set_doc_state(This, READYSTATE_LOADING);
664     hres = IHTMLPrivateWindow_SuperNavigate(window, url, empty_str, NULL, NULL, &post_data_var, &headers_var, 0);
665     SysFreeString(empty_str);
666     if(FAILED(hres))
667         WARN("SuprtNavigate failed: %08x\n", hres);
668 }
669
670 typedef struct {
671     task_header_t header;
672     BSTR url;
673     BSTR headers;
674     SAFEARRAY *post_data;
675     BOOL async_notif;
676 } task_doc_navigate_t;
677
678 static void doc_navigate_task_destr(task_header_t *t)
679 {
680     task_doc_navigate_t *task = (task_doc_navigate_t*)t;
681
682     SysFreeString(task->url);
683     SysFreeString(task->headers);
684     if(task->post_data)
685         SafeArrayDestroy(task->post_data);
686     heap_free(task);
687 }
688
689 static void doc_navigate_proc(DocHost *This, task_header_t *t)
690 {
691     task_doc_navigate_t *task = (task_doc_navigate_t*)t;
692     IHTMLPrivateWindow *priv_window;
693     HRESULT hres;
694
695     if(!This->doc_navigate) {
696         ERR("Skip nav\n");
697         return;
698     }
699
700     if(task->async_notif) {
701         VARIANT_BOOL cancel = VARIANT_FALSE;
702         on_before_navigate2(This, task->url, task->post_data, task->headers, &cancel);
703         if(cancel) {
704             TRACE("Navigation canceled\n");
705             return;
706         }
707     }
708
709     hres = IUnknown_QueryInterface(This->doc_navigate, &IID_IHTMLPrivateWindow, (void**)&priv_window);
710     if(SUCCEEDED(hres)) {
711         html_window_navigate(This, priv_window, task->url, task->headers, task->post_data);
712         IHTMLPrivateWindow_Release(priv_window);
713     }else {
714         WARN("Could not get IHTMLPrivateWindow iface: %08x\n", hres);
715     }
716 }
717
718 static HRESULT async_doc_navigate(DocHost *This, LPCWSTR url, LPCWSTR headers, PBYTE post_data, ULONG post_data_size,
719         BOOL async_notif)
720 {
721     task_doc_navigate_t *task;
722
723     TRACE("%s\n", debugstr_w(url));
724
725     task = heap_alloc_zero(sizeof(*task));
726     if(!task)
727         return E_OUTOFMEMORY;
728
729     task->url = SysAllocString(url);
730     if(!task->url) {
731         doc_navigate_task_destr(&task->header);
732         return E_OUTOFMEMORY;
733     }
734
735     if(headers) {
736         task->headers = SysAllocString(headers);
737         if(!task->headers) {
738             doc_navigate_task_destr(&task->header);
739             return E_OUTOFMEMORY;
740         }
741     }
742
743     if(post_data) {
744         task->post_data = SafeArrayCreateVector(VT_UI1, 0, post_data_size);
745         if(!task->post_data) {
746             doc_navigate_task_destr(&task->header);
747             return E_OUTOFMEMORY;
748         }
749
750         memcpy(task->post_data->pvData, post_data, post_data_size);
751     }
752
753     if(!async_notif) {
754         VARIANT_BOOL cancel = VARIANT_FALSE;
755
756         on_before_navigate2(This, task->url, task->post_data, task->headers, &cancel);
757         if(cancel) {
758             TRACE("Navigation canceled\n");
759             doc_navigate_task_destr(&task->header);
760             return S_OK;
761         }
762     }
763
764     task->async_notif = async_notif;
765     abort_dochost_tasks(This, doc_navigate_proc);
766     push_dochost_task(This, &task->header, doc_navigate_proc, doc_navigate_task_destr, FALSE);
767     return S_OK;
768 }
769
770 static HRESULT navigate_bsc(DocHost *This, BindStatusCallback *bsc, IMoniker *mon)
771 {
772     VARIANT_BOOL cancel = VARIANT_FALSE;
773     SAFEARRAY *post_data = NULL;
774     IBindCtx *bindctx;
775     HRESULT hres;
776
777     set_doc_state(This, READYSTATE_LOADING);
778
779     if(bsc->post_data) {
780         post_data = SafeArrayCreateVector(VT_UI1, 0, bsc->post_data_len);
781         memcpy(post_data->pvData, post_data, bsc->post_data_len);
782     }
783
784     on_before_navigate2(This, bsc->url, post_data, bsc->headers, &cancel);
785     if(post_data)
786         SafeArrayDestroy(post_data);
787     if(cancel) {
788         FIXME("Navigation canceled\n");
789         return S_OK;
790     }
791
792     if(This->document)
793         deactivate_document(This);
794
795     CreateAsyncBindCtx(0, &bsc->IBindStatusCallback_iface, 0, &bindctx);
796
797     if(This->frame)
798         IOleInPlaceFrame_EnableModeless(This->frame, FALSE);
799
800     hres = bind_to_object(This, mon, bsc->url, bindctx, &bsc->IBindStatusCallback_iface);
801
802     if(This->frame)
803         IOleInPlaceFrame_EnableModeless(This->frame, TRUE);
804
805     IBindCtx_Release(bindctx);
806
807     return hres;
808 }
809
810 typedef struct {
811     task_header_t header;
812     BindStatusCallback *bsc;
813 } task_navigate_bsc_t;
814
815 static void navigate_bsc_task_destr(task_header_t *t)
816 {
817     task_navigate_bsc_t *task = (task_navigate_bsc_t*)t;
818
819     IBindStatusCallback_Release(&task->bsc->IBindStatusCallback_iface);
820     heap_free(task);
821 }
822
823 static void navigate_bsc_proc(DocHost *This, task_header_t *t)
824 {
825     task_navigate_bsc_t *task = (task_navigate_bsc_t*)t;
826
827     if(!This->hwnd)
828         create_doc_view_hwnd(This);
829
830     navigate_bsc(This, task->bsc, NULL);
831 }
832
833
834 HRESULT navigate_url(DocHost *This, LPCWSTR url, const VARIANT *Flags,
835                      const VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers)
836 {
837     PBYTE post_data = NULL;
838     ULONG post_data_len = 0;
839     LPWSTR headers = NULL;
840     HRESULT hres = S_OK;
841
842     TRACE("navigating to %s\n", debugstr_w(url));
843
844     if((Flags && V_VT(Flags) != VT_EMPTY)
845        || (TargetFrameName && V_VT(TargetFrameName) != VT_EMPTY))
846         FIXME("Unsupported args (Flags %p:%d; TargetFrameName %p:%d)\n",
847                 Flags, Flags ? V_VT(Flags) : -1, TargetFrameName,
848                 TargetFrameName ? V_VT(TargetFrameName) : -1);
849
850     if(PostData && V_VT(PostData) == (VT_ARRAY | VT_UI1) && V_ARRAY(PostData)) {
851         SafeArrayAccessData(V_ARRAY(PostData), (void**)&post_data);
852         post_data_len = V_ARRAY(PostData)->rgsabound[0].cElements;
853     }
854
855     if(Headers && V_VT(Headers) == VT_BSTR) {
856         headers = V_BSTR(Headers);
857         TRACE("Headers: %s\n", debugstr_w(headers));
858     }
859
860     set_doc_state(This, READYSTATE_LOADING);
861     This->ready_state = READYSTATE_LOADING;
862
863     if(This->doc_navigate) {
864         WCHAR new_url[INTERNET_MAX_URL_LENGTH];
865
866         if(PathIsURLW(url)) {
867             new_url[0] = 0;
868         }else {
869             DWORD size;
870
871             size = sizeof(new_url)/sizeof(WCHAR);
872             hres = UrlApplySchemeW(url, new_url, &size,
873                     URL_APPLY_GUESSSCHEME | URL_APPLY_GUESSFILE | URL_APPLY_DEFAULT);
874             if(FAILED(hres)) {
875                 WARN("UrlApplyScheme failed: %08x\n", hres);
876                 new_url[0] = 0;
877             }
878         }
879
880         hres = async_doc_navigate(This, *new_url ? new_url : url, headers, post_data,
881                 post_data_len, TRUE);
882     }else {
883         task_navigate_bsc_t *task;
884
885         task = heap_alloc(sizeof(*task));
886         task->bsc = create_callback(This, url, post_data, post_data_len, headers);
887         push_dochost_task(This, &task->header, navigate_bsc_proc, navigate_bsc_task_destr, This->url == NULL);
888     }
889
890     if(post_data)
891         SafeArrayUnaccessData(V_ARRAY(PostData));
892
893     return hres;
894 }
895
896 static HRESULT navigate_hlink(DocHost *This, IMoniker *mon, IBindCtx *bindctx,
897                               IBindStatusCallback *callback)
898 {
899     IHttpNegotiate *http_negotiate;
900     BindStatusCallback *bsc;
901     PBYTE post_data = NULL;
902     ULONG post_data_len = 0;
903     LPWSTR headers = NULL, url;
904     BINDINFO bindinfo;
905     DWORD bindf = 0;
906     HRESULT hres;
907
908     TRACE("\n");
909
910     hres = IMoniker_GetDisplayName(mon, 0, NULL, &url);
911     if(FAILED(hres))
912         FIXME("GetDisplayName failed: %08x\n", hres);
913
914     hres = IBindStatusCallback_QueryInterface(callback, &IID_IHttpNegotiate,
915                                               (void**)&http_negotiate);
916     if(SUCCEEDED(hres)) {
917         static const WCHAR null_string[] = {0};
918
919         IHttpNegotiate_BeginningTransaction(http_negotiate, null_string, null_string, 0,
920                                             &headers);
921         IHttpNegotiate_Release(http_negotiate);
922     }
923
924     memset(&bindinfo, 0, sizeof(bindinfo));
925     bindinfo.cbSize = sizeof(bindinfo);
926
927     hres = IBindStatusCallback_GetBindInfo(callback, &bindf, &bindinfo);
928     dump_BINDINFO(&bindinfo);
929     if(bindinfo.dwBindVerb == BINDVERB_POST) {
930         post_data_len = bindinfo.cbstgmedData;
931         if(post_data_len)
932             post_data = bindinfo.stgmedData.u.hGlobal;
933     }
934
935     if(This->doc_navigate) {
936         hres = async_doc_navigate(This, url, headers, post_data, post_data_len, FALSE);
937     }else {
938         bsc = create_callback(This, url, post_data, post_data_len, headers);
939         hres = navigate_bsc(This, bsc, mon);
940         IBindStatusCallback_Release(&bsc->IBindStatusCallback_iface);
941     }
942
943     CoTaskMemFree(url);
944     CoTaskMemFree(headers);
945     ReleaseBindInfo(&bindinfo);
946
947     return hres;
948 }
949
950 HRESULT go_home(DocHost *This)
951 {
952     HKEY hkey;
953     DWORD res, type, size;
954     WCHAR wszPageName[MAX_PATH];
955     static const WCHAR wszAboutBlank[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
956     static const WCHAR wszStartPage[] = {'S','t','a','r','t',' ','P','a','g','e',0};
957     static const WCHAR wszSubKey[] = {'S','o','f','t','w','a','r','e','\\',
958                                       'M','i','c','r','o','s','o','f','t','\\',
959                                       'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\',
960                                       'M','a','i','n',0};
961
962     res = RegOpenKeyW(HKEY_CURRENT_USER, wszSubKey, &hkey);
963     if (res != ERROR_SUCCESS)
964         return navigate_url(This, wszAboutBlank, NULL, NULL, NULL, NULL);
965
966     size = sizeof(wszPageName);
967     res = RegQueryValueExW(hkey, wszStartPage, NULL, &type, (LPBYTE)wszPageName, &size);
968     RegCloseKey(hkey);
969     if (res != ERROR_SUCCESS || type != REG_SZ)
970         return navigate_url(This, wszAboutBlank, NULL, NULL, NULL, NULL);
971
972     return navigate_url(This, wszPageName, NULL, NULL, NULL, NULL);
973 }
974
975 HRESULT get_location_url(DocHost *This, BSTR *ret)
976 {
977     FIXME("semi-stub\n");
978
979     *ret = This->url ? SysAllocString(This->url) : SysAllocStringLen(NULL, 0);
980     if(!*ret)
981         return E_OUTOFMEMORY;
982
983     return This->url ? S_OK : S_FALSE;
984 }
985
986 static inline HlinkFrame *impl_from_IHlinkFrame(IHlinkFrame *iface)
987 {
988     return CONTAINING_RECORD(iface, HlinkFrame, IHlinkFrame_iface);
989 }
990
991 static HRESULT WINAPI HlinkFrame_QueryInterface(IHlinkFrame *iface, REFIID riid, void **ppv)
992 {
993     HlinkFrame *This = impl_from_IHlinkFrame(iface);
994     return IUnknown_QueryInterface(This->outer, riid, ppv);
995 }
996
997 static ULONG WINAPI HlinkFrame_AddRef(IHlinkFrame *iface)
998 {
999     HlinkFrame *This = impl_from_IHlinkFrame(iface);
1000     return IUnknown_AddRef(This->outer);
1001 }
1002
1003 static ULONG WINAPI HlinkFrame_Release(IHlinkFrame *iface)
1004 {
1005     HlinkFrame *This = impl_from_IHlinkFrame(iface);
1006     return IUnknown_Release(This->outer);
1007 }
1008
1009 static HRESULT WINAPI HlinkFrame_SetBrowseContext(IHlinkFrame *iface,
1010                                                   IHlinkBrowseContext *pihlbc)
1011 {
1012     HlinkFrame *This = impl_from_IHlinkFrame(iface);
1013     FIXME("(%p)->(%p)\n", This, pihlbc);
1014     return E_NOTIMPL;
1015 }
1016
1017 static HRESULT WINAPI HlinkFrame_GetBrowseContext(IHlinkFrame *iface,
1018                                                   IHlinkBrowseContext **ppihlbc)
1019 {
1020     HlinkFrame *This = impl_from_IHlinkFrame(iface);
1021     FIXME("(%p)->(%p)\n", This, ppihlbc);
1022     return E_NOTIMPL;
1023 }
1024
1025 static HRESULT WINAPI HlinkFrame_Navigate(IHlinkFrame *iface, DWORD grfHLNF, LPBC pbc,
1026                                           IBindStatusCallback *pibsc, IHlink *pihlNavigate)
1027 {
1028     HlinkFrame *This = impl_from_IHlinkFrame(iface);
1029     IMoniker *mon;
1030     LPWSTR location = NULL;
1031
1032     TRACE("(%p)->(%08x %p %p %p)\n", This, grfHLNF, pbc, pibsc, pihlNavigate);
1033
1034     if(grfHLNF)
1035         FIXME("unsupported grfHLNF=%08x\n", grfHLNF);
1036
1037     /* Windows calls GetTargetFrameName here. */
1038
1039     IHlink_GetMonikerReference(pihlNavigate, 1, &mon, &location);
1040
1041     if(location) {
1042         FIXME("location = %s\n", debugstr_w(location));
1043         CoTaskMemFree(location);
1044     }
1045
1046     /* Windows calls GetHlinkSite here */
1047
1048     if(grfHLNF & HLNF_OPENINNEWWINDOW) {
1049         FIXME("Not supported HLNF_OPENINNEWWINDOW\n");
1050         return E_NOTIMPL;
1051     }
1052
1053     return navigate_hlink(This->doc_host, mon, pbc, pibsc);
1054 }
1055
1056 static HRESULT WINAPI HlinkFrame_OnNavigate(IHlinkFrame *iface, DWORD grfHLNF,
1057         IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName, DWORD dwreserved)
1058 {
1059     HlinkFrame *This = impl_from_IHlinkFrame(iface);
1060     FIXME("(%p)->(%08x %p %s %s %d)\n", This, grfHLNF, pimkTarget, debugstr_w(pwzLocation),
1061           debugstr_w(pwzFriendlyName), dwreserved);
1062     return E_NOTIMPL;
1063 }
1064
1065 static HRESULT WINAPI HlinkFrame_UpdateHlink(IHlinkFrame *iface, ULONG uHLID,
1066         IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName)
1067 {
1068     HlinkFrame *This = impl_from_IHlinkFrame(iface);
1069     FIXME("(%p)->(%u %p %s %s)\n", This, uHLID, pimkTarget, debugstr_w(pwzLocation),
1070           debugstr_w(pwzFriendlyName));
1071     return E_NOTIMPL;
1072 }
1073
1074 static const IHlinkFrameVtbl HlinkFrameVtbl = {
1075     HlinkFrame_QueryInterface,
1076     HlinkFrame_AddRef,
1077     HlinkFrame_Release,
1078     HlinkFrame_SetBrowseContext,
1079     HlinkFrame_GetBrowseContext,
1080     HlinkFrame_Navigate,
1081     HlinkFrame_OnNavigate,
1082     HlinkFrame_UpdateHlink
1083 };
1084
1085 static inline HlinkFrame *impl_from_ITargetFrame2(ITargetFrame2 *iface)
1086 {
1087     return CONTAINING_RECORD(iface, HlinkFrame, IHlinkFrame_iface);
1088 }
1089
1090 static HRESULT WINAPI TargetFrame2_QueryInterface(ITargetFrame2 *iface, REFIID riid, void **ppv)
1091 {
1092     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1093     return IUnknown_QueryInterface(This->outer, riid, ppv);
1094 }
1095
1096 static ULONG WINAPI TargetFrame2_AddRef(ITargetFrame2 *iface)
1097 {
1098     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1099     return IUnknown_AddRef(This->outer);
1100 }
1101
1102 static ULONG WINAPI TargetFrame2_Release(ITargetFrame2 *iface)
1103 {
1104     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1105     return IUnknown_Release(This->outer);
1106 }
1107
1108 static HRESULT WINAPI TargetFrame2_SetFrameName(ITargetFrame2 *iface, LPCWSTR pszFrameName)
1109 {
1110     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1111     FIXME("(%p)->(%s)\n", This, debugstr_w(pszFrameName));
1112     return E_NOTIMPL;
1113 }
1114
1115 static HRESULT WINAPI TargetFrame2_GetFrameName(ITargetFrame2 *iface, LPWSTR *ppszFrameName)
1116 {
1117     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1118     FIXME("(%p)->(%p)\n", This, ppszFrameName);
1119     return E_NOTIMPL;
1120 }
1121
1122 static HRESULT WINAPI TargetFrame2_GetParentFrame(ITargetFrame2 *iface, IUnknown **ppunkParent)
1123 {
1124     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1125     FIXME("(%p)->(%p)\n", This, ppunkParent);
1126     return E_NOTIMPL;
1127 }
1128
1129 static HRESULT WINAPI TargetFrame2_SetFrameSrc(ITargetFrame2 *iface, LPCWSTR pszFrameSrc)
1130 {
1131     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1132     FIXME("(%p)->(%s)\n", This, debugstr_w(pszFrameSrc));
1133     return E_NOTIMPL;
1134 }
1135
1136 static HRESULT WINAPI TargetFrame2_GetFrameSrc(ITargetFrame2 *iface, LPWSTR *ppszFrameSrc)
1137 {
1138     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1139     FIXME("(%p)->()\n", This);
1140     return E_NOTIMPL;
1141 }
1142
1143 static HRESULT WINAPI TargetFrame2_GetFramesContainer(ITargetFrame2 *iface, IOleContainer **ppContainer)
1144 {
1145     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1146     FIXME("(%p)->(%p)\n", This, ppContainer);
1147     return E_NOTIMPL;
1148 }
1149
1150 static HRESULT WINAPI TargetFrame2_SetFrameOptions(ITargetFrame2 *iface, DWORD dwFlags)
1151 {
1152     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1153     FIXME("(%p)->(%x)\n", This, dwFlags);
1154     return E_NOTIMPL;
1155 }
1156
1157 static HRESULT WINAPI TargetFrame2_GetFrameOptions(ITargetFrame2 *iface, DWORD *pdwFlags)
1158 {
1159     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1160     FIXME("(%p)->(%p)\n", This, pdwFlags);
1161     return E_NOTIMPL;
1162 }
1163
1164 static HRESULT WINAPI TargetFrame2_SetFrameMargins(ITargetFrame2 *iface, DWORD dwWidth, DWORD dwHeight)
1165 {
1166     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1167     FIXME("(%p)->(%d %d)\n", This, dwWidth, dwHeight);
1168     return E_NOTIMPL;
1169 }
1170
1171 static HRESULT WINAPI TargetFrame2_GetFrameMargins(ITargetFrame2 *iface, DWORD *pdwWidth, DWORD *pdwHeight)
1172 {
1173     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1174     FIXME("(%p)->(%p %p)\n", This, pdwWidth, pdwHeight);
1175     return E_NOTIMPL;
1176 }
1177
1178 static HRESULT WINAPI TargetFrame2_FindFrame(ITargetFrame2 *iface, LPCWSTR pszTargetName, DWORD dwFlags, IUnknown **ppunkTargetFrame)
1179 {
1180     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1181     FIXME("(%p)->(%s %x %p)\n", This, debugstr_w(pszTargetName), dwFlags, ppunkTargetFrame);
1182     return E_NOTIMPL;
1183 }
1184
1185 static HRESULT WINAPI TargetFrame2_GetTargetAlias(ITargetFrame2 *iface, LPCWSTR pszTargetName, LPWSTR *ppszTargetAlias)
1186 {
1187     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1188     FIXME("(%p)->(%s %p)\n", This, debugstr_w(pszTargetName), ppszTargetAlias);
1189     return E_NOTIMPL;
1190 }
1191
1192 static const ITargetFrame2Vtbl TargetFrame2Vtbl = {
1193     TargetFrame2_QueryInterface,
1194     TargetFrame2_AddRef,
1195     TargetFrame2_Release,
1196     TargetFrame2_SetFrameName,
1197     TargetFrame2_GetFrameName,
1198     TargetFrame2_GetParentFrame,
1199     TargetFrame2_SetFrameSrc,
1200     TargetFrame2_GetFrameSrc,
1201     TargetFrame2_GetFramesContainer,
1202     TargetFrame2_SetFrameOptions,
1203     TargetFrame2_GetFrameOptions,
1204     TargetFrame2_SetFrameMargins,
1205     TargetFrame2_GetFrameMargins,
1206     TargetFrame2_FindFrame,
1207     TargetFrame2_GetTargetAlias
1208 };
1209
1210 BOOL HlinkFrame_QI(HlinkFrame *This, REFIID riid, void **ppv)
1211 {
1212     if(IsEqualGUID(&IID_IHlinkFrame, riid)) {
1213         TRACE("(%p)->(IID_IHlinkFrame %p)\n", This, ppv);
1214         *ppv = &This->IHlinkFrame_iface;
1215     }else if(IsEqualGUID(&IID_ITargetFrame2, riid)) {
1216         TRACE("(%p)->(IID_ITargetFrame2 %p)\n", This, ppv);
1217         *ppv = &This->ITargetFrame2_iface;
1218     }else {
1219         return FALSE;
1220     }
1221
1222     IUnknown_AddRef((IUnknown*)*ppv);
1223     return TRUE;
1224 }
1225
1226 void HlinkFrame_Init(HlinkFrame *This, IUnknown *outer, DocHost *doc_host)
1227 {
1228     This->IHlinkFrame_iface.lpVtbl   = &HlinkFrameVtbl;
1229     This->ITargetFrame2_iface.lpVtbl = &TargetFrame2Vtbl;
1230
1231     This->outer = outer;
1232     This->doc_host = doc_host;
1233 }