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
35 #include "wine/debug.h"
37 #include "mshtml_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
42 #define NS_IOSERVICE_CLASSNAME "nsIOService"
43 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
45 static const IID NS_IOSERVICE_CID
=
46 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
47 static const IID IID_nsWineURI
=
48 {0x5088272e, 0x900b, 0x11da, {0xc6,0x87, 0x00,0x0f,0xea,0x57,0xf2,0x1a}};
50 static nsIIOService
*nsio
= NULL
;
51 static nsINetUtil
*net_util
;
53 static const char *request_method_strings
[] = {"GET", "PUT", "POST"};
57 nsIStandardURL nsIStandardURL_iface
;
61 NSContainer
*container
;
62 windowref_t
*window_ref
;
63 nsChannelBSC
*channel_bsc
;
65 IUriBuilder
*uri_builder
;
70 static BOOL
ensure_uri(nsWineURI
*This
)
74 assert(This
->uri
|| This
->uri_builder
);
77 hres
= IUriBuilder_CreateUriSimple(This
->uri_builder
, 0, 0, &This
->uri
);
79 WARN("CreateUriSimple failed: %08x\n", hres
);
87 IUri
*nsuri_get_uri(nsWineURI
*nsuri
)
89 if(!ensure_uri(nsuri
))
92 IUri_AddRef(nsuri
->uri
);
96 static IUri
*get_uri_nofrag(IUri
*uri
)
98 IUriBuilder
*uri_builder
;
103 hres
= IUri_HasProperty(uri
, Uri_PROPERTY_FRAGMENT
, &b
);
104 if(SUCCEEDED(hres
) && !b
) {
109 hres
= CreateIUriBuilder(uri
, 0, 0, &uri_builder
);
113 hres
= IUriBuilder_RemoveProperties(uri_builder
, Uri_HAS_FRAGMENT
);
115 hres
= IUriBuilder_CreateUriSimple(uri_builder
, 0, 0, &ret
);
116 IUriBuilder_Release(uri_builder
);
123 BOOL
compare_ignoring_frag(IUri
*uri1
, IUri
*uri2
)
125 IUri
*uri_nofrag1
, *uri_nofrag2
;
128 uri_nofrag1
= get_uri_nofrag(uri1
);
132 uri_nofrag2
= get_uri_nofrag(uri2
);
134 IUri_IsEqual(uri_nofrag1
, uri_nofrag2
, &ret
);
135 IUri_Release(uri_nofrag2
);
138 IUri_Release(uri_nofrag1
);
142 static nsresult
create_nsuri(IUri
*,HTMLWindow
*,NSContainer
*,nsWineURI
**);
144 static const char *debugstr_nsacstr(const nsACString
*nsstr
)
148 nsACString_GetData(nsstr
, &data
);
149 return debugstr_a(data
);
152 static nsresult
return_wstr_nsacstr(nsACString
*ret_str
, const WCHAR
*str
, int len
)
157 TRACE("returning %s\n", debugstr_wn(str
, len
));
160 nsACString_SetData(ret_str
, "");
164 lena
= WideCharToMultiByte(CP_ACP
, 0, str
, len
, NULL
, 0, NULL
, NULL
);
165 stra
= heap_alloc(lena
+1);
167 return NS_ERROR_OUT_OF_MEMORY
;
169 WideCharToMultiByte(CP_ACP
, 0, str
, len
, stra
, lena
, NULL
, NULL
);
172 nsACString_SetData(ret_str
, stra
);
177 HRESULT
nsuri_to_url(LPCWSTR nsuri
, BOOL ret_empty
, BSTR
*ret
)
179 const WCHAR
*ptr
= nsuri
;
181 static const WCHAR wine_prefixW
[] = {'w','i','n','e',':'};
183 if(!strncmpW(nsuri
, wine_prefixW
, sizeof(wine_prefixW
)/sizeof(WCHAR
)))
184 ptr
+= sizeof(wine_prefixW
)/sizeof(WCHAR
);
186 if(*ptr
|| ret_empty
) {
187 *ret
= SysAllocString(ptr
);
189 return E_OUTOFMEMORY
;
194 TRACE("%s -> %s\n", debugstr_w(nsuri
), debugstr_w(*ret
));
198 static BOOL
exec_shldocvw_67(HTMLDocumentObj
*doc
, BSTR url
)
200 IOleCommandTarget
*cmdtrg
= NULL
;
203 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
204 if(SUCCEEDED(hres
)) {
205 VARIANT varUrl
, varRes
;
207 V_VT(&varUrl
) = VT_BSTR
;
208 V_BSTR(&varUrl
) = url
;
209 V_VT(&varRes
) = VT_BOOL
;
211 hres
= IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 67, 0, &varUrl
, &varRes
);
213 IOleCommandTarget_Release(cmdtrg
);
215 if(SUCCEEDED(hres
) && !V_BOOL(&varRes
)) {
216 TRACE("got VARIANT_FALSE, do not load\n");
224 static nsresult
before_async_open(nsChannel
*channel
, NSContainer
*container
, BOOL
*cancel
)
226 HTMLDocumentObj
*doc
= container
->doc
;
232 NSContainer
*container_iter
= container
;
234 hlnf
= HLNF_OPENINNEWWINDOW
;
235 while(!container_iter
->doc
)
236 container_iter
= container_iter
->parent
;
237 doc
= container_iter
->doc
;
245 hres
= IUri_GetDisplayUri(channel
->uri
->uri
, &display_uri
);
247 return NS_ERROR_FAILURE
;
252 b
= !exec_shldocvw_67(doc
, display_uri
);
254 SysFreeString(display_uri
);
260 hres
= hlink_frame_navigate(&doc
->basedoc
, display_uri
, channel
, hlnf
, cancel
);
261 SysFreeString(display_uri
);
267 HRESULT
load_nsuri(HTMLWindow
*window
, nsWineURI
*uri
, nsChannelBSC
*channelbsc
, DWORD flags
)
269 nsIWebNavigation
*web_navigation
;
270 nsIDocShell
*doc_shell
;
271 HTMLDocumentNode
*doc
;
274 nsres
= get_nsinterface((nsISupports
*)window
->nswindow
, &IID_nsIWebNavigation
, (void**)&web_navigation
);
275 if(NS_FAILED(nsres
)) {
276 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
280 nsres
= nsIWebNavigation_QueryInterface(web_navigation
, &IID_nsIDocShell
, (void**)&doc_shell
);
281 nsIWebNavigation_Release(web_navigation
);
282 if(NS_FAILED(nsres
)) {
283 ERR("Could not get nsIDocShell: %08x\n", nsres
);
287 uri
->channel_bsc
= channelbsc
;
289 doc
->skip_mutation_notif
= TRUE
;
290 nsres
= nsIDocShell_LoadURI(doc_shell
, (nsIURI
*)&uri
->nsIURL_iface
, NULL
, flags
, FALSE
);
291 if(doc
== window
->doc
)
292 doc
->skip_mutation_notif
= FALSE
;
293 uri
->channel_bsc
= NULL
;
294 nsIDocShell_Release(doc_shell
);
295 if(NS_FAILED(nsres
)) {
296 WARN("LoadURI failed: %08x\n", nsres
);
303 static void set_uri_nscontainer(nsWineURI
*This
, NSContainer
*nscontainer
)
305 if(This
->container
) {
306 if(This
->container
== nscontainer
)
308 TRACE("Changing %p -> %p\n", This
->container
, nscontainer
);
309 nsIWebBrowserChrome_Release(&This
->container
->nsIWebBrowserChrome_iface
);
313 nsIWebBrowserChrome_AddRef(&nscontainer
->nsIWebBrowserChrome_iface
);
314 This
->container
= nscontainer
;
317 static void set_uri_window(nsWineURI
*This
, HTMLWindow
*window
)
319 if(This
->window_ref
) {
320 if(This
->window_ref
->window
== window
)
322 TRACE("Changing %p -> %p\n", This
->window_ref
->window
, window
);
323 windowref_release(This
->window_ref
);
327 windowref_addref(window
->window_ref
);
328 This
->window_ref
= window
->window_ref
;
331 set_uri_nscontainer(This
, window
->doc_obj
->nscontainer
);
333 This
->window_ref
= NULL
;
337 static inline BOOL
is_http_channel(nsChannel
*This
)
339 return This
->url_scheme
== URL_SCHEME_HTTP
|| This
->url_scheme
== URL_SCHEME_HTTPS
;
342 static http_header_t
*find_http_header(struct list
*headers
, const WCHAR
*name
, int len
)
346 LIST_FOR_EACH_ENTRY(iter
, headers
, http_header_t
, entry
) {
347 if(!strcmpiW(iter
->header
, name
))
354 static nsresult
get_channel_http_header(struct list
*headers
, const nsACString
*header_name_str
,
357 const char *header_namea
;
358 http_header_t
*header
;
362 nsACString_GetData(header_name_str
, &header_namea
);
363 header_name
= heap_strdupAtoW(header_namea
);
365 return NS_ERROR_UNEXPECTED
;
367 header
= find_http_header(headers
, header_name
, strlenW(header_name
));
368 heap_free(header_name
);
370 return NS_ERROR_NOT_AVAILABLE
;
372 data
= heap_strdupWtoA(header
->data
);
374 return NS_ERROR_UNEXPECTED
;
376 TRACE("%s -> %s\n", debugstr_a(header_namea
), debugstr_a(data
));
377 nsACString_SetData(_retval
, data
);
382 HRESULT
set_http_header(struct list
*headers
, const WCHAR
*name
, int name_len
,
383 const WCHAR
*value
, int value_len
)
385 http_header_t
*header
;
387 TRACE("%s: %s\n", debugstr_wn(name
, name_len
), debugstr_wn(value
, value_len
));
389 header
= find_http_header(headers
, name
, name_len
);
393 new_data
= heap_strndupW(value
, value_len
);
395 return E_OUTOFMEMORY
;
397 heap_free(header
->data
);
398 header
->data
= new_data
;
400 header
= heap_alloc(sizeof(http_header_t
));
402 return E_OUTOFMEMORY
;
404 header
->header
= heap_strndupW(name
, name_len
);
405 header
->data
= heap_strndupW(value
, value_len
);
406 if(!header
->header
|| !header
->data
) {
407 heap_free(header
->header
);
408 heap_free(header
->data
);
410 return E_OUTOFMEMORY
;
413 list_add_tail(headers
, &header
->entry
);
419 static nsresult
set_channel_http_header(struct list
*headers
, const nsACString
*name_str
,
420 const nsACString
*value_str
)
422 const char *namea
, *valuea
;
426 nsACString_GetData(name_str
, &namea
);
427 name
= heap_strdupAtoW(namea
);
429 return NS_ERROR_UNEXPECTED
;
431 nsACString_GetData(value_str
, &valuea
);
432 value
= heap_strdupAtoW(valuea
);
435 return NS_ERROR_UNEXPECTED
;
438 hres
= set_http_header(headers
, name
, strlenW(name
), value
, strlenW(value
));
442 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_UNEXPECTED
;
445 static nsresult
visit_http_headers(struct list
*headers
, nsIHttpHeaderVisitor
*visitor
)
447 nsACString header_str
, value_str
;
448 char *header
, *value
;
452 LIST_FOR_EACH_ENTRY(iter
, headers
, http_header_t
, entry
) {
453 header
= heap_strdupWtoA(iter
->header
);
455 return NS_ERROR_OUT_OF_MEMORY
;
457 value
= heap_strdupWtoA(iter
->data
);
460 return NS_ERROR_OUT_OF_MEMORY
;
463 nsACString_InitDepend(&header_str
, header
);
464 nsACString_InitDepend(&value_str
, value
);
465 nsres
= nsIHttpHeaderVisitor_VisitHeader(visitor
, &header_str
, &value_str
);
466 nsACString_Finish(&header_str
);
467 nsACString_Finish(&value_str
);
477 static void free_http_headers(struct list
*list
)
479 http_header_t
*iter
, *iter_next
;
481 LIST_FOR_EACH_ENTRY_SAFE(iter
, iter_next
, list
, http_header_t
, entry
) {
482 list_remove(&iter
->entry
);
483 heap_free(iter
->header
);
484 heap_free(iter
->data
);
489 static inline nsChannel
*impl_from_nsIHttpChannel(nsIHttpChannel
*iface
)
491 return CONTAINING_RECORD(iface
, nsChannel
, nsIHttpChannel_iface
);
494 static nsresult NSAPI
nsChannel_QueryInterface(nsIHttpChannel
*iface
, nsIIDRef riid
, void **result
)
496 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
498 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
499 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
500 *result
= &This
->nsIHttpChannel_iface
;
501 }else if(IsEqualGUID(&IID_nsIRequest
, riid
)) {
502 TRACE("(%p)->(IID_nsIRequest %p)\n", This
, result
);
503 *result
= &This
->nsIHttpChannel_iface
;
504 }else if(IsEqualGUID(&IID_nsIChannel
, riid
)) {
505 TRACE("(%p)->(IID_nsIChannel %p)\n", This
, result
);
506 *result
= &This
->nsIHttpChannel_iface
;
507 }else if(IsEqualGUID(&IID_nsIHttpChannel
, riid
)) {
508 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This
, result
);
509 *result
= is_http_channel(This
) ? &This
->nsIHttpChannel_iface
: NULL
;
510 }else if(IsEqualGUID(&IID_nsIUploadChannel
, riid
)) {
511 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This
, result
);
512 *result
= &This
->nsIUploadChannel_iface
;
513 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal
, riid
)) {
514 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This
, result
);
515 *result
= is_http_channel(This
) ? &This
->nsIHttpChannelInternal_iface
: NULL
;
517 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
522 nsIChannel_AddRef(&This
->nsIHttpChannel_iface
);
526 return NS_NOINTERFACE
;
529 static nsrefcnt NSAPI
nsChannel_AddRef(nsIHttpChannel
*iface
)
531 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
532 nsrefcnt ref
= InterlockedIncrement(&This
->ref
);
534 TRACE("(%p) ref=%d\n", This
, ref
);
539 static nsrefcnt NSAPI
nsChannel_Release(nsIHttpChannel
*iface
)
541 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
542 LONG ref
= InterlockedDecrement(&This
->ref
);
545 nsIURI_Release(&This
->uri
->nsIURL_iface
);
547 nsISupports_Release(This
->owner
);
548 if(This
->post_data_stream
)
549 nsIInputStream_Release(This
->post_data_stream
);
551 nsILoadGroup_Release(This
->load_group
);
552 if(This
->notif_callback
)
553 nsIInterfaceRequestor_Release(This
->notif_callback
);
554 if(This
->original_uri
)
555 nsIURI_Release(This
->original_uri
);
557 nsIURI_Release(This
->referrer
);
559 free_http_headers(&This
->response_headers
);
560 free_http_headers(&This
->request_headers
);
562 heap_free(This
->content_type
);
563 heap_free(This
->charset
);
570 static nsresult NSAPI
nsChannel_GetName(nsIHttpChannel
*iface
, nsACString
*aName
)
572 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
574 TRACE("(%p)->(%p)\n", This
, aName
);
576 return nsIURI_GetSpec(&This
->uri
->nsIURL_iface
, aName
);
579 static nsresult NSAPI
nsChannel_IsPending(nsIHttpChannel
*iface
, PRBool
*_retval
)
581 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
583 FIXME("(%p)->(%p)\n", This
, _retval
);
585 return NS_ERROR_NOT_IMPLEMENTED
;
588 static nsresult NSAPI
nsChannel_GetStatus(nsIHttpChannel
*iface
, nsresult
*aStatus
)
590 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
592 WARN("(%p)->(%p) returning NS_OK\n", This
, aStatus
);
594 return *aStatus
= NS_OK
;
597 static nsresult NSAPI
nsChannel_Cancel(nsIHttpChannel
*iface
, nsresult aStatus
)
599 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
601 FIXME("(%p)->(%08x)\n", This
, aStatus
);
603 return NS_ERROR_NOT_IMPLEMENTED
;
606 static nsresult NSAPI
nsChannel_Suspend(nsIHttpChannel
*iface
)
608 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
610 FIXME("(%p)\n", This
);
612 return NS_ERROR_NOT_IMPLEMENTED
;
615 static nsresult NSAPI
nsChannel_Resume(nsIHttpChannel
*iface
)
617 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
619 FIXME("(%p)\n", This
);
621 return NS_ERROR_NOT_IMPLEMENTED
;
624 static nsresult NSAPI
nsChannel_GetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
**aLoadGroup
)
626 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
628 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
631 nsILoadGroup_AddRef(This
->load_group
);
633 *aLoadGroup
= This
->load_group
;
637 static nsresult NSAPI
nsChannel_SetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
*aLoadGroup
)
639 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
641 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
644 nsILoadGroup_Release(This
->load_group
);
646 nsILoadGroup_AddRef(aLoadGroup
);
647 This
->load_group
= aLoadGroup
;
652 static nsresult NSAPI
nsChannel_GetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags
*aLoadFlags
)
654 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
656 TRACE("(%p)->(%p)\n", This
, aLoadFlags
);
658 *aLoadFlags
= This
->load_flags
;
662 static nsresult NSAPI
nsChannel_SetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags aLoadFlags
)
664 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
666 TRACE("(%p)->(%08x)\n", This
, aLoadFlags
);
668 This
->load_flags
= aLoadFlags
;
672 static nsresult NSAPI
nsChannel_GetOriginalURI(nsIHttpChannel
*iface
, nsIURI
**aOriginalURI
)
674 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
676 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
678 if(This
->original_uri
)
679 nsIURI_AddRef(This
->original_uri
);
681 *aOriginalURI
= This
->original_uri
;
685 static nsresult NSAPI
nsChannel_SetOriginalURI(nsIHttpChannel
*iface
, nsIURI
*aOriginalURI
)
687 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
689 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
691 if(This
->original_uri
)
692 nsIURI_Release(This
->original_uri
);
694 nsIURI_AddRef(aOriginalURI
);
695 This
->original_uri
= aOriginalURI
;
699 static nsresult NSAPI
nsChannel_GetURI(nsIHttpChannel
*iface
, nsIURI
**aURI
)
701 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
703 TRACE("(%p)->(%p)\n", This
, aURI
);
705 nsIURI_AddRef(&This
->uri
->nsIURL_iface
);
706 *aURI
= (nsIURI
*)This
->uri
;
711 static nsresult NSAPI
nsChannel_GetOwner(nsIHttpChannel
*iface
, nsISupports
**aOwner
)
713 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
715 TRACE("(%p)->(%p)\n", This
, aOwner
);
718 nsISupports_AddRef(This
->owner
);
719 *aOwner
= This
->owner
;
724 static nsresult NSAPI
nsChannel_SetOwner(nsIHttpChannel
*iface
, nsISupports
*aOwner
)
726 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
728 TRACE("(%p)->(%p)\n", This
, aOwner
);
731 nsISupports_AddRef(aOwner
);
733 nsISupports_Release(This
->owner
);
734 This
->owner
= aOwner
;
739 static nsresult NSAPI
nsChannel_GetNotificationCallbacks(nsIHttpChannel
*iface
,
740 nsIInterfaceRequestor
**aNotificationCallbacks
)
742 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
744 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
746 if(This
->notif_callback
)
747 nsIInterfaceRequestor_AddRef(This
->notif_callback
);
748 *aNotificationCallbacks
= This
->notif_callback
;
753 static nsresult NSAPI
nsChannel_SetNotificationCallbacks(nsIHttpChannel
*iface
,
754 nsIInterfaceRequestor
*aNotificationCallbacks
)
756 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
758 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
760 if(This
->notif_callback
)
761 nsIInterfaceRequestor_Release(This
->notif_callback
);
762 if(aNotificationCallbacks
)
763 nsIInterfaceRequestor_AddRef(aNotificationCallbacks
);
765 This
->notif_callback
= aNotificationCallbacks
;
770 static nsresult NSAPI
nsChannel_GetSecurityInfo(nsIHttpChannel
*iface
, nsISupports
**aSecurityInfo
)
772 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
774 TRACE("(%p)->(%p)\n", This
, aSecurityInfo
);
776 return NS_ERROR_NOT_IMPLEMENTED
;
779 static nsresult NSAPI
nsChannel_GetContentType(nsIHttpChannel
*iface
, nsACString
*aContentType
)
781 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
783 TRACE("(%p)->(%p)\n", This
, aContentType
);
785 if(This
->content_type
) {
786 nsACString_SetData(aContentType
, This
->content_type
);
790 WARN("unknown type\n");
791 return NS_ERROR_FAILURE
;
794 static nsresult NSAPI
nsChannel_SetContentType(nsIHttpChannel
*iface
,
795 const nsACString
*aContentType
)
797 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
798 const char *content_type
;
800 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentType
));
802 nsACString_GetData(aContentType
, &content_type
);
803 heap_free(This
->content_type
);
804 This
->content_type
= heap_strdupA(content_type
);
809 static nsresult NSAPI
nsChannel_GetContentCharset(nsIHttpChannel
*iface
,
810 nsACString
*aContentCharset
)
812 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
814 TRACE("(%p)->(%p)\n", This
, aContentCharset
);
817 nsACString_SetData(aContentCharset
, This
->charset
);
821 nsACString_SetData(aContentCharset
, "");
825 static nsresult NSAPI
nsChannel_SetContentCharset(nsIHttpChannel
*iface
,
826 const nsACString
*aContentCharset
)
828 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
832 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentCharset
));
834 nsACString_GetData(aContentCharset
, &data
);
835 charset
= heap_strdupA(data
);
837 return NS_ERROR_OUT_OF_MEMORY
;
839 heap_free(This
->charset
);
840 This
->charset
= charset
;
844 static nsresult NSAPI
nsChannel_GetContentLength(nsIHttpChannel
*iface
, PRInt32
*aContentLength
)
846 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
848 FIXME("(%p)->(%p)\n", This
, aContentLength
);
850 return NS_ERROR_NOT_IMPLEMENTED
;
853 static nsresult NSAPI
nsChannel_SetContentLength(nsIHttpChannel
*iface
, PRInt32 aContentLength
)
855 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
857 FIXME("(%p)->(%d)\n", This
, aContentLength
);
859 return NS_ERROR_NOT_IMPLEMENTED
;
862 static nsresult NSAPI
nsChannel_Open(nsIHttpChannel
*iface
, nsIInputStream
**_retval
)
864 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
866 FIXME("(%p)->(%p)\n", This
, _retval
);
868 return NS_ERROR_NOT_IMPLEMENTED
;
871 static HTMLWindow
*get_window_from_load_group(nsChannel
*This
)
880 nsres
= nsILoadGroup_GetDefaultLoadRequest(This
->load_group
, &req
);
881 if(NS_FAILED(nsres
)) {
882 ERR("GetDefaultLoadRequest failed: %08x\n", nsres
);
889 nsres
= nsIRequest_QueryInterface(req
, &IID_nsIChannel
, (void**)&channel
);
890 nsIRequest_Release(req
);
891 if(NS_FAILED(nsres
)) {
892 WARN("Could not get nsIChannel interface: %08x\n", nsres
);
896 nsres
= nsIChannel_GetURI(channel
, &uri
);
897 nsIChannel_Release(channel
);
898 if(NS_FAILED(nsres
)) {
899 ERR("GetURI failed: %08x\n", nsres
);
903 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
905 if(NS_FAILED(nsres
)) {
906 TRACE("Could not get nsWineURI: %08x\n", nsres
);
910 window
= wine_uri
->window_ref
? wine_uri
->window_ref
->window
: NULL
;
912 IHTMLWindow2_AddRef(&window
->IHTMLWindow2_iface
);
913 nsIURI_Release(&wine_uri
->nsIURL_iface
);
918 static HTMLWindow
*get_channel_window(nsChannel
*This
)
920 nsIWebProgress
*web_progress
;
921 nsIDOMWindow
*nswindow
;
925 if(This
->load_group
) {
926 nsIRequestObserver
*req_observer
;
928 nsres
= nsILoadGroup_GetGroupObserver(This
->load_group
, &req_observer
);
929 if(NS_FAILED(nsres
) || !req_observer
) {
930 ERR("GetGroupObserver failed: %08x\n", nsres
);
934 nsres
= nsIRequestObserver_QueryInterface(req_observer
, &IID_nsIWebProgress
, (void**)&web_progress
);
935 nsIRequestObserver_Release(req_observer
);
936 if(NS_FAILED(nsres
)) {
937 ERR("Could not get nsIWebProgress iface: %08x\n", nsres
);
940 }else if(This
->notif_callback
) {
941 nsres
= nsIInterfaceRequestor_GetInterface(This
->notif_callback
, &IID_nsIWebProgress
, (void**)&web_progress
);
942 if(NS_FAILED(nsres
)) {
943 ERR("GetInterface(IID_nsIWebProgress failed: %08x\n", nsres
);
947 ERR("no load group nor notif callback\n");
951 nsres
= nsIWebProgress_GetDOMWindow(web_progress
, &nswindow
);
952 nsIWebProgress_Release(web_progress
);
953 if(NS_FAILED(nsres
) || !nswindow
) {
954 ERR("GetDOMWindow failed: %08x\n", nsres
);
958 window
= nswindow_to_window(nswindow
);
959 nsIDOMWindow_Release(nswindow
);
962 IHTMLWindow2_AddRef(&window
->IHTMLWindow2_iface
);
964 FIXME("NULL window for %p\n", nswindow
);
970 HTMLDocumentNode
*doc
;
971 nsChannelBSC
*bscallback
;
972 } start_binding_task_t
;
974 static void start_binding_proc(task_t
*_task
)
976 start_binding_task_t
*task
= (start_binding_task_t
*)_task
;
978 start_binding(NULL
, task
->doc
, (BSCallback
*)task
->bscallback
, NULL
);
981 static void start_binding_task_destr(task_t
*_task
)
983 start_binding_task_t
*task
= (start_binding_task_t
*)_task
;
985 IBindStatusCallback_Release(&task
->bscallback
->bsc
.IBindStatusCallback_iface
);
989 static nsresult
async_open(nsChannel
*This
, HTMLWindow
*window
, BOOL is_doc_channel
, nsIStreamListener
*listener
,
990 nsISupports
*context
)
992 nsChannelBSC
*bscallback
;
993 IMoniker
*mon
= NULL
;
996 hres
= CreateURLMonikerEx2(NULL
, This
->uri
->uri
, &mon
, 0);
998 WARN("CreateURLMoniker failed: %08x\n", hres
);
999 return NS_ERROR_UNEXPECTED
;
1003 set_current_mon(window
, mon
);
1005 hres
= create_channelbsc(mon
, NULL
, NULL
, 0, &bscallback
);
1006 IMoniker_Release(mon
);
1008 return NS_ERROR_UNEXPECTED
;
1010 channelbsc_set_channel(bscallback
, This
, listener
, context
);
1012 if(is_doc_channel
) {
1013 set_window_bscallback(window
, bscallback
);
1014 async_start_doc_binding(window
, bscallback
);
1015 IUnknown_Release((IUnknown
*)bscallback
);
1017 start_binding_task_t
*task
= heap_alloc(sizeof(start_binding_task_t
));
1019 task
->doc
= window
->doc
;
1020 task
->bscallback
= bscallback
;
1021 push_task(&task
->header
, start_binding_proc
, start_binding_task_destr
, window
->doc
->basedoc
.task_magic
);
1027 static nsresult NSAPI
nsChannel_AsyncOpen(nsIHttpChannel
*iface
, nsIStreamListener
*aListener
,
1028 nsISupports
*aContext
)
1030 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1031 HTMLWindow
*window
= NULL
;
1032 BOOL cancel
= FALSE
;
1033 nsresult nsres
= NS_OK
;
1035 TRACE("(%p)->(%p %p)\n", This
, aListener
, aContext
);
1037 if(!ensure_uri(This
->uri
))
1038 return NS_ERROR_FAILURE
;
1040 if(TRACE_ON(mshtml
)) {
1042 IUri_GetDisplayUri(This
->uri
->uri
, &uri_str
);
1043 TRACE("opening %s\n", debugstr_w(uri_str
));
1044 SysFreeString(uri_str
);
1047 if(This
->uri
->is_doc_uri
) {
1048 window
= get_channel_window(This
);
1050 set_uri_window(This
->uri
, window
);
1051 }else if(This
->uri
->container
) {
1054 /* nscontainer->doc should be NULL which means navigation to a new window */
1055 if(This
->uri
->container
->doc
)
1056 FIXME("nscontainer->doc = %p\n", This
->uri
->container
->doc
);
1058 nsres
= before_async_open(This
, This
->uri
->container
, &b
);
1059 if(NS_FAILED(nsres
))
1062 FIXME("Navigation not cancelled\n");
1063 return NS_ERROR_UNEXPECTED
;
1068 if(This
->uri
->window_ref
&& This
->uri
->window_ref
->window
) {
1069 window
= This
->uri
->window_ref
->window
;
1070 IHTMLWindow2_AddRef(&window
->IHTMLWindow2_iface
);
1072 /* FIXME: Analyze removing get_window_from_load_group call */
1073 if(This
->load_group
)
1074 window
= get_window_from_load_group(This
);
1076 window
= get_channel_window(This
);
1078 set_uri_window(This
->uri
, window
);
1083 ERR("window = NULL\n");
1084 return NS_ERROR_UNEXPECTED
;
1087 if(This
->uri
->is_doc_uri
&& window
== window
->doc_obj
->basedoc
.window
) {
1088 if(This
->uri
->channel_bsc
) {
1089 channelbsc_set_channel(This
->uri
->channel_bsc
, This
, aListener
, aContext
);
1091 if(window
->doc_obj
->mime
) {
1092 heap_free(This
->content_type
);
1093 This
->content_type
= heap_strdupWtoA(window
->doc_obj
->mime
);
1098 nsres
= before_async_open(This
, window
->doc_obj
->nscontainer
, &cancel
);
1099 if(NS_SUCCEEDED(nsres
) && cancel
) {
1100 TRACE("canceled\n");
1101 nsres
= NS_BINDING_ABORTED
;
1107 nsres
= async_open(This
, window
, This
->uri
->is_doc_uri
, aListener
, aContext
);
1109 if(NS_SUCCEEDED(nsres
) && This
->load_group
) {
1110 nsres
= nsILoadGroup_AddRequest(This
->load_group
, (nsIRequest
*)&This
->nsIHttpChannel_iface
,
1112 if(NS_FAILED(nsres
))
1113 ERR("AddRequest failed: %08x\n", nsres
);
1116 IHTMLWindow2_Release(&window
->IHTMLWindow2_iface
);
1120 static nsresult NSAPI
nsChannel_GetRequestMethod(nsIHttpChannel
*iface
, nsACString
*aRequestMethod
)
1122 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1124 TRACE("(%p)->(%p)\n", This
, aRequestMethod
);
1126 nsACString_SetData(aRequestMethod
, request_method_strings
[This
->request_method
]);
1130 static nsresult NSAPI
nsChannel_SetRequestMethod(nsIHttpChannel
*iface
,
1131 const nsACString
*aRequestMethod
)
1133 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1137 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRequestMethod
));
1139 nsACString_GetData(aRequestMethod
, &method
);
1140 for(i
=0; i
< sizeof(request_method_strings
)/sizeof(*request_method_strings
); i
++) {
1141 if(!strcasecmp(method
, request_method_strings
[i
])) {
1142 This
->request_method
= i
;
1147 ERR("Invalid method %s\n", debugstr_a(method
));
1148 return NS_ERROR_UNEXPECTED
;
1151 static nsresult NSAPI
nsChannel_GetReferrer(nsIHttpChannel
*iface
, nsIURI
**aReferrer
)
1153 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1155 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1158 nsIURI_AddRef(This
->referrer
);
1159 *aReferrer
= This
->referrer
;
1163 static nsresult NSAPI
nsChannel_SetReferrer(nsIHttpChannel
*iface
, nsIURI
*aReferrer
)
1165 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1167 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1170 nsIURI_AddRef(aReferrer
);
1172 nsIURI_Release(This
->referrer
);
1173 This
->referrer
= aReferrer
;
1177 static nsresult NSAPI
nsChannel_GetRequestHeader(nsIHttpChannel
*iface
,
1178 const nsACString
*aHeader
, nsACString
*_retval
)
1180 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1182 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aHeader
), _retval
);
1184 return get_channel_http_header(&This
->request_headers
, aHeader
, _retval
);
1187 static nsresult NSAPI
nsChannel_SetRequestHeader(nsIHttpChannel
*iface
,
1188 const nsACString
*aHeader
, const nsACString
*aValue
, PRBool aMerge
)
1190 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1192 TRACE("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(aHeader
), debugstr_nsacstr(aValue
), aMerge
);
1195 FIXME("aMerge not supported\n");
1197 return set_channel_http_header(&This
->request_headers
, aHeader
, aValue
);
1200 static nsresult NSAPI
nsChannel_VisitRequestHeaders(nsIHttpChannel
*iface
,
1201 nsIHttpHeaderVisitor
*aVisitor
)
1203 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1205 FIXME("(%p)->(%p)\n", This
, aVisitor
);
1207 return NS_ERROR_NOT_IMPLEMENTED
;
1210 static nsresult NSAPI
nsChannel_GetAllowPipelining(nsIHttpChannel
*iface
, PRBool
*aAllowPipelining
)
1212 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1214 FIXME("(%p)->(%p)\n", This
, aAllowPipelining
);
1216 return NS_ERROR_NOT_IMPLEMENTED
;
1219 static nsresult NSAPI
nsChannel_SetAllowPipelining(nsIHttpChannel
*iface
, PRBool aAllowPipelining
)
1221 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1223 FIXME("(%p)->(%x)\n", This
, aAllowPipelining
);
1225 return NS_ERROR_NOT_IMPLEMENTED
;
1228 static nsresult NSAPI
nsChannel_GetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32
*aRedirectionLimit
)
1230 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1232 FIXME("(%p)->(%p)\n", This
, aRedirectionLimit
);
1234 return NS_ERROR_NOT_IMPLEMENTED
;
1237 static nsresult NSAPI
nsChannel_SetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32 aRedirectionLimit
)
1239 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1241 FIXME("(%p)->(%u)\n", This
, aRedirectionLimit
);
1243 return NS_ERROR_NOT_IMPLEMENTED
;
1246 static nsresult NSAPI
nsChannel_GetResponseStatus(nsIHttpChannel
*iface
, PRUint32
*aResponseStatus
)
1248 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1250 TRACE("(%p)->(%p)\n", This
, aResponseStatus
);
1252 if(This
->response_status
) {
1253 *aResponseStatus
= This
->response_status
;
1257 WARN("No response status\n");
1258 return NS_ERROR_UNEXPECTED
;
1261 static nsresult NSAPI
nsChannel_GetResponseStatusText(nsIHttpChannel
*iface
,
1262 nsACString
*aResponseStatusText
)
1264 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1266 FIXME("(%p)->(%p)\n", This
, aResponseStatusText
);
1268 return NS_ERROR_NOT_IMPLEMENTED
;
1271 static nsresult NSAPI
nsChannel_GetRequestSucceeded(nsIHttpChannel
*iface
,
1272 PRBool
*aRequestSucceeded
)
1274 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1276 TRACE("(%p)->(%p)\n", This
, aRequestSucceeded
);
1278 if(!This
->response_status
)
1279 return NS_ERROR_NOT_AVAILABLE
;
1281 *aRequestSucceeded
= This
->response_status
/100 == 2;
1286 static nsresult NSAPI
nsChannel_GetResponseHeader(nsIHttpChannel
*iface
,
1287 const nsACString
*header
, nsACString
*_retval
)
1289 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1291 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(header
), _retval
);
1293 return get_channel_http_header(&This
->response_headers
, header
, _retval
);
1296 static nsresult NSAPI
nsChannel_SetResponseHeader(nsIHttpChannel
*iface
,
1297 const nsACString
*header
, const nsACString
*value
, PRBool merge
)
1299 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1301 FIXME("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(header
), debugstr_nsacstr(value
), merge
);
1303 return NS_ERROR_NOT_IMPLEMENTED
;
1306 static nsresult NSAPI
nsChannel_VisitResponseHeaders(nsIHttpChannel
*iface
,
1307 nsIHttpHeaderVisitor
*aVisitor
)
1309 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1311 TRACE("(%p)->(%p)\n", This
, aVisitor
);
1313 return visit_http_headers(&This
->response_headers
, aVisitor
);
1316 static nsresult NSAPI
nsChannel_IsNoStoreResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1318 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1319 http_header_t
*header
;
1321 static const WCHAR cache_controlW
[] = {'C','a','c','h','e','-','C','o','n','t','r','o','l'};
1322 static const WCHAR no_storeW
[] = {'n','o','-','s','t','o','r','e',0};
1324 TRACE("(%p)->(%p)\n", This
, _retval
);
1326 header
= find_http_header(&This
->response_headers
, cache_controlW
, sizeof(cache_controlW
)/sizeof(WCHAR
));
1327 *_retval
= header
&& !strcmpiW(header
->data
, no_storeW
);
1331 static nsresult NSAPI
nsChannel_IsNoCacheResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1333 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1335 FIXME("(%p)->(%p)\n", This
, _retval
);
1337 return NS_ERROR_NOT_IMPLEMENTED
;
1340 static const nsIHttpChannelVtbl nsChannelVtbl
= {
1341 nsChannel_QueryInterface
,
1345 nsChannel_IsPending
,
1346 nsChannel_GetStatus
,
1350 nsChannel_GetLoadGroup
,
1351 nsChannel_SetLoadGroup
,
1352 nsChannel_GetLoadFlags
,
1353 nsChannel_SetLoadFlags
,
1354 nsChannel_GetOriginalURI
,
1355 nsChannel_SetOriginalURI
,
1359 nsChannel_GetNotificationCallbacks
,
1360 nsChannel_SetNotificationCallbacks
,
1361 nsChannel_GetSecurityInfo
,
1362 nsChannel_GetContentType
,
1363 nsChannel_SetContentType
,
1364 nsChannel_GetContentCharset
,
1365 nsChannel_SetContentCharset
,
1366 nsChannel_GetContentLength
,
1367 nsChannel_SetContentLength
,
1369 nsChannel_AsyncOpen
,
1370 nsChannel_GetRequestMethod
,
1371 nsChannel_SetRequestMethod
,
1372 nsChannel_GetReferrer
,
1373 nsChannel_SetReferrer
,
1374 nsChannel_GetRequestHeader
,
1375 nsChannel_SetRequestHeader
,
1376 nsChannel_VisitRequestHeaders
,
1377 nsChannel_GetAllowPipelining
,
1378 nsChannel_SetAllowPipelining
,
1379 nsChannel_GetRedirectionLimit
,
1380 nsChannel_SetRedirectionLimit
,
1381 nsChannel_GetResponseStatus
,
1382 nsChannel_GetResponseStatusText
,
1383 nsChannel_GetRequestSucceeded
,
1384 nsChannel_GetResponseHeader
,
1385 nsChannel_SetResponseHeader
,
1386 nsChannel_VisitResponseHeaders
,
1387 nsChannel_IsNoStoreResponse
,
1388 nsChannel_IsNoCacheResponse
1391 static inline nsChannel
*impl_from_nsIUploadChannel(nsIUploadChannel
*iface
)
1393 return CONTAINING_RECORD(iface
, nsChannel
, nsIUploadChannel_iface
);
1396 static nsresult NSAPI
nsUploadChannel_QueryInterface(nsIUploadChannel
*iface
, nsIIDRef riid
,
1399 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1400 return nsIChannel_QueryInterface(&This
->nsIHttpChannel_iface
, riid
, result
);
1403 static nsrefcnt NSAPI
nsUploadChannel_AddRef(nsIUploadChannel
*iface
)
1405 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1406 return nsIChannel_AddRef(&This
->nsIHttpChannel_iface
);
1409 static nsrefcnt NSAPI
nsUploadChannel_Release(nsIUploadChannel
*iface
)
1411 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1412 return nsIChannel_Release(&This
->nsIHttpChannel_iface
);
1415 static nsresult NSAPI
nsUploadChannel_SetUploadStream(nsIUploadChannel
*iface
,
1416 nsIInputStream
*aStream
, const nsACString
*aContentType
, PRInt32 aContentLength
)
1418 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1419 const char *content_type
;
1421 static const WCHAR content_typeW
[] =
1422 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1424 TRACE("(%p)->(%p %s %d)\n", This
, aStream
, debugstr_nsacstr(aContentType
), aContentLength
);
1426 This
->post_data_contains_headers
= TRUE
;
1429 nsACString_GetData(aContentType
, &content_type
);
1433 ct
= heap_strdupAtoW(content_type
);
1435 return NS_ERROR_UNEXPECTED
;
1437 set_http_header(&This
->request_headers
, content_typeW
,
1438 sizeof(content_typeW
)/sizeof(WCHAR
), ct
, strlenW(ct
));
1440 This
->post_data_contains_headers
= FALSE
;
1444 if(This
->post_data_stream
)
1445 nsIInputStream_Release(This
->post_data_stream
);
1447 if(aContentLength
!= -1)
1448 FIXME("Unsupported acontentLength = %d\n", aContentLength
);
1450 if(This
->post_data_stream
)
1451 nsIInputStream_Release(This
->post_data_stream
);
1452 This
->post_data_stream
= aStream
;
1454 nsIInputStream_AddRef(aStream
);
1456 This
->request_method
= METHOD_POST
;
1460 static nsresult NSAPI
nsUploadChannel_GetUploadStream(nsIUploadChannel
*iface
,
1461 nsIInputStream
**aUploadStream
)
1463 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1465 TRACE("(%p)->(%p)\n", This
, aUploadStream
);
1467 if(This
->post_data_stream
)
1468 nsIInputStream_AddRef(This
->post_data_stream
);
1470 *aUploadStream
= This
->post_data_stream
;
1474 static const nsIUploadChannelVtbl nsUploadChannelVtbl
= {
1475 nsUploadChannel_QueryInterface
,
1476 nsUploadChannel_AddRef
,
1477 nsUploadChannel_Release
,
1478 nsUploadChannel_SetUploadStream
,
1479 nsUploadChannel_GetUploadStream
1482 static inline nsChannel
*impl_from_nsIHttpChannelInternal(nsIHttpChannelInternal
*iface
)
1484 return CONTAINING_RECORD(iface
, nsChannel
, nsIHttpChannelInternal_iface
);
1487 static nsresult NSAPI
nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal
*iface
, nsIIDRef riid
,
1490 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1491 return nsIChannel_QueryInterface(&This
->nsIHttpChannel_iface
, riid
, result
);
1494 static nsrefcnt NSAPI
nsHttpChannelInternal_AddRef(nsIHttpChannelInternal
*iface
)
1496 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1497 return nsIChannel_AddRef(&This
->nsIHttpChannel_iface
);
1500 static nsrefcnt NSAPI
nsHttpChannelInternal_Release(nsIHttpChannelInternal
*iface
)
1502 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1503 return nsIChannel_Release(&This
->nsIHttpChannel_iface
);
1506 static nsresult NSAPI
nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
**aDocumentURI
)
1508 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1510 FIXME("(%p)->()\n", This
);
1512 return NS_ERROR_NOT_IMPLEMENTED
;
1515 static nsresult NSAPI
nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
*aDocumentURI
)
1517 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1519 FIXME("(%p)->()\n", This
);
1521 return NS_ERROR_NOT_IMPLEMENTED
;
1524 static nsresult NSAPI
nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal
*iface
, PRUint32
*major
, PRUint32
*minor
)
1526 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1528 FIXME("(%p)->()\n", This
);
1530 return NS_ERROR_NOT_IMPLEMENTED
;
1533 static nsresult NSAPI
nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal
*iface
, PRUint32
*major
, PRUint32
*minor
)
1535 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1537 FIXME("(%p)->()\n", This
);
1539 return NS_ERROR_NOT_IMPLEMENTED
;
1542 static nsresult NSAPI
nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal
*iface
, const char *aCookieHeader
)
1544 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1546 FIXME("(%p)->()\n", This
);
1548 return NS_ERROR_NOT_IMPLEMENTED
;
1551 static nsresult NSAPI
nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal
*iface
, const char *aFallbackKey
)
1553 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1555 FIXME("(%p)->()\n", This
);
1557 return NS_ERROR_NOT_IMPLEMENTED
;
1560 static nsresult NSAPI
nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, PRBool
*aForceThirdPartyCookie
)
1562 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1564 FIXME("(%p)->()\n", This
);
1566 return NS_ERROR_NOT_IMPLEMENTED
;
1569 static nsresult NSAPI
nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, PRBool aForceThirdPartyCookie
)
1571 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1573 FIXME("(%p)->()\n", This
);
1575 return NS_ERROR_NOT_IMPLEMENTED
;
1578 static nsresult NSAPI
nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal
*iface
, PRBool
*aCanceled
)
1580 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1582 FIXME("(%p)->(%p)\n", This
, aCanceled
);
1584 return NS_ERROR_NOT_IMPLEMENTED
;
1587 static nsresult NSAPI
nsHttpChannelInternal_GetChannelIsForDownload(nsIHttpChannelInternal
*iface
, PRBool
*aCanceled
)
1589 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1591 FIXME("(%p)->(%p)\n", This
, aCanceled
);
1593 return NS_ERROR_NOT_IMPLEMENTED
;
1596 static nsresult NSAPI
nsHttpChannelInternal_SetChannelIsForDownload(nsIHttpChannelInternal
*iface
, PRBool aCanceled
)
1598 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1600 FIXME("(%p)->(%x)\n", This
, aCanceled
);
1602 return NS_ERROR_NOT_IMPLEMENTED
;
1605 static nsresult NSAPI
nsHttpChannelInternal_GetLocalAddress(nsIHttpChannelInternal
*iface
, nsACString
*aLocalAddress
)
1607 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1609 FIXME("(%p)->(%p)\n", This
, aLocalAddress
);
1611 return NS_ERROR_NOT_IMPLEMENTED
;
1614 static nsresult NSAPI
nsHttpChannelInternal_GetLocalPort(nsIHttpChannelInternal
*iface
, PRInt32
*aLocalPort
)
1616 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1618 FIXME("(%p)->(%p)\n", This
, aLocalPort
);
1620 return NS_ERROR_NOT_IMPLEMENTED
;
1623 static nsresult NSAPI
nsHttpChannelInternal_GetRemoteAddress(nsIHttpChannelInternal
*iface
, nsACString
*aRemoteAddress
)
1625 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1627 FIXME("(%p)->(%p)\n", This
, aRemoteAddress
);
1629 return NS_ERROR_NOT_IMPLEMENTED
;
1632 static nsresult NSAPI
nsHttpChannelInternal_GetRemotePort(nsIHttpChannelInternal
*iface
, PRInt32
*aRemotePort
)
1634 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1636 FIXME("(%p)->(%p)\n", This
, aRemotePort
);
1638 return NS_ERROR_NOT_IMPLEMENTED
;
1641 static nsresult NSAPI
nsHttpChannelInternal_SetCacheKeysRedirectChain(nsIHttpChannelInternal
*iface
, void *cacheKeys
)
1643 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1645 FIXME("(%p)->(%p)\n", This
, cacheKeys
);
1647 return NS_ERROR_NOT_IMPLEMENTED
;
1650 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl
= {
1651 nsHttpChannelInternal_QueryInterface
,
1652 nsHttpChannelInternal_AddRef
,
1653 nsHttpChannelInternal_Release
,
1654 nsHttpChannelInternal_GetDocumentURI
,
1655 nsHttpChannelInternal_SetDocumentURI
,
1656 nsHttpChannelInternal_GetRequestVersion
,
1657 nsHttpChannelInternal_GetResponseVersion
,
1658 nsHttpChannelInternal_SetCookie
,
1659 nsHttpChannelInternal_SetupFallbackChannel
,
1660 nsHttpChannelInternal_GetForceAllowThirdPartyCookie
,
1661 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
,
1662 nsHttpChannelInternal_GetCanceled
,
1663 nsHttpChannelInternal_GetChannelIsForDownload
,
1664 nsHttpChannelInternal_SetChannelIsForDownload
,
1665 nsHttpChannelInternal_GetLocalAddress
,
1666 nsHttpChannelInternal_GetLocalPort
,
1667 nsHttpChannelInternal_GetRemoteAddress
,
1668 nsHttpChannelInternal_GetRemotePort
,
1669 nsHttpChannelInternal_SetCacheKeysRedirectChain
1673 static void invalidate_uri(nsWineURI
*This
)
1676 IUri_Release(This
->uri
);
1681 static BOOL
ensure_uri_builder(nsWineURI
*This
)
1683 if(!This
->is_mutable
) {
1684 WARN("Not mutable URI\n");
1688 if(!This
->uri_builder
) {
1691 if(!ensure_uri(This
))
1694 hres
= CreateIUriBuilder(This
->uri
, 0, 0, &This
->uri_builder
);
1696 WARN("CreateIUriBuilder failed: %08x\n", hres
);
1701 invalidate_uri(This
);
1705 static nsresult
get_uri_string(nsWineURI
*This
, Uri_PROPERTY prop
, nsACString
*ret
)
1711 if(!ensure_uri(This
))
1712 return NS_ERROR_UNEXPECTED
;
1714 hres
= IUri_GetPropertyBSTR(This
->uri
, prop
, &val
, 0);
1716 WARN("GetPropertyBSTR failed: %08x\n", hres
);
1717 return NS_ERROR_UNEXPECTED
;
1720 vala
= heap_strdupWtoA(val
);
1723 return NS_ERROR_OUT_OF_MEMORY
;
1725 TRACE("ret %s\n", debugstr_a(vala
));
1726 nsACString_SetData(ret
, vala
);
1731 static inline nsWineURI
*impl_from_nsIURL(nsIURL
*iface
)
1733 return CONTAINING_RECORD(iface
, nsWineURI
, nsIURL_iface
);
1736 static nsresult NSAPI
nsURI_QueryInterface(nsIURL
*iface
, nsIIDRef riid
, void **result
)
1738 nsWineURI
*This
= impl_from_nsIURL(iface
);
1742 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1743 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1744 *result
= &This
->nsIURL_iface
;
1745 }else if(IsEqualGUID(&IID_nsIURI
, riid
)) {
1746 TRACE("(%p)->(IID_nsIURI %p)\n", This
, result
);
1747 *result
= &This
->nsIURL_iface
;
1748 }else if(IsEqualGUID(&IID_nsIURL
, riid
)) {
1749 TRACE("(%p)->(IID_nsIURL %p)\n", This
, result
);
1750 *result
= &This
->nsIURL_iface
;
1751 }else if(IsEqualGUID(&IID_nsIMutable
, riid
)) {
1752 TRACE("(%p)->(IID_nsIMutable %p)\n", This
, result
);
1753 *result
= &This
->nsIStandardURL_iface
;
1754 }else if(IsEqualGUID(&IID_nsIStandardURL
, riid
)) {
1755 TRACE("(%p)->(IID_nsIStandardURL %p)\n", This
, result
);
1756 *result
= &This
->nsIStandardURL_iface
;
1757 }else if(IsEqualGUID(&IID_nsWineURI
, riid
)) {
1758 TRACE("(%p)->(IID_nsWineURI %p)\n", This
, result
);
1763 nsIURI_AddRef(&This
->nsIURL_iface
);
1767 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1768 return NS_NOINTERFACE
;
1771 static nsrefcnt NSAPI
nsURI_AddRef(nsIURL
*iface
)
1773 nsWineURI
*This
= impl_from_nsIURL(iface
);
1774 LONG ref
= InterlockedIncrement(&This
->ref
);
1776 TRACE("(%p) ref=%d\n", This
, ref
);
1781 static nsrefcnt NSAPI
nsURI_Release(nsIURL
*iface
)
1783 nsWineURI
*This
= impl_from_nsIURL(iface
);
1784 LONG ref
= InterlockedDecrement(&This
->ref
);
1786 TRACE("(%p) ref=%d\n", This
, ref
);
1789 if(This
->window_ref
)
1790 windowref_release(This
->window_ref
);
1792 nsIWebBrowserChrome_Release(&This
->container
->nsIWebBrowserChrome_iface
);
1794 IUri_Release(This
->uri
);
1801 static nsresult NSAPI
nsURI_GetSpec(nsIURL
*iface
, nsACString
*aSpec
)
1803 nsWineURI
*This
= impl_from_nsIURL(iface
);
1805 TRACE("(%p)->(%p)\n", This
, aSpec
);
1807 return get_uri_string(This
, Uri_PROPERTY_DISPLAY_URI
, aSpec
);
1810 static nsresult NSAPI
nsURI_SetSpec(nsIURL
*iface
, const nsACString
*aSpec
)
1812 nsWineURI
*This
= impl_from_nsIURL(iface
);
1818 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aSpec
));
1820 if(!This
->is_mutable
)
1821 return NS_ERROR_UNEXPECTED
;
1823 nsACString_GetData(aSpec
, &speca
);
1824 spec
= heap_strdupAtoW(speca
);
1826 return NS_ERROR_OUT_OF_MEMORY
;
1828 hres
= CreateUri(spec
, 0, 0, &uri
);
1831 WARN("CreateUri failed: %08x\n", hres
);
1832 return NS_ERROR_FAILURE
;
1835 invalidate_uri(This
);
1836 if(This
->uri_builder
) {
1837 IUriBuilder_Release(This
->uri_builder
);
1838 This
->uri_builder
= NULL
;
1845 static nsresult NSAPI
nsURI_GetPrePath(nsIURL
*iface
, nsACString
*aPrePath
)
1847 nsWineURI
*This
= impl_from_nsIURL(iface
);
1848 FIXME("(%p)->(%p)\n", This
, aPrePath
);
1849 return NS_ERROR_NOT_IMPLEMENTED
;
1852 static nsresult NSAPI
nsURI_GetScheme(nsIURL
*iface
, nsACString
*aScheme
)
1854 nsWineURI
*This
= impl_from_nsIURL(iface
);
1858 TRACE("(%p)->(%p)\n", This
, aScheme
);
1860 if(!ensure_uri(This
))
1861 return NS_ERROR_UNEXPECTED
;
1863 hres
= IUri_GetScheme(This
->uri
, &scheme
);
1865 WARN("GetScheme failed: %08x\n", hres
);
1866 return NS_ERROR_UNEXPECTED
;
1869 if(scheme
== URL_SCHEME_ABOUT
) {
1870 nsACString_SetData(aScheme
, "wine");
1874 return get_uri_string(This
, Uri_PROPERTY_SCHEME_NAME
, aScheme
);
1877 static nsresult NSAPI
nsURI_SetScheme(nsIURL
*iface
, const nsACString
*aScheme
)
1879 nsWineURI
*This
= impl_from_nsIURL(iface
);
1880 const char *schemea
;
1884 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aScheme
));
1886 if(!ensure_uri_builder(This
))
1887 return NS_ERROR_UNEXPECTED
;
1889 nsACString_GetData(aScheme
, &schemea
);
1890 scheme
= heap_strdupAtoW(schemea
);
1892 return NS_ERROR_OUT_OF_MEMORY
;
1894 hres
= IUriBuilder_SetSchemeName(This
->uri_builder
, scheme
);
1897 return NS_ERROR_UNEXPECTED
;
1902 static nsresult NSAPI
nsURI_GetUserPass(nsIURL
*iface
, nsACString
*aUserPass
)
1904 nsWineURI
*This
= impl_from_nsIURL(iface
);
1908 TRACE("(%p)->(%p)\n", This
, aUserPass
);
1910 if(!ensure_uri(This
))
1911 return NS_ERROR_UNEXPECTED
;
1913 hres
= IUri_GetUserName(This
->uri
, &user
);
1915 return NS_ERROR_FAILURE
;
1917 hres
= IUri_GetPassword(This
->uri
, &pass
);
1919 SysFreeString(user
);
1920 return NS_ERROR_FAILURE
;
1923 if(*user
|| *pass
) {
1924 FIXME("Construct user:pass string\n");
1926 nsACString_SetData(aUserPass
, "");
1929 SysFreeString(user
);
1930 SysFreeString(pass
);
1934 static nsresult NSAPI
nsURI_SetUserPass(nsIURL
*iface
, const nsACString
*aUserPass
)
1936 nsWineURI
*This
= impl_from_nsIURL(iface
);
1937 WCHAR
*user
= NULL
, *pass
= NULL
, *buf
= NULL
;
1938 const char *user_pass
;
1941 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUserPass
));
1943 if(!ensure_uri_builder(This
))
1944 return NS_ERROR_UNEXPECTED
;
1946 nsACString_GetData(aUserPass
, &user_pass
);
1950 buf
= heap_strdupAtoW(user_pass
);
1952 return NS_ERROR_OUT_OF_MEMORY
;
1954 ptr
= strchrW(buf
, ':');
1957 }else if(ptr
!= buf
) {
1967 hres
= IUriBuilder_SetUserName(This
->uri_builder
, user
);
1969 hres
= IUriBuilder_SetPassword(This
->uri_builder
, pass
);
1972 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_FAILURE
;
1975 static nsresult NSAPI
nsURI_GetUsername(nsIURL
*iface
, nsACString
*aUsername
)
1977 nsWineURI
*This
= impl_from_nsIURL(iface
);
1979 TRACE("(%p)->(%p)\n", This
, aUsername
);
1981 return get_uri_string(This
, Uri_PROPERTY_USER_NAME
, aUsername
);
1984 static nsresult NSAPI
nsURI_SetUsername(nsIURL
*iface
, const nsACString
*aUsername
)
1986 nsWineURI
*This
= impl_from_nsIURL(iface
);
1991 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUsername
));
1993 if(!ensure_uri_builder(This
))
1994 return NS_ERROR_UNEXPECTED
;
1996 nsACString_GetData(aUsername
, &usera
);
1997 user
= heap_strdupAtoW(usera
);
1999 return NS_ERROR_OUT_OF_MEMORY
;
2001 hres
= IUriBuilder_SetUserName(This
->uri_builder
, user
);
2004 return NS_ERROR_UNEXPECTED
;
2009 static nsresult NSAPI
nsURI_GetPassword(nsIURL
*iface
, nsACString
*aPassword
)
2011 nsWineURI
*This
= impl_from_nsIURL(iface
);
2013 TRACE("(%p)->(%p)\n", This
, aPassword
);
2015 return get_uri_string(This
, Uri_PROPERTY_PASSWORD
, aPassword
);
2018 static nsresult NSAPI
nsURI_SetPassword(nsIURL
*iface
, const nsACString
*aPassword
)
2020 nsWineURI
*This
= impl_from_nsIURL(iface
);
2025 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPassword
));
2027 if(!ensure_uri_builder(This
))
2028 return NS_ERROR_UNEXPECTED
;
2030 nsACString_GetData(aPassword
, &passa
);
2031 pass
= heap_strdupAtoW(passa
);
2033 return NS_ERROR_OUT_OF_MEMORY
;
2035 hres
= IUriBuilder_SetPassword(This
->uri_builder
, pass
);
2038 return NS_ERROR_UNEXPECTED
;
2043 static nsresult NSAPI
nsURI_GetHostPort(nsIURL
*iface
, nsACString
*aHostPort
)
2045 nsWineURI
*This
= impl_from_nsIURL(iface
);
2051 TRACE("(%p)->(%p)\n", This
, aHostPort
);
2053 if(!ensure_uri(This
))
2054 return NS_ERROR_UNEXPECTED
;
2056 hres
= IUri_GetAuthority(This
->uri
, &val
);
2058 WARN("GetAuthority failed: %08x\n", hres
);
2059 return NS_ERROR_UNEXPECTED
;
2062 ptr
= strchrW(val
, '@');
2066 vala
= heap_strdupWtoA(ptr
);
2069 return NS_ERROR_OUT_OF_MEMORY
;
2071 TRACE("ret %s\n", debugstr_a(vala
));
2072 nsACString_SetData(aHostPort
, vala
);
2077 static nsresult NSAPI
nsURI_SetHostPort(nsIURL
*iface
, const nsACString
*aHostPort
)
2079 nsWineURI
*This
= impl_from_nsIURL(iface
);
2081 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aHostPort
));
2083 /* Not implemented by Gecko */
2084 return NS_ERROR_NOT_IMPLEMENTED
;
2087 static nsresult NSAPI
nsURI_GetHost(nsIURL
*iface
, nsACString
*aHost
)
2089 nsWineURI
*This
= impl_from_nsIURL(iface
);
2091 TRACE("(%p)->(%p)\n", This
, aHost
);
2093 return get_uri_string(This
, Uri_PROPERTY_HOST
, aHost
);
2096 static nsresult NSAPI
nsURI_SetHost(nsIURL
*iface
, const nsACString
*aHost
)
2098 nsWineURI
*This
= impl_from_nsIURL(iface
);
2103 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aHost
));
2105 if(!ensure_uri_builder(This
))
2106 return NS_ERROR_UNEXPECTED
;
2108 nsACString_GetData(aHost
, &hosta
);
2109 host
= heap_strdupAtoW(hosta
);
2111 return NS_ERROR_OUT_OF_MEMORY
;
2113 hres
= IUriBuilder_SetHost(This
->uri_builder
, host
);
2116 return NS_ERROR_UNEXPECTED
;
2121 static nsresult NSAPI
nsURI_GetPort(nsIURL
*iface
, PRInt32
*aPort
)
2123 nsWineURI
*This
= impl_from_nsIURL(iface
);
2127 TRACE("(%p)->(%p)\n", This
, aPort
);
2129 if(!ensure_uri(This
))
2130 return NS_ERROR_UNEXPECTED
;
2132 hres
= IUri_GetPort(This
->uri
, &port
);
2134 WARN("GetPort failed: %08x\n", hres
);
2135 return NS_ERROR_UNEXPECTED
;
2138 *aPort
= port
? port
: -1;
2142 static nsresult NSAPI
nsURI_SetPort(nsIURL
*iface
, PRInt32 aPort
)
2144 nsWineURI
*This
= impl_from_nsIURL(iface
);
2147 TRACE("(%p)->(%d)\n", This
, aPort
);
2149 if(!ensure_uri_builder(This
))
2150 return NS_ERROR_UNEXPECTED
;
2152 hres
= IUriBuilder_SetPort(This
->uri_builder
, aPort
!= -1, aPort
);
2153 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_FAILURE
;
2156 static nsresult NSAPI
nsURI_GetPath(nsIURL
*iface
, nsACString
*aPath
)
2158 nsWineURI
*This
= impl_from_nsIURL(iface
);
2160 TRACE("(%p)->(%p)\n", This
, aPath
);
2162 return get_uri_string(This
, Uri_PROPERTY_PATH
, aPath
);
2165 static nsresult NSAPI
nsURI_SetPath(nsIURL
*iface
, const nsACString
*aPath
)
2167 nsWineURI
*This
= impl_from_nsIURL(iface
);
2172 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPath
));
2174 if(!ensure_uri_builder(This
))
2175 return NS_ERROR_UNEXPECTED
;
2177 nsACString_GetData(aPath
, &patha
);
2178 path
= heap_strdupAtoW(patha
);
2180 return NS_ERROR_OUT_OF_MEMORY
;
2182 hres
= IUriBuilder_SetPath(This
->uri_builder
, path
);
2185 return NS_ERROR_UNEXPECTED
;
2190 static nsresult NSAPI
nsURI_Equals(nsIURL
*iface
, nsIURI
*other
, PRBool
*_retval
)
2192 nsWineURI
*This
= impl_from_nsIURL(iface
);
2193 nsWineURI
*other_obj
;
2197 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
2199 nsres
= nsIURI_QueryInterface(other
, &IID_nsWineURI
, (void**)&other_obj
);
2200 if(NS_FAILED(nsres
)) {
2201 TRACE("Could not get nsWineURI interface\n");
2206 if(ensure_uri(This
) && ensure_uri(other_obj
)) {
2209 hres
= IUri_IsEqual(This
->uri
, other_obj
->uri
, &b
);
2210 if(SUCCEEDED(hres
)) {
2214 nsres
= NS_ERROR_FAILURE
;
2217 nsres
= NS_ERROR_UNEXPECTED
;
2220 nsIURI_Release(&other_obj
->nsIURL_iface
);
2224 static nsresult NSAPI
nsURI_SchemeIs(nsIURL
*iface
, const char *scheme
, PRBool
*_retval
)
2226 nsWineURI
*This
= impl_from_nsIURL(iface
);
2227 WCHAR buf
[INTERNET_MAX_SCHEME_LENGTH
];
2231 TRACE("(%p)->(%s %p)\n", This
, debugstr_a(scheme
), _retval
);
2233 if(!ensure_uri(This
))
2234 return NS_ERROR_UNEXPECTED
;
2236 hres
= IUri_GetSchemeName(This
->uri
, &scheme_name
);
2238 return NS_ERROR_UNEXPECTED
;
2240 MultiByteToWideChar(CP_ACP
, 0, scheme
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
2241 *_retval
= !strcmpW(scheme_name
, buf
);
2242 SysFreeString(scheme_name
);
2246 static nsresult NSAPI
nsURI_Clone(nsIURL
*iface
, nsIURI
**_retval
)
2248 nsWineURI
*This
= impl_from_nsIURL(iface
);
2249 nsWineURI
*wine_uri
;
2252 TRACE("(%p)->(%p)\n", This
, _retval
);
2254 if(!ensure_uri(This
))
2255 return NS_ERROR_UNEXPECTED
;
2257 nsres
= create_nsuri(This
->uri
, This
->window_ref
? This
->window_ref
->window
: NULL
, This
->container
, &wine_uri
);
2258 if(NS_FAILED(nsres
)) {
2259 WARN("create_nsuri failed: %08x\n", nsres
);
2263 *_retval
= (nsIURI
*)&wine_uri
->nsIURL_iface
;
2267 static nsresult NSAPI
nsURI_Resolve(nsIURL
*iface
, const nsACString
*aRelativePath
,
2268 nsACString
*_retval
)
2270 nsWineURI
*This
= impl_from_nsIURL(iface
);
2278 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aRelativePath
), _retval
);
2280 if(!ensure_uri(This
))
2281 return NS_ERROR_UNEXPECTED
;
2283 nsACString_GetData(aRelativePath
, &patha
);
2284 path
= heap_strdupAtoW(patha
);
2286 return NS_ERROR_OUT_OF_MEMORY
;
2288 hres
= CoInternetCombineUrlEx(This
->uri
, path
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
, &new_uri
, 0);
2291 ERR("CoIntenetCombineUrlEx failed: %08x\n", hres
);
2292 return NS_ERROR_FAILURE
;
2295 hres
= IUri_GetDisplayUri(new_uri
, &ret
);
2296 IUri_Release(new_uri
);
2298 return NS_ERROR_FAILURE
;
2300 reta
= heap_strdupWtoA(ret
);
2303 return NS_ERROR_OUT_OF_MEMORY
;
2305 TRACE("returning %s\n", debugstr_a(reta
));
2306 nsACString_SetData(_retval
, reta
);
2311 static nsresult NSAPI
nsURI_GetAsciiSpec(nsIURL
*iface
, nsACString
*aAsciiSpec
)
2313 nsWineURI
*This
= impl_from_nsIURL(iface
);
2315 TRACE("(%p)->(%p)\n", This
, aAsciiSpec
);
2317 return nsIURI_GetSpec(&This
->nsIURL_iface
, aAsciiSpec
);
2320 static nsresult NSAPI
nsURI_GetAsciiHost(nsIURL
*iface
, nsACString
*aAsciiHost
)
2322 nsWineURI
*This
= impl_from_nsIURL(iface
);
2324 WARN("(%p)->(%p) FIXME: Use Uri_PUNYCODE_IDN_HOST flag\n", This
, aAsciiHost
);
2326 return get_uri_string(This
, Uri_PROPERTY_HOST
, aAsciiHost
);
2329 static nsresult NSAPI
nsURI_GetOriginCharset(nsIURL
*iface
, nsACString
*aOriginCharset
)
2331 nsWineURI
*This
= impl_from_nsIURL(iface
);
2332 FIXME("(%p)->(%p)\n", This
, aOriginCharset
);
2333 return NS_ERROR_NOT_IMPLEMENTED
;
2336 static nsresult NSAPI
nsURL_GetRef(nsIURL
*iface
, nsACString
*aRef
)
2338 nsWineURI
*This
= impl_from_nsIURL(iface
);
2343 TRACE("(%p)->(%p)\n", This
, aRef
);
2345 if(!ensure_uri(This
))
2346 return NS_ERROR_UNEXPECTED
;
2348 hres
= IUri_GetFragment(This
->uri
, &ref
);
2350 return NS_ERROR_UNEXPECTED
;
2352 refa
= heap_strdupWtoA(ref
);
2355 return NS_ERROR_OUT_OF_MEMORY
;
2357 nsACString_SetData(aRef
, refa
&& *refa
== '#' ? refa
+1 : refa
);
2362 static nsresult NSAPI
nsURL_SetRef(nsIURL
*iface
, const nsACString
*aRef
)
2364 nsWineURI
*This
= impl_from_nsIURL(iface
);
2369 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRef
));
2371 if(!ensure_uri_builder(This
))
2372 return NS_ERROR_UNEXPECTED
;
2374 nsACString_GetData(aRef
, &refa
);
2375 ref
= heap_strdupAtoW(refa
);
2377 return NS_ERROR_OUT_OF_MEMORY
;
2379 hres
= IUriBuilder_SetFragment(This
->uri_builder
, ref
);
2382 return NS_ERROR_UNEXPECTED
;
2387 static nsresult NSAPI
nsURI_EqualsExceptRef(nsIURL
*iface
, nsIURI
*other
, PRBool
*_retval
)
2389 nsWineURI
*This
= impl_from_nsIURL(iface
);
2390 nsWineURI
*other_obj
;
2393 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
2395 nsres
= nsIURI_QueryInterface(other
, &IID_nsWineURI
, (void**)&other_obj
);
2396 if(NS_FAILED(nsres
)) {
2397 TRACE("Could not get nsWineURI interface\n");
2402 if(ensure_uri(This
) && ensure_uri(other_obj
)) {
2403 *_retval
= compare_ignoring_frag(This
->uri
, other_obj
->uri
);
2406 nsres
= NS_ERROR_UNEXPECTED
;
2409 nsIURI_Release(&other_obj
->nsIURL_iface
);
2413 static nsresult NSAPI
nsURI_CloneIgnoreRef(nsIURL
*iface
, nsIURI
**_retval
)
2415 nsWineURI
*This
= impl_from_nsIURL(iface
);
2416 nsWineURI
*wine_uri
;
2420 TRACE("(%p)->(%p)\n", This
, _retval
);
2422 if(!ensure_uri(This
))
2423 return NS_ERROR_UNEXPECTED
;
2425 uri
= get_uri_nofrag(This
->uri
);
2427 return NS_ERROR_FAILURE
;
2429 nsres
= create_nsuri(uri
, This
->window_ref
? This
->window_ref
->window
: NULL
, This
->container
, &wine_uri
);
2431 if(NS_FAILED(nsres
)) {
2432 WARN("create_nsuri failed: %08x\n", nsres
);
2436 *_retval
= (nsIURI
*)&wine_uri
->nsIURL_iface
;
2440 static nsresult NSAPI
nsURI_GetSpecIgnoringRef(nsIURL
*iface
, nsACString
*aSpecIgnoringRef
)
2442 nsWineURI
*This
= impl_from_nsIURL(iface
);
2444 FIXME("(%p)->(%p)\n", This
, aSpecIgnoringRef
);
2446 return nsIURL_GetSpec(&This
->nsIURL_iface
, aSpecIgnoringRef
);
2449 static nsresult NSAPI
nsURI_GetHasRef(nsIURL
*iface
, PRBool
*aHasRef
)
2451 nsWineURI
*This
= impl_from_nsIURL(iface
);
2455 TRACE("(%p)->(%p)\n", This
, aHasRef
);
2457 if(!ensure_uri(This
))
2458 return NS_ERROR_UNEXPECTED
;
2460 hres
= IUri_HasProperty(This
->uri
, Uri_PROPERTY_FRAGMENT
, &b
);
2462 return NS_ERROR_FAILURE
;
2468 static nsresult NSAPI
nsURL_GetFilePath(nsIURL
*iface
, nsACString
*aFilePath
)
2470 nsWineURI
*This
= impl_from_nsIURL(iface
);
2472 TRACE("(%p)->(%p)\n", This
, aFilePath
);
2474 return nsIURL_GetPath(&This
->nsIURL_iface
, aFilePath
);
2477 static nsresult NSAPI
nsURL_SetFilePath(nsIURL
*iface
, const nsACString
*aFilePath
)
2479 nsWineURI
*This
= impl_from_nsIURL(iface
);
2481 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFilePath
));
2483 if(!This
->is_mutable
)
2484 return NS_ERROR_UNEXPECTED
;
2486 return nsIURL_SetPath(&This
->nsIURL_iface
, aFilePath
);
2489 static nsresult NSAPI
nsURL_GetParam(nsIURL
*iface
, nsACString
*aParam
)
2491 nsWineURI
*This
= impl_from_nsIURL(iface
);
2493 WARN("(%p)->(%p)\n", This
, aParam
);
2495 /* This is a leftover of ';' special handling in URLs. It will be removed from Gecko soon */
2496 nsACString_SetData(aParam
, "");
2500 static nsresult NSAPI
nsURL_SetParam(nsIURL
*iface
, const nsACString
*aParam
)
2502 nsWineURI
*This
= impl_from_nsIURL(iface
);
2504 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aParam
));
2506 /* Not implemented by Gecko */
2507 return NS_ERROR_NOT_IMPLEMENTED
;
2510 static nsresult NSAPI
nsURL_GetQuery(nsIURL
*iface
, nsACString
*aQuery
)
2512 nsWineURI
*This
= impl_from_nsIURL(iface
);
2514 TRACE("(%p)->(%p)\n", This
, aQuery
);
2516 return get_uri_string(This
, Uri_PROPERTY_QUERY
, aQuery
);
2519 static nsresult NSAPI
nsURL_SetQuery(nsIURL
*iface
, const nsACString
*aQuery
)
2521 nsWineURI
*This
= impl_from_nsIURL(iface
);
2526 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aQuery
));
2528 if(!ensure_uri_builder(This
))
2529 return NS_ERROR_UNEXPECTED
;
2531 nsACString_GetData(aQuery
, &querya
);
2532 query
= heap_strdupAtoW(querya
);
2534 return NS_ERROR_OUT_OF_MEMORY
;
2536 hres
= IUriBuilder_SetQuery(This
->uri_builder
, query
);
2539 return NS_ERROR_UNEXPECTED
;
2544 static nsresult
get_uri_path(nsWineURI
*This
, BSTR
*path
, const WCHAR
**file
, const WCHAR
**ext
)
2549 if(!ensure_uri(This
))
2550 return NS_ERROR_UNEXPECTED
;
2552 hres
= IUri_GetPath(This
->uri
, path
);
2554 return NS_ERROR_FAILURE
;
2556 for(ptr
= *path
+ SysStringLen(*path
)-1; ptr
> *path
&& *ptr
!= '/' && *ptr
!= '\\'; ptr
--);
2557 if(*ptr
== '/' || *ptr
== '\\')
2562 ptr
= strrchrW(ptr
, '.');
2564 ptr
= *path
+ SysStringLen(*path
);
2571 static nsresult NSAPI
nsURL_GetDirectory(nsIURL
*iface
, nsACString
*aDirectory
)
2573 nsWineURI
*This
= impl_from_nsIURL(iface
);
2578 TRACE("(%p)->(%p)\n", This
, aDirectory
);
2580 nsres
= get_uri_path(This
, &path
, &file
, NULL
);
2581 if(NS_FAILED(nsres
))
2584 nsres
= return_wstr_nsacstr(aDirectory
, path
, file
-path
);
2585 SysFreeString(path
);
2589 static nsresult NSAPI
nsURL_SetDirectory(nsIURL
*iface
, const nsACString
*aDirectory
)
2591 nsWineURI
*This
= impl_from_nsIURL(iface
);
2593 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aDirectory
));
2595 /* Not implemented by Gecko */
2596 return NS_ERROR_NOT_IMPLEMENTED
;
2599 static nsresult NSAPI
nsURL_GetFileName(nsIURL
*iface
, nsACString
*aFileName
)
2601 nsWineURI
*This
= impl_from_nsIURL(iface
);
2606 TRACE("(%p)->(%p)\n", This
, aFileName
);
2608 nsres
= get_uri_path(This
, &path
, &file
, NULL
);
2609 if(NS_FAILED(nsres
))
2612 nsres
= return_wstr_nsacstr(aFileName
, file
, -1);
2613 SysFreeString(path
);
2617 static nsresult NSAPI
nsURL_SetFileName(nsIURL
*iface
, const nsACString
*aFileName
)
2619 nsWineURI
*This
= impl_from_nsIURL(iface
);
2620 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileName
));
2621 return NS_ERROR_NOT_IMPLEMENTED
;
2624 static nsresult NSAPI
nsURL_GetFileBaseName(nsIURL
*iface
, nsACString
*aFileBaseName
)
2626 nsWineURI
*This
= impl_from_nsIURL(iface
);
2627 const WCHAR
*file
, *ext
;
2631 TRACE("(%p)->(%p)\n", This
, aFileBaseName
);
2633 nsres
= get_uri_path(This
, &path
, &file
, &ext
);
2634 if(NS_FAILED(nsres
))
2637 nsres
= return_wstr_nsacstr(aFileBaseName
, file
, ext
-file
);
2638 SysFreeString(path
);
2642 static nsresult NSAPI
nsURL_SetFileBaseName(nsIURL
*iface
, const nsACString
*aFileBaseName
)
2644 nsWineURI
*This
= impl_from_nsIURL(iface
);
2645 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileBaseName
));
2646 return NS_ERROR_NOT_IMPLEMENTED
;
2649 static nsresult NSAPI
nsURL_GetFileExtension(nsIURL
*iface
, nsACString
*aFileExtension
)
2651 nsWineURI
*This
= impl_from_nsIURL(iface
);
2653 TRACE("(%p)->(%p)\n", This
, aFileExtension
);
2655 return get_uri_string(This
, Uri_PROPERTY_EXTENSION
, aFileExtension
);
2658 static nsresult NSAPI
nsURL_SetFileExtension(nsIURL
*iface
, const nsACString
*aFileExtension
)
2660 nsWineURI
*This
= impl_from_nsIURL(iface
);
2661 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileExtension
));
2662 return NS_ERROR_NOT_IMPLEMENTED
;
2665 static nsresult NSAPI
nsURL_GetCommonBaseSpec(nsIURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2667 nsWineURI
*This
= impl_from_nsIURL(iface
);
2668 FIXME("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2669 return NS_ERROR_NOT_IMPLEMENTED
;
2672 static nsresult NSAPI
nsURL_GetRelativeSpec(nsIURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2674 nsWineURI
*This
= impl_from_nsIURL(iface
);
2675 FIXME("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2676 return NS_ERROR_NOT_IMPLEMENTED
;
2679 static const nsIURLVtbl nsURLVtbl
= {
2680 nsURI_QueryInterface
,
2708 nsURI_GetOriginCharset
,
2711 nsURI_EqualsExceptRef
,
2712 nsURI_CloneIgnoreRef
,
2713 nsURI_GetSpecIgnoringRef
,
2725 nsURL_GetFileBaseName
,
2726 nsURL_SetFileBaseName
,
2727 nsURL_GetFileExtension
,
2728 nsURL_SetFileExtension
,
2729 nsURL_GetCommonBaseSpec
,
2730 nsURL_GetRelativeSpec
2733 static inline nsWineURI
*impl_from_nsIStandardURL(nsIStandardURL
*iface
)
2735 return CONTAINING_RECORD(iface
, nsWineURI
, nsIStandardURL_iface
);
2738 static nsresult NSAPI
nsStandardURL_QueryInterface(nsIStandardURL
*iface
, nsIIDRef riid
,
2741 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2742 return nsIURL_QueryInterface(&This
->nsIURL_iface
, riid
, result
);
2745 static nsrefcnt NSAPI
nsStandardURL_AddRef(nsIStandardURL
*iface
)
2747 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2748 return nsIURL_AddRef(&This
->nsIURL_iface
);
2751 static nsrefcnt NSAPI
nsStandardURL_Release(nsIStandardURL
*iface
)
2753 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2754 return nsIURL_Release(&This
->nsIURL_iface
);
2757 static nsresult NSAPI
nsStandardURL_GetMutable(nsIStandardURL
*iface
, PRBool
*aMutable
)
2759 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2761 TRACE("(%p)->(%p)\n", This
, aMutable
);
2763 *aMutable
= This
->is_mutable
;
2767 static nsresult NSAPI
nsStandardURL_SetMutable(nsIStandardURL
*iface
, PRBool aMutable
)
2769 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2771 TRACE("(%p)->(%x)\n", This
, aMutable
);
2773 This
->is_mutable
= aMutable
;
2777 static nsresult NSAPI
nsStandardURL_Init(nsIStandardURL
*iface
, PRUint32 aUrlType
, PRInt32 aDefaultPort
,
2778 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
)
2780 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2781 FIXME("(%p)->(%d %d %s %s %p)\n", This
, aUrlType
, aDefaultPort
, debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
), aBaseURI
);
2782 return NS_ERROR_NOT_IMPLEMENTED
;
2785 static const nsIStandardURLVtbl nsStandardURLVtbl
= {
2786 nsStandardURL_QueryInterface
,
2787 nsStandardURL_AddRef
,
2788 nsStandardURL_Release
,
2789 nsStandardURL_GetMutable
,
2790 nsStandardURL_SetMutable
,
2794 static nsresult
create_nsuri(IUri
*iuri
, HTMLWindow
*window
, NSContainer
*container
, nsWineURI
**_retval
)
2796 nsWineURI
*ret
= heap_alloc_zero(sizeof(nsWineURI
));
2798 ret
->nsIURL_iface
.lpVtbl
= &nsURLVtbl
;
2799 ret
->nsIStandardURL_iface
.lpVtbl
= &nsStandardURLVtbl
;
2801 ret
->is_mutable
= TRUE
;
2803 set_uri_nscontainer(ret
, container
);
2804 set_uri_window(ret
, window
);
2809 TRACE("retval=%p\n", ret
);
2814 HRESULT
create_doc_uri(HTMLWindow
*window
, WCHAR
*url
, nsWineURI
**ret
)
2821 hres
= CreateUri(url
, 0, 0, &iuri
);
2825 nsres
= create_nsuri(iuri
, window
, window
->doc_obj
->nscontainer
, &uri
);
2827 if(NS_FAILED(nsres
))
2830 uri
->is_doc_uri
= TRUE
;
2836 static nsresult
create_nschannel(nsWineURI
*uri
, nsChannel
**ret
)
2841 if(!ensure_uri(uri
))
2842 return NS_ERROR_UNEXPECTED
;
2844 channel
= heap_alloc_zero(sizeof(nsChannel
));
2846 return NS_ERROR_OUT_OF_MEMORY
;
2848 channel
->nsIHttpChannel_iface
.lpVtbl
= &nsChannelVtbl
;
2849 channel
->nsIUploadChannel_iface
.lpVtbl
= &nsUploadChannelVtbl
;
2850 channel
->nsIHttpChannelInternal_iface
.lpVtbl
= &nsHttpChannelInternalVtbl
;
2852 channel
->request_method
= METHOD_GET
;
2853 list_init(&channel
->response_headers
);
2854 list_init(&channel
->request_headers
);
2856 nsIURL_AddRef(&uri
->nsIURL_iface
);
2859 hres
= IUri_GetScheme(uri
->uri
, &channel
->url_scheme
);
2861 channel
->url_scheme
= URL_SCHEME_UNKNOWN
;
2867 HRESULT
create_redirect_nschannel(const WCHAR
*url
, nsChannel
*orig_channel
, nsChannel
**ret
)
2869 HTMLWindow
*window
= NULL
;
2876 hres
= CreateUri(url
, 0, 0, &iuri
);
2880 if(orig_channel
->uri
->window_ref
)
2881 window
= orig_channel
->uri
->window_ref
->window
;
2882 nsres
= create_nsuri(iuri
, window
, NULL
, &uri
);
2884 if(NS_FAILED(nsres
))
2887 nsres
= create_nschannel(uri
, &channel
);
2888 nsIURL_Release(&uri
->nsIURL_iface
);
2889 if(NS_FAILED(nsres
))
2892 if(orig_channel
->load_group
) {
2893 nsILoadGroup_AddRef(orig_channel
->load_group
);
2894 channel
->load_group
= orig_channel
->load_group
;
2897 if(orig_channel
->notif_callback
) {
2898 nsIInterfaceRequestor_AddRef(orig_channel
->notif_callback
);
2899 channel
->notif_callback
= orig_channel
->notif_callback
;
2902 channel
->load_flags
= orig_channel
->load_flags
| LOAD_REPLACE
;
2904 if(orig_channel
->request_method
== METHOD_POST
)
2905 FIXME("unsupported POST method\n");
2907 if(orig_channel
->original_uri
) {
2908 nsIURI_AddRef(orig_channel
->original_uri
);
2909 channel
->original_uri
= orig_channel
->original_uri
;
2912 if(orig_channel
->referrer
) {
2913 nsIURI_AddRef(orig_channel
->referrer
);
2914 channel
->referrer
= orig_channel
->referrer
;
2922 nsIProtocolHandler nsIProtocolHandler_iface
;
2926 nsIProtocolHandler
*nshandler
;
2927 } nsProtocolHandler
;
2929 static inline nsProtocolHandler
*impl_from_nsIProtocolHandler(nsIProtocolHandler
*iface
)
2931 return CONTAINING_RECORD(iface
, nsProtocolHandler
, nsIProtocolHandler_iface
);
2934 static nsresult NSAPI
nsProtocolHandler_QueryInterface(nsIProtocolHandler
*iface
, nsIIDRef riid
,
2937 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2941 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
2942 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
2943 *result
= &This
->nsIProtocolHandler_iface
;
2944 }else if(IsEqualGUID(&IID_nsIProtocolHandler
, riid
)) {
2945 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This
, result
);
2946 *result
= &This
->nsIProtocolHandler_iface
;
2947 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler
, riid
)) {
2948 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This
, result
);
2949 return NS_NOINTERFACE
;
2953 nsISupports_AddRef((nsISupports
*)*result
);
2957 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
2958 return NS_NOINTERFACE
;
2961 static nsrefcnt NSAPI
nsProtocolHandler_AddRef(nsIProtocolHandler
*iface
)
2963 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2964 LONG ref
= InterlockedIncrement(&This
->ref
);
2966 TRACE("(%p) ref=%d\n", This
, ref
);
2971 static nsrefcnt NSAPI
nsProtocolHandler_Release(nsIProtocolHandler
*iface
)
2973 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2974 LONG ref
= InterlockedDecrement(&This
->ref
);
2976 TRACE("(%p) ref=%d\n", This
, ref
);
2980 nsIProtocolHandler_Release(This
->nshandler
);
2987 static nsresult NSAPI
nsProtocolHandler_GetScheme(nsIProtocolHandler
*iface
, nsACString
*aScheme
)
2989 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2991 TRACE("(%p)->(%p)\n", This
, aScheme
);
2994 return nsIProtocolHandler_GetScheme(This
->nshandler
, aScheme
);
2995 return NS_ERROR_NOT_IMPLEMENTED
;
2998 static nsresult NSAPI
nsProtocolHandler_GetDefaultPort(nsIProtocolHandler
*iface
,
2999 PRInt32
*aDefaultPort
)
3001 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3003 TRACE("(%p)->(%p)\n", This
, aDefaultPort
);
3006 return nsIProtocolHandler_GetDefaultPort(This
->nshandler
, aDefaultPort
);
3007 return NS_ERROR_NOT_IMPLEMENTED
;
3010 static nsresult NSAPI
nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler
*iface
,
3011 PRUint32
*aProtocolFlags
)
3013 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3015 TRACE("(%p)->(%p)\n", This
, aProtocolFlags
);
3018 return nsIProtocolHandler_GetProtocolFlags(This
->nshandler
, aProtocolFlags
);
3019 return NS_ERROR_NOT_IMPLEMENTED
;
3022 static nsresult NSAPI
nsProtocolHandler_NewURI(nsIProtocolHandler
*iface
,
3023 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
3025 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3027 TRACE("((%p)->%s %s %p %p)\n", This
, debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
3031 return nsIProtocolHandler_NewURI(This
->nshandler
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3032 return NS_ERROR_NOT_IMPLEMENTED
;
3035 static nsresult NSAPI
nsProtocolHandler_NewChannel(nsIProtocolHandler
*iface
,
3036 nsIURI
*aURI
, nsIChannel
**_retval
)
3038 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3040 TRACE("(%p)->(%p %p)\n", This
, aURI
, _retval
);
3043 return nsIProtocolHandler_NewChannel(This
->nshandler
, aURI
, _retval
);
3044 return NS_ERROR_NOT_IMPLEMENTED
;
3047 static nsresult NSAPI
nsProtocolHandler_AllowPort(nsIProtocolHandler
*iface
,
3048 PRInt32 port
, const char *scheme
, PRBool
*_retval
)
3050 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3052 TRACE("(%p)->(%d %s %p)\n", This
, port
, debugstr_a(scheme
), _retval
);
3055 return nsIProtocolHandler_AllowPort(This
->nshandler
, port
, scheme
, _retval
);
3056 return NS_ERROR_NOT_IMPLEMENTED
;
3059 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl
= {
3060 nsProtocolHandler_QueryInterface
,
3061 nsProtocolHandler_AddRef
,
3062 nsProtocolHandler_Release
,
3063 nsProtocolHandler_GetScheme
,
3064 nsProtocolHandler_GetDefaultPort
,
3065 nsProtocolHandler_GetProtocolFlags
,
3066 nsProtocolHandler_NewURI
,
3067 nsProtocolHandler_NewChannel
,
3068 nsProtocolHandler_AllowPort
3071 static nsIProtocolHandler
*create_protocol_handler(nsIProtocolHandler
*nshandler
)
3073 nsProtocolHandler
*ret
= heap_alloc(sizeof(nsProtocolHandler
));
3075 ret
->nsIProtocolHandler_iface
.lpVtbl
= &nsProtocolHandlerVtbl
;
3077 ret
->nshandler
= nshandler
;
3079 return &ret
->nsIProtocolHandler_iface
;
3082 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*,nsIIDRef
,void**);
3084 static nsrefcnt NSAPI
nsIOService_AddRef(nsIIOService
*iface
)
3089 static nsrefcnt NSAPI
nsIOService_Release(nsIIOService
*iface
)
3094 static nsresult NSAPI
nsIOService_GetProtocolHandler(nsIIOService
*iface
, const char *aScheme
,
3095 nsIProtocolHandler
**_retval
)
3097 nsIExternalProtocolHandler
*nsexthandler
;
3098 nsIProtocolHandler
*nshandler
;
3101 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
3103 nsres
= nsIIOService_GetProtocolHandler(nsio
, aScheme
, &nshandler
);
3104 if(NS_FAILED(nsres
)) {
3105 WARN("GetProtocolHandler failed: %08x\n", nsres
);
3109 nsres
= nsIProtocolHandler_QueryInterface(nshandler
, &IID_nsIExternalProtocolHandler
,
3110 (void**)&nsexthandler
);
3111 if(NS_FAILED(nsres
)) {
3112 *_retval
= nshandler
;
3116 nsIExternalProtocolHandler_Release(nsexthandler
);
3117 *_retval
= create_protocol_handler(nshandler
);
3118 TRACE("return %p\n", *_retval
);
3122 static nsresult NSAPI
nsIOService_GetProtocolFlags(nsIIOService
*iface
, const char *aScheme
,
3125 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
3126 return nsIIOService_GetProtocolFlags(nsio
, aScheme
, _retval
);
3129 static BOOL
is_gecko_special_uri(const char *spec
)
3131 static const char *special_schemes
[] = {"chrome:", "jar:", "moz-safe-about", "resource:", "javascript:", "wyciwyg:"};
3134 for(i
=0; i
< sizeof(special_schemes
)/sizeof(*special_schemes
); i
++) {
3135 if(!strncasecmp(spec
, special_schemes
[i
], strlen(special_schemes
[i
])))
3139 if(!strncasecmp(spec
, "file:", 5)) {
3140 const char *ptr
= spec
+5;
3143 return is_gecko_path(ptr
);
3149 static nsresult NSAPI
nsIOService_NewURI(nsIIOService
*iface
, const nsACString
*aSpec
,
3150 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
3152 nsWineURI
*wine_uri
, *base_wine_uri
= NULL
;
3153 WCHAR new_spec
[INTERNET_MAX_URL_LENGTH
];
3154 HTMLWindow
*window
= NULL
;
3155 const char *spec
= NULL
;
3160 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
3163 nsACString_GetData(aSpec
, &spec
);
3164 if(is_gecko_special_uri(spec
))
3165 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3167 if(!strncmp(spec
, "wine:", 5))
3171 nsres
= nsIURI_QueryInterface(aBaseURI
, &IID_nsWineURI
, (void**)&base_wine_uri
);
3172 if(NS_SUCCEEDED(nsres
)) {
3173 if(!ensure_uri(base_wine_uri
))
3174 return NS_ERROR_UNEXPECTED
;
3175 if(base_wine_uri
->window_ref
)
3176 window
= base_wine_uri
->window_ref
->window
;
3178 WARN("Could not get base nsWineURI: %08x\n", nsres
);
3182 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, new_spec
, sizeof(new_spec
)/sizeof(WCHAR
));
3185 hres
= CoInternetCombineUrlEx(base_wine_uri
->uri
, new_spec
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
3188 WARN("CoInternetCombineUrlEx failed: %08x\n", hres
);
3190 hres
= CreateUri(new_spec
, 0, 0, &urlmon_uri
);
3192 WARN("CreateUri failed: %08x\n", hres
);
3196 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3198 nsres
= create_nsuri(urlmon_uri
, window
, NULL
, &wine_uri
);
3199 IUri_Release(urlmon_uri
);
3201 nsIURI_Release(&base_wine_uri
->nsIURL_iface
);
3202 if(NS_FAILED(nsres
))
3205 *_retval
= (nsIURI
*)&wine_uri
->nsIURL_iface
;
3209 static nsresult NSAPI
nsIOService_NewFileURI(nsIIOService
*iface
, nsIFile
*aFile
,
3212 TRACE("(%p %p)\n", aFile
, _retval
);
3213 return nsIIOService_NewFileURI(nsio
, aFile
, _retval
);
3216 static nsresult NSAPI
nsIOService_NewChannelFromURI(nsIIOService
*iface
, nsIURI
*aURI
,
3217 nsIChannel
**_retval
)
3219 nsWineURI
*wine_uri
;
3223 TRACE("(%p %p)\n", aURI
, _retval
);
3225 nsres
= nsIURI_QueryInterface(aURI
, &IID_nsWineURI
, (void**)&wine_uri
);
3226 if(NS_FAILED(nsres
)) {
3227 TRACE("Could not get nsWineURI: %08x\n", nsres
);
3228 return nsIIOService_NewChannelFromURI(nsio
, aURI
, _retval
);
3231 nsres
= create_nschannel(wine_uri
, &ret
);
3232 nsIURL_Release(&wine_uri
->nsIURL_iface
);
3233 if(NS_FAILED(nsres
))
3236 nsIURI_AddRef(aURI
);
3237 ret
->original_uri
= aURI
;
3239 *_retval
= (nsIChannel
*)&ret
->nsIHttpChannel_iface
;
3243 static nsresult NSAPI
nsIOService_NewChannel(nsIIOService
*iface
, const nsACString
*aSpec
,
3244 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIChannel
**_retval
)
3246 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
), aBaseURI
, _retval
);
3247 return nsIIOService_NewChannel(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3250 static nsresult NSAPI
nsIOService_GetOffline(nsIIOService
*iface
, PRBool
*aOffline
)
3252 TRACE("(%p)\n", aOffline
);
3253 return nsIIOService_GetOffline(nsio
, aOffline
);
3256 static nsresult NSAPI
nsIOService_SetOffline(nsIIOService
*iface
, PRBool aOffline
)
3258 TRACE("(%x)\n", aOffline
);
3259 return nsIIOService_SetOffline(nsio
, aOffline
);
3262 static nsresult NSAPI
nsIOService_AllowPort(nsIIOService
*iface
, PRInt32 aPort
,
3263 const char *aScheme
, PRBool
*_retval
)
3265 TRACE("(%d %s %p)\n", aPort
, debugstr_a(aScheme
), _retval
);
3266 return nsIIOService_AllowPort(nsio
, aPort
, debugstr_a(aScheme
), _retval
);
3269 static nsresult NSAPI
nsIOService_ExtractScheme(nsIIOService
*iface
, const nsACString
*urlString
,
3270 nsACString
* _retval
)
3272 TRACE("(%s %p)\n", debugstr_nsacstr(urlString
), _retval
);
3273 return nsIIOService_ExtractScheme(nsio
, urlString
, _retval
);
3276 static const nsIIOServiceVtbl nsIOServiceVtbl
= {
3277 nsIOService_QueryInterface
,
3279 nsIOService_Release
,
3280 nsIOService_GetProtocolHandler
,
3281 nsIOService_GetProtocolFlags
,
3283 nsIOService_NewFileURI
,
3284 nsIOService_NewChannelFromURI
,
3285 nsIOService_NewChannel
,
3286 nsIOService_GetOffline
,
3287 nsIOService_SetOffline
,
3288 nsIOService_AllowPort
,
3289 nsIOService_ExtractScheme
3292 static nsIIOService nsIOService
= { &nsIOServiceVtbl
};
3294 static nsresult NSAPI
nsNetUtil_QueryInterface(nsINetUtil
*iface
, nsIIDRef riid
,
3297 return nsIIOService_QueryInterface(&nsIOService
, riid
, result
);
3300 static nsrefcnt NSAPI
nsNetUtil_AddRef(nsINetUtil
*iface
)
3305 static nsrefcnt NSAPI
nsNetUtil_Release(nsINetUtil
*iface
)
3310 static nsresult NSAPI
nsNetUtil_ParseContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
3311 nsACString
*aCharset
, PRBool
*aHadCharset
, nsACString
*aContentType
)
3313 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aHadCharset
, aContentType
);
3315 return nsINetUtil_ParseContentType(net_util
, aTypeHeader
, aCharset
, aHadCharset
, aContentType
);
3318 static nsresult NSAPI
nsNetUtil_ProtocolHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, PRUint32 aFlags
, PRBool
*_retval
)
3322 return nsINetUtil_ProtocolHasFlags(net_util
, aURI
, aFlags
, _retval
);
3325 static nsresult NSAPI
nsNetUtil_URIChainHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, PRUint32 aFlags
, PRBool
*_retval
)
3327 TRACE("(%p %08x %p)\n", aURI
, aFlags
, _retval
);
3329 if(aFlags
== (1<<11)) {
3334 return nsINetUtil_URIChainHasFlags(net_util
, aURI
, aFlags
, _retval
);
3337 static nsresult NSAPI
nsNetUtil_ToImmutableURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
3339 TRACE("(%p %p)\n", aURI
, _retval
);
3341 return nsINetUtil_ToImmutableURI(net_util
, aURI
, _retval
);
3344 static nsresult NSAPI
nsNetUtil_NewSimpleNestedURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
3346 TRACE("(%p %p)\n", aURI
, _retval
);
3348 return nsINetUtil_NewSimpleNestedURI(net_util
, aURI
, _retval
);
3351 static nsresult NSAPI
nsNetUtil_EscapeString(nsINetUtil
*iface
, const nsACString
*aString
,
3352 PRUint32 aEscapeType
, nsACString
*_retval
)
3354 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString
), aEscapeType
, _retval
);
3356 return nsINetUtil_EscapeString(net_util
, aString
, aEscapeType
, _retval
);
3359 static nsresult NSAPI
nsNetUtil_EscapeURL(nsINetUtil
*iface
, const nsACString
*aStr
, PRUint32 aFlags
,
3360 nsACString
*_retval
)
3362 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
3364 return nsINetUtil_EscapeURL(net_util
, aStr
, aFlags
, _retval
);
3367 static nsresult NSAPI
nsNetUtil_UnescapeString(nsINetUtil
*iface
, const nsACString
*aStr
,
3368 PRUint32 aFlags
, nsACString
*_retval
)
3370 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
3372 return nsINetUtil_UnescapeString(net_util
, aStr
, aFlags
, _retval
);
3375 static nsresult NSAPI
nsNetUtil_ExtractCharsetFromContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
3376 nsACString
*aCharset
, PRInt32
*aCharsetStart
, PRInt32
*aCharsetEnd
, PRBool
*_retval
)
3378 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aCharsetStart
,
3379 aCharsetEnd
, _retval
);
3381 return nsINetUtil_ExtractCharsetFromContentType(net_util
, aTypeHeader
, aCharset
, aCharsetStart
, aCharsetEnd
, _retval
);
3384 static const nsINetUtilVtbl nsNetUtilVtbl
= {
3385 nsNetUtil_QueryInterface
,
3388 nsNetUtil_ParseContentType
,
3389 nsNetUtil_ProtocolHasFlags
,
3390 nsNetUtil_URIChainHasFlags
,
3391 nsNetUtil_ToImmutableURI
,
3392 nsNetUtil_NewSimpleNestedURI
,
3393 nsNetUtil_EscapeString
,
3394 nsNetUtil_EscapeURL
,
3395 nsNetUtil_UnescapeString
,
3396 nsNetUtil_ExtractCharsetFromContentType
3399 static nsINetUtil nsNetUtil
= { &nsNetUtilVtbl
};
3401 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*iface
, nsIIDRef riid
,
3406 if(IsEqualGUID(&IID_nsISupports
, riid
))
3407 *result
= &nsIOService
;
3408 else if(IsEqualGUID(&IID_nsIIOService
, riid
))
3409 *result
= &nsIOService
;
3410 else if(IsEqualGUID(&IID_nsINetUtil
, riid
))
3411 *result
= &nsNetUtil
;
3414 nsISupports_AddRef((nsISupports
*)*result
);
3418 FIXME("(%s %p)\n", debugstr_guid(riid
), result
);
3419 return NS_NOINTERFACE
;
3422 static nsresult NSAPI
nsIOServiceFactory_QueryInterface(nsIFactory
*iface
, nsIIDRef riid
,
3427 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
3428 TRACE("(IID_nsISupports %p)\n", result
);
3430 }else if(IsEqualGUID(&IID_nsIFactory
, riid
)) {
3431 TRACE("(IID_nsIFactory %p)\n", result
);
3436 nsIFactory_AddRef(iface
);
3440 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
3441 return NS_NOINTERFACE
;
3444 static nsrefcnt NSAPI
nsIOServiceFactory_AddRef(nsIFactory
*iface
)
3449 static nsrefcnt NSAPI
nsIOServiceFactory_Release(nsIFactory
*iface
)
3454 static nsresult NSAPI
nsIOServiceFactory_CreateInstance(nsIFactory
*iface
,
3455 nsISupports
*aOuter
, const nsIID
*iid
, void **result
)
3457 return nsIIOService_QueryInterface(&nsIOService
, iid
, result
);
3460 static nsresult NSAPI
nsIOServiceFactory_LockFactory(nsIFactory
*iface
, PRBool lock
)
3462 WARN("(%x)\n", lock
);
3466 static const nsIFactoryVtbl nsIOServiceFactoryVtbl
= {
3467 nsIOServiceFactory_QueryInterface
,
3468 nsIOServiceFactory_AddRef
,
3469 nsIOServiceFactory_Release
,
3470 nsIOServiceFactory_CreateInstance
,
3471 nsIOServiceFactory_LockFactory
3474 static nsIFactory nsIOServiceFactory
= { &nsIOServiceFactoryVtbl
};
3476 static BOOL
translate_url(HTMLDocumentObj
*doc
, nsWineURI
*uri
)
3478 OLECHAR
*new_url
= NULL
;
3483 if(!doc
->hostui
|| !ensure_uri(uri
))
3486 hres
= IUri_GetDisplayUri(uri
->uri
, &url
);
3490 hres
= IDocHostUIHandler_TranslateUrl(doc
->hostui
, 0, url
, &new_url
);
3491 if(hres
== S_OK
&& new_url
) {
3492 if(strcmpW(url
, new_url
)) {
3493 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url
), debugstr_w(new_url
));
3496 CoTaskMemFree(new_url
);
3503 nsresult
on_start_uri_open(NSContainer
*nscontainer
, nsIURI
*uri
, PRBool
*_retval
)
3505 nsWineURI
*wine_uri
;
3510 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
3511 if(NS_FAILED(nsres
)) {
3512 WARN("Could not get nsWineURI: %08x\n", nsres
);
3513 return NS_ERROR_NOT_IMPLEMENTED
;
3516 if(!wine_uri
->is_doc_uri
) {
3517 wine_uri
->is_doc_uri
= TRUE
;
3519 if(!wine_uri
->container
) {
3520 nsIWebBrowserChrome_AddRef(&nscontainer
->nsIWebBrowserChrome_iface
);
3521 wine_uri
->container
= nscontainer
;
3524 if(nscontainer
->doc
)
3525 *_retval
= translate_url(nscontainer
->doc
, wine_uri
);
3528 nsIURI_Release(&wine_uri
->nsIURL_iface
);
3532 void init_nsio(nsIComponentManager
*component_manager
, nsIComponentRegistrar
*registrar
)
3534 nsIFactory
*old_factory
= NULL
;
3537 nsres
= nsIComponentManager_GetClassObject(component_manager
, &NS_IOSERVICE_CID
,
3538 &IID_nsIFactory
, (void**)&old_factory
);
3539 if(NS_FAILED(nsres
)) {
3540 ERR("Could not get factory: %08x\n", nsres
);
3544 nsres
= nsIFactory_CreateInstance(old_factory
, NULL
, &IID_nsIIOService
, (void**)&nsio
);
3545 if(NS_FAILED(nsres
)) {
3546 ERR("Couldn not create nsIOService instance %08x\n", nsres
);
3547 nsIFactory_Release(old_factory
);
3551 nsres
= nsIIOService_QueryInterface(nsio
, &IID_nsINetUtil
, (void**)&net_util
);
3552 if(NS_FAILED(nsres
)) {
3553 WARN("Could not get nsINetUtil interface: %08x\n", nsres
);
3554 nsIIOService_Release(nsio
);
3558 nsres
= nsIComponentRegistrar_UnregisterFactory(registrar
, &NS_IOSERVICE_CID
, old_factory
);
3559 nsIFactory_Release(old_factory
);
3560 if(NS_FAILED(nsres
))
3561 ERR("UnregisterFactory failed: %08x\n", nsres
);
3563 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_IOSERVICE_CID
,
3564 NS_IOSERVICE_CLASSNAME
, NS_IOSERVICE_CONTRACTID
, &nsIOServiceFactory
);
3565 if(NS_FAILED(nsres
))
3566 ERR("RegisterFactory failed: %08x\n", nsres
);
3569 void release_nsio(void)
3572 nsINetUtil_Release(net_util
);
3577 nsIIOService_Release(nsio
);