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 nsresult
create_nsuri(IUri
*,HTMLOuterWindow
*,NSContainer
*,const char*,nsWineURI
**);
146 static const char *debugstr_nsacstr(const nsACString
*nsstr
)
150 nsACString_GetData(nsstr
, &data
);
151 return debugstr_a(data
);
154 static nsresult
return_wstr_nsacstr(nsACString
*ret_str
, const WCHAR
*str
, int len
)
159 TRACE("returning %s\n", debugstr_wn(str
, len
));
162 nsACString_SetData(ret_str
, "");
166 lena
= WideCharToMultiByte(CP_UTF8
, 0, str
, len
, NULL
, 0, NULL
, NULL
);
167 stra
= heap_alloc(lena
+1);
169 return NS_ERROR_OUT_OF_MEMORY
;
171 WideCharToMultiByte(CP_UTF8
, 0, str
, len
, stra
, lena
, NULL
, NULL
);
174 nsACString_SetData(ret_str
, stra
);
179 HRESULT
nsuri_to_url(LPCWSTR nsuri
, BOOL ret_empty
, BSTR
*ret
)
181 const WCHAR
*ptr
= nsuri
;
183 static const WCHAR wine_prefixW
[] = {'w','i','n','e',':'};
185 if(!strncmpW(nsuri
, wine_prefixW
, sizeof(wine_prefixW
)/sizeof(WCHAR
)))
186 ptr
+= sizeof(wine_prefixW
)/sizeof(WCHAR
);
188 if(*ptr
|| ret_empty
) {
189 *ret
= SysAllocString(ptr
);
191 return E_OUTOFMEMORY
;
196 TRACE("%s -> %s\n", debugstr_w(nsuri
), debugstr_w(*ret
));
200 static BOOL
exec_shldocvw_67(HTMLDocumentObj
*doc
, BSTR url
)
202 IOleCommandTarget
*cmdtrg
= NULL
;
205 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
206 if(SUCCEEDED(hres
)) {
207 VARIANT varUrl
, varRes
;
209 V_VT(&varUrl
) = VT_BSTR
;
210 V_BSTR(&varUrl
) = url
;
211 V_VT(&varRes
) = VT_BOOL
;
213 hres
= IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 67, 0, &varUrl
, &varRes
);
215 IOleCommandTarget_Release(cmdtrg
);
217 if(SUCCEEDED(hres
) && !V_BOOL(&varRes
)) {
218 TRACE("got VARIANT_FALSE, do not load\n");
226 static nsresult
before_async_open(nsChannel
*channel
, NSContainer
*container
, BOOL
*cancel
)
228 HTMLDocumentObj
*doc
= container
->doc
;
237 hres
= IUri_GetDisplayUri(channel
->uri
->uri
, &display_uri
);
239 return NS_ERROR_FAILURE
;
241 if(!exec_shldocvw_67(doc
, display_uri
)) {
242 SysFreeString(display_uri
);
247 hres
= hlink_frame_navigate(&doc
->basedoc
, display_uri
, channel
, 0, cancel
);
248 SysFreeString(display_uri
);
254 HRESULT
load_nsuri(HTMLOuterWindow
*window
, nsWineURI
*uri
, nsChannelBSC
*channelbsc
, DWORD flags
)
256 nsIWebNavigation
*web_navigation
;
257 nsIDocShell
*doc_shell
;
258 HTMLDocumentNode
*doc
;
261 nsres
= get_nsinterface((nsISupports
*)window
->nswindow
, &IID_nsIWebNavigation
, (void**)&web_navigation
);
262 if(NS_FAILED(nsres
)) {
263 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
267 nsres
= nsIWebNavigation_QueryInterface(web_navigation
, &IID_nsIDocShell
, (void**)&doc_shell
);
268 nsIWebNavigation_Release(web_navigation
);
269 if(NS_FAILED(nsres
)) {
270 ERR("Could not get nsIDocShell: %08x\n", nsres
);
274 uri
->channel_bsc
= channelbsc
;
275 doc
= window
->base
.inner_window
->doc
;
276 doc
->skip_mutation_notif
= TRUE
;
277 nsres
= nsIDocShell_LoadURI(doc_shell
, (nsIURI
*)&uri
->nsIFileURL_iface
, NULL
, flags
, FALSE
);
278 if(doc
== window
->base
.inner_window
->doc
)
279 doc
->skip_mutation_notif
= FALSE
;
280 uri
->channel_bsc
= NULL
;
281 nsIDocShell_Release(doc_shell
);
282 if(NS_FAILED(nsres
)) {
283 WARN("LoadURI failed: %08x\n", nsres
);
290 static void set_uri_nscontainer(nsWineURI
*This
, NSContainer
*nscontainer
)
292 if(This
->container
) {
293 if(This
->container
== nscontainer
)
295 TRACE("Changing %p -> %p\n", This
->container
, nscontainer
);
296 nsIWebBrowserChrome_Release(&This
->container
->nsIWebBrowserChrome_iface
);
300 nsIWebBrowserChrome_AddRef(&nscontainer
->nsIWebBrowserChrome_iface
);
301 This
->container
= nscontainer
;
304 static void set_uri_window(nsWineURI
*This
, HTMLOuterWindow
*window
)
306 if(This
->window_ref
) {
307 if(This
->window_ref
->window
== window
)
309 TRACE("Changing %p -> %p\n", This
->window_ref
->window
, window
);
310 windowref_release(This
->window_ref
);
314 windowref_addref(window
->window_ref
);
315 This
->window_ref
= window
->window_ref
;
318 set_uri_nscontainer(This
, window
->doc_obj
->nscontainer
);
320 This
->window_ref
= NULL
;
324 static inline BOOL
is_http_channel(nsChannel
*This
)
326 return This
->uri
->scheme
== URL_SCHEME_HTTP
|| This
->uri
->scheme
== URL_SCHEME_HTTPS
;
329 static http_header_t
*find_http_header(struct list
*headers
, const WCHAR
*name
, int len
)
333 LIST_FOR_EACH_ENTRY(iter
, headers
, http_header_t
, entry
) {
334 if(!strcmpiW(iter
->header
, name
))
341 static nsresult
get_channel_http_header(struct list
*headers
, const nsACString
*header_name_str
,
344 const char *header_namea
;
345 http_header_t
*header
;
349 nsACString_GetData(header_name_str
, &header_namea
);
350 header_name
= heap_strdupAtoW(header_namea
);
352 return NS_ERROR_UNEXPECTED
;
354 header
= find_http_header(headers
, header_name
, strlenW(header_name
));
355 heap_free(header_name
);
357 return NS_ERROR_NOT_AVAILABLE
;
359 data
= heap_strdupWtoA(header
->data
);
361 return NS_ERROR_UNEXPECTED
;
363 TRACE("%s -> %s\n", debugstr_a(header_namea
), debugstr_a(data
));
364 nsACString_SetData(_retval
, data
);
369 HRESULT
set_http_header(struct list
*headers
, const WCHAR
*name
, int name_len
,
370 const WCHAR
*value
, int value_len
)
372 http_header_t
*header
;
374 TRACE("%s: %s\n", debugstr_wn(name
, name_len
), debugstr_wn(value
, value_len
));
376 header
= find_http_header(headers
, name
, name_len
);
380 new_data
= heap_strndupW(value
, value_len
);
382 return E_OUTOFMEMORY
;
384 heap_free(header
->data
);
385 header
->data
= new_data
;
387 header
= heap_alloc(sizeof(http_header_t
));
389 return E_OUTOFMEMORY
;
391 header
->header
= heap_strndupW(name
, name_len
);
392 header
->data
= heap_strndupW(value
, value_len
);
393 if(!header
->header
|| !header
->data
) {
394 heap_free(header
->header
);
395 heap_free(header
->data
);
397 return E_OUTOFMEMORY
;
400 list_add_tail(headers
, &header
->entry
);
406 static nsresult
set_channel_http_header(struct list
*headers
, const nsACString
*name_str
,
407 const nsACString
*value_str
)
409 const char *namea
, *valuea
;
413 nsACString_GetData(name_str
, &namea
);
414 name
= heap_strdupAtoW(namea
);
416 return NS_ERROR_UNEXPECTED
;
418 nsACString_GetData(value_str
, &valuea
);
419 value
= heap_strdupAtoW(valuea
);
422 return NS_ERROR_UNEXPECTED
;
425 hres
= set_http_header(headers
, name
, strlenW(name
), value
, strlenW(value
));
429 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_UNEXPECTED
;
432 static nsresult
visit_http_headers(struct list
*headers
, nsIHttpHeaderVisitor
*visitor
)
434 nsACString header_str
, value_str
;
435 char *header
, *value
;
439 LIST_FOR_EACH_ENTRY(iter
, headers
, http_header_t
, entry
) {
440 header
= heap_strdupWtoA(iter
->header
);
442 return NS_ERROR_OUT_OF_MEMORY
;
444 value
= heap_strdupWtoA(iter
->data
);
447 return NS_ERROR_OUT_OF_MEMORY
;
450 nsACString_InitDepend(&header_str
, header
);
451 nsACString_InitDepend(&value_str
, value
);
452 nsres
= nsIHttpHeaderVisitor_VisitHeader(visitor
, &header_str
, &value_str
);
453 nsACString_Finish(&header_str
);
454 nsACString_Finish(&value_str
);
464 static void free_http_headers(struct list
*list
)
466 http_header_t
*iter
, *iter_next
;
468 LIST_FOR_EACH_ENTRY_SAFE(iter
, iter_next
, list
, http_header_t
, entry
) {
469 list_remove(&iter
->entry
);
470 heap_free(iter
->header
);
471 heap_free(iter
->data
);
476 static inline nsChannel
*impl_from_nsIHttpChannel(nsIHttpChannel
*iface
)
478 return CONTAINING_RECORD(iface
, nsChannel
, nsIHttpChannel_iface
);
481 static nsresult NSAPI
nsChannel_QueryInterface(nsIHttpChannel
*iface
, nsIIDRef riid
, void **result
)
483 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
485 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
486 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
487 *result
= &This
->nsIHttpChannel_iface
;
488 }else if(IsEqualGUID(&IID_nsIRequest
, riid
)) {
489 TRACE("(%p)->(IID_nsIRequest %p)\n", This
, result
);
490 *result
= &This
->nsIHttpChannel_iface
;
491 }else if(IsEqualGUID(&IID_nsIChannel
, riid
)) {
492 TRACE("(%p)->(IID_nsIChannel %p)\n", This
, result
);
493 *result
= &This
->nsIHttpChannel_iface
;
494 }else if(IsEqualGUID(&IID_nsIHttpChannel
, riid
)) {
495 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This
, result
);
496 *result
= is_http_channel(This
) ? &This
->nsIHttpChannel_iface
: NULL
;
497 }else if(IsEqualGUID(&IID_nsIUploadChannel
, riid
)) {
498 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This
, result
);
499 *result
= &This
->nsIUploadChannel_iface
;
500 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal
, riid
)) {
501 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This
, result
);
502 *result
= is_http_channel(This
) ? &This
->nsIHttpChannelInternal_iface
: NULL
;
504 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
509 nsIHttpChannel_AddRef(&This
->nsIHttpChannel_iface
);
513 return NS_NOINTERFACE
;
516 static nsrefcnt NSAPI
nsChannel_AddRef(nsIHttpChannel
*iface
)
518 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
519 nsrefcnt ref
= InterlockedIncrement(&This
->ref
);
521 TRACE("(%p) ref=%d\n", This
, ref
);
526 static nsrefcnt NSAPI
nsChannel_Release(nsIHttpChannel
*iface
)
528 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
529 LONG ref
= InterlockedDecrement(&This
->ref
);
532 nsIFileURL_Release(&This
->uri
->nsIFileURL_iface
);
534 nsISupports_Release(This
->owner
);
535 if(This
->post_data_stream
)
536 nsIInputStream_Release(This
->post_data_stream
);
538 nsILoadGroup_Release(This
->load_group
);
539 if(This
->notif_callback
)
540 nsIInterfaceRequestor_Release(This
->notif_callback
);
541 if(This
->original_uri
)
542 nsIURI_Release(This
->original_uri
);
544 nsIURI_Release(This
->referrer
);
546 free_http_headers(&This
->response_headers
);
547 free_http_headers(&This
->request_headers
);
549 heap_free(This
->content_type
);
550 heap_free(This
->charset
);
557 static nsresult NSAPI
nsChannel_GetName(nsIHttpChannel
*iface
, nsACString
*aName
)
559 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
561 TRACE("(%p)->(%p)\n", This
, aName
);
563 return nsIFileURL_GetSpec(&This
->uri
->nsIFileURL_iface
, aName
);
566 static nsresult NSAPI
nsChannel_IsPending(nsIHttpChannel
*iface
, cpp_bool
*_retval
)
568 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
570 FIXME("(%p)->(%p)\n", This
, _retval
);
572 return NS_ERROR_NOT_IMPLEMENTED
;
575 static nsresult NSAPI
nsChannel_GetStatus(nsIHttpChannel
*iface
, nsresult
*aStatus
)
577 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
579 WARN("(%p)->(%p) returning NS_OK\n", This
, aStatus
);
581 return *aStatus
= NS_OK
;
584 static nsresult NSAPI
nsChannel_Cancel(nsIHttpChannel
*iface
, nsresult aStatus
)
586 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
588 FIXME("(%p)->(%08x)\n", This
, aStatus
);
590 return NS_ERROR_NOT_IMPLEMENTED
;
593 static nsresult NSAPI
nsChannel_Suspend(nsIHttpChannel
*iface
)
595 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
597 FIXME("(%p)\n", This
);
599 return NS_ERROR_NOT_IMPLEMENTED
;
602 static nsresult NSAPI
nsChannel_Resume(nsIHttpChannel
*iface
)
604 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
606 FIXME("(%p)\n", This
);
608 return NS_ERROR_NOT_IMPLEMENTED
;
611 static nsresult NSAPI
nsChannel_GetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
**aLoadGroup
)
613 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
615 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
618 nsILoadGroup_AddRef(This
->load_group
);
620 *aLoadGroup
= This
->load_group
;
624 static nsresult NSAPI
nsChannel_SetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
*aLoadGroup
)
626 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
628 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
631 nsILoadGroup_Release(This
->load_group
);
633 nsILoadGroup_AddRef(aLoadGroup
);
634 This
->load_group
= aLoadGroup
;
639 static nsresult NSAPI
nsChannel_GetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags
*aLoadFlags
)
641 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
643 TRACE("(%p)->(%p)\n", This
, aLoadFlags
);
645 *aLoadFlags
= This
->load_flags
;
649 static nsresult NSAPI
nsChannel_SetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags aLoadFlags
)
651 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
653 TRACE("(%p)->(%08x)\n", This
, aLoadFlags
);
655 This
->load_flags
= aLoadFlags
;
659 static nsresult NSAPI
nsChannel_GetOriginalURI(nsIHttpChannel
*iface
, nsIURI
**aOriginalURI
)
661 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
663 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
665 if(This
->original_uri
)
666 nsIURI_AddRef(This
->original_uri
);
668 *aOriginalURI
= This
->original_uri
;
672 static nsresult NSAPI
nsChannel_SetOriginalURI(nsIHttpChannel
*iface
, nsIURI
*aOriginalURI
)
674 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
676 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
678 if(This
->original_uri
)
679 nsIURI_Release(This
->original_uri
);
681 nsIURI_AddRef(aOriginalURI
);
682 This
->original_uri
= aOriginalURI
;
686 static nsresult NSAPI
nsChannel_GetURI(nsIHttpChannel
*iface
, nsIURI
**aURI
)
688 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
690 TRACE("(%p)->(%p)\n", This
, aURI
);
692 nsIFileURL_AddRef(&This
->uri
->nsIFileURL_iface
);
693 *aURI
= (nsIURI
*)This
->uri
;
698 static nsresult NSAPI
nsChannel_GetOwner(nsIHttpChannel
*iface
, nsISupports
**aOwner
)
700 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
702 TRACE("(%p)->(%p)\n", This
, aOwner
);
705 nsISupports_AddRef(This
->owner
);
706 *aOwner
= This
->owner
;
711 static nsresult NSAPI
nsChannel_SetOwner(nsIHttpChannel
*iface
, nsISupports
*aOwner
)
713 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
715 TRACE("(%p)->(%p)\n", This
, aOwner
);
718 nsISupports_AddRef(aOwner
);
720 nsISupports_Release(This
->owner
);
721 This
->owner
= aOwner
;
726 static nsresult NSAPI
nsChannel_GetNotificationCallbacks(nsIHttpChannel
*iface
,
727 nsIInterfaceRequestor
**aNotificationCallbacks
)
729 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
731 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
733 if(This
->notif_callback
)
734 nsIInterfaceRequestor_AddRef(This
->notif_callback
);
735 *aNotificationCallbacks
= This
->notif_callback
;
740 static nsresult NSAPI
nsChannel_SetNotificationCallbacks(nsIHttpChannel
*iface
,
741 nsIInterfaceRequestor
*aNotificationCallbacks
)
743 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
745 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
747 if(This
->notif_callback
)
748 nsIInterfaceRequestor_Release(This
->notif_callback
);
749 if(aNotificationCallbacks
)
750 nsIInterfaceRequestor_AddRef(aNotificationCallbacks
);
752 This
->notif_callback
= aNotificationCallbacks
;
757 static nsresult NSAPI
nsChannel_GetSecurityInfo(nsIHttpChannel
*iface
, nsISupports
**aSecurityInfo
)
759 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
761 TRACE("(%p)->(%p)\n", This
, aSecurityInfo
);
763 return NS_ERROR_NOT_IMPLEMENTED
;
766 static nsresult NSAPI
nsChannel_GetContentType(nsIHttpChannel
*iface
, nsACString
*aContentType
)
768 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
770 TRACE("(%p)->(%p)\n", This
, aContentType
);
772 if(This
->content_type
) {
773 nsACString_SetData(aContentType
, This
->content_type
);
777 if(This
->uri
->is_doc_uri
) {
778 WARN("Document channel with no MIME set. Assuming text/html\n");
779 nsACString_SetData(aContentType
, "text/html");
783 WARN("unknown type\n");
784 return NS_ERROR_FAILURE
;
787 static nsresult NSAPI
nsChannel_SetContentType(nsIHttpChannel
*iface
,
788 const nsACString
*aContentType
)
790 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
791 const char *content_type
;
793 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentType
));
795 nsACString_GetData(aContentType
, &content_type
);
796 heap_free(This
->content_type
);
797 This
->content_type
= heap_strdupA(content_type
);
802 static nsresult NSAPI
nsChannel_GetContentCharset(nsIHttpChannel
*iface
,
803 nsACString
*aContentCharset
)
805 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
807 TRACE("(%p)->(%p)\n", This
, aContentCharset
);
810 nsACString_SetData(aContentCharset
, This
->charset
);
814 nsACString_SetData(aContentCharset
, "");
818 static nsresult NSAPI
nsChannel_SetContentCharset(nsIHttpChannel
*iface
,
819 const nsACString
*aContentCharset
)
821 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
825 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentCharset
));
827 nsACString_GetData(aContentCharset
, &data
);
828 charset
= heap_strdupA(data
);
830 return NS_ERROR_OUT_OF_MEMORY
;
832 heap_free(This
->charset
);
833 This
->charset
= charset
;
837 static nsresult NSAPI
nsChannel_GetContentLength(nsIHttpChannel
*iface
, LONG
*aContentLength
)
839 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
841 FIXME("(%p)->(%p)\n", This
, aContentLength
);
843 return NS_ERROR_NOT_IMPLEMENTED
;
846 static nsresult NSAPI
nsChannel_SetContentLength(nsIHttpChannel
*iface
, LONG aContentLength
)
848 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
850 FIXME("(%p)->(%d)\n", This
, aContentLength
);
852 return NS_ERROR_NOT_IMPLEMENTED
;
855 static nsresult NSAPI
nsChannel_Open(nsIHttpChannel
*iface
, nsIInputStream
**_retval
)
857 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
859 FIXME("(%p)->(%p)\n", This
, _retval
);
861 return NS_ERROR_NOT_IMPLEMENTED
;
864 static HTMLOuterWindow
*get_window_from_load_group(nsChannel
*This
)
866 HTMLOuterWindow
*window
;
873 nsres
= nsILoadGroup_GetDefaultLoadRequest(This
->load_group
, &req
);
874 if(NS_FAILED(nsres
)) {
875 ERR("GetDefaultLoadRequest failed: %08x\n", nsres
);
882 nsres
= nsIRequest_QueryInterface(req
, &IID_nsIChannel
, (void**)&channel
);
883 nsIRequest_Release(req
);
884 if(NS_FAILED(nsres
)) {
885 WARN("Could not get nsIChannel interface: %08x\n", nsres
);
889 nsres
= nsIChannel_GetURI(channel
, &uri
);
890 nsIChannel_Release(channel
);
891 if(NS_FAILED(nsres
)) {
892 ERR("GetURI failed: %08x\n", nsres
);
896 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
898 if(NS_FAILED(nsres
)) {
899 TRACE("Could not get nsWineURI: %08x\n", nsres
);
903 window
= wine_uri
->window_ref
? wine_uri
->window_ref
->window
: NULL
;
905 IHTMLWindow2_AddRef(&window
->base
.IHTMLWindow2_iface
);
906 nsIFileURL_Release(&wine_uri
->nsIFileURL_iface
);
911 static HTMLOuterWindow
*get_channel_window(nsChannel
*This
)
913 nsIWebProgress
*web_progress
;
914 nsIDOMWindow
*nswindow
;
915 HTMLOuterWindow
*window
;
918 if(This
->load_group
) {
919 nsIRequestObserver
*req_observer
;
921 nsres
= nsILoadGroup_GetGroupObserver(This
->load_group
, &req_observer
);
922 if(NS_FAILED(nsres
) || !req_observer
) {
923 ERR("GetGroupObserver failed: %08x\n", nsres
);
927 nsres
= nsIRequestObserver_QueryInterface(req_observer
, &IID_nsIWebProgress
, (void**)&web_progress
);
928 nsIRequestObserver_Release(req_observer
);
929 if(NS_FAILED(nsres
)) {
930 ERR("Could not get nsIWebProgress iface: %08x\n", nsres
);
933 }else if(This
->notif_callback
) {
934 nsres
= nsIInterfaceRequestor_GetInterface(This
->notif_callback
, &IID_nsIWebProgress
, (void**)&web_progress
);
935 if(NS_FAILED(nsres
)) {
936 ERR("GetInterface(IID_nsIWebProgress failed: %08x\n", nsres
);
940 ERR("no load group nor notif callback\n");
944 nsres
= nsIWebProgress_GetDOMWindow(web_progress
, &nswindow
);
945 nsIWebProgress_Release(web_progress
);
946 if(NS_FAILED(nsres
) || !nswindow
) {
947 ERR("GetDOMWindow failed: %08x\n", nsres
);
951 window
= nswindow_to_window(nswindow
);
952 nsIDOMWindow_Release(nswindow
);
955 IHTMLWindow2_AddRef(&window
->base
.IHTMLWindow2_iface
);
957 FIXME("NULL window for %p\n", nswindow
);
963 HTMLInnerWindow
*window
;
964 nsChannelBSC
*bscallback
;
965 } start_binding_task_t
;
967 static void start_binding_proc(task_t
*_task
)
969 start_binding_task_t
*task
= (start_binding_task_t
*)_task
;
971 start_binding(task
->window
, (BSCallback
*)task
->bscallback
, NULL
);
974 static void start_binding_task_destr(task_t
*_task
)
976 start_binding_task_t
*task
= (start_binding_task_t
*)_task
;
978 IBindStatusCallback_Release(&task
->bscallback
->bsc
.IBindStatusCallback_iface
);
982 static nsresult
async_open(nsChannel
*This
, HTMLOuterWindow
*window
, BOOL is_doc_channel
, nsIStreamListener
*listener
,
983 nsISupports
*context
)
985 nsChannelBSC
*bscallback
;
986 IMoniker
*mon
= NULL
;
989 hres
= CreateURLMonikerEx2(NULL
, This
->uri
->uri
, &mon
, 0);
991 WARN("CreateURLMoniker failed: %08x\n", hres
);
992 return NS_ERROR_UNEXPECTED
;
996 set_current_mon(window
, mon
, BINDING_NAVIGATED
);
998 hres
= create_channelbsc(mon
, NULL
, NULL
, 0, is_doc_channel
, &bscallback
);
999 IMoniker_Release(mon
);
1001 return NS_ERROR_UNEXPECTED
;
1003 channelbsc_set_channel(bscallback
, This
, listener
, context
);
1005 if(is_doc_channel
) {
1006 hres
= create_pending_window(window
, bscallback
);
1008 async_start_doc_binding(window
, window
->pending_window
);
1009 IBindStatusCallback_Release(&bscallback
->bsc
.IBindStatusCallback_iface
);
1011 return NS_ERROR_UNEXPECTED
;
1013 start_binding_task_t
*task
;
1015 task
= heap_alloc(sizeof(start_binding_task_t
));
1017 IBindStatusCallback_Release(&bscallback
->bsc
.IBindStatusCallback_iface
);
1018 return NS_ERROR_OUT_OF_MEMORY
;
1021 task
->window
= window
->base
.inner_window
;
1022 task
->bscallback
= bscallback
;
1023 hres
= push_task(&task
->header
, start_binding_proc
, start_binding_task_destr
, window
->base
.inner_window
->task_magic
);
1025 return NS_ERROR_OUT_OF_MEMORY
;
1031 static nsresult NSAPI
nsChannel_AsyncOpen(nsIHttpChannel
*iface
, nsIStreamListener
*aListener
,
1032 nsISupports
*aContext
)
1034 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1035 HTMLOuterWindow
*window
= NULL
;
1036 BOOL cancel
= FALSE
;
1037 nsresult nsres
= NS_OK
;
1039 TRACE("(%p)->(%p %p)\n", This
, aListener
, aContext
);
1041 if(!ensure_uri(This
->uri
))
1042 return NS_ERROR_FAILURE
;
1044 if(TRACE_ON(mshtml
)) {
1048 hres
= IUri_GetDisplayUri(This
->uri
->uri
, &uri_str
);
1049 if(SUCCEEDED(hres
)) {
1050 TRACE("opening %s\n", debugstr_w(uri_str
));
1051 SysFreeString(uri_str
);
1053 WARN("GetDisplayUri failed: %08x\n", hres
);
1057 if(This
->uri
->is_doc_uri
) {
1058 window
= get_channel_window(This
);
1060 set_uri_window(This
->uri
, window
);
1061 }else if(This
->uri
->container
) {
1064 /* nscontainer->doc should be NULL which means navigation to a new window */
1065 if(This
->uri
->container
->doc
)
1066 FIXME("nscontainer->doc = %p\n", This
->uri
->container
->doc
);
1068 nsres
= before_async_open(This
, This
->uri
->container
, &b
);
1069 if(NS_FAILED(nsres
))
1072 FIXME("Navigation not cancelled\n");
1073 return NS_ERROR_UNEXPECTED
;
1078 if(This
->uri
->window_ref
&& This
->uri
->window_ref
->window
) {
1079 window
= This
->uri
->window_ref
->window
;
1080 IHTMLWindow2_AddRef(&window
->base
.IHTMLWindow2_iface
);
1082 /* FIXME: Analyze removing get_window_from_load_group call */
1083 if(This
->load_group
)
1084 window
= get_window_from_load_group(This
);
1086 window
= get_channel_window(This
);
1088 set_uri_window(This
->uri
, window
);
1093 ERR("window = NULL\n");
1094 return NS_ERROR_UNEXPECTED
;
1097 if(This
->uri
->is_doc_uri
&& window
== window
->doc_obj
->basedoc
.window
) {
1098 if(This
->uri
->channel_bsc
) {
1099 channelbsc_set_channel(This
->uri
->channel_bsc
, This
, aListener
, aContext
);
1101 if(window
->doc_obj
->mime
) {
1102 heap_free(This
->content_type
);
1103 This
->content_type
= heap_strdupWtoA(window
->doc_obj
->mime
);
1108 nsres
= before_async_open(This
, window
->doc_obj
->nscontainer
, &cancel
);
1109 if(NS_SUCCEEDED(nsres
) && cancel
) {
1110 TRACE("canceled\n");
1111 nsres
= NS_BINDING_ABORTED
;
1117 nsres
= async_open(This
, window
, This
->uri
->is_doc_uri
, aListener
, aContext
);
1119 if(NS_SUCCEEDED(nsres
) && This
->load_group
) {
1120 nsres
= nsILoadGroup_AddRequest(This
->load_group
, (nsIRequest
*)&This
->nsIHttpChannel_iface
,
1122 if(NS_FAILED(nsres
))
1123 ERR("AddRequest failed: %08x\n", nsres
);
1126 IHTMLWindow2_Release(&window
->base
.IHTMLWindow2_iface
);
1130 static nsresult NSAPI
nsChannel_GetContentDisposition(nsIHttpChannel
*iface
, UINT32
*aContentDisposition
)
1132 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1133 FIXME("(%p)->(%p)\n", This
, aContentDisposition
);
1134 return NS_ERROR_NOT_IMPLEMENTED
;
1137 static nsresult NSAPI
nsChannel_SetContentDisposition(nsIHttpChannel
*iface
, UINT32 aContentDisposition
)
1139 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1140 FIXME("(%p)->(%u)\n", This
, aContentDisposition
);
1141 return NS_ERROR_NOT_IMPLEMENTED
;
1144 static nsresult NSAPI
nsChannel_GetContentDispositionFilename(nsIHttpChannel
*iface
, nsAString
*aContentDispositionFilename
)
1146 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1147 FIXME("(%p)->(%p)\n", This
, aContentDispositionFilename
);
1148 return NS_ERROR_NOT_IMPLEMENTED
;
1151 static nsresult NSAPI
nsChannel_SetContentDispositionFilename(nsIHttpChannel
*iface
, const nsAString
*aContentDispositionFilename
)
1153 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1154 FIXME("(%p)->(%p)\n", This
, aContentDispositionFilename
);
1155 return NS_ERROR_NOT_IMPLEMENTED
;
1158 static nsresult NSAPI
nsChannel_GetContentDispositionHeader(nsIHttpChannel
*iface
, nsACString
*aContentDispositionHeader
)
1160 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1161 FIXME("(%p)->(%p)\n", This
, aContentDispositionHeader
);
1162 return NS_ERROR_NOT_IMPLEMENTED
;
1165 static nsresult NSAPI
nsChannel_GetRequestMethod(nsIHttpChannel
*iface
, nsACString
*aRequestMethod
)
1167 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1169 TRACE("(%p)->(%p)\n", This
, aRequestMethod
);
1171 nsACString_SetData(aRequestMethod
, request_method_strings
[This
->request_method
]);
1175 static nsresult NSAPI
nsChannel_SetRequestMethod(nsIHttpChannel
*iface
,
1176 const nsACString
*aRequestMethod
)
1178 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1182 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRequestMethod
));
1184 nsACString_GetData(aRequestMethod
, &method
);
1185 for(i
=0; i
< sizeof(request_method_strings
)/sizeof(*request_method_strings
); i
++) {
1186 if(!strcasecmp(method
, request_method_strings
[i
])) {
1187 This
->request_method
= i
;
1192 ERR("Invalid method %s\n", debugstr_a(method
));
1193 return NS_ERROR_UNEXPECTED
;
1196 static nsresult NSAPI
nsChannel_GetReferrer(nsIHttpChannel
*iface
, nsIURI
**aReferrer
)
1198 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1200 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1203 nsIURI_AddRef(This
->referrer
);
1204 *aReferrer
= This
->referrer
;
1208 static nsresult NSAPI
nsChannel_SetReferrer(nsIHttpChannel
*iface
, nsIURI
*aReferrer
)
1210 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1212 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1215 nsIURI_AddRef(aReferrer
);
1217 nsIURI_Release(This
->referrer
);
1218 This
->referrer
= aReferrer
;
1222 static nsresult NSAPI
nsChannel_GetRequestHeader(nsIHttpChannel
*iface
,
1223 const nsACString
*aHeader
, nsACString
*_retval
)
1225 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1227 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aHeader
), _retval
);
1229 return get_channel_http_header(&This
->request_headers
, aHeader
, _retval
);
1232 static nsresult NSAPI
nsChannel_SetRequestHeader(nsIHttpChannel
*iface
,
1233 const nsACString
*aHeader
, const nsACString
*aValue
, cpp_bool aMerge
)
1235 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1237 TRACE("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(aHeader
), debugstr_nsacstr(aValue
), aMerge
);
1240 FIXME("aMerge not supported\n");
1242 return set_channel_http_header(&This
->request_headers
, aHeader
, aValue
);
1245 static nsresult NSAPI
nsChannel_VisitRequestHeaders(nsIHttpChannel
*iface
,
1246 nsIHttpHeaderVisitor
*aVisitor
)
1248 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1250 FIXME("(%p)->(%p)\n", This
, aVisitor
);
1252 return NS_ERROR_NOT_IMPLEMENTED
;
1255 static nsresult NSAPI
nsChannel_GetAllowPipelining(nsIHttpChannel
*iface
, cpp_bool
*aAllowPipelining
)
1257 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1259 FIXME("(%p)->(%p)\n", This
, aAllowPipelining
);
1261 return NS_ERROR_NOT_IMPLEMENTED
;
1264 static nsresult NSAPI
nsChannel_SetAllowPipelining(nsIHttpChannel
*iface
, cpp_bool aAllowPipelining
)
1266 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1268 FIXME("(%p)->(%x)\n", This
, aAllowPipelining
);
1270 return NS_ERROR_NOT_IMPLEMENTED
;
1273 static nsresult NSAPI
nsChannel_GetRedirectionLimit(nsIHttpChannel
*iface
, UINT32
*aRedirectionLimit
)
1275 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1277 FIXME("(%p)->(%p)\n", This
, aRedirectionLimit
);
1279 return NS_ERROR_NOT_IMPLEMENTED
;
1282 static nsresult NSAPI
nsChannel_SetRedirectionLimit(nsIHttpChannel
*iface
, UINT32 aRedirectionLimit
)
1284 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1286 FIXME("(%p)->(%u)\n", This
, aRedirectionLimit
);
1288 return NS_ERROR_NOT_IMPLEMENTED
;
1291 static nsresult NSAPI
nsChannel_GetResponseStatus(nsIHttpChannel
*iface
, UINT32
*aResponseStatus
)
1293 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1295 TRACE("(%p)->(%p)\n", This
, aResponseStatus
);
1297 if(This
->response_status
) {
1298 *aResponseStatus
= This
->response_status
;
1302 WARN("No response status\n");
1303 return NS_ERROR_UNEXPECTED
;
1306 static nsresult NSAPI
nsChannel_GetResponseStatusText(nsIHttpChannel
*iface
,
1307 nsACString
*aResponseStatusText
)
1309 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1311 FIXME("(%p)->(%p)\n", This
, aResponseStatusText
);
1313 return NS_ERROR_NOT_IMPLEMENTED
;
1316 static nsresult NSAPI
nsChannel_GetRequestSucceeded(nsIHttpChannel
*iface
,
1317 cpp_bool
*aRequestSucceeded
)
1319 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1321 TRACE("(%p)->(%p)\n", This
, aRequestSucceeded
);
1323 if(!This
->response_status
)
1324 return NS_ERROR_NOT_AVAILABLE
;
1326 *aRequestSucceeded
= This
->response_status
/100 == 2;
1331 static nsresult NSAPI
nsChannel_GetResponseHeader(nsIHttpChannel
*iface
,
1332 const nsACString
*header
, nsACString
*_retval
)
1334 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1336 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(header
), _retval
);
1338 return get_channel_http_header(&This
->response_headers
, header
, _retval
);
1341 static nsresult NSAPI
nsChannel_SetResponseHeader(nsIHttpChannel
*iface
,
1342 const nsACString
*header
, const nsACString
*value
, cpp_bool merge
)
1344 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1346 FIXME("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(header
), debugstr_nsacstr(value
), merge
);
1348 return NS_ERROR_NOT_IMPLEMENTED
;
1351 static nsresult NSAPI
nsChannel_VisitResponseHeaders(nsIHttpChannel
*iface
,
1352 nsIHttpHeaderVisitor
*aVisitor
)
1354 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1356 TRACE("(%p)->(%p)\n", This
, aVisitor
);
1358 return visit_http_headers(&This
->response_headers
, aVisitor
);
1361 static nsresult NSAPI
nsChannel_IsNoStoreResponse(nsIHttpChannel
*iface
, cpp_bool
*_retval
)
1363 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1364 http_header_t
*header
;
1366 static const WCHAR cache_controlW
[] = {'C','a','c','h','e','-','C','o','n','t','r','o','l'};
1367 static const WCHAR no_storeW
[] = {'n','o','-','s','t','o','r','e',0};
1369 TRACE("(%p)->(%p)\n", This
, _retval
);
1371 header
= find_http_header(&This
->response_headers
, cache_controlW
, sizeof(cache_controlW
)/sizeof(WCHAR
));
1372 *_retval
= header
&& !strcmpiW(header
->data
, no_storeW
);
1376 static nsresult NSAPI
nsChannel_IsNoCacheResponse(nsIHttpChannel
*iface
, cpp_bool
*_retval
)
1378 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1380 FIXME("(%p)->(%p)\n", This
, _retval
);
1382 return NS_ERROR_NOT_IMPLEMENTED
;
1385 static const nsIHttpChannelVtbl nsChannelVtbl
= {
1386 nsChannel_QueryInterface
,
1390 nsChannel_IsPending
,
1391 nsChannel_GetStatus
,
1395 nsChannel_GetLoadGroup
,
1396 nsChannel_SetLoadGroup
,
1397 nsChannel_GetLoadFlags
,
1398 nsChannel_SetLoadFlags
,
1399 nsChannel_GetOriginalURI
,
1400 nsChannel_SetOriginalURI
,
1404 nsChannel_GetNotificationCallbacks
,
1405 nsChannel_SetNotificationCallbacks
,
1406 nsChannel_GetSecurityInfo
,
1407 nsChannel_GetContentType
,
1408 nsChannel_SetContentType
,
1409 nsChannel_GetContentCharset
,
1410 nsChannel_SetContentCharset
,
1411 nsChannel_GetContentLength
,
1412 nsChannel_SetContentLength
,
1414 nsChannel_AsyncOpen
,
1415 nsChannel_GetContentDisposition
,
1416 nsChannel_SetContentDisposition
,
1417 nsChannel_GetContentDispositionFilename
,
1418 nsChannel_SetContentDispositionFilename
,
1419 nsChannel_GetContentDispositionHeader
,
1420 nsChannel_GetRequestMethod
,
1421 nsChannel_SetRequestMethod
,
1422 nsChannel_GetReferrer
,
1423 nsChannel_SetReferrer
,
1424 nsChannel_GetRequestHeader
,
1425 nsChannel_SetRequestHeader
,
1426 nsChannel_VisitRequestHeaders
,
1427 nsChannel_GetAllowPipelining
,
1428 nsChannel_SetAllowPipelining
,
1429 nsChannel_GetRedirectionLimit
,
1430 nsChannel_SetRedirectionLimit
,
1431 nsChannel_GetResponseStatus
,
1432 nsChannel_GetResponseStatusText
,
1433 nsChannel_GetRequestSucceeded
,
1434 nsChannel_GetResponseHeader
,
1435 nsChannel_SetResponseHeader
,
1436 nsChannel_VisitResponseHeaders
,
1437 nsChannel_IsNoStoreResponse
,
1438 nsChannel_IsNoCacheResponse
1441 static inline nsChannel
*impl_from_nsIUploadChannel(nsIUploadChannel
*iface
)
1443 return CONTAINING_RECORD(iface
, nsChannel
, nsIUploadChannel_iface
);
1446 static nsresult NSAPI
nsUploadChannel_QueryInterface(nsIUploadChannel
*iface
, nsIIDRef riid
,
1449 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1450 return nsIHttpChannel_QueryInterface(&This
->nsIHttpChannel_iface
, riid
, result
);
1453 static nsrefcnt NSAPI
nsUploadChannel_AddRef(nsIUploadChannel
*iface
)
1455 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1456 return nsIHttpChannel_AddRef(&This
->nsIHttpChannel_iface
);
1459 static nsrefcnt NSAPI
nsUploadChannel_Release(nsIUploadChannel
*iface
)
1461 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1462 return nsIHttpChannel_Release(&This
->nsIHttpChannel_iface
);
1465 static nsresult NSAPI
nsUploadChannel_SetUploadStream(nsIUploadChannel
*iface
,
1466 nsIInputStream
*aStream
, const nsACString
*aContentType
, INT64 aContentLength
)
1468 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1469 const char *content_type
;
1471 static const WCHAR content_typeW
[] =
1472 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1474 TRACE("(%p)->(%p %s %s)\n", This
, aStream
, debugstr_nsacstr(aContentType
), wine_dbgstr_longlong(aContentLength
));
1476 This
->post_data_contains_headers
= TRUE
;
1479 nsACString_GetData(aContentType
, &content_type
);
1483 ct
= heap_strdupAtoW(content_type
);
1485 return NS_ERROR_UNEXPECTED
;
1487 set_http_header(&This
->request_headers
, content_typeW
,
1488 sizeof(content_typeW
)/sizeof(WCHAR
), ct
, strlenW(ct
));
1490 This
->post_data_contains_headers
= FALSE
;
1494 if(This
->post_data_stream
)
1495 nsIInputStream_Release(This
->post_data_stream
);
1497 if(aContentLength
!= -1)
1498 FIXME("Unsupported acontentLength = %s\n", wine_dbgstr_longlong(aContentLength
));
1500 if(This
->post_data_stream
)
1501 nsIInputStream_Release(This
->post_data_stream
);
1502 This
->post_data_stream
= aStream
;
1504 nsIInputStream_AddRef(aStream
);
1506 This
->request_method
= METHOD_POST
;
1510 static nsresult NSAPI
nsUploadChannel_GetUploadStream(nsIUploadChannel
*iface
,
1511 nsIInputStream
**aUploadStream
)
1513 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1515 TRACE("(%p)->(%p)\n", This
, aUploadStream
);
1517 if(This
->post_data_stream
)
1518 nsIInputStream_AddRef(This
->post_data_stream
);
1520 *aUploadStream
= This
->post_data_stream
;
1524 static const nsIUploadChannelVtbl nsUploadChannelVtbl
= {
1525 nsUploadChannel_QueryInterface
,
1526 nsUploadChannel_AddRef
,
1527 nsUploadChannel_Release
,
1528 nsUploadChannel_SetUploadStream
,
1529 nsUploadChannel_GetUploadStream
1532 static inline nsChannel
*impl_from_nsIHttpChannelInternal(nsIHttpChannelInternal
*iface
)
1534 return CONTAINING_RECORD(iface
, nsChannel
, nsIHttpChannelInternal_iface
);
1537 static nsresult NSAPI
nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal
*iface
, nsIIDRef riid
,
1540 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1541 return nsIHttpChannel_QueryInterface(&This
->nsIHttpChannel_iface
, riid
, result
);
1544 static nsrefcnt NSAPI
nsHttpChannelInternal_AddRef(nsIHttpChannelInternal
*iface
)
1546 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1547 return nsIHttpChannel_AddRef(&This
->nsIHttpChannel_iface
);
1550 static nsrefcnt NSAPI
nsHttpChannelInternal_Release(nsIHttpChannelInternal
*iface
)
1552 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1553 return nsIHttpChannel_Release(&This
->nsIHttpChannel_iface
);
1556 static nsresult NSAPI
nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
**aDocumentURI
)
1558 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1560 FIXME("(%p)->()\n", This
);
1562 return NS_ERROR_NOT_IMPLEMENTED
;
1565 static nsresult NSAPI
nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
*aDocumentURI
)
1567 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1569 FIXME("(%p)->()\n", This
);
1571 return NS_ERROR_NOT_IMPLEMENTED
;
1574 static nsresult NSAPI
nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal
*iface
, UINT32
*major
, UINT32
*minor
)
1576 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1578 FIXME("(%p)->()\n", This
);
1580 return NS_ERROR_NOT_IMPLEMENTED
;
1583 static nsresult NSAPI
nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal
*iface
, UINT32
*major
, UINT32
*minor
)
1585 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1587 FIXME("(%p)->()\n", This
);
1589 return NS_ERROR_NOT_IMPLEMENTED
;
1592 static nsresult NSAPI
nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal
*iface
, const char *aCookieHeader
)
1594 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1596 FIXME("(%p)->()\n", This
);
1598 return NS_ERROR_NOT_IMPLEMENTED
;
1601 static nsresult NSAPI
nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal
*iface
, const char *aFallbackKey
)
1603 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1605 FIXME("(%p)->()\n", This
);
1607 return NS_ERROR_NOT_IMPLEMENTED
;
1610 static nsresult NSAPI
nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, cpp_bool
*aForceThirdPartyCookie
)
1612 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1614 FIXME("(%p)->()\n", This
);
1616 return NS_ERROR_NOT_IMPLEMENTED
;
1619 static nsresult NSAPI
nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, cpp_bool aForceThirdPartyCookie
)
1621 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1623 FIXME("(%p)->()\n", This
);
1625 return NS_ERROR_NOT_IMPLEMENTED
;
1628 static nsresult NSAPI
nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal
*iface
, cpp_bool
*aCanceled
)
1630 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1632 FIXME("(%p)->(%p)\n", This
, aCanceled
);
1634 return NS_ERROR_NOT_IMPLEMENTED
;
1637 static nsresult NSAPI
nsHttpChannelInternal_GetChannelIsForDownload(nsIHttpChannelInternal
*iface
, cpp_bool
*aCanceled
)
1639 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1641 FIXME("(%p)->(%p)\n", This
, aCanceled
);
1643 return NS_ERROR_NOT_IMPLEMENTED
;
1646 static nsresult NSAPI
nsHttpChannelInternal_SetChannelIsForDownload(nsIHttpChannelInternal
*iface
, cpp_bool aCanceled
)
1648 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1650 FIXME("(%p)->(%x)\n", This
, aCanceled
);
1652 return NS_ERROR_NOT_IMPLEMENTED
;
1655 static nsresult NSAPI
nsHttpChannelInternal_GetLocalAddress(nsIHttpChannelInternal
*iface
, nsACString
*aLocalAddress
)
1657 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1659 FIXME("(%p)->(%p)\n", This
, aLocalAddress
);
1661 return NS_ERROR_NOT_IMPLEMENTED
;
1664 static nsresult NSAPI
nsHttpChannelInternal_GetLocalPort(nsIHttpChannelInternal
*iface
, LONG
*aLocalPort
)
1666 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1668 FIXME("(%p)->(%p)\n", This
, aLocalPort
);
1670 return NS_ERROR_NOT_IMPLEMENTED
;
1673 static nsresult NSAPI
nsHttpChannelInternal_GetRemoteAddress(nsIHttpChannelInternal
*iface
, nsACString
*aRemoteAddress
)
1675 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1677 FIXME("(%p)->(%p)\n", This
, aRemoteAddress
);
1679 return NS_ERROR_NOT_IMPLEMENTED
;
1682 static nsresult NSAPI
nsHttpChannelInternal_GetRemotePort(nsIHttpChannelInternal
*iface
, LONG
*aRemotePort
)
1684 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1686 FIXME("(%p)->(%p)\n", This
, aRemotePort
);
1688 return NS_ERROR_NOT_IMPLEMENTED
;
1691 static nsresult NSAPI
nsHttpChannelInternal_SetCacheKeysRedirectChain(nsIHttpChannelInternal
*iface
, void *cacheKeys
)
1693 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1695 FIXME("(%p)->(%p)\n", This
, cacheKeys
);
1697 return NS_ERROR_NOT_IMPLEMENTED
;
1700 static nsresult NSAPI
nsHttpChannelInternal_HTTPUpgrade(nsIHttpChannelInternal
*iface
,
1701 const nsACString
*aProtocolName
, nsIHttpUpgradeListener
*aListener
)
1703 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1704 FIXME("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aProtocolName
), aListener
);
1705 return NS_ERROR_NOT_IMPLEMENTED
;
1708 static nsresult NSAPI
nsHttpChannelInternal_GetAllowSpdy(nsIHttpChannelInternal
*iface
, cpp_bool
*aAllowSpdy
)
1710 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1711 FIXME("(%p)->(%p)\n", This
, aAllowSpdy
);
1712 return NS_ERROR_NOT_IMPLEMENTED
;
1715 static nsresult NSAPI
nsHttpChannelInternal_SetAllowSpdy(nsIHttpChannelInternal
*iface
, cpp_bool aAllowSpdy
)
1717 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1718 FIXME("(%p)->(%x)\n", This
, aAllowSpdy
);
1719 return NS_ERROR_NOT_IMPLEMENTED
;
1722 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl
= {
1723 nsHttpChannelInternal_QueryInterface
,
1724 nsHttpChannelInternal_AddRef
,
1725 nsHttpChannelInternal_Release
,
1726 nsHttpChannelInternal_GetDocumentURI
,
1727 nsHttpChannelInternal_SetDocumentURI
,
1728 nsHttpChannelInternal_GetRequestVersion
,
1729 nsHttpChannelInternal_GetResponseVersion
,
1730 nsHttpChannelInternal_SetCookie
,
1731 nsHttpChannelInternal_SetupFallbackChannel
,
1732 nsHttpChannelInternal_GetForceAllowThirdPartyCookie
,
1733 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
,
1734 nsHttpChannelInternal_GetCanceled
,
1735 nsHttpChannelInternal_GetChannelIsForDownload
,
1736 nsHttpChannelInternal_SetChannelIsForDownload
,
1737 nsHttpChannelInternal_GetLocalAddress
,
1738 nsHttpChannelInternal_GetLocalPort
,
1739 nsHttpChannelInternal_GetRemoteAddress
,
1740 nsHttpChannelInternal_GetRemotePort
,
1741 nsHttpChannelInternal_SetCacheKeysRedirectChain
,
1742 nsHttpChannelInternal_HTTPUpgrade
,
1743 nsHttpChannelInternal_GetAllowSpdy
,
1744 nsHttpChannelInternal_SetAllowSpdy
1748 static void invalidate_uri(nsWineURI
*This
)
1751 IUri_Release(This
->uri
);
1756 static BOOL
ensure_uri_builder(nsWineURI
*This
)
1758 if(!This
->is_mutable
) {
1759 WARN("Not mutable URI\n");
1763 if(!This
->uri_builder
) {
1766 if(!ensure_uri(This
))
1769 hres
= CreateIUriBuilder(This
->uri
, 0, 0, &This
->uri_builder
);
1771 WARN("CreateIUriBuilder failed: %08x\n", hres
);
1776 invalidate_uri(This
);
1780 static nsresult
get_uri_string(nsWineURI
*This
, Uri_PROPERTY prop
, nsACString
*ret
)
1786 if(!ensure_uri(This
))
1787 return NS_ERROR_UNEXPECTED
;
1789 hres
= IUri_GetPropertyBSTR(This
->uri
, prop
, &val
, 0);
1791 WARN("GetPropertyBSTR failed: %08x\n", hres
);
1792 return NS_ERROR_UNEXPECTED
;
1795 vala
= heap_strdupWtoU(val
);
1798 return NS_ERROR_OUT_OF_MEMORY
;
1800 TRACE("ret %s\n", debugstr_a(vala
));
1801 nsACString_SetData(ret
, vala
);
1806 static inline nsWineURI
*impl_from_nsIFileURL(nsIFileURL
*iface
)
1808 return CONTAINING_RECORD(iface
, nsWineURI
, nsIFileURL_iface
);
1811 static nsresult NSAPI
nsURI_QueryInterface(nsIFileURL
*iface
, nsIIDRef riid
, void **result
)
1813 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1817 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1818 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1819 *result
= &This
->nsIFileURL_iface
;
1820 }else if(IsEqualGUID(&IID_nsIURI
, riid
)) {
1821 TRACE("(%p)->(IID_nsIURI %p)\n", This
, result
);
1822 *result
= &This
->nsIFileURL_iface
;
1823 }else if(IsEqualGUID(&IID_nsIURL
, riid
)) {
1824 TRACE("(%p)->(IID_nsIURL %p)\n", This
, result
);
1825 *result
= &This
->nsIFileURL_iface
;
1826 }else if(IsEqualGUID(&IID_nsIFileURL
, riid
)) {
1827 TRACE("(%p)->(IID_nsIFileURL %p)\n", This
, result
);
1828 *result
= This
->scheme
== URL_SCHEME_FILE
? &This
->nsIFileURL_iface
: NULL
;
1829 }else if(IsEqualGUID(&IID_nsIMutable
, riid
)) {
1830 TRACE("(%p)->(IID_nsIMutable %p)\n", This
, result
);
1831 *result
= &This
->nsIStandardURL_iface
;
1832 }else if(IsEqualGUID(&IID_nsIStandardURL
, riid
)) {
1833 TRACE("(%p)->(IID_nsIStandardURL %p)\n", This
, result
);
1834 *result
= &This
->nsIStandardURL_iface
;
1835 }else if(IsEqualGUID(&IID_nsWineURI
, riid
)) {
1836 TRACE("(%p)->(IID_nsWineURI %p)\n", This
, result
);
1841 nsIFileURL_AddRef(&This
->nsIFileURL_iface
);
1845 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1846 return NS_NOINTERFACE
;
1849 static nsrefcnt NSAPI
nsURI_AddRef(nsIFileURL
*iface
)
1851 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1852 LONG ref
= InterlockedIncrement(&This
->ref
);
1854 TRACE("(%p) ref=%d\n", This
, ref
);
1859 static nsrefcnt NSAPI
nsURI_Release(nsIFileURL
*iface
)
1861 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1862 LONG ref
= InterlockedDecrement(&This
->ref
);
1864 TRACE("(%p) ref=%d\n", This
, ref
);
1867 if(This
->window_ref
)
1868 windowref_release(This
->window_ref
);
1870 nsIWebBrowserChrome_Release(&This
->container
->nsIWebBrowserChrome_iface
);
1872 IUri_Release(This
->uri
);
1873 heap_free(This
->origin_charset
);
1880 static nsresult NSAPI
nsURI_GetSpec(nsIFileURL
*iface
, nsACString
*aSpec
)
1882 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1884 TRACE("(%p)->(%p)\n", This
, aSpec
);
1886 return get_uri_string(This
, Uri_PROPERTY_DISPLAY_URI
, aSpec
);
1889 static nsresult NSAPI
nsURI_SetSpec(nsIFileURL
*iface
, const nsACString
*aSpec
)
1891 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1897 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aSpec
));
1899 if(!This
->is_mutable
)
1900 return NS_ERROR_UNEXPECTED
;
1902 nsACString_GetData(aSpec
, &speca
);
1903 spec
= heap_strdupUtoW(speca
);
1905 return NS_ERROR_OUT_OF_MEMORY
;
1907 hres
= create_uri(spec
, 0, &uri
);
1910 WARN("create_uri failed: %08x\n", hres
);
1911 return NS_ERROR_FAILURE
;
1914 invalidate_uri(This
);
1915 if(This
->uri_builder
) {
1916 IUriBuilder_Release(This
->uri_builder
);
1917 This
->uri_builder
= NULL
;
1924 static nsresult NSAPI
nsURI_GetPrePath(nsIFileURL
*iface
, nsACString
*aPrePath
)
1926 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1927 FIXME("(%p)->(%p)\n", This
, aPrePath
);
1928 return NS_ERROR_NOT_IMPLEMENTED
;
1931 static nsresult NSAPI
nsURI_GetScheme(nsIFileURL
*iface
, nsACString
*aScheme
)
1933 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1937 TRACE("(%p)->(%p)\n", This
, aScheme
);
1939 if(!ensure_uri(This
))
1940 return NS_ERROR_UNEXPECTED
;
1942 hres
= IUri_GetScheme(This
->uri
, &scheme
);
1944 WARN("GetScheme failed: %08x\n", hres
);
1945 return NS_ERROR_UNEXPECTED
;
1948 if(scheme
== URL_SCHEME_ABOUT
) {
1949 nsACString_SetData(aScheme
, "wine");
1953 return get_uri_string(This
, Uri_PROPERTY_SCHEME_NAME
, aScheme
);
1956 static nsresult NSAPI
nsURI_SetScheme(nsIFileURL
*iface
, const nsACString
*aScheme
)
1958 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1959 const char *schemea
;
1963 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aScheme
));
1965 if(!ensure_uri_builder(This
))
1966 return NS_ERROR_UNEXPECTED
;
1968 nsACString_GetData(aScheme
, &schemea
);
1969 scheme
= heap_strdupUtoW(schemea
);
1971 return NS_ERROR_OUT_OF_MEMORY
;
1973 hres
= IUriBuilder_SetSchemeName(This
->uri_builder
, scheme
);
1976 return NS_ERROR_UNEXPECTED
;
1981 static nsresult NSAPI
nsURI_GetUserPass(nsIFileURL
*iface
, nsACString
*aUserPass
)
1983 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1987 TRACE("(%p)->(%p)\n", This
, aUserPass
);
1989 if(!ensure_uri(This
))
1990 return NS_ERROR_UNEXPECTED
;
1992 hres
= IUri_GetUserName(This
->uri
, &user
);
1994 return NS_ERROR_FAILURE
;
1996 hres
= IUri_GetPassword(This
->uri
, &pass
);
1998 SysFreeString(user
);
1999 return NS_ERROR_FAILURE
;
2002 if(*user
|| *pass
) {
2003 FIXME("Construct user:pass string\n");
2005 nsACString_SetData(aUserPass
, "");
2008 SysFreeString(user
);
2009 SysFreeString(pass
);
2013 static nsresult NSAPI
nsURI_SetUserPass(nsIFileURL
*iface
, const nsACString
*aUserPass
)
2015 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2016 WCHAR
*user
= NULL
, *pass
= NULL
, *buf
= NULL
;
2017 const char *user_pass
;
2020 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUserPass
));
2022 if(!ensure_uri_builder(This
))
2023 return NS_ERROR_UNEXPECTED
;
2025 nsACString_GetData(aUserPass
, &user_pass
);
2029 buf
= heap_strdupUtoW(user_pass
);
2031 return NS_ERROR_OUT_OF_MEMORY
;
2033 ptr
= strchrW(buf
, ':');
2036 }else if(ptr
!= buf
) {
2046 hres
= IUriBuilder_SetUserName(This
->uri_builder
, user
);
2048 hres
= IUriBuilder_SetPassword(This
->uri_builder
, pass
);
2051 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_FAILURE
;
2054 static nsresult NSAPI
nsURI_GetUsername(nsIFileURL
*iface
, nsACString
*aUsername
)
2056 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2058 TRACE("(%p)->(%p)\n", This
, aUsername
);
2060 return get_uri_string(This
, Uri_PROPERTY_USER_NAME
, aUsername
);
2063 static nsresult NSAPI
nsURI_SetUsername(nsIFileURL
*iface
, const nsACString
*aUsername
)
2065 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2070 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUsername
));
2072 if(!ensure_uri_builder(This
))
2073 return NS_ERROR_UNEXPECTED
;
2075 nsACString_GetData(aUsername
, &usera
);
2076 user
= heap_strdupUtoW(usera
);
2078 return NS_ERROR_OUT_OF_MEMORY
;
2080 hres
= IUriBuilder_SetUserName(This
->uri_builder
, user
);
2083 return NS_ERROR_UNEXPECTED
;
2088 static nsresult NSAPI
nsURI_GetPassword(nsIFileURL
*iface
, nsACString
*aPassword
)
2090 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2092 TRACE("(%p)->(%p)\n", This
, aPassword
);
2094 return get_uri_string(This
, Uri_PROPERTY_PASSWORD
, aPassword
);
2097 static nsresult NSAPI
nsURI_SetPassword(nsIFileURL
*iface
, const nsACString
*aPassword
)
2099 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2104 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPassword
));
2106 if(!ensure_uri_builder(This
))
2107 return NS_ERROR_UNEXPECTED
;
2109 nsACString_GetData(aPassword
, &passa
);
2110 pass
= heap_strdupUtoW(passa
);
2112 return NS_ERROR_OUT_OF_MEMORY
;
2114 hres
= IUriBuilder_SetPassword(This
->uri_builder
, pass
);
2117 return NS_ERROR_UNEXPECTED
;
2122 static nsresult NSAPI
nsURI_GetHostPort(nsIFileURL
*iface
, nsACString
*aHostPort
)
2124 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2130 TRACE("(%p)->(%p)\n", This
, aHostPort
);
2132 if(!ensure_uri(This
))
2133 return NS_ERROR_UNEXPECTED
;
2135 hres
= IUri_GetAuthority(This
->uri
, &val
);
2137 WARN("GetAuthority failed: %08x\n", hres
);
2138 return NS_ERROR_UNEXPECTED
;
2141 ptr
= strchrW(val
, '@');
2145 vala
= heap_strdupWtoU(ptr
);
2148 return NS_ERROR_OUT_OF_MEMORY
;
2150 TRACE("ret %s\n", debugstr_a(vala
));
2151 nsACString_SetData(aHostPort
, vala
);
2156 static nsresult NSAPI
nsURI_SetHostPort(nsIFileURL
*iface
, const nsACString
*aHostPort
)
2158 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2160 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aHostPort
));
2162 /* Not implemented by Gecko */
2163 return NS_ERROR_NOT_IMPLEMENTED
;
2166 static nsresult NSAPI
nsURI_GetHost(nsIFileURL
*iface
, nsACString
*aHost
)
2168 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2170 TRACE("(%p)->(%p)\n", This
, aHost
);
2172 return get_uri_string(This
, Uri_PROPERTY_HOST
, aHost
);
2175 static nsresult NSAPI
nsURI_SetHost(nsIFileURL
*iface
, const nsACString
*aHost
)
2177 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2182 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aHost
));
2184 if(!ensure_uri_builder(This
))
2185 return NS_ERROR_UNEXPECTED
;
2187 nsACString_GetData(aHost
, &hosta
);
2188 host
= heap_strdupUtoW(hosta
);
2190 return NS_ERROR_OUT_OF_MEMORY
;
2192 hres
= IUriBuilder_SetHost(This
->uri_builder
, host
);
2195 return NS_ERROR_UNEXPECTED
;
2200 static nsresult NSAPI
nsURI_GetPort(nsIFileURL
*iface
, LONG
*aPort
)
2202 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2206 TRACE("(%p)->(%p)\n", This
, aPort
);
2208 if(!ensure_uri(This
))
2209 return NS_ERROR_UNEXPECTED
;
2211 hres
= IUri_GetPort(This
->uri
, &port
);
2213 WARN("GetPort failed: %08x\n", hres
);
2214 return NS_ERROR_UNEXPECTED
;
2217 *aPort
= port
? port
: -1;
2221 static nsresult NSAPI
nsURI_SetPort(nsIFileURL
*iface
, LONG aPort
)
2223 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2226 TRACE("(%p)->(%d)\n", This
, aPort
);
2228 if(!ensure_uri_builder(This
))
2229 return NS_ERROR_UNEXPECTED
;
2231 hres
= IUriBuilder_SetPort(This
->uri_builder
, aPort
!= -1, aPort
);
2232 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_FAILURE
;
2235 static nsresult NSAPI
nsURI_GetPath(nsIFileURL
*iface
, nsACString
*aPath
)
2237 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2239 TRACE("(%p)->(%p)\n", This
, aPath
);
2241 return get_uri_string(This
, Uri_PROPERTY_PATH
, aPath
);
2244 static nsresult NSAPI
nsURI_SetPath(nsIFileURL
*iface
, const nsACString
*aPath
)
2246 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2251 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPath
));
2253 if(!ensure_uri_builder(This
))
2254 return NS_ERROR_UNEXPECTED
;
2256 nsACString_GetData(aPath
, &patha
);
2257 path
= heap_strdupUtoW(patha
);
2259 return NS_ERROR_OUT_OF_MEMORY
;
2261 hres
= IUriBuilder_SetPath(This
->uri_builder
, path
);
2264 return NS_ERROR_UNEXPECTED
;
2269 static nsresult NSAPI
nsURI_Equals(nsIFileURL
*iface
, nsIURI
*other
, cpp_bool
*_retval
)
2271 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2272 nsWineURI
*other_obj
;
2276 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
2278 nsres
= nsIURI_QueryInterface(other
, &IID_nsWineURI
, (void**)&other_obj
);
2279 if(NS_FAILED(nsres
)) {
2280 TRACE("Could not get nsWineURI interface\n");
2285 if(ensure_uri(This
) && ensure_uri(other_obj
)) {
2288 hres
= IUri_IsEqual(This
->uri
, other_obj
->uri
, &b
);
2289 if(SUCCEEDED(hres
)) {
2293 nsres
= NS_ERROR_FAILURE
;
2296 nsres
= NS_ERROR_UNEXPECTED
;
2299 nsIFileURL_Release(&other_obj
->nsIFileURL_iface
);
2303 static nsresult NSAPI
nsURI_SchemeIs(nsIFileURL
*iface
, const char *scheme
, cpp_bool
*_retval
)
2305 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2306 WCHAR buf
[INTERNET_MAX_SCHEME_LENGTH
];
2310 TRACE("(%p)->(%s %p)\n", This
, debugstr_a(scheme
), _retval
);
2312 if(!ensure_uri(This
))
2313 return NS_ERROR_UNEXPECTED
;
2315 hres
= IUri_GetSchemeName(This
->uri
, &scheme_name
);
2317 return NS_ERROR_UNEXPECTED
;
2319 MultiByteToWideChar(CP_UTF8
, 0, scheme
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
2320 *_retval
= !strcmpW(scheme_name
, buf
);
2321 SysFreeString(scheme_name
);
2325 static nsresult NSAPI
nsURI_Clone(nsIFileURL
*iface
, nsIURI
**_retval
)
2327 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2328 nsWineURI
*wine_uri
;
2331 TRACE("(%p)->(%p)\n", This
, _retval
);
2333 if(!ensure_uri(This
))
2334 return NS_ERROR_UNEXPECTED
;
2336 nsres
= create_nsuri(This
->uri
, This
->window_ref
? This
->window_ref
->window
: NULL
,
2337 This
->container
, This
->origin_charset
, &wine_uri
);
2338 if(NS_FAILED(nsres
)) {
2339 WARN("create_nsuri failed: %08x\n", nsres
);
2343 *_retval
= (nsIURI
*)&wine_uri
->nsIFileURL_iface
;
2347 static nsresult NSAPI
nsURI_Resolve(nsIFileURL
*iface
, const nsACString
*aRelativePath
,
2348 nsACString
*_retval
)
2350 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2358 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aRelativePath
), _retval
);
2360 if(!ensure_uri(This
))
2361 return NS_ERROR_UNEXPECTED
;
2363 nsACString_GetData(aRelativePath
, &patha
);
2364 path
= heap_strdupUtoW(patha
);
2366 return NS_ERROR_OUT_OF_MEMORY
;
2368 hres
= CoInternetCombineUrlEx(This
->uri
, path
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
, &new_uri
, 0);
2371 ERR("CoIntenetCombineUrlEx failed: %08x\n", hres
);
2372 return NS_ERROR_FAILURE
;
2375 hres
= IUri_GetDisplayUri(new_uri
, &ret
);
2376 IUri_Release(new_uri
);
2378 return NS_ERROR_FAILURE
;
2380 reta
= heap_strdupWtoU(ret
);
2383 return NS_ERROR_OUT_OF_MEMORY
;
2385 TRACE("returning %s\n", debugstr_a(reta
));
2386 nsACString_SetData(_retval
, reta
);
2391 static nsresult NSAPI
nsURI_GetAsciiSpec(nsIFileURL
*iface
, nsACString
*aAsciiSpec
)
2393 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2395 TRACE("(%p)->(%p)\n", This
, aAsciiSpec
);
2397 return nsIFileURL_GetSpec(&This
->nsIFileURL_iface
, aAsciiSpec
);
2400 static nsresult NSAPI
nsURI_GetAsciiHost(nsIFileURL
*iface
, nsACString
*aAsciiHost
)
2402 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2404 WARN("(%p)->(%p) FIXME: Use Uri_PUNYCODE_IDN_HOST flag\n", This
, aAsciiHost
);
2406 return get_uri_string(This
, Uri_PROPERTY_HOST
, aAsciiHost
);
2409 static nsresult NSAPI
nsURI_GetOriginCharset(nsIFileURL
*iface
, nsACString
*aOriginCharset
)
2411 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2413 TRACE("(%p)->(%p)\n", This
, aOriginCharset
);
2415 nsACString_SetData(aOriginCharset
, This
->origin_charset
);
2419 static nsresult NSAPI
nsURL_GetRef(nsIFileURL
*iface
, nsACString
*aRef
)
2421 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2426 TRACE("(%p)->(%p)\n", This
, aRef
);
2428 if(!ensure_uri(This
))
2429 return NS_ERROR_UNEXPECTED
;
2431 hres
= IUri_GetFragment(This
->uri
, &ref
);
2433 return NS_ERROR_UNEXPECTED
;
2435 refa
= heap_strdupWtoU(ref
);
2438 return NS_ERROR_OUT_OF_MEMORY
;
2440 nsACString_SetData(aRef
, refa
&& *refa
== '#' ? refa
+1 : refa
);
2445 static nsresult NSAPI
nsURL_SetRef(nsIFileURL
*iface
, const nsACString
*aRef
)
2447 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2452 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRef
));
2454 if(!ensure_uri_builder(This
))
2455 return NS_ERROR_UNEXPECTED
;
2457 nsACString_GetData(aRef
, &refa
);
2458 ref
= heap_strdupUtoW(refa
);
2460 return NS_ERROR_OUT_OF_MEMORY
;
2462 hres
= IUriBuilder_SetFragment(This
->uri_builder
, ref
);
2465 return NS_ERROR_UNEXPECTED
;
2470 static nsresult NSAPI
nsURI_EqualsExceptRef(nsIFileURL
*iface
, nsIURI
*other
, cpp_bool
*_retval
)
2472 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2473 nsWineURI
*other_obj
;
2476 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
2478 nsres
= nsIURI_QueryInterface(other
, &IID_nsWineURI
, (void**)&other_obj
);
2479 if(NS_FAILED(nsres
)) {
2480 TRACE("Could not get nsWineURI interface\n");
2485 if(ensure_uri(This
) && ensure_uri(other_obj
)) {
2486 *_retval
= compare_ignoring_frag(This
->uri
, other_obj
->uri
);
2489 nsres
= NS_ERROR_UNEXPECTED
;
2492 nsIFileURL_Release(&other_obj
->nsIFileURL_iface
);
2496 static nsresult NSAPI
nsURI_CloneIgnoreRef(nsIFileURL
*iface
, nsIURI
**_retval
)
2498 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2499 nsWineURI
*wine_uri
;
2503 TRACE("(%p)->(%p)\n", This
, _retval
);
2505 if(!ensure_uri(This
))
2506 return NS_ERROR_UNEXPECTED
;
2508 uri
= get_uri_nofrag(This
->uri
);
2510 return NS_ERROR_FAILURE
;
2512 nsres
= create_nsuri(uri
, This
->window_ref
? This
->window_ref
->window
: NULL
, This
->container
,
2513 This
->origin_charset
, &wine_uri
);
2515 if(NS_FAILED(nsres
)) {
2516 WARN("create_nsuri failed: %08x\n", nsres
);
2520 *_retval
= (nsIURI
*)&wine_uri
->nsIFileURL_iface
;
2524 static nsresult NSAPI
nsURI_GetSpecIgnoringRef(nsIFileURL
*iface
, nsACString
*aSpecIgnoringRef
)
2526 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2528 FIXME("(%p)->(%p)\n", This
, aSpecIgnoringRef
);
2530 return nsIFileURL_GetSpec(&This
->nsIFileURL_iface
, aSpecIgnoringRef
);
2533 static nsresult NSAPI
nsURI_GetHasRef(nsIFileURL
*iface
, cpp_bool
*aHasRef
)
2535 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2539 TRACE("(%p)->(%p)\n", This
, aHasRef
);
2541 if(!ensure_uri(This
))
2542 return NS_ERROR_UNEXPECTED
;
2544 hres
= IUri_HasProperty(This
->uri
, Uri_PROPERTY_FRAGMENT
, &b
);
2546 return NS_ERROR_FAILURE
;
2552 static nsresult NSAPI
nsURL_GetFilePath(nsIFileURL
*iface
, nsACString
*aFilePath
)
2554 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2556 TRACE("(%p)->(%p)\n", This
, aFilePath
);
2558 return nsIFileURL_GetPath(&This
->nsIFileURL_iface
, aFilePath
);
2561 static nsresult NSAPI
nsURL_SetFilePath(nsIFileURL
*iface
, const nsACString
*aFilePath
)
2563 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2565 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFilePath
));
2567 if(!This
->is_mutable
)
2568 return NS_ERROR_UNEXPECTED
;
2570 return nsIFileURL_SetPath(&This
->nsIFileURL_iface
, aFilePath
);
2573 static nsresult NSAPI
nsURL_GetQuery(nsIFileURL
*iface
, nsACString
*aQuery
)
2575 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2577 TRACE("(%p)->(%p)\n", This
, aQuery
);
2579 return get_uri_string(This
, Uri_PROPERTY_QUERY
, aQuery
);
2582 static nsresult NSAPI
nsURL_SetQuery(nsIFileURL
*iface
, const nsACString
*aQuery
)
2584 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2589 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aQuery
));
2591 if(!ensure_uri_builder(This
))
2592 return NS_ERROR_UNEXPECTED
;
2594 nsACString_GetData(aQuery
, &querya
);
2595 query
= heap_strdupUtoW(querya
);
2597 return NS_ERROR_OUT_OF_MEMORY
;
2599 hres
= IUriBuilder_SetQuery(This
->uri_builder
, query
);
2602 return NS_ERROR_UNEXPECTED
;
2607 static nsresult
get_uri_path(nsWineURI
*This
, BSTR
*path
, const WCHAR
**file
, const WCHAR
**ext
)
2612 if(!ensure_uri(This
))
2613 return NS_ERROR_UNEXPECTED
;
2615 hres
= IUri_GetPath(This
->uri
, path
);
2617 return NS_ERROR_FAILURE
;
2619 for(ptr
= *path
+ SysStringLen(*path
)-1; ptr
> *path
&& *ptr
!= '/' && *ptr
!= '\\'; ptr
--);
2620 if(*ptr
== '/' || *ptr
== '\\')
2625 ptr
= strrchrW(ptr
, '.');
2627 ptr
= *path
+ SysStringLen(*path
);
2634 static nsresult NSAPI
nsURL_GetDirectory(nsIFileURL
*iface
, nsACString
*aDirectory
)
2636 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2641 TRACE("(%p)->(%p)\n", This
, aDirectory
);
2643 nsres
= get_uri_path(This
, &path
, &file
, NULL
);
2644 if(NS_FAILED(nsres
))
2647 nsres
= return_wstr_nsacstr(aDirectory
, path
, file
-path
);
2648 SysFreeString(path
);
2652 static nsresult NSAPI
nsURL_SetDirectory(nsIFileURL
*iface
, const nsACString
*aDirectory
)
2654 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2656 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aDirectory
));
2658 /* Not implemented by Gecko */
2659 return NS_ERROR_NOT_IMPLEMENTED
;
2662 static nsresult NSAPI
nsURL_GetFileName(nsIFileURL
*iface
, nsACString
*aFileName
)
2664 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2669 TRACE("(%p)->(%p)\n", This
, aFileName
);
2671 nsres
= get_uri_path(This
, &path
, &file
, NULL
);
2672 if(NS_FAILED(nsres
))
2675 nsres
= return_wstr_nsacstr(aFileName
, file
, -1);
2676 SysFreeString(path
);
2680 static nsresult NSAPI
nsURL_SetFileName(nsIFileURL
*iface
, const nsACString
*aFileName
)
2682 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2683 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileName
));
2684 return NS_ERROR_NOT_IMPLEMENTED
;
2687 static nsresult NSAPI
nsURL_GetFileBaseName(nsIFileURL
*iface
, nsACString
*aFileBaseName
)
2689 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2690 const WCHAR
*file
, *ext
;
2694 TRACE("(%p)->(%p)\n", This
, aFileBaseName
);
2696 nsres
= get_uri_path(This
, &path
, &file
, &ext
);
2697 if(NS_FAILED(nsres
))
2700 nsres
= return_wstr_nsacstr(aFileBaseName
, file
, ext
-file
);
2701 SysFreeString(path
);
2705 static nsresult NSAPI
nsURL_SetFileBaseName(nsIFileURL
*iface
, const nsACString
*aFileBaseName
)
2707 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2708 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileBaseName
));
2709 return NS_ERROR_NOT_IMPLEMENTED
;
2712 static nsresult NSAPI
nsURL_GetFileExtension(nsIFileURL
*iface
, nsACString
*aFileExtension
)
2714 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2716 TRACE("(%p)->(%p)\n", This
, aFileExtension
);
2718 return get_uri_string(This
, Uri_PROPERTY_EXTENSION
, aFileExtension
);
2721 static nsresult NSAPI
nsURL_SetFileExtension(nsIFileURL
*iface
, const nsACString
*aFileExtension
)
2723 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2724 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileExtension
));
2725 return NS_ERROR_NOT_IMPLEMENTED
;
2728 static nsresult NSAPI
nsURL_GetCommonBaseSpec(nsIFileURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2730 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2731 FIXME("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2732 return NS_ERROR_NOT_IMPLEMENTED
;
2735 static nsresult NSAPI
nsURL_GetRelativeSpec(nsIFileURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2737 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2738 FIXME("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2739 return NS_ERROR_NOT_IMPLEMENTED
;
2742 static nsresult NSAPI
nsFileURL_GetFile(nsIFileURL
*iface
, nsIFile
**aFile
)
2744 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2745 WCHAR path
[MAX_PATH
];
2749 TRACE("(%p)->(%p)\n", This
, aFile
);
2751 hres
= CoInternetParseIUri(This
->uri
, PARSE_PATH_FROM_URL
, 0, path
, sizeof(path
)/sizeof(WCHAR
), &size
, 0);
2753 WARN("CoInternetParseIUri failed: %08x\n", hres
);
2754 return NS_ERROR_FAILURE
;
2757 return create_nsfile(path
, aFile
);
2760 static nsresult NSAPI
nsFileURL_SetFile(nsIFileURL
*iface
, nsIFile
*aFile
)
2762 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2763 FIXME("(%p)->(%p)\n", This
, aFile
);
2764 return NS_ERROR_NOT_IMPLEMENTED
;
2767 static const nsIFileURLVtbl nsFileURLVtbl
= {
2768 nsURI_QueryInterface
,
2796 nsURI_GetOriginCharset
,
2799 nsURI_EqualsExceptRef
,
2800 nsURI_CloneIgnoreRef
,
2801 nsURI_GetSpecIgnoringRef
,
2811 nsURL_GetFileBaseName
,
2812 nsURL_SetFileBaseName
,
2813 nsURL_GetFileExtension
,
2814 nsURL_SetFileExtension
,
2815 nsURL_GetCommonBaseSpec
,
2816 nsURL_GetRelativeSpec
,
2821 static inline nsWineURI
*impl_from_nsIStandardURL(nsIStandardURL
*iface
)
2823 return CONTAINING_RECORD(iface
, nsWineURI
, nsIStandardURL_iface
);
2826 static nsresult NSAPI
nsStandardURL_QueryInterface(nsIStandardURL
*iface
, nsIIDRef riid
,
2829 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2830 return nsIFileURL_QueryInterface(&This
->nsIFileURL_iface
, riid
, result
);
2833 static nsrefcnt NSAPI
nsStandardURL_AddRef(nsIStandardURL
*iface
)
2835 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2836 return nsIFileURL_AddRef(&This
->nsIFileURL_iface
);
2839 static nsrefcnt NSAPI
nsStandardURL_Release(nsIStandardURL
*iface
)
2841 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2842 return nsIFileURL_Release(&This
->nsIFileURL_iface
);
2845 static nsresult NSAPI
nsStandardURL_GetMutable(nsIStandardURL
*iface
, cpp_bool
*aMutable
)
2847 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2849 TRACE("(%p)->(%p)\n", This
, aMutable
);
2851 *aMutable
= This
->is_mutable
;
2855 static nsresult NSAPI
nsStandardURL_SetMutable(nsIStandardURL
*iface
, cpp_bool aMutable
)
2857 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2859 TRACE("(%p)->(%x)\n", This
, aMutable
);
2861 This
->is_mutable
= aMutable
;
2865 static nsresult NSAPI
nsStandardURL_Init(nsIStandardURL
*iface
, UINT32 aUrlType
, LONG aDefaultPort
,
2866 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
)
2868 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2869 FIXME("(%p)->(%d %d %s %s %p)\n", This
, aUrlType
, aDefaultPort
, debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
), aBaseURI
);
2870 return NS_ERROR_NOT_IMPLEMENTED
;
2873 static const nsIStandardURLVtbl nsStandardURLVtbl
= {
2874 nsStandardURL_QueryInterface
,
2875 nsStandardURL_AddRef
,
2876 nsStandardURL_Release
,
2877 nsStandardURL_GetMutable
,
2878 nsStandardURL_SetMutable
,
2882 static nsresult
create_nsuri(IUri
*iuri
, HTMLOuterWindow
*window
, NSContainer
*container
,
2883 const char *origin_charset
, nsWineURI
**_retval
)
2888 ret
= heap_alloc_zero(sizeof(nsWineURI
));
2890 return NS_ERROR_OUT_OF_MEMORY
;
2892 ret
->nsIFileURL_iface
.lpVtbl
= &nsFileURLVtbl
;
2893 ret
->nsIStandardURL_iface
.lpVtbl
= &nsStandardURLVtbl
;
2895 ret
->is_mutable
= TRUE
;
2897 set_uri_nscontainer(ret
, container
);
2898 set_uri_window(ret
, window
);
2903 hres
= IUri_GetScheme(iuri
, &ret
->scheme
);
2905 ret
->scheme
= URL_SCHEME_UNKNOWN
;
2907 if(origin_charset
&& *origin_charset
&& strcmp(origin_charset
, "UTF-8")) {
2908 ret
->origin_charset
= heap_strdupA(origin_charset
);
2909 if(!ret
->origin_charset
) {
2910 nsIFileURL_Release(&ret
->nsIFileURL_iface
);
2911 return NS_ERROR_OUT_OF_MEMORY
;
2915 TRACE("retval=%p\n", ret
);
2920 HRESULT
create_doc_uri(HTMLOuterWindow
*window
, IUri
*iuri
, nsWineURI
**ret
)
2925 nsres
= create_nsuri(iuri
, window
, window
->doc_obj
->nscontainer
, NULL
, &uri
);
2926 if(NS_FAILED(nsres
))
2929 uri
->is_doc_uri
= TRUE
;
2935 static nsresult
create_nschannel(nsWineURI
*uri
, nsChannel
**ret
)
2939 if(!ensure_uri(uri
))
2940 return NS_ERROR_UNEXPECTED
;
2942 channel
= heap_alloc_zero(sizeof(nsChannel
));
2944 return NS_ERROR_OUT_OF_MEMORY
;
2946 channel
->nsIHttpChannel_iface
.lpVtbl
= &nsChannelVtbl
;
2947 channel
->nsIUploadChannel_iface
.lpVtbl
= &nsUploadChannelVtbl
;
2948 channel
->nsIHttpChannelInternal_iface
.lpVtbl
= &nsHttpChannelInternalVtbl
;
2950 channel
->request_method
= METHOD_GET
;
2951 list_init(&channel
->response_headers
);
2952 list_init(&channel
->request_headers
);
2954 nsIFileURL_AddRef(&uri
->nsIFileURL_iface
);
2961 HRESULT
create_redirect_nschannel(const WCHAR
*url
, nsChannel
*orig_channel
, nsChannel
**ret
)
2963 HTMLOuterWindow
*window
= NULL
;
2970 hres
= create_uri(url
, 0, &iuri
);
2974 if(orig_channel
->uri
->window_ref
)
2975 window
= orig_channel
->uri
->window_ref
->window
;
2976 nsres
= create_nsuri(iuri
, window
, NULL
, NULL
, &uri
);
2978 if(NS_FAILED(nsres
))
2981 nsres
= create_nschannel(uri
, &channel
);
2982 nsIFileURL_Release(&uri
->nsIFileURL_iface
);
2983 if(NS_FAILED(nsres
))
2986 if(orig_channel
->load_group
) {
2987 nsILoadGroup_AddRef(orig_channel
->load_group
);
2988 channel
->load_group
= orig_channel
->load_group
;
2991 if(orig_channel
->notif_callback
) {
2992 nsIInterfaceRequestor_AddRef(orig_channel
->notif_callback
);
2993 channel
->notif_callback
= orig_channel
->notif_callback
;
2996 channel
->load_flags
= orig_channel
->load_flags
| LOAD_REPLACE
;
2998 if(orig_channel
->request_method
== METHOD_POST
)
2999 FIXME("unsupported POST method\n");
3001 if(orig_channel
->original_uri
) {
3002 nsIURI_AddRef(orig_channel
->original_uri
);
3003 channel
->original_uri
= orig_channel
->original_uri
;
3006 if(orig_channel
->referrer
) {
3007 nsIURI_AddRef(orig_channel
->referrer
);
3008 channel
->referrer
= orig_channel
->referrer
;
3016 nsIProtocolHandler nsIProtocolHandler_iface
;
3020 nsIProtocolHandler
*nshandler
;
3021 } nsProtocolHandler
;
3023 static inline nsProtocolHandler
*impl_from_nsIProtocolHandler(nsIProtocolHandler
*iface
)
3025 return CONTAINING_RECORD(iface
, nsProtocolHandler
, nsIProtocolHandler_iface
);
3028 static nsresult NSAPI
nsProtocolHandler_QueryInterface(nsIProtocolHandler
*iface
, nsIIDRef riid
,
3031 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3035 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
3036 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
3037 *result
= &This
->nsIProtocolHandler_iface
;
3038 }else if(IsEqualGUID(&IID_nsIProtocolHandler
, riid
)) {
3039 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This
, result
);
3040 *result
= &This
->nsIProtocolHandler_iface
;
3041 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler
, riid
)) {
3042 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This
, result
);
3043 return NS_NOINTERFACE
;
3047 nsISupports_AddRef((nsISupports
*)*result
);
3051 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
3052 return NS_NOINTERFACE
;
3055 static nsrefcnt NSAPI
nsProtocolHandler_AddRef(nsIProtocolHandler
*iface
)
3057 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3058 LONG ref
= InterlockedIncrement(&This
->ref
);
3060 TRACE("(%p) ref=%d\n", This
, ref
);
3065 static nsrefcnt NSAPI
nsProtocolHandler_Release(nsIProtocolHandler
*iface
)
3067 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3068 LONG ref
= InterlockedDecrement(&This
->ref
);
3070 TRACE("(%p) ref=%d\n", This
, ref
);
3074 nsIProtocolHandler_Release(This
->nshandler
);
3081 static nsresult NSAPI
nsProtocolHandler_GetScheme(nsIProtocolHandler
*iface
, nsACString
*aScheme
)
3083 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3085 TRACE("(%p)->(%p)\n", This
, aScheme
);
3088 return nsIProtocolHandler_GetScheme(This
->nshandler
, aScheme
);
3089 return NS_ERROR_NOT_IMPLEMENTED
;
3092 static nsresult NSAPI
nsProtocolHandler_GetDefaultPort(nsIProtocolHandler
*iface
,
3095 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3097 TRACE("(%p)->(%p)\n", This
, aDefaultPort
);
3100 return nsIProtocolHandler_GetDefaultPort(This
->nshandler
, aDefaultPort
);
3101 return NS_ERROR_NOT_IMPLEMENTED
;
3104 static nsresult NSAPI
nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler
*iface
,
3105 UINT32
*aProtocolFlags
)
3107 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3109 TRACE("(%p)->(%p)\n", This
, aProtocolFlags
);
3112 return nsIProtocolHandler_GetProtocolFlags(This
->nshandler
, aProtocolFlags
);
3113 return NS_ERROR_NOT_IMPLEMENTED
;
3116 static nsresult NSAPI
nsProtocolHandler_NewURI(nsIProtocolHandler
*iface
,
3117 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
3119 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3121 TRACE("((%p)->%s %s %p %p)\n", This
, debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
3125 return nsIProtocolHandler_NewURI(This
->nshandler
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3126 return NS_ERROR_NOT_IMPLEMENTED
;
3129 static nsresult NSAPI
nsProtocolHandler_NewChannel(nsIProtocolHandler
*iface
,
3130 nsIURI
*aURI
, nsIChannel
**_retval
)
3132 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3134 TRACE("(%p)->(%p %p)\n", This
, aURI
, _retval
);
3137 return nsIProtocolHandler_NewChannel(This
->nshandler
, aURI
, _retval
);
3138 return NS_ERROR_NOT_IMPLEMENTED
;
3141 static nsresult NSAPI
nsProtocolHandler_AllowPort(nsIProtocolHandler
*iface
,
3142 LONG port
, const char *scheme
, cpp_bool
*_retval
)
3144 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3146 TRACE("(%p)->(%d %s %p)\n", This
, port
, debugstr_a(scheme
), _retval
);
3149 return nsIProtocolHandler_AllowPort(This
->nshandler
, port
, scheme
, _retval
);
3150 return NS_ERROR_NOT_IMPLEMENTED
;
3153 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl
= {
3154 nsProtocolHandler_QueryInterface
,
3155 nsProtocolHandler_AddRef
,
3156 nsProtocolHandler_Release
,
3157 nsProtocolHandler_GetScheme
,
3158 nsProtocolHandler_GetDefaultPort
,
3159 nsProtocolHandler_GetProtocolFlags
,
3160 nsProtocolHandler_NewURI
,
3161 nsProtocolHandler_NewChannel
,
3162 nsProtocolHandler_AllowPort
3165 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*,nsIIDRef
,void**);
3167 static nsrefcnt NSAPI
nsIOService_AddRef(nsIIOService
*iface
)
3172 static nsrefcnt NSAPI
nsIOService_Release(nsIIOService
*iface
)
3177 static nsresult NSAPI
nsIOService_GetProtocolHandler(nsIIOService
*iface
, const char *aScheme
,
3178 nsIProtocolHandler
**_retval
)
3180 nsIExternalProtocolHandler
*nsexthandler
;
3181 nsIProtocolHandler
*nshandler
;
3182 nsProtocolHandler
*ret
;
3185 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
3187 nsres
= nsIIOService_GetProtocolHandler(nsio
, aScheme
, &nshandler
);
3188 if(NS_FAILED(nsres
)) {
3189 WARN("GetProtocolHandler failed: %08x\n", nsres
);
3193 nsres
= nsIProtocolHandler_QueryInterface(nshandler
, &IID_nsIExternalProtocolHandler
,
3194 (void**)&nsexthandler
);
3195 if(NS_FAILED(nsres
)) {
3196 *_retval
= nshandler
;
3200 nsIExternalProtocolHandler_Release(nsexthandler
);
3202 ret
= heap_alloc(sizeof(nsProtocolHandler
));
3204 return NS_ERROR_OUT_OF_MEMORY
;
3206 ret
->nsIProtocolHandler_iface
.lpVtbl
= &nsProtocolHandlerVtbl
;
3208 ret
->nshandler
= nshandler
;
3209 *_retval
= &ret
->nsIProtocolHandler_iface
;
3211 TRACE("return %p\n", *_retval
);
3215 static nsresult NSAPI
nsIOService_GetProtocolFlags(nsIIOService
*iface
, const char *aScheme
,
3218 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
3219 return nsIIOService_GetProtocolFlags(nsio
, aScheme
, _retval
);
3222 static BOOL
is_gecko_special_uri(const char *spec
)
3224 static const char *special_schemes
[] = {"chrome:", "jar:", "moz-safe-about", "resource:", "javascript:", "wyciwyg:"};
3227 for(i
=0; i
< sizeof(special_schemes
)/sizeof(*special_schemes
); i
++) {
3228 if(!strncasecmp(spec
, special_schemes
[i
], strlen(special_schemes
[i
])))
3232 if(!strncasecmp(spec
, "file:", 5)) {
3233 const char *ptr
= spec
+5;
3236 return is_gecko_path(ptr
);
3242 static nsresult NSAPI
nsIOService_NewURI(nsIIOService
*iface
, const nsACString
*aSpec
,
3243 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
3245 nsWineURI
*wine_uri
, *base_wine_uri
= NULL
;
3246 WCHAR new_spec
[INTERNET_MAX_URL_LENGTH
];
3247 HTMLOuterWindow
*window
= NULL
;
3248 const char *spec
= NULL
;
3253 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
3256 nsACString_GetData(aSpec
, &spec
);
3257 if(is_gecko_special_uri(spec
))
3258 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3260 if(!strncmp(spec
, "wine:", 5))
3264 nsres
= nsIURI_QueryInterface(aBaseURI
, &IID_nsWineURI
, (void**)&base_wine_uri
);
3265 if(NS_SUCCEEDED(nsres
)) {
3266 if(!ensure_uri(base_wine_uri
))
3267 return NS_ERROR_UNEXPECTED
;
3268 if(base_wine_uri
->window_ref
)
3269 window
= base_wine_uri
->window_ref
->window
;
3271 WARN("Could not get base nsWineURI: %08x\n", nsres
);
3275 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, new_spec
, sizeof(new_spec
)/sizeof(WCHAR
));
3278 hres
= CoInternetCombineUrlEx(base_wine_uri
->uri
, new_spec
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
3281 WARN("CoInternetCombineUrlEx failed: %08x\n", hres
);
3283 hres
= create_uri(new_spec
, 0, &urlmon_uri
);
3285 WARN("create_uri failed: %08x\n", hres
);
3289 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3291 nsres
= create_nsuri(urlmon_uri
, window
, NULL
, NULL
, &wine_uri
);
3292 IUri_Release(urlmon_uri
);
3294 nsIFileURL_Release(&base_wine_uri
->nsIFileURL_iface
);
3295 if(NS_FAILED(nsres
))
3298 *_retval
= (nsIURI
*)&wine_uri
->nsIFileURL_iface
;
3302 static nsresult NSAPI
nsIOService_NewFileURI(nsIIOService
*iface
, nsIFile
*aFile
,
3305 TRACE("(%p %p)\n", aFile
, _retval
);
3306 return nsIIOService_NewFileURI(nsio
, aFile
, _retval
);
3309 static nsresult NSAPI
nsIOService_NewChannelFromURI(nsIIOService
*iface
, nsIURI
*aURI
,
3310 nsIChannel
**_retval
)
3312 nsWineURI
*wine_uri
;
3316 TRACE("(%p %p)\n", aURI
, _retval
);
3318 nsres
= nsIURI_QueryInterface(aURI
, &IID_nsWineURI
, (void**)&wine_uri
);
3319 if(NS_FAILED(nsres
)) {
3320 TRACE("Could not get nsWineURI: %08x\n", nsres
);
3321 return nsIIOService_NewChannelFromURI(nsio
, aURI
, _retval
);
3324 nsres
= create_nschannel(wine_uri
, &ret
);
3325 nsIFileURL_Release(&wine_uri
->nsIFileURL_iface
);
3326 if(NS_FAILED(nsres
))
3329 nsIURI_AddRef(aURI
);
3330 ret
->original_uri
= aURI
;
3332 *_retval
= (nsIChannel
*)&ret
->nsIHttpChannel_iface
;
3336 static nsresult NSAPI
nsIOService_NewChannel(nsIIOService
*iface
, const nsACString
*aSpec
,
3337 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIChannel
**_retval
)
3339 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
), aBaseURI
, _retval
);
3340 return nsIIOService_NewChannel(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3343 static nsresult NSAPI
nsIOService_GetOffline(nsIIOService
*iface
, cpp_bool
*aOffline
)
3345 TRACE("(%p)\n", aOffline
);
3346 return nsIIOService_GetOffline(nsio
, aOffline
);
3349 static nsresult NSAPI
nsIOService_SetOffline(nsIIOService
*iface
, cpp_bool aOffline
)
3351 TRACE("(%x)\n", aOffline
);
3352 return nsIIOService_SetOffline(nsio
, aOffline
);
3355 static nsresult NSAPI
nsIOService_AllowPort(nsIIOService
*iface
, LONG aPort
,
3356 const char *aScheme
, cpp_bool
*_retval
)
3358 TRACE("(%d %s %p)\n", aPort
, debugstr_a(aScheme
), _retval
);
3359 return nsIIOService_AllowPort(nsio
, aPort
, debugstr_a(aScheme
), _retval
);
3362 static nsresult NSAPI
nsIOService_ExtractScheme(nsIIOService
*iface
, const nsACString
*urlString
,
3363 nsACString
* _retval
)
3365 TRACE("(%s %p)\n", debugstr_nsacstr(urlString
), _retval
);
3366 return nsIIOService_ExtractScheme(nsio
, urlString
, _retval
);
3369 static const nsIIOServiceVtbl nsIOServiceVtbl
= {
3370 nsIOService_QueryInterface
,
3372 nsIOService_Release
,
3373 nsIOService_GetProtocolHandler
,
3374 nsIOService_GetProtocolFlags
,
3376 nsIOService_NewFileURI
,
3377 nsIOService_NewChannelFromURI
,
3378 nsIOService_NewChannel
,
3379 nsIOService_GetOffline
,
3380 nsIOService_SetOffline
,
3381 nsIOService_AllowPort
,
3382 nsIOService_ExtractScheme
3385 static nsIIOService nsIOService
= { &nsIOServiceVtbl
};
3387 static nsresult NSAPI
nsNetUtil_QueryInterface(nsINetUtil
*iface
, nsIIDRef riid
,
3390 return nsIIOService_QueryInterface(&nsIOService
, riid
, result
);
3393 static nsrefcnt NSAPI
nsNetUtil_AddRef(nsINetUtil
*iface
)
3398 static nsrefcnt NSAPI
nsNetUtil_Release(nsINetUtil
*iface
)
3403 static nsresult NSAPI
nsNetUtil_ParseContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
3404 nsACString
*aCharset
, cpp_bool
*aHadCharset
, nsACString
*aContentType
)
3406 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aHadCharset
, aContentType
);
3408 return nsINetUtil_ParseContentType(net_util
, aTypeHeader
, aCharset
, aHadCharset
, aContentType
);
3411 static nsresult NSAPI
nsNetUtil_ProtocolHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, UINT32 aFlags
, cpp_bool
*_retval
)
3415 return nsINetUtil_ProtocolHasFlags(net_util
, aURI
, aFlags
, _retval
);
3418 static nsresult NSAPI
nsNetUtil_URIChainHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, UINT32 aFlags
, cpp_bool
*_retval
)
3420 TRACE("(%p %08x %p)\n", aURI
, aFlags
, _retval
);
3422 if(aFlags
== (1<<11)) {
3427 return nsINetUtil_URIChainHasFlags(net_util
, aURI
, aFlags
, _retval
);
3430 static nsresult NSAPI
nsNetUtil_ToImmutableURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
3432 TRACE("(%p %p)\n", aURI
, _retval
);
3434 return nsINetUtil_ToImmutableURI(net_util
, aURI
, _retval
);
3437 static nsresult NSAPI
nsNetUtil_NewSimpleNestedURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
3439 TRACE("(%p %p)\n", aURI
, _retval
);
3441 return nsINetUtil_NewSimpleNestedURI(net_util
, aURI
, _retval
);
3444 static nsresult NSAPI
nsNetUtil_EscapeString(nsINetUtil
*iface
, const nsACString
*aString
,
3445 UINT32 aEscapeType
, nsACString
*_retval
)
3447 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString
), aEscapeType
, _retval
);
3449 return nsINetUtil_EscapeString(net_util
, aString
, aEscapeType
, _retval
);
3452 static nsresult NSAPI
nsNetUtil_EscapeURL(nsINetUtil
*iface
, const nsACString
*aStr
, UINT32 aFlags
,
3453 nsACString
*_retval
)
3455 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
3457 return nsINetUtil_EscapeURL(net_util
, aStr
, aFlags
, _retval
);
3460 static nsresult NSAPI
nsNetUtil_UnescapeString(nsINetUtil
*iface
, const nsACString
*aStr
,
3461 UINT32 aFlags
, nsACString
*_retval
)
3463 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
3465 return nsINetUtil_UnescapeString(net_util
, aStr
, aFlags
, _retval
);
3468 static nsresult NSAPI
nsNetUtil_ExtractCharsetFromContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
3469 nsACString
*aCharset
, LONG
*aCharsetStart
, LONG
*aCharsetEnd
, cpp_bool
*_retval
)
3471 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aCharsetStart
,
3472 aCharsetEnd
, _retval
);
3474 return nsINetUtil_ExtractCharsetFromContentType(net_util
, aTypeHeader
, aCharset
, aCharsetStart
, aCharsetEnd
, _retval
);
3477 static const nsINetUtilVtbl nsNetUtilVtbl
= {
3478 nsNetUtil_QueryInterface
,
3481 nsNetUtil_ParseContentType
,
3482 nsNetUtil_ProtocolHasFlags
,
3483 nsNetUtil_URIChainHasFlags
,
3484 nsNetUtil_ToImmutableURI
,
3485 nsNetUtil_NewSimpleNestedURI
,
3486 nsNetUtil_EscapeString
,
3487 nsNetUtil_EscapeURL
,
3488 nsNetUtil_UnescapeString
,
3489 nsNetUtil_ExtractCharsetFromContentType
3492 static nsINetUtil nsNetUtil
= { &nsNetUtilVtbl
};
3494 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*iface
, nsIIDRef riid
,
3499 if(IsEqualGUID(&IID_nsISupports
, riid
))
3500 *result
= &nsIOService
;
3501 else if(IsEqualGUID(&IID_nsIIOService
, riid
))
3502 *result
= &nsIOService
;
3503 else if(IsEqualGUID(&IID_nsINetUtil
, riid
))
3504 *result
= &nsNetUtil
;
3507 nsISupports_AddRef((nsISupports
*)*result
);
3511 FIXME("(%s %p)\n", debugstr_guid(riid
), result
);
3512 return NS_NOINTERFACE
;
3515 static nsresult NSAPI
nsIOServiceFactory_QueryInterface(nsIFactory
*iface
, nsIIDRef riid
,
3520 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
3521 TRACE("(IID_nsISupports %p)\n", result
);
3523 }else if(IsEqualGUID(&IID_nsIFactory
, riid
)) {
3524 TRACE("(IID_nsIFactory %p)\n", result
);
3529 nsIFactory_AddRef(iface
);
3533 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
3534 return NS_NOINTERFACE
;
3537 static nsrefcnt NSAPI
nsIOServiceFactory_AddRef(nsIFactory
*iface
)
3542 static nsrefcnt NSAPI
nsIOServiceFactory_Release(nsIFactory
*iface
)
3547 static nsresult NSAPI
nsIOServiceFactory_CreateInstance(nsIFactory
*iface
,
3548 nsISupports
*aOuter
, const nsIID
*iid
, void **result
)
3550 return nsIIOService_QueryInterface(&nsIOService
, iid
, result
);
3553 static nsresult NSAPI
nsIOServiceFactory_LockFactory(nsIFactory
*iface
, cpp_bool lock
)
3555 WARN("(%x)\n", lock
);
3559 static const nsIFactoryVtbl nsIOServiceFactoryVtbl
= {
3560 nsIOServiceFactory_QueryInterface
,
3561 nsIOServiceFactory_AddRef
,
3562 nsIOServiceFactory_Release
,
3563 nsIOServiceFactory_CreateInstance
,
3564 nsIOServiceFactory_LockFactory
3567 static nsIFactory nsIOServiceFactory
= { &nsIOServiceFactoryVtbl
};
3569 static BOOL
translate_url(HTMLDocumentObj
*doc
, nsWineURI
*uri
)
3571 OLECHAR
*new_url
= NULL
;
3576 if(!doc
->hostui
|| !ensure_uri(uri
))
3579 hres
= IUri_GetDisplayUri(uri
->uri
, &url
);
3583 hres
= IDocHostUIHandler_TranslateUrl(doc
->hostui
, 0, url
, &new_url
);
3584 if(hres
== S_OK
&& new_url
) {
3585 if(strcmpW(url
, new_url
)) {
3586 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url
), debugstr_w(new_url
));
3589 CoTaskMemFree(new_url
);
3596 nsresult
on_start_uri_open(NSContainer
*nscontainer
, nsIURI
*uri
, cpp_bool
*_retval
)
3598 nsWineURI
*wine_uri
;
3603 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
3604 if(NS_FAILED(nsres
)) {
3605 WARN("Could not get nsWineURI: %08x\n", nsres
);
3606 return NS_ERROR_NOT_IMPLEMENTED
;
3609 if(!wine_uri
->is_doc_uri
) {
3610 wine_uri
->is_doc_uri
= TRUE
;
3612 if(!wine_uri
->container
) {
3613 nsIWebBrowserChrome_AddRef(&nscontainer
->nsIWebBrowserChrome_iface
);
3614 wine_uri
->container
= nscontainer
;
3617 if(nscontainer
->doc
)
3618 *_retval
= translate_url(nscontainer
->doc
, wine_uri
);
3621 nsIFileURL_Release(&wine_uri
->nsIFileURL_iface
);
3625 void init_nsio(nsIComponentManager
*component_manager
, nsIComponentRegistrar
*registrar
)
3627 nsIFactory
*old_factory
= NULL
;
3630 nsres
= nsIComponentManager_GetClassObject(component_manager
, &NS_IOSERVICE_CID
,
3631 &IID_nsIFactory
, (void**)&old_factory
);
3632 if(NS_FAILED(nsres
)) {
3633 ERR("Could not get factory: %08x\n", nsres
);
3637 nsres
= nsIFactory_CreateInstance(old_factory
, NULL
, &IID_nsIIOService
, (void**)&nsio
);
3638 if(NS_FAILED(nsres
)) {
3639 ERR("Couldn not create nsIOService instance %08x\n", nsres
);
3640 nsIFactory_Release(old_factory
);
3644 nsres
= nsIIOService_QueryInterface(nsio
, &IID_nsINetUtil
, (void**)&net_util
);
3645 if(NS_FAILED(nsres
)) {
3646 WARN("Could not get nsINetUtil interface: %08x\n", nsres
);
3647 nsIIOService_Release(nsio
);
3651 nsres
= nsIComponentRegistrar_UnregisterFactory(registrar
, &NS_IOSERVICE_CID
, old_factory
);
3652 nsIFactory_Release(old_factory
);
3653 if(NS_FAILED(nsres
))
3654 ERR("UnregisterFactory failed: %08x\n", nsres
);
3656 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_IOSERVICE_CID
,
3657 NS_IOSERVICE_CLASSNAME
, NS_IOSERVICE_CONTRACTID
, &nsIOServiceFactory
);
3658 if(NS_FAILED(nsres
))
3659 ERR("RegisterFactory failed: %08x\n", nsres
);
3662 void release_nsio(void)
3665 nsINetUtil_Release(net_util
);
3670 nsIIOService_Release(nsio
);