2 * Copyright 2006-2010 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
35 #include "wine/debug.h"
37 #include "mshtml_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
42 #define NS_IOSERVICE_CLASSNAME "nsIOService"
43 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
45 static const IID NS_IOSERVICE_CID
=
46 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
47 static const IID IID_nsWineURI
=
48 {0x5088272e, 0x900b, 0x11da, {0xc6,0x87, 0x00,0x0f,0xea,0x57,0xf2,0x1a}};
50 static nsIIOService
*nsio
= NULL
;
51 static nsINetUtil
*net_util
;
53 static const char *request_method_strings
[] = {"GET", "PUT", "POST"};
57 nsIStandardURL nsIStandardURL_iface
;
63 NSContainer
*container
;
64 windowref_t
*window_ref
;
65 nsChannelBSC
*channel_bsc
;
67 IUriBuilder
*uri_builder
;
71 static BOOL
ensure_uri(nsWineURI
*This
)
75 assert(This
->uri
|| This
->uri_builder
);
78 hres
= IUriBuilder_CreateUriSimple(This
->uri_builder
, 0, 0, &This
->uri
);
80 WARN("CreateUriSimple failed: %08x\n", hres
);
88 IUri
*nsuri_get_uri(nsWineURI
*nsuri
)
90 if(!ensure_uri(nsuri
))
93 IUri_AddRef(nsuri
->uri
);
97 static IUri
*get_uri_nofrag(IUri
*uri
)
99 IUriBuilder
*uri_builder
;
104 hres
= IUri_HasProperty(uri
, Uri_PROPERTY_FRAGMENT
, &b
);
105 if(SUCCEEDED(hres
) && !b
) {
110 hres
= CreateIUriBuilder(uri
, 0, 0, &uri_builder
);
114 hres
= IUriBuilder_RemoveProperties(uri_builder
, Uri_HAS_FRAGMENT
);
116 hres
= IUriBuilder_CreateUriSimple(uri_builder
, 0, 0, &ret
);
117 IUriBuilder_Release(uri_builder
);
124 BOOL
compare_ignoring_frag(IUri
*uri1
, IUri
*uri2
)
126 IUri
*uri_nofrag1
, *uri_nofrag2
;
129 uri_nofrag1
= get_uri_nofrag(uri1
);
133 uri_nofrag2
= get_uri_nofrag(uri2
);
135 IUri_IsEqual(uri_nofrag1
, uri_nofrag2
, &ret
);
136 IUri_Release(uri_nofrag2
);
139 IUri_Release(uri_nofrag1
);
143 static nsresult
create_nsuri(IUri
*,nsIURI
*,HTMLWindow
*,NSContainer
*,nsWineURI
**);
145 static const char *debugstr_nsacstr(const nsACString
*nsstr
)
149 nsACString_GetData(nsstr
, &data
);
150 return debugstr_a(data
);
153 HRESULT
nsuri_to_url(LPCWSTR nsuri
, BOOL ret_empty
, BSTR
*ret
)
155 const WCHAR
*ptr
= nsuri
;
157 static const WCHAR wine_prefixW
[] = {'w','i','n','e',':'};
159 if(!strncmpW(nsuri
, wine_prefixW
, sizeof(wine_prefixW
)/sizeof(WCHAR
)))
160 ptr
+= sizeof(wine_prefixW
)/sizeof(WCHAR
);
162 if(*ptr
|| ret_empty
) {
163 *ret
= SysAllocString(ptr
);
165 return E_OUTOFMEMORY
;
170 TRACE("%s -> %s\n", debugstr_w(nsuri
), debugstr_w(*ret
));
174 static BOOL
exec_shldocvw_67(HTMLDocumentObj
*doc
, BSTR url
)
176 IOleCommandTarget
*cmdtrg
= NULL
;
179 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
180 if(SUCCEEDED(hres
)) {
181 VARIANT varUrl
, varRes
;
183 V_VT(&varUrl
) = VT_BSTR
;
184 V_BSTR(&varUrl
) = url
;
185 V_VT(&varRes
) = VT_BOOL
;
187 hres
= IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 67, 0, &varUrl
, &varRes
);
189 IOleCommandTarget_Release(cmdtrg
);
191 if(SUCCEEDED(hres
) && !V_BOOL(&varRes
)) {
192 TRACE("got VARIANT_FALSE, do not load\n");
200 static nsresult
before_async_open(nsChannel
*channel
, NSContainer
*container
, BOOL
*cancel
)
202 HTMLDocumentObj
*doc
= container
->doc
;
208 NSContainer
*container_iter
= container
;
210 hlnf
= HLNF_OPENINNEWWINDOW
;
211 while(!container_iter
->doc
)
212 container_iter
= container_iter
->parent
;
213 doc
= container_iter
->doc
;
221 hres
= IUri_GetDisplayUri(channel
->uri
->uri
, &display_uri
);
223 return NS_ERROR_FAILURE
;
228 b
= !exec_shldocvw_67(doc
, display_uri
);
230 SysFreeString(display_uri
);
236 hres
= hlink_frame_navigate(&doc
->basedoc
, display_uri
, channel
, hlnf
, cancel
);
237 SysFreeString(display_uri
);
243 HRESULT
load_nsuri(HTMLWindow
*window
, nsWineURI
*uri
, nsChannelBSC
*channelbsc
, DWORD flags
)
245 nsIWebNavigation
*web_navigation
;
246 nsIDocShell
*doc_shell
;
247 HTMLDocumentNode
*doc
;
250 nsres
= get_nsinterface((nsISupports
*)window
->nswindow
, &IID_nsIWebNavigation
, (void**)&web_navigation
);
251 if(NS_FAILED(nsres
)) {
252 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
256 nsres
= nsIWebNavigation_QueryInterface(web_navigation
, &IID_nsIDocShell
, (void**)&doc_shell
);
257 nsIWebNavigation_Release(web_navigation
);
258 if(NS_FAILED(nsres
)) {
259 ERR("Could not get nsIDocShell: %08x\n", nsres
);
263 uri
->channel_bsc
= channelbsc
;
265 doc
->skip_mutation_notif
= TRUE
;
266 nsres
= nsIDocShell_LoadURI(doc_shell
, (nsIURI
*)&uri
->nsIURL_iface
, NULL
, flags
, FALSE
);
267 if(doc
== window
->doc
)
268 doc
->skip_mutation_notif
= FALSE
;
269 uri
->channel_bsc
= NULL
;
270 nsIDocShell_Release(doc_shell
);
271 if(NS_FAILED(nsres
)) {
272 WARN("LoadURI failed: %08x\n", nsres
);
279 static void set_uri_nscontainer(nsWineURI
*This
, NSContainer
*nscontainer
)
281 if(This
->container
) {
282 if(This
->container
== nscontainer
)
284 TRACE("Changing %p -> %p\n", This
->container
, nscontainer
);
285 nsIWebBrowserChrome_Release(&This
->container
->nsIWebBrowserChrome_iface
);
289 nsIWebBrowserChrome_AddRef(&nscontainer
->nsIWebBrowserChrome_iface
);
290 This
->container
= nscontainer
;
293 static void set_uri_window(nsWineURI
*This
, HTMLWindow
*window
)
295 if(This
->window_ref
) {
296 if(This
->window_ref
->window
== window
)
298 TRACE("Changing %p -> %p\n", This
->window_ref
->window
, window
);
299 windowref_release(This
->window_ref
);
303 windowref_addref(window
->window_ref
);
304 This
->window_ref
= window
->window_ref
;
307 set_uri_nscontainer(This
, window
->doc_obj
->nscontainer
);
309 This
->window_ref
= NULL
;
313 static inline BOOL
is_http_channel(nsChannel
*This
)
315 return This
->url_scheme
== URL_SCHEME_HTTP
|| This
->url_scheme
== URL_SCHEME_HTTPS
;
318 static http_header_t
*find_http_header(struct list
*headers
, const WCHAR
*name
, int len
)
322 LIST_FOR_EACH_ENTRY(iter
, headers
, http_header_t
, entry
) {
323 if(!strcmpiW(iter
->header
, name
))
330 static nsresult
get_channel_http_header(struct list
*headers
, const nsACString
*header_name_str
,
333 const char *header_namea
;
334 http_header_t
*header
;
338 nsACString_GetData(header_name_str
, &header_namea
);
339 header_name
= heap_strdupAtoW(header_namea
);
341 return NS_ERROR_UNEXPECTED
;
343 header
= find_http_header(headers
, header_name
, strlenW(header_name
));
344 heap_free(header_name
);
346 return NS_ERROR_NOT_AVAILABLE
;
348 data
= heap_strdupWtoA(header
->data
);
350 return NS_ERROR_UNEXPECTED
;
352 TRACE("%s -> %s\n", debugstr_a(header_namea
), debugstr_a(data
));
353 nsACString_SetData(_retval
, data
);
358 HRESULT
set_http_header(struct list
*headers
, const WCHAR
*name
, int name_len
,
359 const WCHAR
*value
, int value_len
)
361 http_header_t
*header
;
363 TRACE("%s: %s\n", debugstr_wn(name
, name_len
), debugstr_wn(value
, value_len
));
365 header
= find_http_header(headers
, name
, name_len
);
369 new_data
= heap_strndupW(value
, value_len
);
371 return E_OUTOFMEMORY
;
373 heap_free(header
->data
);
374 header
->data
= new_data
;
376 header
= heap_alloc(sizeof(http_header_t
));
378 return E_OUTOFMEMORY
;
380 header
->header
= heap_strndupW(name
, name_len
);
381 header
->data
= heap_strndupW(value
, value_len
);
382 if(!header
->header
|| !header
->data
) {
383 heap_free(header
->header
);
384 heap_free(header
->data
);
386 return E_OUTOFMEMORY
;
389 list_add_tail(headers
, &header
->entry
);
395 static nsresult
set_channel_http_header(struct list
*headers
, const nsACString
*name_str
,
396 const nsACString
*value_str
)
398 const char *namea
, *valuea
;
402 nsACString_GetData(name_str
, &namea
);
403 name
= heap_strdupAtoW(namea
);
405 return NS_ERROR_UNEXPECTED
;
407 nsACString_GetData(value_str
, &valuea
);
408 value
= heap_strdupAtoW(valuea
);
411 return NS_ERROR_UNEXPECTED
;
414 hres
= set_http_header(headers
, name
, strlenW(name
), value
, strlenW(value
));
418 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_UNEXPECTED
;
421 static nsresult
visit_http_headers(struct list
*headers
, nsIHttpHeaderVisitor
*visitor
)
423 nsACString header_str
, value_str
;
424 char *header
, *value
;
428 LIST_FOR_EACH_ENTRY(iter
, headers
, http_header_t
, entry
) {
429 header
= heap_strdupWtoA(iter
->header
);
431 return NS_ERROR_OUT_OF_MEMORY
;
433 value
= heap_strdupWtoA(iter
->data
);
436 return NS_ERROR_OUT_OF_MEMORY
;
439 nsACString_InitDepend(&header_str
, header
);
440 nsACString_InitDepend(&value_str
, value
);
441 nsres
= nsIHttpHeaderVisitor_VisitHeader(visitor
, &header_str
, &value_str
);
442 nsACString_Finish(&header_str
);
443 nsACString_Finish(&value_str
);
453 static void free_http_headers(struct list
*list
)
455 http_header_t
*iter
, *iter_next
;
457 LIST_FOR_EACH_ENTRY_SAFE(iter
, iter_next
, list
, http_header_t
, entry
) {
458 list_remove(&iter
->entry
);
459 heap_free(iter
->header
);
460 heap_free(iter
->data
);
465 static inline nsChannel
*impl_from_nsIHttpChannel(nsIHttpChannel
*iface
)
467 return CONTAINING_RECORD(iface
, nsChannel
, nsIHttpChannel_iface
);
470 static nsresult NSAPI
nsChannel_QueryInterface(nsIHttpChannel
*iface
, nsIIDRef riid
, void **result
)
472 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
474 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
475 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
476 *result
= &This
->nsIHttpChannel_iface
;
477 }else if(IsEqualGUID(&IID_nsIRequest
, riid
)) {
478 TRACE("(%p)->(IID_nsIRequest %p)\n", This
, result
);
479 *result
= &This
->nsIHttpChannel_iface
;
480 }else if(IsEqualGUID(&IID_nsIChannel
, riid
)) {
481 TRACE("(%p)->(IID_nsIChannel %p)\n", This
, result
);
482 *result
= &This
->nsIHttpChannel_iface
;
483 }else if(IsEqualGUID(&IID_nsIHttpChannel
, riid
)) {
484 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This
, result
);
485 *result
= is_http_channel(This
) ? &This
->nsIHttpChannel_iface
: NULL
;
486 }else if(IsEqualGUID(&IID_nsIUploadChannel
, riid
)) {
487 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This
, result
);
488 *result
= &This
->nsIUploadChannel_iface
;
489 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal
, riid
)) {
490 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This
, result
);
491 *result
= is_http_channel(This
) ? &This
->nsIHttpChannelInternal_iface
: NULL
;
493 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
498 nsIChannel_AddRef(&This
->nsIHttpChannel_iface
);
502 return NS_NOINTERFACE
;
505 static nsrefcnt NSAPI
nsChannel_AddRef(nsIHttpChannel
*iface
)
507 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
508 nsrefcnt ref
= InterlockedIncrement(&This
->ref
);
510 TRACE("(%p) ref=%d\n", This
, ref
);
515 static nsrefcnt NSAPI
nsChannel_Release(nsIHttpChannel
*iface
)
517 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
518 LONG ref
= InterlockedDecrement(&This
->ref
);
521 nsIURI_Release(&This
->uri
->nsIURL_iface
);
523 nsISupports_Release(This
->owner
);
524 if(This
->post_data_stream
)
525 nsIInputStream_Release(This
->post_data_stream
);
527 nsILoadGroup_Release(This
->load_group
);
528 if(This
->notif_callback
)
529 nsIInterfaceRequestor_Release(This
->notif_callback
);
530 if(This
->original_uri
)
531 nsIURI_Release(This
->original_uri
);
533 nsIURI_Release(This
->referrer
);
535 free_http_headers(&This
->response_headers
);
536 free_http_headers(&This
->request_headers
);
538 heap_free(This
->content_type
);
539 heap_free(This
->charset
);
546 static nsresult NSAPI
nsChannel_GetName(nsIHttpChannel
*iface
, nsACString
*aName
)
548 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
550 TRACE("(%p)->(%p)\n", This
, aName
);
552 return nsIURI_GetSpec(&This
->uri
->nsIURL_iface
, aName
);
555 static nsresult NSAPI
nsChannel_IsPending(nsIHttpChannel
*iface
, PRBool
*_retval
)
557 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
559 FIXME("(%p)->(%p)\n", This
, _retval
);
561 return NS_ERROR_NOT_IMPLEMENTED
;
564 static nsresult NSAPI
nsChannel_GetStatus(nsIHttpChannel
*iface
, nsresult
*aStatus
)
566 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
568 WARN("(%p)->(%p) returning NS_OK\n", This
, aStatus
);
570 return *aStatus
= NS_OK
;
573 static nsresult NSAPI
nsChannel_Cancel(nsIHttpChannel
*iface
, nsresult aStatus
)
575 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
577 FIXME("(%p)->(%08x)\n", This
, aStatus
);
579 return NS_ERROR_NOT_IMPLEMENTED
;
582 static nsresult NSAPI
nsChannel_Suspend(nsIHttpChannel
*iface
)
584 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
586 FIXME("(%p)\n", This
);
588 return NS_ERROR_NOT_IMPLEMENTED
;
591 static nsresult NSAPI
nsChannel_Resume(nsIHttpChannel
*iface
)
593 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
595 FIXME("(%p)\n", This
);
597 return NS_ERROR_NOT_IMPLEMENTED
;
600 static nsresult NSAPI
nsChannel_GetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
**aLoadGroup
)
602 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
604 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
607 nsILoadGroup_AddRef(This
->load_group
);
609 *aLoadGroup
= This
->load_group
;
613 static nsresult NSAPI
nsChannel_SetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
*aLoadGroup
)
615 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
617 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
620 nsILoadGroup_Release(This
->load_group
);
622 nsILoadGroup_AddRef(aLoadGroup
);
623 This
->load_group
= aLoadGroup
;
628 static nsresult NSAPI
nsChannel_GetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags
*aLoadFlags
)
630 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
632 TRACE("(%p)->(%p)\n", This
, aLoadFlags
);
634 *aLoadFlags
= This
->load_flags
;
638 static nsresult NSAPI
nsChannel_SetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags aLoadFlags
)
640 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
642 TRACE("(%p)->(%08x)\n", This
, aLoadFlags
);
644 This
->load_flags
= aLoadFlags
;
648 static nsresult NSAPI
nsChannel_GetOriginalURI(nsIHttpChannel
*iface
, nsIURI
**aOriginalURI
)
650 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
652 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
654 if(This
->original_uri
)
655 nsIURI_AddRef(This
->original_uri
);
657 *aOriginalURI
= This
->original_uri
;
661 static nsresult NSAPI
nsChannel_SetOriginalURI(nsIHttpChannel
*iface
, nsIURI
*aOriginalURI
)
663 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
665 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
667 if(This
->original_uri
)
668 nsIURI_Release(This
->original_uri
);
670 nsIURI_AddRef(aOriginalURI
);
671 This
->original_uri
= aOriginalURI
;
675 static nsresult NSAPI
nsChannel_GetURI(nsIHttpChannel
*iface
, nsIURI
**aURI
)
677 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
679 TRACE("(%p)->(%p)\n", This
, aURI
);
681 nsIURI_AddRef(&This
->uri
->nsIURL_iface
);
682 *aURI
= (nsIURI
*)This
->uri
;
687 static nsresult NSAPI
nsChannel_GetOwner(nsIHttpChannel
*iface
, nsISupports
**aOwner
)
689 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
691 TRACE("(%p)->(%p)\n", This
, aOwner
);
694 nsISupports_AddRef(This
->owner
);
695 *aOwner
= This
->owner
;
700 static nsresult NSAPI
nsChannel_SetOwner(nsIHttpChannel
*iface
, nsISupports
*aOwner
)
702 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
704 TRACE("(%p)->(%p)\n", This
, aOwner
);
707 nsISupports_AddRef(aOwner
);
709 nsISupports_Release(This
->owner
);
710 This
->owner
= aOwner
;
715 static nsresult NSAPI
nsChannel_GetNotificationCallbacks(nsIHttpChannel
*iface
,
716 nsIInterfaceRequestor
**aNotificationCallbacks
)
718 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
720 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
722 if(This
->notif_callback
)
723 nsIInterfaceRequestor_AddRef(This
->notif_callback
);
724 *aNotificationCallbacks
= This
->notif_callback
;
729 static nsresult NSAPI
nsChannel_SetNotificationCallbacks(nsIHttpChannel
*iface
,
730 nsIInterfaceRequestor
*aNotificationCallbacks
)
732 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
734 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
736 if(This
->notif_callback
)
737 nsIInterfaceRequestor_Release(This
->notif_callback
);
738 if(aNotificationCallbacks
)
739 nsIInterfaceRequestor_AddRef(aNotificationCallbacks
);
741 This
->notif_callback
= aNotificationCallbacks
;
746 static nsresult NSAPI
nsChannel_GetSecurityInfo(nsIHttpChannel
*iface
, nsISupports
**aSecurityInfo
)
748 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
750 TRACE("(%p)->(%p)\n", This
, aSecurityInfo
);
752 return NS_ERROR_NOT_IMPLEMENTED
;
755 static nsresult NSAPI
nsChannel_GetContentType(nsIHttpChannel
*iface
, nsACString
*aContentType
)
757 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
759 TRACE("(%p)->(%p)\n", This
, aContentType
);
761 if(This
->content_type
) {
762 nsACString_SetData(aContentType
, This
->content_type
);
766 WARN("unknown type\n");
767 return NS_ERROR_FAILURE
;
770 static nsresult NSAPI
nsChannel_SetContentType(nsIHttpChannel
*iface
,
771 const nsACString
*aContentType
)
773 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
774 const char *content_type
;
776 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentType
));
778 nsACString_GetData(aContentType
, &content_type
);
779 heap_free(This
->content_type
);
780 This
->content_type
= heap_strdupA(content_type
);
785 static nsresult NSAPI
nsChannel_GetContentCharset(nsIHttpChannel
*iface
,
786 nsACString
*aContentCharset
)
788 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
790 TRACE("(%p)->(%p)\n", This
, aContentCharset
);
793 nsACString_SetData(aContentCharset
, This
->charset
);
797 nsACString_SetData(aContentCharset
, "");
801 static nsresult NSAPI
nsChannel_SetContentCharset(nsIHttpChannel
*iface
,
802 const nsACString
*aContentCharset
)
804 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
806 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentCharset
));
808 return NS_ERROR_NOT_IMPLEMENTED
;
811 static nsresult NSAPI
nsChannel_GetContentLength(nsIHttpChannel
*iface
, PRInt32
*aContentLength
)
813 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
815 FIXME("(%p)->(%p)\n", This
, aContentLength
);
817 return NS_ERROR_NOT_IMPLEMENTED
;
820 static nsresult NSAPI
nsChannel_SetContentLength(nsIHttpChannel
*iface
, PRInt32 aContentLength
)
822 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
824 FIXME("(%p)->(%d)\n", This
, aContentLength
);
826 return NS_ERROR_NOT_IMPLEMENTED
;
829 static nsresult NSAPI
nsChannel_Open(nsIHttpChannel
*iface
, nsIInputStream
**_retval
)
831 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
833 FIXME("(%p)->(%p)\n", This
, _retval
);
835 return NS_ERROR_NOT_IMPLEMENTED
;
838 static HTMLWindow
*get_window_from_load_group(nsChannel
*This
)
847 nsres
= nsILoadGroup_GetDefaultLoadRequest(This
->load_group
, &req
);
848 if(NS_FAILED(nsres
)) {
849 ERR("GetDefaultLoadRequest failed: %08x\n", nsres
);
856 nsres
= nsIRequest_QueryInterface(req
, &IID_nsIChannel
, (void**)&channel
);
857 nsIRequest_Release(req
);
858 if(NS_FAILED(nsres
)) {
859 WARN("Could not get nsIChannel interface: %08x\n", nsres
);
863 nsres
= nsIChannel_GetURI(channel
, &uri
);
864 nsIChannel_Release(channel
);
865 if(NS_FAILED(nsres
)) {
866 ERR("GetURI failed: %08x\n", nsres
);
870 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
872 if(NS_FAILED(nsres
)) {
873 TRACE("Could not get nsWineURI: %08x\n", nsres
);
877 window
= wine_uri
->window_ref
? wine_uri
->window_ref
->window
: NULL
;
879 IHTMLWindow2_AddRef(&window
->IHTMLWindow2_iface
);
880 nsIURI_Release(&wine_uri
->nsIURL_iface
);
885 static HTMLWindow
*get_channel_window(nsChannel
*This
)
887 nsIWebProgress
*web_progress
;
888 nsIDOMWindow
*nswindow
;
892 if(This
->load_group
) {
893 nsIRequestObserver
*req_observer
;
895 nsres
= nsILoadGroup_GetGroupObserver(This
->load_group
, &req_observer
);
896 if(NS_FAILED(nsres
) || !req_observer
) {
897 ERR("GetGroupObserver failed: %08x\n", nsres
);
901 nsres
= nsIRequestObserver_QueryInterface(req_observer
, &IID_nsIWebProgress
, (void**)&web_progress
);
902 nsIRequestObserver_Release(req_observer
);
903 if(NS_FAILED(nsres
)) {
904 ERR("Could not get nsIWebProgress iface: %08x\n", nsres
);
907 }else if(This
->notif_callback
) {
908 nsres
= nsIInterfaceRequestor_GetInterface(This
->notif_callback
, &IID_nsIWebProgress
, (void**)&web_progress
);
909 if(NS_FAILED(nsres
)) {
910 ERR("GetInterface(IID_nsIWebProgress failed: %08x\n", nsres
);
914 ERR("no load group nor notif callback\n");
918 nsres
= nsIWebProgress_GetDOMWindow(web_progress
, &nswindow
);
919 nsIWebProgress_Release(web_progress
);
920 if(NS_FAILED(nsres
) || !nswindow
) {
921 ERR("GetDOMWindow failed: %08x\n", nsres
);
925 window
= nswindow_to_window(nswindow
);
926 nsIDOMWindow_Release(nswindow
);
929 IHTMLWindow2_AddRef(&window
->IHTMLWindow2_iface
);
931 FIXME("NULL window for %p\n", nswindow
);
937 HTMLDocumentNode
*doc
;
938 nsChannelBSC
*bscallback
;
939 } start_binding_task_t
;
941 static void start_binding_proc(task_t
*_task
)
943 start_binding_task_t
*task
= (start_binding_task_t
*)_task
;
945 start_binding(NULL
, task
->doc
, (BSCallback
*)task
->bscallback
, NULL
);
948 static void start_binding_task_destr(task_t
*_task
)
950 start_binding_task_t
*task
= (start_binding_task_t
*)_task
;
952 IBindStatusCallback_Release(&task
->bscallback
->bsc
.IBindStatusCallback_iface
);
956 static nsresult
async_open(nsChannel
*This
, HTMLWindow
*window
, BOOL is_doc_channel
, nsIStreamListener
*listener
,
957 nsISupports
*context
)
959 nsChannelBSC
*bscallback
;
960 IMoniker
*mon
= NULL
;
963 hres
= CreateURLMonikerEx2(NULL
, This
->uri
->uri
, &mon
, 0);
965 WARN("CreateURLMoniker failed: %08x\n", hres
);
966 return NS_ERROR_UNEXPECTED
;
970 set_current_mon(window
, mon
);
972 hres
= create_channelbsc(mon
, NULL
, NULL
, 0, &bscallback
);
973 IMoniker_Release(mon
);
975 return NS_ERROR_UNEXPECTED
;
977 channelbsc_set_channel(bscallback
, This
, listener
, context
);
980 set_window_bscallback(window
, bscallback
);
981 async_start_doc_binding(window
, bscallback
);
982 IUnknown_Release((IUnknown
*)bscallback
);
984 start_binding_task_t
*task
= heap_alloc(sizeof(start_binding_task_t
));
986 task
->doc
= window
->doc
;
987 task
->bscallback
= bscallback
;
988 push_task(&task
->header
, start_binding_proc
, start_binding_task_destr
, window
->doc
->basedoc
.task_magic
);
994 static nsresult NSAPI
nsChannel_AsyncOpen(nsIHttpChannel
*iface
, nsIStreamListener
*aListener
,
995 nsISupports
*aContext
)
997 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
998 HTMLWindow
*window
= NULL
;
1000 nsresult nsres
= NS_OK
;
1002 TRACE("(%p)->(%p %p)\n", This
, aListener
, aContext
);
1004 if(!ensure_uri(This
->uri
))
1005 return NS_ERROR_FAILURE
;
1007 if(TRACE_ON(mshtml
)) {
1009 IUri_GetDisplayUri(This
->uri
->uri
, &uri_str
);
1010 TRACE("opening %s\n", debugstr_w(uri_str
));
1011 SysFreeString(uri_str
);
1014 if(This
->uri
->is_doc_uri
) {
1015 window
= get_channel_window(This
);
1017 set_uri_window(This
->uri
, window
);
1018 }else if(This
->uri
->container
) {
1021 /* nscontainer->doc should be NULL which means navigation to a new window */
1022 if(This
->uri
->container
->doc
)
1023 FIXME("nscontainer->doc = %p\n", This
->uri
->container
->doc
);
1025 nsres
= before_async_open(This
, This
->uri
->container
, &b
);
1026 if(NS_FAILED(nsres
))
1029 FIXME("Navigation not cancelled\n");
1030 return NS_ERROR_UNEXPECTED
;
1035 if(This
->uri
->window_ref
&& This
->uri
->window_ref
->window
) {
1036 window
= This
->uri
->window_ref
->window
;
1037 IHTMLWindow2_AddRef(&window
->IHTMLWindow2_iface
);
1039 /* FIXME: Analyze removing get_window_from_load_group call */
1040 if(This
->load_group
)
1041 window
= get_window_from_load_group(This
);
1043 window
= get_channel_window(This
);
1045 set_uri_window(This
->uri
, window
);
1050 ERR("window = NULL\n");
1051 return NS_ERROR_UNEXPECTED
;
1054 if(This
->uri
->is_doc_uri
&& window
== window
->doc_obj
->basedoc
.window
) {
1055 if(This
->uri
->channel_bsc
) {
1056 channelbsc_set_channel(This
->uri
->channel_bsc
, This
, aListener
, aContext
);
1058 if(window
->doc_obj
->mime
) {
1059 heap_free(This
->content_type
);
1060 This
->content_type
= heap_strdupWtoA(window
->doc_obj
->mime
);
1065 nsres
= before_async_open(This
, window
->doc_obj
->nscontainer
, &cancel
);
1066 if(NS_SUCCEEDED(nsres
) && cancel
) {
1067 TRACE("canceled\n");
1068 nsres
= NS_BINDING_ABORTED
;
1074 nsres
= async_open(This
, window
, This
->uri
->is_doc_uri
, aListener
, aContext
);
1076 if(NS_SUCCEEDED(nsres
) && This
->load_group
) {
1077 nsres
= nsILoadGroup_AddRequest(This
->load_group
, (nsIRequest
*)&This
->nsIHttpChannel_iface
,
1079 if(NS_FAILED(nsres
))
1080 ERR("AddRequest failed: %08x\n", nsres
);
1083 IHTMLWindow2_Release(&window
->IHTMLWindow2_iface
);
1087 static nsresult NSAPI
nsChannel_GetRequestMethod(nsIHttpChannel
*iface
, nsACString
*aRequestMethod
)
1089 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1091 TRACE("(%p)->(%p)\n", This
, aRequestMethod
);
1093 nsACString_SetData(aRequestMethod
, request_method_strings
[This
->request_method
]);
1097 static nsresult NSAPI
nsChannel_SetRequestMethod(nsIHttpChannel
*iface
,
1098 const nsACString
*aRequestMethod
)
1100 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1104 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRequestMethod
));
1106 nsACString_GetData(aRequestMethod
, &method
);
1107 for(i
=0; i
< sizeof(request_method_strings
)/sizeof(*request_method_strings
); i
++) {
1108 if(!strcasecmp(method
, request_method_strings
[i
])) {
1109 This
->request_method
= i
;
1114 ERR("Invalid method %s\n", debugstr_a(method
));
1115 return NS_ERROR_UNEXPECTED
;
1118 static nsresult NSAPI
nsChannel_GetReferrer(nsIHttpChannel
*iface
, nsIURI
**aReferrer
)
1120 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1122 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1125 nsIURI_AddRef(This
->referrer
);
1126 *aReferrer
= This
->referrer
;
1130 static nsresult NSAPI
nsChannel_SetReferrer(nsIHttpChannel
*iface
, nsIURI
*aReferrer
)
1132 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1134 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1137 nsIURI_AddRef(aReferrer
);
1139 nsIURI_Release(This
->referrer
);
1140 This
->referrer
= aReferrer
;
1144 static nsresult NSAPI
nsChannel_GetRequestHeader(nsIHttpChannel
*iface
,
1145 const nsACString
*aHeader
, nsACString
*_retval
)
1147 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1149 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aHeader
), _retval
);
1151 return get_channel_http_header(&This
->request_headers
, aHeader
, _retval
);
1154 static nsresult NSAPI
nsChannel_SetRequestHeader(nsIHttpChannel
*iface
,
1155 const nsACString
*aHeader
, const nsACString
*aValue
, PRBool aMerge
)
1157 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1159 TRACE("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(aHeader
), debugstr_nsacstr(aValue
), aMerge
);
1162 FIXME("aMerge not supported\n");
1164 return set_channel_http_header(&This
->request_headers
, aHeader
, aValue
);
1167 static nsresult NSAPI
nsChannel_VisitRequestHeaders(nsIHttpChannel
*iface
,
1168 nsIHttpHeaderVisitor
*aVisitor
)
1170 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1172 FIXME("(%p)->(%p)\n", This
, aVisitor
);
1174 return NS_ERROR_NOT_IMPLEMENTED
;
1177 static nsresult NSAPI
nsChannel_GetAllowPipelining(nsIHttpChannel
*iface
, PRBool
*aAllowPipelining
)
1179 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1181 FIXME("(%p)->(%p)\n", This
, aAllowPipelining
);
1183 return NS_ERROR_NOT_IMPLEMENTED
;
1186 static nsresult NSAPI
nsChannel_SetAllowPipelining(nsIHttpChannel
*iface
, PRBool aAllowPipelining
)
1188 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1190 FIXME("(%p)->(%x)\n", This
, aAllowPipelining
);
1192 return NS_ERROR_NOT_IMPLEMENTED
;
1195 static nsresult NSAPI
nsChannel_GetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32
*aRedirectionLimit
)
1197 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1199 FIXME("(%p)->(%p)\n", This
, aRedirectionLimit
);
1201 return NS_ERROR_NOT_IMPLEMENTED
;
1204 static nsresult NSAPI
nsChannel_SetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32 aRedirectionLimit
)
1206 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1208 FIXME("(%p)->(%u)\n", This
, aRedirectionLimit
);
1210 return NS_ERROR_NOT_IMPLEMENTED
;
1213 static nsresult NSAPI
nsChannel_GetResponseStatus(nsIHttpChannel
*iface
, PRUint32
*aResponseStatus
)
1215 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1217 TRACE("(%p)->(%p)\n", This
, aResponseStatus
);
1219 if(This
->response_status
) {
1220 *aResponseStatus
= This
->response_status
;
1224 WARN("No response status\n");
1225 return NS_ERROR_UNEXPECTED
;
1228 static nsresult NSAPI
nsChannel_GetResponseStatusText(nsIHttpChannel
*iface
,
1229 nsACString
*aResponseStatusText
)
1231 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1233 FIXME("(%p)->(%p)\n", This
, aResponseStatusText
);
1235 return NS_ERROR_NOT_IMPLEMENTED
;
1238 static nsresult NSAPI
nsChannel_GetRequestSucceeded(nsIHttpChannel
*iface
,
1239 PRBool
*aRequestSucceeded
)
1241 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1243 TRACE("(%p)->(%p)\n", This
, aRequestSucceeded
);
1245 if(!This
->response_status
)
1246 return NS_ERROR_NOT_AVAILABLE
;
1248 *aRequestSucceeded
= This
->response_status
/100 == 2;
1253 static nsresult NSAPI
nsChannel_GetResponseHeader(nsIHttpChannel
*iface
,
1254 const nsACString
*header
, nsACString
*_retval
)
1256 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1258 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(header
), _retval
);
1260 return get_channel_http_header(&This
->response_headers
, header
, _retval
);
1263 static nsresult NSAPI
nsChannel_SetResponseHeader(nsIHttpChannel
*iface
,
1264 const nsACString
*header
, const nsACString
*value
, PRBool merge
)
1266 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1268 FIXME("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(header
), debugstr_nsacstr(value
), merge
);
1270 return NS_ERROR_NOT_IMPLEMENTED
;
1273 static nsresult NSAPI
nsChannel_VisitResponseHeaders(nsIHttpChannel
*iface
,
1274 nsIHttpHeaderVisitor
*aVisitor
)
1276 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1278 TRACE("(%p)->(%p)\n", This
, aVisitor
);
1280 return visit_http_headers(&This
->response_headers
, aVisitor
);
1283 static nsresult NSAPI
nsChannel_IsNoStoreResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1285 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1286 http_header_t
*header
;
1288 static const WCHAR cache_controlW
[] = {'C','a','c','h','e','-','C','o','n','t','r','o','l'};
1289 static const WCHAR no_storeW
[] = {'n','o','-','s','t','o','r','e',0};
1291 TRACE("(%p)->(%p)\n", This
, _retval
);
1293 header
= find_http_header(&This
->response_headers
, cache_controlW
, sizeof(cache_controlW
)/sizeof(WCHAR
));
1294 *_retval
= header
&& !strcmpiW(header
->data
, no_storeW
);
1298 static nsresult NSAPI
nsChannel_IsNoCacheResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1300 nsChannel
*This
= impl_from_nsIHttpChannel(iface
);
1302 FIXME("(%p)->(%p)\n", This
, _retval
);
1304 return NS_ERROR_NOT_IMPLEMENTED
;
1307 static const nsIHttpChannelVtbl nsChannelVtbl
= {
1308 nsChannel_QueryInterface
,
1312 nsChannel_IsPending
,
1313 nsChannel_GetStatus
,
1317 nsChannel_GetLoadGroup
,
1318 nsChannel_SetLoadGroup
,
1319 nsChannel_GetLoadFlags
,
1320 nsChannel_SetLoadFlags
,
1321 nsChannel_GetOriginalURI
,
1322 nsChannel_SetOriginalURI
,
1326 nsChannel_GetNotificationCallbacks
,
1327 nsChannel_SetNotificationCallbacks
,
1328 nsChannel_GetSecurityInfo
,
1329 nsChannel_GetContentType
,
1330 nsChannel_SetContentType
,
1331 nsChannel_GetContentCharset
,
1332 nsChannel_SetContentCharset
,
1333 nsChannel_GetContentLength
,
1334 nsChannel_SetContentLength
,
1336 nsChannel_AsyncOpen
,
1337 nsChannel_GetRequestMethod
,
1338 nsChannel_SetRequestMethod
,
1339 nsChannel_GetReferrer
,
1340 nsChannel_SetReferrer
,
1341 nsChannel_GetRequestHeader
,
1342 nsChannel_SetRequestHeader
,
1343 nsChannel_VisitRequestHeaders
,
1344 nsChannel_GetAllowPipelining
,
1345 nsChannel_SetAllowPipelining
,
1346 nsChannel_GetRedirectionLimit
,
1347 nsChannel_SetRedirectionLimit
,
1348 nsChannel_GetResponseStatus
,
1349 nsChannel_GetResponseStatusText
,
1350 nsChannel_GetRequestSucceeded
,
1351 nsChannel_GetResponseHeader
,
1352 nsChannel_SetResponseHeader
,
1353 nsChannel_VisitResponseHeaders
,
1354 nsChannel_IsNoStoreResponse
,
1355 nsChannel_IsNoCacheResponse
1358 static inline nsChannel
*impl_from_nsIUploadChannel(nsIUploadChannel
*iface
)
1360 return CONTAINING_RECORD(iface
, nsChannel
, nsIUploadChannel_iface
);
1363 static nsresult NSAPI
nsUploadChannel_QueryInterface(nsIUploadChannel
*iface
, nsIIDRef riid
,
1366 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1367 return nsIChannel_QueryInterface(&This
->nsIHttpChannel_iface
, riid
, result
);
1370 static nsrefcnt NSAPI
nsUploadChannel_AddRef(nsIUploadChannel
*iface
)
1372 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1373 return nsIChannel_AddRef(&This
->nsIHttpChannel_iface
);
1376 static nsrefcnt NSAPI
nsUploadChannel_Release(nsIUploadChannel
*iface
)
1378 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1379 return nsIChannel_Release(&This
->nsIHttpChannel_iface
);
1382 static nsresult NSAPI
nsUploadChannel_SetUploadStream(nsIUploadChannel
*iface
,
1383 nsIInputStream
*aStream
, const nsACString
*aContentType
, PRInt32 aContentLength
)
1385 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1386 const char *content_type
;
1388 static const WCHAR content_typeW
[] =
1389 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1391 TRACE("(%p)->(%p %s %d)\n", This
, aStream
, debugstr_nsacstr(aContentType
), aContentLength
);
1393 This
->post_data_contains_headers
= TRUE
;
1396 nsACString_GetData(aContentType
, &content_type
);
1400 ct
= heap_strdupAtoW(content_type
);
1402 return NS_ERROR_UNEXPECTED
;
1404 set_http_header(&This
->request_headers
, content_typeW
,
1405 sizeof(content_typeW
)/sizeof(WCHAR
), ct
, strlenW(ct
));
1407 This
->post_data_contains_headers
= FALSE
;
1411 if(This
->post_data_stream
)
1412 nsIInputStream_Release(This
->post_data_stream
);
1414 if(aContentLength
!= -1)
1415 FIXME("Unsupported acontentLength = %d\n", aContentLength
);
1417 if(This
->post_data_stream
)
1418 nsIInputStream_Release(This
->post_data_stream
);
1419 This
->post_data_stream
= aStream
;
1421 nsIInputStream_AddRef(aStream
);
1423 This
->request_method
= METHOD_POST
;
1427 static nsresult NSAPI
nsUploadChannel_GetUploadStream(nsIUploadChannel
*iface
,
1428 nsIInputStream
**aUploadStream
)
1430 nsChannel
*This
= impl_from_nsIUploadChannel(iface
);
1432 TRACE("(%p)->(%p)\n", This
, aUploadStream
);
1434 if(This
->post_data_stream
)
1435 nsIInputStream_AddRef(This
->post_data_stream
);
1437 *aUploadStream
= This
->post_data_stream
;
1441 static const nsIUploadChannelVtbl nsUploadChannelVtbl
= {
1442 nsUploadChannel_QueryInterface
,
1443 nsUploadChannel_AddRef
,
1444 nsUploadChannel_Release
,
1445 nsUploadChannel_SetUploadStream
,
1446 nsUploadChannel_GetUploadStream
1449 static inline nsChannel
*impl_from_nsIHttpChannelInternal(nsIHttpChannelInternal
*iface
)
1451 return CONTAINING_RECORD(iface
, nsChannel
, nsIHttpChannelInternal_iface
);
1454 static nsresult NSAPI
nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal
*iface
, nsIIDRef riid
,
1457 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1458 return nsIChannel_QueryInterface(&This
->nsIHttpChannel_iface
, riid
, result
);
1461 static nsrefcnt NSAPI
nsHttpChannelInternal_AddRef(nsIHttpChannelInternal
*iface
)
1463 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1464 return nsIChannel_AddRef(&This
->nsIHttpChannel_iface
);
1467 static nsrefcnt NSAPI
nsHttpChannelInternal_Release(nsIHttpChannelInternal
*iface
)
1469 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1470 return nsIChannel_Release(&This
->nsIHttpChannel_iface
);
1473 static nsresult NSAPI
nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
**aDocumentURI
)
1475 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1477 FIXME("(%p)->()\n", This
);
1479 return NS_ERROR_NOT_IMPLEMENTED
;
1482 static nsresult NSAPI
nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
*aDocumentURI
)
1484 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1486 FIXME("(%p)->()\n", This
);
1488 return NS_ERROR_NOT_IMPLEMENTED
;
1491 static nsresult NSAPI
nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal
*iface
, PRUint32
*major
, PRUint32
*minor
)
1493 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1495 FIXME("(%p)->()\n", This
);
1497 return NS_ERROR_NOT_IMPLEMENTED
;
1500 static nsresult NSAPI
nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal
*iface
, PRUint32
*major
, PRUint32
*minor
)
1502 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1504 FIXME("(%p)->()\n", This
);
1506 return NS_ERROR_NOT_IMPLEMENTED
;
1509 static nsresult NSAPI
nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal
*iface
, const char *aCookieHeader
)
1511 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1513 FIXME("(%p)->()\n", This
);
1515 return NS_ERROR_NOT_IMPLEMENTED
;
1518 static nsresult NSAPI
nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal
*iface
, const char *aFallbackKey
)
1520 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1522 FIXME("(%p)->()\n", This
);
1524 return NS_ERROR_NOT_IMPLEMENTED
;
1527 static nsresult NSAPI
nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, PRBool
*aForceThirdPartyCookie
)
1529 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1531 FIXME("(%p)->()\n", This
);
1533 return NS_ERROR_NOT_IMPLEMENTED
;
1536 static nsresult NSAPI
nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, PRBool aForceThirdPartyCookie
)
1538 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1540 FIXME("(%p)->()\n", This
);
1542 return NS_ERROR_NOT_IMPLEMENTED
;
1545 static nsresult NSAPI
nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal
*iface
, PRBool
*aCanceled
)
1547 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1549 FIXME("(%p)->(%p)\n", This
, aCanceled
);
1551 return NS_ERROR_NOT_IMPLEMENTED
;
1554 static nsresult NSAPI
nsHttpChannelInternal_GetChannelIsForDownload(nsIHttpChannelInternal
*iface
, PRBool
*aCanceled
)
1556 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1558 FIXME("(%p)->(%p)\n", This
, aCanceled
);
1560 return NS_ERROR_NOT_IMPLEMENTED
;
1563 static nsresult NSAPI
nsHttpChannelInternal_SetChannelIsForDownload(nsIHttpChannelInternal
*iface
, PRBool aCanceled
)
1565 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1567 FIXME("(%p)->(%x)\n", This
, aCanceled
);
1569 return NS_ERROR_NOT_IMPLEMENTED
;
1572 static nsresult NSAPI
nsHttpChannelInternal_GetLocalAddress(nsIHttpChannelInternal
*iface
, nsACString
*aLocalAddress
)
1574 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1576 FIXME("(%p)->(%p)\n", This
, aLocalAddress
);
1578 return NS_ERROR_NOT_IMPLEMENTED
;
1581 static nsresult NSAPI
nsHttpChannelInternal_GetLocalPort(nsIHttpChannelInternal
*iface
, PRInt32
*aLocalPort
)
1583 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1585 FIXME("(%p)->(%p)\n", This
, aLocalPort
);
1587 return NS_ERROR_NOT_IMPLEMENTED
;
1590 static nsresult NSAPI
nsHttpChannelInternal_GetRemoteAddress(nsIHttpChannelInternal
*iface
, nsACString
*aRemoteAddress
)
1592 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1594 FIXME("(%p)->(%p)\n", This
, aRemoteAddress
);
1596 return NS_ERROR_NOT_IMPLEMENTED
;
1599 static nsresult NSAPI
nsHttpChannelInternal_GetRemotePort(nsIHttpChannelInternal
*iface
, PRInt32
*aRemotePort
)
1601 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1603 FIXME("(%p)->(%p)\n", This
, aRemotePort
);
1605 return NS_ERROR_NOT_IMPLEMENTED
;
1608 static nsresult NSAPI
nsHttpChannelInternal_SetCacheKeysRedirectChain(nsIHttpChannelInternal
*iface
, void *cacheKeys
)
1610 nsChannel
*This
= impl_from_nsIHttpChannelInternal(iface
);
1612 FIXME("(%p)->(%p)\n", This
, cacheKeys
);
1614 return NS_ERROR_NOT_IMPLEMENTED
;
1617 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl
= {
1618 nsHttpChannelInternal_QueryInterface
,
1619 nsHttpChannelInternal_AddRef
,
1620 nsHttpChannelInternal_Release
,
1621 nsHttpChannelInternal_GetDocumentURI
,
1622 nsHttpChannelInternal_SetDocumentURI
,
1623 nsHttpChannelInternal_GetRequestVersion
,
1624 nsHttpChannelInternal_GetResponseVersion
,
1625 nsHttpChannelInternal_SetCookie
,
1626 nsHttpChannelInternal_SetupFallbackChannel
,
1627 nsHttpChannelInternal_GetForceAllowThirdPartyCookie
,
1628 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
,
1629 nsHttpChannelInternal_GetCanceled
,
1630 nsHttpChannelInternal_GetChannelIsForDownload
,
1631 nsHttpChannelInternal_SetChannelIsForDownload
,
1632 nsHttpChannelInternal_GetLocalAddress
,
1633 nsHttpChannelInternal_GetLocalPort
,
1634 nsHttpChannelInternal_GetRemoteAddress
,
1635 nsHttpChannelInternal_GetRemotePort
,
1636 nsHttpChannelInternal_SetCacheKeysRedirectChain
1640 static void invalidate_uri(nsWineURI
*This
)
1643 IUri_Release(This
->uri
);
1648 static BOOL
ensure_uri_builder(nsWineURI
*This
)
1650 if(!This
->uri_builder
) {
1653 if(!ensure_uri(This
))
1656 hres
= CreateIUriBuilder(This
->uri
, 0, 0, &This
->uri_builder
);
1658 WARN("CreateIUriBuilder failed: %08x\n", hres
);
1663 invalidate_uri(This
);
1667 static nsresult
get_uri_string(nsWineURI
*This
, Uri_PROPERTY prop
, nsACString
*ret
)
1673 if(!ensure_uri(This
))
1674 return NS_ERROR_UNEXPECTED
;
1676 hres
= IUri_GetPropertyBSTR(This
->uri
, prop
, &val
, 0);
1678 WARN("GetPropertyBSTR failed: %08x\n", hres
);
1679 return NS_ERROR_UNEXPECTED
;
1682 vala
= heap_strdupWtoA(val
);
1685 return NS_ERROR_OUT_OF_MEMORY
;
1687 TRACE("ret %s\n", debugstr_a(vala
));
1688 nsACString_SetData(ret
, vala
);
1693 static inline nsWineURI
*impl_from_nsIURL(nsIURL
*iface
)
1695 return CONTAINING_RECORD(iface
, nsWineURI
, nsIURL_iface
);
1698 static nsresult NSAPI
nsURI_QueryInterface(nsIURL
*iface
, nsIIDRef riid
, void **result
)
1700 nsWineURI
*This
= impl_from_nsIURL(iface
);
1704 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1705 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1706 *result
= &This
->nsIURL_iface
;
1707 }else if(IsEqualGUID(&IID_nsIURI
, riid
)) {
1708 TRACE("(%p)->(IID_nsIURI %p)\n", This
, result
);
1709 *result
= &This
->nsIURL_iface
;
1710 }else if(IsEqualGUID(&IID_nsIURL
, riid
)) {
1711 TRACE("(%p)->(IID_nsIURL %p)\n", This
, result
);
1712 *result
= &This
->nsIURL_iface
;
1713 }else if(IsEqualGUID(&IID_nsIMutable
, riid
)) {
1714 TRACE("(%p)->(IID_nsIMutable %p)\n", This
, result
);
1715 *result
= &This
->nsIStandardURL_iface
;
1716 }else if(IsEqualGUID(&IID_nsIStandardURL
, riid
)) {
1717 TRACE("(%p)->(IID_nsIStandardURL %p)\n", This
, result
);
1718 *result
= &This
->nsIStandardURL_iface
;
1719 }else if(IsEqualGUID(&IID_nsWineURI
, riid
)) {
1720 TRACE("(%p)->(IID_nsWineURI %p)\n", This
, result
);
1725 nsIURI_AddRef(&This
->nsIURL_iface
);
1729 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1730 return This
->nsuri
? nsIURI_QueryInterface(This
->nsuri
, riid
, result
) : NS_NOINTERFACE
;
1733 static nsrefcnt NSAPI
nsURI_AddRef(nsIURL
*iface
)
1735 nsWineURI
*This
= impl_from_nsIURL(iface
);
1736 LONG ref
= InterlockedIncrement(&This
->ref
);
1738 TRACE("(%p) ref=%d\n", This
, ref
);
1743 static nsrefcnt NSAPI
nsURI_Release(nsIURL
*iface
)
1745 nsWineURI
*This
= impl_from_nsIURL(iface
);
1746 LONG ref
= InterlockedDecrement(&This
->ref
);
1748 TRACE("(%p) ref=%d\n", This
, ref
);
1751 if(This
->window_ref
)
1752 windowref_release(This
->window_ref
);
1754 nsIWebBrowserChrome_Release(&This
->container
->nsIWebBrowserChrome_iface
);
1756 nsIURL_Release(This
->nsurl
);
1758 nsIURI_Release(This
->nsuri
);
1760 IUri_Release(This
->uri
);
1767 static nsresult NSAPI
nsURI_GetSpec(nsIURL
*iface
, nsACString
*aSpec
)
1769 nsWineURI
*This
= impl_from_nsIURL(iface
);
1771 TRACE("(%p)->(%p)\n", This
, aSpec
);
1773 return get_uri_string(This
, Uri_PROPERTY_DISPLAY_URI
, aSpec
);
1776 static nsresult NSAPI
nsURI_SetSpec(nsIURL
*iface
, const nsACString
*aSpec
)
1778 nsWineURI
*This
= impl_from_nsIURL(iface
);
1784 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aSpec
));
1786 nsACString_GetData(aSpec
, &speca
);
1787 spec
= heap_strdupAtoW(speca
);
1789 return NS_ERROR_OUT_OF_MEMORY
;
1791 hres
= CreateUri(spec
, 0, 0, &uri
);
1794 WARN("CreateUri failed: %08x\n", hres
);
1795 return NS_ERROR_FAILURE
;
1798 invalidate_uri(This
);
1799 if(This
->uri_builder
) {
1800 IUriBuilder_Release(This
->uri_builder
);
1801 This
->uri_builder
= NULL
;
1808 static nsresult NSAPI
nsURI_GetPrePath(nsIURL
*iface
, nsACString
*aPrePath
)
1810 nsWineURI
*This
= impl_from_nsIURL(iface
);
1812 TRACE("(%p)->(%p)\n", This
, aPrePath
);
1815 return nsIURI_GetPrePath(This
->nsuri
, aPrePath
);
1817 FIXME("default action not implemented\n");
1818 return NS_ERROR_NOT_IMPLEMENTED
;
1821 static nsresult NSAPI
nsURI_GetScheme(nsIURL
*iface
, nsACString
*aScheme
)
1823 nsWineURI
*This
= impl_from_nsIURL(iface
);
1827 TRACE("(%p)->(%p)\n", This
, aScheme
);
1829 if(!ensure_uri(This
))
1830 return NS_ERROR_UNEXPECTED
;
1832 hres
= IUri_GetScheme(This
->uri
, &scheme
);
1834 WARN("GetScheme failed: %08x\n", hres
);
1835 return NS_ERROR_UNEXPECTED
;
1838 if(scheme
== URL_SCHEME_ABOUT
) {
1839 nsACString_SetData(aScheme
, "wine");
1843 return get_uri_string(This
, Uri_PROPERTY_SCHEME_NAME
, aScheme
);
1846 static nsresult NSAPI
nsURI_SetScheme(nsIURL
*iface
, const nsACString
*aScheme
)
1848 nsWineURI
*This
= impl_from_nsIURL(iface
);
1849 const char *schemea
;
1853 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aScheme
));
1855 if(!ensure_uri_builder(This
))
1856 return NS_ERROR_UNEXPECTED
;
1858 nsACString_GetData(aScheme
, &schemea
);
1859 scheme
= heap_strdupAtoW(schemea
);
1861 return NS_ERROR_OUT_OF_MEMORY
;
1863 hres
= IUriBuilder_SetSchemeName(This
->uri_builder
, scheme
);
1866 return NS_ERROR_UNEXPECTED
;
1871 static nsresult NSAPI
nsURI_GetUserPass(nsIURL
*iface
, nsACString
*aUserPass
)
1873 nsWineURI
*This
= impl_from_nsIURL(iface
);
1877 TRACE("(%p)->(%p)\n", This
, aUserPass
);
1879 if(!ensure_uri(This
))
1880 return NS_ERROR_UNEXPECTED
;
1882 hres
= IUri_GetUserName(This
->uri
, &user
);
1884 return NS_ERROR_FAILURE
;
1886 hres
= IUri_GetPassword(This
->uri
, &pass
);
1888 SysFreeString(user
);
1889 return NS_ERROR_FAILURE
;
1892 if(*user
|| *pass
) {
1893 FIXME("Construct user:pass string\n");
1895 nsACString_SetData(aUserPass
, "");
1898 SysFreeString(user
);
1899 SysFreeString(pass
);
1903 static nsresult NSAPI
nsURI_SetUserPass(nsIURL
*iface
, const nsACString
*aUserPass
)
1905 nsWineURI
*This
= impl_from_nsIURL(iface
);
1906 WCHAR
*user
= NULL
, *pass
= NULL
, *buf
= NULL
;
1907 const char *user_pass
;
1910 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUserPass
));
1912 if(!ensure_uri_builder(This
))
1913 return NS_ERROR_UNEXPECTED
;
1915 nsACString_GetData(aUserPass
, &user_pass
);
1919 buf
= heap_strdupAtoW(user_pass
);
1921 return NS_ERROR_OUT_OF_MEMORY
;
1923 ptr
= strchrW(buf
, ':');
1926 }else if(ptr
!= buf
) {
1936 hres
= IUriBuilder_SetUserName(This
->uri_builder
, user
);
1938 hres
= IUriBuilder_SetPassword(This
->uri_builder
, pass
);
1941 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_FAILURE
;
1944 static nsresult NSAPI
nsURI_GetUsername(nsIURL
*iface
, nsACString
*aUsername
)
1946 nsWineURI
*This
= impl_from_nsIURL(iface
);
1948 TRACE("(%p)->(%p)\n", This
, aUsername
);
1950 return get_uri_string(This
, Uri_PROPERTY_USER_NAME
, aUsername
);
1953 static nsresult NSAPI
nsURI_SetUsername(nsIURL
*iface
, const nsACString
*aUsername
)
1955 nsWineURI
*This
= impl_from_nsIURL(iface
);
1960 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUsername
));
1962 if(!ensure_uri_builder(This
))
1963 return NS_ERROR_UNEXPECTED
;
1965 nsACString_GetData(aUsername
, &usera
);
1966 user
= heap_strdupAtoW(usera
);
1968 return NS_ERROR_OUT_OF_MEMORY
;
1970 hres
= IUriBuilder_SetUserName(This
->uri_builder
, user
);
1973 return NS_ERROR_UNEXPECTED
;
1978 static nsresult NSAPI
nsURI_GetPassword(nsIURL
*iface
, nsACString
*aPassword
)
1980 nsWineURI
*This
= impl_from_nsIURL(iface
);
1982 TRACE("(%p)->(%p)\n", This
, aPassword
);
1984 return get_uri_string(This
, Uri_PROPERTY_PASSWORD
, aPassword
);
1987 static nsresult NSAPI
nsURI_SetPassword(nsIURL
*iface
, const nsACString
*aPassword
)
1989 nsWineURI
*This
= impl_from_nsIURL(iface
);
1994 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPassword
));
1996 if(!ensure_uri_builder(This
))
1997 return NS_ERROR_UNEXPECTED
;
1999 nsACString_GetData(aPassword
, &passa
);
2000 pass
= heap_strdupAtoW(passa
);
2002 return NS_ERROR_OUT_OF_MEMORY
;
2004 hres
= IUriBuilder_SetPassword(This
->uri_builder
, pass
);
2007 return NS_ERROR_UNEXPECTED
;
2012 static nsresult NSAPI
nsURI_GetHostPort(nsIURL
*iface
, nsACString
*aHostPort
)
2014 nsWineURI
*This
= impl_from_nsIURL(iface
);
2020 TRACE("(%p)->(%p)\n", This
, aHostPort
);
2022 if(!ensure_uri(This
))
2023 return NS_ERROR_UNEXPECTED
;
2025 hres
= IUri_GetAuthority(This
->uri
, &val
);
2027 WARN("GetAuthority failed: %08x\n", hres
);
2028 return NS_ERROR_UNEXPECTED
;
2031 ptr
= strchrW(val
, '@');
2035 vala
= heap_strdupWtoA(ptr
);
2038 return NS_ERROR_OUT_OF_MEMORY
;
2040 TRACE("ret %s\n", debugstr_a(vala
));
2041 nsACString_SetData(aHostPort
, vala
);
2046 static nsresult NSAPI
nsURI_SetHostPort(nsIURL
*iface
, const nsACString
*aHostPort
)
2048 nsWineURI
*This
= impl_from_nsIURL(iface
);
2050 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aHostPort
));
2052 /* Not implemented by Gecko */
2053 return NS_ERROR_NOT_IMPLEMENTED
;
2056 static nsresult NSAPI
nsURI_GetHost(nsIURL
*iface
, nsACString
*aHost
)
2058 nsWineURI
*This
= impl_from_nsIURL(iface
);
2060 TRACE("(%p)->(%p)\n", This
, aHost
);
2062 return get_uri_string(This
, Uri_PROPERTY_HOST
, aHost
);
2065 static nsresult NSAPI
nsURI_SetHost(nsIURL
*iface
, const nsACString
*aHost
)
2067 nsWineURI
*This
= impl_from_nsIURL(iface
);
2072 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aHost
));
2074 if(!ensure_uri_builder(This
))
2075 return NS_ERROR_UNEXPECTED
;
2077 nsACString_GetData(aHost
, &hosta
);
2078 host
= heap_strdupAtoW(hosta
);
2080 return NS_ERROR_OUT_OF_MEMORY
;
2082 hres
= IUriBuilder_SetHost(This
->uri_builder
, host
);
2085 return NS_ERROR_UNEXPECTED
;
2090 static nsresult NSAPI
nsURI_GetPort(nsIURL
*iface
, PRInt32
*aPort
)
2092 nsWineURI
*This
= impl_from_nsIURL(iface
);
2096 TRACE("(%p)->(%p)\n", This
, aPort
);
2098 if(!ensure_uri(This
))
2099 return NS_ERROR_UNEXPECTED
;
2101 hres
= IUri_GetPort(This
->uri
, &port
);
2103 WARN("GetPort failed: %08x\n", hres
);
2104 return NS_ERROR_UNEXPECTED
;
2107 *aPort
= port
? port
: -1;
2111 static nsresult NSAPI
nsURI_SetPort(nsIURL
*iface
, PRInt32 aPort
)
2113 nsWineURI
*This
= impl_from_nsIURL(iface
);
2116 TRACE("(%p)->(%d)\n", This
, aPort
);
2118 if(!ensure_uri_builder(This
))
2119 return NS_ERROR_UNEXPECTED
;
2121 hres
= IUriBuilder_SetPort(This
->uri_builder
, aPort
!= -1, aPort
);
2122 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_FAILURE
;
2125 static nsresult NSAPI
nsURI_GetPath(nsIURL
*iface
, nsACString
*aPath
)
2127 nsWineURI
*This
= impl_from_nsIURL(iface
);
2129 TRACE("(%p)->(%p)\n", This
, aPath
);
2131 return get_uri_string(This
, Uri_PROPERTY_PATH
, aPath
);
2134 static nsresult NSAPI
nsURI_SetPath(nsIURL
*iface
, const nsACString
*aPath
)
2136 nsWineURI
*This
= impl_from_nsIURL(iface
);
2141 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPath
));
2143 if(!ensure_uri_builder(This
))
2144 return NS_ERROR_UNEXPECTED
;
2146 nsACString_GetData(aPath
, &patha
);
2147 path
= heap_strdupAtoW(patha
);
2149 return NS_ERROR_OUT_OF_MEMORY
;
2151 hres
= IUriBuilder_SetPath(This
->uri_builder
, path
);
2154 return NS_ERROR_UNEXPECTED
;
2159 static nsresult NSAPI
nsURL_GetRef(nsIURL
*iface
, nsACString
*aRef
)
2161 nsWineURI
*This
= impl_from_nsIURL(iface
);
2166 TRACE("(%p)->(%p)\n", This
, aRef
);
2168 if(!ensure_uri(This
))
2169 return NS_ERROR_UNEXPECTED
;
2171 hres
= IUri_GetFragment(This
->uri
, &ref
);
2173 return NS_ERROR_UNEXPECTED
;
2175 refa
= heap_strdupWtoA(ref
);
2178 return NS_ERROR_OUT_OF_MEMORY
;
2180 nsACString_SetData(aRef
, refa
&& *refa
== '#' ? refa
+1 : refa
);
2185 static nsresult NSAPI
nsURL_SetRef(nsIURL
*iface
, const nsACString
*aRef
)
2187 nsWineURI
*This
= impl_from_nsIURL(iface
);
2192 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRef
));
2194 if(!ensure_uri_builder(This
))
2195 return NS_ERROR_UNEXPECTED
;
2197 nsACString_GetData(aRef
, &refa
);
2198 ref
= heap_strdupAtoW(refa
);
2200 return NS_ERROR_OUT_OF_MEMORY
;
2202 hres
= IUriBuilder_SetFragment(This
->uri_builder
, ref
);
2205 return NS_ERROR_UNEXPECTED
;
2210 static nsresult NSAPI
nsURI_Equals(nsIURL
*iface
, nsIURI
*other
, PRBool
*_retval
)
2212 nsWineURI
*This
= impl_from_nsIURL(iface
);
2213 nsWineURI
*other_obj
;
2217 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
2219 nsres
= nsIURI_QueryInterface(other
, &IID_nsWineURI
, (void**)&other_obj
);
2220 if(NS_FAILED(nsres
)) {
2221 TRACE("Could not get nsWineURI interface\n");
2226 if(ensure_uri(This
) && ensure_uri(other_obj
)) {
2229 hres
= IUri_IsEqual(This
->uri
, other_obj
->uri
, &b
);
2230 if(SUCCEEDED(hres
)) {
2234 nsres
= NS_ERROR_FAILURE
;
2237 nsres
= NS_ERROR_UNEXPECTED
;
2240 nsIURI_Release(&other_obj
->nsIURL_iface
);
2244 static nsresult NSAPI
nsURI_SchemeIs(nsIURL
*iface
, const char *scheme
, PRBool
*_retval
)
2246 nsWineURI
*This
= impl_from_nsIURL(iface
);
2247 WCHAR buf
[INTERNET_MAX_SCHEME_LENGTH
];
2251 TRACE("(%p)->(%s %p)\n", This
, debugstr_a(scheme
), _retval
);
2253 if(!ensure_uri(This
))
2254 return NS_ERROR_UNEXPECTED
;
2256 hres
= IUri_GetSchemeName(This
->uri
, &scheme_name
);
2258 return NS_ERROR_UNEXPECTED
;
2260 MultiByteToWideChar(CP_ACP
, 0, scheme
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
2261 *_retval
= !strcmpW(scheme_name
, buf
);
2262 SysFreeString(scheme_name
);
2266 static nsresult NSAPI
nsURI_Clone(nsIURL
*iface
, nsIURI
**_retval
)
2268 nsWineURI
*This
= impl_from_nsIURL(iface
);
2269 nsIURI
*nsuri
= NULL
;
2270 nsWineURI
*wine_uri
;
2273 TRACE("(%p)->(%p)\n", This
, _retval
);
2275 if(!ensure_uri(This
))
2276 return NS_ERROR_UNEXPECTED
;
2279 nsres
= nsIURI_Clone(This
->nsuri
, &nsuri
);
2280 if(NS_FAILED(nsres
)) {
2281 WARN("Clone failed: %08x\n", nsres
);
2286 nsres
= create_nsuri(This
->uri
, nsuri
, This
->window_ref
? This
->window_ref
->window
: NULL
, This
->container
, &wine_uri
);
2287 if(NS_FAILED(nsres
)) {
2288 WARN("create_nsuri failed: %08x\n", nsres
);
2292 *_retval
= (nsIURI
*)&wine_uri
->nsIURL_iface
;
2296 static nsresult NSAPI
nsURI_Resolve(nsIURL
*iface
, const nsACString
*aRelativePath
,
2297 nsACString
*_retval
)
2299 nsWineURI
*This
= impl_from_nsIURL(iface
);
2307 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aRelativePath
), _retval
);
2309 if(!ensure_uri(This
))
2310 return NS_ERROR_UNEXPECTED
;
2312 nsACString_GetData(aRelativePath
, &patha
);
2313 path
= heap_strdupAtoW(patha
);
2315 return NS_ERROR_OUT_OF_MEMORY
;
2317 hres
= CoInternetCombineUrlEx(This
->uri
, path
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
, &new_uri
, 0);
2320 ERR("CoIntenetCombineUrlEx failed: %08x\n", hres
);
2321 return NS_ERROR_FAILURE
;
2324 hres
= IUri_GetDisplayUri(new_uri
, &ret
);
2325 IUri_Release(new_uri
);
2327 return NS_ERROR_FAILURE
;
2329 reta
= heap_strdupWtoA(ret
);
2332 return NS_ERROR_OUT_OF_MEMORY
;
2334 TRACE("returning %s\n", debugstr_a(reta
));
2335 nsACString_SetData(_retval
, reta
);
2340 static nsresult NSAPI
nsURI_GetAsciiSpec(nsIURL
*iface
, nsACString
*aAsciiSpec
)
2342 nsWineURI
*This
= impl_from_nsIURL(iface
);
2344 TRACE("(%p)->(%p)\n", This
, aAsciiSpec
);
2346 return nsIURI_GetSpec(&This
->nsIURL_iface
, aAsciiSpec
);
2349 static nsresult NSAPI
nsURI_GetAsciiHost(nsIURL
*iface
, nsACString
*aAsciiHost
)
2351 nsWineURI
*This
= impl_from_nsIURL(iface
);
2353 WARN("(%p)->(%p) FIXME: Use Uri_PUNYCODE_IDN_HOST flag\n", This
, aAsciiHost
);
2355 return get_uri_string(This
, Uri_PROPERTY_HOST
, aAsciiHost
);
2358 static nsresult NSAPI
nsURI_GetOriginCharset(nsIURL
*iface
, nsACString
*aOriginCharset
)
2360 nsWineURI
*This
= impl_from_nsIURL(iface
);
2362 TRACE("(%p)->(%p)\n", This
, aOriginCharset
);
2365 return nsIURI_GetOriginCharset(This
->nsuri
, aOriginCharset
);
2367 FIXME("default action not implemented\n");
2368 return NS_ERROR_NOT_IMPLEMENTED
;
2371 static nsresult NSAPI
nsURI_EqualsExceptRef(nsIURL
*iface
, nsIURI
*other
, PRBool
*_retval
)
2373 nsWineURI
*This
= impl_from_nsIURL(iface
);
2374 nsWineURI
*other_obj
;
2377 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
2379 nsres
= nsIURI_QueryInterface(other
, &IID_nsWineURI
, (void**)&other_obj
);
2380 if(NS_FAILED(nsres
)) {
2381 TRACE("Could not get nsWineURI interface\n");
2386 if(ensure_uri(This
) && ensure_uri(other_obj
)) {
2387 *_retval
= compare_ignoring_frag(This
->uri
, other_obj
->uri
);
2390 nsres
= NS_ERROR_UNEXPECTED
;
2393 nsIURI_Release(&other_obj
->nsIURL_iface
);
2397 static nsresult NSAPI
nsURI_CloneIgnoreRef(nsIURL
*iface
, nsIURI
**_retval
)
2399 nsWineURI
*This
= impl_from_nsIURL(iface
);
2400 nsWineURI
*wine_uri
;
2404 TRACE("(%p)->(%p)\n", This
, _retval
);
2406 if(!ensure_uri(This
))
2407 return NS_ERROR_UNEXPECTED
;
2409 uri
= get_uri_nofrag(This
->uri
);
2411 return NS_ERROR_FAILURE
;
2413 nsres
= create_nsuri(uri
, NULL
, This
->window_ref
? This
->window_ref
->window
: NULL
, This
->container
, &wine_uri
);
2415 if(NS_FAILED(nsres
)) {
2416 WARN("create_nsuri failed: %08x\n", nsres
);
2420 *_retval
= (nsIURI
*)&wine_uri
->nsIURL_iface
;
2424 static nsresult NSAPI
nsURI_GetSpecIgnoringRef(nsIURL
*iface
, nsACString
*aSpecIgnoringRef
)
2426 nsWineURI
*This
= impl_from_nsIURL(iface
);
2428 FIXME("(%p)->(%p)\n", This
, aSpecIgnoringRef
);
2430 return nsIURL_GetSpec(&This
->nsIURL_iface
, aSpecIgnoringRef
);
2433 static nsresult NSAPI
nsURI_GetHasRef(nsIURL
*iface
, PRBool
*aHasRef
)
2435 nsWineURI
*This
= impl_from_nsIURL(iface
);
2439 TRACE("(%p)->(%p)\n", This
, aHasRef
);
2441 if(!ensure_uri(This
))
2442 return NS_ERROR_UNEXPECTED
;
2444 hres
= IUri_HasProperty(This
->uri
, Uri_PROPERTY_FRAGMENT
, &b
);
2446 return NS_ERROR_FAILURE
;
2452 static nsresult NSAPI
nsURL_GetFilePath(nsIURL
*iface
, nsACString
*aFilePath
)
2454 nsWineURI
*This
= impl_from_nsIURL(iface
);
2456 TRACE("(%p)->(%p)\n", This
, aFilePath
);
2458 return nsIURL_GetPath(&This
->nsIURL_iface
, aFilePath
);
2461 static nsresult NSAPI
nsURL_SetFilePath(nsIURL
*iface
, const nsACString
*aFilePath
)
2463 nsWineURI
*This
= impl_from_nsIURL(iface
);
2465 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFilePath
));
2467 return nsIURL_SetPath(&This
->nsIURL_iface
, aFilePath
);
2470 static nsresult NSAPI
nsURL_GetParam(nsIURL
*iface
, nsACString
*aParam
)
2472 nsWineURI
*This
= impl_from_nsIURL(iface
);
2474 WARN("(%p)->(%p)\n", This
, aParam
);
2476 /* This is a leftover of ';' special handling in URLs. It will be removed from Gecko soon */
2477 nsACString_SetData(aParam
, "");
2481 static nsresult NSAPI
nsURL_SetParam(nsIURL
*iface
, const nsACString
*aParam
)
2483 nsWineURI
*This
= impl_from_nsIURL(iface
);
2485 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aParam
));
2487 /* Not implemented by Gecko */
2488 return NS_ERROR_NOT_IMPLEMENTED
;
2491 static nsresult NSAPI
nsURL_GetQuery(nsIURL
*iface
, nsACString
*aQuery
)
2493 nsWineURI
*This
= impl_from_nsIURL(iface
);
2495 TRACE("(%p)->(%p)\n", This
, aQuery
);
2497 return get_uri_string(This
, Uri_PROPERTY_QUERY
, aQuery
);
2500 static nsresult NSAPI
nsURL_SetQuery(nsIURL
*iface
, const nsACString
*aQuery
)
2502 nsWineURI
*This
= impl_from_nsIURL(iface
);
2507 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aQuery
));
2509 if(!ensure_uri_builder(This
))
2510 return NS_ERROR_UNEXPECTED
;
2512 nsACString_GetData(aQuery
, &querya
);
2513 query
= heap_strdupAtoW(querya
);
2515 return NS_ERROR_OUT_OF_MEMORY
;
2517 hres
= IUriBuilder_SetQuery(This
->uri_builder
, query
);
2520 return NS_ERROR_UNEXPECTED
;
2525 static nsresult NSAPI
nsURL_GetDirectory(nsIURL
*iface
, nsACString
*aDirectory
)
2527 nsWineURI
*This
= impl_from_nsIURL(iface
);
2533 TRACE("(%p)->(%p)\n", This
, aDirectory
);
2535 if(!ensure_uri(This
))
2536 return NS_ERROR_UNEXPECTED
;
2538 hres
= IUri_GetPath(This
->uri
, &path
);
2540 return NS_ERROR_FAILURE
;
2542 ptr
= strrchrW(path
, '/');
2546 dir
= heap_strdupWtoA(path
);
2548 SysFreeString(path
);
2549 return NS_ERROR_OUT_OF_MEMORY
;
2553 SysFreeString(path
);
2554 TRACE("ret %s\n", debugstr_a(dir
));
2555 nsACString_SetData(aDirectory
, dir
? dir
: "");
2560 static nsresult NSAPI
nsURL_SetDirectory(nsIURL
*iface
, const nsACString
*aDirectory
)
2562 nsWineURI
*This
= impl_from_nsIURL(iface
);
2564 WARN("(%p)->(%s)\n", This
, debugstr_nsacstr(aDirectory
));
2566 /* Not implemented by Gecko */
2567 return NS_ERROR_NOT_IMPLEMENTED
;
2570 static nsresult NSAPI
nsURL_GetFileName(nsIURL
*iface
, nsACString
*aFileName
)
2572 nsWineURI
*This
= impl_from_nsIURL(iface
);
2574 TRACE("(%p)->(%p)\n", This
, aFileName
);
2577 return nsIURL_GetFileName(This
->nsurl
, aFileName
);
2579 FIXME("default action not implemented\n");
2580 return NS_ERROR_NOT_IMPLEMENTED
;
2583 static nsresult NSAPI
nsURL_SetFileName(nsIURL
*iface
, const nsACString
*aFileName
)
2585 nsWineURI
*This
= impl_from_nsIURL(iface
);
2587 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileName
));
2590 invalidate_uri(This
);
2591 return nsIURL_SetFileName(This
->nsurl
, aFileName
);
2594 FIXME("default action not implemented\n");
2595 return NS_ERROR_NOT_IMPLEMENTED
;
2598 static nsresult NSAPI
nsURL_GetFileBaseName(nsIURL
*iface
, nsACString
*aFileBaseName
)
2600 nsWineURI
*This
= impl_from_nsIURL(iface
);
2602 TRACE("(%p)->(%p)\n", This
, aFileBaseName
);
2605 return nsIURL_GetFileBaseName(This
->nsurl
, aFileBaseName
);
2607 FIXME("default action not implemented\n");
2608 return NS_ERROR_NOT_IMPLEMENTED
;
2611 static nsresult NSAPI
nsURL_SetFileBaseName(nsIURL
*iface
, const nsACString
*aFileBaseName
)
2613 nsWineURI
*This
= impl_from_nsIURL(iface
);
2615 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileBaseName
));
2618 invalidate_uri(This
);
2619 return nsIURL_SetFileBaseName(This
->nsurl
, aFileBaseName
);
2622 FIXME("default action not implemented\n");
2623 return NS_ERROR_NOT_IMPLEMENTED
;
2626 static nsresult NSAPI
nsURL_GetFileExtension(nsIURL
*iface
, nsACString
*aFileExtension
)
2628 nsWineURI
*This
= impl_from_nsIURL(iface
);
2630 TRACE("(%p)->(%p)\n", This
, aFileExtension
);
2632 return get_uri_string(This
, Uri_PROPERTY_EXTENSION
, aFileExtension
);
2635 static nsresult NSAPI
nsURL_SetFileExtension(nsIURL
*iface
, const nsACString
*aFileExtension
)
2637 nsWineURI
*This
= impl_from_nsIURL(iface
);
2639 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileExtension
));
2642 invalidate_uri(This
);
2643 return nsIURL_SetFileExtension(This
->nsurl
, aFileExtension
);
2646 FIXME("default action not implemented\n");
2647 return NS_ERROR_NOT_IMPLEMENTED
;
2650 static nsresult NSAPI
nsURL_GetCommonBaseSpec(nsIURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2652 nsWineURI
*This
= impl_from_nsIURL(iface
);
2654 TRACE("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2657 return nsIURL_GetCommonBaseSpec(This
->nsurl
, aURIToCompare
, _retval
);
2659 FIXME("default action not implemented\n");
2660 return NS_ERROR_NOT_IMPLEMENTED
;
2663 static nsresult NSAPI
nsURL_GetRelativeSpec(nsIURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2665 nsWineURI
*This
= impl_from_nsIURL(iface
);
2667 TRACE("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2670 return nsIURL_GetRelativeSpec(This
->nsurl
, aURIToCompare
, _retval
);
2672 FIXME("default action not implemented\n");
2673 return NS_ERROR_NOT_IMPLEMENTED
;
2676 static const nsIURLVtbl nsURLVtbl
= {
2677 nsURI_QueryInterface
,
2705 nsURI_GetOriginCharset
,
2708 nsURI_EqualsExceptRef
,
2709 nsURI_CloneIgnoreRef
,
2710 nsURI_GetSpecIgnoringRef
,
2722 nsURL_GetFileBaseName
,
2723 nsURL_SetFileBaseName
,
2724 nsURL_GetFileExtension
,
2725 nsURL_SetFileExtension
,
2726 nsURL_GetCommonBaseSpec
,
2727 nsURL_GetRelativeSpec
2730 static inline nsWineURI
*impl_from_nsIStandardURL(nsIStandardURL
*iface
)
2732 return CONTAINING_RECORD(iface
, nsWineURI
, nsIStandardURL_iface
);
2735 static nsresult NSAPI
nsStandardURL_QueryInterface(nsIStandardURL
*iface
, nsIIDRef riid
,
2738 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2739 return nsIURL_QueryInterface(&This
->nsIURL_iface
, riid
, result
);
2742 static nsrefcnt NSAPI
nsStandardURL_AddRef(nsIStandardURL
*iface
)
2744 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2745 return nsIURL_AddRef(&This
->nsIURL_iface
);
2748 static nsrefcnt NSAPI
nsStandardURL_Release(nsIStandardURL
*iface
)
2750 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2751 return nsIURL_Release(&This
->nsIURL_iface
);
2754 static nsresult NSAPI
nsStandardURL_GetMutable(nsIStandardURL
*iface
, PRBool
*aMutable
)
2756 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2758 TRACE("(%p)->(%p)\n", This
, aMutable
);
2764 static nsresult NSAPI
nsStandardURL_SetMutable(nsIStandardURL
*iface
, PRBool aMutable
)
2766 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2767 FIXME("(%p)->(%x)\n", This
, aMutable
);
2768 return NS_ERROR_NOT_IMPLEMENTED
;
2771 static nsresult NSAPI
nsStandardURL_Init(nsIStandardURL
*iface
, PRUint32 aUrlType
, PRInt32 aDefaultPort
,
2772 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
)
2774 nsWineURI
*This
= impl_from_nsIStandardURL(iface
);
2775 FIXME("(%p)->(%d %d %s %s %p)\n", This
, aUrlType
, aDefaultPort
, debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
), aBaseURI
);
2776 return NS_ERROR_NOT_IMPLEMENTED
;
2779 static const nsIStandardURLVtbl nsStandardURLVtbl
= {
2780 nsStandardURL_QueryInterface
,
2781 nsStandardURL_AddRef
,
2782 nsStandardURL_Release
,
2783 nsStandardURL_GetMutable
,
2784 nsStandardURL_SetMutable
,
2788 static nsresult
create_nsuri(IUri
*iuri
, nsIURI
*nsuri
, HTMLWindow
*window
, NSContainer
*container
, nsWineURI
**_retval
)
2790 nsWineURI
*ret
= heap_alloc_zero(sizeof(nsWineURI
));
2792 ret
->nsIURL_iface
.lpVtbl
= &nsURLVtbl
;
2793 ret
->nsIStandardURL_iface
.lpVtbl
= &nsStandardURLVtbl
;
2797 set_uri_nscontainer(ret
, container
);
2798 set_uri_window(ret
, window
);
2804 nsIURI_QueryInterface(nsuri
, &IID_nsIURL
, (void**)&ret
->nsurl
);
2806 TRACE("retval=%p\n", ret
);
2811 HRESULT
create_doc_uri(HTMLWindow
*window
, WCHAR
*url
, nsWineURI
**ret
)
2818 hres
= CreateUri(url
, 0, 0, &iuri
);
2822 nsres
= create_nsuri(iuri
, NULL
, window
, window
->doc_obj
->nscontainer
, &uri
);
2824 if(NS_FAILED(nsres
))
2827 uri
->is_doc_uri
= TRUE
;
2833 static nsresult
create_nschannel(nsWineURI
*uri
, nsChannel
**ret
)
2838 if(!ensure_uri(uri
))
2839 return NS_ERROR_UNEXPECTED
;
2841 channel
= heap_alloc_zero(sizeof(nsChannel
));
2843 return NS_ERROR_OUT_OF_MEMORY
;
2845 channel
->nsIHttpChannel_iface
.lpVtbl
= &nsChannelVtbl
;
2846 channel
->nsIUploadChannel_iface
.lpVtbl
= &nsUploadChannelVtbl
;
2847 channel
->nsIHttpChannelInternal_iface
.lpVtbl
= &nsHttpChannelInternalVtbl
;
2849 channel
->request_method
= METHOD_GET
;
2850 list_init(&channel
->response_headers
);
2851 list_init(&channel
->request_headers
);
2853 nsIURL_AddRef(&uri
->nsIURL_iface
);
2856 hres
= IUri_GetScheme(uri
->uri
, &channel
->url_scheme
);
2858 channel
->url_scheme
= URL_SCHEME_UNKNOWN
;
2864 HRESULT
create_redirect_nschannel(const WCHAR
*url
, nsChannel
*orig_channel
, nsChannel
**ret
)
2866 HTMLWindow
*window
= NULL
;
2873 hres
= CreateUri(url
, 0, 0, &iuri
);
2877 if(orig_channel
->uri
->window_ref
)
2878 window
= orig_channel
->uri
->window_ref
->window
;
2879 nsres
= create_nsuri(iuri
, NULL
, window
, NULL
, &uri
);
2881 if(NS_FAILED(nsres
))
2884 nsres
= create_nschannel(uri
, &channel
);
2885 nsIURL_Release(&uri
->nsIURL_iface
);
2886 if(NS_FAILED(nsres
))
2889 if(orig_channel
->load_group
) {
2890 nsILoadGroup_AddRef(orig_channel
->load_group
);
2891 channel
->load_group
= orig_channel
->load_group
;
2894 if(orig_channel
->notif_callback
) {
2895 nsIInterfaceRequestor_AddRef(orig_channel
->notif_callback
);
2896 channel
->notif_callback
= orig_channel
->notif_callback
;
2899 channel
->load_flags
= orig_channel
->load_flags
| LOAD_REPLACE
;
2901 if(orig_channel
->request_method
== METHOD_POST
)
2902 FIXME("unsupported POST method\n");
2904 if(orig_channel
->original_uri
) {
2905 nsIURI_AddRef(orig_channel
->original_uri
);
2906 channel
->original_uri
= orig_channel
->original_uri
;
2909 if(orig_channel
->referrer
) {
2910 nsIURI_AddRef(orig_channel
->referrer
);
2911 channel
->referrer
= orig_channel
->referrer
;
2919 nsIProtocolHandler nsIProtocolHandler_iface
;
2923 nsIProtocolHandler
*nshandler
;
2924 } nsProtocolHandler
;
2926 static inline nsProtocolHandler
*impl_from_nsIProtocolHandler(nsIProtocolHandler
*iface
)
2928 return CONTAINING_RECORD(iface
, nsProtocolHandler
, nsIProtocolHandler_iface
);
2931 static nsresult NSAPI
nsProtocolHandler_QueryInterface(nsIProtocolHandler
*iface
, nsIIDRef riid
,
2934 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2938 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
2939 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
2940 *result
= &This
->nsIProtocolHandler_iface
;
2941 }else if(IsEqualGUID(&IID_nsIProtocolHandler
, riid
)) {
2942 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This
, result
);
2943 *result
= &This
->nsIProtocolHandler_iface
;
2944 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler
, riid
)) {
2945 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This
, result
);
2946 return NS_NOINTERFACE
;
2950 nsISupports_AddRef((nsISupports
*)*result
);
2954 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
2955 return NS_NOINTERFACE
;
2958 static nsrefcnt NSAPI
nsProtocolHandler_AddRef(nsIProtocolHandler
*iface
)
2960 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2961 LONG ref
= InterlockedIncrement(&This
->ref
);
2963 TRACE("(%p) ref=%d\n", This
, ref
);
2968 static nsrefcnt NSAPI
nsProtocolHandler_Release(nsIProtocolHandler
*iface
)
2970 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2971 LONG ref
= InterlockedDecrement(&This
->ref
);
2973 TRACE("(%p) ref=%d\n", This
, ref
);
2977 nsIProtocolHandler_Release(This
->nshandler
);
2984 static nsresult NSAPI
nsProtocolHandler_GetScheme(nsIProtocolHandler
*iface
, nsACString
*aScheme
)
2986 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
2988 TRACE("(%p)->(%p)\n", This
, aScheme
);
2991 return nsIProtocolHandler_GetScheme(This
->nshandler
, aScheme
);
2992 return NS_ERROR_NOT_IMPLEMENTED
;
2995 static nsresult NSAPI
nsProtocolHandler_GetDefaultPort(nsIProtocolHandler
*iface
,
2996 PRInt32
*aDefaultPort
)
2998 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3000 TRACE("(%p)->(%p)\n", This
, aDefaultPort
);
3003 return nsIProtocolHandler_GetDefaultPort(This
->nshandler
, aDefaultPort
);
3004 return NS_ERROR_NOT_IMPLEMENTED
;
3007 static nsresult NSAPI
nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler
*iface
,
3008 PRUint32
*aProtocolFlags
)
3010 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3012 TRACE("(%p)->(%p)\n", This
, aProtocolFlags
);
3015 return nsIProtocolHandler_GetProtocolFlags(This
->nshandler
, aProtocolFlags
);
3016 return NS_ERROR_NOT_IMPLEMENTED
;
3019 static nsresult NSAPI
nsProtocolHandler_NewURI(nsIProtocolHandler
*iface
,
3020 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
3022 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3024 TRACE("((%p)->%s %s %p %p)\n", This
, debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
3028 return nsIProtocolHandler_NewURI(This
->nshandler
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3029 return NS_ERROR_NOT_IMPLEMENTED
;
3032 static nsresult NSAPI
nsProtocolHandler_NewChannel(nsIProtocolHandler
*iface
,
3033 nsIURI
*aURI
, nsIChannel
**_retval
)
3035 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3037 TRACE("(%p)->(%p %p)\n", This
, aURI
, _retval
);
3040 return nsIProtocolHandler_NewChannel(This
->nshandler
, aURI
, _retval
);
3041 return NS_ERROR_NOT_IMPLEMENTED
;
3044 static nsresult NSAPI
nsProtocolHandler_AllowPort(nsIProtocolHandler
*iface
,
3045 PRInt32 port
, const char *scheme
, PRBool
*_retval
)
3047 nsProtocolHandler
*This
= impl_from_nsIProtocolHandler(iface
);
3049 TRACE("(%p)->(%d %s %p)\n", This
, port
, debugstr_a(scheme
), _retval
);
3052 return nsIProtocolHandler_AllowPort(This
->nshandler
, port
, scheme
, _retval
);
3053 return NS_ERROR_NOT_IMPLEMENTED
;
3056 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl
= {
3057 nsProtocolHandler_QueryInterface
,
3058 nsProtocolHandler_AddRef
,
3059 nsProtocolHandler_Release
,
3060 nsProtocolHandler_GetScheme
,
3061 nsProtocolHandler_GetDefaultPort
,
3062 nsProtocolHandler_GetProtocolFlags
,
3063 nsProtocolHandler_NewURI
,
3064 nsProtocolHandler_NewChannel
,
3065 nsProtocolHandler_AllowPort
3068 static nsIProtocolHandler
*create_protocol_handler(nsIProtocolHandler
*nshandler
)
3070 nsProtocolHandler
*ret
= heap_alloc(sizeof(nsProtocolHandler
));
3072 ret
->nsIProtocolHandler_iface
.lpVtbl
= &nsProtocolHandlerVtbl
;
3074 ret
->nshandler
= nshandler
;
3076 return &ret
->nsIProtocolHandler_iface
;
3079 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*,nsIIDRef
,void**);
3081 static nsrefcnt NSAPI
nsIOService_AddRef(nsIIOService
*iface
)
3086 static nsrefcnt NSAPI
nsIOService_Release(nsIIOService
*iface
)
3091 static nsresult NSAPI
nsIOService_GetProtocolHandler(nsIIOService
*iface
, const char *aScheme
,
3092 nsIProtocolHandler
**_retval
)
3094 nsIExternalProtocolHandler
*nsexthandler
;
3095 nsIProtocolHandler
*nshandler
;
3098 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
3100 nsres
= nsIIOService_GetProtocolHandler(nsio
, aScheme
, &nshandler
);
3101 if(NS_FAILED(nsres
)) {
3102 WARN("GetProtocolHandler failed: %08x\n", nsres
);
3106 nsres
= nsIProtocolHandler_QueryInterface(nshandler
, &IID_nsIExternalProtocolHandler
,
3107 (void**)&nsexthandler
);
3108 if(NS_FAILED(nsres
)) {
3109 *_retval
= nshandler
;
3113 nsIExternalProtocolHandler_Release(nsexthandler
);
3114 *_retval
= create_protocol_handler(nshandler
);
3115 TRACE("return %p\n", *_retval
);
3119 static nsresult NSAPI
nsIOService_GetProtocolFlags(nsIIOService
*iface
, const char *aScheme
,
3122 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
3123 return nsIIOService_GetProtocolFlags(nsio
, aScheme
, _retval
);
3126 static BOOL
is_gecko_special_uri(const char *spec
)
3128 static const char *special_schemes
[] = {"chrome:", "jar:", "moz-safe-about", "resource:", "javascript:", "wyciwyg:"};
3131 for(i
=0; i
< sizeof(special_schemes
)/sizeof(*special_schemes
); i
++) {
3132 if(!strncasecmp(spec
, special_schemes
[i
], strlen(special_schemes
[i
])))
3136 if(!strncasecmp(spec
, "file:", 5)) {
3137 const char *ptr
= spec
+5;
3140 return is_gecko_path(ptr
);
3146 static nsresult NSAPI
nsIOService_NewURI(nsIIOService
*iface
, const nsACString
*aSpec
,
3147 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
3149 nsWineURI
*wine_uri
, *base_wine_uri
= NULL
;
3150 WCHAR new_spec
[INTERNET_MAX_URL_LENGTH
];
3151 HTMLWindow
*window
= NULL
;
3152 const char *spec
= NULL
;
3158 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
3161 nsACString_GetData(aSpec
, &spec
);
3162 if(is_gecko_special_uri(spec
))
3163 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3165 if(!strncmp(spec
, "wine:", 5))
3169 nsres
= nsIURI_QueryInterface(aBaseURI
, &IID_nsWineURI
, (void**)&base_wine_uri
);
3170 if(NS_SUCCEEDED(nsres
)) {
3171 if(!ensure_uri(base_wine_uri
))
3172 return NS_ERROR_UNEXPECTED
;
3173 if(base_wine_uri
->window_ref
)
3174 window
= base_wine_uri
->window_ref
->window
;
3176 WARN("Could not get base nsWineURI: %08x\n", nsres
);
3180 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, new_spec
, sizeof(new_spec
)/sizeof(WCHAR
));
3183 hres
= CoInternetCombineUrlEx(base_wine_uri
->uri
, new_spec
, URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
3186 WARN("CoInternetCombineUrlEx failed: %08x\n", hres
);
3188 hres
= CreateUri(new_spec
, 0, 0, &urlmon_uri
);
3190 WARN("CreateUri failed: %08x\n", hres
);
3193 nsres
= nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, &uri
);
3194 if(NS_FAILED(nsres
))
3195 TRACE("NewURI failed: %08x\n", nsres
);
3202 nsres
= create_nsuri(urlmon_uri
, uri
, window
, NULL
, &wine_uri
);
3203 IUri_Release(urlmon_uri
);
3205 nsIURI_Release(&base_wine_uri
->nsIURL_iface
);
3206 if(NS_FAILED(nsres
))
3209 *_retval
= (nsIURI
*)&wine_uri
->nsIURL_iface
;
3213 static nsresult NSAPI
nsIOService_NewFileURI(nsIIOService
*iface
, nsIFile
*aFile
,
3216 TRACE("(%p %p)\n", aFile
, _retval
);
3217 return nsIIOService_NewFileURI(nsio
, aFile
, _retval
);
3220 static nsresult NSAPI
nsIOService_NewChannelFromURI(nsIIOService
*iface
, nsIURI
*aURI
,
3221 nsIChannel
**_retval
)
3223 nsWineURI
*wine_uri
;
3227 TRACE("(%p %p)\n", aURI
, _retval
);
3229 nsres
= nsIURI_QueryInterface(aURI
, &IID_nsWineURI
, (void**)&wine_uri
);
3230 if(NS_FAILED(nsres
)) {
3231 TRACE("Could not get nsWineURI: %08x\n", nsres
);
3232 return nsIIOService_NewChannelFromURI(nsio
, aURI
, _retval
);
3235 nsres
= create_nschannel(wine_uri
, &ret
);
3236 nsIURL_Release(&wine_uri
->nsIURL_iface
);
3237 if(NS_FAILED(nsres
))
3240 nsIURI_AddRef(aURI
);
3241 ret
->original_uri
= aURI
;
3243 *_retval
= (nsIChannel
*)&ret
->nsIHttpChannel_iface
;
3247 static nsresult NSAPI
nsIOService_NewChannel(nsIIOService
*iface
, const nsACString
*aSpec
,
3248 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIChannel
**_retval
)
3250 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
), aBaseURI
, _retval
);
3251 return nsIIOService_NewChannel(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
3254 static nsresult NSAPI
nsIOService_GetOffline(nsIIOService
*iface
, PRBool
*aOffline
)
3256 TRACE("(%p)\n", aOffline
);
3257 return nsIIOService_GetOffline(nsio
, aOffline
);
3260 static nsresult NSAPI
nsIOService_SetOffline(nsIIOService
*iface
, PRBool aOffline
)
3262 TRACE("(%x)\n", aOffline
);
3263 return nsIIOService_SetOffline(nsio
, aOffline
);
3266 static nsresult NSAPI
nsIOService_AllowPort(nsIIOService
*iface
, PRInt32 aPort
,
3267 const char *aScheme
, PRBool
*_retval
)
3269 TRACE("(%d %s %p)\n", aPort
, debugstr_a(aScheme
), _retval
);
3270 return nsIIOService_AllowPort(nsio
, aPort
, debugstr_a(aScheme
), _retval
);
3273 static nsresult NSAPI
nsIOService_ExtractScheme(nsIIOService
*iface
, const nsACString
*urlString
,
3274 nsACString
* _retval
)
3276 TRACE("(%s %p)\n", debugstr_nsacstr(urlString
), _retval
);
3277 return nsIIOService_ExtractScheme(nsio
, urlString
, _retval
);
3280 static const nsIIOServiceVtbl nsIOServiceVtbl
= {
3281 nsIOService_QueryInterface
,
3283 nsIOService_Release
,
3284 nsIOService_GetProtocolHandler
,
3285 nsIOService_GetProtocolFlags
,
3287 nsIOService_NewFileURI
,
3288 nsIOService_NewChannelFromURI
,
3289 nsIOService_NewChannel
,
3290 nsIOService_GetOffline
,
3291 nsIOService_SetOffline
,
3292 nsIOService_AllowPort
,
3293 nsIOService_ExtractScheme
3296 static nsIIOService nsIOService
= { &nsIOServiceVtbl
};
3298 static nsresult NSAPI
nsNetUtil_QueryInterface(nsINetUtil
*iface
, nsIIDRef riid
,
3301 return nsIIOService_QueryInterface(&nsIOService
, riid
, result
);
3304 static nsrefcnt NSAPI
nsNetUtil_AddRef(nsINetUtil
*iface
)
3309 static nsrefcnt NSAPI
nsNetUtil_Release(nsINetUtil
*iface
)
3314 static nsresult NSAPI
nsNetUtil_ParseContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
3315 nsACString
*aCharset
, PRBool
*aHadCharset
, nsACString
*aContentType
)
3317 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aHadCharset
, aContentType
);
3319 return nsINetUtil_ParseContentType(net_util
, aTypeHeader
, aCharset
, aHadCharset
, aContentType
);
3322 static nsresult NSAPI
nsNetUtil_ProtocolHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, PRUint32 aFlags
, PRBool
*_retval
)
3326 return nsINetUtil_ProtocolHasFlags(net_util
, aURI
, aFlags
, _retval
);
3329 static nsresult NSAPI
nsNetUtil_URIChainHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, PRUint32 aFlags
, PRBool
*_retval
)
3331 TRACE("(%p %08x %p)\n", aURI
, aFlags
, _retval
);
3333 if(aFlags
== (1<<11)) {
3338 return nsINetUtil_URIChainHasFlags(net_util
, aURI
, aFlags
, _retval
);
3341 static nsresult NSAPI
nsNetUtil_ToImmutableURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
3343 TRACE("(%p %p)\n", aURI
, _retval
);
3345 return nsINetUtil_ToImmutableURI(net_util
, aURI
, _retval
);
3348 static nsresult NSAPI
nsNetUtil_NewSimpleNestedURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
3350 TRACE("(%p %p)\n", aURI
, _retval
);
3352 return nsINetUtil_NewSimpleNestedURI(net_util
, aURI
, _retval
);
3355 static nsresult NSAPI
nsNetUtil_EscapeString(nsINetUtil
*iface
, const nsACString
*aString
,
3356 PRUint32 aEscapeType
, nsACString
*_retval
)
3358 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString
), aEscapeType
, _retval
);
3360 return nsINetUtil_EscapeString(net_util
, aString
, aEscapeType
, _retval
);
3363 static nsresult NSAPI
nsNetUtil_EscapeURL(nsINetUtil
*iface
, const nsACString
*aStr
, PRUint32 aFlags
,
3364 nsACString
*_retval
)
3366 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
3368 return nsINetUtil_EscapeURL(net_util
, aStr
, aFlags
, _retval
);
3371 static nsresult NSAPI
nsNetUtil_UnescapeString(nsINetUtil
*iface
, const nsACString
*aStr
,
3372 PRUint32 aFlags
, nsACString
*_retval
)
3374 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
3376 return nsINetUtil_UnescapeString(net_util
, aStr
, aFlags
, _retval
);
3379 static nsresult NSAPI
nsNetUtil_ExtractCharsetFromContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
3380 nsACString
*aCharset
, PRInt32
*aCharsetStart
, PRInt32
*aCharsetEnd
, PRBool
*_retval
)
3382 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aCharsetStart
,
3383 aCharsetEnd
, _retval
);
3385 return nsINetUtil_ExtractCharsetFromContentType(net_util
, aTypeHeader
, aCharset
, aCharsetStart
, aCharsetEnd
, _retval
);
3388 static const nsINetUtilVtbl nsNetUtilVtbl
= {
3389 nsNetUtil_QueryInterface
,
3392 nsNetUtil_ParseContentType
,
3393 nsNetUtil_ProtocolHasFlags
,
3394 nsNetUtil_URIChainHasFlags
,
3395 nsNetUtil_ToImmutableURI
,
3396 nsNetUtil_NewSimpleNestedURI
,
3397 nsNetUtil_EscapeString
,
3398 nsNetUtil_EscapeURL
,
3399 nsNetUtil_UnescapeString
,
3400 nsNetUtil_ExtractCharsetFromContentType
3403 static nsINetUtil nsNetUtil
= { &nsNetUtilVtbl
};
3405 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*iface
, nsIIDRef riid
,
3410 if(IsEqualGUID(&IID_nsISupports
, riid
))
3411 *result
= &nsIOService
;
3412 else if(IsEqualGUID(&IID_nsIIOService
, riid
))
3413 *result
= &nsIOService
;
3414 else if(IsEqualGUID(&IID_nsINetUtil
, riid
))
3415 *result
= &nsNetUtil
;
3418 nsISupports_AddRef((nsISupports
*)*result
);
3422 FIXME("(%s %p)\n", debugstr_guid(riid
), result
);
3423 return NS_NOINTERFACE
;
3426 static nsresult NSAPI
nsIOServiceFactory_QueryInterface(nsIFactory
*iface
, nsIIDRef riid
,
3431 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
3432 TRACE("(IID_nsISupports %p)\n", result
);
3434 }else if(IsEqualGUID(&IID_nsIFactory
, riid
)) {
3435 TRACE("(IID_nsIFactory %p)\n", result
);
3440 nsIFactory_AddRef(iface
);
3444 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
3445 return NS_NOINTERFACE
;
3448 static nsrefcnt NSAPI
nsIOServiceFactory_AddRef(nsIFactory
*iface
)
3453 static nsrefcnt NSAPI
nsIOServiceFactory_Release(nsIFactory
*iface
)
3458 static nsresult NSAPI
nsIOServiceFactory_CreateInstance(nsIFactory
*iface
,
3459 nsISupports
*aOuter
, const nsIID
*iid
, void **result
)
3461 return nsIIOService_QueryInterface(&nsIOService
, iid
, result
);
3464 static nsresult NSAPI
nsIOServiceFactory_LockFactory(nsIFactory
*iface
, PRBool lock
)
3466 WARN("(%x)\n", lock
);
3470 static const nsIFactoryVtbl nsIOServiceFactoryVtbl
= {
3471 nsIOServiceFactory_QueryInterface
,
3472 nsIOServiceFactory_AddRef
,
3473 nsIOServiceFactory_Release
,
3474 nsIOServiceFactory_CreateInstance
,
3475 nsIOServiceFactory_LockFactory
3478 static nsIFactory nsIOServiceFactory
= { &nsIOServiceFactoryVtbl
};
3480 static BOOL
translate_url(HTMLDocumentObj
*doc
, nsWineURI
*uri
)
3482 OLECHAR
*new_url
= NULL
;
3487 if(!doc
->hostui
|| !ensure_uri(uri
))
3490 hres
= IUri_GetDisplayUri(uri
->uri
, &url
);
3494 hres
= IDocHostUIHandler_TranslateUrl(doc
->hostui
, 0, url
, &new_url
);
3495 if(hres
== S_OK
&& new_url
) {
3496 if(strcmpW(url
, new_url
)) {
3497 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url
), debugstr_w(new_url
));
3500 CoTaskMemFree(new_url
);
3507 nsresult
on_start_uri_open(NSContainer
*nscontainer
, nsIURI
*uri
, PRBool
*_retval
)
3509 nsWineURI
*wine_uri
;
3514 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
3515 if(NS_FAILED(nsres
)) {
3516 WARN("Could not get nsWineURI: %08x\n", nsres
);
3517 return NS_ERROR_NOT_IMPLEMENTED
;
3520 if(!wine_uri
->is_doc_uri
) {
3521 wine_uri
->is_doc_uri
= TRUE
;
3523 if(!wine_uri
->container
) {
3524 nsIWebBrowserChrome_AddRef(&nscontainer
->nsIWebBrowserChrome_iface
);
3525 wine_uri
->container
= nscontainer
;
3528 if(nscontainer
->doc
)
3529 *_retval
= translate_url(nscontainer
->doc
, wine_uri
);
3532 nsIURI_Release(&wine_uri
->nsIURL_iface
);
3536 void init_nsio(nsIComponentManager
*component_manager
, nsIComponentRegistrar
*registrar
)
3538 nsIFactory
*old_factory
= NULL
;
3541 nsres
= nsIComponentManager_GetClassObject(component_manager
, &NS_IOSERVICE_CID
,
3542 &IID_nsIFactory
, (void**)&old_factory
);
3543 if(NS_FAILED(nsres
)) {
3544 ERR("Could not get factory: %08x\n", nsres
);
3548 nsres
= nsIFactory_CreateInstance(old_factory
, NULL
, &IID_nsIIOService
, (void**)&nsio
);
3549 if(NS_FAILED(nsres
)) {
3550 ERR("Couldn not create nsIOService instance %08x\n", nsres
);
3551 nsIFactory_Release(old_factory
);
3555 nsres
= nsIIOService_QueryInterface(nsio
, &IID_nsINetUtil
, (void**)&net_util
);
3556 if(NS_FAILED(nsres
)) {
3557 WARN("Could not get nsINetUtil interface: %08x\n", nsres
);
3558 nsIIOService_Release(nsio
);
3562 nsres
= nsIComponentRegistrar_UnregisterFactory(registrar
, &NS_IOSERVICE_CID
, old_factory
);
3563 nsIFactory_Release(old_factory
);
3564 if(NS_FAILED(nsres
))
3565 ERR("UnregisterFactory failed: %08x\n", nsres
);
3567 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_IOSERVICE_CID
,
3568 NS_IOSERVICE_CLASSNAME
, NS_IOSERVICE_CONTRACTID
, &nsIOServiceFactory
);
3569 if(NS_FAILED(nsres
))
3570 ERR("RegisterFactory failed: %08x\n", nsres
);
3573 void release_nsio(void)
3576 nsINetUtil_Release(net_util
);
3581 nsIIOService_Release(nsio
);