2 * Copyright 2006-2010 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
23 #define NONAMELESSUNION
35 #include "shdeprecated.h"
37 #include "wine/debug.h"
39 #include "mshtml_private.h"
40 #include "htmlscript.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
45 #define CONTENT_LENGTH "Content-Length"
46 #define UTF8_STR "utf-8"
47 #define UTF16_STR "utf-16"
49 struct nsProtocolStream
{
50 nsIInputStream nsIInputStream_iface
;
58 static inline nsProtocolStream
*impl_from_nsIInputStream(nsIInputStream
*iface
)
60 return CONTAINING_RECORD(iface
, nsProtocolStream
, nsIInputStream_iface
);
63 static nsresult NSAPI
nsInputStream_QueryInterface(nsIInputStream
*iface
, nsIIDRef riid
,
66 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
70 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
71 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
72 *result
= &This
->nsIInputStream_iface
;
73 }else if(IsEqualGUID(&IID_nsIInputStream
, riid
)) {
74 TRACE("(%p)->(IID_nsIInputStream %p)\n", This
, result
);
75 *result
= &This
->nsIInputStream_iface
;
79 nsIInputStream_AddRef(&This
->nsIInputStream_iface
);
83 WARN("unsupported interface %s\n", debugstr_guid(riid
));
84 return NS_NOINTERFACE
;
87 static nsrefcnt NSAPI
nsInputStream_AddRef(nsIInputStream
*iface
)
89 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
90 LONG ref
= InterlockedIncrement(&This
->ref
);
92 TRACE("(%p) ref=%d\n", This
, ref
);
98 static nsrefcnt NSAPI
nsInputStream_Release(nsIInputStream
*iface
)
100 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
101 LONG ref
= InterlockedDecrement(&This
->ref
);
103 TRACE("(%p) ref=%d\n", This
, ref
);
111 static nsresult NSAPI
nsInputStream_Close(nsIInputStream
*iface
)
113 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
114 FIXME("(%p)\n", This
);
115 return NS_ERROR_NOT_IMPLEMENTED
;
118 static nsresult NSAPI
nsInputStream_Available(nsIInputStream
*iface
, UINT64
*_retval
)
120 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
121 FIXME("(%p)->(%p)\n", This
, _retval
);
122 return NS_ERROR_NOT_IMPLEMENTED
;
125 static nsresult NSAPI
nsInputStream_Read(nsIInputStream
*iface
, char *aBuf
, UINT32 aCount
,
128 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
131 TRACE("(%p)->(%p %d %p)\n", This
, aBuf
, aCount
, _retval
);
133 if(read
> This
->buf_size
)
134 read
= This
->buf_size
;
137 memcpy(aBuf
, This
->buf
, read
);
138 if(read
< This
->buf_size
)
139 memmove(This
->buf
, This
->buf
+read
, This
->buf_size
-read
);
140 This
->buf_size
-= read
;
147 static nsresult NSAPI
nsInputStream_ReadSegments(nsIInputStream
*iface
,
148 nsresult (WINAPI
*aWriter
)(nsIInputStream
*,void*,const char*,UINT32
,UINT32
,UINT32
*),
149 void *aClousure
, UINT32 aCount
, UINT32
*_retval
)
151 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
155 TRACE("(%p)->(%p %p %d %p)\n", This
, aWriter
, aClousure
, aCount
, _retval
);
160 if(aCount
> This
->buf_size
)
161 aCount
= This
->buf_size
;
163 nsres
= aWriter(&This
->nsIInputStream_iface
, aClousure
, This
->buf
, 0, aCount
, &written
);
165 TRACE("aWriter failed: %08x\n", nsres
);
166 else if(written
!= This
->buf_size
)
167 FIXME("written %d != buf_size %d\n", written
, This
->buf_size
);
169 This
->buf_size
-= written
;
175 static nsresult NSAPI
nsInputStream_IsNonBlocking(nsIInputStream
*iface
, cpp_bool
*_retval
)
177 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
178 FIXME("(%p)->(%p)\n", This
, _retval
);
179 return NS_ERROR_NOT_IMPLEMENTED
;
182 static const nsIInputStreamVtbl nsInputStreamVtbl
= {
183 nsInputStream_QueryInterface
,
184 nsInputStream_AddRef
,
185 nsInputStream_Release
,
187 nsInputStream_Available
,
189 nsInputStream_ReadSegments
,
190 nsInputStream_IsNonBlocking
193 static nsProtocolStream
*create_nsprotocol_stream(void)
195 nsProtocolStream
*ret
;
197 ret
= heap_alloc(sizeof(nsProtocolStream
));
201 ret
->nsIInputStream_iface
.lpVtbl
= &nsInputStreamVtbl
;
208 static void release_request_data(request_data_t
*request_data
)
210 if(request_data
->post_stream
)
211 nsIInputStream_Release(request_data
->post_stream
);
212 heap_free(request_data
->headers
);
213 if(request_data
->post_data
)
214 GlobalFree(request_data
->post_data
);
217 static inline BSCallback
*impl_from_IBindStatusCallback(IBindStatusCallback
*iface
)
219 return CONTAINING_RECORD(iface
, BSCallback
, IBindStatusCallback_iface
);
222 static HRESULT WINAPI
BindStatusCallback_QueryInterface(IBindStatusCallback
*iface
,
223 REFIID riid
, void **ppv
)
225 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
228 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
229 TRACE("(%p)->(IID_IUnknown, %p)\n", This
, ppv
);
230 *ppv
= &This
->IBindStatusCallback_iface
;
231 }else if(IsEqualGUID(&IID_IBindStatusCallback
, riid
)) {
232 TRACE("(%p)->(IID_IBindStatusCallback, %p)\n", This
, ppv
);
233 *ppv
= &This
->IBindStatusCallback_iface
;
234 }else if(IsEqualGUID(&IID_IServiceProvider
, riid
)) {
235 TRACE("(%p)->(IID_IServiceProvider %p)\n", This
, ppv
);
236 *ppv
= &This
->IServiceProvider_iface
;
237 }else if(IsEqualGUID(&IID_IHttpNegotiate
, riid
)) {
238 TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This
, ppv
);
239 *ppv
= &This
->IHttpNegotiate2_iface
;
240 }else if(IsEqualGUID(&IID_IHttpNegotiate2
, riid
)) {
241 TRACE("(%p)->(IID_IHttpNegotiate2 %p)\n", This
, ppv
);
242 *ppv
= &This
->IHttpNegotiate2_iface
;
243 }else if(IsEqualGUID(&IID_IInternetBindInfo
, riid
)) {
244 TRACE("(%p)->(IID_IInternetBindInfo %p)\n", This
, ppv
);
245 *ppv
= &This
->IInternetBindInfo_iface
;
246 }else if(IsEqualGUID(&IID_IBindCallbackRedirect
, riid
)) {
247 TRACE("(%p)->(IID_IBindCallbackRedirect %p)\n", This
, ppv
);
248 *ppv
= &This
->IBindCallbackRedirect_iface
;
252 IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
256 TRACE("Unsupported riid = %s\n", debugstr_guid(riid
));
257 return E_NOINTERFACE
;
260 static ULONG WINAPI
BindStatusCallback_AddRef(IBindStatusCallback
*iface
)
262 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
263 LONG ref
= InterlockedIncrement(&This
->ref
);
265 TRACE("(%p) ref = %d\n", This
, ref
);
270 static ULONG WINAPI
BindStatusCallback_Release(IBindStatusCallback
*iface
)
272 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
273 LONG ref
= InterlockedDecrement(&This
->ref
);
275 TRACE("(%p) ref = %d\n", This
, ref
);
278 release_request_data(&This
->request_data
);
280 IMoniker_Release(This
->mon
);
282 IBinding_Release(This
->binding
);
283 list_remove(&This
->entry
);
284 list_init(&This
->entry
);
286 This
->vtbl
->destroy(This
);
292 static HRESULT WINAPI
BindStatusCallback_OnStartBinding(IBindStatusCallback
*iface
,
293 DWORD dwReserved
, IBinding
*pbind
)
295 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
297 TRACE("(%p)->(%d %p)\n", This
, dwReserved
, pbind
);
299 IBinding_AddRef(pbind
);
300 This
->binding
= pbind
;
303 list_add_head(&This
->window
->bindings
, &This
->entry
);
305 return This
->vtbl
->start_binding(This
);
308 static HRESULT WINAPI
BindStatusCallback_GetPriority(IBindStatusCallback
*iface
, LONG
*pnPriority
)
310 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
311 FIXME("(%p)->(%p)\n", This
, pnPriority
);
315 static HRESULT WINAPI
BindStatusCallback_OnLowResource(IBindStatusCallback
*iface
, DWORD reserved
)
317 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
318 FIXME("(%p)->(%d)\n", This
, reserved
);
322 static HRESULT WINAPI
BindStatusCallback_OnProgress(IBindStatusCallback
*iface
, ULONG ulProgress
,
323 ULONG ulProgressMax
, ULONG ulStatusCode
, LPCWSTR szStatusText
)
325 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
327 TRACE("%p)->(%u %u %u %s)\n", This
, ulProgress
, ulProgressMax
, ulStatusCode
,
328 debugstr_w(szStatusText
));
330 return This
->vtbl
->on_progress(This
, ulStatusCode
, szStatusText
);
333 static HRESULT WINAPI
BindStatusCallback_OnStopBinding(IBindStatusCallback
*iface
,
334 HRESULT hresult
, LPCWSTR szError
)
336 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
339 TRACE("(%p)->(%08x %s)\n", This
, hresult
, debugstr_w(szError
));
341 /* NOTE: IE7 calls GetBindResult here */
343 hres
= This
->vtbl
->stop_binding(This
, hresult
);
346 IBinding_Release(This
->binding
);
347 This
->binding
= NULL
;
351 IMoniker_Release(This
->mon
);
355 list_remove(&This
->entry
);
356 list_init(&This
->entry
);
362 static HRESULT WINAPI
BindStatusCallback_GetBindInfo(IBindStatusCallback
*iface
,
363 DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
365 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
368 TRACE("(%p)->(%p %p)\n", This
, grfBINDF
, pbindinfo
);
370 if(!This
->bindinfo_ready
) {
373 hres
= This
->vtbl
->init_bindinfo(This
);
377 This
->bindinfo_ready
= TRUE
;
380 *grfBINDF
= This
->bindf
;
382 size
= pbindinfo
->cbSize
;
383 memset(pbindinfo
, 0, size
);
384 pbindinfo
->cbSize
= size
;
386 pbindinfo
->cbstgmedData
= This
->request_data
.post_data_len
;
387 pbindinfo
->dwCodePage
= CP_UTF8
;
388 pbindinfo
->dwOptions
= This
->bindinfo_options
;
390 if(This
->request_data
.post_data_len
) {
391 pbindinfo
->dwBindVerb
= BINDVERB_POST
;
393 pbindinfo
->stgmedData
.tymed
= TYMED_HGLOBAL
;
394 pbindinfo
->stgmedData
.u
.hGlobal
= This
->request_data
.post_data
;
395 pbindinfo
->stgmedData
.pUnkForRelease
= (IUnknown
*)&This
->IBindStatusCallback_iface
;
396 IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
402 static HRESULT WINAPI
BindStatusCallback_OnDataAvailable(IBindStatusCallback
*iface
,
403 DWORD grfBSCF
, DWORD dwSize
, FORMATETC
*pformatetc
, STGMEDIUM
*pstgmed
)
405 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
407 TRACE("(%p)->(%08x %d %p %p)\n", This
, grfBSCF
, dwSize
, pformatetc
, pstgmed
);
409 return This
->vtbl
->read_data(This
, pstgmed
->u
.pstm
);
412 static HRESULT WINAPI
BindStatusCallback_OnObjectAvailable(IBindStatusCallback
*iface
,
413 REFIID riid
, IUnknown
*punk
)
415 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
416 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), punk
);
420 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl
= {
421 BindStatusCallback_QueryInterface
,
422 BindStatusCallback_AddRef
,
423 BindStatusCallback_Release
,
424 BindStatusCallback_OnStartBinding
,
425 BindStatusCallback_GetPriority
,
426 BindStatusCallback_OnLowResource
,
427 BindStatusCallback_OnProgress
,
428 BindStatusCallback_OnStopBinding
,
429 BindStatusCallback_GetBindInfo
,
430 BindStatusCallback_OnDataAvailable
,
431 BindStatusCallback_OnObjectAvailable
434 static inline BSCallback
*impl_from_IHttpNegotiate2(IHttpNegotiate2
*iface
)
436 return CONTAINING_RECORD(iface
, BSCallback
, IHttpNegotiate2_iface
);
439 static HRESULT WINAPI
HttpNegotiate_QueryInterface(IHttpNegotiate2
*iface
,
440 REFIID riid
, void **ppv
)
442 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
443 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
446 static ULONG WINAPI
HttpNegotiate_AddRef(IHttpNegotiate2
*iface
)
448 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
449 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
452 static ULONG WINAPI
HttpNegotiate_Release(IHttpNegotiate2
*iface
)
454 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
455 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
458 static HRESULT WINAPI
HttpNegotiate_BeginningTransaction(IHttpNegotiate2
*iface
,
459 LPCWSTR szURL
, LPCWSTR szHeaders
, DWORD dwReserved
, LPWSTR
*pszAdditionalHeaders
)
461 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
464 TRACE("(%p)->(%s %s %d %p)\n", This
, debugstr_w(szURL
), debugstr_w(szHeaders
),
465 dwReserved
, pszAdditionalHeaders
);
467 *pszAdditionalHeaders
= NULL
;
469 hres
= This
->vtbl
->beginning_transaction(This
, pszAdditionalHeaders
);
473 if(This
->request_data
.headers
) {
476 size
= (lstrlenW(This
->request_data
.headers
)+1)*sizeof(WCHAR
);
477 *pszAdditionalHeaders
= CoTaskMemAlloc(size
);
478 if(!*pszAdditionalHeaders
)
479 return E_OUTOFMEMORY
;
480 memcpy(*pszAdditionalHeaders
, This
->request_data
.headers
, size
);
486 static HRESULT WINAPI
HttpNegotiate_OnResponse(IHttpNegotiate2
*iface
, DWORD dwResponseCode
,
487 LPCWSTR szResponseHeaders
, LPCWSTR szRequestHeaders
, LPWSTR
*pszAdditionalRequestHeaders
)
489 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
491 TRACE("(%p)->(%d %s %s %p)\n", This
, dwResponseCode
, debugstr_w(szResponseHeaders
),
492 debugstr_w(szRequestHeaders
), pszAdditionalRequestHeaders
);
494 return This
->vtbl
->on_response(This
, dwResponseCode
, szResponseHeaders
);
497 static HRESULT WINAPI
HttpNegotiate_GetRootSecurityId(IHttpNegotiate2
*iface
,
498 BYTE
*pbSecurityId
, DWORD
*pcbSecurityId
, DWORD_PTR dwReserved
)
500 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
501 TRACE("(%p)->(%p %p %ld)\n", This
, pbSecurityId
, pcbSecurityId
, dwReserved
);
502 return E_NOTIMPL
; /* FIXME */
505 static const IHttpNegotiate2Vtbl HttpNegotiate2Vtbl
= {
506 HttpNegotiate_QueryInterface
,
507 HttpNegotiate_AddRef
,
508 HttpNegotiate_Release
,
509 HttpNegotiate_BeginningTransaction
,
510 HttpNegotiate_OnResponse
,
511 HttpNegotiate_GetRootSecurityId
514 static inline BSCallback
*impl_from_IInternetBindInfo(IInternetBindInfo
*iface
)
516 return CONTAINING_RECORD(iface
, BSCallback
, IInternetBindInfo_iface
);
519 static HRESULT WINAPI
InternetBindInfo_QueryInterface(IInternetBindInfo
*iface
,
520 REFIID riid
, void **ppv
)
522 BSCallback
*This
= impl_from_IInternetBindInfo(iface
);
523 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
526 static ULONG WINAPI
InternetBindInfo_AddRef(IInternetBindInfo
*iface
)
528 BSCallback
*This
= impl_from_IInternetBindInfo(iface
);
529 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
532 static ULONG WINAPI
InternetBindInfo_Release(IInternetBindInfo
*iface
)
534 BSCallback
*This
= impl_from_IInternetBindInfo(iface
);
535 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
538 static HRESULT WINAPI
InternetBindInfo_GetBindInfo(IInternetBindInfo
*iface
,
539 DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
541 BSCallback
*This
= impl_from_IInternetBindInfo(iface
);
542 FIXME("(%p)->(%p %p)\n", This
, grfBINDF
, pbindinfo
);
546 static HRESULT WINAPI
InternetBindInfo_GetBindString(IInternetBindInfo
*iface
,
547 ULONG ulStringType
, LPOLESTR
*ppwzStr
, ULONG cEl
, ULONG
*pcElFetched
)
549 BSCallback
*This
= impl_from_IInternetBindInfo(iface
);
550 FIXME("(%p)->(%u %p %u %p)\n", This
, ulStringType
, ppwzStr
, cEl
, pcElFetched
);
554 static const IInternetBindInfoVtbl InternetBindInfoVtbl
= {
555 InternetBindInfo_QueryInterface
,
556 InternetBindInfo_AddRef
,
557 InternetBindInfo_Release
,
558 InternetBindInfo_GetBindInfo
,
559 InternetBindInfo_GetBindString
562 static inline BSCallback
*impl_from_IBindCallbackRedirect(IBindCallbackRedirect
*iface
)
564 return CONTAINING_RECORD(iface
, BSCallback
, IBindCallbackRedirect_iface
);
567 static HRESULT WINAPI
BindCallbackRedirect_QueryInterface(IBindCallbackRedirect
*iface
, REFIID riid
, void **ppv
)
569 BSCallback
*This
= impl_from_IBindCallbackRedirect(iface
);
570 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
573 static ULONG WINAPI
BindCallbackRedirect_AddRef(IBindCallbackRedirect
*iface
)
575 BSCallback
*This
= impl_from_IBindCallbackRedirect(iface
);
576 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
579 static ULONG WINAPI
BindCallbackRedirect_Release(IBindCallbackRedirect
*iface
)
581 BSCallback
*This
= impl_from_IBindCallbackRedirect(iface
);
582 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
585 static HRESULT WINAPI
BindCallbackRedirect_Redirect(IBindCallbackRedirect
*iface
, const WCHAR
*url
, VARIANT_BOOL
*vbCancel
)
587 BSCallback
*This
= impl_from_IBindCallbackRedirect(iface
);
588 GeckoBrowser
*browser
;
590 BSTR frame_name
= NULL
;
593 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(url
), vbCancel
);
595 if(This
->window
&& This
->window
->base
.outer_window
&& (browser
= This
->window
->base
.outer_window
->browser
)
596 && browser
->doc
->doc_object_service
) {
597 if(is_main_content_window(This
->window
->base
.outer_window
)) {
598 hres
= IHTMLWindow2_get_name(&This
->window
->base
.IHTMLWindow2_iface
, &frame_name
);
603 hres
= IDocObjectService_FireBeforeNavigate2(browser
->doc
->doc_object_service
, NULL
, url
, 0x40,
604 frame_name
, NULL
, 0, NULL
, TRUE
, &cancel
);
605 SysFreeString(frame_name
);
608 *vbCancel
= variant_bool(cancel
);
612 static const IBindCallbackRedirectVtbl BindCallbackRedirectVtbl
= {
613 BindCallbackRedirect_QueryInterface
,
614 BindCallbackRedirect_AddRef
,
615 BindCallbackRedirect_Release
,
616 BindCallbackRedirect_Redirect
619 static inline BSCallback
*impl_from_IServiceProvider(IServiceProvider
*iface
)
621 return CONTAINING_RECORD(iface
, BSCallback
, IServiceProvider_iface
);
624 static HRESULT WINAPI
BSCServiceProvider_QueryInterface(IServiceProvider
*iface
,
625 REFIID riid
, void **ppv
)
627 BSCallback
*This
= impl_from_IServiceProvider(iface
);
628 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
631 static ULONG WINAPI
BSCServiceProvider_AddRef(IServiceProvider
*iface
)
633 BSCallback
*This
= impl_from_IServiceProvider(iface
);
634 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
637 static ULONG WINAPI
BSCServiceProvider_Release(IServiceProvider
*iface
)
639 BSCallback
*This
= impl_from_IServiceProvider(iface
);
640 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
643 static HRESULT WINAPI
BSCServiceProvider_QueryService(IServiceProvider
*iface
,
644 REFGUID guidService
, REFIID riid
, void **ppv
)
646 BSCallback
*This
= impl_from_IServiceProvider(iface
);
648 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_guid(guidService
), debugstr_guid(riid
), ppv
);
650 if(This
->window
&& IsEqualGUID(guidService
, &IID_IWindowForBindingUI
))
651 return IServiceProvider_QueryService(&This
->window
->base
.IServiceProvider_iface
, guidService
, riid
, ppv
);
652 return E_NOINTERFACE
;
655 static const IServiceProviderVtbl ServiceProviderVtbl
= {
656 BSCServiceProvider_QueryInterface
,
657 BSCServiceProvider_AddRef
,
658 BSCServiceProvider_Release
,
659 BSCServiceProvider_QueryService
662 void init_bscallback(BSCallback
*This
, const BSCallbackVtbl
*vtbl
, IMoniker
*mon
, DWORD bindf
)
664 This
->IBindStatusCallback_iface
.lpVtbl
= &BindStatusCallbackVtbl
;
665 This
->IServiceProvider_iface
.lpVtbl
= &ServiceProviderVtbl
;
666 This
->IHttpNegotiate2_iface
.lpVtbl
= &HttpNegotiate2Vtbl
;
667 This
->IInternetBindInfo_iface
.lpVtbl
= &InternetBindInfoVtbl
;
668 This
->IBindCallbackRedirect_iface
.lpVtbl
= &BindCallbackRedirectVtbl
;
672 This
->bindinfo_options
= BINDINFO_OPTIONS_USE_IE_ENCODING
;
673 This
->bom
= BOM_NONE
;
675 list_init(&This
->entry
);
678 IMoniker_AddRef(mon
);
682 HRESULT
read_stream(BSCallback
*This
, IStream
*stream
, void *buf
, DWORD size
, DWORD
*ret_size
)
684 DWORD read_size
= 0, skip
=0;
688 hres
= IStream_Read(stream
, buf
, size
, &read_size
);
690 if(!This
->read
&& This
->bom
== BOM_NONE
) {
691 if(read_size
>= 2 && data
[0] == 0xff && data
[1] == 0xfe) {
692 This
->bom
= BOM_UTF16
;
694 }else if(read_size
>= 3 && data
[0] == 0xef && data
[1] == 0xbb && data
[2] == 0xbf) {
695 This
->bom
= BOM_UTF8
;
701 memmove(data
, data
+skip
, read_size
);
705 This
->read
+= read_size
;
706 *ret_size
= read_size
;
710 static void parse_content_type(nsChannelBSC
*This
, const WCHAR
*value
)
715 static const WCHAR charsetW
[] = {'c','h','a','r','s','e','t','='};
717 ptr
= wcschr(value
, ';');
722 while(*ptr
&& iswspace(*ptr
))
725 len
= lstrlenW(value
);
726 if(ptr
+ ARRAY_SIZE(charsetW
) < value
+len
&& !wcsnicmp(ptr
, charsetW
, ARRAY_SIZE(charsetW
))) {
727 size_t charset_len
, lena
;
728 nsACString charset_str
;
729 const WCHAR
*charset
;
732 ptr
+= ARRAY_SIZE(charsetW
);
735 FIXME("Quoted value\n");
739 while(*ptr
&& *ptr
!= ',')
741 charset_len
= ptr
-charset
;
744 lena
= WideCharToMultiByte(CP_ACP
, 0, charset
, charset_len
, NULL
, 0, NULL
, NULL
);
745 charseta
= heap_alloc(lena
+1);
749 WideCharToMultiByte(CP_ACP
, 0, charset
, charset_len
, charseta
, lena
, NULL
, NULL
);
752 nsACString_InitDepend(&charset_str
, charseta
);
753 nsIHttpChannel_SetContentCharset(&This
->nschannel
->nsIHttpChannel_iface
, &charset_str
);
754 nsACString_Finish(&charset_str
);
757 FIXME("unhandled: %s\n", debugstr_wn(ptr
, len
- (ptr
-value
)));
761 static HRESULT
parse_headers(const WCHAR
*headers
, struct list
*headers_list
)
763 const WCHAR
*header
, *header_end
, *colon
, *value
;
768 if(header
[0] == '\r' && header
[1] == '\n' && !header
[2])
770 for(colon
= header
; *colon
&& *colon
!= ':' && *colon
!= '\r'; colon
++);
780 for(header_end
= value
+1; *header_end
&& *header_end
!= '\r'; header_end
++);
782 hres
= set_http_header(headers_list
, header
, colon
-header
, value
, header_end
-value
);
787 if(header
[0] == '\r' && header
[1] == '\n')
794 static HRESULT
process_response_headers(nsChannelBSC
*This
, const WCHAR
*headers
)
799 hres
= parse_headers(headers
, &This
->nschannel
->response_headers
);
803 LIST_FOR_EACH_ENTRY(iter
, &This
->nschannel
->response_headers
, http_header_t
, entry
) {
804 if(!wcsicmp(iter
->header
, L
"content-type"))
805 parse_content_type(This
, iter
->data
);
811 static void query_http_info(nsChannelBSC
*This
, IWinInetHttpInfo
*wininet_info
)
817 IWinInetHttpInfo_QueryInfo(wininet_info
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &len
, NULL
, NULL
);
821 buf
= heap_alloc(len
);
825 IWinInetHttpInfo_QueryInfo(wininet_info
, HTTP_QUERY_RAW_HEADERS_CRLF
, buf
, &len
, NULL
, NULL
);
831 ptr
= wcschr(buf
, '\r');
832 if(ptr
&& ptr
[1] == '\n') {
834 process_response_headers(This
, ptr
);
840 HRESULT
start_binding(HTMLInnerWindow
*inner_window
, BSCallback
*bscallback
, IBindCtx
*bctx
)
845 TRACE("(%p %p %p)\n", inner_window
, bscallback
, bctx
);
847 bscallback
->window
= inner_window
;
849 /* NOTE: IE7 calls IsSystemMoniker here*/
852 hres
= RegisterBindStatusCallback(bctx
, &bscallback
->IBindStatusCallback_iface
, NULL
, 0);
854 IBindCtx_AddRef(bctx
);
856 hres
= CreateAsyncBindCtx(0, &bscallback
->IBindStatusCallback_iface
, NULL
, &bctx
);
860 bscallback
->window
= NULL
;
864 hres
= IMoniker_BindToStorage(bscallback
->mon
, bctx
, NULL
, &IID_IStream
, (void**)&str
);
865 IBindCtx_Release(bctx
);
867 WARN("BindToStorage failed: %08x\n", hres
);
868 bscallback
->window
= NULL
;
873 IStream_Release(str
);
878 static HRESULT
read_post_data_stream(nsIInputStream
*stream
, BOOL contains_headers
, struct list
*headers_list
,
879 request_data_t
*request_data
)
881 nsISeekableStream
*seekable_stream
;
882 UINT64 available
= 0;
884 char *data
, *post_data
;
891 nsres
= nsIInputStream_Available(stream
, &available
);
895 post_data
= data
= GlobalAlloc(0, available
+1);
897 return E_OUTOFMEMORY
;
899 nsres
= nsIInputStream_Read(stream
, data
, available
, &data_len
);
900 if(NS_FAILED(nsres
)) {
905 if(contains_headers
) {
906 if(data_len
>= 2 && data
[0] == '\r' && data
[1] == '\n') {
914 post_data
+= data_len
;
915 for(ptr
= data
; ptr
+4 < data
+data_len
; ptr
++) {
916 if(!memcmp(ptr
, "\r\n\r\n", 4)) {
923 data_len
-= post_data
-data
;
925 size
= MultiByteToWideChar(CP_ACP
, 0, data
, ptr
-data
, NULL
, 0);
926 headers
= heap_alloc((size
+1)*sizeof(WCHAR
));
928 MultiByteToWideChar(CP_ACP
, 0, data
, ptr
-data
, headers
, size
);
931 hres
= parse_headers(headers
, headers_list
);
933 request_data
->headers
= headers
;
937 hres
= E_OUTOFMEMORY
;
950 }else if(post_data
!= data
) {
953 new_data
= GlobalAlloc(0, data_len
+1);
955 memcpy(new_data
, post_data
, data_len
);
958 return E_OUTOFMEMORY
;
959 post_data
= new_data
;
963 post_data
[data_len
] = 0;
964 request_data
->post_data
= post_data
;
965 request_data
->post_data_len
= data_len
;
967 nsres
= nsIInputStream_QueryInterface(stream
, &IID_nsISeekableStream
, (void**)&seekable_stream
);
968 assert(nsres
== NS_OK
);
970 nsres
= nsISeekableStream_Seek(seekable_stream
, NS_SEEK_SET
, 0);
971 assert(nsres
== NS_OK
);
973 nsISeekableStream_Release(seekable_stream
);
975 nsIInputStream_AddRef(stream
);
976 request_data
->post_stream
= stream
;
977 TRACE("post_data = %s\n", debugstr_an(request_data
->post_data
, request_data
->post_data_len
));
981 static HRESULT
on_start_nsrequest(nsChannelBSC
*This
)
985 This
->nschannel
->binding
= This
;
987 /* FIXME: it's needed for http connections from BindToObject. */
988 if(!This
->nschannel
->response_status
)
989 This
->nschannel
->response_status
= 200;
991 nsres
= nsIStreamListener_OnStartRequest(This
->nslistener
,
992 (nsIRequest
*)&This
->nschannel
->nsIHttpChannel_iface
, This
->nscontext
);
993 if(NS_FAILED(nsres
)) {
994 FIXME("OnStartRequest failed: %08x\n", nsres
);
998 if(This
->is_doc_channel
) {
1001 if(!This
->bsc
.window
)
1002 return E_ABORT
; /* Binding aborted in OnStartRequest call. */
1003 hres
= update_window_doc(This
->bsc
.window
);
1007 if(This
->bsc
.binding
)
1008 process_document_response_headers(This
->bsc
.window
->doc
, This
->bsc
.binding
);
1009 if(This
->bsc
.window
->base
.outer_window
->readystate
!= READYSTATE_LOADING
)
1010 set_ready_state(This
->bsc
.window
->base
.outer_window
, READYSTATE_LOADING
);
1016 static void on_stop_nsrequest(nsChannelBSC
*This
, HRESULT result
)
1018 nsresult nsres
, request_result
;
1022 request_result
= NS_OK
;
1025 request_result
= NS_BINDING_ABORTED
;
1028 request_result
= NS_ERROR_FAILURE
;
1031 if(This
->nslistener
) {
1032 nsres
= nsIStreamListener_OnStopRequest(This
->nslistener
,
1033 (nsIRequest
*)&This
->nschannel
->nsIHttpChannel_iface
, This
->nscontext
,
1035 if(NS_FAILED(nsres
))
1036 WARN("OnStopRequest failed: %08x\n", nsres
);
1039 if(This
->nschannel
) {
1040 if(This
->nschannel
->load_group
) {
1041 nsres
= nsILoadGroup_RemoveRequest(This
->nschannel
->load_group
,
1042 (nsIRequest
*)&This
->nschannel
->nsIHttpChannel_iface
, NULL
, request_result
);
1043 if(NS_FAILED(nsres
))
1044 ERR("RemoveRequest failed: %08x\n", nsres
);
1046 if(This
->nschannel
->binding
== This
)
1047 This
->nschannel
->binding
= NULL
;
1051 static HRESULT
read_stream_data(nsChannelBSC
*This
, IStream
*stream
)
1057 if(!This
->response_processed
) {
1058 IWinInetHttpInfo
*wininet_info
;
1060 This
->response_processed
= TRUE
;
1061 if(This
->bsc
.binding
) {
1062 hres
= IBinding_QueryInterface(This
->bsc
.binding
, &IID_IWinInetHttpInfo
, (void**)&wininet_info
);
1063 if(SUCCEEDED(hres
)) {
1064 query_http_info(This
, wininet_info
);
1065 IWinInetHttpInfo_Release(wininet_info
);
1070 if(!This
->nschannel
)
1073 if(!This
->nslistener
) {
1077 hres
= read_stream(&This
->bsc
, stream
, buf
, sizeof(buf
), &read
);
1078 }while(hres
== S_OK
&& read
);
1083 if(!This
->nsstream
) {
1084 This
->nsstream
= create_nsprotocol_stream();
1086 return E_OUTOFMEMORY
;
1090 BOOL first_read
= !This
->bsc
.read
;
1092 hres
= read_stream(&This
->bsc
, stream
, This
->nsstream
->buf
+This
->nsstream
->buf_size
,
1093 sizeof(This
->nsstream
->buf
)-This
->nsstream
->buf_size
, &read
);
1097 This
->nsstream
->buf_size
+= read
;
1100 switch(This
->bsc
.bom
) {
1102 This
->nschannel
->charset
= heap_strdupA(UTF8_STR
);
1105 This
->nschannel
->charset
= heap_strdupA(UTF16_STR
);
1107 /* FIXME: Get charset from HTTP headers */;
1110 if(!This
->nschannel
->content_type
) {
1113 hres
= FindMimeFromData(NULL
, NULL
, This
->nsstream
->buf
, This
->nsstream
->buf_size
,
1114 This
->is_doc_channel
? L
"text/html" : NULL
, 0, &mime
, 0);
1118 TRACE("Found MIME %s\n", debugstr_w(mime
));
1120 This
->nschannel
->content_type
= heap_strdupWtoA(mime
);
1121 CoTaskMemFree(mime
);
1122 if(!This
->nschannel
->content_type
)
1123 return E_OUTOFMEMORY
;
1126 hres
= on_start_nsrequest(This
);
1131 nsres
= nsIStreamListener_OnDataAvailable(This
->nslistener
,
1132 (nsIRequest
*)&This
->nschannel
->nsIHttpChannel_iface
, This
->nscontext
,
1133 &This
->nsstream
->nsIInputStream_iface
, This
->bsc
.read
-This
->nsstream
->buf_size
,
1134 This
->nsstream
->buf_size
);
1135 if(NS_FAILED(nsres
))
1136 ERR("OnDataAvailable failed: %08x\n", nsres
);
1138 if(This
->nsstream
->buf_size
== sizeof(This
->nsstream
->buf
)) {
1139 ERR("buffer is full\n");
1142 }while(hres
== S_OK
);
1148 nsIAsyncVerifyRedirectCallback nsIAsyncVerifyRedirectCallback_iface
;
1152 nsChannel
*nschannel
;
1154 } nsRedirectCallback
;
1156 static nsRedirectCallback
*impl_from_nsIAsyncVerifyRedirectCallback(nsIAsyncVerifyRedirectCallback
*iface
)
1158 return CONTAINING_RECORD(iface
, nsRedirectCallback
, nsIAsyncVerifyRedirectCallback_iface
);
1161 static nsresult NSAPI
nsAsyncVerifyRedirectCallback_QueryInterface(nsIAsyncVerifyRedirectCallback
*iface
,
1162 nsIIDRef riid
, void **result
)
1164 nsRedirectCallback
*This
= impl_from_nsIAsyncVerifyRedirectCallback(iface
);
1166 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1167 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1168 *result
= &This
->nsIAsyncVerifyRedirectCallback_iface
;
1169 }else if(IsEqualGUID(&IID_nsIAsyncVerifyRedirectCallback
, riid
)) {
1170 TRACE("(%p)->(IID_nsIAsyncVerifyRedirectCallback %p)\n", This
, result
);
1171 *result
= &This
->nsIAsyncVerifyRedirectCallback_iface
;
1174 WARN("unimplemented iface %s\n", debugstr_guid(riid
));
1175 return NS_NOINTERFACE
;
1178 nsISupports_AddRef((nsISupports
*)*result
);
1182 static nsrefcnt NSAPI
nsAsyncVerifyRedirectCallback_AddRef(nsIAsyncVerifyRedirectCallback
*iface
)
1184 nsRedirectCallback
*This
= impl_from_nsIAsyncVerifyRedirectCallback(iface
);
1185 LONG ref
= InterlockedIncrement(&This
->ref
);
1187 TRACE("(%p) ref=%d\n", This
, ref
);
1192 static nsrefcnt NSAPI
nsAsyncVerifyRedirectCallback_Release(nsIAsyncVerifyRedirectCallback
*iface
)
1194 nsRedirectCallback
*This
= impl_from_nsIAsyncVerifyRedirectCallback(iface
);
1195 LONG ref
= InterlockedDecrement(&This
->ref
);
1197 TRACE("(%p) ref=%d\n", This
, ref
);
1200 IBindStatusCallback_Release(&This
->bsc
->bsc
.IBindStatusCallback_iface
);
1201 nsIHttpChannel_Release(&This
->nschannel
->nsIHttpChannel_iface
);
1208 static nsresult NSAPI
nsAsyncVerifyRedirectCallback_OnRedirectVerifyCallback(nsIAsyncVerifyRedirectCallback
*iface
, nsresult result
)
1210 nsRedirectCallback
*This
= impl_from_nsIAsyncVerifyRedirectCallback(iface
);
1211 nsChannel
*old_nschannel
;
1214 TRACE("(%p)->(%08x)\n", This
, result
);
1216 old_nschannel
= This
->bsc
->nschannel
;
1217 nsIHttpChannel_AddRef(&This
->nschannel
->nsIHttpChannel_iface
);
1218 This
->bsc
->nschannel
= This
->nschannel
;
1220 if(This
->nschannel
->load_group
) {
1221 nsres
= nsILoadGroup_AddRequest(This
->nschannel
->load_group
, (nsIRequest
*)&This
->nschannel
->nsIHttpChannel_iface
,
1223 if(NS_FAILED(nsres
))
1224 ERR("AddRequest failed: %08x\n", nsres
);
1227 if(This
->bsc
->is_doc_channel
&& This
->bsc
->bsc
.window
&& This
->bsc
->bsc
.window
->base
.outer_window
) {
1228 IUri
*uri
= nsuri_get_uri(This
->nschannel
->uri
);
1231 set_current_uri(This
->bsc
->bsc
.window
->base
.outer_window
, uri
);
1234 WARN("Could not get IUri from nsWineURI\n");
1239 if(old_nschannel
->load_group
) {
1240 nsres
= nsILoadGroup_RemoveRequest(old_nschannel
->load_group
,
1241 (nsIRequest
*)&old_nschannel
->nsIHttpChannel_iface
, NULL
, NS_OK
);
1242 if(NS_FAILED(nsres
))
1243 ERR("RemoveRequest failed: %08x\n", nsres
);
1245 nsIHttpChannel_Release(&old_nschannel
->nsIHttpChannel_iface
);
1251 static const nsIAsyncVerifyRedirectCallbackVtbl nsAsyncVerifyRedirectCallbackVtbl
= {
1252 nsAsyncVerifyRedirectCallback_QueryInterface
,
1253 nsAsyncVerifyRedirectCallback_AddRef
,
1254 nsAsyncVerifyRedirectCallback_Release
,
1255 nsAsyncVerifyRedirectCallback_OnRedirectVerifyCallback
1258 static HRESULT
create_redirect_callback(nsChannel
*nschannel
, nsChannelBSC
*bsc
, nsRedirectCallback
**ret
)
1260 nsRedirectCallback
*callback
;
1262 callback
= heap_alloc(sizeof(*callback
));
1264 return E_OUTOFMEMORY
;
1266 callback
->nsIAsyncVerifyRedirectCallback_iface
.lpVtbl
= &nsAsyncVerifyRedirectCallbackVtbl
;
1269 nsIHttpChannel_AddRef(&nschannel
->nsIHttpChannel_iface
);
1270 callback
->nschannel
= nschannel
;
1272 IBindStatusCallback_AddRef(&bsc
->bsc
.IBindStatusCallback_iface
);
1273 callback
->bsc
= bsc
;
1279 static inline nsChannelBSC
*nsChannelBSC_from_BSCallback(BSCallback
*iface
)
1281 return CONTAINING_RECORD(iface
, nsChannelBSC
, bsc
);
1284 static void nsChannelBSC_destroy(BSCallback
*bsc
)
1286 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1288 if(This
->nschannel
) {
1289 if(This
->nschannel
->binding
== This
)
1290 This
->nschannel
->binding
= NULL
;
1291 nsIHttpChannel_Release(&This
->nschannel
->nsIHttpChannel_iface
);
1293 if(This
->nslistener
)
1294 nsIStreamListener_Release(This
->nslistener
);
1296 nsISupports_Release(This
->nscontext
);
1298 nsIInputStream_Release(&This
->nsstream
->nsIInputStream_iface
);
1302 static HRESULT
nsChannelBSC_start_binding(BSCallback
*bsc
)
1304 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1306 if(This
->is_doc_channel
)
1307 This
->bsc
.window
->base
.outer_window
->base
.inner_window
->doc
->skip_mutation_notif
= FALSE
;
1312 static HRESULT
nsChannelBSC_init_bindinfo(BSCallback
*bsc
)
1314 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1315 nsChannel
*nschannel
= This
->nschannel
;
1316 GeckoBrowser
*browser
;
1319 if(This
->is_doc_channel
&& This
->bsc
.window
&& This
->bsc
.window
->base
.outer_window
1320 && (browser
= This
->bsc
.window
->base
.outer_window
->browser
)) {
1321 if(browser
->doc
->hostinfo
.dwFlags
& DOCHOSTUIFLAG_ENABLE_REDIRECT_NOTIFICATION
)
1322 This
->bsc
.bindinfo_options
|= BINDINFO_OPTIONS_DISABLEAUTOREDIRECTS
;
1325 if(nschannel
&& nschannel
->post_data_stream
) {
1326 hres
= read_post_data_stream(nschannel
->post_data_stream
, nschannel
->post_data_contains_headers
,
1327 &nschannel
->request_headers
, &This
->bsc
.request_data
);
1338 } stop_request_task_t
;
1340 static void stop_request_proc(task_t
*_task
)
1342 stop_request_task_t
*task
= (stop_request_task_t
*)_task
;
1344 TRACE("(%p)\n", task
->bsc
);
1346 list_remove(&task
->bsc
->bsc
.entry
);
1347 list_init(&task
->bsc
->bsc
.entry
);
1348 on_stop_nsrequest(task
->bsc
, S_OK
);
1351 static void stop_request_task_destr(task_t
*_task
)
1353 stop_request_task_t
*task
= (stop_request_task_t
*)_task
;
1355 IBindStatusCallback_Release(&task
->bsc
->bsc
.IBindStatusCallback_iface
);
1359 static HRESULT
async_stop_request(nsChannelBSC
*This
)
1361 stop_request_task_t
*task
;
1363 if(!This
->bsc
.read
) {
1364 TRACE("No data read, calling OnStartRequest\n");
1365 on_start_nsrequest(This
);
1368 task
= heap_alloc(sizeof(*task
));
1370 return E_OUTOFMEMORY
;
1372 IBindStatusCallback_AddRef(&This
->bsc
.IBindStatusCallback_iface
);
1375 return push_task(&task
->header
, stop_request_proc
, stop_request_task_destr
, This
->bsc
.window
->task_magic
);
1378 static void handle_navigation_error(nsChannelBSC
*This
, DWORD result
)
1380 HTMLOuterWindow
*outer_window
;
1381 HTMLDocumentObj
*doc
;
1384 SAFEARRAYBOUND bound
;
1385 VARIANT var
, varOut
;
1390 if(!This
->is_doc_channel
|| !This
->bsc
.window
|| !This
->bsc
.window
->base
.outer_window
1391 || !This
->bsc
.window
->base
.outer_window
->browser
)
1394 outer_window
= This
->bsc
.window
->base
.outer_window
;
1395 doc
= outer_window
->browser
->doc
;
1396 if(!doc
->doc_object_service
|| !doc
->client
)
1399 hres
= IDocObjectService_IsErrorUrl(doc
->doc_object_service
,
1400 outer_window
->url
, &is_error_url
);
1401 if(FAILED(hres
) || is_error_url
)
1404 if(!doc
->client_cmdtrg
)
1408 bound
.cElements
= 8;
1409 sa
= SafeArrayCreate(VT_VARIANT
, 1, &bound
);
1415 V_I4(&var
) = result
;
1416 SafeArrayPutElement(sa
, &ind
, &var
);
1419 V_VT(&var
) = VT_BSTR
;
1420 V_BSTR(&var
) = outer_window
->url
;
1421 SafeArrayPutElement(sa
, &ind
, &var
);
1424 V_VT(&var
) = VT_UNKNOWN
;
1425 V_UNKNOWN(&var
) = (IUnknown
*)&outer_window
->base
.IHTMLWindow2_iface
;
1426 SafeArrayPutElement(sa
, &ind
, &var
);
1428 /* FIXME: what are the following fields for? */
1430 V_VT(&var
) = VT_UNKNOWN
;
1431 V_UNKNOWN(&var
) = NULL
;
1432 SafeArrayPutElement(sa
, &ind
, &var
);
1435 V_VT(&var
) = VT_BOOL
;
1436 V_BOOL(&var
) = FALSE
;
1437 SafeArrayPutElement(sa
, &ind
, &var
);
1440 V_VT(&var
) = VT_BOOL
;
1441 V_BOOL(&var
) = FALSE
;
1442 SafeArrayPutElement(sa
, &ind
, &var
);
1445 V_VT(&var
) = VT_BSTR
;
1446 unk
= SysAllocString(NULL
);
1448 SafeArrayPutElement(sa
, &ind
, &var
);
1451 V_VT(&var
) = VT_UNKNOWN
;
1452 V_UNKNOWN(&var
) = NULL
;
1453 SafeArrayPutElement(sa
, &ind
, &var
);
1455 V_VT(&var
) = VT_ARRAY
;
1457 V_VT(&varOut
) = VT_BOOL
;
1458 V_BOOL(&varOut
) = VARIANT_TRUE
;
1459 IOleCommandTarget_Exec(doc
->client_cmdtrg
, &CGID_DocHostCmdPriv
, 1, 0, &var
, FAILED(hres
)?NULL
:&varOut
);
1462 SafeArrayDestroy(sa
);
1465 static HRESULT
nsChannelBSC_stop_binding(BSCallback
*bsc
, HRESULT result
)
1467 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1469 if(result
!= E_ABORT
&& This
->is_doc_channel
&& This
->bsc
.window
) {
1471 handle_navigation_error(This
, result
);
1472 else if(This
->nschannel
) {
1473 result
= async_stop_request(This
);
1474 if(SUCCEEDED(result
))
1479 on_stop_nsrequest(This
, result
);
1483 static HRESULT
nsChannelBSC_read_data(BSCallback
*bsc
, IStream
*stream
)
1485 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1487 return read_stream_data(This
, stream
);
1490 static HRESULT
handle_redirect(nsChannelBSC
*This
, const WCHAR
*new_url
)
1492 nsRedirectCallback
*callback
;
1493 nsIChannelEventSink
*sink
;
1494 nsChannel
*new_channel
;
1499 TRACE("(%p)->(%s)\n", This
, debugstr_w(new_url
));
1501 hres
= CreateURLMoniker(NULL
, new_url
, &mon
);
1504 IMoniker_Release(This
->bsc
.mon
);
1505 This
->bsc
.mon
= mon
;
1507 if(!This
->nschannel
|| !This
->nschannel
->notif_callback
)
1510 nsres
= nsIInterfaceRequestor_GetInterface(This
->nschannel
->notif_callback
, &IID_nsIChannelEventSink
, (void**)&sink
);
1511 if(NS_FAILED(nsres
))
1514 hres
= create_redirect_nschannel(new_url
, This
->nschannel
, &new_channel
);
1515 if(SUCCEEDED(hres
)) {
1516 TRACE("%p %p->%p\n", This
, This
->nschannel
, new_channel
);
1518 hres
= create_redirect_callback(new_channel
, This
, &callback
);
1519 nsIHttpChannel_Release(&new_channel
->nsIHttpChannel_iface
);
1522 if(SUCCEEDED(hres
)) {
1523 nsres
= nsIChannelEventSink_AsyncOnChannelRedirect(sink
, (nsIChannel
*)&This
->nschannel
->nsIHttpChannel_iface
,
1524 (nsIChannel
*)&callback
->nschannel
->nsIHttpChannel_iface
, REDIRECT_TEMPORARY
, /* FIXME */
1525 &callback
->nsIAsyncVerifyRedirectCallback_iface
);
1527 if(NS_FAILED(nsres
))
1528 FIXME("AsyncOnChannelRedirect failed: %08x\n", hres
);
1529 else if(This
->nschannel
!= callback
->nschannel
)
1530 FIXME("nschannel not updated\n");
1532 nsIAsyncVerifyRedirectCallback_Release(&callback
->nsIAsyncVerifyRedirectCallback_iface
);
1535 nsIChannelEventSink_Release(sink
);
1539 static BOOL
is_supported_doc_mime(const WCHAR
*mime
)
1541 char *nscat
, *mimea
;
1544 mimea
= heap_strdupWtoA(mime
);
1548 nscat
= get_nscategory_entry("Gecko-Content-Viewers", mimea
);
1550 ret
= nscat
!= NULL
&& !strcmp(nscat
, "@mozilla.org/content/document-loader-factory;1");
1557 static IUri
*get_moniker_uri(IMoniker
*mon
)
1559 IUriContainer
*uri_container
;
1563 hres
= IMoniker_QueryInterface(mon
, &IID_IUriContainer
, (void**)&uri_container
);
1564 if(SUCCEEDED(hres
)) {
1565 hres
= IUriContainer_GetIUri(uri_container
, &ret
);
1566 IUriContainer_Release(uri_container
);
1570 FIXME("No IUriContainer\n");
1576 static void handle_extern_mime_navigation(nsChannelBSC
*This
)
1578 IWebBrowserPriv2IE9
*webbrowser_priv
;
1579 IOleCommandTarget
*cmdtrg
;
1580 HTMLDocumentObj
*doc_obj
;
1586 if(!This
->bsc
.window
|| !This
->bsc
.window
->base
.outer_window
|| !This
->bsc
.window
->base
.outer_window
->browser
)
1589 doc_obj
= This
->bsc
.window
->base
.outer_window
->browser
->doc
;
1591 hres
= IOleClientSite_QueryInterface(doc_obj
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
1592 if(SUCCEEDED(hres
)) {
1593 IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 62, 0, NULL
, NULL
);
1594 IOleCommandTarget_Release(cmdtrg
);
1597 set_document_navigation(doc_obj
, FALSE
);
1599 if(!doc_obj
->webbrowser
) {
1600 FIXME("unimplemented in non-webbrowser mode\n");
1604 uri
= get_moniker_uri(This
->bsc
.mon
);
1608 hres
= CreateBindCtx(0, &bind_ctx
);
1614 V_VT(&flags
) = VT_I4
;
1615 V_I4(&flags
) = navHyperlink
;
1617 hres
= IUnknown_QueryInterface(doc_obj
->webbrowser
, &IID_IWebBrowserPriv2IE8
, (void**)&webbrowser_priv
);
1618 if(SUCCEEDED(hres
)) {
1619 hres
= IWebBrowserPriv2IE9_NavigateWithBindCtx2(webbrowser_priv
, uri
, &flags
, NULL
, NULL
, NULL
, bind_ctx
, NULL
, 0);
1620 IWebBrowserPriv2IE9_Release(webbrowser_priv
);
1622 IWebBrowserPriv
*webbrowser_priv_old
;
1625 hres
= IUnknown_QueryInterface(doc_obj
->webbrowser
, &IID_IWebBrowserPriv
, (void**)&webbrowser_priv_old
);
1626 if(SUCCEEDED(hres
)) {
1627 V_VT(&uriv
) = VT_BSTR
;
1628 IUri_GetDisplayUri(uri
, &V_BSTR(&uriv
));
1630 hres
= IWebBrowserPriv_NavigateWithBindCtx(webbrowser_priv_old
, &uriv
, &flags
, NULL
, NULL
, NULL
, bind_ctx
, NULL
);
1632 SysFreeString(V_BSTR(&uriv
));
1633 IWebBrowserPriv_Release(webbrowser_priv_old
);
1640 static HRESULT
nsChannelBSC_on_progress(BSCallback
*bsc
, ULONG status_code
, LPCWSTR status_text
)
1642 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1644 switch(status_code
) {
1645 case BINDSTATUS_MIMETYPEAVAILABLE
:
1646 if(This
->is_doc_channel
&& !is_supported_doc_mime(status_text
)) {
1647 FIXME("External MIME: %s\n", debugstr_w(status_text
));
1649 handle_extern_mime_navigation(This
);
1651 This
->nschannel
= NULL
;
1654 if(!This
->nschannel
)
1657 heap_free(This
->nschannel
->content_type
);
1658 This
->nschannel
->content_type
= heap_strdupWtoA(status_text
);
1660 case BINDSTATUS_REDIRECTING
:
1661 return handle_redirect(This
, status_text
);
1662 case BINDSTATUS_BEGINDOWNLOADDATA
: {
1663 IWinInetHttpInfo
*http_info
;
1664 DWORD status
, size
= sizeof(DWORD
);
1667 if(!This
->bsc
.binding
)
1670 hres
= IBinding_QueryInterface(This
->bsc
.binding
, &IID_IWinInetHttpInfo
, (void**)&http_info
);
1674 hres
= IWinInetHttpInfo_QueryInfo(http_info
,
1675 HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
, NULL
);
1676 IWinInetHttpInfo_Release(http_info
);
1677 if(FAILED(hres
) || status
== HTTP_STATUS_OK
)
1680 handle_navigation_error(This
, status
);
1687 static HRESULT
process_response_status_text(const WCHAR
*header
, const WCHAR
*header_end
, char **status_text
)
1689 header
= wcschr(header
+ 1, ' ');
1690 if(!header
|| header
>= header_end
)
1692 header
= wcschr(header
+ 1, ' ');
1693 if(!header
|| header
>= header_end
)
1697 *status_text
= heap_strndupWtoU(header
, header_end
- header
);
1700 return E_OUTOFMEMORY
;
1705 static HRESULT
nsChannelBSC_on_response(BSCallback
*bsc
, DWORD response_code
,
1706 LPCWSTR response_headers
)
1708 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1712 This
->response_processed
= TRUE
;
1713 This
->nschannel
->response_status
= response_code
;
1715 if(response_headers
) {
1716 const WCHAR
*headers
;
1718 headers
= wcschr(response_headers
, '\r');
1719 hres
= process_response_status_text(response_headers
, headers
, &str
);
1721 WARN("parsing headers failed: %08x\n", hres
);
1725 heap_free(This
->nschannel
->response_status_text
);
1726 This
->nschannel
->response_status_text
= str
;
1728 if(headers
&& headers
[1] == '\n') {
1730 hres
= process_response_headers(This
, headers
);
1732 WARN("parsing headers failed: %08x\n", hres
);
1741 static HRESULT
nsChannelBSC_beginning_transaction(BSCallback
*bsc
, WCHAR
**additional_headers
)
1743 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1744 http_header_t
*iter
;
1748 if(!This
->nschannel
)
1751 LIST_FOR_EACH_ENTRY(iter
, &This
->nschannel
->request_headers
, http_header_t
, entry
) {
1752 if(wcscmp(iter
->header
, L
"Content-Length"))
1753 len
+= lstrlenW(iter
->header
) + 2 /* ": " */ + lstrlenW(iter
->data
) + 2 /* "\r\n" */;
1759 *additional_headers
= ptr
= CoTaskMemAlloc((len
+1)*sizeof(WCHAR
));
1761 return E_OUTOFMEMORY
;
1763 LIST_FOR_EACH_ENTRY(iter
, &This
->nschannel
->request_headers
, http_header_t
, entry
) {
1764 if(!wcscmp(iter
->header
, L
"Content-Length"))
1767 len
= lstrlenW(iter
->header
);
1768 memcpy(ptr
, iter
->header
, len
*sizeof(WCHAR
));
1774 len
= lstrlenW(iter
->data
);
1775 memcpy(ptr
, iter
->data
, len
*sizeof(WCHAR
));
1787 static const BSCallbackVtbl nsChannelBSCVtbl
= {
1788 nsChannelBSC_destroy
,
1789 nsChannelBSC_init_bindinfo
,
1790 nsChannelBSC_start_binding
,
1791 nsChannelBSC_stop_binding
,
1792 nsChannelBSC_read_data
,
1793 nsChannelBSC_on_progress
,
1794 nsChannelBSC_on_response
,
1795 nsChannelBSC_beginning_transaction
1798 HRESULT
create_channelbsc(IMoniker
*mon
, const WCHAR
*headers
, BYTE
*post_data
, DWORD post_data_size
,
1799 BOOL is_doc_binding
, nsChannelBSC
**retval
)
1804 ret
= heap_alloc_zero(sizeof(*ret
));
1806 return E_OUTOFMEMORY
;
1808 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
;
1810 bindf
|= BINDF_FORMS_SUBMIT
| BINDF_PRAGMA_NO_CACHE
| BINDF_HYPERLINK
| BINDF_GETNEWESTVERSION
;
1812 init_bscallback(&ret
->bsc
, &nsChannelBSCVtbl
, mon
, bindf
);
1813 ret
->is_doc_channel
= is_doc_binding
;
1816 ret
->bsc
.request_data
.headers
= heap_strdupW(headers
);
1817 if(!ret
->bsc
.request_data
.headers
) {
1818 IBindStatusCallback_Release(&ret
->bsc
.IBindStatusCallback_iface
);
1819 return E_OUTOFMEMORY
;
1824 ret
->bsc
.request_data
.post_data
= GlobalAlloc(0, post_data_size
+1);
1825 if(!ret
->bsc
.request_data
.post_data
) {
1826 release_request_data(&ret
->bsc
.request_data
);
1827 IBindStatusCallback_Release(&ret
->bsc
.IBindStatusCallback_iface
);
1828 return E_OUTOFMEMORY
;
1831 memcpy(ret
->bsc
.request_data
.post_data
, post_data
, post_data_size
);
1832 ((BYTE
*)ret
->bsc
.request_data
.post_data
)[post_data_size
] = 0;
1833 ret
->bsc
.request_data
.post_data_len
= post_data_size
;
1836 TRACE("created %p\n", ret
);
1843 HTMLOuterWindow
*window
;
1844 HTMLInnerWindow
*pending_window
;
1845 } start_doc_binding_task_t
;
1847 static void start_doc_binding_proc(task_t
*_task
)
1849 start_doc_binding_task_t
*task
= (start_doc_binding_task_t
*)_task
;
1851 set_current_mon(task
->window
, task
->pending_window
->bscallback
->bsc
.mon
, BINDING_NAVIGATED
);
1852 start_binding(task
->pending_window
, &task
->pending_window
->bscallback
->bsc
, NULL
);
1855 static void start_doc_binding_task_destr(task_t
*_task
)
1857 start_doc_binding_task_t
*task
= (start_doc_binding_task_t
*)_task
;
1859 IHTMLWindow2_Release(&task
->pending_window
->base
.IHTMLWindow2_iface
);
1863 HRESULT
async_start_doc_binding(HTMLOuterWindow
*window
, HTMLInnerWindow
*pending_window
)
1865 start_doc_binding_task_t
*task
;
1867 TRACE("%p\n", pending_window
);
1869 task
= heap_alloc(sizeof(start_doc_binding_task_t
));
1871 return E_OUTOFMEMORY
;
1873 task
->window
= window
;
1874 task
->pending_window
= pending_window
;
1875 IHTMLWindow2_AddRef(&pending_window
->base
.IHTMLWindow2_iface
);
1877 return push_task(&task
->header
, start_doc_binding_proc
, start_doc_binding_task_destr
, pending_window
->task_magic
);
1880 void abort_window_bindings(HTMLInnerWindow
*window
)
1884 remove_target_tasks(window
->task_magic
);
1886 while(!list_empty(&window
->bindings
)) {
1887 iter
= LIST_ENTRY(window
->bindings
.next
, BSCallback
, entry
);
1889 TRACE("Aborting %p\n", iter
);
1891 IBindStatusCallback_AddRef(&iter
->IBindStatusCallback_iface
);
1894 IBinding_Abort(iter
->binding
);
1896 iter
->vtbl
->stop_binding(iter
, E_ABORT
);
1898 iter
->window
= NULL
;
1899 list_remove(&iter
->entry
);
1900 list_init(&iter
->entry
);
1902 IBindStatusCallback_Release(&iter
->IBindStatusCallback_iface
);
1905 if(window
->bscallback
) {
1906 IBindStatusCallback_Release(&window
->bscallback
->bsc
.IBindStatusCallback_iface
);
1907 window
->bscallback
= NULL
;
1911 IMoniker_Release(window
->mon
);
1916 HRESULT
channelbsc_load_stream(HTMLInnerWindow
*pending_window
, IMoniker
*mon
, IStream
*stream
)
1918 nsChannelBSC
*bscallback
= pending_window
->bscallback
;
1919 HRESULT hres
= S_OK
;
1921 if(!bscallback
->nschannel
) {
1922 ERR("NULL nschannel\n");
1926 bscallback
->nschannel
->content_type
= heap_strdupA("text/html");
1927 if(!bscallback
->nschannel
->content_type
)
1928 return E_OUTOFMEMORY
;
1930 set_current_mon(pending_window
->base
.outer_window
, mon
, 0);
1932 bscallback
->bsc
.window
= pending_window
;
1934 hres
= read_stream_data(bscallback
, stream
);
1936 hres
= async_stop_request(bscallback
);
1938 IBindStatusCallback_OnStopBinding(&bscallback
->bsc
.IBindStatusCallback_iface
, hres
, NULL
);
1943 void channelbsc_set_channel(nsChannelBSC
*This
, nsChannel
*channel
, nsIStreamListener
*listener
, nsISupports
*context
)
1945 nsIHttpChannel_AddRef(&channel
->nsIHttpChannel_iface
);
1946 This
->nschannel
= channel
;
1948 nsIStreamListener_AddRef(listener
);
1949 This
->nslistener
= listener
;
1952 nsISupports_AddRef(context
);
1953 This
->nscontext
= context
;
1956 if(This
->bsc
.request_data
.headers
) {
1959 hres
= parse_headers(This
->bsc
.request_data
.headers
, &channel
->request_headers
);
1960 heap_free(This
->bsc
.request_data
.headers
);
1961 This
->bsc
.request_data
.headers
= NULL
;
1963 WARN("parse_headers failed: %08x\n", hres
);
1969 HTMLOuterWindow
*window
;
1971 } navigate_javascript_task_t
;
1973 static void navigate_javascript_proc(task_t
*_task
)
1975 navigate_javascript_task_t
*task
= (navigate_javascript_task_t
*)_task
;
1976 HTMLOuterWindow
*window
= task
->window
;
1981 task
->window
->readystate
= READYSTATE_COMPLETE
;
1983 hres
= IUri_GetPath(task
->uri
, &code
);
1987 hres
= UrlUnescapeW(code
, NULL
, NULL
, URL_UNESCAPE_INPLACE
);
1989 SysFreeString(code
);
1993 set_download_state(window
->browser
->doc
, 1);
1995 V_VT(&v
) = VT_EMPTY
;
1996 hres
= exec_script(window
->base
.inner_window
, code
, L
"jscript", &v
);
1997 SysFreeString(code
);
1998 if(SUCCEEDED(hres
) && V_VT(&v
) != VT_EMPTY
) {
1999 FIXME("javascirpt URL returned %s\n", debugstr_variant(&v
));
2003 if(window
->browser
->doc
->view_sink
)
2004 IAdviseSink_OnViewChange(window
->browser
->doc
->view_sink
, DVASPECT_CONTENT
, -1);
2006 set_download_state(window
->browser
->doc
, 0);
2009 static void navigate_javascript_task_destr(task_t
*_task
)
2011 navigate_javascript_task_t
*task
= (navigate_javascript_task_t
*)_task
;
2013 IUri_Release(task
->uri
);
2019 HTMLOuterWindow
*window
;
2020 nsChannelBSC
*bscallback
;
2026 static void navigate_proc(task_t
*_task
)
2028 navigate_task_t
*task
= (navigate_task_t
*)_task
;
2031 hres
= set_moniker(task
->window
, task
->mon
, task
->uri
, NULL
, task
->bscallback
, TRUE
);
2032 if(SUCCEEDED(hres
)) {
2033 set_current_mon(task
->window
, task
->bscallback
->bsc
.mon
, task
->flags
);
2034 set_current_uri(task
->window
, task
->uri
);
2035 start_binding(task
->window
->pending_window
, &task
->bscallback
->bsc
, NULL
);
2039 static void navigate_task_destr(task_t
*_task
)
2041 navigate_task_t
*task
= (navigate_task_t
*)_task
;
2043 IBindStatusCallback_Release(&task
->bscallback
->bsc
.IBindStatusCallback_iface
);
2044 IMoniker_Release(task
->mon
);
2045 IUri_Release(task
->uri
);
2049 static HRESULT
navigate_fragment(HTMLOuterWindow
*window
, IUri
*uri
)
2051 nsIDOMLocation
*nslocation
;
2052 nsAString nsfrag_str
;
2057 static const WCHAR selector_formatW
[] = L
"a[id=\"%s\"]";
2059 set_current_uri(window
, uri
);
2061 nsres
= nsIDOMWindow_GetLocation(window
->nswindow
, &nslocation
);
2062 if(FAILED(nsres
) || !nslocation
)
2065 hres
= IUri_GetFragment(uri
, &frag
);
2067 nsIDOMLocation_Release(nslocation
);
2071 nsAString_InitDepend(&nsfrag_str
, frag
);
2072 nsres
= nsIDOMLocation_SetHash(nslocation
, &nsfrag_str
);
2073 nsAString_Finish(&nsfrag_str
);
2074 nsIDOMLocation_Release(nslocation
);
2075 if(NS_FAILED(nsres
))
2076 ERR("SetHash failed: %08x\n", nsres
);
2079 * IE supports scrolling to anchor elements with "#hash" ids (note that '#' is part of the id),
2080 * while Gecko scrolls only to elements with "hash" ids. We scroll the page ourselves if
2081 * a[id="#hash"] element can be found.
2083 selector
= heap_alloc(sizeof(selector_formatW
)+SysStringLen(frag
)*sizeof(WCHAR
));
2085 nsIDOMElement
*nselem
= NULL
;
2086 nsAString selector_str
;
2088 swprintf(selector
, ARRAY_SIZE(selector_formatW
)+SysStringLen(frag
), selector_formatW
, frag
);
2089 nsAString_InitDepend(&selector_str
, selector
);
2090 /* NOTE: Gecko doesn't set result to NULL if there is no match, so nselem must be initialized */
2091 nsres
= nsIDOMHTMLDocument_QuerySelector(window
->base
.inner_window
->doc
->nsdoc
, &selector_str
, &nselem
);
2092 nsAString_Finish(&selector_str
);
2093 heap_free(selector
);
2094 if(NS_SUCCEEDED(nsres
) && nselem
) {
2095 nsIDOMHTMLElement
*html_elem
;
2097 nsres
= nsIDOMElement_QueryInterface(nselem
, &IID_nsIDOMHTMLElement
, (void**)&html_elem
);
2098 nsIDOMElement_Release(nselem
);
2099 if(NS_SUCCEEDED(nsres
)) {
2100 nsIDOMHTMLElement_ScrollIntoView(html_elem
, TRUE
, 1);
2101 nsIDOMHTMLElement_Release(html_elem
);
2106 SysFreeString(frag
);
2108 if(window
->browser
->doc
->doc_object_service
) {
2109 IDocObjectService_FireNavigateComplete2(window
->browser
->doc
->doc_object_service
, &window
->base
.IHTMLWindow2_iface
, 0x10);
2110 IDocObjectService_FireDocumentComplete(window
->browser
->doc
->doc_object_service
, &window
->base
.IHTMLWindow2_iface
, 0);
2117 HRESULT
super_navigate(HTMLOuterWindow
*window
, IUri
*uri
, DWORD flags
, const WCHAR
*headers
, BYTE
*post_data
, DWORD post_data_size
)
2125 uri_nofrag
= get_uri_nofrag(uri
);
2129 if(window
->browser
->doc
->client
&& !(flags
& BINDING_REFRESH
)) {
2130 IOleCommandTarget
*cmdtrg
;
2132 hres
= IOleClientSite_QueryInterface(window
->browser
->doc
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
2133 if(SUCCEEDED(hres
)) {
2137 hres
= IUri_GetDisplayUri(uri_nofrag
, &url_str
);
2138 if(SUCCEEDED(hres
)) {
2139 V_VT(&in
) = VT_BSTR
;
2140 V_BSTR(&in
) = url_str
;
2141 V_VT(&out
) = VT_BOOL
;
2142 V_BOOL(&out
) = VARIANT_TRUE
;
2143 hres
= IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 67, 0, &in
, &out
);
2144 IOleCommandTarget_Release(cmdtrg
);
2147 SysFreeString(url_str
);
2152 if(!(flags
& BINDING_NOFRAG
) && window
->uri_nofrag
&& !post_data_size
) {
2155 hres
= IUri_IsEqual(uri_nofrag
, window
->uri_nofrag
, &eq
);
2156 if(SUCCEEDED(hres
) && eq
) {
2157 IUri_Release(uri_nofrag
);
2158 TRACE("fragment navigate\n");
2159 return navigate_fragment(window
, uri
);
2163 hres
= CreateURLMonikerEx2(NULL
, uri_nofrag
, &mon
, URL_MK_UNIFORM
);
2164 IUri_Release(uri_nofrag
);
2168 /* FIXME: Why not set_ready_state? */
2169 window
->readystate
= READYSTATE_UNINITIALIZED
;
2171 hres
= create_channelbsc(mon
, headers
, post_data
, post_data_size
, TRUE
, &bsc
);
2173 IMoniker_Release(mon
);
2177 prepare_for_binding(&window
->browser
->doc
->basedoc
, mon
, flags
);
2179 hres
= IUri_GetScheme(uri
, &scheme
);
2180 if(SUCCEEDED(hres
) && scheme
== URL_SCHEME_JAVASCRIPT
) {
2181 navigate_javascript_task_t
*task
;
2183 IBindStatusCallback_Release(&bsc
->bsc
.IBindStatusCallback_iface
);
2184 IMoniker_Release(mon
);
2186 task
= heap_alloc(sizeof(*task
));
2188 return E_OUTOFMEMORY
;
2191 window
->readystate
= READYSTATE_COMPLETE
;
2192 if(!(flags
& BINDING_FROMHIST
))
2193 call_docview_84(window
->browser
->doc
);
2196 task
->window
= window
;
2198 hres
= push_task(&task
->header
, navigate_javascript_proc
, navigate_javascript_task_destr
, window
->task_magic
);
2199 }else if(flags
& BINDING_SUBMIT
) {
2200 hres
= set_moniker(window
, mon
, uri
, NULL
, bsc
, TRUE
);
2202 hres
= start_binding(window
->pending_window
, &bsc
->bsc
, NULL
);
2203 IBindStatusCallback_Release(&bsc
->bsc
.IBindStatusCallback_iface
);
2204 IMoniker_Release(mon
);
2206 navigate_task_t
*task
;
2208 task
= heap_alloc(sizeof(*task
));
2210 IBindStatusCallback_Release(&bsc
->bsc
.IBindStatusCallback_iface
);
2211 IMoniker_Release(mon
);
2212 return E_OUTOFMEMORY
;
2215 /* Silently and repeated when real loading starts? */
2216 window
->readystate
= READYSTATE_LOADING
;
2217 if(!(flags
& (BINDING_FROMHIST
|BINDING_REFRESH
)))
2218 call_docview_84(window
->browser
->doc
);
2220 task
->window
= window
;
2221 task
->bscallback
= bsc
;
2222 task
->flags
= flags
;
2227 hres
= push_task(&task
->header
, navigate_proc
, navigate_task_destr
, window
->task_magic
);
2233 HRESULT
navigate_new_window(HTMLOuterWindow
*window
, IUri
*uri
, const WCHAR
*name
, request_data_t
*request_data
, IHTMLWindow2
**ret
)
2235 INewWindowManager
*new_window_mgr
;
2236 BSTR display_uri
, context_url
;
2237 IWebBrowser2
*web_browser
;
2238 IHTMLWindow2
*new_window
;
2243 if(!window
->browser
)
2244 return E_UNEXPECTED
;
2246 if (window
->browser
->doc
->client
) {
2247 hres
= do_query_service((IUnknown
*)window
->browser
->doc
->client
, &SID_SNewWindowManager
,
2248 &IID_INewWindowManager
, (void**)&new_window_mgr
);
2250 FIXME("No INewWindowManager\n");
2254 hres
= IUri_GetDisplayUri(window
->uri_nofrag
, &context_url
);
2258 hres
= IUri_GetDisplayUri(uri
, &display_uri
);
2260 SysFreeString(context_url
);
2264 hres
= INewWindowManager_EvaluateNewWindow(new_window_mgr
, display_uri
, name
, context_url
,
2265 NULL
, FALSE
, window
->browser
->doc
->has_popup
? 0 : NWMF_FIRST
, 0);
2266 window
->browser
->doc
->has_popup
= TRUE
;
2267 SysFreeString(display_uri
);
2268 SysFreeString(context_url
);
2269 INewWindowManager_Release(new_window_mgr
);
2279 hres
= create_channelbsc(NULL
, request_data
->headers
,
2280 request_data
->post_data
, request_data
->post_data_len
, FALSE
,
2283 hres
= create_channelbsc(NULL
, NULL
, NULL
, 0, FALSE
, &bsc
);
2287 hres
= CreateAsyncBindCtx(0, &bsc
->bsc
.IBindStatusCallback_iface
, NULL
, &bind_ctx
);
2289 IBindStatusCallback_Release(&bsc
->bsc
.IBindStatusCallback_iface
);
2293 hres
= CoCreateInstance(&CLSID_InternetExplorer
, NULL
, CLSCTX_LOCAL_SERVER
,
2294 &IID_IWebBrowser2
, (void**)&web_browser
);
2295 if(SUCCEEDED(hres
)) {
2296 ITargetFramePriv2
*target_frame_priv
;
2298 hres
= IWebBrowser2_QueryInterface(web_browser
, &IID_ITargetFramePriv2
, (void**)&target_frame_priv
);
2299 if(SUCCEEDED(hres
)) {
2300 hres
= ITargetFramePriv2_AggregatedNavigation2(target_frame_priv
,
2301 HLNF_DISABLEWINDOWRESTRICTIONS
|HLNF_OPENINNEWWINDOW
, bind_ctx
, &bsc
->bsc
.IBindStatusCallback_iface
,
2303 ITargetFramePriv2_Release(target_frame_priv
);
2306 hres
= do_query_service((IUnknown
*)web_browser
, &SID_SHTMLWindow
, &IID_IHTMLWindow2
, (void**)&new_window
);
2309 IWebBrowser2_Quit(web_browser
);
2310 IWebBrowser2_Release(web_browser
);
2313 WARN("Could not create InternetExplorer instance: %08x\n", hres
);
2316 IBindStatusCallback_Release(&bsc
->bsc
.IBindStatusCallback_iface
);
2317 IBindCtx_Release(bind_ctx
);
2321 IWebBrowser2_put_Visible(web_browser
, VARIANT_TRUE
);
2322 IWebBrowser2_Release(web_browser
);
2327 IHTMLWindow2_Release(new_window
);
2331 HRESULT
hlink_frame_navigate(HTMLDocument
*doc
, LPCWSTR url
, nsChannel
*nschannel
, DWORD hlnf
, BOOL
*cancel
)
2333 IHlinkFrame
*hlink_frame
;
2334 nsChannelBSC
*callback
;
2342 hres
= do_query_service((IUnknown
*)doc
->doc_obj
->client
, &IID_IHlinkFrame
, &IID_IHlinkFrame
,
2343 (void**)&hlink_frame
);
2347 hres
= create_channelbsc(NULL
, NULL
, NULL
, 0, FALSE
, &callback
);
2349 IHlinkFrame_Release(hlink_frame
);
2354 read_post_data_stream(nschannel
->post_data_stream
, nschannel
->post_data_contains_headers
,
2355 &nschannel
->request_headers
, &callback
->bsc
.request_data
);
2357 hres
= CreateAsyncBindCtx(0, &callback
->bsc
.IBindStatusCallback_iface
, NULL
, &bindctx
);
2359 hres
= CoCreateInstance(&CLSID_StdHlink
, NULL
, CLSCTX_INPROC_SERVER
,
2360 &IID_IHlink
, (LPVOID
*)&hlink
);
2363 hres
= CreateURLMoniker(NULL
, url
, &mon
);
2365 if(SUCCEEDED(hres
)) {
2366 IHlink_SetMonikerReference(hlink
, HLINKSETF_TARGET
, mon
, NULL
);
2368 if(hlnf
& HLNF_OPENINNEWWINDOW
) {
2369 IHlink_SetTargetFrameName(hlink
, L
"_blank"); /* FIXME */
2372 hres
= IHlinkFrame_Navigate(hlink_frame
, hlnf
, bindctx
,
2373 &callback
->bsc
.IBindStatusCallback_iface
, hlink
);
2374 IMoniker_Release(mon
);
2375 *cancel
= hres
== S_OK
;
2379 IHlinkFrame_Release(hlink_frame
);
2380 IBindCtx_Release(bindctx
);
2381 IBindStatusCallback_Release(&callback
->bsc
.IBindStatusCallback_iface
);
2385 static HRESULT
navigate_uri(HTMLOuterWindow
*window
, IUri
*uri
, const WCHAR
*display_uri
, const request_data_t
*request_data
,
2391 TRACE("%s\n", debugstr_w(display_uri
));
2393 if(!window
->browser
)
2394 return E_UNEXPECTED
;
2396 if(window
->browser
->doc
->webbrowser
) {
2397 DWORD post_data_len
= request_data
? request_data
->post_data_len
: 0;
2398 void *post_data
= post_data_len
? request_data
->post_data
: NULL
;
2399 const WCHAR
*headers
= request_data
? request_data
->headers
: NULL
;
2401 if(!(flags
& BINDING_REFRESH
)) {
2402 BSTR frame_name
= NULL
;
2403 BOOL cancel
= FALSE
;
2405 if(!is_main_content_window(window
)) {
2406 hres
= IHTMLWindow2_get_name(&window
->base
.IHTMLWindow2_iface
, &frame_name
);
2411 hres
= IDocObjectService_FireBeforeNavigate2(window
->browser
->doc
->doc_object_service
, NULL
, display_uri
, 0x40,
2412 frame_name
, post_data
, post_data_len
? post_data_len
+1 : 0, headers
, TRUE
, &cancel
);
2413 SysFreeString(frame_name
);
2414 if(SUCCEEDED(hres
) && cancel
) {
2415 TRACE("Navigation canceled\n");
2420 if(is_main_content_window(window
))
2421 return super_navigate(window
, uri
, flags
, headers
, post_data
, post_data_len
);
2424 if(is_main_content_window(window
)) {
2427 hres
= hlink_frame_navigate(&window
->base
.inner_window
->doc
->basedoc
, display_uri
, NULL
, 0, &cancel
);
2432 TRACE("Navigation handled by hlink frame\n");
2437 hres
= create_doc_uri(uri
, &nsuri
);
2441 hres
= load_nsuri(window
, nsuri
, request_data
? request_data
->post_stream
: NULL
, NULL
, LOAD_FLAGS_NONE
);
2442 nsISupports_Release((nsISupports
*)nsuri
);
2446 HRESULT
load_uri(HTMLOuterWindow
*window
, IUri
*uri
, DWORD flags
)
2451 hres
= IUri_GetDisplayUri(uri
, &display_uri
);
2455 hres
= navigate_uri(window
, uri
, display_uri
, NULL
, flags
);
2456 SysFreeString(display_uri
);
2460 static HRESULT
translate_uri(HTMLOuterWindow
*window
, IUri
*orig_uri
, BSTR
*ret_display_uri
, IUri
**ret_uri
)
2466 hres
= IUri_GetDisplayUri(orig_uri
, &display_uri
);
2470 if(window
->browser
->doc
->hostui
) {
2471 OLECHAR
*translated_url
= NULL
;
2473 hres
= IDocHostUIHandler_TranslateUrl(window
->browser
->doc
->hostui
, 0, display_uri
,
2475 if(hres
== S_OK
&& translated_url
) {
2476 TRACE("%08x %s -> %s\n", hres
, debugstr_w(display_uri
), debugstr_w(translated_url
));
2477 SysFreeString(display_uri
);
2478 hres
= create_uri(translated_url
, 0, &uri
);
2479 CoTaskMemFree(translated_url
);
2483 hres
= IUri_GetDisplayUri(uri
, &display_uri
);
2492 IUri_AddRef(orig_uri
);
2496 *ret_display_uri
= display_uri
;
2501 HRESULT
submit_form(HTMLOuterWindow
*window
, const WCHAR
*target
, IUri
*submit_uri
, nsIInputStream
*post_stream
)
2503 request_data_t request_data
= {NULL
};
2506 hres
= read_post_data_stream(post_stream
, TRUE
, NULL
, &request_data
);
2514 window
->readystate_locked
++;
2516 hres
= translate_uri(window
, submit_uri
, &display_uri
, &uri
);
2517 if(SUCCEEDED(hres
)) {
2518 hres
= navigate_uri(window
, uri
, display_uri
, &request_data
, BINDING_NAVIGATED
|BINDING_SUBMIT
);
2520 SysFreeString(display_uri
);
2523 window
->readystate_locked
--;
2525 hres
= navigate_new_window(window
, submit_uri
, target
, &request_data
, NULL
);
2527 release_request_data(&request_data
);
2531 HRESULT
navigate_url(HTMLOuterWindow
*window
, const WCHAR
*new_url
, IUri
*base_uri
, DWORD flags
)
2533 IUri
*uri
, *nav_uri
;
2537 if(new_url
&& base_uri
)
2538 hres
= CoInternetCombineUrlEx(base_uri
, new_url
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
2541 hres
= create_uri(new_url
, 0, &nav_uri
);
2545 hres
= translate_uri(window
, nav_uri
, &display_uri
, &uri
);
2546 IUri_Release(nav_uri
);
2550 hres
= navigate_uri(window
, uri
, display_uri
, NULL
, flags
);
2552 SysFreeString(display_uri
);