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
25 #define NONAMELESSUNION
37 #include "shdeprecated.h"
39 #include "wine/debug.h"
41 #include "mshtml_private.h"
42 #include "htmlscript.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
47 #define CONTENT_LENGTH "Content-Length"
48 #define UTF8_STR "utf-8"
49 #define UTF16_STR "utf-16"
51 static const WCHAR emptyW
[] = {0};
52 static const WCHAR text_htmlW
[] = {'t','e','x','t','/','h','t','m','l',0};
54 struct nsProtocolStream
{
55 nsIInputStream nsIInputStream_iface
;
63 static inline nsProtocolStream
*impl_from_nsIInputStream(nsIInputStream
*iface
)
65 return CONTAINING_RECORD(iface
, nsProtocolStream
, nsIInputStream_iface
);
68 static nsresult NSAPI
nsInputStream_QueryInterface(nsIInputStream
*iface
, nsIIDRef riid
,
71 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
75 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
76 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
77 *result
= &This
->nsIInputStream_iface
;
78 }else if(IsEqualGUID(&IID_nsIInputStream
, riid
)) {
79 TRACE("(%p)->(IID_nsIInputStream %p)\n", This
, result
);
80 *result
= &This
->nsIInputStream_iface
;
84 nsIInputStream_AddRef(&This
->nsIInputStream_iface
);
88 WARN("unsupported interface %s\n", debugstr_guid(riid
));
89 return NS_NOINTERFACE
;
92 static nsrefcnt NSAPI
nsInputStream_AddRef(nsIInputStream
*iface
)
94 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
95 LONG ref
= InterlockedIncrement(&This
->ref
);
97 TRACE("(%p) ref=%d\n", This
, ref
);
103 static nsrefcnt NSAPI
nsInputStream_Release(nsIInputStream
*iface
)
105 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
106 LONG ref
= InterlockedDecrement(&This
->ref
);
108 TRACE("(%p) ref=%d\n", This
, ref
);
116 static nsresult NSAPI
nsInputStream_Close(nsIInputStream
*iface
)
118 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
119 FIXME("(%p)\n", This
);
120 return NS_ERROR_NOT_IMPLEMENTED
;
123 static nsresult NSAPI
nsInputStream_Available(nsIInputStream
*iface
, UINT64
*_retval
)
125 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
126 FIXME("(%p)->(%p)\n", This
, _retval
);
127 return NS_ERROR_NOT_IMPLEMENTED
;
130 static nsresult NSAPI
nsInputStream_Read(nsIInputStream
*iface
, char *aBuf
, UINT32 aCount
,
133 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
136 TRACE("(%p)->(%p %d %p)\n", This
, aBuf
, aCount
, _retval
);
138 if(read
> This
->buf_size
)
139 read
= This
->buf_size
;
142 memcpy(aBuf
, This
->buf
, read
);
143 if(read
< This
->buf_size
)
144 memmove(This
->buf
, This
->buf
+read
, This
->buf_size
-read
);
145 This
->buf_size
-= read
;
152 static nsresult NSAPI
nsInputStream_ReadSegments(nsIInputStream
*iface
,
153 nsresult (WINAPI
*aWriter
)(nsIInputStream
*,void*,const char*,UINT32
,UINT32
,UINT32
*),
154 void *aClousure
, UINT32 aCount
, UINT32
*_retval
)
156 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
160 TRACE("(%p)->(%p %p %d %p)\n", This
, aWriter
, aClousure
, aCount
, _retval
);
165 if(aCount
> This
->buf_size
)
166 aCount
= This
->buf_size
;
168 nsres
= aWriter(&This
->nsIInputStream_iface
, aClousure
, This
->buf
, 0, aCount
, &written
);
170 TRACE("aWriter failed: %08x\n", nsres
);
171 else if(written
!= This
->buf_size
)
172 FIXME("written %d != buf_size %d\n", written
, This
->buf_size
);
174 This
->buf_size
-= written
;
180 static nsresult NSAPI
nsInputStream_IsNonBlocking(nsIInputStream
*iface
, cpp_bool
*_retval
)
182 nsProtocolStream
*This
= impl_from_nsIInputStream(iface
);
183 FIXME("(%p)->(%p)\n", This
, _retval
);
184 return NS_ERROR_NOT_IMPLEMENTED
;
187 static const nsIInputStreamVtbl nsInputStreamVtbl
= {
188 nsInputStream_QueryInterface
,
189 nsInputStream_AddRef
,
190 nsInputStream_Release
,
192 nsInputStream_Available
,
194 nsInputStream_ReadSegments
,
195 nsInputStream_IsNonBlocking
198 static nsProtocolStream
*create_nsprotocol_stream(void)
200 nsProtocolStream
*ret
;
202 ret
= heap_alloc(sizeof(nsProtocolStream
));
206 ret
->nsIInputStream_iface
.lpVtbl
= &nsInputStreamVtbl
;
213 static void release_request_data(request_data_t
*request_data
)
215 if(request_data
->post_stream
)
216 nsIInputStream_Release(request_data
->post_stream
);
217 heap_free(request_data
->headers
);
218 if(request_data
->post_data
)
219 GlobalFree(request_data
->post_data
);
222 static inline BSCallback
*impl_from_IBindStatusCallback(IBindStatusCallback
*iface
)
224 return CONTAINING_RECORD(iface
, BSCallback
, IBindStatusCallback_iface
);
227 static HRESULT WINAPI
BindStatusCallback_QueryInterface(IBindStatusCallback
*iface
,
228 REFIID riid
, void **ppv
)
230 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
233 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
234 TRACE("(%p)->(IID_IUnknown, %p)\n", This
, ppv
);
235 *ppv
= &This
->IBindStatusCallback_iface
;
236 }else if(IsEqualGUID(&IID_IBindStatusCallback
, riid
)) {
237 TRACE("(%p)->(IID_IBindStatusCallback, %p)\n", This
, ppv
);
238 *ppv
= &This
->IBindStatusCallback_iface
;
239 }else if(IsEqualGUID(&IID_IServiceProvider
, riid
)) {
240 TRACE("(%p)->(IID_IServiceProvider %p)\n", This
, ppv
);
241 *ppv
= &This
->IServiceProvider_iface
;
242 }else if(IsEqualGUID(&IID_IHttpNegotiate
, riid
)) {
243 TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This
, ppv
);
244 *ppv
= &This
->IHttpNegotiate2_iface
;
245 }else if(IsEqualGUID(&IID_IHttpNegotiate2
, riid
)) {
246 TRACE("(%p)->(IID_IHttpNegotiate2 %p)\n", This
, ppv
);
247 *ppv
= &This
->IHttpNegotiate2_iface
;
248 }else if(IsEqualGUID(&IID_IInternetBindInfo
, riid
)) {
249 TRACE("(%p)->(IID_IInternetBindInfo %p)\n", This
, ppv
);
250 *ppv
= &This
->IInternetBindInfo_iface
;
251 }else if(IsEqualGUID(&IID_IBindCallbackRedirect
, riid
)) {
252 TRACE("(%p)->(IID_IBindCallbackRedirect %p)\n", This
, ppv
);
253 *ppv
= &This
->IBindCallbackRedirect_iface
;
257 IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
261 TRACE("Unsupported riid = %s\n", debugstr_guid(riid
));
262 return E_NOINTERFACE
;
265 static ULONG WINAPI
BindStatusCallback_AddRef(IBindStatusCallback
*iface
)
267 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
268 LONG ref
= InterlockedIncrement(&This
->ref
);
270 TRACE("(%p) ref = %d\n", This
, ref
);
275 static ULONG WINAPI
BindStatusCallback_Release(IBindStatusCallback
*iface
)
277 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
278 LONG ref
= InterlockedDecrement(&This
->ref
);
280 TRACE("(%p) ref = %d\n", This
, ref
);
283 release_request_data(&This
->request_data
);
285 IMoniker_Release(This
->mon
);
287 IBinding_Release(This
->binding
);
288 list_remove(&This
->entry
);
289 list_init(&This
->entry
);
291 This
->vtbl
->destroy(This
);
297 static HRESULT WINAPI
BindStatusCallback_OnStartBinding(IBindStatusCallback
*iface
,
298 DWORD dwReserved
, IBinding
*pbind
)
300 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
302 TRACE("(%p)->(%d %p)\n", This
, dwReserved
, pbind
);
304 IBinding_AddRef(pbind
);
305 This
->binding
= pbind
;
308 list_add_head(&This
->window
->bindings
, &This
->entry
);
310 return This
->vtbl
->start_binding(This
);
313 static HRESULT WINAPI
BindStatusCallback_GetPriority(IBindStatusCallback
*iface
, LONG
*pnPriority
)
315 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
316 FIXME("(%p)->(%p)\n", This
, pnPriority
);
320 static HRESULT WINAPI
BindStatusCallback_OnLowResource(IBindStatusCallback
*iface
, DWORD reserved
)
322 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
323 FIXME("(%p)->(%d)\n", This
, reserved
);
327 static HRESULT WINAPI
BindStatusCallback_OnProgress(IBindStatusCallback
*iface
, ULONG ulProgress
,
328 ULONG ulProgressMax
, ULONG ulStatusCode
, LPCWSTR szStatusText
)
330 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
332 TRACE("%p)->(%u %u %u %s)\n", This
, ulProgress
, ulProgressMax
, ulStatusCode
,
333 debugstr_w(szStatusText
));
335 return This
->vtbl
->on_progress(This
, ulStatusCode
, szStatusText
);
338 static HRESULT WINAPI
BindStatusCallback_OnStopBinding(IBindStatusCallback
*iface
,
339 HRESULT hresult
, LPCWSTR szError
)
341 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
344 TRACE("(%p)->(%08x %s)\n", This
, hresult
, debugstr_w(szError
));
346 /* NOTE: IE7 calls GetBindResult here */
348 hres
= This
->vtbl
->stop_binding(This
, hresult
);
351 IBinding_Release(This
->binding
);
352 This
->binding
= NULL
;
356 IMoniker_Release(This
->mon
);
360 list_remove(&This
->entry
);
361 list_init(&This
->entry
);
367 static HRESULT WINAPI
BindStatusCallback_GetBindInfo(IBindStatusCallback
*iface
,
368 DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
370 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
373 TRACE("(%p)->(%p %p)\n", This
, grfBINDF
, pbindinfo
);
375 if(!This
->bindinfo_ready
) {
378 hres
= This
->vtbl
->init_bindinfo(This
);
382 This
->bindinfo_ready
= TRUE
;
385 *grfBINDF
= This
->bindf
;
387 size
= pbindinfo
->cbSize
;
388 memset(pbindinfo
, 0, size
);
389 pbindinfo
->cbSize
= size
;
391 pbindinfo
->cbstgmedData
= This
->request_data
.post_data_len
;
392 pbindinfo
->dwCodePage
= CP_UTF8
;
393 pbindinfo
->dwOptions
= This
->bindinfo_options
;
395 if(This
->request_data
.post_data_len
) {
396 pbindinfo
->dwBindVerb
= BINDVERB_POST
;
398 pbindinfo
->stgmedData
.tymed
= TYMED_HGLOBAL
;
399 pbindinfo
->stgmedData
.u
.hGlobal
= This
->request_data
.post_data
;
400 pbindinfo
->stgmedData
.pUnkForRelease
= (IUnknown
*)&This
->IBindStatusCallback_iface
;
401 IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
407 static HRESULT WINAPI
BindStatusCallback_OnDataAvailable(IBindStatusCallback
*iface
,
408 DWORD grfBSCF
, DWORD dwSize
, FORMATETC
*pformatetc
, STGMEDIUM
*pstgmed
)
410 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
412 TRACE("(%p)->(%08x %d %p %p)\n", This
, grfBSCF
, dwSize
, pformatetc
, pstgmed
);
414 return This
->vtbl
->read_data(This
, pstgmed
->u
.pstm
);
417 static HRESULT WINAPI
BindStatusCallback_OnObjectAvailable(IBindStatusCallback
*iface
,
418 REFIID riid
, IUnknown
*punk
)
420 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
421 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), punk
);
425 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl
= {
426 BindStatusCallback_QueryInterface
,
427 BindStatusCallback_AddRef
,
428 BindStatusCallback_Release
,
429 BindStatusCallback_OnStartBinding
,
430 BindStatusCallback_GetPriority
,
431 BindStatusCallback_OnLowResource
,
432 BindStatusCallback_OnProgress
,
433 BindStatusCallback_OnStopBinding
,
434 BindStatusCallback_GetBindInfo
,
435 BindStatusCallback_OnDataAvailable
,
436 BindStatusCallback_OnObjectAvailable
439 static inline BSCallback
*impl_from_IHttpNegotiate2(IHttpNegotiate2
*iface
)
441 return CONTAINING_RECORD(iface
, BSCallback
, IHttpNegotiate2_iface
);
444 static HRESULT WINAPI
HttpNegotiate_QueryInterface(IHttpNegotiate2
*iface
,
445 REFIID riid
, void **ppv
)
447 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
448 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
451 static ULONG WINAPI
HttpNegotiate_AddRef(IHttpNegotiate2
*iface
)
453 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
454 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
457 static ULONG WINAPI
HttpNegotiate_Release(IHttpNegotiate2
*iface
)
459 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
460 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
463 static HRESULT WINAPI
HttpNegotiate_BeginningTransaction(IHttpNegotiate2
*iface
,
464 LPCWSTR szURL
, LPCWSTR szHeaders
, DWORD dwReserved
, LPWSTR
*pszAdditionalHeaders
)
466 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
469 TRACE("(%p)->(%s %s %d %p)\n", This
, debugstr_w(szURL
), debugstr_w(szHeaders
),
470 dwReserved
, pszAdditionalHeaders
);
472 *pszAdditionalHeaders
= NULL
;
474 hres
= This
->vtbl
->beginning_transaction(This
, pszAdditionalHeaders
);
478 if(This
->request_data
.headers
) {
481 size
= (strlenW(This
->request_data
.headers
)+1)*sizeof(WCHAR
);
482 *pszAdditionalHeaders
= CoTaskMemAlloc(size
);
483 if(!*pszAdditionalHeaders
)
484 return E_OUTOFMEMORY
;
485 memcpy(*pszAdditionalHeaders
, This
->request_data
.headers
, size
);
491 static HRESULT WINAPI
HttpNegotiate_OnResponse(IHttpNegotiate2
*iface
, DWORD dwResponseCode
,
492 LPCWSTR szResponseHeaders
, LPCWSTR szRequestHeaders
, LPWSTR
*pszAdditionalRequestHeaders
)
494 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
496 TRACE("(%p)->(%d %s %s %p)\n", This
, dwResponseCode
, debugstr_w(szResponseHeaders
),
497 debugstr_w(szRequestHeaders
), pszAdditionalRequestHeaders
);
499 return This
->vtbl
->on_response(This
, dwResponseCode
, szResponseHeaders
);
502 static HRESULT WINAPI
HttpNegotiate_GetRootSecurityId(IHttpNegotiate2
*iface
,
503 BYTE
*pbSecurityId
, DWORD
*pcbSecurityId
, DWORD_PTR dwReserved
)
505 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
506 TRACE("(%p)->(%p %p %ld)\n", This
, pbSecurityId
, pcbSecurityId
, dwReserved
);
507 return E_NOTIMPL
; /* FIXME */
510 static const IHttpNegotiate2Vtbl HttpNegotiate2Vtbl
= {
511 HttpNegotiate_QueryInterface
,
512 HttpNegotiate_AddRef
,
513 HttpNegotiate_Release
,
514 HttpNegotiate_BeginningTransaction
,
515 HttpNegotiate_OnResponse
,
516 HttpNegotiate_GetRootSecurityId
519 static inline BSCallback
*impl_from_IInternetBindInfo(IInternetBindInfo
*iface
)
521 return CONTAINING_RECORD(iface
, BSCallback
, IInternetBindInfo_iface
);
524 static HRESULT WINAPI
InternetBindInfo_QueryInterface(IInternetBindInfo
*iface
,
525 REFIID riid
, void **ppv
)
527 BSCallback
*This
= impl_from_IInternetBindInfo(iface
);
528 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
531 static ULONG WINAPI
InternetBindInfo_AddRef(IInternetBindInfo
*iface
)
533 BSCallback
*This
= impl_from_IInternetBindInfo(iface
);
534 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
537 static ULONG WINAPI
InternetBindInfo_Release(IInternetBindInfo
*iface
)
539 BSCallback
*This
= impl_from_IInternetBindInfo(iface
);
540 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
543 static HRESULT WINAPI
InternetBindInfo_GetBindInfo(IInternetBindInfo
*iface
,
544 DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
546 BSCallback
*This
= impl_from_IInternetBindInfo(iface
);
547 FIXME("(%p)->(%p %p)\n", This
, grfBINDF
, pbindinfo
);
551 static HRESULT WINAPI
InternetBindInfo_GetBindString(IInternetBindInfo
*iface
,
552 ULONG ulStringType
, LPOLESTR
*ppwzStr
, ULONG cEl
, ULONG
*pcElFetched
)
554 BSCallback
*This
= impl_from_IInternetBindInfo(iface
);
555 FIXME("(%p)->(%u %p %u %p)\n", This
, ulStringType
, ppwzStr
, cEl
, pcElFetched
);
559 static const IInternetBindInfoVtbl InternetBindInfoVtbl
= {
560 InternetBindInfo_QueryInterface
,
561 InternetBindInfo_AddRef
,
562 InternetBindInfo_Release
,
563 InternetBindInfo_GetBindInfo
,
564 InternetBindInfo_GetBindString
567 static inline BSCallback
*impl_from_IBindCallbackRedirect(IBindCallbackRedirect
*iface
)
569 return CONTAINING_RECORD(iface
, BSCallback
, IBindCallbackRedirect_iface
);
572 static HRESULT WINAPI
BindCallbackRedirect_QueryInterface(IBindCallbackRedirect
*iface
, REFIID riid
, void **ppv
)
574 BSCallback
*This
= impl_from_IBindCallbackRedirect(iface
);
575 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
578 static ULONG WINAPI
BindCallbackRedirect_AddRef(IBindCallbackRedirect
*iface
)
580 BSCallback
*This
= impl_from_IBindCallbackRedirect(iface
);
581 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
584 static ULONG WINAPI
BindCallbackRedirect_Release(IBindCallbackRedirect
*iface
)
586 BSCallback
*This
= impl_from_IBindCallbackRedirect(iface
);
587 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
590 static HRESULT WINAPI
BindCallbackRedirect_Redirect(IBindCallbackRedirect
*iface
, const WCHAR
*url
, VARIANT_BOOL
*vbCancel
)
592 BSCallback
*This
= impl_from_IBindCallbackRedirect(iface
);
593 HTMLDocumentObj
*doc_obj
;
595 BSTR frame_name
= NULL
;
598 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(url
), vbCancel
);
600 if(This
->window
&& This
->window
->base
.outer_window
&& (doc_obj
= This
->window
->base
.outer_window
->doc_obj
)
601 && doc_obj
->doc_object_service
) {
602 if(This
->window
->base
.outer_window
!= doc_obj
->basedoc
.window
) {
603 hres
= IHTMLWindow2_get_name(&This
->window
->base
.IHTMLWindow2_iface
, &frame_name
);
608 hres
= IDocObjectService_FireBeforeNavigate2(doc_obj
->doc_object_service
, NULL
, url
, 0x40,
609 frame_name
, NULL
, 0, NULL
, TRUE
, &cancel
);
610 SysFreeString(frame_name
);
613 *vbCancel
= cancel
? VARIANT_TRUE
: VARIANT_FALSE
;
617 static const IBindCallbackRedirectVtbl BindCallbackRedirectVtbl
= {
618 BindCallbackRedirect_QueryInterface
,
619 BindCallbackRedirect_AddRef
,
620 BindCallbackRedirect_Release
,
621 BindCallbackRedirect_Redirect
624 static inline BSCallback
*impl_from_IServiceProvider(IServiceProvider
*iface
)
626 return CONTAINING_RECORD(iface
, BSCallback
, IServiceProvider_iface
);
629 static HRESULT WINAPI
BSCServiceProvider_QueryInterface(IServiceProvider
*iface
,
630 REFIID riid
, void **ppv
)
632 BSCallback
*This
= impl_from_IServiceProvider(iface
);
633 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
636 static ULONG WINAPI
BSCServiceProvider_AddRef(IServiceProvider
*iface
)
638 BSCallback
*This
= impl_from_IServiceProvider(iface
);
639 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
642 static ULONG WINAPI
BSCServiceProvider_Release(IServiceProvider
*iface
)
644 BSCallback
*This
= impl_from_IServiceProvider(iface
);
645 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
648 static HRESULT WINAPI
BSCServiceProvider_QueryService(IServiceProvider
*iface
,
649 REFGUID guidService
, REFIID riid
, void **ppv
)
651 BSCallback
*This
= impl_from_IServiceProvider(iface
);
653 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_guid(guidService
), debugstr_guid(riid
), ppv
);
655 if(This
->window
&& IsEqualGUID(guidService
, &IID_IWindowForBindingUI
))
656 return IServiceProvider_QueryService(&This
->window
->base
.IServiceProvider_iface
, guidService
, riid
, ppv
);
657 return E_NOINTERFACE
;
660 static const IServiceProviderVtbl ServiceProviderVtbl
= {
661 BSCServiceProvider_QueryInterface
,
662 BSCServiceProvider_AddRef
,
663 BSCServiceProvider_Release
,
664 BSCServiceProvider_QueryService
667 void init_bscallback(BSCallback
*This
, const BSCallbackVtbl
*vtbl
, IMoniker
*mon
, DWORD bindf
)
669 This
->IBindStatusCallback_iface
.lpVtbl
= &BindStatusCallbackVtbl
;
670 This
->IServiceProvider_iface
.lpVtbl
= &ServiceProviderVtbl
;
671 This
->IHttpNegotiate2_iface
.lpVtbl
= &HttpNegotiate2Vtbl
;
672 This
->IInternetBindInfo_iface
.lpVtbl
= &InternetBindInfoVtbl
;
673 This
->IBindCallbackRedirect_iface
.lpVtbl
= &BindCallbackRedirectVtbl
;
677 This
->bindinfo_options
= BINDINFO_OPTIONS_USE_IE_ENCODING
;
678 This
->bom
= BOM_NONE
;
680 list_init(&This
->entry
);
683 IMoniker_AddRef(mon
);
687 HRESULT
read_stream(BSCallback
*This
, IStream
*stream
, void *buf
, DWORD size
, DWORD
*ret_size
)
689 DWORD read_size
= 0, skip
=0;
693 hres
= IStream_Read(stream
, buf
, size
, &read_size
);
695 if(!This
->readed
&& This
->bom
== BOM_NONE
) {
696 if(read_size
>= 2 && data
[0] == 0xff && data
[1] == 0xfe) {
697 This
->bom
= BOM_UTF16
;
699 }else if(read_size
>= 3 && data
[0] == 0xef && data
[1] == 0xbb && data
[2] == 0xbf) {
700 This
->bom
= BOM_UTF8
;
706 memmove(data
, data
+skip
, read_size
);
710 This
->readed
+= read_size
;
711 *ret_size
= read_size
;
715 static void parse_content_type(nsChannelBSC
*This
, const WCHAR
*value
)
720 static const WCHAR charsetW
[] = {'c','h','a','r','s','e','t','='};
722 ptr
= strchrW(value
, ';');
727 while(*ptr
&& isspaceW(*ptr
))
730 len
= strlenW(value
);
731 if(ptr
+ sizeof(charsetW
)/sizeof(WCHAR
) < value
+len
&& !memicmpW(ptr
, charsetW
, sizeof(charsetW
)/sizeof(WCHAR
))) {
732 size_t charset_len
, lena
;
733 nsACString charset_str
;
734 const WCHAR
*charset
;
737 ptr
+= sizeof(charsetW
)/sizeof(WCHAR
);
740 FIXME("Quoted value\n");
744 while(*ptr
&& *ptr
!= ',')
746 charset_len
= ptr
-charset
;
749 lena
= WideCharToMultiByte(CP_ACP
, 0, charset
, charset_len
, NULL
, 0, NULL
, NULL
);
750 charseta
= heap_alloc(lena
+1);
754 WideCharToMultiByte(CP_ACP
, 0, charset
, charset_len
, charseta
, lena
, NULL
, NULL
);
757 nsACString_InitDepend(&charset_str
, charseta
);
758 nsIHttpChannel_SetContentCharset(&This
->nschannel
->nsIHttpChannel_iface
, &charset_str
);
759 nsACString_Finish(&charset_str
);
762 FIXME("unhandled: %s\n", debugstr_wn(ptr
, len
- (ptr
-value
)));
766 static HRESULT
parse_headers(const WCHAR
*headers
, struct list
*headers_list
)
768 const WCHAR
*header
, *header_end
, *colon
, *value
;
773 if(header
[0] == '\r' && header
[1] == '\n' && !header
[2])
775 for(colon
= header
; *colon
&& *colon
!= ':' && *colon
!= '\r'; colon
++);
785 for(header_end
= value
+1; *header_end
&& *header_end
!= '\r'; header_end
++);
787 hres
= set_http_header(headers_list
, header
, colon
-header
, value
, header_end
-value
);
792 if(header
[0] == '\r' && header
[1] == '\n')
799 static HRESULT
process_response_headers(nsChannelBSC
*This
, const WCHAR
*headers
)
804 static const WCHAR content_typeW
[] = {'c','o','n','t','e','n','t','-','t','y','p','e',0};
806 hres
= parse_headers(headers
, &This
->nschannel
->response_headers
);
810 LIST_FOR_EACH_ENTRY(iter
, &This
->nschannel
->response_headers
, http_header_t
, entry
) {
811 if(!strcmpiW(iter
->header
, content_typeW
))
812 parse_content_type(This
, iter
->data
);
818 static void query_http_info(nsChannelBSC
*This
, IWinInetHttpInfo
*wininet_info
)
824 IWinInetHttpInfo_QueryInfo(wininet_info
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &len
, NULL
, NULL
);
828 buf
= heap_alloc(len
);
832 IWinInetHttpInfo_QueryInfo(wininet_info
, HTTP_QUERY_RAW_HEADERS_CRLF
, buf
, &len
, NULL
, NULL
);
838 ptr
= strchrW(buf
, '\r');
839 if(ptr
&& ptr
[1] == '\n') {
841 process_response_headers(This
, ptr
);
847 HRESULT
start_binding(HTMLInnerWindow
*inner_window
, BSCallback
*bscallback
, IBindCtx
*bctx
)
852 TRACE("(%p %p %p)\n", inner_window
, bscallback
, bctx
);
854 bscallback
->window
= inner_window
;
856 /* NOTE: IE7 calls IsSystemMoniker here*/
859 hres
= RegisterBindStatusCallback(bctx
, &bscallback
->IBindStatusCallback_iface
, NULL
, 0);
861 IBindCtx_AddRef(bctx
);
863 hres
= CreateAsyncBindCtx(0, &bscallback
->IBindStatusCallback_iface
, NULL
, &bctx
);
867 bscallback
->window
= NULL
;
871 hres
= IMoniker_BindToStorage(bscallback
->mon
, bctx
, NULL
, &IID_IStream
, (void**)&str
);
872 IBindCtx_Release(bctx
);
874 WARN("BindToStorage failed: %08x\n", hres
);
875 bscallback
->window
= NULL
;
880 IStream_Release(str
);
885 static HRESULT
read_post_data_stream(nsIInputStream
*stream
, BOOL contains_headers
, struct list
*headers_list
,
886 request_data_t
*request_data
)
888 nsISeekableStream
*seekable_stream
;
889 UINT64 available
= 0;
891 char *data
, *post_data
;
898 nsres
= nsIInputStream_Available(stream
, &available
);
902 post_data
= data
= GlobalAlloc(0, available
+1);
904 return E_OUTOFMEMORY
;
906 nsres
= nsIInputStream_Read(stream
, data
, available
, &data_len
);
907 if(NS_FAILED(nsres
)) {
912 if(contains_headers
) {
913 if(data_len
>= 2 && data
[0] == '\r' && data
[1] == '\n') {
921 post_data
+= data_len
;
922 for(ptr
= data
; ptr
+4 < data
+data_len
; ptr
++) {
923 if(!memcmp(ptr
, "\r\n\r\n", 4)) {
930 data_len
-= post_data
-data
;
932 size
= MultiByteToWideChar(CP_ACP
, 0, data
, ptr
-data
, NULL
, 0);
933 headers
= heap_alloc((size
+1)*sizeof(WCHAR
));
935 MultiByteToWideChar(CP_ACP
, 0, data
, ptr
-data
, headers
, size
);
938 hres
= parse_headers(headers
, headers_list
);
940 request_data
->headers
= headers
;
944 hres
= E_OUTOFMEMORY
;
957 }else if(post_data
!= data
) {
960 new_data
= GlobalAlloc(0, data_len
+1);
962 memcpy(new_data
, post_data
, data_len
);
965 return E_OUTOFMEMORY
;
966 post_data
= new_data
;
970 post_data
[data_len
] = 0;
971 request_data
->post_data
= post_data
;
972 request_data
->post_data_len
= data_len
;
974 nsres
= nsIInputStream_QueryInterface(stream
, &IID_nsISeekableStream
, (void**)&seekable_stream
);
975 assert(nsres
== NS_OK
);
977 nsres
= nsISeekableStream_Seek(seekable_stream
, NS_SEEK_SET
, 0);
978 assert(nsres
== NS_OK
);
980 nsISeekableStream_Release(seekable_stream
);
982 nsIInputStream_AddRef(stream
);
983 request_data
->post_stream
= stream
;
984 TRACE("post_data = %s\n", debugstr_an(request_data
->post_data
, request_data
->post_data_len
));
988 static HRESULT
on_start_nsrequest(nsChannelBSC
*This
)
992 This
->nschannel
->binding
= This
;
994 /* FIXME: it's needed for http connections from BindToObject. */
995 if(!This
->nschannel
->response_status
)
996 This
->nschannel
->response_status
= 200;
998 nsres
= nsIStreamListener_OnStartRequest(This
->nslistener
,
999 (nsIRequest
*)&This
->nschannel
->nsIHttpChannel_iface
, This
->nscontext
);
1000 if(NS_FAILED(nsres
)) {
1001 FIXME("OnStartRequest failed: %08x\n", nsres
);
1005 if(This
->is_doc_channel
) {
1006 if(!This
->bsc
.window
)
1007 return E_ABORT
; /* Binding aborted in OnStartRequest call. */
1008 update_window_doc(This
->bsc
.window
);
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
.readed
;
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
? text_htmlW
: 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
.readed
-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
) {
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 HTMLDocumentObj
*doc_obj
;
1319 if(This
->is_doc_channel
&& This
->bsc
.window
&& This
->bsc
.window
->base
.outer_window
1320 && (doc_obj
= This
->bsc
.window
->base
.outer_window
->doc_obj
)) {
1321 if(doc_obj
->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
.readed
) {
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
)
1393 outer_window
= This
->bsc
.window
->base
.outer_window
;
1395 doc
= outer_window
->doc_obj
;
1396 if(!doc
|| !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
->doc_obj
)
1589 doc_obj
= This
->bsc
.window
->base
.outer_window
->doc_obj
;
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
= strchrW(header
+ 1, ' ');
1690 if(!header
|| header
>= header_end
)
1692 header
= strchrW(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
= strchrW(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 static const WCHAR content_lengthW
[] =
1749 {'C','o','n','t','e','n','t','-','L','e','n','g','t','h',0};
1751 if(!This
->nschannel
)
1754 LIST_FOR_EACH_ENTRY(iter
, &This
->nschannel
->request_headers
, http_header_t
, entry
) {
1755 if(strcmpW(iter
->header
, content_lengthW
))
1756 len
+= strlenW(iter
->header
) + 2 /* ": " */ + strlenW(iter
->data
) + 2 /* "\r\n" */;
1762 *additional_headers
= ptr
= CoTaskMemAlloc((len
+1)*sizeof(WCHAR
));
1764 return E_OUTOFMEMORY
;
1766 LIST_FOR_EACH_ENTRY(iter
, &This
->nschannel
->request_headers
, http_header_t
, entry
) {
1767 if(!strcmpW(iter
->header
, content_lengthW
))
1770 len
= strlenW(iter
->header
);
1771 memcpy(ptr
, iter
->header
, len
*sizeof(WCHAR
));
1777 len
= strlenW(iter
->data
);
1778 memcpy(ptr
, iter
->data
, len
*sizeof(WCHAR
));
1790 static const BSCallbackVtbl nsChannelBSCVtbl
= {
1791 nsChannelBSC_destroy
,
1792 nsChannelBSC_init_bindinfo
,
1793 nsChannelBSC_start_binding
,
1794 nsChannelBSC_stop_binding
,
1795 nsChannelBSC_read_data
,
1796 nsChannelBSC_on_progress
,
1797 nsChannelBSC_on_response
,
1798 nsChannelBSC_beginning_transaction
1801 HRESULT
create_channelbsc(IMoniker
*mon
, const WCHAR
*headers
, BYTE
*post_data
, DWORD post_data_size
,
1802 BOOL is_doc_binding
, nsChannelBSC
**retval
)
1807 ret
= heap_alloc_zero(sizeof(*ret
));
1809 return E_OUTOFMEMORY
;
1811 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
;
1813 bindf
|= BINDF_FORMS_SUBMIT
| BINDF_PRAGMA_NO_CACHE
| BINDF_HYPERLINK
| BINDF_GETNEWESTVERSION
;
1815 init_bscallback(&ret
->bsc
, &nsChannelBSCVtbl
, mon
, bindf
);
1816 ret
->is_doc_channel
= is_doc_binding
;
1819 ret
->bsc
.request_data
.headers
= heap_strdupW(headers
);
1820 if(!ret
->bsc
.request_data
.headers
) {
1821 IBindStatusCallback_Release(&ret
->bsc
.IBindStatusCallback_iface
);
1822 return E_OUTOFMEMORY
;
1827 ret
->bsc
.request_data
.post_data
= GlobalAlloc(0, post_data_size
+1);
1828 if(!ret
->bsc
.request_data
.post_data
) {
1829 release_request_data(&ret
->bsc
.request_data
);
1830 IBindStatusCallback_Release(&ret
->bsc
.IBindStatusCallback_iface
);
1831 return E_OUTOFMEMORY
;
1834 memcpy(ret
->bsc
.request_data
.post_data
, post_data
, post_data_size
);
1835 ((BYTE
*)ret
->bsc
.request_data
.post_data
)[post_data_size
] = 0;
1836 ret
->bsc
.request_data
.post_data_len
= post_data_size
;
1839 TRACE("created %p\n", ret
);
1846 HTMLOuterWindow
*window
;
1847 HTMLInnerWindow
*pending_window
;
1848 } start_doc_binding_task_t
;
1850 static void start_doc_binding_proc(task_t
*_task
)
1852 start_doc_binding_task_t
*task
= (start_doc_binding_task_t
*)_task
;
1854 set_current_mon(task
->window
, task
->pending_window
->bscallback
->bsc
.mon
, BINDING_NAVIGATED
);
1855 start_binding(task
->pending_window
, &task
->pending_window
->bscallback
->bsc
, NULL
);
1858 static void start_doc_binding_task_destr(task_t
*_task
)
1860 start_doc_binding_task_t
*task
= (start_doc_binding_task_t
*)_task
;
1862 IHTMLWindow2_Release(&task
->pending_window
->base
.IHTMLWindow2_iface
);
1866 HRESULT
async_start_doc_binding(HTMLOuterWindow
*window
, HTMLInnerWindow
*pending_window
)
1868 start_doc_binding_task_t
*task
;
1870 TRACE("%p\n", pending_window
);
1872 task
= heap_alloc(sizeof(start_doc_binding_task_t
));
1874 return E_OUTOFMEMORY
;
1876 task
->window
= window
;
1877 task
->pending_window
= pending_window
;
1878 IHTMLWindow2_AddRef(&pending_window
->base
.IHTMLWindow2_iface
);
1880 return push_task(&task
->header
, start_doc_binding_proc
, start_doc_binding_task_destr
, pending_window
->task_magic
);
1883 void abort_window_bindings(HTMLInnerWindow
*window
)
1887 remove_target_tasks(window
->task_magic
);
1889 while(!list_empty(&window
->bindings
)) {
1890 iter
= LIST_ENTRY(window
->bindings
.next
, BSCallback
, entry
);
1892 TRACE("Aborting %p\n", iter
);
1894 IBindStatusCallback_AddRef(&iter
->IBindStatusCallback_iface
);
1897 IBinding_Abort(iter
->binding
);
1899 iter
->vtbl
->stop_binding(iter
, E_ABORT
);
1901 iter
->window
= NULL
;
1902 list_remove(&iter
->entry
);
1903 list_init(&iter
->entry
);
1905 IBindStatusCallback_Release(&iter
->IBindStatusCallback_iface
);
1908 if(window
->bscallback
) {
1909 IBindStatusCallback_Release(&window
->bscallback
->bsc
.IBindStatusCallback_iface
);
1910 window
->bscallback
= NULL
;
1914 IMoniker_Release(window
->mon
);
1919 HRESULT
channelbsc_load_stream(HTMLInnerWindow
*pending_window
, IMoniker
*mon
, IStream
*stream
)
1921 nsChannelBSC
*bscallback
= pending_window
->bscallback
;
1922 HRESULT hres
= S_OK
;
1924 if(!bscallback
->nschannel
) {
1925 ERR("NULL nschannel\n");
1929 bscallback
->nschannel
->content_type
= heap_strdupA("text/html");
1930 if(!bscallback
->nschannel
->content_type
)
1931 return E_OUTOFMEMORY
;
1933 set_current_mon(pending_window
->base
.outer_window
, mon
, 0);
1935 bscallback
->bsc
.window
= pending_window
;
1937 hres
= read_stream_data(bscallback
, stream
);
1939 hres
= async_stop_request(bscallback
);
1941 IBindStatusCallback_OnStopBinding(&bscallback
->bsc
.IBindStatusCallback_iface
, hres
, NULL
);
1946 void channelbsc_set_channel(nsChannelBSC
*This
, nsChannel
*channel
, nsIStreamListener
*listener
, nsISupports
*context
)
1948 nsIHttpChannel_AddRef(&channel
->nsIHttpChannel_iface
);
1949 This
->nschannel
= channel
;
1951 nsIStreamListener_AddRef(listener
);
1952 This
->nslistener
= listener
;
1955 nsISupports_AddRef(context
);
1956 This
->nscontext
= context
;
1959 if(This
->bsc
.request_data
.headers
) {
1962 hres
= parse_headers(This
->bsc
.request_data
.headers
, &channel
->request_headers
);
1963 heap_free(This
->bsc
.request_data
.headers
);
1964 This
->bsc
.request_data
.headers
= NULL
;
1966 WARN("parse_headers failed: %08x\n", hres
);
1972 HTMLOuterWindow
*window
;
1974 } navigate_javascript_task_t
;
1976 static void navigate_javascript_proc(task_t
*_task
)
1978 navigate_javascript_task_t
*task
= (navigate_javascript_task_t
*)_task
;
1979 HTMLOuterWindow
*window
= task
->window
;
1984 static const WCHAR jscriptW
[] = {'j','s','c','r','i','p','t',0};
1986 task
->window
->readystate
= READYSTATE_COMPLETE
;
1988 hres
= IUri_GetPath(task
->uri
, &code
);
1992 hres
= UrlUnescapeW(code
, NULL
, NULL
, URL_UNESCAPE_INPLACE
);
1994 SysFreeString(code
);
1998 set_download_state(window
->doc_obj
, 1);
2000 V_VT(&v
) = VT_EMPTY
;
2001 hres
= exec_script(window
->base
.inner_window
, code
, jscriptW
, &v
);
2002 SysFreeString(code
);
2003 if(SUCCEEDED(hres
) && V_VT(&v
) != VT_EMPTY
) {
2004 FIXME("javascirpt URL returned %s\n", debugstr_variant(&v
));
2008 if(window
->doc_obj
->view_sink
)
2009 IAdviseSink_OnViewChange(window
->doc_obj
->view_sink
, DVASPECT_CONTENT
, -1);
2011 set_download_state(window
->doc_obj
, 0);
2014 static void navigate_javascript_task_destr(task_t
*_task
)
2016 navigate_javascript_task_t
*task
= (navigate_javascript_task_t
*)_task
;
2018 IUri_Release(task
->uri
);
2024 HTMLOuterWindow
*window
;
2025 nsChannelBSC
*bscallback
;
2031 static void navigate_proc(task_t
*_task
)
2033 navigate_task_t
*task
= (navigate_task_t
*)_task
;
2036 hres
= set_moniker(task
->window
, task
->mon
, task
->uri
, NULL
, task
->bscallback
, TRUE
);
2037 if(SUCCEEDED(hres
)) {
2038 set_current_mon(task
->window
, task
->bscallback
->bsc
.mon
, task
->flags
);
2039 set_current_uri(task
->window
, task
->uri
);
2040 start_binding(task
->window
->pending_window
, &task
->bscallback
->bsc
, NULL
);
2044 static void navigate_task_destr(task_t
*_task
)
2046 navigate_task_t
*task
= (navigate_task_t
*)_task
;
2048 IBindStatusCallback_Release(&task
->bscallback
->bsc
.IBindStatusCallback_iface
);
2049 IMoniker_Release(task
->mon
);
2050 IUri_Release(task
->uri
);
2054 static HRESULT
navigate_fragment(HTMLOuterWindow
*window
, IUri
*uri
)
2056 nsIDOMLocation
*nslocation
;
2057 nsAString nsfrag_str
;
2063 const WCHAR selector_formatW
[] = {'a','[','i','d','=','"','%','s','"',']',0};
2065 set_current_uri(window
, uri
);
2067 nsres
= nsIDOMWindow_GetLocation(window
->nswindow
, &nslocation
);
2068 if(FAILED(nsres
) || !nslocation
)
2071 hres
= IUri_GetFragment(uri
, &frag
);
2073 nsIDOMLocation_Release(nslocation
);
2077 nsAString_InitDepend(&nsfrag_str
, frag
);
2078 nsres
= nsIDOMLocation_SetHash(nslocation
, &nsfrag_str
);
2079 nsAString_Finish(&nsfrag_str
);
2080 nsIDOMLocation_Release(nslocation
);
2081 if(NS_FAILED(nsres
))
2082 ERR("SetHash failed: %08x\n", nsres
);
2085 * IE supports scrolling to anchor elements with "#hash" ids (note that '#' is part of the id),
2086 * while Gecko scrolls only to elements with "hash" ids. We scroll the page ourselves if
2087 * a[id="#hash"] element can be found.
2089 selector
= heap_alloc(sizeof(selector_formatW
)+SysStringLen(frag
)*sizeof(WCHAR
));
2091 nsIDOMElement
*nselem
= NULL
;
2092 nsAString selector_str
;
2094 sprintfW(selector
, selector_formatW
, frag
);
2095 nsAString_InitDepend(&selector_str
, selector
);
2096 /* NOTE: Gecko doesn't set result to NULL if there is no match, so nselem must be initialized */
2097 nsres
= nsIDOMHTMLDocument_QuerySelector(window
->base
.inner_window
->doc
->nsdoc
, &selector_str
, &nselem
);
2098 nsAString_Finish(&selector_str
);
2099 heap_free(selector
);
2100 if(NS_SUCCEEDED(nsres
) && nselem
) {
2101 nsIDOMHTMLElement
*html_elem
;
2103 nsres
= nsIDOMElement_QueryInterface(nselem
, &IID_nsIDOMHTMLElement
, (void**)&html_elem
);
2104 nsIDOMElement_Release(nselem
);
2105 if(NS_SUCCEEDED(nsres
)) {
2106 nsIDOMHTMLElement_ScrollIntoView(html_elem
, TRUE
, 1);
2107 nsIDOMHTMLElement_Release(html_elem
);
2112 SysFreeString(frag
);
2114 if(window
->doc_obj
->doc_object_service
) {
2115 IDocObjectService_FireNavigateComplete2(window
->doc_obj
->doc_object_service
, &window
->base
.IHTMLWindow2_iface
, 0x10);
2116 IDocObjectService_FireDocumentComplete(window
->doc_obj
->doc_object_service
, &window
->base
.IHTMLWindow2_iface
, 0);
2123 HRESULT
super_navigate(HTMLOuterWindow
*window
, IUri
*uri
, DWORD flags
, const WCHAR
*headers
, BYTE
*post_data
, DWORD post_data_size
)
2131 uri_nofrag
= get_uri_nofrag(uri
);
2135 if(window
->doc_obj
->client
&& !(flags
& BINDING_REFRESH
)) {
2136 IOleCommandTarget
*cmdtrg
;
2138 hres
= IOleClientSite_QueryInterface(window
->doc_obj
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
2139 if(SUCCEEDED(hres
)) {
2143 hres
= IUri_GetDisplayUri(uri_nofrag
, &url_str
);
2144 if(SUCCEEDED(hres
)) {
2145 V_VT(&in
) = VT_BSTR
;
2146 V_BSTR(&in
) = url_str
;
2147 V_VT(&out
) = VT_BOOL
;
2148 V_BOOL(&out
) = VARIANT_TRUE
;
2149 hres
= IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 67, 0, &in
, &out
);
2150 IOleCommandTarget_Release(cmdtrg
);
2153 SysFreeString(url_str
);
2158 if(!(flags
& BINDING_NOFRAG
) && window
->uri_nofrag
&& !post_data_size
) {
2161 hres
= IUri_IsEqual(uri_nofrag
, window
->uri_nofrag
, &eq
);
2162 if(SUCCEEDED(hres
) && eq
) {
2163 IUri_Release(uri_nofrag
);
2164 TRACE("fragment navigate\n");
2165 return navigate_fragment(window
, uri
);
2169 hres
= CreateURLMonikerEx2(NULL
, uri_nofrag
, &mon
, URL_MK_UNIFORM
);
2170 IUri_Release(uri_nofrag
);
2174 /* FIXME: Why not set_ready_state? */
2175 window
->readystate
= READYSTATE_UNINITIALIZED
;
2177 hres
= create_channelbsc(mon
, headers
, post_data
, post_data_size
, TRUE
, &bsc
);
2179 IMoniker_Release(mon
);
2183 prepare_for_binding(&window
->doc_obj
->basedoc
, mon
, flags
);
2185 hres
= IUri_GetScheme(uri
, &scheme
);
2186 if(SUCCEEDED(hres
) && scheme
== URL_SCHEME_JAVASCRIPT
) {
2187 navigate_javascript_task_t
*task
;
2189 IBindStatusCallback_Release(&bsc
->bsc
.IBindStatusCallback_iface
);
2190 IMoniker_Release(mon
);
2192 task
= heap_alloc(sizeof(*task
));
2194 return E_OUTOFMEMORY
;
2197 window
->readystate
= READYSTATE_COMPLETE
;
2198 if(!(flags
& BINDING_FROMHIST
))
2199 call_docview_84(window
->doc_obj
);
2202 task
->window
= window
;
2204 hres
= push_task(&task
->header
, navigate_javascript_proc
, navigate_javascript_task_destr
, window
->task_magic
);
2205 }else if(flags
& BINDING_SUBMIT
) {
2206 hres
= set_moniker(window
, mon
, uri
, NULL
, bsc
, TRUE
);
2208 hres
= start_binding(window
->pending_window
, &bsc
->bsc
, NULL
);
2209 IBindStatusCallback_Release(&bsc
->bsc
.IBindStatusCallback_iface
);
2210 IMoniker_Release(mon
);
2212 navigate_task_t
*task
;
2214 task
= heap_alloc(sizeof(*task
));
2216 IBindStatusCallback_Release(&bsc
->bsc
.IBindStatusCallback_iface
);
2217 IMoniker_Release(mon
);
2218 return E_OUTOFMEMORY
;
2221 /* Silently and repeated when real loading starts? */
2222 window
->readystate
= READYSTATE_LOADING
;
2223 if(!(flags
& (BINDING_FROMHIST
|BINDING_REFRESH
)))
2224 call_docview_84(window
->doc_obj
);
2226 task
->window
= window
;
2227 task
->bscallback
= bsc
;
2228 task
->flags
= flags
;
2233 hres
= push_task(&task
->header
, navigate_proc
, navigate_task_destr
, window
->task_magic
);
2239 HRESULT
navigate_new_window(HTMLOuterWindow
*window
, IUri
*uri
, const WCHAR
*name
, request_data_t
*request_data
, IHTMLWindow2
**ret
)
2241 IWebBrowser2
*web_browser
;
2242 IHTMLWindow2
*new_window
;
2248 hres
= create_channelbsc(NULL
, request_data
->headers
,
2249 request_data
->post_data
, request_data
->post_data_len
, FALSE
,
2252 hres
= create_channelbsc(NULL
, NULL
, NULL
, 0, FALSE
, &bsc
);
2256 hres
= CreateAsyncBindCtx(0, &bsc
->bsc
.IBindStatusCallback_iface
, NULL
, &bind_ctx
);
2258 IBindStatusCallback_Release(&bsc
->bsc
.IBindStatusCallback_iface
);
2262 hres
= CoCreateInstance(&CLSID_InternetExplorer
, NULL
, CLSCTX_LOCAL_SERVER
,
2263 &IID_IWebBrowser2
, (void**)&web_browser
);
2264 if(SUCCEEDED(hres
)) {
2265 ITargetFramePriv2
*target_frame_priv
;
2267 hres
= IWebBrowser2_QueryInterface(web_browser
, &IID_ITargetFramePriv2
, (void**)&target_frame_priv
);
2268 if(SUCCEEDED(hres
)) {
2269 hres
= ITargetFramePriv2_AggregatedNavigation2(target_frame_priv
,
2270 HLNF_DISABLEWINDOWRESTRICTIONS
|HLNF_OPENINNEWWINDOW
, bind_ctx
, &bsc
->bsc
.IBindStatusCallback_iface
,
2272 ITargetFramePriv2_Release(target_frame_priv
);
2275 hres
= do_query_service((IUnknown
*)web_browser
, &SID_SHTMLWindow
, &IID_IHTMLWindow2
, (void**)&new_window
);
2278 IWebBrowser2_Quit(web_browser
);
2279 IWebBrowser2_Release(web_browser
);
2282 WARN("Could not create InternetExplorer instance: %08x\n", hres
);
2285 IBindStatusCallback_Release(&bsc
->bsc
.IBindStatusCallback_iface
);
2286 IBindCtx_Release(bind_ctx
);
2290 IWebBrowser2_put_Visible(web_browser
, VARIANT_TRUE
);
2291 IWebBrowser2_Release(web_browser
);
2296 IHTMLWindow2_Release(new_window
);
2300 HRESULT
hlink_frame_navigate(HTMLDocument
*doc
, LPCWSTR url
, nsChannel
*nschannel
, DWORD hlnf
, BOOL
*cancel
)
2302 IHlinkFrame
*hlink_frame
;
2303 nsChannelBSC
*callback
;
2311 hres
= do_query_service((IUnknown
*)doc
->doc_obj
->client
, &IID_IHlinkFrame
, &IID_IHlinkFrame
,
2312 (void**)&hlink_frame
);
2316 hres
= create_channelbsc(NULL
, NULL
, NULL
, 0, FALSE
, &callback
);
2318 IHlinkFrame_Release(hlink_frame
);
2323 read_post_data_stream(nschannel
->post_data_stream
, nschannel
->post_data_contains_headers
,
2324 &nschannel
->request_headers
, &callback
->bsc
.request_data
);
2326 hres
= CreateAsyncBindCtx(0, &callback
->bsc
.IBindStatusCallback_iface
, NULL
, &bindctx
);
2328 hres
= CoCreateInstance(&CLSID_StdHlink
, NULL
, CLSCTX_INPROC_SERVER
,
2329 &IID_IHlink
, (LPVOID
*)&hlink
);
2332 hres
= CreateURLMoniker(NULL
, url
, &mon
);
2334 if(SUCCEEDED(hres
)) {
2335 IHlink_SetMonikerReference(hlink
, HLINKSETF_TARGET
, mon
, NULL
);
2337 if(hlnf
& HLNF_OPENINNEWWINDOW
) {
2338 static const WCHAR wszBlank
[] = {'_','b','l','a','n','k',0};
2339 IHlink_SetTargetFrameName(hlink
, wszBlank
); /* FIXME */
2342 hres
= IHlinkFrame_Navigate(hlink_frame
, hlnf
, bindctx
,
2343 &callback
->bsc
.IBindStatusCallback_iface
, hlink
);
2344 IMoniker_Release(mon
);
2345 *cancel
= hres
== S_OK
;
2349 IHlinkFrame_Release(hlink_frame
);
2350 IBindCtx_Release(bindctx
);
2351 IBindStatusCallback_Release(&callback
->bsc
.IBindStatusCallback_iface
);
2355 static HRESULT
navigate_uri(HTMLOuterWindow
*window
, IUri
*uri
, const WCHAR
*display_uri
, const request_data_t
*request_data
,
2361 TRACE("%s\n", debugstr_w(display_uri
));
2363 if(window
->doc_obj
&& window
->doc_obj
->webbrowser
) {
2364 DWORD post_data_len
= request_data
? request_data
->post_data_len
: 0;
2365 void *post_data
= post_data_len
? request_data
->post_data
: NULL
;
2366 const WCHAR
*headers
= request_data
? request_data
->headers
: NULL
;
2368 if(!(flags
& BINDING_REFRESH
)) {
2369 BSTR frame_name
= NULL
;
2370 BOOL cancel
= FALSE
;
2372 if(window
!= window
->doc_obj
->basedoc
.window
) {
2373 hres
= IHTMLWindow2_get_name(&window
->base
.IHTMLWindow2_iface
, &frame_name
);
2378 hres
= IDocObjectService_FireBeforeNavigate2(window
->doc_obj
->doc_object_service
, NULL
, display_uri
, 0x40,
2379 frame_name
, post_data
, post_data_len
? post_data_len
+1 : 0, headers
, TRUE
, &cancel
);
2380 SysFreeString(frame_name
);
2381 if(SUCCEEDED(hres
) && cancel
) {
2382 TRACE("Navigation canceled\n");
2387 if(window
== window
->doc_obj
->basedoc
.window
)
2388 return super_navigate(window
, uri
, flags
, headers
, post_data
, post_data_len
);
2391 if(window
->doc_obj
&& window
== window
->doc_obj
->basedoc
.window
) {
2394 hres
= hlink_frame_navigate(&window
->base
.inner_window
->doc
->basedoc
, display_uri
, NULL
, 0, &cancel
);
2399 TRACE("Navigation handled by hlink frame\n");
2404 hres
= create_doc_uri(window
, uri
, &nsuri
);
2408 hres
= load_nsuri(window
, nsuri
, request_data
? request_data
->post_stream
: NULL
, NULL
, LOAD_FLAGS_NONE
);
2409 nsISupports_Release((nsISupports
*)nsuri
);
2413 HRESULT
load_uri(HTMLOuterWindow
*window
, IUri
*uri
, DWORD flags
)
2418 hres
= IUri_GetDisplayUri(uri
, &display_uri
);
2422 hres
= navigate_uri(window
, uri
, display_uri
, NULL
, flags
);
2423 SysFreeString(display_uri
);
2427 static HRESULT
translate_uri(HTMLOuterWindow
*window
, IUri
*orig_uri
, BSTR
*ret_display_uri
, IUri
**ret_uri
)
2433 hres
= IUri_GetDisplayUri(orig_uri
, &display_uri
);
2437 if(window
->doc_obj
&& window
->doc_obj
->hostui
) {
2438 OLECHAR
*translated_url
= NULL
;
2440 hres
= IDocHostUIHandler_TranslateUrl(window
->doc_obj
->hostui
, 0, display_uri
,
2442 if(hres
== S_OK
&& translated_url
) {
2443 TRACE("%08x %s -> %s\n", hres
, debugstr_w(display_uri
), debugstr_w(translated_url
));
2444 SysFreeString(display_uri
);
2445 hres
= create_uri(translated_url
, 0, &uri
);
2446 CoTaskMemFree(translated_url
);
2450 hres
= IUri_GetDisplayUri(uri
, &display_uri
);
2459 IUri_AddRef(orig_uri
);
2463 *ret_display_uri
= display_uri
;
2468 HRESULT
submit_form(HTMLOuterWindow
*window
, const WCHAR
*target
, IUri
*submit_uri
, nsIInputStream
*post_stream
)
2470 request_data_t request_data
= {NULL
};
2473 hres
= read_post_data_stream(post_stream
, TRUE
, NULL
, &request_data
);
2481 window
->readystate_locked
++;
2483 hres
= translate_uri(window
, submit_uri
, &display_uri
, &uri
);
2484 if(SUCCEEDED(hres
)) {
2485 hres
= navigate_uri(window
, uri
, display_uri
, &request_data
, BINDING_NAVIGATED
|BINDING_SUBMIT
);
2487 SysFreeString(display_uri
);
2490 window
->readystate_locked
--;
2492 hres
= navigate_new_window(window
, submit_uri
, target
, &request_data
, NULL
);
2494 release_request_data(&request_data
);
2498 HRESULT
navigate_url(HTMLOuterWindow
*window
, const WCHAR
*new_url
, IUri
*base_uri
, DWORD flags
)
2500 IUri
*uri
, *nav_uri
;
2504 if(new_url
&& base_uri
)
2505 hres
= CoInternetCombineUrlEx(base_uri
, new_url
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
2508 hres
= create_uri(new_url
, 0, &nav_uri
);
2512 hres
= translate_uri(window
, nav_uri
, &display_uri
, &uri
);
2513 IUri_Release(nav_uri
);
2517 hres
= navigate_uri(window
, uri
, display_uri
, NULL
, flags
);
2519 SysFreeString(display_uri
);