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 static const WCHAR emptyW
[] = {0};
50 static const WCHAR text_htmlW
[] = {'t','e','x','t','/','h','t','m','l',0};
52 struct nsProtocolStream
{
53 nsIInputStream nsIInputStream_iface
;
61 static inline nsProtocolStream
*impl_from_nsIInputStream(nsIInputStream
*iface
)
63 return CONTAINING_RECORD(iface
, nsProtocolStream
, nsIInputStream_iface
);
66 static nsresult NSAPI
nsInputStream_QueryInterface(nsIInputStream
*iface
, nsIIDRef riid
,
69 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
73 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
74 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
75 *result
= &This
->nsIInputStream_iface
;
76 }else if(IsEqualGUID(&IID_nsIInputStream
, riid
)) {
77 TRACE("(%p)->(IID_nsIInputStream %p)\n", This
, result
);
78 *result
= &This
->nsIInputStream_iface
;
82 nsIInputStream_AddRef(&This
->nsIInputStream_iface
);
86 WARN("unsupported interface %s\n", debugstr_guid(riid
));
87 return NS_NOINTERFACE
;
90 static nsrefcnt NSAPI
nsInputStream_AddRef(nsIInputStream
*iface
)
92 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
93 LONG ref
= InterlockedIncrement(&This
->ref
);
95 TRACE("(%p) ref=%d\n", This
, ref
);
101 static nsrefcnt NSAPI
nsInputStream_Release(nsIInputStream
*iface
)
103 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
104 LONG ref
= InterlockedDecrement(&This
->ref
);
106 TRACE("(%p) ref=%d\n", This
, ref
);
114 static nsresult NSAPI
nsInputStream_Close(nsIInputStream
*iface
)
116 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
117 FIXME("(%p)\n", This
);
118 return NS_ERROR_NOT_IMPLEMENTED
;
121 static nsresult NSAPI
nsInputStream_Available(nsIInputStream
*iface
, UINT64
*_retval
)
123 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
124 FIXME("(%p)->(%p)\n", This
, _retval
);
125 return NS_ERROR_NOT_IMPLEMENTED
;
128 static nsresult NSAPI
nsInputStream_Read(nsIInputStream
*iface
, char *aBuf
, UINT32 aCount
,
131 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
134 TRACE("(%p)->(%p %d %p)\n", This
, aBuf
, aCount
, _retval
);
136 if(read
> This
->buf_size
)
137 read
= This
->buf_size
;
140 memcpy(aBuf
, This
->buf
, read
);
141 if(read
< This
->buf_size
)
142 memmove(This
->buf
, This
->buf
+read
, This
->buf_size
-read
);
143 This
->buf_size
-= read
;
150 static nsresult NSAPI
nsInputStream_ReadSegments(nsIInputStream
*iface
,
151 nsresult (WINAPI
*aWriter
)(nsIInputStream
*,void*,const char*,UINT32
,UINT32
,UINT32
*),
152 void *aClousure
, UINT32 aCount
, UINT32
*_retval
)
154 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
158 TRACE("(%p)->(%p %p %d %p)\n", This
, aWriter
, aClousure
, aCount
, _retval
);
163 if(aCount
> This
->buf_size
)
164 aCount
= This
->buf_size
;
166 nsres
= aWriter(&This
->nsIInputStream_iface
, aClousure
, This
->buf
, 0, aCount
, &written
);
168 TRACE("aWriter failed: %08x\n", nsres
);
169 else if(written
!= This
->buf_size
)
170 FIXME("written %d != buf_size %d\n", written
, This
->buf_size
);
172 This
->buf_size
-= written
;
178 static nsresult NSAPI
nsInputStream_IsNonBlocking(nsIInputStream
*iface
, cpp_bool
*_retval
)
180 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
181 FIXME("(%p)->(%p)\n", This
, _retval
);
182 return NS_ERROR_NOT_IMPLEMENTED
;
185 static const nsIInputStreamVtbl nsInputStreamVtbl
= {
186 nsInputStream_QueryInterface
,
187 nsInputStream_AddRef
,
188 nsInputStream_Release
,
190 nsInputStream_Available
,
192 nsInputStream_ReadSegments
,
193 nsInputStream_IsNonBlocking
196 static nsProtocolStream
*create_nsprotocol_stream(void)
198 nsProtocolStream
*ret
;
200 ret
= heap_alloc(sizeof(nsProtocolStream
));
204 ret
->nsIInputStream_iface
.lpVtbl
= &nsInputStreamVtbl
;
211 static void release_request_data(request_data_t
*request_data
)
213 if(request_data
->post_stream
)
214 nsIInputStream_Release(request_data
->post_stream
);
215 heap_free(request_data
->headers
);
216 if(request_data
->post_data
)
217 GlobalFree(request_data
->post_data
);
220 static inline BSCallback
*impl_from_IBindStatusCallback(IBindStatusCallback
*iface
)
222 return CONTAINING_RECORD(iface
, BSCallback
, IBindStatusCallback_iface
);
225 static HRESULT WINAPI
BindStatusCallback_QueryInterface(IBindStatusCallback
*iface
,
226 REFIID riid
, void **ppv
)
228 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
231 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
232 TRACE("(%p)->(IID_IUnknown, %p)\n", This
, ppv
);
233 *ppv
= &This
->IBindStatusCallback_iface
;
234 }else if(IsEqualGUID(&IID_IBindStatusCallback
, riid
)) {
235 TRACE("(%p)->(IID_IBindStatusCallback, %p)\n", This
, ppv
);
236 *ppv
= &This
->IBindStatusCallback_iface
;
237 }else if(IsEqualGUID(&IID_IServiceProvider
, riid
)) {
238 TRACE("(%p)->(IID_IServiceProvider %p)\n", This
, ppv
);
239 *ppv
= &This
->IServiceProvider_iface
;
240 }else if(IsEqualGUID(&IID_IHttpNegotiate
, riid
)) {
241 TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This
, ppv
);
242 *ppv
= &This
->IHttpNegotiate2_iface
;
243 }else if(IsEqualGUID(&IID_IHttpNegotiate2
, riid
)) {
244 TRACE("(%p)->(IID_IHttpNegotiate2 %p)\n", This
, ppv
);
245 *ppv
= &This
->IHttpNegotiate2_iface
;
246 }else if(IsEqualGUID(&IID_IInternetBindInfo
, riid
)) {
247 TRACE("(%p)->(IID_IInternetBindInfo %p)\n", This
, ppv
);
248 *ppv
= &This
->IInternetBindInfo_iface
;
249 }else if(IsEqualGUID(&IID_IBindCallbackRedirect
, riid
)) {
250 TRACE("(%p)->(IID_IBindCallbackRedirect %p)\n", This
, ppv
);
251 *ppv
= &This
->IBindCallbackRedirect_iface
;
255 IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
259 TRACE("Unsupported riid = %s\n", debugstr_guid(riid
));
260 return E_NOINTERFACE
;
263 static ULONG WINAPI
BindStatusCallback_AddRef(IBindStatusCallback
*iface
)
265 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
266 LONG ref
= InterlockedIncrement(&This
->ref
);
268 TRACE("(%p) ref = %d\n", This
, ref
);
273 static ULONG WINAPI
BindStatusCallback_Release(IBindStatusCallback
*iface
)
275 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
276 LONG ref
= InterlockedDecrement(&This
->ref
);
278 TRACE("(%p) ref = %d\n", This
, ref
);
281 release_request_data(&This
->request_data
);
283 IMoniker_Release(This
->mon
);
285 IBinding_Release(This
->binding
);
286 list_remove(&This
->entry
);
287 list_init(&This
->entry
);
289 This
->vtbl
->destroy(This
);
295 static HRESULT WINAPI
BindStatusCallback_OnStartBinding(IBindStatusCallback
*iface
,
296 DWORD dwReserved
, IBinding
*pbind
)
298 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
300 TRACE("(%p)->(%d %p)\n", This
, dwReserved
, pbind
);
302 IBinding_AddRef(pbind
);
303 This
->binding
= pbind
;
306 list_add_head(&This
->window
->bindings
, &This
->entry
);
308 return This
->vtbl
->start_binding(This
);
311 static HRESULT WINAPI
BindStatusCallback_GetPriority(IBindStatusCallback
*iface
, LONG
*pnPriority
)
313 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
314 FIXME("(%p)->(%p)\n", This
, pnPriority
);
318 static HRESULT WINAPI
BindStatusCallback_OnLowResource(IBindStatusCallback
*iface
, DWORD reserved
)
320 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
321 FIXME("(%p)->(%d)\n", This
, reserved
);
325 static HRESULT WINAPI
BindStatusCallback_OnProgress(IBindStatusCallback
*iface
, ULONG ulProgress
,
326 ULONG ulProgressMax
, ULONG ulStatusCode
, LPCWSTR szStatusText
)
328 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
330 TRACE("%p)->(%u %u %u %s)\n", This
, ulProgress
, ulProgressMax
, ulStatusCode
,
331 debugstr_w(szStatusText
));
333 return This
->vtbl
->on_progress(This
, ulStatusCode
, szStatusText
);
336 static HRESULT WINAPI
BindStatusCallback_OnStopBinding(IBindStatusCallback
*iface
,
337 HRESULT hresult
, LPCWSTR szError
)
339 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
342 TRACE("(%p)->(%08x %s)\n", This
, hresult
, debugstr_w(szError
));
344 /* NOTE: IE7 calls GetBindResult here */
346 hres
= This
->vtbl
->stop_binding(This
, hresult
);
349 IBinding_Release(This
->binding
);
350 This
->binding
= NULL
;
354 IMoniker_Release(This
->mon
);
358 list_remove(&This
->entry
);
359 list_init(&This
->entry
);
365 static HRESULT WINAPI
BindStatusCallback_GetBindInfo(IBindStatusCallback
*iface
,
366 DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
368 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
371 TRACE("(%p)->(%p %p)\n", This
, grfBINDF
, pbindinfo
);
373 if(!This
->bindinfo_ready
) {
376 hres
= This
->vtbl
->init_bindinfo(This
);
380 This
->bindinfo_ready
= TRUE
;
383 *grfBINDF
= This
->bindf
;
385 size
= pbindinfo
->cbSize
;
386 memset(pbindinfo
, 0, size
);
387 pbindinfo
->cbSize
= size
;
389 pbindinfo
->cbstgmedData
= This
->request_data
.post_data_len
;
390 pbindinfo
->dwCodePage
= CP_UTF8
;
391 pbindinfo
->dwOptions
= This
->bindinfo_options
;
393 if(This
->request_data
.post_data_len
) {
394 pbindinfo
->dwBindVerb
= BINDVERB_POST
;
396 pbindinfo
->stgmedData
.tymed
= TYMED_HGLOBAL
;
397 pbindinfo
->stgmedData
.u
.hGlobal
= This
->request_data
.post_data
;
398 pbindinfo
->stgmedData
.pUnkForRelease
= (IUnknown
*)&This
->IBindStatusCallback_iface
;
399 IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
405 static HRESULT WINAPI
BindStatusCallback_OnDataAvailable(IBindStatusCallback
*iface
,
406 DWORD grfBSCF
, DWORD dwSize
, FORMATETC
*pformatetc
, STGMEDIUM
*pstgmed
)
408 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
410 TRACE("(%p)->(%08x %d %p %p)\n", This
, grfBSCF
, dwSize
, pformatetc
, pstgmed
);
412 return This
->vtbl
->read_data(This
, pstgmed
->u
.pstm
);
415 static HRESULT WINAPI
BindStatusCallback_OnObjectAvailable(IBindStatusCallback
*iface
,
416 REFIID riid
, IUnknown
*punk
)
418 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
419 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), punk
);
423 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl
= {
424 BindStatusCallback_QueryInterface
,
425 BindStatusCallback_AddRef
,
426 BindStatusCallback_Release
,
427 BindStatusCallback_OnStartBinding
,
428 BindStatusCallback_GetPriority
,
429 BindStatusCallback_OnLowResource
,
430 BindStatusCallback_OnProgress
,
431 BindStatusCallback_OnStopBinding
,
432 BindStatusCallback_GetBindInfo
,
433 BindStatusCallback_OnDataAvailable
,
434 BindStatusCallback_OnObjectAvailable
437 static inline BSCallback
*impl_from_IHttpNegotiate2(IHttpNegotiate2
*iface
)
439 return CONTAINING_RECORD(iface
, BSCallback
, IHttpNegotiate2_iface
);
442 static HRESULT WINAPI
HttpNegotiate_QueryInterface(IHttpNegotiate2
*iface
,
443 REFIID riid
, void **ppv
)
445 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
446 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
449 static ULONG WINAPI
HttpNegotiate_AddRef(IHttpNegotiate2
*iface
)
451 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
452 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
455 static ULONG WINAPI
HttpNegotiate_Release(IHttpNegotiate2
*iface
)
457 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
458 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
461 static HRESULT WINAPI
HttpNegotiate_BeginningTransaction(IHttpNegotiate2
*iface
,
462 LPCWSTR szURL
, LPCWSTR szHeaders
, DWORD dwReserved
, LPWSTR
*pszAdditionalHeaders
)
464 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
467 TRACE("(%p)->(%s %s %d %p)\n", This
, debugstr_w(szURL
), debugstr_w(szHeaders
),
468 dwReserved
, pszAdditionalHeaders
);
470 *pszAdditionalHeaders
= NULL
;
472 hres
= This
->vtbl
->beginning_transaction(This
, pszAdditionalHeaders
);
476 if(This
->request_data
.headers
) {
479 size
= (lstrlenW(This
->request_data
.headers
)+1)*sizeof(WCHAR
);
480 *pszAdditionalHeaders
= CoTaskMemAlloc(size
);
481 if(!*pszAdditionalHeaders
)
482 return E_OUTOFMEMORY
;
483 memcpy(*pszAdditionalHeaders
, This
->request_data
.headers
, size
);
489 static HRESULT WINAPI
HttpNegotiate_OnResponse(IHttpNegotiate2
*iface
, DWORD dwResponseCode
,
490 LPCWSTR szResponseHeaders
, LPCWSTR szRequestHeaders
, LPWSTR
*pszAdditionalRequestHeaders
)
492 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
494 TRACE("(%p)->(%d %s %s %p)\n", This
, dwResponseCode
, debugstr_w(szResponseHeaders
),
495 debugstr_w(szRequestHeaders
), pszAdditionalRequestHeaders
);
497 return This
->vtbl
->on_response(This
, dwResponseCode
, szResponseHeaders
);
500 static HRESULT WINAPI
HttpNegotiate_GetRootSecurityId(IHttpNegotiate2
*iface
,
501 BYTE
*pbSecurityId
, DWORD
*pcbSecurityId
, DWORD_PTR dwReserved
)
503 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
504 TRACE("(%p)->(%p %p %ld)\n", This
, pbSecurityId
, pcbSecurityId
, dwReserved
);
505 return E_NOTIMPL
; /* FIXME */
508 static const IHttpNegotiate2Vtbl HttpNegotiate2Vtbl
= {
509 HttpNegotiate_QueryInterface
,
510 HttpNegotiate_AddRef
,
511 HttpNegotiate_Release
,
512 HttpNegotiate_BeginningTransaction
,
513 HttpNegotiate_OnResponse
,
514 HttpNegotiate_GetRootSecurityId
517 static inline BSCallback
*impl_from_IInternetBindInfo(IInternetBindInfo
*iface
)
519 return CONTAINING_RECORD(iface
, BSCallback
, IInternetBindInfo_iface
);
522 static HRESULT WINAPI
InternetBindInfo_QueryInterface(IInternetBindInfo
*iface
,
523 REFIID riid
, void **ppv
)
525 BSCallback
*This
= impl_from_IInternetBindInfo(iface
);
526 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
529 static ULONG WINAPI
InternetBindInfo_AddRef(IInternetBindInfo
*iface
)
531 BSCallback
*This
= impl_from_IInternetBindInfo(iface
);
532 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
535 static ULONG WINAPI
InternetBindInfo_Release(IInternetBindInfo
*iface
)
537 BSCallback
*This
= impl_from_IInternetBindInfo(iface
);
538 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
541 static HRESULT WINAPI
InternetBindInfo_GetBindInfo(IInternetBindInfo
*iface
,
542 DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
544 BSCallback
*This
= impl_from_IInternetBindInfo(iface
);
545 FIXME("(%p)->(%p %p)\n", This
, grfBINDF
, pbindinfo
);
549 static HRESULT WINAPI
InternetBindInfo_GetBindString(IInternetBindInfo
*iface
,
550 ULONG ulStringType
, LPOLESTR
*ppwzStr
, ULONG cEl
, ULONG
*pcElFetched
)
552 BSCallback
*This
= impl_from_IInternetBindInfo(iface
);
553 FIXME("(%p)->(%u %p %u %p)\n", This
, ulStringType
, ppwzStr
, cEl
, pcElFetched
);
557 static const IInternetBindInfoVtbl InternetBindInfoVtbl
= {
558 InternetBindInfo_QueryInterface
,
559 InternetBindInfo_AddRef
,
560 InternetBindInfo_Release
,
561 InternetBindInfo_GetBindInfo
,
562 InternetBindInfo_GetBindString
565 static inline BSCallback
*impl_from_IBindCallbackRedirect(IBindCallbackRedirect
*iface
)
567 return CONTAINING_RECORD(iface
, BSCallback
, IBindCallbackRedirect_iface
);
570 static HRESULT WINAPI
BindCallbackRedirect_QueryInterface(IBindCallbackRedirect
*iface
, REFIID riid
, void **ppv
)
572 BSCallback
*This
= impl_from_IBindCallbackRedirect(iface
);
573 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
576 static ULONG WINAPI
BindCallbackRedirect_AddRef(IBindCallbackRedirect
*iface
)
578 BSCallback
*This
= impl_from_IBindCallbackRedirect(iface
);
579 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
582 static ULONG WINAPI
BindCallbackRedirect_Release(IBindCallbackRedirect
*iface
)
584 BSCallback
*This
= impl_from_IBindCallbackRedirect(iface
);
585 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
588 static HRESULT WINAPI
BindCallbackRedirect_Redirect(IBindCallbackRedirect
*iface
, const WCHAR
*url
, VARIANT_BOOL
*vbCancel
)
590 BSCallback
*This
= impl_from_IBindCallbackRedirect(iface
);
591 GeckoBrowser
*browser
;
593 BSTR frame_name
= NULL
;
596 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(url
), vbCancel
);
598 if(This
->window
&& This
->window
->base
.outer_window
&& (browser
= This
->window
->base
.outer_window
->browser
)
599 && browser
->doc
->doc_object_service
) {
600 if(is_main_content_window(This
->window
->base
.outer_window
)) {
601 hres
= IHTMLWindow2_get_name(&This
->window
->base
.IHTMLWindow2_iface
, &frame_name
);
606 hres
= IDocObjectService_FireBeforeNavigate2(browser
->doc
->doc_object_service
, NULL
, url
, 0x40,
607 frame_name
, NULL
, 0, NULL
, TRUE
, &cancel
);
608 SysFreeString(frame_name
);
611 *vbCancel
= variant_bool(cancel
);
615 static const IBindCallbackRedirectVtbl BindCallbackRedirectVtbl
= {
616 BindCallbackRedirect_QueryInterface
,
617 BindCallbackRedirect_AddRef
,
618 BindCallbackRedirect_Release
,
619 BindCallbackRedirect_Redirect
622 static inline BSCallback
*impl_from_IServiceProvider(IServiceProvider
*iface
)
624 return CONTAINING_RECORD(iface
, BSCallback
, IServiceProvider_iface
);
627 static HRESULT WINAPI
BSCServiceProvider_QueryInterface(IServiceProvider
*iface
,
628 REFIID riid
, void **ppv
)
630 BSCallback
*This
= impl_from_IServiceProvider(iface
);
631 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
634 static ULONG WINAPI
BSCServiceProvider_AddRef(IServiceProvider
*iface
)
636 BSCallback
*This
= impl_from_IServiceProvider(iface
);
637 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
640 static ULONG WINAPI
BSCServiceProvider_Release(IServiceProvider
*iface
)
642 BSCallback
*This
= impl_from_IServiceProvider(iface
);
643 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
646 static HRESULT WINAPI
BSCServiceProvider_QueryService(IServiceProvider
*iface
,
647 REFGUID guidService
, REFIID riid
, void **ppv
)
649 BSCallback
*This
= impl_from_IServiceProvider(iface
);
651 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_guid(guidService
), debugstr_guid(riid
), ppv
);
653 if(This
->window
&& IsEqualGUID(guidService
, &IID_IWindowForBindingUI
))
654 return IServiceProvider_QueryService(&This
->window
->base
.IServiceProvider_iface
, guidService
, riid
, ppv
);
655 return E_NOINTERFACE
;
658 static const IServiceProviderVtbl ServiceProviderVtbl
= {
659 BSCServiceProvider_QueryInterface
,
660 BSCServiceProvider_AddRef
,
661 BSCServiceProvider_Release
,
662 BSCServiceProvider_QueryService
665 void init_bscallback(BSCallback
*This
, const BSCallbackVtbl
*vtbl
, IMoniker
*mon
, DWORD bindf
)
667 This
->IBindStatusCallback_iface
.lpVtbl
= &BindStatusCallbackVtbl
;
668 This
->IServiceProvider_iface
.lpVtbl
= &ServiceProviderVtbl
;
669 This
->IHttpNegotiate2_iface
.lpVtbl
= &HttpNegotiate2Vtbl
;
670 This
->IInternetBindInfo_iface
.lpVtbl
= &InternetBindInfoVtbl
;
671 This
->IBindCallbackRedirect_iface
.lpVtbl
= &BindCallbackRedirectVtbl
;
675 This
->bindinfo_options
= BINDINFO_OPTIONS_USE_IE_ENCODING
;
676 This
->bom
= BOM_NONE
;
678 list_init(&This
->entry
);
681 IMoniker_AddRef(mon
);
685 HRESULT
read_stream(BSCallback
*This
, IStream
*stream
, void *buf
, DWORD size
, DWORD
*ret_size
)
687 DWORD read_size
= 0, skip
=0;
691 hres
= IStream_Read(stream
, buf
, size
, &read_size
);
693 if(!This
->read
&& This
->bom
== BOM_NONE
) {
694 if(read_size
>= 2 && data
[0] == 0xff && data
[1] == 0xfe) {
695 This
->bom
= BOM_UTF16
;
697 }else if(read_size
>= 3 && data
[0] == 0xef && data
[1] == 0xbb && data
[2] == 0xbf) {
698 This
->bom
= BOM_UTF8
;
704 memmove(data
, data
+skip
, read_size
);
708 This
->read
+= read_size
;
709 *ret_size
= read_size
;
713 static void parse_content_type(nsChannelBSC
*This
, const WCHAR
*value
)
718 static const WCHAR charsetW
[] = {'c','h','a','r','s','e','t','='};
720 ptr
= wcschr(value
, ';');
725 while(*ptr
&& iswspace(*ptr
))
728 len
= lstrlenW(value
);
729 if(ptr
+ ARRAY_SIZE(charsetW
) < value
+len
&& !wcsnicmp(ptr
, charsetW
, ARRAY_SIZE(charsetW
))) {
730 size_t charset_len
, lena
;
731 nsACString charset_str
;
732 const WCHAR
*charset
;
735 ptr
+= ARRAY_SIZE(charsetW
);
738 FIXME("Quoted value\n");
742 while(*ptr
&& *ptr
!= ',')
744 charset_len
= ptr
-charset
;
747 lena
= WideCharToMultiByte(CP_ACP
, 0, charset
, charset_len
, NULL
, 0, NULL
, NULL
);
748 charseta
= heap_alloc(lena
+1);
752 WideCharToMultiByte(CP_ACP
, 0, charset
, charset_len
, charseta
, lena
, NULL
, NULL
);
755 nsACString_InitDepend(&charset_str
, charseta
);
756 nsIHttpChannel_SetContentCharset(&This
->nschannel
->nsIHttpChannel_iface
, &charset_str
);
757 nsACString_Finish(&charset_str
);
760 FIXME("unhandled: %s\n", debugstr_wn(ptr
, len
- (ptr
-value
)));
764 static HRESULT
parse_headers(const WCHAR
*headers
, struct list
*headers_list
)
766 const WCHAR
*header
, *header_end
, *colon
, *value
;
771 if(header
[0] == '\r' && header
[1] == '\n' && !header
[2])
773 for(colon
= header
; *colon
&& *colon
!= ':' && *colon
!= '\r'; colon
++);
783 for(header_end
= value
+1; *header_end
&& *header_end
!= '\r'; header_end
++);
785 hres
= set_http_header(headers_list
, header
, colon
-header
, value
, header_end
-value
);
790 if(header
[0] == '\r' && header
[1] == '\n')
797 static HRESULT
process_response_headers(nsChannelBSC
*This
, const WCHAR
*headers
)
802 static const WCHAR content_typeW
[] = {'c','o','n','t','e','n','t','-','t','y','p','e',0};
804 hres
= parse_headers(headers
, &This
->nschannel
->response_headers
);
808 LIST_FOR_EACH_ENTRY(iter
, &This
->nschannel
->response_headers
, http_header_t
, entry
) {
809 if(!wcsicmp(iter
->header
, content_typeW
))
810 parse_content_type(This
, iter
->data
);
816 static void query_http_info(nsChannelBSC
*This
, IWinInetHttpInfo
*wininet_info
)
822 IWinInetHttpInfo_QueryInfo(wininet_info
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &len
, NULL
, NULL
);
826 buf
= heap_alloc(len
);
830 IWinInetHttpInfo_QueryInfo(wininet_info
, HTTP_QUERY_RAW_HEADERS_CRLF
, buf
, &len
, NULL
, NULL
);
836 ptr
= wcschr(buf
, '\r');
837 if(ptr
&& ptr
[1] == '\n') {
839 process_response_headers(This
, ptr
);
845 HRESULT
start_binding(HTMLInnerWindow
*inner_window
, BSCallback
*bscallback
, IBindCtx
*bctx
)
850 TRACE("(%p %p %p)\n", inner_window
, bscallback
, bctx
);
852 bscallback
->window
= inner_window
;
854 /* NOTE: IE7 calls IsSystemMoniker here*/
857 hres
= RegisterBindStatusCallback(bctx
, &bscallback
->IBindStatusCallback_iface
, NULL
, 0);
859 IBindCtx_AddRef(bctx
);
861 hres
= CreateAsyncBindCtx(0, &bscallback
->IBindStatusCallback_iface
, NULL
, &bctx
);
865 bscallback
->window
= NULL
;
869 hres
= IMoniker_BindToStorage(bscallback
->mon
, bctx
, NULL
, &IID_IStream
, (void**)&str
);
870 IBindCtx_Release(bctx
);
872 WARN("BindToStorage failed: %08x\n", hres
);
873 bscallback
->window
= NULL
;
878 IStream_Release(str
);
883 static HRESULT
read_post_data_stream(nsIInputStream
*stream
, BOOL contains_headers
, struct list
*headers_list
,
884 request_data_t
*request_data
)
886 nsISeekableStream
*seekable_stream
;
887 UINT64 available
= 0;
889 char *data
, *post_data
;
896 nsres
= nsIInputStream_Available(stream
, &available
);
900 post_data
= data
= GlobalAlloc(0, available
+1);
902 return E_OUTOFMEMORY
;
904 nsres
= nsIInputStream_Read(stream
, data
, available
, &data_len
);
905 if(NS_FAILED(nsres
)) {
910 if(contains_headers
) {
911 if(data_len
>= 2 && data
[0] == '\r' && data
[1] == '\n') {
919 post_data
+= data_len
;
920 for(ptr
= data
; ptr
+4 < data
+data_len
; ptr
++) {
921 if(!memcmp(ptr
, "\r\n\r\n", 4)) {
928 data_len
-= post_data
-data
;
930 size
= MultiByteToWideChar(CP_ACP
, 0, data
, ptr
-data
, NULL
, 0);
931 headers
= heap_alloc((size
+1)*sizeof(WCHAR
));
933 MultiByteToWideChar(CP_ACP
, 0, data
, ptr
-data
, headers
, size
);
936 hres
= parse_headers(headers
, headers_list
);
938 request_data
->headers
= headers
;
942 hres
= E_OUTOFMEMORY
;
955 }else if(post_data
!= data
) {
958 new_data
= GlobalAlloc(0, data_len
+1);
960 memcpy(new_data
, post_data
, data_len
);
963 return E_OUTOFMEMORY
;
964 post_data
= new_data
;
968 post_data
[data_len
] = 0;
969 request_data
->post_data
= post_data
;
970 request_data
->post_data_len
= data_len
;
972 nsres
= nsIInputStream_QueryInterface(stream
, &IID_nsISeekableStream
, (void**)&seekable_stream
);
973 assert(nsres
== NS_OK
);
975 nsres
= nsISeekableStream_Seek(seekable_stream
, NS_SEEK_SET
, 0);
976 assert(nsres
== NS_OK
);
978 nsISeekableStream_Release(seekable_stream
);
980 nsIInputStream_AddRef(stream
);
981 request_data
->post_stream
= stream
;
982 TRACE("post_data = %s\n", debugstr_an(request_data
->post_data
, request_data
->post_data_len
));
986 static HRESULT
on_start_nsrequest(nsChannelBSC
*This
)
990 This
->nschannel
->binding
= This
;
992 /* FIXME: it's needed for http connections from BindToObject. */
993 if(!This
->nschannel
->response_status
)
994 This
->nschannel
->response_status
= 200;
996 nsres
= nsIStreamListener_OnStartRequest(This
->nslistener
,
997 (nsIRequest
*)&This
->nschannel
->nsIHttpChannel_iface
, This
->nscontext
);
998 if(NS_FAILED(nsres
)) {
999 FIXME("OnStartRequest failed: %08x\n", nsres
);
1003 if(This
->is_doc_channel
) {
1006 if(!This
->bsc
.window
)
1007 return E_ABORT
; /* Binding aborted in OnStartRequest call. */
1008 hres
= update_window_doc(This
->bsc
.window
);
1012 if(This
->bsc
.binding
)
1013 process_document_response_headers(This
->bsc
.window
->doc
, This
->bsc
.binding
);
1014 if(This
->bsc
.window
->base
.outer_window
->readystate
!= READYSTATE_LOADING
)
1015 set_ready_state(This
->bsc
.window
->base
.outer_window
, READYSTATE_LOADING
);
1021 static void on_stop_nsrequest(nsChannelBSC
*This
, HRESULT result
)
1023 nsresult nsres
, request_result
;
1027 request_result
= NS_OK
;
1030 request_result
= NS_BINDING_ABORTED
;
1033 request_result
= NS_ERROR_FAILURE
;
1036 if(This
->nslistener
) {
1037 nsres
= nsIStreamListener_OnStopRequest(This
->nslistener
,
1038 (nsIRequest
*)&This
->nschannel
->nsIHttpChannel_iface
, This
->nscontext
,
1040 if(NS_FAILED(nsres
))
1041 WARN("OnStopRequest failed: %08x\n", nsres
);
1044 if(This
->nschannel
) {
1045 if(This
->nschannel
->load_group
) {
1046 nsres
= nsILoadGroup_RemoveRequest(This
->nschannel
->load_group
,
1047 (nsIRequest
*)&This
->nschannel
->nsIHttpChannel_iface
, NULL
, request_result
);
1048 if(NS_FAILED(nsres
))
1049 ERR("RemoveRequest failed: %08x\n", nsres
);
1051 if(This
->nschannel
->binding
== This
)
1052 This
->nschannel
->binding
= NULL
;
1056 static HRESULT
read_stream_data(nsChannelBSC
*This
, IStream
*stream
)
1062 if(!This
->response_processed
) {
1063 IWinInetHttpInfo
*wininet_info
;
1065 This
->response_processed
= TRUE
;
1066 if(This
->bsc
.binding
) {
1067 hres
= IBinding_QueryInterface(This
->bsc
.binding
, &IID_IWinInetHttpInfo
, (void**)&wininet_info
);
1068 if(SUCCEEDED(hres
)) {
1069 query_http_info(This
, wininet_info
);
1070 IWinInetHttpInfo_Release(wininet_info
);
1075 if(!This
->nschannel
)
1078 if(!This
->nslistener
) {
1082 hres
= read_stream(&This
->bsc
, stream
, buf
, sizeof(buf
), &read
);
1083 }while(hres
== S_OK
&& read
);
1088 if(!This
->nsstream
) {
1089 This
->nsstream
= create_nsprotocol_stream();
1091 return E_OUTOFMEMORY
;
1095 BOOL first_read
= !This
->bsc
.read
;
1097 hres
= read_stream(&This
->bsc
, stream
, This
->nsstream
->buf
+This
->nsstream
->buf_size
,
1098 sizeof(This
->nsstream
->buf
)-This
->nsstream
->buf_size
, &read
);
1102 This
->nsstream
->buf_size
+= read
;
1105 switch(This
->bsc
.bom
) {
1107 This
->nschannel
->charset
= heap_strdupA(UTF8_STR
);
1110 This
->nschannel
->charset
= heap_strdupA(UTF16_STR
);
1112 /* FIXME: Get charset from HTTP headers */;
1115 if(!This
->nschannel
->content_type
) {
1118 hres
= FindMimeFromData(NULL
, NULL
, This
->nsstream
->buf
, This
->nsstream
->buf_size
,
1119 This
->is_doc_channel
? text_htmlW
: NULL
, 0, &mime
, 0);
1123 TRACE("Found MIME %s\n", debugstr_w(mime
));
1125 This
->nschannel
->content_type
= heap_strdupWtoA(mime
);
1126 CoTaskMemFree(mime
);
1127 if(!This
->nschannel
->content_type
)
1128 return E_OUTOFMEMORY
;
1131 hres
= on_start_nsrequest(This
);
1136 nsres
= nsIStreamListener_OnDataAvailable(This
->nslistener
,
1137 (nsIRequest
*)&This
->nschannel
->nsIHttpChannel_iface
, This
->nscontext
,
1138 &This
->nsstream
->nsIInputStream_iface
, This
->bsc
.read
-This
->nsstream
->buf_size
,
1139 This
->nsstream
->buf_size
);
1140 if(NS_FAILED(nsres
))
1141 ERR("OnDataAvailable failed: %08x\n", nsres
);
1143 if(This
->nsstream
->buf_size
== sizeof(This
->nsstream
->buf
)) {
1144 ERR("buffer is full\n");
1147 }while(hres
== S_OK
);
1153 nsIAsyncVerifyRedirectCallback nsIAsyncVerifyRedirectCallback_iface
;
1157 nsChannel
*nschannel
;
1159 } nsRedirectCallback
;
1161 static nsRedirectCallback
*impl_from_nsIAsyncVerifyRedirectCallback(nsIAsyncVerifyRedirectCallback
*iface
)
1163 return CONTAINING_RECORD(iface
, nsRedirectCallback
, nsIAsyncVerifyRedirectCallback_iface
);
1166 static nsresult NSAPI
nsAsyncVerifyRedirectCallback_QueryInterface(nsIAsyncVerifyRedirectCallback
*iface
,
1167 nsIIDRef riid
, void **result
)
1169 nsRedirectCallback
*This
= impl_from_nsIAsyncVerifyRedirectCallback(iface
);
1171 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1172 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1173 *result
= &This
->nsIAsyncVerifyRedirectCallback_iface
;
1174 }else if(IsEqualGUID(&IID_nsIAsyncVerifyRedirectCallback
, riid
)) {
1175 TRACE("(%p)->(IID_nsIAsyncVerifyRedirectCallback %p)\n", This
, result
);
1176 *result
= &This
->nsIAsyncVerifyRedirectCallback_iface
;
1179 WARN("unimplemented iface %s\n", debugstr_guid(riid
));
1180 return NS_NOINTERFACE
;
1183 nsISupports_AddRef((nsISupports
*)*result
);
1187 static nsrefcnt NSAPI
nsAsyncVerifyRedirectCallback_AddRef(nsIAsyncVerifyRedirectCallback
*iface
)
1189 nsRedirectCallback
*This
= impl_from_nsIAsyncVerifyRedirectCallback(iface
);
1190 LONG ref
= InterlockedIncrement(&This
->ref
);
1192 TRACE("(%p) ref=%d\n", This
, ref
);
1197 static nsrefcnt NSAPI
nsAsyncVerifyRedirectCallback_Release(nsIAsyncVerifyRedirectCallback
*iface
)
1199 nsRedirectCallback
*This
= impl_from_nsIAsyncVerifyRedirectCallback(iface
);
1200 LONG ref
= InterlockedDecrement(&This
->ref
);
1202 TRACE("(%p) ref=%d\n", This
, ref
);
1205 IBindStatusCallback_Release(&This
->bsc
->bsc
.IBindStatusCallback_iface
);
1206 nsIHttpChannel_Release(&This
->nschannel
->nsIHttpChannel_iface
);
1213 static nsresult NSAPI
nsAsyncVerifyRedirectCallback_OnRedirectVerifyCallback(nsIAsyncVerifyRedirectCallback
*iface
, nsresult result
)
1215 nsRedirectCallback
*This
= impl_from_nsIAsyncVerifyRedirectCallback(iface
);
1216 nsChannel
*old_nschannel
;
1219 TRACE("(%p)->(%08x)\n", This
, result
);
1221 old_nschannel
= This
->bsc
->nschannel
;
1222 nsIHttpChannel_AddRef(&This
->nschannel
->nsIHttpChannel_iface
);
1223 This
->bsc
->nschannel
= This
->nschannel
;
1225 if(This
->nschannel
->load_group
) {
1226 nsres
= nsILoadGroup_AddRequest(This
->nschannel
->load_group
, (nsIRequest
*)&This
->nschannel
->nsIHttpChannel_iface
,
1228 if(NS_FAILED(nsres
))
1229 ERR("AddRequest failed: %08x\n", nsres
);
1232 if(This
->bsc
->is_doc_channel
&& This
->bsc
->bsc
.window
&& This
->bsc
->bsc
.window
->base
.outer_window
) {
1233 IUri
*uri
= nsuri_get_uri(This
->nschannel
->uri
);
1236 set_current_uri(This
->bsc
->bsc
.window
->base
.outer_window
, uri
);
1239 WARN("Could not get IUri from nsWineURI\n");
1244 if(old_nschannel
->load_group
) {
1245 nsres
= nsILoadGroup_RemoveRequest(old_nschannel
->load_group
,
1246 (nsIRequest
*)&old_nschannel
->nsIHttpChannel_iface
, NULL
, NS_OK
);
1247 if(NS_FAILED(nsres
))
1248 ERR("RemoveRequest failed: %08x\n", nsres
);
1250 nsIHttpChannel_Release(&old_nschannel
->nsIHttpChannel_iface
);
1256 static const nsIAsyncVerifyRedirectCallbackVtbl nsAsyncVerifyRedirectCallbackVtbl
= {
1257 nsAsyncVerifyRedirectCallback_QueryInterface
,
1258 nsAsyncVerifyRedirectCallback_AddRef
,
1259 nsAsyncVerifyRedirectCallback_Release
,
1260 nsAsyncVerifyRedirectCallback_OnRedirectVerifyCallback
1263 static HRESULT
create_redirect_callback(nsChannel
*nschannel
, nsChannelBSC
*bsc
, nsRedirectCallback
**ret
)
1265 nsRedirectCallback
*callback
;
1267 callback
= heap_alloc(sizeof(*callback
));
1269 return E_OUTOFMEMORY
;
1271 callback
->nsIAsyncVerifyRedirectCallback_iface
.lpVtbl
= &nsAsyncVerifyRedirectCallbackVtbl
;
1274 nsIHttpChannel_AddRef(&nschannel
->nsIHttpChannel_iface
);
1275 callback
->nschannel
= nschannel
;
1277 IBindStatusCallback_AddRef(&bsc
->bsc
.IBindStatusCallback_iface
);
1278 callback
->bsc
= bsc
;
1284 static inline nsChannelBSC
*nsChannelBSC_from_BSCallback(BSCallback
*iface
)
1286 return CONTAINING_RECORD(iface
, nsChannelBSC
, bsc
);
1289 static void nsChannelBSC_destroy(BSCallback
*bsc
)
1291 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1293 if(This
->nschannel
) {
1294 if(This
->nschannel
->binding
== This
)
1295 This
->nschannel
->binding
= NULL
;
1296 nsIHttpChannel_Release(&This
->nschannel
->nsIHttpChannel_iface
);
1298 if(This
->nslistener
)
1299 nsIStreamListener_Release(This
->nslistener
);
1301 nsISupports_Release(This
->nscontext
);
1303 nsIInputStream_Release(&This
->nsstream
->nsIInputStream_iface
);
1307 static HRESULT
nsChannelBSC_start_binding(BSCallback
*bsc
)
1309 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1311 if(This
->is_doc_channel
)
1312 This
->bsc
.window
->base
.outer_window
->base
.inner_window
->doc
->skip_mutation_notif
= FALSE
;
1317 static HRESULT
nsChannelBSC_init_bindinfo(BSCallback
*bsc
)
1319 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1320 nsChannel
*nschannel
= This
->nschannel
;
1321 GeckoBrowser
*browser
;
1324 if(This
->is_doc_channel
&& This
->bsc
.window
&& This
->bsc
.window
->base
.outer_window
1325 && (browser
= This
->bsc
.window
->base
.outer_window
->browser
)) {
1326 if(browser
->doc
->hostinfo
.dwFlags
& DOCHOSTUIFLAG_ENABLE_REDIRECT_NOTIFICATION
)
1327 This
->bsc
.bindinfo_options
|= BINDINFO_OPTIONS_DISABLEAUTOREDIRECTS
;
1330 if(nschannel
&& nschannel
->post_data_stream
) {
1331 hres
= read_post_data_stream(nschannel
->post_data_stream
, nschannel
->post_data_contains_headers
,
1332 &nschannel
->request_headers
, &This
->bsc
.request_data
);
1343 } stop_request_task_t
;
1345 static void stop_request_proc(task_t
*_task
)
1347 stop_request_task_t
*task
= (stop_request_task_t
*)_task
;
1349 TRACE("(%p)\n", task
->bsc
);
1351 list_remove(&task
->bsc
->bsc
.entry
);
1352 list_init(&task
->bsc
->bsc
.entry
);
1353 on_stop_nsrequest(task
->bsc
, S_OK
);
1356 static void stop_request_task_destr(task_t
*_task
)
1358 stop_request_task_t
*task
= (stop_request_task_t
*)_task
;
1360 IBindStatusCallback_Release(&task
->bsc
->bsc
.IBindStatusCallback_iface
);
1364 static HRESULT
async_stop_request(nsChannelBSC
*This
)
1366 stop_request_task_t
*task
;
1368 if(!This
->bsc
.read
) {
1369 TRACE("No data read, calling OnStartRequest\n");
1370 on_start_nsrequest(This
);
1373 task
= heap_alloc(sizeof(*task
));
1375 return E_OUTOFMEMORY
;
1377 IBindStatusCallback_AddRef(&This
->bsc
.IBindStatusCallback_iface
);
1380 return push_task(&task
->header
, stop_request_proc
, stop_request_task_destr
, This
->bsc
.window
->task_magic
);
1383 static void handle_navigation_error(nsChannelBSC
*This
, DWORD result
)
1385 HTMLOuterWindow
*outer_window
;
1386 HTMLDocumentObj
*doc
;
1389 SAFEARRAYBOUND bound
;
1390 VARIANT var
, varOut
;
1395 if(!This
->is_doc_channel
|| !This
->bsc
.window
|| !This
->bsc
.window
->base
.outer_window
1396 || !This
->bsc
.window
->base
.outer_window
->browser
)
1399 outer_window
= This
->bsc
.window
->base
.outer_window
;
1400 doc
= outer_window
->browser
->doc
;
1401 if(!doc
->doc_object_service
|| !doc
->client
)
1404 hres
= IDocObjectService_IsErrorUrl(doc
->doc_object_service
,
1405 outer_window
->url
, &is_error_url
);
1406 if(FAILED(hres
) || is_error_url
)
1409 if(!doc
->client_cmdtrg
)
1413 bound
.cElements
= 8;
1414 sa
= SafeArrayCreate(VT_VARIANT
, 1, &bound
);
1420 V_I4(&var
) = result
;
1421 SafeArrayPutElement(sa
, &ind
, &var
);
1424 V_VT(&var
) = VT_BSTR
;
1425 V_BSTR(&var
) = outer_window
->url
;
1426 SafeArrayPutElement(sa
, &ind
, &var
);
1429 V_VT(&var
) = VT_UNKNOWN
;
1430 V_UNKNOWN(&var
) = (IUnknown
*)&outer_window
->base
.IHTMLWindow2_iface
;
1431 SafeArrayPutElement(sa
, &ind
, &var
);
1433 /* FIXME: what are the following fields for? */
1435 V_VT(&var
) = VT_UNKNOWN
;
1436 V_UNKNOWN(&var
) = NULL
;
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_BOOL
;
1446 V_BOOL(&var
) = FALSE
;
1447 SafeArrayPutElement(sa
, &ind
, &var
);
1450 V_VT(&var
) = VT_BSTR
;
1451 unk
= SysAllocString(NULL
);
1453 SafeArrayPutElement(sa
, &ind
, &var
);
1456 V_VT(&var
) = VT_UNKNOWN
;
1457 V_UNKNOWN(&var
) = NULL
;
1458 SafeArrayPutElement(sa
, &ind
, &var
);
1460 V_VT(&var
) = VT_ARRAY
;
1462 V_VT(&varOut
) = VT_BOOL
;
1463 V_BOOL(&varOut
) = VARIANT_TRUE
;
1464 IOleCommandTarget_Exec(doc
->client_cmdtrg
, &CGID_DocHostCmdPriv
, 1, 0, &var
, FAILED(hres
)?NULL
:&varOut
);
1467 SafeArrayDestroy(sa
);
1470 static HRESULT
nsChannelBSC_stop_binding(BSCallback
*bsc
, HRESULT result
)
1472 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1474 if(result
!= E_ABORT
&& This
->is_doc_channel
&& This
->bsc
.window
) {
1476 handle_navigation_error(This
, result
);
1477 else if(This
->nschannel
) {
1478 result
= async_stop_request(This
);
1479 if(SUCCEEDED(result
))
1484 on_stop_nsrequest(This
, result
);
1488 static HRESULT
nsChannelBSC_read_data(BSCallback
*bsc
, IStream
*stream
)
1490 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1492 return read_stream_data(This
, stream
);
1495 static HRESULT
handle_redirect(nsChannelBSC
*This
, const WCHAR
*new_url
)
1497 nsRedirectCallback
*callback
;
1498 nsIChannelEventSink
*sink
;
1499 nsChannel
*new_channel
;
1504 TRACE("(%p)->(%s)\n", This
, debugstr_w(new_url
));
1506 hres
= CreateURLMoniker(NULL
, new_url
, &mon
);
1509 IMoniker_Release(This
->bsc
.mon
);
1510 This
->bsc
.mon
= mon
;
1512 if(!This
->nschannel
|| !This
->nschannel
->notif_callback
)
1515 nsres
= nsIInterfaceRequestor_GetInterface(This
->nschannel
->notif_callback
, &IID_nsIChannelEventSink
, (void**)&sink
);
1516 if(NS_FAILED(nsres
))
1519 hres
= create_redirect_nschannel(new_url
, This
->nschannel
, &new_channel
);
1520 if(SUCCEEDED(hres
)) {
1521 TRACE("%p %p->%p\n", This
, This
->nschannel
, new_channel
);
1523 hres
= create_redirect_callback(new_channel
, This
, &callback
);
1524 nsIHttpChannel_Release(&new_channel
->nsIHttpChannel_iface
);
1527 if(SUCCEEDED(hres
)) {
1528 nsres
= nsIChannelEventSink_AsyncOnChannelRedirect(sink
, (nsIChannel
*)&This
->nschannel
->nsIHttpChannel_iface
,
1529 (nsIChannel
*)&callback
->nschannel
->nsIHttpChannel_iface
, REDIRECT_TEMPORARY
, /* FIXME */
1530 &callback
->nsIAsyncVerifyRedirectCallback_iface
);
1532 if(NS_FAILED(nsres
))
1533 FIXME("AsyncOnChannelRedirect failed: %08x\n", hres
);
1534 else if(This
->nschannel
!= callback
->nschannel
)
1535 FIXME("nschannel not updated\n");
1537 nsIAsyncVerifyRedirectCallback_Release(&callback
->nsIAsyncVerifyRedirectCallback_iface
);
1540 nsIChannelEventSink_Release(sink
);
1544 static BOOL
is_supported_doc_mime(const WCHAR
*mime
)
1546 char *nscat
, *mimea
;
1549 mimea
= heap_strdupWtoA(mime
);
1553 nscat
= get_nscategory_entry("Gecko-Content-Viewers", mimea
);
1555 ret
= nscat
!= NULL
&& !strcmp(nscat
, "@mozilla.org/content/document-loader-factory;1");
1562 static IUri
*get_moniker_uri(IMoniker
*mon
)
1564 IUriContainer
*uri_container
;
1568 hres
= IMoniker_QueryInterface(mon
, &IID_IUriContainer
, (void**)&uri_container
);
1569 if(SUCCEEDED(hres
)) {
1570 hres
= IUriContainer_GetIUri(uri_container
, &ret
);
1571 IUriContainer_Release(uri_container
);
1575 FIXME("No IUriContainer\n");
1581 static void handle_extern_mime_navigation(nsChannelBSC
*This
)
1583 IWebBrowserPriv2IE9
*webbrowser_priv
;
1584 IOleCommandTarget
*cmdtrg
;
1585 HTMLDocumentObj
*doc_obj
;
1591 if(!This
->bsc
.window
|| !This
->bsc
.window
->base
.outer_window
|| !This
->bsc
.window
->base
.outer_window
->browser
)
1594 doc_obj
= This
->bsc
.window
->base
.outer_window
->browser
->doc
;
1596 hres
= IOleClientSite_QueryInterface(doc_obj
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
1597 if(SUCCEEDED(hres
)) {
1598 IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 62, 0, NULL
, NULL
);
1599 IOleCommandTarget_Release(cmdtrg
);
1602 set_document_navigation(doc_obj
, FALSE
);
1604 if(!doc_obj
->webbrowser
) {
1605 FIXME("unimplemented in non-webbrowser mode\n");
1609 uri
= get_moniker_uri(This
->bsc
.mon
);
1613 hres
= CreateBindCtx(0, &bind_ctx
);
1619 V_VT(&flags
) = VT_I4
;
1620 V_I4(&flags
) = navHyperlink
;
1622 hres
= IUnknown_QueryInterface(doc_obj
->webbrowser
, &IID_IWebBrowserPriv2IE8
, (void**)&webbrowser_priv
);
1623 if(SUCCEEDED(hres
)) {
1624 hres
= IWebBrowserPriv2IE9_NavigateWithBindCtx2(webbrowser_priv
, uri
, &flags
, NULL
, NULL
, NULL
, bind_ctx
, NULL
, 0);
1625 IWebBrowserPriv2IE9_Release(webbrowser_priv
);
1627 IWebBrowserPriv
*webbrowser_priv_old
;
1630 hres
= IUnknown_QueryInterface(doc_obj
->webbrowser
, &IID_IWebBrowserPriv
, (void**)&webbrowser_priv_old
);
1631 if(SUCCEEDED(hres
)) {
1632 V_VT(&uriv
) = VT_BSTR
;
1633 IUri_GetDisplayUri(uri
, &V_BSTR(&uriv
));
1635 hres
= IWebBrowserPriv_NavigateWithBindCtx(webbrowser_priv_old
, &uriv
, &flags
, NULL
, NULL
, NULL
, bind_ctx
, NULL
);
1637 SysFreeString(V_BSTR(&uriv
));
1638 IWebBrowserPriv_Release(webbrowser_priv_old
);
1645 static HRESULT
nsChannelBSC_on_progress(BSCallback
*bsc
, ULONG status_code
, LPCWSTR status_text
)
1647 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1649 switch(status_code
) {
1650 case BINDSTATUS_MIMETYPEAVAILABLE
:
1651 if(This
->is_doc_channel
&& !is_supported_doc_mime(status_text
)) {
1652 FIXME("External MIME: %s\n", debugstr_w(status_text
));
1654 handle_extern_mime_navigation(This
);
1656 This
->nschannel
= NULL
;
1659 if(!This
->nschannel
)
1662 heap_free(This
->nschannel
->content_type
);
1663 This
->nschannel
->content_type
= heap_strdupWtoA(status_text
);
1665 case BINDSTATUS_REDIRECTING
:
1666 return handle_redirect(This
, status_text
);
1667 case BINDSTATUS_BEGINDOWNLOADDATA
: {
1668 IWinInetHttpInfo
*http_info
;
1669 DWORD status
, size
= sizeof(DWORD
);
1672 if(!This
->bsc
.binding
)
1675 hres
= IBinding_QueryInterface(This
->bsc
.binding
, &IID_IWinInetHttpInfo
, (void**)&http_info
);
1679 hres
= IWinInetHttpInfo_QueryInfo(http_info
,
1680 HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
, NULL
);
1681 IWinInetHttpInfo_Release(http_info
);
1682 if(FAILED(hres
) || status
== HTTP_STATUS_OK
)
1685 handle_navigation_error(This
, status
);
1692 static HRESULT
process_response_status_text(const WCHAR
*header
, const WCHAR
*header_end
, char **status_text
)
1694 header
= wcschr(header
+ 1, ' ');
1695 if(!header
|| header
>= header_end
)
1697 header
= wcschr(header
+ 1, ' ');
1698 if(!header
|| header
>= header_end
)
1702 *status_text
= heap_strndupWtoU(header
, header_end
- header
);
1705 return E_OUTOFMEMORY
;
1710 static HRESULT
nsChannelBSC_on_response(BSCallback
*bsc
, DWORD response_code
,
1711 LPCWSTR response_headers
)
1713 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1717 This
->response_processed
= TRUE
;
1718 This
->nschannel
->response_status
= response_code
;
1720 if(response_headers
) {
1721 const WCHAR
*headers
;
1723 headers
= wcschr(response_headers
, '\r');
1724 hres
= process_response_status_text(response_headers
, headers
, &str
);
1726 WARN("parsing headers failed: %08x\n", hres
);
1730 heap_free(This
->nschannel
->response_status_text
);
1731 This
->nschannel
->response_status_text
= str
;
1733 if(headers
&& headers
[1] == '\n') {
1735 hres
= process_response_headers(This
, headers
);
1737 WARN("parsing headers failed: %08x\n", hres
);
1746 static HRESULT
nsChannelBSC_beginning_transaction(BSCallback
*bsc
, WCHAR
**additional_headers
)
1748 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1749 http_header_t
*iter
;
1753 static const WCHAR content_lengthW
[] =
1754 {'C','o','n','t','e','n','t','-','L','e','n','g','t','h',0};
1756 if(!This
->nschannel
)
1759 LIST_FOR_EACH_ENTRY(iter
, &This
->nschannel
->request_headers
, http_header_t
, entry
) {
1760 if(wcscmp(iter
->header
, content_lengthW
))
1761 len
+= lstrlenW(iter
->header
) + 2 /* ": " */ + lstrlenW(iter
->data
) + 2 /* "\r\n" */;
1767 *additional_headers
= ptr
= CoTaskMemAlloc((len
+1)*sizeof(WCHAR
));
1769 return E_OUTOFMEMORY
;
1771 LIST_FOR_EACH_ENTRY(iter
, &This
->nschannel
->request_headers
, http_header_t
, entry
) {
1772 if(!wcscmp(iter
->header
, content_lengthW
))
1775 len
= lstrlenW(iter
->header
);
1776 memcpy(ptr
, iter
->header
, len
*sizeof(WCHAR
));
1782 len
= lstrlenW(iter
->data
);
1783 memcpy(ptr
, iter
->data
, len
*sizeof(WCHAR
));
1795 static const BSCallbackVtbl nsChannelBSCVtbl
= {
1796 nsChannelBSC_destroy
,
1797 nsChannelBSC_init_bindinfo
,
1798 nsChannelBSC_start_binding
,
1799 nsChannelBSC_stop_binding
,
1800 nsChannelBSC_read_data
,
1801 nsChannelBSC_on_progress
,
1802 nsChannelBSC_on_response
,
1803 nsChannelBSC_beginning_transaction
1806 HRESULT
create_channelbsc(IMoniker
*mon
, const WCHAR
*headers
, BYTE
*post_data
, DWORD post_data_size
,
1807 BOOL is_doc_binding
, nsChannelBSC
**retval
)
1812 ret
= heap_alloc_zero(sizeof(*ret
));
1814 return E_OUTOFMEMORY
;
1816 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
;
1818 bindf
|= BINDF_FORMS_SUBMIT
| BINDF_PRAGMA_NO_CACHE
| BINDF_HYPERLINK
| BINDF_GETNEWESTVERSION
;
1820 init_bscallback(&ret
->bsc
, &nsChannelBSCVtbl
, mon
, bindf
);
1821 ret
->is_doc_channel
= is_doc_binding
;
1824 ret
->bsc
.request_data
.headers
= heap_strdupW(headers
);
1825 if(!ret
->bsc
.request_data
.headers
) {
1826 IBindStatusCallback_Release(&ret
->bsc
.IBindStatusCallback_iface
);
1827 return E_OUTOFMEMORY
;
1832 ret
->bsc
.request_data
.post_data
= GlobalAlloc(0, post_data_size
+1);
1833 if(!ret
->bsc
.request_data
.post_data
) {
1834 release_request_data(&ret
->bsc
.request_data
);
1835 IBindStatusCallback_Release(&ret
->bsc
.IBindStatusCallback_iface
);
1836 return E_OUTOFMEMORY
;
1839 memcpy(ret
->bsc
.request_data
.post_data
, post_data
, post_data_size
);
1840 ((BYTE
*)ret
->bsc
.request_data
.post_data
)[post_data_size
] = 0;
1841 ret
->bsc
.request_data
.post_data_len
= post_data_size
;
1844 TRACE("created %p\n", ret
);
1851 HTMLOuterWindow
*window
;
1852 HTMLInnerWindow
*pending_window
;
1853 } start_doc_binding_task_t
;
1855 static void start_doc_binding_proc(task_t
*_task
)
1857 start_doc_binding_task_t
*task
= (start_doc_binding_task_t
*)_task
;
1859 set_current_mon(task
->window
, task
->pending_window
->bscallback
->bsc
.mon
, BINDING_NAVIGATED
);
1860 start_binding(task
->pending_window
, &task
->pending_window
->bscallback
->bsc
, NULL
);
1863 static void start_doc_binding_task_destr(task_t
*_task
)
1865 start_doc_binding_task_t
*task
= (start_doc_binding_task_t
*)_task
;
1867 IHTMLWindow2_Release(&task
->pending_window
->base
.IHTMLWindow2_iface
);
1871 HRESULT
async_start_doc_binding(HTMLOuterWindow
*window
, HTMLInnerWindow
*pending_window
)
1873 start_doc_binding_task_t
*task
;
1875 TRACE("%p\n", pending_window
);
1877 task
= heap_alloc(sizeof(start_doc_binding_task_t
));
1879 return E_OUTOFMEMORY
;
1881 task
->window
= window
;
1882 task
->pending_window
= pending_window
;
1883 IHTMLWindow2_AddRef(&pending_window
->base
.IHTMLWindow2_iface
);
1885 return push_task(&task
->header
, start_doc_binding_proc
, start_doc_binding_task_destr
, pending_window
->task_magic
);
1888 void abort_window_bindings(HTMLInnerWindow
*window
)
1892 remove_target_tasks(window
->task_magic
);
1894 while(!list_empty(&window
->bindings
)) {
1895 iter
= LIST_ENTRY(window
->bindings
.next
, BSCallback
, entry
);
1897 TRACE("Aborting %p\n", iter
);
1899 IBindStatusCallback_AddRef(&iter
->IBindStatusCallback_iface
);
1902 IBinding_Abort(iter
->binding
);
1904 iter
->vtbl
->stop_binding(iter
, E_ABORT
);
1906 iter
->window
= NULL
;
1907 list_remove(&iter
->entry
);
1908 list_init(&iter
->entry
);
1910 IBindStatusCallback_Release(&iter
->IBindStatusCallback_iface
);
1913 if(window
->bscallback
) {
1914 IBindStatusCallback_Release(&window
->bscallback
->bsc
.IBindStatusCallback_iface
);
1915 window
->bscallback
= NULL
;
1919 IMoniker_Release(window
->mon
);
1924 HRESULT
channelbsc_load_stream(HTMLInnerWindow
*pending_window
, IMoniker
*mon
, IStream
*stream
)
1926 nsChannelBSC
*bscallback
= pending_window
->bscallback
;
1927 HRESULT hres
= S_OK
;
1929 if(!bscallback
->nschannel
) {
1930 ERR("NULL nschannel\n");
1934 bscallback
->nschannel
->content_type
= heap_strdupA("text/html");
1935 if(!bscallback
->nschannel
->content_type
)
1936 return E_OUTOFMEMORY
;
1938 set_current_mon(pending_window
->base
.outer_window
, mon
, 0);
1940 bscallback
->bsc
.window
= pending_window
;
1942 hres
= read_stream_data(bscallback
, stream
);
1944 hres
= async_stop_request(bscallback
);
1946 IBindStatusCallback_OnStopBinding(&bscallback
->bsc
.IBindStatusCallback_iface
, hres
, NULL
);
1951 void channelbsc_set_channel(nsChannelBSC
*This
, nsChannel
*channel
, nsIStreamListener
*listener
, nsISupports
*context
)
1953 nsIHttpChannel_AddRef(&channel
->nsIHttpChannel_iface
);
1954 This
->nschannel
= channel
;
1956 nsIStreamListener_AddRef(listener
);
1957 This
->nslistener
= listener
;
1960 nsISupports_AddRef(context
);
1961 This
->nscontext
= context
;
1964 if(This
->bsc
.request_data
.headers
) {
1967 hres
= parse_headers(This
->bsc
.request_data
.headers
, &channel
->request_headers
);
1968 heap_free(This
->bsc
.request_data
.headers
);
1969 This
->bsc
.request_data
.headers
= NULL
;
1971 WARN("parse_headers failed: %08x\n", hres
);
1977 HTMLOuterWindow
*window
;
1979 } navigate_javascript_task_t
;
1981 static void navigate_javascript_proc(task_t
*_task
)
1983 navigate_javascript_task_t
*task
= (navigate_javascript_task_t
*)_task
;
1984 HTMLOuterWindow
*window
= task
->window
;
1989 static const WCHAR jscriptW
[] = {'j','s','c','r','i','p','t',0};
1991 task
->window
->readystate
= READYSTATE_COMPLETE
;
1993 hres
= IUri_GetPath(task
->uri
, &code
);
1997 hres
= UrlUnescapeW(code
, NULL
, NULL
, URL_UNESCAPE_INPLACE
);
1999 SysFreeString(code
);
2003 set_download_state(window
->browser
->doc
, 1);
2005 V_VT(&v
) = VT_EMPTY
;
2006 hres
= exec_script(window
->base
.inner_window
, code
, jscriptW
, &v
);
2007 SysFreeString(code
);
2008 if(SUCCEEDED(hres
) && V_VT(&v
) != VT_EMPTY
) {
2009 FIXME("javascirpt URL returned %s\n", debugstr_variant(&v
));
2013 if(window
->browser
->doc
->view_sink
)
2014 IAdviseSink_OnViewChange(window
->browser
->doc
->view_sink
, DVASPECT_CONTENT
, -1);
2016 set_download_state(window
->browser
->doc
, 0);
2019 static void navigate_javascript_task_destr(task_t
*_task
)
2021 navigate_javascript_task_t
*task
= (navigate_javascript_task_t
*)_task
;
2023 IUri_Release(task
->uri
);
2029 HTMLOuterWindow
*window
;
2030 nsChannelBSC
*bscallback
;
2036 static void navigate_proc(task_t
*_task
)
2038 navigate_task_t
*task
= (navigate_task_t
*)_task
;
2041 hres
= set_moniker(task
->window
, task
->mon
, task
->uri
, NULL
, task
->bscallback
, TRUE
);
2042 if(SUCCEEDED(hres
)) {
2043 set_current_mon(task
->window
, task
->bscallback
->bsc
.mon
, task
->flags
);
2044 set_current_uri(task
->window
, task
->uri
);
2045 start_binding(task
->window
->pending_window
, &task
->bscallback
->bsc
, NULL
);
2049 static void navigate_task_destr(task_t
*_task
)
2051 navigate_task_t
*task
= (navigate_task_t
*)_task
;
2053 IBindStatusCallback_Release(&task
->bscallback
->bsc
.IBindStatusCallback_iface
);
2054 IMoniker_Release(task
->mon
);
2055 IUri_Release(task
->uri
);
2059 static HRESULT
navigate_fragment(HTMLOuterWindow
*window
, IUri
*uri
)
2061 nsIDOMLocation
*nslocation
;
2062 nsAString nsfrag_str
;
2068 static const WCHAR selector_formatW
[] = {'a','[','i','d','=','"','%','s','"',']',0};
2070 set_current_uri(window
, uri
);
2072 nsres
= nsIDOMWindow_GetLocation(window
->nswindow
, &nslocation
);
2073 if(FAILED(nsres
) || !nslocation
)
2076 hres
= IUri_GetFragment(uri
, &frag
);
2078 nsIDOMLocation_Release(nslocation
);
2082 nsAString_InitDepend(&nsfrag_str
, frag
);
2083 nsres
= nsIDOMLocation_SetHash(nslocation
, &nsfrag_str
);
2084 nsAString_Finish(&nsfrag_str
);
2085 nsIDOMLocation_Release(nslocation
);
2086 if(NS_FAILED(nsres
))
2087 ERR("SetHash failed: %08x\n", nsres
);
2090 * IE supports scrolling to anchor elements with "#hash" ids (note that '#' is part of the id),
2091 * while Gecko scrolls only to elements with "hash" ids. We scroll the page ourselves if
2092 * a[id="#hash"] element can be found.
2094 selector
= heap_alloc(sizeof(selector_formatW
)+SysStringLen(frag
)*sizeof(WCHAR
));
2096 nsIDOMElement
*nselem
= NULL
;
2097 nsAString selector_str
;
2099 swprintf(selector
, ARRAY_SIZE(selector_formatW
)+SysStringLen(frag
), selector_formatW
, frag
);
2100 nsAString_InitDepend(&selector_str
, selector
);
2101 /* NOTE: Gecko doesn't set result to NULL if there is no match, so nselem must be initialized */
2102 nsres
= nsIDOMHTMLDocument_QuerySelector(window
->base
.inner_window
->doc
->nsdoc
, &selector_str
, &nselem
);
2103 nsAString_Finish(&selector_str
);
2104 heap_free(selector
);
2105 if(NS_SUCCEEDED(nsres
) && nselem
) {
2106 nsIDOMHTMLElement
*html_elem
;
2108 nsres
= nsIDOMElement_QueryInterface(nselem
, &IID_nsIDOMHTMLElement
, (void**)&html_elem
);
2109 nsIDOMElement_Release(nselem
);
2110 if(NS_SUCCEEDED(nsres
)) {
2111 nsIDOMHTMLElement_ScrollIntoView(html_elem
, TRUE
, 1);
2112 nsIDOMHTMLElement_Release(html_elem
);
2117 SysFreeString(frag
);
2119 if(window
->browser
->doc
->doc_object_service
) {
2120 IDocObjectService_FireNavigateComplete2(window
->browser
->doc
->doc_object_service
, &window
->base
.IHTMLWindow2_iface
, 0x10);
2121 IDocObjectService_FireDocumentComplete(window
->browser
->doc
->doc_object_service
, &window
->base
.IHTMLWindow2_iface
, 0);
2128 HRESULT
super_navigate(HTMLOuterWindow
*window
, IUri
*uri
, DWORD flags
, const WCHAR
*headers
, BYTE
*post_data
, DWORD post_data_size
)
2136 uri_nofrag
= get_uri_nofrag(uri
);
2140 if(window
->browser
->doc
->client
&& !(flags
& BINDING_REFRESH
)) {
2141 IOleCommandTarget
*cmdtrg
;
2143 hres
= IOleClientSite_QueryInterface(window
->browser
->doc
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
2144 if(SUCCEEDED(hres
)) {
2148 hres
= IUri_GetDisplayUri(uri_nofrag
, &url_str
);
2149 if(SUCCEEDED(hres
)) {
2150 V_VT(&in
) = VT_BSTR
;
2151 V_BSTR(&in
) = url_str
;
2152 V_VT(&out
) = VT_BOOL
;
2153 V_BOOL(&out
) = VARIANT_TRUE
;
2154 hres
= IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 67, 0, &in
, &out
);
2155 IOleCommandTarget_Release(cmdtrg
);
2158 SysFreeString(url_str
);
2163 if(!(flags
& BINDING_NOFRAG
) && window
->uri_nofrag
&& !post_data_size
) {
2166 hres
= IUri_IsEqual(uri_nofrag
, window
->uri_nofrag
, &eq
);
2167 if(SUCCEEDED(hres
) && eq
) {
2168 IUri_Release(uri_nofrag
);
2169 TRACE("fragment navigate\n");
2170 return navigate_fragment(window
, uri
);
2174 hres
= CreateURLMonikerEx2(NULL
, uri_nofrag
, &mon
, URL_MK_UNIFORM
);
2175 IUri_Release(uri_nofrag
);
2179 /* FIXME: Why not set_ready_state? */
2180 window
->readystate
= READYSTATE_UNINITIALIZED
;
2182 hres
= create_channelbsc(mon
, headers
, post_data
, post_data_size
, TRUE
, &bsc
);
2184 IMoniker_Release(mon
);
2188 prepare_for_binding(&window
->browser
->doc
->basedoc
, mon
, flags
);
2190 hres
= IUri_GetScheme(uri
, &scheme
);
2191 if(SUCCEEDED(hres
) && scheme
== URL_SCHEME_JAVASCRIPT
) {
2192 navigate_javascript_task_t
*task
;
2194 IBindStatusCallback_Release(&bsc
->bsc
.IBindStatusCallback_iface
);
2195 IMoniker_Release(mon
);
2197 task
= heap_alloc(sizeof(*task
));
2199 return E_OUTOFMEMORY
;
2202 window
->readystate
= READYSTATE_COMPLETE
;
2203 if(!(flags
& BINDING_FROMHIST
))
2204 call_docview_84(window
->browser
->doc
);
2207 task
->window
= window
;
2209 hres
= push_task(&task
->header
, navigate_javascript_proc
, navigate_javascript_task_destr
, window
->task_magic
);
2210 }else if(flags
& BINDING_SUBMIT
) {
2211 hres
= set_moniker(window
, mon
, uri
, NULL
, bsc
, TRUE
);
2213 hres
= start_binding(window
->pending_window
, &bsc
->bsc
, NULL
);
2214 IBindStatusCallback_Release(&bsc
->bsc
.IBindStatusCallback_iface
);
2215 IMoniker_Release(mon
);
2217 navigate_task_t
*task
;
2219 task
= heap_alloc(sizeof(*task
));
2221 IBindStatusCallback_Release(&bsc
->bsc
.IBindStatusCallback_iface
);
2222 IMoniker_Release(mon
);
2223 return E_OUTOFMEMORY
;
2226 /* Silently and repeated when real loading starts? */
2227 window
->readystate
= READYSTATE_LOADING
;
2228 if(!(flags
& (BINDING_FROMHIST
|BINDING_REFRESH
)))
2229 call_docview_84(window
->browser
->doc
);
2231 task
->window
= window
;
2232 task
->bscallback
= bsc
;
2233 task
->flags
= flags
;
2238 hres
= push_task(&task
->header
, navigate_proc
, navigate_task_destr
, window
->task_magic
);
2244 HRESULT
navigate_new_window(HTMLOuterWindow
*window
, IUri
*uri
, const WCHAR
*name
, request_data_t
*request_data
, IHTMLWindow2
**ret
)
2246 INewWindowManager
*new_window_mgr
;
2247 BSTR display_uri
, context_url
;
2248 IWebBrowser2
*web_browser
;
2249 IHTMLWindow2
*new_window
;
2254 if(!window
->browser
)
2255 return E_UNEXPECTED
;
2257 if (window
->browser
->doc
->client
) {
2258 hres
= do_query_service((IUnknown
*)window
->browser
->doc
->client
, &SID_SNewWindowManager
,
2259 &IID_INewWindowManager
, (void**)&new_window_mgr
);
2261 FIXME("No INewWindowManager\n");
2265 hres
= IUri_GetDisplayUri(window
->uri_nofrag
, &context_url
);
2269 hres
= IUri_GetDisplayUri(uri
, &display_uri
);
2271 SysFreeString(context_url
);
2275 hres
= INewWindowManager_EvaluateNewWindow(new_window_mgr
, display_uri
, name
, context_url
,
2276 NULL
, FALSE
, window
->browser
->doc
->has_popup
? 0 : NWMF_FIRST
, 0);
2277 window
->browser
->doc
->has_popup
= TRUE
;
2278 SysFreeString(display_uri
);
2279 SysFreeString(context_url
);
2280 INewWindowManager_Release(new_window_mgr
);
2290 hres
= create_channelbsc(NULL
, request_data
->headers
,
2291 request_data
->post_data
, request_data
->post_data_len
, FALSE
,
2294 hres
= create_channelbsc(NULL
, NULL
, NULL
, 0, FALSE
, &bsc
);
2298 hres
= CreateAsyncBindCtx(0, &bsc
->bsc
.IBindStatusCallback_iface
, NULL
, &bind_ctx
);
2300 IBindStatusCallback_Release(&bsc
->bsc
.IBindStatusCallback_iface
);
2304 hres
= CoCreateInstance(&CLSID_InternetExplorer
, NULL
, CLSCTX_LOCAL_SERVER
,
2305 &IID_IWebBrowser2
, (void**)&web_browser
);
2306 if(SUCCEEDED(hres
)) {
2307 ITargetFramePriv2
*target_frame_priv
;
2309 hres
= IWebBrowser2_QueryInterface(web_browser
, &IID_ITargetFramePriv2
, (void**)&target_frame_priv
);
2310 if(SUCCEEDED(hres
)) {
2311 hres
= ITargetFramePriv2_AggregatedNavigation2(target_frame_priv
,
2312 HLNF_DISABLEWINDOWRESTRICTIONS
|HLNF_OPENINNEWWINDOW
, bind_ctx
, &bsc
->bsc
.IBindStatusCallback_iface
,
2314 ITargetFramePriv2_Release(target_frame_priv
);
2317 hres
= do_query_service((IUnknown
*)web_browser
, &SID_SHTMLWindow
, &IID_IHTMLWindow2
, (void**)&new_window
);
2320 IWebBrowser2_Quit(web_browser
);
2321 IWebBrowser2_Release(web_browser
);
2324 WARN("Could not create InternetExplorer instance: %08x\n", hres
);
2327 IBindStatusCallback_Release(&bsc
->bsc
.IBindStatusCallback_iface
);
2328 IBindCtx_Release(bind_ctx
);
2332 IWebBrowser2_put_Visible(web_browser
, VARIANT_TRUE
);
2333 IWebBrowser2_Release(web_browser
);
2338 IHTMLWindow2_Release(new_window
);
2342 HRESULT
hlink_frame_navigate(HTMLDocument
*doc
, LPCWSTR url
, nsChannel
*nschannel
, DWORD hlnf
, BOOL
*cancel
)
2344 IHlinkFrame
*hlink_frame
;
2345 nsChannelBSC
*callback
;
2353 hres
= do_query_service((IUnknown
*)doc
->doc_obj
->client
, &IID_IHlinkFrame
, &IID_IHlinkFrame
,
2354 (void**)&hlink_frame
);
2358 hres
= create_channelbsc(NULL
, NULL
, NULL
, 0, FALSE
, &callback
);
2360 IHlinkFrame_Release(hlink_frame
);
2365 read_post_data_stream(nschannel
->post_data_stream
, nschannel
->post_data_contains_headers
,
2366 &nschannel
->request_headers
, &callback
->bsc
.request_data
);
2368 hres
= CreateAsyncBindCtx(0, &callback
->bsc
.IBindStatusCallback_iface
, NULL
, &bindctx
);
2370 hres
= CoCreateInstance(&CLSID_StdHlink
, NULL
, CLSCTX_INPROC_SERVER
,
2371 &IID_IHlink
, (LPVOID
*)&hlink
);
2374 hres
= CreateURLMoniker(NULL
, url
, &mon
);
2376 if(SUCCEEDED(hres
)) {
2377 IHlink_SetMonikerReference(hlink
, HLINKSETF_TARGET
, mon
, NULL
);
2379 if(hlnf
& HLNF_OPENINNEWWINDOW
) {
2380 static const WCHAR wszBlank
[] = {'_','b','l','a','n','k',0};
2381 IHlink_SetTargetFrameName(hlink
, wszBlank
); /* FIXME */
2384 hres
= IHlinkFrame_Navigate(hlink_frame
, hlnf
, bindctx
,
2385 &callback
->bsc
.IBindStatusCallback_iface
, hlink
);
2386 IMoniker_Release(mon
);
2387 *cancel
= hres
== S_OK
;
2391 IHlinkFrame_Release(hlink_frame
);
2392 IBindCtx_Release(bindctx
);
2393 IBindStatusCallback_Release(&callback
->bsc
.IBindStatusCallback_iface
);
2397 static HRESULT
navigate_uri(HTMLOuterWindow
*window
, IUri
*uri
, const WCHAR
*display_uri
, const request_data_t
*request_data
,
2403 TRACE("%s\n", debugstr_w(display_uri
));
2405 if(!window
->browser
)
2406 return E_UNEXPECTED
;
2408 if(window
->browser
->doc
->webbrowser
) {
2409 DWORD post_data_len
= request_data
? request_data
->post_data_len
: 0;
2410 void *post_data
= post_data_len
? request_data
->post_data
: NULL
;
2411 const WCHAR
*headers
= request_data
? request_data
->headers
: NULL
;
2413 if(!(flags
& BINDING_REFRESH
)) {
2414 BSTR frame_name
= NULL
;
2415 BOOL cancel
= FALSE
;
2417 if(!is_main_content_window(window
)) {
2418 hres
= IHTMLWindow2_get_name(&window
->base
.IHTMLWindow2_iface
, &frame_name
);
2423 hres
= IDocObjectService_FireBeforeNavigate2(window
->browser
->doc
->doc_object_service
, NULL
, display_uri
, 0x40,
2424 frame_name
, post_data
, post_data_len
? post_data_len
+1 : 0, headers
, TRUE
, &cancel
);
2425 SysFreeString(frame_name
);
2426 if(SUCCEEDED(hres
) && cancel
) {
2427 TRACE("Navigation canceled\n");
2432 if(is_main_content_window(window
))
2433 return super_navigate(window
, uri
, flags
, headers
, post_data
, post_data_len
);
2436 if(is_main_content_window(window
)) {
2439 hres
= hlink_frame_navigate(&window
->base
.inner_window
->doc
->basedoc
, display_uri
, NULL
, 0, &cancel
);
2444 TRACE("Navigation handled by hlink frame\n");
2449 hres
= create_doc_uri(uri
, &nsuri
);
2453 hres
= load_nsuri(window
, nsuri
, request_data
? request_data
->post_stream
: NULL
, NULL
, LOAD_FLAGS_NONE
);
2454 nsISupports_Release((nsISupports
*)nsuri
);
2458 HRESULT
load_uri(HTMLOuterWindow
*window
, IUri
*uri
, DWORD flags
)
2463 hres
= IUri_GetDisplayUri(uri
, &display_uri
);
2467 hres
= navigate_uri(window
, uri
, display_uri
, NULL
, flags
);
2468 SysFreeString(display_uri
);
2472 static HRESULT
translate_uri(HTMLOuterWindow
*window
, IUri
*orig_uri
, BSTR
*ret_display_uri
, IUri
**ret_uri
)
2478 hres
= IUri_GetDisplayUri(orig_uri
, &display_uri
);
2482 if(window
->browser
->doc
->hostui
) {
2483 OLECHAR
*translated_url
= NULL
;
2485 hres
= IDocHostUIHandler_TranslateUrl(window
->browser
->doc
->hostui
, 0, display_uri
,
2487 if(hres
== S_OK
&& translated_url
) {
2488 TRACE("%08x %s -> %s\n", hres
, debugstr_w(display_uri
), debugstr_w(translated_url
));
2489 SysFreeString(display_uri
);
2490 hres
= create_uri(translated_url
, 0, &uri
);
2491 CoTaskMemFree(translated_url
);
2495 hres
= IUri_GetDisplayUri(uri
, &display_uri
);
2504 IUri_AddRef(orig_uri
);
2508 *ret_display_uri
= display_uri
;
2513 HRESULT
submit_form(HTMLOuterWindow
*window
, const WCHAR
*target
, IUri
*submit_uri
, nsIInputStream
*post_stream
)
2515 request_data_t request_data
= {NULL
};
2518 hres
= read_post_data_stream(post_stream
, TRUE
, NULL
, &request_data
);
2526 window
->readystate_locked
++;
2528 hres
= translate_uri(window
, submit_uri
, &display_uri
, &uri
);
2529 if(SUCCEEDED(hres
)) {
2530 hres
= navigate_uri(window
, uri
, display_uri
, &request_data
, BINDING_NAVIGATED
|BINDING_SUBMIT
);
2532 SysFreeString(display_uri
);
2535 window
->readystate_locked
--;
2537 hres
= navigate_new_window(window
, submit_uri
, target
, &request_data
, NULL
);
2539 release_request_data(&request_data
);
2543 HRESULT
navigate_url(HTMLOuterWindow
*window
, const WCHAR
*new_url
, IUri
*base_uri
, DWORD flags
)
2545 IUri
*uri
, *nav_uri
;
2549 if(new_url
&& base_uri
)
2550 hres
= CoInternetCombineUrlEx(base_uri
, new_url
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
2553 hres
= create_uri(new_url
, 0, &nav_uri
);
2557 hres
= translate_uri(window
, nav_uri
, &display_uri
, &uri
);
2558 IUri_Release(nav_uri
);
2562 hres
= navigate_uri(window
, uri
, display_uri
, NULL
, flags
);
2564 SysFreeString(display_uri
);