2 * Copyright 2006 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
35 #include "mshtml_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39 #define CONTENT_LENGTH "Content-Length"
40 #define UTF16_STR "utf-16"
42 #define NSINSTREAM(x) ((nsIInputStream*) &(x)->lpInputStreamVtbl)
44 #define NSINSTREAM_THIS(iface) DEFINE_THIS(nsProtocolStream, InputStream, iface)
46 static nsresult NSAPI nsInputStream_QueryInterface(nsIInputStream *iface, nsIIDRef riid,
49 nsProtocolStream *This = NSINSTREAM_THIS(iface);
53 if(IsEqualGUID(&IID_nsISupports, riid)) {
54 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
55 *result = NSINSTREAM(This);
56 }else if(IsEqualGUID(&IID_nsIInputStream, riid)) {
57 TRACE("(%p)->(IID_nsIInputStream %p)\n", This, result);
58 *result = NSINSTREAM(This);
62 nsIInputStream_AddRef(NSINSTREAM(This));
66 WARN("unsupported interface %s\n", debugstr_guid(riid));
67 return NS_NOINTERFACE;
70 static nsrefcnt NSAPI nsInputStream_AddRef(nsIInputStream *iface)
72 nsProtocolStream *This = NSINSTREAM_THIS(iface);
73 LONG ref = InterlockedIncrement(&This->ref);
75 TRACE("(%p) ref=%d\n", This, ref);
81 static nsrefcnt NSAPI nsInputStream_Release(nsIInputStream *iface)
83 nsProtocolStream *This = NSINSTREAM_THIS(iface);
84 LONG ref = InterlockedDecrement(&This->ref);
86 TRACE("(%p) ref=%d\n", This, ref);
94 static nsresult NSAPI nsInputStream_Close(nsIInputStream *iface)
96 nsProtocolStream *This = NSINSTREAM_THIS(iface);
97 FIXME("(%p)\n", This);
98 return NS_ERROR_NOT_IMPLEMENTED;
101 static nsresult NSAPI nsInputStream_Available(nsIInputStream *iface, PRUint32 *_retval)
103 nsProtocolStream *This = NSINSTREAM_THIS(iface);
104 FIXME("(%p)->(%p)\n", This, _retval);
105 return NS_ERROR_NOT_IMPLEMENTED;
108 static nsresult NSAPI nsInputStream_Read(nsIInputStream *iface, char *aBuf, PRUint32 aCount,
111 nsProtocolStream *This = NSINSTREAM_THIS(iface);
113 TRACE("(%p)->(%p %d %p)\n", This, aBuf, aCount, _retval);
115 /* Gecko always calls Read with big enough buffer */
116 if(aCount < This->buf_size)
117 FIXME("aCount < This->buf_size\n");
119 *_retval = This->buf_size;
121 memcpy(aBuf, This->buf, This->buf_size);
127 static nsresult NSAPI nsInputStream_ReadSegments(nsIInputStream *iface,
128 nsresult (WINAPI *aWriter)(nsIInputStream*,void*,const char*,PRUint32,PRUint32,PRUint32*),
129 void *aClousure, PRUint32 aCount, PRUint32 *_retval)
131 nsProtocolStream *This = NSINSTREAM_THIS(iface);
132 PRUint32 written = 0;
135 TRACE("(%p)->(%p %p %d %p)\n", This, aWriter, aClousure, aCount, _retval);
140 if(This->buf_size > aCount)
141 FIXME("buf_size > aCount\n");
143 nsres = aWriter(NSINSTREAM(This), aClousure, This->buf, 0, This->buf_size, &written);
145 TRACE("aWritter failed: %08x\n", nsres);
146 else if(written != This->buf_size)
147 FIXME("written %d != buf_size %d\n", written, This->buf_size);
149 This->buf_size -= written;
155 static nsresult NSAPI nsInputStream_IsNonBlocking(nsIInputStream *iface, PRBool *_retval)
157 nsProtocolStream *This = NSINSTREAM_THIS(iface);
158 FIXME("(%p)->(%p)\n", This, _retval);
159 return NS_ERROR_NOT_IMPLEMENTED;
162 #undef NSINSTREAM_THIS
164 static const nsIInputStreamVtbl nsInputStreamVtbl = {
165 nsInputStream_QueryInterface,
166 nsInputStream_AddRef,
167 nsInputStream_Release,
169 nsInputStream_Available,
171 nsInputStream_ReadSegments,
172 nsInputStream_IsNonBlocking
175 static nsProtocolStream *create_nsprotocol_stream(IStream *stream)
177 nsProtocolStream *ret = mshtml_alloc(sizeof(nsProtocolStream));
179 ret->lpInputStreamVtbl = &nsInputStreamVtbl;
186 #define STATUSCLB_THIS(iface) DEFINE_THIS(BSCallback, BindStatusCallback, iface)
188 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallback *iface,
189 REFIID riid, void **ppv)
191 BSCallback *This = STATUSCLB_THIS(iface);
194 if(IsEqualGUID(&IID_IUnknown, riid)) {
195 TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppv);
196 *ppv = STATUSCLB(This);
197 }else if(IsEqualGUID(&IID_IBindStatusCallback, riid)) {
198 TRACE("(%p)->(IID_IBindStatusCallback, %p)\n", This, ppv);
199 *ppv = STATUSCLB(This);
200 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
201 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
202 *ppv = SERVPROV(This);
203 }else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) {
204 TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This, ppv);
205 *ppv = HTTPNEG(This);
206 }else if(IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
207 TRACE("(%p)->(IID_IHttpNegotiate2 %p)\n", This, ppv);
208 *ppv = HTTPNEG(This);
209 }else if(IsEqualGUID(&IID_IInternetBindInfo, riid)) {
210 TRACE("(%p)->(IID_IInternetBindInfo %p)\n", This, ppv);
211 *ppv = BINDINFO(This);
215 IBindStatusCallback_AddRef(STATUSCLB(This));
219 TRACE("Unsupported riid = %s\n", debugstr_guid(riid));
220 return E_NOINTERFACE;
223 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallback *iface)
225 BSCallback *This = STATUSCLB_THIS(iface);
226 LONG ref = InterlockedIncrement(&This->ref);
228 TRACE("(%p) ref = %d\n", This, ref);
233 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallback *iface)
235 BSCallback *This = STATUSCLB_THIS(iface);
236 LONG ref = InterlockedDecrement(&This->ref);
238 TRACE("(%p) ref = %d\n", This, ref);
242 GlobalFree(This->post_data);
244 nsIChannel_Release(NSCHANNEL(This->nschannel));
246 nsIStreamListener_Release(This->nslistener);
248 nsISupports_Release(This->nscontext);
250 nsIInputStream_Release(NSINSTREAM(This->nsstream));
252 IMoniker_Release(This->mon);
254 IBinding_Release(This->binding);
255 mshtml_free(This->headers);
262 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallback *iface,
263 DWORD dwReserved, IBinding *pbind)
265 BSCallback *This = STATUSCLB_THIS(iface);
267 TRACE("(%p)->(%d %p)\n", This, dwReserved, pbind);
269 IBinding_AddRef(pbind);
270 This->binding = pbind;
272 if(This->nschannel && This->nschannel->load_group) {
273 nsresult nsres = nsILoadGroup_AddRequest(This->nschannel->load_group,
274 (nsIRequest*)NSCHANNEL(This->nschannel), This->nscontext);
277 ERR("AddRequest failed:%08x\n", nsres);
283 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface, LONG *pnPriority)
285 BSCallback *This = STATUSCLB_THIS(iface);
286 FIXME("(%p)->(%p)\n", This, pnPriority);
290 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface, DWORD reserved)
292 BSCallback *This = STATUSCLB_THIS(iface);
293 FIXME("(%p)->(%d)\n", This, reserved);
297 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
298 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
300 BSCallback *This = STATUSCLB_THIS(iface);
302 TRACE("%p)->(%u %u %u %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
303 debugstr_w(szStatusText));
305 switch(ulStatusCode) {
306 case BINDSTATUS_MIMETYPEAVAILABLE: {
311 mshtml_free(This->nschannel->content);
313 len = WideCharToMultiByte(CP_ACP, 0, szStatusText, -1, NULL, 0, NULL, NULL);
314 This->nschannel->content = mshtml_alloc(len*sizeof(WCHAR));
315 WideCharToMultiByte(CP_ACP, 0, szStatusText, -1, This->nschannel->content, -1, NULL, NULL);
322 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
323 HRESULT hresult, LPCWSTR szError)
325 BSCallback *This = STATUSCLB_THIS(iface);
327 TRACE("(%p)->(%08x %s)\n", This, hresult, debugstr_w(szError));
329 IBinding_Release(This->binding);
330 This->binding = NULL;
332 if(This->nslistener) {
333 nsIStreamListener_OnStopRequest(This->nslistener, (nsIRequest*)NSCHANNEL(This->nschannel),
334 This->nscontext, NS_OK);
336 if(This->nschannel->load_group) {
339 nsres = nsILoadGroup_RemoveRequest(This->nschannel->load_group,
340 (nsIRequest*)NSCHANNEL(This->nschannel), NULL, NS_OK);
342 ERR("RemoveRequest failed: %08x\n", nsres);
347 task_t *task = mshtml_alloc(sizeof(task_t));
349 task->doc = This->doc;
350 task->task_id = TASK_PARSECOMPLETE;
354 * This should be done in the worker thread that parses HTML,
355 * but we don't have such thread (Gecko parses HTML for us).
363 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
364 DWORD *grfBINDF, BINDINFO *pbindinfo)
366 BSCallback *This = STATUSCLB_THIS(iface);
369 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
371 *grfBINDF = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
373 size = pbindinfo->cbSize;
374 memset(pbindinfo, 0, size);
375 pbindinfo->cbSize = size;
377 pbindinfo->cbstgmedData = This->post_data_len;
378 pbindinfo->dwCodePage = CP_UTF8;
379 pbindinfo->dwOptions = 0x80000;
381 if(This->post_data) {
382 pbindinfo->dwBindVerb = BINDVERB_POST;
384 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
385 pbindinfo->stgmedData.u.hGlobal = This->post_data;
386 pbindinfo->stgmedData.pUnkForRelease = (IUnknown*)STATUSCLB(This);
387 IBindStatusCallback_AddRef(STATUSCLB(This));
393 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
394 DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
396 BSCallback *This = STATUSCLB_THIS(iface);
400 TRACE("(%p)->(%08x %d %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed);
402 if(This->nslistener) {
404 This->nsstream = create_nsprotocol_stream(pstgmed->u.pstm);
407 hres = IStream_Read(pstgmed->u.pstm, This->nsstream->buf, sizeof(This->nsstream->buf),
408 &This->nsstream->buf_size);
409 if(!This->nsstream->buf_size)
412 if(!This->readed && This->nsstream->buf_size >= 2 && *(WORD*)This->nsstream->buf == 0xfeff) {
413 This->nschannel->charset = mshtml_alloc(sizeof(UTF16_STR));
414 memcpy(This->nschannel->charset, UTF16_STR, sizeof(UTF16_STR));
418 nsres = nsIStreamListener_OnStartRequest(This->nslistener,
419 (nsIRequest*)NSCHANNEL(This->nschannel), This->nscontext);
421 FIXME("OnStartRequest failed: %08x\n", nsres);
424 This->readed += This->nsstream->buf_size;
426 nsres = nsIStreamListener_OnDataAvailable(This->nslistener,
427 (nsIRequest*)NSCHANNEL(This->nschannel), This->nscontext,
428 NSINSTREAM(This->nsstream), This->readed, This->nsstream->buf_size);
430 ERR("OnDataAvailable failed: %08x\n", nsres);
432 if(This->nsstream->buf_size)
433 FIXME("buffer is not empty!\n");
434 }while(hres == S_OK);
440 hres = IStream_Read(pstgmed->u.pstm, buf, sizeof(buf), &read);
441 }while(hres == S_OK && read);
447 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
448 REFIID riid, IUnknown *punk)
450 BSCallback *This = STATUSCLB_THIS(iface);
451 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), punk);
455 #undef STATUSCLB_THIS
457 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
458 BindStatusCallback_QueryInterface,
459 BindStatusCallback_AddRef,
460 BindStatusCallback_Release,
461 BindStatusCallback_OnStartBinding,
462 BindStatusCallback_GetPriority,
463 BindStatusCallback_OnLowResource,
464 BindStatusCallback_OnProgress,
465 BindStatusCallback_OnStopBinding,
466 BindStatusCallback_GetBindInfo,
467 BindStatusCallback_OnDataAvailable,
468 BindStatusCallback_OnObjectAvailable
471 #define HTTPNEG_THIS(iface) DEFINE_THIS(BSCallback, HttpNegotiate2, iface)
473 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface,
474 REFIID riid, void **ppv)
476 BSCallback *This = HTTPNEG_THIS(iface);
477 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
480 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
482 BSCallback *This = HTTPNEG_THIS(iface);
483 return IBindStatusCallback_AddRef(STATUSCLB(This));
486 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
488 BSCallback *This = HTTPNEG_THIS(iface);
489 return IBindStatusCallback_Release(STATUSCLB(This));
492 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface,
493 LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
495 BSCallback *This = HTTPNEG_THIS(iface);
498 TRACE("(%p)->(%s %s %d %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders),
499 dwReserved, pszAdditionalHeaders);
502 *pszAdditionalHeaders = NULL;
506 size = (strlenW(This->headers)+1)*sizeof(WCHAR);
507 *pszAdditionalHeaders = CoTaskMemAlloc(size);
508 memcpy(*pszAdditionalHeaders, This->headers, size);
513 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
514 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
516 BSCallback *This = HTTPNEG_THIS(iface);
517 FIXME("(%p)->(%d %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
518 debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
522 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
523 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
525 BSCallback *This = HTTPNEG_THIS(iface);
526 FIXME("(%p)->(%p %p %ld)\n", This, pbSecurityId, pcbSecurityId, dwReserved);
532 static const IHttpNegotiate2Vtbl HttpNegotiate2Vtbl = {
533 HttpNegotiate_QueryInterface,
534 HttpNegotiate_AddRef,
535 HttpNegotiate_Release,
536 HttpNegotiate_BeginningTransaction,
537 HttpNegotiate_OnResponse,
538 HttpNegotiate_GetRootSecurityId
541 #define BINDINFO_THIS(iface) DEFINE_THIS(BSCallback, InternetBindInfo, iface)
543 static HRESULT WINAPI InternetBindInfo_QueryInterface(IInternetBindInfo *iface,
544 REFIID riid, void **ppv)
546 BSCallback *This = BINDINFO_THIS(iface);
547 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
550 static ULONG WINAPI InternetBindInfo_AddRef(IInternetBindInfo *iface)
552 BSCallback *This = BINDINFO_THIS(iface);
553 return IBindStatusCallback_AddRef(STATUSCLB(This));
556 static ULONG WINAPI InternetBindInfo_Release(IInternetBindInfo *iface)
558 BSCallback *This = BINDINFO_THIS(iface);
559 return IBindStatusCallback_Release(STATUSCLB(This));
562 static HRESULT WINAPI InternetBindInfo_GetBindInfo(IInternetBindInfo *iface,
563 DWORD *grfBINDF, BINDINFO *pbindinfo)
565 BSCallback *This = BINDINFO_THIS(iface);
566 FIXME("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
570 static HRESULT WINAPI InternetBindInfo_GetBindString(IInternetBindInfo *iface,
571 ULONG ulStringType, LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
573 BSCallback *This = BINDINFO_THIS(iface);
574 FIXME("(%p)->(%u %p %u %p)\n", This, ulStringType, ppwzStr, cEl, pcElFetched);
580 static const IInternetBindInfoVtbl InternetBindInfoVtbl = {
581 InternetBindInfo_QueryInterface,
582 InternetBindInfo_AddRef,
583 InternetBindInfo_Release,
584 InternetBindInfo_GetBindInfo,
585 InternetBindInfo_GetBindString
588 #define SERVPROV_THIS(iface) DEFINE_THIS(BSCallback, ServiceProvider, iface)
590 static HRESULT WINAPI BSCServiceProvider_QueryInterface(IServiceProvider *iface,
591 REFIID riid, void **ppv)
593 BSCallback *This = SERVPROV_THIS(iface);
594 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
597 static ULONG WINAPI BSCServiceProvider_AddRef(IServiceProvider *iface)
599 BSCallback *This = SERVPROV_THIS(iface);
600 return IBindStatusCallback_AddRef(STATUSCLB(This));
603 static ULONG WINAPI BSCServiceProvider_Release(IServiceProvider *iface)
605 BSCallback *This = SERVPROV_THIS(iface);
606 return IBindStatusCallback_Release(STATUSCLB(This));
609 static HRESULT WINAPI BSCServiceProvider_QueryService(IServiceProvider *iface,
610 REFGUID guidService, REFIID riid, void **ppv)
612 BSCallback *This = SERVPROV_THIS(iface);
613 FIXME("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
619 static const IServiceProviderVtbl ServiceProviderVtbl = {
620 BSCServiceProvider_QueryInterface,
621 BSCServiceProvider_AddRef,
622 BSCServiceProvider_Release,
623 BSCServiceProvider_QueryService
626 BSCallback *create_bscallback(IMoniker *mon)
628 BSCallback *ret = mshtml_alloc(sizeof(BSCallback));
630 ret->lpBindStatusCallbackVtbl = &BindStatusCallbackVtbl;
631 ret->lpServiceProviderVtbl = &ServiceProviderVtbl;
632 ret->lpHttpNegotiate2Vtbl = &HttpNegotiate2Vtbl;
633 ret->lpInternetBindInfoVtbl = &InternetBindInfoVtbl;
635 ret->post_data = NULL;
637 ret->post_data_len = 0;
639 ret->nschannel = NULL;
640 ret->nslistener = NULL;
641 ret->nscontext = NULL;
642 ret->nsstream = NULL;
647 IMoniker_AddRef(mon);
653 static void parse_post_data(nsIInputStream *post_data_stream, LPWSTR *headers_ret,
654 HGLOBAL *post_data_ret, ULONG *post_data_len_ret)
656 PRUint32 post_data_len = 0, available = 0;
657 HGLOBAL post_data = NULL;
658 LPWSTR headers = NULL;
659 DWORD headers_len = 0, len;
660 const char *ptr, *ptr2, *post_data_end;
662 nsIInputStream_Available(post_data_stream, &available);
663 post_data = GlobalAlloc(0, available+1);
664 nsIInputStream_Read(post_data_stream, post_data, available, &post_data_len);
666 TRACE("post_data = %s\n", debugstr_an(post_data, post_data_len));
668 ptr = ptr2 = post_data;
669 post_data_end = (const char*)post_data+post_data_len;
671 while(ptr < post_data_end && (*ptr != '\r' || ptr[1] != '\n')) {
672 while(ptr < post_data_end && (*ptr != '\r' || ptr[1] != '\n'))
682 if(ptr-ptr2 >= sizeof(CONTENT_LENGTH)
683 && CompareStringA(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE,
684 CONTENT_LENGTH, sizeof(CONTENT_LENGTH)-1,
685 ptr2, sizeof(CONTENT_LENGTH)-1) == CSTR_EQUAL) {
690 len = MultiByteToWideChar(CP_ACP, 0, ptr2, ptr-ptr2, NULL, 0);
693 headers = mshtml_realloc(headers,(headers_len+len+1)*sizeof(WCHAR));
695 headers = mshtml_alloc((len+1)*sizeof(WCHAR));
697 len = MultiByteToWideChar(CP_ACP, 0, ptr2, ptr-ptr2, headers+headers_len, -1);
703 headers[headers_len] = 0;
704 *headers_ret = headers;
706 if(ptr >= post_data_end-2) {
707 GlobalFree(post_data);
714 post_data_len -= ptr-(const char*)post_data;
715 memmove(post_data, ptr, post_data_len);
716 post_data = GlobalReAlloc(post_data, post_data_len+1, 0);
719 *post_data_ret = post_data;
720 *post_data_len_ret = post_data_len;
723 void hlink_frame_navigate(HTMLDocument *doc, IHlinkFrame *hlink_frame,
724 LPCWSTR uri, nsIInputStream *post_data_stream, DWORD hlnf)
726 BSCallback *callback;
731 callback = create_bscallback(NULL);
733 if(post_data_stream) {
734 parse_post_data(post_data_stream, &callback->headers, &callback->post_data,
735 &callback->post_data_len);
736 TRACE("headers = %s post_data = %s\n", debugstr_w(callback->headers),
737 debugstr_an(callback->post_data, callback->post_data_len));
740 CreateAsyncBindCtx(0, STATUSCLB(callback), NULL, &bindctx);
742 hlink = Hlink_Create();
744 CreateURLMoniker(NULL, uri, &mon);
745 IHlink_SetMonikerReference(hlink, 0, mon, NULL);
747 if(hlnf & HLNF_OPENINNEWWINDOW) {
748 static const WCHAR wszBlank[] = {'_','b','l','a','n','k',0};
749 IHlink_SetTargetFrameName(hlink, wszBlank); /* FIXME */
752 IHlinkFrame_Navigate(hlink_frame, hlnf, bindctx, STATUSCLB(callback), hlink);
754 IBindCtx_Release(bindctx);
755 IBindStatusCallback_Release(STATUSCLB(callback));
756 IMoniker_Release(mon);
760 HRESULT start_binding(BSCallback *bscallback)
766 hres = CreateAsyncBindCtx(0, STATUSCLB(bscallback), NULL, &bctx);
768 WARN("CreateAsyncBindCtx failed: %08x\n", hres);
772 hres = IMoniker_BindToStorage(bscallback->mon, bctx, NULL, &IID_IStream, (void**)&str);
773 IBindCtx_Release(bctx);
775 WARN("BindToStorage failed: %08x\n", hres);
780 IStream_Release(str);
782 IMoniker_Release(bscallback->mon);
783 bscallback->mon = NULL;
787 void set_document_bscallback(HTMLDocument *doc, BSCallback *callback)
789 if(doc->bscallback) {
790 if(doc->bscallback->binding)
791 IBinding_Abort(doc->bscallback->binding);
792 doc->bscallback->doc = NULL;
793 IBindStatusCallback_Release(STATUSCLB(doc->bscallback));
796 doc->bscallback = callback;
799 IBindStatusCallback_AddRef(STATUSCLB(callback));