2 * Copyright 2006-2007 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(void)
177 nsProtocolStream *ret = mshtml_alloc(sizeof(nsProtocolStream));
179 ret->lpInputStreamVtbl = &nsInputStreamVtbl;
186 static HRESULT read_stream_data(BSCallback *This, IStream *stream)
191 if(!This->nslistener) {
197 hres = IStream_Read(stream, buf, sizeof(buf), &read);
198 }while(hres == S_OK && read);
204 This->nsstream = create_nsprotocol_stream();
207 hres = IStream_Read(stream, This->nsstream->buf, sizeof(This->nsstream->buf),
208 &This->nsstream->buf_size);
209 if(!This->nsstream->buf_size)
212 if(!This->readed && This->nsstream->buf_size >= 2 && *(WORD*)This->nsstream->buf == 0xfeff) {
213 This->nschannel->charset = mshtml_alloc(sizeof(UTF16_STR));
214 memcpy(This->nschannel->charset, UTF16_STR, sizeof(UTF16_STR));
218 nsres = nsIStreamListener_OnStartRequest(This->nslistener,
219 (nsIRequest*)NSCHANNEL(This->nschannel), This->nscontext);
221 FIXME("OnStartRequest failed: %08x\n", nsres);
224 This->readed += This->nsstream->buf_size;
226 nsres = nsIStreamListener_OnDataAvailable(This->nslistener,
227 (nsIRequest*)NSCHANNEL(This->nschannel), This->nscontext,
228 NSINSTREAM(This->nsstream), This->readed-This->nsstream->buf_size,
229 This->nsstream->buf_size);
231 ERR("OnDataAvailable failed: %08x\n", nsres);
233 if(This->nsstream->buf_size)
234 FIXME("buffer is not empty!\n");
235 }while(hres == S_OK);
240 static void add_nsrequest(BSCallback *This)
242 if(This->nschannel && This->nschannel->load_group) {
243 nsresult nsres = nsILoadGroup_AddRequest(This->nschannel->load_group,
244 (nsIRequest*)NSCHANNEL(This->nschannel), This->nscontext);
247 ERR("AddRequest failed:%08x\n", nsres);
251 #define STATUSCLB_THIS(iface) DEFINE_THIS(BSCallback, BindStatusCallback, iface)
253 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallback *iface,
254 REFIID riid, void **ppv)
256 BSCallback *This = STATUSCLB_THIS(iface);
259 if(IsEqualGUID(&IID_IUnknown, riid)) {
260 TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppv);
261 *ppv = STATUSCLB(This);
262 }else if(IsEqualGUID(&IID_IBindStatusCallback, riid)) {
263 TRACE("(%p)->(IID_IBindStatusCallback, %p)\n", This, ppv);
264 *ppv = STATUSCLB(This);
265 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
266 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
267 *ppv = SERVPROV(This);
268 }else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) {
269 TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This, ppv);
270 *ppv = HTTPNEG(This);
271 }else if(IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
272 TRACE("(%p)->(IID_IHttpNegotiate2 %p)\n", This, ppv);
273 *ppv = HTTPNEG(This);
274 }else if(IsEqualGUID(&IID_IInternetBindInfo, riid)) {
275 TRACE("(%p)->(IID_IInternetBindInfo %p)\n", This, ppv);
276 *ppv = BINDINFO(This);
280 IBindStatusCallback_AddRef(STATUSCLB(This));
284 TRACE("Unsupported riid = %s\n", debugstr_guid(riid));
285 return E_NOINTERFACE;
288 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallback *iface)
290 BSCallback *This = STATUSCLB_THIS(iface);
291 LONG ref = InterlockedIncrement(&This->ref);
293 TRACE("(%p) ref = %d\n", This, ref);
298 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallback *iface)
300 BSCallback *This = STATUSCLB_THIS(iface);
301 LONG ref = InterlockedDecrement(&This->ref);
303 TRACE("(%p) ref = %d\n", This, ref);
307 GlobalFree(This->post_data);
309 nsIChannel_Release(NSCHANNEL(This->nschannel));
311 nsIStreamListener_Release(This->nslistener);
313 nsISupports_Release(This->nscontext);
315 nsIInputStream_Release(NSINSTREAM(This->nsstream));
317 IMoniker_Release(This->mon);
319 IBinding_Release(This->binding);
320 mshtml_free(This->headers);
327 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallback *iface,
328 DWORD dwReserved, IBinding *pbind)
330 BSCallback *This = STATUSCLB_THIS(iface);
332 TRACE("(%p)->(%d %p)\n", This, dwReserved, pbind);
334 IBinding_AddRef(pbind);
335 This->binding = pbind;
342 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface, LONG *pnPriority)
344 BSCallback *This = STATUSCLB_THIS(iface);
345 FIXME("(%p)->(%p)\n", This, pnPriority);
349 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface, DWORD reserved)
351 BSCallback *This = STATUSCLB_THIS(iface);
352 FIXME("(%p)->(%d)\n", This, reserved);
356 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
357 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
359 BSCallback *This = STATUSCLB_THIS(iface);
361 TRACE("%p)->(%u %u %u %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
362 debugstr_w(szStatusText));
364 switch(ulStatusCode) {
365 case BINDSTATUS_MIMETYPEAVAILABLE: {
370 mshtml_free(This->nschannel->content);
372 len = WideCharToMultiByte(CP_ACP, 0, szStatusText, -1, NULL, 0, NULL, NULL);
373 This->nschannel->content = mshtml_alloc(len*sizeof(WCHAR));
374 WideCharToMultiByte(CP_ACP, 0, szStatusText, -1, This->nschannel->content, -1, NULL, NULL);
381 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
382 HRESULT hresult, LPCWSTR szError)
384 BSCallback *This = STATUSCLB_THIS(iface);
386 TRACE("(%p)->(%08x %s)\n", This, hresult, debugstr_w(szError));
389 IBinding_Release(This->binding);
390 This->binding = NULL;
393 if(This->nslistener) {
394 nsIStreamListener_OnStopRequest(This->nslistener, (nsIRequest*)NSCHANNEL(This->nschannel),
395 This->nscontext, NS_OK);
397 if(This->nschannel->load_group) {
400 nsres = nsILoadGroup_RemoveRequest(This->nschannel->load_group,
401 (nsIRequest*)NSCHANNEL(This->nschannel), NULL, NS_OK);
403 ERR("RemoveRequest failed: %08x\n", nsres);
408 task_t *task = mshtml_alloc(sizeof(task_t));
410 task->doc = This->doc;
411 task->task_id = TASK_PARSECOMPLETE;
415 * This should be done in the worker thread that parses HTML,
416 * but we don't have such thread (Gecko parses HTML for us).
424 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
425 DWORD *grfBINDF, BINDINFO *pbindinfo)
427 BSCallback *This = STATUSCLB_THIS(iface);
430 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
432 *grfBINDF = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
434 size = pbindinfo->cbSize;
435 memset(pbindinfo, 0, size);
436 pbindinfo->cbSize = size;
438 pbindinfo->cbstgmedData = This->post_data_len;
439 pbindinfo->dwCodePage = CP_UTF8;
440 pbindinfo->dwOptions = 0x80000;
442 if(This->post_data) {
443 pbindinfo->dwBindVerb = BINDVERB_POST;
445 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
446 pbindinfo->stgmedData.u.hGlobal = This->post_data;
447 pbindinfo->stgmedData.pUnkForRelease = (IUnknown*)STATUSCLB(This);
448 IBindStatusCallback_AddRef(STATUSCLB(This));
454 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
455 DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
457 BSCallback *This = STATUSCLB_THIS(iface);
459 TRACE("(%p)->(%08x %d %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed);
461 return read_stream_data(This, pstgmed->u.pstm);
464 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
465 REFIID riid, IUnknown *punk)
467 BSCallback *This = STATUSCLB_THIS(iface);
468 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), punk);
472 #undef STATUSCLB_THIS
474 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
475 BindStatusCallback_QueryInterface,
476 BindStatusCallback_AddRef,
477 BindStatusCallback_Release,
478 BindStatusCallback_OnStartBinding,
479 BindStatusCallback_GetPriority,
480 BindStatusCallback_OnLowResource,
481 BindStatusCallback_OnProgress,
482 BindStatusCallback_OnStopBinding,
483 BindStatusCallback_GetBindInfo,
484 BindStatusCallback_OnDataAvailable,
485 BindStatusCallback_OnObjectAvailable
488 #define HTTPNEG_THIS(iface) DEFINE_THIS(BSCallback, HttpNegotiate2, iface)
490 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface,
491 REFIID riid, void **ppv)
493 BSCallback *This = HTTPNEG_THIS(iface);
494 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
497 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
499 BSCallback *This = HTTPNEG_THIS(iface);
500 return IBindStatusCallback_AddRef(STATUSCLB(This));
503 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
505 BSCallback *This = HTTPNEG_THIS(iface);
506 return IBindStatusCallback_Release(STATUSCLB(This));
509 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface,
510 LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
512 BSCallback *This = HTTPNEG_THIS(iface);
515 TRACE("(%p)->(%s %s %d %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders),
516 dwReserved, pszAdditionalHeaders);
519 *pszAdditionalHeaders = NULL;
523 size = (strlenW(This->headers)+1)*sizeof(WCHAR);
524 *pszAdditionalHeaders = CoTaskMemAlloc(size);
525 memcpy(*pszAdditionalHeaders, This->headers, size);
530 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
531 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
533 BSCallback *This = HTTPNEG_THIS(iface);
534 FIXME("(%p)->(%d %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
535 debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
539 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
540 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
542 BSCallback *This = HTTPNEG_THIS(iface);
543 FIXME("(%p)->(%p %p %ld)\n", This, pbSecurityId, pcbSecurityId, dwReserved);
549 static const IHttpNegotiate2Vtbl HttpNegotiate2Vtbl = {
550 HttpNegotiate_QueryInterface,
551 HttpNegotiate_AddRef,
552 HttpNegotiate_Release,
553 HttpNegotiate_BeginningTransaction,
554 HttpNegotiate_OnResponse,
555 HttpNegotiate_GetRootSecurityId
558 #define BINDINFO_THIS(iface) DEFINE_THIS(BSCallback, InternetBindInfo, iface)
560 static HRESULT WINAPI InternetBindInfo_QueryInterface(IInternetBindInfo *iface,
561 REFIID riid, void **ppv)
563 BSCallback *This = BINDINFO_THIS(iface);
564 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
567 static ULONG WINAPI InternetBindInfo_AddRef(IInternetBindInfo *iface)
569 BSCallback *This = BINDINFO_THIS(iface);
570 return IBindStatusCallback_AddRef(STATUSCLB(This));
573 static ULONG WINAPI InternetBindInfo_Release(IInternetBindInfo *iface)
575 BSCallback *This = BINDINFO_THIS(iface);
576 return IBindStatusCallback_Release(STATUSCLB(This));
579 static HRESULT WINAPI InternetBindInfo_GetBindInfo(IInternetBindInfo *iface,
580 DWORD *grfBINDF, BINDINFO *pbindinfo)
582 BSCallback *This = BINDINFO_THIS(iface);
583 FIXME("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
587 static HRESULT WINAPI InternetBindInfo_GetBindString(IInternetBindInfo *iface,
588 ULONG ulStringType, LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
590 BSCallback *This = BINDINFO_THIS(iface);
591 FIXME("(%p)->(%u %p %u %p)\n", This, ulStringType, ppwzStr, cEl, pcElFetched);
597 static const IInternetBindInfoVtbl InternetBindInfoVtbl = {
598 InternetBindInfo_QueryInterface,
599 InternetBindInfo_AddRef,
600 InternetBindInfo_Release,
601 InternetBindInfo_GetBindInfo,
602 InternetBindInfo_GetBindString
605 #define SERVPROV_THIS(iface) DEFINE_THIS(BSCallback, ServiceProvider, iface)
607 static HRESULT WINAPI BSCServiceProvider_QueryInterface(IServiceProvider *iface,
608 REFIID riid, void **ppv)
610 BSCallback *This = SERVPROV_THIS(iface);
611 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
614 static ULONG WINAPI BSCServiceProvider_AddRef(IServiceProvider *iface)
616 BSCallback *This = SERVPROV_THIS(iface);
617 return IBindStatusCallback_AddRef(STATUSCLB(This));
620 static ULONG WINAPI BSCServiceProvider_Release(IServiceProvider *iface)
622 BSCallback *This = SERVPROV_THIS(iface);
623 return IBindStatusCallback_Release(STATUSCLB(This));
626 static HRESULT WINAPI BSCServiceProvider_QueryService(IServiceProvider *iface,
627 REFGUID guidService, REFIID riid, void **ppv)
629 BSCallback *This = SERVPROV_THIS(iface);
630 FIXME("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
636 static const IServiceProviderVtbl ServiceProviderVtbl = {
637 BSCServiceProvider_QueryInterface,
638 BSCServiceProvider_AddRef,
639 BSCServiceProvider_Release,
640 BSCServiceProvider_QueryService
643 BSCallback *create_bscallback(IMoniker *mon)
645 BSCallback *ret = mshtml_alloc(sizeof(BSCallback));
647 ret->lpBindStatusCallbackVtbl = &BindStatusCallbackVtbl;
648 ret->lpServiceProviderVtbl = &ServiceProviderVtbl;
649 ret->lpHttpNegotiate2Vtbl = &HttpNegotiate2Vtbl;
650 ret->lpInternetBindInfoVtbl = &InternetBindInfoVtbl;
652 ret->post_data = NULL;
654 ret->post_data_len = 0;
656 ret->nschannel = NULL;
657 ret->nslistener = NULL;
658 ret->nscontext = NULL;
659 ret->nsstream = NULL;
664 IMoniker_AddRef(mon);
670 static void parse_post_data(nsIInputStream *post_data_stream, LPWSTR *headers_ret,
671 HGLOBAL *post_data_ret, ULONG *post_data_len_ret)
673 PRUint32 post_data_len = 0, available = 0;
674 HGLOBAL post_data = NULL;
675 LPWSTR headers = NULL;
676 DWORD headers_len = 0, len;
677 const char *ptr, *ptr2, *post_data_end;
679 nsIInputStream_Available(post_data_stream, &available);
680 post_data = GlobalAlloc(0, available+1);
681 nsIInputStream_Read(post_data_stream, post_data, available, &post_data_len);
683 TRACE("post_data = %s\n", debugstr_an(post_data, post_data_len));
685 ptr = ptr2 = post_data;
686 post_data_end = (const char*)post_data+post_data_len;
688 while(ptr < post_data_end && (*ptr != '\r' || ptr[1] != '\n')) {
689 while(ptr < post_data_end && (*ptr != '\r' || ptr[1] != '\n'))
699 if(ptr-ptr2 >= sizeof(CONTENT_LENGTH)
700 && CompareStringA(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE,
701 CONTENT_LENGTH, sizeof(CONTENT_LENGTH)-1,
702 ptr2, sizeof(CONTENT_LENGTH)-1) == CSTR_EQUAL) {
707 len = MultiByteToWideChar(CP_ACP, 0, ptr2, ptr-ptr2, NULL, 0);
710 headers = mshtml_realloc(headers,(headers_len+len+1)*sizeof(WCHAR));
712 headers = mshtml_alloc((len+1)*sizeof(WCHAR));
714 len = MultiByteToWideChar(CP_ACP, 0, ptr2, ptr-ptr2, headers+headers_len, -1);
720 headers[headers_len] = 0;
721 *headers_ret = headers;
723 if(ptr >= post_data_end-2) {
724 GlobalFree(post_data);
731 post_data_len -= ptr-(const char*)post_data;
732 memmove(post_data, ptr, post_data_len);
733 post_data = GlobalReAlloc(post_data, post_data_len+1, 0);
736 *post_data_ret = post_data;
737 *post_data_len_ret = post_data_len;
740 void hlink_frame_navigate(HTMLDocument *doc, IHlinkFrame *hlink_frame,
741 LPCWSTR uri, nsIInputStream *post_data_stream, DWORD hlnf)
743 BSCallback *callback;
748 callback = create_bscallback(NULL);
750 if(post_data_stream) {
751 parse_post_data(post_data_stream, &callback->headers, &callback->post_data,
752 &callback->post_data_len);
753 TRACE("headers = %s post_data = %s\n", debugstr_w(callback->headers),
754 debugstr_an(callback->post_data, callback->post_data_len));
757 CreateAsyncBindCtx(0, STATUSCLB(callback), NULL, &bindctx);
759 hlink = Hlink_Create();
761 CreateURLMoniker(NULL, uri, &mon);
762 IHlink_SetMonikerReference(hlink, 0, mon, NULL);
764 if(hlnf & HLNF_OPENINNEWWINDOW) {
765 static const WCHAR wszBlank[] = {'_','b','l','a','n','k',0};
766 IHlink_SetTargetFrameName(hlink, wszBlank); /* FIXME */
769 IHlinkFrame_Navigate(hlink_frame, hlnf, bindctx, STATUSCLB(callback), hlink);
771 IBindCtx_Release(bindctx);
772 IBindStatusCallback_Release(STATUSCLB(callback));
773 IMoniker_Release(mon);
777 HRESULT start_binding(BSCallback *bscallback)
783 hres = CreateAsyncBindCtx(0, STATUSCLB(bscallback), NULL, &bctx);
785 WARN("CreateAsyncBindCtx failed: %08x\n", hres);
789 hres = IMoniker_BindToStorage(bscallback->mon, bctx, NULL, &IID_IStream, (void**)&str);
790 IBindCtx_Release(bctx);
792 WARN("BindToStorage failed: %08x\n", hres);
797 IStream_Release(str);
799 IMoniker_Release(bscallback->mon);
800 bscallback->mon = NULL;
804 void set_document_bscallback(HTMLDocument *doc, BSCallback *callback)
806 if(doc->bscallback) {
807 if(doc->bscallback->binding)
808 IBinding_Abort(doc->bscallback->binding);
809 doc->bscallback->doc = NULL;
810 IBindStatusCallback_Release(STATUSCLB(doc->bscallback));
813 doc->bscallback = callback;
816 IBindStatusCallback_AddRef(STATUSCLB(callback));
821 HRESULT load_stream(BSCallback *bscallback, IStream *stream)
825 const char text_html[] = "text/html";
827 add_nsrequest(bscallback);
829 bscallback->nschannel->content = mshtml_alloc(sizeof(text_html));
830 memcpy(bscallback->nschannel->content, text_html, sizeof(text_html));
832 hres = read_stream_data(bscallback, stream);
833 IBindStatusCallback_OnStopBinding(STATUSCLB(bscallback), hres, ERROR_SUCCESS);