2 * Copyright 2006-2010 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
35 #include "wine/debug.h"
37 #include "mshtml_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
42 #define NS_IOSERVICE_CLASSNAME "nsIOService"
43 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
45 static const IID NS_IOSERVICE_CID
=
46 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
47 static const IID IID_nsWineURI
=
48 {0x5088272e, 0x900b, 0x11da, {0xc6,0x87, 0x00,0x0f,0xea,0x57,0xf2,0x1a}};
50 static nsIIOService
*nsio
= NULL
;
51 static nsINetUtil
*net_util
;
53 static const WCHAR about_blankW
[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
55 static const char *request_method_strings
[] = {"GET", "PUT", "POST"};
64 NSContainer
*container
;
65 windowref_t
*window_ref
;
66 nsChannelBSC
*channel_bsc
;
68 IUriBuilder
*uri_builder
;
72 static BOOL
ensure_uri(nsWineURI
*This
)
76 assert(This
->uri
|| This
->uri_builder
);
79 hres
= IUriBuilder_CreateUriSimple(This
->uri_builder
, 0, 0, &This
->uri
);
81 WARN("CreateUriSimple failed: %08x\n", hres
);
89 static nsresult
create_nsuri(IUri
*,nsIURI
*,HTMLWindow
*,NSContainer
*,nsWineURI
**);
91 static const char *debugstr_nsacstr(const nsACString
*nsstr
)
95 nsACString_GetData(nsstr
, &data
);
96 return debugstr_a(data
);
99 HRESULT
nsuri_to_url(LPCWSTR nsuri
, BOOL ret_empty
, BSTR
*ret
)
101 const WCHAR
*ptr
= nsuri
;
103 static const WCHAR wine_prefixW
[] = {'w','i','n','e',':'};
105 if(!strncmpW(nsuri
, wine_prefixW
, sizeof(wine_prefixW
)/sizeof(WCHAR
)))
106 ptr
+= sizeof(wine_prefixW
)/sizeof(WCHAR
);
108 if(*ptr
|| ret_empty
) {
109 *ret
= SysAllocString(ptr
);
111 return E_OUTOFMEMORY
;
116 TRACE("%s -> %s\n", debugstr_w(nsuri
), debugstr_w(*ret
));
120 static BOOL
exec_shldocvw_67(HTMLDocumentObj
*doc
, BSTR url
)
122 IOleCommandTarget
*cmdtrg
= NULL
;
125 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
126 if(SUCCEEDED(hres
)) {
127 VARIANT varUrl
, varRes
;
129 V_VT(&varUrl
) = VT_BSTR
;
130 V_BSTR(&varUrl
) = url
;
131 V_VT(&varRes
) = VT_BOOL
;
133 hres
= IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 67, 0, &varUrl
, &varRes
);
135 IOleCommandTarget_Release(cmdtrg
);
137 if(SUCCEEDED(hres
) && !V_BOOL(&varRes
)) {
138 TRACE("got VARIANT_FALSE, do not load\n");
146 static nsresult
before_async_open(nsChannel
*channel
, NSContainer
*container
, BOOL
*cancel
)
148 HTMLDocumentObj
*doc
= container
->doc
;
154 NSContainer
*container_iter
= container
;
156 hlnf
= HLNF_OPENINNEWWINDOW
;
157 while(!container_iter
->doc
)
158 container_iter
= container_iter
->parent
;
159 doc
= container_iter
->doc
;
167 hres
= IUri_GetDisplayUri(channel
->uri
->uri
, &display_uri
);
169 return NS_ERROR_FAILURE
;
174 b
= !exec_shldocvw_67(doc
, display_uri
);
176 SysFreeString(display_uri
);
182 hres
= hlink_frame_navigate(&doc
->basedoc
, display_uri
, channel
, hlnf
, cancel
);
183 SysFreeString(display_uri
);
189 HRESULT
load_nsuri(HTMLWindow
*window
, nsWineURI
*uri
, nsChannelBSC
*channelbsc
, DWORD flags
)
191 nsIWebNavigation
*web_navigation
;
192 nsIDocShell
*doc_shell
;
193 HTMLDocumentNode
*doc
;
196 nsres
= get_nsinterface((nsISupports
*)window
->nswindow
, &IID_nsIWebNavigation
, (void**)&web_navigation
);
197 if(NS_FAILED(nsres
)) {
198 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
202 nsres
= nsIWebNavigation_QueryInterface(web_navigation
, &IID_nsIDocShell
, (void**)&doc_shell
);
203 nsIWebNavigation_Release(web_navigation
);
204 if(NS_FAILED(nsres
)) {
205 ERR("Could not get nsIDocShell: %08x\n", nsres
);
209 uri
->channel_bsc
= channelbsc
;
211 doc
->skip_mutation_notif
= TRUE
;
212 nsres
= nsIDocShell_LoadURI(doc_shell
, (nsIURI
*)&uri
->nsIURL_iface
, NULL
, flags
, FALSE
);
213 if(doc
== window
->doc
)
214 doc
->skip_mutation_notif
= FALSE
;
215 uri
->channel_bsc
= NULL
;
216 nsIDocShell_Release(doc_shell
);
217 if(NS_FAILED(nsres
)) {
218 WARN("LoadURI failed: %08x\n", nsres
);
225 static void set_uri_nscontainer(nsWineURI
*This
, NSContainer
*nscontainer
)
227 if(This
->container
) {
228 if(This
->container
== nscontainer
)
230 TRACE("Changing %p -> %p\n", This
->container
, nscontainer
);
231 nsIWebBrowserChrome_Release(&This
->container
->nsIWebBrowserChrome_iface
);
235 nsIWebBrowserChrome_AddRef(&nscontainer
->nsIWebBrowserChrome_iface
);
236 This
->container
= nscontainer
;
239 static void set_uri_window(nsWineURI
*This
, HTMLWindow
*window
)
241 if(This
->window_ref
) {
242 if(This
->window_ref
->window
== window
)
244 TRACE("Changing %p -> %p\n", This
->window_ref
->window
, window
);
245 windowref_release(This
->window_ref
);
249 windowref_addref(window
->window_ref
);
250 This
->window_ref
= window
->window_ref
;
253 set_uri_nscontainer(This
, window
->doc_obj
->nscontainer
);
255 This
->window_ref
= NULL
;
259 static inline BOOL
is_http_channel(nsChannel
*This
)
261 return This
->url_scheme
== URL_SCHEME_HTTP
|| This
->url_scheme
== URL_SCHEME_HTTPS
;
264 static http_header_t
*find_http_header(struct list
*headers
, const WCHAR
*name
, int len
)
268 LIST_FOR_EACH_ENTRY(iter
, headers
, http_header_t
, entry
) {
269 if(!strcmpiW(iter
->header
, name
))
276 static nsresult
get_channel_http_header(struct list
*headers
, const nsACString
*header_name_str
,
279 const char *header_namea
;
280 http_header_t
*header
;
284 nsACString_GetData(header_name_str
, &header_namea
);
285 header_name
= heap_strdupAtoW(header_namea
);
287 return NS_ERROR_UNEXPECTED
;
289 header
= find_http_header(headers
, header_name
, strlenW(header_name
));
290 heap_free(header_name
);
292 return NS_ERROR_NOT_AVAILABLE
;
294 data
= heap_strdupWtoA(header
->data
);
296 return NS_ERROR_UNEXPECTED
;
298 nsACString_SetData(_retval
, data
);
303 HRESULT
set_http_header(struct list
*headers
, const WCHAR
*name
, int name_len
,
304 const WCHAR
*value
, int value_len
)
306 http_header_t
*header
;
308 TRACE("%s: %s\n", debugstr_wn(name
, name_len
), debugstr_wn(value
, value_len
));
310 header
= find_http_header(headers
, name
, name_len
);
314 new_data
= heap_strndupW(value
, value_len
);
316 return E_OUTOFMEMORY
;
318 heap_free(header
->data
);
319 header
->data
= new_data
;
321 header
= heap_alloc(sizeof(http_header_t
));
323 return E_OUTOFMEMORY
;
325 header
->header
= heap_strndupW(name
, name_len
);
326 header
->data
= heap_strndupW(value
, value_len
);
327 if(!header
->header
|| !header
->data
) {
328 heap_free(header
->header
);
329 heap_free(header
->data
);
331 return E_OUTOFMEMORY
;
334 list_add_tail(headers
, &header
->entry
);
340 static nsresult
set_channel_http_header(struct list
*headers
, const nsACString
*name_str
,
341 const nsACString
*value_str
)
343 const char *namea
, *valuea
;
347 nsACString_GetData(name_str
, &namea
);
348 name
= heap_strdupAtoW(namea
);
350 return NS_ERROR_UNEXPECTED
;
352 nsACString_GetData(value_str
, &valuea
);
353 value
= heap_strdupAtoW(valuea
);
356 return NS_ERROR_UNEXPECTED
;
359 hres
= set_http_header(headers
, name
, strlenW(name
), value
, strlenW(value
));
363 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_UNEXPECTED
;
366 static nsresult
visit_http_headers(struct list
*headers
, nsIHttpHeaderVisitor
*visitor
)
368 nsACString header_str
, value_str
;
369 char *header
, *value
;
373 LIST_FOR_EACH_ENTRY(iter
, headers
, http_header_t
, entry
) {
374 header
= heap_strdupWtoA(iter
->header
);
376 return NS_ERROR_OUT_OF_MEMORY
;
378 value
= heap_strdupWtoA(iter
->data
);
381 return NS_ERROR_OUT_OF_MEMORY
;
384 nsACString_InitDepend(&header_str
, header
);
385 nsACString_InitDepend(&value_str
, value
);
386 nsres
= nsIHttpHeaderVisitor_VisitHeader(visitor
, &header_str
, &value_str
);
387 nsACString_Finish(&header_str
);
388 nsACString_Finish(&value_str
);
398 static void free_http_headers(struct list
*list
)
400 http_header_t
*iter
, *iter_next
;
402 LIST_FOR_EACH_ENTRY_SAFE(iter
, iter_next
, list
, http_header_t
, entry
) {
403 list_remove(&iter
->entry
);
404 heap_free(iter
->header
);
405 heap_free(iter
->data
);
410 static inline nsChannel
*impl_from_nsIHttpChannel(nsIHttpChannel
*iface
)
412 return CONTAINING_RECORD(iface
, nsChannel
, nsIHttpChannel_iface
);
415 static nsresult NSAPI
nsChannel_QueryInterface(nsIHttpChannel
*iface
, nsIIDRef riid
, void **result
)
417 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
419 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
420 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
421 *result
= &This
->nsIHttpChannel_iface
;
422 }else if(IsEqualGUID(&IID_nsIRequest
, riid
)) {
423 TRACE("(%p)->(IID_nsIRequest %p)\n", This
, result
);
424 *result
= &This
->nsIHttpChannel_iface
;
425 }else if(IsEqualGUID(&IID_nsIChannel
, riid
)) {
426 TRACE("(%p)->(IID_nsIChannel %p)\n", This
, result
);
427 *result
= &This
->nsIHttpChannel_iface
;
428 }else if(IsEqualGUID(&IID_nsIHttpChannel
, riid
)) {
429 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This
, result
);
430 *result
= is_http_channel(This
) ? &This
->nsIHttpChannel_iface
: NULL
;
431 }else if(IsEqualGUID(&IID_nsIUploadChannel
, riid
)) {
432 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This
, result
);
433 *result
= &This
->nsIUploadChannel_iface
;
434 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal
, riid
)) {
435 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This
, result
);
436 *result
= is_http_channel(This
) ? &This
->nsIHttpChannelInternal_iface
: NULL
;
438 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
443 nsIChannel_AddRef(&This
->nsIHttpChannel_iface
);
447 return NS_NOINTERFACE
;
450 static nsrefcnt NSAPI
nsChannel_AddRef(nsIHttpChannel
*iface
)
452 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
453 nsrefcnt ref
= InterlockedIncrement(&This
->ref
);
455 TRACE("(%p) ref=%d\n", This
, ref
);
460 static nsrefcnt NSAPI
nsChannel_Release(nsIHttpChannel
*iface
)
462 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
463 LONG ref
= InterlockedDecrement(&This
->ref
);
466 nsIURI_Release(&This
->uri
->nsIURL_iface
);
468 nsISupports_Release(This
->owner
);
469 if(This
->post_data_stream
)
470 nsIInputStream_Release(This
->post_data_stream
);
472 nsILoadGroup_Release(This
->load_group
);
473 if(This
->notif_callback
)
474 nsIInterfaceRequestor_Release(This
->notif_callback
);
475 if(This
->original_uri
)
476 nsIURI_Release(This
->original_uri
);
478 nsIURI_Release(This
->referrer
);
480 free_http_headers(&This
->response_headers
);
481 free_http_headers(&This
->request_headers
);
483 heap_free(This
->content_type
);
484 heap_free(This
->charset
);
491 static nsresult NSAPI
nsChannel_GetName(nsIHttpChannel
*iface
, nsACString
*aName
)
493 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
495 TRACE("(%p)->(%p)\n", This
, aName
);
497 return nsIURI_GetSpec(&This
->uri
->nsIURL_iface
, aName
);
500 static nsresult NSAPI
nsChannel_IsPending(nsIHttpChannel
*iface
, PRBool
*_retval
)
502 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
504 FIXME("(%p)->(%p)\n", This
, _retval
);
506 return NS_ERROR_NOT_IMPLEMENTED
;
509 static nsresult NSAPI
nsChannel_GetStatus(nsIHttpChannel
*iface
, nsresult
*aStatus
)
511 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
513 WARN("(%p)->(%p) returning NS_OK\n", This
, aStatus
);
515 return *aStatus
= NS_OK
;
518 static nsresult NSAPI
nsChannel_Cancel(nsIHttpChannel
*iface
, nsresult aStatus
)
520 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
522 FIXME("(%p)->(%08x)\n", This
, aStatus
);
524 return NS_ERROR_NOT_IMPLEMENTED
;
527 static nsresult NSAPI
nsChannel_Suspend(nsIHttpChannel
*iface
)
529 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
531 FIXME("(%p)\n", This
);
533 return NS_ERROR_NOT_IMPLEMENTED
;
536 static nsresult NSAPI
nsChannel_Resume(nsIHttpChannel
*iface
)
538 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
540 FIXME("(%p)\n", This
);
542 return NS_ERROR_NOT_IMPLEMENTED
;
545 static nsresult NSAPI
nsChannel_GetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
**aLoadGroup
)
547 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
549 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
552 nsILoadGroup_AddRef(This
->load_group
);
554 *aLoadGroup
= This
->load_group
;
558 static nsresult NSAPI
nsChannel_SetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
*aLoadGroup
)
560 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
562 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
565 nsILoadGroup_Release(This
->load_group
);
567 nsILoadGroup_AddRef(aLoadGroup
);
568 This
->load_group
= aLoadGroup
;
573 static nsresult NSAPI
nsChannel_GetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags
*aLoadFlags
)
575 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
577 TRACE("(%p)->(%p)\n", This
, aLoadFlags
);
579 *aLoadFlags
= This
->load_flags
;
583 static nsresult NSAPI
nsChannel_SetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags aLoadFlags
)
585 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
587 TRACE("(%p)->(%08x)\n", This
, aLoadFlags
);
589 This
->load_flags
= aLoadFlags
;
593 static nsresult NSAPI
nsChannel_GetOriginalURI(nsIHttpChannel
*iface
, nsIURI
**aOriginalURI
)
595 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
597 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
599 if(This
->original_uri
)
600 nsIURI_AddRef(This
->original_uri
);
602 *aOriginalURI
= This
->original_uri
;
606 static nsresult NSAPI
nsChannel_SetOriginalURI(nsIHttpChannel
*iface
, nsIURI
*aOriginalURI
)
608 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
610 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
612 if(This
->original_uri
)
613 nsIURI_Release(This
->original_uri
);
615 nsIURI_AddRef(aOriginalURI
);
616 This
->original_uri
= aOriginalURI
;
620 static nsresult NSAPI
nsChannel_GetURI(nsIHttpChannel
*iface
, nsIURI
**aURI
)
622 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
624 TRACE("(%p)->(%p)\n", This
, aURI
);
626 nsIURI_AddRef(&This
->uri
->nsIURL_iface
);
627 *aURI
= (nsIURI
*)This
->uri
;
632 static nsresult NSAPI
nsChannel_GetOwner(nsIHttpChannel
*iface
, nsISupports
**aOwner
)
634 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
636 TRACE("(%p)->(%p)\n", This
, aOwner
);
639 nsISupports_AddRef(This
->owner
);
640 *aOwner
= This
->owner
;
645 static nsresult NSAPI
nsChannel_SetOwner(nsIHttpChannel
*iface
, nsISupports
*aOwner
)
647 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
649 TRACE("(%p)->(%p)\n", This
, aOwner
);
652 nsISupports_AddRef(aOwner
);
654 nsISupports_Release(This
->owner
);
655 This
->owner
= aOwner
;
660 static nsresult NSAPI
nsChannel_GetNotificationCallbacks(nsIHttpChannel
*iface
,
661 nsIInterfaceRequestor
**aNotificationCallbacks
)
663 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
665 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
667 if(This
->notif_callback
)
668 nsIInterfaceRequestor_AddRef(This
->notif_callback
);
669 *aNotificationCallbacks
= This
->notif_callback
;
674 static nsresult NSAPI
nsChannel_SetNotificationCallbacks(nsIHttpChannel
*iface
,
675 nsIInterfaceRequestor
*aNotificationCallbacks
)
677 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
679 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
681 if(This
->notif_callback
)
682 nsIInterfaceRequestor_Release(This
->notif_callback
);
683 if(aNotificationCallbacks
)
684 nsIInterfaceRequestor_AddRef(aNotificationCallbacks
);
686 This
->notif_callback
= aNotificationCallbacks
;
691 static nsresult NSAPI
nsChannel_GetSecurityInfo(nsIHttpChannel
*iface
, nsISupports
**aSecurityInfo
)
693 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
695 TRACE("(%p)->(%p)\n", This
, aSecurityInfo
);
697 return NS_ERROR_NOT_IMPLEMENTED
;
700 static nsresult NSAPI
nsChannel_GetContentType(nsIHttpChannel
*iface
, nsACString
*aContentType
)
702 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
704 TRACE("(%p)->(%p)\n", This
, aContentType
);
706 if(This
->content_type
) {
707 nsACString_SetData(aContentType
, This
->content_type
);
711 WARN("unknown type\n");
712 return NS_ERROR_FAILURE
;
715 static nsresult NSAPI
nsChannel_SetContentType(nsIHttpChannel
*iface
,
716 const nsACString
*aContentType
)
718 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
719 const char *content_type
;
721 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentType
));
723 nsACString_GetData(aContentType
, &content_type
);
724 heap_free(This
->content_type
);
725 This
->content_type
= heap_strdupA(content_type
);
730 static nsresult NSAPI
nsChannel_GetContentCharset(nsIHttpChannel
*iface
,
731 nsACString
*aContentCharset
)
733 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
735 TRACE("(%p)->(%p)\n", This
, aContentCharset
);
738 nsACString_SetData(aContentCharset
, This
->charset
);
742 nsACString_SetData(aContentCharset
, "");
746 static nsresult NSAPI
nsChannel_SetContentCharset(nsIHttpChannel
*iface
,
747 const nsACString
*aContentCharset
)
749 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
751 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentCharset
));
753 return NS_ERROR_NOT_IMPLEMENTED
;
756 static nsresult NSAPI
nsChannel_GetContentLength(nsIHttpChannel
*iface
, PRInt32
*aContentLength
)
758 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
760 FIXME("(%p)->(%p)\n", This
, aContentLength
);
762 return NS_ERROR_NOT_IMPLEMENTED
;
765 static nsresult NSAPI
nsChannel_SetContentLength(nsIHttpChannel
*iface
, PRInt32 aContentLength
)
767 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
769 FIXME("(%p)->(%d)\n", This
, aContentLength
);
771 return NS_ERROR_NOT_IMPLEMENTED
;
774 static nsresult NSAPI
nsChannel_Open(nsIHttpChannel
*iface
, nsIInputStream
**_retval
)
776 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
778 FIXME("(%p)->(%p)\n", This
, _retval
);
780 return NS_ERROR_NOT_IMPLEMENTED
;
783 static HTMLWindow
*get_window_from_load_group(nsChannel
*This
)
792 nsres
= nsILoadGroup_GetDefaultLoadRequest(This
->load_group
, &req
);
793 if(NS_FAILED(nsres
)) {
794 ERR("GetDefaultLoadRequest failed: %08x\n", nsres
);
801 nsres
= nsIRequest_QueryInterface(req
, &IID_nsIChannel
, (void**)&channel
);
802 nsIRequest_Release(req
);
803 if(NS_FAILED(nsres
)) {
804 WARN("Could not get nsIChannel interface: %08x\n", nsres
);
808 nsres
= nsIChannel_GetURI(channel
, &uri
);
809 nsIChannel_Release(channel
);
810 if(NS_FAILED(nsres
)) {
811 ERR("GetURI failed: %08x\n", nsres
);
815 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
817 if(NS_FAILED(nsres
)) {
818 TRACE("Could not get nsWineURI: %08x\n", nsres
);
822 window
= wine_uri
->window_ref
? wine_uri
->window_ref
->window
: NULL
;
824 IHTMLWindow2_AddRef(&window
->IHTMLWindow2_iface
);
825 nsIURI_Release(&wine_uri
->nsIURL_iface
);
830 static HTMLWindow
*get_channel_window(nsChannel
*This
)
832 nsIWebProgress
*web_progress
;
833 nsIDOMWindow
*nswindow
;
837 if(This
->load_group
) {
838 nsIRequestObserver
*req_observer
;
840 nsres
= nsILoadGroup_GetGroupObserver(This
->load_group
, &req_observer
);
841 if(NS_FAILED(nsres
) || !req_observer
) {
842 ERR("GetGroupObserver failed: %08x\n", nsres
);
846 nsres
= nsIRequestObserver_QueryInterface(req_observer
, &IID_nsIWebProgress
, (void**)&web_progress
);
847 nsIRequestObserver_Release(req_observer
);
848 if(NS_FAILED(nsres
)) {
849 ERR("Could not get nsIWebProgress iface: %08x\n", nsres
);
852 }else if(This
->notif_callback
) {
853 nsres
= nsIInterfaceRequestor_GetInterface(This
->notif_callback
, &IID_nsIWebProgress
, (void**)&web_progress
);
854 if(NS_FAILED(nsres
)) {
855 ERR("GetInterface(IID_nsIWebProgress failed: %08x\n", nsres
);
859 ERR("no load group nor notif callback\n");
863 nsres
= nsIWebProgress_GetDOMWindow(web_progress
, &nswindow
);
864 nsIWebProgress_Release(web_progress
);
865 if(NS_FAILED(nsres
) || !nswindow
) {
866 ERR("GetDOMWindow failed: %08x\n", nsres
);
870 window
= nswindow_to_window(nswindow
);
871 nsIDOMWindow_Release(nswindow
);
874 IHTMLWindow2_AddRef(&window
->IHTMLWindow2_iface
);
876 FIXME("NULL window for %p\n", nswindow
);
882 HTMLDocumentNode
*doc
;
883 nsChannelBSC
*bscallback
;
884 } start_binding_task_t
;
886 static void start_binding_proc(task_t
*_task
)
888 start_binding_task_t
*task
= (start_binding_task_t
*)_task
;
890 start_binding(NULL
, task
->doc
, (BSCallback
*)task
->bscallback
, NULL
);
893 static void start_binding_task_destr(task_t
*_task
)
895 start_binding_task_t
*task
= (start_binding_task_t
*)_task
;
897 IBindStatusCallback_Release(&task
->bscallback
->bsc
.IBindStatusCallback_iface
);
901 static nsresult
async_open(nsChannel
*This
, HTMLWindow
*window
, BOOL is_doc_channel
, nsIStreamListener
*listener
,
902 nsISupports
*context
)
904 nsChannelBSC
*bscallback
;
905 IMoniker
*mon
= NULL
;
908 hres
= CreateURLMonikerEx2(NULL
, This
->uri
->uri
, &mon
, 0);
910 WARN("CreateURLMoniker failed: %08x\n", hres
);
911 return NS_ERROR_UNEXPECTED
;
915 set_current_mon(window
, mon
);
917 hres
= create_channelbsc(mon
, NULL
, NULL
, 0, &bscallback
);
918 IMoniker_Release(mon
);
920 return NS_ERROR_UNEXPECTED
;
922 channelbsc_set_channel(bscallback
, This
, listener
, context
);
925 set_window_bscallback(window
, bscallback
);
926 async_start_doc_binding(window
, bscallback
);
927 IUnknown_Release((IUnknown
*)bscallback
);
929 start_binding_task_t
*task
= heap_alloc(sizeof(start_binding_task_t
));
931 task
->doc
= window
->doc
;
932 task
->bscallback
= bscallback
;
933 push_task(&task
->header
, start_binding_proc
, start_binding_task_destr
, window
->doc
->basedoc
.task_magic
);
939 static nsresult NSAPI
nsChannel_AsyncOpen(nsIHttpChannel
*iface
, nsIStreamListener
*aListener
,
940 nsISupports
*aContext
)
942 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
943 HTMLWindow
*window
= NULL
;
945 nsresult nsres
= NS_OK
;
947 TRACE("(%p)->(%p %p)\n", This
, aListener
, aContext
);
949 if(!ensure_uri(This
->uri
))
950 return NS_ERROR_FAILURE
;
952 if(This
->uri
->is_doc_uri
) {
953 window
= get_channel_window(This
);
955 set_uri_window(This
->uri
, window
);
956 }else if(This
->uri
->container
) {
959 /* nscontainer->doc should be NULL which means navigation to a new window */
960 if(This
->uri
->container
->doc
)
961 FIXME("nscontainer->doc = %p\n", This
->uri
->container
->doc
);
963 nsres
= before_async_open(This
, This
->uri
->container
, &b
);
967 FIXME("Navigation not cancelled\n");
968 return NS_ERROR_UNEXPECTED
;
973 if(This
->uri
->window_ref
&& This
->uri
->window_ref
->window
) {
974 window
= This
->uri
->window_ref
->window
;
975 IHTMLWindow2_AddRef(&window
->IHTMLWindow2_iface
);
977 /* FIXME: Analyze removing get_window_from_load_group call */
979 window
= get_window_from_load_group(This
);
981 window
= get_channel_window(This
);
983 set_uri_window(This
->uri
, window
);
988 ERR("window = NULL\n");
989 return NS_ERROR_UNEXPECTED
;
992 if(This
->uri
->is_doc_uri
&& window
== window
->doc_obj
->basedoc
.window
) {
993 if(This
->uri
->channel_bsc
) {
994 channelbsc_set_channel(This
->uri
->channel_bsc
, This
, aListener
, aContext
);
996 if(window
->doc_obj
->mime
) {
997 heap_free(This
->content_type
);
998 This
->content_type
= heap_strdupWtoA(window
->doc_obj
->mime
);
1003 nsres
= before_async_open(This
, window
->doc_obj
->nscontainer
, &cancel
);
1004 if(NS_SUCCEEDED(nsres
) && cancel
) {
1005 TRACE("canceled\n");
1006 nsres
= NS_BINDING_ABORTED
;
1012 nsres
= async_open(This
, window
, This
->uri
->is_doc_uri
, aListener
, aContext
);
1014 if(NS_SUCCEEDED(nsres
) && This
->load_group
) {
1015 nsres
= nsILoadGroup_AddRequest(This
->load_group
, (nsIRequest
*)&This
->nsIHttpChannel_iface
,
1017 if(NS_FAILED(nsres
))
1018 ERR("AddRequest failed: %08x\n", nsres
);
1021 IHTMLWindow2_Release(&window
->IHTMLWindow2_iface
);
1025 static nsresult NSAPI
nsChannel_GetRequestMethod(nsIHttpChannel
*iface
, nsACString
*aRequestMethod
)
1027 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1029 TRACE("(%p)->(%p)\n", This
, aRequestMethod
);
1031 nsACString_SetData(aRequestMethod
, request_method_strings
[This
->request_method
]);
1035 static nsresult NSAPI
nsChannel_SetRequestMethod(nsIHttpChannel
*iface
,
1036 const nsACString
*aRequestMethod
)
1038 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1042 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRequestMethod
));
1044 nsACString_GetData(aRequestMethod
, &method
);
1045 for(i
=0; i
< sizeof(request_method_strings
)/sizeof(*request_method_strings
); i
++) {
1046 if(!strcasecmp(method
, request_method_strings
[i
])) {
1047 This
->request_method
= i
;
1052 ERR("Invalid method %s\n", debugstr_a(method
));
1053 return NS_ERROR_UNEXPECTED
;
1056 static nsresult NSAPI
nsChannel_GetReferrer(nsIHttpChannel
*iface
, nsIURI
**aReferrer
)
1058 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1060 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1063 nsIURI_AddRef(This
->referrer
);
1064 *aReferrer
= This
->referrer
;
1068 static nsresult NSAPI
nsChannel_SetReferrer(nsIHttpChannel
*iface
, nsIURI
*aReferrer
)
1070 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1072 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1075 nsIURI_AddRef(aReferrer
);
1077 nsIURI_Release(This
->referrer
);
1078 This
->referrer
= aReferrer
;
1082 static nsresult NSAPI
nsChannel_GetRequestHeader(nsIHttpChannel
*iface
,
1083 const nsACString
*aHeader
, nsACString
*_retval
)
1085 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1087 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aHeader
), _retval
);
1089 return get_channel_http_header(&This
->request_headers
, aHeader
, _retval
);
1092 static nsresult NSAPI
nsChannel_SetRequestHeader(nsIHttpChannel
*iface
,
1093 const nsACString
*aHeader
, const nsACString
*aValue
, PRBool aMerge
)
1095 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1097 TRACE("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(aHeader
), debugstr_nsacstr(aValue
), aMerge
);
1100 FIXME("aMerge not supported\n");
1102 return set_channel_http_header(&This
->request_headers
, aHeader
, aValue
);
1105 static nsresult NSAPI
nsChannel_VisitRequestHeaders(nsIHttpChannel
*iface
,
1106 nsIHttpHeaderVisitor
*aVisitor
)
1108 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1110 FIXME("(%p)->(%p)\n", This
, aVisitor
);
1112 return NS_ERROR_NOT_IMPLEMENTED
;
1115 static nsresult NSAPI
nsChannel_GetAllowPipelining(nsIHttpChannel
*iface
, PRBool
*aAllowPipelining
)
1117 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1119 FIXME("(%p)->(%p)\n", This
, aAllowPipelining
);
1121 return NS_ERROR_NOT_IMPLEMENTED
;
1124 static nsresult NSAPI
nsChannel_SetAllowPipelining(nsIHttpChannel
*iface
, PRBool aAllowPipelining
)
1126 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1128 FIXME("(%p)->(%x)\n", This
, aAllowPipelining
);
1130 return NS_ERROR_NOT_IMPLEMENTED
;
1133 static nsresult NSAPI
nsChannel_GetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32
*aRedirectionLimit
)
1135 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1137 FIXME("(%p)->(%p)\n", This
, aRedirectionLimit
);
1139 return NS_ERROR_NOT_IMPLEMENTED
;
1142 static nsresult NSAPI
nsChannel_SetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32 aRedirectionLimit
)
1144 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1146 FIXME("(%p)->(%u)\n", This
, aRedirectionLimit
);
1148 return NS_ERROR_NOT_IMPLEMENTED
;
1151 static nsresult NSAPI
nsChannel_GetResponseStatus(nsIHttpChannel
*iface
, PRUint32
*aResponseStatus
)
1153 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1155 TRACE("(%p)->(%p)\n", This
, aResponseStatus
);
1157 if(This
->response_status
) {
1158 *aResponseStatus
= This
->response_status
;
1162 WARN("No response status\n");
1163 return NS_ERROR_UNEXPECTED
;
1166 static nsresult NSAPI
nsChannel_GetResponseStatusText(nsIHttpChannel
*iface
,
1167 nsACString
*aResponseStatusText
)
1169 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1171 FIXME("(%p)->(%p)\n", This
, aResponseStatusText
);
1173 return NS_ERROR_NOT_IMPLEMENTED
;
1176 static nsresult NSAPI
nsChannel_GetRequestSucceeded(nsIHttpChannel
*iface
,
1177 PRBool
*aRequestSucceeded
)
1179 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1181 TRACE("(%p)->(%p)\n", This
, aRequestSucceeded
);
1183 if(!This
->response_status
)
1184 return NS_ERROR_NOT_AVAILABLE
;
1186 *aRequestSucceeded
= This
->response_status
/100 == 2;
1191 static nsresult NSAPI
nsChannel_GetResponseHeader(nsIHttpChannel
*iface
,
1192 const nsACString
*header
, nsACString
*_retval
)
1194 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1196 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(header
), _retval
);
1198 return get_channel_http_header(&This
->response_headers
, header
, _retval
);
1201 static nsresult NSAPI
nsChannel_SetResponseHeader(nsIHttpChannel
*iface
,
1202 const nsACString
*header
, const nsACString
*value
, PRBool merge
)
1204 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1206 FIXME("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(header
), debugstr_nsacstr(value
), merge
);
1208 return NS_ERROR_NOT_IMPLEMENTED
;
1211 static nsresult NSAPI
nsChannel_VisitResponseHeaders(nsIHttpChannel
*iface
,
1212 nsIHttpHeaderVisitor
*aVisitor
)
1214 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1216 TRACE("(%p)->(%p)\n", This
, aVisitor
);
1218 return visit_http_headers(&This
->response_headers
, aVisitor
);
1221 static nsresult NSAPI
nsChannel_IsNoStoreResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1223 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1224 http_header_t
*header
;
1226 static const WCHAR cache_controlW
[] = {'C','a','c','h','e','-','C','o','n','t','r','o','l'};
1227 static const WCHAR no_storeW
[] = {'n','o','-','s','t','o','r','e',0};
1229 TRACE("(%p)->(%p)\n", This
, _retval
);
1231 header
= find_http_header(&This
->response_headers
, cache_controlW
, sizeof(cache_controlW
)/sizeof(WCHAR
));
1232 *_retval
= header
&& !strcmpiW(header
->data
, no_storeW
);
1236 static nsresult NSAPI
nsChannel_IsNoCacheResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1238 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1240 FIXME("(%p)->(%p)\n", This
, _retval
);
1242 return NS_ERROR_NOT_IMPLEMENTED
;
1245 static const nsIHttpChannelVtbl nsChannelVtbl
= {
1246 nsChannel_QueryInterface
,
1250 nsChannel_IsPending
,
1251 nsChannel_GetStatus
,
1255 nsChannel_GetLoadGroup
,
1256 nsChannel_SetLoadGroup
,
1257 nsChannel_GetLoadFlags
,
1258 nsChannel_SetLoadFlags
,
1259 nsChannel_GetOriginalURI
,
1260 nsChannel_SetOriginalURI
,
1264 nsChannel_GetNotificationCallbacks
,
1265 nsChannel_SetNotificationCallbacks
,
1266 nsChannel_GetSecurityInfo
,
1267 nsChannel_GetContentType
,
1268 nsChannel_SetContentType
,
1269 nsChannel_GetContentCharset
,
1270 nsChannel_SetContentCharset
,
1271 nsChannel_GetContentLength
,
1272 nsChannel_SetContentLength
,
1274 nsChannel_AsyncOpen
,
1275 nsChannel_GetRequestMethod
,
1276 nsChannel_SetRequestMethod
,
1277 nsChannel_GetReferrer
,
1278 nsChannel_SetReferrer
,
1279 nsChannel_GetRequestHeader
,
1280 nsChannel_SetRequestHeader
,
1281 nsChannel_VisitRequestHeaders
,
1282 nsChannel_GetAllowPipelining
,
1283 nsChannel_SetAllowPipelining
,
1284 nsChannel_GetRedirectionLimit
,
1285 nsChannel_SetRedirectionLimit
,
1286 nsChannel_GetResponseStatus
,
1287 nsChannel_GetResponseStatusText
,
1288 nsChannel_GetRequestSucceeded
,
1289 nsChannel_GetResponseHeader
,
1290 nsChannel_SetResponseHeader
,
1291 nsChannel_VisitResponseHeaders
,
1292 nsChannel_IsNoStoreResponse
,
1293 nsChannel_IsNoCacheResponse
1296 static inline nsChannel
*impl_from_nsIUploadChannel(nsIUploadChannel
*iface
)
1298 return CONTAINING_RECORD(iface
, nsChannel
, nsIUploadChannel_iface
);
1301 static nsresult NSAPI
nsUploadChannel_QueryInterface(nsIUploadChannel
*iface
, nsIIDRef riid
,
1304 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1305 return nsIChannel_QueryInterface(&This
->nsIHttpChannel_iface
, riid
, result
);
1308 static nsrefcnt NSAPI
nsUploadChannel_AddRef(nsIUploadChannel
*iface
)
1310 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1311 return nsIChannel_AddRef(&This
->nsIHttpChannel_iface
);
1314 static nsrefcnt NSAPI
nsUploadChannel_Release(nsIUploadChannel
*iface
)
1316 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1317 return nsIChannel_Release(&This
->nsIHttpChannel_iface
);
1320 static nsresult NSAPI
nsUploadChannel_SetUploadStream(nsIUploadChannel
*iface
,
1321 nsIInputStream
*aStream
, const nsACString
*aContentType
, PRInt32 aContentLength
)
1323 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1324 const char *content_type
;
1326 static const WCHAR content_typeW
[] =
1327 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1329 TRACE("(%p)->(%p %s %d)\n", This
, aStream
, debugstr_nsacstr(aContentType
), aContentLength
);
1331 This
->post_data_contains_headers
= TRUE
;
1334 nsACString_GetData(aContentType
, &content_type
);
1338 ct
= heap_strdupAtoW(content_type
);
1340 return NS_ERROR_UNEXPECTED
;
1342 set_http_header(&This
->request_headers
, content_typeW
,
1343 sizeof(content_typeW
)/sizeof(WCHAR
), ct
, strlenW(ct
));
1345 This
->post_data_contains_headers
= FALSE
;
1349 if(This
->post_data_stream
)
1350 nsIInputStream_Release(This
->post_data_stream
);
1352 if(aContentLength
!= -1)
1353 FIXME("Unsupported acontentLength = %d\n", aContentLength
);
1355 if(This
->post_data_stream
)
1356 nsIInputStream_Release(This
->post_data_stream
);
1357 This
->post_data_stream
= aStream
;
1359 nsIInputStream_AddRef(aStream
);
1361 This
->request_method
= METHOD_POST
;
1365 static nsresult NSAPI
nsUploadChannel_GetUploadStream(nsIUploadChannel
*iface
,
1366 nsIInputStream
**aUploadStream
)
1368 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1370 TRACE("(%p)->(%p)\n", This
, aUploadStream
);
1372 if(This
->post_data_stream
)
1373 nsIInputStream_AddRef(This
->post_data_stream
);
1375 *aUploadStream
= This
->post_data_stream
;
1379 static const nsIUploadChannelVtbl nsUploadChannelVtbl
= {
1380 nsUploadChannel_QueryInterface
,
1381 nsUploadChannel_AddRef
,
1382 nsUploadChannel_Release
,
1383 nsUploadChannel_SetUploadStream
,
1384 nsUploadChannel_GetUploadStream
1387 static inline nsChannel
*impl_from_nsIHttpChannelInternal(nsIHttpChannelInternal
*iface
)
1389 return CONTAINING_RECORD(iface
, nsChannel
, nsIHttpChannelInternal_iface
);
1392 static nsresult NSAPI
nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal
*iface
, nsIIDRef riid
,
1395 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1396 return nsIChannel_QueryInterface(&This
->nsIHttpChannel_iface
, riid
, result
);
1399 static nsrefcnt NSAPI
nsHttpChannelInternal_AddRef(nsIHttpChannelInternal
*iface
)
1401 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1402 return nsIChannel_AddRef(&This
->nsIHttpChannel_iface
);
1405 static nsrefcnt NSAPI
nsHttpChannelInternal_Release(nsIHttpChannelInternal
*iface
)
1407 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1408 return nsIChannel_Release(&This
->nsIHttpChannel_iface
);
1411 static nsresult NSAPI
nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
**aDocumentURI
)
1413 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1415 FIXME("(%p)->()\n", This
);
1417 return NS_ERROR_NOT_IMPLEMENTED
;
1420 static nsresult NSAPI
nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
*aDocumentURI
)
1422 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1424 FIXME("(%p)->()\n", This
);
1426 return NS_ERROR_NOT_IMPLEMENTED
;
1429 static nsresult NSAPI
nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal
*iface
, PRUint32
*major
, PRUint32
*minor
)
1431 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1433 FIXME("(%p)->()\n", This
);
1435 return NS_ERROR_NOT_IMPLEMENTED
;
1438 static nsresult NSAPI
nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal
*iface
, PRUint32
*major
, PRUint32
*minor
)
1440 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1442 FIXME("(%p)->()\n", This
);
1444 return NS_ERROR_NOT_IMPLEMENTED
;
1447 static nsresult NSAPI
nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal
*iface
, const char *aCookieHeader
)
1449 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1451 FIXME("(%p)->()\n", This
);
1453 return NS_ERROR_NOT_IMPLEMENTED
;
1456 static nsresult NSAPI
nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal
*iface
, const char *aFallbackKey
)
1458 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1460 FIXME("(%p)->()\n", This
);
1462 return NS_ERROR_NOT_IMPLEMENTED
;
1465 static nsresult NSAPI
nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, PRBool
*aForceThirdPartyCookie
)
1467 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1469 FIXME("(%p)->()\n", This
);
1471 return NS_ERROR_NOT_IMPLEMENTED
;
1474 static nsresult NSAPI
nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, PRBool aForceThirdPartyCookie
)
1476 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1478 FIXME("(%p)->()\n", This
);
1480 return NS_ERROR_NOT_IMPLEMENTED
;
1483 static nsresult NSAPI
nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal
*iface
, PRBool
*aCanceled
)
1485 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1487 FIXME("(%p)->(%p)\n", This
, aCanceled
);
1489 return NS_ERROR_NOT_IMPLEMENTED
;
1492 static nsresult NSAPI
nsHttpChannelInternal_GetChannelIsForDownload(nsIHttpChannelInternal
*iface
, PRBool
*aCanceled
)
1494 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1496 FIXME("(%p)->(%p)\n", This
, aCanceled
);
1498 return NS_ERROR_NOT_IMPLEMENTED
;
1501 static nsresult NSAPI
nsHttpChannelInternal_SetChannelIsForDownload(nsIHttpChannelInternal
*iface
, PRBool aCanceled
)
1503 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1505 FIXME("(%p)->(%x)\n", This
, aCanceled
);
1507 return NS_ERROR_NOT_IMPLEMENTED
;
1510 static nsresult NSAPI
nsHttpChannelInternal_GetLocalAddress(nsIHttpChannelInternal
*iface
, nsACString
*aLocalAddress
)
1512 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1514 FIXME("(%p)->(%p)\n", This
, aLocalAddress
);
1516 return NS_ERROR_NOT_IMPLEMENTED
;
1519 static nsresult NSAPI
nsHttpChannelInternal_GetLocalPort(nsIHttpChannelInternal
*iface
, PRInt32
*aLocalPort
)
1521 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1523 FIXME("(%p)->(%p)\n", This
, aLocalPort
);
1525 return NS_ERROR_NOT_IMPLEMENTED
;
1528 static nsresult NSAPI
nsHttpChannelInternal_GetRemoteAddress(nsIHttpChannelInternal
*iface
, nsACString
*aRemoteAddress
)
1530 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1532 FIXME("(%p)->(%p)\n", This
, aRemoteAddress
);
1534 return NS_ERROR_NOT_IMPLEMENTED
;
1537 static nsresult NSAPI
nsHttpChannelInternal_GetRemotePort(nsIHttpChannelInternal
*iface
, PRInt32
*aRemotePort
)
1539 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1541 FIXME("(%p)->(%p)\n", This
, aRemotePort
);
1543 return NS_ERROR_NOT_IMPLEMENTED
;
1546 static nsresult NSAPI
nsHttpChannelInternal_SetCacheKeysRedirectChain(nsIHttpChannelInternal
*iface
, void *cacheKeys
)
1548 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1550 FIXME("(%p)->(%p)\n", This
, cacheKeys
);
1552 return NS_ERROR_NOT_IMPLEMENTED
;
1555 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl
= {
1556 nsHttpChannelInternal_QueryInterface
,
1557 nsHttpChannelInternal_AddRef
,
1558 nsHttpChannelInternal_Release
,
1559 nsHttpChannelInternal_GetDocumentURI
,
1560 nsHttpChannelInternal_SetDocumentURI
,
1561 nsHttpChannelInternal_GetRequestVersion
,
1562 nsHttpChannelInternal_GetResponseVersion
,
1563 nsHttpChannelInternal_SetCookie
,
1564 nsHttpChannelInternal_SetupFallbackChannel
,
1565 nsHttpChannelInternal_GetForceAllowThirdPartyCookie
,
1566 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
,
1567 nsHttpChannelInternal_GetCanceled
,
1568 nsHttpChannelInternal_GetChannelIsForDownload
,
1569 nsHttpChannelInternal_SetChannelIsForDownload
,
1570 nsHttpChannelInternal_GetLocalAddress
,
1571 nsHttpChannelInternal_GetLocalPort
,
1572 nsHttpChannelInternal_GetRemoteAddress
,
1573 nsHttpChannelInternal_GetRemotePort
,
1574 nsHttpChannelInternal_SetCacheKeysRedirectChain
1578 static void invalidate_uri(nsWineURI
*This
)
1581 IUri_Release(This
->uri
);
1586 static BOOL
ensure_uri_builder(nsWineURI
*This
)
1588 if(!This
->uri_builder
) {
1591 if(!ensure_uri(This
))
1594 hres
= CreateIUriBuilder(This
->uri
, 0, 0, &This
->uri_builder
);
1596 WARN("CreateIUriBuilder failed: %08x\n", hres
);
1601 invalidate_uri(This
);
1605 static nsresult
get_uri_string(nsWineURI
*This
, Uri_PROPERTY prop
, nsACString
*ret
)
1611 if(!ensure_uri(This
))
1612 return NS_ERROR_UNEXPECTED
;
1614 hres
= IUri_GetPropertyBSTR(This
->uri
, prop
, &val
, 0);
1616 WARN("GetPropertyBSTR failed: %08x\n", hres
);
1617 return NS_ERROR_UNEXPECTED
;
1620 vala
= heap_strdupWtoA(val
);
1623 return NS_ERROR_OUT_OF_MEMORY
;
1625 TRACE("ret %s\n", debugstr_a(vala
));
1626 nsACString_SetData(ret
, vala
);
1631 static inline nsWineURI
*impl_from_nsIURL(nsIURL
*iface
)
1633 return CONTAINING_RECORD(iface
, nsWineURI
, nsIURL_iface
);
1636 static nsresult NSAPI
nsURI_QueryInterface(nsIURL
*iface
, nsIIDRef riid
, void **result
)
1638 nsWineURI
*This
= impl_from_nsIURL(iface
);
1642 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1643 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1644 *result
= &This
->nsIURL_iface
;
1645 }else if(IsEqualGUID(&IID_nsIURI
, riid
)) {
1646 TRACE("(%p)->(IID_nsIURI %p)\n", This
, result
);
1647 *result
= &This
->nsIURL_iface
;
1648 }else if(IsEqualGUID(&IID_nsIURL
, riid
)) {
1649 TRACE("(%p)->(IID_nsIURL %p)\n", This
, result
);
1650 *result
= &This
->nsIURL_iface
;
1651 }else if(IsEqualGUID(&IID_nsWineURI
, riid
)) {
1652 TRACE("(%p)->(IID_nsWineURI %p)\n", This
, result
);
1657 nsIURI_AddRef(&This
->nsIURL_iface
);
1661 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1662 return This
->nsuri
? nsIURI_QueryInterface(This
->nsuri
, riid
, result
) : NS_NOINTERFACE
;
1665 static nsrefcnt NSAPI
nsURI_AddRef(nsIURL
*iface
)
1667 nsWineURI
*This
= impl_from_nsIURL(iface
);
1668 LONG ref
= InterlockedIncrement(&This
->ref
);
1670 TRACE("(%p) ref=%d\n", This
, ref
);
1675 static nsrefcnt NSAPI
nsURI_Release(nsIURL
*iface
)
1677 nsWineURI
*This
= impl_from_nsIURL(iface
);
1678 LONG ref
= InterlockedDecrement(&This
->ref
);
1680 TRACE("(%p) ref=%d\n", This
, ref
);
1683 if(This
->window_ref
)
1684 windowref_release(This
->window_ref
);
1686 nsIWebBrowserChrome_Release(&This
->container
->nsIWebBrowserChrome_iface
);
1688 nsIURL_Release(This
->nsurl
);
1690 nsIURI_Release(This
->nsuri
);
1692 IUri_Release(This
->uri
);
1699 static nsresult NSAPI
nsURI_GetSpec(nsIURL
*iface
, nsACString
*aSpec
)
1701 nsWineURI
*This
= impl_from_nsIURL(iface
);
1703 TRACE("(%p)->(%p)\n", This
, aSpec
);
1705 return get_uri_string(This
, Uri_PROPERTY_DISPLAY_URI
, aSpec
);
1708 static nsresult NSAPI
nsURI_SetSpec(nsIURL
*iface
, const nsACString
*aSpec
)
1710 nsWineURI
*This
= impl_from_nsIURL(iface
);
1716 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aSpec
));
1718 nsACString_GetData(aSpec
, &speca
);
1719 spec
= heap_strdupAtoW(speca
);
1721 return NS_ERROR_OUT_OF_MEMORY
;
1723 hres
= CreateUri(spec
, 0, 0, &uri
);
1726 WARN("CreateUri failed: %08x\n", hres
);
1727 return NS_ERROR_FAILURE
;
1730 invalidate_uri(This
);
1731 if(This
->uri_builder
) {
1732 IUriBuilder_Release(This
->uri_builder
);
1733 This
->uri_builder
= NULL
;
1740 static nsresult NSAPI
nsURI_GetPrePath(nsIURL
*iface
, nsACString
*aPrePath
)
1742 nsWineURI
*This
= impl_from_nsIURL(iface
);
1744 TRACE("(%p)->(%p)\n", This
, aPrePath
);
1747 return nsIURI_GetPrePath(This
->nsuri
, aPrePath
);
1749 FIXME("default action not implemented\n");
1750 return NS_ERROR_NOT_IMPLEMENTED
;
1753 static nsresult NSAPI
nsURI_GetScheme(nsIURL
*iface
, nsACString
*aScheme
)
1755 nsWineURI
*This
= impl_from_nsIURL(iface
);
1759 TRACE("(%p)->(%p)\n", This
, aScheme
);
1761 if(!ensure_uri(This
))
1762 return NS_ERROR_UNEXPECTED
;
1764 hres
= IUri_GetScheme(This
->uri
, &scheme
);
1766 WARN("GetScheme failed: %08x\n", hres
);
1767 return NS_ERROR_UNEXPECTED
;
1770 if(scheme
== URL_SCHEME_ABOUT
) {
1771 nsACString_SetData(aScheme
, "wine");
1775 return get_uri_string(This
, Uri_PROPERTY_SCHEME_NAME
, aScheme
);
1778 static nsresult NSAPI
nsURI_SetScheme(nsIURL
*iface
, const nsACString
*aScheme
)
1780 nsWineURI
*This
= impl_from_nsIURL(iface
);
1781 const char *schemea
;
1785 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aScheme
));
1787 if(!ensure_uri_builder(This
))
1788 return NS_ERROR_UNEXPECTED
;
1790 nsACString_GetData(aScheme
, &schemea
);
1791 scheme
= heap_strdupAtoW(schemea
);
1793 return NS_ERROR_OUT_OF_MEMORY
;
1795 hres
= IUriBuilder_SetSchemeName(This
->uri_builder
, scheme
);
1798 return NS_ERROR_UNEXPECTED
;
1803 static nsresult NSAPI
nsURI_GetUserPass(nsIURL
*iface
, nsACString
*aUserPass
)
1805 nsWineURI
*This
= impl_from_nsIURL(iface
);
1809 TRACE("(%p)->(%p)\n", This
, aUserPass
);
1811 if(!ensure_uri(This
))
1812 return NS_ERROR_UNEXPECTED
;
1814 hres
= IUri_GetUserName(This
->uri
, &user
);
1816 return NS_ERROR_FAILURE
;
1818 hres
= IUri_GetPassword(This
->uri
, &pass
);
1820 SysFreeString(user
);
1821 return NS_ERROR_FAILURE
;
1824 if(*user
|| *pass
) {
1825 FIXME("Construct user:pass string\n");
1827 nsACString_SetData(aUserPass
, "");
1830 SysFreeString(user
);
1831 SysFreeString(pass
);
1835 static nsresult NSAPI
nsURI_SetUserPass(nsIURL
*iface
, const nsACString
*aUserPass
)
1837 nsWineURI
*This
= impl_from_nsIURL(iface
);
1838 WCHAR
*user
= NULL
, *pass
= NULL
, *buf
= NULL
;
1839 const char *user_pass
;
1842 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUserPass
));
1844 if(!ensure_uri_builder(This
))
1845 return NS_ERROR_UNEXPECTED
;
1847 nsACString_GetData(aUserPass
, &user_pass
);
1851 buf
= heap_strdupAtoW(user_pass
);
1853 return NS_ERROR_OUT_OF_MEMORY
;
1855 ptr
= strchrW(buf
, ':');
1858 }else if(ptr
!= buf
) {
1868 hres
= IUriBuilder_SetUserName(This
->uri_builder
, user
);
1870 hres
= IUriBuilder_SetPassword(This
->uri_builder
, pass
);
1873 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_FAILURE
;
1876 static nsresult NSAPI
nsURI_GetUsername(nsIURL
*iface
, nsACString
*aUsername
)
1878 nsWineURI
*This
= impl_from_nsIURL(iface
);
1880 TRACE("(%p)->(%p)\n", This
, aUsername
);
1882 return get_uri_string(This
, Uri_PROPERTY_USER_NAME
, aUsername
);
1885 static nsresult NSAPI
nsURI_SetUsername(nsIURL
*iface
, const nsACString
*aUsername
)
1887 nsWineURI
*This
= impl_from_nsIURL(iface
);
1892 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUsername
));
1894 if(!ensure_uri_builder(This
))
1895 return NS_ERROR_UNEXPECTED
;
1897 nsACString_GetData(aUsername
, &usera
);
1898 user
= heap_strdupAtoW(usera
);
1900 return NS_ERROR_OUT_OF_MEMORY
;
1902 hres
= IUriBuilder_SetUserName(This
->uri_builder
, user
);
1905 return NS_ERROR_UNEXPECTED
;
1910 static nsresult NSAPI
nsURI_GetPassword(nsIURL
*iface
, nsACString
*aPassword
)
1912 nsWineURI
*This
= impl_from_nsIURL(iface
);
1914 TRACE("(%p)->(%p)\n", This
, aPassword
);
1916 return get_uri_string(This
, Uri_PROPERTY_PASSWORD
, aPassword
);
1919 static nsresult NSAPI
nsURI_SetPassword(nsIURL
*iface
, const nsACString
*aPassword
)
1921 nsWineURI
*This
= impl_from_nsIURL(iface
);
1926 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPassword
));
1928 if(!ensure_uri_builder(This
))
1929 return NS_ERROR_UNEXPECTED
;
1931 nsACString_GetData(aPassword
, &passa
);
1932 pass
= heap_strdupAtoW(passa
);
1934 return NS_ERROR_OUT_OF_MEMORY
;
1936 hres
= IUriBuilder_SetPassword(This
->uri_builder
, pass
);
1939 return NS_ERROR_UNEXPECTED
;
1944 static nsresult NSAPI
nsURI_GetHostPort(nsIURL
*iface
, nsACString
*aHostPort
)
1946 nsWineURI
*This
= impl_from_nsIURL(iface
);
1952 TRACE("(%p)->(%p)\n", This
, aHostPort
);
1954 if(!ensure_uri(This
))
1955 return NS_ERROR_UNEXPECTED
;
1957 hres
= IUri_GetAuthority(This
->uri
, &val
);
1959 WARN("GetAuthority failed: %08x\n", hres
);
1960 return NS_ERROR_UNEXPECTED
;
1963 ptr
= strchrW(val
, '@');
1967 vala
= heap_strdupWtoA(ptr
);
1970 return NS_ERROR_OUT_OF_MEMORY
;
1972 TRACE("ret %s\n", debugstr_a(vala
));
1973 nsACString_SetData(aHostPort
, vala
);
1978 static nsresult NSAPI
nsURI_SetHostPort(nsIURL
*iface
, const nsACString
*aHostPort
)
1980 nsWineURI
*This
= impl_from_nsIURL(iface
);
1982 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aHostPort
));
1984 /* Not implemented by Gecko */
1985 return NS_ERROR_NOT_IMPLEMENTED
;
1988 static nsresult NSAPI
nsURI_GetHost(nsIURL
*iface
, nsACString
*aHost
)
1990 nsWineURI
*This
= impl_from_nsIURL(iface
);
1992 TRACE("(%p)->(%p)\n", This
, aHost
);
1994 return get_uri_string(This
, Uri_PROPERTY_HOST
, aHost
);
1997 static nsresult NSAPI
nsURI_SetHost(nsIURL
*iface
, const nsACString
*aHost
)
1999 nsWineURI
*This
= impl_from_nsIURL(iface
);
2004 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aHost
));
2006 if(!ensure_uri_builder(This
))
2007 return NS_ERROR_UNEXPECTED
;
2009 nsACString_GetData(aHost
, &hosta
);
2010 host
= heap_strdupAtoW(hosta
);
2012 return NS_ERROR_OUT_OF_MEMORY
;
2014 hres
= IUriBuilder_SetHost(This
->uri_builder
, host
);
2017 return NS_ERROR_UNEXPECTED
;
2022 static nsresult NSAPI
nsURI_GetPort(nsIURL
*iface
, PRInt32
*aPort
)
2024 nsWineURI
*This
= impl_from_nsIURL(iface
);
2028 TRACE("(%p)->(%p)\n", This
, aPort
);
2030 if(!ensure_uri(This
))
2031 return NS_ERROR_UNEXPECTED
;
2033 hres
= IUri_GetPort(This
->uri
, &port
);
2035 WARN("GetPort failed: %08x\n", hres
);
2036 return NS_ERROR_UNEXPECTED
;
2039 *aPort
= port
? port
: -1;
2043 static nsresult NSAPI
nsURI_SetPort(nsIURL
*iface
, PRInt32 aPort
)
2045 nsWineURI
*This
= impl_from_nsIURL(iface
);
2048 TRACE("(%p)->(%d)\n", This
, aPort
);
2050 if(!ensure_uri_builder(This
))
2051 return NS_ERROR_UNEXPECTED
;
2053 hres
= IUriBuilder_SetPort(This
->uri_builder
, aPort
!= -1, aPort
);
2054 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_FAILURE
;
2057 static nsresult NSAPI
nsURI_GetPath(nsIURL
*iface
, nsACString
*aPath
)
2059 nsWineURI
*This
= impl_from_nsIURL(iface
);
2061 TRACE("(%p)->(%p)\n", This
, aPath
);
2063 return get_uri_string(This
, Uri_PROPERTY_PATH
, aPath
);
2066 static nsresult NSAPI
nsURI_SetPath(nsIURL
*iface
, const nsACString
*aPath
)
2068 nsWineURI
*This
= impl_from_nsIURL(iface
);
2073 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPath
));
2075 if(!ensure_uri_builder(This
))
2076 return NS_ERROR_UNEXPECTED
;
2078 nsACString_GetData(aPath
, &patha
);
2079 path
= heap_strdupAtoW(patha
);
2081 return NS_ERROR_OUT_OF_MEMORY
;
2083 hres
= IUriBuilder_SetPath(This
->uri_builder
, path
);
2086 return NS_ERROR_UNEXPECTED
;
2091 static nsresult NSAPI
nsURL_GetRef(nsIURL
*iface
, nsACString
*aRef
)
2093 nsWineURI
*This
= impl_from_nsIURL(iface
);
2098 TRACE("(%p)->(%p)\n", This
, aRef
);
2100 if(!ensure_uri(This
))
2101 return NS_ERROR_UNEXPECTED
;
2103 hres
= IUri_GetFragment(This
->uri
, &ref
);
2105 return NS_ERROR_UNEXPECTED
;
2107 refa
= heap_strdupWtoA(ref
);
2110 return NS_ERROR_OUT_OF_MEMORY
;
2112 nsACString_SetData(aRef
, refa
&& *refa
== '#' ? refa
+1 : refa
);
2117 static nsresult NSAPI
nsURL_SetRef(nsIURL
*iface
, const nsACString
*aRef
)
2119 nsWineURI
*This
= impl_from_nsIURL(iface
);
2124 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRef
));
2126 if(!ensure_uri_builder(This
))
2127 return NS_ERROR_UNEXPECTED
;
2129 nsACString_GetData(aRef
, &refa
);
2130 ref
= heap_strdupAtoW(refa
);
2132 return NS_ERROR_OUT_OF_MEMORY
;
2134 hres
= IUriBuilder_SetFragment(This
->uri_builder
, ref
);
2137 return NS_ERROR_UNEXPECTED
;
2142 static nsresult NSAPI
nsURI_Equals(nsIURL
*iface
, nsIURI
*other
, PRBool
*_retval
)
2144 nsWineURI
*This
= impl_from_nsIURL(iface
);
2145 nsWineURI
*other_obj
;
2149 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
2151 nsres
= nsIURI_QueryInterface(other
, &IID_nsWineURI
, (void**)&other_obj
);
2152 if(NS_FAILED(nsres
)) {
2153 TRACE("Could not get nsWineURI interface\n");
2158 if(ensure_uri(This
) && ensure_uri(other_obj
)) {
2159 hres
= IUri_IsEqual(This
->uri
, other_obj
->uri
, _retval
);
2160 nsres
= SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_FAILURE
;
2162 nsres
= NS_ERROR_UNEXPECTED
;
2165 nsIURI_Release(&other_obj
->nsIURL_iface
);
2169 static nsresult NSAPI
nsURI_EqualsExceptRef(nsIURL
*iface
, nsIURI
*other
, PRBool
*_retval
)
2171 nsWineURI
*This
= impl_from_nsIURL(iface
);
2172 FIXME("(%p)->(%p %p)\n", This
, other
, _retval
);
2173 return nsIURL_Equals(&This
->nsIURL_iface
, other
, _retval
);
2176 static nsresult NSAPI
nsURI_SchemeIs(nsIURL
*iface
, const char *scheme
, PRBool
*_retval
)
2178 nsWineURI
*This
= impl_from_nsIURL(iface
);
2179 WCHAR buf
[INTERNET_MAX_SCHEME_LENGTH
];
2183 TRACE("(%p)->(%s %p)\n", This
, debugstr_a(scheme
), _retval
);
2185 if(!ensure_uri(This
))
2186 return NS_ERROR_UNEXPECTED
;
2188 hres
= IUri_GetSchemeName(This
->uri
, &scheme_name
);
2190 return NS_ERROR_UNEXPECTED
;
2192 MultiByteToWideChar(CP_ACP
, 0, scheme
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
2193 *_retval
= !strcmpW(scheme_name
, buf
);
2194 SysFreeString(scheme_name
);
2198 static nsresult NSAPI
nsURI_Clone(nsIURL
*iface
, nsIURI
**_retval
)
2200 nsWineURI
*This
= impl_from_nsIURL(iface
);
2201 nsIURI
*nsuri
= NULL
;
2202 nsWineURI
*wine_uri
;
2205 TRACE("(%p)->(%p)\n", This
, _retval
);
2207 if(!ensure_uri(This
))
2208 return NS_ERROR_UNEXPECTED
;
2211 nsres
= nsIURI_Clone(This
->nsuri
, &nsuri
);
2212 if(NS_FAILED(nsres
)) {
2213 WARN("Clone failed: %08x\n", nsres
);
2218 nsres
= create_nsuri(This
->uri
, nsuri
, This
->window_ref
? This
->window_ref
->window
: NULL
, This
->container
, &wine_uri
);
2219 if(NS_FAILED(nsres
)) {
2220 WARN("create_nsuri failed: %08x\n", nsres
);
2224 *_retval
= (nsIURI
*)&wine_uri
->nsIURL_iface
;
2228 static nsresult NSAPI
nsURI_CloneIgnoreRef(nsIURL
*iface
, nsIURI
**_retval
)
2230 nsWineURI
*This
= impl_from_nsIURL(iface
);
2231 FIXME("(%p)->(%p)\n", This
, _retval
);
2232 return nsIURL_Clone(&This
->nsIURL_iface
, _retval
);
2235 static nsresult NSAPI
nsURI_Resolve(nsIURL
*iface
, const nsACString
*aRelativePath
,
2236 nsACString
*_retval
)
2238 nsWineURI
*This
= impl_from_nsIURL(iface
);
2246 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aRelativePath
), _retval
);
2248 if(!ensure_uri(This
))
2249 return NS_ERROR_UNEXPECTED
;
2251 nsACString_GetData(aRelativePath
, &patha
);
2252 path
= heap_strdupAtoW(patha
);
2254 return NS_ERROR_OUT_OF_MEMORY
;
2256 hres
= CoInternetCombineUrlEx(This
->uri
, path
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
, &new_uri
, 0);
2259 ERR("CoIntenetCombineUrlEx failed: %08x\n", hres
);
2260 return NS_ERROR_FAILURE
;
2263 hres
= IUri_GetDisplayUri(new_uri
, &ret
);
2264 IUri_Release(new_uri
);
2266 return NS_ERROR_FAILURE
;
2268 reta
= heap_strdupWtoA(ret
);
2271 return NS_ERROR_OUT_OF_MEMORY
;
2273 TRACE("returning %s\n", debugstr_a(reta
));
2274 nsACString_SetData(_retval
, reta
);
2279 static nsresult NSAPI
nsURI_GetAsciiSpec(nsIURL
*iface
, nsACString
*aAsciiSpec
)
2281 nsWineURI
*This
= impl_from_nsIURL(iface
);
2283 TRACE("(%p)->(%p)\n", This
, aAsciiSpec
);
2285 return nsIURI_GetSpec(&This
->nsIURL_iface
, aAsciiSpec
);
2288 static nsresult NSAPI
nsURI_GetAsciiHost(nsIURL
*iface
, nsACString
*aAsciiHost
)
2290 nsWineURI
*This
= impl_from_nsIURL(iface
);
2292 TRACE("(%p)->(%p)\n", This
, aAsciiHost
);
2295 return nsIURI_GetAsciiHost(This
->nsuri
, aAsciiHost
);
2297 WARN("Use Uri_PUNYCODE_IDN_HOST flag\n");
2298 return get_uri_string(This
, Uri_PROPERTY_HOST
, aAsciiHost
);
2301 static nsresult NSAPI
nsURI_GetOriginCharset(nsIURL
*iface
, nsACString
*aOriginCharset
)
2303 nsWineURI
*This
= impl_from_nsIURL(iface
);
2305 TRACE("(%p)->(%p)\n", This
, aOriginCharset
);
2308 return nsIURI_GetOriginCharset(This
->nsuri
, aOriginCharset
);
2310 FIXME("default action not implemented\n");
2311 return NS_ERROR_NOT_IMPLEMENTED
;
2314 static nsresult NSAPI
nsURL_GetFilePath(nsIURL
*iface
, nsACString
*aFilePath
)
2316 nsWineURI
*This
= impl_from_nsIURL(iface
);
2318 TRACE("(%p)->(%p)\n", This
, aFilePath
);
2320 return nsIURL_GetPath(&This
->nsIURL_iface
, aFilePath
);
2323 static nsresult NSAPI
nsURL_SetFilePath(nsIURL
*iface
, const nsACString
*aFilePath
)
2325 nsWineURI
*This
= impl_from_nsIURL(iface
);
2327 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFilePath
));
2329 return nsIURL_SetPath(&This
->nsIURL_iface
, aFilePath
);
2332 static nsresult NSAPI
nsURL_GetParam(nsIURL
*iface
, nsACString
*aParam
)
2334 nsWineURI
*This
= impl_from_nsIURL(iface
);
2336 TRACE("(%p)->(%p)\n", This
, aParam
);
2339 return nsIURL_GetParam(This
->nsurl
, aParam
);
2341 FIXME("default action not implemented\n");
2342 return NS_ERROR_NOT_IMPLEMENTED
;
2345 static nsresult NSAPI
nsURL_SetParam(nsIURL
*iface
, const nsACString
*aParam
)
2347 nsWineURI
*This
= impl_from_nsIURL(iface
);
2349 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aParam
));
2351 /* Not implemented by Gecko */
2352 return NS_ERROR_NOT_IMPLEMENTED
;
2355 static nsresult NSAPI
nsURL_GetQuery(nsIURL
*iface
, nsACString
*aQuery
)
2357 nsWineURI
*This
= impl_from_nsIURL(iface
);
2359 TRACE("(%p)->(%p)\n", This
, aQuery
);
2361 return get_uri_string(This
, Uri_PROPERTY_QUERY
, aQuery
);
2364 static nsresult NSAPI
nsURL_SetQuery(nsIURL
*iface
, const nsACString
*aQuery
)
2366 nsWineURI
*This
= impl_from_nsIURL(iface
);
2371 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aQuery
));
2373 if(!ensure_uri_builder(This
))
2374 return NS_ERROR_UNEXPECTED
;
2376 nsACString_GetData(aQuery
, &querya
);
2377 query
= heap_strdupAtoW(querya
);
2379 return NS_ERROR_OUT_OF_MEMORY
;
2381 hres
= IUriBuilder_SetQuery(This
->uri_builder
, query
);
2384 return NS_ERROR_UNEXPECTED
;
2389 static nsresult NSAPI
nsURL_GetDirectory(nsIURL
*iface
, nsACString
*aDirectory
)
2391 nsWineURI
*This
= impl_from_nsIURL(iface
);
2397 TRACE("(%p)->(%p)\n", This
, aDirectory
);
2399 if(!ensure_uri(This
))
2400 return NS_ERROR_UNEXPECTED
;
2402 hres
= IUri_GetPath(This
->uri
, &path
);
2404 return NS_ERROR_FAILURE
;
2406 ptr
= strrchrW(path
, '/');
2410 dir
= heap_strdupWtoA(path
);
2412 SysFreeString(path
);
2413 return NS_ERROR_OUT_OF_MEMORY
;
2417 SysFreeString(path
);
2418 TRACE("ret %s\n", debugstr_a(dir
));
2419 nsACString_SetData(aDirectory
, dir
? dir
: "");
2423 static nsresult NSAPI
nsURL_SetDirectory(nsIURL
*iface
, const nsACString
*aDirectory
)
2425 nsWineURI
*This
= impl_from_nsIURL(iface
);
2427 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aDirectory
));
2429 /* Not implemented by Gecko */
2430 return NS_ERROR_NOT_IMPLEMENTED
;
2433 static nsresult NSAPI
nsURL_GetFileName(nsIURL
*iface
, nsACString
*aFileName
)
2435 nsWineURI
*This
= impl_from_nsIURL(iface
);
2437 TRACE("(%p)->(%p)\n", This
, aFileName
);
2440 return nsIURL_GetFileName(This
->nsurl
, aFileName
);
2442 FIXME("default action not implemented\n");
2443 return NS_ERROR_NOT_IMPLEMENTED
;
2446 static nsresult NSAPI
nsURL_SetFileName(nsIURL
*iface
, const nsACString
*aFileName
)
2448 nsWineURI
*This
= impl_from_nsIURL(iface
);
2450 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileName
));
2453 invalidate_uri(This
);
2454 return nsIURL_SetFileName(This
->nsurl
, aFileName
);
2457 FIXME("default action not implemented\n");
2458 return NS_ERROR_NOT_IMPLEMENTED
;
2461 static nsresult NSAPI
nsURL_GetFileBaseName(nsIURL
*iface
, nsACString
*aFileBaseName
)
2463 nsWineURI
*This
= impl_from_nsIURL(iface
);
2465 TRACE("(%p)->(%p)\n", This
, aFileBaseName
);
2468 return nsIURL_GetFileBaseName(This
->nsurl
, aFileBaseName
);
2470 FIXME("default action not implemented\n");
2471 return NS_ERROR_NOT_IMPLEMENTED
;
2474 static nsresult NSAPI
nsURL_SetFileBaseName(nsIURL
*iface
, const nsACString
*aFileBaseName
)
2476 nsWineURI
*This
= impl_from_nsIURL(iface
);
2478 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileBaseName
));
2481 invalidate_uri(This
);
2482 return nsIURL_SetFileBaseName(This
->nsurl
, aFileBaseName
);
2485 FIXME("default action not implemented\n");
2486 return NS_ERROR_NOT_IMPLEMENTED
;
2489 static nsresult NSAPI
nsURL_GetFileExtension(nsIURL
*iface
, nsACString
*aFileExtension
)
2491 nsWineURI
*This
= impl_from_nsIURL(iface
);
2493 TRACE("(%p)->(%p)\n", This
, aFileExtension
);
2495 return get_uri_string(This
, Uri_PROPERTY_EXTENSION
, aFileExtension
);
2498 static nsresult NSAPI
nsURL_SetFileExtension(nsIURL
*iface
, const nsACString
*aFileExtension
)
2500 nsWineURI
*This
= impl_from_nsIURL(iface
);
2502 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileExtension
));
2505 invalidate_uri(This
);
2506 return nsIURL_SetFileExtension(This
->nsurl
, aFileExtension
);
2509 FIXME("default action not implemented\n");
2510 return NS_ERROR_NOT_IMPLEMENTED
;
2513 static nsresult NSAPI
nsURL_GetCommonBaseSpec(nsIURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2515 nsWineURI
*This
= impl_from_nsIURL(iface
);
2517 TRACE("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2520 return nsIURL_GetCommonBaseSpec(This
->nsurl
, aURIToCompare
, _retval
);
2522 FIXME("default action not implemented\n");
2523 return NS_ERROR_NOT_IMPLEMENTED
;
2526 static nsresult NSAPI
nsURL_GetRelativeSpec(nsIURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2528 nsWineURI
*This
= impl_from_nsIURL(iface
);
2530 TRACE("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2533 return nsIURL_GetRelativeSpec(This
->nsurl
, aURIToCompare
, _retval
);
2535 FIXME("default action not implemented\n");
2536 return NS_ERROR_NOT_IMPLEMENTED
;
2539 static const nsIURLVtbl nsURLVtbl
= {
2540 nsURI_QueryInterface
,
2565 nsURI_EqualsExceptRef
,
2568 nsURI_CloneIgnoreRef
,
2572 nsURI_GetOriginCharset
,
2583 nsURL_GetFileBaseName
,
2584 nsURL_SetFileBaseName
,
2585 nsURL_GetFileExtension
,
2586 nsURL_SetFileExtension
,
2587 nsURL_GetCommonBaseSpec
,
2588 nsURL_GetRelativeSpec
2591 static nsresult
create_nsuri(IUri
*iuri
, nsIURI
*nsuri
, HTMLWindow
*window
, NSContainer
*container
, nsWineURI
**_retval
)
2593 nsWineURI
*ret
= heap_alloc_zero(sizeof(nsWineURI
));
2595 ret
->nsIURL_iface
.lpVtbl
= &nsURLVtbl
;
2599 set_uri_nscontainer(ret
, container
);
2600 set_uri_window(ret
, window
);
2606 nsIURI_QueryInterface(nsuri
, &IID_nsIURL
, (void**)&ret
->nsurl
);
2608 TRACE("retval=%p\n", ret
);
2613 HRESULT
create_doc_uri(HTMLWindow
*window
, WCHAR
*url
, nsWineURI
**ret
)
2620 hres
= CreateUri(url
, 0, 0, &iuri
);
2624 nsres
= create_nsuri(iuri
, NULL
, window
, window
->doc_obj
->nscontainer
, &uri
);
2626 if(NS_FAILED(nsres
))
2629 uri
->is_doc_uri
= TRUE
;
2635 static nsresult
create_nschannel(nsWineURI
*uri
, nsChannel
**ret
)
2640 if(!ensure_uri(uri
))
2641 return NS_ERROR_UNEXPECTED
;
2643 channel
= heap_alloc_zero(sizeof(nsChannel
));
2645 return NS_ERROR_OUT_OF_MEMORY
;
2647 channel
->nsIHttpChannel_iface
.lpVtbl
= &nsChannelVtbl
;
2648 channel
->nsIUploadChannel_iface
.lpVtbl
= &nsUploadChannelVtbl
;
2649 channel
->nsIHttpChannelInternal_iface
.lpVtbl
= &nsHttpChannelInternalVtbl
;
2651 channel
->request_method
= METHOD_GET
;
2652 list_init(&channel
->response_headers
);
2653 list_init(&channel
->request_headers
);
2655 nsIURL_AddRef(&uri
->nsIURL_iface
);
2658 hres
= IUri_GetScheme(uri
->uri
, &channel
->url_scheme
);
2660 channel
->url_scheme
= URL_SCHEME_UNKNOWN
;
2666 HRESULT
create_redirect_nschannel(const WCHAR
*url
, nsChannel
*orig_channel
, nsChannel
**ret
)
2668 HTMLWindow
*window
= NULL
;
2675 hres
= CreateUri(url
, 0, 0, &iuri
);
2679 if(orig_channel
->uri
->window_ref
)
2680 window
= orig_channel
->uri
->window_ref
->window
;
2681 nsres
= create_nsuri(iuri
, NULL
, window
, NULL
, &uri
);
2683 if(NS_FAILED(nsres
))
2686 nsres
= create_nschannel(uri
, &channel
);
2687 nsIURL_Release(&uri
->nsIURL_iface
);
2688 if(NS_FAILED(nsres
))
2691 if(orig_channel
->load_group
) {
2692 nsILoadGroup_AddRef(orig_channel
->load_group
);
2693 channel
->load_group
= orig_channel
->load_group
;
2696 if(orig_channel
->notif_callback
) {
2697 nsIInterfaceRequestor_AddRef(orig_channel
->notif_callback
);
2698 channel
->notif_callback
= orig_channel
->notif_callback
;
2701 channel
->load_flags
= orig_channel
->load_flags
| LOAD_REPLACE
;
2703 if(orig_channel
->request_method
== METHOD_POST
)
2704 FIXME("unsupported POST method\n");
2706 if(orig_channel
->original_uri
) {
2707 nsIURI_AddRef(orig_channel
->original_uri
);
2708 channel
->original_uri
= orig_channel
->original_uri
;
2711 if(orig_channel
->referrer
) {
2712 nsIURI_AddRef(orig_channel
->referrer
);
2713 channel
->referrer
= orig_channel
->referrer
;
2721 nsIProtocolHandler nsIProtocolHandler_iface
;
2725 nsIProtocolHandler
*nshandler
;
2726 } nsProtocolHandler
;
2728 static inline nsProtocolHandler
*impl_from_nsIProtocolHandler(nsIProtocolHandler
*iface
)
2730 return CONTAINING_RECORD(iface
, nsProtocolHandler
, nsIProtocolHandler_iface
);
2733 static nsresult NSAPI
nsProtocolHandler_QueryInterface(nsIProtocolHandler
*iface
, nsIIDRef riid
,
2736 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2740 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
2741 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
2742 *result
= &This
->nsIProtocolHandler_iface
;
2743 }else if(IsEqualGUID(&IID_nsIProtocolHandler
, riid
)) {
2744 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This
, result
);
2745 *result
= &This
->nsIProtocolHandler_iface
;
2746 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler
, riid
)) {
2747 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This
, result
);
2748 return NS_NOINTERFACE
;
2752 nsISupports_AddRef((nsISupports
*)*result
);
2756 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
2757 return NS_NOINTERFACE
;
2760 static nsrefcnt NSAPI
nsProtocolHandler_AddRef(nsIProtocolHandler
*iface
)
2762 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2763 LONG ref
= InterlockedIncrement(&This
->ref
);
2765 TRACE("(%p) ref=%d\n", This
, ref
);
2770 static nsrefcnt NSAPI
nsProtocolHandler_Release(nsIProtocolHandler
*iface
)
2772 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2773 LONG ref
= InterlockedDecrement(&This
->ref
);
2775 TRACE("(%p) ref=%d\n", This
, ref
);
2779 nsIProtocolHandler_Release(This
->nshandler
);
2786 static nsresult NSAPI
nsProtocolHandler_GetScheme(nsIProtocolHandler
*iface
, nsACString
*aScheme
)
2788 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2790 TRACE("(%p)->(%p)\n", This
, aScheme
);
2793 return nsIProtocolHandler_GetScheme(This
->nshandler
, aScheme
);
2794 return NS_ERROR_NOT_IMPLEMENTED
;
2797 static nsresult NSAPI
nsProtocolHandler_GetDefaultPort(nsIProtocolHandler
*iface
,
2798 PRInt32
*aDefaultPort
)
2800 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2802 TRACE("(%p)->(%p)\n", This
, aDefaultPort
);
2805 return nsIProtocolHandler_GetDefaultPort(This
->nshandler
, aDefaultPort
);
2806 return NS_ERROR_NOT_IMPLEMENTED
;
2809 static nsresult NSAPI
nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler
*iface
,
2810 PRUint32
*aProtocolFlags
)
2812 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2814 TRACE("(%p)->(%p)\n", This
, aProtocolFlags
);
2817 return nsIProtocolHandler_GetProtocolFlags(This
->nshandler
, aProtocolFlags
);
2818 return NS_ERROR_NOT_IMPLEMENTED
;
2821 static nsresult NSAPI
nsProtocolHandler_NewURI(nsIProtocolHandler
*iface
,
2822 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
2824 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2826 TRACE("((%p)->%s %s %p %p)\n", This
, debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
2830 return nsIProtocolHandler_NewURI(This
->nshandler
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2831 return NS_ERROR_NOT_IMPLEMENTED
;
2834 static nsresult NSAPI
nsProtocolHandler_NewChannel(nsIProtocolHandler
*iface
,
2835 nsIURI
*aURI
, nsIChannel
**_retval
)
2837 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2839 TRACE("(%p)->(%p %p)\n", This
, aURI
, _retval
);
2842 return nsIProtocolHandler_NewChannel(This
->nshandler
, aURI
, _retval
);
2843 return NS_ERROR_NOT_IMPLEMENTED
;
2846 static nsresult NSAPI
nsProtocolHandler_AllowPort(nsIProtocolHandler
*iface
,
2847 PRInt32 port
, const char *scheme
, PRBool
*_retval
)
2849 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2851 TRACE("(%p)->(%d %s %p)\n", This
, port
, debugstr_a(scheme
), _retval
);
2854 return nsIProtocolHandler_AllowPort(This
->nshandler
, port
, scheme
, _retval
);
2855 return NS_ERROR_NOT_IMPLEMENTED
;
2858 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl
= {
2859 nsProtocolHandler_QueryInterface
,
2860 nsProtocolHandler_AddRef
,
2861 nsProtocolHandler_Release
,
2862 nsProtocolHandler_GetScheme
,
2863 nsProtocolHandler_GetDefaultPort
,
2864 nsProtocolHandler_GetProtocolFlags
,
2865 nsProtocolHandler_NewURI
,
2866 nsProtocolHandler_NewChannel
,
2867 nsProtocolHandler_AllowPort
2870 static nsIProtocolHandler
*create_protocol_handler(nsIProtocolHandler
*nshandler
)
2872 nsProtocolHandler
*ret
= heap_alloc(sizeof(nsProtocolHandler
));
2874 ret
->nsIProtocolHandler_iface
.lpVtbl
= &nsProtocolHandlerVtbl
;
2876 ret
->nshandler
= nshandler
;
2878 return &ret
->nsIProtocolHandler_iface
;
2881 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*,nsIIDRef
,void**);
2883 static nsrefcnt NSAPI
nsIOService_AddRef(nsIIOService
*iface
)
2888 static nsrefcnt NSAPI
nsIOService_Release(nsIIOService
*iface
)
2893 static nsresult NSAPI
nsIOService_GetProtocolHandler(nsIIOService
*iface
, const char *aScheme
,
2894 nsIProtocolHandler
**_retval
)
2896 nsIExternalProtocolHandler
*nsexthandler
;
2897 nsIProtocolHandler
*nshandler
;
2900 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
2902 nsres
= nsIIOService_GetProtocolHandler(nsio
, aScheme
, &nshandler
);
2903 if(NS_FAILED(nsres
)) {
2904 WARN("GetProtocolHandler failed: %08x\n", nsres
);
2908 nsres
= nsIProtocolHandler_QueryInterface(nshandler
, &IID_nsIExternalProtocolHandler
,
2909 (void**)&nsexthandler
);
2910 if(NS_FAILED(nsres
)) {
2911 *_retval
= nshandler
;
2915 nsIExternalProtocolHandler_Release(nsexthandler
);
2916 *_retval
= create_protocol_handler(nshandler
);
2917 TRACE("return %p\n", *_retval
);
2921 static nsresult NSAPI
nsIOService_GetProtocolFlags(nsIIOService
*iface
, const char *aScheme
,
2924 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
2925 return nsIIOService_GetProtocolFlags(nsio
, aScheme
, _retval
);
2928 static BOOL
is_gecko_special_uri(const char *spec
)
2930 static const char *special_schemes
[] = {"chrome:", "jar:", "moz-safe-about", "resource:", "javascript:", "wyciwyg:"};
2933 for(i
=0; i
< sizeof(special_schemes
)/sizeof(*special_schemes
); i
++) {
2934 if(!strncasecmp(spec
, special_schemes
[i
], strlen(special_schemes
[i
])))
2938 if(!strncasecmp(spec
, "file:", 5)) {
2939 const char *ptr
= spec
+5;
2942 return is_gecko_path(ptr
);
2948 static nsresult NSAPI
nsIOService_NewURI(nsIIOService
*iface
, const nsACString
*aSpec
,
2949 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
2951 nsWineURI
*wine_uri
, *base_wine_uri
= NULL
;
2952 WCHAR new_spec
[INTERNET_MAX_URL_LENGTH
];
2953 HTMLWindow
*window
= NULL
;
2954 const char *spec
= NULL
;
2960 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
2963 nsACString_GetData(aSpec
, &spec
);
2964 if(is_gecko_special_uri(spec
))
2965 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2967 if(!strncmp(spec
, "wine:", 5))
2971 nsres
= nsIURI_QueryInterface(aBaseURI
, &IID_nsWineURI
, (void**)&base_wine_uri
);
2972 if(NS_SUCCEEDED(nsres
)) {
2973 if(!ensure_uri(base_wine_uri
))
2974 return NS_ERROR_UNEXPECTED
;
2975 if(base_wine_uri
->window_ref
)
2976 window
= base_wine_uri
->window_ref
->window
;
2978 WARN("Could not get base nsWineURI: %08x\n", nsres
);
2982 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, new_spec
, sizeof(new_spec
)/sizeof(WCHAR
));
2985 hres
= CoInternetCombineUrlEx(base_wine_uri
->uri
, new_spec
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
2988 WARN("CoInternetCombineUrlEx failed: %08x\n", hres
);
2990 hres
= CreateUri(new_spec
, 0, 0, &urlmon_uri
);
2992 WARN("CreateUri failed: %08x\n", hres
);
2995 nsres
= nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, &uri
);
2996 if(NS_FAILED(nsres
))
2997 TRACE("NewURI failed: %08x\n", nsres
);
3004 nsres
= create_nsuri(urlmon_uri
, uri
, window
, NULL
, &wine_uri
);
3005 IUri_Release(urlmon_uri
);
3007 nsIURI_Release(&base_wine_uri
->nsIURL_iface
);
3008 if(NS_FAILED(nsres
))
3011 *_retval
= (nsIURI
*)&wine_uri
->nsIURL_iface
;
3015 static nsresult NSAPI
nsIOService_NewFileURI(nsIIOService
*iface
, nsIFile
*aFile
,
3018 TRACE("(%p %p)\n", aFile
, _retval
);
3019 return nsIIOService_NewFileURI(nsio
, aFile
, _retval
);
3022 static nsresult NSAPI
nsIOService_NewChannelFromURI(nsIIOService
*iface
, nsIURI
*aURI
,
3023 nsIChannel
**_retval
)
3025 nsWineURI
*wine_uri
;
3029 TRACE("(%p %p)\n", aURI
, _retval
);
3031 nsres
= nsIURI_QueryInterface(aURI
, &IID_nsWineURI
, (void**)&wine_uri
);
3032 if(NS_FAILED(nsres
)) {
3033 TRACE("Could not get nsWineURI: %08x\n", nsres
);
3034 return nsIIOService_NewChannelFromURI(nsio
, aURI
, _retval
);
3037 nsres
= create_nschannel(wine_uri
, &ret
);
3038 nsIURL_Release(&wine_uri
->nsIURL_iface
);
3039 if(NS_FAILED(nsres
))
3042 nsIURI_AddRef(aURI
);
3043 ret
->original_uri
= aURI
;
3045 *_retval
= (nsIChannel
*)&ret
->nsIHttpChannel_iface
;
3049 static nsresult NSAPI
nsIOService_NewChannel(nsIIOService
*iface
, const nsACString
*aSpec
,
3050 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIChannel
**_retval
)
3052 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
), aBaseURI
, _retval
);
3053 return nsIIOService_NewChannel(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3056 static nsresult NSAPI
nsIOService_GetOffline(nsIIOService
*iface
, PRBool
*aOffline
)
3058 TRACE("(%p)\n", aOffline
);
3059 return nsIIOService_GetOffline(nsio
, aOffline
);
3062 static nsresult NSAPI
nsIOService_SetOffline(nsIIOService
*iface
, PRBool aOffline
)
3064 TRACE("(%x)\n", aOffline
);
3065 return nsIIOService_SetOffline(nsio
, aOffline
);
3068 static nsresult NSAPI
nsIOService_AllowPort(nsIIOService
*iface
, PRInt32 aPort
,
3069 const char *aScheme
, PRBool
*_retval
)
3071 TRACE("(%d %s %p)\n", aPort
, debugstr_a(aScheme
), _retval
);
3072 return nsIIOService_AllowPort(nsio
, aPort
, debugstr_a(aScheme
), _retval
);
3075 static nsresult NSAPI
nsIOService_ExtractScheme(nsIIOService
*iface
, const nsACString
*urlString
,
3076 nsACString
* _retval
)
3078 TRACE("(%s %p)\n", debugstr_nsacstr(urlString
), _retval
);
3079 return nsIIOService_ExtractScheme(nsio
, urlString
, _retval
);
3082 static const nsIIOServiceVtbl nsIOServiceVtbl
= {
3083 nsIOService_QueryInterface
,
3085 nsIOService_Release
,
3086 nsIOService_GetProtocolHandler
,
3087 nsIOService_GetProtocolFlags
,
3089 nsIOService_NewFileURI
,
3090 nsIOService_NewChannelFromURI
,
3091 nsIOService_NewChannel
,
3092 nsIOService_GetOffline
,
3093 nsIOService_SetOffline
,
3094 nsIOService_AllowPort
,
3095 nsIOService_ExtractScheme
3098 static nsIIOService nsIOService
= { &nsIOServiceVtbl
};
3100 static nsresult NSAPI
nsNetUtil_QueryInterface(nsINetUtil
*iface
, nsIIDRef riid
,
3103 return nsIIOService_QueryInterface(&nsIOService
, riid
, result
);
3106 static nsrefcnt NSAPI
nsNetUtil_AddRef(nsINetUtil
*iface
)
3111 static nsrefcnt NSAPI
nsNetUtil_Release(nsINetUtil
*iface
)
3116 static nsresult NSAPI
nsNetUtil_ParseContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
3117 nsACString
*aCharset
, PRBool
*aHadCharset
, nsACString
*aContentType
)
3119 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aHadCharset
, aContentType
);
3121 return nsINetUtil_ParseContentType(net_util
, aTypeHeader
, aCharset
, aHadCharset
, aContentType
);
3124 static nsresult NSAPI
nsNetUtil_ProtocolHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, PRUint32 aFlags
, PRBool
*_retval
)
3128 return nsINetUtil_ProtocolHasFlags(net_util
, aURI
, aFlags
, _retval
);
3131 static nsresult NSAPI
nsNetUtil_URIChainHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, PRUint32 aFlags
, PRBool
*_retval
)
3133 TRACE("(%p %08x %p)\n", aURI
, aFlags
, _retval
);
3135 if(aFlags
== (1<<11)) {
3140 return nsINetUtil_URIChainHasFlags(net_util
, aURI
, aFlags
, _retval
);
3143 static nsresult NSAPI
nsNetUtil_ToImmutableURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
3145 TRACE("(%p %p)\n", aURI
, _retval
);
3147 return nsINetUtil_ToImmutableURI(net_util
, aURI
, _retval
);
3150 static nsresult NSAPI
nsNetUtil_NewSimpleNestedURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
3152 TRACE("(%p %p)\n", aURI
, _retval
);
3154 return nsINetUtil_NewSimpleNestedURI(net_util
, aURI
, _retval
);
3157 static nsresult NSAPI
nsNetUtil_EscapeString(nsINetUtil
*iface
, const nsACString
*aString
,
3158 PRUint32 aEscapeType
, nsACString
*_retval
)
3160 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString
), aEscapeType
, _retval
);
3162 return nsINetUtil_EscapeString(net_util
, aString
, aEscapeType
, _retval
);
3165 static nsresult NSAPI
nsNetUtil_EscapeURL(nsINetUtil
*iface
, const nsACString
*aStr
, PRUint32 aFlags
,
3166 nsACString
*_retval
)
3168 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
3170 return nsINetUtil_EscapeURL(net_util
, aStr
, aFlags
, _retval
);
3173 static nsresult NSAPI
nsNetUtil_UnescapeString(nsINetUtil
*iface
, const nsACString
*aStr
,
3174 PRUint32 aFlags
, nsACString
*_retval
)
3176 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
3178 return nsINetUtil_UnescapeString(net_util
, aStr
, aFlags
, _retval
);
3181 static nsresult NSAPI
nsNetUtil_ExtractCharsetFromContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
3182 nsACString
*aCharset
, PRInt32
*aCharsetStart
, PRInt32
*aCharsetEnd
, PRBool
*_retval
)
3184 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aCharsetStart
,
3185 aCharsetEnd
, _retval
);
3187 return nsINetUtil_ExtractCharsetFromContentType(net_util
, aTypeHeader
, aCharset
, aCharsetStart
, aCharsetEnd
, _retval
);
3190 static const nsINetUtilVtbl nsNetUtilVtbl
= {
3191 nsNetUtil_QueryInterface
,
3194 nsNetUtil_ParseContentType
,
3195 nsNetUtil_ProtocolHasFlags
,
3196 nsNetUtil_URIChainHasFlags
,
3197 nsNetUtil_ToImmutableURI
,
3198 nsNetUtil_NewSimpleNestedURI
,
3199 nsNetUtil_EscapeString
,
3200 nsNetUtil_EscapeURL
,
3201 nsNetUtil_UnescapeString
,
3202 nsNetUtil_ExtractCharsetFromContentType
3205 static nsINetUtil nsNetUtil
= { &nsNetUtilVtbl
};
3207 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*iface
, nsIIDRef riid
,
3212 if(IsEqualGUID(&IID_nsISupports
, riid
))
3213 *result
= &nsIOService
;
3214 else if(IsEqualGUID(&IID_nsIIOService
, riid
))
3215 *result
= &nsIOService
;
3216 else if(IsEqualGUID(&IID_nsINetUtil
, riid
))
3217 *result
= &nsNetUtil
;
3220 nsISupports_AddRef((nsISupports
*)*result
);
3224 FIXME("(%s %p)\n", debugstr_guid(riid
), result
);
3225 return NS_NOINTERFACE
;
3228 static nsresult NSAPI
nsIOServiceFactory_QueryInterface(nsIFactory
*iface
, nsIIDRef riid
,
3233 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
3234 TRACE("(IID_nsISupports %p)\n", result
);
3236 }else if(IsEqualGUID(&IID_nsIFactory
, riid
)) {
3237 TRACE("(IID_nsIFactory %p)\n", result
);
3242 nsIFactory_AddRef(iface
);
3246 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
3247 return NS_NOINTERFACE
;
3250 static nsrefcnt NSAPI
nsIOServiceFactory_AddRef(nsIFactory
*iface
)
3255 static nsrefcnt NSAPI
nsIOServiceFactory_Release(nsIFactory
*iface
)
3260 static nsresult NSAPI
nsIOServiceFactory_CreateInstance(nsIFactory
*iface
,
3261 nsISupports
*aOuter
, const nsIID
*iid
, void **result
)
3263 return nsIIOService_QueryInterface(&nsIOService
, iid
, result
);
3266 static nsresult NSAPI
nsIOServiceFactory_LockFactory(nsIFactory
*iface
, PRBool lock
)
3268 WARN("(%x)\n", lock
);
3272 static const nsIFactoryVtbl nsIOServiceFactoryVtbl
= {
3273 nsIOServiceFactory_QueryInterface
,
3274 nsIOServiceFactory_AddRef
,
3275 nsIOServiceFactory_Release
,
3276 nsIOServiceFactory_CreateInstance
,
3277 nsIOServiceFactory_LockFactory
3280 static nsIFactory nsIOServiceFactory
= { &nsIOServiceFactoryVtbl
};
3282 static BOOL
translate_url(HTMLDocumentObj
*doc
, nsWineURI
*uri
)
3284 OLECHAR
*new_url
= NULL
;
3289 if(!doc
->hostui
|| !ensure_uri(uri
))
3292 hres
= IUri_GetDisplayUri(uri
->uri
, &url
);
3296 hres
= IDocHostUIHandler_TranslateUrl(doc
->hostui
, 0, url
, &new_url
);
3297 if(hres
== S_OK
&& new_url
) {
3298 if(strcmpW(url
, new_url
)) {
3299 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url
), debugstr_w(new_url
));
3302 CoTaskMemFree(new_url
);
3309 nsresult
on_start_uri_open(NSContainer
*nscontainer
, nsIURI
*uri
, PRBool
*_retval
)
3311 nsWineURI
*wine_uri
;
3316 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
3317 if(NS_FAILED(nsres
)) {
3318 WARN("Could not get nsWineURI: %08x\n", nsres
);
3319 return NS_ERROR_NOT_IMPLEMENTED
;
3322 if(!wine_uri
->is_doc_uri
) {
3323 wine_uri
->is_doc_uri
= TRUE
;
3325 if(!wine_uri
->container
) {
3326 nsIWebBrowserChrome_AddRef(&nscontainer
->nsIWebBrowserChrome_iface
);
3327 wine_uri
->container
= nscontainer
;
3330 if(nscontainer
->doc
)
3331 *_retval
= translate_url(nscontainer
->doc
, wine_uri
);
3334 nsIURI_Release(&wine_uri
->nsIURL_iface
);
3338 void init_nsio(nsIComponentManager
*component_manager
, nsIComponentRegistrar
*registrar
)
3340 nsIFactory
*old_factory
= NULL
;
3343 nsres
= nsIComponentManager_GetClassObject(component_manager
, &NS_IOSERVICE_CID
,
3344 &IID_nsIFactory
, (void**)&old_factory
);
3345 if(NS_FAILED(nsres
)) {
3346 ERR("Could not get factory: %08x\n", nsres
);
3350 nsres
= nsIFactory_CreateInstance(old_factory
, NULL
, &IID_nsIIOService
, (void**)&nsio
);
3351 if(NS_FAILED(nsres
)) {
3352 ERR("Couldn not create nsIOService instance %08x\n", nsres
);
3353 nsIFactory_Release(old_factory
);
3357 nsres
= nsIIOService_QueryInterface(nsio
, &IID_nsINetUtil
, (void**)&net_util
);
3358 if(NS_FAILED(nsres
)) {
3359 WARN("Could not get nsINetUtil interface: %08x\n", nsres
);
3360 nsIIOService_Release(nsio
);
3364 nsres
= nsIComponentRegistrar_UnregisterFactory(registrar
, &NS_IOSERVICE_CID
, old_factory
);
3365 nsIFactory_Release(old_factory
);
3366 if(NS_FAILED(nsres
))
3367 ERR("UnregisterFactory failed: %08x\n", nsres
);
3369 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_IOSERVICE_CID
,
3370 NS_IOSERVICE_CLASSNAME
, NS_IOSERVICE_CONTRACTID
, &nsIOServiceFactory
);
3371 if(NS_FAILED(nsres
))
3372 ERR("RegisterFactory failed: %08x\n", nsres
);
3375 void release_nsio(void)
3378 nsINetUtil_Release(net_util
);
3383 nsIIOService_Release(nsio
);