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
;
254 IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
258 TRACE("Unsupported riid = %s\n", debugstr_guid(riid
));
259 return E_NOINTERFACE
;
262 static ULONG WINAPI
BindStatusCallback_AddRef(IBindStatusCallback
*iface
)
264 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
265 LONG ref
= InterlockedIncrement(&This
->ref
);
267 TRACE("(%p) ref = %d\n", This
, ref
);
272 static ULONG WINAPI
BindStatusCallback_Release(IBindStatusCallback
*iface
)
274 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
275 LONG ref
= InterlockedDecrement(&This
->ref
);
277 TRACE("(%p) ref = %d\n", This
, ref
);
280 release_request_data(&This
->request_data
);
282 IMoniker_Release(This
->mon
);
284 IBinding_Release(This
->binding
);
285 list_remove(&This
->entry
);
286 list_init(&This
->entry
);
288 This
->vtbl
->destroy(This
);
294 static HRESULT WINAPI
BindStatusCallback_OnStartBinding(IBindStatusCallback
*iface
,
295 DWORD dwReserved
, IBinding
*pbind
)
297 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
299 TRACE("(%p)->(%d %p)\n", This
, dwReserved
, pbind
);
301 IBinding_AddRef(pbind
);
302 This
->binding
= pbind
;
305 list_add_head(&This
->window
->bindings
, &This
->entry
);
307 return This
->vtbl
->start_binding(This
);
310 static HRESULT WINAPI
BindStatusCallback_GetPriority(IBindStatusCallback
*iface
, LONG
*pnPriority
)
312 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
313 FIXME("(%p)->(%p)\n", This
, pnPriority
);
317 static HRESULT WINAPI
BindStatusCallback_OnLowResource(IBindStatusCallback
*iface
, DWORD reserved
)
319 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
320 FIXME("(%p)->(%d)\n", This
, reserved
);
324 static HRESULT WINAPI
BindStatusCallback_OnProgress(IBindStatusCallback
*iface
, ULONG ulProgress
,
325 ULONG ulProgressMax
, ULONG ulStatusCode
, LPCWSTR szStatusText
)
327 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
329 TRACE("%p)->(%u %u %u %s)\n", This
, ulProgress
, ulProgressMax
, ulStatusCode
,
330 debugstr_w(szStatusText
));
332 return This
->vtbl
->on_progress(This
, ulStatusCode
, szStatusText
);
335 static HRESULT WINAPI
BindStatusCallback_OnStopBinding(IBindStatusCallback
*iface
,
336 HRESULT hresult
, LPCWSTR szError
)
338 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
341 TRACE("(%p)->(%08x %s)\n", This
, hresult
, debugstr_w(szError
));
343 /* NOTE: IE7 calls GetBindResult here */
345 hres
= This
->vtbl
->stop_binding(This
, hresult
);
348 IBinding_Release(This
->binding
);
349 This
->binding
= NULL
;
353 IMoniker_Release(This
->mon
);
357 list_remove(&This
->entry
);
358 list_init(&This
->entry
);
364 static HRESULT WINAPI
BindStatusCallback_GetBindInfo(IBindStatusCallback
*iface
,
365 DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
367 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
370 TRACE("(%p)->(%p %p)\n", This
, grfBINDF
, pbindinfo
);
372 if(!This
->bindinfo_ready
) {
375 hres
= This
->vtbl
->init_bindinfo(This
);
379 This
->bindinfo_ready
= TRUE
;
382 *grfBINDF
= This
->bindf
;
384 size
= pbindinfo
->cbSize
;
385 memset(pbindinfo
, 0, size
);
386 pbindinfo
->cbSize
= size
;
388 pbindinfo
->cbstgmedData
= This
->request_data
.post_data_len
;
389 pbindinfo
->dwCodePage
= CP_UTF8
;
390 pbindinfo
->dwOptions
= 0x80000;
392 if(This
->request_data
.post_data_len
) {
393 pbindinfo
->dwBindVerb
= BINDVERB_POST
;
395 pbindinfo
->stgmedData
.tymed
= TYMED_HGLOBAL
;
396 pbindinfo
->stgmedData
.u
.hGlobal
= This
->request_data
.post_data
;
397 pbindinfo
->stgmedData
.pUnkForRelease
= (IUnknown
*)&This
->IBindStatusCallback_iface
;
398 IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
404 static HRESULT WINAPI
BindStatusCallback_OnDataAvailable(IBindStatusCallback
*iface
,
405 DWORD grfBSCF
, DWORD dwSize
, FORMATETC
*pformatetc
, STGMEDIUM
*pstgmed
)
407 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
409 TRACE("(%p)->(%08x %d %p %p)\n", This
, grfBSCF
, dwSize
, pformatetc
, pstgmed
);
411 return This
->vtbl
->read_data(This
, pstgmed
->u
.pstm
);
414 static HRESULT WINAPI
BindStatusCallback_OnObjectAvailable(IBindStatusCallback
*iface
,
415 REFIID riid
, IUnknown
*punk
)
417 BSCallback
*This
= impl_from_IBindStatusCallback(iface
);
418 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), punk
);
422 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl
= {
423 BindStatusCallback_QueryInterface
,
424 BindStatusCallback_AddRef
,
425 BindStatusCallback_Release
,
426 BindStatusCallback_OnStartBinding
,
427 BindStatusCallback_GetPriority
,
428 BindStatusCallback_OnLowResource
,
429 BindStatusCallback_OnProgress
,
430 BindStatusCallback_OnStopBinding
,
431 BindStatusCallback_GetBindInfo
,
432 BindStatusCallback_OnDataAvailable
,
433 BindStatusCallback_OnObjectAvailable
436 static inline BSCallback
*impl_from_IHttpNegotiate2(IHttpNegotiate2
*iface
)
438 return CONTAINING_RECORD(iface
, BSCallback
, IHttpNegotiate2_iface
);
441 static HRESULT WINAPI
HttpNegotiate_QueryInterface(IHttpNegotiate2
*iface
,
442 REFIID riid
, void **ppv
)
444 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
445 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
448 static ULONG WINAPI
HttpNegotiate_AddRef(IHttpNegotiate2
*iface
)
450 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
451 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
454 static ULONG WINAPI
HttpNegotiate_Release(IHttpNegotiate2
*iface
)
456 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
457 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
460 static HRESULT WINAPI
HttpNegotiate_BeginningTransaction(IHttpNegotiate2
*iface
,
461 LPCWSTR szURL
, LPCWSTR szHeaders
, DWORD dwReserved
, LPWSTR
*pszAdditionalHeaders
)
463 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
466 TRACE("(%p)->(%s %s %d %p)\n", This
, debugstr_w(szURL
), debugstr_w(szHeaders
),
467 dwReserved
, pszAdditionalHeaders
);
469 *pszAdditionalHeaders
= NULL
;
471 hres
= This
->vtbl
->beginning_transaction(This
, pszAdditionalHeaders
);
475 if(This
->request_data
.headers
) {
478 size
= (strlenW(This
->request_data
.headers
)+1)*sizeof(WCHAR
);
479 *pszAdditionalHeaders
= CoTaskMemAlloc(size
);
480 if(!*pszAdditionalHeaders
)
481 return E_OUTOFMEMORY
;
482 memcpy(*pszAdditionalHeaders
, This
->request_data
.headers
, size
);
488 static HRESULT WINAPI
HttpNegotiate_OnResponse(IHttpNegotiate2
*iface
, DWORD dwResponseCode
,
489 LPCWSTR szResponseHeaders
, LPCWSTR szRequestHeaders
, LPWSTR
*pszAdditionalRequestHeaders
)
491 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
493 TRACE("(%p)->(%d %s %s %p)\n", This
, dwResponseCode
, debugstr_w(szResponseHeaders
),
494 debugstr_w(szRequestHeaders
), pszAdditionalRequestHeaders
);
496 return This
->vtbl
->on_response(This
, dwResponseCode
, szResponseHeaders
);
499 static HRESULT WINAPI
HttpNegotiate_GetRootSecurityId(IHttpNegotiate2
*iface
,
500 BYTE
*pbSecurityId
, DWORD
*pcbSecurityId
, DWORD_PTR dwReserved
)
502 BSCallback
*This
= impl_from_IHttpNegotiate2(iface
);
503 FIXME("(%p)->(%p %p %ld)\n", This
, pbSecurityId
, pcbSecurityId
, dwReserved
);
507 static const IHttpNegotiate2Vtbl HttpNegotiate2Vtbl
= {
508 HttpNegotiate_QueryInterface
,
509 HttpNegotiate_AddRef
,
510 HttpNegotiate_Release
,
511 HttpNegotiate_BeginningTransaction
,
512 HttpNegotiate_OnResponse
,
513 HttpNegotiate_GetRootSecurityId
516 static inline BSCallback
*impl_from_IInternetBindInfo(IInternetBindInfo
*iface
)
518 return CONTAINING_RECORD(iface
, BSCallback
, IInternetBindInfo_iface
);
521 static HRESULT WINAPI
InternetBindInfo_QueryInterface(IInternetBindInfo
*iface
,
522 REFIID riid
, void **ppv
)
524 BSCallback
*This
= impl_from_IInternetBindInfo(iface
);
525 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
528 static ULONG WINAPI
InternetBindInfo_AddRef(IInternetBindInfo
*iface
)
530 BSCallback
*This
= impl_from_IInternetBindInfo(iface
);
531 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
534 static ULONG WINAPI
InternetBindInfo_Release(IInternetBindInfo
*iface
)
536 BSCallback
*This
= impl_from_IInternetBindInfo(iface
);
537 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
540 static HRESULT WINAPI
InternetBindInfo_GetBindInfo(IInternetBindInfo
*iface
,
541 DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
543 BSCallback
*This
= impl_from_IInternetBindInfo(iface
);
544 FIXME("(%p)->(%p %p)\n", This
, grfBINDF
, pbindinfo
);
548 static HRESULT WINAPI
InternetBindInfo_GetBindString(IInternetBindInfo
*iface
,
549 ULONG ulStringType
, LPOLESTR
*ppwzStr
, ULONG cEl
, ULONG
*pcElFetched
)
551 BSCallback
*This
= impl_from_IInternetBindInfo(iface
);
552 FIXME("(%p)->(%u %p %u %p)\n", This
, ulStringType
, ppwzStr
, cEl
, pcElFetched
);
556 static const IInternetBindInfoVtbl InternetBindInfoVtbl
= {
557 InternetBindInfo_QueryInterface
,
558 InternetBindInfo_AddRef
,
559 InternetBindInfo_Release
,
560 InternetBindInfo_GetBindInfo
,
561 InternetBindInfo_GetBindString
564 static inline BSCallback
*impl_from_IServiceProvider(IServiceProvider
*iface
)
566 return CONTAINING_RECORD(iface
, BSCallback
, IServiceProvider_iface
);
569 static HRESULT WINAPI
BSCServiceProvider_QueryInterface(IServiceProvider
*iface
,
570 REFIID riid
, void **ppv
)
572 BSCallback
*This
= impl_from_IServiceProvider(iface
);
573 return IBindStatusCallback_QueryInterface(&This
->IBindStatusCallback_iface
, riid
, ppv
);
576 static ULONG WINAPI
BSCServiceProvider_AddRef(IServiceProvider
*iface
)
578 BSCallback
*This
= impl_from_IServiceProvider(iface
);
579 return IBindStatusCallback_AddRef(&This
->IBindStatusCallback_iface
);
582 static ULONG WINAPI
BSCServiceProvider_Release(IServiceProvider
*iface
)
584 BSCallback
*This
= impl_from_IServiceProvider(iface
);
585 return IBindStatusCallback_Release(&This
->IBindStatusCallback_iface
);
588 static HRESULT WINAPI
BSCServiceProvider_QueryService(IServiceProvider
*iface
,
589 REFGUID guidService
, REFIID riid
, void **ppv
)
591 BSCallback
*This
= impl_from_IServiceProvider(iface
);
593 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_guid(guidService
), debugstr_guid(riid
), ppv
);
595 if(This
->window
&& IsEqualGUID(guidService
, &IID_IWindowForBindingUI
))
596 return IServiceProvider_QueryService(&This
->window
->base
.IServiceProvider_iface
, guidService
, riid
, ppv
);
597 return E_NOINTERFACE
;
600 static const IServiceProviderVtbl ServiceProviderVtbl
= {
601 BSCServiceProvider_QueryInterface
,
602 BSCServiceProvider_AddRef
,
603 BSCServiceProvider_Release
,
604 BSCServiceProvider_QueryService
607 void init_bscallback(BSCallback
*This
, const BSCallbackVtbl
*vtbl
, IMoniker
*mon
, DWORD bindf
)
609 This
->IBindStatusCallback_iface
.lpVtbl
= &BindStatusCallbackVtbl
;
610 This
->IServiceProvider_iface
.lpVtbl
= &ServiceProviderVtbl
;
611 This
->IHttpNegotiate2_iface
.lpVtbl
= &HttpNegotiate2Vtbl
;
612 This
->IInternetBindInfo_iface
.lpVtbl
= &InternetBindInfoVtbl
;
616 This
->bom
= BOM_NONE
;
618 list_init(&This
->entry
);
621 IMoniker_AddRef(mon
);
625 HRESULT
read_stream(BSCallback
*This
, IStream
*stream
, void *buf
, DWORD size
, DWORD
*ret_size
)
627 DWORD read_size
= 0, skip
=0;
631 hres
= IStream_Read(stream
, buf
, size
, &read_size
);
633 if(!This
->readed
&& This
->bom
== BOM_NONE
) {
634 if(read_size
>= 2 && data
[0] == 0xff && data
[1] == 0xfe) {
635 This
->bom
= BOM_UTF16
;
637 }else if(read_size
>= 3 && data
[0] == 0xef && data
[1] == 0xbb && data
[2] == 0xbf) {
638 This
->bom
= BOM_UTF8
;
644 memmove(data
, data
+skip
, read_size
);
648 This
->readed
+= read_size
;
649 *ret_size
= read_size
;
653 static void parse_content_type(nsChannelBSC
*This
, const WCHAR
*value
)
658 static const WCHAR charsetW
[] = {'c','h','a','r','s','e','t','='};
660 ptr
= strchrW(value
, ';');
665 while(*ptr
&& isspaceW(*ptr
))
668 len
= strlenW(value
);
669 if(ptr
+ sizeof(charsetW
)/sizeof(WCHAR
) < value
+len
&& !memicmpW(ptr
, charsetW
, sizeof(charsetW
)/sizeof(WCHAR
))) {
670 size_t charset_len
, lena
;
671 nsACString charset_str
;
672 const WCHAR
*charset
;
675 ptr
+= sizeof(charsetW
)/sizeof(WCHAR
);
678 FIXME("Quoted value\n");
682 while(*ptr
&& *ptr
!= ',')
684 charset_len
= ptr
-charset
;
687 lena
= WideCharToMultiByte(CP_ACP
, 0, charset
, charset_len
, NULL
, 0, NULL
, NULL
);
688 charseta
= heap_alloc(lena
+1);
692 WideCharToMultiByte(CP_ACP
, 0, charset
, charset_len
, charseta
, lena
, NULL
, NULL
);
695 nsACString_InitDepend(&charset_str
, charseta
);
696 nsIHttpChannel_SetContentCharset(&This
->nschannel
->nsIHttpChannel_iface
, &charset_str
);
697 nsACString_Finish(&charset_str
);
700 FIXME("unhandled: %s\n", debugstr_wn(ptr
, len
- (ptr
-value
)));
704 static HRESULT
parse_headers(const WCHAR
*headers
, struct list
*headers_list
)
706 const WCHAR
*header
, *header_end
, *colon
, *value
;
711 if(header
[0] == '\r' && header
[1] == '\n' && !header
[2])
713 for(colon
= header
; *colon
&& *colon
!= ':' && *colon
!= '\r'; colon
++);
723 for(header_end
= value
+1; *header_end
&& *header_end
!= '\r'; header_end
++);
725 hres
= set_http_header(headers_list
, header
, colon
-header
, value
, header_end
-value
);
730 if(header
[0] == '\r' && header
[1] == '\n')
737 static HRESULT
process_response_headers(nsChannelBSC
*This
, const WCHAR
*headers
)
742 static const WCHAR content_typeW
[] = {'c','o','n','t','e','n','t','-','t','y','p','e',0};
744 hres
= parse_headers(headers
, &This
->nschannel
->response_headers
);
748 LIST_FOR_EACH_ENTRY(iter
, &This
->nschannel
->response_headers
, http_header_t
, entry
) {
749 if(!strcmpiW(iter
->header
, content_typeW
))
750 parse_content_type(This
, iter
->data
);
756 static void query_http_info(nsChannelBSC
*This
, IWinInetHttpInfo
*wininet_info
)
762 IWinInetHttpInfo_QueryInfo(wininet_info
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &len
, NULL
, NULL
);
766 buf
= heap_alloc(len
);
770 IWinInetHttpInfo_QueryInfo(wininet_info
, HTTP_QUERY_RAW_HEADERS_CRLF
, buf
, &len
, NULL
, NULL
);
776 ptr
= strchrW(buf
, '\r');
777 if(ptr
&& ptr
[1] == '\n') {
779 process_response_headers(This
, ptr
);
785 HRESULT
start_binding(HTMLInnerWindow
*inner_window
, BSCallback
*bscallback
, IBindCtx
*bctx
)
790 TRACE("(%p %p %p)\n", inner_window
, bscallback
, bctx
);
792 bscallback
->window
= inner_window
;
794 /* NOTE: IE7 calls IsSystemMoniker here*/
797 hres
= RegisterBindStatusCallback(bctx
, &bscallback
->IBindStatusCallback_iface
, NULL
, 0);
799 IBindCtx_AddRef(bctx
);
801 hres
= CreateAsyncBindCtx(0, &bscallback
->IBindStatusCallback_iface
, NULL
, &bctx
);
805 bscallback
->window
= NULL
;
809 hres
= IMoniker_BindToStorage(bscallback
->mon
, bctx
, NULL
, &IID_IStream
, (void**)&str
);
810 IBindCtx_Release(bctx
);
812 WARN("BindToStorage failed: %08x\n", hres
);
813 bscallback
->window
= NULL
;
818 IStream_Release(str
);
823 static HRESULT
read_post_data_stream(nsIInputStream
*stream
, BOOL contains_headers
, struct list
*headers_list
,
824 request_data_t
*request_data
)
826 nsISeekableStream
*seekable_stream
;
827 UINT64 available
= 0;
829 char *data
, *post_data
;
836 nsres
= nsIInputStream_Available(stream
, &available
);
840 post_data
= data
= GlobalAlloc(0, available
+1);
842 return E_OUTOFMEMORY
;
844 nsres
= nsIInputStream_Read(stream
, data
, available
, &data_len
);
845 if(NS_FAILED(nsres
)) {
850 if(contains_headers
) {
851 if(data_len
>= 2 && data
[0] == '\r' && data
[1] == '\n') {
859 post_data
+= data_len
;
860 for(ptr
= data
; ptr
+4 < data
+data_len
; ptr
++) {
861 if(!memcmp(ptr
, "\r\n\r\n", 4)) {
868 data_len
-= post_data
-data
;
870 size
= MultiByteToWideChar(CP_ACP
, 0, data
, ptr
-data
, NULL
, 0);
871 headers
= heap_alloc((size
+1)*sizeof(WCHAR
));
873 MultiByteToWideChar(CP_ACP
, 0, data
, ptr
-data
, headers
, size
);
876 hres
= parse_headers(headers
, headers_list
);
878 request_data
->headers
= headers
;
882 hres
= E_OUTOFMEMORY
;
895 }else if(post_data
!= data
) {
898 new_data
= GlobalAlloc(0, data_len
+1);
900 memcpy(new_data
, post_data
, data_len
);
903 return E_OUTOFMEMORY
;
904 post_data
= new_data
;
908 post_data
[data_len
] = 0;
909 request_data
->post_data
= post_data
;
910 request_data
->post_data_len
= data_len
;
912 nsres
= nsIInputStream_QueryInterface(stream
, &IID_nsISeekableStream
, (void**)&seekable_stream
);
913 assert(nsres
== NS_OK
);
915 nsres
= nsISeekableStream_Seek(seekable_stream
, NS_SEEK_SET
, 0);
916 assert(nsres
== NS_OK
);
918 nsISeekableStream_Release(seekable_stream
);
920 nsIInputStream_AddRef(stream
);
921 request_data
->post_stream
= stream
;
922 TRACE("post_data = %s\n", debugstr_an(request_data
->post_data
, request_data
->post_data_len
));
926 static HRESULT
on_start_nsrequest(nsChannelBSC
*This
)
930 /* FIXME: it's needed for http connections from BindToObject. */
931 if(!This
->nschannel
->response_status
)
932 This
->nschannel
->response_status
= 200;
934 nsres
= nsIStreamListener_OnStartRequest(This
->nslistener
,
935 (nsIRequest
*)&This
->nschannel
->nsIHttpChannel_iface
, This
->nscontext
);
936 if(NS_FAILED(nsres
)) {
937 FIXME("OnStartRequest failed: %08x\n", nsres
);
941 if(This
->is_doc_channel
) {
942 update_window_doc(This
->bsc
.window
);
943 if(This
->bsc
.window
->base
.outer_window
->readystate
!= READYSTATE_LOADING
)
944 set_ready_state(This
->bsc
.window
->base
.outer_window
, READYSTATE_LOADING
);
950 static void on_stop_nsrequest(nsChannelBSC
*This
, HRESULT result
)
952 nsresult nsres
, request_result
;
956 request_result
= NS_OK
;
959 request_result
= NS_BINDING_ABORTED
;
962 request_result
= NS_ERROR_FAILURE
;
965 if(This
->nslistener
) {
966 nsres
= nsIStreamListener_OnStopRequest(This
->nslistener
,
967 (nsIRequest
*)&This
->nschannel
->nsIHttpChannel_iface
, This
->nscontext
,
970 WARN("OnStopRequest failed: %08x\n", nsres
);
973 if(This
->nschannel
&& This
->nschannel
->load_group
) {
974 nsres
= nsILoadGroup_RemoveRequest(This
->nschannel
->load_group
,
975 (nsIRequest
*)&This
->nschannel
->nsIHttpChannel_iface
, NULL
, request_result
);
977 ERR("RemoveRequest failed: %08x\n", nsres
);
981 static HRESULT
read_stream_data(nsChannelBSC
*This
, IStream
*stream
)
987 if(!This
->response_processed
) {
988 IWinInetHttpInfo
*wininet_info
;
990 This
->response_processed
= TRUE
;
991 if(This
->bsc
.binding
) {
992 hres
= IBinding_QueryInterface(This
->bsc
.binding
, &IID_IWinInetHttpInfo
, (void**)&wininet_info
);
993 if(SUCCEEDED(hres
)) {
994 query_http_info(This
, wininet_info
);
995 IWinInetHttpInfo_Release(wininet_info
);
1000 if(!This
->nschannel
)
1003 if(!This
->nslistener
) {
1007 hres
= read_stream(&This
->bsc
, stream
, buf
, sizeof(buf
), &read
);
1008 }while(hres
== S_OK
&& read
);
1013 if(!This
->nsstream
) {
1014 This
->nsstream
= create_nsprotocol_stream();
1016 return E_OUTOFMEMORY
;
1020 BOOL first_read
= !This
->bsc
.readed
;
1022 hres
= read_stream(&This
->bsc
, stream
, This
->nsstream
->buf
+This
->nsstream
->buf_size
,
1023 sizeof(This
->nsstream
->buf
)-This
->nsstream
->buf_size
, &read
);
1027 This
->nsstream
->buf_size
+= read
;
1030 switch(This
->bsc
.bom
) {
1032 This
->nschannel
->charset
= heap_strdupA(UTF8_STR
);
1035 This
->nschannel
->charset
= heap_strdupA(UTF16_STR
);
1037 /* FIXME: Get charset from HTTP headers */;
1040 if(!This
->nschannel
->content_type
) {
1043 hres
= FindMimeFromData(NULL
, NULL
, This
->nsstream
->buf
, This
->nsstream
->buf_size
,
1044 This
->is_doc_channel
? text_htmlW
: NULL
, 0, &mime
, 0);
1048 TRACE("Found MIME %s\n", debugstr_w(mime
));
1050 This
->nschannel
->content_type
= heap_strdupWtoA(mime
);
1051 CoTaskMemFree(mime
);
1052 if(!This
->nschannel
->content_type
)
1053 return E_OUTOFMEMORY
;
1056 on_start_nsrequest(This
);
1059 nsres
= nsIStreamListener_OnDataAvailable(This
->nslistener
,
1060 (nsIRequest
*)&This
->nschannel
->nsIHttpChannel_iface
, This
->nscontext
,
1061 &This
->nsstream
->nsIInputStream_iface
, This
->bsc
.readed
-This
->nsstream
->buf_size
,
1062 This
->nsstream
->buf_size
);
1063 if(NS_FAILED(nsres
))
1064 ERR("OnDataAvailable failed: %08x\n", nsres
);
1066 if(This
->nsstream
->buf_size
== sizeof(This
->nsstream
->buf
)) {
1067 ERR("buffer is full\n");
1070 }while(hres
== S_OK
);
1076 nsIAsyncVerifyRedirectCallback nsIAsyncVerifyRedirectCallback_iface
;
1080 nsChannel
*nschannel
;
1082 } nsRedirectCallback
;
1084 static nsRedirectCallback
*impl_from_nsIAsyncVerifyRedirectCallback(nsIAsyncVerifyRedirectCallback
*iface
)
1086 return CONTAINING_RECORD(iface
, nsRedirectCallback
, nsIAsyncVerifyRedirectCallback_iface
);
1089 static nsresult NSAPI
nsAsyncVerifyRedirectCallback_QueryInterface(nsIAsyncVerifyRedirectCallback
*iface
,
1090 nsIIDRef riid
, void **result
)
1092 nsRedirectCallback
*This
= impl_from_nsIAsyncVerifyRedirectCallback(iface
);
1094 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1095 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1096 *result
= &This
->nsIAsyncVerifyRedirectCallback_iface
;
1097 }else if(IsEqualGUID(&IID_nsIAsyncVerifyRedirectCallback
, riid
)) {
1098 TRACE("(%p)->(IID_nsIAsyncVerifyRedirectCallback %p)\n", This
, result
);
1099 *result
= &This
->nsIAsyncVerifyRedirectCallback_iface
;
1102 WARN("unimplemented iface %s\n", debugstr_guid(riid
));
1103 return NS_NOINTERFACE
;
1106 nsISupports_AddRef((nsISupports
*)*result
);
1110 static nsrefcnt NSAPI
nsAsyncVerifyRedirectCallback_AddRef(nsIAsyncVerifyRedirectCallback
*iface
)
1112 nsRedirectCallback
*This
= impl_from_nsIAsyncVerifyRedirectCallback(iface
);
1113 LONG ref
= InterlockedIncrement(&This
->ref
);
1115 TRACE("(%p) ref=%d\n", This
, ref
);
1120 static nsrefcnt NSAPI
nsAsyncVerifyRedirectCallback_Release(nsIAsyncVerifyRedirectCallback
*iface
)
1122 nsRedirectCallback
*This
= impl_from_nsIAsyncVerifyRedirectCallback(iface
);
1123 LONG ref
= InterlockedDecrement(&This
->ref
);
1125 TRACE("(%p) ref=%d\n", This
, ref
);
1128 IBindStatusCallback_Release(&This
->bsc
->bsc
.IBindStatusCallback_iface
);
1129 nsIHttpChannel_Release(&This
->nschannel
->nsIHttpChannel_iface
);
1136 static nsresult NSAPI
nsAsyncVerifyRedirectCallback_AsyncOnChannelRedirect(nsIAsyncVerifyRedirectCallback
*iface
, nsresult result
)
1138 nsRedirectCallback
*This
= impl_from_nsIAsyncVerifyRedirectCallback(iface
);
1139 nsChannel
*old_nschannel
;
1142 TRACE("(%p)->(%08x)\n", This
, result
);
1144 old_nschannel
= This
->bsc
->nschannel
;
1145 nsIHttpChannel_AddRef(&This
->nschannel
->nsIHttpChannel_iface
);
1146 This
->bsc
->nschannel
= This
->nschannel
;
1148 if(This
->nschannel
->load_group
) {
1149 nsres
= nsILoadGroup_AddRequest(This
->nschannel
->load_group
, (nsIRequest
*)&This
->nschannel
->nsIHttpChannel_iface
,
1151 if(NS_FAILED(nsres
))
1152 ERR("AddRequest failed: %08x\n", nsres
);
1155 if(This
->bsc
->is_doc_channel
) {
1156 IUri
*uri
= nsuri_get_uri(This
->nschannel
->uri
);
1159 set_current_uri(This
->bsc
->bsc
.window
->base
.outer_window
, uri
);
1162 WARN("Could not get IUri from nsWineURI\n");
1167 if(old_nschannel
->load_group
) {
1168 nsres
= nsILoadGroup_RemoveRequest(old_nschannel
->load_group
,
1169 (nsIRequest
*)&old_nschannel
->nsIHttpChannel_iface
, NULL
, NS_OK
);
1170 if(NS_FAILED(nsres
))
1171 ERR("RemoveRequest failed: %08x\n", nsres
);
1173 nsIHttpChannel_Release(&old_nschannel
->nsIHttpChannel_iface
);
1179 static const nsIAsyncVerifyRedirectCallbackVtbl nsAsyncVerifyRedirectCallbackVtbl
= {
1180 nsAsyncVerifyRedirectCallback_QueryInterface
,
1181 nsAsyncVerifyRedirectCallback_AddRef
,
1182 nsAsyncVerifyRedirectCallback_Release
,
1183 nsAsyncVerifyRedirectCallback_AsyncOnChannelRedirect
1186 static HRESULT
create_redirect_callback(nsChannel
*nschannel
, nsChannelBSC
*bsc
, nsRedirectCallback
**ret
)
1188 nsRedirectCallback
*callback
;
1190 callback
= heap_alloc(sizeof(*callback
));
1192 return E_OUTOFMEMORY
;
1194 callback
->nsIAsyncVerifyRedirectCallback_iface
.lpVtbl
= &nsAsyncVerifyRedirectCallbackVtbl
;
1197 nsIHttpChannel_AddRef(&nschannel
->nsIHttpChannel_iface
);
1198 callback
->nschannel
= nschannel
;
1200 IBindStatusCallback_AddRef(&bsc
->bsc
.IBindStatusCallback_iface
);
1201 callback
->bsc
= bsc
;
1207 static inline nsChannelBSC
*nsChannelBSC_from_BSCallback(BSCallback
*iface
)
1209 return CONTAINING_RECORD(iface
, nsChannelBSC
, bsc
);
1212 static void nsChannelBSC_destroy(BSCallback
*bsc
)
1214 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1217 nsIHttpChannel_Release(&This
->nschannel
->nsIHttpChannel_iface
);
1218 if(This
->nslistener
)
1219 nsIStreamListener_Release(This
->nslistener
);
1221 nsISupports_Release(This
->nscontext
);
1223 nsIInputStream_Release(&This
->nsstream
->nsIInputStream_iface
);
1227 static HRESULT
nsChannelBSC_start_binding(BSCallback
*bsc
)
1229 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1231 if(This
->is_doc_channel
)
1232 This
->bsc
.window
->base
.outer_window
->base
.inner_window
->doc
->skip_mutation_notif
= FALSE
;
1237 static HRESULT
nsChannelBSC_init_bindinfo(BSCallback
*bsc
)
1239 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1240 nsChannel
*nschannel
= This
->nschannel
;
1243 if(nschannel
&& nschannel
->post_data_stream
) {
1244 hres
= read_post_data_stream(nschannel
->post_data_stream
, nschannel
->post_data_contains_headers
,
1245 &nschannel
->request_headers
, &This
->bsc
.request_data
);
1256 } stop_request_task_t
;
1258 static void stop_request_proc(task_t
*_task
)
1260 stop_request_task_t
*task
= (stop_request_task_t
*)_task
;
1262 TRACE("(%p)\n", task
->bsc
);
1264 list_remove(&task
->bsc
->bsc
.entry
);
1265 list_init(&task
->bsc
->bsc
.entry
);
1266 on_stop_nsrequest(task
->bsc
, S_OK
);
1269 static void stop_request_task_destr(task_t
*_task
)
1271 stop_request_task_t
*task
= (stop_request_task_t
*)_task
;
1273 IBindStatusCallback_Release(&task
->bsc
->bsc
.IBindStatusCallback_iface
);
1277 static HRESULT
async_stop_request(nsChannelBSC
*This
)
1279 stop_request_task_t
*task
;
1281 if(!This
->bsc
.readed
) {
1282 TRACE("No data read, calling OnStartRequest\n");
1283 on_start_nsrequest(This
);
1286 task
= heap_alloc(sizeof(*task
));
1288 return E_OUTOFMEMORY
;
1290 IBindStatusCallback_AddRef(&This
->bsc
.IBindStatusCallback_iface
);
1293 return push_task(&task
->header
, stop_request_proc
, stop_request_task_destr
, This
->bsc
.window
->task_magic
);
1296 static void handle_navigation_error(nsChannelBSC
*This
, DWORD result
)
1298 HTMLOuterWindow
*outer_window
;
1299 HTMLDocumentObj
*doc
;
1302 SAFEARRAYBOUND bound
;
1303 VARIANT var
, varOut
;
1308 if(!This
->is_doc_channel
|| !This
->bsc
.window
)
1311 outer_window
= This
->bsc
.window
->base
.outer_window
;
1313 doc
= outer_window
->doc_obj
;
1314 if(!doc
|| !doc
->doc_object_service
|| !doc
->client
)
1317 hres
= IDocObjectService_IsErrorUrl(doc
->doc_object_service
,
1318 outer_window
->url
, &is_error_url
);
1319 if(FAILED(hres
) || is_error_url
)
1322 if(!doc
->client_cmdtrg
)
1326 bound
.cElements
= 8;
1327 sa
= SafeArrayCreate(VT_VARIANT
, 1, &bound
);
1333 V_I4(&var
) = result
;
1334 SafeArrayPutElement(sa
, &ind
, &var
);
1337 V_VT(&var
) = VT_BSTR
;
1338 V_BSTR(&var
) = outer_window
->url
;
1339 SafeArrayPutElement(sa
, &ind
, &var
);
1342 V_VT(&var
) = VT_UNKNOWN
;
1343 V_UNKNOWN(&var
) = (IUnknown
*)&outer_window
->base
.IHTMLWindow2_iface
;
1344 SafeArrayPutElement(sa
, &ind
, &var
);
1346 /* FIXME: what are the following fields for? */
1348 V_VT(&var
) = VT_UNKNOWN
;
1349 V_UNKNOWN(&var
) = NULL
;
1350 SafeArrayPutElement(sa
, &ind
, &var
);
1353 V_VT(&var
) = VT_BOOL
;
1354 V_BOOL(&var
) = FALSE
;
1355 SafeArrayPutElement(sa
, &ind
, &var
);
1358 V_VT(&var
) = VT_BOOL
;
1359 V_BOOL(&var
) = FALSE
;
1360 SafeArrayPutElement(sa
, &ind
, &var
);
1363 V_VT(&var
) = VT_BSTR
;
1364 unk
= SysAllocString(NULL
);
1366 SafeArrayPutElement(sa
, &ind
, &var
);
1369 V_VT(&var
) = VT_UNKNOWN
;
1370 V_UNKNOWN(&var
) = NULL
;
1371 SafeArrayPutElement(sa
, &ind
, &var
);
1373 V_VT(&var
) = VT_ARRAY
;
1375 V_VT(&varOut
) = VT_BOOL
;
1376 V_BOOL(&varOut
) = VARIANT_TRUE
;
1377 IOleCommandTarget_Exec(doc
->client_cmdtrg
, &CGID_DocHostCmdPriv
, 1, 0, &var
, FAILED(hres
)?NULL
:&varOut
);
1380 SafeArrayDestroy(sa
);
1383 static HRESULT
nsChannelBSC_stop_binding(BSCallback
*bsc
, HRESULT result
)
1385 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1387 if(result
!= E_ABORT
) {
1389 handle_navigation_error(This
, result
);
1390 else if(This
->is_doc_channel
&& This
->nschannel
) {
1391 result
= async_stop_request(This
);
1392 if(SUCCEEDED(result
))
1397 on_stop_nsrequest(This
, result
);
1401 static HRESULT
nsChannelBSC_read_data(BSCallback
*bsc
, IStream
*stream
)
1403 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1405 return read_stream_data(This
, stream
);
1408 static HRESULT
handle_redirect(nsChannelBSC
*This
, const WCHAR
*new_url
)
1410 nsRedirectCallback
*callback
;
1411 nsIChannelEventSink
*sink
;
1412 nsChannel
*new_channel
;
1416 TRACE("(%p)->(%s)\n", This
, debugstr_w(new_url
));
1418 if(!This
->nschannel
|| !This
->nschannel
->notif_callback
)
1421 nsres
= nsIInterfaceRequestor_GetInterface(This
->nschannel
->notif_callback
, &IID_nsIChannelEventSink
, (void**)&sink
);
1422 if(NS_FAILED(nsres
))
1425 hres
= create_redirect_nschannel(new_url
, This
->nschannel
, &new_channel
);
1426 if(SUCCEEDED(hres
)) {
1427 TRACE("%p %p->%p\n", This
, This
->nschannel
, new_channel
);
1429 hres
= create_redirect_callback(new_channel
, This
, &callback
);
1430 nsIHttpChannel_Release(&new_channel
->nsIHttpChannel_iface
);
1433 if(SUCCEEDED(hres
)) {
1434 nsres
= nsIChannelEventSink_AsyncOnChannelRedirect(sink
, (nsIChannel
*)&This
->nschannel
->nsIHttpChannel_iface
,
1435 (nsIChannel
*)&callback
->nschannel
->nsIHttpChannel_iface
, REDIRECT_TEMPORARY
, /* FIXME */
1436 &callback
->nsIAsyncVerifyRedirectCallback_iface
);
1438 if(NS_FAILED(nsres
))
1439 FIXME("AsyncOnChannelRedirect failed: %08x\n", hres
);
1440 else if(This
->nschannel
!= callback
->nschannel
)
1441 FIXME("nschannel not updated\n");
1443 nsIAsyncVerifyRedirectCallback_Release(&callback
->nsIAsyncVerifyRedirectCallback_iface
);
1446 nsIChannelEventSink_Release(sink
);
1450 static BOOL
is_supported_doc_mime(const WCHAR
*mime
)
1452 char *nscat
, *mimea
;
1455 mimea
= heap_strdupWtoA(mime
);
1459 nscat
= get_nscategory_entry("Gecko-Content-Viewers", mimea
);
1461 ret
= nscat
!= NULL
&& !strcmp(nscat
, "@mozilla.org/content/document-loader-factory;1");
1468 static IUri
*get_moniker_uri(IMoniker
*mon
)
1470 IUriContainer
*uri_container
;
1474 hres
= IMoniker_QueryInterface(mon
, &IID_IUriContainer
, (void**)&uri_container
);
1475 if(SUCCEEDED(hres
)) {
1476 hres
= IUriContainer_GetIUri(uri_container
, &ret
);
1477 IUriContainer_Release(uri_container
);
1481 FIXME("No IUriContainer\n");
1487 static void handle_extern_mime_navigation(nsChannelBSC
*This
)
1489 IWebBrowserPriv2IE9
*webbrowser_priv
;
1490 IOleCommandTarget
*cmdtrg
;
1491 HTMLDocumentObj
*doc_obj
;
1497 if(!This
->bsc
.window
|| !This
->bsc
.window
->base
.outer_window
|| !This
->bsc
.window
->base
.outer_window
->doc_obj
)
1500 doc_obj
= This
->bsc
.window
->base
.outer_window
->doc_obj
;
1502 hres
= IOleClientSite_QueryInterface(doc_obj
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
1503 if(SUCCEEDED(hres
)) {
1504 IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 62, 0, NULL
, NULL
);
1505 IOleCommandTarget_Release(cmdtrg
);
1508 set_document_navigation(doc_obj
, FALSE
);
1510 if(!doc_obj
->webbrowser
) {
1511 FIXME("unimplemented in non-webbrowser mode\n");
1515 uri
= get_moniker_uri(This
->bsc
.mon
);
1519 hres
= CreateBindCtx(0, &bind_ctx
);
1525 V_VT(&flags
) = VT_I4
;
1526 V_I4(&flags
) = navHyperlink
;
1528 hres
= IUnknown_QueryInterface(doc_obj
->webbrowser
, &IID_IWebBrowserPriv2IE8
, (void**)&webbrowser_priv
);
1529 if(SUCCEEDED(hres
)) {
1530 hres
= IWebBrowserPriv2IE9_NavigateWithBindCtx2(webbrowser_priv
, uri
, &flags
, NULL
, NULL
, NULL
, bind_ctx
, NULL
, 0);
1531 IWebBrowserPriv2IE9_Release(webbrowser_priv
);
1533 IWebBrowserPriv
*webbrowser_priv_old
;
1536 hres
= IUnknown_QueryInterface(doc_obj
->webbrowser
, &IID_IWebBrowserPriv
, (void**)&webbrowser_priv_old
);
1537 if(SUCCEEDED(hres
)) {
1538 V_VT(&uriv
) = VT_BSTR
;
1539 IUri_GetDisplayUri(uri
, &V_BSTR(&uriv
));
1541 hres
= IWebBrowserPriv_NavigateWithBindCtx(webbrowser_priv_old
, &uriv
, &flags
, NULL
, NULL
, NULL
, bind_ctx
, NULL
);
1543 SysFreeString(V_BSTR(&uriv
));
1544 IWebBrowserPriv_Release(webbrowser_priv_old
);
1551 static HRESULT
nsChannelBSC_on_progress(BSCallback
*bsc
, ULONG status_code
, LPCWSTR status_text
)
1553 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1555 switch(status_code
) {
1556 case BINDSTATUS_MIMETYPEAVAILABLE
:
1557 if(This
->is_doc_channel
&& !is_supported_doc_mime(status_text
)) {
1558 FIXME("External MIME: %s\n", debugstr_w(status_text
));
1560 handle_extern_mime_navigation(This
);
1562 This
->nschannel
= NULL
;
1565 if(!This
->nschannel
)
1568 heap_free(This
->nschannel
->content_type
);
1569 This
->nschannel
->content_type
= heap_strdupWtoA(status_text
);
1571 case BINDSTATUS_REDIRECTING
:
1572 return handle_redirect(This
, status_text
);
1573 case BINDSTATUS_BEGINDOWNLOADDATA
: {
1574 IWinInetHttpInfo
*http_info
;
1575 DWORD status
, size
= sizeof(DWORD
);
1578 if(!This
->bsc
.binding
)
1581 hres
= IBinding_QueryInterface(This
->bsc
.binding
, &IID_IWinInetHttpInfo
, (void**)&http_info
);
1585 hres
= IWinInetHttpInfo_QueryInfo(http_info
,
1586 HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
, NULL
);
1587 IWinInetHttpInfo_Release(http_info
);
1588 if(FAILED(hres
) || status
== HTTP_STATUS_OK
)
1591 handle_navigation_error(This
, status
);
1598 static HRESULT
process_response_status_text(const WCHAR
*header
, const WCHAR
*header_end
, char **status_text
)
1600 header
= strchrW(header
+ 1, ' ');
1601 if(!header
|| header
>= header_end
)
1603 header
= strchrW(header
+ 1, ' ');
1604 if(!header
|| header
>= header_end
)
1608 *status_text
= heap_strndupWtoU(header
, header_end
- header
);
1611 return E_OUTOFMEMORY
;
1616 static HRESULT
nsChannelBSC_on_response(BSCallback
*bsc
, DWORD response_code
,
1617 LPCWSTR response_headers
)
1619 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1623 This
->response_processed
= TRUE
;
1624 This
->nschannel
->response_status
= response_code
;
1626 if(response_headers
) {
1627 const WCHAR
*headers
;
1629 headers
= strchrW(response_headers
, '\r');
1630 hres
= process_response_status_text(response_headers
, headers
, &str
);
1632 WARN("parsing headers failed: %08x\n", hres
);
1636 heap_free(This
->nschannel
->response_status_text
);
1637 This
->nschannel
->response_status_text
= str
;
1639 if(headers
&& headers
[1] == '\n') {
1641 hres
= process_response_headers(This
, headers
);
1643 WARN("parsing headers failed: %08x\n", hres
);
1652 static HRESULT
nsChannelBSC_beginning_transaction(BSCallback
*bsc
, WCHAR
**additional_headers
)
1654 nsChannelBSC
*This
= nsChannelBSC_from_BSCallback(bsc
);
1655 http_header_t
*iter
;
1659 static const WCHAR content_lengthW
[] =
1660 {'C','o','n','t','e','n','t','-','L','e','n','g','t','h',0};
1662 if(!This
->nschannel
)
1665 LIST_FOR_EACH_ENTRY(iter
, &This
->nschannel
->request_headers
, http_header_t
, entry
) {
1666 if(strcmpW(iter
->header
, content_lengthW
))
1667 len
+= strlenW(iter
->header
) + 2 /* ": " */ + strlenW(iter
->data
) + 2 /* "\r\n" */;
1673 *additional_headers
= ptr
= CoTaskMemAlloc((len
+1)*sizeof(WCHAR
));
1675 return E_OUTOFMEMORY
;
1677 LIST_FOR_EACH_ENTRY(iter
, &This
->nschannel
->request_headers
, http_header_t
, entry
) {
1678 if(!strcmpW(iter
->header
, content_lengthW
))
1681 len
= strlenW(iter
->header
);
1682 memcpy(ptr
, iter
->header
, len
*sizeof(WCHAR
));
1688 len
= strlenW(iter
->data
);
1689 memcpy(ptr
, iter
->data
, len
*sizeof(WCHAR
));
1701 static const BSCallbackVtbl nsChannelBSCVtbl
= {
1702 nsChannelBSC_destroy
,
1703 nsChannelBSC_init_bindinfo
,
1704 nsChannelBSC_start_binding
,
1705 nsChannelBSC_stop_binding
,
1706 nsChannelBSC_read_data
,
1707 nsChannelBSC_on_progress
,
1708 nsChannelBSC_on_response
,
1709 nsChannelBSC_beginning_transaction
1712 HRESULT
create_channelbsc(IMoniker
*mon
, const WCHAR
*headers
, BYTE
*post_data
, DWORD post_data_size
,
1713 BOOL is_doc_binding
, nsChannelBSC
**retval
)
1718 ret
= heap_alloc_zero(sizeof(*ret
));
1720 return E_OUTOFMEMORY
;
1722 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
;
1724 bindf
|= BINDF_FORMS_SUBMIT
| BINDF_PRAGMA_NO_CACHE
| BINDF_HYPERLINK
| BINDF_GETNEWESTVERSION
;
1726 init_bscallback(&ret
->bsc
, &nsChannelBSCVtbl
, mon
, bindf
);
1727 ret
->is_doc_channel
= is_doc_binding
;
1730 ret
->bsc
.request_data
.headers
= heap_strdupW(headers
);
1731 if(!ret
->bsc
.request_data
.headers
) {
1732 IBindStatusCallback_Release(&ret
->bsc
.IBindStatusCallback_iface
);
1733 return E_OUTOFMEMORY
;
1738 ret
->bsc
.request_data
.post_data
= GlobalAlloc(0, post_data_size
+1);
1739 if(!ret
->bsc
.request_data
.post_data
) {
1740 release_request_data(&ret
->bsc
.request_data
);
1741 IBindStatusCallback_Release(&ret
->bsc
.IBindStatusCallback_iface
);
1742 return E_OUTOFMEMORY
;
1745 memcpy(ret
->bsc
.request_data
.post_data
, post_data
, post_data_size
);
1746 ((BYTE
*)ret
->bsc
.request_data
.post_data
)[post_data_size
] = 0;
1747 ret
->bsc
.request_data
.post_data_len
= post_data_size
;
1750 TRACE("created %p\n", ret
);
1757 HTMLOuterWindow
*window
;
1758 HTMLInnerWindow
*pending_window
;
1759 } start_doc_binding_task_t
;
1761 static void start_doc_binding_proc(task_t
*_task
)
1763 start_doc_binding_task_t
*task
= (start_doc_binding_task_t
*)_task
;
1765 set_current_mon(task
->window
, task
->pending_window
->bscallback
->bsc
.mon
, BINDING_NAVIGATED
);
1766 start_binding(task
->pending_window
, &task
->pending_window
->bscallback
->bsc
, NULL
);
1769 static void start_doc_binding_task_destr(task_t
*_task
)
1771 start_doc_binding_task_t
*task
= (start_doc_binding_task_t
*)_task
;
1773 IHTMLWindow2_Release(&task
->pending_window
->base
.IHTMLWindow2_iface
);
1777 HRESULT
async_start_doc_binding(HTMLOuterWindow
*window
, HTMLInnerWindow
*pending_window
)
1779 start_doc_binding_task_t
*task
;
1781 TRACE("%p\n", pending_window
);
1783 task
= heap_alloc(sizeof(start_doc_binding_task_t
));
1785 return E_OUTOFMEMORY
;
1787 task
->window
= window
;
1788 task
->pending_window
= pending_window
;
1789 IHTMLWindow2_AddRef(&pending_window
->base
.IHTMLWindow2_iface
);
1791 return push_task(&task
->header
, start_doc_binding_proc
, start_doc_binding_task_destr
, pending_window
->task_magic
);
1794 void abort_window_bindings(HTMLInnerWindow
*window
)
1798 remove_target_tasks(window
->task_magic
);
1800 while(!list_empty(&window
->bindings
)) {
1801 iter
= LIST_ENTRY(window
->bindings
.next
, BSCallback
, entry
);
1803 TRACE("Aborting %p\n", iter
);
1805 IBindStatusCallback_AddRef(&iter
->IBindStatusCallback_iface
);
1808 IBinding_Abort(iter
->binding
);
1810 iter
->vtbl
->stop_binding(iter
, E_ABORT
);
1812 iter
->window
= NULL
;
1813 list_remove(&iter
->entry
);
1814 list_init(&iter
->entry
);
1816 IBindStatusCallback_Release(&iter
->IBindStatusCallback_iface
);
1819 if(window
->bscallback
) {
1820 IBindStatusCallback_Release(&window
->bscallback
->bsc
.IBindStatusCallback_iface
);
1821 window
->bscallback
= NULL
;
1825 IMoniker_Release(window
->mon
);
1830 HRESULT
channelbsc_load_stream(HTMLInnerWindow
*pending_window
, IMoniker
*mon
, IStream
*stream
)
1832 nsChannelBSC
*bscallback
= pending_window
->bscallback
;
1833 HRESULT hres
= S_OK
;
1835 if(!bscallback
->nschannel
) {
1836 ERR("NULL nschannel\n");
1840 bscallback
->nschannel
->content_type
= heap_strdupA("text/html");
1841 if(!bscallback
->nschannel
->content_type
)
1842 return E_OUTOFMEMORY
;
1844 set_current_mon(pending_window
->base
.outer_window
, mon
, 0);
1846 bscallback
->bsc
.window
= pending_window
;
1848 hres
= read_stream_data(bscallback
, stream
);
1850 hres
= async_stop_request(bscallback
);
1852 IBindStatusCallback_OnStopBinding(&bscallback
->bsc
.IBindStatusCallback_iface
, hres
,
1858 void channelbsc_set_channel(nsChannelBSC
*This
, nsChannel
*channel
, nsIStreamListener
*listener
, nsISupports
*context
)
1860 nsIHttpChannel_AddRef(&channel
->nsIHttpChannel_iface
);
1861 This
->nschannel
= channel
;
1863 nsIStreamListener_AddRef(listener
);
1864 This
->nslistener
= listener
;
1867 nsISupports_AddRef(context
);
1868 This
->nscontext
= context
;
1871 if(This
->bsc
.request_data
.headers
) {
1874 hres
= parse_headers(This
->bsc
.request_data
.headers
, &channel
->request_headers
);
1875 heap_free(This
->bsc
.request_data
.headers
);
1876 This
->bsc
.request_data
.headers
= NULL
;
1878 WARN("parse_headers failed: %08x\n", hres
);
1884 HTMLOuterWindow
*window
;
1886 } navigate_javascript_task_t
;
1888 static void navigate_javascript_proc(task_t
*_task
)
1890 navigate_javascript_task_t
*task
= (navigate_javascript_task_t
*)_task
;
1891 HTMLOuterWindow
*window
= task
->window
;
1896 static const WCHAR jscriptW
[] = {'j','s','c','r','i','p','t',0};
1898 task
->window
->readystate
= READYSTATE_COMPLETE
;
1900 hres
= IUri_GetPath(task
->uri
, &code
);
1904 hres
= UrlUnescapeW(code
, NULL
, NULL
, URL_UNESCAPE_INPLACE
);
1906 SysFreeString(code
);
1910 set_download_state(window
->doc_obj
, 1);
1912 V_VT(&v
) = VT_EMPTY
;
1913 hres
= exec_script(window
->base
.inner_window
, code
, jscriptW
, &v
);
1914 SysFreeString(code
);
1915 if(SUCCEEDED(hres
) && V_VT(&v
) != VT_EMPTY
) {
1916 FIXME("javascirpt URL returned %s\n", debugstr_variant(&v
));
1920 if(window
->doc_obj
->view_sink
)
1921 IAdviseSink_OnViewChange(window
->doc_obj
->view_sink
, DVASPECT_CONTENT
, -1);
1923 set_download_state(window
->doc_obj
, 0);
1926 static void navigate_javascript_task_destr(task_t
*_task
)
1928 navigate_javascript_task_t
*task
= (navigate_javascript_task_t
*)_task
;
1930 IUri_Release(task
->uri
);
1936 HTMLOuterWindow
*window
;
1937 nsChannelBSC
*bscallback
;
1943 static void navigate_proc(task_t
*_task
)
1945 navigate_task_t
*task
= (navigate_task_t
*)_task
;
1948 hres
= set_moniker(task
->window
, task
->mon
, task
->uri
, NULL
, task
->bscallback
, TRUE
);
1949 if(SUCCEEDED(hres
)) {
1950 set_current_mon(task
->window
, task
->bscallback
->bsc
.mon
, task
->flags
);
1951 set_current_uri(task
->window
, task
->uri
);
1952 start_binding(task
->window
->pending_window
, &task
->bscallback
->bsc
, NULL
);
1956 static void navigate_task_destr(task_t
*_task
)
1958 navigate_task_t
*task
= (navigate_task_t
*)_task
;
1960 IBindStatusCallback_Release(&task
->bscallback
->bsc
.IBindStatusCallback_iface
);
1961 IMoniker_Release(task
->mon
);
1962 IUri_Release(task
->uri
);
1966 static HRESULT
navigate_fragment(HTMLOuterWindow
*window
, IUri
*uri
)
1968 nsIDOMLocation
*nslocation
;
1969 nsAString nsfrag_str
;
1975 const WCHAR selector_formatW
[] = {'a','[','i','d','=','"','%','s','"',']',0};
1977 set_current_uri(window
, uri
);
1979 nsres
= nsIDOMWindow_GetLocation(window
->nswindow
, &nslocation
);
1980 if(FAILED(nsres
) || !nslocation
)
1983 hres
= IUri_GetFragment(uri
, &frag
);
1985 nsIDOMLocation_Release(nslocation
);
1989 nsAString_InitDepend(&nsfrag_str
, frag
);
1990 nsres
= nsIDOMLocation_SetHash(nslocation
, &nsfrag_str
);
1991 nsAString_Finish(&nsfrag_str
);
1992 nsIDOMLocation_Release(nslocation
);
1993 if(NS_FAILED(nsres
))
1994 ERR("SetHash failed: %08x\n", nsres
);
1997 * IE supports scrolling to anchor elements with "#hash" ids (note that '#' is part of the id),
1998 * while Gecko scrolls only to elements with "hash" ids. We scroll the page ourselves if
1999 * a[id="#hash"] element can be found.
2001 selector
= heap_alloc(sizeof(selector_formatW
)+SysStringLen(frag
)*sizeof(WCHAR
));
2003 nsIDOMElement
*nselem
= NULL
;
2004 nsAString selector_str
;
2006 sprintfW(selector
, selector_formatW
, frag
);
2007 nsAString_InitDepend(&selector_str
, selector
);
2008 /* NOTE: Gecko doesn't set result to NULL if there is no match, so nselem must be initialized */
2009 nsres
= nsIDOMHTMLDocument_QuerySelector(window
->base
.inner_window
->doc
->nsdoc
, &selector_str
, &nselem
);
2010 nsAString_Finish(&selector_str
);
2011 heap_free(selector
);
2012 if(NS_SUCCEEDED(nsres
) && nselem
) {
2013 nsIDOMHTMLElement
*html_elem
;
2015 nsres
= nsIDOMElement_QueryInterface(nselem
, &IID_nsIDOMHTMLElement
, (void**)&html_elem
);
2016 nsIDOMElement_Release(nselem
);
2017 if(NS_SUCCEEDED(nsres
)) {
2018 nsIDOMHTMLElement_ScrollIntoView(html_elem
, TRUE
, 1);
2019 nsIDOMHTMLElement_Release(html_elem
);
2024 SysFreeString(frag
);
2026 if(window
->doc_obj
->doc_object_service
) {
2027 IDocObjectService_FireNavigateComplete2(window
->doc_obj
->doc_object_service
, &window
->base
.IHTMLWindow2_iface
, 0x10);
2028 IDocObjectService_FireDocumentComplete(window
->doc_obj
->doc_object_service
, &window
->base
.IHTMLWindow2_iface
, 0);
2035 HRESULT
super_navigate(HTMLOuterWindow
*window
, IUri
*uri
, DWORD flags
, const WCHAR
*headers
, BYTE
*post_data
, DWORD post_data_size
)
2043 uri_nofrag
= get_uri_nofrag(uri
);
2047 if(window
->doc_obj
->client
&& !(flags
& BINDING_REFRESH
)) {
2048 IOleCommandTarget
*cmdtrg
;
2050 hres
= IOleClientSite_QueryInterface(window
->doc_obj
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
2051 if(SUCCEEDED(hres
)) {
2055 hres
= IUri_GetDisplayUri(uri_nofrag
, &url_str
);
2056 if(SUCCEEDED(hres
)) {
2057 V_VT(&in
) = VT_BSTR
;
2058 V_BSTR(&in
) = url_str
;
2059 V_VT(&out
) = VT_BOOL
;
2060 V_BOOL(&out
) = VARIANT_TRUE
;
2061 hres
= IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 67, 0, &in
, &out
);
2062 IOleCommandTarget_Release(cmdtrg
);
2065 SysFreeString(url_str
);
2070 if(!(flags
& BINDING_NOFRAG
) && window
->uri_nofrag
&& !post_data_size
) {
2073 hres
= IUri_IsEqual(uri_nofrag
, window
->uri_nofrag
, &eq
);
2074 if(SUCCEEDED(hres
) && eq
) {
2075 IUri_Release(uri_nofrag
);
2076 TRACE("fragment navigate\n");
2077 return navigate_fragment(window
, uri
);
2081 hres
= CreateURLMonikerEx2(NULL
, uri_nofrag
, &mon
, URL_MK_UNIFORM
);
2082 IUri_Release(uri_nofrag
);
2086 /* FIXME: Why not set_ready_state? */
2087 window
->readystate
= READYSTATE_UNINITIALIZED
;
2089 hres
= create_channelbsc(mon
, headers
, post_data
, post_data_size
, TRUE
, &bsc
);
2091 IMoniker_Release(mon
);
2095 prepare_for_binding(&window
->doc_obj
->basedoc
, mon
, flags
);
2097 hres
= IUri_GetScheme(uri
, &scheme
);
2098 if(SUCCEEDED(hres
) && scheme
== URL_SCHEME_JAVASCRIPT
) {
2099 navigate_javascript_task_t
*task
;
2101 IBindStatusCallback_Release(&bsc
->bsc
.IBindStatusCallback_iface
);
2102 IMoniker_Release(mon
);
2104 task
= heap_alloc(sizeof(*task
));
2106 return E_OUTOFMEMORY
;
2109 window
->readystate
= READYSTATE_COMPLETE
;
2110 if(!(flags
& BINDING_FROMHIST
))
2111 call_docview_84(window
->doc_obj
);
2114 task
->window
= window
;
2116 hres
= push_task(&task
->header
, navigate_javascript_proc
, navigate_javascript_task_destr
, window
->task_magic
);
2117 }else if(flags
& BINDING_SUBMIT
) {
2118 hres
= set_moniker(window
, mon
, uri
, NULL
, bsc
, TRUE
);
2120 hres
= start_binding(window
->pending_window
, &bsc
->bsc
, NULL
);
2121 IBindStatusCallback_Release(&bsc
->bsc
.IBindStatusCallback_iface
);
2122 IMoniker_Release(mon
);
2124 navigate_task_t
*task
;
2126 task
= heap_alloc(sizeof(*task
));
2128 IBindStatusCallback_Release(&bsc
->bsc
.IBindStatusCallback_iface
);
2129 IMoniker_Release(mon
);
2130 return E_OUTOFMEMORY
;
2133 /* Silently and repeated when real loading starts? */
2134 window
->readystate
= READYSTATE_LOADING
;
2135 if(!(flags
& (BINDING_FROMHIST
|BINDING_REFRESH
)))
2136 call_docview_84(window
->doc_obj
);
2138 task
->window
= window
;
2139 task
->bscallback
= bsc
;
2140 task
->flags
= flags
;
2145 hres
= push_task(&task
->header
, navigate_proc
, navigate_task_destr
, window
->task_magic
);
2151 HRESULT
navigate_new_window(HTMLOuterWindow
*window
, IUri
*uri
, const WCHAR
*name
, request_data_t
*request_data
, IHTMLWindow2
**ret
)
2153 IWebBrowser2
*web_browser
;
2154 IHTMLWindow2
*new_window
;
2160 hres
= create_channelbsc(NULL
, request_data
->headers
,
2161 request_data
->post_data
, request_data
->post_data_len
, FALSE
,
2164 hres
= create_channelbsc(NULL
, NULL
, NULL
, 0, FALSE
, &bsc
);
2168 hres
= CreateAsyncBindCtx(0, &bsc
->bsc
.IBindStatusCallback_iface
, NULL
, &bind_ctx
);
2170 IBindStatusCallback_Release(&bsc
->bsc
.IBindStatusCallback_iface
);
2174 hres
= CoCreateInstance(&CLSID_InternetExplorer
, NULL
, CLSCTX_LOCAL_SERVER
,
2175 &IID_IWebBrowser2
, (void**)&web_browser
);
2176 if(SUCCEEDED(hres
)) {
2177 ITargetFramePriv2
*target_frame_priv
;
2179 hres
= IWebBrowser2_QueryInterface(web_browser
, &IID_ITargetFramePriv2
, (void**)&target_frame_priv
);
2180 if(SUCCEEDED(hres
)) {
2181 hres
= ITargetFramePriv2_AggregatedNavigation2(target_frame_priv
,
2182 HLNF_DISABLEWINDOWRESTRICTIONS
|HLNF_OPENINNEWWINDOW
, bind_ctx
, &bsc
->bsc
.IBindStatusCallback_iface
,
2184 ITargetFramePriv2_Release(target_frame_priv
);
2187 hres
= do_query_service((IUnknown
*)web_browser
, &SID_SHTMLWindow
, &IID_IHTMLWindow2
, (void**)&new_window
);
2190 IWebBrowser2_Quit(web_browser
);
2191 IWebBrowser2_Release(web_browser
);
2194 WARN("Could not create InternetExplorer instance: %08x\n", hres
);
2197 IBindStatusCallback_Release(&bsc
->bsc
.IBindStatusCallback_iface
);
2198 IBindCtx_Release(bind_ctx
);
2202 IWebBrowser2_put_Visible(web_browser
, VARIANT_TRUE
);
2203 IWebBrowser2_Release(web_browser
);
2208 IHTMLWindow2_Release(new_window
);
2212 HRESULT
hlink_frame_navigate(HTMLDocument
*doc
, LPCWSTR url
, nsChannel
*nschannel
, DWORD hlnf
, BOOL
*cancel
)
2214 IHlinkFrame
*hlink_frame
;
2215 nsChannelBSC
*callback
;
2223 hres
= do_query_service((IUnknown
*)doc
->doc_obj
->client
, &IID_IHlinkFrame
, &IID_IHlinkFrame
,
2224 (void**)&hlink_frame
);
2228 hres
= create_channelbsc(NULL
, NULL
, NULL
, 0, FALSE
, &callback
);
2230 IHlinkFrame_Release(hlink_frame
);
2235 read_post_data_stream(nschannel
->post_data_stream
, nschannel
->post_data_contains_headers
,
2236 &nschannel
->request_headers
, &callback
->bsc
.request_data
);
2238 hres
= CreateAsyncBindCtx(0, &callback
->bsc
.IBindStatusCallback_iface
, NULL
, &bindctx
);
2240 hres
= CoCreateInstance(&CLSID_StdHlink
, NULL
, CLSCTX_INPROC_SERVER
,
2241 &IID_IHlink
, (LPVOID
*)&hlink
);
2244 hres
= CreateURLMoniker(NULL
, url
, &mon
);
2246 if(SUCCEEDED(hres
)) {
2247 IHlink_SetMonikerReference(hlink
, HLINKSETF_TARGET
, mon
, NULL
);
2249 if(hlnf
& HLNF_OPENINNEWWINDOW
) {
2250 static const WCHAR wszBlank
[] = {'_','b','l','a','n','k',0};
2251 IHlink_SetTargetFrameName(hlink
, wszBlank
); /* FIXME */
2254 hres
= IHlinkFrame_Navigate(hlink_frame
, hlnf
, bindctx
,
2255 &callback
->bsc
.IBindStatusCallback_iface
, hlink
);
2256 IMoniker_Release(mon
);
2257 *cancel
= hres
== S_OK
;
2261 IHlinkFrame_Release(hlink_frame
);
2262 IBindCtx_Release(bindctx
);
2263 IBindStatusCallback_Release(&callback
->bsc
.IBindStatusCallback_iface
);
2267 static HRESULT
navigate_uri(HTMLOuterWindow
*window
, IUri
*uri
, const WCHAR
*display_uri
, const request_data_t
*request_data
,
2273 TRACE("%s\n", debugstr_w(display_uri
));
2275 if(window
->doc_obj
&& window
->doc_obj
->webbrowser
) {
2276 DWORD post_data_len
= request_data
? request_data
->post_data_len
: 0;
2277 void *post_data
= post_data_len
? request_data
->post_data
: NULL
;
2278 const WCHAR
*headers
= request_data
? request_data
->headers
: NULL
;
2280 if(!(flags
& BINDING_REFRESH
)) {
2281 BSTR frame_name
= NULL
;
2282 BOOL cancel
= FALSE
;
2284 if(window
!= window
->doc_obj
->basedoc
.window
) {
2285 hres
= IHTMLWindow2_get_name(&window
->base
.IHTMLWindow2_iface
, &frame_name
);
2290 hres
= IDocObjectService_FireBeforeNavigate2(window
->doc_obj
->doc_object_service
, NULL
, display_uri
, 0x40,
2291 frame_name
, post_data
, post_data_len
? post_data_len
+1 : 0, headers
, TRUE
, &cancel
);
2292 SysFreeString(frame_name
);
2293 if(SUCCEEDED(hres
) && cancel
) {
2294 TRACE("Navigation canceled\n");
2299 if(window
== window
->doc_obj
->basedoc
.window
)
2300 return super_navigate(window
, uri
, flags
, headers
, post_data
, post_data_len
);
2303 if(window
->doc_obj
&& window
== window
->doc_obj
->basedoc
.window
) {
2306 hres
= hlink_frame_navigate(&window
->base
.inner_window
->doc
->basedoc
, display_uri
, NULL
, 0, &cancel
);
2311 TRACE("Navigation handled by hlink frame\n");
2316 hres
= create_doc_uri(window
, uri
, &nsuri
);
2320 hres
= load_nsuri(window
, nsuri
, request_data
? request_data
->post_stream
: NULL
, NULL
, LOAD_FLAGS_NONE
);
2321 nsISupports_Release((nsISupports
*)nsuri
);
2325 HRESULT
load_uri(HTMLOuterWindow
*window
, IUri
*uri
, DWORD flags
)
2330 hres
= IUri_GetDisplayUri(uri
, &display_uri
);
2334 hres
= navigate_uri(window
, uri
, display_uri
, NULL
, flags
);
2335 SysFreeString(display_uri
);
2339 static HRESULT
translate_uri(HTMLOuterWindow
*window
, IUri
*orig_uri
, BSTR
*ret_display_uri
, IUri
**ret_uri
)
2345 hres
= IUri_GetDisplayUri(orig_uri
, &display_uri
);
2349 if(window
->doc_obj
&& window
->doc_obj
->hostui
) {
2350 OLECHAR
*translated_url
= NULL
;
2352 hres
= IDocHostUIHandler_TranslateUrl(window
->doc_obj
->hostui
, 0, display_uri
,
2354 if(hres
== S_OK
&& translated_url
) {
2355 TRACE("%08x %s -> %s\n", hres
, debugstr_w(display_uri
), debugstr_w(translated_url
));
2356 SysFreeString(display_uri
);
2357 hres
= create_uri(translated_url
, 0, &uri
);
2358 CoTaskMemFree(translated_url
);
2362 hres
= IUri_GetDisplayUri(uri
, &display_uri
);
2371 IUri_AddRef(orig_uri
);
2375 *ret_display_uri
= display_uri
;
2380 HRESULT
submit_form(HTMLOuterWindow
*window
, const WCHAR
*target
, IUri
*submit_uri
, nsIInputStream
*post_stream
)
2382 request_data_t request_data
= {NULL
};
2385 hres
= read_post_data_stream(post_stream
, TRUE
, NULL
, &request_data
);
2393 window
->readystate_locked
++;
2395 hres
= translate_uri(window
, submit_uri
, &display_uri
, &uri
);
2396 if(SUCCEEDED(hres
)) {
2397 hres
= navigate_uri(window
, uri
, display_uri
, &request_data
, BINDING_NAVIGATED
|BINDING_SUBMIT
);
2399 SysFreeString(display_uri
);
2402 window
->readystate_locked
--;
2404 hres
= navigate_new_window(window
, submit_uri
, target
, &request_data
, NULL
);
2406 release_request_data(&request_data
);
2410 HRESULT
navigate_url(HTMLOuterWindow
*window
, const WCHAR
*new_url
, IUri
*base_uri
, DWORD flags
)
2412 IUri
*uri
, *nav_uri
;
2416 if(new_url
&& base_uri
)
2417 hres
= CoInternetCombineUrlEx(base_uri
, new_url
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
2420 hres
= create_uri(new_url
, 0, &nav_uri
);
2424 hres
= translate_uri(window
, nav_uri
, &display_uri
, &uri
);
2425 IUri_Release(nav_uri
);
2429 hres
= navigate_uri(window
, uri
, display_uri
, NULL
, flags
);
2431 SysFreeString(display_uri
);