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"};
56 nsIFileURL nsIFileURL_iface
; /* For non-file URL objects, it's just nsIURL */
57 nsIStandardURL nsIStandardURL_iface
;
61 NSContainer
*container
;
62 windowref_t
*window_ref
;
63 nsChannelBSC
*channel_bsc
;
65 IUriBuilder
*uri_builder
;
72 static BOOL
ensure_uri(nsWineURI
*This
)
76 assert(This
->uri
|| This
->uri_builder
);
79 hres
= IUriBuilder_CreateUriSimple(This
->uri_builder
, 0, 0, &This
->uri
);
81 WARN("CreateUriSimple failed: %08x\n", hres
);
89 IUri
*nsuri_get_uri(nsWineURI
*nsuri
)
91 if(!ensure_uri(nsuri
))
94 IUri_AddRef(nsuri
->uri
);
98 IUri
*get_uri_nofrag(IUri
*uri
)
100 IUriBuilder
*uri_builder
;
105 hres
= IUri_HasProperty(uri
, Uri_PROPERTY_FRAGMENT
, &b
);
106 if(SUCCEEDED(hres
) && !b
) {
111 hres
= CreateIUriBuilder(uri
, 0, 0, &uri_builder
);
115 hres
= IUriBuilder_RemoveProperties(uri_builder
, Uri_HAS_FRAGMENT
);
117 hres
= IUriBuilder_CreateUriSimple(uri_builder
, 0, 0, &ret
);
118 IUriBuilder_Release(uri_builder
);
125 static BOOL
compare_ignoring_frag(IUri
*uri1
, IUri
*uri2
)
127 IUri
*uri_nofrag1
, *uri_nofrag2
;
130 uri_nofrag1
= get_uri_nofrag(uri1
);
134 uri_nofrag2
= get_uri_nofrag(uri2
);
136 IUri_IsEqual(uri_nofrag1
, uri_nofrag2
, &ret
);
137 IUri_Release(uri_nofrag2
);
140 IUri_Release(uri_nofrag1
);
144 static HRESULT
combine_url(IUri
*base_uri
, const WCHAR
*rel_url
, IUri
**ret
)
149 uri_nofrag
= get_uri_nofrag(base_uri
);
153 hres
= CoInternetCombineUrlEx(uri_nofrag
, rel_url
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
155 IUri_Release(uri_nofrag
);
157 WARN("CoInternetCombineUrlEx failed: %08x\n", hres
);
161 static nsresult
create_nsuri(IUri
*,HTMLOuterWindow
*,NSContainer
*,const char*,nsWineURI
**);
163 static const char *debugstr_nsacstr(const nsACString
*nsstr
)
167 nsACString_GetData(nsstr
, &data
);
168 return debugstr_a(data
);
171 static nsresult
return_wstr_nsacstr(nsACString
*ret_str
, const WCHAR
*str
, int len
)
176 TRACE("returning %s\n", debugstr_wn(str
, len
));
179 nsACString_SetData(ret_str
, "");
183 lena
= WideCharToMultiByte(CP_UTF8
, 0, str
, len
, NULL
, 0, NULL
, NULL
);
184 stra
= heap_alloc(lena
+1);
186 return NS_ERROR_OUT_OF_MEMORY
;
188 WideCharToMultiByte(CP_UTF8
, 0, str
, len
, stra
, lena
, NULL
, NULL
);
191 nsACString_SetData(ret_str
, stra
);
196 HRESULT
nsuri_to_url(LPCWSTR nsuri
, BOOL ret_empty
, BSTR
*ret
)
198 const WCHAR
*ptr
= nsuri
;
200 static const WCHAR wine_prefixW
[] = {'w','i','n','e',':'};
202 if(!strncmpW(nsuri
, wine_prefixW
, sizeof(wine_prefixW
)/sizeof(WCHAR
)))
203 ptr
+= sizeof(wine_prefixW
)/sizeof(WCHAR
);
205 if(*ptr
|| ret_empty
) {
206 *ret
= SysAllocString(ptr
);
208 return E_OUTOFMEMORY
;
213 TRACE("%s -> %s\n", debugstr_w(nsuri
), debugstr_w(*ret
));
217 static BOOL
exec_shldocvw_67(HTMLDocumentObj
*doc
, BSTR url
)
219 IOleCommandTarget
*cmdtrg
= NULL
;
222 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
223 if(SUCCEEDED(hres
)) {
224 VARIANT varUrl
, varRes
;
226 V_VT(&varUrl
) = VT_BSTR
;
227 V_BSTR(&varUrl
) = url
;
228 V_VT(&varRes
) = VT_BOOL
;
230 hres
= IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 67, 0, &varUrl
, &varRes
);
232 IOleCommandTarget_Release(cmdtrg
);
234 if(SUCCEEDED(hres
) && !V_BOOL(&varRes
)) {
235 TRACE("got VARIANT_FALSE, do not load\n");
243 static nsresult
before_async_open(nsChannel
*channel
, NSContainer
*container
, BOOL
*cancel
)
245 HTMLDocumentObj
*doc
= container
->doc
;
254 hres
= IUri_GetDisplayUri(channel
->uri
->uri
, &display_uri
);
256 return NS_ERROR_FAILURE
;
258 if(!exec_shldocvw_67(doc
, display_uri
)) {
259 SysFreeString(display_uri
);
264 hres
= hlink_frame_navigate(&doc
->basedoc
, display_uri
, channel
, 0, cancel
);
265 SysFreeString(display_uri
);
271 HRESULT
load_nsuri(HTMLOuterWindow
*window
, nsWineURI
*uri
, nsIInputStream
*post_stream
,
272 nsChannelBSC
*channelbsc
, DWORD flags
)
274 nsIDocShellLoadInfo
*load_info
= NULL
;
275 nsIWebNavigation
*web_navigation
;
276 nsIDocShell
*doc_shell
;
277 HTMLDocumentNode
*doc
;
280 nsres
= get_nsinterface((nsISupports
*)window
->nswindow
, &IID_nsIWebNavigation
, (void**)&web_navigation
);
281 if(NS_FAILED(nsres
)) {
282 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
286 nsres
= nsIWebNavigation_QueryInterface(web_navigation
, &IID_nsIDocShell
, (void**)&doc_shell
);
287 nsIWebNavigation_Release(web_navigation
);
288 if(NS_FAILED(nsres
)) {
289 ERR("Could not get nsIDocShell: %08x\n", nsres
);
294 nsres
= nsIDocShell_CreateLoadInfo(doc_shell
, &load_info
);
295 if(NS_FAILED(nsres
)) {
296 nsIDocShell_Release(doc_shell
);
300 nsres
= nsIDocShellLoadInfo_SetPostDataStream(load_info
, post_stream
);
301 assert(nsres
== NS_OK
);
304 uri
->channel_bsc
= channelbsc
;
305 doc
= window
->base
.inner_window
->doc
;
306 doc
->skip_mutation_notif
= TRUE
;
307 nsres
= nsIDocShell_LoadURI(doc_shell
, (nsIURI
*)&uri
->nsIFileURL_iface
, load_info
, flags
, FALSE
);
308 if(doc
== window
->base
.inner_window
->doc
)
309 doc
->skip_mutation_notif
= FALSE
;
310 uri
->channel_bsc
= NULL
;
311 nsIDocShell_Release(doc_shell
);
313 nsIDocShellLoadInfo_Release(load_info
);
314 if(NS_FAILED(nsres
)) {
315 WARN("LoadURI failed: %08x\n", nsres
);
322 static void set_uri_nscontainer(nsWineURI
*This
, NSContainer
*nscontainer
)
324 if(This
->container
) {
325 if(This
->container
== nscontainer
)
327 TRACE("Changing %p -> %p\n", This
->container
, nscontainer
);
328 nsIWebBrowserChrome_Release(&This
->container
->nsIWebBrowserChrome_iface
);
332 nsIWebBrowserChrome_AddRef(&nscontainer
->nsIWebBrowserChrome_iface
);
333 This
->container
= nscontainer
;
336 static void set_uri_window(nsWineURI
*This
, HTMLOuterWindow
*window
)
338 if(This
->window_ref
) {
339 if(This
->window_ref
->window
== window
)
341 TRACE("Changing %p -> %p\n", This
->window_ref
->window
, window
);
342 windowref_release(This
->window_ref
);
346 windowref_addref(window
->window_ref
);
347 This
->window_ref
= window
->window_ref
;
350 set_uri_nscontainer(This
, window
->doc_obj
->nscontainer
);
352 This
->window_ref
= NULL
;
356 static inline BOOL
is_http_channel(nsChannel
*This
)
358 return This
->uri
->scheme
== URL_SCHEME_HTTP
|| This
->uri
->scheme
== URL_SCHEME_HTTPS
;
361 static http_header_t
*find_http_header(struct list
*headers
, const WCHAR
*name
, int len
)
365 LIST_FOR_EACH_ENTRY(iter
, headers
, http_header_t
, entry
) {
366 if(!strcmpiW(iter
->header
, name
))
373 static nsresult
get_channel_http_header(struct list
*headers
, const nsACString
*header_name_str
,
376 const char *header_namea
;
377 http_header_t
*header
;
381 nsACString_GetData(header_name_str
, &header_namea
);
382 header_name
= heap_strdupAtoW(header_namea
);
384 return NS_ERROR_UNEXPECTED
;
386 header
= find_http_header(headers
, header_name
, strlenW(header_name
));
387 heap_free(header_name
);
389 return NS_ERROR_NOT_AVAILABLE
;
391 data
= heap_strdupWtoA(header
->data
);
393 return NS_ERROR_UNEXPECTED
;
395 TRACE("%s -> %s\n", debugstr_a(header_namea
), debugstr_a(data
));
396 nsACString_SetData(_retval
, data
);
401 HRESULT
set_http_header(struct list
*headers
, const WCHAR
*name
, int name_len
,
402 const WCHAR
*value
, int value_len
)
404 http_header_t
*header
;
406 TRACE("%s: %s\n", debugstr_wn(name
, name_len
), debugstr_wn(value
, value_len
));
408 header
= find_http_header(headers
, name
, name_len
);
412 new_data
= heap_strndupW(value
, value_len
);
414 return E_OUTOFMEMORY
;
416 heap_free(header
->data
);
417 header
->data
= new_data
;
419 header
= heap_alloc(sizeof(http_header_t
));
421 return E_OUTOFMEMORY
;
423 header
->header
= heap_strndupW(name
, name_len
);
424 header
->data
= heap_strndupW(value
, value_len
);
425 if(!header
->header
|| !header
->data
) {
426 heap_free(header
->header
);
427 heap_free(header
->data
);
429 return E_OUTOFMEMORY
;
432 list_add_tail(headers
, &header
->entry
);
438 static nsresult
set_channel_http_header(struct list
*headers
, const nsACString
*name_str
,
439 const nsACString
*value_str
)
441 const char *namea
, *valuea
;
445 nsACString_GetData(name_str
, &namea
);
446 name
= heap_strdupAtoW(namea
);
448 return NS_ERROR_UNEXPECTED
;
450 nsACString_GetData(value_str
, &valuea
);
451 value
= heap_strdupAtoW(valuea
);
454 return NS_ERROR_UNEXPECTED
;
457 hres
= set_http_header(headers
, name
, strlenW(name
), value
, strlenW(value
));
461 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_UNEXPECTED
;
464 static nsresult
visit_http_headers(struct list
*headers
, nsIHttpHeaderVisitor
*visitor
)
466 nsACString header_str
, value_str
;
467 char *header
, *value
;
471 LIST_FOR_EACH_ENTRY(iter
, headers
, http_header_t
, entry
) {
472 header
= heap_strdupWtoA(iter
->header
);
474 return NS_ERROR_OUT_OF_MEMORY
;
476 value
= heap_strdupWtoA(iter
->data
);
479 return NS_ERROR_OUT_OF_MEMORY
;
482 nsACString_InitDepend(&header_str
, header
);
483 nsACString_InitDepend(&value_str
, value
);
484 nsres
= nsIHttpHeaderVisitor_VisitHeader(visitor
, &header_str
, &value_str
);
485 nsACString_Finish(&header_str
);
486 nsACString_Finish(&value_str
);
496 static void free_http_headers(struct list
*list
)
498 http_header_t
*iter
, *iter_next
;
500 LIST_FOR_EACH_ENTRY_SAFE(iter
, iter_next
, list
, http_header_t
, entry
) {
501 list_remove(&iter
->entry
);
502 heap_free(iter
->header
);
503 heap_free(iter
->data
);
508 static inline nsChannel
*impl_from_nsIHttpChannel(nsIHttpChannel
*iface
)
510 return CONTAINING_RECORD(iface
, nsChannel
, nsIHttpChannel_iface
);
513 static nsresult NSAPI
nsChannel_QueryInterface(nsIHttpChannel
*iface
, nsIIDRef riid
, void **result
)
515 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
517 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
518 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
519 *result
= &This
->nsIHttpChannel_iface
;
520 }else if(IsEqualGUID(&IID_nsIRequest
, riid
)) {
521 TRACE("(%p)->(IID_nsIRequest %p)\n", This
, result
);
522 *result
= &This
->nsIHttpChannel_iface
;
523 }else if(IsEqualGUID(&IID_nsIChannel
, riid
)) {
524 TRACE("(%p)->(IID_nsIChannel %p)\n", This
, result
);
525 *result
= &This
->nsIHttpChannel_iface
;
526 }else if(IsEqualGUID(&IID_nsIHttpChannel
, riid
)) {
527 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This
, result
);
528 *result
= is_http_channel(This
) ? &This
->nsIHttpChannel_iface
: NULL
;
529 }else if(IsEqualGUID(&IID_nsIUploadChannel
, riid
)) {
530 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This
, result
);
531 *result
= &This
->nsIUploadChannel_iface
;
532 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal
, riid
)) {
533 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This
, result
);
534 *result
= is_http_channel(This
) ? &This
->nsIHttpChannelInternal_iface
: NULL
;
536 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
541 nsIHttpChannel_AddRef(&This
->nsIHttpChannel_iface
);
545 return NS_NOINTERFACE
;
548 static nsrefcnt NSAPI
nsChannel_AddRef(nsIHttpChannel
*iface
)
550 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
551 nsrefcnt ref
= InterlockedIncrement(&This
->ref
);
553 TRACE("(%p) ref=%d\n", This
, ref
);
558 static nsrefcnt NSAPI
nsChannel_Release(nsIHttpChannel
*iface
)
560 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
561 LONG ref
= InterlockedDecrement(&This
->ref
);
564 nsIFileURL_Release(&This
->uri
->nsIFileURL_iface
);
566 nsISupports_Release(This
->owner
);
567 if(This
->post_data_stream
)
568 nsIInputStream_Release(This
->post_data_stream
);
570 nsILoadGroup_Release(This
->load_group
);
571 if(This
->notif_callback
)
572 nsIInterfaceRequestor_Release(This
->notif_callback
);
573 if(This
->original_uri
)
574 nsIURI_Release(This
->original_uri
);
576 nsIURI_Release(This
->referrer
);
578 free_http_headers(&This
->response_headers
);
579 free_http_headers(&This
->request_headers
);
581 heap_free(This
->content_type
);
582 heap_free(This
->charset
);
589 static nsresult NSAPI
nsChannel_GetName(nsIHttpChannel
*iface
, nsACString
*aName
)
591 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
593 TRACE("(%p)->(%p)\n", This
, aName
);
595 return nsIFileURL_GetSpec(&This
->uri
->nsIFileURL_iface
, aName
);
598 static nsresult NSAPI
nsChannel_IsPending(nsIHttpChannel
*iface
, cpp_bool
*_retval
)
600 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
602 FIXME("(%p)->(%p)\n", This
, _retval
);
604 return NS_ERROR_NOT_IMPLEMENTED
;
607 static nsresult NSAPI
nsChannel_GetStatus(nsIHttpChannel
*iface
, nsresult
*aStatus
)
609 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
611 WARN("(%p)->(%p) returning NS_OK\n", This
, aStatus
);
613 return *aStatus
= NS_OK
;
616 static nsresult NSAPI
nsChannel_Cancel(nsIHttpChannel
*iface
, nsresult aStatus
)
618 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
620 FIXME("(%p)->(%08x)\n", This
, aStatus
);
622 return NS_ERROR_NOT_IMPLEMENTED
;
625 static nsresult NSAPI
nsChannel_Suspend(nsIHttpChannel
*iface
)
627 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
629 FIXME("(%p)\n", This
);
631 return NS_ERROR_NOT_IMPLEMENTED
;
634 static nsresult NSAPI
nsChannel_Resume(nsIHttpChannel
*iface
)
636 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
638 FIXME("(%p)\n", This
);
640 return NS_ERROR_NOT_IMPLEMENTED
;
643 static nsresult NSAPI
nsChannel_GetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
**aLoadGroup
)
645 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
647 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
650 nsILoadGroup_AddRef(This
->load_group
);
652 *aLoadGroup
= This
->load_group
;
656 static nsresult NSAPI
nsChannel_SetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
*aLoadGroup
)
658 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
660 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
663 nsILoadGroup_Release(This
->load_group
);
665 nsILoadGroup_AddRef(aLoadGroup
);
666 This
->load_group
= aLoadGroup
;
671 static nsresult NSAPI
nsChannel_GetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags
*aLoadFlags
)
673 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
675 TRACE("(%p)->(%p)\n", This
, aLoadFlags
);
677 *aLoadFlags
= This
->load_flags
;
681 static nsresult NSAPI
nsChannel_SetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags aLoadFlags
)
683 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
685 TRACE("(%p)->(%08x)\n", This
, aLoadFlags
);
687 This
->load_flags
= aLoadFlags
;
691 static nsresult NSAPI
nsChannel_GetOriginalURI(nsIHttpChannel
*iface
, nsIURI
**aOriginalURI
)
693 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
695 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
697 if(This
->original_uri
)
698 nsIURI_AddRef(This
->original_uri
);
700 *aOriginalURI
= This
->original_uri
;
704 static nsresult NSAPI
nsChannel_SetOriginalURI(nsIHttpChannel
*iface
, nsIURI
*aOriginalURI
)
706 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
708 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
710 if(This
->original_uri
)
711 nsIURI_Release(This
->original_uri
);
713 nsIURI_AddRef(aOriginalURI
);
714 This
->original_uri
= aOriginalURI
;
718 static nsresult NSAPI
nsChannel_GetURI(nsIHttpChannel
*iface
, nsIURI
**aURI
)
720 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
722 TRACE("(%p)->(%p)\n", This
, aURI
);
724 nsIFileURL_AddRef(&This
->uri
->nsIFileURL_iface
);
725 *aURI
= (nsIURI
*)This
->uri
;
730 static nsresult NSAPI
nsChannel_GetOwner(nsIHttpChannel
*iface
, nsISupports
**aOwner
)
732 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
734 TRACE("(%p)->(%p)\n", This
, aOwner
);
737 nsISupports_AddRef(This
->owner
);
738 *aOwner
= This
->owner
;
743 static nsresult NSAPI
nsChannel_SetOwner(nsIHttpChannel
*iface
, nsISupports
*aOwner
)
745 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
747 TRACE("(%p)->(%p)\n", This
, aOwner
);
750 nsISupports_AddRef(aOwner
);
752 nsISupports_Release(This
->owner
);
753 This
->owner
= aOwner
;
758 static nsresult NSAPI
nsChannel_GetNotificationCallbacks(nsIHttpChannel
*iface
,
759 nsIInterfaceRequestor
**aNotificationCallbacks
)
761 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
763 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
765 if(This
->notif_callback
)
766 nsIInterfaceRequestor_AddRef(This
->notif_callback
);
767 *aNotificationCallbacks
= This
->notif_callback
;
772 static nsresult NSAPI
nsChannel_SetNotificationCallbacks(nsIHttpChannel
*iface
,
773 nsIInterfaceRequestor
*aNotificationCallbacks
)
775 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
777 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
779 if(This
->notif_callback
)
780 nsIInterfaceRequestor_Release(This
->notif_callback
);
781 if(aNotificationCallbacks
)
782 nsIInterfaceRequestor_AddRef(aNotificationCallbacks
);
784 This
->notif_callback
= aNotificationCallbacks
;
789 static nsresult NSAPI
nsChannel_GetSecurityInfo(nsIHttpChannel
*iface
, nsISupports
**aSecurityInfo
)
791 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
793 TRACE("(%p)->(%p)\n", This
, aSecurityInfo
);
795 return NS_ERROR_NOT_IMPLEMENTED
;
798 static nsresult NSAPI
nsChannel_GetContentType(nsIHttpChannel
*iface
, nsACString
*aContentType
)
800 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
802 TRACE("(%p)->(%p)\n", This
, aContentType
);
804 if(This
->content_type
) {
805 nsACString_SetData(aContentType
, This
->content_type
);
809 if(This
->uri
->is_doc_uri
) {
810 WARN("Document channel with no MIME set. Assuming text/html\n");
811 nsACString_SetData(aContentType
, "text/html");
815 WARN("unknown type\n");
816 return NS_ERROR_FAILURE
;
819 static nsresult NSAPI
nsChannel_SetContentType(nsIHttpChannel
*iface
,
820 const nsACString
*aContentType
)
822 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
823 const char *content_type
;
825 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentType
));
827 nsACString_GetData(aContentType
, &content_type
);
828 heap_free(This
->content_type
);
829 This
->content_type
= heap_strdupA(content_type
);
834 static nsresult NSAPI
nsChannel_GetContentCharset(nsIHttpChannel
*iface
,
835 nsACString
*aContentCharset
)
837 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
839 TRACE("(%p)->(%p)\n", This
, aContentCharset
);
842 nsACString_SetData(aContentCharset
, This
->charset
);
846 nsACString_SetData(aContentCharset
, "");
850 static nsresult NSAPI
nsChannel_SetContentCharset(nsIHttpChannel
*iface
,
851 const nsACString
*aContentCharset
)
853 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
857 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentCharset
));
859 nsACString_GetData(aContentCharset
, &data
);
860 charset
= heap_strdupA(data
);
862 return NS_ERROR_OUT_OF_MEMORY
;
864 heap_free(This
->charset
);
865 This
->charset
= charset
;
869 static nsresult NSAPI
nsChannel_GetContentLength(nsIHttpChannel
*iface
, INT64
*aContentLength
)
871 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
873 FIXME("(%p)->(%p)\n", This
, aContentLength
);
875 return NS_ERROR_NOT_IMPLEMENTED
;
878 static nsresult NSAPI
nsChannel_SetContentLength(nsIHttpChannel
*iface
, INT64 aContentLength
)
880 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
882 FIXME("(%p)->(%s)\n", This
, wine_dbgstr_longlong(aContentLength
));
884 return NS_ERROR_NOT_IMPLEMENTED
;
887 static nsresult NSAPI
nsChannel_Open(nsIHttpChannel
*iface
, nsIInputStream
**_retval
)
889 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
891 FIXME("(%p)->(%p)\n", This
, _retval
);
893 return NS_ERROR_NOT_IMPLEMENTED
;
896 static HTMLOuterWindow
*get_window_from_load_group(nsChannel
*This
)
898 HTMLOuterWindow
*window
;
905 nsres
= nsILoadGroup_GetDefaultLoadRequest(This
->load_group
, &req
);
906 if(NS_FAILED(nsres
)) {
907 ERR("GetDefaultLoadRequest failed: %08x\n", nsres
);
914 nsres
= nsIRequest_QueryInterface(req
, &IID_nsIChannel
, (void**)&channel
);
915 nsIRequest_Release(req
);
916 if(NS_FAILED(nsres
)) {
917 WARN("Could not get nsIChannel interface: %08x\n", nsres
);
921 nsres
= nsIChannel_GetURI(channel
, &uri
);
922 nsIChannel_Release(channel
);
923 if(NS_FAILED(nsres
)) {
924 ERR("GetURI failed: %08x\n", nsres
);
928 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
930 if(NS_FAILED(nsres
)) {
931 TRACE("Could not get nsWineURI: %08x\n", nsres
);
935 window
= wine_uri
->window_ref
? wine_uri
->window_ref
->window
: NULL
;
937 IHTMLWindow2_AddRef(&window
->base
.IHTMLWindow2_iface
);
938 nsIFileURL_Release(&wine_uri
->nsIFileURL_iface
);
943 static HTMLOuterWindow
*get_channel_window(nsChannel
*This
)
945 nsIWebProgress
*web_progress
;
946 nsIDOMWindow
*nswindow
;
947 HTMLOuterWindow
*window
;
950 if(This
->load_group
) {
951 nsIRequestObserver
*req_observer
;
953 nsres
= nsILoadGroup_GetGroupObserver(This
->load_group
, &req_observer
);
954 if(NS_FAILED(nsres
) || !req_observer
) {
955 ERR("GetGroupObserver failed: %08x\n", nsres
);
959 nsres
= nsIRequestObserver_QueryInterface(req_observer
, &IID_nsIWebProgress
, (void**)&web_progress
);
960 nsIRequestObserver_Release(req_observer
);
961 if(NS_FAILED(nsres
)) {
962 ERR("Could not get nsIWebProgress iface: %08x\n", nsres
);
965 }else if(This
->notif_callback
) {
966 nsres
= nsIInterfaceRequestor_GetInterface(This
->notif_callback
, &IID_nsIWebProgress
, (void**)&web_progress
);
967 if(NS_FAILED(nsres
)) {
968 ERR("GetInterface(IID_nsIWebProgress failed: %08x\n", nsres
);
972 ERR("no load group nor notif callback\n");
976 nsres
= nsIWebProgress_GetDOMWindow(web_progress
, &nswindow
);
977 nsIWebProgress_Release(web_progress
);
978 if(NS_FAILED(nsres
) || !nswindow
) {
979 ERR("GetDOMWindow failed: %08x\n", nsres
);
983 window
= nswindow_to_window(nswindow
);
984 nsIDOMWindow_Release(nswindow
);
987 IHTMLWindow2_AddRef(&window
->base
.IHTMLWindow2_iface
);
989 FIXME("NULL window for %p\n", nswindow
);
995 HTMLInnerWindow
*window
;
996 nsChannelBSC
*bscallback
;
997 } start_binding_task_t
;
999 static void start_binding_proc(task_t
*_task
)
1001 start_binding_task_t
*task
= (start_binding_task_t
*)_task
;
1003 start_binding(task
->window
, (BSCallback
*)task
->bscallback
, NULL
);
1006 static void start_binding_task_destr(task_t
*_task
)
1008 start_binding_task_t
*task
= (start_binding_task_t
*)_task
;
1010 IBindStatusCallback_Release(&task
->bscallback
->bsc
.IBindStatusCallback_iface
);
1014 static nsresult
async_open(nsChannel
*This
, HTMLOuterWindow
*window
, BOOL is_doc_channel
, nsIStreamListener
*listener
,
1015 nsISupports
*context
)
1017 nsChannelBSC
*bscallback
;
1018 IMoniker
*mon
= NULL
;
1021 hres
= CreateURLMonikerEx2(NULL
, This
->uri
->uri
, &mon
, 0);
1023 WARN("CreateURLMoniker failed: %08x\n", hres
);
1024 return NS_ERROR_UNEXPECTED
;
1028 set_current_mon(window
, mon
, BINDING_NAVIGATED
);
1030 hres
= create_channelbsc(mon
, NULL
, NULL
, 0, is_doc_channel
, &bscallback
);
1031 IMoniker_Release(mon
);
1033 return NS_ERROR_UNEXPECTED
;
1035 channelbsc_set_channel(bscallback
, This
, listener
, context
);
1037 if(is_doc_channel
) {
1038 hres
= create_pending_window(window
, bscallback
);
1040 async_start_doc_binding(window
, window
->pending_window
);
1041 IBindStatusCallback_Release(&bscallback
->bsc
.IBindStatusCallback_iface
);
1043 return NS_ERROR_UNEXPECTED
;
1045 start_binding_task_t
*task
;
1047 task
= heap_alloc(sizeof(start_binding_task_t
));
1049 IBindStatusCallback_Release(&bscallback
->bsc
.IBindStatusCallback_iface
);
1050 return NS_ERROR_OUT_OF_MEMORY
;
1053 task
->window
= window
->base
.inner_window
;
1054 task
->bscallback
= bscallback
;
1055 hres
= push_task(&task
->header
, start_binding_proc
, start_binding_task_destr
, window
->base
.inner_window
->task_magic
);
1057 return NS_ERROR_OUT_OF_MEMORY
;
1063 static nsresult NSAPI
nsChannel_AsyncOpen(nsIHttpChannel
*iface
, nsIStreamListener
*aListener
,
1064 nsISupports
*aContext
)
1066 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1067 HTMLOuterWindow
*window
= NULL
;
1068 BOOL cancel
= FALSE
;
1069 nsresult nsres
= NS_OK
;
1071 TRACE("(%p)->(%p %p)\n", This
, aListener
, aContext
);
1073 if(!ensure_uri(This
->uri
))
1074 return NS_ERROR_FAILURE
;
1076 if(TRACE_ON(mshtml
)) {
1080 hres
= IUri_GetDisplayUri(This
->uri
->uri
, &uri_str
);
1081 if(SUCCEEDED(hres
)) {
1082 TRACE("opening %s\n", debugstr_w(uri_str
));
1083 SysFreeString(uri_str
);
1085 WARN("GetDisplayUri failed: %08x\n", hres
);
1089 if(This
->uri
->is_doc_uri
) {
1090 window
= get_channel_window(This
);
1092 set_uri_window(This
->uri
, window
);
1093 }else if(This
->uri
->container
) {
1096 /* nscontainer->doc should be NULL which means navigation to a new window */
1097 if(This
->uri
->container
->doc
)
1098 FIXME("nscontainer->doc = %p\n", This
->uri
->container
->doc
);
1100 nsres
= before_async_open(This
, This
->uri
->container
, &b
);
1101 if(NS_FAILED(nsres
))
1104 FIXME("Navigation not cancelled\n");
1105 return NS_ERROR_UNEXPECTED
;
1110 if(This
->uri
->window_ref
&& This
->uri
->window_ref
->window
) {
1111 window
= This
->uri
->window_ref
->window
;
1112 IHTMLWindow2_AddRef(&window
->base
.IHTMLWindow2_iface
);
1114 /* FIXME: Analyze removing get_window_from_load_group call */
1115 if(This
->load_group
)
1116 window
= get_window_from_load_group(This
);
1118 window
= get_channel_window(This
);
1120 set_uri_window(This
->uri
, window
);
1125 ERR("window = NULL\n");
1126 return NS_ERROR_UNEXPECTED
;
1129 if(This
->uri
->is_doc_uri
&& window
== window
->doc_obj
->basedoc
.window
) {
1130 if(This
->uri
->channel_bsc
) {
1131 channelbsc_set_channel(This
->uri
->channel_bsc
, This
, aListener
, aContext
);
1133 if(window
->doc_obj
->mime
) {
1134 heap_free(This
->content_type
);
1135 This
->content_type
= heap_strdupWtoA(window
->doc_obj
->mime
);
1140 nsres
= before_async_open(This
, window
->doc_obj
->nscontainer
, &cancel
);
1141 if(NS_SUCCEEDED(nsres
) && cancel
) {
1142 TRACE("canceled\n");
1143 nsres
= NS_BINDING_ABORTED
;
1149 nsres
= async_open(This
, window
, This
->uri
->is_doc_uri
, aListener
, aContext
);
1151 if(NS_SUCCEEDED(nsres
) && This
->load_group
) {
1152 nsres
= nsILoadGroup_AddRequest(This
->load_group
, (nsIRequest
*)&This
->nsIHttpChannel_iface
,
1154 if(NS_FAILED(nsres
))
1155 ERR("AddRequest failed: %08x\n", nsres
);
1158 IHTMLWindow2_Release(&window
->base
.IHTMLWindow2_iface
);
1162 static nsresult NSAPI
nsChannel_GetContentDisposition(nsIHttpChannel
*iface
, UINT32
*aContentDisposition
)
1164 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1165 FIXME("(%p)->(%p)\n", This
, aContentDisposition
);
1166 return NS_ERROR_NOT_IMPLEMENTED
;
1169 static nsresult NSAPI
nsChannel_SetContentDisposition(nsIHttpChannel
*iface
, UINT32 aContentDisposition
)
1171 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1172 FIXME("(%p)->(%u)\n", This
, aContentDisposition
);
1173 return NS_ERROR_NOT_IMPLEMENTED
;
1176 static nsresult NSAPI
nsChannel_GetContentDispositionFilename(nsIHttpChannel
*iface
, nsAString
*aContentDispositionFilename
)
1178 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1179 FIXME("(%p)->(%p)\n", This
, aContentDispositionFilename
);
1180 return NS_ERROR_NOT_IMPLEMENTED
;
1183 static nsresult NSAPI
nsChannel_SetContentDispositionFilename(nsIHttpChannel
*iface
, const nsAString
*aContentDispositionFilename
)
1185 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1186 FIXME("(%p)->(%p)\n", This
, aContentDispositionFilename
);
1187 return NS_ERROR_NOT_IMPLEMENTED
;
1190 static nsresult NSAPI
nsChannel_GetContentDispositionHeader(nsIHttpChannel
*iface
, nsACString
*aContentDispositionHeader
)
1192 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1193 FIXME("(%p)->(%p)\n", This
, aContentDispositionHeader
);
1194 return NS_ERROR_NOT_IMPLEMENTED
;
1197 static nsresult NSAPI
nsChannel_GetLoadInfo(nsIHttpChannel
*iface
, nsILoadInfo
**aLoadInfo
)
1199 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1201 TRACE("(%p)->(%p)\n", This
, aLoadInfo
);
1204 nsISupports_AddRef(This
->load_info
);
1205 *aLoadInfo
= This
->load_info
;
1209 static nsresult NSAPI
nsChannel_SetLoadInfo(nsIHttpChannel
*iface
, nsILoadInfo
*aLoadInfo
)
1211 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1213 TRACE("(%p)->(%p)\n", This
, aLoadInfo
);
1216 nsISupports_Release(This
->load_info
);
1217 This
->load_info
= aLoadInfo
;
1219 nsISupports_AddRef(This
->load_info
);
1223 static nsresult NSAPI
nsChannel_GetRequestMethod(nsIHttpChannel
*iface
, nsACString
*aRequestMethod
)
1225 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1227 TRACE("(%p)->(%p)\n", This
, aRequestMethod
);
1229 nsACString_SetData(aRequestMethod
, request_method_strings
[This
->request_method
]);
1233 static nsresult NSAPI
nsChannel_SetRequestMethod(nsIHttpChannel
*iface
,
1234 const nsACString
*aRequestMethod
)
1236 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1240 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRequestMethod
));
1242 nsACString_GetData(aRequestMethod
, &method
);
1243 for(i
=0; i
< sizeof(request_method_strings
)/sizeof(*request_method_strings
); i
++) {
1244 if(!strcasecmp(method
, request_method_strings
[i
])) {
1245 This
->request_method
= i
;
1250 ERR("Invalid method %s\n", debugstr_a(method
));
1251 return NS_ERROR_UNEXPECTED
;
1254 static nsresult NSAPI
nsChannel_GetReferrer(nsIHttpChannel
*iface
, nsIURI
**aReferrer
)
1256 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1258 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1261 nsIURI_AddRef(This
->referrer
);
1262 *aReferrer
= This
->referrer
;
1266 static nsresult NSAPI
nsChannel_SetReferrer(nsIHttpChannel
*iface
, nsIURI
*aReferrer
)
1268 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1270 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1273 nsIURI_AddRef(aReferrer
);
1275 nsIURI_Release(This
->referrer
);
1276 This
->referrer
= aReferrer
;
1280 static nsresult NSAPI
nsChannel_GetReferrerPolicy(nsIHttpChannel
*iface
, UINT32
*aReferrerPolicy
)
1282 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1283 FIXME("(%p)->(%p)\n", This
, aReferrerPolicy
);
1284 return NS_ERROR_NOT_IMPLEMENTED
;
1287 static nsresult NSAPI
nsChannel_SetReferrerWithPolicy(nsIHttpChannel
*iface
, nsIURI
*aReferrer
, UINT32 aReferrerPolicy
)
1289 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1290 FIXME("(%p)->(%p %x)\n", This
, aReferrer
, aReferrerPolicy
);
1291 return NS_ERROR_NOT_IMPLEMENTED
;
1294 static nsresult NSAPI
nsChannel_GetRequestHeader(nsIHttpChannel
*iface
,
1295 const nsACString
*aHeader
, nsACString
*_retval
)
1297 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1299 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aHeader
), _retval
);
1301 return get_channel_http_header(&This
->request_headers
, aHeader
, _retval
);
1304 static nsresult NSAPI
nsChannel_SetRequestHeader(nsIHttpChannel
*iface
,
1305 const nsACString
*aHeader
, const nsACString
*aValue
, cpp_bool aMerge
)
1307 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1309 TRACE("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(aHeader
), debugstr_nsacstr(aValue
), aMerge
);
1312 FIXME("aMerge not supported\n");
1314 return set_channel_http_header(&This
->request_headers
, aHeader
, aValue
);
1317 static nsresult NSAPI
nsChannel_VisitRequestHeaders(nsIHttpChannel
*iface
,
1318 nsIHttpHeaderVisitor
*aVisitor
)
1320 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1322 FIXME("(%p)->(%p)\n", This
, aVisitor
);
1324 return NS_ERROR_NOT_IMPLEMENTED
;
1327 static nsresult NSAPI
nsChannel_GetAllowPipelining(nsIHttpChannel
*iface
, cpp_bool
*aAllowPipelining
)
1329 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1331 FIXME("(%p)->(%p)\n", This
, aAllowPipelining
);
1333 return NS_ERROR_NOT_IMPLEMENTED
;
1336 static nsresult NSAPI
nsChannel_SetAllowPipelining(nsIHttpChannel
*iface
, cpp_bool aAllowPipelining
)
1338 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1340 FIXME("(%p)->(%x)\n", This
, aAllowPipelining
);
1342 return NS_ERROR_NOT_IMPLEMENTED
;
1345 static nsresult NSAPI
nsChannel_GetAllowTLS(nsIHttpChannel
*iface
, cpp_bool
*aAllowTLS
)
1347 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1348 FIXME("(%p)->(%p)\n", This
, aAllowTLS
);
1349 return NS_ERROR_NOT_IMPLEMENTED
;
1352 static nsresult NSAPI
nsChannel_SetAllowTLS(nsIHttpChannel
*iface
, cpp_bool aAllowTLS
)
1354 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1355 FIXME("(%p)->(%x)\n", This
, aAllowTLS
);
1356 return NS_ERROR_NOT_IMPLEMENTED
;
1359 static nsresult NSAPI
nsChannel_GetRedirectionLimit(nsIHttpChannel
*iface
, UINT32
*aRedirectionLimit
)
1361 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1363 FIXME("(%p)->(%p)\n", This
, aRedirectionLimit
);
1365 return NS_ERROR_NOT_IMPLEMENTED
;
1368 static nsresult NSAPI
nsChannel_SetRedirectionLimit(nsIHttpChannel
*iface
, UINT32 aRedirectionLimit
)
1370 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1372 FIXME("(%p)->(%u)\n", This
, aRedirectionLimit
);
1374 return NS_ERROR_NOT_IMPLEMENTED
;
1377 static nsresult NSAPI
nsChannel_GetResponseStatus(nsIHttpChannel
*iface
, UINT32
*aResponseStatus
)
1379 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1381 TRACE("(%p)->(%p)\n", This
, aResponseStatus
);
1383 if(This
->response_status
) {
1384 *aResponseStatus
= This
->response_status
;
1388 WARN("No response status\n");
1389 return NS_ERROR_UNEXPECTED
;
1392 static nsresult NSAPI
nsChannel_GetResponseStatusText(nsIHttpChannel
*iface
,
1393 nsACString
*aResponseStatusText
)
1395 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1397 FIXME("(%p)->(%p)\n", This
, aResponseStatusText
);
1399 return NS_ERROR_NOT_IMPLEMENTED
;
1402 static nsresult NSAPI
nsChannel_GetRequestSucceeded(nsIHttpChannel
*iface
,
1403 cpp_bool
*aRequestSucceeded
)
1405 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1407 TRACE("(%p)->(%p)\n", This
, aRequestSucceeded
);
1409 if(!This
->response_status
)
1410 return NS_ERROR_NOT_AVAILABLE
;
1412 *aRequestSucceeded
= This
->response_status
/100 == 2;
1417 static nsresult NSAPI
nsChannel_GetResponseHeader(nsIHttpChannel
*iface
,
1418 const nsACString
*header
, nsACString
*_retval
)
1420 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1422 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(header
), _retval
);
1424 return get_channel_http_header(&This
->response_headers
, header
, _retval
);
1427 static nsresult NSAPI
nsChannel_SetResponseHeader(nsIHttpChannel
*iface
,
1428 const nsACString
*header
, const nsACString
*value
, cpp_bool merge
)
1430 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1432 FIXME("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(header
), debugstr_nsacstr(value
), merge
);
1434 return NS_ERROR_NOT_IMPLEMENTED
;
1437 static nsresult NSAPI
nsChannel_VisitResponseHeaders(nsIHttpChannel
*iface
,
1438 nsIHttpHeaderVisitor
*aVisitor
)
1440 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1442 TRACE("(%p)->(%p)\n", This
, aVisitor
);
1444 return visit_http_headers(&This
->response_headers
, aVisitor
);
1447 static nsresult NSAPI
nsChannel_IsNoStoreResponse(nsIHttpChannel
*iface
, cpp_bool
*_retval
)
1449 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1450 http_header_t
*header
;
1452 static const WCHAR cache_controlW
[] = {'C','a','c','h','e','-','C','o','n','t','r','o','l'};
1453 static const WCHAR no_storeW
[] = {'n','o','-','s','t','o','r','e',0};
1455 TRACE("(%p)->(%p)\n", This
, _retval
);
1457 header
= find_http_header(&This
->response_headers
, cache_controlW
, sizeof(cache_controlW
)/sizeof(WCHAR
));
1458 *_retval
= header
&& !strcmpiW(header
->data
, no_storeW
);
1462 static nsresult NSAPI
nsChannel_IsNoCacheResponse(nsIHttpChannel
*iface
, cpp_bool
*_retval
)
1464 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1466 FIXME("(%p)->(%p)\n", This
, _retval
);
1468 return NS_ERROR_NOT_IMPLEMENTED
;
1471 static nsresult NSAPI
nsChannel_RedirectTo(nsIHttpChannel
*iface
, nsIURI
*aNewURI
)
1473 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1475 FIXME("(%p)->(%p)\n", This
, aNewURI
);
1477 return NS_ERROR_NOT_IMPLEMENTED
;
1480 static const nsIHttpChannelVtbl nsChannelVtbl
= {
1481 nsChannel_QueryInterface
,
1485 nsChannel_IsPending
,
1486 nsChannel_GetStatus
,
1490 nsChannel_GetLoadGroup
,
1491 nsChannel_SetLoadGroup
,
1492 nsChannel_GetLoadFlags
,
1493 nsChannel_SetLoadFlags
,
1494 nsChannel_GetOriginalURI
,
1495 nsChannel_SetOriginalURI
,
1499 nsChannel_GetNotificationCallbacks
,
1500 nsChannel_SetNotificationCallbacks
,
1501 nsChannel_GetSecurityInfo
,
1502 nsChannel_GetContentType
,
1503 nsChannel_SetContentType
,
1504 nsChannel_GetContentCharset
,
1505 nsChannel_SetContentCharset
,
1506 nsChannel_GetContentLength
,
1507 nsChannel_SetContentLength
,
1509 nsChannel_AsyncOpen
,
1510 nsChannel_GetContentDisposition
,
1511 nsChannel_SetContentDisposition
,
1512 nsChannel_GetContentDispositionFilename
,
1513 nsChannel_SetContentDispositionFilename
,
1514 nsChannel_GetContentDispositionHeader
,
1515 nsChannel_GetLoadInfo
,
1516 nsChannel_SetLoadInfo
,
1517 nsChannel_GetRequestMethod
,
1518 nsChannel_SetRequestMethod
,
1519 nsChannel_GetReferrer
,
1520 nsChannel_SetReferrer
,
1521 nsChannel_GetReferrerPolicy
,
1522 nsChannel_SetReferrerWithPolicy
,
1523 nsChannel_GetRequestHeader
,
1524 nsChannel_SetRequestHeader
,
1525 nsChannel_VisitRequestHeaders
,
1526 nsChannel_GetAllowPipelining
,
1527 nsChannel_SetAllowPipelining
,
1528 nsChannel_GetAllowTLS
,
1529 nsChannel_SetAllowTLS
,
1530 nsChannel_GetRedirectionLimit
,
1531 nsChannel_SetRedirectionLimit
,
1532 nsChannel_GetResponseStatus
,
1533 nsChannel_GetResponseStatusText
,
1534 nsChannel_GetRequestSucceeded
,
1535 nsChannel_GetResponseHeader
,
1536 nsChannel_SetResponseHeader
,
1537 nsChannel_VisitResponseHeaders
,
1538 nsChannel_IsNoStoreResponse
,
1539 nsChannel_IsNoCacheResponse
,
1540 nsChannel_RedirectTo
1543 static inline nsChannel
*impl_from_nsIUploadChannel(nsIUploadChannel
*iface
)
1545 return CONTAINING_RECORD(iface
, nsChannel
, nsIUploadChannel_iface
);
1548 static nsresult NSAPI
nsUploadChannel_QueryInterface(nsIUploadChannel
*iface
, nsIIDRef riid
,
1551 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1552 return nsIHttpChannel_QueryInterface(&This
->nsIHttpChannel_iface
, riid
, result
);
1555 static nsrefcnt NSAPI
nsUploadChannel_AddRef(nsIUploadChannel
*iface
)
1557 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1558 return nsIHttpChannel_AddRef(&This
->nsIHttpChannel_iface
);
1561 static nsrefcnt NSAPI
nsUploadChannel_Release(nsIUploadChannel
*iface
)
1563 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1564 return nsIHttpChannel_Release(&This
->nsIHttpChannel_iface
);
1567 static nsresult NSAPI
nsUploadChannel_SetUploadStream(nsIUploadChannel
*iface
,
1568 nsIInputStream
*aStream
, const nsACString
*aContentType
, INT64 aContentLength
)
1570 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1571 const char *content_type
;
1573 static const WCHAR content_typeW
[] =
1574 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1576 TRACE("(%p)->(%p %s %s)\n", This
, aStream
, debugstr_nsacstr(aContentType
), wine_dbgstr_longlong(aContentLength
));
1578 This
->post_data_contains_headers
= TRUE
;
1581 nsACString_GetData(aContentType
, &content_type
);
1585 ct
= heap_strdupAtoW(content_type
);
1587 return NS_ERROR_UNEXPECTED
;
1589 set_http_header(&This
->request_headers
, content_typeW
,
1590 sizeof(content_typeW
)/sizeof(WCHAR
), ct
, strlenW(ct
));
1592 This
->post_data_contains_headers
= FALSE
;
1596 if(aContentLength
!= -1)
1597 FIXME("Unsupported acontentLength = %s\n", wine_dbgstr_longlong(aContentLength
));
1599 if(This
->post_data_stream
)
1600 nsIInputStream_Release(This
->post_data_stream
);
1601 This
->post_data_stream
= aStream
;
1603 nsIInputStream_AddRef(aStream
);
1605 This
->request_method
= METHOD_POST
;
1609 static nsresult NSAPI
nsUploadChannel_GetUploadStream(nsIUploadChannel
*iface
,
1610 nsIInputStream
**aUploadStream
)
1612 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1614 TRACE("(%p)->(%p)\n", This
, aUploadStream
);
1616 if(This
->post_data_stream
)
1617 nsIInputStream_AddRef(This
->post_data_stream
);
1619 *aUploadStream
= This
->post_data_stream
;
1623 static const nsIUploadChannelVtbl nsUploadChannelVtbl
= {
1624 nsUploadChannel_QueryInterface
,
1625 nsUploadChannel_AddRef
,
1626 nsUploadChannel_Release
,
1627 nsUploadChannel_SetUploadStream
,
1628 nsUploadChannel_GetUploadStream
1631 static inline nsChannel
*impl_from_nsIHttpChannelInternal(nsIHttpChannelInternal
*iface
)
1633 return CONTAINING_RECORD(iface
, nsChannel
, nsIHttpChannelInternal_iface
);
1636 static nsresult NSAPI
nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal
*iface
, nsIIDRef riid
,
1639 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1640 return nsIHttpChannel_QueryInterface(&This
->nsIHttpChannel_iface
, riid
, result
);
1643 static nsrefcnt NSAPI
nsHttpChannelInternal_AddRef(nsIHttpChannelInternal
*iface
)
1645 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1646 return nsIHttpChannel_AddRef(&This
->nsIHttpChannel_iface
);
1649 static nsrefcnt NSAPI
nsHttpChannelInternal_Release(nsIHttpChannelInternal
*iface
)
1651 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1652 return nsIHttpChannel_Release(&This
->nsIHttpChannel_iface
);
1655 static nsresult NSAPI
nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
**aDocumentURI
)
1657 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1659 FIXME("(%p)->()\n", This
);
1661 return NS_ERROR_NOT_IMPLEMENTED
;
1664 static nsresult NSAPI
nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
*aDocumentURI
)
1666 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1668 FIXME("(%p)->()\n", This
);
1670 return NS_ERROR_NOT_IMPLEMENTED
;
1673 static nsresult NSAPI
nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal
*iface
, UINT32
*major
, UINT32
*minor
)
1675 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1677 FIXME("(%p)->()\n", This
);
1679 return NS_ERROR_NOT_IMPLEMENTED
;
1682 static nsresult NSAPI
nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal
*iface
, UINT32
*major
, UINT32
*minor
)
1684 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1686 FIXME("(%p)->()\n", This
);
1688 return NS_ERROR_NOT_IMPLEMENTED
;
1691 static nsresult NSAPI
nsHttpChannelInternal_TakeAllSecurityMessages(nsIHttpChannelInternal
*iface
, void *aMessages
)
1693 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1695 FIXME("(%p)->()\n", This
);
1697 return NS_ERROR_NOT_IMPLEMENTED
;
1700 static nsresult NSAPI
nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal
*iface
, const char *aCookieHeader
)
1702 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1704 FIXME("(%p)->()\n", This
);
1706 return NS_ERROR_NOT_IMPLEMENTED
;
1709 static nsresult NSAPI
nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal
*iface
, const char *aFallbackKey
)
1711 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1713 FIXME("(%p)->()\n", This
);
1715 return NS_ERROR_NOT_IMPLEMENTED
;
1718 static nsresult NSAPI
nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, cpp_bool
*aForceThirdPartyCookie
)
1720 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1722 FIXME("(%p)->()\n", This
);
1724 return NS_ERROR_NOT_IMPLEMENTED
;
1727 static nsresult NSAPI
nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, cpp_bool aForceThirdPartyCookie
)
1729 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1731 FIXME("(%p)->()\n", This
);
1733 return NS_ERROR_NOT_IMPLEMENTED
;
1736 static nsresult NSAPI
nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal
*iface
, cpp_bool
*aCanceled
)
1738 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1740 FIXME("(%p)->(%p)\n", This
, aCanceled
);
1742 return NS_ERROR_NOT_IMPLEMENTED
;
1745 static nsresult NSAPI
nsHttpChannelInternal_GetChannelIsForDownload(nsIHttpChannelInternal
*iface
, cpp_bool
*aCanceled
)
1747 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1749 FIXME("(%p)->(%p)\n", This
, aCanceled
);
1751 return NS_ERROR_NOT_IMPLEMENTED
;
1754 static nsresult NSAPI
nsHttpChannelInternal_SetChannelIsForDownload(nsIHttpChannelInternal
*iface
, cpp_bool aCanceled
)
1756 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1758 FIXME("(%p)->(%x)\n", This
, aCanceled
);
1760 return NS_ERROR_NOT_IMPLEMENTED
;
1763 static nsresult NSAPI
nsHttpChannelInternal_GetLocalAddress(nsIHttpChannelInternal
*iface
, nsACString
*aLocalAddress
)
1765 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1767 FIXME("(%p)->(%p)\n", This
, aLocalAddress
);
1769 return NS_ERROR_NOT_IMPLEMENTED
;
1772 static nsresult NSAPI
nsHttpChannelInternal_GetLocalPort(nsIHttpChannelInternal
*iface
, LONG
*aLocalPort
)
1774 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1776 FIXME("(%p)->(%p)\n", This
, aLocalPort
);
1778 return NS_ERROR_NOT_IMPLEMENTED
;
1781 static nsresult NSAPI
nsHttpChannelInternal_GetRemoteAddress(nsIHttpChannelInternal
*iface
, nsACString
*aRemoteAddress
)
1783 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1785 FIXME("(%p)->(%p)\n", This
, aRemoteAddress
);
1787 return NS_ERROR_NOT_IMPLEMENTED
;
1790 static nsresult NSAPI
nsHttpChannelInternal_GetRemotePort(nsIHttpChannelInternal
*iface
, LONG
*aRemotePort
)
1792 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1794 FIXME("(%p)->(%p)\n", This
, aRemotePort
);
1796 return NS_ERROR_NOT_IMPLEMENTED
;
1799 static nsresult NSAPI
nsHttpChannelInternal_SetCacheKeysRedirectChain(nsIHttpChannelInternal
*iface
, void *cacheKeys
)
1801 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1803 FIXME("(%p)->(%p)\n", This
, cacheKeys
);
1805 return NS_ERROR_NOT_IMPLEMENTED
;
1808 static nsresult NSAPI
nsHttpChannelInternal_HTTPUpgrade(nsIHttpChannelInternal
*iface
,
1809 const nsACString
*aProtocolName
, nsIHttpUpgradeListener
*aListener
)
1811 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1812 FIXME("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aProtocolName
), aListener
);
1813 return NS_ERROR_NOT_IMPLEMENTED
;
1816 static nsresult NSAPI
nsHttpChannelInternal_GetAllowSpdy(nsIHttpChannelInternal
*iface
, cpp_bool
*aAllowSpdy
)
1818 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1819 FIXME("(%p)->(%p)\n", This
, aAllowSpdy
);
1820 return NS_ERROR_NOT_IMPLEMENTED
;
1823 static nsresult NSAPI
nsHttpChannelInternal_SetAllowSpdy(nsIHttpChannelInternal
*iface
, cpp_bool aAllowSpdy
)
1825 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1826 FIXME("(%p)->(%x)\n", This
, aAllowSpdy
);
1827 return NS_ERROR_NOT_IMPLEMENTED
;
1830 static nsresult NSAPI
nsHttpChannelInternal_GetLoadAsBlocking(nsIHttpChannelInternal
*iface
, cpp_bool
*aLoadAsBlocking
)
1832 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1833 FIXME("(%p)->(%p)\n", This
, aLoadAsBlocking
);
1834 return NS_ERROR_NOT_IMPLEMENTED
;
1837 static nsresult NSAPI
nsHttpChannelInternal_SetLoadAsBlocking(nsIHttpChannelInternal
*iface
, cpp_bool aLoadAsBlocking
)
1839 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1840 FIXME("(%p)->(%x)\n", This
, aLoadAsBlocking
);
1841 return NS_ERROR_NOT_IMPLEMENTED
;
1844 static nsresult NSAPI
nsHttpChannelInternal_GetLoadUnblocked(nsIHttpChannelInternal
*iface
, cpp_bool
*aLoadUnblocked
)
1846 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1847 FIXME("(%p)->(%p)\n", This
, aLoadUnblocked
);
1848 return NS_ERROR_NOT_IMPLEMENTED
;
1851 static nsresult NSAPI
nsHttpChannelInternal_SetLoadUnblocked(nsIHttpChannelInternal
*iface
, cpp_bool aLoadUnblocked
)
1853 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1854 FIXME("(%p)->(%x)\n", This
, aLoadUnblocked
);
1855 return NS_ERROR_NOT_IMPLEMENTED
;
1858 static nsresult NSAPI
nsHttpChannelInternal_GetResponseTimeoutEnabled(nsIHttpChannelInternal
*iface
,
1859 cpp_bool
*aResponseTimeoutEnabled
)
1861 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1862 FIXME("(%p)->(%p)\n", This
, aResponseTimeoutEnabled
);
1863 return NS_ERROR_NOT_IMPLEMENTED
;
1866 static nsresult NSAPI
nsHttpChannelInternal_SetResponseTimeoutEnabled(nsIHttpChannelInternal
*iface
,
1867 cpp_bool aResponseTimeoutEnabled
)
1869 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1870 FIXME("(%p)->(%x)\n", This
, aResponseTimeoutEnabled
);
1871 return NS_ERROR_NOT_IMPLEMENTED
;
1874 static nsresult NSAPI
nsHttpChannelInternal_GetApiRedirectToURI(nsIHttpChannelInternal
*iface
, nsIURI
**aApiRedirectToURI
)
1876 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1877 FIXME("(%p)->(%p)\n", This
, aApiRedirectToURI
);
1878 return NS_ERROR_NOT_IMPLEMENTED
;
1881 static nsresult NSAPI
nsHttpChannelInternal_AddRedirect(nsIHttpChannelInternal
*iface
, nsIPrincipal
*aPrincipal
)
1883 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1884 FIXME("(%p)->(%p)\n", This
, aPrincipal
);
1885 return NS_ERROR_NOT_IMPLEMENTED
;
1888 static nsresult NSAPI
nsHttpChannelInternal_GetLastModifiedTime(nsIHttpChannelInternal
*iface
, PRTime
*aLastModifiedTime
)
1890 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1891 FIXME("(%p)->(%p)\n", This
, aLastModifiedTime
);
1892 return NS_ERROR_NOT_IMPLEMENTED
;
1895 static nsresult NSAPI
nsHttpChannelInternal_ForceNoIntercept(nsIHttpChannelInternal
*iface
)
1897 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1898 FIXME("(%p)\n", This
);
1899 return NS_ERROR_NOT_IMPLEMENTED
;
1902 static nsresult NSAPI
nsHttpChannelInternal_GetTopWindowURI(nsIHttpChannelInternal
*iface
, nsIURI
**aTopWindowURI
)
1904 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1905 FIXME("(%p)->(%p)\n", This
, aTopWindowURI
);
1906 return NS_ERROR_NOT_IMPLEMENTED
;
1909 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl
= {
1910 nsHttpChannelInternal_QueryInterface
,
1911 nsHttpChannelInternal_AddRef
,
1912 nsHttpChannelInternal_Release
,
1913 nsHttpChannelInternal_GetDocumentURI
,
1914 nsHttpChannelInternal_SetDocumentURI
,
1915 nsHttpChannelInternal_GetRequestVersion
,
1916 nsHttpChannelInternal_GetResponseVersion
,
1917 nsHttpChannelInternal_TakeAllSecurityMessages
,
1918 nsHttpChannelInternal_SetCookie
,
1919 nsHttpChannelInternal_SetupFallbackChannel
,
1920 nsHttpChannelInternal_GetForceAllowThirdPartyCookie
,
1921 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
,
1922 nsHttpChannelInternal_GetCanceled
,
1923 nsHttpChannelInternal_GetChannelIsForDownload
,
1924 nsHttpChannelInternal_SetChannelIsForDownload
,
1925 nsHttpChannelInternal_GetLocalAddress
,
1926 nsHttpChannelInternal_GetLocalPort
,
1927 nsHttpChannelInternal_GetRemoteAddress
,
1928 nsHttpChannelInternal_GetRemotePort
,
1929 nsHttpChannelInternal_SetCacheKeysRedirectChain
,
1930 nsHttpChannelInternal_HTTPUpgrade
,
1931 nsHttpChannelInternal_GetAllowSpdy
,
1932 nsHttpChannelInternal_SetAllowSpdy
,
1933 nsHttpChannelInternal_GetLoadAsBlocking
,
1934 nsHttpChannelInternal_SetLoadAsBlocking
,
1935 nsHttpChannelInternal_GetLoadUnblocked
,
1936 nsHttpChannelInternal_SetLoadUnblocked
,
1937 nsHttpChannelInternal_GetResponseTimeoutEnabled
,
1938 nsHttpChannelInternal_SetResponseTimeoutEnabled
,
1939 nsHttpChannelInternal_GetApiRedirectToURI
,
1940 nsHttpChannelInternal_AddRedirect
,
1941 nsHttpChannelInternal_GetLastModifiedTime
,
1942 nsHttpChannelInternal_ForceNoIntercept
,
1943 nsHttpChannelInternal_GetTopWindowURI
1947 static void invalidate_uri(nsWineURI
*This
)
1950 IUri_Release(This
->uri
);
1955 static BOOL
ensure_uri_builder(nsWineURI
*This
)
1957 if(!This
->is_mutable
) {
1958 WARN("Not mutable URI\n");
1962 if(!This
->uri_builder
) {
1965 if(!ensure_uri(This
))
1968 hres
= CreateIUriBuilder(This
->uri
, 0, 0, &This
->uri_builder
);
1970 WARN("CreateIUriBuilder failed: %08x\n", hres
);
1975 invalidate_uri(This
);
1979 static nsresult
get_uri_string(nsWineURI
*This
, Uri_PROPERTY prop
, nsACString
*ret
)
1985 if(!ensure_uri(This
))
1986 return NS_ERROR_UNEXPECTED
;
1988 hres
= IUri_GetPropertyBSTR(This
->uri
, prop
, &val
, 0);
1990 WARN("GetPropertyBSTR failed: %08x\n", hres
);
1991 return NS_ERROR_UNEXPECTED
;
1994 vala
= heap_strdupWtoU(val
);
1997 return NS_ERROR_OUT_OF_MEMORY
;
1999 TRACE("ret %s\n", debugstr_a(vala
));
2000 nsACString_SetData(ret
, vala
);
2005 static inline nsWineURI
*impl_from_nsIFileURL(nsIFileURL
*iface
)
2007 return CONTAINING_RECORD(iface
, nsWineURI
, nsIFileURL_iface
);
2010 static nsresult NSAPI
nsURI_QueryInterface(nsIFileURL
*iface
, nsIIDRef riid
, void **result
)
2012 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2016 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
2017 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
2018 *result
= &This
->nsIFileURL_iface
;
2019 }else if(IsEqualGUID(&IID_nsIURI
, riid
)) {
2020 TRACE("(%p)->(IID_nsIURI %p)\n", This
, result
);
2021 *result
= &This
->nsIFileURL_iface
;
2022 }else if(IsEqualGUID(&IID_nsIURL
, riid
)) {
2023 TRACE("(%p)->(IID_nsIURL %p)\n", This
, result
);
2024 *result
= &This
->nsIFileURL_iface
;
2025 }else if(IsEqualGUID(&IID_nsIFileURL
, riid
)) {
2026 TRACE("(%p)->(IID_nsIFileURL %p)\n", This
, result
);
2027 *result
= This
->scheme
== URL_SCHEME_FILE
? &This
->nsIFileURL_iface
: NULL
;
2028 }else if(IsEqualGUID(&IID_nsIMutable
, riid
)) {
2029 TRACE("(%p)->(IID_nsIMutable %p)\n", This
, result
);
2030 *result
= &This
->nsIStandardURL_iface
;
2031 }else if(IsEqualGUID(&IID_nsIStandardURL
, riid
)) {
2032 TRACE("(%p)->(IID_nsIStandardURL %p)\n", This
, result
);
2033 *result
= &This
->nsIStandardURL_iface
;
2034 }else if(IsEqualGUID(&IID_nsWineURI
, riid
)) {
2035 TRACE("(%p)->(IID_nsWineURI %p)\n", This
, result
);
2040 nsIFileURL_AddRef(&This
->nsIFileURL_iface
);
2044 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
2045 return NS_NOINTERFACE
;
2048 static nsrefcnt NSAPI
nsURI_AddRef(nsIFileURL
*iface
)
2050 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2051 LONG ref
= InterlockedIncrement(&This
->ref
);
2053 TRACE("(%p) ref=%d\n", This
, ref
);
2058 static nsrefcnt NSAPI
nsURI_Release(nsIFileURL
*iface
)
2060 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2061 LONG ref
= InterlockedDecrement(&This
->ref
);
2063 TRACE("(%p) ref=%d\n", This
, ref
);
2066 if(This
->window_ref
)
2067 windowref_release(This
->window_ref
);
2069 nsIWebBrowserChrome_Release(&This
->container
->nsIWebBrowserChrome_iface
);
2071 IUri_Release(This
->uri
);
2072 heap_free(This
->origin_charset
);
2079 static nsresult NSAPI
nsURI_GetSpec(nsIFileURL
*iface
, nsACString
*aSpec
)
2081 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2083 TRACE("(%p)->(%p)\n", This
, aSpec
);
2085 return get_uri_string(This
, Uri_PROPERTY_DISPLAY_URI
, aSpec
);
2088 static nsresult NSAPI
nsURI_SetSpec(nsIFileURL
*iface
, const nsACString
*aSpec
)
2090 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2096 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aSpec
));
2098 if(!This
->is_mutable
)
2099 return NS_ERROR_UNEXPECTED
;
2101 nsACString_GetData(aSpec
, &speca
);
2102 spec
= heap_strdupUtoW(speca
);
2104 return NS_ERROR_OUT_OF_MEMORY
;
2106 hres
= create_uri(spec
, 0, &uri
);
2109 WARN("create_uri failed: %08x\n", hres
);
2110 return NS_ERROR_FAILURE
;
2113 invalidate_uri(This
);
2114 if(This
->uri_builder
) {
2115 IUriBuilder_Release(This
->uri_builder
);
2116 This
->uri_builder
= NULL
;
2123 static nsresult NSAPI
nsURI_GetPrePath(nsIFileURL
*iface
, nsACString
*aPrePath
)
2125 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2126 IUriBuilder
*uri_builder
;
2133 TRACE("(%p)->(%p)\n", This
, aPrePath
);
2135 if(!ensure_uri(This
))
2136 return NS_ERROR_UNEXPECTED
;
2138 hres
= CreateIUriBuilder(This
->uri
, 0, 0, &uri_builder
);
2140 return NS_ERROR_FAILURE
;
2142 hres
= IUriBuilder_RemoveProperties(uri_builder
, Uri_HAS_PATH
|Uri_HAS_QUERY
|Uri_HAS_FRAGMENT
);
2144 hres
= IUriBuilder_CreateUriSimple(uri_builder
, 0, 0, &uri
);
2145 IUriBuilder_Release(uri_builder
);
2147 return NS_ERROR_FAILURE
;
2149 hres
= IUri_GetDisplayUri(uri
, &display_uri
);
2152 return NS_ERROR_FAILURE
;
2154 /* Remove trailing slash that may be appended as default path. */
2155 len
= SysStringLen(display_uri
);
2156 if(len
&& display_uri
[len
-1] == '/')
2157 display_uri
[len
-1] = 0;
2159 nsres
= return_wstr_nsacstr(aPrePath
, display_uri
, -1);
2160 SysFreeString(display_uri
);
2164 static nsresult NSAPI
nsURI_GetScheme(nsIFileURL
*iface
, nsACString
*aScheme
)
2166 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2170 TRACE("(%p)->(%p)\n", This
, aScheme
);
2172 if(!ensure_uri(This
))
2173 return NS_ERROR_UNEXPECTED
;
2175 hres
= IUri_GetScheme(This
->uri
, &scheme
);
2177 WARN("GetScheme failed: %08x\n", hres
);
2178 return NS_ERROR_UNEXPECTED
;
2181 if(scheme
== URL_SCHEME_ABOUT
) {
2182 nsACString_SetData(aScheme
, "wine");
2186 return get_uri_string(This
, Uri_PROPERTY_SCHEME_NAME
, aScheme
);
2189 static nsresult NSAPI
nsURI_SetScheme(nsIFileURL
*iface
, const nsACString
*aScheme
)
2191 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2192 const char *schemea
;
2196 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aScheme
));
2198 if(!ensure_uri_builder(This
))
2199 return NS_ERROR_UNEXPECTED
;
2201 nsACString_GetData(aScheme
, &schemea
);
2202 scheme
= heap_strdupUtoW(schemea
);
2204 return NS_ERROR_OUT_OF_MEMORY
;
2206 hres
= IUriBuilder_SetSchemeName(This
->uri_builder
, scheme
);
2209 return NS_ERROR_UNEXPECTED
;
2214 static nsresult NSAPI
nsURI_GetUserPass(nsIFileURL
*iface
, nsACString
*aUserPass
)
2216 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2220 TRACE("(%p)->(%p)\n", This
, aUserPass
);
2222 if(!ensure_uri(This
))
2223 return NS_ERROR_UNEXPECTED
;
2225 hres
= IUri_GetUserName(This
->uri
, &user
);
2227 return NS_ERROR_FAILURE
;
2229 hres
= IUri_GetPassword(This
->uri
, &pass
);
2231 SysFreeString(user
);
2232 return NS_ERROR_FAILURE
;
2235 if(*user
|| *pass
) {
2236 FIXME("Construct user:pass string\n");
2238 nsACString_SetData(aUserPass
, "");
2241 SysFreeString(user
);
2242 SysFreeString(pass
);
2246 static nsresult NSAPI
nsURI_SetUserPass(nsIFileURL
*iface
, const nsACString
*aUserPass
)
2248 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2249 WCHAR
*user
= NULL
, *pass
= NULL
, *buf
= NULL
;
2250 const char *user_pass
;
2253 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUserPass
));
2255 if(!ensure_uri_builder(This
))
2256 return NS_ERROR_UNEXPECTED
;
2258 nsACString_GetData(aUserPass
, &user_pass
);
2262 buf
= heap_strdupUtoW(user_pass
);
2264 return NS_ERROR_OUT_OF_MEMORY
;
2266 ptr
= strchrW(buf
, ':');
2269 }else if(ptr
!= buf
) {
2279 hres
= IUriBuilder_SetUserName(This
->uri_builder
, user
);
2281 hres
= IUriBuilder_SetPassword(This
->uri_builder
, pass
);
2284 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_FAILURE
;
2287 static nsresult NSAPI
nsURI_GetUsername(nsIFileURL
*iface
, nsACString
*aUsername
)
2289 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2291 TRACE("(%p)->(%p)\n", This
, aUsername
);
2293 return get_uri_string(This
, Uri_PROPERTY_USER_NAME
, aUsername
);
2296 static nsresult NSAPI
nsURI_SetUsername(nsIFileURL
*iface
, const nsACString
*aUsername
)
2298 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2303 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUsername
));
2305 if(!ensure_uri_builder(This
))
2306 return NS_ERROR_UNEXPECTED
;
2308 nsACString_GetData(aUsername
, &usera
);
2309 user
= heap_strdupUtoW(usera
);
2311 return NS_ERROR_OUT_OF_MEMORY
;
2313 hres
= IUriBuilder_SetUserName(This
->uri_builder
, user
);
2316 return NS_ERROR_UNEXPECTED
;
2321 static nsresult NSAPI
nsURI_GetPassword(nsIFileURL
*iface
, nsACString
*aPassword
)
2323 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2325 TRACE("(%p)->(%p)\n", This
, aPassword
);
2327 return get_uri_string(This
, Uri_PROPERTY_PASSWORD
, aPassword
);
2330 static nsresult NSAPI
nsURI_SetPassword(nsIFileURL
*iface
, const nsACString
*aPassword
)
2332 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2337 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPassword
));
2339 if(!ensure_uri_builder(This
))
2340 return NS_ERROR_UNEXPECTED
;
2342 nsACString_GetData(aPassword
, &passa
);
2343 pass
= heap_strdupUtoW(passa
);
2345 return NS_ERROR_OUT_OF_MEMORY
;
2347 hres
= IUriBuilder_SetPassword(This
->uri_builder
, pass
);
2350 return NS_ERROR_UNEXPECTED
;
2355 static nsresult NSAPI
nsURI_GetHostPort(nsIFileURL
*iface
, nsACString
*aHostPort
)
2357 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2363 TRACE("(%p)->(%p)\n", This
, aHostPort
);
2365 if(!ensure_uri(This
))
2366 return NS_ERROR_UNEXPECTED
;
2368 hres
= IUri_GetAuthority(This
->uri
, &val
);
2370 WARN("GetAuthority failed: %08x\n", hres
);
2371 return NS_ERROR_UNEXPECTED
;
2374 ptr
= strchrW(val
, '@');
2378 vala
= heap_strdupWtoU(ptr
);
2381 return NS_ERROR_OUT_OF_MEMORY
;
2383 TRACE("ret %s\n", debugstr_a(vala
));
2384 nsACString_SetData(aHostPort
, vala
);
2389 static nsresult NSAPI
nsURI_SetHostPort(nsIFileURL
*iface
, const nsACString
*aHostPort
)
2391 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2393 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aHostPort
));
2395 /* Not implemented by Gecko */
2396 return NS_ERROR_NOT_IMPLEMENTED
;
2399 static nsresult NSAPI
nsURI_GetHost(nsIFileURL
*iface
, nsACString
*aHost
)
2401 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2403 TRACE("(%p)->(%p)\n", This
, aHost
);
2405 return get_uri_string(This
, Uri_PROPERTY_HOST
, aHost
);
2408 static nsresult NSAPI
nsURI_SetHost(nsIFileURL
*iface
, const nsACString
*aHost
)
2410 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2415 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aHost
));
2417 if(!ensure_uri_builder(This
))
2418 return NS_ERROR_UNEXPECTED
;
2420 nsACString_GetData(aHost
, &hosta
);
2421 host
= heap_strdupUtoW(hosta
);
2423 return NS_ERROR_OUT_OF_MEMORY
;
2425 hres
= IUriBuilder_SetHost(This
->uri_builder
, host
);
2428 return NS_ERROR_UNEXPECTED
;
2433 static nsresult NSAPI
nsURI_GetPort(nsIFileURL
*iface
, LONG
*aPort
)
2435 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2439 TRACE("(%p)->(%p)\n", This
, aPort
);
2441 if(!ensure_uri(This
))
2442 return NS_ERROR_UNEXPECTED
;
2444 hres
= IUri_GetPort(This
->uri
, &port
);
2446 WARN("GetPort failed: %08x\n", hres
);
2447 return NS_ERROR_UNEXPECTED
;
2450 *aPort
= port
? port
: -1;
2454 static nsresult NSAPI
nsURI_SetPort(nsIFileURL
*iface
, LONG aPort
)
2456 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2459 TRACE("(%p)->(%d)\n", This
, aPort
);
2461 if(!ensure_uri_builder(This
))
2462 return NS_ERROR_UNEXPECTED
;
2464 hres
= IUriBuilder_SetPort(This
->uri_builder
, aPort
!= -1, aPort
);
2465 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_FAILURE
;
2468 static nsresult NSAPI
nsURI_GetPath(nsIFileURL
*iface
, nsACString
*aPath
)
2470 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2472 TRACE("(%p)->(%p)\n", This
, aPath
);
2474 return get_uri_string(This
, Uri_PROPERTY_PATH
, aPath
);
2477 static nsresult NSAPI
nsURI_SetPath(nsIFileURL
*iface
, const nsACString
*aPath
)
2479 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2484 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPath
));
2486 if(!ensure_uri_builder(This
))
2487 return NS_ERROR_UNEXPECTED
;
2489 nsACString_GetData(aPath
, &patha
);
2490 path
= heap_strdupUtoW(patha
);
2492 return NS_ERROR_OUT_OF_MEMORY
;
2494 hres
= IUriBuilder_SetPath(This
->uri_builder
, path
);
2497 return NS_ERROR_UNEXPECTED
;
2502 static nsresult NSAPI
nsURI_Equals(nsIFileURL
*iface
, nsIURI
*other
, cpp_bool
*_retval
)
2504 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2505 nsWineURI
*other_obj
;
2509 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
2511 nsres
= nsIURI_QueryInterface(other
, &IID_nsWineURI
, (void**)&other_obj
);
2512 if(NS_FAILED(nsres
)) {
2513 TRACE("Could not get nsWineURI interface\n");
2518 if(ensure_uri(This
) && ensure_uri(other_obj
)) {
2521 hres
= IUri_IsEqual(This
->uri
, other_obj
->uri
, &b
);
2522 if(SUCCEEDED(hres
)) {
2526 nsres
= NS_ERROR_FAILURE
;
2529 nsres
= NS_ERROR_UNEXPECTED
;
2532 nsIFileURL_Release(&other_obj
->nsIFileURL_iface
);
2536 static nsresult NSAPI
nsURI_SchemeIs(nsIFileURL
*iface
, const char *scheme
, cpp_bool
*_retval
)
2538 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2539 WCHAR buf
[INTERNET_MAX_SCHEME_LENGTH
];
2543 TRACE("(%p)->(%s %p)\n", This
, debugstr_a(scheme
), _retval
);
2545 if(!ensure_uri(This
))
2546 return NS_ERROR_UNEXPECTED
;
2548 hres
= IUri_GetSchemeName(This
->uri
, &scheme_name
);
2550 return NS_ERROR_UNEXPECTED
;
2552 MultiByteToWideChar(CP_UTF8
, 0, scheme
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
2553 *_retval
= !strcmpW(scheme_name
, buf
);
2554 SysFreeString(scheme_name
);
2558 static nsresult NSAPI
nsURI_Clone(nsIFileURL
*iface
, nsIURI
**_retval
)
2560 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2561 nsWineURI
*wine_uri
;
2564 TRACE("(%p)->(%p)\n", This
, _retval
);
2566 if(!ensure_uri(This
))
2567 return NS_ERROR_UNEXPECTED
;
2569 nsres
= create_nsuri(This
->uri
, This
->window_ref
? This
->window_ref
->window
: NULL
,
2570 This
->container
, This
->origin_charset
, &wine_uri
);
2571 if(NS_FAILED(nsres
)) {
2572 WARN("create_nsuri failed: %08x\n", nsres
);
2576 *_retval
= (nsIURI
*)&wine_uri
->nsIFileURL_iface
;
2580 static nsresult NSAPI
nsURI_Resolve(nsIFileURL
*iface
, const nsACString
*aRelativePath
,
2581 nsACString
*_retval
)
2583 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2591 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aRelativePath
), _retval
);
2593 if(!ensure_uri(This
))
2594 return NS_ERROR_UNEXPECTED
;
2596 nsACString_GetData(aRelativePath
, &patha
);
2597 path
= heap_strdupUtoW(patha
);
2599 return NS_ERROR_OUT_OF_MEMORY
;
2601 hres
= combine_url(This
->uri
, path
, &new_uri
);
2604 return NS_ERROR_FAILURE
;
2606 hres
= IUri_GetDisplayUri(new_uri
, &ret
);
2607 IUri_Release(new_uri
);
2609 return NS_ERROR_FAILURE
;
2611 reta
= heap_strdupWtoU(ret
);
2614 return NS_ERROR_OUT_OF_MEMORY
;
2616 TRACE("returning %s\n", debugstr_a(reta
));
2617 nsACString_SetData(_retval
, reta
);
2622 static nsresult NSAPI
nsURI_GetAsciiSpec(nsIFileURL
*iface
, nsACString
*aAsciiSpec
)
2624 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2626 TRACE("(%p)->(%p)\n", This
, aAsciiSpec
);
2628 return nsIFileURL_GetSpec(&This
->nsIFileURL_iface
, aAsciiSpec
);
2631 static nsresult NSAPI
nsURI_GetAsciiHost(nsIFileURL
*iface
, nsACString
*aAsciiHost
)
2633 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2635 WARN("(%p)->(%p) FIXME: Use Uri_PUNYCODE_IDN_HOST flag\n", This
, aAsciiHost
);
2637 return get_uri_string(This
, Uri_PROPERTY_HOST
, aAsciiHost
);
2640 static nsresult NSAPI
nsURI_GetOriginCharset(nsIFileURL
*iface
, nsACString
*aOriginCharset
)
2642 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2644 TRACE("(%p)->(%p)\n", This
, aOriginCharset
);
2646 nsACString_SetData(aOriginCharset
, This
->origin_charset
);
2650 static nsresult NSAPI
nsURL_GetRef(nsIFileURL
*iface
, nsACString
*aRef
)
2652 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2657 TRACE("(%p)->(%p)\n", This
, aRef
);
2659 if(!ensure_uri(This
))
2660 return NS_ERROR_UNEXPECTED
;
2662 hres
= IUri_GetFragment(This
->uri
, &ref
);
2664 return NS_ERROR_UNEXPECTED
;
2666 refa
= heap_strdupWtoU(ref
);
2669 return NS_ERROR_OUT_OF_MEMORY
;
2671 nsACString_SetData(aRef
, refa
&& *refa
== '#' ? refa
+1 : refa
);
2676 static nsresult NSAPI
nsURL_SetRef(nsIFileURL
*iface
, const nsACString
*aRef
)
2678 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2683 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRef
));
2685 if(!ensure_uri_builder(This
))
2686 return NS_ERROR_UNEXPECTED
;
2688 nsACString_GetData(aRef
, &refa
);
2689 ref
= heap_strdupUtoW(refa
);
2691 return NS_ERROR_OUT_OF_MEMORY
;
2693 hres
= IUriBuilder_SetFragment(This
->uri_builder
, ref
);
2696 return NS_ERROR_UNEXPECTED
;
2701 static nsresult NSAPI
nsURI_EqualsExceptRef(nsIFileURL
*iface
, nsIURI
*other
, cpp_bool
*_retval
)
2703 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2704 nsWineURI
*other_obj
;
2707 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
2709 nsres
= nsIURI_QueryInterface(other
, &IID_nsWineURI
, (void**)&other_obj
);
2710 if(NS_FAILED(nsres
)) {
2711 TRACE("Could not get nsWineURI interface\n");
2716 if(ensure_uri(This
) && ensure_uri(other_obj
)) {
2717 *_retval
= compare_ignoring_frag(This
->uri
, other_obj
->uri
);
2720 nsres
= NS_ERROR_UNEXPECTED
;
2723 nsIFileURL_Release(&other_obj
->nsIFileURL_iface
);
2727 static nsresult NSAPI
nsURI_CloneIgnoreRef(nsIFileURL
*iface
, nsIURI
**_retval
)
2729 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2730 nsWineURI
*wine_uri
;
2734 TRACE("(%p)->(%p)\n", This
, _retval
);
2736 if(!ensure_uri(This
))
2737 return NS_ERROR_UNEXPECTED
;
2739 uri
= get_uri_nofrag(This
->uri
);
2741 return NS_ERROR_FAILURE
;
2743 nsres
= create_nsuri(uri
, This
->window_ref
? This
->window_ref
->window
: NULL
, This
->container
,
2744 This
->origin_charset
, &wine_uri
);
2746 if(NS_FAILED(nsres
)) {
2747 WARN("create_nsuri failed: %08x\n", nsres
);
2751 *_retval
= (nsIURI
*)&wine_uri
->nsIFileURL_iface
;
2755 static nsresult NSAPI
nsURI_GetSpecIgnoringRef(nsIFileURL
*iface
, nsACString
*aSpecIgnoringRef
)
2757 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2759 FIXME("(%p)->(%p)\n", This
, aSpecIgnoringRef
);
2761 return nsIFileURL_GetSpec(&This
->nsIFileURL_iface
, aSpecIgnoringRef
);
2764 static nsresult NSAPI
nsURI_GetHasRef(nsIFileURL
*iface
, cpp_bool
*aHasRef
)
2766 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2770 TRACE("(%p)->(%p)\n", This
, aHasRef
);
2772 if(!ensure_uri(This
))
2773 return NS_ERROR_UNEXPECTED
;
2775 hres
= IUri_HasProperty(This
->uri
, Uri_PROPERTY_FRAGMENT
, &b
);
2777 return NS_ERROR_FAILURE
;
2783 static nsresult NSAPI
nsURL_GetFilePath(nsIFileURL
*iface
, nsACString
*aFilePath
)
2785 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2787 TRACE("(%p)->(%p)\n", This
, aFilePath
);
2789 return nsIFileURL_GetPath(&This
->nsIFileURL_iface
, aFilePath
);
2792 static nsresult NSAPI
nsURL_SetFilePath(nsIFileURL
*iface
, const nsACString
*aFilePath
)
2794 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2796 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFilePath
));
2798 if(!This
->is_mutable
)
2799 return NS_ERROR_UNEXPECTED
;
2801 return nsIFileURL_SetPath(&This
->nsIFileURL_iface
, aFilePath
);
2804 static nsresult NSAPI
nsURL_GetQuery(nsIFileURL
*iface
, nsACString
*aQuery
)
2806 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2812 TRACE("(%p)->(%p)\n", This
, aQuery
);
2814 if(!ensure_uri(This
))
2815 return NS_ERROR_UNEXPECTED
;
2817 hres
= IUri_GetQuery(This
->uri
, &query
);
2819 return NS_ERROR_FAILURE
;
2822 if(ptr
&& *ptr
== '?')
2825 nsres
= return_wstr_nsacstr(aQuery
, ptr
, -1);
2826 SysFreeString(query
);
2830 static nsresult NSAPI
nsURL_SetQuery(nsIFileURL
*iface
, const nsACString
*aQuery
)
2832 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2837 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aQuery
));
2839 if(!ensure_uri_builder(This
))
2840 return NS_ERROR_UNEXPECTED
;
2842 nsACString_GetData(aQuery
, &querya
);
2843 query
= heap_strdupUtoW(querya
);
2845 return NS_ERROR_OUT_OF_MEMORY
;
2847 hres
= IUriBuilder_SetQuery(This
->uri_builder
, query
);
2850 return NS_ERROR_UNEXPECTED
;
2855 static nsresult
get_uri_path(nsWineURI
*This
, BSTR
*path
, const WCHAR
**file
, const WCHAR
**ext
)
2860 if(!ensure_uri(This
))
2861 return NS_ERROR_UNEXPECTED
;
2863 hres
= IUri_GetPath(This
->uri
, path
);
2865 return NS_ERROR_FAILURE
;
2867 for(ptr
= *path
+ SysStringLen(*path
)-1; ptr
> *path
&& *ptr
!= '/' && *ptr
!= '\\'; ptr
--);
2868 if(*ptr
== '/' || *ptr
== '\\')
2873 ptr
= strrchrW(ptr
, '.');
2875 ptr
= *path
+ SysStringLen(*path
);
2882 static nsresult NSAPI
nsURL_GetDirectory(nsIFileURL
*iface
, nsACString
*aDirectory
)
2884 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2889 TRACE("(%p)->(%p)\n", This
, aDirectory
);
2891 nsres
= get_uri_path(This
, &path
, &file
, NULL
);
2892 if(NS_FAILED(nsres
))
2895 nsres
= return_wstr_nsacstr(aDirectory
, path
, file
-path
);
2896 SysFreeString(path
);
2900 static nsresult NSAPI
nsURL_SetDirectory(nsIFileURL
*iface
, const nsACString
*aDirectory
)
2902 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2904 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aDirectory
));
2906 /* Not implemented by Gecko */
2907 return NS_ERROR_NOT_IMPLEMENTED
;
2910 static nsresult NSAPI
nsURL_GetFileName(nsIFileURL
*iface
, nsACString
*aFileName
)
2912 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2917 TRACE("(%p)->(%p)\n", This
, aFileName
);
2919 nsres
= get_uri_path(This
, &path
, &file
, NULL
);
2920 if(NS_FAILED(nsres
))
2923 nsres
= return_wstr_nsacstr(aFileName
, file
, -1);
2924 SysFreeString(path
);
2928 static nsresult NSAPI
nsURL_SetFileName(nsIFileURL
*iface
, const nsACString
*aFileName
)
2930 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2931 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileName
));
2932 return NS_ERROR_NOT_IMPLEMENTED
;
2935 static nsresult NSAPI
nsURL_GetFileBaseName(nsIFileURL
*iface
, nsACString
*aFileBaseName
)
2937 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2938 const WCHAR
*file
, *ext
;
2942 TRACE("(%p)->(%p)\n", This
, aFileBaseName
);
2944 nsres
= get_uri_path(This
, &path
, &file
, &ext
);
2945 if(NS_FAILED(nsres
))
2948 nsres
= return_wstr_nsacstr(aFileBaseName
, file
, ext
-file
);
2949 SysFreeString(path
);
2953 static nsresult NSAPI
nsURL_SetFileBaseName(nsIFileURL
*iface
, const nsACString
*aFileBaseName
)
2955 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2956 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileBaseName
));
2957 return NS_ERROR_NOT_IMPLEMENTED
;
2960 static nsresult NSAPI
nsURL_GetFileExtension(nsIFileURL
*iface
, nsACString
*aFileExtension
)
2962 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2964 TRACE("(%p)->(%p)\n", This
, aFileExtension
);
2966 return get_uri_string(This
, Uri_PROPERTY_EXTENSION
, aFileExtension
);
2969 static nsresult NSAPI
nsURL_SetFileExtension(nsIFileURL
*iface
, const nsACString
*aFileExtension
)
2971 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2972 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileExtension
));
2973 return NS_ERROR_NOT_IMPLEMENTED
;
2976 static nsresult NSAPI
nsURL_GetCommonBaseSpec(nsIFileURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2978 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2979 FIXME("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2980 return NS_ERROR_NOT_IMPLEMENTED
;
2983 static nsresult NSAPI
nsURL_GetRelativeSpec(nsIFileURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2985 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2986 FIXME("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2987 return NS_ERROR_NOT_IMPLEMENTED
;
2990 static nsresult NSAPI
nsFileURL_GetFile(nsIFileURL
*iface
, nsIFile
**aFile
)
2992 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2993 WCHAR path
[MAX_PATH
];
2997 TRACE("(%p)->(%p)\n", This
, aFile
);
2999 hres
= CoInternetParseIUri(This
->uri
, PARSE_PATH_FROM_URL
, 0, path
, sizeof(path
)/sizeof(WCHAR
), &size
, 0);
3001 WARN("CoInternetParseIUri failed: %08x\n", hres
);
3002 return NS_ERROR_FAILURE
;
3005 return create_nsfile(path
, aFile
);
3008 static nsresult NSAPI
nsFileURL_SetFile(nsIFileURL
*iface
, nsIFile
*aFile
)
3010 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
3011 FIXME("(%p)->(%p)\n", This
, aFile
);
3012 return NS_ERROR_NOT_IMPLEMENTED
;
3015 static const nsIFileURLVtbl nsFileURLVtbl
= {
3016 nsURI_QueryInterface
,
3044 nsURI_GetOriginCharset
,
3047 nsURI_EqualsExceptRef
,
3048 nsURI_CloneIgnoreRef
,
3049 nsURI_GetSpecIgnoringRef
,
3059 nsURL_GetFileBaseName
,
3060 nsURL_SetFileBaseName
,
3061 nsURL_GetFileExtension
,
3062 nsURL_SetFileExtension
,
3063 nsURL_GetCommonBaseSpec
,
3064 nsURL_GetRelativeSpec
,
3069 static inline nsWineURI
*impl_from_nsIStandardURL(nsIStandardURL
*iface
)
3071 return CONTAINING_RECORD(iface
, nsWineURI
, nsIStandardURL_iface
);
3074 static nsresult NSAPI
nsStandardURL_QueryInterface(nsIStandardURL
*iface
, nsIIDRef riid
,
3077 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
3078 return nsIFileURL_QueryInterface(&This
->nsIFileURL_iface
, riid
, result
);
3081 static nsrefcnt NSAPI
nsStandardURL_AddRef(nsIStandardURL
*iface
)
3083 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
3084 return nsIFileURL_AddRef(&This
->nsIFileURL_iface
);
3087 static nsrefcnt NSAPI
nsStandardURL_Release(nsIStandardURL
*iface
)
3089 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
3090 return nsIFileURL_Release(&This
->nsIFileURL_iface
);
3093 static nsresult NSAPI
nsStandardURL_GetMutable(nsIStandardURL
*iface
, cpp_bool
*aMutable
)
3095 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
3097 TRACE("(%p)->(%p)\n", This
, aMutable
);
3099 *aMutable
= This
->is_mutable
;
3103 static nsresult NSAPI
nsStandardURL_SetMutable(nsIStandardURL
*iface
, cpp_bool aMutable
)
3105 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
3107 TRACE("(%p)->(%x)\n", This
, aMutable
);
3109 This
->is_mutable
= aMutable
;
3113 static nsresult NSAPI
nsStandardURL_Init(nsIStandardURL
*iface
, UINT32 aUrlType
, LONG aDefaultPort
,
3114 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
)
3116 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
3117 FIXME("(%p)->(%d %d %s %s %p)\n", This
, aUrlType
, aDefaultPort
, debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
), aBaseURI
);
3118 return NS_ERROR_NOT_IMPLEMENTED
;
3121 static const nsIStandardURLVtbl nsStandardURLVtbl
= {
3122 nsStandardURL_QueryInterface
,
3123 nsStandardURL_AddRef
,
3124 nsStandardURL_Release
,
3125 nsStandardURL_GetMutable
,
3126 nsStandardURL_SetMutable
,
3130 static nsresult
create_nsuri(IUri
*iuri
, HTMLOuterWindow
*window
, NSContainer
*container
,
3131 const char *origin_charset
, nsWineURI
**_retval
)
3136 ret
= heap_alloc_zero(sizeof(nsWineURI
));
3138 return NS_ERROR_OUT_OF_MEMORY
;
3140 ret
->nsIFileURL_iface
.lpVtbl
= &nsFileURLVtbl
;
3141 ret
->nsIStandardURL_iface
.lpVtbl
= &nsStandardURLVtbl
;
3143 ret
->is_mutable
= TRUE
;
3145 set_uri_nscontainer(ret
, container
);
3146 set_uri_window(ret
, window
);
3151 hres
= IUri_GetScheme(iuri
, &ret
->scheme
);
3153 ret
->scheme
= URL_SCHEME_UNKNOWN
;
3155 if(origin_charset
&& *origin_charset
&& strcmp(origin_charset
, "UTF-8")) {
3156 ret
->origin_charset
= heap_strdupA(origin_charset
);
3157 if(!ret
->origin_charset
) {
3158 nsIFileURL_Release(&ret
->nsIFileURL_iface
);
3159 return NS_ERROR_OUT_OF_MEMORY
;
3163 TRACE("retval=%p\n", ret
);
3168 HRESULT
create_doc_uri(HTMLOuterWindow
*window
, IUri
*iuri
, nsWineURI
**ret
)
3173 nsres
= create_nsuri(iuri
, window
, window
->doc_obj
->nscontainer
, NULL
, &uri
);
3174 if(NS_FAILED(nsres
))
3177 uri
->is_doc_uri
= TRUE
;
3183 static nsresult
create_nschannel(nsWineURI
*uri
, nsChannel
**ret
)
3187 if(!ensure_uri(uri
))
3188 return NS_ERROR_UNEXPECTED
;
3190 channel
= heap_alloc_zero(sizeof(nsChannel
));
3192 return NS_ERROR_OUT_OF_MEMORY
;
3194 channel
->nsIHttpChannel_iface
.lpVtbl
= &nsChannelVtbl
;
3195 channel
->nsIUploadChannel_iface
.lpVtbl
= &nsUploadChannelVtbl
;
3196 channel
->nsIHttpChannelInternal_iface
.lpVtbl
= &nsHttpChannelInternalVtbl
;
3198 channel
->request_method
= METHOD_GET
;
3199 list_init(&channel
->response_headers
);
3200 list_init(&channel
->request_headers
);
3202 nsIFileURL_AddRef(&uri
->nsIFileURL_iface
);
3209 HRESULT
create_redirect_nschannel(const WCHAR
*url
, nsChannel
*orig_channel
, nsChannel
**ret
)
3211 HTMLOuterWindow
*window
= NULL
;
3218 hres
= create_uri(url
, 0, &iuri
);
3222 if(orig_channel
->uri
->window_ref
)
3223 window
= orig_channel
->uri
->window_ref
->window
;
3224 nsres
= create_nsuri(iuri
, window
, NULL
, NULL
, &uri
);
3226 if(NS_FAILED(nsres
))
3229 nsres
= create_nschannel(uri
, &channel
);
3230 nsIFileURL_Release(&uri
->nsIFileURL_iface
);
3231 if(NS_FAILED(nsres
))
3234 if(orig_channel
->load_group
) {
3235 nsILoadGroup_AddRef(orig_channel
->load_group
);
3236 channel
->load_group
= orig_channel
->load_group
;
3239 if(orig_channel
->notif_callback
) {
3240 nsIInterfaceRequestor_AddRef(orig_channel
->notif_callback
);
3241 channel
->notif_callback
= orig_channel
->notif_callback
;
3244 channel
->load_flags
= orig_channel
->load_flags
| LOAD_REPLACE
;
3246 if(orig_channel
->request_method
== METHOD_POST
)
3247 FIXME("unsupported POST method\n");
3249 if(orig_channel
->original_uri
) {
3250 nsIURI_AddRef(orig_channel
->original_uri
);
3251 channel
->original_uri
= orig_channel
->original_uri
;
3254 if(orig_channel
->referrer
) {
3255 nsIURI_AddRef(orig_channel
->referrer
);
3256 channel
->referrer
= orig_channel
->referrer
;
3264 nsIProtocolHandler nsIProtocolHandler_iface
;
3268 nsIProtocolHandler
*nshandler
;
3269 } nsProtocolHandler
;
3271 static inline nsProtocolHandler
*impl_from_nsIProtocolHandler(nsIProtocolHandler
*iface
)
3273 return CONTAINING_RECORD(iface
, nsProtocolHandler
, nsIProtocolHandler_iface
);
3276 static nsresult NSAPI
nsProtocolHandler_QueryInterface(nsIProtocolHandler
*iface
, nsIIDRef riid
,
3279 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3283 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
3284 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
3285 *result
= &This
->nsIProtocolHandler_iface
;
3286 }else if(IsEqualGUID(&IID_nsIProtocolHandler
, riid
)) {
3287 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This
, result
);
3288 *result
= &This
->nsIProtocolHandler_iface
;
3289 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler
, riid
)) {
3290 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This
, result
);
3291 return NS_NOINTERFACE
;
3295 nsISupports_AddRef((nsISupports
*)*result
);
3299 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
3300 return NS_NOINTERFACE
;
3303 static nsrefcnt NSAPI
nsProtocolHandler_AddRef(nsIProtocolHandler
*iface
)
3305 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3306 LONG ref
= InterlockedIncrement(&This
->ref
);
3308 TRACE("(%p) ref=%d\n", This
, ref
);
3313 static nsrefcnt NSAPI
nsProtocolHandler_Release(nsIProtocolHandler
*iface
)
3315 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3316 LONG ref
= InterlockedDecrement(&This
->ref
);
3318 TRACE("(%p) ref=%d\n", This
, ref
);
3322 nsIProtocolHandler_Release(This
->nshandler
);
3329 static nsresult NSAPI
nsProtocolHandler_GetScheme(nsIProtocolHandler
*iface
, nsACString
*aScheme
)
3331 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3333 TRACE("(%p)->(%p)\n", This
, aScheme
);
3336 return nsIProtocolHandler_GetScheme(This
->nshandler
, aScheme
);
3337 return NS_ERROR_NOT_IMPLEMENTED
;
3340 static nsresult NSAPI
nsProtocolHandler_GetDefaultPort(nsIProtocolHandler
*iface
,
3343 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3345 TRACE("(%p)->(%p)\n", This
, aDefaultPort
);
3348 return nsIProtocolHandler_GetDefaultPort(This
->nshandler
, aDefaultPort
);
3349 return NS_ERROR_NOT_IMPLEMENTED
;
3352 static nsresult NSAPI
nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler
*iface
,
3353 UINT32
*aProtocolFlags
)
3355 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3357 TRACE("(%p)->(%p)\n", This
, aProtocolFlags
);
3360 return nsIProtocolHandler_GetProtocolFlags(This
->nshandler
, aProtocolFlags
);
3361 return NS_ERROR_NOT_IMPLEMENTED
;
3364 static nsresult NSAPI
nsProtocolHandler_NewURI(nsIProtocolHandler
*iface
,
3365 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
3367 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3369 TRACE("((%p)->%s %s %p %p)\n", This
, debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
3373 return nsIProtocolHandler_NewURI(This
->nshandler
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3374 return NS_ERROR_NOT_IMPLEMENTED
;
3377 static nsresult NSAPI
nsProtocolHandler_NewChannel2(nsIProtocolHandler
*iface
,
3378 nsIURI
*aURI
, nsILoadInfo
*aLoadInfo
, nsIChannel
**_retval
)
3380 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3382 TRACE("(%p)->(%p %p %p)\n", This
, aURI
, aLoadInfo
, _retval
);
3385 return nsIProtocolHandler_NewChannel2(This
->nshandler
, aURI
, aLoadInfo
, _retval
);
3386 return NS_ERROR_NOT_IMPLEMENTED
;
3389 static nsresult NSAPI
nsProtocolHandler_NewChannel(nsIProtocolHandler
*iface
,
3390 nsIURI
*aURI
, nsIChannel
**_retval
)
3392 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3394 TRACE("(%p)->(%p %p)\n", This
, aURI
, _retval
);
3397 return nsIProtocolHandler_NewChannel(This
->nshandler
, aURI
, _retval
);
3398 return NS_ERROR_NOT_IMPLEMENTED
;
3401 static nsresult NSAPI
nsProtocolHandler_AllowPort(nsIProtocolHandler
*iface
,
3402 LONG port
, const char *scheme
, cpp_bool
*_retval
)
3404 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3406 TRACE("(%p)->(%d %s %p)\n", This
, port
, debugstr_a(scheme
), _retval
);
3409 return nsIProtocolHandler_AllowPort(This
->nshandler
, port
, scheme
, _retval
);
3410 return NS_ERROR_NOT_IMPLEMENTED
;
3413 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl
= {
3414 nsProtocolHandler_QueryInterface
,
3415 nsProtocolHandler_AddRef
,
3416 nsProtocolHandler_Release
,
3417 nsProtocolHandler_GetScheme
,
3418 nsProtocolHandler_GetDefaultPort
,
3419 nsProtocolHandler_GetProtocolFlags
,
3420 nsProtocolHandler_NewURI
,
3421 nsProtocolHandler_NewChannel2
,
3422 nsProtocolHandler_NewChannel
,
3423 nsProtocolHandler_AllowPort
3426 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*,nsIIDRef
,void**);
3428 static nsrefcnt NSAPI
nsIOService_AddRef(nsIIOService
*iface
)
3433 static nsrefcnt NSAPI
nsIOService_Release(nsIIOService
*iface
)
3438 static nsresult NSAPI
nsIOService_GetProtocolHandler(nsIIOService
*iface
, const char *aScheme
,
3439 nsIProtocolHandler
**_retval
)
3441 nsIExternalProtocolHandler
*nsexthandler
;
3442 nsIProtocolHandler
*nshandler
;
3443 nsProtocolHandler
*ret
;
3446 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
3448 nsres
= nsIIOService_GetProtocolHandler(nsio
, aScheme
, &nshandler
);
3449 if(NS_FAILED(nsres
)) {
3450 WARN("GetProtocolHandler failed: %08x\n", nsres
);
3454 nsres
= nsIProtocolHandler_QueryInterface(nshandler
, &IID_nsIExternalProtocolHandler
,
3455 (void**)&nsexthandler
);
3456 if(NS_FAILED(nsres
)) {
3457 *_retval
= nshandler
;
3461 nsIExternalProtocolHandler_Release(nsexthandler
);
3463 ret
= heap_alloc(sizeof(nsProtocolHandler
));
3465 return NS_ERROR_OUT_OF_MEMORY
;
3467 ret
->nsIProtocolHandler_iface
.lpVtbl
= &nsProtocolHandlerVtbl
;
3469 ret
->nshandler
= nshandler
;
3470 *_retval
= &ret
->nsIProtocolHandler_iface
;
3472 TRACE("return %p\n", *_retval
);
3476 static nsresult NSAPI
nsIOService_GetProtocolFlags(nsIIOService
*iface
, const char *aScheme
,
3479 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
3480 return nsIIOService_GetProtocolFlags(nsio
, aScheme
, _retval
);
3483 static BOOL
is_gecko_special_uri(const char *spec
)
3485 static const char *special_schemes
[] = {"chrome:", "jar:", "moz-safe-about", "resource:", "javascript:", "wyciwyg:"};
3488 for(i
=0; i
< sizeof(special_schemes
)/sizeof(*special_schemes
); i
++) {
3489 if(!strncasecmp(spec
, special_schemes
[i
], strlen(special_schemes
[i
])))
3493 if(!strncasecmp(spec
, "file:", 5)) {
3494 const char *ptr
= spec
+5;
3497 return is_gecko_path(ptr
);
3503 static nsresult NSAPI
nsIOService_NewURI(nsIIOService
*iface
, const nsACString
*aSpec
,
3504 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
3506 nsWineURI
*wine_uri
, *base_wine_uri
= NULL
;
3507 WCHAR new_spec
[INTERNET_MAX_URL_LENGTH
];
3508 HTMLOuterWindow
*window
= NULL
;
3509 const char *spec
= NULL
;
3515 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
3518 nsACString_GetData(aSpec
, &spec
);
3519 if(is_gecko_special_uri(spec
))
3520 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3522 if(!strncmp(spec
, "wine:", 5))
3526 nsres
= nsIURI_QueryInterface(aBaseURI
, &IID_nsWineURI
, (void**)&base_wine_uri
);
3527 if(NS_SUCCEEDED(nsres
)) {
3528 if(!ensure_uri(base_wine_uri
))
3529 return NS_ERROR_UNEXPECTED
;
3530 if(base_wine_uri
->window_ref
)
3531 window
= base_wine_uri
->window_ref
->window
;
3533 WARN("Could not get base nsWineURI: %08x\n", nsres
);
3537 if(aOriginCharset
&& *aOriginCharset
&& strncasecmp(aOriginCharset
, "utf", 3)) {
3541 len
= MultiByteToWideChar(CP_UTF8
, 0, aOriginCharset
, -1, NULL
, 0);
3542 charset
= SysAllocStringLen(NULL
, len
-1);
3544 return NS_ERROR_OUT_OF_MEMORY
;
3545 MultiByteToWideChar(CP_UTF8
, 0, aOriginCharset
, -1, charset
, len
);
3547 cp
= cp_from_charset_string(charset
);
3549 SysFreeString(charset
);
3552 MultiByteToWideChar(cp
, 0, spec
, -1, new_spec
, sizeof(new_spec
)/sizeof(WCHAR
));
3555 hres
= combine_url(base_wine_uri
->uri
, new_spec
, &urlmon_uri
);
3557 hres
= create_uri(new_spec
, 0, &urlmon_uri
);
3559 WARN("create_uri failed: %08x\n", hres
);
3563 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3565 nsres
= create_nsuri(urlmon_uri
, window
, NULL
, NULL
, &wine_uri
);
3566 IUri_Release(urlmon_uri
);
3568 nsIFileURL_Release(&base_wine_uri
->nsIFileURL_iface
);
3569 if(NS_FAILED(nsres
))
3572 *_retval
= (nsIURI
*)&wine_uri
->nsIFileURL_iface
;
3576 static nsresult NSAPI
nsIOService_NewFileURI(nsIIOService
*iface
, nsIFile
*aFile
,
3579 TRACE("(%p %p)\n", aFile
, _retval
);
3580 return nsIIOService_NewFileURI(nsio
, aFile
, _retval
);
3583 static nsresult NSAPI
nsIOService_NewChannelFromURI2(nsIIOService
*iface
, nsIURI
*aURI
,
3584 nsIDOMNode
*aLoadingNode
, nsIPrincipal
*aLoadingPrincipal
, nsIPrincipal
*aTriggeringPrincipal
,
3585 UINT32 aSecurityFlags
, UINT32 aContentPolicyType
, nsIChannel
**_retval
)
3587 FIXME("(%p %p %p %p %x %d %p)\n", aURI
, aLoadingNode
, aLoadingPrincipal
, aTriggeringPrincipal
,
3588 aSecurityFlags
, aContentPolicyType
, _retval
);
3589 return NS_ERROR_NOT_IMPLEMENTED
;
3592 static nsresult NSAPI
nsIOService_NewChannelFromURI(nsIIOService
*iface
, nsIURI
*aURI
,
3593 nsIChannel
**_retval
)
3595 nsWineURI
*wine_uri
;
3599 TRACE("(%p %p)\n", aURI
, _retval
);
3601 nsres
= nsIURI_QueryInterface(aURI
, &IID_nsWineURI
, (void**)&wine_uri
);
3602 if(NS_FAILED(nsres
)) {
3603 TRACE("Could not get nsWineURI: %08x\n", nsres
);
3604 return nsIIOService_NewChannelFromURI(nsio
, aURI
, _retval
);
3607 nsres
= create_nschannel(wine_uri
, &ret
);
3608 nsIFileURL_Release(&wine_uri
->nsIFileURL_iface
);
3609 if(NS_FAILED(nsres
))
3612 nsIURI_AddRef(aURI
);
3613 ret
->original_uri
= aURI
;
3615 *_retval
= (nsIChannel
*)&ret
->nsIHttpChannel_iface
;
3619 static nsresult NSAPI
nsIOService_NewChannel2(nsIIOService
*iface
, const nsACString
*aSpec
,
3620 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIDOMNode
*aLoadingNode
, nsIPrincipal
*aLoadingPrincipal
,
3621 nsIPrincipal
*aTriggeringPrincipal
, UINT32 aSecurityFlags
, UINT32 aContentPolicyType
, nsIChannel
**_retval
)
3623 TRACE("(%s %s %p %p %p %p %x %d %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
), aBaseURI
,
3624 aLoadingNode
, aLoadingPrincipal
, aTriggeringPrincipal
, aSecurityFlags
, aContentPolicyType
, _retval
);
3625 return nsIIOService_NewChannel2(nsio
, aSpec
, aOriginCharset
, aBaseURI
, aLoadingNode
, aLoadingPrincipal
,
3626 aTriggeringPrincipal
, aSecurityFlags
, aContentPolicyType
, _retval
);
3629 static nsresult NSAPI
nsIOService_NewChannel(nsIIOService
*iface
, const nsACString
*aSpec
,
3630 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIChannel
**_retval
)
3632 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
), aBaseURI
, _retval
);
3633 return nsIIOService_NewChannel(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3636 static nsresult NSAPI
nsIOService_GetOffline(nsIIOService
*iface
, cpp_bool
*aOffline
)
3638 TRACE("(%p)\n", aOffline
);
3639 return nsIIOService_GetOffline(nsio
, aOffline
);
3642 static nsresult NSAPI
nsIOService_SetOffline(nsIIOService
*iface
, cpp_bool aOffline
)
3644 TRACE("(%x)\n", aOffline
);
3645 return nsIIOService_SetOffline(nsio
, aOffline
);
3648 static nsresult NSAPI
nsIOService_SetAppOffline(nsIIOService
*iface
, UINT32 appId
, INT32 state
)
3650 TRACE("(%d %x)\n", appId
, state
);
3651 return nsIIOService_SetAppOffline(nsio
, appId
, state
);
3654 static nsresult NSAPI
nsIOService_IsAppOffline(nsIIOService
*iface
, UINT32 appId
, cpp_bool
*_retval
)
3656 TRACE("(%u %p)\n", appId
, _retval
);
3657 return nsIIOService_IsAppOffline(nsio
, appId
, _retval
);
3660 static nsresult NSAPI
nsIOService_GetAppOfflineState(nsIIOService
*iface
, UINT32 appId
, INT32
*_retval
)
3662 TRACE("(%d %p)\n", appId
, _retval
);
3663 return nsIIOService_GetAppOfflineState(nsio
, appId
, _retval
);
3666 static nsresult NSAPI
nsIOService_AllowPort(nsIIOService
*iface
, LONG aPort
,
3667 const char *aScheme
, cpp_bool
*_retval
)
3669 TRACE("(%d %s %p)\n", aPort
, debugstr_a(aScheme
), _retval
);
3670 return nsIIOService_AllowPort(nsio
, aPort
, debugstr_a(aScheme
), _retval
);
3673 static nsresult NSAPI
nsIOService_ExtractScheme(nsIIOService
*iface
, const nsACString
*urlString
,
3674 nsACString
* _retval
)
3676 TRACE("(%s %p)\n", debugstr_nsacstr(urlString
), _retval
);
3677 return nsIIOService_ExtractScheme(nsio
, urlString
, _retval
);
3680 static const nsIIOServiceVtbl nsIOServiceVtbl
= {
3681 nsIOService_QueryInterface
,
3683 nsIOService_Release
,
3684 nsIOService_GetProtocolHandler
,
3685 nsIOService_GetProtocolFlags
,
3687 nsIOService_NewFileURI
,
3688 nsIOService_NewChannelFromURI2
,
3689 nsIOService_NewChannelFromURI
,
3690 nsIOService_NewChannel2
,
3691 nsIOService_NewChannel
,
3692 nsIOService_GetOffline
,
3693 nsIOService_SetOffline
,
3694 nsIOService_SetAppOffline
,
3695 nsIOService_IsAppOffline
,
3696 nsIOService_GetAppOfflineState
,
3697 nsIOService_AllowPort
,
3698 nsIOService_ExtractScheme
3701 static nsIIOService nsIOService
= { &nsIOServiceVtbl
};
3703 static nsresult NSAPI
nsNetUtil_QueryInterface(nsINetUtil
*iface
, nsIIDRef riid
,
3706 return nsIIOService_QueryInterface(&nsIOService
, riid
, result
);
3709 static nsrefcnt NSAPI
nsNetUtil_AddRef(nsINetUtil
*iface
)
3714 static nsrefcnt NSAPI
nsNetUtil_Release(nsINetUtil
*iface
)
3719 static nsresult NSAPI
nsNetUtil_ParseContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
3720 nsACString
*aCharset
, cpp_bool
*aHadCharset
, nsACString
*aContentType
)
3722 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aHadCharset
, aContentType
);
3724 return nsINetUtil_ParseContentType(net_util
, aTypeHeader
, aCharset
, aHadCharset
, aContentType
);
3727 static const char *debugstr_protocol_flags(UINT32 flags
)
3730 #define X(f) case f: return #f
3735 X(ALLOWS_PROXY_HTTP
);
3736 X(URI_INHERITS_SECURITY_CONTEXT
);
3737 X(URI_FORBIDS_AUTOMATIC_DOCUMENT_REPLACEMENT
);
3738 X(URI_LOADABLE_BY_ANYONE
);
3739 X(URI_DANGEROUS_TO_LOAD
);
3740 X(URI_IS_UI_RESOURCE
);
3741 X(URI_IS_LOCAL_FILE
);
3742 X(URI_LOADABLE_BY_SUBSUMERS
);
3743 X(URI_DOES_NOT_RETURN_DATA
);
3744 X(URI_IS_LOCAL_RESOURCE
);
3745 X(URI_OPENING_EXECUTES_SCRIPT
);
3746 X(URI_NON_PERSISTABLE
);
3747 X(URI_FORBIDS_COOKIE_ACCESS
);
3748 X(URI_CROSS_ORIGIN_NEEDS_WEBAPPS_PERM
);
3749 X(URI_SYNC_LOAD_IS_OK
);
3750 X(URI_SAFE_TO_LOAD_IN_SECURE_CONTEXT
);
3753 return wine_dbg_sprintf("%08x", flags
);
3757 static nsresult NSAPI
nsNetUtil_ProtocolHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, UINT32 aFlags
, cpp_bool
*_retval
)
3759 TRACE("(%p %s %p)\n", aURI
, debugstr_protocol_flags(aFlags
), _retval
);
3761 return nsINetUtil_ProtocolHasFlags(net_util
, aURI
, aFlags
, _retval
);
3764 static nsresult NSAPI
nsNetUtil_URIChainHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, UINT32 aFlags
, cpp_bool
*_retval
)
3766 TRACE("(%p %s %p)\n", aURI
, debugstr_protocol_flags(aFlags
), _retval
);
3768 if(aFlags
== URI_DOES_NOT_RETURN_DATA
) {
3773 return nsINetUtil_URIChainHasFlags(net_util
, aURI
, aFlags
, _retval
);
3776 static nsresult NSAPI
nsNetUtil_ToImmutableURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
3778 TRACE("(%p %p)\n", aURI
, _retval
);
3780 return nsINetUtil_ToImmutableURI(net_util
, aURI
, _retval
);
3783 static nsresult NSAPI
nsNetUtil_NewSimpleNestedURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
3785 TRACE("(%p %p)\n", aURI
, _retval
);
3787 return nsINetUtil_NewSimpleNestedURI(net_util
, aURI
, _retval
);
3790 static nsresult NSAPI
nsNetUtil_EscapeString(nsINetUtil
*iface
, const nsACString
*aString
,
3791 UINT32 aEscapeType
, nsACString
*_retval
)
3793 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString
), aEscapeType
, _retval
);
3795 return nsINetUtil_EscapeString(net_util
, aString
, aEscapeType
, _retval
);
3798 static nsresult NSAPI
nsNetUtil_EscapeURL(nsINetUtil
*iface
, const nsACString
*aStr
, UINT32 aFlags
,
3799 nsACString
*_retval
)
3801 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
3803 return nsINetUtil_EscapeURL(net_util
, aStr
, aFlags
, _retval
);
3806 static nsresult NSAPI
nsNetUtil_UnescapeString(nsINetUtil
*iface
, const nsACString
*aStr
,
3807 UINT32 aFlags
, nsACString
*_retval
)
3809 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
3811 return nsINetUtil_UnescapeString(net_util
, aStr
, aFlags
, _retval
);
3814 static nsresult NSAPI
nsNetUtil_ExtractCharsetFromContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
3815 nsACString
*aCharset
, LONG
*aCharsetStart
, LONG
*aCharsetEnd
, cpp_bool
*_retval
)
3817 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aCharsetStart
,
3818 aCharsetEnd
, _retval
);
3820 return nsINetUtil_ExtractCharsetFromContentType(net_util
, aTypeHeader
, aCharset
, aCharsetStart
, aCharsetEnd
, _retval
);
3823 static const nsINetUtilVtbl nsNetUtilVtbl
= {
3824 nsNetUtil_QueryInterface
,
3827 nsNetUtil_ParseContentType
,
3828 nsNetUtil_ProtocolHasFlags
,
3829 nsNetUtil_URIChainHasFlags
,
3830 nsNetUtil_ToImmutableURI
,
3831 nsNetUtil_NewSimpleNestedURI
,
3832 nsNetUtil_EscapeString
,
3833 nsNetUtil_EscapeURL
,
3834 nsNetUtil_UnescapeString
,
3835 nsNetUtil_ExtractCharsetFromContentType
3838 static nsINetUtil nsNetUtil
= { &nsNetUtilVtbl
};
3840 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*iface
, nsIIDRef riid
,
3845 if(IsEqualGUID(&IID_nsISupports
, riid
))
3846 *result
= &nsIOService
;
3847 else if(IsEqualGUID(&IID_nsIIOService
, riid
))
3848 *result
= &nsIOService
;
3849 else if(IsEqualGUID(&IID_nsINetUtil
, riid
))
3850 *result
= &nsNetUtil
;
3853 nsISupports_AddRef((nsISupports
*)*result
);
3857 FIXME("(%s %p)\n", debugstr_guid(riid
), result
);
3858 return NS_NOINTERFACE
;
3861 static nsresult NSAPI
nsIOServiceFactory_QueryInterface(nsIFactory
*iface
, nsIIDRef riid
,
3866 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
3867 TRACE("(IID_nsISupports %p)\n", result
);
3869 }else if(IsEqualGUID(&IID_nsIFactory
, riid
)) {
3870 TRACE("(IID_nsIFactory %p)\n", result
);
3875 nsIFactory_AddRef(iface
);
3879 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
3880 return NS_NOINTERFACE
;
3883 static nsrefcnt NSAPI
nsIOServiceFactory_AddRef(nsIFactory
*iface
)
3888 static nsrefcnt NSAPI
nsIOServiceFactory_Release(nsIFactory
*iface
)
3893 static nsresult NSAPI
nsIOServiceFactory_CreateInstance(nsIFactory
*iface
,
3894 nsISupports
*aOuter
, const nsIID
*iid
, void **result
)
3896 return nsIIOService_QueryInterface(&nsIOService
, iid
, result
);
3899 static nsresult NSAPI
nsIOServiceFactory_LockFactory(nsIFactory
*iface
, cpp_bool lock
)
3901 WARN("(%x)\n", lock
);
3905 static const nsIFactoryVtbl nsIOServiceFactoryVtbl
= {
3906 nsIOServiceFactory_QueryInterface
,
3907 nsIOServiceFactory_AddRef
,
3908 nsIOServiceFactory_Release
,
3909 nsIOServiceFactory_CreateInstance
,
3910 nsIOServiceFactory_LockFactory
3913 static nsIFactory nsIOServiceFactory
= { &nsIOServiceFactoryVtbl
};
3915 static BOOL
translate_url(HTMLDocumentObj
*doc
, nsWineURI
*uri
)
3917 OLECHAR
*new_url
= NULL
;
3922 if(!doc
->hostui
|| !ensure_uri(uri
))
3925 hres
= IUri_GetDisplayUri(uri
->uri
, &url
);
3929 hres
= IDocHostUIHandler_TranslateUrl(doc
->hostui
, 0, url
, &new_url
);
3930 if(hres
== S_OK
&& new_url
) {
3931 if(strcmpW(url
, new_url
)) {
3932 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url
), debugstr_w(new_url
));
3935 CoTaskMemFree(new_url
);
3942 nsresult
on_start_uri_open(NSContainer
*nscontainer
, nsIURI
*uri
, cpp_bool
*_retval
)
3944 nsWineURI
*wine_uri
;
3949 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
3950 if(NS_FAILED(nsres
)) {
3951 WARN("Could not get nsWineURI: %08x\n", nsres
);
3952 return NS_ERROR_NOT_IMPLEMENTED
;
3955 if(!wine_uri
->is_doc_uri
) {
3956 wine_uri
->is_doc_uri
= TRUE
;
3958 if(!wine_uri
->container
) {
3959 nsIWebBrowserChrome_AddRef(&nscontainer
->nsIWebBrowserChrome_iface
);
3960 wine_uri
->container
= nscontainer
;
3963 if(nscontainer
->doc
)
3964 *_retval
= translate_url(nscontainer
->doc
, wine_uri
);
3967 nsIFileURL_Release(&wine_uri
->nsIFileURL_iface
);
3971 void init_nsio(nsIComponentManager
*component_manager
, nsIComponentRegistrar
*registrar
)
3973 nsIFactory
*old_factory
= NULL
;
3976 nsres
= nsIComponentManager_GetClassObject(component_manager
, &NS_IOSERVICE_CID
,
3977 &IID_nsIFactory
, (void**)&old_factory
);
3978 if(NS_FAILED(nsres
)) {
3979 ERR("Could not get factory: %08x\n", nsres
);
3983 nsres
= nsIFactory_CreateInstance(old_factory
, NULL
, &IID_nsIIOService
, (void**)&nsio
);
3984 if(NS_FAILED(nsres
)) {
3985 ERR("Couldn not create nsIOService instance %08x\n", nsres
);
3986 nsIFactory_Release(old_factory
);
3990 nsres
= nsIIOService_QueryInterface(nsio
, &IID_nsINetUtil
, (void**)&net_util
);
3991 if(NS_FAILED(nsres
)) {
3992 WARN("Could not get nsINetUtil interface: %08x\n", nsres
);
3993 nsIIOService_Release(nsio
);
3997 nsres
= nsIComponentRegistrar_UnregisterFactory(registrar
, &NS_IOSERVICE_CID
, old_factory
);
3998 nsIFactory_Release(old_factory
);
3999 if(NS_FAILED(nsres
))
4000 ERR("UnregisterFactory failed: %08x\n", nsres
);
4002 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_IOSERVICE_CID
,
4003 NS_IOSERVICE_CLASSNAME
, NS_IOSERVICE_CONTRACTID
, &nsIOServiceFactory
);
4004 if(NS_FAILED(nsres
))
4005 ERR("RegisterFactory failed: %08x\n", nsres
);
4008 void release_nsio(void)
4011 nsINetUtil_Release(net_util
);
4016 nsIIOService_Release(nsio
);