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
33 #include "wine/debug.h"
34 #include "wine/unicode.h"
36 #include "mshtml_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
40 #define CONTENT_LENGTH "Content-Length"
41 #define UTF16_STR "utf-16"
43 #define NSINSTREAM(x) ((nsIInputStream*) &(x)->lpInputStreamVtbl)
45 #define NSINSTREAM_THIS(iface) DEFINE_THIS(nsProtocolStream, InputStream, iface)
47 static nsresult NSAPI nsInputStream_QueryInterface(nsIInputStream *iface, nsIIDRef riid,
50 nsProtocolStream *This = NSINSTREAM_THIS(iface);
54 if(IsEqualGUID(&IID_nsISupports, riid)) {
55 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
56 *result = NSINSTREAM(This);
57 }else if(IsEqualGUID(&IID_nsIInputStream, riid)) {
58 TRACE("(%p)->(IID_nsIInputStream %p)\n", This, result);
59 *result = NSINSTREAM(This);
63 nsIInputStream_AddRef(NSINSTREAM(This));
67 WARN("unsupported interface %s\n", debugstr_guid(riid));
68 return NS_NOINTERFACE;
71 static nsrefcnt NSAPI nsInputStream_AddRef(nsIInputStream *iface)
73 nsProtocolStream *This = NSINSTREAM_THIS(iface);
74 LONG ref = InterlockedIncrement(&This->ref);
76 TRACE("(%p) ref=%d\n", This, ref);
82 static nsrefcnt NSAPI nsInputStream_Release(nsIInputStream *iface)
84 nsProtocolStream *This = NSINSTREAM_THIS(iface);
85 LONG ref = InterlockedDecrement(&This->ref);
87 TRACE("(%p) ref=%d\n", This, ref);
95 static nsresult NSAPI nsInputStream_Close(nsIInputStream *iface)
97 nsProtocolStream *This = NSINSTREAM_THIS(iface);
98 FIXME("(%p)\n", This);
99 return NS_ERROR_NOT_IMPLEMENTED;
102 static nsresult NSAPI nsInputStream_Available(nsIInputStream *iface, PRUint32 *_retval)
104 nsProtocolStream *This = NSINSTREAM_THIS(iface);
105 FIXME("(%p)->(%p)\n", This, _retval);
106 return NS_ERROR_NOT_IMPLEMENTED;
109 static nsresult NSAPI nsInputStream_Read(nsIInputStream *iface, char *aBuf, PRUint32 aCount,
112 nsProtocolStream *This = NSINSTREAM_THIS(iface);
114 TRACE("(%p)->(%p %d %p)\n", This, aBuf, aCount, _retval);
116 /* Gecko always calls Read with big enough buffer */
117 if(aCount < This->buf_size)
118 FIXME("aCount < This->buf_size\n");
120 *_retval = This->buf_size;
122 memcpy(aBuf, This->buf, This->buf_size);
128 static nsresult NSAPI nsInputStream_ReadSegments(nsIInputStream *iface,
129 nsresult (WINAPI *aWriter)(nsIInputStream*,void*,const char*,PRUint32,PRUint32,PRUint32*),
130 void *aClousure, PRUint32 aCount, PRUint32 *_retval)
132 nsProtocolStream *This = NSINSTREAM_THIS(iface);
133 PRUint32 written = 0;
136 TRACE("(%p)->(%p %p %d %p)\n", This, aWriter, aClousure, aCount, _retval);
141 if(This->buf_size > aCount)
142 FIXME("buf_size > aCount\n");
144 nsres = aWriter(NSINSTREAM(This), aClousure, This->buf, 0, This->buf_size, &written);
146 TRACE("aWritter failed: %08x\n", nsres);
147 else if(written != This->buf_size)
148 FIXME("written %d != buf_size %d\n", written, This->buf_size);
150 This->buf_size -= written;
156 static nsresult NSAPI nsInputStream_IsNonBlocking(nsIInputStream *iface, PRBool *_retval)
158 nsProtocolStream *This = NSINSTREAM_THIS(iface);
159 FIXME("(%p)->(%p)\n", This, _retval);
160 return NS_ERROR_NOT_IMPLEMENTED;
163 #undef NSINSTREAM_THIS
165 static const nsIInputStreamVtbl nsInputStreamVtbl = {
166 nsInputStream_QueryInterface,
167 nsInputStream_AddRef,
168 nsInputStream_Release,
170 nsInputStream_Available,
172 nsInputStream_ReadSegments,
173 nsInputStream_IsNonBlocking
176 static nsProtocolStream *create_nsprotocol_stream(void)
178 nsProtocolStream *ret = mshtml_alloc(sizeof(nsProtocolStream));
180 ret->lpInputStreamVtbl = &nsInputStreamVtbl;
187 static HRESULT read_stream_data(BSCallback *This, IStream *stream)
192 if(!This->nslistener) {
198 hres = IStream_Read(stream, buf, sizeof(buf), &read);
199 }while(hres == S_OK && read);
205 This->nsstream = create_nsprotocol_stream();
208 hres = IStream_Read(stream, This->nsstream->buf, sizeof(This->nsstream->buf),
209 &This->nsstream->buf_size);
210 if(!This->nsstream->buf_size)
213 if(!This->readed && This->nsstream->buf_size >= 2 && *(WORD*)This->nsstream->buf == 0xfeff) {
214 This->nschannel->charset = mshtml_alloc(sizeof(UTF16_STR));
215 memcpy(This->nschannel->charset, UTF16_STR, sizeof(UTF16_STR));
219 nsres = nsIStreamListener_OnStartRequest(This->nslistener,
220 (nsIRequest*)NSCHANNEL(This->nschannel), This->nscontext);
222 FIXME("OnStartRequest failed: %08x\n", nsres);
224 /* events are reset when a new document URI is loaded, so re-initialise them here */
225 if(This->doc && This->doc->nscontainer)
226 init_nsevents(This->doc->nscontainer);
229 This->readed += This->nsstream->buf_size;
231 nsres = nsIStreamListener_OnDataAvailable(This->nslistener,
232 (nsIRequest*)NSCHANNEL(This->nschannel), This->nscontext,
233 NSINSTREAM(This->nsstream), This->readed-This->nsstream->buf_size,
234 This->nsstream->buf_size);
236 ERR("OnDataAvailable failed: %08x\n", nsres);
238 if(This->nsstream->buf_size)
239 FIXME("buffer is not empty!\n");
240 }while(hres == S_OK);
245 static void add_nsrequest(BSCallback *This)
247 if(This->nschannel && This->nschannel->load_group) {
248 nsresult nsres = nsILoadGroup_AddRequest(This->nschannel->load_group,
249 (nsIRequest*)NSCHANNEL(This->nschannel), This->nscontext);
252 ERR("AddRequest failed:%08x\n", nsres);
256 static void on_stop_nsrequest(BSCallback *This) {
258 nsIStreamListener_OnStopRequest(This->nslistener, (nsIRequest*)NSCHANNEL(This->nschannel),
259 This->nscontext, NS_OK);
262 #define STATUSCLB_THIS(iface) DEFINE_THIS(BSCallback, BindStatusCallback, iface)
264 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallback *iface,
265 REFIID riid, void **ppv)
267 BSCallback *This = STATUSCLB_THIS(iface);
270 if(IsEqualGUID(&IID_IUnknown, riid)) {
271 TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppv);
272 *ppv = STATUSCLB(This);
273 }else if(IsEqualGUID(&IID_IBindStatusCallback, riid)) {
274 TRACE("(%p)->(IID_IBindStatusCallback, %p)\n", This, ppv);
275 *ppv = STATUSCLB(This);
276 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
277 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
278 *ppv = SERVPROV(This);
279 }else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) {
280 TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This, ppv);
281 *ppv = HTTPNEG(This);
282 }else if(IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
283 TRACE("(%p)->(IID_IHttpNegotiate2 %p)\n", This, ppv);
284 *ppv = HTTPNEG(This);
285 }else if(IsEqualGUID(&IID_IInternetBindInfo, riid)) {
286 TRACE("(%p)->(IID_IInternetBindInfo %p)\n", This, ppv);
287 *ppv = BINDINFO(This);
291 IBindStatusCallback_AddRef(STATUSCLB(This));
295 TRACE("Unsupported riid = %s\n", debugstr_guid(riid));
296 return E_NOINTERFACE;
299 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallback *iface)
301 BSCallback *This = STATUSCLB_THIS(iface);
302 LONG ref = InterlockedIncrement(&This->ref);
304 TRACE("(%p) ref = %d\n", This, ref);
309 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallback *iface)
311 BSCallback *This = STATUSCLB_THIS(iface);
312 LONG ref = InterlockedDecrement(&This->ref);
314 TRACE("(%p) ref = %d\n", This, ref);
318 GlobalFree(This->post_data);
320 nsIChannel_Release(NSCHANNEL(This->nschannel));
322 nsIStreamListener_Release(This->nslistener);
324 nsISupports_Release(This->nscontext);
326 nsIInputStream_Release(NSINSTREAM(This->nsstream));
328 IMoniker_Release(This->mon);
330 IBinding_Release(This->binding);
331 mshtml_free(This->headers);
338 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallback *iface,
339 DWORD dwReserved, IBinding *pbind)
341 BSCallback *This = STATUSCLB_THIS(iface);
343 TRACE("(%p)->(%d %p)\n", This, dwReserved, pbind);
345 IBinding_AddRef(pbind);
346 This->binding = pbind;
353 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface, LONG *pnPriority)
355 BSCallback *This = STATUSCLB_THIS(iface);
356 FIXME("(%p)->(%p)\n", This, pnPriority);
360 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface, DWORD reserved)
362 BSCallback *This = STATUSCLB_THIS(iface);
363 FIXME("(%p)->(%d)\n", This, reserved);
367 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
368 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
370 BSCallback *This = STATUSCLB_THIS(iface);
372 TRACE("%p)->(%u %u %u %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
373 debugstr_w(szStatusText));
375 switch(ulStatusCode) {
376 case BINDSTATUS_MIMETYPEAVAILABLE: {
381 mshtml_free(This->nschannel->content);
383 len = WideCharToMultiByte(CP_ACP, 0, szStatusText, -1, NULL, 0, NULL, NULL);
384 This->nschannel->content = mshtml_alloc(len*sizeof(WCHAR));
385 WideCharToMultiByte(CP_ACP, 0, szStatusText, -1, This->nschannel->content, -1, NULL, NULL);
392 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
393 HRESULT hresult, LPCWSTR szError)
395 BSCallback *This = STATUSCLB_THIS(iface);
397 TRACE("(%p)->(%08x %s)\n", This, hresult, debugstr_w(szError));
400 IBinding_Release(This->binding);
401 This->binding = NULL;
404 on_stop_nsrequest(This);
406 if(This->nslistener) {
407 if(This->nschannel->load_group) {
410 nsres = nsILoadGroup_RemoveRequest(This->nschannel->load_group,
411 (nsIRequest*)NSCHANNEL(This->nschannel), NULL, NS_OK);
413 ERR("RemoveRequest failed: %08x\n", nsres);
417 if(This->doc && !This->doc->nscontainer) {
418 task_t *task = mshtml_alloc(sizeof(task_t));
420 task->doc = This->doc;
421 task->task_id = TASK_PARSECOMPLETE;
425 * This should be done in the worker thread that parses HTML,
426 * but we don't have such thread.
434 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
435 DWORD *grfBINDF, BINDINFO *pbindinfo)
437 BSCallback *This = STATUSCLB_THIS(iface);
440 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
442 *grfBINDF = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
444 size = pbindinfo->cbSize;
445 memset(pbindinfo, 0, size);
446 pbindinfo->cbSize = size;
448 pbindinfo->cbstgmedData = This->post_data_len;
449 pbindinfo->dwCodePage = CP_UTF8;
450 pbindinfo->dwOptions = 0x80000;
452 if(This->post_data) {
453 pbindinfo->dwBindVerb = BINDVERB_POST;
455 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
456 pbindinfo->stgmedData.u.hGlobal = This->post_data;
457 pbindinfo->stgmedData.pUnkForRelease = (IUnknown*)STATUSCLB(This);
458 IBindStatusCallback_AddRef(STATUSCLB(This));
464 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
465 DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
467 BSCallback *This = STATUSCLB_THIS(iface);
469 TRACE("(%p)->(%08x %d %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed);
471 return read_stream_data(This, pstgmed->u.pstm);
474 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
475 REFIID riid, IUnknown *punk)
477 BSCallback *This = STATUSCLB_THIS(iface);
478 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), punk);
482 #undef STATUSCLB_THIS
484 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
485 BindStatusCallback_QueryInterface,
486 BindStatusCallback_AddRef,
487 BindStatusCallback_Release,
488 BindStatusCallback_OnStartBinding,
489 BindStatusCallback_GetPriority,
490 BindStatusCallback_OnLowResource,
491 BindStatusCallback_OnProgress,
492 BindStatusCallback_OnStopBinding,
493 BindStatusCallback_GetBindInfo,
494 BindStatusCallback_OnDataAvailable,
495 BindStatusCallback_OnObjectAvailable
498 #define HTTPNEG_THIS(iface) DEFINE_THIS(BSCallback, HttpNegotiate2, iface)
500 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface,
501 REFIID riid, void **ppv)
503 BSCallback *This = HTTPNEG_THIS(iface);
504 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
507 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
509 BSCallback *This = HTTPNEG_THIS(iface);
510 return IBindStatusCallback_AddRef(STATUSCLB(This));
513 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
515 BSCallback *This = HTTPNEG_THIS(iface);
516 return IBindStatusCallback_Release(STATUSCLB(This));
519 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface,
520 LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
522 BSCallback *This = HTTPNEG_THIS(iface);
525 TRACE("(%p)->(%s %s %d %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders),
526 dwReserved, pszAdditionalHeaders);
529 *pszAdditionalHeaders = NULL;
533 size = (strlenW(This->headers)+1)*sizeof(WCHAR);
534 *pszAdditionalHeaders = CoTaskMemAlloc(size);
535 memcpy(*pszAdditionalHeaders, This->headers, size);
540 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
541 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
543 BSCallback *This = HTTPNEG_THIS(iface);
544 FIXME("(%p)->(%d %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
545 debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
549 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
550 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
552 BSCallback *This = HTTPNEG_THIS(iface);
553 FIXME("(%p)->(%p %p %ld)\n", This, pbSecurityId, pcbSecurityId, dwReserved);
559 static const IHttpNegotiate2Vtbl HttpNegotiate2Vtbl = {
560 HttpNegotiate_QueryInterface,
561 HttpNegotiate_AddRef,
562 HttpNegotiate_Release,
563 HttpNegotiate_BeginningTransaction,
564 HttpNegotiate_OnResponse,
565 HttpNegotiate_GetRootSecurityId
568 #define BINDINFO_THIS(iface) DEFINE_THIS(BSCallback, InternetBindInfo, iface)
570 static HRESULT WINAPI InternetBindInfo_QueryInterface(IInternetBindInfo *iface,
571 REFIID riid, void **ppv)
573 BSCallback *This = BINDINFO_THIS(iface);
574 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
577 static ULONG WINAPI InternetBindInfo_AddRef(IInternetBindInfo *iface)
579 BSCallback *This = BINDINFO_THIS(iface);
580 return IBindStatusCallback_AddRef(STATUSCLB(This));
583 static ULONG WINAPI InternetBindInfo_Release(IInternetBindInfo *iface)
585 BSCallback *This = BINDINFO_THIS(iface);
586 return IBindStatusCallback_Release(STATUSCLB(This));
589 static HRESULT WINAPI InternetBindInfo_GetBindInfo(IInternetBindInfo *iface,
590 DWORD *grfBINDF, BINDINFO *pbindinfo)
592 BSCallback *This = BINDINFO_THIS(iface);
593 FIXME("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
597 static HRESULT WINAPI InternetBindInfo_GetBindString(IInternetBindInfo *iface,
598 ULONG ulStringType, LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
600 BSCallback *This = BINDINFO_THIS(iface);
601 FIXME("(%p)->(%u %p %u %p)\n", This, ulStringType, ppwzStr, cEl, pcElFetched);
607 static const IInternetBindInfoVtbl InternetBindInfoVtbl = {
608 InternetBindInfo_QueryInterface,
609 InternetBindInfo_AddRef,
610 InternetBindInfo_Release,
611 InternetBindInfo_GetBindInfo,
612 InternetBindInfo_GetBindString
615 #define SERVPROV_THIS(iface) DEFINE_THIS(BSCallback, ServiceProvider, iface)
617 static HRESULT WINAPI BSCServiceProvider_QueryInterface(IServiceProvider *iface,
618 REFIID riid, void **ppv)
620 BSCallback *This = SERVPROV_THIS(iface);
621 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
624 static ULONG WINAPI BSCServiceProvider_AddRef(IServiceProvider *iface)
626 BSCallback *This = SERVPROV_THIS(iface);
627 return IBindStatusCallback_AddRef(STATUSCLB(This));
630 static ULONG WINAPI BSCServiceProvider_Release(IServiceProvider *iface)
632 BSCallback *This = SERVPROV_THIS(iface);
633 return IBindStatusCallback_Release(STATUSCLB(This));
636 static HRESULT WINAPI BSCServiceProvider_QueryService(IServiceProvider *iface,
637 REFGUID guidService, REFIID riid, void **ppv)
639 BSCallback *This = SERVPROV_THIS(iface);
640 FIXME("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
646 static const IServiceProviderVtbl ServiceProviderVtbl = {
647 BSCServiceProvider_QueryInterface,
648 BSCServiceProvider_AddRef,
649 BSCServiceProvider_Release,
650 BSCServiceProvider_QueryService
653 BSCallback *create_bscallback(IMoniker *mon)
655 BSCallback *ret = mshtml_alloc(sizeof(BSCallback));
657 ret->lpBindStatusCallbackVtbl = &BindStatusCallbackVtbl;
658 ret->lpServiceProviderVtbl = &ServiceProviderVtbl;
659 ret->lpHttpNegotiate2Vtbl = &HttpNegotiate2Vtbl;
660 ret->lpInternetBindInfoVtbl = &InternetBindInfoVtbl;
662 ret->post_data = NULL;
664 ret->post_data_len = 0;
666 ret->nschannel = NULL;
667 ret->nslistener = NULL;
668 ret->nscontext = NULL;
669 ret->nsstream = NULL;
674 IMoniker_AddRef(mon);
680 static void parse_post_data(nsIInputStream *post_data_stream, LPWSTR *headers_ret,
681 HGLOBAL *post_data_ret, ULONG *post_data_len_ret)
683 PRUint32 post_data_len = 0, available = 0;
684 HGLOBAL post_data = NULL;
685 LPWSTR headers = NULL;
686 DWORD headers_len = 0, len;
687 const char *ptr, *ptr2, *post_data_end;
689 nsIInputStream_Available(post_data_stream, &available);
690 post_data = GlobalAlloc(0, available+1);
691 nsIInputStream_Read(post_data_stream, post_data, available, &post_data_len);
693 TRACE("post_data = %s\n", debugstr_an(post_data, post_data_len));
695 ptr = ptr2 = post_data;
696 post_data_end = (const char*)post_data+post_data_len;
698 while(ptr < post_data_end && (*ptr != '\r' || ptr[1] != '\n')) {
699 while(ptr < post_data_end && (*ptr != '\r' || ptr[1] != '\n'))
709 if(ptr-ptr2 >= sizeof(CONTENT_LENGTH)
710 && CompareStringA(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE,
711 CONTENT_LENGTH, sizeof(CONTENT_LENGTH)-1,
712 ptr2, sizeof(CONTENT_LENGTH)-1) == CSTR_EQUAL) {
717 len = MultiByteToWideChar(CP_ACP, 0, ptr2, ptr-ptr2, NULL, 0);
720 headers = mshtml_realloc(headers,(headers_len+len+1)*sizeof(WCHAR));
722 headers = mshtml_alloc((len+1)*sizeof(WCHAR));
724 len = MultiByteToWideChar(CP_ACP, 0, ptr2, ptr-ptr2, headers+headers_len, -1);
730 headers[headers_len] = 0;
731 *headers_ret = headers;
733 if(ptr >= post_data_end-2) {
734 GlobalFree(post_data);
741 post_data_len -= ptr-(const char*)post_data;
742 memmove(post_data, ptr, post_data_len);
743 post_data = GlobalReAlloc(post_data, post_data_len+1, 0);
746 *post_data_ret = post_data;
747 *post_data_len_ret = post_data_len;
750 void hlink_frame_navigate(HTMLDocument *doc, IHlinkFrame *hlink_frame,
751 LPCWSTR uri, nsIInputStream *post_data_stream, DWORD hlnf)
753 BSCallback *callback;
759 callback = create_bscallback(NULL);
761 if(post_data_stream) {
762 parse_post_data(post_data_stream, &callback->headers, &callback->post_data,
763 &callback->post_data_len);
764 TRACE("headers = %s post_data = %s\n", debugstr_w(callback->headers),
765 debugstr_an(callback->post_data, callback->post_data_len));
768 hr = CreateAsyncBindCtx(0, STATUSCLB(callback), NULL, &bindctx);
770 IBindStatusCallback_Release(STATUSCLB(callback));
774 hr = CoCreateInstance(&CLSID_StdHlink, NULL, CLSCTX_INPROC_SERVER, &IID_IHlink, (LPVOID*)&hlink);
776 IBindCtx_Release(bindctx);
777 IBindStatusCallback_Release(STATUSCLB(callback));
781 hr = CreateURLMoniker(NULL, uri, &mon);
783 IHlink_SetMonikerReference(hlink, 0, mon, NULL);
785 if(hlnf & HLNF_OPENINNEWWINDOW) {
786 static const WCHAR wszBlank[] = {'_','b','l','a','n','k',0};
787 IHlink_SetTargetFrameName(hlink, wszBlank); /* FIXME */
790 IHlinkFrame_Navigate(hlink_frame, hlnf, bindctx, STATUSCLB(callback), hlink);
792 IMoniker_Release(mon);
795 IBindCtx_Release(bindctx);
796 IBindStatusCallback_Release(STATUSCLB(callback));
799 HRESULT start_binding(BSCallback *bscallback)
805 hres = CreateAsyncBindCtx(0, STATUSCLB(bscallback), NULL, &bctx);
807 WARN("CreateAsyncBindCtx failed: %08x\n", hres);
808 on_stop_nsrequest(bscallback);
812 hres = IMoniker_BindToStorage(bscallback->mon, bctx, NULL, &IID_IStream, (void**)&str);
813 IBindCtx_Release(bctx);
815 WARN("BindToStorage failed: %08x\n", hres);
816 on_stop_nsrequest(bscallback);
821 IStream_Release(str);
823 IMoniker_Release(bscallback->mon);
824 bscallback->mon = NULL;
829 void set_document_bscallback(HTMLDocument *doc, BSCallback *callback)
831 if(doc->bscallback) {
832 if(doc->bscallback->binding)
833 IBinding_Abort(doc->bscallback->binding);
834 doc->bscallback->doc = NULL;
835 IBindStatusCallback_Release(STATUSCLB(doc->bscallback));
838 doc->bscallback = callback;
841 IBindStatusCallback_AddRef(STATUSCLB(callback));
846 HRESULT load_stream(BSCallback *bscallback, IStream *stream)
850 const char text_html[] = "text/html";
852 add_nsrequest(bscallback);
854 if(bscallback->nschannel) {
855 bscallback->nschannel->content = mshtml_alloc(sizeof(text_html));
856 memcpy(bscallback->nschannel->content, text_html, sizeof(text_html));
859 hres = read_stream_data(bscallback, stream);
860 IBindStatusCallback_OnStopBinding(STATUSCLB(bscallback), hres, ERROR_SUCCESS);