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