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