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
19 #define WIN32_NO_STATUS
31 //#include "winuser.h"
38 #include <wine/debug.h>
40 #include "mshtml_private.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
45 #define NS_IOSERVICE_CLASSNAME "nsIOService"
46 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
48 static const IID NS_IOSERVICE_CID
=
49 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
50 static const IID IID_nsWineURI
=
51 {0x5088272e, 0x900b, 0x11da, {0xc6,0x87, 0x00,0x0f,0xea,0x57,0xf2,0x1a}};
53 static nsIIOService
*nsio
= NULL
;
54 static nsINetUtil
*net_util
;
56 static const char *request_method_strings
[] = {"GET", "PUT", "POST"};
59 nsIFileURL nsIFileURL_iface
; /* For non-file URL objects, it's just nsIURL */
60 nsIStandardURL nsIStandardURL_iface
;
64 NSContainer
*container
;
65 windowref_t
*window_ref
;
66 nsChannelBSC
*channel_bsc
;
68 IUriBuilder
*uri_builder
;
75 static BOOL
ensure_uri(nsWineURI
*This
)
79 assert(This
->uri
|| This
->uri_builder
);
82 hres
= IUriBuilder_CreateUriSimple(This
->uri_builder
, 0, 0, &This
->uri
);
84 WARN("CreateUriSimple failed: %08x\n", hres
);
92 IUri
*nsuri_get_uri(nsWineURI
*nsuri
)
94 if(!ensure_uri(nsuri
))
97 IUri_AddRef(nsuri
->uri
);
101 IUri
*get_uri_nofrag(IUri
*uri
)
103 IUriBuilder
*uri_builder
;
108 hres
= IUri_HasProperty(uri
, Uri_PROPERTY_FRAGMENT
, &b
);
109 if(SUCCEEDED(hres
) && !b
) {
114 hres
= CreateIUriBuilder(uri
, 0, 0, &uri_builder
);
118 hres
= IUriBuilder_RemoveProperties(uri_builder
, Uri_HAS_FRAGMENT
);
120 hres
= IUriBuilder_CreateUriSimple(uri_builder
, 0, 0, &ret
);
121 IUriBuilder_Release(uri_builder
);
128 static BOOL
compare_ignoring_frag(IUri
*uri1
, IUri
*uri2
)
130 IUri
*uri_nofrag1
, *uri_nofrag2
;
133 uri_nofrag1
= get_uri_nofrag(uri1
);
137 uri_nofrag2
= get_uri_nofrag(uri2
);
139 IUri_IsEqual(uri_nofrag1
, uri_nofrag2
, &ret
);
140 IUri_Release(uri_nofrag2
);
143 IUri_Release(uri_nofrag1
);
147 static nsresult
create_nsuri(IUri
*,HTMLOuterWindow
*,NSContainer
*,const char*,nsWineURI
**);
149 static const char *debugstr_nsacstr(const nsACString
*nsstr
)
153 nsACString_GetData(nsstr
, &data
);
154 return debugstr_a(data
);
157 static nsresult
return_wstr_nsacstr(nsACString
*ret_str
, const WCHAR
*str
, int len
)
162 TRACE("returning %s\n", debugstr_wn(str
, len
));
165 nsACString_SetData(ret_str
, "");
169 lena
= WideCharToMultiByte(CP_UTF8
, 0, str
, len
, NULL
, 0, NULL
, NULL
);
170 stra
= heap_alloc(lena
+1);
172 return NS_ERROR_OUT_OF_MEMORY
;
174 WideCharToMultiByte(CP_UTF8
, 0, str
, len
, stra
, lena
, NULL
, NULL
);
177 nsACString_SetData(ret_str
, stra
);
182 HRESULT
nsuri_to_url(LPCWSTR nsuri
, BOOL ret_empty
, BSTR
*ret
)
184 const WCHAR
*ptr
= nsuri
;
186 static const WCHAR wine_prefixW
[] = {'w','i','n','e',':'};
188 if(!strncmpW(nsuri
, wine_prefixW
, sizeof(wine_prefixW
)/sizeof(WCHAR
)))
189 ptr
+= sizeof(wine_prefixW
)/sizeof(WCHAR
);
191 if(*ptr
|| ret_empty
) {
192 *ret
= SysAllocString(ptr
);
194 return E_OUTOFMEMORY
;
199 TRACE("%s -> %s\n", debugstr_w(nsuri
), debugstr_w(*ret
));
203 static BOOL
exec_shldocvw_67(HTMLDocumentObj
*doc
, BSTR url
)
205 IOleCommandTarget
*cmdtrg
= NULL
;
208 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
209 if(SUCCEEDED(hres
)) {
210 VARIANT varUrl
, varRes
;
212 V_VT(&varUrl
) = VT_BSTR
;
213 V_BSTR(&varUrl
) = url
;
214 V_VT(&varRes
) = VT_BOOL
;
216 hres
= IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 67, 0, &varUrl
, &varRes
);
218 IOleCommandTarget_Release(cmdtrg
);
220 if(SUCCEEDED(hres
) && !V_BOOL(&varRes
)) {
221 TRACE("got VARIANT_FALSE, do not load\n");
229 static nsresult
before_async_open(nsChannel
*channel
, NSContainer
*container
, BOOL
*cancel
)
231 HTMLDocumentObj
*doc
= container
->doc
;
240 hres
= IUri_GetDisplayUri(channel
->uri
->uri
, &display_uri
);
242 return NS_ERROR_FAILURE
;
244 if(!exec_shldocvw_67(doc
, display_uri
)) {
245 SysFreeString(display_uri
);
250 hres
= hlink_frame_navigate(&doc
->basedoc
, display_uri
, channel
, 0, cancel
);
251 SysFreeString(display_uri
);
257 HRESULT
load_nsuri(HTMLOuterWindow
*window
, nsWineURI
*uri
, nsChannelBSC
*channelbsc
, DWORD flags
)
259 nsIWebNavigation
*web_navigation
;
260 nsIDocShell
*doc_shell
;
261 HTMLDocumentNode
*doc
;
264 nsres
= get_nsinterface((nsISupports
*)window
->nswindow
, &IID_nsIWebNavigation
, (void**)&web_navigation
);
265 if(NS_FAILED(nsres
)) {
266 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
270 nsres
= nsIWebNavigation_QueryInterface(web_navigation
, &IID_nsIDocShell
, (void**)&doc_shell
);
271 nsIWebNavigation_Release(web_navigation
);
272 if(NS_FAILED(nsres
)) {
273 ERR("Could not get nsIDocShell: %08x\n", nsres
);
277 uri
->channel_bsc
= channelbsc
;
278 doc
= window
->base
.inner_window
->doc
;
279 doc
->skip_mutation_notif
= TRUE
;
280 nsres
= nsIDocShell_LoadURI(doc_shell
, (nsIURI
*)&uri
->nsIFileURL_iface
, NULL
, flags
, FALSE
);
281 if(doc
== window
->base
.inner_window
->doc
)
282 doc
->skip_mutation_notif
= FALSE
;
283 uri
->channel_bsc
= NULL
;
284 nsIDocShell_Release(doc_shell
);
285 if(NS_FAILED(nsres
)) {
286 WARN("LoadURI failed: %08x\n", nsres
);
293 static void set_uri_nscontainer(nsWineURI
*This
, NSContainer
*nscontainer
)
295 if(This
->container
) {
296 if(This
->container
== nscontainer
)
298 TRACE("Changing %p -> %p\n", This
->container
, nscontainer
);
299 nsIWebBrowserChrome_Release(&This
->container
->nsIWebBrowserChrome_iface
);
303 nsIWebBrowserChrome_AddRef(&nscontainer
->nsIWebBrowserChrome_iface
);
304 This
->container
= nscontainer
;
307 static void set_uri_window(nsWineURI
*This
, HTMLOuterWindow
*window
)
309 if(This
->window_ref
) {
310 if(This
->window_ref
->window
== window
)
312 TRACE("Changing %p -> %p\n", This
->window_ref
->window
, window
);
313 windowref_release(This
->window_ref
);
317 windowref_addref(window
->window_ref
);
318 This
->window_ref
= window
->window_ref
;
321 set_uri_nscontainer(This
, window
->doc_obj
->nscontainer
);
323 This
->window_ref
= NULL
;
327 static inline BOOL
is_http_channel(nsChannel
*This
)
329 return This
->uri
->scheme
== URL_SCHEME_HTTP
|| This
->uri
->scheme
== URL_SCHEME_HTTPS
;
332 static http_header_t
*find_http_header(struct list
*headers
, const WCHAR
*name
, int len
)
336 LIST_FOR_EACH_ENTRY(iter
, headers
, http_header_t
, entry
) {
337 if(!strcmpiW(iter
->header
, name
))
344 static nsresult
get_channel_http_header(struct list
*headers
, const nsACString
*header_name_str
,
347 const char *header_namea
;
348 http_header_t
*header
;
352 nsACString_GetData(header_name_str
, &header_namea
);
353 header_name
= heap_strdupAtoW(header_namea
);
355 return NS_ERROR_UNEXPECTED
;
357 header
= find_http_header(headers
, header_name
, strlenW(header_name
));
358 heap_free(header_name
);
360 return NS_ERROR_NOT_AVAILABLE
;
362 data
= heap_strdupWtoA(header
->data
);
364 return NS_ERROR_UNEXPECTED
;
366 TRACE("%s -> %s\n", debugstr_a(header_namea
), debugstr_a(data
));
367 nsACString_SetData(_retval
, data
);
372 HRESULT
set_http_header(struct list
*headers
, const WCHAR
*name
, int name_len
,
373 const WCHAR
*value
, int value_len
)
375 http_header_t
*header
;
377 TRACE("%s: %s\n", debugstr_wn(name
, name_len
), debugstr_wn(value
, value_len
));
379 header
= find_http_header(headers
, name
, name_len
);
383 new_data
= heap_strndupW(value
, value_len
);
385 return E_OUTOFMEMORY
;
387 heap_free(header
->data
);
388 header
->data
= new_data
;
390 header
= heap_alloc(sizeof(http_header_t
));
392 return E_OUTOFMEMORY
;
394 header
->header
= heap_strndupW(name
, name_len
);
395 header
->data
= heap_strndupW(value
, value_len
);
396 if(!header
->header
|| !header
->data
) {
397 heap_free(header
->header
);
398 heap_free(header
->data
);
400 return E_OUTOFMEMORY
;
403 list_add_tail(headers
, &header
->entry
);
409 static nsresult
set_channel_http_header(struct list
*headers
, const nsACString
*name_str
,
410 const nsACString
*value_str
)
412 const char *namea
, *valuea
;
416 nsACString_GetData(name_str
, &namea
);
417 name
= heap_strdupAtoW(namea
);
419 return NS_ERROR_UNEXPECTED
;
421 nsACString_GetData(value_str
, &valuea
);
422 value
= heap_strdupAtoW(valuea
);
425 return NS_ERROR_UNEXPECTED
;
428 hres
= set_http_header(headers
, name
, strlenW(name
), value
, strlenW(value
));
432 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_UNEXPECTED
;
435 static nsresult
visit_http_headers(struct list
*headers
, nsIHttpHeaderVisitor
*visitor
)
437 nsACString header_str
, value_str
;
438 char *header
, *value
;
442 LIST_FOR_EACH_ENTRY(iter
, headers
, http_header_t
, entry
) {
443 header
= heap_strdupWtoA(iter
->header
);
445 return NS_ERROR_OUT_OF_MEMORY
;
447 value
= heap_strdupWtoA(iter
->data
);
450 return NS_ERROR_OUT_OF_MEMORY
;
453 nsACString_InitDepend(&header_str
, header
);
454 nsACString_InitDepend(&value_str
, value
);
455 nsres
= nsIHttpHeaderVisitor_VisitHeader(visitor
, &header_str
, &value_str
);
456 nsACString_Finish(&header_str
);
457 nsACString_Finish(&value_str
);
467 static void free_http_headers(struct list
*list
)
469 http_header_t
*iter
, *iter_next
;
471 LIST_FOR_EACH_ENTRY_SAFE(iter
, iter_next
, list
, http_header_t
, entry
) {
472 list_remove(&iter
->entry
);
473 heap_free(iter
->header
);
474 heap_free(iter
->data
);
479 static inline nsChannel
*impl_from_nsIHttpChannel(nsIHttpChannel
*iface
)
481 return CONTAINING_RECORD(iface
, nsChannel
, nsIHttpChannel_iface
);
484 static nsresult NSAPI
nsChannel_QueryInterface(nsIHttpChannel
*iface
, nsIIDRef riid
, void **result
)
486 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
488 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
489 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
490 *result
= &This
->nsIHttpChannel_iface
;
491 }else if(IsEqualGUID(&IID_nsIRequest
, riid
)) {
492 TRACE("(%p)->(IID_nsIRequest %p)\n", This
, result
);
493 *result
= &This
->nsIHttpChannel_iface
;
494 }else if(IsEqualGUID(&IID_nsIChannel
, riid
)) {
495 TRACE("(%p)->(IID_nsIChannel %p)\n", This
, result
);
496 *result
= &This
->nsIHttpChannel_iface
;
497 }else if(IsEqualGUID(&IID_nsIHttpChannel
, riid
)) {
498 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This
, result
);
499 *result
= is_http_channel(This
) ? &This
->nsIHttpChannel_iface
: NULL
;
500 }else if(IsEqualGUID(&IID_nsIUploadChannel
, riid
)) {
501 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This
, result
);
502 *result
= &This
->nsIUploadChannel_iface
;
503 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal
, riid
)) {
504 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This
, result
);
505 *result
= is_http_channel(This
) ? &This
->nsIHttpChannelInternal_iface
: NULL
;
507 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
512 nsIHttpChannel_AddRef(&This
->nsIHttpChannel_iface
);
516 return NS_NOINTERFACE
;
519 static nsrefcnt NSAPI
nsChannel_AddRef(nsIHttpChannel
*iface
)
521 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
522 nsrefcnt ref
= InterlockedIncrement(&This
->ref
);
524 TRACE("(%p) ref=%d\n", This
, ref
);
529 static nsrefcnt NSAPI
nsChannel_Release(nsIHttpChannel
*iface
)
531 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
532 LONG ref
= InterlockedDecrement(&This
->ref
);
535 nsIFileURL_Release(&This
->uri
->nsIFileURL_iface
);
537 nsISupports_Release(This
->owner
);
538 if(This
->post_data_stream
)
539 nsIInputStream_Release(This
->post_data_stream
);
541 nsILoadGroup_Release(This
->load_group
);
542 if(This
->notif_callback
)
543 nsIInterfaceRequestor_Release(This
->notif_callback
);
544 if(This
->original_uri
)
545 nsIURI_Release(This
->original_uri
);
547 nsIURI_Release(This
->referrer
);
549 free_http_headers(&This
->response_headers
);
550 free_http_headers(&This
->request_headers
);
552 heap_free(This
->content_type
);
553 heap_free(This
->charset
);
560 static nsresult NSAPI
nsChannel_GetName(nsIHttpChannel
*iface
, nsACString
*aName
)
562 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
564 TRACE("(%p)->(%p)\n", This
, aName
);
566 return nsIFileURL_GetSpec(&This
->uri
->nsIFileURL_iface
, aName
);
569 static nsresult NSAPI
nsChannel_IsPending(nsIHttpChannel
*iface
, cpp_bool
*_retval
)
571 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
573 FIXME("(%p)->(%p)\n", This
, _retval
);
575 return NS_ERROR_NOT_IMPLEMENTED
;
578 static nsresult NSAPI
nsChannel_GetStatus(nsIHttpChannel
*iface
, nsresult
*aStatus
)
580 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
582 WARN("(%p)->(%p) returning NS_OK\n", This
, aStatus
);
584 return *aStatus
= NS_OK
;
587 static nsresult NSAPI
nsChannel_Cancel(nsIHttpChannel
*iface
, nsresult aStatus
)
589 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
591 FIXME("(%p)->(%08x)\n", This
, aStatus
);
593 return NS_ERROR_NOT_IMPLEMENTED
;
596 static nsresult NSAPI
nsChannel_Suspend(nsIHttpChannel
*iface
)
598 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
600 FIXME("(%p)\n", This
);
602 return NS_ERROR_NOT_IMPLEMENTED
;
605 static nsresult NSAPI
nsChannel_Resume(nsIHttpChannel
*iface
)
607 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
609 FIXME("(%p)\n", This
);
611 return NS_ERROR_NOT_IMPLEMENTED
;
614 static nsresult NSAPI
nsChannel_GetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
**aLoadGroup
)
616 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
618 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
621 nsILoadGroup_AddRef(This
->load_group
);
623 *aLoadGroup
= This
->load_group
;
627 static nsresult NSAPI
nsChannel_SetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
*aLoadGroup
)
629 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
631 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
634 nsILoadGroup_Release(This
->load_group
);
636 nsILoadGroup_AddRef(aLoadGroup
);
637 This
->load_group
= aLoadGroup
;
642 static nsresult NSAPI
nsChannel_GetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags
*aLoadFlags
)
644 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
646 TRACE("(%p)->(%p)\n", This
, aLoadFlags
);
648 *aLoadFlags
= This
->load_flags
;
652 static nsresult NSAPI
nsChannel_SetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags aLoadFlags
)
654 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
656 TRACE("(%p)->(%08x)\n", This
, aLoadFlags
);
658 This
->load_flags
= aLoadFlags
;
662 static nsresult NSAPI
nsChannel_GetOriginalURI(nsIHttpChannel
*iface
, nsIURI
**aOriginalURI
)
664 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
666 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
668 if(This
->original_uri
)
669 nsIURI_AddRef(This
->original_uri
);
671 *aOriginalURI
= This
->original_uri
;
675 static nsresult NSAPI
nsChannel_SetOriginalURI(nsIHttpChannel
*iface
, nsIURI
*aOriginalURI
)
677 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
679 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
681 if(This
->original_uri
)
682 nsIURI_Release(This
->original_uri
);
684 nsIURI_AddRef(aOriginalURI
);
685 This
->original_uri
= aOriginalURI
;
689 static nsresult NSAPI
nsChannel_GetURI(nsIHttpChannel
*iface
, nsIURI
**aURI
)
691 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
693 TRACE("(%p)->(%p)\n", This
, aURI
);
695 nsIFileURL_AddRef(&This
->uri
->nsIFileURL_iface
);
696 *aURI
= (nsIURI
*)This
->uri
;
701 static nsresult NSAPI
nsChannel_GetOwner(nsIHttpChannel
*iface
, nsISupports
**aOwner
)
703 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
705 TRACE("(%p)->(%p)\n", This
, aOwner
);
708 nsISupports_AddRef(This
->owner
);
709 *aOwner
= This
->owner
;
714 static nsresult NSAPI
nsChannel_SetOwner(nsIHttpChannel
*iface
, nsISupports
*aOwner
)
716 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
718 TRACE("(%p)->(%p)\n", This
, aOwner
);
721 nsISupports_AddRef(aOwner
);
723 nsISupports_Release(This
->owner
);
724 This
->owner
= aOwner
;
729 static nsresult NSAPI
nsChannel_GetNotificationCallbacks(nsIHttpChannel
*iface
,
730 nsIInterfaceRequestor
**aNotificationCallbacks
)
732 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
734 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
736 if(This
->notif_callback
)
737 nsIInterfaceRequestor_AddRef(This
->notif_callback
);
738 *aNotificationCallbacks
= This
->notif_callback
;
743 static nsresult NSAPI
nsChannel_SetNotificationCallbacks(nsIHttpChannel
*iface
,
744 nsIInterfaceRequestor
*aNotificationCallbacks
)
746 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
748 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
750 if(This
->notif_callback
)
751 nsIInterfaceRequestor_Release(This
->notif_callback
);
752 if(aNotificationCallbacks
)
753 nsIInterfaceRequestor_AddRef(aNotificationCallbacks
);
755 This
->notif_callback
= aNotificationCallbacks
;
760 static nsresult NSAPI
nsChannel_GetSecurityInfo(nsIHttpChannel
*iface
, nsISupports
**aSecurityInfo
)
762 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
764 TRACE("(%p)->(%p)\n", This
, aSecurityInfo
);
766 return NS_ERROR_NOT_IMPLEMENTED
;
769 static nsresult NSAPI
nsChannel_GetContentType(nsIHttpChannel
*iface
, nsACString
*aContentType
)
771 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
773 TRACE("(%p)->(%p)\n", This
, aContentType
);
775 if(This
->content_type
) {
776 nsACString_SetData(aContentType
, This
->content_type
);
780 if(This
->uri
->is_doc_uri
) {
781 WARN("Document channel with no MIME set. Assuming text/html\n");
782 nsACString_SetData(aContentType
, "text/html");
786 WARN("unknown type\n");
787 return NS_ERROR_FAILURE
;
790 static nsresult NSAPI
nsChannel_SetContentType(nsIHttpChannel
*iface
,
791 const nsACString
*aContentType
)
793 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
794 const char *content_type
;
796 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentType
));
798 nsACString_GetData(aContentType
, &content_type
);
799 heap_free(This
->content_type
);
800 This
->content_type
= heap_strdupA(content_type
);
805 static nsresult NSAPI
nsChannel_GetContentCharset(nsIHttpChannel
*iface
,
806 nsACString
*aContentCharset
)
808 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
810 TRACE("(%p)->(%p)\n", This
, aContentCharset
);
813 nsACString_SetData(aContentCharset
, This
->charset
);
817 nsACString_SetData(aContentCharset
, "");
821 static nsresult NSAPI
nsChannel_SetContentCharset(nsIHttpChannel
*iface
,
822 const nsACString
*aContentCharset
)
824 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
828 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentCharset
));
830 nsACString_GetData(aContentCharset
, &data
);
831 charset
= heap_strdupA(data
);
833 return NS_ERROR_OUT_OF_MEMORY
;
835 heap_free(This
->charset
);
836 This
->charset
= charset
;
840 static nsresult NSAPI
nsChannel_GetContentLength(nsIHttpChannel
*iface
, INT64
*aContentLength
)
842 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
844 FIXME("(%p)->(%p)\n", This
, aContentLength
);
846 return NS_ERROR_NOT_IMPLEMENTED
;
849 static nsresult NSAPI
nsChannel_SetContentLength(nsIHttpChannel
*iface
, INT64 aContentLength
)
851 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
853 FIXME("(%p)->(%s)\n", This
, wine_dbgstr_longlong(aContentLength
));
855 return NS_ERROR_NOT_IMPLEMENTED
;
858 static nsresult NSAPI
nsChannel_Open(nsIHttpChannel
*iface
, nsIInputStream
**_retval
)
860 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
862 FIXME("(%p)->(%p)\n", This
, _retval
);
864 return NS_ERROR_NOT_IMPLEMENTED
;
867 static HTMLOuterWindow
*get_window_from_load_group(nsChannel
*This
)
869 HTMLOuterWindow
*window
;
876 nsres
= nsILoadGroup_GetDefaultLoadRequest(This
->load_group
, &req
);
877 if(NS_FAILED(nsres
)) {
878 ERR("GetDefaultLoadRequest failed: %08x\n", nsres
);
885 nsres
= nsIRequest_QueryInterface(req
, &IID_nsIChannel
, (void**)&channel
);
886 nsIRequest_Release(req
);
887 if(NS_FAILED(nsres
)) {
888 WARN("Could not get nsIChannel interface: %08x\n", nsres
);
892 nsres
= nsIChannel_GetURI(channel
, &uri
);
893 nsIChannel_Release(channel
);
894 if(NS_FAILED(nsres
)) {
895 ERR("GetURI failed: %08x\n", nsres
);
899 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
901 if(NS_FAILED(nsres
)) {
902 TRACE("Could not get nsWineURI: %08x\n", nsres
);
906 window
= wine_uri
->window_ref
? wine_uri
->window_ref
->window
: NULL
;
908 IHTMLWindow2_AddRef(&window
->base
.IHTMLWindow2_iface
);
909 nsIFileURL_Release(&wine_uri
->nsIFileURL_iface
);
914 static HTMLOuterWindow
*get_channel_window(nsChannel
*This
)
916 nsIWebProgress
*web_progress
;
917 nsIDOMWindow
*nswindow
;
918 HTMLOuterWindow
*window
;
921 if(This
->load_group
) {
922 nsIRequestObserver
*req_observer
;
924 nsres
= nsILoadGroup_GetGroupObserver(This
->load_group
, &req_observer
);
925 if(NS_FAILED(nsres
) || !req_observer
) {
926 ERR("GetGroupObserver failed: %08x\n", nsres
);
930 nsres
= nsIRequestObserver_QueryInterface(req_observer
, &IID_nsIWebProgress
, (void**)&web_progress
);
931 nsIRequestObserver_Release(req_observer
);
932 if(NS_FAILED(nsres
)) {
933 ERR("Could not get nsIWebProgress iface: %08x\n", nsres
);
936 }else if(This
->notif_callback
) {
937 nsres
= nsIInterfaceRequestor_GetInterface(This
->notif_callback
, &IID_nsIWebProgress
, (void**)&web_progress
);
938 if(NS_FAILED(nsres
)) {
939 ERR("GetInterface(IID_nsIWebProgress failed: %08x\n", nsres
);
943 ERR("no load group nor notif callback\n");
947 nsres
= nsIWebProgress_GetDOMWindow(web_progress
, &nswindow
);
948 nsIWebProgress_Release(web_progress
);
949 if(NS_FAILED(nsres
) || !nswindow
) {
950 ERR("GetDOMWindow failed: %08x\n", nsres
);
954 window
= nswindow_to_window(nswindow
);
955 nsIDOMWindow_Release(nswindow
);
958 IHTMLWindow2_AddRef(&window
->base
.IHTMLWindow2_iface
);
960 FIXME("NULL window for %p\n", nswindow
);
966 HTMLInnerWindow
*window
;
967 nsChannelBSC
*bscallback
;
968 } start_binding_task_t
;
970 static void start_binding_proc(task_t
*_task
)
972 start_binding_task_t
*task
= (start_binding_task_t
*)_task
;
974 start_binding(task
->window
, (BSCallback
*)task
->bscallback
, NULL
);
977 static void start_binding_task_destr(task_t
*_task
)
979 start_binding_task_t
*task
= (start_binding_task_t
*)_task
;
981 IBindStatusCallback_Release(&task
->bscallback
->bsc
.IBindStatusCallback_iface
);
985 static nsresult
async_open(nsChannel
*This
, HTMLOuterWindow
*window
, BOOL is_doc_channel
, nsIStreamListener
*listener
,
986 nsISupports
*context
)
988 nsChannelBSC
*bscallback
;
989 IMoniker
*mon
= NULL
;
992 hres
= CreateURLMonikerEx2(NULL
, This
->uri
->uri
, &mon
, 0);
994 WARN("CreateURLMoniker failed: %08x\n", hres
);
995 return NS_ERROR_UNEXPECTED
;
999 set_current_mon(window
, mon
, BINDING_NAVIGATED
);
1001 hres
= create_channelbsc(mon
, NULL
, NULL
, 0, is_doc_channel
, &bscallback
);
1002 IMoniker_Release(mon
);
1004 return NS_ERROR_UNEXPECTED
;
1006 channelbsc_set_channel(bscallback
, This
, listener
, context
);
1008 if(is_doc_channel
) {
1009 hres
= create_pending_window(window
, bscallback
);
1011 async_start_doc_binding(window
, window
->pending_window
);
1012 IBindStatusCallback_Release(&bscallback
->bsc
.IBindStatusCallback_iface
);
1014 return NS_ERROR_UNEXPECTED
;
1016 start_binding_task_t
*task
;
1018 task
= heap_alloc(sizeof(start_binding_task_t
));
1020 IBindStatusCallback_Release(&bscallback
->bsc
.IBindStatusCallback_iface
);
1021 return NS_ERROR_OUT_OF_MEMORY
;
1024 task
->window
= window
->base
.inner_window
;
1025 task
->bscallback
= bscallback
;
1026 hres
= push_task(&task
->header
, start_binding_proc
, start_binding_task_destr
, window
->base
.inner_window
->task_magic
);
1028 return NS_ERROR_OUT_OF_MEMORY
;
1034 static nsresult NSAPI
nsChannel_AsyncOpen(nsIHttpChannel
*iface
, nsIStreamListener
*aListener
,
1035 nsISupports
*aContext
)
1037 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1038 HTMLOuterWindow
*window
= NULL
;
1039 BOOL cancel
= FALSE
;
1040 nsresult nsres
= NS_OK
;
1042 TRACE("(%p)->(%p %p)\n", This
, aListener
, aContext
);
1044 if(!ensure_uri(This
->uri
))
1045 return NS_ERROR_FAILURE
;
1047 if(TRACE_ON(mshtml
)) {
1051 hres
= IUri_GetDisplayUri(This
->uri
->uri
, &uri_str
);
1052 if(SUCCEEDED(hres
)) {
1053 TRACE("opening %s\n", debugstr_w(uri_str
));
1054 SysFreeString(uri_str
);
1056 WARN("GetDisplayUri failed: %08x\n", hres
);
1060 if(This
->uri
->is_doc_uri
) {
1061 window
= get_channel_window(This
);
1063 set_uri_window(This
->uri
, window
);
1064 }else if(This
->uri
->container
) {
1067 /* nscontainer->doc should be NULL which means navigation to a new window */
1068 if(This
->uri
->container
->doc
)
1069 FIXME("nscontainer->doc = %p\n", This
->uri
->container
->doc
);
1071 nsres
= before_async_open(This
, This
->uri
->container
, &b
);
1072 if(NS_FAILED(nsres
))
1075 FIXME("Navigation not cancelled\n");
1076 return NS_ERROR_UNEXPECTED
;
1081 if(This
->uri
->window_ref
&& This
->uri
->window_ref
->window
) {
1082 window
= This
->uri
->window_ref
->window
;
1083 IHTMLWindow2_AddRef(&window
->base
.IHTMLWindow2_iface
);
1085 /* FIXME: Analyze removing get_window_from_load_group call */
1086 if(This
->load_group
)
1087 window
= get_window_from_load_group(This
);
1089 window
= get_channel_window(This
);
1091 set_uri_window(This
->uri
, window
);
1096 ERR("window = NULL\n");
1097 return NS_ERROR_UNEXPECTED
;
1100 if(This
->uri
->is_doc_uri
&& window
== window
->doc_obj
->basedoc
.window
) {
1101 if(This
->uri
->channel_bsc
) {
1102 channelbsc_set_channel(This
->uri
->channel_bsc
, This
, aListener
, aContext
);
1104 if(window
->doc_obj
->mime
) {
1105 heap_free(This
->content_type
);
1106 This
->content_type
= heap_strdupWtoA(window
->doc_obj
->mime
);
1111 nsres
= before_async_open(This
, window
->doc_obj
->nscontainer
, &cancel
);
1112 if(NS_SUCCEEDED(nsres
) && cancel
) {
1113 TRACE("canceled\n");
1114 nsres
= NS_BINDING_ABORTED
;
1120 nsres
= async_open(This
, window
, This
->uri
->is_doc_uri
, aListener
, aContext
);
1122 if(NS_SUCCEEDED(nsres
) && This
->load_group
) {
1123 nsres
= nsILoadGroup_AddRequest(This
->load_group
, (nsIRequest
*)&This
->nsIHttpChannel_iface
,
1125 if(NS_FAILED(nsres
))
1126 ERR("AddRequest failed: %08x\n", nsres
);
1129 IHTMLWindow2_Release(&window
->base
.IHTMLWindow2_iface
);
1133 static nsresult NSAPI
nsChannel_GetContentDisposition(nsIHttpChannel
*iface
, UINT32
*aContentDisposition
)
1135 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1136 FIXME("(%p)->(%p)\n", This
, aContentDisposition
);
1137 return NS_ERROR_NOT_IMPLEMENTED
;
1140 static nsresult NSAPI
nsChannel_SetContentDisposition(nsIHttpChannel
*iface
, UINT32 aContentDisposition
)
1142 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1143 FIXME("(%p)->(%u)\n", This
, aContentDisposition
);
1144 return NS_ERROR_NOT_IMPLEMENTED
;
1147 static nsresult NSAPI
nsChannel_GetContentDispositionFilename(nsIHttpChannel
*iface
, nsAString
*aContentDispositionFilename
)
1149 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1150 FIXME("(%p)->(%p)\n", This
, aContentDispositionFilename
);
1151 return NS_ERROR_NOT_IMPLEMENTED
;
1154 static nsresult NSAPI
nsChannel_SetContentDispositionFilename(nsIHttpChannel
*iface
, const nsAString
*aContentDispositionFilename
)
1156 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1157 FIXME("(%p)->(%p)\n", This
, aContentDispositionFilename
);
1158 return NS_ERROR_NOT_IMPLEMENTED
;
1161 static nsresult NSAPI
nsChannel_GetContentDispositionHeader(nsIHttpChannel
*iface
, nsACString
*aContentDispositionHeader
)
1163 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1164 FIXME("(%p)->(%p)\n", This
, aContentDispositionHeader
);
1165 return NS_ERROR_NOT_IMPLEMENTED
;
1168 static nsresult NSAPI
nsChannel_GetRequestMethod(nsIHttpChannel
*iface
, nsACString
*aRequestMethod
)
1170 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1172 TRACE("(%p)->(%p)\n", This
, aRequestMethod
);
1174 nsACString_SetData(aRequestMethod
, request_method_strings
[This
->request_method
]);
1178 static nsresult NSAPI
nsChannel_SetRequestMethod(nsIHttpChannel
*iface
,
1179 const nsACString
*aRequestMethod
)
1181 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1185 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRequestMethod
));
1187 nsACString_GetData(aRequestMethod
, &method
);
1188 for(i
=0; i
< sizeof(request_method_strings
)/sizeof(*request_method_strings
); i
++) {
1189 if(!strcasecmp(method
, request_method_strings
[i
])) {
1190 This
->request_method
= i
;
1195 ERR("Invalid method %s\n", debugstr_a(method
));
1196 return NS_ERROR_UNEXPECTED
;
1199 static nsresult NSAPI
nsChannel_GetReferrer(nsIHttpChannel
*iface
, nsIURI
**aReferrer
)
1201 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1203 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1206 nsIURI_AddRef(This
->referrer
);
1207 *aReferrer
= This
->referrer
;
1211 static nsresult NSAPI
nsChannel_SetReferrer(nsIHttpChannel
*iface
, nsIURI
*aReferrer
)
1213 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1215 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1218 nsIURI_AddRef(aReferrer
);
1220 nsIURI_Release(This
->referrer
);
1221 This
->referrer
= aReferrer
;
1225 static nsresult NSAPI
nsChannel_GetRequestHeader(nsIHttpChannel
*iface
,
1226 const nsACString
*aHeader
, nsACString
*_retval
)
1228 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1230 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aHeader
), _retval
);
1232 return get_channel_http_header(&This
->request_headers
, aHeader
, _retval
);
1235 static nsresult NSAPI
nsChannel_SetRequestHeader(nsIHttpChannel
*iface
,
1236 const nsACString
*aHeader
, const nsACString
*aValue
, cpp_bool aMerge
)
1238 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1240 TRACE("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(aHeader
), debugstr_nsacstr(aValue
), aMerge
);
1243 FIXME("aMerge not supported\n");
1245 return set_channel_http_header(&This
->request_headers
, aHeader
, aValue
);
1248 static nsresult NSAPI
nsChannel_VisitRequestHeaders(nsIHttpChannel
*iface
,
1249 nsIHttpHeaderVisitor
*aVisitor
)
1251 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1253 FIXME("(%p)->(%p)\n", This
, aVisitor
);
1255 return NS_ERROR_NOT_IMPLEMENTED
;
1258 static nsresult NSAPI
nsChannel_GetAllowPipelining(nsIHttpChannel
*iface
, cpp_bool
*aAllowPipelining
)
1260 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1262 FIXME("(%p)->(%p)\n", This
, aAllowPipelining
);
1264 return NS_ERROR_NOT_IMPLEMENTED
;
1267 static nsresult NSAPI
nsChannel_SetAllowPipelining(nsIHttpChannel
*iface
, cpp_bool aAllowPipelining
)
1269 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1271 FIXME("(%p)->(%x)\n", This
, aAllowPipelining
);
1273 return NS_ERROR_NOT_IMPLEMENTED
;
1276 static nsresult NSAPI
nsChannel_GetRedirectionLimit(nsIHttpChannel
*iface
, UINT32
*aRedirectionLimit
)
1278 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1280 FIXME("(%p)->(%p)\n", This
, aRedirectionLimit
);
1282 return NS_ERROR_NOT_IMPLEMENTED
;
1285 static nsresult NSAPI
nsChannel_SetRedirectionLimit(nsIHttpChannel
*iface
, UINT32 aRedirectionLimit
)
1287 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1289 FIXME("(%p)->(%u)\n", This
, aRedirectionLimit
);
1291 return NS_ERROR_NOT_IMPLEMENTED
;
1294 static nsresult NSAPI
nsChannel_GetResponseStatus(nsIHttpChannel
*iface
, UINT32
*aResponseStatus
)
1296 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1298 TRACE("(%p)->(%p)\n", This
, aResponseStatus
);
1300 if(This
->response_status
) {
1301 *aResponseStatus
= This
->response_status
;
1305 WARN("No response status\n");
1306 return NS_ERROR_UNEXPECTED
;
1309 static nsresult NSAPI
nsChannel_GetResponseStatusText(nsIHttpChannel
*iface
,
1310 nsACString
*aResponseStatusText
)
1312 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1314 FIXME("(%p)->(%p)\n", This
, aResponseStatusText
);
1316 return NS_ERROR_NOT_IMPLEMENTED
;
1319 static nsresult NSAPI
nsChannel_GetRequestSucceeded(nsIHttpChannel
*iface
,
1320 cpp_bool
*aRequestSucceeded
)
1322 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1324 TRACE("(%p)->(%p)\n", This
, aRequestSucceeded
);
1326 if(!This
->response_status
)
1327 return NS_ERROR_NOT_AVAILABLE
;
1329 *aRequestSucceeded
= This
->response_status
/100 == 2;
1334 static nsresult NSAPI
nsChannel_GetResponseHeader(nsIHttpChannel
*iface
,
1335 const nsACString
*header
, nsACString
*_retval
)
1337 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1339 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(header
), _retval
);
1341 return get_channel_http_header(&This
->response_headers
, header
, _retval
);
1344 static nsresult NSAPI
nsChannel_SetResponseHeader(nsIHttpChannel
*iface
,
1345 const nsACString
*header
, const nsACString
*value
, cpp_bool merge
)
1347 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1349 FIXME("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(header
), debugstr_nsacstr(value
), merge
);
1351 return NS_ERROR_NOT_IMPLEMENTED
;
1354 static nsresult NSAPI
nsChannel_VisitResponseHeaders(nsIHttpChannel
*iface
,
1355 nsIHttpHeaderVisitor
*aVisitor
)
1357 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1359 TRACE("(%p)->(%p)\n", This
, aVisitor
);
1361 return visit_http_headers(&This
->response_headers
, aVisitor
);
1364 static nsresult NSAPI
nsChannel_IsNoStoreResponse(nsIHttpChannel
*iface
, cpp_bool
*_retval
)
1366 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1367 http_header_t
*header
;
1369 static const WCHAR cache_controlW
[] = {'C','a','c','h','e','-','C','o','n','t','r','o','l'};
1370 static const WCHAR no_storeW
[] = {'n','o','-','s','t','o','r','e',0};
1372 TRACE("(%p)->(%p)\n", This
, _retval
);
1374 header
= find_http_header(&This
->response_headers
, cache_controlW
, sizeof(cache_controlW
)/sizeof(WCHAR
));
1375 *_retval
= header
&& !strcmpiW(header
->data
, no_storeW
);
1379 static nsresult NSAPI
nsChannel_IsNoCacheResponse(nsIHttpChannel
*iface
, cpp_bool
*_retval
)
1381 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1383 FIXME("(%p)->(%p)\n", This
, _retval
);
1385 return NS_ERROR_NOT_IMPLEMENTED
;
1388 static nsresult NSAPI
nsChannel_RedirectTo(nsIHttpChannel
*iface
, nsIURI
*aNewURI
)
1390 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1392 FIXME("(%p)->(%p)\n", This
, aNewURI
);
1394 return NS_ERROR_NOT_IMPLEMENTED
;
1397 static const nsIHttpChannelVtbl nsChannelVtbl
= {
1398 nsChannel_QueryInterface
,
1402 nsChannel_IsPending
,
1403 nsChannel_GetStatus
,
1407 nsChannel_GetLoadGroup
,
1408 nsChannel_SetLoadGroup
,
1409 nsChannel_GetLoadFlags
,
1410 nsChannel_SetLoadFlags
,
1411 nsChannel_GetOriginalURI
,
1412 nsChannel_SetOriginalURI
,
1416 nsChannel_GetNotificationCallbacks
,
1417 nsChannel_SetNotificationCallbacks
,
1418 nsChannel_GetSecurityInfo
,
1419 nsChannel_GetContentType
,
1420 nsChannel_SetContentType
,
1421 nsChannel_GetContentCharset
,
1422 nsChannel_SetContentCharset
,
1423 nsChannel_GetContentLength
,
1424 nsChannel_SetContentLength
,
1426 nsChannel_AsyncOpen
,
1427 nsChannel_GetContentDisposition
,
1428 nsChannel_SetContentDisposition
,
1429 nsChannel_GetContentDispositionFilename
,
1430 nsChannel_SetContentDispositionFilename
,
1431 nsChannel_GetContentDispositionHeader
,
1432 nsChannel_GetRequestMethod
,
1433 nsChannel_SetRequestMethod
,
1434 nsChannel_GetReferrer
,
1435 nsChannel_SetReferrer
,
1436 nsChannel_GetRequestHeader
,
1437 nsChannel_SetRequestHeader
,
1438 nsChannel_VisitRequestHeaders
,
1439 nsChannel_GetAllowPipelining
,
1440 nsChannel_SetAllowPipelining
,
1441 nsChannel_GetRedirectionLimit
,
1442 nsChannel_SetRedirectionLimit
,
1443 nsChannel_GetResponseStatus
,
1444 nsChannel_GetResponseStatusText
,
1445 nsChannel_GetRequestSucceeded
,
1446 nsChannel_GetResponseHeader
,
1447 nsChannel_SetResponseHeader
,
1448 nsChannel_VisitResponseHeaders
,
1449 nsChannel_IsNoStoreResponse
,
1450 nsChannel_IsNoCacheResponse
,
1451 nsChannel_RedirectTo
1454 static inline nsChannel
*impl_from_nsIUploadChannel(nsIUploadChannel
*iface
)
1456 return CONTAINING_RECORD(iface
, nsChannel
, nsIUploadChannel_iface
);
1459 static nsresult NSAPI
nsUploadChannel_QueryInterface(nsIUploadChannel
*iface
, nsIIDRef riid
,
1462 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1463 return nsIHttpChannel_QueryInterface(&This
->nsIHttpChannel_iface
, riid
, result
);
1466 static nsrefcnt NSAPI
nsUploadChannel_AddRef(nsIUploadChannel
*iface
)
1468 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1469 return nsIHttpChannel_AddRef(&This
->nsIHttpChannel_iface
);
1472 static nsrefcnt NSAPI
nsUploadChannel_Release(nsIUploadChannel
*iface
)
1474 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1475 return nsIHttpChannel_Release(&This
->nsIHttpChannel_iface
);
1478 static nsresult NSAPI
nsUploadChannel_SetUploadStream(nsIUploadChannel
*iface
,
1479 nsIInputStream
*aStream
, const nsACString
*aContentType
, INT64 aContentLength
)
1481 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1482 const char *content_type
;
1484 static const WCHAR content_typeW
[] =
1485 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1487 TRACE("(%p)->(%p %s %s)\n", This
, aStream
, debugstr_nsacstr(aContentType
), wine_dbgstr_longlong(aContentLength
));
1489 This
->post_data_contains_headers
= TRUE
;
1492 nsACString_GetData(aContentType
, &content_type
);
1496 ct
= heap_strdupAtoW(content_type
);
1498 return NS_ERROR_UNEXPECTED
;
1500 set_http_header(&This
->request_headers
, content_typeW
,
1501 sizeof(content_typeW
)/sizeof(WCHAR
), ct
, strlenW(ct
));
1503 This
->post_data_contains_headers
= FALSE
;
1507 if(This
->post_data_stream
)
1508 nsIInputStream_Release(This
->post_data_stream
);
1510 if(aContentLength
!= -1)
1511 FIXME("Unsupported acontentLength = %s\n", wine_dbgstr_longlong(aContentLength
));
1513 if(This
->post_data_stream
)
1514 nsIInputStream_Release(This
->post_data_stream
);
1515 This
->post_data_stream
= aStream
;
1517 nsIInputStream_AddRef(aStream
);
1519 This
->request_method
= METHOD_POST
;
1523 static nsresult NSAPI
nsUploadChannel_GetUploadStream(nsIUploadChannel
*iface
,
1524 nsIInputStream
**aUploadStream
)
1526 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1528 TRACE("(%p)->(%p)\n", This
, aUploadStream
);
1530 if(This
->post_data_stream
)
1531 nsIInputStream_AddRef(This
->post_data_stream
);
1533 *aUploadStream
= This
->post_data_stream
;
1537 static const nsIUploadChannelVtbl nsUploadChannelVtbl
= {
1538 nsUploadChannel_QueryInterface
,
1539 nsUploadChannel_AddRef
,
1540 nsUploadChannel_Release
,
1541 nsUploadChannel_SetUploadStream
,
1542 nsUploadChannel_GetUploadStream
1545 static inline nsChannel
*impl_from_nsIHttpChannelInternal(nsIHttpChannelInternal
*iface
)
1547 return CONTAINING_RECORD(iface
, nsChannel
, nsIHttpChannelInternal_iface
);
1550 static nsresult NSAPI
nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal
*iface
, nsIIDRef riid
,
1553 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1554 return nsIHttpChannel_QueryInterface(&This
->nsIHttpChannel_iface
, riid
, result
);
1557 static nsrefcnt NSAPI
nsHttpChannelInternal_AddRef(nsIHttpChannelInternal
*iface
)
1559 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1560 return nsIHttpChannel_AddRef(&This
->nsIHttpChannel_iface
);
1563 static nsrefcnt NSAPI
nsHttpChannelInternal_Release(nsIHttpChannelInternal
*iface
)
1565 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1566 return nsIHttpChannel_Release(&This
->nsIHttpChannel_iface
);
1569 static nsresult NSAPI
nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
**aDocumentURI
)
1571 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1573 FIXME("(%p)->()\n", This
);
1575 return NS_ERROR_NOT_IMPLEMENTED
;
1578 static nsresult NSAPI
nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
*aDocumentURI
)
1580 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1582 FIXME("(%p)->()\n", This
);
1584 return NS_ERROR_NOT_IMPLEMENTED
;
1587 static nsresult NSAPI
nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal
*iface
, UINT32
*major
, UINT32
*minor
)
1589 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1591 FIXME("(%p)->()\n", This
);
1593 return NS_ERROR_NOT_IMPLEMENTED
;
1596 static nsresult NSAPI
nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal
*iface
, UINT32
*major
, UINT32
*minor
)
1598 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1600 FIXME("(%p)->()\n", This
);
1602 return NS_ERROR_NOT_IMPLEMENTED
;
1605 static nsresult NSAPI
nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal
*iface
, const char *aCookieHeader
)
1607 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1609 FIXME("(%p)->()\n", This
);
1611 return NS_ERROR_NOT_IMPLEMENTED
;
1614 static nsresult NSAPI
nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal
*iface
, const char *aFallbackKey
)
1616 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1618 FIXME("(%p)->()\n", This
);
1620 return NS_ERROR_NOT_IMPLEMENTED
;
1623 static nsresult NSAPI
nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, cpp_bool
*aForceThirdPartyCookie
)
1625 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1627 FIXME("(%p)->()\n", This
);
1629 return NS_ERROR_NOT_IMPLEMENTED
;
1632 static nsresult NSAPI
nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, cpp_bool aForceThirdPartyCookie
)
1634 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1636 FIXME("(%p)->()\n", This
);
1638 return NS_ERROR_NOT_IMPLEMENTED
;
1641 static nsresult NSAPI
nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal
*iface
, cpp_bool
*aCanceled
)
1643 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1645 FIXME("(%p)->(%p)\n", This
, aCanceled
);
1647 return NS_ERROR_NOT_IMPLEMENTED
;
1650 static nsresult NSAPI
nsHttpChannelInternal_GetChannelIsForDownload(nsIHttpChannelInternal
*iface
, cpp_bool
*aCanceled
)
1652 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1654 FIXME("(%p)->(%p)\n", This
, aCanceled
);
1656 return NS_ERROR_NOT_IMPLEMENTED
;
1659 static nsresult NSAPI
nsHttpChannelInternal_SetChannelIsForDownload(nsIHttpChannelInternal
*iface
, cpp_bool aCanceled
)
1661 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1663 FIXME("(%p)->(%x)\n", This
, aCanceled
);
1665 return NS_ERROR_NOT_IMPLEMENTED
;
1668 static nsresult NSAPI
nsHttpChannelInternal_GetLocalAddress(nsIHttpChannelInternal
*iface
, nsACString
*aLocalAddress
)
1670 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1672 FIXME("(%p)->(%p)\n", This
, aLocalAddress
);
1674 return NS_ERROR_NOT_IMPLEMENTED
;
1677 static nsresult NSAPI
nsHttpChannelInternal_GetLocalPort(nsIHttpChannelInternal
*iface
, LONG
*aLocalPort
)
1679 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1681 FIXME("(%p)->(%p)\n", This
, aLocalPort
);
1683 return NS_ERROR_NOT_IMPLEMENTED
;
1686 static nsresult NSAPI
nsHttpChannelInternal_GetRemoteAddress(nsIHttpChannelInternal
*iface
, nsACString
*aRemoteAddress
)
1688 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1690 FIXME("(%p)->(%p)\n", This
, aRemoteAddress
);
1692 return NS_ERROR_NOT_IMPLEMENTED
;
1695 static nsresult NSAPI
nsHttpChannelInternal_GetRemotePort(nsIHttpChannelInternal
*iface
, LONG
*aRemotePort
)
1697 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1699 FIXME("(%p)->(%p)\n", This
, aRemotePort
);
1701 return NS_ERROR_NOT_IMPLEMENTED
;
1704 static nsresult NSAPI
nsHttpChannelInternal_SetCacheKeysRedirectChain(nsIHttpChannelInternal
*iface
, void *cacheKeys
)
1706 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1708 FIXME("(%p)->(%p)\n", This
, cacheKeys
);
1710 return NS_ERROR_NOT_IMPLEMENTED
;
1713 static nsresult NSAPI
nsHttpChannelInternal_HTTPUpgrade(nsIHttpChannelInternal
*iface
,
1714 const nsACString
*aProtocolName
, nsIHttpUpgradeListener
*aListener
)
1716 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1717 FIXME("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aProtocolName
), aListener
);
1718 return NS_ERROR_NOT_IMPLEMENTED
;
1721 static nsresult NSAPI
nsHttpChannelInternal_GetAllowSpdy(nsIHttpChannelInternal
*iface
, cpp_bool
*aAllowSpdy
)
1723 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1724 FIXME("(%p)->(%p)\n", This
, aAllowSpdy
);
1725 return NS_ERROR_NOT_IMPLEMENTED
;
1728 static nsresult NSAPI
nsHttpChannelInternal_SetAllowSpdy(nsIHttpChannelInternal
*iface
, cpp_bool aAllowSpdy
)
1730 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1731 FIXME("(%p)->(%x)\n", This
, aAllowSpdy
);
1732 return NS_ERROR_NOT_IMPLEMENTED
;
1735 static nsresult NSAPI
nsHttpChannelInternal_GetLoadAsBlocking(nsIHttpChannelInternal
*iface
, cpp_bool
*aLoadAsBlocking
)
1737 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1738 FIXME("(%p)->(%p)\n", This
, aLoadAsBlocking
);
1739 return NS_ERROR_NOT_IMPLEMENTED
;
1742 static nsresult NSAPI
nsHttpChannelInternal_SetLoadAsBlocking(nsIHttpChannelInternal
*iface
, cpp_bool aLoadAsBlocking
)
1744 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1745 FIXME("(%p)->(%x)\n", This
, aLoadAsBlocking
);
1746 return NS_ERROR_NOT_IMPLEMENTED
;
1749 static nsresult NSAPI
nsHttpChannelInternal_GetLoadUnblocked(nsIHttpChannelInternal
*iface
, cpp_bool
*aLoadUnblocked
)
1751 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1752 FIXME("(%p)->(%p)\n", This
, aLoadUnblocked
);
1753 return NS_ERROR_NOT_IMPLEMENTED
;
1756 static nsresult NSAPI
nsHttpChannelInternal_SetLoadUnblocked(nsIHttpChannelInternal
*iface
, cpp_bool aLoadUnblocked
)
1758 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1759 FIXME("(%p)->(%x)\n", This
, aLoadUnblocked
);
1760 return NS_ERROR_NOT_IMPLEMENTED
;
1763 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl
= {
1764 nsHttpChannelInternal_QueryInterface
,
1765 nsHttpChannelInternal_AddRef
,
1766 nsHttpChannelInternal_Release
,
1767 nsHttpChannelInternal_GetDocumentURI
,
1768 nsHttpChannelInternal_SetDocumentURI
,
1769 nsHttpChannelInternal_GetRequestVersion
,
1770 nsHttpChannelInternal_GetResponseVersion
,
1771 nsHttpChannelInternal_SetCookie
,
1772 nsHttpChannelInternal_SetupFallbackChannel
,
1773 nsHttpChannelInternal_GetForceAllowThirdPartyCookie
,
1774 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
,
1775 nsHttpChannelInternal_GetCanceled
,
1776 nsHttpChannelInternal_GetChannelIsForDownload
,
1777 nsHttpChannelInternal_SetChannelIsForDownload
,
1778 nsHttpChannelInternal_GetLocalAddress
,
1779 nsHttpChannelInternal_GetLocalPort
,
1780 nsHttpChannelInternal_GetRemoteAddress
,
1781 nsHttpChannelInternal_GetRemotePort
,
1782 nsHttpChannelInternal_SetCacheKeysRedirectChain
,
1783 nsHttpChannelInternal_HTTPUpgrade
,
1784 nsHttpChannelInternal_GetAllowSpdy
,
1785 nsHttpChannelInternal_SetAllowSpdy
,
1786 nsHttpChannelInternal_GetLoadAsBlocking
,
1787 nsHttpChannelInternal_SetLoadAsBlocking
,
1788 nsHttpChannelInternal_GetLoadUnblocked
,
1789 nsHttpChannelInternal_SetLoadUnblocked
1793 static void invalidate_uri(nsWineURI
*This
)
1796 IUri_Release(This
->uri
);
1801 static BOOL
ensure_uri_builder(nsWineURI
*This
)
1803 if(!This
->is_mutable
) {
1804 WARN("Not mutable URI\n");
1808 if(!This
->uri_builder
) {
1811 if(!ensure_uri(This
))
1814 hres
= CreateIUriBuilder(This
->uri
, 0, 0, &This
->uri_builder
);
1816 WARN("CreateIUriBuilder failed: %08x\n", hres
);
1821 invalidate_uri(This
);
1825 static nsresult
get_uri_string(nsWineURI
*This
, Uri_PROPERTY prop
, nsACString
*ret
)
1831 if(!ensure_uri(This
))
1832 return NS_ERROR_UNEXPECTED
;
1834 hres
= IUri_GetPropertyBSTR(This
->uri
, prop
, &val
, 0);
1836 WARN("GetPropertyBSTR failed: %08x\n", hres
);
1837 return NS_ERROR_UNEXPECTED
;
1840 vala
= heap_strdupWtoU(val
);
1843 return NS_ERROR_OUT_OF_MEMORY
;
1845 TRACE("ret %s\n", debugstr_a(vala
));
1846 nsACString_SetData(ret
, vala
);
1851 static inline nsWineURI
*impl_from_nsIFileURL(nsIFileURL
*iface
)
1853 return CONTAINING_RECORD(iface
, nsWineURI
, nsIFileURL_iface
);
1856 static nsresult NSAPI
nsURI_QueryInterface(nsIFileURL
*iface
, nsIIDRef riid
, void **result
)
1858 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1862 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1863 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1864 *result
= &This
->nsIFileURL_iface
;
1865 }else if(IsEqualGUID(&IID_nsIURI
, riid
)) {
1866 TRACE("(%p)->(IID_nsIURI %p)\n", This
, result
);
1867 *result
= &This
->nsIFileURL_iface
;
1868 }else if(IsEqualGUID(&IID_nsIURL
, riid
)) {
1869 TRACE("(%p)->(IID_nsIURL %p)\n", This
, result
);
1870 *result
= &This
->nsIFileURL_iface
;
1871 }else if(IsEqualGUID(&IID_nsIFileURL
, riid
)) {
1872 TRACE("(%p)->(IID_nsIFileURL %p)\n", This
, result
);
1873 *result
= This
->scheme
== URL_SCHEME_FILE
? &This
->nsIFileURL_iface
: NULL
;
1874 }else if(IsEqualGUID(&IID_nsIMutable
, riid
)) {
1875 TRACE("(%p)->(IID_nsIMutable %p)\n", This
, result
);
1876 *result
= &This
->nsIStandardURL_iface
;
1877 }else if(IsEqualGUID(&IID_nsIStandardURL
, riid
)) {
1878 TRACE("(%p)->(IID_nsIStandardURL %p)\n", This
, result
);
1879 *result
= &This
->nsIStandardURL_iface
;
1880 }else if(IsEqualGUID(&IID_nsWineURI
, riid
)) {
1881 TRACE("(%p)->(IID_nsWineURI %p)\n", This
, result
);
1886 nsIFileURL_AddRef(&This
->nsIFileURL_iface
);
1890 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1891 return NS_NOINTERFACE
;
1894 static nsrefcnt NSAPI
nsURI_AddRef(nsIFileURL
*iface
)
1896 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1897 LONG ref
= InterlockedIncrement(&This
->ref
);
1899 TRACE("(%p) ref=%d\n", This
, ref
);
1904 static nsrefcnt NSAPI
nsURI_Release(nsIFileURL
*iface
)
1906 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1907 LONG ref
= InterlockedDecrement(&This
->ref
);
1909 TRACE("(%p) ref=%d\n", This
, ref
);
1912 if(This
->window_ref
)
1913 windowref_release(This
->window_ref
);
1915 nsIWebBrowserChrome_Release(&This
->container
->nsIWebBrowserChrome_iface
);
1917 IUri_Release(This
->uri
);
1918 heap_free(This
->origin_charset
);
1925 static nsresult NSAPI
nsURI_GetSpec(nsIFileURL
*iface
, nsACString
*aSpec
)
1927 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1929 TRACE("(%p)->(%p)\n", This
, aSpec
);
1931 return get_uri_string(This
, Uri_PROPERTY_DISPLAY_URI
, aSpec
);
1934 static nsresult NSAPI
nsURI_SetSpec(nsIFileURL
*iface
, const nsACString
*aSpec
)
1936 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1942 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aSpec
));
1944 if(!This
->is_mutable
)
1945 return NS_ERROR_UNEXPECTED
;
1947 nsACString_GetData(aSpec
, &speca
);
1948 spec
= heap_strdupUtoW(speca
);
1950 return NS_ERROR_OUT_OF_MEMORY
;
1952 hres
= create_uri(spec
, 0, &uri
);
1955 WARN("create_uri failed: %08x\n", hres
);
1956 return NS_ERROR_FAILURE
;
1959 invalidate_uri(This
);
1960 if(This
->uri_builder
) {
1961 IUriBuilder_Release(This
->uri_builder
);
1962 This
->uri_builder
= NULL
;
1969 static nsresult NSAPI
nsURI_GetPrePath(nsIFileURL
*iface
, nsACString
*aPrePath
)
1971 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1972 FIXME("(%p)->(%p)\n", This
, aPrePath
);
1973 return NS_ERROR_NOT_IMPLEMENTED
;
1976 static nsresult NSAPI
nsURI_GetScheme(nsIFileURL
*iface
, nsACString
*aScheme
)
1978 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
1982 TRACE("(%p)->(%p)\n", This
, aScheme
);
1984 if(!ensure_uri(This
))
1985 return NS_ERROR_UNEXPECTED
;
1987 hres
= IUri_GetScheme(This
->uri
, &scheme
);
1989 WARN("GetScheme failed: %08x\n", hres
);
1990 return NS_ERROR_UNEXPECTED
;
1993 if(scheme
== URL_SCHEME_ABOUT
) {
1994 nsACString_SetData(aScheme
, "wine");
1998 return get_uri_string(This
, Uri_PROPERTY_SCHEME_NAME
, aScheme
);
2001 static nsresult NSAPI
nsURI_SetScheme(nsIFileURL
*iface
, const nsACString
*aScheme
)
2003 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2004 const char *schemea
;
2008 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aScheme
));
2010 if(!ensure_uri_builder(This
))
2011 return NS_ERROR_UNEXPECTED
;
2013 nsACString_GetData(aScheme
, &schemea
);
2014 scheme
= heap_strdupUtoW(schemea
);
2016 return NS_ERROR_OUT_OF_MEMORY
;
2018 hres
= IUriBuilder_SetSchemeName(This
->uri_builder
, scheme
);
2021 return NS_ERROR_UNEXPECTED
;
2026 static nsresult NSAPI
nsURI_GetUserPass(nsIFileURL
*iface
, nsACString
*aUserPass
)
2028 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2032 TRACE("(%p)->(%p)\n", This
, aUserPass
);
2034 if(!ensure_uri(This
))
2035 return NS_ERROR_UNEXPECTED
;
2037 hres
= IUri_GetUserName(This
->uri
, &user
);
2039 return NS_ERROR_FAILURE
;
2041 hres
= IUri_GetPassword(This
->uri
, &pass
);
2043 SysFreeString(user
);
2044 return NS_ERROR_FAILURE
;
2047 if(*user
|| *pass
) {
2048 FIXME("Construct user:pass string\n");
2050 nsACString_SetData(aUserPass
, "");
2053 SysFreeString(user
);
2054 SysFreeString(pass
);
2058 static nsresult NSAPI
nsURI_SetUserPass(nsIFileURL
*iface
, const nsACString
*aUserPass
)
2060 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2061 WCHAR
*user
= NULL
, *pass
= NULL
, *buf
= NULL
;
2062 const char *user_pass
;
2065 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUserPass
));
2067 if(!ensure_uri_builder(This
))
2068 return NS_ERROR_UNEXPECTED
;
2070 nsACString_GetData(aUserPass
, &user_pass
);
2074 buf
= heap_strdupUtoW(user_pass
);
2076 return NS_ERROR_OUT_OF_MEMORY
;
2078 ptr
= strchrW(buf
, ':');
2081 }else if(ptr
!= buf
) {
2091 hres
= IUriBuilder_SetUserName(This
->uri_builder
, user
);
2093 hres
= IUriBuilder_SetPassword(This
->uri_builder
, pass
);
2096 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_FAILURE
;
2099 static nsresult NSAPI
nsURI_GetUsername(nsIFileURL
*iface
, nsACString
*aUsername
)
2101 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2103 TRACE("(%p)->(%p)\n", This
, aUsername
);
2105 return get_uri_string(This
, Uri_PROPERTY_USER_NAME
, aUsername
);
2108 static nsresult NSAPI
nsURI_SetUsername(nsIFileURL
*iface
, const nsACString
*aUsername
)
2110 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2115 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUsername
));
2117 if(!ensure_uri_builder(This
))
2118 return NS_ERROR_UNEXPECTED
;
2120 nsACString_GetData(aUsername
, &usera
);
2121 user
= heap_strdupUtoW(usera
);
2123 return NS_ERROR_OUT_OF_MEMORY
;
2125 hres
= IUriBuilder_SetUserName(This
->uri_builder
, user
);
2128 return NS_ERROR_UNEXPECTED
;
2133 static nsresult NSAPI
nsURI_GetPassword(nsIFileURL
*iface
, nsACString
*aPassword
)
2135 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2137 TRACE("(%p)->(%p)\n", This
, aPassword
);
2139 return get_uri_string(This
, Uri_PROPERTY_PASSWORD
, aPassword
);
2142 static nsresult NSAPI
nsURI_SetPassword(nsIFileURL
*iface
, const nsACString
*aPassword
)
2144 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2149 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPassword
));
2151 if(!ensure_uri_builder(This
))
2152 return NS_ERROR_UNEXPECTED
;
2154 nsACString_GetData(aPassword
, &passa
);
2155 pass
= heap_strdupUtoW(passa
);
2157 return NS_ERROR_OUT_OF_MEMORY
;
2159 hres
= IUriBuilder_SetPassword(This
->uri_builder
, pass
);
2162 return NS_ERROR_UNEXPECTED
;
2167 static nsresult NSAPI
nsURI_GetHostPort(nsIFileURL
*iface
, nsACString
*aHostPort
)
2169 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2175 TRACE("(%p)->(%p)\n", This
, aHostPort
);
2177 if(!ensure_uri(This
))
2178 return NS_ERROR_UNEXPECTED
;
2180 hres
= IUri_GetAuthority(This
->uri
, &val
);
2182 WARN("GetAuthority failed: %08x\n", hres
);
2183 return NS_ERROR_UNEXPECTED
;
2186 ptr
= strchrW(val
, '@');
2190 vala
= heap_strdupWtoU(ptr
);
2193 return NS_ERROR_OUT_OF_MEMORY
;
2195 TRACE("ret %s\n", debugstr_a(vala
));
2196 nsACString_SetData(aHostPort
, vala
);
2201 static nsresult NSAPI
nsURI_SetHostPort(nsIFileURL
*iface
, const nsACString
*aHostPort
)
2203 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2205 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aHostPort
));
2207 /* Not implemented by Gecko */
2208 return NS_ERROR_NOT_IMPLEMENTED
;
2211 static nsresult NSAPI
nsURI_GetHost(nsIFileURL
*iface
, nsACString
*aHost
)
2213 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2215 TRACE("(%p)->(%p)\n", This
, aHost
);
2217 return get_uri_string(This
, Uri_PROPERTY_HOST
, aHost
);
2220 static nsresult NSAPI
nsURI_SetHost(nsIFileURL
*iface
, const nsACString
*aHost
)
2222 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2227 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aHost
));
2229 if(!ensure_uri_builder(This
))
2230 return NS_ERROR_UNEXPECTED
;
2232 nsACString_GetData(aHost
, &hosta
);
2233 host
= heap_strdupUtoW(hosta
);
2235 return NS_ERROR_OUT_OF_MEMORY
;
2237 hres
= IUriBuilder_SetHost(This
->uri_builder
, host
);
2240 return NS_ERROR_UNEXPECTED
;
2245 static nsresult NSAPI
nsURI_GetPort(nsIFileURL
*iface
, LONG
*aPort
)
2247 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2251 TRACE("(%p)->(%p)\n", This
, aPort
);
2253 if(!ensure_uri(This
))
2254 return NS_ERROR_UNEXPECTED
;
2256 hres
= IUri_GetPort(This
->uri
, &port
);
2258 WARN("GetPort failed: %08x\n", hres
);
2259 return NS_ERROR_UNEXPECTED
;
2262 *aPort
= port
? port
: -1;
2266 static nsresult NSAPI
nsURI_SetPort(nsIFileURL
*iface
, LONG aPort
)
2268 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2271 TRACE("(%p)->(%d)\n", This
, aPort
);
2273 if(!ensure_uri_builder(This
))
2274 return NS_ERROR_UNEXPECTED
;
2276 hres
= IUriBuilder_SetPort(This
->uri_builder
, aPort
!= -1, aPort
);
2277 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_FAILURE
;
2280 static nsresult NSAPI
nsURI_GetPath(nsIFileURL
*iface
, nsACString
*aPath
)
2282 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2284 TRACE("(%p)->(%p)\n", This
, aPath
);
2286 return get_uri_string(This
, Uri_PROPERTY_PATH
, aPath
);
2289 static nsresult NSAPI
nsURI_SetPath(nsIFileURL
*iface
, const nsACString
*aPath
)
2291 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2296 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPath
));
2298 if(!ensure_uri_builder(This
))
2299 return NS_ERROR_UNEXPECTED
;
2301 nsACString_GetData(aPath
, &patha
);
2302 path
= heap_strdupUtoW(patha
);
2304 return NS_ERROR_OUT_OF_MEMORY
;
2306 hres
= IUriBuilder_SetPath(This
->uri_builder
, path
);
2309 return NS_ERROR_UNEXPECTED
;
2314 static nsresult NSAPI
nsURI_Equals(nsIFileURL
*iface
, nsIURI
*other
, cpp_bool
*_retval
)
2316 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2317 nsWineURI
*other_obj
;
2321 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
2323 nsres
= nsIURI_QueryInterface(other
, &IID_nsWineURI
, (void**)&other_obj
);
2324 if(NS_FAILED(nsres
)) {
2325 TRACE("Could not get nsWineURI interface\n");
2330 if(ensure_uri(This
) && ensure_uri(other_obj
)) {
2333 hres
= IUri_IsEqual(This
->uri
, other_obj
->uri
, &b
);
2334 if(SUCCEEDED(hres
)) {
2338 nsres
= NS_ERROR_FAILURE
;
2341 nsres
= NS_ERROR_UNEXPECTED
;
2344 nsIFileURL_Release(&other_obj
->nsIFileURL_iface
);
2348 static nsresult NSAPI
nsURI_SchemeIs(nsIFileURL
*iface
, const char *scheme
, cpp_bool
*_retval
)
2350 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2351 WCHAR buf
[INTERNET_MAX_SCHEME_LENGTH
];
2355 TRACE("(%p)->(%s %p)\n", This
, debugstr_a(scheme
), _retval
);
2357 if(!ensure_uri(This
))
2358 return NS_ERROR_UNEXPECTED
;
2360 hres
= IUri_GetSchemeName(This
->uri
, &scheme_name
);
2362 return NS_ERROR_UNEXPECTED
;
2364 MultiByteToWideChar(CP_UTF8
, 0, scheme
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
2365 *_retval
= !strcmpW(scheme_name
, buf
);
2366 SysFreeString(scheme_name
);
2370 static nsresult NSAPI
nsURI_Clone(nsIFileURL
*iface
, nsIURI
**_retval
)
2372 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2373 nsWineURI
*wine_uri
;
2376 TRACE("(%p)->(%p)\n", This
, _retval
);
2378 if(!ensure_uri(This
))
2379 return NS_ERROR_UNEXPECTED
;
2381 nsres
= create_nsuri(This
->uri
, This
->window_ref
? This
->window_ref
->window
: NULL
,
2382 This
->container
, This
->origin_charset
, &wine_uri
);
2383 if(NS_FAILED(nsres
)) {
2384 WARN("create_nsuri failed: %08x\n", nsres
);
2388 *_retval
= (nsIURI
*)&wine_uri
->nsIFileURL_iface
;
2392 static nsresult NSAPI
nsURI_Resolve(nsIFileURL
*iface
, const nsACString
*aRelativePath
,
2393 nsACString
*_retval
)
2395 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2403 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aRelativePath
), _retval
);
2405 if(!ensure_uri(This
))
2406 return NS_ERROR_UNEXPECTED
;
2408 nsACString_GetData(aRelativePath
, &patha
);
2409 path
= heap_strdupUtoW(patha
);
2411 return NS_ERROR_OUT_OF_MEMORY
;
2413 hres
= CoInternetCombineUrlEx(This
->uri
, path
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
, &new_uri
, 0);
2416 ERR("CoIntenetCombineUrlEx failed: %08x\n", hres
);
2417 return NS_ERROR_FAILURE
;
2420 hres
= IUri_GetDisplayUri(new_uri
, &ret
);
2421 IUri_Release(new_uri
);
2423 return NS_ERROR_FAILURE
;
2425 reta
= heap_strdupWtoU(ret
);
2428 return NS_ERROR_OUT_OF_MEMORY
;
2430 TRACE("returning %s\n", debugstr_a(reta
));
2431 nsACString_SetData(_retval
, reta
);
2436 static nsresult NSAPI
nsURI_GetAsciiSpec(nsIFileURL
*iface
, nsACString
*aAsciiSpec
)
2438 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2440 TRACE("(%p)->(%p)\n", This
, aAsciiSpec
);
2442 return nsIFileURL_GetSpec(&This
->nsIFileURL_iface
, aAsciiSpec
);
2445 static nsresult NSAPI
nsURI_GetAsciiHost(nsIFileURL
*iface
, nsACString
*aAsciiHost
)
2447 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2449 WARN("(%p)->(%p) FIXME: Use Uri_PUNYCODE_IDN_HOST flag\n", This
, aAsciiHost
);
2451 return get_uri_string(This
, Uri_PROPERTY_HOST
, aAsciiHost
);
2454 static nsresult NSAPI
nsURI_GetOriginCharset(nsIFileURL
*iface
, nsACString
*aOriginCharset
)
2456 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2458 TRACE("(%p)->(%p)\n", This
, aOriginCharset
);
2460 nsACString_SetData(aOriginCharset
, This
->origin_charset
);
2464 static nsresult NSAPI
nsURL_GetRef(nsIFileURL
*iface
, nsACString
*aRef
)
2466 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2471 TRACE("(%p)->(%p)\n", This
, aRef
);
2473 if(!ensure_uri(This
))
2474 return NS_ERROR_UNEXPECTED
;
2476 hres
= IUri_GetFragment(This
->uri
, &ref
);
2478 return NS_ERROR_UNEXPECTED
;
2480 refa
= heap_strdupWtoU(ref
);
2483 return NS_ERROR_OUT_OF_MEMORY
;
2485 nsACString_SetData(aRef
, refa
&& *refa
== '#' ? refa
+1 : refa
);
2490 static nsresult NSAPI
nsURL_SetRef(nsIFileURL
*iface
, const nsACString
*aRef
)
2492 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2497 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRef
));
2499 if(!ensure_uri_builder(This
))
2500 return NS_ERROR_UNEXPECTED
;
2502 nsACString_GetData(aRef
, &refa
);
2503 ref
= heap_strdupUtoW(refa
);
2505 return NS_ERROR_OUT_OF_MEMORY
;
2507 hres
= IUriBuilder_SetFragment(This
->uri_builder
, ref
);
2510 return NS_ERROR_UNEXPECTED
;
2515 static nsresult NSAPI
nsURI_EqualsExceptRef(nsIFileURL
*iface
, nsIURI
*other
, cpp_bool
*_retval
)
2517 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2518 nsWineURI
*other_obj
;
2521 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
2523 nsres
= nsIURI_QueryInterface(other
, &IID_nsWineURI
, (void**)&other_obj
);
2524 if(NS_FAILED(nsres
)) {
2525 TRACE("Could not get nsWineURI interface\n");
2530 if(ensure_uri(This
) && ensure_uri(other_obj
)) {
2531 *_retval
= compare_ignoring_frag(This
->uri
, other_obj
->uri
);
2534 nsres
= NS_ERROR_UNEXPECTED
;
2537 nsIFileURL_Release(&other_obj
->nsIFileURL_iface
);
2541 static nsresult NSAPI
nsURI_CloneIgnoreRef(nsIFileURL
*iface
, nsIURI
**_retval
)
2543 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2544 nsWineURI
*wine_uri
;
2548 TRACE("(%p)->(%p)\n", This
, _retval
);
2550 if(!ensure_uri(This
))
2551 return NS_ERROR_UNEXPECTED
;
2553 uri
= get_uri_nofrag(This
->uri
);
2555 return NS_ERROR_FAILURE
;
2557 nsres
= create_nsuri(uri
, This
->window_ref
? This
->window_ref
->window
: NULL
, This
->container
,
2558 This
->origin_charset
, &wine_uri
);
2560 if(NS_FAILED(nsres
)) {
2561 WARN("create_nsuri failed: %08x\n", nsres
);
2565 *_retval
= (nsIURI
*)&wine_uri
->nsIFileURL_iface
;
2569 static nsresult NSAPI
nsURI_GetSpecIgnoringRef(nsIFileURL
*iface
, nsACString
*aSpecIgnoringRef
)
2571 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2573 FIXME("(%p)->(%p)\n", This
, aSpecIgnoringRef
);
2575 return nsIFileURL_GetSpec(&This
->nsIFileURL_iface
, aSpecIgnoringRef
);
2578 static nsresult NSAPI
nsURI_GetHasRef(nsIFileURL
*iface
, cpp_bool
*aHasRef
)
2580 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2584 TRACE("(%p)->(%p)\n", This
, aHasRef
);
2586 if(!ensure_uri(This
))
2587 return NS_ERROR_UNEXPECTED
;
2589 hres
= IUri_HasProperty(This
->uri
, Uri_PROPERTY_FRAGMENT
, &b
);
2591 return NS_ERROR_FAILURE
;
2597 static nsresult NSAPI
nsURL_GetFilePath(nsIFileURL
*iface
, nsACString
*aFilePath
)
2599 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2601 TRACE("(%p)->(%p)\n", This
, aFilePath
);
2603 return nsIFileURL_GetPath(&This
->nsIFileURL_iface
, aFilePath
);
2606 static nsresult NSAPI
nsURL_SetFilePath(nsIFileURL
*iface
, const nsACString
*aFilePath
)
2608 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2610 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFilePath
));
2612 if(!This
->is_mutable
)
2613 return NS_ERROR_UNEXPECTED
;
2615 return nsIFileURL_SetPath(&This
->nsIFileURL_iface
, aFilePath
);
2618 static nsresult NSAPI
nsURL_GetQuery(nsIFileURL
*iface
, nsACString
*aQuery
)
2620 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2622 TRACE("(%p)->(%p)\n", This
, aQuery
);
2624 return get_uri_string(This
, Uri_PROPERTY_QUERY
, aQuery
);
2627 static nsresult NSAPI
nsURL_SetQuery(nsIFileURL
*iface
, const nsACString
*aQuery
)
2629 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2634 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aQuery
));
2636 if(!ensure_uri_builder(This
))
2637 return NS_ERROR_UNEXPECTED
;
2639 nsACString_GetData(aQuery
, &querya
);
2640 query
= heap_strdupUtoW(querya
);
2642 return NS_ERROR_OUT_OF_MEMORY
;
2644 hres
= IUriBuilder_SetQuery(This
->uri_builder
, query
);
2647 return NS_ERROR_UNEXPECTED
;
2652 static nsresult
get_uri_path(nsWineURI
*This
, BSTR
*path
, const WCHAR
**file
, const WCHAR
**ext
)
2657 if(!ensure_uri(This
))
2658 return NS_ERROR_UNEXPECTED
;
2660 hres
= IUri_GetPath(This
->uri
, path
);
2662 return NS_ERROR_FAILURE
;
2664 for(ptr
= *path
+ SysStringLen(*path
)-1; ptr
> *path
&& *ptr
!= '/' && *ptr
!= '\\'; ptr
--);
2665 if(*ptr
== '/' || *ptr
== '\\')
2670 ptr
= strrchrW(ptr
, '.');
2672 ptr
= *path
+ SysStringLen(*path
);
2679 static nsresult NSAPI
nsURL_GetDirectory(nsIFileURL
*iface
, nsACString
*aDirectory
)
2681 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2686 TRACE("(%p)->(%p)\n", This
, aDirectory
);
2688 nsres
= get_uri_path(This
, &path
, &file
, NULL
);
2689 if(NS_FAILED(nsres
))
2692 nsres
= return_wstr_nsacstr(aDirectory
, path
, file
-path
);
2693 SysFreeString(path
);
2697 static nsresult NSAPI
nsURL_SetDirectory(nsIFileURL
*iface
, const nsACString
*aDirectory
)
2699 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2701 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aDirectory
));
2703 /* Not implemented by Gecko */
2704 return NS_ERROR_NOT_IMPLEMENTED
;
2707 static nsresult NSAPI
nsURL_GetFileName(nsIFileURL
*iface
, nsACString
*aFileName
)
2709 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2714 TRACE("(%p)->(%p)\n", This
, aFileName
);
2716 nsres
= get_uri_path(This
, &path
, &file
, NULL
);
2717 if(NS_FAILED(nsres
))
2720 nsres
= return_wstr_nsacstr(aFileName
, file
, -1);
2721 SysFreeString(path
);
2725 static nsresult NSAPI
nsURL_SetFileName(nsIFileURL
*iface
, const nsACString
*aFileName
)
2727 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2728 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileName
));
2729 return NS_ERROR_NOT_IMPLEMENTED
;
2732 static nsresult NSAPI
nsURL_GetFileBaseName(nsIFileURL
*iface
, nsACString
*aFileBaseName
)
2734 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2735 const WCHAR
*file
, *ext
;
2739 TRACE("(%p)->(%p)\n", This
, aFileBaseName
);
2741 nsres
= get_uri_path(This
, &path
, &file
, &ext
);
2742 if(NS_FAILED(nsres
))
2745 nsres
= return_wstr_nsacstr(aFileBaseName
, file
, ext
-file
);
2746 SysFreeString(path
);
2750 static nsresult NSAPI
nsURL_SetFileBaseName(nsIFileURL
*iface
, const nsACString
*aFileBaseName
)
2752 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2753 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileBaseName
));
2754 return NS_ERROR_NOT_IMPLEMENTED
;
2757 static nsresult NSAPI
nsURL_GetFileExtension(nsIFileURL
*iface
, nsACString
*aFileExtension
)
2759 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2761 TRACE("(%p)->(%p)\n", This
, aFileExtension
);
2763 return get_uri_string(This
, Uri_PROPERTY_EXTENSION
, aFileExtension
);
2766 static nsresult NSAPI
nsURL_SetFileExtension(nsIFileURL
*iface
, const nsACString
*aFileExtension
)
2768 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2769 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileExtension
));
2770 return NS_ERROR_NOT_IMPLEMENTED
;
2773 static nsresult NSAPI
nsURL_GetCommonBaseSpec(nsIFileURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2775 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2776 FIXME("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2777 return NS_ERROR_NOT_IMPLEMENTED
;
2780 static nsresult NSAPI
nsURL_GetRelativeSpec(nsIFileURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2782 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2783 FIXME("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2784 return NS_ERROR_NOT_IMPLEMENTED
;
2787 static nsresult NSAPI
nsFileURL_GetFile(nsIFileURL
*iface
, nsIFile
**aFile
)
2789 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2790 WCHAR path
[MAX_PATH
];
2794 TRACE("(%p)->(%p)\n", This
, aFile
);
2796 hres
= CoInternetParseIUri(This
->uri
, PARSE_PATH_FROM_URL
, 0, path
, sizeof(path
)/sizeof(WCHAR
), &size
, 0);
2798 WARN("CoInternetParseIUri failed: %08x\n", hres
);
2799 return NS_ERROR_FAILURE
;
2802 return create_nsfile(path
, aFile
);
2805 static nsresult NSAPI
nsFileURL_SetFile(nsIFileURL
*iface
, nsIFile
*aFile
)
2807 nsWineURI
*This
= impl_from_nsIFileURL(iface
);
2808 FIXME("(%p)->(%p)\n", This
, aFile
);
2809 return NS_ERROR_NOT_IMPLEMENTED
;
2812 static const nsIFileURLVtbl nsFileURLVtbl
= {
2813 nsURI_QueryInterface
,
2841 nsURI_GetOriginCharset
,
2844 nsURI_EqualsExceptRef
,
2845 nsURI_CloneIgnoreRef
,
2846 nsURI_GetSpecIgnoringRef
,
2856 nsURL_GetFileBaseName
,
2857 nsURL_SetFileBaseName
,
2858 nsURL_GetFileExtension
,
2859 nsURL_SetFileExtension
,
2860 nsURL_GetCommonBaseSpec
,
2861 nsURL_GetRelativeSpec
,
2866 static inline nsWineURI
*impl_from_nsIStandardURL(nsIStandardURL
*iface
)
2868 return CONTAINING_RECORD(iface
, nsWineURI
, nsIStandardURL_iface
);
2871 static nsresult NSAPI
nsStandardURL_QueryInterface(nsIStandardURL
*iface
, nsIIDRef riid
,
2874 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2875 return nsIFileURL_QueryInterface(&This
->nsIFileURL_iface
, riid
, result
);
2878 static nsrefcnt NSAPI
nsStandardURL_AddRef(nsIStandardURL
*iface
)
2880 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2881 return nsIFileURL_AddRef(&This
->nsIFileURL_iface
);
2884 static nsrefcnt NSAPI
nsStandardURL_Release(nsIStandardURL
*iface
)
2886 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2887 return nsIFileURL_Release(&This
->nsIFileURL_iface
);
2890 static nsresult NSAPI
nsStandardURL_GetMutable(nsIStandardURL
*iface
, cpp_bool
*aMutable
)
2892 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2894 TRACE("(%p)->(%p)\n", This
, aMutable
);
2896 *aMutable
= This
->is_mutable
;
2900 static nsresult NSAPI
nsStandardURL_SetMutable(nsIStandardURL
*iface
, cpp_bool aMutable
)
2902 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2904 TRACE("(%p)->(%x)\n", This
, aMutable
);
2906 This
->is_mutable
= aMutable
;
2910 static nsresult NSAPI
nsStandardURL_Init(nsIStandardURL
*iface
, UINT32 aUrlType
, LONG aDefaultPort
,
2911 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
)
2913 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2914 FIXME("(%p)->(%d %d %s %s %p)\n", This
, aUrlType
, aDefaultPort
, debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
), aBaseURI
);
2915 return NS_ERROR_NOT_IMPLEMENTED
;
2918 static const nsIStandardURLVtbl nsStandardURLVtbl
= {
2919 nsStandardURL_QueryInterface
,
2920 nsStandardURL_AddRef
,
2921 nsStandardURL_Release
,
2922 nsStandardURL_GetMutable
,
2923 nsStandardURL_SetMutable
,
2927 static nsresult
create_nsuri(IUri
*iuri
, HTMLOuterWindow
*window
, NSContainer
*container
,
2928 const char *origin_charset
, nsWineURI
**_retval
)
2933 ret
= heap_alloc_zero(sizeof(nsWineURI
));
2935 return NS_ERROR_OUT_OF_MEMORY
;
2937 ret
->nsIFileURL_iface
.lpVtbl
= &nsFileURLVtbl
;
2938 ret
->nsIStandardURL_iface
.lpVtbl
= &nsStandardURLVtbl
;
2940 ret
->is_mutable
= TRUE
;
2942 set_uri_nscontainer(ret
, container
);
2943 set_uri_window(ret
, window
);
2948 hres
= IUri_GetScheme(iuri
, &ret
->scheme
);
2950 ret
->scheme
= URL_SCHEME_UNKNOWN
;
2952 if(origin_charset
&& *origin_charset
&& strcmp(origin_charset
, "UTF-8")) {
2953 ret
->origin_charset
= heap_strdupA(origin_charset
);
2954 if(!ret
->origin_charset
) {
2955 nsIFileURL_Release(&ret
->nsIFileURL_iface
);
2956 return NS_ERROR_OUT_OF_MEMORY
;
2960 TRACE("retval=%p\n", ret
);
2965 HRESULT
create_doc_uri(HTMLOuterWindow
*window
, IUri
*iuri
, nsWineURI
**ret
)
2970 nsres
= create_nsuri(iuri
, window
, window
->doc_obj
->nscontainer
, NULL
, &uri
);
2971 if(NS_FAILED(nsres
))
2974 uri
->is_doc_uri
= TRUE
;
2980 static nsresult
create_nschannel(nsWineURI
*uri
, nsChannel
**ret
)
2984 if(!ensure_uri(uri
))
2985 return NS_ERROR_UNEXPECTED
;
2987 channel
= heap_alloc_zero(sizeof(nsChannel
));
2989 return NS_ERROR_OUT_OF_MEMORY
;
2991 channel
->nsIHttpChannel_iface
.lpVtbl
= &nsChannelVtbl
;
2992 channel
->nsIUploadChannel_iface
.lpVtbl
= &nsUploadChannelVtbl
;
2993 channel
->nsIHttpChannelInternal_iface
.lpVtbl
= &nsHttpChannelInternalVtbl
;
2995 channel
->request_method
= METHOD_GET
;
2996 list_init(&channel
->response_headers
);
2997 list_init(&channel
->request_headers
);
2999 nsIFileURL_AddRef(&uri
->nsIFileURL_iface
);
3006 HRESULT
create_redirect_nschannel(const WCHAR
*url
, nsChannel
*orig_channel
, nsChannel
**ret
)
3008 HTMLOuterWindow
*window
= NULL
;
3015 hres
= create_uri(url
, 0, &iuri
);
3019 if(orig_channel
->uri
->window_ref
)
3020 window
= orig_channel
->uri
->window_ref
->window
;
3021 nsres
= create_nsuri(iuri
, window
, NULL
, NULL
, &uri
);
3023 if(NS_FAILED(nsres
))
3026 nsres
= create_nschannel(uri
, &channel
);
3027 nsIFileURL_Release(&uri
->nsIFileURL_iface
);
3028 if(NS_FAILED(nsres
))
3031 if(orig_channel
->load_group
) {
3032 nsILoadGroup_AddRef(orig_channel
->load_group
);
3033 channel
->load_group
= orig_channel
->load_group
;
3036 if(orig_channel
->notif_callback
) {
3037 nsIInterfaceRequestor_AddRef(orig_channel
->notif_callback
);
3038 channel
->notif_callback
= orig_channel
->notif_callback
;
3041 channel
->load_flags
= orig_channel
->load_flags
| LOAD_REPLACE
;
3043 if(orig_channel
->request_method
== METHOD_POST
)
3044 FIXME("unsupported POST method\n");
3046 if(orig_channel
->original_uri
) {
3047 nsIURI_AddRef(orig_channel
->original_uri
);
3048 channel
->original_uri
= orig_channel
->original_uri
;
3051 if(orig_channel
->referrer
) {
3052 nsIURI_AddRef(orig_channel
->referrer
);
3053 channel
->referrer
= orig_channel
->referrer
;
3061 nsIProtocolHandler nsIProtocolHandler_iface
;
3065 nsIProtocolHandler
*nshandler
;
3066 } nsProtocolHandler
;
3068 static inline nsProtocolHandler
*impl_from_nsIProtocolHandler(nsIProtocolHandler
*iface
)
3070 return CONTAINING_RECORD(iface
, nsProtocolHandler
, nsIProtocolHandler_iface
);
3073 static nsresult NSAPI
nsProtocolHandler_QueryInterface(nsIProtocolHandler
*iface
, nsIIDRef riid
,
3076 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3080 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
3081 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
3082 *result
= &This
->nsIProtocolHandler_iface
;
3083 }else if(IsEqualGUID(&IID_nsIProtocolHandler
, riid
)) {
3084 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This
, result
);
3085 *result
= &This
->nsIProtocolHandler_iface
;
3086 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler
, riid
)) {
3087 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This
, result
);
3088 return NS_NOINTERFACE
;
3092 nsISupports_AddRef((nsISupports
*)*result
);
3096 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
3097 return NS_NOINTERFACE
;
3100 static nsrefcnt NSAPI
nsProtocolHandler_AddRef(nsIProtocolHandler
*iface
)
3102 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3103 LONG ref
= InterlockedIncrement(&This
->ref
);
3105 TRACE("(%p) ref=%d\n", This
, ref
);
3110 static nsrefcnt NSAPI
nsProtocolHandler_Release(nsIProtocolHandler
*iface
)
3112 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3113 LONG ref
= InterlockedDecrement(&This
->ref
);
3115 TRACE("(%p) ref=%d\n", This
, ref
);
3119 nsIProtocolHandler_Release(This
->nshandler
);
3126 static nsresult NSAPI
nsProtocolHandler_GetScheme(nsIProtocolHandler
*iface
, nsACString
*aScheme
)
3128 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3130 TRACE("(%p)->(%p)\n", This
, aScheme
);
3133 return nsIProtocolHandler_GetScheme(This
->nshandler
, aScheme
);
3134 return NS_ERROR_NOT_IMPLEMENTED
;
3137 static nsresult NSAPI
nsProtocolHandler_GetDefaultPort(nsIProtocolHandler
*iface
,
3140 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3142 TRACE("(%p)->(%p)\n", This
, aDefaultPort
);
3145 return nsIProtocolHandler_GetDefaultPort(This
->nshandler
, aDefaultPort
);
3146 return NS_ERROR_NOT_IMPLEMENTED
;
3149 static nsresult NSAPI
nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler
*iface
,
3150 UINT32
*aProtocolFlags
)
3152 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3154 TRACE("(%p)->(%p)\n", This
, aProtocolFlags
);
3157 return nsIProtocolHandler_GetProtocolFlags(This
->nshandler
, aProtocolFlags
);
3158 return NS_ERROR_NOT_IMPLEMENTED
;
3161 static nsresult NSAPI
nsProtocolHandler_NewURI(nsIProtocolHandler
*iface
,
3162 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
3164 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3166 TRACE("((%p)->%s %s %p %p)\n", This
, debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
3170 return nsIProtocolHandler_NewURI(This
->nshandler
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3171 return NS_ERROR_NOT_IMPLEMENTED
;
3174 static nsresult NSAPI
nsProtocolHandler_NewChannel(nsIProtocolHandler
*iface
,
3175 nsIURI
*aURI
, nsIChannel
**_retval
)
3177 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3179 TRACE("(%p)->(%p %p)\n", This
, aURI
, _retval
);
3182 return nsIProtocolHandler_NewChannel(This
->nshandler
, aURI
, _retval
);
3183 return NS_ERROR_NOT_IMPLEMENTED
;
3186 static nsresult NSAPI
nsProtocolHandler_AllowPort(nsIProtocolHandler
*iface
,
3187 LONG port
, const char *scheme
, cpp_bool
*_retval
)
3189 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3191 TRACE("(%p)->(%d %s %p)\n", This
, port
, debugstr_a(scheme
), _retval
);
3194 return nsIProtocolHandler_AllowPort(This
->nshandler
, port
, scheme
, _retval
);
3195 return NS_ERROR_NOT_IMPLEMENTED
;
3198 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl
= {
3199 nsProtocolHandler_QueryInterface
,
3200 nsProtocolHandler_AddRef
,
3201 nsProtocolHandler_Release
,
3202 nsProtocolHandler_GetScheme
,
3203 nsProtocolHandler_GetDefaultPort
,
3204 nsProtocolHandler_GetProtocolFlags
,
3205 nsProtocolHandler_NewURI
,
3206 nsProtocolHandler_NewChannel
,
3207 nsProtocolHandler_AllowPort
3210 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*,nsIIDRef
,void**);
3212 static nsrefcnt NSAPI
nsIOService_AddRef(nsIIOService
*iface
)
3217 static nsrefcnt NSAPI
nsIOService_Release(nsIIOService
*iface
)
3222 static nsresult NSAPI
nsIOService_GetProtocolHandler(nsIIOService
*iface
, const char *aScheme
,
3223 nsIProtocolHandler
**_retval
)
3225 nsIExternalProtocolHandler
*nsexthandler
;
3226 nsIProtocolHandler
*nshandler
;
3227 nsProtocolHandler
*ret
;
3230 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
3232 nsres
= nsIIOService_GetProtocolHandler(nsio
, aScheme
, &nshandler
);
3233 if(NS_FAILED(nsres
)) {
3234 WARN("GetProtocolHandler failed: %08x\n", nsres
);
3238 nsres
= nsIProtocolHandler_QueryInterface(nshandler
, &IID_nsIExternalProtocolHandler
,
3239 (void**)&nsexthandler
);
3240 if(NS_FAILED(nsres
)) {
3241 *_retval
= nshandler
;
3245 nsIExternalProtocolHandler_Release(nsexthandler
);
3247 ret
= heap_alloc(sizeof(nsProtocolHandler
));
3249 return NS_ERROR_OUT_OF_MEMORY
;
3251 ret
->nsIProtocolHandler_iface
.lpVtbl
= &nsProtocolHandlerVtbl
;
3253 ret
->nshandler
= nshandler
;
3254 *_retval
= &ret
->nsIProtocolHandler_iface
;
3256 TRACE("return %p\n", *_retval
);
3260 static nsresult NSAPI
nsIOService_GetProtocolFlags(nsIIOService
*iface
, const char *aScheme
,
3263 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
3264 return nsIIOService_GetProtocolFlags(nsio
, aScheme
, _retval
);
3267 static BOOL
is_gecko_special_uri(const char *spec
)
3269 static const char *special_schemes
[] = {"chrome:", "jar:", "moz-safe-about", "resource:", "javascript:", "wyciwyg:"};
3272 for(i
=0; i
< sizeof(special_schemes
)/sizeof(*special_schemes
); i
++) {
3273 if(!strncasecmp(spec
, special_schemes
[i
], strlen(special_schemes
[i
])))
3277 if(!strncasecmp(spec
, "file:", 5)) {
3278 const char *ptr
= spec
+5;
3281 return is_gecko_path(ptr
);
3287 static nsresult NSAPI
nsIOService_NewURI(nsIIOService
*iface
, const nsACString
*aSpec
,
3288 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
3290 nsWineURI
*wine_uri
, *base_wine_uri
= NULL
;
3291 WCHAR new_spec
[INTERNET_MAX_URL_LENGTH
];
3292 HTMLOuterWindow
*window
= NULL
;
3293 const char *spec
= NULL
;
3298 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
3301 nsACString_GetData(aSpec
, &spec
);
3302 if(is_gecko_special_uri(spec
))
3303 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3305 if(!strncmp(spec
, "wine:", 5))
3309 nsres
= nsIURI_QueryInterface(aBaseURI
, &IID_nsWineURI
, (void**)&base_wine_uri
);
3310 if(NS_SUCCEEDED(nsres
)) {
3311 if(!ensure_uri(base_wine_uri
))
3312 return NS_ERROR_UNEXPECTED
;
3313 if(base_wine_uri
->window_ref
)
3314 window
= base_wine_uri
->window_ref
->window
;
3316 WARN("Could not get base nsWineURI: %08x\n", nsres
);
3320 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, new_spec
, sizeof(new_spec
)/sizeof(WCHAR
));
3323 hres
= CoInternetCombineUrlEx(base_wine_uri
->uri
, new_spec
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
3326 WARN("CoInternetCombineUrlEx failed: %08x\n", hres
);
3328 hres
= create_uri(new_spec
, 0, &urlmon_uri
);
3330 WARN("create_uri failed: %08x\n", hres
);
3334 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3336 nsres
= create_nsuri(urlmon_uri
, window
, NULL
, NULL
, &wine_uri
);
3337 IUri_Release(urlmon_uri
);
3339 nsIFileURL_Release(&base_wine_uri
->nsIFileURL_iface
);
3340 if(NS_FAILED(nsres
))
3343 *_retval
= (nsIURI
*)&wine_uri
->nsIFileURL_iface
;
3347 static nsresult NSAPI
nsIOService_NewFileURI(nsIIOService
*iface
, nsIFile
*aFile
,
3350 TRACE("(%p %p)\n", aFile
, _retval
);
3351 return nsIIOService_NewFileURI(nsio
, aFile
, _retval
);
3354 static nsresult NSAPI
nsIOService_NewChannelFromURI(nsIIOService
*iface
, nsIURI
*aURI
,
3355 nsIChannel
**_retval
)
3357 nsWineURI
*wine_uri
;
3361 TRACE("(%p %p)\n", aURI
, _retval
);
3363 nsres
= nsIURI_QueryInterface(aURI
, &IID_nsWineURI
, (void**)&wine_uri
);
3364 if(NS_FAILED(nsres
)) {
3365 TRACE("Could not get nsWineURI: %08x\n", nsres
);
3366 return nsIIOService_NewChannelFromURI(nsio
, aURI
, _retval
);
3369 nsres
= create_nschannel(wine_uri
, &ret
);
3370 nsIFileURL_Release(&wine_uri
->nsIFileURL_iface
);
3371 if(NS_FAILED(nsres
))
3374 nsIURI_AddRef(aURI
);
3375 ret
->original_uri
= aURI
;
3377 *_retval
= (nsIChannel
*)&ret
->nsIHttpChannel_iface
;
3381 static nsresult NSAPI
nsIOService_NewChannel(nsIIOService
*iface
, const nsACString
*aSpec
,
3382 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIChannel
**_retval
)
3384 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
), aBaseURI
, _retval
);
3385 return nsIIOService_NewChannel(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3388 static nsresult NSAPI
nsIOService_GetOffline(nsIIOService
*iface
, cpp_bool
*aOffline
)
3390 TRACE("(%p)\n", aOffline
);
3391 return nsIIOService_GetOffline(nsio
, aOffline
);
3394 static nsresult NSAPI
nsIOService_SetOffline(nsIIOService
*iface
, cpp_bool aOffline
)
3396 TRACE("(%x)\n", aOffline
);
3397 return nsIIOService_SetOffline(nsio
, aOffline
);
3400 static nsresult NSAPI
nsIOService_AllowPort(nsIIOService
*iface
, LONG aPort
,
3401 const char *aScheme
, cpp_bool
*_retval
)
3403 TRACE("(%d %s %p)\n", aPort
, debugstr_a(aScheme
), _retval
);
3404 return nsIIOService_AllowPort(nsio
, aPort
, debugstr_a(aScheme
), _retval
);
3407 static nsresult NSAPI
nsIOService_ExtractScheme(nsIIOService
*iface
, const nsACString
*urlString
,
3408 nsACString
* _retval
)
3410 TRACE("(%s %p)\n", debugstr_nsacstr(urlString
), _retval
);
3411 return nsIIOService_ExtractScheme(nsio
, urlString
, _retval
);
3414 static const nsIIOServiceVtbl nsIOServiceVtbl
= {
3415 nsIOService_QueryInterface
,
3417 nsIOService_Release
,
3418 nsIOService_GetProtocolHandler
,
3419 nsIOService_GetProtocolFlags
,
3421 nsIOService_NewFileURI
,
3422 nsIOService_NewChannelFromURI
,
3423 nsIOService_NewChannel
,
3424 nsIOService_GetOffline
,
3425 nsIOService_SetOffline
,
3426 nsIOService_AllowPort
,
3427 nsIOService_ExtractScheme
3430 static nsIIOService nsIOService
= { &nsIOServiceVtbl
};
3432 static nsresult NSAPI
nsNetUtil_QueryInterface(nsINetUtil
*iface
, nsIIDRef riid
,
3435 return nsIIOService_QueryInterface(&nsIOService
, riid
, result
);
3438 static nsrefcnt NSAPI
nsNetUtil_AddRef(nsINetUtil
*iface
)
3443 static nsrefcnt NSAPI
nsNetUtil_Release(nsINetUtil
*iface
)
3448 static nsresult NSAPI
nsNetUtil_ParseContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
3449 nsACString
*aCharset
, cpp_bool
*aHadCharset
, nsACString
*aContentType
)
3451 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aHadCharset
, aContentType
);
3453 return nsINetUtil_ParseContentType(net_util
, aTypeHeader
, aCharset
, aHadCharset
, aContentType
);
3456 static nsresult NSAPI
nsNetUtil_ProtocolHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, UINT32 aFlags
, cpp_bool
*_retval
)
3460 return nsINetUtil_ProtocolHasFlags(net_util
, aURI
, aFlags
, _retval
);
3463 static nsresult NSAPI
nsNetUtil_URIChainHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, UINT32 aFlags
, cpp_bool
*_retval
)
3465 TRACE("(%p %08x %p)\n", aURI
, aFlags
, _retval
);
3467 if(aFlags
== (1<<11)) {
3472 return nsINetUtil_URIChainHasFlags(net_util
, aURI
, aFlags
, _retval
);
3475 static nsresult NSAPI
nsNetUtil_ToImmutableURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
3477 TRACE("(%p %p)\n", aURI
, _retval
);
3479 return nsINetUtil_ToImmutableURI(net_util
, aURI
, _retval
);
3482 static nsresult NSAPI
nsNetUtil_NewSimpleNestedURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
3484 TRACE("(%p %p)\n", aURI
, _retval
);
3486 return nsINetUtil_NewSimpleNestedURI(net_util
, aURI
, _retval
);
3489 static nsresult NSAPI
nsNetUtil_EscapeString(nsINetUtil
*iface
, const nsACString
*aString
,
3490 UINT32 aEscapeType
, nsACString
*_retval
)
3492 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString
), aEscapeType
, _retval
);
3494 return nsINetUtil_EscapeString(net_util
, aString
, aEscapeType
, _retval
);
3497 static nsresult NSAPI
nsNetUtil_EscapeURL(nsINetUtil
*iface
, const nsACString
*aStr
, UINT32 aFlags
,
3498 nsACString
*_retval
)
3500 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
3502 return nsINetUtil_EscapeURL(net_util
, aStr
, aFlags
, _retval
);
3505 static nsresult NSAPI
nsNetUtil_UnescapeString(nsINetUtil
*iface
, const nsACString
*aStr
,
3506 UINT32 aFlags
, nsACString
*_retval
)
3508 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
3510 return nsINetUtil_UnescapeString(net_util
, aStr
, aFlags
, _retval
);
3513 static nsresult NSAPI
nsNetUtil_ExtractCharsetFromContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
3514 nsACString
*aCharset
, LONG
*aCharsetStart
, LONG
*aCharsetEnd
, cpp_bool
*_retval
)
3516 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aCharsetStart
,
3517 aCharsetEnd
, _retval
);
3519 return nsINetUtil_ExtractCharsetFromContentType(net_util
, aTypeHeader
, aCharset
, aCharsetStart
, aCharsetEnd
, _retval
);
3522 static const nsINetUtilVtbl nsNetUtilVtbl
= {
3523 nsNetUtil_QueryInterface
,
3526 nsNetUtil_ParseContentType
,
3527 nsNetUtil_ProtocolHasFlags
,
3528 nsNetUtil_URIChainHasFlags
,
3529 nsNetUtil_ToImmutableURI
,
3530 nsNetUtil_NewSimpleNestedURI
,
3531 nsNetUtil_EscapeString
,
3532 nsNetUtil_EscapeURL
,
3533 nsNetUtil_UnescapeString
,
3534 nsNetUtil_ExtractCharsetFromContentType
3537 static nsINetUtil nsNetUtil
= { &nsNetUtilVtbl
};
3539 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*iface
, nsIIDRef riid
,
3544 if(IsEqualGUID(&IID_nsISupports
, riid
))
3545 *result
= &nsIOService
;
3546 else if(IsEqualGUID(&IID_nsIIOService
, riid
))
3547 *result
= &nsIOService
;
3548 else if(IsEqualGUID(&IID_nsINetUtil
, riid
))
3549 *result
= &nsNetUtil
;
3552 nsISupports_AddRef((nsISupports
*)*result
);
3556 FIXME("(%s %p)\n", debugstr_guid(riid
), result
);
3557 return NS_NOINTERFACE
;
3560 static nsresult NSAPI
nsIOServiceFactory_QueryInterface(nsIFactory
*iface
, nsIIDRef riid
,
3565 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
3566 TRACE("(IID_nsISupports %p)\n", result
);
3568 }else if(IsEqualGUID(&IID_nsIFactory
, riid
)) {
3569 TRACE("(IID_nsIFactory %p)\n", result
);
3574 nsIFactory_AddRef(iface
);
3578 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
3579 return NS_NOINTERFACE
;
3582 static nsrefcnt NSAPI
nsIOServiceFactory_AddRef(nsIFactory
*iface
)
3587 static nsrefcnt NSAPI
nsIOServiceFactory_Release(nsIFactory
*iface
)
3592 static nsresult NSAPI
nsIOServiceFactory_CreateInstance(nsIFactory
*iface
,
3593 nsISupports
*aOuter
, const nsIID
*iid
, void **result
)
3595 return nsIIOService_QueryInterface(&nsIOService
, iid
, result
);
3598 static nsresult NSAPI
nsIOServiceFactory_LockFactory(nsIFactory
*iface
, cpp_bool lock
)
3600 WARN("(%x)\n", lock
);
3604 static const nsIFactoryVtbl nsIOServiceFactoryVtbl
= {
3605 nsIOServiceFactory_QueryInterface
,
3606 nsIOServiceFactory_AddRef
,
3607 nsIOServiceFactory_Release
,
3608 nsIOServiceFactory_CreateInstance
,
3609 nsIOServiceFactory_LockFactory
3612 static nsIFactory nsIOServiceFactory
= { &nsIOServiceFactoryVtbl
};
3614 static BOOL
translate_url(HTMLDocumentObj
*doc
, nsWineURI
*uri
)
3616 OLECHAR
*new_url
= NULL
;
3621 if(!doc
->hostui
|| !ensure_uri(uri
))
3624 hres
= IUri_GetDisplayUri(uri
->uri
, &url
);
3628 hres
= IDocHostUIHandler_TranslateUrl(doc
->hostui
, 0, url
, &new_url
);
3629 if(hres
== S_OK
&& new_url
) {
3630 if(strcmpW(url
, new_url
)) {
3631 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url
), debugstr_w(new_url
));
3634 CoTaskMemFree(new_url
);
3641 nsresult
on_start_uri_open(NSContainer
*nscontainer
, nsIURI
*uri
, cpp_bool
*_retval
)
3643 nsWineURI
*wine_uri
;
3648 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
3649 if(NS_FAILED(nsres
)) {
3650 WARN("Could not get nsWineURI: %08x\n", nsres
);
3651 return NS_ERROR_NOT_IMPLEMENTED
;
3654 if(!wine_uri
->is_doc_uri
) {
3655 wine_uri
->is_doc_uri
= TRUE
;
3657 if(!wine_uri
->container
) {
3658 nsIWebBrowserChrome_AddRef(&nscontainer
->nsIWebBrowserChrome_iface
);
3659 wine_uri
->container
= nscontainer
;
3662 if(nscontainer
->doc
)
3663 *_retval
= translate_url(nscontainer
->doc
, wine_uri
);
3666 nsIFileURL_Release(&wine_uri
->nsIFileURL_iface
);
3670 void init_nsio(nsIComponentManager
*component_manager
, nsIComponentRegistrar
*registrar
)
3672 nsIFactory
*old_factory
= NULL
;
3675 nsres
= nsIComponentManager_GetClassObject(component_manager
, &NS_IOSERVICE_CID
,
3676 &IID_nsIFactory
, (void**)&old_factory
);
3677 if(NS_FAILED(nsres
)) {
3678 ERR("Could not get factory: %08x\n", nsres
);
3682 nsres
= nsIFactory_CreateInstance(old_factory
, NULL
, &IID_nsIIOService
, (void**)&nsio
);
3683 if(NS_FAILED(nsres
)) {
3684 ERR("Couldn not create nsIOService instance %08x\n", nsres
);
3685 nsIFactory_Release(old_factory
);
3689 nsres
= nsIIOService_QueryInterface(nsio
, &IID_nsINetUtil
, (void**)&net_util
);
3690 if(NS_FAILED(nsres
)) {
3691 WARN("Could not get nsINetUtil interface: %08x\n", nsres
);
3692 nsIIOService_Release(nsio
);
3696 nsres
= nsIComponentRegistrar_UnregisterFactory(registrar
, &NS_IOSERVICE_CID
, old_factory
);
3697 nsIFactory_Release(old_factory
);
3698 if(NS_FAILED(nsres
))
3699 ERR("UnregisterFactory failed: %08x\n", nsres
);
3701 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_IOSERVICE_CID
,
3702 NS_IOSERVICE_CLASSNAME
, NS_IOSERVICE_CONTRACTID
, &nsIOServiceFactory
);
3703 if(NS_FAILED(nsres
))
3704 ERR("RegisterFactory failed: %08x\n", nsres
);
3707 void release_nsio(void)
3710 nsINetUtil_Release(net_util
);
3715 nsIIOService_Release(nsio
);