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,
429 This->nsstream->buf_size);
431 ERR("OnDataAvailable failed: %08x\n", nsres);
433 if(This->nsstream->buf_size)
434 FIXME("buffer is not empty!\n");
435 }while(hres == S_OK);
441 hres = IStream_Read(pstgmed->u.pstm, buf, sizeof(buf), &read);
442 }while(hres == S_OK && read);
448 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
449 REFIID riid, IUnknown *punk)
451 BSCallback *This = STATUSCLB_THIS(iface);
452 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), punk);
456 #undef STATUSCLB_THIS
458 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
459 BindStatusCallback_QueryInterface,
460 BindStatusCallback_AddRef,
461 BindStatusCallback_Release,
462 BindStatusCallback_OnStartBinding,
463 BindStatusCallback_GetPriority,
464 BindStatusCallback_OnLowResource,
465 BindStatusCallback_OnProgress,
466 BindStatusCallback_OnStopBinding,
467 BindStatusCallback_GetBindInfo,
468 BindStatusCallback_OnDataAvailable,
469 BindStatusCallback_OnObjectAvailable
472 #define HTTPNEG_THIS(iface) DEFINE_THIS(BSCallback, HttpNegotiate2, iface)
474 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface,
475 REFIID riid, void **ppv)
477 BSCallback *This = HTTPNEG_THIS(iface);
478 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
481 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
483 BSCallback *This = HTTPNEG_THIS(iface);
484 return IBindStatusCallback_AddRef(STATUSCLB(This));
487 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
489 BSCallback *This = HTTPNEG_THIS(iface);
490 return IBindStatusCallback_Release(STATUSCLB(This));
493 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface,
494 LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
496 BSCallback *This = HTTPNEG_THIS(iface);
499 TRACE("(%p)->(%s %s %d %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders),
500 dwReserved, pszAdditionalHeaders);
503 *pszAdditionalHeaders = NULL;
507 size = (strlenW(This->headers)+1)*sizeof(WCHAR);
508 *pszAdditionalHeaders = CoTaskMemAlloc(size);
509 memcpy(*pszAdditionalHeaders, This->headers, size);
514 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
515 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
517 BSCallback *This = HTTPNEG_THIS(iface);
518 FIXME("(%p)->(%d %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
519 debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
523 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
524 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
526 BSCallback *This = HTTPNEG_THIS(iface);
527 FIXME("(%p)->(%p %p %ld)\n", This, pbSecurityId, pcbSecurityId, dwReserved);
533 static const IHttpNegotiate2Vtbl HttpNegotiate2Vtbl = {
534 HttpNegotiate_QueryInterface,
535 HttpNegotiate_AddRef,
536 HttpNegotiate_Release,
537 HttpNegotiate_BeginningTransaction,
538 HttpNegotiate_OnResponse,
539 HttpNegotiate_GetRootSecurityId
542 #define BINDINFO_THIS(iface) DEFINE_THIS(BSCallback, InternetBindInfo, iface)
544 static HRESULT WINAPI InternetBindInfo_QueryInterface(IInternetBindInfo *iface,
545 REFIID riid, void **ppv)
547 BSCallback *This = BINDINFO_THIS(iface);
548 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
551 static ULONG WINAPI InternetBindInfo_AddRef(IInternetBindInfo *iface)
553 BSCallback *This = BINDINFO_THIS(iface);
554 return IBindStatusCallback_AddRef(STATUSCLB(This));
557 static ULONG WINAPI InternetBindInfo_Release(IInternetBindInfo *iface)
559 BSCallback *This = BINDINFO_THIS(iface);
560 return IBindStatusCallback_Release(STATUSCLB(This));
563 static HRESULT WINAPI InternetBindInfo_GetBindInfo(IInternetBindInfo *iface,
564 DWORD *grfBINDF, BINDINFO *pbindinfo)
566 BSCallback *This = BINDINFO_THIS(iface);
567 FIXME("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
571 static HRESULT WINAPI InternetBindInfo_GetBindString(IInternetBindInfo *iface,
572 ULONG ulStringType, LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
574 BSCallback *This = BINDINFO_THIS(iface);
575 FIXME("(%p)->(%u %p %u %p)\n", This, ulStringType, ppwzStr, cEl, pcElFetched);
581 static const IInternetBindInfoVtbl InternetBindInfoVtbl = {
582 InternetBindInfo_QueryInterface,
583 InternetBindInfo_AddRef,
584 InternetBindInfo_Release,
585 InternetBindInfo_GetBindInfo,
586 InternetBindInfo_GetBindString
589 #define SERVPROV_THIS(iface) DEFINE_THIS(BSCallback, ServiceProvider, iface)
591 static HRESULT WINAPI BSCServiceProvider_QueryInterface(IServiceProvider *iface,
592 REFIID riid, void **ppv)
594 BSCallback *This = SERVPROV_THIS(iface);
595 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
598 static ULONG WINAPI BSCServiceProvider_AddRef(IServiceProvider *iface)
600 BSCallback *This = SERVPROV_THIS(iface);
601 return IBindStatusCallback_AddRef(STATUSCLB(This));
604 static ULONG WINAPI BSCServiceProvider_Release(IServiceProvider *iface)
606 BSCallback *This = SERVPROV_THIS(iface);
607 return IBindStatusCallback_Release(STATUSCLB(This));
610 static HRESULT WINAPI BSCServiceProvider_QueryService(IServiceProvider *iface,
611 REFGUID guidService, REFIID riid, void **ppv)
613 BSCallback *This = SERVPROV_THIS(iface);
614 FIXME("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
620 static const IServiceProviderVtbl ServiceProviderVtbl = {
621 BSCServiceProvider_QueryInterface,
622 BSCServiceProvider_AddRef,
623 BSCServiceProvider_Release,
624 BSCServiceProvider_QueryService
627 BSCallback *create_bscallback(IMoniker *mon)
629 BSCallback *ret = mshtml_alloc(sizeof(BSCallback));
631 ret->lpBindStatusCallbackVtbl = &BindStatusCallbackVtbl;
632 ret->lpServiceProviderVtbl = &ServiceProviderVtbl;
633 ret->lpHttpNegotiate2Vtbl = &HttpNegotiate2Vtbl;
634 ret->lpInternetBindInfoVtbl = &InternetBindInfoVtbl;
636 ret->post_data = NULL;
638 ret->post_data_len = 0;
640 ret->nschannel = NULL;
641 ret->nslistener = NULL;
642 ret->nscontext = NULL;
643 ret->nsstream = NULL;
648 IMoniker_AddRef(mon);
654 static void parse_post_data(nsIInputStream *post_data_stream, LPWSTR *headers_ret,
655 HGLOBAL *post_data_ret, ULONG *post_data_len_ret)
657 PRUint32 post_data_len = 0, available = 0;
658 HGLOBAL post_data = NULL;
659 LPWSTR headers = NULL;
660 DWORD headers_len = 0, len;
661 const char *ptr, *ptr2, *post_data_end;
663 nsIInputStream_Available(post_data_stream, &available);
664 post_data = GlobalAlloc(0, available+1);
665 nsIInputStream_Read(post_data_stream, post_data, available, &post_data_len);
667 TRACE("post_data = %s\n", debugstr_an(post_data, post_data_len));
669 ptr = ptr2 = post_data;
670 post_data_end = (const char*)post_data+post_data_len;
672 while(ptr < post_data_end && (*ptr != '\r' || ptr[1] != '\n')) {
673 while(ptr < post_data_end && (*ptr != '\r' || ptr[1] != '\n'))
683 if(ptr-ptr2 >= sizeof(CONTENT_LENGTH)
684 && CompareStringA(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE,
685 CONTENT_LENGTH, sizeof(CONTENT_LENGTH)-1,
686 ptr2, sizeof(CONTENT_LENGTH)-1) == CSTR_EQUAL) {
691 len = MultiByteToWideChar(CP_ACP, 0, ptr2, ptr-ptr2, NULL, 0);
694 headers = mshtml_realloc(headers,(headers_len+len+1)*sizeof(WCHAR));
696 headers = mshtml_alloc((len+1)*sizeof(WCHAR));
698 len = MultiByteToWideChar(CP_ACP, 0, ptr2, ptr-ptr2, headers+headers_len, -1);
704 headers[headers_len] = 0;
705 *headers_ret = headers;
707 if(ptr >= post_data_end-2) {
708 GlobalFree(post_data);
715 post_data_len -= ptr-(const char*)post_data;
716 memmove(post_data, ptr, post_data_len);
717 post_data = GlobalReAlloc(post_data, post_data_len+1, 0);
720 *post_data_ret = post_data;
721 *post_data_len_ret = post_data_len;
724 void hlink_frame_navigate(HTMLDocument *doc, IHlinkFrame *hlink_frame,
725 LPCWSTR uri, nsIInputStream *post_data_stream, DWORD hlnf)
727 BSCallback *callback;
732 callback = create_bscallback(NULL);
734 if(post_data_stream) {
735 parse_post_data(post_data_stream, &callback->headers, &callback->post_data,
736 &callback->post_data_len);
737 TRACE("headers = %s post_data = %s\n", debugstr_w(callback->headers),
738 debugstr_an(callback->post_data, callback->post_data_len));
741 CreateAsyncBindCtx(0, STATUSCLB(callback), NULL, &bindctx);
743 hlink = Hlink_Create();
745 CreateURLMoniker(NULL, uri, &mon);
746 IHlink_SetMonikerReference(hlink, 0, mon, NULL);
748 if(hlnf & HLNF_OPENINNEWWINDOW) {
749 static const WCHAR wszBlank[] = {'_','b','l','a','n','k',0};
750 IHlink_SetTargetFrameName(hlink, wszBlank); /* FIXME */
753 IHlinkFrame_Navigate(hlink_frame, hlnf, bindctx, STATUSCLB(callback), hlink);
755 IBindCtx_Release(bindctx);
756 IBindStatusCallback_Release(STATUSCLB(callback));
757 IMoniker_Release(mon);
761 HRESULT start_binding(BSCallback *bscallback)
767 hres = CreateAsyncBindCtx(0, STATUSCLB(bscallback), NULL, &bctx);
769 WARN("CreateAsyncBindCtx failed: %08x\n", hres);
773 hres = IMoniker_BindToStorage(bscallback->mon, bctx, NULL, &IID_IStream, (void**)&str);
774 IBindCtx_Release(bctx);
776 WARN("BindToStorage failed: %08x\n", hres);
781 IStream_Release(str);
783 IMoniker_Release(bscallback->mon);
784 bscallback->mon = NULL;
788 void set_document_bscallback(HTMLDocument *doc, BSCallback *callback)
790 if(doc->bscallback) {
791 if(doc->bscallback->binding)
792 IBinding_Abort(doc->bscallback->binding);
793 doc->bscallback->doc = NULL;
794 IBindStatusCallback_Release(STATUSCLB(doc->bscallback));
797 doc->bscallback = callback;
800 IBindStatusCallback_AddRef(STATUSCLB(callback));