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"
36 #include "wine/unicode.h"
38 #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
);
892 IUnknown_Release((IUnknown
*)task
->bscallback
);
895 static nsresult
async_open(nsChannel
*This
, HTMLWindow
*window
, BOOL is_doc_channel
, nsIStreamListener
*listener
,
896 nsISupports
*context
)
898 nsChannelBSC
*bscallback
;
899 IMoniker
*mon
= NULL
;
902 hres
= CreateURLMonikerEx2(NULL
, This
->uri
->uri
, &mon
, 0);
904 WARN("CreateURLMoniker failed: %08x\n", hres
);
905 return NS_ERROR_UNEXPECTED
;
909 set_current_mon(window
, mon
);
911 hres
= create_channelbsc(mon
, NULL
, NULL
, 0, &bscallback
);
912 IMoniker_Release(mon
);
914 return NS_ERROR_UNEXPECTED
;
916 channelbsc_set_channel(bscallback
, This
, listener
, context
);
919 set_window_bscallback(window
, bscallback
);
920 async_start_doc_binding(window
, bscallback
);
921 IUnknown_Release((IUnknown
*)bscallback
);
923 start_binding_task_t
*task
= heap_alloc(sizeof(start_binding_task_t
));
925 task
->doc
= window
->doc
;
926 task
->bscallback
= bscallback
;
927 push_task(&task
->header
, start_binding_proc
, window
->doc
->basedoc
.task_magic
);
933 static nsresult NSAPI
nsChannel_AsyncOpen(nsIHttpChannel
*iface
, nsIStreamListener
*aListener
,
934 nsISupports
*aContext
)
936 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
937 HTMLWindow
*window
= NULL
;
939 nsresult nsres
= NS_OK
;
941 TRACE("(%p)->(%p %p)\n", This
, aListener
, aContext
);
943 if(!ensure_uri(This
->uri
))
944 return NS_ERROR_FAILURE
;
946 if(This
->uri
->is_doc_uri
) {
947 window
= get_channel_window(This
);
949 set_uri_window(This
->uri
, window
);
950 }else if(This
->uri
->container
) {
953 /* nscontainer->doc should be NULL which means navigation to a new window */
954 if(This
->uri
->container
->doc
)
955 FIXME("nscontainer->doc = %p\n", This
->uri
->container
->doc
);
957 nsres
= before_async_open(This
, This
->uri
->container
, &b
);
961 FIXME("Navigation not cancelled\n");
962 return NS_ERROR_UNEXPECTED
;
967 if(This
->uri
->window_ref
&& This
->uri
->window_ref
->window
) {
968 window
= This
->uri
->window_ref
->window
;
969 IHTMLWindow2_AddRef(&window
->IHTMLWindow2_iface
);
971 /* FIXME: Analyze removing get_window_from_load_group call */
973 window
= get_window_from_load_group(This
);
975 window
= get_channel_window(This
);
977 set_uri_window(This
->uri
, window
);
982 ERR("window = NULL\n");
983 return NS_ERROR_UNEXPECTED
;
986 if(This
->uri
->is_doc_uri
&& window
== window
->doc_obj
->basedoc
.window
) {
987 if(This
->uri
->channel_bsc
) {
988 channelbsc_set_channel(This
->uri
->channel_bsc
, This
, aListener
, aContext
);
990 if(window
->doc_obj
->mime
) {
991 heap_free(This
->content_type
);
992 This
->content_type
= heap_strdupWtoA(window
->doc_obj
->mime
);
997 nsres
= before_async_open(This
, window
->doc_obj
->nscontainer
, &cancel
);
998 if(NS_SUCCEEDED(nsres
) && cancel
) {
1000 nsres
= NS_ERROR_UNEXPECTED
;
1006 nsres
= async_open(This
, window
, This
->uri
->is_doc_uri
, aListener
, aContext
);
1008 if(NS_SUCCEEDED(nsres
) && This
->load_group
) {
1009 nsres
= nsILoadGroup_AddRequest(This
->load_group
, (nsIRequest
*)&This
->nsIHttpChannel_iface
,
1011 if(NS_FAILED(nsres
))
1012 ERR("AddRequest failed: %08x\n", nsres
);
1015 IHTMLWindow2_Release(&window
->IHTMLWindow2_iface
);
1019 static nsresult NSAPI
nsChannel_GetRequestMethod(nsIHttpChannel
*iface
, nsACString
*aRequestMethod
)
1021 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1023 TRACE("(%p)->(%p)\n", This
, aRequestMethod
);
1025 nsACString_SetData(aRequestMethod
, request_method_strings
[This
->request_method
]);
1029 static nsresult NSAPI
nsChannel_SetRequestMethod(nsIHttpChannel
*iface
,
1030 const nsACString
*aRequestMethod
)
1032 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1036 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRequestMethod
));
1038 nsACString_GetData(aRequestMethod
, &method
);
1039 for(i
=0; i
< sizeof(request_method_strings
)/sizeof(*request_method_strings
); i
++) {
1040 if(!strcasecmp(method
, request_method_strings
[i
])) {
1041 This
->request_method
= i
;
1046 ERR("Invalid method %s\n", debugstr_a(method
));
1047 return NS_ERROR_UNEXPECTED
;
1050 static nsresult NSAPI
nsChannel_GetReferrer(nsIHttpChannel
*iface
, nsIURI
**aReferrer
)
1052 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1054 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1057 nsIURI_AddRef(This
->referrer
);
1058 *aReferrer
= This
->referrer
;
1062 static nsresult NSAPI
nsChannel_SetReferrer(nsIHttpChannel
*iface
, nsIURI
*aReferrer
)
1064 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1066 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1069 nsIURI_AddRef(aReferrer
);
1071 nsIURI_Release(This
->referrer
);
1072 This
->referrer
= aReferrer
;
1076 static nsresult NSAPI
nsChannel_GetRequestHeader(nsIHttpChannel
*iface
,
1077 const nsACString
*aHeader
, nsACString
*_retval
)
1079 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1081 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aHeader
), _retval
);
1083 return get_channel_http_header(&This
->request_headers
, aHeader
, _retval
);
1086 static nsresult NSAPI
nsChannel_SetRequestHeader(nsIHttpChannel
*iface
,
1087 const nsACString
*aHeader
, const nsACString
*aValue
, PRBool aMerge
)
1089 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1091 TRACE("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(aHeader
), debugstr_nsacstr(aValue
), aMerge
);
1094 FIXME("aMerge not supported\n");
1096 return set_channel_http_header(&This
->request_headers
, aHeader
, aValue
);
1099 static nsresult NSAPI
nsChannel_VisitRequestHeaders(nsIHttpChannel
*iface
,
1100 nsIHttpHeaderVisitor
*aVisitor
)
1102 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1104 FIXME("(%p)->(%p)\n", This
, aVisitor
);
1106 return NS_ERROR_NOT_IMPLEMENTED
;
1109 static nsresult NSAPI
nsChannel_GetAllowPipelining(nsIHttpChannel
*iface
, PRBool
*aAllowPipelining
)
1111 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1113 FIXME("(%p)->(%p)\n", This
, aAllowPipelining
);
1115 return NS_ERROR_NOT_IMPLEMENTED
;
1118 static nsresult NSAPI
nsChannel_SetAllowPipelining(nsIHttpChannel
*iface
, PRBool aAllowPipelining
)
1120 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1122 FIXME("(%p)->(%x)\n", This
, aAllowPipelining
);
1124 return NS_ERROR_NOT_IMPLEMENTED
;
1127 static nsresult NSAPI
nsChannel_GetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32
*aRedirectionLimit
)
1129 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1131 FIXME("(%p)->(%p)\n", This
, aRedirectionLimit
);
1133 return NS_ERROR_NOT_IMPLEMENTED
;
1136 static nsresult NSAPI
nsChannel_SetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32 aRedirectionLimit
)
1138 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1140 FIXME("(%p)->(%u)\n", This
, aRedirectionLimit
);
1142 return NS_ERROR_NOT_IMPLEMENTED
;
1145 static nsresult NSAPI
nsChannel_GetResponseStatus(nsIHttpChannel
*iface
, PRUint32
*aResponseStatus
)
1147 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1149 TRACE("(%p)->(%p)\n", This
, aResponseStatus
);
1151 if(This
->response_status
) {
1152 *aResponseStatus
= This
->response_status
;
1156 WARN("No response status\n");
1157 return NS_ERROR_UNEXPECTED
;
1160 static nsresult NSAPI
nsChannel_GetResponseStatusText(nsIHttpChannel
*iface
,
1161 nsACString
*aResponseStatusText
)
1163 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1165 FIXME("(%p)->(%p)\n", This
, aResponseStatusText
);
1167 return NS_ERROR_NOT_IMPLEMENTED
;
1170 static nsresult NSAPI
nsChannel_GetRequestSucceeded(nsIHttpChannel
*iface
,
1171 PRBool
*aRequestSucceeded
)
1173 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1175 TRACE("(%p)->(%p)\n", This
, aRequestSucceeded
);
1177 if(!This
->response_status
)
1178 return NS_ERROR_NOT_AVAILABLE
;
1180 *aRequestSucceeded
= This
->response_status
/100 == 2;
1185 static nsresult NSAPI
nsChannel_GetResponseHeader(nsIHttpChannel
*iface
,
1186 const nsACString
*header
, nsACString
*_retval
)
1188 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1190 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(header
), _retval
);
1192 return get_channel_http_header(&This
->response_headers
, header
, _retval
);
1195 static nsresult NSAPI
nsChannel_SetResponseHeader(nsIHttpChannel
*iface
,
1196 const nsACString
*header
, const nsACString
*value
, PRBool merge
)
1198 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1200 FIXME("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(header
), debugstr_nsacstr(value
), merge
);
1202 return NS_ERROR_NOT_IMPLEMENTED
;
1205 static nsresult NSAPI
nsChannel_VisitResponseHeaders(nsIHttpChannel
*iface
,
1206 nsIHttpHeaderVisitor
*aVisitor
)
1208 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1210 TRACE("(%p)->(%p)\n", This
, aVisitor
);
1212 return visit_http_headers(&This
->response_headers
, aVisitor
);
1215 static nsresult NSAPI
nsChannel_IsNoStoreResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1217 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1218 http_header_t
*header
;
1220 static const WCHAR cache_controlW
[] = {'C','a','c','h','e','-','C','o','n','t','r','o','l'};
1221 static const WCHAR no_storeW
[] = {'n','o','-','s','t','o','r','e',0};
1223 TRACE("(%p)->(%p)\n", This
, _retval
);
1225 header
= find_http_header(&This
->response_headers
, cache_controlW
, sizeof(cache_controlW
)/sizeof(WCHAR
));
1226 *_retval
= header
&& !strcmpiW(header
->data
, no_storeW
);
1230 static nsresult NSAPI
nsChannel_IsNoCacheResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1232 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1234 FIXME("(%p)->(%p)\n", This
, _retval
);
1236 return NS_ERROR_NOT_IMPLEMENTED
;
1239 static const nsIHttpChannelVtbl nsChannelVtbl
= {
1240 nsChannel_QueryInterface
,
1244 nsChannel_IsPending
,
1245 nsChannel_GetStatus
,
1249 nsChannel_GetLoadGroup
,
1250 nsChannel_SetLoadGroup
,
1251 nsChannel_GetLoadFlags
,
1252 nsChannel_SetLoadFlags
,
1253 nsChannel_GetOriginalURI
,
1254 nsChannel_SetOriginalURI
,
1258 nsChannel_GetNotificationCallbacks
,
1259 nsChannel_SetNotificationCallbacks
,
1260 nsChannel_GetSecurityInfo
,
1261 nsChannel_GetContentType
,
1262 nsChannel_SetContentType
,
1263 nsChannel_GetContentCharset
,
1264 nsChannel_SetContentCharset
,
1265 nsChannel_GetContentLength
,
1266 nsChannel_SetContentLength
,
1268 nsChannel_AsyncOpen
,
1269 nsChannel_GetRequestMethod
,
1270 nsChannel_SetRequestMethod
,
1271 nsChannel_GetReferrer
,
1272 nsChannel_SetReferrer
,
1273 nsChannel_GetRequestHeader
,
1274 nsChannel_SetRequestHeader
,
1275 nsChannel_VisitRequestHeaders
,
1276 nsChannel_GetAllowPipelining
,
1277 nsChannel_SetAllowPipelining
,
1278 nsChannel_GetRedirectionLimit
,
1279 nsChannel_SetRedirectionLimit
,
1280 nsChannel_GetResponseStatus
,
1281 nsChannel_GetResponseStatusText
,
1282 nsChannel_GetRequestSucceeded
,
1283 nsChannel_GetResponseHeader
,
1284 nsChannel_SetResponseHeader
,
1285 nsChannel_VisitResponseHeaders
,
1286 nsChannel_IsNoStoreResponse
,
1287 nsChannel_IsNoCacheResponse
1290 static inline nsChannel
*impl_from_nsIUploadChannel(nsIUploadChannel
*iface
)
1292 return CONTAINING_RECORD(iface
, nsChannel
, nsIUploadChannel_iface
);
1295 static nsresult NSAPI
nsUploadChannel_QueryInterface(nsIUploadChannel
*iface
, nsIIDRef riid
,
1298 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1299 return nsIChannel_QueryInterface(&This
->nsIHttpChannel_iface
, riid
, result
);
1302 static nsrefcnt NSAPI
nsUploadChannel_AddRef(nsIUploadChannel
*iface
)
1304 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1305 return nsIChannel_AddRef(&This
->nsIHttpChannel_iface
);
1308 static nsrefcnt NSAPI
nsUploadChannel_Release(nsIUploadChannel
*iface
)
1310 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1311 return nsIChannel_Release(&This
->nsIHttpChannel_iface
);
1314 static nsresult NSAPI
nsUploadChannel_SetUploadStream(nsIUploadChannel
*iface
,
1315 nsIInputStream
*aStream
, const nsACString
*aContentType
, PRInt32 aContentLength
)
1317 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1318 const char *content_type
;
1320 static const WCHAR content_typeW
[] =
1321 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1323 TRACE("(%p)->(%p %s %d)\n", This
, aStream
, debugstr_nsacstr(aContentType
), aContentLength
);
1325 This
->post_data_contains_headers
= TRUE
;
1328 nsACString_GetData(aContentType
, &content_type
);
1332 ct
= heap_strdupAtoW(content_type
);
1334 return NS_ERROR_UNEXPECTED
;
1336 set_http_header(&This
->request_headers
, content_typeW
,
1337 sizeof(content_typeW
)/sizeof(WCHAR
), ct
, strlenW(ct
));
1339 This
->post_data_contains_headers
= FALSE
;
1343 if(This
->post_data_stream
)
1344 nsIInputStream_Release(This
->post_data_stream
);
1346 if(aContentLength
!= -1)
1347 FIXME("Unsupported acontentLength = %d\n", aContentLength
);
1349 if(This
->post_data_stream
)
1350 nsIInputStream_Release(This
->post_data_stream
);
1351 This
->post_data_stream
= aStream
;
1353 nsIInputStream_AddRef(aStream
);
1355 This
->request_method
= METHOD_POST
;
1359 static nsresult NSAPI
nsUploadChannel_GetUploadStream(nsIUploadChannel
*iface
,
1360 nsIInputStream
**aUploadStream
)
1362 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1364 TRACE("(%p)->(%p)\n", This
, aUploadStream
);
1366 if(This
->post_data_stream
)
1367 nsIInputStream_AddRef(This
->post_data_stream
);
1369 *aUploadStream
= This
->post_data_stream
;
1373 static const nsIUploadChannelVtbl nsUploadChannelVtbl
= {
1374 nsUploadChannel_QueryInterface
,
1375 nsUploadChannel_AddRef
,
1376 nsUploadChannel_Release
,
1377 nsUploadChannel_SetUploadStream
,
1378 nsUploadChannel_GetUploadStream
1381 static inline nsChannel
*impl_from_nsIHttpChannelInternal(nsIHttpChannelInternal
*iface
)
1383 return CONTAINING_RECORD(iface
, nsChannel
, nsIHttpChannelInternal_iface
);
1386 static nsresult NSAPI
nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal
*iface
, nsIIDRef riid
,
1389 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1390 return nsIChannel_QueryInterface(&This
->nsIHttpChannel_iface
, riid
, result
);
1393 static nsrefcnt NSAPI
nsHttpChannelInternal_AddRef(nsIHttpChannelInternal
*iface
)
1395 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1396 return nsIChannel_AddRef(&This
->nsIHttpChannel_iface
);
1399 static nsrefcnt NSAPI
nsHttpChannelInternal_Release(nsIHttpChannelInternal
*iface
)
1401 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1402 return nsIChannel_Release(&This
->nsIHttpChannel_iface
);
1405 static nsresult NSAPI
nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
**aDocumentURI
)
1407 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1409 FIXME("(%p)->()\n", This
);
1411 return NS_ERROR_NOT_IMPLEMENTED
;
1414 static nsresult NSAPI
nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
*aDocumentURI
)
1416 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1418 FIXME("(%p)->()\n", This
);
1420 return NS_ERROR_NOT_IMPLEMENTED
;
1423 static nsresult NSAPI
nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal
*iface
, PRUint32
*major
, PRUint32
*minor
)
1425 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1427 FIXME("(%p)->()\n", This
);
1429 return NS_ERROR_NOT_IMPLEMENTED
;
1432 static nsresult NSAPI
nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal
*iface
, PRUint32
*major
, PRUint32
*minor
)
1434 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1436 FIXME("(%p)->()\n", This
);
1438 return NS_ERROR_NOT_IMPLEMENTED
;
1441 static nsresult NSAPI
nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal
*iface
, const char *aCookieHeader
)
1443 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1445 FIXME("(%p)->()\n", This
);
1447 return NS_ERROR_NOT_IMPLEMENTED
;
1450 static nsresult NSAPI
nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal
*iface
, const char *aFallbackKey
)
1452 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1454 FIXME("(%p)->()\n", This
);
1456 return NS_ERROR_NOT_IMPLEMENTED
;
1459 static nsresult NSAPI
nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, PRBool
*aForceThirdPartyCookie
)
1461 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1463 FIXME("(%p)->()\n", This
);
1465 return NS_ERROR_NOT_IMPLEMENTED
;
1468 static nsresult NSAPI
nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, PRBool aForceThirdPartyCookie
)
1470 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1472 FIXME("(%p)->()\n", This
);
1474 return NS_ERROR_NOT_IMPLEMENTED
;
1477 static nsresult NSAPI
nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal
*iface
, PRBool
*aCanceled
)
1479 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1481 FIXME("(%p)->(%p)\n", This
, aCanceled
);
1483 return NS_ERROR_NOT_IMPLEMENTED
;
1486 static nsresult NSAPI
nsHttpChannelInternal_GetChannelIsForDownload(nsIHttpChannelInternal
*iface
, PRBool
*aCanceled
)
1488 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1490 FIXME("(%p)->(%p)\n", This
, aCanceled
);
1492 return NS_ERROR_NOT_IMPLEMENTED
;
1495 static nsresult NSAPI
nsHttpChannelInternal_SetChannelIsForDownload(nsIHttpChannelInternal
*iface
, PRBool aCanceled
)
1497 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1499 FIXME("(%p)->(%x)\n", This
, aCanceled
);
1501 return NS_ERROR_NOT_IMPLEMENTED
;
1504 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl
= {
1505 nsHttpChannelInternal_QueryInterface
,
1506 nsHttpChannelInternal_AddRef
,
1507 nsHttpChannelInternal_Release
,
1508 nsHttpChannelInternal_GetDocumentURI
,
1509 nsHttpChannelInternal_SetDocumentURI
,
1510 nsHttpChannelInternal_GetRequestVersion
,
1511 nsHttpChannelInternal_GetResponseVersion
,
1512 nsHttpChannelInternal_SetCookie
,
1513 nsHttpChannelInternal_SetupFallbackChannel
,
1514 nsHttpChannelInternal_GetForceAllowThirdPartyCookie
,
1515 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
,
1516 nsHttpChannelInternal_GetCanceled
,
1517 nsHttpChannelInternal_GetChannelIsForDownload
,
1518 nsHttpChannelInternal_SetChannelIsForDownload
1522 static void invalidate_uri(nsWineURI
*This
)
1525 IUri_Release(This
->uri
);
1530 static BOOL
ensure_uri_builder(nsWineURI
*This
)
1532 if(!This
->uri_builder
) {
1535 if(!ensure_uri(This
))
1538 hres
= CreateIUriBuilder(This
->uri
, 0, 0, &This
->uri_builder
);
1540 WARN("CreateIUriBulder failed: %08x\n", hres
);
1545 invalidate_uri(This
);
1549 static nsresult
get_uri_string(nsWineURI
*This
, Uri_PROPERTY prop
, nsACString
*ret
)
1555 if(!ensure_uri(This
))
1556 return NS_ERROR_UNEXPECTED
;
1558 hres
= IUri_GetPropertyBSTR(This
->uri
, prop
, &val
, 0);
1560 WARN("GetPropertyBSTR failed: %08x\n", hres
);
1561 return NS_ERROR_UNEXPECTED
;
1564 vala
= heap_strdupWtoA(val
);
1567 return NS_ERROR_OUT_OF_MEMORY
;
1569 TRACE("ret %s\n", debugstr_a(vala
));
1570 nsACString_SetData(ret
, vala
);
1575 static inline nsWineURI
*impl_from_nsIURL(nsIURL
*iface
)
1577 return CONTAINING_RECORD(iface
, nsWineURI
, nsIURL_iface
);
1580 static nsresult NSAPI
nsURI_QueryInterface(nsIURL
*iface
, nsIIDRef riid
, void **result
)
1582 nsWineURI
*This
= impl_from_nsIURL(iface
);
1586 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1587 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1588 *result
= &This
->nsIURL_iface
;
1589 }else if(IsEqualGUID(&IID_nsIURI
, riid
)) {
1590 TRACE("(%p)->(IID_nsIURI %p)\n", This
, result
);
1591 *result
= &This
->nsIURL_iface
;
1592 }else if(IsEqualGUID(&IID_nsIURL
, riid
)) {
1593 TRACE("(%p)->(IID_nsIURL %p)\n", This
, result
);
1594 *result
= &This
->nsIURL_iface
;
1595 }else if(IsEqualGUID(&IID_nsWineURI
, riid
)) {
1596 TRACE("(%p)->(IID_nsWineURI %p)\n", This
, result
);
1601 nsIURI_AddRef(&This
->nsIURL_iface
);
1605 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1606 return This
->nsuri
? nsIURI_QueryInterface(This
->nsuri
, riid
, result
) : NS_NOINTERFACE
;
1609 static nsrefcnt NSAPI
nsURI_AddRef(nsIURL
*iface
)
1611 nsWineURI
*This
= impl_from_nsIURL(iface
);
1612 LONG ref
= InterlockedIncrement(&This
->ref
);
1614 TRACE("(%p) ref=%d\n", This
, ref
);
1619 static nsrefcnt NSAPI
nsURI_Release(nsIURL
*iface
)
1621 nsWineURI
*This
= impl_from_nsIURL(iface
);
1622 LONG ref
= InterlockedDecrement(&This
->ref
);
1624 TRACE("(%p) ref=%d\n", This
, ref
);
1627 if(This
->window_ref
)
1628 windowref_release(This
->window_ref
);
1630 nsIWebBrowserChrome_Release(&This
->container
->nsIWebBrowserChrome_iface
);
1632 nsIURL_Release(This
->nsurl
);
1634 nsIURI_Release(This
->nsuri
);
1636 IUri_Release(This
->uri
);
1643 static nsresult NSAPI
nsURI_GetSpec(nsIURL
*iface
, nsACString
*aSpec
)
1645 nsWineURI
*This
= impl_from_nsIURL(iface
);
1647 TRACE("(%p)->(%p)\n", This
, aSpec
);
1649 return get_uri_string(This
, Uri_PROPERTY_DISPLAY_URI
, aSpec
);
1652 static nsresult NSAPI
nsURI_SetSpec(nsIURL
*iface
, const nsACString
*aSpec
)
1654 nsWineURI
*This
= impl_from_nsIURL(iface
);
1660 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aSpec
));
1662 nsACString_GetData(aSpec
, &speca
);
1663 spec
= heap_strdupAtoW(speca
);
1665 return NS_ERROR_OUT_OF_MEMORY
;
1667 hres
= CreateUri(spec
, 0, 0, &uri
);
1670 WARN("CreateUri failed: %08x\n", hres
);
1671 return NS_ERROR_FAILURE
;
1674 invalidate_uri(This
);
1675 if(This
->uri_builder
) {
1676 IUriBuilder_Release(This
->uri_builder
);
1677 This
->uri_builder
= NULL
;
1684 static nsresult NSAPI
nsURI_GetPrePath(nsIURL
*iface
, nsACString
*aPrePath
)
1686 nsWineURI
*This
= impl_from_nsIURL(iface
);
1688 TRACE("(%p)->(%p)\n", This
, aPrePath
);
1691 return nsIURI_GetPrePath(This
->nsuri
, aPrePath
);
1693 FIXME("default action not implemented\n");
1694 return NS_ERROR_NOT_IMPLEMENTED
;
1697 static nsresult NSAPI
nsURI_GetScheme(nsIURL
*iface
, nsACString
*aScheme
)
1699 nsWineURI
*This
= impl_from_nsIURL(iface
);
1703 TRACE("(%p)->(%p)\n", This
, aScheme
);
1705 if(!ensure_uri(This
))
1706 return NS_ERROR_UNEXPECTED
;
1708 hres
= IUri_GetScheme(This
->uri
, &scheme
);
1710 WARN("GetScheme failed: %08x\n", hres
);
1711 return NS_ERROR_UNEXPECTED
;
1714 if(scheme
== URL_SCHEME_ABOUT
) {
1715 nsACString_SetData(aScheme
, "wine");
1719 return get_uri_string(This
, Uri_PROPERTY_SCHEME_NAME
, aScheme
);
1722 static nsresult NSAPI
nsURI_SetScheme(nsIURL
*iface
, const nsACString
*aScheme
)
1724 nsWineURI
*This
= impl_from_nsIURL(iface
);
1725 const char *schemea
;
1729 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aScheme
));
1731 if(!ensure_uri_builder(This
))
1732 return NS_ERROR_UNEXPECTED
;
1734 nsACString_GetData(aScheme
, &schemea
);
1735 scheme
= heap_strdupAtoW(schemea
);
1737 return NS_ERROR_OUT_OF_MEMORY
;
1739 hres
= IUriBuilder_SetSchemeName(This
->uri_builder
, scheme
);
1742 return NS_ERROR_UNEXPECTED
;
1747 static nsresult NSAPI
nsURI_GetUserPass(nsIURL
*iface
, nsACString
*aUserPass
)
1749 nsWineURI
*This
= impl_from_nsIURL(iface
);
1751 TRACE("(%p)->(%p)\n", This
, aUserPass
);
1754 return nsIURI_GetUserPass(This
->nsuri
, aUserPass
);
1756 return get_uri_string(This
, Uri_PROPERTY_USER_INFO
, aUserPass
);
1759 static nsresult NSAPI
nsURI_SetUserPass(nsIURL
*iface
, const nsACString
*aUserPass
)
1761 nsWineURI
*This
= impl_from_nsIURL(iface
);
1763 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUserPass
));
1766 invalidate_uri(This
);
1767 return nsIURI_SetUserPass(This
->nsuri
, aUserPass
);
1770 FIXME("default action not implemented\n");
1771 return NS_ERROR_NOT_IMPLEMENTED
;
1774 static nsresult NSAPI
nsURI_GetUsername(nsIURL
*iface
, nsACString
*aUsername
)
1776 nsWineURI
*This
= impl_from_nsIURL(iface
);
1778 TRACE("(%p)->(%p)\n", This
, aUsername
);
1780 return get_uri_string(This
, Uri_PROPERTY_USER_NAME
, aUsername
);
1783 static nsresult NSAPI
nsURI_SetUsername(nsIURL
*iface
, const nsACString
*aUsername
)
1785 nsWineURI
*This
= impl_from_nsIURL(iface
);
1790 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUsername
));
1792 if(!ensure_uri_builder(This
))
1793 return NS_ERROR_UNEXPECTED
;
1795 nsACString_GetData(aUsername
, &usera
);
1796 user
= heap_strdupAtoW(usera
);
1798 return NS_ERROR_OUT_OF_MEMORY
;
1800 hres
= IUriBuilder_SetUserName(This
->uri_builder
, user
);
1803 return NS_ERROR_UNEXPECTED
;
1808 static nsresult NSAPI
nsURI_GetPassword(nsIURL
*iface
, nsACString
*aPassword
)
1810 nsWineURI
*This
= impl_from_nsIURL(iface
);
1812 TRACE("(%p)->(%p)\n", This
, aPassword
);
1814 return get_uri_string(This
, Uri_PROPERTY_PASSWORD
, aPassword
);
1817 static nsresult NSAPI
nsURI_SetPassword(nsIURL
*iface
, const nsACString
*aPassword
)
1819 nsWineURI
*This
= impl_from_nsIURL(iface
);
1824 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPassword
));
1826 if(!ensure_uri_builder(This
))
1827 return NS_ERROR_UNEXPECTED
;
1829 nsACString_GetData(aPassword
, &passa
);
1830 pass
= heap_strdupAtoW(passa
);
1832 return NS_ERROR_OUT_OF_MEMORY
;
1834 hres
= IUriBuilder_SetPassword(This
->uri_builder
, pass
);
1837 return NS_ERROR_UNEXPECTED
;
1842 static nsresult NSAPI
nsURI_GetHostPort(nsIURL
*iface
, nsACString
*aHostPort
)
1844 nsWineURI
*This
= impl_from_nsIURL(iface
);
1850 TRACE("(%p)->(%p)\n", This
, aHostPort
);
1852 if(!ensure_uri(This
))
1853 return NS_ERROR_UNEXPECTED
;
1855 hres
= IUri_GetAuthority(This
->uri
, &val
);
1857 WARN("GetAuthority failed: %08x\n", hres
);
1858 return NS_ERROR_UNEXPECTED
;
1861 ptr
= strchrW(val
, '@');
1865 vala
= heap_strdupWtoA(ptr
);
1868 return NS_ERROR_OUT_OF_MEMORY
;
1870 TRACE("ret %s\n", debugstr_a(vala
));
1871 nsACString_SetData(aHostPort
, vala
);
1876 static nsresult NSAPI
nsURI_SetHostPort(nsIURL
*iface
, const nsACString
*aHostPort
)
1878 nsWineURI
*This
= impl_from_nsIURL(iface
);
1880 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aHostPort
));
1882 /* Not implemented by Gecko */
1883 return NS_ERROR_NOT_IMPLEMENTED
;
1886 static nsresult NSAPI
nsURI_GetHost(nsIURL
*iface
, nsACString
*aHost
)
1888 nsWineURI
*This
= impl_from_nsIURL(iface
);
1890 TRACE("(%p)->(%p)\n", This
, aHost
);
1892 return get_uri_string(This
, Uri_PROPERTY_HOST
, aHost
);
1895 static nsresult NSAPI
nsURI_SetHost(nsIURL
*iface
, const nsACString
*aHost
)
1897 nsWineURI
*This
= impl_from_nsIURL(iface
);
1902 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aHost
));
1904 if(!ensure_uri_builder(This
))
1905 return NS_ERROR_UNEXPECTED
;
1907 nsACString_GetData(aHost
, &hosta
);
1908 host
= heap_strdupAtoW(hosta
);
1910 return NS_ERROR_OUT_OF_MEMORY
;
1912 hres
= IUriBuilder_SetHost(This
->uri_builder
, host
);
1915 return NS_ERROR_UNEXPECTED
;
1920 static nsresult NSAPI
nsURI_GetPort(nsIURL
*iface
, PRInt32
*aPort
)
1922 nsWineURI
*This
= impl_from_nsIURL(iface
);
1926 TRACE("(%p)->(%p)\n", This
, aPort
);
1928 if(!ensure_uri(This
))
1929 return NS_ERROR_UNEXPECTED
;
1931 hres
= IUri_GetPort(This
->uri
, &port
);
1933 WARN("GetPort failed: %08x\n", hres
);
1934 return NS_ERROR_UNEXPECTED
;
1937 *aPort
= port
? port
: -1;
1941 static nsresult NSAPI
nsURI_SetPort(nsIURL
*iface
, PRInt32 aPort
)
1943 nsWineURI
*This
= impl_from_nsIURL(iface
);
1946 TRACE("(%p)->(%d)\n", This
, aPort
);
1948 if(!ensure_uri_builder(This
))
1949 return NS_ERROR_UNEXPECTED
;
1951 hres
= IUriBuilder_SetPort(This
->uri_builder
, aPort
!= -1, aPort
);
1952 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_FAILURE
;
1955 static nsresult NSAPI
nsURI_GetPath(nsIURL
*iface
, nsACString
*aPath
)
1957 nsWineURI
*This
= impl_from_nsIURL(iface
);
1959 TRACE("(%p)->(%p)\n", This
, aPath
);
1961 return get_uri_string(This
, Uri_PROPERTY_PATH
, aPath
);
1964 static nsresult NSAPI
nsURI_SetPath(nsIURL
*iface
, const nsACString
*aPath
)
1966 nsWineURI
*This
= impl_from_nsIURL(iface
);
1971 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPath
));
1973 if(!ensure_uri_builder(This
))
1974 return NS_ERROR_UNEXPECTED
;
1976 nsACString_GetData(aPath
, &patha
);
1977 path
= heap_strdupAtoW(patha
);
1979 return NS_ERROR_OUT_OF_MEMORY
;
1981 hres
= IUriBuilder_SetPath(This
->uri_builder
, path
);
1984 return NS_ERROR_UNEXPECTED
;
1989 static nsresult NSAPI
nsURI_Equals(nsIURL
*iface
, nsIURI
*other
, PRBool
*_retval
)
1991 nsWineURI
*This
= impl_from_nsIURL(iface
);
1992 nsWineURI
*other_obj
;
1996 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
1998 nsres
= nsIURI_QueryInterface(other
, &IID_nsWineURI
, (void**)&other_obj
);
1999 if(NS_FAILED(nsres
)) {
2000 TRACE("Could not get nsWineURI interface\n");
2005 if(ensure_uri(This
) && ensure_uri(other_obj
)) {
2006 hres
= IUri_IsEqual(This
->uri
, other_obj
->uri
, _retval
);
2007 nsres
= SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_FAILURE
;
2009 nsres
= NS_ERROR_UNEXPECTED
;
2012 nsIURI_Release(&other_obj
->nsIURL_iface
);
2016 static nsresult NSAPI
nsURI_SchemeIs(nsIURL
*iface
, const char *scheme
, PRBool
*_retval
)
2018 nsWineURI
*This
= impl_from_nsIURL(iface
);
2019 WCHAR buf
[INTERNET_MAX_SCHEME_LENGTH
];
2023 TRACE("(%p)->(%s %p)\n", This
, debugstr_a(scheme
), _retval
);
2025 if(!ensure_uri(This
))
2026 return NS_ERROR_UNEXPECTED
;
2028 hres
= IUri_GetSchemeName(This
->uri
, &scheme_name
);
2030 return NS_ERROR_UNEXPECTED
;
2032 MultiByteToWideChar(CP_ACP
, 0, scheme
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
2033 *_retval
= !strcmpW(scheme_name
, buf
);
2034 SysFreeString(scheme_name
);
2038 static nsresult NSAPI
nsURI_Clone(nsIURL
*iface
, nsIURI
**_retval
)
2040 nsWineURI
*This
= impl_from_nsIURL(iface
);
2041 nsIURI
*nsuri
= NULL
;
2042 nsWineURI
*wine_uri
;
2045 TRACE("(%p)->(%p)\n", This
, _retval
);
2047 if(!ensure_uri(This
))
2048 return NS_ERROR_UNEXPECTED
;
2051 nsres
= nsIURI_Clone(This
->nsuri
, &nsuri
);
2052 if(NS_FAILED(nsres
)) {
2053 WARN("Clone failed: %08x\n", nsres
);
2058 nsres
= create_nsuri(This
->uri
, nsuri
, This
->window_ref
? This
->window_ref
->window
: NULL
, This
->container
, &wine_uri
);
2059 if(NS_FAILED(nsres
)) {
2060 WARN("create_nsuri failed: %08x\n", nsres
);
2064 *_retval
= (nsIURI
*)&wine_uri
->nsIURL_iface
;
2068 static nsresult NSAPI
nsURI_Resolve(nsIURL
*iface
, const nsACString
*aRelativePath
,
2069 nsACString
*_retval
)
2071 nsWineURI
*This
= impl_from_nsIURL(iface
);
2079 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aRelativePath
), _retval
);
2081 if(!ensure_uri(This
))
2082 return NS_ERROR_UNEXPECTED
;
2084 nsACString_GetData(aRelativePath
, &patha
);
2085 path
= heap_strdupAtoW(patha
);
2087 return NS_ERROR_OUT_OF_MEMORY
;
2089 hres
= CoInternetCombineUrlEx(This
->uri
, path
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
, &new_uri
, 0);
2092 ERR("CoIntenetCombineUrlEx failed: %08x\n", hres
);
2093 return NS_ERROR_FAILURE
;
2096 hres
= IUri_GetDisplayUri(new_uri
, &ret
);
2097 IUri_Release(new_uri
);
2099 return NS_ERROR_FAILURE
;
2101 reta
= heap_strdupWtoA(ret
);
2104 return NS_ERROR_OUT_OF_MEMORY
;
2106 TRACE("returning %s\n", debugstr_a(reta
));
2107 nsACString_SetData(_retval
, reta
);
2112 static nsresult NSAPI
nsURI_GetAsciiSpec(nsIURL
*iface
, nsACString
*aAsciiSpec
)
2114 nsWineURI
*This
= impl_from_nsIURL(iface
);
2116 TRACE("(%p)->(%p)\n", This
, aAsciiSpec
);
2118 return nsIURI_GetSpec(&This
->nsIURL_iface
, aAsciiSpec
);
2121 static nsresult NSAPI
nsURI_GetAsciiHost(nsIURL
*iface
, nsACString
*aAsciiHost
)
2123 nsWineURI
*This
= impl_from_nsIURL(iface
);
2125 TRACE("(%p)->(%p)\n", This
, aAsciiHost
);
2128 return nsIURI_GetAsciiHost(This
->nsuri
, aAsciiHost
);
2130 FIXME("Use Uri_PUNYCODE_IDN_HOST flag\n");
2131 return get_uri_string(This
, Uri_PROPERTY_HOST
, aAsciiHost
);
2134 static nsresult NSAPI
nsURI_GetOriginCharset(nsIURL
*iface
, nsACString
*aOriginCharset
)
2136 nsWineURI
*This
= impl_from_nsIURL(iface
);
2138 TRACE("(%p)->(%p)\n", This
, aOriginCharset
);
2141 return nsIURI_GetOriginCharset(This
->nsuri
, aOriginCharset
);
2143 FIXME("default action not implemented\n");
2144 return NS_ERROR_NOT_IMPLEMENTED
;
2147 static nsresult NSAPI
nsURL_GetFilePath(nsIURL
*iface
, nsACString
*aFilePath
)
2149 nsWineURI
*This
= impl_from_nsIURL(iface
);
2151 TRACE("(%p)->(%p)\n", This
, aFilePath
);
2153 return nsIURL_GetPath(&This
->nsIURL_iface
, aFilePath
);
2156 static nsresult NSAPI
nsURL_SetFilePath(nsIURL
*iface
, const nsACString
*aFilePath
)
2158 nsWineURI
*This
= impl_from_nsIURL(iface
);
2160 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFilePath
));
2162 return nsIURL_SetPath(&This
->nsIURL_iface
, aFilePath
);
2165 static nsresult NSAPI
nsURL_GetParam(nsIURL
*iface
, nsACString
*aParam
)
2167 nsWineURI
*This
= impl_from_nsIURL(iface
);
2169 TRACE("(%p)->(%p)\n", This
, aParam
);
2172 return nsIURL_GetParam(This
->nsurl
, aParam
);
2174 FIXME("default action not implemented\n");
2175 return NS_ERROR_NOT_IMPLEMENTED
;
2178 static nsresult NSAPI
nsURL_SetParam(nsIURL
*iface
, const nsACString
*aParam
)
2180 nsWineURI
*This
= impl_from_nsIURL(iface
);
2182 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aParam
));
2184 /* Not implemented by Gecko */
2185 return NS_ERROR_NOT_IMPLEMENTED
;
2188 static nsresult NSAPI
nsURL_GetQuery(nsIURL
*iface
, nsACString
*aQuery
)
2190 nsWineURI
*This
= impl_from_nsIURL(iface
);
2192 TRACE("(%p)->(%p)\n", This
, aQuery
);
2194 return get_uri_string(This
, Uri_PROPERTY_QUERY
, aQuery
);
2197 static nsresult NSAPI
nsURL_SetQuery(nsIURL
*iface
, const nsACString
*aQuery
)
2199 nsWineURI
*This
= impl_from_nsIURL(iface
);
2204 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aQuery
));
2206 if(!ensure_uri_builder(This
))
2207 return NS_ERROR_UNEXPECTED
;
2209 nsACString_GetData(aQuery
, &querya
);
2210 query
= heap_strdupAtoW(querya
);
2212 return NS_ERROR_OUT_OF_MEMORY
;
2214 hres
= IUriBuilder_SetQuery(This
->uri_builder
, query
);
2217 return NS_ERROR_UNEXPECTED
;
2222 static nsresult NSAPI
nsURL_GetRef(nsIURL
*iface
, nsACString
*aRef
)
2224 nsWineURI
*This
= impl_from_nsIURL(iface
);
2229 TRACE("(%p)->(%p)\n", This
, aRef
);
2231 if(!ensure_uri(This
))
2232 return NS_ERROR_UNEXPECTED
;
2234 hres
= IUri_GetFragment(This
->uri
, &ref
);
2236 return NS_ERROR_UNEXPECTED
;
2238 refa
= heap_strdupWtoA(ref
);
2241 return NS_ERROR_OUT_OF_MEMORY
;
2243 nsACString_SetData(aRef
, refa
&& *refa
== '#' ? refa
+1 : refa
);
2248 static nsresult NSAPI
nsURL_SetRef(nsIURL
*iface
, const nsACString
*aRef
)
2250 nsWineURI
*This
= impl_from_nsIURL(iface
);
2255 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRef
));
2257 if(!ensure_uri_builder(This
))
2258 return NS_ERROR_UNEXPECTED
;
2260 nsACString_GetData(aRef
, &refa
);
2261 ref
= heap_strdupAtoW(refa
);
2263 return NS_ERROR_OUT_OF_MEMORY
;
2265 hres
= IUriBuilder_SetFragment(This
->uri_builder
, ref
);
2268 return NS_ERROR_UNEXPECTED
;
2273 static nsresult NSAPI
nsURL_GetDirectory(nsIURL
*iface
, nsACString
*aDirectory
)
2275 nsWineURI
*This
= impl_from_nsIURL(iface
);
2277 TRACE("(%p)->(%p)\n", This
, aDirectory
);
2280 return nsIURL_GetDirectory(This
->nsurl
, aDirectory
);
2282 FIXME("default action not implemented\n");
2283 return NS_ERROR_NOT_IMPLEMENTED
;
2286 static nsresult NSAPI
nsURL_SetDirectory(nsIURL
*iface
, const nsACString
*aDirectory
)
2288 nsWineURI
*This
= impl_from_nsIURL(iface
);
2290 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aDirectory
));
2292 /* Not implemented by Gecko */
2293 return NS_ERROR_NOT_IMPLEMENTED
;
2296 static nsresult NSAPI
nsURL_GetFileName(nsIURL
*iface
, nsACString
*aFileName
)
2298 nsWineURI
*This
= impl_from_nsIURL(iface
);
2300 TRACE("(%p)->(%p)\n", This
, aFileName
);
2303 return nsIURL_GetFileName(This
->nsurl
, aFileName
);
2305 FIXME("default action not implemented\n");
2306 return NS_ERROR_NOT_IMPLEMENTED
;
2309 static nsresult NSAPI
nsURL_SetFileName(nsIURL
*iface
, const nsACString
*aFileName
)
2311 nsWineURI
*This
= impl_from_nsIURL(iface
);
2313 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileName
));
2316 invalidate_uri(This
);
2317 return nsIURL_SetFileName(This
->nsurl
, aFileName
);
2320 FIXME("default action not implemented\n");
2321 return NS_ERROR_NOT_IMPLEMENTED
;
2324 static nsresult NSAPI
nsURL_GetFileBaseName(nsIURL
*iface
, nsACString
*aFileBaseName
)
2326 nsWineURI
*This
= impl_from_nsIURL(iface
);
2328 TRACE("(%p)->(%p)\n", This
, aFileBaseName
);
2331 return nsIURL_GetFileBaseName(This
->nsurl
, aFileBaseName
);
2333 FIXME("default action not implemented\n");
2334 return NS_ERROR_NOT_IMPLEMENTED
;
2337 static nsresult NSAPI
nsURL_SetFileBaseName(nsIURL
*iface
, const nsACString
*aFileBaseName
)
2339 nsWineURI
*This
= impl_from_nsIURL(iface
);
2341 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileBaseName
));
2344 invalidate_uri(This
);
2345 return nsIURL_SetFileBaseName(This
->nsurl
, aFileBaseName
);
2348 FIXME("default action not implemented\n");
2349 return NS_ERROR_NOT_IMPLEMENTED
;
2352 static nsresult NSAPI
nsURL_GetFileExtension(nsIURL
*iface
, nsACString
*aFileExtension
)
2354 nsWineURI
*This
= impl_from_nsIURL(iface
);
2356 TRACE("(%p)->(%p)\n", This
, aFileExtension
);
2359 return nsIURL_GetFileExtension(This
->nsurl
, aFileExtension
);
2361 FIXME("default action not implemented\n");
2362 return NS_ERROR_NOT_IMPLEMENTED
;
2365 static nsresult NSAPI
nsURL_SetFileExtension(nsIURL
*iface
, const nsACString
*aFileExtension
)
2367 nsWineURI
*This
= impl_from_nsIURL(iface
);
2369 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileExtension
));
2372 invalidate_uri(This
);
2373 return nsIURL_SetFileExtension(This
->nsurl
, aFileExtension
);
2376 FIXME("default action not implemented\n");
2377 return NS_ERROR_NOT_IMPLEMENTED
;
2380 static nsresult NSAPI
nsURL_GetCommonBaseSpec(nsIURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2382 nsWineURI
*This
= impl_from_nsIURL(iface
);
2384 TRACE("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2387 return nsIURL_GetCommonBaseSpec(This
->nsurl
, aURIToCompare
, _retval
);
2389 FIXME("default action not implemented\n");
2390 return NS_ERROR_NOT_IMPLEMENTED
;
2393 static nsresult NSAPI
nsURL_GetRelativeSpec(nsIURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2395 nsWineURI
*This
= impl_from_nsIURL(iface
);
2397 TRACE("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2400 return nsIURL_GetRelativeSpec(This
->nsurl
, aURIToCompare
, _retval
);
2402 FIXME("default action not implemented\n");
2403 return NS_ERROR_NOT_IMPLEMENTED
;
2406 static const nsIURLVtbl nsURLVtbl
= {
2407 nsURI_QueryInterface
,
2435 nsURI_GetOriginCharset
,
2448 nsURL_GetFileBaseName
,
2449 nsURL_SetFileBaseName
,
2450 nsURL_GetFileExtension
,
2451 nsURL_SetFileExtension
,
2452 nsURL_GetCommonBaseSpec
,
2453 nsURL_GetRelativeSpec
2456 static nsresult
create_nsuri(IUri
*iuri
, nsIURI
*nsuri
, HTMLWindow
*window
, NSContainer
*container
, nsWineURI
**_retval
)
2458 nsWineURI
*ret
= heap_alloc_zero(sizeof(nsWineURI
));
2460 ret
->nsIURL_iface
.lpVtbl
= &nsURLVtbl
;
2464 set_uri_nscontainer(ret
, container
);
2465 set_uri_window(ret
, window
);
2471 nsIURI_QueryInterface(nsuri
, &IID_nsIURL
, (void**)&ret
->nsurl
);
2473 TRACE("retval=%p\n", ret
);
2478 HRESULT
create_doc_uri(HTMLWindow
*window
, WCHAR
*url
, nsWineURI
**ret
)
2485 hres
= CreateUri(url
, 0, 0, &iuri
);
2489 nsres
= create_nsuri(iuri
, NULL
, window
, window
->doc_obj
->nscontainer
, &uri
);
2491 if(NS_FAILED(nsres
))
2494 uri
->is_doc_uri
= TRUE
;
2500 static nsresult
create_nschannel(nsWineURI
*uri
, nsChannel
**ret
)
2505 if(!ensure_uri(uri
))
2506 return NS_ERROR_UNEXPECTED
;
2508 channel
= heap_alloc_zero(sizeof(nsChannel
));
2510 return NS_ERROR_OUT_OF_MEMORY
;
2512 channel
->nsIHttpChannel_iface
.lpVtbl
= &nsChannelVtbl
;
2513 channel
->nsIUploadChannel_iface
.lpVtbl
= &nsUploadChannelVtbl
;
2514 channel
->nsIHttpChannelInternal_iface
.lpVtbl
= &nsHttpChannelInternalVtbl
;
2516 channel
->request_method
= METHOD_GET
;
2517 list_init(&channel
->response_headers
);
2518 list_init(&channel
->request_headers
);
2520 nsIURL_AddRef(&uri
->nsIURL_iface
);
2523 hres
= IUri_GetScheme(uri
->uri
, &channel
->url_scheme
);
2525 channel
->url_scheme
= URL_SCHEME_UNKNOWN
;
2531 HRESULT
create_redirect_nschannel(const WCHAR
*url
, nsChannel
*orig_channel
, nsChannel
**ret
)
2533 HTMLWindow
*window
= NULL
;
2540 hres
= CreateUri(url
, 0, 0, &iuri
);
2544 if(orig_channel
->uri
->window_ref
)
2545 window
= orig_channel
->uri
->window_ref
->window
;
2546 nsres
= create_nsuri(iuri
, NULL
, window
, NULL
, &uri
);
2548 if(NS_FAILED(nsres
))
2551 nsres
= create_nschannel(uri
, &channel
);
2552 nsIURL_Release(&uri
->nsIURL_iface
);
2553 if(NS_FAILED(nsres
))
2556 if(orig_channel
->load_group
) {
2557 nsILoadGroup_AddRef(orig_channel
->load_group
);
2558 channel
->load_group
= orig_channel
->load_group
;
2561 if(orig_channel
->notif_callback
) {
2562 nsIInterfaceRequestor_AddRef(orig_channel
->notif_callback
);
2563 channel
->notif_callback
= orig_channel
->notif_callback
;
2566 channel
->load_flags
= orig_channel
->load_flags
| LOAD_REPLACE
;
2568 if(orig_channel
->request_method
== METHOD_POST
)
2569 FIXME("unsupported POST method\n");
2571 if(orig_channel
->original_uri
) {
2572 nsIURI_AddRef(orig_channel
->original_uri
);
2573 channel
->original_uri
= orig_channel
->original_uri
;
2576 if(orig_channel
->referrer
) {
2577 nsIURI_AddRef(orig_channel
->referrer
);
2578 channel
->referrer
= orig_channel
->referrer
;
2586 nsIProtocolHandler nsIProtocolHandler_iface
;
2590 nsIProtocolHandler
*nshandler
;
2591 } nsProtocolHandler
;
2593 static inline nsProtocolHandler
*impl_from_nsIProtocolHandler(nsIProtocolHandler
*iface
)
2595 return CONTAINING_RECORD(iface
, nsProtocolHandler
, nsIProtocolHandler_iface
);
2598 static nsresult NSAPI
nsProtocolHandler_QueryInterface(nsIProtocolHandler
*iface
, nsIIDRef riid
,
2601 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2605 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
2606 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
2607 *result
= &This
->nsIProtocolHandler_iface
;
2608 }else if(IsEqualGUID(&IID_nsIProtocolHandler
, riid
)) {
2609 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This
, result
);
2610 *result
= &This
->nsIProtocolHandler_iface
;
2611 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler
, riid
)) {
2612 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This
, result
);
2613 return NS_NOINTERFACE
;
2617 nsISupports_AddRef((nsISupports
*)*result
);
2621 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
2622 return NS_NOINTERFACE
;
2625 static nsrefcnt NSAPI
nsProtocolHandler_AddRef(nsIProtocolHandler
*iface
)
2627 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2628 LONG ref
= InterlockedIncrement(&This
->ref
);
2630 TRACE("(%p) ref=%d\n", This
, ref
);
2635 static nsrefcnt NSAPI
nsProtocolHandler_Release(nsIProtocolHandler
*iface
)
2637 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2638 LONG ref
= InterlockedDecrement(&This
->ref
);
2640 TRACE("(%p) ref=%d\n", This
, ref
);
2644 nsIProtocolHandler_Release(This
->nshandler
);
2651 static nsresult NSAPI
nsProtocolHandler_GetScheme(nsIProtocolHandler
*iface
, nsACString
*aScheme
)
2653 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2655 TRACE("(%p)->(%p)\n", This
, aScheme
);
2658 return nsIProtocolHandler_GetScheme(This
->nshandler
, aScheme
);
2659 return NS_ERROR_NOT_IMPLEMENTED
;
2662 static nsresult NSAPI
nsProtocolHandler_GetDefaultPort(nsIProtocolHandler
*iface
,
2663 PRInt32
*aDefaultPort
)
2665 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2667 TRACE("(%p)->(%p)\n", This
, aDefaultPort
);
2670 return nsIProtocolHandler_GetDefaultPort(This
->nshandler
, aDefaultPort
);
2671 return NS_ERROR_NOT_IMPLEMENTED
;
2674 static nsresult NSAPI
nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler
*iface
,
2675 PRUint32
*aProtocolFlags
)
2677 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2679 TRACE("(%p)->(%p)\n", This
, aProtocolFlags
);
2682 return nsIProtocolHandler_GetProtocolFlags(This
->nshandler
, aProtocolFlags
);
2683 return NS_ERROR_NOT_IMPLEMENTED
;
2686 static nsresult NSAPI
nsProtocolHandler_NewURI(nsIProtocolHandler
*iface
,
2687 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
2689 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2691 TRACE("((%p)->%s %s %p %p)\n", This
, debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
2695 return nsIProtocolHandler_NewURI(This
->nshandler
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2696 return NS_ERROR_NOT_IMPLEMENTED
;
2699 static nsresult NSAPI
nsProtocolHandler_NewChannel(nsIProtocolHandler
*iface
,
2700 nsIURI
*aURI
, nsIChannel
**_retval
)
2702 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2704 TRACE("(%p)->(%p %p)\n", This
, aURI
, _retval
);
2707 return nsIProtocolHandler_NewChannel(This
->nshandler
, aURI
, _retval
);
2708 return NS_ERROR_NOT_IMPLEMENTED
;
2711 static nsresult NSAPI
nsProtocolHandler_AllowPort(nsIProtocolHandler
*iface
,
2712 PRInt32 port
, const char *scheme
, PRBool
*_retval
)
2714 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2716 TRACE("(%p)->(%d %s %p)\n", This
, port
, debugstr_a(scheme
), _retval
);
2719 return nsIProtocolHandler_AllowPort(This
->nshandler
, port
, scheme
, _retval
);
2720 return NS_ERROR_NOT_IMPLEMENTED
;
2723 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl
= {
2724 nsProtocolHandler_QueryInterface
,
2725 nsProtocolHandler_AddRef
,
2726 nsProtocolHandler_Release
,
2727 nsProtocolHandler_GetScheme
,
2728 nsProtocolHandler_GetDefaultPort
,
2729 nsProtocolHandler_GetProtocolFlags
,
2730 nsProtocolHandler_NewURI
,
2731 nsProtocolHandler_NewChannel
,
2732 nsProtocolHandler_AllowPort
2735 static nsIProtocolHandler
*create_protocol_handler(nsIProtocolHandler
*nshandler
)
2737 nsProtocolHandler
*ret
= heap_alloc(sizeof(nsProtocolHandler
));
2739 ret
->nsIProtocolHandler_iface
.lpVtbl
= &nsProtocolHandlerVtbl
;
2741 ret
->nshandler
= nshandler
;
2743 return &ret
->nsIProtocolHandler_iface
;
2746 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*,nsIIDRef
,void**);
2748 static nsrefcnt NSAPI
nsIOService_AddRef(nsIIOService
*iface
)
2753 static nsrefcnt NSAPI
nsIOService_Release(nsIIOService
*iface
)
2758 static nsresult NSAPI
nsIOService_GetProtocolHandler(nsIIOService
*iface
, const char *aScheme
,
2759 nsIProtocolHandler
**_retval
)
2761 nsIExternalProtocolHandler
*nsexthandler
;
2762 nsIProtocolHandler
*nshandler
;
2765 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
2767 nsres
= nsIIOService_GetProtocolHandler(nsio
, aScheme
, &nshandler
);
2768 if(NS_FAILED(nsres
)) {
2769 WARN("GetProtocolHandler failed: %08x\n", nsres
);
2773 nsres
= nsIProtocolHandler_QueryInterface(nshandler
, &IID_nsIExternalProtocolHandler
,
2774 (void**)&nsexthandler
);
2775 if(NS_FAILED(nsres
)) {
2776 *_retval
= nshandler
;
2780 nsIExternalProtocolHandler_Release(nsexthandler
);
2781 *_retval
= create_protocol_handler(nshandler
);
2782 TRACE("return %p\n", *_retval
);
2786 static nsresult NSAPI
nsIOService_GetProtocolFlags(nsIIOService
*iface
, const char *aScheme
,
2789 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
2790 return nsIIOService_GetProtocolFlags(nsio
, aScheme
, _retval
);
2793 static BOOL
is_gecko_special_uri(const char *spec
)
2795 static const char *special_schemes
[] = {"chrome:", "jar:", "moz-safe-about", "resource:", "javascript:", "wyciwyg:"};
2798 for(i
=0; i
< sizeof(special_schemes
)/sizeof(*special_schemes
); i
++) {
2799 if(!strncasecmp(spec
, special_schemes
[i
], strlen(special_schemes
[i
])))
2803 if(!strncasecmp(spec
, "file:", 5)) {
2804 const char *ptr
= spec
+5;
2807 return is_gecko_path(ptr
);
2813 static nsresult NSAPI
nsIOService_NewURI(nsIIOService
*iface
, const nsACString
*aSpec
,
2814 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
2816 nsWineURI
*wine_uri
, *base_wine_uri
= NULL
;
2817 WCHAR new_spec
[INTERNET_MAX_URL_LENGTH
];
2818 HTMLWindow
*window
= NULL
;
2819 const char *spec
= NULL
;
2825 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
2828 nsACString_GetData(aSpec
, &spec
);
2829 if(is_gecko_special_uri(spec
))
2830 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2832 if(!strncmp(spec
, "wine:", 5))
2836 nsres
= nsIURI_QueryInterface(aBaseURI
, &IID_nsWineURI
, (void**)&base_wine_uri
);
2837 if(NS_SUCCEEDED(nsres
)) {
2838 if(!ensure_uri(base_wine_uri
))
2839 return NS_ERROR_UNEXPECTED
;
2840 if(base_wine_uri
->window_ref
)
2841 window
= base_wine_uri
->window_ref
->window
;
2843 WARN("Could not get base nsWineURI: %08x\n", nsres
);
2847 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, new_spec
, sizeof(new_spec
)/sizeof(WCHAR
));
2850 hres
= CoInternetCombineUrlEx(base_wine_uri
->uri
, new_spec
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
2853 WARN("CoInternetCombineUrlEx failed: %08x\n", hres
);
2855 hres
= CreateUri(new_spec
, 0, 0, &urlmon_uri
);
2857 WARN("CreateUri failed: %08x\n", hres
);
2860 nsres
= nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, &uri
);
2861 if(NS_FAILED(nsres
))
2862 TRACE("NewURI failed: %08x\n", nsres
);
2869 nsres
= create_nsuri(urlmon_uri
, uri
, window
, NULL
, &wine_uri
);
2870 IUri_Release(urlmon_uri
);
2872 nsIURI_Release(&base_wine_uri
->nsIURL_iface
);
2873 if(NS_FAILED(nsres
))
2876 *_retval
= (nsIURI
*)&wine_uri
->nsIURL_iface
;
2880 static nsresult NSAPI
nsIOService_NewFileURI(nsIIOService
*iface
, nsIFile
*aFile
,
2883 TRACE("(%p %p)\n", aFile
, _retval
);
2884 return nsIIOService_NewFileURI(nsio
, aFile
, _retval
);
2887 static nsresult NSAPI
nsIOService_NewChannelFromURI(nsIIOService
*iface
, nsIURI
*aURI
,
2888 nsIChannel
**_retval
)
2890 nsWineURI
*wine_uri
;
2894 TRACE("(%p %p)\n", aURI
, _retval
);
2896 nsres
= nsIURI_QueryInterface(aURI
, &IID_nsWineURI
, (void**)&wine_uri
);
2897 if(NS_FAILED(nsres
)) {
2898 TRACE("Could not get nsWineURI: %08x\n", nsres
);
2899 return nsIIOService_NewChannelFromURI(nsio
, aURI
, _retval
);
2902 nsres
= create_nschannel(wine_uri
, &ret
);
2903 nsIURL_Release(&wine_uri
->nsIURL_iface
);
2904 if(NS_FAILED(nsres
))
2907 nsIURI_AddRef(aURI
);
2908 ret
->original_uri
= aURI
;
2910 *_retval
= (nsIChannel
*)&ret
->nsIHttpChannel_iface
;
2914 static nsresult NSAPI
nsIOService_NewChannel(nsIIOService
*iface
, const nsACString
*aSpec
,
2915 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIChannel
**_retval
)
2917 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
), aBaseURI
, _retval
);
2918 return nsIIOService_NewChannel(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2921 static nsresult NSAPI
nsIOService_GetOffline(nsIIOService
*iface
, PRBool
*aOffline
)
2923 TRACE("(%p)\n", aOffline
);
2924 return nsIIOService_GetOffline(nsio
, aOffline
);
2927 static nsresult NSAPI
nsIOService_SetOffline(nsIIOService
*iface
, PRBool aOffline
)
2929 TRACE("(%x)\n", aOffline
);
2930 return nsIIOService_SetOffline(nsio
, aOffline
);
2933 static nsresult NSAPI
nsIOService_AllowPort(nsIIOService
*iface
, PRInt32 aPort
,
2934 const char *aScheme
, PRBool
*_retval
)
2936 TRACE("(%d %s %p)\n", aPort
, debugstr_a(aScheme
), _retval
);
2937 return nsIIOService_AllowPort(nsio
, aPort
, debugstr_a(aScheme
), _retval
);
2940 static nsresult NSAPI
nsIOService_ExtractScheme(nsIIOService
*iface
, const nsACString
*urlString
,
2941 nsACString
* _retval
)
2943 TRACE("(%s %p)\n", debugstr_nsacstr(urlString
), _retval
);
2944 return nsIIOService_ExtractScheme(nsio
, urlString
, _retval
);
2947 static const nsIIOServiceVtbl nsIOServiceVtbl
= {
2948 nsIOService_QueryInterface
,
2950 nsIOService_Release
,
2951 nsIOService_GetProtocolHandler
,
2952 nsIOService_GetProtocolFlags
,
2954 nsIOService_NewFileURI
,
2955 nsIOService_NewChannelFromURI
,
2956 nsIOService_NewChannel
,
2957 nsIOService_GetOffline
,
2958 nsIOService_SetOffline
,
2959 nsIOService_AllowPort
,
2960 nsIOService_ExtractScheme
2963 static nsIIOService nsIOService
= { &nsIOServiceVtbl
};
2965 static nsresult NSAPI
nsNetUtil_QueryInterface(nsINetUtil
*iface
, nsIIDRef riid
,
2968 return nsIIOService_QueryInterface(&nsIOService
, riid
, result
);
2971 static nsrefcnt NSAPI
nsNetUtil_AddRef(nsINetUtil
*iface
)
2976 static nsrefcnt NSAPI
nsNetUtil_Release(nsINetUtil
*iface
)
2981 static nsresult NSAPI
nsNetUtil_ParseContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
2982 nsACString
*aCharset
, PRBool
*aHadCharset
, nsACString
*aContentType
)
2984 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aHadCharset
, aContentType
);
2986 return nsINetUtil_ParseContentType(net_util
, aTypeHeader
, aCharset
, aHadCharset
, aContentType
);
2989 static nsresult NSAPI
nsNetUtil_ProtocolHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, PRUint32 aFlags
, PRBool
*_retval
)
2993 return nsINetUtil_ProtocolHasFlags(net_util
, aURI
, aFlags
, _retval
);
2996 static nsresult NSAPI
nsNetUtil_URIChainHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, PRUint32 aFlags
, PRBool
*_retval
)
2998 TRACE("(%p %08x %p)\n", aURI
, aFlags
, _retval
);
3000 if(aFlags
== (1<<11)) {
3005 return nsINetUtil_URIChainHasFlags(net_util
, aURI
, aFlags
, _retval
);
3008 static nsresult NSAPI
nsNetUtil_ToImmutableURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
3010 TRACE("(%p %p)\n", aURI
, _retval
);
3012 return nsINetUtil_ToImmutableURI(net_util
, aURI
, _retval
);
3015 static nsresult NSAPI
nsNetUtil_NewSimpleNestedURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
3017 TRACE("(%p %p)\n", aURI
, _retval
);
3019 return nsINetUtil_NewSimpleNestedURI(net_util
, aURI
, _retval
);
3022 static nsresult NSAPI
nsNetUtil_EscapeString(nsINetUtil
*iface
, const nsACString
*aString
,
3023 PRUint32 aEscapeType
, nsACString
*_retval
)
3025 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString
), aEscapeType
, _retval
);
3027 return nsINetUtil_EscapeString(net_util
, aString
, aEscapeType
, _retval
);
3030 static nsresult NSAPI
nsNetUtil_EscapeURL(nsINetUtil
*iface
, const nsACString
*aStr
, PRUint32 aFlags
,
3031 nsACString
*_retval
)
3033 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
3035 return nsINetUtil_EscapeURL(net_util
, aStr
, aFlags
, _retval
);
3038 static nsresult NSAPI
nsNetUtil_UnescapeString(nsINetUtil
*iface
, const nsACString
*aStr
,
3039 PRUint32 aFlags
, nsACString
*_retval
)
3041 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
3043 return nsINetUtil_UnescapeString(net_util
, aStr
, aFlags
, _retval
);
3046 static nsresult NSAPI
nsNetUtil_ExtractCharsetFromContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
3047 nsACString
*aCharset
, PRInt32
*aCharsetStart
, PRInt32
*aCharsetEnd
, PRBool
*_retval
)
3049 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aCharsetStart
,
3050 aCharsetEnd
, _retval
);
3052 return nsINetUtil_ExtractCharsetFromContentType(net_util
, aTypeHeader
, aCharset
, aCharsetStart
, aCharsetEnd
, _retval
);
3055 static const nsINetUtilVtbl nsNetUtilVtbl
= {
3056 nsNetUtil_QueryInterface
,
3059 nsNetUtil_ParseContentType
,
3060 nsNetUtil_ProtocolHasFlags
,
3061 nsNetUtil_URIChainHasFlags
,
3062 nsNetUtil_ToImmutableURI
,
3063 nsNetUtil_NewSimpleNestedURI
,
3064 nsNetUtil_EscapeString
,
3065 nsNetUtil_EscapeURL
,
3066 nsNetUtil_UnescapeString
,
3067 nsNetUtil_ExtractCharsetFromContentType
3070 static nsINetUtil nsNetUtil
= { &nsNetUtilVtbl
};
3072 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*iface
, nsIIDRef riid
,
3077 if(IsEqualGUID(&IID_nsISupports
, riid
))
3078 *result
= &nsIOService
;
3079 else if(IsEqualGUID(&IID_nsIIOService
, riid
))
3080 *result
= &nsIOService
;
3081 else if(IsEqualGUID(&IID_nsINetUtil
, riid
))
3082 *result
= &nsNetUtil
;
3085 nsISupports_AddRef((nsISupports
*)*result
);
3089 FIXME("(%s %p)\n", debugstr_guid(riid
), result
);
3090 return NS_NOINTERFACE
;
3093 static nsresult NSAPI
nsIOServiceFactory_QueryInterface(nsIFactory
*iface
, nsIIDRef riid
,
3098 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
3099 TRACE("(IID_nsISupports %p)\n", result
);
3101 }else if(IsEqualGUID(&IID_nsIFactory
, riid
)) {
3102 TRACE("(IID_nsIFactory %p)\n", result
);
3107 nsIFactory_AddRef(iface
);
3111 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
3112 return NS_NOINTERFACE
;
3115 static nsrefcnt NSAPI
nsIOServiceFactory_AddRef(nsIFactory
*iface
)
3120 static nsrefcnt NSAPI
nsIOServiceFactory_Release(nsIFactory
*iface
)
3125 static nsresult NSAPI
nsIOServiceFactory_CreateInstance(nsIFactory
*iface
,
3126 nsISupports
*aOuter
, const nsIID
*iid
, void **result
)
3128 return nsIIOService_QueryInterface(&nsIOService
, iid
, result
);
3131 static nsresult NSAPI
nsIOServiceFactory_LockFactory(nsIFactory
*iface
, PRBool lock
)
3133 WARN("(%x)\n", lock
);
3137 static const nsIFactoryVtbl nsIOServiceFactoryVtbl
= {
3138 nsIOServiceFactory_QueryInterface
,
3139 nsIOServiceFactory_AddRef
,
3140 nsIOServiceFactory_Release
,
3141 nsIOServiceFactory_CreateInstance
,
3142 nsIOServiceFactory_LockFactory
3145 static nsIFactory nsIOServiceFactory
= { &nsIOServiceFactoryVtbl
};
3147 static BOOL
translate_url(HTMLDocumentObj
*doc
, nsWineURI
*uri
)
3149 OLECHAR
*new_url
= NULL
;
3154 if(!doc
->hostui
|| !ensure_uri(uri
))
3157 hres
= IUri_GetDisplayUri(uri
->uri
, &url
);
3161 hres
= IDocHostUIHandler_TranslateUrl(doc
->hostui
, 0, url
, &new_url
);
3162 if(hres
== S_OK
&& new_url
) {
3163 if(strcmpW(url
, new_url
)) {
3164 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url
), debugstr_w(new_url
));
3167 CoTaskMemFree(new_url
);
3174 nsresult
on_start_uri_open(NSContainer
*nscontainer
, nsIURI
*uri
, PRBool
*_retval
)
3176 nsWineURI
*wine_uri
;
3181 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
3182 if(NS_FAILED(nsres
)) {
3183 WARN("Could not get nsWineURI: %08x\n", nsres
);
3184 return NS_ERROR_NOT_IMPLEMENTED
;
3187 if(!wine_uri
->is_doc_uri
) {
3188 wine_uri
->is_doc_uri
= TRUE
;
3190 if(!wine_uri
->container
) {
3191 nsIWebBrowserChrome_AddRef(&nscontainer
->nsIWebBrowserChrome_iface
);
3192 wine_uri
->container
= nscontainer
;
3195 if(nscontainer
->doc
)
3196 *_retval
= translate_url(nscontainer
->doc
, wine_uri
);
3199 nsIURI_Release(&wine_uri
->nsIURL_iface
);
3203 void init_nsio(nsIComponentManager
*component_manager
, nsIComponentRegistrar
*registrar
)
3205 nsIFactory
*old_factory
= NULL
;
3208 nsres
= nsIComponentManager_GetClassObject(component_manager
, &NS_IOSERVICE_CID
,
3209 &IID_nsIFactory
, (void**)&old_factory
);
3210 if(NS_FAILED(nsres
)) {
3211 ERR("Could not get factory: %08x\n", nsres
);
3215 nsres
= nsIFactory_CreateInstance(old_factory
, NULL
, &IID_nsIIOService
, (void**)&nsio
);
3216 if(NS_FAILED(nsres
)) {
3217 ERR("Couldn not create nsIOService instance %08x\n", nsres
);
3218 nsIFactory_Release(old_factory
);
3222 nsres
= nsIIOService_QueryInterface(nsio
, &IID_nsINetUtil
, (void**)&net_util
);
3223 if(NS_FAILED(nsres
)) {
3224 WARN("Could not get nsINetUtil interface: %08x\n", nsres
);
3225 nsIIOService_Release(nsio
);
3229 nsres
= nsIComponentRegistrar_UnregisterFactory(registrar
, &NS_IOSERVICE_CID
, old_factory
);
3230 nsIFactory_Release(old_factory
);
3231 if(NS_FAILED(nsres
))
3232 ERR("UnregisterFactory failed: %08x\n", nsres
);
3234 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_IOSERVICE_CID
,
3235 NS_IOSERVICE_CLASSNAME
, NS_IOSERVICE_CONTRACTID
, &nsIOServiceFactory
);
3236 if(NS_FAILED(nsres
))
3237 ERR("RegisterFactory failed: %08x\n", nsres
);
3240 void release_nsio(void)
3243 nsINetUtil_Release(net_util
);
3248 nsIIOService_Release(nsio
);