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"};
57 const nsIURLVtbl
*lpIURLVtbl
;
63 NSContainer
*container
;
64 windowref_t
*window_ref
;
65 nsChannelBSC
*channel_bsc
;
71 #define NSURI(x) ((nsIURI*) &(x)->lpIURLVtbl)
72 #define NSURL(x) ((nsIURL*) &(x)->lpIURLVtbl)
74 static nsresult
create_uri(nsIURI
*,HTMLWindow
*,NSContainer
*,nsWineURI
**);
76 static const char *debugstr_nsacstr(const nsACString
*nsstr
)
80 nsACString_GetData(nsstr
, &data
);
81 return debugstr_a(data
);
84 HRESULT
nsuri_to_url(LPCWSTR nsuri
, BOOL ret_empty
, BSTR
*ret
)
86 const WCHAR
*ptr
= nsuri
;
88 static const WCHAR wine_prefixW
[] = {'w','i','n','e',':'};
90 if(!strncmpW(nsuri
, wine_prefixW
, sizeof(wine_prefixW
)/sizeof(WCHAR
)))
91 ptr
+= sizeof(wine_prefixW
)/sizeof(WCHAR
);
93 if(*ptr
|| ret_empty
) {
94 *ret
= SysAllocString(ptr
);
101 TRACE("%s -> %s\n", debugstr_w(nsuri
), debugstr_w(*ret
));
105 static BOOL
exec_shldocvw_67(HTMLDocumentObj
*doc
, LPCWSTR url
)
107 IOleCommandTarget
*cmdtrg
= NULL
;
110 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
111 if(SUCCEEDED(hres
)) {
112 VARIANT varUrl
, varRes
;
114 V_VT(&varUrl
) = VT_BSTR
;
115 V_BSTR(&varUrl
) = SysAllocString(url
);
116 V_VT(&varRes
) = VT_BOOL
;
118 hres
= IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 67, 0, &varUrl
, &varRes
);
120 IOleCommandTarget_Release(cmdtrg
);
121 SysFreeString(V_BSTR(&varUrl
));
123 if(SUCCEEDED(hres
) && !V_BOOL(&varRes
)) {
124 TRACE("got VARIANT_FALSE, do not load\n");
132 static BOOL
before_async_open(nsChannel
*channel
, NSContainer
*container
)
134 HTMLDocumentObj
*doc
= container
->doc
;
140 NSContainer
*container_iter
= container
;
142 hlnf
= HLNF_OPENINNEWWINDOW
;
143 while(!container_iter
->doc
)
144 container_iter
= container_iter
->parent
;
145 doc
= container_iter
->doc
;
151 if(!hlnf
&& !exec_shldocvw_67(doc
, channel
->uri
->wine_url
))
154 hres
= hlink_frame_navigate(&doc
->basedoc
, channel
->uri
->wine_url
, channel
->post_data_stream
, hlnf
, &cancel
);
155 return FAILED(hres
) || cancel
;
158 HRESULT
load_nsuri(HTMLWindow
*window
, nsWineURI
*uri
, nsChannelBSC
*channelbsc
, DWORD flags
)
160 nsIWebNavigation
*web_navigation
;
161 nsIDocShell
*doc_shell
;
162 HTMLDocumentNode
*doc
;
165 nsres
= get_nsinterface((nsISupports
*)window
->nswindow
, &IID_nsIWebNavigation
, (void**)&web_navigation
);
166 if(NS_FAILED(nsres
)) {
167 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
171 nsres
= nsIWebNavigation_QueryInterface(web_navigation
, &IID_nsIDocShell
, (void**)&doc_shell
);
172 nsIWebNavigation_Release(web_navigation
);
173 if(NS_FAILED(nsres
)) {
174 ERR("Could not get nsIDocShell: %08x\n", nsres
);
178 uri
->channel_bsc
= channelbsc
;
180 doc
->skip_mutation_notif
= TRUE
;
181 nsres
= nsIDocShell_LoadURI(doc_shell
, NSURI(uri
), NULL
, flags
, FALSE
);
182 if(doc
== window
->doc
)
183 doc
->skip_mutation_notif
= FALSE
;
184 uri
->channel_bsc
= NULL
;
185 nsIDocShell_Release(doc_shell
);
186 if(NS_FAILED(nsres
)) {
187 WARN("LoadURI failed: %08x\n", nsres
);
194 static BOOL
translate_url(HTMLDocumentObj
*doc
, nsWineURI
*uri
)
196 OLECHAR
*new_url
= NULL
, *url
;
203 url
= heap_strdupW(uri
->wine_url
);
204 hres
= IDocHostUIHandler_TranslateUrl(doc
->hostui
, 0, url
, &new_url
);
205 if(hres
== S_OK
&& new_url
) {
206 if(strcmpW(url
, new_url
)) {
207 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url
), debugstr_w(new_url
));
210 CoTaskMemFree(new_url
);
217 nsresult
on_start_uri_open(NSContainer
*nscontainer
, nsIURI
*uri
, PRBool
*_retval
)
224 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
225 if(NS_FAILED(nsres
)) {
226 WARN("Could not get nsWineURI: %08x\n", nsres
);
227 return NS_ERROR_NOT_IMPLEMENTED
;
230 if(!wine_uri
->is_doc_uri
) {
231 wine_uri
->is_doc_uri
= TRUE
;
233 if(!wine_uri
->container
) {
234 nsIWebBrowserChrome_AddRef(NSWBCHROME(nscontainer
));
235 wine_uri
->container
= nscontainer
;
239 *_retval
= translate_url(nscontainer
->doc
, wine_uri
);
242 nsIURI_Release(NSURI(wine_uri
));
246 HRESULT
set_wine_url(nsWineURI
*This
, LPCWSTR url
)
248 static const WCHAR wszFtp
[] = {'f','t','p',':'};
249 static const WCHAR wszHttp
[] = {'h','t','t','p',':'};
250 static const WCHAR wszHttps
[] = {'h','t','t','p','s',':'};
252 TRACE("(%p)->(%s)\n", This
, debugstr_w(url
));
257 new_url
= heap_strdupW(url
);
259 return E_OUTOFMEMORY
;
260 heap_free(This
->wine_url
);
261 This
->wine_url
= new_url
;
264 /* FIXME: Always use wine url */
266 strncmpW(url
, wszFtp
, sizeof(wszFtp
)/sizeof(WCHAR
))
267 && strncmpW(url
, wszHttp
, sizeof(wszHttp
)/sizeof(WCHAR
))
268 && strncmpW(url
, wszHttps
, sizeof(wszHttps
)/sizeof(WCHAR
));
270 This
->use_wine_url
= TRUE
;
273 heap_free(This
->wine_url
);
274 This
->wine_url
= NULL
;
275 This
->use_wine_url
= FALSE
;
281 static void set_uri_nscontainer(nsWineURI
*This
, NSContainer
*nscontainer
)
283 if(This
->container
) {
284 if(This
->container
== nscontainer
)
286 TRACE("Changing %p -> %p\n", This
->container
, nscontainer
);
287 nsIWebBrowserChrome_Release(NSWBCHROME(This
->container
));
291 nsIWebBrowserChrome_AddRef(NSWBCHROME(nscontainer
));
292 This
->container
= nscontainer
;
295 static void set_uri_window(nsWineURI
*This
, HTMLWindow
*window
)
297 if(This
->window_ref
) {
298 if(This
->window_ref
->window
== window
)
300 TRACE("Changing %p -> %p\n", This
->window_ref
->window
, window
);
301 windowref_release(This
->window_ref
);
305 windowref_addref(window
->window_ref
);
306 This
->window_ref
= window
->window_ref
;
309 set_uri_nscontainer(This
, window
->doc_obj
->nscontainer
);
311 This
->window_ref
= NULL
;
315 static inline BOOL
is_http_channel(nsChannel
*This
)
317 return This
->url_scheme
== URL_SCHEME_HTTP
|| This
->url_scheme
== URL_SCHEME_HTTPS
;
320 static http_header_t
*find_http_header(struct list
*headers
, const WCHAR
*name
, int len
)
324 LIST_FOR_EACH_ENTRY(iter
, headers
, http_header_t
, entry
) {
325 if(!strcmpiW(iter
->header
, name
))
332 static nsresult
get_channel_http_header(struct list
*headers
, const nsACString
*header_name_str
,
335 const char *header_namea
;
336 http_header_t
*header
;
340 nsACString_GetData(header_name_str
, &header_namea
);
341 header_name
= heap_strdupAtoW(header_namea
);
343 return NS_ERROR_UNEXPECTED
;
345 header
= find_http_header(headers
, header_name
, strlenW(header_name
));
346 heap_free(header_name
);
348 return NS_ERROR_NOT_AVAILABLE
;
350 data
= heap_strdupWtoA(header
->data
);
352 return NS_ERROR_UNEXPECTED
;
354 nsACString_SetData(_retval
, data
);
359 HRESULT
set_http_header(struct list
*headers
, const WCHAR
*name
, int name_len
,
360 const WCHAR
*value
, int value_len
)
362 http_header_t
*header
;
364 TRACE("%s: %s\n", debugstr_wn(name
, name_len
), debugstr_wn(value
, value_len
));
366 header
= find_http_header(headers
, name
, name_len
);
370 new_data
= heap_strndupW(value
, value_len
);
372 return E_OUTOFMEMORY
;
374 heap_free(header
->data
);
375 header
->data
= new_data
;
377 header
= heap_alloc(sizeof(http_header_t
));
379 return E_OUTOFMEMORY
;
381 header
->header
= heap_strndupW(name
, name_len
);
382 header
->data
= heap_strndupW(value
, value_len
);
383 if(!header
->header
|| !header
->data
) {
384 heap_free(header
->header
);
385 heap_free(header
->data
);
387 return E_OUTOFMEMORY
;
390 list_add_tail(headers
, &header
->entry
);
396 static nsresult
set_channel_http_header(struct list
*headers
, const nsACString
*name_str
,
397 const nsACString
*value_str
)
399 const char *namea
, *valuea
;
403 nsACString_GetData(name_str
, &namea
);
404 name
= heap_strdupAtoW(namea
);
406 return NS_ERROR_UNEXPECTED
;
408 nsACString_GetData(value_str
, &valuea
);
409 value
= heap_strdupAtoW(valuea
);
412 return NS_ERROR_UNEXPECTED
;
415 hres
= set_http_header(headers
, name
, strlenW(name
), value
, strlenW(value
));
419 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_UNEXPECTED
;
422 static void free_http_headers(struct list
*list
)
424 http_header_t
*iter
, *iter_next
;
426 LIST_FOR_EACH_ENTRY_SAFE(iter
, iter_next
, list
, http_header_t
, entry
) {
427 list_remove(&iter
->entry
);
428 heap_free(iter
->header
);
429 heap_free(iter
->data
);
434 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
436 static nsresult NSAPI
nsChannel_QueryInterface(nsIHttpChannel
*iface
, nsIIDRef riid
, void **result
)
438 nsChannel
*This
= NSCHANNEL_THIS(iface
);
440 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
441 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
442 *result
= NSCHANNEL(This
);
443 }else if(IsEqualGUID(&IID_nsIRequest
, riid
)) {
444 TRACE("(%p)->(IID_nsIRequest %p)\n", This
, result
);
445 *result
= NSCHANNEL(This
);
446 }else if(IsEqualGUID(&IID_nsIChannel
, riid
)) {
447 TRACE("(%p)->(IID_nsIChannel %p)\n", This
, result
);
448 *result
= NSCHANNEL(This
);
449 }else if(IsEqualGUID(&IID_nsIHttpChannel
, riid
)) {
450 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This
, result
);
451 *result
= is_http_channel(This
) ? NSHTTPCHANNEL(This
) : NULL
;
452 }else if(IsEqualGUID(&IID_nsIUploadChannel
, riid
)) {
453 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This
, result
);
454 *result
= NSUPCHANNEL(This
);
455 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal
, riid
)) {
456 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This
, result
);
457 *result
= is_http_channel(This
) ? NSHTTPINTERNAL(This
) : NULL
;
459 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
464 nsIChannel_AddRef(NSCHANNEL(This
));
468 return NS_NOINTERFACE
;
471 static nsrefcnt NSAPI
nsChannel_AddRef(nsIHttpChannel
*iface
)
473 nsChannel
*This
= NSCHANNEL_THIS(iface
);
474 nsrefcnt ref
= InterlockedIncrement(&This
->ref
);
476 TRACE("(%p) ref=%d\n", This
, ref
);
481 static nsrefcnt NSAPI
nsChannel_Release(nsIHttpChannel
*iface
)
483 nsChannel
*This
= NSCHANNEL_THIS(iface
);
484 LONG ref
= InterlockedDecrement(&This
->ref
);
487 nsIURI_Release(NSURI(This
->uri
));
489 nsISupports_Release(This
->owner
);
490 if(This
->post_data_stream
)
491 nsIInputStream_Release(This
->post_data_stream
);
493 nsILoadGroup_Release(This
->load_group
);
494 if(This
->notif_callback
)
495 nsIInterfaceRequestor_Release(This
->notif_callback
);
496 if(This
->original_uri
)
497 nsIURI_Release(This
->original_uri
);
499 nsIURI_Release(This
->referrer
);
501 free_http_headers(&This
->response_headers
);
502 free_http_headers(&This
->request_headers
);
504 heap_free(This
->content_type
);
505 heap_free(This
->charset
);
512 static nsresult NSAPI
nsChannel_GetName(nsIHttpChannel
*iface
, nsACString
*aName
)
514 nsChannel
*This
= NSCHANNEL_THIS(iface
);
516 TRACE("(%p)->(%p)\n", This
, aName
);
518 return nsIURI_GetSpec(NSURI(This
->uri
), aName
);
521 static nsresult NSAPI
nsChannel_IsPending(nsIHttpChannel
*iface
, PRBool
*_retval
)
523 nsChannel
*This
= NSCHANNEL_THIS(iface
);
525 FIXME("(%p)->(%p)\n", This
, _retval
);
527 return NS_ERROR_NOT_IMPLEMENTED
;
530 static nsresult NSAPI
nsChannel_GetStatus(nsIHttpChannel
*iface
, nsresult
*aStatus
)
532 nsChannel
*This
= NSCHANNEL_THIS(iface
);
534 WARN("(%p)->(%p) returning NS_OK\n", This
, aStatus
);
536 return *aStatus
= NS_OK
;
539 static nsresult NSAPI
nsChannel_Cancel(nsIHttpChannel
*iface
, nsresult aStatus
)
541 nsChannel
*This
= NSCHANNEL_THIS(iface
);
543 FIXME("(%p)->(%08x)\n", This
, aStatus
);
545 return NS_ERROR_NOT_IMPLEMENTED
;
548 static nsresult NSAPI
nsChannel_Suspend(nsIHttpChannel
*iface
)
550 nsChannel
*This
= NSCHANNEL_THIS(iface
);
552 FIXME("(%p)\n", This
);
554 return NS_ERROR_NOT_IMPLEMENTED
;
557 static nsresult NSAPI
nsChannel_Resume(nsIHttpChannel
*iface
)
559 nsChannel
*This
= NSCHANNEL_THIS(iface
);
561 FIXME("(%p)\n", This
);
563 return NS_ERROR_NOT_IMPLEMENTED
;
566 static nsresult NSAPI
nsChannel_GetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
**aLoadGroup
)
568 nsChannel
*This
= NSCHANNEL_THIS(iface
);
570 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
573 nsILoadGroup_AddRef(This
->load_group
);
575 *aLoadGroup
= This
->load_group
;
579 static nsresult NSAPI
nsChannel_SetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
*aLoadGroup
)
581 nsChannel
*This
= NSCHANNEL_THIS(iface
);
583 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
586 nsILoadGroup_Release(This
->load_group
);
588 nsILoadGroup_AddRef(aLoadGroup
);
589 This
->load_group
= aLoadGroup
;
594 static nsresult NSAPI
nsChannel_GetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags
*aLoadFlags
)
596 nsChannel
*This
= NSCHANNEL_THIS(iface
);
598 TRACE("(%p)->(%p)\n", This
, aLoadFlags
);
600 *aLoadFlags
= This
->load_flags
;
604 static nsresult NSAPI
nsChannel_SetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags aLoadFlags
)
606 nsChannel
*This
= NSCHANNEL_THIS(iface
);
608 TRACE("(%p)->(%08x)\n", This
, aLoadFlags
);
610 This
->load_flags
= aLoadFlags
;
614 static nsresult NSAPI
nsChannel_GetOriginalURI(nsIHttpChannel
*iface
, nsIURI
**aOriginalURI
)
616 nsChannel
*This
= NSCHANNEL_THIS(iface
);
618 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
620 if(This
->original_uri
)
621 nsIURI_AddRef(This
->original_uri
);
623 *aOriginalURI
= This
->original_uri
;
627 static nsresult NSAPI
nsChannel_SetOriginalURI(nsIHttpChannel
*iface
, nsIURI
*aOriginalURI
)
629 nsChannel
*This
= NSCHANNEL_THIS(iface
);
631 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
633 if(This
->original_uri
)
634 nsIURI_Release(This
->original_uri
);
636 nsIURI_AddRef(aOriginalURI
);
637 This
->original_uri
= aOriginalURI
;
641 static nsresult NSAPI
nsChannel_GetURI(nsIHttpChannel
*iface
, nsIURI
**aURI
)
643 nsChannel
*This
= NSCHANNEL_THIS(iface
);
645 TRACE("(%p)->(%p)\n", This
, aURI
);
647 nsIURI_AddRef(NSURI(This
->uri
));
648 *aURI
= (nsIURI
*)This
->uri
;
653 static nsresult NSAPI
nsChannel_GetOwner(nsIHttpChannel
*iface
, nsISupports
**aOwner
)
655 nsChannel
*This
= NSCHANNEL_THIS(iface
);
657 TRACE("(%p)->(%p)\n", This
, aOwner
);
660 nsISupports_AddRef(This
->owner
);
661 *aOwner
= This
->owner
;
666 static nsresult NSAPI
nsChannel_SetOwner(nsIHttpChannel
*iface
, nsISupports
*aOwner
)
668 nsChannel
*This
= NSCHANNEL_THIS(iface
);
670 TRACE("(%p)->(%p)\n", This
, aOwner
);
673 nsISupports_AddRef(aOwner
);
675 nsISupports_Release(This
->owner
);
676 This
->owner
= aOwner
;
681 static nsresult NSAPI
nsChannel_GetNotificationCallbacks(nsIHttpChannel
*iface
,
682 nsIInterfaceRequestor
**aNotificationCallbacks
)
684 nsChannel
*This
= NSCHANNEL_THIS(iface
);
686 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
688 if(This
->notif_callback
)
689 nsIInterfaceRequestor_AddRef(This
->notif_callback
);
690 *aNotificationCallbacks
= This
->notif_callback
;
695 static nsresult NSAPI
nsChannel_SetNotificationCallbacks(nsIHttpChannel
*iface
,
696 nsIInterfaceRequestor
*aNotificationCallbacks
)
698 nsChannel
*This
= NSCHANNEL_THIS(iface
);
700 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
702 if(This
->notif_callback
)
703 nsIInterfaceRequestor_Release(This
->notif_callback
);
704 if(aNotificationCallbacks
)
705 nsIInterfaceRequestor_AddRef(aNotificationCallbacks
);
707 This
->notif_callback
= aNotificationCallbacks
;
712 static nsresult NSAPI
nsChannel_GetSecurityInfo(nsIHttpChannel
*iface
, nsISupports
**aSecurityInfo
)
714 nsChannel
*This
= NSCHANNEL_THIS(iface
);
716 TRACE("(%p)->(%p)\n", This
, aSecurityInfo
);
718 return NS_ERROR_NOT_IMPLEMENTED
;
721 static nsresult NSAPI
nsChannel_GetContentType(nsIHttpChannel
*iface
, nsACString
*aContentType
)
723 nsChannel
*This
= NSCHANNEL_THIS(iface
);
725 TRACE("(%p)->(%p)\n", This
, aContentType
);
727 if(This
->content_type
) {
728 nsACString_SetData(aContentType
, This
->content_type
);
732 WARN("unknown type\n");
733 return NS_ERROR_FAILURE
;
736 static nsresult NSAPI
nsChannel_SetContentType(nsIHttpChannel
*iface
,
737 const nsACString
*aContentType
)
739 nsChannel
*This
= NSCHANNEL_THIS(iface
);
740 const char *content_type
;
742 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentType
));
744 nsACString_GetData(aContentType
, &content_type
);
745 heap_free(This
->content_type
);
746 This
->content_type
= heap_strdupA(content_type
);
751 static nsresult NSAPI
nsChannel_GetContentCharset(nsIHttpChannel
*iface
,
752 nsACString
*aContentCharset
)
754 nsChannel
*This
= NSCHANNEL_THIS(iface
);
756 TRACE("(%p)->(%p)\n", This
, aContentCharset
);
759 nsACString_SetData(aContentCharset
, This
->charset
);
763 nsACString_SetData(aContentCharset
, "");
767 static nsresult NSAPI
nsChannel_SetContentCharset(nsIHttpChannel
*iface
,
768 const nsACString
*aContentCharset
)
770 nsChannel
*This
= NSCHANNEL_THIS(iface
);
772 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentCharset
));
774 return NS_ERROR_NOT_IMPLEMENTED
;
777 static nsresult NSAPI
nsChannel_GetContentLength(nsIHttpChannel
*iface
, PRInt32
*aContentLength
)
779 nsChannel
*This
= NSCHANNEL_THIS(iface
);
781 FIXME("(%p)->(%p)\n", This
, aContentLength
);
783 return NS_ERROR_NOT_IMPLEMENTED
;
786 static nsresult NSAPI
nsChannel_SetContentLength(nsIHttpChannel
*iface
, PRInt32 aContentLength
)
788 nsChannel
*This
= NSCHANNEL_THIS(iface
);
790 FIXME("(%p)->(%d)\n", This
, aContentLength
);
792 return NS_ERROR_NOT_IMPLEMENTED
;
795 static nsresult NSAPI
nsChannel_Open(nsIHttpChannel
*iface
, nsIInputStream
**_retval
)
797 nsChannel
*This
= NSCHANNEL_THIS(iface
);
799 FIXME("(%p)->(%p)\n", This
, _retval
);
801 return NS_ERROR_NOT_IMPLEMENTED
;
804 static HRESULT
create_mon_for_nschannel(nsChannel
*channel
, IMoniker
**mon
)
810 if(!channel
->original_uri
) {
811 ERR("original_uri == NULL\n");
815 nsres
= nsIURI_QueryInterface(channel
->original_uri
, &IID_nsWineURI
, (void**)&wine_uri
);
816 if(NS_FAILED(nsres
)) {
817 ERR("Could not get nsWineURI: %08x\n", nsres
);
821 if(wine_uri
->wine_url
) {
822 hres
= CreateURLMoniker(NULL
, wine_uri
->wine_url
, mon
);
824 WARN("CreateURLMoniker failed: %08x\n", hres
);
826 TRACE("wine_url == NULL\n");
830 nsIURI_Release(NSURI(wine_uri
));
835 static HTMLWindow
*get_window_from_load_group(nsChannel
*This
)
844 nsres
= nsILoadGroup_GetDefaultLoadRequest(This
->load_group
, &req
);
845 if(NS_FAILED(nsres
)) {
846 ERR("GetDefaultLoadRequest failed: %08x\n", nsres
);
853 nsres
= nsIRequest_QueryInterface(req
, &IID_nsIChannel
, (void**)&channel
);
854 nsIRequest_Release(req
);
855 if(NS_FAILED(nsres
)) {
856 WARN("Could not get nsIChannel interface: %08x\n", nsres
);
860 nsres
= nsIChannel_GetURI(channel
, &uri
);
861 nsIChannel_Release(channel
);
862 if(NS_FAILED(nsres
)) {
863 ERR("GetURI failed: %08x\n", nsres
);
867 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
869 if(NS_FAILED(nsres
)) {
870 TRACE("Could not get nsWineURI: %08x\n", nsres
);
874 window
= wine_uri
->window_ref
? wine_uri
->window_ref
->window
: NULL
;
876 IHTMLWindow2_AddRef(HTMLWINDOW2(window
));
877 nsIURI_Release(NSURI(wine_uri
));
882 static HTMLWindow
*get_channel_window(nsChannel
*This
)
884 nsIRequestObserver
*req_observer
;
885 nsIWebProgress
*web_progress
;
886 nsIDOMWindow
*nswindow
;
890 if(!This
->load_group
) {
891 ERR("NULL load_group\n");
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
);
908 nsres
= nsIWebProgress_GetDOMWindow(web_progress
, &nswindow
);
909 nsIWebProgress_Release(web_progress
);
910 if(NS_FAILED(nsres
) || !nswindow
) {
911 ERR("GetDOMWindow failed: %08x\n", nsres
);
915 window
= nswindow_to_window(nswindow
);
916 nsIDOMWindow_Release(nswindow
);
919 IHTMLWindow2_AddRef(HTMLWINDOW2(window
));
921 FIXME("NULL window for %p\n", nswindow
);
927 HTMLDocumentNode
*doc
;
928 nsChannelBSC
*bscallback
;
929 } start_binding_task_t
;
931 static void start_binding_proc(task_t
*_task
)
933 start_binding_task_t
*task
= (start_binding_task_t
*)_task
;
935 start_binding(NULL
, task
->doc
, (BSCallback
*)task
->bscallback
, NULL
);
937 IUnknown_Release((IUnknown
*)task
->bscallback
);
940 static nsresult
async_open(nsChannel
*This
, HTMLWindow
*window
, BOOL is_doc_channel
, nsIStreamListener
*listener
,
941 nsISupports
*context
)
943 nsChannelBSC
*bscallback
;
944 IMoniker
*mon
= NULL
;
947 hres
= create_mon_for_nschannel(This
, &mon
);
949 return NS_ERROR_UNEXPECTED
;
952 set_current_mon(window
, mon
);
954 hres
= create_channelbsc(mon
, NULL
, NULL
, 0, &bscallback
);
955 IMoniker_Release(mon
);
957 return NS_ERROR_UNEXPECTED
;
959 channelbsc_set_channel(bscallback
, This
, listener
, context
);
962 set_window_bscallback(window
, bscallback
);
963 async_start_doc_binding(window
, bscallback
);
964 IUnknown_Release((IUnknown
*)bscallback
);
966 start_binding_task_t
*task
= heap_alloc(sizeof(start_binding_task_t
));
968 task
->doc
= window
->doc
;
969 task
->bscallback
= bscallback
;
970 push_task(&task
->header
, start_binding_proc
, window
->doc
->basedoc
.task_magic
);
976 static nsresult NSAPI
nsChannel_AsyncOpen(nsIHttpChannel
*iface
, nsIStreamListener
*aListener
,
977 nsISupports
*aContext
)
979 nsChannel
*This
= NSCHANNEL_THIS(iface
);
980 HTMLWindow
*window
= NULL
;
982 nsresult nsres
= NS_OK
;
984 TRACE("(%p)->(%p %p) opening %s\n", This
, aListener
, aContext
, debugstr_w(This
->uri
->wine_url
));
986 if(This
->uri
->is_doc_uri
) {
987 window
= get_channel_window(This
);
989 set_uri_window(This
->uri
, window
);
990 }else if(This
->uri
->container
) {
993 /* nscontainer->doc should be NULL which means navigation to a new window */
994 if(This
->uri
->container
->doc
)
995 FIXME("nscontainer->doc = %p\n", This
->uri
->container
->doc
);
997 b
= before_async_open(This
, This
->uri
->container
);
999 FIXME("Navigation not cancelled\n");
1000 return NS_ERROR_UNEXPECTED
;
1005 if(This
->uri
->window_ref
&& This
->uri
->window_ref
->window
) {
1006 window
= This
->uri
->window_ref
->window
;
1007 IHTMLWindow2_AddRef(HTMLWINDOW2(window
));
1008 }else if(This
->load_group
) {
1009 window
= get_window_from_load_group(This
);
1011 set_uri_window(This
->uri
, window
);
1016 ERR("window = NULL\n");
1017 return NS_ERROR_UNEXPECTED
;
1020 if(This
->uri
->is_doc_uri
&& window
== window
->doc_obj
->basedoc
.window
) {
1021 if(This
->uri
->channel_bsc
) {
1022 channelbsc_set_channel(This
->uri
->channel_bsc
, This
, aListener
, aContext
);
1024 if(window
->doc_obj
->mime
) {
1025 heap_free(This
->content_type
);
1026 This
->content_type
= heap_strdupWtoA(window
->doc_obj
->mime
);
1031 open
= !before_async_open(This
, window
->doc_obj
->nscontainer
);
1033 TRACE("canceled\n");
1034 nsres
= NS_ERROR_UNEXPECTED
;
1040 nsres
= async_open(This
, window
, This
->uri
->is_doc_uri
, aListener
, aContext
);
1042 if(NS_SUCCEEDED(nsres
) && This
->load_group
) {
1043 nsres
= nsILoadGroup_AddRequest(This
->load_group
, (nsIRequest
*)NSCHANNEL(This
), aContext
);
1044 if(NS_FAILED(nsres
))
1045 ERR("AddRequest failed: %08x\n", nsres
);
1048 IHTMLWindow2_Release(HTMLWINDOW2(window
));
1052 static nsresult NSAPI
nsChannel_GetRequestMethod(nsIHttpChannel
*iface
, nsACString
*aRequestMethod
)
1054 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1056 TRACE("(%p)->(%p)\n", This
, aRequestMethod
);
1058 nsACString_SetData(aRequestMethod
, request_method_strings
[This
->request_method
]);
1062 static nsresult NSAPI
nsChannel_SetRequestMethod(nsIHttpChannel
*iface
,
1063 const nsACString
*aRequestMethod
)
1065 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1069 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRequestMethod
));
1071 nsACString_GetData(aRequestMethod
, &method
);
1072 for(i
=0; i
< sizeof(request_method_strings
)/sizeof(*request_method_strings
); i
++) {
1073 if(!strcasecmp(method
, request_method_strings
[i
])) {
1074 This
->request_method
= i
;
1079 ERR("Invalid method %s\n", debugstr_a(method
));
1080 return NS_ERROR_UNEXPECTED
;
1083 static nsresult NSAPI
nsChannel_GetReferrer(nsIHttpChannel
*iface
, nsIURI
**aReferrer
)
1085 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1087 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1090 nsIURI_AddRef(This
->referrer
);
1091 *aReferrer
= This
->referrer
;
1095 static nsresult NSAPI
nsChannel_SetReferrer(nsIHttpChannel
*iface
, nsIURI
*aReferrer
)
1097 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1099 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1102 nsIURI_AddRef(aReferrer
);
1104 nsIURI_Release(This
->referrer
);
1105 This
->referrer
= aReferrer
;
1109 static nsresult NSAPI
nsChannel_GetRequestHeader(nsIHttpChannel
*iface
,
1110 const nsACString
*aHeader
, nsACString
*_retval
)
1112 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1114 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aHeader
), _retval
);
1116 return get_channel_http_header(&This
->request_headers
, aHeader
, _retval
);
1119 static nsresult NSAPI
nsChannel_SetRequestHeader(nsIHttpChannel
*iface
,
1120 const nsACString
*aHeader
, const nsACString
*aValue
, PRBool aMerge
)
1122 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1124 TRACE("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(aHeader
), debugstr_nsacstr(aValue
), aMerge
);
1127 FIXME("aMerge not supported\n");
1129 return set_channel_http_header(&This
->request_headers
, aHeader
, aValue
);
1132 static nsresult NSAPI
nsChannel_VisitRequestHeaders(nsIHttpChannel
*iface
,
1133 nsIHttpHeaderVisitor
*aVisitor
)
1135 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1137 FIXME("(%p)->(%p)\n", This
, aVisitor
);
1139 return NS_ERROR_NOT_IMPLEMENTED
;
1142 static nsresult NSAPI
nsChannel_GetAllowPipelining(nsIHttpChannel
*iface
, PRBool
*aAllowPipelining
)
1144 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1146 FIXME("(%p)->(%p)\n", This
, aAllowPipelining
);
1148 return NS_ERROR_NOT_IMPLEMENTED
;
1151 static nsresult NSAPI
nsChannel_SetAllowPipelining(nsIHttpChannel
*iface
, PRBool aAllowPipelining
)
1153 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1155 FIXME("(%p)->(%x)\n", This
, aAllowPipelining
);
1157 return NS_ERROR_NOT_IMPLEMENTED
;
1160 static nsresult NSAPI
nsChannel_GetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32
*aRedirectionLimit
)
1162 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1164 FIXME("(%p)->(%p)\n", This
, aRedirectionLimit
);
1166 return NS_ERROR_NOT_IMPLEMENTED
;
1169 static nsresult NSAPI
nsChannel_SetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32 aRedirectionLimit
)
1171 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1173 FIXME("(%p)->(%u)\n", This
, aRedirectionLimit
);
1175 return NS_ERROR_NOT_IMPLEMENTED
;
1178 static nsresult NSAPI
nsChannel_GetResponseStatus(nsIHttpChannel
*iface
, PRUint32
*aResponseStatus
)
1180 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1182 TRACE("(%p)->(%p)\n", This
, aResponseStatus
);
1184 if(This
->response_status
) {
1185 *aResponseStatus
= This
->response_status
;
1189 WARN("No response status\n");
1190 return NS_ERROR_UNEXPECTED
;
1193 static nsresult NSAPI
nsChannel_GetResponseStatusText(nsIHttpChannel
*iface
,
1194 nsACString
*aResponseStatusText
)
1196 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1198 FIXME("(%p)->(%p)\n", This
, aResponseStatusText
);
1200 return NS_ERROR_NOT_IMPLEMENTED
;
1203 static nsresult NSAPI
nsChannel_GetRequestSucceeded(nsIHttpChannel
*iface
,
1204 PRBool
*aRequestSucceeded
)
1206 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1208 TRACE("(%p)->(%p)\n", This
, aRequestSucceeded
);
1210 if(!This
->response_status
)
1211 return NS_ERROR_NOT_AVAILABLE
;
1213 *aRequestSucceeded
= This
->response_status
/100 == 2;
1218 static nsresult NSAPI
nsChannel_GetResponseHeader(nsIHttpChannel
*iface
,
1219 const nsACString
*header
, nsACString
*_retval
)
1221 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1223 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(header
), _retval
);
1225 return get_channel_http_header(&This
->response_headers
, header
, _retval
);
1228 static nsresult NSAPI
nsChannel_SetResponseHeader(nsIHttpChannel
*iface
,
1229 const nsACString
*header
, const nsACString
*value
, PRBool merge
)
1231 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1233 FIXME("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(header
), debugstr_nsacstr(value
), merge
);
1235 return NS_ERROR_NOT_IMPLEMENTED
;
1238 static nsresult NSAPI
nsChannel_VisitResponseHeaders(nsIHttpChannel
*iface
,
1239 nsIHttpHeaderVisitor
*aVisitor
)
1241 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1243 FIXME("(%p)->(%p)\n", This
, aVisitor
);
1245 return NS_ERROR_NOT_IMPLEMENTED
;
1248 static nsresult NSAPI
nsChannel_IsNoStoreResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1250 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1252 FIXME("(%p)->(%p)\n", This
, _retval
);
1254 return NS_ERROR_NOT_IMPLEMENTED
;
1257 static nsresult NSAPI
nsChannel_IsNoCacheResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1259 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1261 FIXME("(%p)->(%p)\n", This
, _retval
);
1263 return NS_ERROR_NOT_IMPLEMENTED
;
1266 #undef NSCHANNEL_THIS
1268 static const nsIHttpChannelVtbl nsChannelVtbl
= {
1269 nsChannel_QueryInterface
,
1273 nsChannel_IsPending
,
1274 nsChannel_GetStatus
,
1278 nsChannel_GetLoadGroup
,
1279 nsChannel_SetLoadGroup
,
1280 nsChannel_GetLoadFlags
,
1281 nsChannel_SetLoadFlags
,
1282 nsChannel_GetOriginalURI
,
1283 nsChannel_SetOriginalURI
,
1287 nsChannel_GetNotificationCallbacks
,
1288 nsChannel_SetNotificationCallbacks
,
1289 nsChannel_GetSecurityInfo
,
1290 nsChannel_GetContentType
,
1291 nsChannel_SetContentType
,
1292 nsChannel_GetContentCharset
,
1293 nsChannel_SetContentCharset
,
1294 nsChannel_GetContentLength
,
1295 nsChannel_SetContentLength
,
1297 nsChannel_AsyncOpen
,
1298 nsChannel_GetRequestMethod
,
1299 nsChannel_SetRequestMethod
,
1300 nsChannel_GetReferrer
,
1301 nsChannel_SetReferrer
,
1302 nsChannel_GetRequestHeader
,
1303 nsChannel_SetRequestHeader
,
1304 nsChannel_VisitRequestHeaders
,
1305 nsChannel_GetAllowPipelining
,
1306 nsChannel_SetAllowPipelining
,
1307 nsChannel_GetRedirectionLimit
,
1308 nsChannel_SetRedirectionLimit
,
1309 nsChannel_GetResponseStatus
,
1310 nsChannel_GetResponseStatusText
,
1311 nsChannel_GetRequestSucceeded
,
1312 nsChannel_GetResponseHeader
,
1313 nsChannel_SetResponseHeader
,
1314 nsChannel_VisitResponseHeaders
,
1315 nsChannel_IsNoStoreResponse
,
1316 nsChannel_IsNoCacheResponse
1319 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1321 static nsresult NSAPI
nsUploadChannel_QueryInterface(nsIUploadChannel
*iface
, nsIIDRef riid
,
1324 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1325 return nsIChannel_QueryInterface(NSCHANNEL(This
), riid
, result
);
1328 static nsrefcnt NSAPI
nsUploadChannel_AddRef(nsIUploadChannel
*iface
)
1330 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1331 return nsIChannel_AddRef(NSCHANNEL(This
));
1334 static nsrefcnt NSAPI
nsUploadChannel_Release(nsIUploadChannel
*iface
)
1336 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1337 return nsIChannel_Release(NSCHANNEL(This
));
1340 static nsresult NSAPI
nsUploadChannel_SetUploadStream(nsIUploadChannel
*iface
,
1341 nsIInputStream
*aStream
, const nsACString
*aContentType
, PRInt32 aContentLength
)
1343 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1344 const char *content_type
;
1346 static const WCHAR content_typeW
[] =
1347 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1349 TRACE("(%p)->(%p %s %d)\n", This
, aStream
, debugstr_nsacstr(aContentType
), aContentLength
);
1351 This
->parse_stream
= TRUE
;
1353 nsACString_GetData(aContentType
, &content_type
);
1357 ct
= heap_strdupAtoW(content_type
);
1359 return NS_ERROR_UNEXPECTED
;
1361 set_http_header(&This
->request_headers
, content_typeW
,
1362 sizeof(content_typeW
)/sizeof(WCHAR
), ct
, strlenW(ct
));
1364 This
->parse_stream
= FALSE
;
1368 if(This
->post_data_stream
)
1369 nsIInputStream_Release(This
->post_data_stream
);
1371 if(aContentLength
!= -1)
1372 FIXME("Unsupported acontentLength = %d\n", aContentLength
);
1374 if(This
->post_data_stream
)
1375 nsIInputStream_Release(This
->post_data_stream
);
1376 This
->post_data_stream
= aStream
;
1378 nsIInputStream_AddRef(aStream
);
1380 This
->request_method
= METHOD_POST
;
1384 static nsresult NSAPI
nsUploadChannel_GetUploadStream(nsIUploadChannel
*iface
,
1385 nsIInputStream
**aUploadStream
)
1387 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1389 TRACE("(%p)->(%p)\n", This
, aUploadStream
);
1391 if(This
->post_data_stream
)
1392 nsIInputStream_AddRef(This
->post_data_stream
);
1394 *aUploadStream
= This
->post_data_stream
;
1398 #undef NSUPCHANNEL_THIS
1400 static const nsIUploadChannelVtbl nsUploadChannelVtbl
= {
1401 nsUploadChannel_QueryInterface
,
1402 nsUploadChannel_AddRef
,
1403 nsUploadChannel_Release
,
1404 nsUploadChannel_SetUploadStream
,
1405 nsUploadChannel_GetUploadStream
1408 #define NSHTTPINTERNAL_THIS(iface) DEFINE_THIS(nsChannel, IHttpChannelInternal, iface)
1410 static nsresult NSAPI
nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal
*iface
, nsIIDRef riid
,
1413 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1414 return nsIChannel_QueryInterface(NSCHANNEL(This
), riid
, result
);
1417 static nsrefcnt NSAPI
nsHttpChannelInternal_AddRef(nsIHttpChannelInternal
*iface
)
1419 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1420 return nsIChannel_AddRef(NSCHANNEL(This
));
1423 static nsrefcnt NSAPI
nsHttpChannelInternal_Release(nsIHttpChannelInternal
*iface
)
1425 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1426 return nsIChannel_Release(NSCHANNEL(This
));
1429 static nsresult NSAPI
nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
**aDocumentURI
)
1431 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1433 FIXME("(%p)->()\n", This
);
1435 return NS_ERROR_NOT_IMPLEMENTED
;
1438 static nsresult NSAPI
nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
*aDocumentURI
)
1440 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1442 FIXME("(%p)->()\n", This
);
1444 return NS_ERROR_NOT_IMPLEMENTED
;
1447 static nsresult NSAPI
nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal
*iface
, PRUint32
*major
, PRUint32
*minor
)
1449 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1451 FIXME("(%p)->()\n", This
);
1453 return NS_ERROR_NOT_IMPLEMENTED
;
1456 static nsresult NSAPI
nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal
*iface
, PRUint32
*major
, PRUint32
*minor
)
1458 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1460 FIXME("(%p)->()\n", This
);
1462 return NS_ERROR_NOT_IMPLEMENTED
;
1465 static nsresult NSAPI
nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal
*iface
, const char *aCookieHeader
)
1467 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1469 FIXME("(%p)->()\n", This
);
1471 return NS_ERROR_NOT_IMPLEMENTED
;
1474 static nsresult NSAPI
nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal
*iface
, const char *aFallbackKey
)
1476 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1478 FIXME("(%p)->()\n", This
);
1480 return NS_ERROR_NOT_IMPLEMENTED
;
1483 static nsresult NSAPI
nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, PRBool
*aForceThirdPartyCookie
)
1485 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1487 FIXME("(%p)->()\n", This
);
1489 return NS_ERROR_NOT_IMPLEMENTED
;
1492 static nsresult NSAPI
nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, PRBool aForceThirdPartyCookie
)
1494 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1496 FIXME("(%p)->()\n", This
);
1498 return NS_ERROR_NOT_IMPLEMENTED
;
1501 static nsresult NSAPI
nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal
*iface
, PRBool
*aCanceled
)
1503 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1505 FIXME("(%p)->(%p)\n", This
, aCanceled
);
1507 return NS_ERROR_NOT_IMPLEMENTED
;
1510 #undef NSHTTPINTERNAL_THIS
1512 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl
= {
1513 nsHttpChannelInternal_QueryInterface
,
1514 nsHttpChannelInternal_AddRef
,
1515 nsHttpChannelInternal_Release
,
1516 nsHttpChannelInternal_GetDocumentURI
,
1517 nsHttpChannelInternal_SetDocumentURI
,
1518 nsHttpChannelInternal_GetRequestVersion
,
1519 nsHttpChannelInternal_GetResponseVersion
,
1520 nsHttpChannelInternal_SetCookie
,
1521 nsHttpChannelInternal_SetupFallbackChannel
,
1522 nsHttpChannelInternal_GetForceAllowThirdPartyCookie
,
1523 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
,
1524 nsHttpChannelInternal_GetCanceled
1527 #define NSURI_THIS(iface) DEFINE_THIS(nsWineURI, IURL, iface)
1529 static nsresult NSAPI
nsURI_QueryInterface(nsIURL
*iface
, nsIIDRef riid
, void **result
)
1531 nsWineURI
*This
= NSURI_THIS(iface
);
1535 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1536 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1537 *result
= NSURI(This
);
1538 }else if(IsEqualGUID(&IID_nsIURI
, riid
)) {
1539 TRACE("(%p)->(IID_nsIURI %p)\n", This
, result
);
1540 *result
= NSURI(This
);
1541 }else if(IsEqualGUID(&IID_nsIURL
, riid
)) {
1542 TRACE("(%p)->(IID_nsIURL %p)\n", This
, result
);
1543 *result
= NSURL(This
);
1544 }else if(IsEqualGUID(&IID_nsWineURI
, riid
)) {
1545 TRACE("(%p)->(IID_nsWineURI %p)\n", This
, result
);
1550 nsIURI_AddRef(NSURI(This
));
1554 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1555 return This
->uri
? nsIURI_QueryInterface(This
->uri
, riid
, result
) : NS_NOINTERFACE
;
1558 static nsrefcnt NSAPI
nsURI_AddRef(nsIURL
*iface
)
1560 nsWineURI
*This
= NSURI_THIS(iface
);
1561 LONG ref
= InterlockedIncrement(&This
->ref
);
1563 TRACE("(%p) ref=%d\n", This
, ref
);
1568 static nsrefcnt NSAPI
nsURI_Release(nsIURL
*iface
)
1570 nsWineURI
*This
= NSURI_THIS(iface
);
1571 LONG ref
= InterlockedDecrement(&This
->ref
);
1573 TRACE("(%p) ref=%d\n", This
, ref
);
1576 if(This
->window_ref
)
1577 windowref_release(This
->window_ref
);
1579 nsIWebBrowserChrome_Release(NSWBCHROME(This
->container
));
1581 nsIURL_Release(This
->nsurl
);
1583 nsIURI_Release(This
->uri
);
1584 heap_free(This
->wine_url
);
1591 static nsresult NSAPI
nsURI_GetSpec(nsIURL
*iface
, nsACString
*aSpec
)
1593 nsWineURI
*This
= NSURI_THIS(iface
);
1595 TRACE("(%p)->(%p)\n", This
, aSpec
);
1597 if(This
->use_wine_url
) {
1598 char speca
[INTERNET_MAX_URL_LENGTH
];
1599 WideCharToMultiByte(CP_ACP
, 0, This
->wine_url
, -1, speca
, sizeof(speca
), NULL
, NULL
);
1600 nsACString_SetData(aSpec
, speca
);
1606 return nsIURI_GetSpec(This
->uri
, aSpec
);
1608 TRACE("returning error\n");
1609 return NS_ERROR_NOT_IMPLEMENTED
;
1613 static nsresult NSAPI
nsURI_SetSpec(nsIURL
*iface
, const nsACString
*aSpec
)
1615 nsWineURI
*This
= NSURI_THIS(iface
);
1617 TRACE("(%p)->(%p)\n", This
, debugstr_nsacstr(aSpec
));
1620 return nsIURI_SetSpec(This
->uri
, aSpec
);
1622 FIXME("default action not implemented\n");
1623 return NS_ERROR_NOT_IMPLEMENTED
;
1626 static nsresult NSAPI
nsURI_GetPrePath(nsIURL
*iface
, nsACString
*aPrePath
)
1628 nsWineURI
*This
= NSURI_THIS(iface
);
1630 TRACE("(%p)->(%p)\n", This
, aPrePath
);
1633 return nsIURI_GetPrePath(This
->uri
, aPrePath
);
1635 FIXME("default action not implemented\n");
1636 return NS_ERROR_NOT_IMPLEMENTED
;
1639 static nsresult NSAPI
nsURI_GetScheme(nsIURL
*iface
, nsACString
*aScheme
)
1641 nsWineURI
*This
= NSURI_THIS(iface
);
1643 TRACE("(%p)->(%p)\n", This
, aScheme
);
1645 if(This
->use_wine_url
) {
1646 char scheme
[INTERNET_MAX_SCHEME_LENGTH
+1];
1650 ptr
= strchrW(This
->wine_url
, ':');
1652 nsACString_SetData(aScheme
, "wine");
1656 len
= WideCharToMultiByte(CP_ACP
, 0, This
->wine_url
, ptr
-This
->wine_url
, scheme
,
1657 sizeof(scheme
), NULL
, NULL
);
1658 scheme
[min(len
,sizeof(scheme
)-1)] = 0;
1659 nsACString_SetData(aScheme
, strcmp(scheme
, "about") ? scheme
: "wine");
1664 return nsIURI_GetScheme(This
->uri
, aScheme
);
1666 TRACE("returning error\n");
1667 return NS_ERROR_NOT_IMPLEMENTED
;
1670 static nsresult NSAPI
nsURI_SetScheme(nsIURL
*iface
, const nsACString
*aScheme
)
1672 nsWineURI
*This
= NSURI_THIS(iface
);
1674 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aScheme
));
1677 return nsIURI_SetScheme(This
->uri
, aScheme
);
1679 FIXME("default action not implemented\n");
1680 return NS_ERROR_NOT_IMPLEMENTED
;
1683 static nsresult NSAPI
nsURI_GetUserPass(nsIURL
*iface
, nsACString
*aUserPass
)
1685 nsWineURI
*This
= NSURI_THIS(iface
);
1687 TRACE("(%p)->(%p)\n", This
, aUserPass
);
1690 return nsIURI_GetUserPass(This
->uri
, aUserPass
);
1692 FIXME("default action not implemented\n");
1693 return NS_ERROR_NOT_IMPLEMENTED
;
1696 static nsresult NSAPI
nsURI_SetUserPass(nsIURL
*iface
, const nsACString
*aUserPass
)
1698 nsWineURI
*This
= NSURI_THIS(iface
);
1700 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUserPass
));
1703 return nsIURI_SetUserPass(This
->uri
, aUserPass
);
1705 FIXME("default action not implemented\n");
1706 return NS_ERROR_NOT_IMPLEMENTED
;
1709 static nsresult NSAPI
nsURI_GetUsername(nsIURL
*iface
, nsACString
*aUsername
)
1711 nsWineURI
*This
= NSURI_THIS(iface
);
1713 TRACE("(%p)->(%p)\n", This
, aUsername
);
1716 return nsIURI_GetUsername(This
->uri
, aUsername
);
1718 FIXME("default action not implemented\n");
1719 return NS_ERROR_NOT_IMPLEMENTED
;
1722 static nsresult NSAPI
nsURI_SetUsername(nsIURL
*iface
, const nsACString
*aUsername
)
1724 nsWineURI
*This
= NSURI_THIS(iface
);
1726 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUsername
));
1729 return nsIURI_SetUsername(This
->uri
, aUsername
);
1731 FIXME("default action not implemented\n");
1732 return NS_ERROR_NOT_IMPLEMENTED
;
1735 static nsresult NSAPI
nsURI_GetPassword(nsIURL
*iface
, nsACString
*aPassword
)
1737 nsWineURI
*This
= NSURI_THIS(iface
);
1739 TRACE("(%p)->(%p)\n", This
, aPassword
);
1742 return nsIURI_GetPassword(This
->uri
, aPassword
);
1744 FIXME("default action not implemented\n");
1745 return NS_ERROR_NOT_IMPLEMENTED
;
1748 static nsresult NSAPI
nsURI_SetPassword(nsIURL
*iface
, const nsACString
*aPassword
)
1750 nsWineURI
*This
= NSURI_THIS(iface
);
1752 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPassword
));
1755 return nsIURI_SetPassword(This
->uri
, aPassword
);
1757 FIXME("default action not implemented\n");
1758 return NS_ERROR_NOT_IMPLEMENTED
;
1761 static nsresult NSAPI
nsURI_GetHostPort(nsIURL
*iface
, nsACString
*aHostPort
)
1763 nsWineURI
*This
= NSURI_THIS(iface
);
1765 TRACE("(%p)->(%p)\n", This
, aHostPort
);
1768 return nsIURI_GetHostPort(This
->uri
, aHostPort
);
1770 FIXME("default action not implemented\n");
1771 return NS_ERROR_NOT_IMPLEMENTED
;
1774 static nsresult NSAPI
nsURI_SetHostPort(nsIURL
*iface
, const nsACString
*aHostPort
)
1776 nsWineURI
*This
= NSURI_THIS(iface
);
1778 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aHostPort
));
1781 return nsIURI_SetHostPort(This
->uri
, aHostPort
);
1783 FIXME("default action not implemented\n");
1784 return NS_ERROR_NOT_IMPLEMENTED
;
1787 static nsresult NSAPI
nsURI_GetHost(nsIURL
*iface
, nsACString
*aHost
)
1789 nsWineURI
*This
= NSURI_THIS(iface
);
1791 TRACE("(%p)->(%p)\n", This
, aHost
);
1794 return nsIURI_GetHost(This
->uri
, aHost
);
1796 FIXME("default action not implemented\n");
1797 return NS_ERROR_NOT_IMPLEMENTED
;
1800 static nsresult NSAPI
nsURI_SetHost(nsIURL
*iface
, const nsACString
*aHost
)
1802 nsWineURI
*This
= NSURI_THIS(iface
);
1804 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aHost
));
1807 return nsIURI_SetHost(This
->uri
, aHost
);
1809 FIXME("default action not implemented\n");
1810 return NS_ERROR_NOT_IMPLEMENTED
;
1813 static nsresult NSAPI
nsURI_GetPort(nsIURL
*iface
, PRInt32
*aPort
)
1815 nsWineURI
*This
= NSURI_THIS(iface
);
1817 TRACE("(%p)->(%p)\n", This
, aPort
);
1820 return nsIURI_GetPort(This
->uri
, aPort
);
1822 FIXME("default action not implemented\n");
1823 return NS_ERROR_NOT_IMPLEMENTED
;
1826 static nsresult NSAPI
nsURI_SetPort(nsIURL
*iface
, PRInt32 aPort
)
1828 nsWineURI
*This
= NSURI_THIS(iface
);
1830 TRACE("(%p)->(%d)\n", This
, aPort
);
1833 return nsIURI_SetPort(This
->uri
, aPort
);
1835 FIXME("default action not implemented\n");
1836 return NS_ERROR_NOT_IMPLEMENTED
;
1839 static nsresult NSAPI
nsURI_GetPath(nsIURL
*iface
, nsACString
*aPath
)
1841 nsWineURI
*This
= NSURI_THIS(iface
);
1843 TRACE("(%p)->(%p)\n", This
, aPath
);
1846 return nsIURI_GetPath(This
->uri
, aPath
);
1848 FIXME("default action not implemented\n");
1849 return NS_ERROR_NOT_IMPLEMENTED
;
1852 static nsresult NSAPI
nsURI_SetPath(nsIURL
*iface
, const nsACString
*aPath
)
1854 nsWineURI
*This
= NSURI_THIS(iface
);
1857 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPath
));
1859 nsACString_GetData(aPath
, &path
);
1860 if(This
->wine_url
) {
1861 WCHAR new_url
[INTERNET_MAX_URL_LENGTH
];
1862 DWORD size
= sizeof(new_url
)/sizeof(WCHAR
);
1866 pathw
= heap_strdupAtoW(path
);
1867 hres
= UrlCombineW(This
->wine_url
, pathw
, new_url
, &size
, 0);
1870 set_wine_url(This
, new_url
);
1872 WARN("UrlCombine failed: %08x\n", hres
);
1878 return nsIURI_SetPath(This
->uri
, aPath
);
1881 static nsresult NSAPI
nsURI_Equals(nsIURL
*iface
, nsIURI
*other
, PRBool
*_retval
)
1883 nsWineURI
*This
= NSURI_THIS(iface
);
1884 nsWineURI
*wine_uri
;
1887 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
1890 return nsIURI_Equals(This
->uri
, other
, _retval
);
1892 nsres
= nsIURI_QueryInterface(other
, &IID_nsWineURI
, (void**)&wine_uri
);
1893 if(NS_FAILED(nsres
)) {
1894 TRACE("Could not get nsWineURI interface\n");
1899 *_retval
= wine_uri
->wine_url
&& !UrlCompareW(This
->wine_url
, wine_uri
->wine_url
, TRUE
);
1900 nsIURI_Release(NSURI(wine_uri
));
1905 static nsresult NSAPI
nsURI_SchemeIs(nsIURL
*iface
, const char *scheme
, PRBool
*_retval
)
1907 nsWineURI
*This
= NSURI_THIS(iface
);
1909 TRACE("(%p)->(%s %p)\n", This
, debugstr_a(scheme
), _retval
);
1911 if(This
->use_wine_url
) {
1912 WCHAR buf
[INTERNET_MAX_SCHEME_LENGTH
];
1913 int len
= MultiByteToWideChar(CP_ACP
, 0, scheme
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
))-1;
1915 *_retval
= lstrlenW(This
->wine_url
) > len
1916 && This
->wine_url
[len
] == ':'
1917 && !memcmp(buf
, This
->wine_url
, len
*sizeof(WCHAR
));
1922 return nsIURI_SchemeIs(This
->uri
, scheme
, _retval
);
1924 TRACE("returning error\n");
1925 return NS_ERROR_NOT_IMPLEMENTED
;
1928 static nsresult NSAPI
nsURI_Clone(nsIURL
*iface
, nsIURI
**_retval
)
1930 nsWineURI
*This
= NSURI_THIS(iface
);
1931 nsIURI
*nsuri
= NULL
;
1932 nsWineURI
*wine_uri
;
1935 TRACE("(%p)->(%p)\n", This
, _retval
);
1938 nsres
= nsIURI_Clone(This
->uri
, &nsuri
);
1939 if(NS_FAILED(nsres
)) {
1940 WARN("Clone failed: %08x\n", nsres
);
1945 nsres
= create_uri(nsuri
, This
->window_ref
? This
->window_ref
->window
: NULL
, This
->container
, &wine_uri
);
1946 if(NS_FAILED(nsres
)) {
1947 WARN("create_uri failed: %08x\n", nsres
);
1951 set_wine_url(wine_uri
, This
->wine_url
);
1953 *_retval
= NSURI(wine_uri
);
1957 static nsresult NSAPI
nsURI_Resolve(nsIURL
*iface
, const nsACString
*aRelativePath
,
1958 nsACString
*_retval
)
1960 nsWineURI
*This
= NSURI_THIS(iface
);
1961 WCHAR url
[INTERNET_MAX_URL_LENGTH
];
1968 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aRelativePath
), _retval
);
1971 return nsIURI_Resolve(This
->uri
, aRelativePath
, _retval
);
1973 nsACString_GetData(aRelativePath
, &patha
);
1974 path
= heap_strdupAtoW(patha
);
1976 return NS_ERROR_OUT_OF_MEMORY
;
1978 hres
= CoInternetCombineUrl(This
->wine_url
, path
,
1979 URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
1980 url
, sizeof(url
)/sizeof(WCHAR
), &len
, 0);
1983 ERR("CoIntenetCombineUrl failed: %08x\n", hres
);
1984 return NS_ERROR_FAILURE
;
1987 urla
= heap_strdupWtoA(url
);
1989 return NS_ERROR_OUT_OF_MEMORY
;
1991 TRACE("returning %s\n", debugstr_a(urla
));
1992 nsACString_SetData(_retval
, urla
);
1997 static nsresult NSAPI
nsURI_GetAsciiSpec(nsIURL
*iface
, nsACString
*aAsciiSpec
)
1999 nsWineURI
*This
= NSURI_THIS(iface
);
2001 TRACE("(%p)->(%p)\n", This
, aAsciiSpec
);
2003 if(This
->use_wine_url
)
2004 return nsIURI_GetSpec(NSURI(This
), aAsciiSpec
);
2007 return nsIURI_GetAsciiSpec(This
->uri
, aAsciiSpec
);
2009 TRACE("returning error\n");
2010 return NS_ERROR_NOT_IMPLEMENTED
;
2013 static nsresult NSAPI
nsURI_GetAsciiHost(nsIURL
*iface
, nsACString
*aAsciiHost
)
2015 nsWineURI
*This
= NSURI_THIS(iface
);
2017 TRACE("(%p)->(%p)\n", This
, aAsciiHost
);
2020 return nsIURI_GetAsciiHost(This
->uri
, aAsciiHost
);
2022 FIXME("default action not implemented\n");
2023 return NS_ERROR_NOT_IMPLEMENTED
;
2026 static nsresult NSAPI
nsURI_GetOriginCharset(nsIURL
*iface
, nsACString
*aOriginCharset
)
2028 nsWineURI
*This
= NSURI_THIS(iface
);
2030 TRACE("(%p)->(%p)\n", This
, aOriginCharset
);
2033 return nsIURI_GetOriginCharset(This
->uri
, aOriginCharset
);
2035 FIXME("default action not implemented\n");
2036 return NS_ERROR_NOT_IMPLEMENTED
;
2039 static nsresult NSAPI
nsURL_GetFilePath(nsIURL
*iface
, nsACString
*aFilePath
)
2041 nsWineURI
*This
= NSURI_THIS(iface
);
2043 TRACE("(%p)->(%p)\n", This
, aFilePath
);
2046 return nsIURL_GetFilePath(This
->nsurl
, aFilePath
);
2048 FIXME("default action not implemented\n");
2049 return NS_ERROR_NOT_IMPLEMENTED
;
2052 static nsresult NSAPI
nsURL_SetFilePath(nsIURL
*iface
, const nsACString
*aFilePath
)
2054 nsWineURI
*This
= NSURI_THIS(iface
);
2056 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFilePath
));
2059 return nsIURL_SetFilePath(This
->nsurl
, aFilePath
);
2061 FIXME("default action not implemented\n");
2062 return NS_ERROR_NOT_IMPLEMENTED
;
2065 static nsresult NSAPI
nsURL_GetParam(nsIURL
*iface
, nsACString
*aParam
)
2067 nsWineURI
*This
= NSURI_THIS(iface
);
2069 TRACE("(%p)->(%p)\n", This
, aParam
);
2072 return nsIURL_GetParam(This
->nsurl
, aParam
);
2074 FIXME("default action not implemented\n");
2075 return NS_ERROR_NOT_IMPLEMENTED
;
2078 static nsresult NSAPI
nsURL_SetParam(nsIURL
*iface
, const nsACString
*aParam
)
2080 nsWineURI
*This
= NSURI_THIS(iface
);
2082 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aParam
));
2085 return nsIURL_SetParam(This
->nsurl
, aParam
);
2087 FIXME("default action not implemented\n");
2088 return NS_ERROR_NOT_IMPLEMENTED
;
2091 static nsresult NSAPI
nsURL_GetQuery(nsIURL
*iface
, nsACString
*aQuery
)
2093 nsWineURI
*This
= NSURI_THIS(iface
);
2095 TRACE("(%p)->(%p)\n", This
, aQuery
);
2098 return nsIURL_GetQuery(This
->nsurl
, aQuery
);
2100 FIXME("default action not implemented\n");
2101 return NS_ERROR_NOT_IMPLEMENTED
;
2104 static nsresult NSAPI
nsURL_SetQuery(nsIURL
*iface
, const nsACString
*aQuery
)
2106 nsWineURI
*This
= NSURI_THIS(iface
);
2107 const WCHAR
*ptr1
, *ptr2
;
2109 WCHAR
*new_url
, *ptr
;
2112 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aQuery
));
2115 nsIURL_SetQuery(This
->nsurl
, aQuery
);
2120 nsACString_GetData(aQuery
, &query
);
2121 size
= len
= MultiByteToWideChar(CP_ACP
, 0, query
, -1, NULL
, 0);
2122 ptr1
= strchrW(This
->wine_url
, '?');
2124 size
+= ptr1
-This
->wine_url
;
2125 ptr2
= strchrW(ptr1
, '#');
2127 size
+= strlenW(ptr2
);
2129 ptr1
= This
->wine_url
+ strlenW(This
->wine_url
);
2131 size
+= strlenW(This
->wine_url
);
2137 new_url
= heap_alloc(size
*sizeof(WCHAR
));
2138 memcpy(new_url
, This
->wine_url
, (ptr1
-This
->wine_url
)*sizeof(WCHAR
));
2139 ptr
= new_url
+ (ptr1
-This
->wine_url
);
2142 MultiByteToWideChar(CP_ACP
, 0, query
, -1, ptr
, len
);
2150 TRACE("setting %s\n", debugstr_w(new_url
));
2152 heap_free(This
->wine_url
);
2153 This
->wine_url
= new_url
;
2157 static nsresult NSAPI
nsURL_GetRef(nsIURL
*iface
, nsACString
*aRef
)
2159 nsWineURI
*This
= NSURI_THIS(iface
);
2161 TRACE("(%p)->(%p)\n", This
, aRef
);
2164 return nsIURL_GetRef(This
->nsurl
, aRef
);
2166 FIXME("default action not implemented\n");
2167 return NS_ERROR_NOT_IMPLEMENTED
;
2170 static nsresult NSAPI
nsURL_SetRef(nsIURL
*iface
, const nsACString
*aRef
)
2172 nsWineURI
*This
= NSURI_THIS(iface
);
2175 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRef
));
2178 return nsIURL_SetRef(This
->nsurl
, aRef
);
2180 nsACString_GetData(aRef
, &refa
);
2184 FIXME("default action not implemented\n");
2185 return NS_ERROR_NOT_IMPLEMENTED
;
2188 static nsresult NSAPI
nsURL_GetDirectory(nsIURL
*iface
, nsACString
*aDirectory
)
2190 nsWineURI
*This
= NSURI_THIS(iface
);
2192 TRACE("(%p)->(%p)\n", This
, aDirectory
);
2195 return nsIURL_GetDirectory(This
->nsurl
, aDirectory
);
2197 FIXME("default action not implemented\n");
2198 return NS_ERROR_NOT_IMPLEMENTED
;
2201 static nsresult NSAPI
nsURL_SetDirectory(nsIURL
*iface
, const nsACString
*aDirectory
)
2203 nsWineURI
*This
= NSURI_THIS(iface
);
2205 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aDirectory
));
2208 return nsIURL_SetDirectory(This
->nsurl
, aDirectory
);
2210 FIXME("default action not implemented\n");
2211 return NS_ERROR_NOT_IMPLEMENTED
;
2214 static nsresult NSAPI
nsURL_GetFileName(nsIURL
*iface
, nsACString
*aFileName
)
2216 nsWineURI
*This
= NSURI_THIS(iface
);
2218 TRACE("(%p)->(%p)\n", This
, aFileName
);
2221 return nsIURL_GetFileName(This
->nsurl
, aFileName
);
2223 FIXME("default action not implemented\n");
2224 return NS_ERROR_NOT_IMPLEMENTED
;
2227 static nsresult NSAPI
nsURL_SetFileName(nsIURL
*iface
, const nsACString
*aFileName
)
2229 nsWineURI
*This
= NSURI_THIS(iface
);
2231 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileName
));
2234 return nsIURL_SetFileName(This
->nsurl
, aFileName
);
2236 FIXME("default action not implemented\n");
2237 return NS_ERROR_NOT_IMPLEMENTED
;
2240 static nsresult NSAPI
nsURL_GetFileBaseName(nsIURL
*iface
, nsACString
*aFileBaseName
)
2242 nsWineURI
*This
= NSURI_THIS(iface
);
2244 TRACE("(%p)->(%p)\n", This
, aFileBaseName
);
2247 return nsIURL_GetFileBaseName(This
->nsurl
, aFileBaseName
);
2249 FIXME("default action not implemented\n");
2250 return NS_ERROR_NOT_IMPLEMENTED
;
2253 static nsresult NSAPI
nsURL_SetFileBaseName(nsIURL
*iface
, const nsACString
*aFileBaseName
)
2255 nsWineURI
*This
= NSURI_THIS(iface
);
2257 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileBaseName
));
2260 return nsIURL_SetFileBaseName(This
->nsurl
, aFileBaseName
);
2262 FIXME("default action not implemented\n");
2263 return NS_ERROR_NOT_IMPLEMENTED
;
2266 static nsresult NSAPI
nsURL_GetFileExtension(nsIURL
*iface
, nsACString
*aFileExtension
)
2268 nsWineURI
*This
= NSURI_THIS(iface
);
2270 TRACE("(%p)->(%p)\n", This
, aFileExtension
);
2273 return nsIURL_GetFileExtension(This
->nsurl
, aFileExtension
);
2275 FIXME("default action not implemented\n");
2276 return NS_ERROR_NOT_IMPLEMENTED
;
2279 static nsresult NSAPI
nsURL_SetFileExtension(nsIURL
*iface
, const nsACString
*aFileExtension
)
2281 nsWineURI
*This
= NSURI_THIS(iface
);
2283 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileExtension
));
2286 return nsIURL_SetFileExtension(This
->nsurl
, aFileExtension
);
2288 FIXME("default action not implemented\n");
2289 return NS_ERROR_NOT_IMPLEMENTED
;
2292 static nsresult NSAPI
nsURL_GetCommonBaseSpec(nsIURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2294 nsWineURI
*This
= NSURI_THIS(iface
);
2296 TRACE("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2299 return nsIURL_GetCommonBaseSpec(This
->nsurl
, aURIToCompare
, _retval
);
2301 FIXME("default action not implemented\n");
2302 return NS_ERROR_NOT_IMPLEMENTED
;
2305 static nsresult NSAPI
nsURL_GetRelativeSpec(nsIURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2307 nsWineURI
*This
= NSURI_THIS(iface
);
2309 TRACE("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2312 return nsIURL_GetRelativeSpec(This
->nsurl
, aURIToCompare
, _retval
);
2314 FIXME("default action not implemented\n");
2315 return NS_ERROR_NOT_IMPLEMENTED
;
2320 static const nsIURLVtbl nsURLVtbl
= {
2321 nsURI_QueryInterface
,
2349 nsURI_GetOriginCharset
,
2362 nsURL_GetFileBaseName
,
2363 nsURL_SetFileBaseName
,
2364 nsURL_GetFileExtension
,
2365 nsURL_SetFileExtension
,
2366 nsURL_GetCommonBaseSpec
,
2367 nsURL_GetRelativeSpec
2370 static nsresult
create_uri(nsIURI
*uri
, HTMLWindow
*window
, NSContainer
*container
, nsWineURI
**_retval
)
2372 nsWineURI
*ret
= heap_alloc_zero(sizeof(nsWineURI
));
2374 ret
->lpIURLVtbl
= &nsURLVtbl
;
2378 set_uri_nscontainer(ret
, container
);
2379 set_uri_window(ret
, window
);
2382 nsIURI_QueryInterface(uri
, &IID_nsIURL
, (void**)&ret
->nsurl
);
2384 TRACE("retval=%p\n", ret
);
2389 HRESULT
create_doc_uri(HTMLWindow
*window
, WCHAR
*url
, nsWineURI
**ret
)
2394 nsres
= create_uri(NULL
, window
, window
->doc_obj
->nscontainer
, &uri
);
2395 if(NS_FAILED(nsres
))
2398 set_wine_url(uri
, url
);
2399 uri
->is_doc_uri
= TRUE
;
2406 const nsIProtocolHandlerVtbl
*lpProtocolHandlerVtbl
;
2410 nsIProtocolHandler
*nshandler
;
2411 } nsProtocolHandler
;
2413 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
2415 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
2417 static nsresult NSAPI
nsProtocolHandler_QueryInterface(nsIProtocolHandler
*iface
, nsIIDRef riid
,
2420 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2424 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
2425 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
2426 *result
= NSPROTHANDLER(This
);
2427 }else if(IsEqualGUID(&IID_nsIProtocolHandler
, riid
)) {
2428 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This
, result
);
2429 *result
= NSPROTHANDLER(This
);
2430 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler
, riid
)) {
2431 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This
, result
);
2432 return NS_NOINTERFACE
;
2436 nsISupports_AddRef((nsISupports
*)*result
);
2440 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
2441 return NS_NOINTERFACE
;
2444 static nsrefcnt NSAPI
nsProtocolHandler_AddRef(nsIProtocolHandler
*iface
)
2446 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2447 LONG ref
= InterlockedIncrement(&This
->ref
);
2449 TRACE("(%p) ref=%d\n", This
, ref
);
2454 static nsrefcnt NSAPI
nsProtocolHandler_Release(nsIProtocolHandler
*iface
)
2456 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2457 LONG ref
= InterlockedDecrement(&This
->ref
);
2459 TRACE("(%p) ref=%d\n", This
, ref
);
2463 nsIProtocolHandler_Release(This
->nshandler
);
2470 static nsresult NSAPI
nsProtocolHandler_GetScheme(nsIProtocolHandler
*iface
, nsACString
*aScheme
)
2472 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2474 TRACE("(%p)->(%p)\n", This
, aScheme
);
2477 return nsIProtocolHandler_GetScheme(This
->nshandler
, aScheme
);
2478 return NS_ERROR_NOT_IMPLEMENTED
;
2481 static nsresult NSAPI
nsProtocolHandler_GetDefaultPort(nsIProtocolHandler
*iface
,
2482 PRInt32
*aDefaultPort
)
2484 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2486 TRACE("(%p)->(%p)\n", This
, aDefaultPort
);
2489 return nsIProtocolHandler_GetDefaultPort(This
->nshandler
, aDefaultPort
);
2490 return NS_ERROR_NOT_IMPLEMENTED
;
2493 static nsresult NSAPI
nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler
*iface
,
2494 PRUint32
*aProtocolFlags
)
2496 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2498 TRACE("(%p)->(%p)\n", This
, aProtocolFlags
);
2501 return nsIProtocolHandler_GetProtocolFlags(This
->nshandler
, aProtocolFlags
);
2502 return NS_ERROR_NOT_IMPLEMENTED
;
2505 static nsresult NSAPI
nsProtocolHandler_NewURI(nsIProtocolHandler
*iface
,
2506 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
2508 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2510 TRACE("((%p)->%s %s %p %p)\n", This
, debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
2514 return nsIProtocolHandler_NewURI(This
->nshandler
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2515 return NS_ERROR_NOT_IMPLEMENTED
;
2518 static nsresult NSAPI
nsProtocolHandler_NewChannel(nsIProtocolHandler
*iface
,
2519 nsIURI
*aURI
, nsIChannel
**_retval
)
2521 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2523 TRACE("(%p)->(%p %p)\n", This
, aURI
, _retval
);
2526 return nsIProtocolHandler_NewChannel(This
->nshandler
, aURI
, _retval
);
2527 return NS_ERROR_NOT_IMPLEMENTED
;
2530 static nsresult NSAPI
nsProtocolHandler_AllowPort(nsIProtocolHandler
*iface
,
2531 PRInt32 port
, const char *scheme
, PRBool
*_retval
)
2533 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2535 TRACE("(%p)->(%d %s %p)\n", This
, port
, debugstr_a(scheme
), _retval
);
2538 return nsIProtocolHandler_AllowPort(This
->nshandler
, port
, scheme
, _retval
);
2539 return NS_ERROR_NOT_IMPLEMENTED
;
2542 #undef NSPROTHANDLER_THIS
2544 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl
= {
2545 nsProtocolHandler_QueryInterface
,
2546 nsProtocolHandler_AddRef
,
2547 nsProtocolHandler_Release
,
2548 nsProtocolHandler_GetScheme
,
2549 nsProtocolHandler_GetDefaultPort
,
2550 nsProtocolHandler_GetProtocolFlags
,
2551 nsProtocolHandler_NewURI
,
2552 nsProtocolHandler_NewChannel
,
2553 nsProtocolHandler_AllowPort
2556 static nsIProtocolHandler
*create_protocol_handler(nsIProtocolHandler
*nshandler
)
2558 nsProtocolHandler
*ret
= heap_alloc(sizeof(nsProtocolHandler
));
2560 ret
->lpProtocolHandlerVtbl
= &nsProtocolHandlerVtbl
;
2562 ret
->nshandler
= nshandler
;
2564 return NSPROTHANDLER(ret
);
2567 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*,nsIIDRef
,void**);
2569 static nsrefcnt NSAPI
nsIOService_AddRef(nsIIOService
*iface
)
2574 static nsrefcnt NSAPI
nsIOService_Release(nsIIOService
*iface
)
2579 static nsresult NSAPI
nsIOService_GetProtocolHandler(nsIIOService
*iface
, const char *aScheme
,
2580 nsIProtocolHandler
**_retval
)
2582 nsIExternalProtocolHandler
*nsexthandler
;
2583 nsIProtocolHandler
*nshandler
;
2586 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
2588 nsres
= nsIIOService_GetProtocolHandler(nsio
, aScheme
, &nshandler
);
2589 if(NS_FAILED(nsres
)) {
2590 WARN("GetProtocolHandler failed: %08x\n", nsres
);
2594 nsres
= nsIProtocolHandler_QueryInterface(nshandler
, &IID_nsIExternalProtocolHandler
,
2595 (void**)&nsexthandler
);
2596 if(NS_FAILED(nsres
)) {
2597 *_retval
= nshandler
;
2601 nsIExternalProtocolHandler_Release(nsexthandler
);
2602 *_retval
= create_protocol_handler(nshandler
);
2603 TRACE("return %p\n", *_retval
);
2607 static nsresult NSAPI
nsIOService_GetProtocolFlags(nsIIOService
*iface
, const char *aScheme
,
2610 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
2611 return nsIIOService_GetProtocolFlags(nsio
, aScheme
, _retval
);
2614 static BOOL
is_gecko_special_uri(const char *spec
)
2616 static const char *special_schemes
[] = {"chrome:", "jar:", "resource:", "javascript:", "wyciwyg:"};
2619 for(i
=0; i
< sizeof(special_schemes
)/sizeof(*special_schemes
); i
++) {
2620 if(!strncasecmp(spec
, special_schemes
[i
], strlen(special_schemes
[i
])))
2624 if(!strncasecmp(spec
, "file:", 5)) {
2625 const char *ptr
= spec
+5;
2628 return is_gecko_path(ptr
);
2634 static nsresult NSAPI
nsIOService_NewURI(nsIIOService
*iface
, const nsACString
*aSpec
,
2635 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
2637 nsWineURI
*wine_uri
, *base_wine_uri
= NULL
;
2638 const char *spec
= NULL
;
2639 HTMLWindow
*window
= NULL
;
2641 LPCWSTR base_wine_url
= NULL
;
2642 nsACString spec_str
;
2646 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
2649 nsACString_GetData(aSpec
, &spec
);
2650 if(is_gecko_special_uri(spec
))
2651 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2653 if(!strncmp(spec
, "wine:", 5))
2657 PARSEDURLA parsed_url
= {sizeof(PARSEDURLA
)};
2659 nsres
= nsIURI_QueryInterface(aBaseURI
, &IID_nsWineURI
, (void**)&base_wine_uri
);
2660 if(NS_SUCCEEDED(nsres
)) {
2661 base_wine_url
= base_wine_uri
->wine_url
;
2662 if(base_wine_uri
->window_ref
&& base_wine_uri
->window_ref
->window
) {
2663 window
= base_wine_uri
->window_ref
->window
;
2664 IHTMLWindow2_AddRef(HTMLWINDOW2(window
));
2666 TRACE("base url: %s window: %p\n", debugstr_w(base_wine_url
), window
);
2667 }else if(FAILED(ParseURLA(spec
, &parsed_url
))) {
2668 TRACE("not wraping\n");
2669 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2671 WARN("Could not get base nsWineURI: %08x\n", nsres
);
2675 nsACString_InitDepend(&spec_str
, spec
);
2676 nsres
= nsIIOService_NewURI(nsio
, &spec_str
, aOriginCharset
, aBaseURI
, &uri
);
2677 nsACString_Finish(&spec_str
);
2678 if(NS_FAILED(nsres
))
2679 TRACE("NewURI failed: %08x\n", nsres
);
2681 nsres
= create_uri(uri
, window
, NULL
, &wine_uri
);
2682 *_retval
= (nsIURI
*)wine_uri
;
2685 IHTMLWindow2_Release(HTMLWINDOW2(window
));
2688 WCHAR url
[INTERNET_MAX_URL_LENGTH
], rel_url
[INTERNET_MAX_URL_LENGTH
];
2692 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, rel_url
, sizeof(rel_url
)/sizeof(WCHAR
));
2694 hres
= CoInternetCombineUrl(base_wine_url
, rel_url
,
2695 URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
2696 url
, sizeof(url
)/sizeof(WCHAR
), &len
, 0);
2698 set_wine_url(wine_uri
, url
);
2700 WARN("CoCombineUrl failed: %08x\n", hres
);
2702 WCHAR url
[INTERNET_MAX_URL_LENGTH
];
2704 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, url
, sizeof(url
)/sizeof(WCHAR
));
2705 set_wine_url(wine_uri
, url
);
2709 nsIURI_Release(NSURI(base_wine_uri
));
2714 static nsresult NSAPI
nsIOService_NewFileURI(nsIIOService
*iface
, nsIFile
*aFile
,
2717 TRACE("(%p %p)\n", aFile
, _retval
);
2718 return nsIIOService_NewFileURI(nsio
, aFile
, _retval
);
2721 static nsresult NSAPI
nsIOService_NewChannelFromURI(nsIIOService
*iface
, nsIURI
*aURI
,
2722 nsIChannel
**_retval
)
2724 PARSEDURLW parsed_url
= {sizeof(PARSEDURLW
)};
2726 nsWineURI
*wine_uri
;
2729 TRACE("(%p %p)\n", aURI
, _retval
);
2731 nsres
= nsIURI_QueryInterface(aURI
, &IID_nsWineURI
, (void**)&wine_uri
);
2732 if(NS_FAILED(nsres
)) {
2733 TRACE("Could not get nsWineURI: %08x\n", nsres
);
2734 return nsIIOService_NewChannelFromURI(nsio
, aURI
, _retval
);
2737 ret
= heap_alloc_zero(sizeof(nsChannel
));
2739 ret
->lpHttpChannelVtbl
= &nsChannelVtbl
;
2740 ret
->lpUploadChannelVtbl
= &nsUploadChannelVtbl
;
2741 ret
->lpIHttpChannelInternalVtbl
= &nsHttpChannelInternalVtbl
;
2743 ret
->uri
= wine_uri
;
2744 ret
->request_method
= METHOD_GET
;
2745 list_init(&ret
->response_headers
);
2746 list_init(&ret
->request_headers
);
2748 nsIURI_AddRef(aURI
);
2749 ret
->original_uri
= aURI
;
2750 ret
->url_scheme
= wine_uri
->wine_url
&& SUCCEEDED(ParseURLW(wine_uri
->wine_url
, &parsed_url
))
2751 ? parsed_url
.nScheme
: URL_SCHEME_UNKNOWN
;
2753 *_retval
= NSCHANNEL(ret
);
2757 static nsresult NSAPI
nsIOService_NewChannel(nsIIOService
*iface
, const nsACString
*aSpec
,
2758 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIChannel
**_retval
)
2760 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
), aBaseURI
, _retval
);
2761 return nsIIOService_NewChannel(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2764 static nsresult NSAPI
nsIOService_GetOffline(nsIIOService
*iface
, PRBool
*aOffline
)
2766 TRACE("(%p)\n", aOffline
);
2767 return nsIIOService_GetOffline(nsio
, aOffline
);
2770 static nsresult NSAPI
nsIOService_SetOffline(nsIIOService
*iface
, PRBool aOffline
)
2772 TRACE("(%x)\n", aOffline
);
2773 return nsIIOService_SetOffline(nsio
, aOffline
);
2776 static nsresult NSAPI
nsIOService_AllowPort(nsIIOService
*iface
, PRInt32 aPort
,
2777 const char *aScheme
, PRBool
*_retval
)
2779 TRACE("(%d %s %p)\n", aPort
, debugstr_a(aScheme
), _retval
);
2780 return nsIIOService_AllowPort(nsio
, aPort
, debugstr_a(aScheme
), _retval
);
2783 static nsresult NSAPI
nsIOService_ExtractScheme(nsIIOService
*iface
, const nsACString
*urlString
,
2784 nsACString
* _retval
)
2786 TRACE("(%s %p)\n", debugstr_nsacstr(urlString
), _retval
);
2787 return nsIIOService_ExtractScheme(nsio
, urlString
, _retval
);
2790 static const nsIIOServiceVtbl nsIOServiceVtbl
= {
2791 nsIOService_QueryInterface
,
2793 nsIOService_Release
,
2794 nsIOService_GetProtocolHandler
,
2795 nsIOService_GetProtocolFlags
,
2797 nsIOService_NewFileURI
,
2798 nsIOService_NewChannelFromURI
,
2799 nsIOService_NewChannel
,
2800 nsIOService_GetOffline
,
2801 nsIOService_SetOffline
,
2802 nsIOService_AllowPort
,
2803 nsIOService_ExtractScheme
2806 static nsIIOService nsIOService
= { &nsIOServiceVtbl
};
2808 static nsresult NSAPI
nsNetUtil_QueryInterface(nsINetUtil
*iface
, nsIIDRef riid
,
2811 return nsIIOService_QueryInterface(&nsIOService
, riid
, result
);
2814 static nsrefcnt NSAPI
nsNetUtil_AddRef(nsINetUtil
*iface
)
2819 static nsrefcnt NSAPI
nsNetUtil_Release(nsINetUtil
*iface
)
2824 static nsresult NSAPI
nsNetUtil_ParseContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
2825 nsACString
*aCharset
, PRBool
*aHadCharset
, nsACString
*aContentType
)
2827 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aHadCharset
, aContentType
);
2829 return nsINetUtil_ParseContentType(net_util
, aTypeHeader
, aCharset
, aHadCharset
, aContentType
);
2832 static nsresult NSAPI
nsNetUtil_ProtocolHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, PRUint32 aFlags
, PRBool
*_retval
)
2836 return nsINetUtil_ProtocolHasFlags(net_util
, aURI
, aFlags
, _retval
);
2839 static nsresult NSAPI
nsNetUtil_URIChainHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, PRUint32 aFlags
, PRBool
*_retval
)
2841 TRACE("(%p %08x %p)\n", aURI
, aFlags
, _retval
);
2843 if(aFlags
== (1<<11)) {
2848 return nsINetUtil_URIChainHasFlags(net_util
, aURI
, aFlags
, _retval
);
2851 static nsresult NSAPI
nsNetUtil_ToImmutableURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
2853 TRACE("(%p %p)\n", aURI
, _retval
);
2855 return nsINetUtil_ToImmutableURI(net_util
, aURI
, _retval
);
2858 static nsresult NSAPI
nsNetUtil_NewSimpleNestedURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
2860 TRACE("(%p %p)\n", aURI
, _retval
);
2862 return nsINetUtil_NewSimpleNestedURI(net_util
, aURI
, _retval
);
2865 static nsresult NSAPI
nsNetUtil_EscapeString(nsINetUtil
*iface
, const nsACString
*aString
,
2866 PRUint32 aEscapeType
, nsACString
*_retval
)
2868 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString
), aEscapeType
, _retval
);
2870 return nsINetUtil_EscapeString(net_util
, aString
, aEscapeType
, _retval
);
2873 static nsresult NSAPI
nsNetUtil_EscapeURL(nsINetUtil
*iface
, const nsACString
*aStr
, PRUint32 aFlags
,
2874 nsACString
*_retval
)
2876 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
2878 return nsINetUtil_EscapeURL(net_util
, aStr
, aFlags
, _retval
);
2881 static nsresult NSAPI
nsNetUtil_UnescapeString(nsINetUtil
*iface
, const nsACString
*aStr
,
2882 PRUint32 aFlags
, nsACString
*_retval
)
2884 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
2886 return nsINetUtil_UnescapeString(net_util
, aStr
, aFlags
, _retval
);
2889 static nsresult NSAPI
nsNetUtil_ExtractCharsetFromContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
2890 nsACString
*aCharset
, PRInt32
*aCharsetStart
, PRInt32
*aCharsetEnd
, PRBool
*_retval
)
2892 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aCharsetStart
,
2893 aCharsetEnd
, _retval
);
2895 return nsINetUtil_ExtractCharsetFromContentType(net_util
, aTypeHeader
, aCharset
, aCharsetStart
, aCharsetEnd
, _retval
);
2898 static const nsINetUtilVtbl nsNetUtilVtbl
= {
2899 nsNetUtil_QueryInterface
,
2902 nsNetUtil_ParseContentType
,
2903 nsNetUtil_ProtocolHasFlags
,
2904 nsNetUtil_URIChainHasFlags
,
2905 nsNetUtil_ToImmutableURI
,
2906 nsNetUtil_NewSimpleNestedURI
,
2907 nsNetUtil_EscapeString
,
2908 nsNetUtil_EscapeURL
,
2909 nsNetUtil_UnescapeString
,
2910 nsNetUtil_ExtractCharsetFromContentType
2913 static nsINetUtil nsNetUtil
= { &nsNetUtilVtbl
};
2915 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*iface
, nsIIDRef riid
,
2920 if(IsEqualGUID(&IID_nsISupports
, riid
))
2921 *result
= &nsIOService
;
2922 else if(IsEqualGUID(&IID_nsIIOService
, riid
))
2923 *result
= &nsIOService
;
2924 else if(IsEqualGUID(&IID_nsINetUtil
, riid
))
2925 *result
= &nsNetUtil
;
2928 nsISupports_AddRef((nsISupports
*)*result
);
2932 FIXME("(%s %p)\n", debugstr_guid(riid
), result
);
2933 return NS_NOINTERFACE
;
2936 static nsresult NSAPI
nsIOServiceFactory_QueryInterface(nsIFactory
*iface
, nsIIDRef riid
,
2941 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
2942 TRACE("(IID_nsISupports %p)\n", result
);
2944 }else if(IsEqualGUID(&IID_nsIFactory
, riid
)) {
2945 TRACE("(IID_nsIFactory %p)\n", result
);
2950 nsIFactory_AddRef(iface
);
2954 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
2955 return NS_NOINTERFACE
;
2958 static nsrefcnt NSAPI
nsIOServiceFactory_AddRef(nsIFactory
*iface
)
2963 static nsrefcnt NSAPI
nsIOServiceFactory_Release(nsIFactory
*iface
)
2968 static nsresult NSAPI
nsIOServiceFactory_CreateInstance(nsIFactory
*iface
,
2969 nsISupports
*aOuter
, const nsIID
*iid
, void **result
)
2971 return nsIIOService_QueryInterface(&nsIOService
, iid
, result
);
2974 static nsresult NSAPI
nsIOServiceFactory_LockFactory(nsIFactory
*iface
, PRBool lock
)
2976 WARN("(%x)\n", lock
);
2980 static const nsIFactoryVtbl nsIOServiceFactoryVtbl
= {
2981 nsIOServiceFactory_QueryInterface
,
2982 nsIOServiceFactory_AddRef
,
2983 nsIOServiceFactory_Release
,
2984 nsIOServiceFactory_CreateInstance
,
2985 nsIOServiceFactory_LockFactory
2988 static nsIFactory nsIOServiceFactory
= { &nsIOServiceFactoryVtbl
};
2990 void init_nsio(nsIComponentManager
*component_manager
, nsIComponentRegistrar
*registrar
)
2992 nsIFactory
*old_factory
= NULL
;
2995 nsres
= nsIComponentManager_GetClassObject(component_manager
, &NS_IOSERVICE_CID
,
2996 &IID_nsIFactory
, (void**)&old_factory
);
2997 if(NS_FAILED(nsres
)) {
2998 ERR("Could not get factory: %08x\n", nsres
);
3002 nsres
= nsIFactory_CreateInstance(old_factory
, NULL
, &IID_nsIIOService
, (void**)&nsio
);
3003 if(NS_FAILED(nsres
)) {
3004 ERR("Couldn not create nsIOService instance %08x\n", nsres
);
3005 nsIFactory_Release(old_factory
);
3009 nsres
= nsIIOService_QueryInterface(nsio
, &IID_nsINetUtil
, (void**)&net_util
);
3010 if(NS_FAILED(nsres
)) {
3011 WARN("Could not get nsINetUtil interface: %08x\n", nsres
);
3012 nsIIOService_Release(nsio
);
3016 nsres
= nsIComponentRegistrar_UnregisterFactory(registrar
, &NS_IOSERVICE_CID
, old_factory
);
3017 nsIFactory_Release(old_factory
);
3018 if(NS_FAILED(nsres
))
3019 ERR("UnregisterFactory failed: %08x\n", nsres
);
3021 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_IOSERVICE_CID
,
3022 NS_IOSERVICE_CLASSNAME
, NS_IOSERVICE_CONTRACTID
, &nsIOServiceFactory
);
3023 if(NS_FAILED(nsres
))
3024 ERR("RegisterFactory failed: %08x\n", nsres
);
3027 void release_nsio(void)
3030 nsINetUtil_Release(net_util
);
3035 nsIIOService_Release(nsio
);