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
, nsChannelBSC
*channelbsc
, DWORD flags
)
273 nsIWebNavigation
*web_navigation
;
274 nsIDocShell
*doc_shell
;
275 HTMLDocumentNode
*doc
;
278 nsres
= get_nsinterface((nsISupports
*)window
->nswindow
, &IID_nsIWebNavigation
, (void**)&web_navigation
);
279 if(NS_FAILED(nsres
)) {
280 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
284 nsres
= nsIWebNavigation_QueryInterface(web_navigation
, &IID_nsIDocShell
, (void**)&doc_shell
);
285 nsIWebNavigation_Release(web_navigation
);
286 if(NS_FAILED(nsres
)) {
287 ERR("Could not get nsIDocShell: %08x\n", nsres
);
291 uri
->channel_bsc
= channelbsc
;
292 doc
= window
->base
.inner_window
->doc
;
293 doc
->skip_mutation_notif
= TRUE
;
294 nsres
= nsIDocShell_LoadURI(doc_shell
, (nsIURI
*)&uri
->nsIFileURL_iface
, NULL
, flags
, FALSE
);
295 if(doc
== window
->base
.inner_window
->doc
)
296 doc
->skip_mutation_notif
= FALSE
;
297 uri
->channel_bsc
= NULL
;
298 nsIDocShell_Release(doc_shell
);
299 if(NS_FAILED(nsres
)) {
300 WARN("LoadURI failed: %08x\n", nsres
);
307 static void set_uri_nscontainer(nsWineURI
*This
, NSContainer
*nscontainer
)
309 if(This
->container
) {
310 if(This
->container
== nscontainer
)
312 TRACE("Changing %p -> %p\n", This
->container
, nscontainer
);
313 nsIWebBrowserChrome_Release(&This
->container
->nsIWebBrowserChrome_iface
);
317 nsIWebBrowserChrome_AddRef(&nscontainer
->nsIWebBrowserChrome_iface
);
318 This
->container
= nscontainer
;
321 static void set_uri_window(nsWineURI
*This
, HTMLOuterWindow
*window
)
323 if(This
->window_ref
) {
324 if(This
->window_ref
->window
== window
)
326 TRACE("Changing %p -> %p\n", This
->window_ref
->window
, window
);
327 windowref_release(This
->window_ref
);
331 windowref_addref(window
->window_ref
);
332 This
->window_ref
= window
->window_ref
;
335 set_uri_nscontainer(This
, window
->doc_obj
->nscontainer
);
337 This
->window_ref
= NULL
;
341 static inline BOOL
is_http_channel(nsChannel
*This
)
343 return This
->uri
->scheme
== URL_SCHEME_HTTP
|| This
->uri
->scheme
== URL_SCHEME_HTTPS
;
346 static http_header_t
*find_http_header(struct list
*headers
, const WCHAR
*name
, int len
)
350 LIST_FOR_EACH_ENTRY(iter
, headers
, http_header_t
, entry
) {
351 if(!strcmpiW(iter
->header
, name
))
358 static nsresult
get_channel_http_header(struct list
*headers
, const nsACString
*header_name_str
,
361 const char *header_namea
;
362 http_header_t
*header
;
366 nsACString_GetData(header_name_str
, &header_namea
);
367 header_name
= heap_strdupAtoW(header_namea
);
369 return NS_ERROR_UNEXPECTED
;
371 header
= find_http_header(headers
, header_name
, strlenW(header_name
));
372 heap_free(header_name
);
374 return NS_ERROR_NOT_AVAILABLE
;
376 data
= heap_strdupWtoA(header
->data
);
378 return NS_ERROR_UNEXPECTED
;
380 TRACE("%s -> %s\n", debugstr_a(header_namea
), debugstr_a(data
));
381 nsACString_SetData(_retval
, data
);
386 HRESULT
set_http_header(struct list
*headers
, const WCHAR
*name
, int name_len
,
387 const WCHAR
*value
, int value_len
)
389 http_header_t
*header
;
391 TRACE("%s: %s\n", debugstr_wn(name
, name_len
), debugstr_wn(value
, value_len
));
393 header
= find_http_header(headers
, name
, name_len
);
397 new_data
= heap_strndupW(value
, value_len
);
399 return E_OUTOFMEMORY
;
401 heap_free(header
->data
);
402 header
->data
= new_data
;
404 header
= heap_alloc(sizeof(http_header_t
));
406 return E_OUTOFMEMORY
;
408 header
->header
= heap_strndupW(name
, name_len
);
409 header
->data
= heap_strndupW(value
, value_len
);
410 if(!header
->header
|| !header
->data
) {
411 heap_free(header
->header
);
412 heap_free(header
->data
);
414 return E_OUTOFMEMORY
;
417 list_add_tail(headers
, &header
->entry
);
423 static nsresult
set_channel_http_header(struct list
*headers
, const nsACString
*name_str
,
424 const nsACString
*value_str
)
426 const char *namea
, *valuea
;
430 nsACString_GetData(name_str
, &namea
);
431 name
= heap_strdupAtoW(namea
);
433 return NS_ERROR_UNEXPECTED
;
435 nsACString_GetData(value_str
, &valuea
);
436 value
= heap_strdupAtoW(valuea
);
439 return NS_ERROR_UNEXPECTED
;
442 hres
= set_http_header(headers
, name
, strlenW(name
), value
, strlenW(value
));
446 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_UNEXPECTED
;
449 static nsresult
visit_http_headers(struct list
*headers
, nsIHttpHeaderVisitor
*visitor
)
451 nsACString header_str
, value_str
;
452 char *header
, *value
;
456 LIST_FOR_EACH_ENTRY(iter
, headers
, http_header_t
, entry
) {
457 header
= heap_strdupWtoA(iter
->header
);
459 return NS_ERROR_OUT_OF_MEMORY
;
461 value
= heap_strdupWtoA(iter
->data
);
464 return NS_ERROR_OUT_OF_MEMORY
;
467 nsACString_InitDepend(&header_str
, header
);
468 nsACString_InitDepend(&value_str
, value
);
469 nsres
= nsIHttpHeaderVisitor_VisitHeader(visitor
, &header_str
, &value_str
);
470 nsACString_Finish(&header_str
);
471 nsACString_Finish(&value_str
);
481 static void free_http_headers(struct list
*list
)
483 http_header_t
*iter
, *iter_next
;
485 LIST_FOR_EACH_ENTRY_SAFE(iter
, iter_next
, list
, http_header_t
, entry
) {
486 list_remove(&iter
->entry
);
487 heap_free(iter
->header
);
488 heap_free(iter
->data
);
493 static inline nsChannel
*impl_from_nsIHttpChannel(nsIHttpChannel
*iface
)
495 return CONTAINING_RECORD(iface
, nsChannel
, nsIHttpChannel_iface
);
498 static nsresult NSAPI
nsChannel_QueryInterface(nsIHttpChannel
*iface
, nsIIDRef riid
, void **result
)
500 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
502 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
503 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
504 *result
= &This
->nsIHttpChannel_iface
;
505 }else if(IsEqualGUID(&IID_nsIRequest
, riid
)) {
506 TRACE("(%p)->(IID_nsIRequest %p)\n", This
, result
);
507 *result
= &This
->nsIHttpChannel_iface
;
508 }else if(IsEqualGUID(&IID_nsIChannel
, riid
)) {
509 TRACE("(%p)->(IID_nsIChannel %p)\n", This
, result
);
510 *result
= &This
->nsIHttpChannel_iface
;
511 }else if(IsEqualGUID(&IID_nsIHttpChannel
, riid
)) {
512 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This
, result
);
513 *result
= is_http_channel(This
) ? &This
->nsIHttpChannel_iface
: NULL
;
514 }else if(IsEqualGUID(&IID_nsIUploadChannel
, riid
)) {
515 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This
, result
);
516 *result
= &This
->nsIUploadChannel_iface
;
517 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal
, riid
)) {
518 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This
, result
);
519 *result
= is_http_channel(This
) ? &This
->nsIHttpChannelInternal_iface
: NULL
;
521 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
526 nsIHttpChannel_AddRef(&This
->nsIHttpChannel_iface
);
530 return NS_NOINTERFACE
;
533 static nsrefcnt NSAPI
nsChannel_AddRef(nsIHttpChannel
*iface
)
535 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
536 nsrefcnt ref
= InterlockedIncrement(&This
->ref
);
538 TRACE("(%p) ref=%d\n", This
, ref
);
543 static nsrefcnt NSAPI
nsChannel_Release(nsIHttpChannel
*iface
)
545 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
546 LONG ref
= InterlockedDecrement(&This
->ref
);
549 nsIFileURL_Release(&This
->uri
->nsIFileURL_iface
);
551 nsISupports_Release(This
->owner
);
552 if(This
->post_data_stream
)
553 nsIInputStream_Release(This
->post_data_stream
);
555 nsILoadGroup_Release(This
->load_group
);
556 if(This
->notif_callback
)
557 nsIInterfaceRequestor_Release(This
->notif_callback
);
558 if(This
->original_uri
)
559 nsIURI_Release(This
->original_uri
);
561 nsIURI_Release(This
->referrer
);
563 free_http_headers(&This
->response_headers
);
564 free_http_headers(&This
->request_headers
);
566 heap_free(This
->content_type
);
567 heap_free(This
->charset
);
574 static nsresult NSAPI
nsChannel_GetName(nsIHttpChannel
*iface
, nsACString
*aName
)
576 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
578 TRACE("(%p)->(%p)\n", This
, aName
);
580 return nsIFileURL_GetSpec(&This
->uri
->nsIFileURL_iface
, aName
);
583 static nsresult NSAPI
nsChannel_IsPending(nsIHttpChannel
*iface
, cpp_bool
*_retval
)
585 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
587 FIXME("(%p)->(%p)\n", This
, _retval
);
589 return NS_ERROR_NOT_IMPLEMENTED
;
592 static nsresult NSAPI
nsChannel_GetStatus(nsIHttpChannel
*iface
, nsresult
*aStatus
)
594 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
596 WARN("(%p)->(%p) returning NS_OK\n", This
, aStatus
);
598 return *aStatus
= NS_OK
;
601 static nsresult NSAPI
nsChannel_Cancel(nsIHttpChannel
*iface
, nsresult aStatus
)
603 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
605 FIXME("(%p)->(%08x)\n", This
, aStatus
);
607 return NS_ERROR_NOT_IMPLEMENTED
;
610 static nsresult NSAPI
nsChannel_Suspend(nsIHttpChannel
*iface
)
612 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
614 FIXME("(%p)\n", This
);
616 return NS_ERROR_NOT_IMPLEMENTED
;
619 static nsresult NSAPI
nsChannel_Resume(nsIHttpChannel
*iface
)
621 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
623 FIXME("(%p)\n", This
);
625 return NS_ERROR_NOT_IMPLEMENTED
;
628 static nsresult NSAPI
nsChannel_GetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
**aLoadGroup
)
630 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
632 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
635 nsILoadGroup_AddRef(This
->load_group
);
637 *aLoadGroup
= This
->load_group
;
641 static nsresult NSAPI
nsChannel_SetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
*aLoadGroup
)
643 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
645 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
648 nsILoadGroup_Release(This
->load_group
);
650 nsILoadGroup_AddRef(aLoadGroup
);
651 This
->load_group
= aLoadGroup
;
656 static nsresult NSAPI
nsChannel_GetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags
*aLoadFlags
)
658 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
660 TRACE("(%p)->(%p)\n", This
, aLoadFlags
);
662 *aLoadFlags
= This
->load_flags
;
666 static nsresult NSAPI
nsChannel_SetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags aLoadFlags
)
668 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
670 TRACE("(%p)->(%08x)\n", This
, aLoadFlags
);
672 This
->load_flags
= aLoadFlags
;
676 static nsresult NSAPI
nsChannel_GetOriginalURI(nsIHttpChannel
*iface
, nsIURI
**aOriginalURI
)
678 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
680 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
682 if(This
->original_uri
)
683 nsIURI_AddRef(This
->original_uri
);
685 *aOriginalURI
= This
->original_uri
;
689 static nsresult NSAPI
nsChannel_SetOriginalURI(nsIHttpChannel
*iface
, nsIURI
*aOriginalURI
)
691 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
693 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
695 if(This
->original_uri
)
696 nsIURI_Release(This
->original_uri
);
698 nsIURI_AddRef(aOriginalURI
);
699 This
->original_uri
= aOriginalURI
;
703 static nsresult NSAPI
nsChannel_GetURI(nsIHttpChannel
*iface
, nsIURI
**aURI
)
705 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
707 TRACE("(%p)->(%p)\n", This
, aURI
);
709 nsIFileURL_AddRef(&This
->uri
->nsIFileURL_iface
);
710 *aURI
= (nsIURI
*)This
->uri
;
715 static nsresult NSAPI
nsChannel_GetOwner(nsIHttpChannel
*iface
, nsISupports
**aOwner
)
717 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
719 TRACE("(%p)->(%p)\n", This
, aOwner
);
722 nsISupports_AddRef(This
->owner
);
723 *aOwner
= This
->owner
;
728 static nsresult NSAPI
nsChannel_SetOwner(nsIHttpChannel
*iface
, nsISupports
*aOwner
)
730 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
732 TRACE("(%p)->(%p)\n", This
, aOwner
);
735 nsISupports_AddRef(aOwner
);
737 nsISupports_Release(This
->owner
);
738 This
->owner
= aOwner
;
743 static nsresult NSAPI
nsChannel_GetNotificationCallbacks(nsIHttpChannel
*iface
,
744 nsIInterfaceRequestor
**aNotificationCallbacks
)
746 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
748 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
750 if(This
->notif_callback
)
751 nsIInterfaceRequestor_AddRef(This
->notif_callback
);
752 *aNotificationCallbacks
= This
->notif_callback
;
757 static nsresult NSAPI
nsChannel_SetNotificationCallbacks(nsIHttpChannel
*iface
,
758 nsIInterfaceRequestor
*aNotificationCallbacks
)
760 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
762 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
764 if(This
->notif_callback
)
765 nsIInterfaceRequestor_Release(This
->notif_callback
);
766 if(aNotificationCallbacks
)
767 nsIInterfaceRequestor_AddRef(aNotificationCallbacks
);
769 This
->notif_callback
= aNotificationCallbacks
;
774 static nsresult NSAPI
nsChannel_GetSecurityInfo(nsIHttpChannel
*iface
, nsISupports
**aSecurityInfo
)
776 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
778 TRACE("(%p)->(%p)\n", This
, aSecurityInfo
);
780 return NS_ERROR_NOT_IMPLEMENTED
;
783 static nsresult NSAPI
nsChannel_GetContentType(nsIHttpChannel
*iface
, nsACString
*aContentType
)
785 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
787 TRACE("(%p)->(%p)\n", This
, aContentType
);
789 if(This
->content_type
) {
790 nsACString_SetData(aContentType
, This
->content_type
);
794 if(This
->uri
->is_doc_uri
) {
795 WARN("Document channel with no MIME set. Assuming text/html\n");
796 nsACString_SetData(aContentType
, "text/html");
800 WARN("unknown type\n");
801 return NS_ERROR_FAILURE
;
804 static nsresult NSAPI
nsChannel_SetContentType(nsIHttpChannel
*iface
,
805 const nsACString
*aContentType
)
807 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
808 const char *content_type
;
810 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentType
));
812 nsACString_GetData(aContentType
, &content_type
);
813 heap_free(This
->content_type
);
814 This
->content_type
= heap_strdupA(content_type
);
819 static nsresult NSAPI
nsChannel_GetContentCharset(nsIHttpChannel
*iface
,
820 nsACString
*aContentCharset
)
822 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
824 TRACE("(%p)->(%p)\n", This
, aContentCharset
);
827 nsACString_SetData(aContentCharset
, This
->charset
);
831 nsACString_SetData(aContentCharset
, "");
835 static nsresult NSAPI
nsChannel_SetContentCharset(nsIHttpChannel
*iface
,
836 const nsACString
*aContentCharset
)
838 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
842 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentCharset
));
844 nsACString_GetData(aContentCharset
, &data
);
845 charset
= heap_strdupA(data
);
847 return NS_ERROR_OUT_OF_MEMORY
;
849 heap_free(This
->charset
);
850 This
->charset
= charset
;
854 static nsresult NSAPI
nsChannel_GetContentLength(nsIHttpChannel
*iface
, INT64
*aContentLength
)
856 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
858 FIXME("(%p)->(%p)\n", This
, aContentLength
);
860 return NS_ERROR_NOT_IMPLEMENTED
;
863 static nsresult NSAPI
nsChannel_SetContentLength(nsIHttpChannel
*iface
, INT64 aContentLength
)
865 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
867 FIXME("(%p)->(%s)\n", This
, wine_dbgstr_longlong(aContentLength
));
869 return NS_ERROR_NOT_IMPLEMENTED
;
872 static nsresult NSAPI
nsChannel_Open(nsIHttpChannel
*iface
, nsIInputStream
**_retval
)
874 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
876 FIXME("(%p)->(%p)\n", This
, _retval
);
878 return NS_ERROR_NOT_IMPLEMENTED
;
881 static HTMLOuterWindow
*get_window_from_load_group(nsChannel
*This
)
883 HTMLOuterWindow
*window
;
890 nsres
= nsILoadGroup_GetDefaultLoadRequest(This
->load_group
, &req
);
891 if(NS_FAILED(nsres
)) {
892 ERR("GetDefaultLoadRequest failed: %08x\n", nsres
);
899 nsres
= nsIRequest_QueryInterface(req
, &IID_nsIChannel
, (void**)&channel
);
900 nsIRequest_Release(req
);
901 if(NS_FAILED(nsres
)) {
902 WARN("Could not get nsIChannel interface: %08x\n", nsres
);
906 nsres
= nsIChannel_GetURI(channel
, &uri
);
907 nsIChannel_Release(channel
);
908 if(NS_FAILED(nsres
)) {
909 ERR("GetURI failed: %08x\n", nsres
);
913 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
915 if(NS_FAILED(nsres
)) {
916 TRACE("Could not get nsWineURI: %08x\n", nsres
);
920 window
= wine_uri
->window_ref
? wine_uri
->window_ref
->window
: NULL
;
922 IHTMLWindow2_AddRef(&window
->base
.IHTMLWindow2_iface
);
923 nsIFileURL_Release(&wine_uri
->nsIFileURL_iface
);
928 static HTMLOuterWindow
*get_channel_window(nsChannel
*This
)
930 nsIWebProgress
*web_progress
;
931 nsIDOMWindow
*nswindow
;
932 HTMLOuterWindow
*window
;
935 if(This
->load_group
) {
936 nsIRequestObserver
*req_observer
;
938 nsres
= nsILoadGroup_GetGroupObserver(This
->load_group
, &req_observer
);
939 if(NS_FAILED(nsres
) || !req_observer
) {
940 ERR("GetGroupObserver failed: %08x\n", nsres
);
944 nsres
= nsIRequestObserver_QueryInterface(req_observer
, &IID_nsIWebProgress
, (void**)&web_progress
);
945 nsIRequestObserver_Release(req_observer
);
946 if(NS_FAILED(nsres
)) {
947 ERR("Could not get nsIWebProgress iface: %08x\n", nsres
);
950 }else if(This
->notif_callback
) {
951 nsres
= nsIInterfaceRequestor_GetInterface(This
->notif_callback
, &IID_nsIWebProgress
, (void**)&web_progress
);
952 if(NS_FAILED(nsres
)) {
953 ERR("GetInterface(IID_nsIWebProgress failed: %08x\n", nsres
);
957 ERR("no load group nor notif callback\n");
961 nsres
= nsIWebProgress_GetDOMWindow(web_progress
, &nswindow
);
962 nsIWebProgress_Release(web_progress
);
963 if(NS_FAILED(nsres
) || !nswindow
) {
964 ERR("GetDOMWindow failed: %08x\n", nsres
);
968 window
= nswindow_to_window(nswindow
);
969 nsIDOMWindow_Release(nswindow
);
972 IHTMLWindow2_AddRef(&window
->base
.IHTMLWindow2_iface
);
974 FIXME("NULL window for %p\n", nswindow
);
980 HTMLInnerWindow
*window
;
981 nsChannelBSC
*bscallback
;
982 } start_binding_task_t
;
984 static void start_binding_proc(task_t
*_task
)
986 start_binding_task_t
*task
= (start_binding_task_t
*)_task
;
988 start_binding(task
->window
, (BSCallback
*)task
->bscallback
, NULL
);
991 static void start_binding_task_destr(task_t
*_task
)
993 start_binding_task_t
*task
= (start_binding_task_t
*)_task
;
995 IBindStatusCallback_Release(&task
->bscallback
->bsc
.IBindStatusCallback_iface
);
999 static nsresult
async_open(nsChannel
*This
, HTMLOuterWindow
*window
, BOOL is_doc_channel
, nsIStreamListener
*listener
,
1000 nsISupports
*context
)
1002 nsChannelBSC
*bscallback
;
1003 IMoniker
*mon
= NULL
;
1006 hres
= CreateURLMonikerEx2(NULL
, This
->uri
->uri
, &mon
, 0);
1008 WARN("CreateURLMoniker failed: %08x\n", hres
);
1009 return NS_ERROR_UNEXPECTED
;
1013 set_current_mon(window
, mon
, BINDING_NAVIGATED
);
1015 hres
= create_channelbsc(mon
, NULL
, NULL
, 0, is_doc_channel
, &bscallback
);
1016 IMoniker_Release(mon
);
1018 return NS_ERROR_UNEXPECTED
;
1020 channelbsc_set_channel(bscallback
, This
, listener
, context
);
1022 if(is_doc_channel
) {
1023 hres
= create_pending_window(window
, bscallback
);
1025 async_start_doc_binding(window
, window
->pending_window
);
1026 IBindStatusCallback_Release(&bscallback
->bsc
.IBindStatusCallback_iface
);
1028 return NS_ERROR_UNEXPECTED
;
1030 start_binding_task_t
*task
;
1032 task
= heap_alloc(sizeof(start_binding_task_t
));
1034 IBindStatusCallback_Release(&bscallback
->bsc
.IBindStatusCallback_iface
);
1035 return NS_ERROR_OUT_OF_MEMORY
;
1038 task
->window
= window
->base
.inner_window
;
1039 task
->bscallback
= bscallback
;
1040 hres
= push_task(&task
->header
, start_binding_proc
, start_binding_task_destr
, window
->base
.inner_window
->task_magic
);
1042 return NS_ERROR_OUT_OF_MEMORY
;
1048 static nsresult NSAPI
nsChannel_AsyncOpen(nsIHttpChannel
*iface
, nsIStreamListener
*aListener
,
1049 nsISupports
*aContext
)
1051 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1052 HTMLOuterWindow
*window
= NULL
;
1053 BOOL cancel
= FALSE
;
1054 nsresult nsres
= NS_OK
;
1056 TRACE("(%p)->(%p %p)\n", This
, aListener
, aContext
);
1058 if(!ensure_uri(This
->uri
))
1059 return NS_ERROR_FAILURE
;
1061 if(TRACE_ON(mshtml
)) {
1065 hres
= IUri_GetDisplayUri(This
->uri
->uri
, &uri_str
);
1066 if(SUCCEEDED(hres
)) {
1067 TRACE("opening %s\n", debugstr_w(uri_str
));
1068 SysFreeString(uri_str
);
1070 WARN("GetDisplayUri failed: %08x\n", hres
);
1074 if(This
->uri
->is_doc_uri
) {
1075 window
= get_channel_window(This
);
1077 set_uri_window(This
->uri
, window
);
1078 }else if(This
->uri
->container
) {
1081 /* nscontainer->doc should be NULL which means navigation to a new window */
1082 if(This
->uri
->container
->doc
)
1083 FIXME("nscontainer->doc = %p\n", This
->uri
->container
->doc
);
1085 nsres
= before_async_open(This
, This
->uri
->container
, &b
);
1086 if(NS_FAILED(nsres
))
1089 FIXME("Navigation not cancelled\n");
1090 return NS_ERROR_UNEXPECTED
;
1095 if(This
->uri
->window_ref
&& This
->uri
->window_ref
->window
) {
1096 window
= This
->uri
->window_ref
->window
;
1097 IHTMLWindow2_AddRef(&window
->base
.IHTMLWindow2_iface
);
1099 /* FIXME: Analyze removing get_window_from_load_group call */
1100 if(This
->load_group
)
1101 window
= get_window_from_load_group(This
);
1103 window
= get_channel_window(This
);
1105 set_uri_window(This
->uri
, window
);
1110 ERR("window = NULL\n");
1111 return NS_ERROR_UNEXPECTED
;
1114 if(This
->uri
->is_doc_uri
&& window
== window
->doc_obj
->basedoc
.window
) {
1115 if(This
->uri
->channel_bsc
) {
1116 channelbsc_set_channel(This
->uri
->channel_bsc
, This
, aListener
, aContext
);
1118 if(window
->doc_obj
->mime
) {
1119 heap_free(This
->content_type
);
1120 This
->content_type
= heap_strdupWtoA(window
->doc_obj
->mime
);
1125 nsres
= before_async_open(This
, window
->doc_obj
->nscontainer
, &cancel
);
1126 if(NS_SUCCEEDED(nsres
) && cancel
) {
1127 TRACE("canceled\n");
1128 nsres
= NS_BINDING_ABORTED
;
1134 nsres
= async_open(This
, window
, This
->uri
->is_doc_uri
, aListener
, aContext
);
1136 if(NS_SUCCEEDED(nsres
) && This
->load_group
) {
1137 nsres
= nsILoadGroup_AddRequest(This
->load_group
, (nsIRequest
*)&This
->nsIHttpChannel_iface
,
1139 if(NS_FAILED(nsres
))
1140 ERR("AddRequest failed: %08x\n", nsres
);
1143 IHTMLWindow2_Release(&window
->base
.IHTMLWindow2_iface
);
1147 static nsresult NSAPI
nsChannel_GetContentDisposition(nsIHttpChannel
*iface
, UINT32
*aContentDisposition
)
1149 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1150 FIXME("(%p)->(%p)\n", This
, aContentDisposition
);
1151 return NS_ERROR_NOT_IMPLEMENTED
;
1154 static nsresult NSAPI
nsChannel_SetContentDisposition(nsIHttpChannel
*iface
, UINT32 aContentDisposition
)
1156 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1157 FIXME("(%p)->(%u)\n", This
, aContentDisposition
);
1158 return NS_ERROR_NOT_IMPLEMENTED
;
1161 static nsresult NSAPI
nsChannel_GetContentDispositionFilename(nsIHttpChannel
*iface
, nsAString
*aContentDispositionFilename
)
1163 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1164 FIXME("(%p)->(%p)\n", This
, aContentDispositionFilename
);
1165 return NS_ERROR_NOT_IMPLEMENTED
;
1168 static nsresult NSAPI
nsChannel_SetContentDispositionFilename(nsIHttpChannel
*iface
, const nsAString
*aContentDispositionFilename
)
1170 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1171 FIXME("(%p)->(%p)\n", This
, aContentDispositionFilename
);
1172 return NS_ERROR_NOT_IMPLEMENTED
;
1175 static nsresult NSAPI
nsChannel_GetContentDispositionHeader(nsIHttpChannel
*iface
, nsACString
*aContentDispositionHeader
)
1177 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1178 FIXME("(%p)->(%p)\n", This
, aContentDispositionHeader
);
1179 return NS_ERROR_NOT_IMPLEMENTED
;
1182 static nsresult NSAPI
nsChannel_GetRequestMethod(nsIHttpChannel
*iface
, nsACString
*aRequestMethod
)
1184 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1186 TRACE("(%p)->(%p)\n", This
, aRequestMethod
);
1188 nsACString_SetData(aRequestMethod
, request_method_strings
[This
->request_method
]);
1192 static nsresult NSAPI
nsChannel_SetRequestMethod(nsIHttpChannel
*iface
,
1193 const nsACString
*aRequestMethod
)
1195 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1199 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRequestMethod
));
1201 nsACString_GetData(aRequestMethod
, &method
);
1202 for(i
=0; i
< sizeof(request_method_strings
)/sizeof(*request_method_strings
); i
++) {
1203 if(!strcasecmp(method
, request_method_strings
[i
])) {
1204 This
->request_method
= i
;
1209 ERR("Invalid method %s\n", debugstr_a(method
));
1210 return NS_ERROR_UNEXPECTED
;
1213 static nsresult NSAPI
nsChannel_GetReferrer(nsIHttpChannel
*iface
, nsIURI
**aReferrer
)
1215 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1217 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1220 nsIURI_AddRef(This
->referrer
);
1221 *aReferrer
= This
->referrer
;
1225 static nsresult NSAPI
nsChannel_SetReferrer(nsIHttpChannel
*iface
, nsIURI
*aReferrer
)
1227 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1229 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1232 nsIURI_AddRef(aReferrer
);
1234 nsIURI_Release(This
->referrer
);
1235 This
->referrer
= aReferrer
;
1239 static nsresult NSAPI
nsChannel_GetRequestHeader(nsIHttpChannel
*iface
,
1240 const nsACString
*aHeader
, nsACString
*_retval
)
1242 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1244 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aHeader
), _retval
);
1246 return get_channel_http_header(&This
->request_headers
, aHeader
, _retval
);
1249 static nsresult NSAPI
nsChannel_SetRequestHeader(nsIHttpChannel
*iface
,
1250 const nsACString
*aHeader
, const nsACString
*aValue
, cpp_bool aMerge
)
1252 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1254 TRACE("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(aHeader
), debugstr_nsacstr(aValue
), aMerge
);
1257 FIXME("aMerge not supported\n");
1259 return set_channel_http_header(&This
->request_headers
, aHeader
, aValue
);
1262 static nsresult NSAPI
nsChannel_VisitRequestHeaders(nsIHttpChannel
*iface
,
1263 nsIHttpHeaderVisitor
*aVisitor
)
1265 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1267 FIXME("(%p)->(%p)\n", This
, aVisitor
);
1269 return NS_ERROR_NOT_IMPLEMENTED
;
1272 static nsresult NSAPI
nsChannel_GetAllowPipelining(nsIHttpChannel
*iface
, cpp_bool
*aAllowPipelining
)
1274 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1276 FIXME("(%p)->(%p)\n", This
, aAllowPipelining
);
1278 return NS_ERROR_NOT_IMPLEMENTED
;
1281 static nsresult NSAPI
nsChannel_SetAllowPipelining(nsIHttpChannel
*iface
, cpp_bool aAllowPipelining
)
1283 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1285 FIXME("(%p)->(%x)\n", This
, aAllowPipelining
);
1287 return NS_ERROR_NOT_IMPLEMENTED
;
1290 static nsresult NSAPI
nsChannel_GetRedirectionLimit(nsIHttpChannel
*iface
, UINT32
*aRedirectionLimit
)
1292 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1294 FIXME("(%p)->(%p)\n", This
, aRedirectionLimit
);
1296 return NS_ERROR_NOT_IMPLEMENTED
;
1299 static nsresult NSAPI
nsChannel_SetRedirectionLimit(nsIHttpChannel
*iface
, UINT32 aRedirectionLimit
)
1301 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1303 FIXME("(%p)->(%u)\n", This
, aRedirectionLimit
);
1305 return NS_ERROR_NOT_IMPLEMENTED
;
1308 static nsresult NSAPI
nsChannel_GetResponseStatus(nsIHttpChannel
*iface
, UINT32
*aResponseStatus
)
1310 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1312 TRACE("(%p)->(%p)\n", This
, aResponseStatus
);
1314 if(This
->response_status
) {
1315 *aResponseStatus
= This
->response_status
;
1319 WARN("No response status\n");
1320 return NS_ERROR_UNEXPECTED
;
1323 static nsresult NSAPI
nsChannel_GetResponseStatusText(nsIHttpChannel
*iface
,
1324 nsACString
*aResponseStatusText
)
1326 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1328 FIXME("(%p)->(%p)\n", This
, aResponseStatusText
);
1330 return NS_ERROR_NOT_IMPLEMENTED
;
1333 static nsresult NSAPI
nsChannel_GetRequestSucceeded(nsIHttpChannel
*iface
,
1334 cpp_bool
*aRequestSucceeded
)
1336 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1338 TRACE("(%p)->(%p)\n", This
, aRequestSucceeded
);
1340 if(!This
->response_status
)
1341 return NS_ERROR_NOT_AVAILABLE
;
1343 *aRequestSucceeded
= This
->response_status
/100 == 2;
1348 static nsresult NSAPI
nsChannel_GetResponseHeader(nsIHttpChannel
*iface
,
1349 const nsACString
*header
, nsACString
*_retval
)
1351 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1353 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(header
), _retval
);
1355 return get_channel_http_header(&This
->response_headers
, header
, _retval
);
1358 static nsresult NSAPI
nsChannel_SetResponseHeader(nsIHttpChannel
*iface
,
1359 const nsACString
*header
, const nsACString
*value
, cpp_bool merge
)
1361 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1363 FIXME("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(header
), debugstr_nsacstr(value
), merge
);
1365 return NS_ERROR_NOT_IMPLEMENTED
;
1368 static nsresult NSAPI
nsChannel_VisitResponseHeaders(nsIHttpChannel
*iface
,
1369 nsIHttpHeaderVisitor
*aVisitor
)
1371 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1373 TRACE("(%p)->(%p)\n", This
, aVisitor
);
1375 return visit_http_headers(&This
->response_headers
, aVisitor
);
1378 static nsresult NSAPI
nsChannel_IsNoStoreResponse(nsIHttpChannel
*iface
, cpp_bool
*_retval
)
1380 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1381 http_header_t
*header
;
1383 static const WCHAR cache_controlW
[] = {'C','a','c','h','e','-','C','o','n','t','r','o','l'};
1384 static const WCHAR no_storeW
[] = {'n','o','-','s','t','o','r','e',0};
1386 TRACE("(%p)->(%p)\n", This
, _retval
);
1388 header
= find_http_header(&This
->response_headers
, cache_controlW
, sizeof(cache_controlW
)/sizeof(WCHAR
));
1389 *_retval
= header
&& !strcmpiW(header
->data
, no_storeW
);
1393 static nsresult NSAPI
nsChannel_IsNoCacheResponse(nsIHttpChannel
*iface
, cpp_bool
*_retval
)
1395 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1397 FIXME("(%p)->(%p)\n", This
, _retval
);
1399 return NS_ERROR_NOT_IMPLEMENTED
;
1402 static nsresult NSAPI
nsChannel_RedirectTo(nsIHttpChannel
*iface
, nsIURI
*aNewURI
)
1404 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1406 FIXME("(%p)->(%p)\n", This
, aNewURI
);
1408 return NS_ERROR_NOT_IMPLEMENTED
;
1411 static const nsIHttpChannelVtbl nsChannelVtbl
= {
1412 nsChannel_QueryInterface
,
1416 nsChannel_IsPending
,
1417 nsChannel_GetStatus
,
1421 nsChannel_GetLoadGroup
,
1422 nsChannel_SetLoadGroup
,
1423 nsChannel_GetLoadFlags
,
1424 nsChannel_SetLoadFlags
,
1425 nsChannel_GetOriginalURI
,
1426 nsChannel_SetOriginalURI
,
1430 nsChannel_GetNotificationCallbacks
,
1431 nsChannel_SetNotificationCallbacks
,
1432 nsChannel_GetSecurityInfo
,
1433 nsChannel_GetContentType
,
1434 nsChannel_SetContentType
,
1435 nsChannel_GetContentCharset
,
1436 nsChannel_SetContentCharset
,
1437 nsChannel_GetContentLength
,
1438 nsChannel_SetContentLength
,
1440 nsChannel_AsyncOpen
,
1441 nsChannel_GetContentDisposition
,
1442 nsChannel_SetContentDisposition
,
1443 nsChannel_GetContentDispositionFilename
,
1444 nsChannel_SetContentDispositionFilename
,
1445 nsChannel_GetContentDispositionHeader
,
1446 nsChannel_GetRequestMethod
,
1447 nsChannel_SetRequestMethod
,
1448 nsChannel_GetReferrer
,
1449 nsChannel_SetReferrer
,
1450 nsChannel_GetRequestHeader
,
1451 nsChannel_SetRequestHeader
,
1452 nsChannel_VisitRequestHeaders
,
1453 nsChannel_GetAllowPipelining
,
1454 nsChannel_SetAllowPipelining
,
1455 nsChannel_GetRedirectionLimit
,
1456 nsChannel_SetRedirectionLimit
,
1457 nsChannel_GetResponseStatus
,
1458 nsChannel_GetResponseStatusText
,
1459 nsChannel_GetRequestSucceeded
,
1460 nsChannel_GetResponseHeader
,
1461 nsChannel_SetResponseHeader
,
1462 nsChannel_VisitResponseHeaders
,
1463 nsChannel_IsNoStoreResponse
,
1464 nsChannel_IsNoCacheResponse
,
1465 nsChannel_RedirectTo
1468 static inline nsChannel
*impl_from_nsIUploadChannel(nsIUploadChannel
*iface
)
1470 return CONTAINING_RECORD(iface
, nsChannel
, nsIUploadChannel_iface
);
1473 static nsresult NSAPI
nsUploadChannel_QueryInterface(nsIUploadChannel
*iface
, nsIIDRef riid
,
1476 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1477 return nsIHttpChannel_QueryInterface(&This
->nsIHttpChannel_iface
, riid
, result
);
1480 static nsrefcnt NSAPI
nsUploadChannel_AddRef(nsIUploadChannel
*iface
)
1482 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1483 return nsIHttpChannel_AddRef(&This
->nsIHttpChannel_iface
);
1486 static nsrefcnt NSAPI
nsUploadChannel_Release(nsIUploadChannel
*iface
)
1488 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1489 return nsIHttpChannel_Release(&This
->nsIHttpChannel_iface
);
1492 static nsresult NSAPI
nsUploadChannel_SetUploadStream(nsIUploadChannel
*iface
,
1493 nsIInputStream
*aStream
, const nsACString
*aContentType
, INT64 aContentLength
)
1495 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1496 const char *content_type
;
1498 static const WCHAR content_typeW
[] =
1499 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1501 TRACE("(%p)->(%p %s %s)\n", This
, aStream
, debugstr_nsacstr(aContentType
), wine_dbgstr_longlong(aContentLength
));
1503 This
->post_data_contains_headers
= TRUE
;
1506 nsACString_GetData(aContentType
, &content_type
);
1510 ct
= heap_strdupAtoW(content_type
);
1512 return NS_ERROR_UNEXPECTED
;
1514 set_http_header(&This
->request_headers
, content_typeW
,
1515 sizeof(content_typeW
)/sizeof(WCHAR
), ct
, strlenW(ct
));
1517 This
->post_data_contains_headers
= FALSE
;
1521 if(aContentLength
!= -1)
1522 FIXME("Unsupported acontentLength = %s\n", wine_dbgstr_longlong(aContentLength
));
1524 if(This
->post_data_stream
)
1525 nsIInputStream_Release(This
->post_data_stream
);
1526 This
->post_data_stream
= aStream
;
1528 nsIInputStream_AddRef(aStream
);
1530 This
->request_method
= METHOD_POST
;
1534 static nsresult NSAPI
nsUploadChannel_GetUploadStream(nsIUploadChannel
*iface
,
1535 nsIInputStream
**aUploadStream
)
1537 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1539 TRACE("(%p)->(%p)\n", This
, aUploadStream
);
1541 if(This
->post_data_stream
)
1542 nsIInputStream_AddRef(This
->post_data_stream
);
1544 *aUploadStream
= This
->post_data_stream
;
1548 static const nsIUploadChannelVtbl nsUploadChannelVtbl
= {
1549 nsUploadChannel_QueryInterface
,
1550 nsUploadChannel_AddRef
,
1551 nsUploadChannel_Release
,
1552 nsUploadChannel_SetUploadStream
,
1553 nsUploadChannel_GetUploadStream
1556 static inline nsChannel
*impl_from_nsIHttpChannelInternal(nsIHttpChannelInternal
*iface
)
1558 return CONTAINING_RECORD(iface
, nsChannel
, nsIHttpChannelInternal_iface
);
1561 static nsresult NSAPI
nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal
*iface
, nsIIDRef riid
,
1564 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1565 return nsIHttpChannel_QueryInterface(&This
->nsIHttpChannel_iface
, riid
, result
);
1568 static nsrefcnt NSAPI
nsHttpChannelInternal_AddRef(nsIHttpChannelInternal
*iface
)
1570 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1571 return nsIHttpChannel_AddRef(&This
->nsIHttpChannel_iface
);
1574 static nsrefcnt NSAPI
nsHttpChannelInternal_Release(nsIHttpChannelInternal
*iface
)
1576 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1577 return nsIHttpChannel_Release(&This
->nsIHttpChannel_iface
);
1580 static nsresult NSAPI
nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
**aDocumentURI
)
1582 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1584 FIXME("(%p)->()\n", This
);
1586 return NS_ERROR_NOT_IMPLEMENTED
;
1589 static nsresult NSAPI
nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
*aDocumentURI
)
1591 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1593 FIXME("(%p)->()\n", This
);
1595 return NS_ERROR_NOT_IMPLEMENTED
;
1598 static nsresult NSAPI
nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal
*iface
, UINT32
*major
, UINT32
*minor
)
1600 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1602 FIXME("(%p)->()\n", This
);
1604 return NS_ERROR_NOT_IMPLEMENTED
;
1607 static nsresult NSAPI
nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal
*iface
, UINT32
*major
, UINT32
*minor
)
1609 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1611 FIXME("(%p)->()\n", This
);
1613 return NS_ERROR_NOT_IMPLEMENTED
;
1616 static nsresult NSAPI
nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal
*iface
, const char *aCookieHeader
)
1618 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1620 FIXME("(%p)->()\n", This
);
1622 return NS_ERROR_NOT_IMPLEMENTED
;
1625 static nsresult NSAPI
nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal
*iface
, const char *aFallbackKey
)
1627 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1629 FIXME("(%p)->()\n", This
);
1631 return NS_ERROR_NOT_IMPLEMENTED
;
1634 static nsresult NSAPI
nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, cpp_bool
*aForceThirdPartyCookie
)
1636 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1638 FIXME("(%p)->()\n", This
);
1640 return NS_ERROR_NOT_IMPLEMENTED
;
1643 static nsresult NSAPI
nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, cpp_bool aForceThirdPartyCookie
)
1645 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1647 FIXME("(%p)->()\n", This
);
1649 return NS_ERROR_NOT_IMPLEMENTED
;
1652 static nsresult NSAPI
nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal
*iface
, cpp_bool
*aCanceled
)
1654 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1656 FIXME("(%p)->(%p)\n", This
, aCanceled
);
1658 return NS_ERROR_NOT_IMPLEMENTED
;
1661 static nsresult NSAPI
nsHttpChannelInternal_GetChannelIsForDownload(nsIHttpChannelInternal
*iface
, cpp_bool
*aCanceled
)
1663 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1665 FIXME("(%p)->(%p)\n", This
, aCanceled
);
1667 return NS_ERROR_NOT_IMPLEMENTED
;
1670 static nsresult NSAPI
nsHttpChannelInternal_SetChannelIsForDownload(nsIHttpChannelInternal
*iface
, cpp_bool aCanceled
)
1672 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1674 FIXME("(%p)->(%x)\n", This
, aCanceled
);
1676 return NS_ERROR_NOT_IMPLEMENTED
;
1679 static nsresult NSAPI
nsHttpChannelInternal_GetLocalAddress(nsIHttpChannelInternal
*iface
, nsACString
*aLocalAddress
)
1681 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1683 FIXME("(%p)->(%p)\n", This
, aLocalAddress
);
1685 return NS_ERROR_NOT_IMPLEMENTED
;
1688 static nsresult NSAPI
nsHttpChannelInternal_GetLocalPort(nsIHttpChannelInternal
*iface
, LONG
*aLocalPort
)
1690 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1692 FIXME("(%p)->(%p)\n", This
, aLocalPort
);
1694 return NS_ERROR_NOT_IMPLEMENTED
;
1697 static nsresult NSAPI
nsHttpChannelInternal_GetRemoteAddress(nsIHttpChannelInternal
*iface
, nsACString
*aRemoteAddress
)
1699 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1701 FIXME("(%p)->(%p)\n", This
, aRemoteAddress
);
1703 return NS_ERROR_NOT_IMPLEMENTED
;
1706 static nsresult NSAPI
nsHttpChannelInternal_GetRemotePort(nsIHttpChannelInternal
*iface
, LONG
*aRemotePort
)
1708 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1710 FIXME("(%p)->(%p)\n", This
, aRemotePort
);
1712 return NS_ERROR_NOT_IMPLEMENTED
;
1715 static nsresult NSAPI
nsHttpChannelInternal_SetCacheKeysRedirectChain(nsIHttpChannelInternal
*iface
, void *cacheKeys
)
1717 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1719 FIXME("(%p)->(%p)\n", This
, cacheKeys
);
1721 return NS_ERROR_NOT_IMPLEMENTED
;
1724 static nsresult NSAPI
nsHttpChannelInternal_HTTPUpgrade(nsIHttpChannelInternal
*iface
,
1725 const nsACString
*aProtocolName
, nsIHttpUpgradeListener
*aListener
)
1727 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1728 FIXME("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aProtocolName
), aListener
);
1729 return NS_ERROR_NOT_IMPLEMENTED
;
1732 static nsresult NSAPI
nsHttpChannelInternal_GetAllowSpdy(nsIHttpChannelInternal
*iface
, cpp_bool
*aAllowSpdy
)
1734 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1735 FIXME("(%p)->(%p)\n", This
, aAllowSpdy
);
1736 return NS_ERROR_NOT_IMPLEMENTED
;
1739 static nsresult NSAPI
nsHttpChannelInternal_SetAllowSpdy(nsIHttpChannelInternal
*iface
, cpp_bool aAllowSpdy
)
1741 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1742 FIXME("(%p)->(%x)\n", This
, aAllowSpdy
);
1743 return NS_ERROR_NOT_IMPLEMENTED
;
1746 static nsresult NSAPI
nsHttpChannelInternal_GetLoadAsBlocking(nsIHttpChannelInternal
*iface
, cpp_bool
*aLoadAsBlocking
)
1748 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1749 FIXME("(%p)->(%p)\n", This
, aLoadAsBlocking
);
1750 return NS_ERROR_NOT_IMPLEMENTED
;
1753 static nsresult NSAPI
nsHttpChannelInternal_SetLoadAsBlocking(nsIHttpChannelInternal
*iface
, cpp_bool aLoadAsBlocking
)
1755 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1756 FIXME("(%p)->(%x)\n", This
, aLoadAsBlocking
);
1757 return NS_ERROR_NOT_IMPLEMENTED
;
1760 static nsresult NSAPI
nsHttpChannelInternal_GetLoadUnblocked(nsIHttpChannelInternal
*iface
, cpp_bool
*aLoadUnblocked
)
1762 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1763 FIXME("(%p)->(%p)\n", This
, aLoadUnblocked
);
1764 return NS_ERROR_NOT_IMPLEMENTED
;
1767 static nsresult NSAPI
nsHttpChannelInternal_SetLoadUnblocked(nsIHttpChannelInternal
*iface
, cpp_bool aLoadUnblocked
)
1769 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1770 FIXME("(%p)->(%x)\n", This
, aLoadUnblocked
);
1771 return NS_ERROR_NOT_IMPLEMENTED
;
1774 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl
= {
1775 nsHttpChannelInternal_QueryInterface
,
1776 nsHttpChannelInternal_AddRef
,
1777 nsHttpChannelInternal_Release
,
1778 nsHttpChannelInternal_GetDocumentURI
,
1779 nsHttpChannelInternal_SetDocumentURI
,
1780 nsHttpChannelInternal_GetRequestVersion
,
1781 nsHttpChannelInternal_GetResponseVersion
,
1782 nsHttpChannelInternal_SetCookie
,
1783 nsHttpChannelInternal_SetupFallbackChannel
,
1784 nsHttpChannelInternal_GetForceAllowThirdPartyCookie
,
1785 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
,
1786 nsHttpChannelInternal_GetCanceled
,
1787 nsHttpChannelInternal_GetChannelIsForDownload
,
1788 nsHttpChannelInternal_SetChannelIsForDownload
,
1789 nsHttpChannelInternal_GetLocalAddress
,
1790 nsHttpChannelInternal_GetLocalPort
,
1791 nsHttpChannelInternal_GetRemoteAddress
,
1792 nsHttpChannelInternal_GetRemotePort
,
1793 nsHttpChannelInternal_SetCacheKeysRedirectChain
,
1794 nsHttpChannelInternal_HTTPUpgrade
,
1795 nsHttpChannelInternal_GetAllowSpdy
,
1796 nsHttpChannelInternal_SetAllowSpdy
,
1797 nsHttpChannelInternal_GetLoadAsBlocking
,
1798 nsHttpChannelInternal_SetLoadAsBlocking
,
1799 nsHttpChannelInternal_GetLoadUnblocked
,
1800 nsHttpChannelInternal_SetLoadUnblocked
1804 static void invalidate_uri(nsWineURI
*This
)
1807 IUri_Release(This
->uri
);
1812 static BOOL
ensure_uri_builder(nsWineURI
*This
)
1814 if(!This
->is_mutable
) {
1815 WARN("Not mutable URI\n");
1819 if(!This
->uri_builder
) {
1822 if(!ensure_uri(This
))
1825 hres
= CreateIUriBuilder(This
->uri
, 0, 0, &This
->uri_builder
);
1827 WARN("CreateIUriBuilder failed: %08x\n", hres
);
1832 invalidate_uri(This
);
1836 static nsresult
get_uri_string(nsWineURI
*This
, Uri_PROPERTY prop
, nsACString
*ret
)
1842 if(!ensure_uri(This
))
1843 return NS_ERROR_UNEXPECTED
;
1845 hres
= IUri_GetPropertyBSTR(This
->uri
, prop
, &val
, 0);
1847 WARN("GetPropertyBSTR failed: %08x\n", hres
);
1848 return NS_ERROR_UNEXPECTED
;
1851 vala
= heap_strdupWtoU(val
);
1854 return NS_ERROR_OUT_OF_MEMORY
;
1856 TRACE("ret %s\n", debugstr_a(vala
));
1857 nsACString_SetData(ret
, vala
);
1862 static inline nsWineURI
*impl_from_nsIFileURL(nsIFileURL
*iface
)
1864 return CONTAINING_RECORD(iface
, nsWineURI
, nsIFileURL_iface
);
1867 static nsresult NSAPI
nsURI_QueryInterface(nsIFileURL
*iface
, nsIIDRef riid
, void **result
)
1869 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1873 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1874 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1875 *result
= &This
->nsIFileURL_iface
;
1876 }else if(IsEqualGUID(&IID_nsIURI
, riid
)) {
1877 TRACE("(%p)->(IID_nsIURI %p)\n", This
, result
);
1878 *result
= &This
->nsIFileURL_iface
;
1879 }else if(IsEqualGUID(&IID_nsIURL
, riid
)) {
1880 TRACE("(%p)->(IID_nsIURL %p)\n", This
, result
);
1881 *result
= &This
->nsIFileURL_iface
;
1882 }else if(IsEqualGUID(&IID_nsIFileURL
, riid
)) {
1883 TRACE("(%p)->(IID_nsIFileURL %p)\n", This
, result
);
1884 *result
= This
->scheme
== URL_SCHEME_FILE
? &This
->nsIFileURL_iface
: NULL
;
1885 }else if(IsEqualGUID(&IID_nsIMutable
, riid
)) {
1886 TRACE("(%p)->(IID_nsIMutable %p)\n", This
, result
);
1887 *result
= &This
->nsIStandardURL_iface
;
1888 }else if(IsEqualGUID(&IID_nsIStandardURL
, riid
)) {
1889 TRACE("(%p)->(IID_nsIStandardURL %p)\n", This
, result
);
1890 *result
= &This
->nsIStandardURL_iface
;
1891 }else if(IsEqualGUID(&IID_nsWineURI
, riid
)) {
1892 TRACE("(%p)->(IID_nsWineURI %p)\n", This
, result
);
1897 nsIFileURL_AddRef(&This
->nsIFileURL_iface
);
1901 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1902 return NS_NOINTERFACE
;
1905 static nsrefcnt NSAPI
nsURI_AddRef(nsIFileURL
*iface
)
1907 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1908 LONG ref
= InterlockedIncrement(&This
->ref
);
1910 TRACE("(%p) ref=%d\n", This
, ref
);
1915 static nsrefcnt NSAPI
nsURI_Release(nsIFileURL
*iface
)
1917 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1918 LONG ref
= InterlockedDecrement(&This
->ref
);
1920 TRACE("(%p) ref=%d\n", This
, ref
);
1923 if(This
->window_ref
)
1924 windowref_release(This
->window_ref
);
1926 nsIWebBrowserChrome_Release(&This
->container
->nsIWebBrowserChrome_iface
);
1928 IUri_Release(This
->uri
);
1929 heap_free(This
->origin_charset
);
1936 static nsresult NSAPI
nsURI_GetSpec(nsIFileURL
*iface
, nsACString
*aSpec
)
1938 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1940 TRACE("(%p)->(%p)\n", This
, aSpec
);
1942 return get_uri_string(This
, Uri_PROPERTY_DISPLAY_URI
, aSpec
);
1945 static nsresult NSAPI
nsURI_SetSpec(nsIFileURL
*iface
, const nsACString
*aSpec
)
1947 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1953 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aSpec
));
1955 if(!This
->is_mutable
)
1956 return NS_ERROR_UNEXPECTED
;
1958 nsACString_GetData(aSpec
, &speca
);
1959 spec
= heap_strdupUtoW(speca
);
1961 return NS_ERROR_OUT_OF_MEMORY
;
1963 hres
= create_uri(spec
, 0, &uri
);
1966 WARN("create_uri failed: %08x\n", hres
);
1967 return NS_ERROR_FAILURE
;
1970 invalidate_uri(This
);
1971 if(This
->uri_builder
) {
1972 IUriBuilder_Release(This
->uri_builder
);
1973 This
->uri_builder
= NULL
;
1980 static nsresult NSAPI
nsURI_GetPrePath(nsIFileURL
*iface
, nsACString
*aPrePath
)
1982 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1983 FIXME("(%p)->(%p)\n", This
, aPrePath
);
1984 return NS_ERROR_NOT_IMPLEMENTED
;
1987 static nsresult NSAPI
nsURI_GetScheme(nsIFileURL
*iface
, nsACString
*aScheme
)
1989 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1993 TRACE("(%p)->(%p)\n", This
, aScheme
);
1995 if(!ensure_uri(This
))
1996 return NS_ERROR_UNEXPECTED
;
1998 hres
= IUri_GetScheme(This
->uri
, &scheme
);
2000 WARN("GetScheme failed: %08x\n", hres
);
2001 return NS_ERROR_UNEXPECTED
;
2004 if(scheme
== URL_SCHEME_ABOUT
) {
2005 nsACString_SetData(aScheme
, "wine");
2009 return get_uri_string(This
, Uri_PROPERTY_SCHEME_NAME
, aScheme
);
2012 static nsresult NSAPI
nsURI_SetScheme(nsIFileURL
*iface
, const nsACString
*aScheme
)
2014 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2015 const char *schemea
;
2019 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aScheme
));
2021 if(!ensure_uri_builder(This
))
2022 return NS_ERROR_UNEXPECTED
;
2024 nsACString_GetData(aScheme
, &schemea
);
2025 scheme
= heap_strdupUtoW(schemea
);
2027 return NS_ERROR_OUT_OF_MEMORY
;
2029 hres
= IUriBuilder_SetSchemeName(This
->uri_builder
, scheme
);
2032 return NS_ERROR_UNEXPECTED
;
2037 static nsresult NSAPI
nsURI_GetUserPass(nsIFileURL
*iface
, nsACString
*aUserPass
)
2039 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2043 TRACE("(%p)->(%p)\n", This
, aUserPass
);
2045 if(!ensure_uri(This
))
2046 return NS_ERROR_UNEXPECTED
;
2048 hres
= IUri_GetUserName(This
->uri
, &user
);
2050 return NS_ERROR_FAILURE
;
2052 hres
= IUri_GetPassword(This
->uri
, &pass
);
2054 SysFreeString(user
);
2055 return NS_ERROR_FAILURE
;
2058 if(*user
|| *pass
) {
2059 FIXME("Construct user:pass string\n");
2061 nsACString_SetData(aUserPass
, "");
2064 SysFreeString(user
);
2065 SysFreeString(pass
);
2069 static nsresult NSAPI
nsURI_SetUserPass(nsIFileURL
*iface
, const nsACString
*aUserPass
)
2071 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2072 WCHAR
*user
= NULL
, *pass
= NULL
, *buf
= NULL
;
2073 const char *user_pass
;
2076 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUserPass
));
2078 if(!ensure_uri_builder(This
))
2079 return NS_ERROR_UNEXPECTED
;
2081 nsACString_GetData(aUserPass
, &user_pass
);
2085 buf
= heap_strdupUtoW(user_pass
);
2087 return NS_ERROR_OUT_OF_MEMORY
;
2089 ptr
= strchrW(buf
, ':');
2092 }else if(ptr
!= buf
) {
2102 hres
= IUriBuilder_SetUserName(This
->uri_builder
, user
);
2104 hres
= IUriBuilder_SetPassword(This
->uri_builder
, pass
);
2107 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_FAILURE
;
2110 static nsresult NSAPI
nsURI_GetUsername(nsIFileURL
*iface
, nsACString
*aUsername
)
2112 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2114 TRACE("(%p)->(%p)\n", This
, aUsername
);
2116 return get_uri_string(This
, Uri_PROPERTY_USER_NAME
, aUsername
);
2119 static nsresult NSAPI
nsURI_SetUsername(nsIFileURL
*iface
, const nsACString
*aUsername
)
2121 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2126 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUsername
));
2128 if(!ensure_uri_builder(This
))
2129 return NS_ERROR_UNEXPECTED
;
2131 nsACString_GetData(aUsername
, &usera
);
2132 user
= heap_strdupUtoW(usera
);
2134 return NS_ERROR_OUT_OF_MEMORY
;
2136 hres
= IUriBuilder_SetUserName(This
->uri_builder
, user
);
2139 return NS_ERROR_UNEXPECTED
;
2144 static nsresult NSAPI
nsURI_GetPassword(nsIFileURL
*iface
, nsACString
*aPassword
)
2146 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2148 TRACE("(%p)->(%p)\n", This
, aPassword
);
2150 return get_uri_string(This
, Uri_PROPERTY_PASSWORD
, aPassword
);
2153 static nsresult NSAPI
nsURI_SetPassword(nsIFileURL
*iface
, const nsACString
*aPassword
)
2155 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2160 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPassword
));
2162 if(!ensure_uri_builder(This
))
2163 return NS_ERROR_UNEXPECTED
;
2165 nsACString_GetData(aPassword
, &passa
);
2166 pass
= heap_strdupUtoW(passa
);
2168 return NS_ERROR_OUT_OF_MEMORY
;
2170 hres
= IUriBuilder_SetPassword(This
->uri_builder
, pass
);
2173 return NS_ERROR_UNEXPECTED
;
2178 static nsresult NSAPI
nsURI_GetHostPort(nsIFileURL
*iface
, nsACString
*aHostPort
)
2180 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2186 TRACE("(%p)->(%p)\n", This
, aHostPort
);
2188 if(!ensure_uri(This
))
2189 return NS_ERROR_UNEXPECTED
;
2191 hres
= IUri_GetAuthority(This
->uri
, &val
);
2193 WARN("GetAuthority failed: %08x\n", hres
);
2194 return NS_ERROR_UNEXPECTED
;
2197 ptr
= strchrW(val
, '@');
2201 vala
= heap_strdupWtoU(ptr
);
2204 return NS_ERROR_OUT_OF_MEMORY
;
2206 TRACE("ret %s\n", debugstr_a(vala
));
2207 nsACString_SetData(aHostPort
, vala
);
2212 static nsresult NSAPI
nsURI_SetHostPort(nsIFileURL
*iface
, const nsACString
*aHostPort
)
2214 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2216 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aHostPort
));
2218 /* Not implemented by Gecko */
2219 return NS_ERROR_NOT_IMPLEMENTED
;
2222 static nsresult NSAPI
nsURI_GetHost(nsIFileURL
*iface
, nsACString
*aHost
)
2224 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2226 TRACE("(%p)->(%p)\n", This
, aHost
);
2228 return get_uri_string(This
, Uri_PROPERTY_HOST
, aHost
);
2231 static nsresult NSAPI
nsURI_SetHost(nsIFileURL
*iface
, const nsACString
*aHost
)
2233 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2238 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aHost
));
2240 if(!ensure_uri_builder(This
))
2241 return NS_ERROR_UNEXPECTED
;
2243 nsACString_GetData(aHost
, &hosta
);
2244 host
= heap_strdupUtoW(hosta
);
2246 return NS_ERROR_OUT_OF_MEMORY
;
2248 hres
= IUriBuilder_SetHost(This
->uri_builder
, host
);
2251 return NS_ERROR_UNEXPECTED
;
2256 static nsresult NSAPI
nsURI_GetPort(nsIFileURL
*iface
, LONG
*aPort
)
2258 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2262 TRACE("(%p)->(%p)\n", This
, aPort
);
2264 if(!ensure_uri(This
))
2265 return NS_ERROR_UNEXPECTED
;
2267 hres
= IUri_GetPort(This
->uri
, &port
);
2269 WARN("GetPort failed: %08x\n", hres
);
2270 return NS_ERROR_UNEXPECTED
;
2273 *aPort
= port
? port
: -1;
2277 static nsresult NSAPI
nsURI_SetPort(nsIFileURL
*iface
, LONG aPort
)
2279 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2282 TRACE("(%p)->(%d)\n", This
, aPort
);
2284 if(!ensure_uri_builder(This
))
2285 return NS_ERROR_UNEXPECTED
;
2287 hres
= IUriBuilder_SetPort(This
->uri_builder
, aPort
!= -1, aPort
);
2288 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_FAILURE
;
2291 static nsresult NSAPI
nsURI_GetPath(nsIFileURL
*iface
, nsACString
*aPath
)
2293 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2295 TRACE("(%p)->(%p)\n", This
, aPath
);
2297 return get_uri_string(This
, Uri_PROPERTY_PATH
, aPath
);
2300 static nsresult NSAPI
nsURI_SetPath(nsIFileURL
*iface
, const nsACString
*aPath
)
2302 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2307 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPath
));
2309 if(!ensure_uri_builder(This
))
2310 return NS_ERROR_UNEXPECTED
;
2312 nsACString_GetData(aPath
, &patha
);
2313 path
= heap_strdupUtoW(patha
);
2315 return NS_ERROR_OUT_OF_MEMORY
;
2317 hres
= IUriBuilder_SetPath(This
->uri_builder
, path
);
2320 return NS_ERROR_UNEXPECTED
;
2325 static nsresult NSAPI
nsURI_Equals(nsIFileURL
*iface
, nsIURI
*other
, cpp_bool
*_retval
)
2327 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2328 nsWineURI
*other_obj
;
2332 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
2334 nsres
= nsIURI_QueryInterface(other
, &IID_nsWineURI
, (void**)&other_obj
);
2335 if(NS_FAILED(nsres
)) {
2336 TRACE("Could not get nsWineURI interface\n");
2341 if(ensure_uri(This
) && ensure_uri(other_obj
)) {
2344 hres
= IUri_IsEqual(This
->uri
, other_obj
->uri
, &b
);
2345 if(SUCCEEDED(hres
)) {
2349 nsres
= NS_ERROR_FAILURE
;
2352 nsres
= NS_ERROR_UNEXPECTED
;
2355 nsIFileURL_Release(&other_obj
->nsIFileURL_iface
);
2359 static nsresult NSAPI
nsURI_SchemeIs(nsIFileURL
*iface
, const char *scheme
, cpp_bool
*_retval
)
2361 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2362 WCHAR buf
[INTERNET_MAX_SCHEME_LENGTH
];
2366 TRACE("(%p)->(%s %p)\n", This
, debugstr_a(scheme
), _retval
);
2368 if(!ensure_uri(This
))
2369 return NS_ERROR_UNEXPECTED
;
2371 hres
= IUri_GetSchemeName(This
->uri
, &scheme_name
);
2373 return NS_ERROR_UNEXPECTED
;
2375 MultiByteToWideChar(CP_UTF8
, 0, scheme
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
2376 *_retval
= !strcmpW(scheme_name
, buf
);
2377 SysFreeString(scheme_name
);
2381 static nsresult NSAPI
nsURI_Clone(nsIFileURL
*iface
, nsIURI
**_retval
)
2383 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2384 nsWineURI
*wine_uri
;
2387 TRACE("(%p)->(%p)\n", This
, _retval
);
2389 if(!ensure_uri(This
))
2390 return NS_ERROR_UNEXPECTED
;
2392 nsres
= create_nsuri(This
->uri
, This
->window_ref
? This
->window_ref
->window
: NULL
,
2393 This
->container
, This
->origin_charset
, &wine_uri
);
2394 if(NS_FAILED(nsres
)) {
2395 WARN("create_nsuri failed: %08x\n", nsres
);
2399 *_retval
= (nsIURI
*)&wine_uri
->nsIFileURL_iface
;
2403 static nsresult NSAPI
nsURI_Resolve(nsIFileURL
*iface
, const nsACString
*aRelativePath
,
2404 nsACString
*_retval
)
2406 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2414 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aRelativePath
), _retval
);
2416 if(!ensure_uri(This
))
2417 return NS_ERROR_UNEXPECTED
;
2419 nsACString_GetData(aRelativePath
, &patha
);
2420 path
= heap_strdupUtoW(patha
);
2422 return NS_ERROR_OUT_OF_MEMORY
;
2424 hres
= combine_url(This
->uri
, path
, &new_uri
);
2427 return NS_ERROR_FAILURE
;
2429 hres
= IUri_GetDisplayUri(new_uri
, &ret
);
2430 IUri_Release(new_uri
);
2432 return NS_ERROR_FAILURE
;
2434 reta
= heap_strdupWtoU(ret
);
2437 return NS_ERROR_OUT_OF_MEMORY
;
2439 TRACE("returning %s\n", debugstr_a(reta
));
2440 nsACString_SetData(_retval
, reta
);
2445 static nsresult NSAPI
nsURI_GetAsciiSpec(nsIFileURL
*iface
, nsACString
*aAsciiSpec
)
2447 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2449 TRACE("(%p)->(%p)\n", This
, aAsciiSpec
);
2451 return nsIFileURL_GetSpec(&This
->nsIFileURL_iface
, aAsciiSpec
);
2454 static nsresult NSAPI
nsURI_GetAsciiHost(nsIFileURL
*iface
, nsACString
*aAsciiHost
)
2456 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2458 WARN("(%p)->(%p) FIXME: Use Uri_PUNYCODE_IDN_HOST flag\n", This
, aAsciiHost
);
2460 return get_uri_string(This
, Uri_PROPERTY_HOST
, aAsciiHost
);
2463 static nsresult NSAPI
nsURI_GetOriginCharset(nsIFileURL
*iface
, nsACString
*aOriginCharset
)
2465 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2467 TRACE("(%p)->(%p)\n", This
, aOriginCharset
);
2469 nsACString_SetData(aOriginCharset
, This
->origin_charset
);
2473 static nsresult NSAPI
nsURL_GetRef(nsIFileURL
*iface
, nsACString
*aRef
)
2475 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2480 TRACE("(%p)->(%p)\n", This
, aRef
);
2482 if(!ensure_uri(This
))
2483 return NS_ERROR_UNEXPECTED
;
2485 hres
= IUri_GetFragment(This
->uri
, &ref
);
2487 return NS_ERROR_UNEXPECTED
;
2489 refa
= heap_strdupWtoU(ref
);
2492 return NS_ERROR_OUT_OF_MEMORY
;
2494 nsACString_SetData(aRef
, refa
&& *refa
== '#' ? refa
+1 : refa
);
2499 static nsresult NSAPI
nsURL_SetRef(nsIFileURL
*iface
, const nsACString
*aRef
)
2501 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2506 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRef
));
2508 if(!ensure_uri_builder(This
))
2509 return NS_ERROR_UNEXPECTED
;
2511 nsACString_GetData(aRef
, &refa
);
2512 ref
= heap_strdupUtoW(refa
);
2514 return NS_ERROR_OUT_OF_MEMORY
;
2516 hres
= IUriBuilder_SetFragment(This
->uri_builder
, ref
);
2519 return NS_ERROR_UNEXPECTED
;
2524 static nsresult NSAPI
nsURI_EqualsExceptRef(nsIFileURL
*iface
, nsIURI
*other
, cpp_bool
*_retval
)
2526 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2527 nsWineURI
*other_obj
;
2530 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
2532 nsres
= nsIURI_QueryInterface(other
, &IID_nsWineURI
, (void**)&other_obj
);
2533 if(NS_FAILED(nsres
)) {
2534 TRACE("Could not get nsWineURI interface\n");
2539 if(ensure_uri(This
) && ensure_uri(other_obj
)) {
2540 *_retval
= compare_ignoring_frag(This
->uri
, other_obj
->uri
);
2543 nsres
= NS_ERROR_UNEXPECTED
;
2546 nsIFileURL_Release(&other_obj
->nsIFileURL_iface
);
2550 static nsresult NSAPI
nsURI_CloneIgnoreRef(nsIFileURL
*iface
, nsIURI
**_retval
)
2552 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2553 nsWineURI
*wine_uri
;
2557 TRACE("(%p)->(%p)\n", This
, _retval
);
2559 if(!ensure_uri(This
))
2560 return NS_ERROR_UNEXPECTED
;
2562 uri
= get_uri_nofrag(This
->uri
);
2564 return NS_ERROR_FAILURE
;
2566 nsres
= create_nsuri(uri
, This
->window_ref
? This
->window_ref
->window
: NULL
, This
->container
,
2567 This
->origin_charset
, &wine_uri
);
2569 if(NS_FAILED(nsres
)) {
2570 WARN("create_nsuri failed: %08x\n", nsres
);
2574 *_retval
= (nsIURI
*)&wine_uri
->nsIFileURL_iface
;
2578 static nsresult NSAPI
nsURI_GetSpecIgnoringRef(nsIFileURL
*iface
, nsACString
*aSpecIgnoringRef
)
2580 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2582 FIXME("(%p)->(%p)\n", This
, aSpecIgnoringRef
);
2584 return nsIFileURL_GetSpec(&This
->nsIFileURL_iface
, aSpecIgnoringRef
);
2587 static nsresult NSAPI
nsURI_GetHasRef(nsIFileURL
*iface
, cpp_bool
*aHasRef
)
2589 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2593 TRACE("(%p)->(%p)\n", This
, aHasRef
);
2595 if(!ensure_uri(This
))
2596 return NS_ERROR_UNEXPECTED
;
2598 hres
= IUri_HasProperty(This
->uri
, Uri_PROPERTY_FRAGMENT
, &b
);
2600 return NS_ERROR_FAILURE
;
2606 static nsresult NSAPI
nsURL_GetFilePath(nsIFileURL
*iface
, nsACString
*aFilePath
)
2608 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2610 TRACE("(%p)->(%p)\n", This
, aFilePath
);
2612 return nsIFileURL_GetPath(&This
->nsIFileURL_iface
, aFilePath
);
2615 static nsresult NSAPI
nsURL_SetFilePath(nsIFileURL
*iface
, const nsACString
*aFilePath
)
2617 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2619 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFilePath
));
2621 if(!This
->is_mutable
)
2622 return NS_ERROR_UNEXPECTED
;
2624 return nsIFileURL_SetPath(&This
->nsIFileURL_iface
, aFilePath
);
2627 static nsresult NSAPI
nsURL_GetQuery(nsIFileURL
*iface
, nsACString
*aQuery
)
2629 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2631 TRACE("(%p)->(%p)\n", This
, aQuery
);
2633 return get_uri_string(This
, Uri_PROPERTY_QUERY
, aQuery
);
2636 static nsresult NSAPI
nsURL_SetQuery(nsIFileURL
*iface
, const nsACString
*aQuery
)
2638 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2643 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aQuery
));
2645 if(!ensure_uri_builder(This
))
2646 return NS_ERROR_UNEXPECTED
;
2648 nsACString_GetData(aQuery
, &querya
);
2649 query
= heap_strdupUtoW(querya
);
2651 return NS_ERROR_OUT_OF_MEMORY
;
2653 hres
= IUriBuilder_SetQuery(This
->uri_builder
, query
);
2656 return NS_ERROR_UNEXPECTED
;
2661 static nsresult
get_uri_path(nsWineURI
*This
, BSTR
*path
, const WCHAR
**file
, const WCHAR
**ext
)
2666 if(!ensure_uri(This
))
2667 return NS_ERROR_UNEXPECTED
;
2669 hres
= IUri_GetPath(This
->uri
, path
);
2671 return NS_ERROR_FAILURE
;
2673 for(ptr
= *path
+ SysStringLen(*path
)-1; ptr
> *path
&& *ptr
!= '/' && *ptr
!= '\\'; ptr
--);
2674 if(*ptr
== '/' || *ptr
== '\\')
2679 ptr
= strrchrW(ptr
, '.');
2681 ptr
= *path
+ SysStringLen(*path
);
2688 static nsresult NSAPI
nsURL_GetDirectory(nsIFileURL
*iface
, nsACString
*aDirectory
)
2690 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2695 TRACE("(%p)->(%p)\n", This
, aDirectory
);
2697 nsres
= get_uri_path(This
, &path
, &file
, NULL
);
2698 if(NS_FAILED(nsres
))
2701 nsres
= return_wstr_nsacstr(aDirectory
, path
, file
-path
);
2702 SysFreeString(path
);
2706 static nsresult NSAPI
nsURL_SetDirectory(nsIFileURL
*iface
, const nsACString
*aDirectory
)
2708 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2710 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aDirectory
));
2712 /* Not implemented by Gecko */
2713 return NS_ERROR_NOT_IMPLEMENTED
;
2716 static nsresult NSAPI
nsURL_GetFileName(nsIFileURL
*iface
, nsACString
*aFileName
)
2718 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2723 TRACE("(%p)->(%p)\n", This
, aFileName
);
2725 nsres
= get_uri_path(This
, &path
, &file
, NULL
);
2726 if(NS_FAILED(nsres
))
2729 nsres
= return_wstr_nsacstr(aFileName
, file
, -1);
2730 SysFreeString(path
);
2734 static nsresult NSAPI
nsURL_SetFileName(nsIFileURL
*iface
, const nsACString
*aFileName
)
2736 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2737 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileName
));
2738 return NS_ERROR_NOT_IMPLEMENTED
;
2741 static nsresult NSAPI
nsURL_GetFileBaseName(nsIFileURL
*iface
, nsACString
*aFileBaseName
)
2743 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2744 const WCHAR
*file
, *ext
;
2748 TRACE("(%p)->(%p)\n", This
, aFileBaseName
);
2750 nsres
= get_uri_path(This
, &path
, &file
, &ext
);
2751 if(NS_FAILED(nsres
))
2754 nsres
= return_wstr_nsacstr(aFileBaseName
, file
, ext
-file
);
2755 SysFreeString(path
);
2759 static nsresult NSAPI
nsURL_SetFileBaseName(nsIFileURL
*iface
, const nsACString
*aFileBaseName
)
2761 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2762 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileBaseName
));
2763 return NS_ERROR_NOT_IMPLEMENTED
;
2766 static nsresult NSAPI
nsURL_GetFileExtension(nsIFileURL
*iface
, nsACString
*aFileExtension
)
2768 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2770 TRACE("(%p)->(%p)\n", This
, aFileExtension
);
2772 return get_uri_string(This
, Uri_PROPERTY_EXTENSION
, aFileExtension
);
2775 static nsresult NSAPI
nsURL_SetFileExtension(nsIFileURL
*iface
, const nsACString
*aFileExtension
)
2777 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2778 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileExtension
));
2779 return NS_ERROR_NOT_IMPLEMENTED
;
2782 static nsresult NSAPI
nsURL_GetCommonBaseSpec(nsIFileURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2784 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2785 FIXME("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2786 return NS_ERROR_NOT_IMPLEMENTED
;
2789 static nsresult NSAPI
nsURL_GetRelativeSpec(nsIFileURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2791 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2792 FIXME("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2793 return NS_ERROR_NOT_IMPLEMENTED
;
2796 static nsresult NSAPI
nsFileURL_GetFile(nsIFileURL
*iface
, nsIFile
**aFile
)
2798 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2799 WCHAR path
[MAX_PATH
];
2803 TRACE("(%p)->(%p)\n", This
, aFile
);
2805 hres
= CoInternetParseIUri(This
->uri
, PARSE_PATH_FROM_URL
, 0, path
, sizeof(path
)/sizeof(WCHAR
), &size
, 0);
2807 WARN("CoInternetParseIUri failed: %08x\n", hres
);
2808 return NS_ERROR_FAILURE
;
2811 return create_nsfile(path
, aFile
);
2814 static nsresult NSAPI
nsFileURL_SetFile(nsIFileURL
*iface
, nsIFile
*aFile
)
2816 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2817 FIXME("(%p)->(%p)\n", This
, aFile
);
2818 return NS_ERROR_NOT_IMPLEMENTED
;
2821 static const nsIFileURLVtbl nsFileURLVtbl
= {
2822 nsURI_QueryInterface
,
2850 nsURI_GetOriginCharset
,
2853 nsURI_EqualsExceptRef
,
2854 nsURI_CloneIgnoreRef
,
2855 nsURI_GetSpecIgnoringRef
,
2865 nsURL_GetFileBaseName
,
2866 nsURL_SetFileBaseName
,
2867 nsURL_GetFileExtension
,
2868 nsURL_SetFileExtension
,
2869 nsURL_GetCommonBaseSpec
,
2870 nsURL_GetRelativeSpec
,
2875 static inline nsWineURI
*impl_from_nsIStandardURL(nsIStandardURL
*iface
)
2877 return CONTAINING_RECORD(iface
, nsWineURI
, nsIStandardURL_iface
);
2880 static nsresult NSAPI
nsStandardURL_QueryInterface(nsIStandardURL
*iface
, nsIIDRef riid
,
2883 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2884 return nsIFileURL_QueryInterface(&This
->nsIFileURL_iface
, riid
, result
);
2887 static nsrefcnt NSAPI
nsStandardURL_AddRef(nsIStandardURL
*iface
)
2889 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2890 return nsIFileURL_AddRef(&This
->nsIFileURL_iface
);
2893 static nsrefcnt NSAPI
nsStandardURL_Release(nsIStandardURL
*iface
)
2895 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2896 return nsIFileURL_Release(&This
->nsIFileURL_iface
);
2899 static nsresult NSAPI
nsStandardURL_GetMutable(nsIStandardURL
*iface
, cpp_bool
*aMutable
)
2901 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2903 TRACE("(%p)->(%p)\n", This
, aMutable
);
2905 *aMutable
= This
->is_mutable
;
2909 static nsresult NSAPI
nsStandardURL_SetMutable(nsIStandardURL
*iface
, cpp_bool aMutable
)
2911 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2913 TRACE("(%p)->(%x)\n", This
, aMutable
);
2915 This
->is_mutable
= aMutable
;
2919 static nsresult NSAPI
nsStandardURL_Init(nsIStandardURL
*iface
, UINT32 aUrlType
, LONG aDefaultPort
,
2920 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
)
2922 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2923 FIXME("(%p)->(%d %d %s %s %p)\n", This
, aUrlType
, aDefaultPort
, debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
), aBaseURI
);
2924 return NS_ERROR_NOT_IMPLEMENTED
;
2927 static const nsIStandardURLVtbl nsStandardURLVtbl
= {
2928 nsStandardURL_QueryInterface
,
2929 nsStandardURL_AddRef
,
2930 nsStandardURL_Release
,
2931 nsStandardURL_GetMutable
,
2932 nsStandardURL_SetMutable
,
2936 static nsresult
create_nsuri(IUri
*iuri
, HTMLOuterWindow
*window
, NSContainer
*container
,
2937 const char *origin_charset
, nsWineURI
**_retval
)
2942 ret
= heap_alloc_zero(sizeof(nsWineURI
));
2944 return NS_ERROR_OUT_OF_MEMORY
;
2946 ret
->nsIFileURL_iface
.lpVtbl
= &nsFileURLVtbl
;
2947 ret
->nsIStandardURL_iface
.lpVtbl
= &nsStandardURLVtbl
;
2949 ret
->is_mutable
= TRUE
;
2951 set_uri_nscontainer(ret
, container
);
2952 set_uri_window(ret
, window
);
2957 hres
= IUri_GetScheme(iuri
, &ret
->scheme
);
2959 ret
->scheme
= URL_SCHEME_UNKNOWN
;
2961 if(origin_charset
&& *origin_charset
&& strcmp(origin_charset
, "UTF-8")) {
2962 ret
->origin_charset
= heap_strdupA(origin_charset
);
2963 if(!ret
->origin_charset
) {
2964 nsIFileURL_Release(&ret
->nsIFileURL_iface
);
2965 return NS_ERROR_OUT_OF_MEMORY
;
2969 TRACE("retval=%p\n", ret
);
2974 HRESULT
create_doc_uri(HTMLOuterWindow
*window
, IUri
*iuri
, nsWineURI
**ret
)
2979 nsres
= create_nsuri(iuri
, window
, window
->doc_obj
->nscontainer
, NULL
, &uri
);
2980 if(NS_FAILED(nsres
))
2983 uri
->is_doc_uri
= TRUE
;
2989 static nsresult
create_nschannel(nsWineURI
*uri
, nsChannel
**ret
)
2993 if(!ensure_uri(uri
))
2994 return NS_ERROR_UNEXPECTED
;
2996 channel
= heap_alloc_zero(sizeof(nsChannel
));
2998 return NS_ERROR_OUT_OF_MEMORY
;
3000 channel
->nsIHttpChannel_iface
.lpVtbl
= &nsChannelVtbl
;
3001 channel
->nsIUploadChannel_iface
.lpVtbl
= &nsUploadChannelVtbl
;
3002 channel
->nsIHttpChannelInternal_iface
.lpVtbl
= &nsHttpChannelInternalVtbl
;
3004 channel
->request_method
= METHOD_GET
;
3005 list_init(&channel
->response_headers
);
3006 list_init(&channel
->request_headers
);
3008 nsIFileURL_AddRef(&uri
->nsIFileURL_iface
);
3015 HRESULT
create_redirect_nschannel(const WCHAR
*url
, nsChannel
*orig_channel
, nsChannel
**ret
)
3017 HTMLOuterWindow
*window
= NULL
;
3024 hres
= create_uri(url
, 0, &iuri
);
3028 if(orig_channel
->uri
->window_ref
)
3029 window
= orig_channel
->uri
->window_ref
->window
;
3030 nsres
= create_nsuri(iuri
, window
, NULL
, NULL
, &uri
);
3032 if(NS_FAILED(nsres
))
3035 nsres
= create_nschannel(uri
, &channel
);
3036 nsIFileURL_Release(&uri
->nsIFileURL_iface
);
3037 if(NS_FAILED(nsres
))
3040 if(orig_channel
->load_group
) {
3041 nsILoadGroup_AddRef(orig_channel
->load_group
);
3042 channel
->load_group
= orig_channel
->load_group
;
3045 if(orig_channel
->notif_callback
) {
3046 nsIInterfaceRequestor_AddRef(orig_channel
->notif_callback
);
3047 channel
->notif_callback
= orig_channel
->notif_callback
;
3050 channel
->load_flags
= orig_channel
->load_flags
| LOAD_REPLACE
;
3052 if(orig_channel
->request_method
== METHOD_POST
)
3053 FIXME("unsupported POST method\n");
3055 if(orig_channel
->original_uri
) {
3056 nsIURI_AddRef(orig_channel
->original_uri
);
3057 channel
->original_uri
= orig_channel
->original_uri
;
3060 if(orig_channel
->referrer
) {
3061 nsIURI_AddRef(orig_channel
->referrer
);
3062 channel
->referrer
= orig_channel
->referrer
;
3070 nsIProtocolHandler nsIProtocolHandler_iface
;
3074 nsIProtocolHandler
*nshandler
;
3075 } nsProtocolHandler
;
3077 static inline nsProtocolHandler
*impl_from_nsIProtocolHandler(nsIProtocolHandler
*iface
)
3079 return CONTAINING_RECORD(iface
, nsProtocolHandler
, nsIProtocolHandler_iface
);
3082 static nsresult NSAPI
nsProtocolHandler_QueryInterface(nsIProtocolHandler
*iface
, nsIIDRef riid
,
3085 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3089 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
3090 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
3091 *result
= &This
->nsIProtocolHandler_iface
;
3092 }else if(IsEqualGUID(&IID_nsIProtocolHandler
, riid
)) {
3093 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This
, result
);
3094 *result
= &This
->nsIProtocolHandler_iface
;
3095 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler
, riid
)) {
3096 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This
, result
);
3097 return NS_NOINTERFACE
;
3101 nsISupports_AddRef((nsISupports
*)*result
);
3105 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
3106 return NS_NOINTERFACE
;
3109 static nsrefcnt NSAPI
nsProtocolHandler_AddRef(nsIProtocolHandler
*iface
)
3111 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3112 LONG ref
= InterlockedIncrement(&This
->ref
);
3114 TRACE("(%p) ref=%d\n", This
, ref
);
3119 static nsrefcnt NSAPI
nsProtocolHandler_Release(nsIProtocolHandler
*iface
)
3121 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3122 LONG ref
= InterlockedDecrement(&This
->ref
);
3124 TRACE("(%p) ref=%d\n", This
, ref
);
3128 nsIProtocolHandler_Release(This
->nshandler
);
3135 static nsresult NSAPI
nsProtocolHandler_GetScheme(nsIProtocolHandler
*iface
, nsACString
*aScheme
)
3137 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3139 TRACE("(%p)->(%p)\n", This
, aScheme
);
3142 return nsIProtocolHandler_GetScheme(This
->nshandler
, aScheme
);
3143 return NS_ERROR_NOT_IMPLEMENTED
;
3146 static nsresult NSAPI
nsProtocolHandler_GetDefaultPort(nsIProtocolHandler
*iface
,
3149 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3151 TRACE("(%p)->(%p)\n", This
, aDefaultPort
);
3154 return nsIProtocolHandler_GetDefaultPort(This
->nshandler
, aDefaultPort
);
3155 return NS_ERROR_NOT_IMPLEMENTED
;
3158 static nsresult NSAPI
nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler
*iface
,
3159 UINT32
*aProtocolFlags
)
3161 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3163 TRACE("(%p)->(%p)\n", This
, aProtocolFlags
);
3166 return nsIProtocolHandler_GetProtocolFlags(This
->nshandler
, aProtocolFlags
);
3167 return NS_ERROR_NOT_IMPLEMENTED
;
3170 static nsresult NSAPI
nsProtocolHandler_NewURI(nsIProtocolHandler
*iface
,
3171 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
3173 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3175 TRACE("((%p)->%s %s %p %p)\n", This
, debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
3179 return nsIProtocolHandler_NewURI(This
->nshandler
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3180 return NS_ERROR_NOT_IMPLEMENTED
;
3183 static nsresult NSAPI
nsProtocolHandler_NewChannel(nsIProtocolHandler
*iface
,
3184 nsIURI
*aURI
, nsIChannel
**_retval
)
3186 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3188 TRACE("(%p)->(%p %p)\n", This
, aURI
, _retval
);
3191 return nsIProtocolHandler_NewChannel(This
->nshandler
, aURI
, _retval
);
3192 return NS_ERROR_NOT_IMPLEMENTED
;
3195 static nsresult NSAPI
nsProtocolHandler_AllowPort(nsIProtocolHandler
*iface
,
3196 LONG port
, const char *scheme
, cpp_bool
*_retval
)
3198 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3200 TRACE("(%p)->(%d %s %p)\n", This
, port
, debugstr_a(scheme
), _retval
);
3203 return nsIProtocolHandler_AllowPort(This
->nshandler
, port
, scheme
, _retval
);
3204 return NS_ERROR_NOT_IMPLEMENTED
;
3207 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl
= {
3208 nsProtocolHandler_QueryInterface
,
3209 nsProtocolHandler_AddRef
,
3210 nsProtocolHandler_Release
,
3211 nsProtocolHandler_GetScheme
,
3212 nsProtocolHandler_GetDefaultPort
,
3213 nsProtocolHandler_GetProtocolFlags
,
3214 nsProtocolHandler_NewURI
,
3215 nsProtocolHandler_NewChannel
,
3216 nsProtocolHandler_AllowPort
3219 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*,nsIIDRef
,void**);
3221 static nsrefcnt NSAPI
nsIOService_AddRef(nsIIOService
*iface
)
3226 static nsrefcnt NSAPI
nsIOService_Release(nsIIOService
*iface
)
3231 static nsresult NSAPI
nsIOService_GetProtocolHandler(nsIIOService
*iface
, const char *aScheme
,
3232 nsIProtocolHandler
**_retval
)
3234 nsIExternalProtocolHandler
*nsexthandler
;
3235 nsIProtocolHandler
*nshandler
;
3236 nsProtocolHandler
*ret
;
3239 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
3241 nsres
= nsIIOService_GetProtocolHandler(nsio
, aScheme
, &nshandler
);
3242 if(NS_FAILED(nsres
)) {
3243 WARN("GetProtocolHandler failed: %08x\n", nsres
);
3247 nsres
= nsIProtocolHandler_QueryInterface(nshandler
, &IID_nsIExternalProtocolHandler
,
3248 (void**)&nsexthandler
);
3249 if(NS_FAILED(nsres
)) {
3250 *_retval
= nshandler
;
3254 nsIExternalProtocolHandler_Release(nsexthandler
);
3256 ret
= heap_alloc(sizeof(nsProtocolHandler
));
3258 return NS_ERROR_OUT_OF_MEMORY
;
3260 ret
->nsIProtocolHandler_iface
.lpVtbl
= &nsProtocolHandlerVtbl
;
3262 ret
->nshandler
= nshandler
;
3263 *_retval
= &ret
->nsIProtocolHandler_iface
;
3265 TRACE("return %p\n", *_retval
);
3269 static nsresult NSAPI
nsIOService_GetProtocolFlags(nsIIOService
*iface
, const char *aScheme
,
3272 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
3273 return nsIIOService_GetProtocolFlags(nsio
, aScheme
, _retval
);
3276 static BOOL
is_gecko_special_uri(const char *spec
)
3278 static const char *special_schemes
[] = {"chrome:", "jar:", "moz-safe-about", "resource:", "javascript:", "wyciwyg:"};
3281 for(i
=0; i
< sizeof(special_schemes
)/sizeof(*special_schemes
); i
++) {
3282 if(!strncasecmp(spec
, special_schemes
[i
], strlen(special_schemes
[i
])))
3286 if(!strncasecmp(spec
, "file:", 5)) {
3287 const char *ptr
= spec
+5;
3290 return is_gecko_path(ptr
);
3296 static nsresult NSAPI
nsIOService_NewURI(nsIIOService
*iface
, const nsACString
*aSpec
,
3297 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
3299 nsWineURI
*wine_uri
, *base_wine_uri
= NULL
;
3300 WCHAR new_spec
[INTERNET_MAX_URL_LENGTH
];
3301 HTMLOuterWindow
*window
= NULL
;
3302 const char *spec
= NULL
;
3307 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
3310 nsACString_GetData(aSpec
, &spec
);
3311 if(is_gecko_special_uri(spec
))
3312 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3314 if(!strncmp(spec
, "wine:", 5))
3318 nsres
= nsIURI_QueryInterface(aBaseURI
, &IID_nsWineURI
, (void**)&base_wine_uri
);
3319 if(NS_SUCCEEDED(nsres
)) {
3320 if(!ensure_uri(base_wine_uri
))
3321 return NS_ERROR_UNEXPECTED
;
3322 if(base_wine_uri
->window_ref
)
3323 window
= base_wine_uri
->window_ref
->window
;
3325 WARN("Could not get base nsWineURI: %08x\n", nsres
);
3329 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, new_spec
, sizeof(new_spec
)/sizeof(WCHAR
));
3332 hres
= combine_url(base_wine_uri
->uri
, new_spec
, &urlmon_uri
);
3334 hres
= create_uri(new_spec
, 0, &urlmon_uri
);
3336 WARN("create_uri failed: %08x\n", hres
);
3340 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3342 nsres
= create_nsuri(urlmon_uri
, window
, NULL
, NULL
, &wine_uri
);
3343 IUri_Release(urlmon_uri
);
3345 nsIFileURL_Release(&base_wine_uri
->nsIFileURL_iface
);
3346 if(NS_FAILED(nsres
))
3349 *_retval
= (nsIURI
*)&wine_uri
->nsIFileURL_iface
;
3353 static nsresult NSAPI
nsIOService_NewFileURI(nsIIOService
*iface
, nsIFile
*aFile
,
3356 TRACE("(%p %p)\n", aFile
, _retval
);
3357 return nsIIOService_NewFileURI(nsio
, aFile
, _retval
);
3360 static nsresult NSAPI
nsIOService_NewChannelFromURI(nsIIOService
*iface
, nsIURI
*aURI
,
3361 nsIChannel
**_retval
)
3363 nsWineURI
*wine_uri
;
3367 TRACE("(%p %p)\n", aURI
, _retval
);
3369 nsres
= nsIURI_QueryInterface(aURI
, &IID_nsWineURI
, (void**)&wine_uri
);
3370 if(NS_FAILED(nsres
)) {
3371 TRACE("Could not get nsWineURI: %08x\n", nsres
);
3372 return nsIIOService_NewChannelFromURI(nsio
, aURI
, _retval
);
3375 nsres
= create_nschannel(wine_uri
, &ret
);
3376 nsIFileURL_Release(&wine_uri
->nsIFileURL_iface
);
3377 if(NS_FAILED(nsres
))
3380 nsIURI_AddRef(aURI
);
3381 ret
->original_uri
= aURI
;
3383 *_retval
= (nsIChannel
*)&ret
->nsIHttpChannel_iface
;
3387 static nsresult NSAPI
nsIOService_NewChannel(nsIIOService
*iface
, const nsACString
*aSpec
,
3388 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIChannel
**_retval
)
3390 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
), aBaseURI
, _retval
);
3391 return nsIIOService_NewChannel(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3394 static nsresult NSAPI
nsIOService_GetOffline(nsIIOService
*iface
, cpp_bool
*aOffline
)
3396 TRACE("(%p)\n", aOffline
);
3397 return nsIIOService_GetOffline(nsio
, aOffline
);
3400 static nsresult NSAPI
nsIOService_SetOffline(nsIIOService
*iface
, cpp_bool aOffline
)
3402 TRACE("(%x)\n", aOffline
);
3403 return nsIIOService_SetOffline(nsio
, aOffline
);
3406 static nsresult NSAPI
nsIOService_AllowPort(nsIIOService
*iface
, LONG aPort
,
3407 const char *aScheme
, cpp_bool
*_retval
)
3409 TRACE("(%d %s %p)\n", aPort
, debugstr_a(aScheme
), _retval
);
3410 return nsIIOService_AllowPort(nsio
, aPort
, debugstr_a(aScheme
), _retval
);
3413 static nsresult NSAPI
nsIOService_ExtractScheme(nsIIOService
*iface
, const nsACString
*urlString
,
3414 nsACString
* _retval
)
3416 TRACE("(%s %p)\n", debugstr_nsacstr(urlString
), _retval
);
3417 return nsIIOService_ExtractScheme(nsio
, urlString
, _retval
);
3420 static const nsIIOServiceVtbl nsIOServiceVtbl
= {
3421 nsIOService_QueryInterface
,
3423 nsIOService_Release
,
3424 nsIOService_GetProtocolHandler
,
3425 nsIOService_GetProtocolFlags
,
3427 nsIOService_NewFileURI
,
3428 nsIOService_NewChannelFromURI
,
3429 nsIOService_NewChannel
,
3430 nsIOService_GetOffline
,
3431 nsIOService_SetOffline
,
3432 nsIOService_AllowPort
,
3433 nsIOService_ExtractScheme
3436 static nsIIOService nsIOService
= { &nsIOServiceVtbl
};
3438 static nsresult NSAPI
nsNetUtil_QueryInterface(nsINetUtil
*iface
, nsIIDRef riid
,
3441 return nsIIOService_QueryInterface(&nsIOService
, riid
, result
);
3444 static nsrefcnt NSAPI
nsNetUtil_AddRef(nsINetUtil
*iface
)
3449 static nsrefcnt NSAPI
nsNetUtil_Release(nsINetUtil
*iface
)
3454 static nsresult NSAPI
nsNetUtil_ParseContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
3455 nsACString
*aCharset
, cpp_bool
*aHadCharset
, nsACString
*aContentType
)
3457 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aHadCharset
, aContentType
);
3459 return nsINetUtil_ParseContentType(net_util
, aTypeHeader
, aCharset
, aHadCharset
, aContentType
);
3462 static nsresult NSAPI
nsNetUtil_ProtocolHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, UINT32 aFlags
, cpp_bool
*_retval
)
3466 return nsINetUtil_ProtocolHasFlags(net_util
, aURI
, aFlags
, _retval
);
3469 static nsresult NSAPI
nsNetUtil_URIChainHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, UINT32 aFlags
, cpp_bool
*_retval
)
3471 TRACE("(%p %08x %p)\n", aURI
, aFlags
, _retval
);
3473 if(aFlags
== (1<<11)) {
3478 return nsINetUtil_URIChainHasFlags(net_util
, aURI
, aFlags
, _retval
);
3481 static nsresult NSAPI
nsNetUtil_ToImmutableURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
3483 TRACE("(%p %p)\n", aURI
, _retval
);
3485 return nsINetUtil_ToImmutableURI(net_util
, aURI
, _retval
);
3488 static nsresult NSAPI
nsNetUtil_NewSimpleNestedURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
3490 TRACE("(%p %p)\n", aURI
, _retval
);
3492 return nsINetUtil_NewSimpleNestedURI(net_util
, aURI
, _retval
);
3495 static nsresult NSAPI
nsNetUtil_EscapeString(nsINetUtil
*iface
, const nsACString
*aString
,
3496 UINT32 aEscapeType
, nsACString
*_retval
)
3498 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString
), aEscapeType
, _retval
);
3500 return nsINetUtil_EscapeString(net_util
, aString
, aEscapeType
, _retval
);
3503 static nsresult NSAPI
nsNetUtil_EscapeURL(nsINetUtil
*iface
, const nsACString
*aStr
, UINT32 aFlags
,
3504 nsACString
*_retval
)
3506 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
3508 return nsINetUtil_EscapeURL(net_util
, aStr
, aFlags
, _retval
);
3511 static nsresult NSAPI
nsNetUtil_UnescapeString(nsINetUtil
*iface
, const nsACString
*aStr
,
3512 UINT32 aFlags
, nsACString
*_retval
)
3514 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
3516 return nsINetUtil_UnescapeString(net_util
, aStr
, aFlags
, _retval
);
3519 static nsresult NSAPI
nsNetUtil_ExtractCharsetFromContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
3520 nsACString
*aCharset
, LONG
*aCharsetStart
, LONG
*aCharsetEnd
, cpp_bool
*_retval
)
3522 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aCharsetStart
,
3523 aCharsetEnd
, _retval
);
3525 return nsINetUtil_ExtractCharsetFromContentType(net_util
, aTypeHeader
, aCharset
, aCharsetStart
, aCharsetEnd
, _retval
);
3528 static const nsINetUtilVtbl nsNetUtilVtbl
= {
3529 nsNetUtil_QueryInterface
,
3532 nsNetUtil_ParseContentType
,
3533 nsNetUtil_ProtocolHasFlags
,
3534 nsNetUtil_URIChainHasFlags
,
3535 nsNetUtil_ToImmutableURI
,
3536 nsNetUtil_NewSimpleNestedURI
,
3537 nsNetUtil_EscapeString
,
3538 nsNetUtil_EscapeURL
,
3539 nsNetUtil_UnescapeString
,
3540 nsNetUtil_ExtractCharsetFromContentType
3543 static nsINetUtil nsNetUtil
= { &nsNetUtilVtbl
};
3545 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*iface
, nsIIDRef riid
,
3550 if(IsEqualGUID(&IID_nsISupports
, riid
))
3551 *result
= &nsIOService
;
3552 else if(IsEqualGUID(&IID_nsIIOService
, riid
))
3553 *result
= &nsIOService
;
3554 else if(IsEqualGUID(&IID_nsINetUtil
, riid
))
3555 *result
= &nsNetUtil
;
3558 nsISupports_AddRef((nsISupports
*)*result
);
3562 FIXME("(%s %p)\n", debugstr_guid(riid
), result
);
3563 return NS_NOINTERFACE
;
3566 static nsresult NSAPI
nsIOServiceFactory_QueryInterface(nsIFactory
*iface
, nsIIDRef riid
,
3571 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
3572 TRACE("(IID_nsISupports %p)\n", result
);
3574 }else if(IsEqualGUID(&IID_nsIFactory
, riid
)) {
3575 TRACE("(IID_nsIFactory %p)\n", result
);
3580 nsIFactory_AddRef(iface
);
3584 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
3585 return NS_NOINTERFACE
;
3588 static nsrefcnt NSAPI
nsIOServiceFactory_AddRef(nsIFactory
*iface
)
3593 static nsrefcnt NSAPI
nsIOServiceFactory_Release(nsIFactory
*iface
)
3598 static nsresult NSAPI
nsIOServiceFactory_CreateInstance(nsIFactory
*iface
,
3599 nsISupports
*aOuter
, const nsIID
*iid
, void **result
)
3601 return nsIIOService_QueryInterface(&nsIOService
, iid
, result
);
3604 static nsresult NSAPI
nsIOServiceFactory_LockFactory(nsIFactory
*iface
, cpp_bool lock
)
3606 WARN("(%x)\n", lock
);
3610 static const nsIFactoryVtbl nsIOServiceFactoryVtbl
= {
3611 nsIOServiceFactory_QueryInterface
,
3612 nsIOServiceFactory_AddRef
,
3613 nsIOServiceFactory_Release
,
3614 nsIOServiceFactory_CreateInstance
,
3615 nsIOServiceFactory_LockFactory
3618 static nsIFactory nsIOServiceFactory
= { &nsIOServiceFactoryVtbl
};
3620 static BOOL
translate_url(HTMLDocumentObj
*doc
, nsWineURI
*uri
)
3622 OLECHAR
*new_url
= NULL
;
3627 if(!doc
->hostui
|| !ensure_uri(uri
))
3630 hres
= IUri_GetDisplayUri(uri
->uri
, &url
);
3634 hres
= IDocHostUIHandler_TranslateUrl(doc
->hostui
, 0, url
, &new_url
);
3635 if(hres
== S_OK
&& new_url
) {
3636 if(strcmpW(url
, new_url
)) {
3637 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url
), debugstr_w(new_url
));
3640 CoTaskMemFree(new_url
);
3647 nsresult
on_start_uri_open(NSContainer
*nscontainer
, nsIURI
*uri
, cpp_bool
*_retval
)
3649 nsWineURI
*wine_uri
;
3654 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
3655 if(NS_FAILED(nsres
)) {
3656 WARN("Could not get nsWineURI: %08x\n", nsres
);
3657 return NS_ERROR_NOT_IMPLEMENTED
;
3660 if(!wine_uri
->is_doc_uri
) {
3661 wine_uri
->is_doc_uri
= TRUE
;
3663 if(!wine_uri
->container
) {
3664 nsIWebBrowserChrome_AddRef(&nscontainer
->nsIWebBrowserChrome_iface
);
3665 wine_uri
->container
= nscontainer
;
3668 if(nscontainer
->doc
)
3669 *_retval
= translate_url(nscontainer
->doc
, wine_uri
);
3672 nsIFileURL_Release(&wine_uri
->nsIFileURL_iface
);
3676 void init_nsio(nsIComponentManager
*component_manager
, nsIComponentRegistrar
*registrar
)
3678 nsIFactory
*old_factory
= NULL
;
3681 nsres
= nsIComponentManager_GetClassObject(component_manager
, &NS_IOSERVICE_CID
,
3682 &IID_nsIFactory
, (void**)&old_factory
);
3683 if(NS_FAILED(nsres
)) {
3684 ERR("Could not get factory: %08x\n", nsres
);
3688 nsres
= nsIFactory_CreateInstance(old_factory
, NULL
, &IID_nsIIOService
, (void**)&nsio
);
3689 if(NS_FAILED(nsres
)) {
3690 ERR("Couldn not create nsIOService instance %08x\n", nsres
);
3691 nsIFactory_Release(old_factory
);
3695 nsres
= nsIIOService_QueryInterface(nsio
, &IID_nsINetUtil
, (void**)&net_util
);
3696 if(NS_FAILED(nsres
)) {
3697 WARN("Could not get nsINetUtil interface: %08x\n", nsres
);
3698 nsIIOService_Release(nsio
);
3702 nsres
= nsIComponentRegistrar_UnregisterFactory(registrar
, &NS_IOSERVICE_CID
, old_factory
);
3703 nsIFactory_Release(old_factory
);
3704 if(NS_FAILED(nsres
))
3705 ERR("UnregisterFactory failed: %08x\n", nsres
);
3707 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_IOSERVICE_CID
,
3708 NS_IOSERVICE_CLASSNAME
, NS_IOSERVICE_CONTRACTID
, &nsIOServiceFactory
);
3709 if(NS_FAILED(nsres
))
3710 ERR("RegisterFactory failed: %08x\n", nsres
);
3713 void release_nsio(void)
3716 nsINetUtil_Release(net_util
);
3721 nsIIOService_Release(nsio
);