mmdevapi/tests: Add tests for volume control interfaces.
[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     if(url[1] == ':') {
582         size = sizeof(new_url);
583         hres = UrlCreateFromPathW(url, new_url, &size, 0);
584         if(FAILED(hres)) {
585             WARN("UrlCreateFromPathW failed: %08x\n", hres);
586             return hres;
587         }
588     }else {
589         size = sizeof(new_url)/sizeof(WCHAR);
590         hres = UrlApplySchemeW(url, new_url, &size, URL_APPLY_GUESSSCHEME);
591         TRACE("got %s\n", debugstr_w(new_url));
592         if(FAILED(hres)) {
593             WARN("UrlApplyScheme failed: %08x\n", hres);
594             return hres;
595         }
596     }
597
598     return CreateURLMoniker(NULL, new_url, mon);
599 }
600
601 static HRESULT bind_to_object(DocHost *This, IMoniker *mon, LPCWSTR url, IBindCtx *bindctx,
602                               IBindStatusCallback *callback)
603 {
604     IUnknown *unk = NULL;
605     WCHAR *display_name;
606     HRESULT hres;
607
608     if(mon) {
609         IMoniker_AddRef(mon);
610     }else {
611         hres = create_moniker(url, &mon);
612         if(FAILED(hres))
613             return hres;
614     }
615
616     hres = IMoniker_GetDisplayName(mon, 0, NULL, &display_name);
617     if(FAILED(hres)) {
618         FIXME("GetDisplayName failed: %08x\n", hres);
619         return hres;
620     }
621
622     hres = set_dochost_url(This, display_name);
623     CoTaskMemFree(display_name);
624     if(FAILED(hres))
625         return hres;
626
627     IBindCtx_RegisterObjectParam(bindctx, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM,
628                                  (IUnknown*)&This->IOleClientSite_iface);
629
630     hres = IMoniker_BindToObject(mon, bindctx, NULL, &IID_IUnknown, (void**)&unk);
631     if(SUCCEEDED(hres)) {
632         hres = S_OK;
633         if(unk)
634             IUnknown_Release(unk);
635     }else if(try_application_url(url)) {
636         hres = S_OK;
637     }else {
638         FIXME("BindToObject failed: %08x\n", hres);
639     }
640
641     IMoniker_Release(mon);
642     return S_OK;
643 }
644
645 static void html_window_navigate(DocHost *This, IHTMLPrivateWindow *window, BSTR url, BSTR headers, SAFEARRAY *post_data)
646 {
647     VARIANT headers_var, post_data_var;
648     BSTR empty_str;
649     HRESULT hres;
650
651     hres = set_dochost_url(This, url);
652     if(FAILED(hres))
653         return;
654
655     empty_str = SysAllocStringLen(NULL, 0);
656
657     if(headers) {
658         V_VT(&headers_var) = VT_BSTR;
659         V_BSTR(&headers_var) = headers;
660     }else {
661         V_VT(&headers_var) = VT_EMPTY;
662     }
663
664     if(post_data) {
665         V_VT(&post_data_var) = VT_UI1|VT_ARRAY;
666         V_ARRAY(&post_data_var) = post_data;
667     }else {
668         V_VT(&post_data_var) = VT_EMPTY;
669     }
670
671     set_doc_state(This, READYSTATE_LOADING);
672     hres = IHTMLPrivateWindow_SuperNavigate(window, url, empty_str, NULL, NULL, &post_data_var, &headers_var, 0);
673     SysFreeString(empty_str);
674     if(FAILED(hres))
675         WARN("SuprtNavigate failed: %08x\n", hres);
676 }
677
678 typedef struct {
679     task_header_t header;
680     BSTR url;
681     BSTR headers;
682     SAFEARRAY *post_data;
683     BOOL async_notif;
684 } task_doc_navigate_t;
685
686 static HRESULT free_doc_navigate_task(task_doc_navigate_t *task, BOOL free_task)
687 {
688     SysFreeString(task->url);
689     SysFreeString(task->headers);
690     if(task->post_data)
691         SafeArrayDestroy(task->post_data);
692     if(free_task)
693         heap_free(task);
694     return E_OUTOFMEMORY;
695 }
696
697 static void doc_navigate_proc(DocHost *This, task_header_t *t)
698 {
699     task_doc_navigate_t *task = (task_doc_navigate_t*)t;
700     IHTMLPrivateWindow *priv_window;
701     HRESULT hres;
702
703     if(!This->doc_navigate)
704         return;
705
706     if(task->async_notif) {
707         VARIANT_BOOL cancel = VARIANT_FALSE;
708         on_before_navigate2(This, task->url, task->post_data, task->headers, &cancel);
709         if(cancel) {
710             TRACE("Navigation calnceled\n");
711             free_doc_navigate_task(task, FALSE);
712             return;
713         }
714     }
715
716     hres = IUnknown_QueryInterface(This->doc_navigate, &IID_IHTMLPrivateWindow, (void**)&priv_window);
717     if(SUCCEEDED(hres)) {
718         html_window_navigate(This, priv_window, task->url, task->headers, task->post_data);
719         IHTMLPrivateWindow_Release(priv_window);
720     }else {
721         WARN("Could not get IHTMLPrivateWindow iface: %08x\n", hres);
722     }
723
724     free_doc_navigate_task(task, FALSE);
725 }
726
727 static HRESULT async_doc_navigate(DocHost *This, LPCWSTR url, LPCWSTR headers, PBYTE post_data, ULONG post_data_size,
728         BOOL async_notif)
729 {
730     task_doc_navigate_t *task;
731
732     task = heap_alloc_zero(sizeof(*task));
733     if(!task)
734         return E_OUTOFMEMORY;
735
736     task->url = SysAllocString(url);
737     if(!task->url)
738         return free_doc_navigate_task(task, TRUE);
739
740     if(headers) {
741         task->headers = SysAllocString(headers);
742         if(!task->headers)
743             return free_doc_navigate_task(task, TRUE);
744     }
745
746     if(post_data) {
747         task->post_data = SafeArrayCreateVector(VT_UI1, 0, post_data_size);
748         if(!task->post_data)
749             return free_doc_navigate_task(task, TRUE);
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 calnceled\n");
759             free_doc_navigate_task(task, TRUE);
760             return S_OK;
761         }
762     }
763
764     task->async_notif = async_notif;
765     push_dochost_task(This, &task->header, doc_navigate_proc, 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_proc(DocHost *This, task_header_t *t)
815 {
816     task_navigate_bsc_t *task = (task_navigate_bsc_t*)t;
817
818     if(!This->hwnd)
819         create_doc_view_hwnd(This);
820
821     navigate_bsc(This, task->bsc, NULL);
822
823     IBindStatusCallback_Release(&task->bsc->IBindStatusCallback_iface);
824 }
825
826
827 HRESULT navigate_url(DocHost *This, LPCWSTR url, const VARIANT *Flags,
828                      const VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers)
829 {
830     PBYTE post_data = NULL;
831     ULONG post_data_len = 0;
832     LPWSTR headers = NULL;
833     HRESULT hres = S_OK;
834
835     TRACE("navigating to %s\n", debugstr_w(url));
836
837     if((Flags && V_VT(Flags) != VT_EMPTY) 
838        || (TargetFrameName && V_VT(TargetFrameName) != VT_EMPTY))
839         FIXME("Unsupported args (Flags %p:%d; TargetFrameName %p:%d)\n",
840                 Flags, Flags ? V_VT(Flags) : -1, TargetFrameName,
841                 TargetFrameName ? V_VT(TargetFrameName) : -1);
842
843     if(PostData && V_VT(PostData) == (VT_ARRAY | VT_UI1) && V_ARRAY(PostData)) {
844         SafeArrayAccessData(V_ARRAY(PostData), (void**)&post_data);
845         post_data_len = V_ARRAY(PostData)->rgsabound[0].cElements;
846     }
847
848     if(Headers && V_VT(Headers) == VT_BSTR) {
849         headers = V_BSTR(Headers);
850         TRACE("Headers: %s\n", debugstr_w(headers));
851     }
852
853     set_doc_state(This, READYSTATE_LOADING);
854     This->ready_state = READYSTATE_LOADING;
855
856     if(This->doc_navigate) {
857         WCHAR new_url[INTERNET_MAX_URL_LENGTH];
858
859         if(PathIsURLW(url)) {
860             new_url[0] = 0;
861         }else {
862             DWORD size;
863
864             size = sizeof(new_url)/sizeof(WCHAR);
865             hres = UrlApplySchemeW(url, new_url, &size,
866                     URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT);
867             if(FAILED(hres)) {
868                 WARN("UrlApplyScheme failed: %08x\n", hres);
869                 new_url[0] = 0;
870             }
871         }
872
873         hres = async_doc_navigate(This, *new_url ? new_url : url, headers, post_data,
874                 post_data_len, TRUE);
875     }else {
876         task_navigate_bsc_t *task;
877
878         task = heap_alloc(sizeof(*task));
879         task->bsc = create_callback(This, url, post_data, post_data_len, headers);
880         push_dochost_task(This, &task->header, navigate_bsc_proc, This->url == NULL);
881     }
882
883     if(post_data)
884         SafeArrayUnaccessData(V_ARRAY(PostData));
885
886     return hres;
887 }
888
889 static HRESULT navigate_hlink(DocHost *This, IMoniker *mon, IBindCtx *bindctx,
890                               IBindStatusCallback *callback)
891 {
892     IHttpNegotiate *http_negotiate;
893     BindStatusCallback *bsc;
894     PBYTE post_data = NULL;
895     ULONG post_data_len = 0;
896     LPWSTR headers = NULL, url;
897     BINDINFO bindinfo;
898     DWORD bindf = 0;
899     HRESULT hres;
900
901     hres = IMoniker_GetDisplayName(mon, 0, NULL, &url);
902     if(FAILED(hres))
903         FIXME("GetDisplayName failed: %08x\n", hres);
904
905     hres = IBindStatusCallback_QueryInterface(callback, &IID_IHttpNegotiate,
906                                               (void**)&http_negotiate);
907     if(SUCCEEDED(hres)) {
908         static const WCHAR null_string[] = {0};
909
910         IHttpNegotiate_BeginningTransaction(http_negotiate, null_string, null_string, 0,
911                                             &headers);
912         IHttpNegotiate_Release(http_negotiate);
913     }
914
915     memset(&bindinfo, 0, sizeof(bindinfo));
916     bindinfo.cbSize = sizeof(bindinfo);
917
918     hres = IBindStatusCallback_GetBindInfo(callback, &bindf, &bindinfo);
919     dump_BINDINFO(&bindinfo);
920     if(bindinfo.dwBindVerb == BINDVERB_POST) {
921         post_data_len = bindinfo.cbstgmedData;
922         if(post_data_len)
923             post_data = bindinfo.stgmedData.u.hGlobal;
924     }
925
926     if(This->doc_navigate) {
927         hres = async_doc_navigate(This, url, headers, post_data, post_data_len, FALSE);
928     }else {
929         bsc = create_callback(This, url, post_data, post_data_len, headers);
930         hres = navigate_bsc(This, bsc, mon);
931         IBindStatusCallback_Release(&bsc->IBindStatusCallback_iface);
932     }
933
934     CoTaskMemFree(url);
935     CoTaskMemFree(headers);
936     ReleaseBindInfo(&bindinfo);
937
938     return hres;
939 }
940
941 HRESULT go_home(DocHost *This)
942 {
943     HKEY hkey;
944     DWORD res, type, size;
945     WCHAR wszPageName[MAX_PATH];
946     static const WCHAR wszAboutBlank[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
947     static const WCHAR wszStartPage[] = {'S','t','a','r','t',' ','P','a','g','e',0};
948     static const WCHAR wszSubKey[] = {'S','o','f','t','w','a','r','e','\\',
949                                       'M','i','c','r','o','s','o','f','t','\\',
950                                       'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\',
951                                       'M','a','i','n',0};
952
953     res = RegOpenKeyW(HKEY_CURRENT_USER, wszSubKey, &hkey);
954     if (res != ERROR_SUCCESS)
955         return navigate_url(This, wszAboutBlank, NULL, NULL, NULL, NULL);
956
957     size = sizeof(wszPageName);
958     res = RegQueryValueExW(hkey, wszStartPage, NULL, &type, (LPBYTE)wszPageName, &size);
959     RegCloseKey(hkey);
960     if (res != ERROR_SUCCESS || type != REG_SZ)
961         return navigate_url(This, wszAboutBlank, NULL, NULL, NULL, NULL);
962
963     return navigate_url(This, wszPageName, NULL, NULL, NULL, NULL);
964 }
965
966 HRESULT get_location_url(DocHost *This, BSTR *ret)
967 {
968     FIXME("semi-stub\n");
969
970     *ret = This->url ? SysAllocString(This->url) : SysAllocStringLen(NULL, 0);
971     if(!*ret)
972         return E_OUTOFMEMORY;
973
974     return This->url ? S_OK : S_FALSE;
975 }
976
977 static inline HlinkFrame *impl_from_IHlinkFrame(IHlinkFrame *iface)
978 {
979     return CONTAINING_RECORD(iface, HlinkFrame, IHlinkFrame_iface);
980 }
981
982 static HRESULT WINAPI HlinkFrame_QueryInterface(IHlinkFrame *iface, REFIID riid, void **ppv)
983 {
984     HlinkFrame *This = impl_from_IHlinkFrame(iface);
985     return IUnknown_QueryInterface(This->outer, riid, ppv);
986 }
987
988 static ULONG WINAPI HlinkFrame_AddRef(IHlinkFrame *iface)
989 {
990     HlinkFrame *This = impl_from_IHlinkFrame(iface);
991     return IUnknown_AddRef(This->outer);
992 }
993
994 static ULONG WINAPI HlinkFrame_Release(IHlinkFrame *iface)
995 {
996     HlinkFrame *This = impl_from_IHlinkFrame(iface);
997     return IUnknown_Release(This->outer);
998 }
999
1000 static HRESULT WINAPI HlinkFrame_SetBrowseContext(IHlinkFrame *iface,
1001                                                   IHlinkBrowseContext *pihlbc)
1002 {
1003     HlinkFrame *This = impl_from_IHlinkFrame(iface);
1004     FIXME("(%p)->(%p)\n", This, pihlbc);
1005     return E_NOTIMPL;
1006 }
1007
1008 static HRESULT WINAPI HlinkFrame_GetBrowseContext(IHlinkFrame *iface,
1009                                                   IHlinkBrowseContext **ppihlbc)
1010 {
1011     HlinkFrame *This = impl_from_IHlinkFrame(iface);
1012     FIXME("(%p)->(%p)\n", This, ppihlbc);
1013     return E_NOTIMPL;
1014 }
1015
1016 static HRESULT WINAPI HlinkFrame_Navigate(IHlinkFrame *iface, DWORD grfHLNF, LPBC pbc,
1017                                           IBindStatusCallback *pibsc, IHlink *pihlNavigate)
1018 {
1019     HlinkFrame *This = impl_from_IHlinkFrame(iface);
1020     IMoniker *mon;
1021     LPWSTR location = NULL;
1022
1023     TRACE("(%p)->(%08x %p %p %p)\n", This, grfHLNF, pbc, pibsc, pihlNavigate);
1024
1025     if(grfHLNF)
1026         FIXME("unsupported grfHLNF=%08x\n", grfHLNF);
1027
1028     /* Windows calls GetTargetFrameName here. */
1029
1030     IHlink_GetMonikerReference(pihlNavigate, 1, &mon, &location);
1031
1032     if(location) {
1033         FIXME("location = %s\n", debugstr_w(location));
1034         CoTaskMemFree(location);
1035     }
1036
1037     /* Windows calls GetHlinkSite here */
1038
1039     if(grfHLNF & HLNF_OPENINNEWWINDOW) {
1040         FIXME("Not supported HLNF_OPENINNEWWINDOW\n");
1041         return E_NOTIMPL;
1042     }
1043
1044     return navigate_hlink(This->doc_host, mon, pbc, pibsc);
1045 }
1046
1047 static HRESULT WINAPI HlinkFrame_OnNavigate(IHlinkFrame *iface, DWORD grfHLNF,
1048         IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName, DWORD dwreserved)
1049 {
1050     HlinkFrame *This = impl_from_IHlinkFrame(iface);
1051     FIXME("(%p)->(%08x %p %s %s %d)\n", This, grfHLNF, pimkTarget, debugstr_w(pwzLocation),
1052           debugstr_w(pwzFriendlyName), dwreserved);
1053     return E_NOTIMPL;
1054 }
1055
1056 static HRESULT WINAPI HlinkFrame_UpdateHlink(IHlinkFrame *iface, ULONG uHLID,
1057         IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName)
1058 {
1059     HlinkFrame *This = impl_from_IHlinkFrame(iface);
1060     FIXME("(%p)->(%u %p %s %s)\n", This, uHLID, pimkTarget, debugstr_w(pwzLocation),
1061           debugstr_w(pwzFriendlyName));
1062     return E_NOTIMPL;
1063 }
1064
1065 static const IHlinkFrameVtbl HlinkFrameVtbl = {
1066     HlinkFrame_QueryInterface,
1067     HlinkFrame_AddRef,
1068     HlinkFrame_Release,
1069     HlinkFrame_SetBrowseContext,
1070     HlinkFrame_GetBrowseContext,
1071     HlinkFrame_Navigate,
1072     HlinkFrame_OnNavigate,
1073     HlinkFrame_UpdateHlink
1074 };
1075
1076 static inline HlinkFrame *impl_from_ITargetFrame2(ITargetFrame2 *iface)
1077 {
1078     return CONTAINING_RECORD(iface, HlinkFrame, IHlinkFrame_iface);
1079 }
1080
1081 static HRESULT WINAPI TargetFrame2_QueryInterface(ITargetFrame2 *iface, REFIID riid, void **ppv)
1082 {
1083     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1084     return IUnknown_QueryInterface(This->outer, riid, ppv);
1085 }
1086
1087 static ULONG WINAPI TargetFrame2_AddRef(ITargetFrame2 *iface)
1088 {
1089     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1090     return IUnknown_AddRef(This->outer);
1091 }
1092
1093 static ULONG WINAPI TargetFrame2_Release(ITargetFrame2 *iface)
1094 {
1095     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1096     return IUnknown_Release(This->outer);
1097 }
1098
1099 static HRESULT WINAPI TargetFrame2_SetFrameName(ITargetFrame2 *iface, LPCWSTR pszFrameName)
1100 {
1101     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1102     FIXME("(%p)->(%s)\n", This, debugstr_w(pszFrameName));
1103     return E_NOTIMPL;
1104 }
1105
1106 static HRESULT WINAPI TargetFrame2_GetFrameName(ITargetFrame2 *iface, LPWSTR *ppszFrameName)
1107 {
1108     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1109     FIXME("(%p)->(%p)\n", This, ppszFrameName);
1110     return E_NOTIMPL;
1111 }
1112
1113 static HRESULT WINAPI TargetFrame2_GetParentFrame(ITargetFrame2 *iface, IUnknown **ppunkParent)
1114 {
1115     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1116     FIXME("(%p)->(%p)\n", This, ppunkParent);
1117     return E_NOTIMPL;
1118 }
1119
1120 static HRESULT WINAPI TargetFrame2_SetFrameSrc(ITargetFrame2 *iface, LPCWSTR pszFrameSrc)
1121 {
1122     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1123     FIXME("(%p)->(%s)\n", This, debugstr_w(pszFrameSrc));
1124     return E_NOTIMPL;
1125 }
1126
1127 static HRESULT WINAPI TargetFrame2_GetFrameSrc(ITargetFrame2 *iface, LPWSTR *ppszFrameSrc)
1128 {
1129     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1130     FIXME("(%p)->()\n", This);
1131     return E_NOTIMPL;
1132 }
1133
1134 static HRESULT WINAPI TargetFrame2_GetFramesContainer(ITargetFrame2 *iface, IOleContainer **ppContainer)
1135 {
1136     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1137     FIXME("(%p)->(%p)\n", This, ppContainer);
1138     return E_NOTIMPL;
1139 }
1140
1141 static HRESULT WINAPI TargetFrame2_SetFrameOptions(ITargetFrame2 *iface, DWORD dwFlags)
1142 {
1143     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1144     FIXME("(%p)->(%x)\n", This, dwFlags);
1145     return E_NOTIMPL;
1146 }
1147
1148 static HRESULT WINAPI TargetFrame2_GetFrameOptions(ITargetFrame2 *iface, DWORD *pdwFlags)
1149 {
1150     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1151     FIXME("(%p)->(%p)\n", This, pdwFlags);
1152     return E_NOTIMPL;
1153 }
1154
1155 static HRESULT WINAPI TargetFrame2_SetFrameMargins(ITargetFrame2 *iface, DWORD dwWidth, DWORD dwHeight)
1156 {
1157     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1158     FIXME("(%p)->(%d %d)\n", This, dwWidth, dwHeight);
1159     return E_NOTIMPL;
1160 }
1161
1162 static HRESULT WINAPI TargetFrame2_GetFrameMargins(ITargetFrame2 *iface, DWORD *pdwWidth, DWORD *pdwHeight)
1163 {
1164     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1165     FIXME("(%p)->(%p %p)\n", This, pdwWidth, pdwHeight);
1166     return E_NOTIMPL;
1167 }
1168
1169 static HRESULT WINAPI TargetFrame2_FindFrame(ITargetFrame2 *iface, LPCWSTR pszTargetName, DWORD dwFlags, IUnknown **ppunkTargetFrame)
1170 {
1171     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1172     FIXME("(%p)->(%s %x %p)\n", This, debugstr_w(pszTargetName), dwFlags, ppunkTargetFrame);
1173     return E_NOTIMPL;
1174 }
1175
1176 static HRESULT WINAPI TargetFrame2_GetTargetAlias(ITargetFrame2 *iface, LPCWSTR pszTargetName, LPWSTR *ppszTargetAlias)
1177 {
1178     HlinkFrame *This = impl_from_ITargetFrame2(iface);
1179     FIXME("(%p)->(%s %p)\n", This, debugstr_w(pszTargetName), ppszTargetAlias);
1180     return E_NOTIMPL;
1181 }
1182
1183 static const ITargetFrame2Vtbl TargetFrame2Vtbl = {
1184     TargetFrame2_QueryInterface,
1185     TargetFrame2_AddRef,
1186     TargetFrame2_Release,
1187     TargetFrame2_SetFrameName,
1188     TargetFrame2_GetFrameName,
1189     TargetFrame2_GetParentFrame,
1190     TargetFrame2_SetFrameSrc,
1191     TargetFrame2_GetFrameSrc,
1192     TargetFrame2_GetFramesContainer,
1193     TargetFrame2_SetFrameOptions,
1194     TargetFrame2_GetFrameOptions,
1195     TargetFrame2_SetFrameMargins,
1196     TargetFrame2_GetFrameMargins,
1197     TargetFrame2_FindFrame,
1198     TargetFrame2_GetTargetAlias
1199 };
1200
1201 BOOL HlinkFrame_QI(HlinkFrame *This, REFIID riid, void **ppv)
1202 {
1203     if(IsEqualGUID(&IID_IHlinkFrame, riid)) {
1204         TRACE("(%p)->(IID_IHlinkFrame %p)\n", This, ppv);
1205         *ppv = &This->IHlinkFrame_iface;
1206     }else if(IsEqualGUID(&IID_ITargetFrame2, riid)) {
1207         TRACE("(%p)->(IID_ITargetFrame2 %p)\n", This, ppv);
1208         *ppv = &This->ITargetFrame2_iface;
1209     }else {
1210         return FALSE;
1211     }
1212
1213     IUnknown_AddRef((IUnknown*)*ppv);
1214     return TRUE;
1215 }
1216
1217 void HlinkFrame_Init(HlinkFrame *This, IUnknown *outer, DocHost *doc_host)
1218 {
1219     This->IHlinkFrame_iface.lpVtbl   = &HlinkFrameVtbl;
1220     This->ITargetFrame2_iface.lpVtbl = &TargetFrame2Vtbl;
1221
1222     This->outer = outer;
1223     This->doc_host = doc_host;
1224 }