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
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
37 #include "mshtml_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
41 #define NS_IOSERVICE_CLASSNAME "nsIOService"
42 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
44 static const IID NS_IOSERVICE_CID
=
45 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
46 static const IID IID_nsWineURI
=
47 {0x5088272e, 0x900b, 0x11da, {0xc6,0x87, 0x00,0x0f,0xea,0x57,0xf2,0x1a}};
49 static nsIIOService
*nsio
= NULL
;
50 static nsINetUtil
*net_util
;
52 static const WCHAR about_blankW
[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
54 static const char *request_method_strings
[] = {"GET", "PUT", "POST"};
63 NSContainer
*container
;
64 windowref_t
*window_ref
;
65 nsChannelBSC
*channel_bsc
;
68 IUriBuilder
*uri_builder
;
72 static nsresult
create_uri(nsIURI
*,HTMLWindow
*,NSContainer
*,nsWineURI
**);
74 static const char *debugstr_nsacstr(const nsACString
*nsstr
)
78 nsACString_GetData(nsstr
, &data
);
79 return debugstr_a(data
);
82 HRESULT
nsuri_to_url(LPCWSTR nsuri
, BOOL ret_empty
, BSTR
*ret
)
84 const WCHAR
*ptr
= nsuri
;
86 static const WCHAR wine_prefixW
[] = {'w','i','n','e',':'};
88 if(!strncmpW(nsuri
, wine_prefixW
, sizeof(wine_prefixW
)/sizeof(WCHAR
)))
89 ptr
+= sizeof(wine_prefixW
)/sizeof(WCHAR
);
91 if(*ptr
|| ret_empty
) {
92 *ret
= SysAllocString(ptr
);
99 TRACE("%s -> %s\n", debugstr_w(nsuri
), debugstr_w(*ret
));
103 static BOOL
exec_shldocvw_67(HTMLDocumentObj
*doc
, LPCWSTR url
)
105 IOleCommandTarget
*cmdtrg
= NULL
;
108 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
109 if(SUCCEEDED(hres
)) {
110 VARIANT varUrl
, varRes
;
112 V_VT(&varUrl
) = VT_BSTR
;
113 V_BSTR(&varUrl
) = SysAllocString(url
);
114 V_VT(&varRes
) = VT_BOOL
;
116 hres
= IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 67, 0, &varUrl
, &varRes
);
118 IOleCommandTarget_Release(cmdtrg
);
119 SysFreeString(V_BSTR(&varUrl
));
121 if(SUCCEEDED(hres
) && !V_BOOL(&varRes
)) {
122 TRACE("got VARIANT_FALSE, do not load\n");
130 static BOOL
before_async_open(nsChannel
*channel
, NSContainer
*container
)
132 HTMLDocumentObj
*doc
= container
->doc
;
138 NSContainer
*container_iter
= container
;
140 hlnf
= HLNF_OPENINNEWWINDOW
;
141 while(!container_iter
->doc
)
142 container_iter
= container_iter
->parent
;
143 doc
= container_iter
->doc
;
149 if(!hlnf
&& !exec_shldocvw_67(doc
, channel
->uri
->wine_url
))
152 hres
= hlink_frame_navigate(&doc
->basedoc
, channel
->uri
->wine_url
, channel
, hlnf
, &cancel
);
153 return FAILED(hres
) || cancel
;
156 HRESULT
load_nsuri(HTMLWindow
*window
, nsWineURI
*uri
, nsChannelBSC
*channelbsc
, DWORD flags
)
158 nsIWebNavigation
*web_navigation
;
159 nsIDocShell
*doc_shell
;
160 HTMLDocumentNode
*doc
;
163 nsres
= get_nsinterface((nsISupports
*)window
->nswindow
, &IID_nsIWebNavigation
, (void**)&web_navigation
);
164 if(NS_FAILED(nsres
)) {
165 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
169 nsres
= nsIWebNavigation_QueryInterface(web_navigation
, &IID_nsIDocShell
, (void**)&doc_shell
);
170 nsIWebNavigation_Release(web_navigation
);
171 if(NS_FAILED(nsres
)) {
172 ERR("Could not get nsIDocShell: %08x\n", nsres
);
176 uri
->channel_bsc
= channelbsc
;
178 doc
->skip_mutation_notif
= TRUE
;
179 nsres
= nsIDocShell_LoadURI(doc_shell
, (nsIURI
*)&uri
->nsIURL_iface
, NULL
, flags
, FALSE
);
180 if(doc
== window
->doc
)
181 doc
->skip_mutation_notif
= FALSE
;
182 uri
->channel_bsc
= NULL
;
183 nsIDocShell_Release(doc_shell
);
184 if(NS_FAILED(nsres
)) {
185 WARN("LoadURI failed: %08x\n", nsres
);
192 static HRESULT
set_wine_url(nsWineURI
*This
, LPCWSTR url
)
194 TRACE("(%p)->(%s)\n", This
, debugstr_w(url
));
199 new_url
= SysAllocString(url
);
201 return E_OUTOFMEMORY
;
202 SysFreeString(This
->wine_url
);
203 This
->wine_url
= new_url
;
205 heap_free(This
->wine_url
);
206 This
->wine_url
= NULL
;
212 static void set_uri_nscontainer(nsWineURI
*This
, NSContainer
*nscontainer
)
214 if(This
->container
) {
215 if(This
->container
== nscontainer
)
217 TRACE("Changing %p -> %p\n", This
->container
, nscontainer
);
218 nsIWebBrowserChrome_Release(&This
->container
->nsIWebBrowserChrome_iface
);
222 nsIWebBrowserChrome_AddRef(&nscontainer
->nsIWebBrowserChrome_iface
);
223 This
->container
= nscontainer
;
226 static void set_uri_window(nsWineURI
*This
, HTMLWindow
*window
)
228 if(This
->window_ref
) {
229 if(This
->window_ref
->window
== window
)
231 TRACE("Changing %p -> %p\n", This
->window_ref
->window
, window
);
232 windowref_release(This
->window_ref
);
236 windowref_addref(window
->window_ref
);
237 This
->window_ref
= window
->window_ref
;
240 set_uri_nscontainer(This
, window
->doc_obj
->nscontainer
);
242 This
->window_ref
= NULL
;
246 static inline BOOL
is_http_channel(nsChannel
*This
)
248 return This
->url_scheme
== URL_SCHEME_HTTP
|| This
->url_scheme
== URL_SCHEME_HTTPS
;
251 static http_header_t
*find_http_header(struct list
*headers
, const WCHAR
*name
, int len
)
255 LIST_FOR_EACH_ENTRY(iter
, headers
, http_header_t
, entry
) {
256 if(!strcmpiW(iter
->header
, name
))
263 static nsresult
get_channel_http_header(struct list
*headers
, const nsACString
*header_name_str
,
266 const char *header_namea
;
267 http_header_t
*header
;
271 nsACString_GetData(header_name_str
, &header_namea
);
272 header_name
= heap_strdupAtoW(header_namea
);
274 return NS_ERROR_UNEXPECTED
;
276 header
= find_http_header(headers
, header_name
, strlenW(header_name
));
277 heap_free(header_name
);
279 return NS_ERROR_NOT_AVAILABLE
;
281 data
= heap_strdupWtoA(header
->data
);
283 return NS_ERROR_UNEXPECTED
;
285 nsACString_SetData(_retval
, data
);
290 HRESULT
set_http_header(struct list
*headers
, const WCHAR
*name
, int name_len
,
291 const WCHAR
*value
, int value_len
)
293 http_header_t
*header
;
295 TRACE("%s: %s\n", debugstr_wn(name
, name_len
), debugstr_wn(value
, value_len
));
297 header
= find_http_header(headers
, name
, name_len
);
301 new_data
= heap_strndupW(value
, value_len
);
303 return E_OUTOFMEMORY
;
305 heap_free(header
->data
);
306 header
->data
= new_data
;
308 header
= heap_alloc(sizeof(http_header_t
));
310 return E_OUTOFMEMORY
;
312 header
->header
= heap_strndupW(name
, name_len
);
313 header
->data
= heap_strndupW(value
, value_len
);
314 if(!header
->header
|| !header
->data
) {
315 heap_free(header
->header
);
316 heap_free(header
->data
);
318 return E_OUTOFMEMORY
;
321 list_add_tail(headers
, &header
->entry
);
327 static nsresult
set_channel_http_header(struct list
*headers
, const nsACString
*name_str
,
328 const nsACString
*value_str
)
330 const char *namea
, *valuea
;
334 nsACString_GetData(name_str
, &namea
);
335 name
= heap_strdupAtoW(namea
);
337 return NS_ERROR_UNEXPECTED
;
339 nsACString_GetData(value_str
, &valuea
);
340 value
= heap_strdupAtoW(valuea
);
343 return NS_ERROR_UNEXPECTED
;
346 hres
= set_http_header(headers
, name
, strlenW(name
), value
, strlenW(value
));
350 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_UNEXPECTED
;
353 static nsresult
visit_http_headers(struct list
*headers
, nsIHttpHeaderVisitor
*visitor
)
355 nsACString header_str
, value_str
;
356 char *header
, *value
;
360 LIST_FOR_EACH_ENTRY(iter
, headers
, http_header_t
, entry
) {
361 header
= heap_strdupWtoA(iter
->header
);
363 return NS_ERROR_OUT_OF_MEMORY
;
365 value
= heap_strdupWtoA(iter
->data
);
368 return NS_ERROR_OUT_OF_MEMORY
;
371 nsACString_InitDepend(&header_str
, header
);
372 nsACString_InitDepend(&value_str
, value
);
373 nsres
= nsIHttpHeaderVisitor_VisitHeader(visitor
, &header_str
, &value_str
);
374 nsACString_Finish(&header_str
);
375 nsACString_Finish(&value_str
);
385 static void free_http_headers(struct list
*list
)
387 http_header_t
*iter
, *iter_next
;
389 LIST_FOR_EACH_ENTRY_SAFE(iter
, iter_next
, list
, http_header_t
, entry
) {
390 list_remove(&iter
->entry
);
391 heap_free(iter
->header
);
392 heap_free(iter
->data
);
397 static inline nsChannel
*impl_from_nsIHttpChannel(nsIHttpChannel
*iface
)
399 return CONTAINING_RECORD(iface
, nsChannel
, nsIHttpChannel_iface
);
402 static nsresult NSAPI
nsChannel_QueryInterface(nsIHttpChannel
*iface
, nsIIDRef riid
, void **result
)
404 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
406 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
407 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
408 *result
= &This
->nsIHttpChannel_iface
;
409 }else if(IsEqualGUID(&IID_nsIRequest
, riid
)) {
410 TRACE("(%p)->(IID_nsIRequest %p)\n", This
, result
);
411 *result
= &This
->nsIHttpChannel_iface
;
412 }else if(IsEqualGUID(&IID_nsIChannel
, riid
)) {
413 TRACE("(%p)->(IID_nsIChannel %p)\n", This
, result
);
414 *result
= &This
->nsIHttpChannel_iface
;
415 }else if(IsEqualGUID(&IID_nsIHttpChannel
, riid
)) {
416 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This
, result
);
417 *result
= is_http_channel(This
) ? &This
->nsIHttpChannel_iface
: NULL
;
418 }else if(IsEqualGUID(&IID_nsIUploadChannel
, riid
)) {
419 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This
, result
);
420 *result
= &This
->nsIUploadChannel_iface
;
421 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal
, riid
)) {
422 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This
, result
);
423 *result
= is_http_channel(This
) ? &This
->nsIHttpChannelInternal_iface
: NULL
;
425 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
430 nsIChannel_AddRef(&This
->nsIHttpChannel_iface
);
434 return NS_NOINTERFACE
;
437 static nsrefcnt NSAPI
nsChannel_AddRef(nsIHttpChannel
*iface
)
439 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
440 nsrefcnt ref
= InterlockedIncrement(&This
->ref
);
442 TRACE("(%p) ref=%d\n", This
, ref
);
447 static nsrefcnt NSAPI
nsChannel_Release(nsIHttpChannel
*iface
)
449 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
450 LONG ref
= InterlockedDecrement(&This
->ref
);
453 nsIURI_Release(&This
->uri
->nsIURL_iface
);
455 nsISupports_Release(This
->owner
);
456 if(This
->post_data_stream
)
457 nsIInputStream_Release(This
->post_data_stream
);
459 nsILoadGroup_Release(This
->load_group
);
460 if(This
->notif_callback
)
461 nsIInterfaceRequestor_Release(This
->notif_callback
);
462 if(This
->original_uri
)
463 nsIURI_Release(This
->original_uri
);
465 nsIURI_Release(This
->referrer
);
467 free_http_headers(&This
->response_headers
);
468 free_http_headers(&This
->request_headers
);
470 heap_free(This
->content_type
);
471 heap_free(This
->charset
);
478 static nsresult NSAPI
nsChannel_GetName(nsIHttpChannel
*iface
, nsACString
*aName
)
480 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
482 TRACE("(%p)->(%p)\n", This
, aName
);
484 return nsIURI_GetSpec(&This
->uri
->nsIURL_iface
, aName
);
487 static nsresult NSAPI
nsChannel_IsPending(nsIHttpChannel
*iface
, PRBool
*_retval
)
489 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
491 FIXME("(%p)->(%p)\n", This
, _retval
);
493 return NS_ERROR_NOT_IMPLEMENTED
;
496 static nsresult NSAPI
nsChannel_GetStatus(nsIHttpChannel
*iface
, nsresult
*aStatus
)
498 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
500 WARN("(%p)->(%p) returning NS_OK\n", This
, aStatus
);
502 return *aStatus
= NS_OK
;
505 static nsresult NSAPI
nsChannel_Cancel(nsIHttpChannel
*iface
, nsresult aStatus
)
507 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
509 FIXME("(%p)->(%08x)\n", This
, aStatus
);
511 return NS_ERROR_NOT_IMPLEMENTED
;
514 static nsresult NSAPI
nsChannel_Suspend(nsIHttpChannel
*iface
)
516 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
518 FIXME("(%p)\n", This
);
520 return NS_ERROR_NOT_IMPLEMENTED
;
523 static nsresult NSAPI
nsChannel_Resume(nsIHttpChannel
*iface
)
525 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
527 FIXME("(%p)\n", This
);
529 return NS_ERROR_NOT_IMPLEMENTED
;
532 static nsresult NSAPI
nsChannel_GetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
**aLoadGroup
)
534 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
536 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
539 nsILoadGroup_AddRef(This
->load_group
);
541 *aLoadGroup
= This
->load_group
;
545 static nsresult NSAPI
nsChannel_SetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
*aLoadGroup
)
547 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
549 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
552 nsILoadGroup_Release(This
->load_group
);
554 nsILoadGroup_AddRef(aLoadGroup
);
555 This
->load_group
= aLoadGroup
;
560 static nsresult NSAPI
nsChannel_GetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags
*aLoadFlags
)
562 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
564 TRACE("(%p)->(%p)\n", This
, aLoadFlags
);
566 *aLoadFlags
= This
->load_flags
;
570 static nsresult NSAPI
nsChannel_SetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags aLoadFlags
)
572 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
574 TRACE("(%p)->(%08x)\n", This
, aLoadFlags
);
576 This
->load_flags
= aLoadFlags
;
580 static nsresult NSAPI
nsChannel_GetOriginalURI(nsIHttpChannel
*iface
, nsIURI
**aOriginalURI
)
582 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
584 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
586 if(This
->original_uri
)
587 nsIURI_AddRef(This
->original_uri
);
589 *aOriginalURI
= This
->original_uri
;
593 static nsresult NSAPI
nsChannel_SetOriginalURI(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_Release(This
->original_uri
);
602 nsIURI_AddRef(aOriginalURI
);
603 This
->original_uri
= aOriginalURI
;
607 static nsresult NSAPI
nsChannel_GetURI(nsIHttpChannel
*iface
, nsIURI
**aURI
)
609 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
611 TRACE("(%p)->(%p)\n", This
, aURI
);
613 nsIURI_AddRef(&This
->uri
->nsIURL_iface
);
614 *aURI
= (nsIURI
*)This
->uri
;
619 static nsresult NSAPI
nsChannel_GetOwner(nsIHttpChannel
*iface
, nsISupports
**aOwner
)
621 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
623 TRACE("(%p)->(%p)\n", This
, aOwner
);
626 nsISupports_AddRef(This
->owner
);
627 *aOwner
= This
->owner
;
632 static nsresult NSAPI
nsChannel_SetOwner(nsIHttpChannel
*iface
, nsISupports
*aOwner
)
634 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
636 TRACE("(%p)->(%p)\n", This
, aOwner
);
639 nsISupports_AddRef(aOwner
);
641 nsISupports_Release(This
->owner
);
642 This
->owner
= aOwner
;
647 static nsresult NSAPI
nsChannel_GetNotificationCallbacks(nsIHttpChannel
*iface
,
648 nsIInterfaceRequestor
**aNotificationCallbacks
)
650 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
652 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
654 if(This
->notif_callback
)
655 nsIInterfaceRequestor_AddRef(This
->notif_callback
);
656 *aNotificationCallbacks
= This
->notif_callback
;
661 static nsresult NSAPI
nsChannel_SetNotificationCallbacks(nsIHttpChannel
*iface
,
662 nsIInterfaceRequestor
*aNotificationCallbacks
)
664 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
666 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
668 if(This
->notif_callback
)
669 nsIInterfaceRequestor_Release(This
->notif_callback
);
670 if(aNotificationCallbacks
)
671 nsIInterfaceRequestor_AddRef(aNotificationCallbacks
);
673 This
->notif_callback
= aNotificationCallbacks
;
678 static nsresult NSAPI
nsChannel_GetSecurityInfo(nsIHttpChannel
*iface
, nsISupports
**aSecurityInfo
)
680 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
682 TRACE("(%p)->(%p)\n", This
, aSecurityInfo
);
684 return NS_ERROR_NOT_IMPLEMENTED
;
687 static nsresult NSAPI
nsChannel_GetContentType(nsIHttpChannel
*iface
, nsACString
*aContentType
)
689 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
691 TRACE("(%p)->(%p)\n", This
, aContentType
);
693 if(This
->content_type
) {
694 nsACString_SetData(aContentType
, This
->content_type
);
698 WARN("unknown type\n");
699 return NS_ERROR_FAILURE
;
702 static nsresult NSAPI
nsChannel_SetContentType(nsIHttpChannel
*iface
,
703 const nsACString
*aContentType
)
705 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
706 const char *content_type
;
708 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentType
));
710 nsACString_GetData(aContentType
, &content_type
);
711 heap_free(This
->content_type
);
712 This
->content_type
= heap_strdupA(content_type
);
717 static nsresult NSAPI
nsChannel_GetContentCharset(nsIHttpChannel
*iface
,
718 nsACString
*aContentCharset
)
720 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
722 TRACE("(%p)->(%p)\n", This
, aContentCharset
);
725 nsACString_SetData(aContentCharset
, This
->charset
);
729 nsACString_SetData(aContentCharset
, "");
733 static nsresult NSAPI
nsChannel_SetContentCharset(nsIHttpChannel
*iface
,
734 const nsACString
*aContentCharset
)
736 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
738 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentCharset
));
740 return NS_ERROR_NOT_IMPLEMENTED
;
743 static nsresult NSAPI
nsChannel_GetContentLength(nsIHttpChannel
*iface
, PRInt32
*aContentLength
)
745 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
747 FIXME("(%p)->(%p)\n", This
, aContentLength
);
749 return NS_ERROR_NOT_IMPLEMENTED
;
752 static nsresult NSAPI
nsChannel_SetContentLength(nsIHttpChannel
*iface
, PRInt32 aContentLength
)
754 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
756 FIXME("(%p)->(%d)\n", This
, aContentLength
);
758 return NS_ERROR_NOT_IMPLEMENTED
;
761 static nsresult NSAPI
nsChannel_Open(nsIHttpChannel
*iface
, nsIInputStream
**_retval
)
763 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
765 FIXME("(%p)->(%p)\n", This
, _retval
);
767 return NS_ERROR_NOT_IMPLEMENTED
;
770 static HTMLWindow
*get_window_from_load_group(nsChannel
*This
)
779 nsres
= nsILoadGroup_GetDefaultLoadRequest(This
->load_group
, &req
);
780 if(NS_FAILED(nsres
)) {
781 ERR("GetDefaultLoadRequest failed: %08x\n", nsres
);
788 nsres
= nsIRequest_QueryInterface(req
, &IID_nsIChannel
, (void**)&channel
);
789 nsIRequest_Release(req
);
790 if(NS_FAILED(nsres
)) {
791 WARN("Could not get nsIChannel interface: %08x\n", nsres
);
795 nsres
= nsIChannel_GetURI(channel
, &uri
);
796 nsIChannel_Release(channel
);
797 if(NS_FAILED(nsres
)) {
798 ERR("GetURI failed: %08x\n", nsres
);
802 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
804 if(NS_FAILED(nsres
)) {
805 TRACE("Could not get nsWineURI: %08x\n", nsres
);
809 window
= wine_uri
->window_ref
? wine_uri
->window_ref
->window
: NULL
;
811 IHTMLWindow2_AddRef(&window
->IHTMLWindow2_iface
);
812 nsIURI_Release(&wine_uri
->nsIURL_iface
);
817 static HTMLWindow
*get_channel_window(nsChannel
*This
)
819 nsIWebProgress
*web_progress
;
820 nsIDOMWindow
*nswindow
;
824 if(This
->load_group
) {
825 nsIRequestObserver
*req_observer
;
827 nsres
= nsILoadGroup_GetGroupObserver(This
->load_group
, &req_observer
);
828 if(NS_FAILED(nsres
) || !req_observer
) {
829 ERR("GetGroupObserver failed: %08x\n", nsres
);
833 nsres
= nsIRequestObserver_QueryInterface(req_observer
, &IID_nsIWebProgress
, (void**)&web_progress
);
834 nsIRequestObserver_Release(req_observer
);
835 if(NS_FAILED(nsres
)) {
836 ERR("Could not get nsIWebProgress iface: %08x\n", nsres
);
839 }else if(This
->notif_callback
) {
840 nsres
= nsIInterfaceRequestor_GetInterface(This
->notif_callback
, &IID_nsIWebProgress
, (void**)&web_progress
);
841 if(NS_FAILED(nsres
)) {
842 ERR("GetInterface(IID_nsIWebProgress failed: %08x\n", nsres
);
846 ERR("no load group nor notif callback\n");
850 nsres
= nsIWebProgress_GetDOMWindow(web_progress
, &nswindow
);
851 nsIWebProgress_Release(web_progress
);
852 if(NS_FAILED(nsres
) || !nswindow
) {
853 ERR("GetDOMWindow failed: %08x\n", nsres
);
857 window
= nswindow_to_window(nswindow
);
858 nsIDOMWindow_Release(nswindow
);
861 IHTMLWindow2_AddRef(&window
->IHTMLWindow2_iface
);
863 FIXME("NULL window for %p\n", nswindow
);
869 HTMLDocumentNode
*doc
;
870 nsChannelBSC
*bscallback
;
871 } start_binding_task_t
;
873 static void start_binding_proc(task_t
*_task
)
875 start_binding_task_t
*task
= (start_binding_task_t
*)_task
;
877 start_binding(NULL
, task
->doc
, (BSCallback
*)task
->bscallback
, NULL
);
879 IUnknown_Release((IUnknown
*)task
->bscallback
);
882 static nsresult
async_open(nsChannel
*This
, HTMLWindow
*window
, BOOL is_doc_channel
, nsIStreamListener
*listener
,
883 nsISupports
*context
)
885 nsChannelBSC
*bscallback
;
886 IMoniker
*mon
= NULL
;
889 hres
= CreateURLMoniker(NULL
, This
->uri
->wine_url
, &mon
);
891 WARN("CreateURLMoniker failed: %08x\n", hres
);
892 return NS_ERROR_UNEXPECTED
;
896 set_current_mon(window
, mon
);
898 hres
= create_channelbsc(mon
, NULL
, NULL
, 0, &bscallback
);
899 IMoniker_Release(mon
);
901 return NS_ERROR_UNEXPECTED
;
903 channelbsc_set_channel(bscallback
, This
, listener
, context
);
906 set_window_bscallback(window
, bscallback
);
907 async_start_doc_binding(window
, bscallback
);
908 IUnknown_Release((IUnknown
*)bscallback
);
910 start_binding_task_t
*task
= heap_alloc(sizeof(start_binding_task_t
));
912 task
->doc
= window
->doc
;
913 task
->bscallback
= bscallback
;
914 push_task(&task
->header
, start_binding_proc
, window
->doc
->basedoc
.task_magic
);
920 static nsresult NSAPI
nsChannel_AsyncOpen(nsIHttpChannel
*iface
, nsIStreamListener
*aListener
,
921 nsISupports
*aContext
)
923 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
924 HTMLWindow
*window
= NULL
;
926 nsresult nsres
= NS_OK
;
928 TRACE("(%p)->(%p %p) opening %s\n", This
, aListener
, aContext
, debugstr_w(This
->uri
->wine_url
));
930 if(This
->uri
->is_doc_uri
) {
931 window
= get_channel_window(This
);
933 set_uri_window(This
->uri
, window
);
934 }else if(This
->uri
->container
) {
937 /* nscontainer->doc should be NULL which means navigation to a new window */
938 if(This
->uri
->container
->doc
)
939 FIXME("nscontainer->doc = %p\n", This
->uri
->container
->doc
);
941 b
= before_async_open(This
, This
->uri
->container
);
943 FIXME("Navigation not cancelled\n");
944 return NS_ERROR_UNEXPECTED
;
949 if(This
->uri
->window_ref
&& This
->uri
->window_ref
->window
) {
950 window
= This
->uri
->window_ref
->window
;
951 IHTMLWindow2_AddRef(&window
->IHTMLWindow2_iface
);
953 /* FIXME: Analyze removing get_window_from_load_group call */
955 window
= get_window_from_load_group(This
);
957 window
= get_channel_window(This
);
959 set_uri_window(This
->uri
, window
);
964 ERR("window = NULL\n");
965 return NS_ERROR_UNEXPECTED
;
968 if(This
->uri
->is_doc_uri
&& window
== window
->doc_obj
->basedoc
.window
) {
969 if(This
->uri
->channel_bsc
) {
970 channelbsc_set_channel(This
->uri
->channel_bsc
, This
, aListener
, aContext
);
972 if(window
->doc_obj
->mime
) {
973 heap_free(This
->content_type
);
974 This
->content_type
= heap_strdupWtoA(window
->doc_obj
->mime
);
979 open
= !before_async_open(This
, window
->doc_obj
->nscontainer
);
982 nsres
= NS_ERROR_UNEXPECTED
;
988 nsres
= async_open(This
, window
, This
->uri
->is_doc_uri
, aListener
, aContext
);
990 if(NS_SUCCEEDED(nsres
) && This
->load_group
) {
991 nsres
= nsILoadGroup_AddRequest(This
->load_group
, (nsIRequest
*)&This
->nsIHttpChannel_iface
,
994 ERR("AddRequest failed: %08x\n", nsres
);
997 IHTMLWindow2_Release(&window
->IHTMLWindow2_iface
);
1001 static nsresult NSAPI
nsChannel_GetRequestMethod(nsIHttpChannel
*iface
, nsACString
*aRequestMethod
)
1003 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1005 TRACE("(%p)->(%p)\n", This
, aRequestMethod
);
1007 nsACString_SetData(aRequestMethod
, request_method_strings
[This
->request_method
]);
1011 static nsresult NSAPI
nsChannel_SetRequestMethod(nsIHttpChannel
*iface
,
1012 const nsACString
*aRequestMethod
)
1014 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1018 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRequestMethod
));
1020 nsACString_GetData(aRequestMethod
, &method
);
1021 for(i
=0; i
< sizeof(request_method_strings
)/sizeof(*request_method_strings
); i
++) {
1022 if(!strcasecmp(method
, request_method_strings
[i
])) {
1023 This
->request_method
= i
;
1028 ERR("Invalid method %s\n", debugstr_a(method
));
1029 return NS_ERROR_UNEXPECTED
;
1032 static nsresult NSAPI
nsChannel_GetReferrer(nsIHttpChannel
*iface
, nsIURI
**aReferrer
)
1034 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1036 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1039 nsIURI_AddRef(This
->referrer
);
1040 *aReferrer
= This
->referrer
;
1044 static nsresult NSAPI
nsChannel_SetReferrer(nsIHttpChannel
*iface
, nsIURI
*aReferrer
)
1046 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1048 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1051 nsIURI_AddRef(aReferrer
);
1053 nsIURI_Release(This
->referrer
);
1054 This
->referrer
= aReferrer
;
1058 static nsresult NSAPI
nsChannel_GetRequestHeader(nsIHttpChannel
*iface
,
1059 const nsACString
*aHeader
, nsACString
*_retval
)
1061 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1063 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aHeader
), _retval
);
1065 return get_channel_http_header(&This
->request_headers
, aHeader
, _retval
);
1068 static nsresult NSAPI
nsChannel_SetRequestHeader(nsIHttpChannel
*iface
,
1069 const nsACString
*aHeader
, const nsACString
*aValue
, PRBool aMerge
)
1071 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1073 TRACE("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(aHeader
), debugstr_nsacstr(aValue
), aMerge
);
1076 FIXME("aMerge not supported\n");
1078 return set_channel_http_header(&This
->request_headers
, aHeader
, aValue
);
1081 static nsresult NSAPI
nsChannel_VisitRequestHeaders(nsIHttpChannel
*iface
,
1082 nsIHttpHeaderVisitor
*aVisitor
)
1084 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1086 FIXME("(%p)->(%p)\n", This
, aVisitor
);
1088 return NS_ERROR_NOT_IMPLEMENTED
;
1091 static nsresult NSAPI
nsChannel_GetAllowPipelining(nsIHttpChannel
*iface
, PRBool
*aAllowPipelining
)
1093 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1095 FIXME("(%p)->(%p)\n", This
, aAllowPipelining
);
1097 return NS_ERROR_NOT_IMPLEMENTED
;
1100 static nsresult NSAPI
nsChannel_SetAllowPipelining(nsIHttpChannel
*iface
, PRBool aAllowPipelining
)
1102 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1104 FIXME("(%p)->(%x)\n", This
, aAllowPipelining
);
1106 return NS_ERROR_NOT_IMPLEMENTED
;
1109 static nsresult NSAPI
nsChannel_GetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32
*aRedirectionLimit
)
1111 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1113 FIXME("(%p)->(%p)\n", This
, aRedirectionLimit
);
1115 return NS_ERROR_NOT_IMPLEMENTED
;
1118 static nsresult NSAPI
nsChannel_SetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32 aRedirectionLimit
)
1120 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1122 FIXME("(%p)->(%u)\n", This
, aRedirectionLimit
);
1124 return NS_ERROR_NOT_IMPLEMENTED
;
1127 static nsresult NSAPI
nsChannel_GetResponseStatus(nsIHttpChannel
*iface
, PRUint32
*aResponseStatus
)
1129 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1131 TRACE("(%p)->(%p)\n", This
, aResponseStatus
);
1133 if(This
->response_status
) {
1134 *aResponseStatus
= This
->response_status
;
1138 WARN("No response status\n");
1139 return NS_ERROR_UNEXPECTED
;
1142 static nsresult NSAPI
nsChannel_GetResponseStatusText(nsIHttpChannel
*iface
,
1143 nsACString
*aResponseStatusText
)
1145 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1147 FIXME("(%p)->(%p)\n", This
, aResponseStatusText
);
1149 return NS_ERROR_NOT_IMPLEMENTED
;
1152 static nsresult NSAPI
nsChannel_GetRequestSucceeded(nsIHttpChannel
*iface
,
1153 PRBool
*aRequestSucceeded
)
1155 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1157 TRACE("(%p)->(%p)\n", This
, aRequestSucceeded
);
1159 if(!This
->response_status
)
1160 return NS_ERROR_NOT_AVAILABLE
;
1162 *aRequestSucceeded
= This
->response_status
/100 == 2;
1167 static nsresult NSAPI
nsChannel_GetResponseHeader(nsIHttpChannel
*iface
,
1168 const nsACString
*header
, nsACString
*_retval
)
1170 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1172 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(header
), _retval
);
1174 return get_channel_http_header(&This
->response_headers
, header
, _retval
);
1177 static nsresult NSAPI
nsChannel_SetResponseHeader(nsIHttpChannel
*iface
,
1178 const nsACString
*header
, const nsACString
*value
, PRBool merge
)
1180 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1182 FIXME("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(header
), debugstr_nsacstr(value
), merge
);
1184 return NS_ERROR_NOT_IMPLEMENTED
;
1187 static nsresult NSAPI
nsChannel_VisitResponseHeaders(nsIHttpChannel
*iface
,
1188 nsIHttpHeaderVisitor
*aVisitor
)
1190 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1192 TRACE("(%p)->(%p)\n", This
, aVisitor
);
1194 return visit_http_headers(&This
->response_headers
, aVisitor
);
1197 static nsresult NSAPI
nsChannel_IsNoStoreResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1199 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1200 http_header_t
*header
;
1202 static const WCHAR cache_controlW
[] = {'C','a','c','h','e','-','C','o','n','t','r','o','l'};
1203 static const WCHAR no_storeW
[] = {'n','o','-','s','t','o','r','e',0};
1205 TRACE("(%p)->(%p)\n", This
, _retval
);
1207 header
= find_http_header(&This
->response_headers
, cache_controlW
, sizeof(cache_controlW
)/sizeof(WCHAR
));
1208 *_retval
= header
&& !strcmpiW(header
->data
, no_storeW
);
1212 static nsresult NSAPI
nsChannel_IsNoCacheResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1214 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1216 FIXME("(%p)->(%p)\n", This
, _retval
);
1218 return NS_ERROR_NOT_IMPLEMENTED
;
1221 static const nsIHttpChannelVtbl nsChannelVtbl
= {
1222 nsChannel_QueryInterface
,
1226 nsChannel_IsPending
,
1227 nsChannel_GetStatus
,
1231 nsChannel_GetLoadGroup
,
1232 nsChannel_SetLoadGroup
,
1233 nsChannel_GetLoadFlags
,
1234 nsChannel_SetLoadFlags
,
1235 nsChannel_GetOriginalURI
,
1236 nsChannel_SetOriginalURI
,
1240 nsChannel_GetNotificationCallbacks
,
1241 nsChannel_SetNotificationCallbacks
,
1242 nsChannel_GetSecurityInfo
,
1243 nsChannel_GetContentType
,
1244 nsChannel_SetContentType
,
1245 nsChannel_GetContentCharset
,
1246 nsChannel_SetContentCharset
,
1247 nsChannel_GetContentLength
,
1248 nsChannel_SetContentLength
,
1250 nsChannel_AsyncOpen
,
1251 nsChannel_GetRequestMethod
,
1252 nsChannel_SetRequestMethod
,
1253 nsChannel_GetReferrer
,
1254 nsChannel_SetReferrer
,
1255 nsChannel_GetRequestHeader
,
1256 nsChannel_SetRequestHeader
,
1257 nsChannel_VisitRequestHeaders
,
1258 nsChannel_GetAllowPipelining
,
1259 nsChannel_SetAllowPipelining
,
1260 nsChannel_GetRedirectionLimit
,
1261 nsChannel_SetRedirectionLimit
,
1262 nsChannel_GetResponseStatus
,
1263 nsChannel_GetResponseStatusText
,
1264 nsChannel_GetRequestSucceeded
,
1265 nsChannel_GetResponseHeader
,
1266 nsChannel_SetResponseHeader
,
1267 nsChannel_VisitResponseHeaders
,
1268 nsChannel_IsNoStoreResponse
,
1269 nsChannel_IsNoCacheResponse
1272 static inline nsChannel
*impl_from_nsIUploadChannel(nsIUploadChannel
*iface
)
1274 return CONTAINING_RECORD(iface
, nsChannel
, nsIUploadChannel_iface
);
1277 static nsresult NSAPI
nsUploadChannel_QueryInterface(nsIUploadChannel
*iface
, nsIIDRef riid
,
1280 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1281 return nsIChannel_QueryInterface(&This
->nsIHttpChannel_iface
, riid
, result
);
1284 static nsrefcnt NSAPI
nsUploadChannel_AddRef(nsIUploadChannel
*iface
)
1286 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1287 return nsIChannel_AddRef(&This
->nsIHttpChannel_iface
);
1290 static nsrefcnt NSAPI
nsUploadChannel_Release(nsIUploadChannel
*iface
)
1292 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1293 return nsIChannel_Release(&This
->nsIHttpChannel_iface
);
1296 static nsresult NSAPI
nsUploadChannel_SetUploadStream(nsIUploadChannel
*iface
,
1297 nsIInputStream
*aStream
, const nsACString
*aContentType
, PRInt32 aContentLength
)
1299 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1300 const char *content_type
;
1302 static const WCHAR content_typeW
[] =
1303 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1305 TRACE("(%p)->(%p %s %d)\n", This
, aStream
, debugstr_nsacstr(aContentType
), aContentLength
);
1307 This
->post_data_contains_headers
= TRUE
;
1310 nsACString_GetData(aContentType
, &content_type
);
1314 ct
= heap_strdupAtoW(content_type
);
1316 return NS_ERROR_UNEXPECTED
;
1318 set_http_header(&This
->request_headers
, content_typeW
,
1319 sizeof(content_typeW
)/sizeof(WCHAR
), ct
, strlenW(ct
));
1321 This
->post_data_contains_headers
= FALSE
;
1325 if(This
->post_data_stream
)
1326 nsIInputStream_Release(This
->post_data_stream
);
1328 if(aContentLength
!= -1)
1329 FIXME("Unsupported acontentLength = %d\n", aContentLength
);
1331 if(This
->post_data_stream
)
1332 nsIInputStream_Release(This
->post_data_stream
);
1333 This
->post_data_stream
= aStream
;
1335 nsIInputStream_AddRef(aStream
);
1337 This
->request_method
= METHOD_POST
;
1341 static nsresult NSAPI
nsUploadChannel_GetUploadStream(nsIUploadChannel
*iface
,
1342 nsIInputStream
**aUploadStream
)
1344 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1346 TRACE("(%p)->(%p)\n", This
, aUploadStream
);
1348 if(This
->post_data_stream
)
1349 nsIInputStream_AddRef(This
->post_data_stream
);
1351 *aUploadStream
= This
->post_data_stream
;
1355 static const nsIUploadChannelVtbl nsUploadChannelVtbl
= {
1356 nsUploadChannel_QueryInterface
,
1357 nsUploadChannel_AddRef
,
1358 nsUploadChannel_Release
,
1359 nsUploadChannel_SetUploadStream
,
1360 nsUploadChannel_GetUploadStream
1363 static inline nsChannel
*impl_from_nsIHttpChannelInternal(nsIHttpChannelInternal
*iface
)
1365 return CONTAINING_RECORD(iface
, nsChannel
, nsIHttpChannelInternal_iface
);
1368 static nsresult NSAPI
nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal
*iface
, nsIIDRef riid
,
1371 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1372 return nsIChannel_QueryInterface(&This
->nsIHttpChannel_iface
, riid
, result
);
1375 static nsrefcnt NSAPI
nsHttpChannelInternal_AddRef(nsIHttpChannelInternal
*iface
)
1377 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1378 return nsIChannel_AddRef(&This
->nsIHttpChannel_iface
);
1381 static nsrefcnt NSAPI
nsHttpChannelInternal_Release(nsIHttpChannelInternal
*iface
)
1383 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1384 return nsIChannel_Release(&This
->nsIHttpChannel_iface
);
1387 static nsresult NSAPI
nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
**aDocumentURI
)
1389 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1391 FIXME("(%p)->()\n", This
);
1393 return NS_ERROR_NOT_IMPLEMENTED
;
1396 static nsresult NSAPI
nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
*aDocumentURI
)
1398 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1400 FIXME("(%p)->()\n", This
);
1402 return NS_ERROR_NOT_IMPLEMENTED
;
1405 static nsresult NSAPI
nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal
*iface
, PRUint32
*major
, PRUint32
*minor
)
1407 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1409 FIXME("(%p)->()\n", This
);
1411 return NS_ERROR_NOT_IMPLEMENTED
;
1414 static nsresult NSAPI
nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal
*iface
, PRUint32
*major
, PRUint32
*minor
)
1416 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1418 FIXME("(%p)->()\n", This
);
1420 return NS_ERROR_NOT_IMPLEMENTED
;
1423 static nsresult NSAPI
nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal
*iface
, const char *aCookieHeader
)
1425 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1427 FIXME("(%p)->()\n", This
);
1429 return NS_ERROR_NOT_IMPLEMENTED
;
1432 static nsresult NSAPI
nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal
*iface
, const char *aFallbackKey
)
1434 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1436 FIXME("(%p)->()\n", This
);
1438 return NS_ERROR_NOT_IMPLEMENTED
;
1441 static nsresult NSAPI
nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, PRBool
*aForceThirdPartyCookie
)
1443 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1445 FIXME("(%p)->()\n", This
);
1447 return NS_ERROR_NOT_IMPLEMENTED
;
1450 static nsresult NSAPI
nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, PRBool aForceThirdPartyCookie
)
1452 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1454 FIXME("(%p)->()\n", This
);
1456 return NS_ERROR_NOT_IMPLEMENTED
;
1459 static nsresult NSAPI
nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal
*iface
, PRBool
*aCanceled
)
1461 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1463 FIXME("(%p)->(%p)\n", This
, aCanceled
);
1465 return NS_ERROR_NOT_IMPLEMENTED
;
1468 static nsresult NSAPI
nsHttpChannelInternal_GetChannelIsForDownload(nsIHttpChannelInternal
*iface
, PRBool
*aCanceled
)
1470 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1472 FIXME("(%p)->(%p)\n", This
, aCanceled
);
1474 return NS_ERROR_NOT_IMPLEMENTED
;
1477 static nsresult NSAPI
nsHttpChannelInternal_SetChannelIsForDownload(nsIHttpChannelInternal
*iface
, PRBool aCanceled
)
1479 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1481 FIXME("(%p)->(%x)\n", This
, aCanceled
);
1483 return NS_ERROR_NOT_IMPLEMENTED
;
1486 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl
= {
1487 nsHttpChannelInternal_QueryInterface
,
1488 nsHttpChannelInternal_AddRef
,
1489 nsHttpChannelInternal_Release
,
1490 nsHttpChannelInternal_GetDocumentURI
,
1491 nsHttpChannelInternal_SetDocumentURI
,
1492 nsHttpChannelInternal_GetRequestVersion
,
1493 nsHttpChannelInternal_GetResponseVersion
,
1494 nsHttpChannelInternal_SetCookie
,
1495 nsHttpChannelInternal_SetupFallbackChannel
,
1496 nsHttpChannelInternal_GetForceAllowThirdPartyCookie
,
1497 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
,
1498 nsHttpChannelInternal_GetCanceled
,
1499 nsHttpChannelInternal_GetChannelIsForDownload
,
1500 nsHttpChannelInternal_SetChannelIsForDownload
1503 static BOOL
ensure_uri(nsWineURI
*This
)
1510 if(This
->uri_builder
) {
1511 hres
= IUriBuilder_CreateUriSimple(This
->uri_builder
, 0, 0, &This
->uri
);
1513 WARN("CreateUriSimple failed: %08x\n", hres
);
1520 hres
= CreateUri(This
->wine_url
, 0, 0, &This
->uri
);
1522 WARN("CreateUri failed: %08x\n", hres
);
1529 static void invalidate_uri(nsWineURI
*This
)
1532 IUri_Release(This
->uri
);
1537 static BOOL
ensure_uri_builder(nsWineURI
*This
)
1539 if(!This
->uri_builder
) {
1542 if(!ensure_uri(This
))
1545 hres
= CreateIUriBuilder(This
->uri
, 0, 0, &This
->uri_builder
);
1547 WARN("CreateIUriBulder failed: %08x\n", hres
);
1552 invalidate_uri(This
);
1556 /* Temporary helper */
1557 static void sync_wine_url(nsWineURI
*This
)
1562 if(!ensure_uri(This
))
1565 hres
= IUri_GetDisplayUri(This
->uri
, &new_url
);
1569 SysFreeString(This
->wine_url
);
1570 This
->wine_url
= new_url
;
1573 static nsresult
get_uri_string(nsWineURI
*This
, Uri_PROPERTY prop
, nsACString
*ret
)
1579 if(!ensure_uri(This
))
1580 return NS_ERROR_UNEXPECTED
;
1582 hres
= IUri_GetPropertyBSTR(This
->uri
, prop
, &val
, 0);
1584 WARN("GetPropertyBSTR failed: %08x\n", hres
);
1585 return NS_ERROR_UNEXPECTED
;
1588 vala
= heap_strdupWtoA(val
);
1591 return NS_ERROR_OUT_OF_MEMORY
;
1593 TRACE("ret %s\n", debugstr_a(vala
));
1594 nsACString_SetData(ret
, vala
);
1599 static inline nsWineURI
*impl_from_nsIURL(nsIURL
*iface
)
1601 return CONTAINING_RECORD(iface
, nsWineURI
, nsIURL_iface
);
1604 static nsresult NSAPI
nsURI_QueryInterface(nsIURL
*iface
, nsIIDRef riid
, void **result
)
1606 nsWineURI
*This
= impl_from_nsIURL(iface
);
1610 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1611 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1612 *result
= &This
->nsIURL_iface
;
1613 }else if(IsEqualGUID(&IID_nsIURI
, riid
)) {
1614 TRACE("(%p)->(IID_nsIURI %p)\n", This
, result
);
1615 *result
= &This
->nsIURL_iface
;
1616 }else if(IsEqualGUID(&IID_nsIURL
, riid
)) {
1617 TRACE("(%p)->(IID_nsIURL %p)\n", This
, result
);
1618 *result
= &This
->nsIURL_iface
;
1619 }else if(IsEqualGUID(&IID_nsWineURI
, riid
)) {
1620 TRACE("(%p)->(IID_nsWineURI %p)\n", This
, result
);
1625 nsIURI_AddRef(&This
->nsIURL_iface
);
1629 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1630 return This
->nsuri
? nsIURI_QueryInterface(This
->nsuri
, riid
, result
) : NS_NOINTERFACE
;
1633 static nsrefcnt NSAPI
nsURI_AddRef(nsIURL
*iface
)
1635 nsWineURI
*This
= impl_from_nsIURL(iface
);
1636 LONG ref
= InterlockedIncrement(&This
->ref
);
1638 TRACE("(%p) ref=%d\n", This
, ref
);
1643 static nsrefcnt NSAPI
nsURI_Release(nsIURL
*iface
)
1645 nsWineURI
*This
= impl_from_nsIURL(iface
);
1646 LONG ref
= InterlockedDecrement(&This
->ref
);
1648 TRACE("(%p) ref=%d\n", This
, ref
);
1651 if(This
->window_ref
)
1652 windowref_release(This
->window_ref
);
1654 nsIWebBrowserChrome_Release(&This
->container
->nsIWebBrowserChrome_iface
);
1656 nsIURL_Release(This
->nsurl
);
1658 nsIURI_Release(This
->nsuri
);
1660 IUri_Release(This
->uri
);
1661 SysFreeString(This
->wine_url
);
1668 static nsresult NSAPI
nsURI_GetSpec(nsIURL
*iface
, nsACString
*aSpec
)
1670 nsWineURI
*This
= impl_from_nsIURL(iface
);
1672 TRACE("(%p)->(%p)\n", This
, aSpec
);
1674 return get_uri_string(This
, Uri_PROPERTY_DISPLAY_URI
, aSpec
);
1677 static nsresult NSAPI
nsURI_SetSpec(nsIURL
*iface
, const nsACString
*aSpec
)
1679 nsWineURI
*This
= impl_from_nsIURL(iface
);
1685 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aSpec
));
1687 nsACString_GetData(aSpec
, &speca
);
1688 spec
= heap_strdupAtoW(speca
);
1690 return NS_ERROR_OUT_OF_MEMORY
;
1692 hres
= CreateUri(spec
, 0, 0, &uri
);
1695 WARN("CreateUri failed: %08x\n", hres
);
1696 return NS_ERROR_FAILURE
;
1699 invalidate_uri(This
);
1700 if(This
->uri_builder
) {
1701 IUriBuilder_Release(This
->uri_builder
);
1702 This
->uri_builder
= NULL
;
1706 sync_wine_url(This
);
1710 static nsresult NSAPI
nsURI_GetPrePath(nsIURL
*iface
, nsACString
*aPrePath
)
1712 nsWineURI
*This
= impl_from_nsIURL(iface
);
1714 TRACE("(%p)->(%p)\n", This
, aPrePath
);
1717 return nsIURI_GetPrePath(This
->nsuri
, aPrePath
);
1719 FIXME("default action not implemented\n");
1720 return NS_ERROR_NOT_IMPLEMENTED
;
1723 static nsresult NSAPI
nsURI_GetScheme(nsIURL
*iface
, nsACString
*aScheme
)
1725 nsWineURI
*This
= impl_from_nsIURL(iface
);
1729 TRACE("(%p)->(%p)\n", This
, aScheme
);
1731 if(!ensure_uri(This
))
1732 return NS_ERROR_UNEXPECTED
;
1734 hres
= IUri_GetScheme(This
->uri
, &scheme
);
1736 WARN("GetScheme failed: %08x\n", hres
);
1737 return NS_ERROR_UNEXPECTED
;
1740 if(scheme
== URL_SCHEME_ABOUT
) {
1741 nsACString_SetData(aScheme
, "wine");
1745 return get_uri_string(This
, Uri_PROPERTY_SCHEME_NAME
, aScheme
);
1748 static nsresult NSAPI
nsURI_SetScheme(nsIURL
*iface
, const nsACString
*aScheme
)
1750 nsWineURI
*This
= impl_from_nsIURL(iface
);
1751 const char *schemea
;
1755 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aScheme
));
1757 if(!ensure_uri_builder(This
))
1758 return NS_ERROR_UNEXPECTED
;
1760 nsACString_GetData(aScheme
, &schemea
);
1761 scheme
= heap_strdupAtoW(schemea
);
1763 return NS_ERROR_OUT_OF_MEMORY
;
1765 hres
= IUriBuilder_SetSchemeName(This
->uri_builder
, scheme
);
1768 return NS_ERROR_UNEXPECTED
;
1770 sync_wine_url(This
);
1774 static nsresult NSAPI
nsURI_GetUserPass(nsIURL
*iface
, nsACString
*aUserPass
)
1776 nsWineURI
*This
= impl_from_nsIURL(iface
);
1778 TRACE("(%p)->(%p)\n", This
, aUserPass
);
1781 return nsIURI_GetUserPass(This
->nsuri
, aUserPass
);
1783 return get_uri_string(This
, Uri_PROPERTY_USER_INFO
, aUserPass
);
1786 static nsresult NSAPI
nsURI_SetUserPass(nsIURL
*iface
, const nsACString
*aUserPass
)
1788 nsWineURI
*This
= impl_from_nsIURL(iface
);
1790 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUserPass
));
1793 invalidate_uri(This
);
1794 return nsIURI_SetUserPass(This
->nsuri
, aUserPass
);
1797 FIXME("default action not implemented\n");
1798 return NS_ERROR_NOT_IMPLEMENTED
;
1801 static nsresult NSAPI
nsURI_GetUsername(nsIURL
*iface
, nsACString
*aUsername
)
1803 nsWineURI
*This
= impl_from_nsIURL(iface
);
1805 TRACE("(%p)->(%p)\n", This
, aUsername
);
1807 return get_uri_string(This
, Uri_PROPERTY_USER_NAME
, aUsername
);
1810 static nsresult NSAPI
nsURI_SetUsername(nsIURL
*iface
, const nsACString
*aUsername
)
1812 nsWineURI
*This
= impl_from_nsIURL(iface
);
1817 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUsername
));
1819 if(!ensure_uri_builder(This
))
1820 return NS_ERROR_UNEXPECTED
;
1822 nsACString_GetData(aUsername
, &usera
);
1823 user
= heap_strdupAtoW(usera
);
1825 return NS_ERROR_OUT_OF_MEMORY
;
1827 hres
= IUriBuilder_SetUserName(This
->uri_builder
, user
);
1830 return NS_ERROR_UNEXPECTED
;
1832 sync_wine_url(This
);
1836 static nsresult NSAPI
nsURI_GetPassword(nsIURL
*iface
, nsACString
*aPassword
)
1838 nsWineURI
*This
= impl_from_nsIURL(iface
);
1840 TRACE("(%p)->(%p)\n", This
, aPassword
);
1842 return get_uri_string(This
, Uri_PROPERTY_PASSWORD
, aPassword
);
1845 static nsresult NSAPI
nsURI_SetPassword(nsIURL
*iface
, const nsACString
*aPassword
)
1847 nsWineURI
*This
= impl_from_nsIURL(iface
);
1852 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPassword
));
1854 if(!ensure_uri_builder(This
))
1855 return NS_ERROR_UNEXPECTED
;
1857 nsACString_GetData(aPassword
, &passa
);
1858 pass
= heap_strdupAtoW(passa
);
1860 return NS_ERROR_OUT_OF_MEMORY
;
1862 hres
= IUriBuilder_SetPassword(This
->uri_builder
, pass
);
1865 return NS_ERROR_UNEXPECTED
;
1867 sync_wine_url(This
);
1871 static nsresult NSAPI
nsURI_GetHostPort(nsIURL
*iface
, nsACString
*aHostPort
)
1873 nsWineURI
*This
= impl_from_nsIURL(iface
);
1879 TRACE("(%p)->(%p)\n", This
, aHostPort
);
1881 if(!ensure_uri(This
))
1882 return NS_ERROR_UNEXPECTED
;
1884 hres
= IUri_GetAuthority(This
->uri
, &val
);
1886 WARN("GetAuthority failed: %08x\n", hres
);
1887 return NS_ERROR_UNEXPECTED
;
1890 ptr
= strchrW(val
, '@');
1894 vala
= heap_strdupWtoA(ptr
);
1897 return NS_ERROR_OUT_OF_MEMORY
;
1899 TRACE("ret %s\n", debugstr_a(vala
));
1900 nsACString_SetData(aHostPort
, vala
);
1905 static nsresult NSAPI
nsURI_SetHostPort(nsIURL
*iface
, const nsACString
*aHostPort
)
1907 nsWineURI
*This
= impl_from_nsIURL(iface
);
1909 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aHostPort
));
1911 /* Not implemented by Gecko */
1912 return NS_ERROR_NOT_IMPLEMENTED
;
1915 static nsresult NSAPI
nsURI_GetHost(nsIURL
*iface
, nsACString
*aHost
)
1917 nsWineURI
*This
= impl_from_nsIURL(iface
);
1919 TRACE("(%p)->(%p)\n", This
, aHost
);
1921 return get_uri_string(This
, Uri_PROPERTY_HOST
, aHost
);
1924 static nsresult NSAPI
nsURI_SetHost(nsIURL
*iface
, const nsACString
*aHost
)
1926 nsWineURI
*This
= impl_from_nsIURL(iface
);
1931 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aHost
));
1933 if(!ensure_uri_builder(This
))
1934 return NS_ERROR_UNEXPECTED
;
1936 nsACString_GetData(aHost
, &hosta
);
1937 host
= heap_strdupAtoW(hosta
);
1939 return NS_ERROR_OUT_OF_MEMORY
;
1941 hres
= IUriBuilder_SetHost(This
->uri_builder
, host
);
1944 return NS_ERROR_UNEXPECTED
;
1946 sync_wine_url(This
);
1950 static nsresult NSAPI
nsURI_GetPort(nsIURL
*iface
, PRInt32
*aPort
)
1952 nsWineURI
*This
= impl_from_nsIURL(iface
);
1956 TRACE("(%p)->(%p)\n", This
, aPort
);
1959 return nsIURI_GetPort(This
->nsuri
, aPort
);
1961 if(!ensure_uri(This
))
1962 return NS_ERROR_UNEXPECTED
;
1964 hres
= IUri_GetPort(This
->uri
, &port
);
1966 WARN("GetPort failed: %08x\n", hres
);
1967 return NS_ERROR_UNEXPECTED
;
1970 *aPort
= port
? port
: -1;
1974 static nsresult NSAPI
nsURI_SetPort(nsIURL
*iface
, PRInt32 aPort
)
1976 nsWineURI
*This
= impl_from_nsIURL(iface
);
1978 TRACE("(%p)->(%d)\n", This
, aPort
);
1981 invalidate_uri(This
);
1982 return nsIURI_SetPort(This
->nsuri
, aPort
);
1985 FIXME("default action not implemented\n");
1986 return NS_ERROR_NOT_IMPLEMENTED
;
1989 static nsresult NSAPI
nsURI_GetPath(nsIURL
*iface
, nsACString
*aPath
)
1991 nsWineURI
*This
= impl_from_nsIURL(iface
);
1993 TRACE("(%p)->(%p)\n", This
, aPath
);
1995 return get_uri_string(This
, Uri_PROPERTY_PATH
, aPath
);
1998 static nsresult NSAPI
nsURI_SetPath(nsIURL
*iface
, const nsACString
*aPath
)
2000 nsWineURI
*This
= impl_from_nsIURL(iface
);
2005 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPath
));
2007 if(!ensure_uri_builder(This
))
2008 return NS_ERROR_UNEXPECTED
;
2010 nsACString_GetData(aPath
, &patha
);
2011 path
= heap_strdupAtoW(patha
);
2013 return NS_ERROR_OUT_OF_MEMORY
;
2015 hres
= IUriBuilder_SetPath(This
->uri_builder
, path
);
2018 return NS_ERROR_UNEXPECTED
;
2020 sync_wine_url(This
);
2024 static nsresult NSAPI
nsURI_Equals(nsIURL
*iface
, nsIURI
*other
, PRBool
*_retval
)
2026 nsWineURI
*This
= impl_from_nsIURL(iface
);
2027 nsWineURI
*other_obj
;
2031 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
2033 nsres
= nsIURI_QueryInterface(other
, &IID_nsWineURI
, (void**)&other_obj
);
2034 if(NS_FAILED(nsres
)) {
2035 TRACE("Could not get nsWineURI interface\n");
2040 if(ensure_uri(This
) && ensure_uri(other_obj
)) {
2041 hres
= IUri_IsEqual(This
->uri
, other_obj
->uri
, _retval
);
2042 nsres
= SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_FAILURE
;
2044 nsres
= NS_ERROR_UNEXPECTED
;
2047 nsIURI_Release(&other_obj
->nsIURL_iface
);
2051 static nsresult NSAPI
nsURI_SchemeIs(nsIURL
*iface
, const char *scheme
, PRBool
*_retval
)
2053 nsWineURI
*This
= impl_from_nsIURL(iface
);
2054 WCHAR buf
[INTERNET_MAX_SCHEME_LENGTH
];
2058 TRACE("(%p)->(%s %p)\n", This
, debugstr_a(scheme
), _retval
);
2060 if(!ensure_uri(This
))
2061 return NS_ERROR_UNEXPECTED
;
2063 hres
= IUri_GetSchemeName(This
->uri
, &scheme_name
);
2065 return NS_ERROR_UNEXPECTED
;
2067 MultiByteToWideChar(CP_ACP
, 0, scheme
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
2068 *_retval
= !strcmpW(scheme_name
, buf
);
2069 SysFreeString(scheme_name
);
2073 static nsresult NSAPI
nsURI_Clone(nsIURL
*iface
, nsIURI
**_retval
)
2075 nsWineURI
*This
= impl_from_nsIURL(iface
);
2076 nsIURI
*nsuri
= NULL
;
2077 nsWineURI
*wine_uri
;
2080 TRACE("(%p)->(%p)\n", This
, _retval
);
2082 if(!ensure_uri(This
))
2083 return NS_ERROR_UNEXPECTED
;
2086 nsres
= nsIURI_Clone(This
->nsuri
, &nsuri
);
2087 if(NS_FAILED(nsres
)) {
2088 WARN("Clone failed: %08x\n", nsres
);
2093 nsres
= create_uri(nsuri
, This
->window_ref
? This
->window_ref
->window
: NULL
, This
->container
, &wine_uri
);
2094 if(NS_FAILED(nsres
)) {
2095 WARN("create_uri failed: %08x\n", nsres
);
2099 wine_uri
->uri
= This
->uri
;
2100 IUri_AddRef(wine_uri
->uri
);
2101 sync_wine_url(wine_uri
);
2103 *_retval
= (nsIURI
*)&wine_uri
->nsIURL_iface
;
2107 static nsresult NSAPI
nsURI_Resolve(nsIURL
*iface
, const nsACString
*aRelativePath
,
2108 nsACString
*_retval
)
2110 nsWineURI
*This
= impl_from_nsIURL(iface
);
2118 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aRelativePath
), _retval
);
2120 if(!ensure_uri(This
))
2121 return NS_ERROR_UNEXPECTED
;
2123 nsACString_GetData(aRelativePath
, &patha
);
2124 path
= heap_strdupAtoW(patha
);
2126 return NS_ERROR_OUT_OF_MEMORY
;
2128 hres
= CoInternetCombineUrlEx(This
->uri
, path
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
, &new_uri
, 0);
2131 ERR("CoIntenetCombineUrlEx failed: %08x\n", hres
);
2132 return NS_ERROR_FAILURE
;
2135 hres
= IUri_GetDisplayUri(new_uri
, &ret
);
2136 IUri_Release(new_uri
);
2138 return NS_ERROR_FAILURE
;
2140 reta
= heap_strdupWtoA(ret
);
2143 return NS_ERROR_OUT_OF_MEMORY
;
2145 TRACE("returning %s\n", debugstr_a(reta
));
2146 nsACString_SetData(_retval
, reta
);
2151 static nsresult NSAPI
nsURI_GetAsciiSpec(nsIURL
*iface
, nsACString
*aAsciiSpec
)
2153 nsWineURI
*This
= impl_from_nsIURL(iface
);
2155 TRACE("(%p)->(%p)\n", This
, aAsciiSpec
);
2157 return nsIURI_GetSpec(&This
->nsIURL_iface
, aAsciiSpec
);
2160 static nsresult NSAPI
nsURI_GetAsciiHost(nsIURL
*iface
, nsACString
*aAsciiHost
)
2162 nsWineURI
*This
= impl_from_nsIURL(iface
);
2164 TRACE("(%p)->(%p)\n", This
, aAsciiHost
);
2167 return nsIURI_GetAsciiHost(This
->nsuri
, aAsciiHost
);
2169 FIXME("Use Uri_PUNYCODE_IDN_HOST flag\n");
2170 return get_uri_string(This
, Uri_PROPERTY_HOST
, aAsciiHost
);
2173 static nsresult NSAPI
nsURI_GetOriginCharset(nsIURL
*iface
, nsACString
*aOriginCharset
)
2175 nsWineURI
*This
= impl_from_nsIURL(iface
);
2177 TRACE("(%p)->(%p)\n", This
, aOriginCharset
);
2180 return nsIURI_GetOriginCharset(This
->nsuri
, aOriginCharset
);
2182 FIXME("default action not implemented\n");
2183 return NS_ERROR_NOT_IMPLEMENTED
;
2186 static nsresult NSAPI
nsURL_GetFilePath(nsIURL
*iface
, nsACString
*aFilePath
)
2188 nsWineURI
*This
= impl_from_nsIURL(iface
);
2190 TRACE("(%p)->(%p)\n", This
, aFilePath
);
2192 return nsIURL_GetPath(&This
->nsIURL_iface
, aFilePath
);
2195 static nsresult NSAPI
nsURL_SetFilePath(nsIURL
*iface
, const nsACString
*aFilePath
)
2197 nsWineURI
*This
= impl_from_nsIURL(iface
);
2199 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFilePath
));
2201 return nsIURL_SetPath(&This
->nsIURL_iface
, aFilePath
);
2204 static nsresult NSAPI
nsURL_GetParam(nsIURL
*iface
, nsACString
*aParam
)
2206 nsWineURI
*This
= impl_from_nsIURL(iface
);
2208 TRACE("(%p)->(%p)\n", This
, aParam
);
2211 return nsIURL_GetParam(This
->nsurl
, aParam
);
2213 FIXME("default action not implemented\n");
2214 return NS_ERROR_NOT_IMPLEMENTED
;
2217 static nsresult NSAPI
nsURL_SetParam(nsIURL
*iface
, const nsACString
*aParam
)
2219 nsWineURI
*This
= impl_from_nsIURL(iface
);
2221 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aParam
));
2223 /* Not implemented by Gecko */
2224 return NS_ERROR_NOT_IMPLEMENTED
;
2227 static nsresult NSAPI
nsURL_GetQuery(nsIURL
*iface
, nsACString
*aQuery
)
2229 nsWineURI
*This
= impl_from_nsIURL(iface
);
2231 TRACE("(%p)->(%p)\n", This
, aQuery
);
2233 return get_uri_string(This
, Uri_PROPERTY_QUERY
, aQuery
);
2236 static nsresult NSAPI
nsURL_SetQuery(nsIURL
*iface
, const nsACString
*aQuery
)
2238 nsWineURI
*This
= impl_from_nsIURL(iface
);
2243 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aQuery
));
2245 if(!ensure_uri_builder(This
))
2246 return NS_ERROR_UNEXPECTED
;
2248 nsACString_GetData(aQuery
, &querya
);
2249 query
= heap_strdupAtoW(querya
);
2251 return NS_ERROR_OUT_OF_MEMORY
;
2253 hres
= IUriBuilder_SetQuery(This
->uri_builder
, query
);
2256 return NS_ERROR_UNEXPECTED
;
2258 sync_wine_url(This
);
2262 static nsresult NSAPI
nsURL_GetRef(nsIURL
*iface
, nsACString
*aRef
)
2264 nsWineURI
*This
= impl_from_nsIURL(iface
);
2269 TRACE("(%p)->(%p)\n", This
, aRef
);
2271 if(!ensure_uri(This
))
2272 return NS_ERROR_UNEXPECTED
;
2274 hres
= IUri_GetFragment(This
->uri
, &ref
);
2276 return NS_ERROR_UNEXPECTED
;
2278 refa
= heap_strdupWtoA(ref
);
2281 return NS_ERROR_OUT_OF_MEMORY
;
2283 nsACString_SetData(aRef
, refa
&& *refa
== '#' ? refa
+1 : refa
);
2288 static nsresult NSAPI
nsURL_SetRef(nsIURL
*iface
, const nsACString
*aRef
)
2290 nsWineURI
*This
= impl_from_nsIURL(iface
);
2295 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRef
));
2297 if(!ensure_uri_builder(This
))
2298 return NS_ERROR_UNEXPECTED
;
2300 nsACString_GetData(aRef
, &refa
);
2301 ref
= heap_strdupAtoW(refa
);
2303 return NS_ERROR_OUT_OF_MEMORY
;
2305 hres
= IUriBuilder_SetFragment(This
->uri_builder
, ref
);
2308 return NS_ERROR_UNEXPECTED
;
2310 sync_wine_url(This
);
2314 static nsresult NSAPI
nsURL_GetDirectory(nsIURL
*iface
, nsACString
*aDirectory
)
2316 nsWineURI
*This
= impl_from_nsIURL(iface
);
2318 TRACE("(%p)->(%p)\n", This
, aDirectory
);
2321 return nsIURL_GetDirectory(This
->nsurl
, aDirectory
);
2323 FIXME("default action not implemented\n");
2324 return NS_ERROR_NOT_IMPLEMENTED
;
2327 static nsresult NSAPI
nsURL_SetDirectory(nsIURL
*iface
, const nsACString
*aDirectory
)
2329 nsWineURI
*This
= impl_from_nsIURL(iface
);
2331 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aDirectory
));
2333 /* Not implemented by Gecko */
2334 return NS_ERROR_NOT_IMPLEMENTED
;
2337 static nsresult NSAPI
nsURL_GetFileName(nsIURL
*iface
, nsACString
*aFileName
)
2339 nsWineURI
*This
= impl_from_nsIURL(iface
);
2341 TRACE("(%p)->(%p)\n", This
, aFileName
);
2344 return nsIURL_GetFileName(This
->nsurl
, aFileName
);
2346 FIXME("default action not implemented\n");
2347 return NS_ERROR_NOT_IMPLEMENTED
;
2350 static nsresult NSAPI
nsURL_SetFileName(nsIURL
*iface
, const nsACString
*aFileName
)
2352 nsWineURI
*This
= impl_from_nsIURL(iface
);
2354 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileName
));
2357 invalidate_uri(This
);
2358 return nsIURL_SetFileName(This
->nsurl
, aFileName
);
2361 FIXME("default action not implemented\n");
2362 return NS_ERROR_NOT_IMPLEMENTED
;
2365 static nsresult NSAPI
nsURL_GetFileBaseName(nsIURL
*iface
, nsACString
*aFileBaseName
)
2367 nsWineURI
*This
= impl_from_nsIURL(iface
);
2369 TRACE("(%p)->(%p)\n", This
, aFileBaseName
);
2372 return nsIURL_GetFileBaseName(This
->nsurl
, aFileBaseName
);
2374 FIXME("default action not implemented\n");
2375 return NS_ERROR_NOT_IMPLEMENTED
;
2378 static nsresult NSAPI
nsURL_SetFileBaseName(nsIURL
*iface
, const nsACString
*aFileBaseName
)
2380 nsWineURI
*This
= impl_from_nsIURL(iface
);
2382 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileBaseName
));
2385 invalidate_uri(This
);
2386 return nsIURL_SetFileBaseName(This
->nsurl
, aFileBaseName
);
2389 FIXME("default action not implemented\n");
2390 return NS_ERROR_NOT_IMPLEMENTED
;
2393 static nsresult NSAPI
nsURL_GetFileExtension(nsIURL
*iface
, nsACString
*aFileExtension
)
2395 nsWineURI
*This
= impl_from_nsIURL(iface
);
2397 TRACE("(%p)->(%p)\n", This
, aFileExtension
);
2400 return nsIURL_GetFileExtension(This
->nsurl
, aFileExtension
);
2402 FIXME("default action not implemented\n");
2403 return NS_ERROR_NOT_IMPLEMENTED
;
2406 static nsresult NSAPI
nsURL_SetFileExtension(nsIURL
*iface
, const nsACString
*aFileExtension
)
2408 nsWineURI
*This
= impl_from_nsIURL(iface
);
2410 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileExtension
));
2413 invalidate_uri(This
);
2414 return nsIURL_SetFileExtension(This
->nsurl
, aFileExtension
);
2417 FIXME("default action not implemented\n");
2418 return NS_ERROR_NOT_IMPLEMENTED
;
2421 static nsresult NSAPI
nsURL_GetCommonBaseSpec(nsIURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2423 nsWineURI
*This
= impl_from_nsIURL(iface
);
2425 TRACE("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2428 return nsIURL_GetCommonBaseSpec(This
->nsurl
, aURIToCompare
, _retval
);
2430 FIXME("default action not implemented\n");
2431 return NS_ERROR_NOT_IMPLEMENTED
;
2434 static nsresult NSAPI
nsURL_GetRelativeSpec(nsIURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2436 nsWineURI
*This
= impl_from_nsIURL(iface
);
2438 TRACE("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2441 return nsIURL_GetRelativeSpec(This
->nsurl
, aURIToCompare
, _retval
);
2443 FIXME("default action not implemented\n");
2444 return NS_ERROR_NOT_IMPLEMENTED
;
2447 static const nsIURLVtbl nsURLVtbl
= {
2448 nsURI_QueryInterface
,
2476 nsURI_GetOriginCharset
,
2489 nsURL_GetFileBaseName
,
2490 nsURL_SetFileBaseName
,
2491 nsURL_GetFileExtension
,
2492 nsURL_SetFileExtension
,
2493 nsURL_GetCommonBaseSpec
,
2494 nsURL_GetRelativeSpec
2497 static nsresult
create_uri(nsIURI
*nsuri
, HTMLWindow
*window
, NSContainer
*container
, nsWineURI
**_retval
)
2499 nsWineURI
*ret
= heap_alloc_zero(sizeof(nsWineURI
));
2501 ret
->nsIURL_iface
.lpVtbl
= &nsURLVtbl
;
2505 set_uri_nscontainer(ret
, container
);
2506 set_uri_window(ret
, window
);
2509 nsIURI_QueryInterface(nsuri
, &IID_nsIURL
, (void**)&ret
->nsurl
);
2511 TRACE("retval=%p\n", ret
);
2516 HRESULT
create_doc_uri(HTMLWindow
*window
, WCHAR
*url
, nsWineURI
**ret
)
2521 nsres
= create_uri(NULL
, window
, window
->doc_obj
->nscontainer
, &uri
);
2522 if(NS_FAILED(nsres
))
2525 set_wine_url(uri
, url
);
2526 uri
->is_doc_uri
= TRUE
;
2532 static nsresult
create_nschannel(nsWineURI
*uri
, nsChannel
**ret
)
2537 if(!ensure_uri(uri
))
2538 return NS_ERROR_UNEXPECTED
;
2540 channel
= heap_alloc_zero(sizeof(nsChannel
));
2542 return NS_ERROR_OUT_OF_MEMORY
;
2544 channel
->nsIHttpChannel_iface
.lpVtbl
= &nsChannelVtbl
;
2545 channel
->nsIUploadChannel_iface
.lpVtbl
= &nsUploadChannelVtbl
;
2546 channel
->nsIHttpChannelInternal_iface
.lpVtbl
= &nsHttpChannelInternalVtbl
;
2548 channel
->request_method
= METHOD_GET
;
2549 list_init(&channel
->response_headers
);
2550 list_init(&channel
->request_headers
);
2552 nsIURL_AddRef(&uri
->nsIURL_iface
);
2555 hres
= IUri_GetScheme(uri
->uri
, &channel
->url_scheme
);
2557 channel
->url_scheme
= URL_SCHEME_UNKNOWN
;
2563 HRESULT
create_redirect_nschannel(const WCHAR
*url
, nsChannel
*orig_channel
, nsChannel
**ret
)
2565 HTMLWindow
*window
= NULL
;
2571 if(orig_channel
->uri
->window_ref
)
2572 window
= orig_channel
->uri
->window_ref
->window
;
2573 nsres
= create_uri(NULL
, window
, NULL
, &uri
);
2574 if(NS_FAILED(nsres
))
2577 hres
= CreateUri(url
, 0, 0, &uri
->uri
);
2579 nsres
= create_nschannel(uri
, &channel
);
2581 nsIURL_Release(&uri
->nsIURL_iface
);
2584 if(NS_FAILED(nsres
))
2587 if(orig_channel
->load_group
) {
2588 nsILoadGroup_AddRef(orig_channel
->load_group
);
2589 channel
->load_group
= orig_channel
->load_group
;
2592 if(orig_channel
->notif_callback
) {
2593 nsIInterfaceRequestor_AddRef(orig_channel
->notif_callback
);
2594 channel
->notif_callback
= orig_channel
->notif_callback
;
2597 channel
->load_flags
= orig_channel
->load_flags
| LOAD_REPLACE
;
2599 if(orig_channel
->request_method
== METHOD_POST
)
2600 FIXME("unsupported POST method\n");
2602 if(orig_channel
->original_uri
) {
2603 nsIURI_AddRef(orig_channel
->original_uri
);
2604 channel
->original_uri
= orig_channel
->original_uri
;
2607 if(orig_channel
->referrer
) {
2608 nsIURI_AddRef(orig_channel
->referrer
);
2609 channel
->referrer
= orig_channel
->referrer
;
2617 nsIProtocolHandler nsIProtocolHandler_iface
;
2621 nsIProtocolHandler
*nshandler
;
2622 } nsProtocolHandler
;
2624 static inline nsProtocolHandler
*impl_from_nsIProtocolHandler(nsIProtocolHandler
*iface
)
2626 return CONTAINING_RECORD(iface
, nsProtocolHandler
, nsIProtocolHandler_iface
);
2629 static nsresult NSAPI
nsProtocolHandler_QueryInterface(nsIProtocolHandler
*iface
, nsIIDRef riid
,
2632 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2636 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
2637 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
2638 *result
= &This
->nsIProtocolHandler_iface
;
2639 }else if(IsEqualGUID(&IID_nsIProtocolHandler
, riid
)) {
2640 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This
, result
);
2641 *result
= &This
->nsIProtocolHandler_iface
;
2642 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler
, riid
)) {
2643 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This
, result
);
2644 return NS_NOINTERFACE
;
2648 nsISupports_AddRef((nsISupports
*)*result
);
2652 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
2653 return NS_NOINTERFACE
;
2656 static nsrefcnt NSAPI
nsProtocolHandler_AddRef(nsIProtocolHandler
*iface
)
2658 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2659 LONG ref
= InterlockedIncrement(&This
->ref
);
2661 TRACE("(%p) ref=%d\n", This
, ref
);
2666 static nsrefcnt NSAPI
nsProtocolHandler_Release(nsIProtocolHandler
*iface
)
2668 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2669 LONG ref
= InterlockedDecrement(&This
->ref
);
2671 TRACE("(%p) ref=%d\n", This
, ref
);
2675 nsIProtocolHandler_Release(This
->nshandler
);
2682 static nsresult NSAPI
nsProtocolHandler_GetScheme(nsIProtocolHandler
*iface
, nsACString
*aScheme
)
2684 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2686 TRACE("(%p)->(%p)\n", This
, aScheme
);
2689 return nsIProtocolHandler_GetScheme(This
->nshandler
, aScheme
);
2690 return NS_ERROR_NOT_IMPLEMENTED
;
2693 static nsresult NSAPI
nsProtocolHandler_GetDefaultPort(nsIProtocolHandler
*iface
,
2694 PRInt32
*aDefaultPort
)
2696 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2698 TRACE("(%p)->(%p)\n", This
, aDefaultPort
);
2701 return nsIProtocolHandler_GetDefaultPort(This
->nshandler
, aDefaultPort
);
2702 return NS_ERROR_NOT_IMPLEMENTED
;
2705 static nsresult NSAPI
nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler
*iface
,
2706 PRUint32
*aProtocolFlags
)
2708 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2710 TRACE("(%p)->(%p)\n", This
, aProtocolFlags
);
2713 return nsIProtocolHandler_GetProtocolFlags(This
->nshandler
, aProtocolFlags
);
2714 return NS_ERROR_NOT_IMPLEMENTED
;
2717 static nsresult NSAPI
nsProtocolHandler_NewURI(nsIProtocolHandler
*iface
,
2718 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
2720 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2722 TRACE("((%p)->%s %s %p %p)\n", This
, debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
2726 return nsIProtocolHandler_NewURI(This
->nshandler
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2727 return NS_ERROR_NOT_IMPLEMENTED
;
2730 static nsresult NSAPI
nsProtocolHandler_NewChannel(nsIProtocolHandler
*iface
,
2731 nsIURI
*aURI
, nsIChannel
**_retval
)
2733 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2735 TRACE("(%p)->(%p %p)\n", This
, aURI
, _retval
);
2738 return nsIProtocolHandler_NewChannel(This
->nshandler
, aURI
, _retval
);
2739 return NS_ERROR_NOT_IMPLEMENTED
;
2742 static nsresult NSAPI
nsProtocolHandler_AllowPort(nsIProtocolHandler
*iface
,
2743 PRInt32 port
, const char *scheme
, PRBool
*_retval
)
2745 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2747 TRACE("(%p)->(%d %s %p)\n", This
, port
, debugstr_a(scheme
), _retval
);
2750 return nsIProtocolHandler_AllowPort(This
->nshandler
, port
, scheme
, _retval
);
2751 return NS_ERROR_NOT_IMPLEMENTED
;
2754 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl
= {
2755 nsProtocolHandler_QueryInterface
,
2756 nsProtocolHandler_AddRef
,
2757 nsProtocolHandler_Release
,
2758 nsProtocolHandler_GetScheme
,
2759 nsProtocolHandler_GetDefaultPort
,
2760 nsProtocolHandler_GetProtocolFlags
,
2761 nsProtocolHandler_NewURI
,
2762 nsProtocolHandler_NewChannel
,
2763 nsProtocolHandler_AllowPort
2766 static nsIProtocolHandler
*create_protocol_handler(nsIProtocolHandler
*nshandler
)
2768 nsProtocolHandler
*ret
= heap_alloc(sizeof(nsProtocolHandler
));
2770 ret
->nsIProtocolHandler_iface
.lpVtbl
= &nsProtocolHandlerVtbl
;
2772 ret
->nshandler
= nshandler
;
2774 return &ret
->nsIProtocolHandler_iface
;
2777 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*,nsIIDRef
,void**);
2779 static nsrefcnt NSAPI
nsIOService_AddRef(nsIIOService
*iface
)
2784 static nsrefcnt NSAPI
nsIOService_Release(nsIIOService
*iface
)
2789 static nsresult NSAPI
nsIOService_GetProtocolHandler(nsIIOService
*iface
, const char *aScheme
,
2790 nsIProtocolHandler
**_retval
)
2792 nsIExternalProtocolHandler
*nsexthandler
;
2793 nsIProtocolHandler
*nshandler
;
2796 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
2798 nsres
= nsIIOService_GetProtocolHandler(nsio
, aScheme
, &nshandler
);
2799 if(NS_FAILED(nsres
)) {
2800 WARN("GetProtocolHandler failed: %08x\n", nsres
);
2804 nsres
= nsIProtocolHandler_QueryInterface(nshandler
, &IID_nsIExternalProtocolHandler
,
2805 (void**)&nsexthandler
);
2806 if(NS_FAILED(nsres
)) {
2807 *_retval
= nshandler
;
2811 nsIExternalProtocolHandler_Release(nsexthandler
);
2812 *_retval
= create_protocol_handler(nshandler
);
2813 TRACE("return %p\n", *_retval
);
2817 static nsresult NSAPI
nsIOService_GetProtocolFlags(nsIIOService
*iface
, const char *aScheme
,
2820 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
2821 return nsIIOService_GetProtocolFlags(nsio
, aScheme
, _retval
);
2824 static BOOL
is_gecko_special_uri(const char *spec
)
2826 static const char *special_schemes
[] = {"chrome:", "jar:", "moz-safe-about", "resource:", "javascript:", "wyciwyg:"};
2829 for(i
=0; i
< sizeof(special_schemes
)/sizeof(*special_schemes
); i
++) {
2830 if(!strncasecmp(spec
, special_schemes
[i
], strlen(special_schemes
[i
])))
2834 if(!strncasecmp(spec
, "file:", 5)) {
2835 const char *ptr
= spec
+5;
2838 return is_gecko_path(ptr
);
2844 static nsresult NSAPI
nsIOService_NewURI(nsIIOService
*iface
, const nsACString
*aSpec
,
2845 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
2847 nsWineURI
*wine_uri
, *base_wine_uri
= NULL
;
2848 WCHAR new_spec
[INTERNET_MAX_URL_LENGTH
];
2849 HTMLWindow
*window
= NULL
;
2850 const char *spec
= NULL
;
2856 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
2859 nsACString_GetData(aSpec
, &spec
);
2860 if(is_gecko_special_uri(spec
))
2861 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2863 if(!strncmp(spec
, "wine:", 5))
2867 nsres
= nsIURI_QueryInterface(aBaseURI
, &IID_nsWineURI
, (void**)&base_wine_uri
);
2868 if(NS_SUCCEEDED(nsres
)) {
2869 if(!ensure_uri(base_wine_uri
))
2870 return NS_ERROR_UNEXPECTED
;
2871 if(base_wine_uri
->window_ref
)
2872 window
= base_wine_uri
->window_ref
->window
;
2874 WARN("Could not get base nsWineURI: %08x\n", nsres
);
2878 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, new_spec
, sizeof(new_spec
)/sizeof(WCHAR
));
2881 hres
= CoInternetCombineUrlEx(base_wine_uri
->uri
, new_spec
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
2884 WARN("CoInternetCombineUrlEx failed: %08x\n", hres
);
2886 hres
= CreateUri(new_spec
, 0, 0, &urlmon_uri
);
2888 WARN("CreateUri failed: %08x\n", hres
);
2891 nsres
= nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, &uri
);
2892 if(NS_FAILED(nsres
))
2893 TRACE("NewURI failed: %08x\n", nsres
);
2900 nsres
= create_uri(uri
, window
, NULL
, &wine_uri
);
2902 nsIURI_Release(&base_wine_uri
->nsIURL_iface
);
2903 if(NS_FAILED(nsres
))
2906 wine_uri
->uri
= urlmon_uri
;
2908 sync_wine_url(wine_uri
);
2909 *_retval
= (nsIURI
*)wine_uri
;
2913 static nsresult NSAPI
nsIOService_NewFileURI(nsIIOService
*iface
, nsIFile
*aFile
,
2916 TRACE("(%p %p)\n", aFile
, _retval
);
2917 return nsIIOService_NewFileURI(nsio
, aFile
, _retval
);
2920 static nsresult NSAPI
nsIOService_NewChannelFromURI(nsIIOService
*iface
, nsIURI
*aURI
,
2921 nsIChannel
**_retval
)
2923 nsWineURI
*wine_uri
;
2927 TRACE("(%p %p)\n", aURI
, _retval
);
2929 nsres
= nsIURI_QueryInterface(aURI
, &IID_nsWineURI
, (void**)&wine_uri
);
2930 if(NS_FAILED(nsres
)) {
2931 TRACE("Could not get nsWineURI: %08x\n", nsres
);
2932 return nsIIOService_NewChannelFromURI(nsio
, aURI
, _retval
);
2935 nsres
= create_nschannel(wine_uri
, &ret
);
2936 nsIURL_Release(&wine_uri
->nsIURL_iface
);
2937 if(NS_FAILED(nsres
))
2940 nsIURI_AddRef(aURI
);
2941 ret
->original_uri
= aURI
;
2943 *_retval
= (nsIChannel
*)&ret
->nsIHttpChannel_iface
;
2947 static nsresult NSAPI
nsIOService_NewChannel(nsIIOService
*iface
, const nsACString
*aSpec
,
2948 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIChannel
**_retval
)
2950 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
), aBaseURI
, _retval
);
2951 return nsIIOService_NewChannel(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2954 static nsresult NSAPI
nsIOService_GetOffline(nsIIOService
*iface
, PRBool
*aOffline
)
2956 TRACE("(%p)\n", aOffline
);
2957 return nsIIOService_GetOffline(nsio
, aOffline
);
2960 static nsresult NSAPI
nsIOService_SetOffline(nsIIOService
*iface
, PRBool aOffline
)
2962 TRACE("(%x)\n", aOffline
);
2963 return nsIIOService_SetOffline(nsio
, aOffline
);
2966 static nsresult NSAPI
nsIOService_AllowPort(nsIIOService
*iface
, PRInt32 aPort
,
2967 const char *aScheme
, PRBool
*_retval
)
2969 TRACE("(%d %s %p)\n", aPort
, debugstr_a(aScheme
), _retval
);
2970 return nsIIOService_AllowPort(nsio
, aPort
, debugstr_a(aScheme
), _retval
);
2973 static nsresult NSAPI
nsIOService_ExtractScheme(nsIIOService
*iface
, const nsACString
*urlString
,
2974 nsACString
* _retval
)
2976 TRACE("(%s %p)\n", debugstr_nsacstr(urlString
), _retval
);
2977 return nsIIOService_ExtractScheme(nsio
, urlString
, _retval
);
2980 static const nsIIOServiceVtbl nsIOServiceVtbl
= {
2981 nsIOService_QueryInterface
,
2983 nsIOService_Release
,
2984 nsIOService_GetProtocolHandler
,
2985 nsIOService_GetProtocolFlags
,
2987 nsIOService_NewFileURI
,
2988 nsIOService_NewChannelFromURI
,
2989 nsIOService_NewChannel
,
2990 nsIOService_GetOffline
,
2991 nsIOService_SetOffline
,
2992 nsIOService_AllowPort
,
2993 nsIOService_ExtractScheme
2996 static nsIIOService nsIOService
= { &nsIOServiceVtbl
};
2998 static nsresult NSAPI
nsNetUtil_QueryInterface(nsINetUtil
*iface
, nsIIDRef riid
,
3001 return nsIIOService_QueryInterface(&nsIOService
, riid
, result
);
3004 static nsrefcnt NSAPI
nsNetUtil_AddRef(nsINetUtil
*iface
)
3009 static nsrefcnt NSAPI
nsNetUtil_Release(nsINetUtil
*iface
)
3014 static nsresult NSAPI
nsNetUtil_ParseContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
3015 nsACString
*aCharset
, PRBool
*aHadCharset
, nsACString
*aContentType
)
3017 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aHadCharset
, aContentType
);
3019 return nsINetUtil_ParseContentType(net_util
, aTypeHeader
, aCharset
, aHadCharset
, aContentType
);
3022 static nsresult NSAPI
nsNetUtil_ProtocolHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, PRUint32 aFlags
, PRBool
*_retval
)
3026 return nsINetUtil_ProtocolHasFlags(net_util
, aURI
, aFlags
, _retval
);
3029 static nsresult NSAPI
nsNetUtil_URIChainHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, PRUint32 aFlags
, PRBool
*_retval
)
3031 TRACE("(%p %08x %p)\n", aURI
, aFlags
, _retval
);
3033 if(aFlags
== (1<<11)) {
3038 return nsINetUtil_URIChainHasFlags(net_util
, aURI
, aFlags
, _retval
);
3041 static nsresult NSAPI
nsNetUtil_ToImmutableURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
3043 TRACE("(%p %p)\n", aURI
, _retval
);
3045 return nsINetUtil_ToImmutableURI(net_util
, aURI
, _retval
);
3048 static nsresult NSAPI
nsNetUtil_NewSimpleNestedURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
3050 TRACE("(%p %p)\n", aURI
, _retval
);
3052 return nsINetUtil_NewSimpleNestedURI(net_util
, aURI
, _retval
);
3055 static nsresult NSAPI
nsNetUtil_EscapeString(nsINetUtil
*iface
, const nsACString
*aString
,
3056 PRUint32 aEscapeType
, nsACString
*_retval
)
3058 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString
), aEscapeType
, _retval
);
3060 return nsINetUtil_EscapeString(net_util
, aString
, aEscapeType
, _retval
);
3063 static nsresult NSAPI
nsNetUtil_EscapeURL(nsINetUtil
*iface
, const nsACString
*aStr
, PRUint32 aFlags
,
3064 nsACString
*_retval
)
3066 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
3068 return nsINetUtil_EscapeURL(net_util
, aStr
, aFlags
, _retval
);
3071 static nsresult NSAPI
nsNetUtil_UnescapeString(nsINetUtil
*iface
, const nsACString
*aStr
,
3072 PRUint32 aFlags
, nsACString
*_retval
)
3074 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
3076 return nsINetUtil_UnescapeString(net_util
, aStr
, aFlags
, _retval
);
3079 static nsresult NSAPI
nsNetUtil_ExtractCharsetFromContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
3080 nsACString
*aCharset
, PRInt32
*aCharsetStart
, PRInt32
*aCharsetEnd
, PRBool
*_retval
)
3082 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aCharsetStart
,
3083 aCharsetEnd
, _retval
);
3085 return nsINetUtil_ExtractCharsetFromContentType(net_util
, aTypeHeader
, aCharset
, aCharsetStart
, aCharsetEnd
, _retval
);
3088 static const nsINetUtilVtbl nsNetUtilVtbl
= {
3089 nsNetUtil_QueryInterface
,
3092 nsNetUtil_ParseContentType
,
3093 nsNetUtil_ProtocolHasFlags
,
3094 nsNetUtil_URIChainHasFlags
,
3095 nsNetUtil_ToImmutableURI
,
3096 nsNetUtil_NewSimpleNestedURI
,
3097 nsNetUtil_EscapeString
,
3098 nsNetUtil_EscapeURL
,
3099 nsNetUtil_UnescapeString
,
3100 nsNetUtil_ExtractCharsetFromContentType
3103 static nsINetUtil nsNetUtil
= { &nsNetUtilVtbl
};
3105 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*iface
, nsIIDRef riid
,
3110 if(IsEqualGUID(&IID_nsISupports
, riid
))
3111 *result
= &nsIOService
;
3112 else if(IsEqualGUID(&IID_nsIIOService
, riid
))
3113 *result
= &nsIOService
;
3114 else if(IsEqualGUID(&IID_nsINetUtil
, riid
))
3115 *result
= &nsNetUtil
;
3118 nsISupports_AddRef((nsISupports
*)*result
);
3122 FIXME("(%s %p)\n", debugstr_guid(riid
), result
);
3123 return NS_NOINTERFACE
;
3126 static nsresult NSAPI
nsIOServiceFactory_QueryInterface(nsIFactory
*iface
, nsIIDRef riid
,
3131 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
3132 TRACE("(IID_nsISupports %p)\n", result
);
3134 }else if(IsEqualGUID(&IID_nsIFactory
, riid
)) {
3135 TRACE("(IID_nsIFactory %p)\n", result
);
3140 nsIFactory_AddRef(iface
);
3144 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
3145 return NS_NOINTERFACE
;
3148 static nsrefcnt NSAPI
nsIOServiceFactory_AddRef(nsIFactory
*iface
)
3153 static nsrefcnt NSAPI
nsIOServiceFactory_Release(nsIFactory
*iface
)
3158 static nsresult NSAPI
nsIOServiceFactory_CreateInstance(nsIFactory
*iface
,
3159 nsISupports
*aOuter
, const nsIID
*iid
, void **result
)
3161 return nsIIOService_QueryInterface(&nsIOService
, iid
, result
);
3164 static nsresult NSAPI
nsIOServiceFactory_LockFactory(nsIFactory
*iface
, PRBool lock
)
3166 WARN("(%x)\n", lock
);
3170 static const nsIFactoryVtbl nsIOServiceFactoryVtbl
= {
3171 nsIOServiceFactory_QueryInterface
,
3172 nsIOServiceFactory_AddRef
,
3173 nsIOServiceFactory_Release
,
3174 nsIOServiceFactory_CreateInstance
,
3175 nsIOServiceFactory_LockFactory
3178 static nsIFactory nsIOServiceFactory
= { &nsIOServiceFactoryVtbl
};
3180 static BOOL
translate_url(HTMLDocumentObj
*doc
, nsWineURI
*uri
)
3182 OLECHAR
*new_url
= NULL
;
3187 if(!doc
->hostui
|| !ensure_uri(uri
))
3190 hres
= IUri_GetDisplayUri(uri
->uri
, &url
);
3194 hres
= IDocHostUIHandler_TranslateUrl(doc
->hostui
, 0, url
, &new_url
);
3195 if(hres
== S_OK
&& new_url
) {
3196 if(strcmpW(url
, new_url
)) {
3197 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url
), debugstr_w(new_url
));
3200 CoTaskMemFree(new_url
);
3207 nsresult
on_start_uri_open(NSContainer
*nscontainer
, nsIURI
*uri
, PRBool
*_retval
)
3209 nsWineURI
*wine_uri
;
3214 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
3215 if(NS_FAILED(nsres
)) {
3216 WARN("Could not get nsWineURI: %08x\n", nsres
);
3217 return NS_ERROR_NOT_IMPLEMENTED
;
3220 if(!wine_uri
->is_doc_uri
) {
3221 wine_uri
->is_doc_uri
= TRUE
;
3223 if(!wine_uri
->container
) {
3224 nsIWebBrowserChrome_AddRef(&nscontainer
->nsIWebBrowserChrome_iface
);
3225 wine_uri
->container
= nscontainer
;
3228 if(nscontainer
->doc
)
3229 *_retval
= translate_url(nscontainer
->doc
, wine_uri
);
3232 nsIURI_Release(&wine_uri
->nsIURL_iface
);
3236 void init_nsio(nsIComponentManager
*component_manager
, nsIComponentRegistrar
*registrar
)
3238 nsIFactory
*old_factory
= NULL
;
3241 nsres
= nsIComponentManager_GetClassObject(component_manager
, &NS_IOSERVICE_CID
,
3242 &IID_nsIFactory
, (void**)&old_factory
);
3243 if(NS_FAILED(nsres
)) {
3244 ERR("Could not get factory: %08x\n", nsres
);
3248 nsres
= nsIFactory_CreateInstance(old_factory
, NULL
, &IID_nsIIOService
, (void**)&nsio
);
3249 if(NS_FAILED(nsres
)) {
3250 ERR("Couldn not create nsIOService instance %08x\n", nsres
);
3251 nsIFactory_Release(old_factory
);
3255 nsres
= nsIIOService_QueryInterface(nsio
, &IID_nsINetUtil
, (void**)&net_util
);
3256 if(NS_FAILED(nsres
)) {
3257 WARN("Could not get nsINetUtil interface: %08x\n", nsres
);
3258 nsIIOService_Release(nsio
);
3262 nsres
= nsIComponentRegistrar_UnregisterFactory(registrar
, &NS_IOSERVICE_CID
, old_factory
);
3263 nsIFactory_Release(old_factory
);
3264 if(NS_FAILED(nsres
))
3265 ERR("UnregisterFactory failed: %08x\n", nsres
);
3267 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_IOSERVICE_CID
,
3268 NS_IOSERVICE_CLASSNAME
, NS_IOSERVICE_CONTRACTID
, &nsIOServiceFactory
);
3269 if(NS_FAILED(nsres
))
3270 ERR("RegisterFactory failed: %08x\n", nsres
);
3273 void release_nsio(void)
3276 nsINetUtil_Release(net_util
);
3281 nsIIOService_Release(nsio
);