2 * Copyright 2006-2007 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 LOAD_INITIAL_DOCUMENT_URI 0x80000
43 #define NS_IOSERVICE_CLASSNAME "nsIOService"
44 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
46 static const IID NS_IOSERVICE_CID
=
47 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
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};
55 const nsIWineURIVtbl
*lpWineURIVtbl
;
60 NSContainer
*container
;
66 #define NSURI(x) ((nsIURI*) &(x)->lpWineURIVtbl)
67 #define NSWINEURI(x) ((nsIWineURI*) &(x)->lpWineURIVtbl)
69 static nsresult
create_uri(nsIURI
*,NSContainer
*,nsIWineURI
**);
71 HRESULT
nsuri_to_url(LPCWSTR nsuri
, BSTR
*ret
)
73 const WCHAR
*ptr
= nsuri
;
75 static const WCHAR wine_prefixW
[] = {'w','i','n','e',':'};
77 if(!strncmpW(nsuri
, wine_prefixW
, sizeof(wine_prefixW
)/sizeof(WCHAR
)))
78 ptr
+= sizeof(wine_prefixW
)/sizeof(WCHAR
);
80 *ret
= SysAllocString(ptr
);
84 TRACE("%s -> %s\n", debugstr_w(nsuri
), debugstr_w(*ret
));
88 static BOOL
exec_shldocvw_67(HTMLDocument
*doc
, LPCWSTR url
)
90 IOleCommandTarget
*cmdtrg
= NULL
;
93 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
,
96 VARIANT varUrl
, varRes
;
98 V_VT(&varUrl
) = VT_BSTR
;
99 V_BSTR(&varUrl
) = SysAllocString(url
);
100 V_VT(&varRes
) = VT_BOOL
;
102 hres
= IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 67, 0, &varUrl
, &varRes
);
104 IOleCommandTarget_Release(cmdtrg
);
105 SysFreeString(V_BSTR(&varUrl
));
107 if(SUCCEEDED(hres
) && !V_BOOL(&varRes
)) {
108 TRACE("got VARIANT_FALSE, do not load\n");
116 static BOOL
before_async_open(nsChannel
*channel
, NSContainer
*container
)
118 IServiceProvider
*service_provider
;
119 HTMLDocument
*doc
= container
->doc
;
124 nsIWineURI_GetWineURL(channel
->uri
, &uri
);
126 ERR("GetWineURL returned NULL\n");
131 NSContainer
*container_iter
= container
;
133 hlnf
= HLNF_OPENINNEWWINDOW
;
134 while(!container_iter
->doc
)
135 container_iter
= container_iter
->parent
;
136 doc
= container_iter
->doc
;
142 if(!hlnf
&& !exec_shldocvw_67(doc
, uri
))
145 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IServiceProvider
,
146 (void**)&service_provider
);
147 if(SUCCEEDED(hres
)) {
148 IHlinkFrame
*hlink_frame
;
150 hres
= IServiceProvider_QueryService(service_provider
, &IID_IHlinkFrame
,
151 &IID_IHlinkFrame
, (void**)&hlink_frame
);
152 IServiceProvider_Release(service_provider
);
153 if(SUCCEEDED(hres
)) {
154 hlink_frame_navigate(doc
, hlink_frame
, uri
, channel
->post_data_stream
, hlnf
);
155 IHlinkFrame_Release(hlink_frame
);
164 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
166 static nsresult NSAPI
nsChannel_QueryInterface(nsIHttpChannel
*iface
, nsIIDRef riid
, nsQIResult result
)
168 nsChannel
*This
= NSCHANNEL_THIS(iface
);
172 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
173 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
174 *result
= NSCHANNEL(This
);
175 }else if(IsEqualGUID(&IID_nsIRequest
, riid
)) {
176 TRACE("(%p)->(IID_nsIRequest %p)\n", This
, result
);
177 *result
= NSCHANNEL(This
);
178 }else if(IsEqualGUID(&IID_nsIChannel
, riid
)) {
179 TRACE("(%p)->(IID_nsIChannel %p)\n", This
, result
);
180 *result
= NSCHANNEL(This
);
181 }else if(This
->http_channel
&& IsEqualGUID(&IID_nsIHttpChannel
, riid
)) {
182 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This
, result
);
183 *result
= NSHTTPCHANNEL(This
);
184 }else if(IsEqualGUID(&IID_nsIUploadChannel
, riid
)) {
185 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This
, result
);
186 *result
= NSUPCHANNEL(This
);
190 nsIChannel_AddRef(NSCHANNEL(This
));
194 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
197 return nsIChannel_QueryInterface(This
->channel
, riid
, result
);
198 return NS_NOINTERFACE
;
201 static nsrefcnt NSAPI
nsChannel_AddRef(nsIHttpChannel
*iface
)
203 nsChannel
*This
= NSCHANNEL_THIS(iface
);
204 nsrefcnt ref
= InterlockedIncrement(&This
->ref
);
206 TRACE("(%p) ref=%d\n", This
, ref
);
211 static nsrefcnt NSAPI
nsChannel_Release(nsIHttpChannel
*iface
)
213 nsChannel
*This
= NSCHANNEL_THIS(iface
);
214 LONG ref
= InterlockedDecrement(&This
->ref
);
217 nsIWineURI_Release(This
->uri
);
219 nsIChannel_Release(This
->channel
);
220 if(This
->http_channel
)
221 nsIHttpChannel_Release(This
->http_channel
);
223 nsISupports_Release(This
->owner
);
224 if(This
->post_data_stream
)
225 nsIInputStream_Release(This
->post_data_stream
);
227 nsILoadGroup_Release(This
->load_group
);
228 if(This
->notif_callback
)
229 nsIInterfaceRequestor_Release(This
->notif_callback
);
230 if(This
->original_uri
)
231 nsIURI_Release(This
->original_uri
);
232 heap_free(This
->content_type
);
233 heap_free(This
->charset
);
240 static nsresult NSAPI
nsChannel_GetName(nsIHttpChannel
*iface
, nsACString
*aName
)
242 nsChannel
*This
= NSCHANNEL_THIS(iface
);
244 TRACE("(%p)->(%p)\n", This
, aName
);
247 return nsIChannel_GetName(This
->channel
, aName
);
249 return NS_ERROR_NOT_IMPLEMENTED
;
252 static nsresult NSAPI
nsChannel_IsPending(nsIHttpChannel
*iface
, PRBool
*_retval
)
254 nsChannel
*This
= NSCHANNEL_THIS(iface
);
256 TRACE("(%p)->(%p)\n", This
, _retval
);
259 return nsIChannel_IsPending(This
->channel
, _retval
);
261 FIXME("default action not implemented\n");
262 return NS_ERROR_NOT_IMPLEMENTED
;
265 static nsresult NSAPI
nsChannel_GetStatus(nsIHttpChannel
*iface
, nsresult
*aStatus
)
267 nsChannel
*This
= NSCHANNEL_THIS(iface
);
269 TRACE("(%p)->(%p)\n", This
, aStatus
);
272 return nsIChannel_GetStatus(This
->channel
, aStatus
);
274 TRACE("returning NS_OK\n");
275 return *aStatus
= NS_OK
;
278 static nsresult NSAPI
nsChannel_Cancel(nsIHttpChannel
*iface
, nsresult aStatus
)
280 nsChannel
*This
= NSCHANNEL_THIS(iface
);
282 TRACE("(%p)->(%08x)\n", This
, aStatus
);
285 return nsIChannel_Cancel(This
->channel
, aStatus
);
287 FIXME("default action not implemented\n");
288 return NS_ERROR_NOT_IMPLEMENTED
;
291 static nsresult NSAPI
nsChannel_Suspend(nsIHttpChannel
*iface
)
293 nsChannel
*This
= NSCHANNEL_THIS(iface
);
295 TRACE("(%p)\n", This
);
298 return nsIChannel_Suspend(This
->channel
);
300 FIXME("default action not implemented\n");
301 return NS_ERROR_NOT_IMPLEMENTED
;
304 static nsresult NSAPI
nsChannel_Resume(nsIHttpChannel
*iface
)
306 nsChannel
*This
= NSCHANNEL_THIS(iface
);
308 TRACE("(%p)\n", This
);
311 return nsIChannel_Resume(This
->channel
);
313 FIXME("default action not implemented\n");
314 return NS_ERROR_NOT_IMPLEMENTED
;
317 static nsresult NSAPI
nsChannel_GetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
**aLoadGroup
)
319 nsChannel
*This
= NSCHANNEL_THIS(iface
);
321 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
324 nsILoadGroup_AddRef(This
->load_group
);
326 *aLoadGroup
= This
->load_group
;
330 static nsresult NSAPI
nsChannel_SetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
*aLoadGroup
)
332 nsChannel
*This
= NSCHANNEL_THIS(iface
);
334 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
337 nsILoadGroup_Release(This
->load_group
);
339 nsILoadGroup_AddRef(aLoadGroup
);
341 This
->load_group
= aLoadGroup
;
344 return nsIChannel_SetLoadGroup(This
->channel
, aLoadGroup
);
348 static nsresult NSAPI
nsChannel_GetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags
*aLoadFlags
)
350 nsChannel
*This
= NSCHANNEL_THIS(iface
);
352 TRACE("(%p)->(%p)\n", This
, aLoadFlags
);
354 *aLoadFlags
= This
->load_flags
;
358 static nsresult NSAPI
nsChannel_SetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags aLoadFlags
)
360 nsChannel
*This
= NSCHANNEL_THIS(iface
);
362 TRACE("(%p)->(%08x)\n", This
, aLoadFlags
);
364 This
->load_flags
= aLoadFlags
;
367 return nsIChannel_SetLoadFlags(This
->channel
, aLoadFlags
);
371 static nsresult NSAPI
nsChannel_GetOriginalURI(nsIHttpChannel
*iface
, nsIURI
**aOriginalURI
)
373 nsChannel
*This
= NSCHANNEL_THIS(iface
);
375 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
377 if(This
->original_uri
)
378 nsIURI_AddRef(This
->original_uri
);
380 *aOriginalURI
= This
->original_uri
;
384 static nsresult NSAPI
nsChannel_SetOriginalURI(nsIHttpChannel
*iface
, nsIURI
*aOriginalURI
)
386 nsChannel
*This
= NSCHANNEL_THIS(iface
);
388 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
390 if(This
->original_uri
)
391 nsIURI_Release(This
->original_uri
);
393 nsIURI_AddRef(aOriginalURI
);
394 This
->original_uri
= aOriginalURI
;
397 return nsIChannel_SetOriginalURI(This
->channel
, aOriginalURI
);
401 static nsresult NSAPI
nsChannel_GetURI(nsIHttpChannel
*iface
, nsIURI
**aURI
)
403 nsChannel
*This
= NSCHANNEL_THIS(iface
);
405 TRACE("(%p)->(%p)\n", This
, aURI
);
407 nsIWineURI_AddRef(This
->uri
);
408 *aURI
= (nsIURI
*)This
->uri
;
413 static nsresult NSAPI
nsChannel_GetOwner(nsIHttpChannel
*iface
, nsISupports
**aOwner
)
415 nsChannel
*This
= NSCHANNEL_THIS(iface
);
417 TRACE("(%p)->(%p)\n", This
, aOwner
);
420 return nsIChannel_GetOwner(This
->channel
, aOwner
);
423 nsISupports_AddRef(This
->owner
);
424 *aOwner
= This
->owner
;
429 static nsresult NSAPI
nsChannel_SetOwner(nsIHttpChannel
*iface
, nsISupports
*aOwner
)
431 nsChannel
*This
= NSCHANNEL_THIS(iface
);
433 TRACE("(%p)->(%p)\n", This
, aOwner
);
436 return nsIChannel_SetOwner(This
->channel
, aOwner
);
439 nsISupports_AddRef(aOwner
);
441 nsISupports_Release(This
->owner
);
442 This
->owner
= aOwner
;
447 static nsresult NSAPI
nsChannel_GetNotificationCallbacks(nsIHttpChannel
*iface
,
448 nsIInterfaceRequestor
**aNotificationCallbacks
)
450 nsChannel
*This
= NSCHANNEL_THIS(iface
);
452 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
454 if(This
->notif_callback
)
455 nsIInterfaceRequestor_AddRef(This
->notif_callback
);
456 *aNotificationCallbacks
= This
->notif_callback
;
461 static nsresult NSAPI
nsChannel_SetNotificationCallbacks(nsIHttpChannel
*iface
,
462 nsIInterfaceRequestor
*aNotificationCallbacks
)
464 nsChannel
*This
= NSCHANNEL_THIS(iface
);
466 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
468 if(This
->notif_callback
)
469 nsIInterfaceRequestor_Release(This
->notif_callback
);
470 if(aNotificationCallbacks
)
471 nsIInterfaceRequestor_AddRef(aNotificationCallbacks
);
473 This
->notif_callback
= aNotificationCallbacks
;
476 return nsIChannel_SetNotificationCallbacks(This
->channel
, aNotificationCallbacks
);
480 static nsresult NSAPI
nsChannel_GetSecurityInfo(nsIHttpChannel
*iface
, nsISupports
**aSecurityInfo
)
482 nsChannel
*This
= NSCHANNEL_THIS(iface
);
484 TRACE("(%p)->(%p)\n", This
, aSecurityInfo
);
487 return nsIChannel_GetSecurityInfo(This
->channel
, aSecurityInfo
);
489 FIXME("default action not implemented\n");
490 return NS_ERROR_NOT_IMPLEMENTED
;
493 static nsresult NSAPI
nsChannel_GetContentType(nsIHttpChannel
*iface
, nsACString
*aContentType
)
495 nsChannel
*This
= NSCHANNEL_THIS(iface
);
497 TRACE("(%p)->(%p)\n", This
, aContentType
);
499 if(This
->content_type
) {
500 nsACString_SetData(aContentType
, This
->content_type
);
505 return nsIChannel_GetContentType(This
->channel
, aContentType
);
507 TRACE("returning default text/html\n");
508 nsACString_SetData(aContentType
, "text/html");
512 static nsresult NSAPI
nsChannel_SetContentType(nsIHttpChannel
*iface
,
513 const nsACString
*aContentType
)
515 nsChannel
*This
= NSCHANNEL_THIS(iface
);
516 const char *content_type
;
518 TRACE("(%p)->(%p)\n", This
, aContentType
);
520 nsACString_GetData(aContentType
, &content_type
);
522 TRACE("content_type %s\n", content_type
);
524 heap_free(This
->content_type
);
525 This
->content_type
= heap_strdupA(content_type
);
528 return nsIChannel_SetContentType(This
->channel
, aContentType
);
533 static nsresult NSAPI
nsChannel_GetContentCharset(nsIHttpChannel
*iface
,
534 nsACString
*aContentCharset
)
536 nsChannel
*This
= NSCHANNEL_THIS(iface
);
538 TRACE("(%p)->(%p)\n", This
, aContentCharset
);
541 nsACString_SetData(aContentCharset
, This
->charset
);
546 nsresult nsres
= nsIChannel_GetContentCharset(This
->channel
, aContentCharset
);
548 nsACString_GetData(aContentCharset
, &ch
);
552 nsACString_SetData(aContentCharset
, "");
556 static nsresult NSAPI
nsChannel_SetContentCharset(nsIHttpChannel
*iface
,
557 const nsACString
*aContentCharset
)
559 nsChannel
*This
= NSCHANNEL_THIS(iface
);
561 TRACE("(%p)->(%p)\n", This
, aContentCharset
);
564 return nsIChannel_SetContentCharset(This
->channel
, aContentCharset
);
566 FIXME("default action not implemented\n");
567 return NS_ERROR_NOT_IMPLEMENTED
;
570 static nsresult NSAPI
nsChannel_GetContentLength(nsIHttpChannel
*iface
, PRInt32
*aContentLength
)
572 nsChannel
*This
= NSCHANNEL_THIS(iface
);
574 TRACE("(%p)->(%p)\n", This
, aContentLength
);
577 return nsIChannel_GetContentLength(This
->channel
, aContentLength
);
579 FIXME("default action not implemented\n");
580 return NS_ERROR_NOT_IMPLEMENTED
;
583 static nsresult NSAPI
nsChannel_SetContentLength(nsIHttpChannel
*iface
, PRInt32 aContentLength
)
585 nsChannel
*This
= NSCHANNEL_THIS(iface
);
587 TRACE("(%p)->(%d)\n", This
, aContentLength
);
590 return nsIChannel_SetContentLength(This
->channel
, aContentLength
);
592 FIXME("default action not implemented\n");
593 return NS_ERROR_NOT_IMPLEMENTED
;
596 static nsresult NSAPI
nsChannel_Open(nsIHttpChannel
*iface
, nsIInputStream
**_retval
)
598 nsChannel
*This
= NSCHANNEL_THIS(iface
);
600 TRACE("(%p)->(%p)\n", This
, _retval
);
603 return nsIChannel_Open(This
->channel
, _retval
);
605 FIXME("default action not implemented\n");
606 return NS_ERROR_NOT_IMPLEMENTED
;
609 static BOOL
do_load_from_moniker_hack(nsChannel
*This
)
611 nsACString scheme_str
;
616 * We should always load the page from IMoniker, but Wine is not yet
617 * ready for this. This function is a heuristic, that decides which
618 * way of loading is better (Gecko implementation or IMoniker). The
619 * aim is to always return TRUE.
622 /* Load from moniker if there is no Gecko channel available */
626 nsACString_Init(&scheme_str
, NULL
);
627 nsres
= nsIWineURI_GetScheme(This
->uri
, &scheme_str
);
629 if(NS_SUCCEEDED(nsres
)) {
632 nsACString_GetData(&scheme_str
, &scheme
);
633 ret
= !strcmp(scheme
, "wine") || !strcmp(scheme
, "about");
636 nsACString_Finish(&scheme_str
);
640 static HRESULT
create_mon_for_nschannel(nsChannel
*channel
, IMoniker
**mon
)
642 nsIWineURI
*wine_uri
;
647 if(!channel
->original_uri
) {
648 ERR("original_uri == NULL\n");
652 nsres
= nsIURI_QueryInterface(channel
->original_uri
, &IID_nsIWineURI
, (void**)&wine_uri
);
653 if(NS_FAILED(nsres
)) {
654 ERR("Could not get nsIWineURI: %08x\n", nsres
);
658 nsIWineURI_GetWineURL(wine_uri
, &wine_url
);
659 nsIWineURI_Release(wine_uri
);
661 TRACE("wine_url == NULL\n");
665 hres
= CreateURLMoniker(NULL
, wine_url
, mon
);
667 WARN("CreateURLMonikrer failed: %08x\n", hres
);
672 static NSContainer
*get_nscontainer_from_load_group(nsChannel
*This
)
674 NSContainer
*container
;
677 nsIWineURI
*wine_uri
;
681 nsres
= nsILoadGroup_GetDefaultLoadRequest(This
->load_group
, &req
);
682 if(NS_FAILED(nsres
)) {
683 ERR("GetDefaultLoadRequest failed: %08x\n", nsres
);
690 nsres
= nsIRequest_QueryInterface(req
, &IID_nsIChannel
, (void**)&channel
);
691 nsIRequest_Release(req
);
692 if(NS_FAILED(nsres
)) {
693 WARN("Could not get nsIChannel interface: %08x\n", nsres
);
697 nsres
= nsIChannel_GetURI(channel
, &uri
);
698 nsIChannel_Release(channel
);
699 if(NS_FAILED(nsres
)) {
700 ERR("GetURI failed: %08x\n", nsres
);
704 nsres
= nsIURI_QueryInterface(uri
, &IID_nsIWineURI
, (void**)&wine_uri
);
706 if(NS_FAILED(nsres
)) {
707 TRACE("Could not get nsIWineURI: %08x\n", nsres
);
711 nsIWineURI_GetNSContainer(wine_uri
, &container
);
712 nsIWineURI_Release(wine_uri
);
717 static nsresult
async_open_doc_uri(nsChannel
*This
, NSContainer
*container
,
718 nsIStreamListener
*listener
, nsISupports
*context
, BOOL
*open
)
725 if(container
->bscallback
) {
726 channelbsc_set_channel(container
->bscallback
, This
, listener
, context
);
728 if(container
->doc
&& container
->doc
->mime
) {
729 heap_free(This
->content_type
);
730 This
->content_type
= heap_strdupWtoA(container
->doc
->mime
);
733 if(do_load_from_moniker_hack(This
))
734 return WINE_NS_LOAD_FROM_MONIKER
;
736 BOOL cont
= before_async_open(This
, container
);
740 return NS_ERROR_UNEXPECTED
;
743 if(!container
->doc
) {
745 ? nsIChannel_AsyncOpen(This
->channel
, listener
, context
)
746 : NS_ERROR_UNEXPECTED
;
749 hres
= create_mon_for_nschannel(This
, &mon
);
751 return NS_ERROR_UNEXPECTED
;
753 set_current_mon(container
->doc
, mon
);
760 static nsresult
async_open(nsChannel
*This
, NSContainer
*container
, nsIStreamListener
*listener
,
761 nsISupports
*context
)
763 nsChannelBSC
*bscallback
;
764 IMoniker
*mon
= NULL
;
770 nsres
= nsIChannel_AsyncOpen(This
->channel
, listener
, context
);
773 IMoniker_Release(mon
);
775 if(NS_FAILED(nsres
) && (This
->load_flags
& LOAD_INITIAL_DOCUMENT_URI
))
776 return WINE_NS_LOAD_FROM_MONIKER
;
780 TRACE("channel == NULL\n");
782 hres
= create_mon_for_nschannel(This
, &mon
);
784 return NS_ERROR_UNEXPECTED
;
786 bscallback
= create_channelbsc(mon
);
787 IMoniker_Release(mon
);
789 channelbsc_set_channel(bscallback
, This
, listener
, context
);
791 task
= heap_alloc(sizeof(task_t
));
793 task
->doc
= container
->doc
;
794 task
->task_id
= TASK_START_BINDING
;
796 task
->bscallback
= bscallback
;
803 static nsresult NSAPI
nsChannel_AsyncOpen(nsIHttpChannel
*iface
, nsIStreamListener
*aListener
,
804 nsISupports
*aContext
)
806 nsChannel
*This
= NSCHANNEL_THIS(iface
);
807 NSContainer
*container
;
810 nsresult nsres
= NS_OK
;
812 TRACE("(%p)->(%p %p)\n", This
, aListener
, aContext
);
814 nsIWineURI_GetNSContainer(This
->uri
, &container
);
816 if(!container
&& This
->load_group
) {
817 container
= get_nscontainer_from_load_group(This
);
819 nsIWineURI_SetNSContainer(This
->uri
, container
);
823 TRACE("container = NULL\n");
825 ? nsIChannel_AsyncOpen(This
->channel
, aListener
, aContext
)
826 : NS_ERROR_UNEXPECTED
;
829 nsIWineURI_GetIsDocumentURI(This
->uri
, &is_doc_uri
);
831 if(is_doc_uri
&& (This
->load_flags
& LOAD_INITIAL_DOCUMENT_URI
))
832 nsres
= async_open_doc_uri(This
, container
, aListener
, aContext
, &open
);
835 nsres
= async_open(This
, container
, aListener
, aContext
);
837 nsIWebBrowserChrome_Release(NSWBCHROME(container
));
841 static nsresult NSAPI
nsChannel_GetRequestMethod(nsIHttpChannel
*iface
, nsACString
*aRequestMethod
)
843 nsChannel
*This
= NSCHANNEL_THIS(iface
);
845 TRACE("(%p)->(%p)\n", This
, aRequestMethod
);
847 if(This
->http_channel
)
848 return nsIHttpChannel_GetRequestMethod(This
->http_channel
, aRequestMethod
);
850 return NS_ERROR_NOT_IMPLEMENTED
;
853 static nsresult NSAPI
nsChannel_SetRequestMethod(nsIHttpChannel
*iface
,
854 const nsACString
*aRequestMethod
)
856 nsChannel
*This
= NSCHANNEL_THIS(iface
);
858 TRACE("(%p)->(%p)\n", This
, aRequestMethod
);
860 if(This
->http_channel
)
861 return nsIHttpChannel_SetRequestMethod(This
->http_channel
, aRequestMethod
);
863 return NS_ERROR_NOT_IMPLEMENTED
;
866 static nsresult NSAPI
nsChannel_GetReferrer(nsIHttpChannel
*iface
, nsIURI
**aReferrer
)
868 nsChannel
*This
= NSCHANNEL_THIS(iface
);
870 TRACE("(%p)->(%p)\n", This
, aReferrer
);
872 if(This
->http_channel
)
873 return nsIHttpChannel_GetReferrer(This
->http_channel
, aReferrer
);
875 return NS_ERROR_NOT_IMPLEMENTED
;
878 static nsresult NSAPI
nsChannel_SetReferrer(nsIHttpChannel
*iface
, nsIURI
*aReferrer
)
880 nsChannel
*This
= NSCHANNEL_THIS(iface
);
882 TRACE("(%p)->(%p)\n", This
, aReferrer
);
884 if(This
->http_channel
)
885 return nsIHttpChannel_SetReferrer(This
->http_channel
, aReferrer
);
887 return NS_ERROR_NOT_IMPLEMENTED
;
890 static nsresult NSAPI
nsChannel_GetRequestHeader(nsIHttpChannel
*iface
,
891 const nsACString
*aHeader
, nsACString
*_retval
)
893 nsChannel
*This
= NSCHANNEL_THIS(iface
);
895 TRACE("(%p)->(%p %p)\n", This
, aHeader
, _retval
);
897 if(This
->http_channel
)
898 return nsIHttpChannel_GetRequestHeader(This
->http_channel
, aHeader
, _retval
);
900 return NS_ERROR_NOT_IMPLEMENTED
;
903 static nsresult NSAPI
nsChannel_SetRequestHeader(nsIHttpChannel
*iface
,
904 const nsACString
*aHeader
, const nsACString
*aValue
, PRBool aMerge
)
906 nsChannel
*This
= NSCHANNEL_THIS(iface
);
908 TRACE("(%p)->(%p %p %x)\n", This
, aHeader
, aValue
, aMerge
);
910 if(This
->http_channel
)
911 return nsIHttpChannel_SetRequestHeader(This
->http_channel
, aHeader
, aValue
, aMerge
);
913 return NS_ERROR_NOT_IMPLEMENTED
;
916 static nsresult NSAPI
nsChannel_VisitRequestHeaders(nsIHttpChannel
*iface
,
917 nsIHttpHeaderVisitor
*aVisitor
)
919 nsChannel
*This
= NSCHANNEL_THIS(iface
);
921 TRACE("(%p)->(%p)\n", This
, aVisitor
);
923 if(This
->http_channel
)
924 return nsIHttpChannel_VisitRequestHeaders(This
->http_channel
, aVisitor
);
926 return NS_ERROR_NOT_IMPLEMENTED
;
929 static nsresult NSAPI
nsChannel_GetAllowPipelining(nsIHttpChannel
*iface
, PRBool
*aAllowPipelining
)
931 nsChannel
*This
= NSCHANNEL_THIS(iface
);
933 TRACE("(%p)->(%p)\n", This
, aAllowPipelining
);
935 if(This
->http_channel
)
936 return nsIHttpChannel_GetAllowPipelining(This
->http_channel
, aAllowPipelining
);
938 return NS_ERROR_NOT_IMPLEMENTED
;
941 static nsresult NSAPI
nsChannel_SetAllowPipelining(nsIHttpChannel
*iface
, PRBool aAllowPipelining
)
943 nsChannel
*This
= NSCHANNEL_THIS(iface
);
945 TRACE("(%p)->(%x)\n", This
, aAllowPipelining
);
947 if(This
->http_channel
)
948 return nsIHttpChannel_SetAllowPipelining(This
->http_channel
, aAllowPipelining
);
950 return NS_ERROR_NOT_IMPLEMENTED
;
953 static nsresult NSAPI
nsChannel_GetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32
*aRedirectionLimit
)
955 nsChannel
*This
= NSCHANNEL_THIS(iface
);
957 TRACE("(%p)->(%p)\n", This
, aRedirectionLimit
);
959 if(This
->http_channel
)
960 return nsIHttpChannel_GetRedirectionLimit(This
->http_channel
, aRedirectionLimit
);
962 return NS_ERROR_NOT_IMPLEMENTED
;
965 static nsresult NSAPI
nsChannel_SetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32 aRedirectionLimit
)
967 nsChannel
*This
= NSCHANNEL_THIS(iface
);
969 TRACE("(%p)->(%u)\n", This
, aRedirectionLimit
);
971 if(This
->http_channel
)
972 return nsIHttpChannel_SetRedirectionLimit(This
->http_channel
, aRedirectionLimit
);
974 return NS_ERROR_NOT_IMPLEMENTED
;
977 static nsresult NSAPI
nsChannel_GetResponseStatus(nsIHttpChannel
*iface
, PRUint32
*aResponseStatus
)
979 nsChannel
*This
= NSCHANNEL_THIS(iface
);
981 TRACE("(%p)->(%p)\n", This
, aResponseStatus
);
983 if(This
->http_channel
)
984 return nsIHttpChannel_GetResponseStatus(This
->http_channel
, aResponseStatus
);
986 return NS_ERROR_NOT_IMPLEMENTED
;
989 static nsresult NSAPI
nsChannel_GetResponseStatusText(nsIHttpChannel
*iface
,
990 nsACString
*aResponseStatusText
)
992 nsChannel
*This
= NSCHANNEL_THIS(iface
);
994 TRACE("(%p)->(%p)\n", This
, aResponseStatusText
);
996 if(This
->http_channel
)
997 return nsIHttpChannel_GetResponseStatusText(This
->http_channel
, aResponseStatusText
);
999 return NS_ERROR_NOT_IMPLEMENTED
;
1002 static nsresult NSAPI
nsChannel_GetRequestSucceeded(nsIHttpChannel
*iface
,
1003 PRBool
*aRequestSucceeded
)
1005 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1007 TRACE("(%p)->(%p)\n", This
, aRequestSucceeded
);
1009 if(This
->http_channel
)
1010 return nsIHttpChannel_GetRequestSucceeded(This
->http_channel
, aRequestSucceeded
);
1012 return NS_ERROR_NOT_IMPLEMENTED
;
1015 static nsresult NSAPI
nsChannel_GetResponseHeader(nsIHttpChannel
*iface
,
1016 const nsACString
*header
, nsACString
*_retval
)
1018 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1020 TRACE("(%p)->(%p %p)\n", This
, header
, _retval
);
1022 if(This
->http_channel
)
1023 return nsIHttpChannel_GetResponseHeader(This
->http_channel
, header
, _retval
);
1025 return NS_ERROR_NOT_IMPLEMENTED
;
1028 static nsresult NSAPI
nsChannel_SetResponseHeader(nsIHttpChannel
*iface
,
1029 const nsACString
*header
, const nsACString
*value
, PRBool merge
)
1031 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1033 TRACE("(%p)->(%p %p %x)\n", This
, header
, value
, merge
);
1035 if(This
->http_channel
)
1036 return nsIHttpChannel_SetResponseHeader(This
->http_channel
, header
, value
, merge
);
1038 return NS_ERROR_NOT_IMPLEMENTED
;
1041 static nsresult NSAPI
nsChannel_VisitResponseHeaders(nsIHttpChannel
*iface
,
1042 nsIHttpHeaderVisitor
*aVisitor
)
1044 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1046 TRACE("(%p)->(%p)\n", This
, aVisitor
);
1048 if(This
->http_channel
)
1049 return nsIHttpChannel_VisitResponseHeaders(This
->http_channel
, aVisitor
);
1051 return NS_ERROR_NOT_IMPLEMENTED
;
1054 static nsresult NSAPI
nsChannel_IsNoStoreResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1056 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1058 TRACE("(%p)->(%p)\n", This
, _retval
);
1060 if(This
->http_channel
)
1061 return nsIHttpChannel_IsNoStoreResponse(This
->http_channel
, _retval
);
1063 return NS_ERROR_NOT_IMPLEMENTED
;
1066 static nsresult NSAPI
nsChannel_IsNoCacheResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1068 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1070 TRACE("(%p)->(%p)\n", This
, _retval
);
1072 if(This
->http_channel
)
1073 return nsIHttpChannel_IsNoCacheResponse(This
->http_channel
, _retval
);
1075 return NS_ERROR_NOT_IMPLEMENTED
;
1078 #undef NSCHANNEL_THIS
1080 static const nsIHttpChannelVtbl nsChannelVtbl
= {
1081 nsChannel_QueryInterface
,
1085 nsChannel_IsPending
,
1086 nsChannel_GetStatus
,
1090 nsChannel_GetLoadGroup
,
1091 nsChannel_SetLoadGroup
,
1092 nsChannel_GetLoadFlags
,
1093 nsChannel_SetLoadFlags
,
1094 nsChannel_GetOriginalURI
,
1095 nsChannel_SetOriginalURI
,
1099 nsChannel_GetNotificationCallbacks
,
1100 nsChannel_SetNotificationCallbacks
,
1101 nsChannel_GetSecurityInfo
,
1102 nsChannel_GetContentType
,
1103 nsChannel_SetContentType
,
1104 nsChannel_GetContentCharset
,
1105 nsChannel_SetContentCharset
,
1106 nsChannel_GetContentLength
,
1107 nsChannel_SetContentLength
,
1109 nsChannel_AsyncOpen
,
1110 nsChannel_GetRequestMethod
,
1111 nsChannel_SetRequestMethod
,
1112 nsChannel_GetReferrer
,
1113 nsChannel_SetReferrer
,
1114 nsChannel_GetRequestHeader
,
1115 nsChannel_SetRequestHeader
,
1116 nsChannel_VisitRequestHeaders
,
1117 nsChannel_GetAllowPipelining
,
1118 nsChannel_SetAllowPipelining
,
1119 nsChannel_GetRedirectionLimit
,
1120 nsChannel_SetRedirectionLimit
,
1121 nsChannel_GetResponseStatus
,
1122 nsChannel_GetResponseStatusText
,
1123 nsChannel_GetRequestSucceeded
,
1124 nsChannel_GetResponseHeader
,
1125 nsChannel_SetResponseHeader
,
1126 nsChannel_VisitResponseHeaders
,
1127 nsChannel_IsNoStoreResponse
,
1128 nsChannel_IsNoCacheResponse
1131 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1133 static nsresult NSAPI
nsUploadChannel_QueryInterface(nsIUploadChannel
*iface
, nsIIDRef riid
,
1136 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1137 return nsIChannel_QueryInterface(NSCHANNEL(This
), riid
, result
);
1140 static nsrefcnt NSAPI
nsUploadChannel_AddRef(nsIUploadChannel
*iface
)
1142 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1143 return nsIChannel_AddRef(NSCHANNEL(This
));
1146 static nsrefcnt NSAPI
nsUploadChannel_Release(nsIUploadChannel
*iface
)
1148 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1149 return nsIChannel_Release(NSCHANNEL(This
));
1152 static nsresult NSAPI
nsUploadChannel_SetUploadStream(nsIUploadChannel
*iface
,
1153 nsIInputStream
*aStream
, const nsACString
*aContentType
, PRInt32 aContentLength
)
1155 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1156 const char *content_type
;
1159 TRACE("(%p)->(%p %p %d)\n", This
, aStream
, aContentType
, aContentLength
);
1161 if(This
->post_data_stream
)
1162 nsIInputStream_Release(This
->post_data_stream
);
1165 nsACString_GetData(aContentType
, &content_type
);
1167 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type
));
1170 if(aContentLength
!= -1)
1171 FIXME("Unsupported acontentLength = %d\n", aContentLength
);
1173 if(This
->post_data_stream
)
1174 nsIInputStream_Release(This
->post_data_stream
);
1175 This
->post_data_stream
= aStream
;
1177 nsIInputStream_AddRef(aStream
);
1179 if(This
->post_data_stream
) {
1180 nsIUploadChannel
*upload_channel
;
1182 nsres
= nsIChannel_QueryInterface(This
->channel
, &IID_nsIUploadChannel
,
1183 (void**)&upload_channel
);
1184 if(NS_SUCCEEDED(nsres
)) {
1185 nsres
= nsIUploadChannel_SetUploadStream(upload_channel
, aStream
, aContentType
, aContentLength
);
1186 nsIUploadChannel_Release(upload_channel
);
1187 if(NS_FAILED(nsres
))
1188 WARN("SetUploadStream failed: %08x\n", nsres
);
1196 static nsresult NSAPI
nsUploadChannel_GetUploadStream(nsIUploadChannel
*iface
,
1197 nsIInputStream
**aUploadStream
)
1199 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1201 TRACE("(%p)->(%p)\n", This
, aUploadStream
);
1203 if(This
->post_data_stream
)
1204 nsIInputStream_AddRef(This
->post_data_stream
);
1206 *aUploadStream
= This
->post_data_stream
;
1210 #undef NSUPCHANNEL_THIS
1212 static const nsIUploadChannelVtbl nsUploadChannelVtbl
= {
1213 nsUploadChannel_QueryInterface
,
1214 nsUploadChannel_AddRef
,
1215 nsUploadChannel_Release
,
1216 nsUploadChannel_SetUploadStream
,
1217 nsUploadChannel_GetUploadStream
1220 #define NSURI_THIS(iface) DEFINE_THIS(nsURI, WineURI, iface)
1222 static nsresult NSAPI
nsURI_QueryInterface(nsIWineURI
*iface
, nsIIDRef riid
, nsQIResult result
)
1224 nsURI
*This
= NSURI_THIS(iface
);
1228 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1229 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1230 *result
= NSURI(This
);
1231 }else if(IsEqualGUID(&IID_nsIURI
, riid
)) {
1232 TRACE("(%p)->(IID_nsIURI %p)\n", This
, result
);
1233 *result
= NSURI(This
);
1234 }else if(IsEqualGUID(&IID_nsIWineURI
, riid
)) {
1235 TRACE("(%p)->(IID_nsIWineURI %p)\n", This
, result
);
1236 *result
= NSURI(This
);
1240 nsIURI_AddRef(NSURI(This
));
1244 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1245 return This
->uri
? nsIURI_QueryInterface(This
->uri
, riid
, result
) : NS_NOINTERFACE
;
1248 static nsrefcnt NSAPI
nsURI_AddRef(nsIWineURI
*iface
)
1250 nsURI
*This
= NSURI_THIS(iface
);
1251 LONG ref
= InterlockedIncrement(&This
->ref
);
1253 TRACE("(%p) ref=%d\n", This
, ref
);
1258 static nsrefcnt NSAPI
nsURI_Release(nsIWineURI
*iface
)
1260 nsURI
*This
= NSURI_THIS(iface
);
1261 LONG ref
= InterlockedDecrement(&This
->ref
);
1263 TRACE("(%p) ref=%d\n", This
, ref
);
1267 nsIWebBrowserChrome_Release(NSWBCHROME(This
->container
));
1269 nsIURI_Release(This
->uri
);
1270 heap_free(This
->wine_url
);
1277 static nsresult NSAPI
nsURI_GetSpec(nsIWineURI
*iface
, nsACString
*aSpec
)
1279 nsURI
*This
= NSURI_THIS(iface
);
1281 TRACE("(%p)->(%p)\n", This
, aSpec
);
1283 if(This
->use_wine_url
) {
1284 char speca
[INTERNET_MAX_URL_LENGTH
] = "wine:";
1285 WideCharToMultiByte(CP_ACP
, 0, This
->wine_url
, -1, speca
+5, sizeof(speca
)-5, NULL
, NULL
);
1286 nsACString_SetData(aSpec
, speca
);
1292 return nsIURI_GetSpec(This
->uri
, aSpec
);
1294 TRACE("returning error\n");
1295 return NS_ERROR_NOT_IMPLEMENTED
;
1299 static nsresult NSAPI
nsURI_SetSpec(nsIWineURI
*iface
, const nsACString
*aSpec
)
1301 nsURI
*This
= NSURI_THIS(iface
);
1303 TRACE("(%p)->(%p)\n", This
, aSpec
);
1306 return nsIURI_SetSpec(This
->uri
, aSpec
);
1308 FIXME("default action not implemented\n");
1309 return NS_ERROR_NOT_IMPLEMENTED
;
1312 static nsresult NSAPI
nsURI_GetPrePath(nsIWineURI
*iface
, nsACString
*aPrePath
)
1314 nsURI
*This
= NSURI_THIS(iface
);
1316 TRACE("(%p)->(%p)\n", This
, aPrePath
);
1319 return nsIURI_GetPrePath(This
->uri
, aPrePath
);
1321 FIXME("default action not implemented\n");
1322 return NS_ERROR_NOT_IMPLEMENTED
;
1325 static nsresult NSAPI
nsURI_GetScheme(nsIWineURI
*iface
, nsACString
*aScheme
)
1327 nsURI
*This
= NSURI_THIS(iface
);
1329 TRACE("(%p)->(%p)\n", This
, aScheme
);
1331 if(This
->use_wine_url
&& strcmpW(This
->wine_url
, about_blankW
)) {
1333 * For Gecko we set scheme to unknown so it won't be handled
1334 * as any special case.
1336 nsACString_SetData(aScheme
, "wine");
1341 return nsIURI_GetScheme(This
->uri
, aScheme
);
1343 TRACE("returning error\n");
1344 return NS_ERROR_NOT_IMPLEMENTED
;
1347 static nsresult NSAPI
nsURI_SetScheme(nsIWineURI
*iface
, const nsACString
*aScheme
)
1349 nsURI
*This
= NSURI_THIS(iface
);
1351 TRACE("(%p)->(%p)\n", This
, aScheme
);
1354 return nsIURI_SetScheme(This
->uri
, aScheme
);
1356 FIXME("default action not implemented\n");
1357 return NS_ERROR_NOT_IMPLEMENTED
;
1360 static nsresult NSAPI
nsURI_GetUserPass(nsIWineURI
*iface
, nsACString
*aUserPass
)
1362 nsURI
*This
= NSURI_THIS(iface
);
1364 TRACE("(%p)->(%p)\n", This
, aUserPass
);
1367 return nsIURI_GetUserPass(This
->uri
, aUserPass
);
1369 FIXME("default action not implemented\n");
1370 return NS_ERROR_NOT_IMPLEMENTED
;
1373 static nsresult NSAPI
nsURI_SetUserPass(nsIWineURI
*iface
, const nsACString
*aUserPass
)
1375 nsURI
*This
= NSURI_THIS(iface
);
1377 TRACE("(%p)->(%p)\n", This
, aUserPass
);
1380 return nsIURI_SetUserPass(This
->uri
, aUserPass
);
1382 FIXME("default action not implemented\n");
1383 return NS_ERROR_NOT_IMPLEMENTED
;
1386 static nsresult NSAPI
nsURI_GetUsername(nsIWineURI
*iface
, nsACString
*aUsername
)
1388 nsURI
*This
= NSURI_THIS(iface
);
1390 TRACE("(%p)->(%p)\n", This
, aUsername
);
1393 return nsIURI_GetUsername(This
->uri
, aUsername
);
1395 FIXME("default action not implemented\n");
1396 return NS_ERROR_NOT_IMPLEMENTED
;
1399 static nsresult NSAPI
nsURI_SetUsername(nsIWineURI
*iface
, const nsACString
*aUsername
)
1401 nsURI
*This
= NSURI_THIS(iface
);
1403 TRACE("(%p)->(%p)\n", This
, aUsername
);
1406 return nsIURI_SetUsername(This
->uri
, aUsername
);
1408 FIXME("default action not implemented\n");
1409 return NS_ERROR_NOT_IMPLEMENTED
;
1412 static nsresult NSAPI
nsURI_GetPassword(nsIWineURI
*iface
, nsACString
*aPassword
)
1414 nsURI
*This
= NSURI_THIS(iface
);
1416 TRACE("(%p)->(%p)\n", This
, aPassword
);
1419 return nsIURI_GetPassword(This
->uri
, aPassword
);
1421 FIXME("default action not implemented\n");
1422 return NS_ERROR_NOT_IMPLEMENTED
;
1425 static nsresult NSAPI
nsURI_SetPassword(nsIWineURI
*iface
, const nsACString
*aPassword
)
1427 nsURI
*This
= NSURI_THIS(iface
);
1429 TRACE("(%p)->(%p)\n", This
, aPassword
);
1432 return nsIURI_SetPassword(This
->uri
, aPassword
);
1434 FIXME("default action not implemented\n");
1435 return NS_ERROR_NOT_IMPLEMENTED
;
1438 static nsresult NSAPI
nsURI_GetHostPort(nsIWineURI
*iface
, nsACString
*aHostPort
)
1440 nsURI
*This
= NSURI_THIS(iface
);
1442 TRACE("(%p)->(%p)\n", This
, aHostPort
);
1445 return nsIURI_GetHostPort(This
->uri
, aHostPort
);
1447 FIXME("default action not implemented\n");
1448 return NS_ERROR_NOT_IMPLEMENTED
;
1451 static nsresult NSAPI
nsURI_SetHostPort(nsIWineURI
*iface
, const nsACString
*aHostPort
)
1453 nsURI
*This
= NSURI_THIS(iface
);
1455 TRACE("(%p)->(%p)\n", This
, aHostPort
);
1458 return nsIURI_SetHostPort(This
->uri
, aHostPort
);
1460 FIXME("default action not implemented\n");
1461 return NS_ERROR_NOT_IMPLEMENTED
;
1464 static nsresult NSAPI
nsURI_GetHost(nsIWineURI
*iface
, nsACString
*aHost
)
1466 nsURI
*This
= NSURI_THIS(iface
);
1468 TRACE("(%p)->(%p)\n", This
, aHost
);
1471 return nsIURI_GetHost(This
->uri
, aHost
);
1473 FIXME("default action not implemented\n");
1474 return NS_ERROR_NOT_IMPLEMENTED
;
1477 static nsresult NSAPI
nsURI_SetHost(nsIWineURI
*iface
, const nsACString
*aHost
)
1479 nsURI
*This
= NSURI_THIS(iface
);
1481 TRACE("(%p)->(%p)\n", This
, aHost
);
1484 return nsIURI_SetHost(This
->uri
, aHost
);
1486 FIXME("default action not implemented\n");
1487 return NS_ERROR_NOT_IMPLEMENTED
;
1490 static nsresult NSAPI
nsURI_GetPort(nsIWineURI
*iface
, PRInt32
*aPort
)
1492 nsURI
*This
= NSURI_THIS(iface
);
1494 TRACE("(%p)->(%p)\n", This
, aPort
);
1497 return nsIURI_GetPort(This
->uri
, aPort
);
1499 FIXME("default action not implemented\n");
1500 return NS_ERROR_NOT_IMPLEMENTED
;
1503 static nsresult NSAPI
nsURI_SetPort(nsIWineURI
*iface
, PRInt32 aPort
)
1505 nsURI
*This
= NSURI_THIS(iface
);
1507 TRACE("(%p)->(%d)\n", This
, aPort
);
1510 return nsIURI_SetPort(This
->uri
, aPort
);
1512 FIXME("default action not implemented\n");
1513 return NS_ERROR_NOT_IMPLEMENTED
;
1516 static nsresult NSAPI
nsURI_GetPath(nsIWineURI
*iface
, nsACString
*aPath
)
1518 nsURI
*This
= NSURI_THIS(iface
);
1520 TRACE("(%p)->(%p)\n", This
, aPath
);
1523 return nsIURI_GetPath(This
->uri
, aPath
);
1525 FIXME("default action not implemented\n");
1526 return NS_ERROR_NOT_IMPLEMENTED
;
1529 static nsresult NSAPI
nsURI_SetPath(nsIWineURI
*iface
, const nsACString
*aPath
)
1531 nsURI
*This
= NSURI_THIS(iface
);
1534 nsACString_GetData(aPath
, &path
);
1535 TRACE("(%p)->(%p(%s))\n", This
, aPath
, debugstr_a(path
));
1538 if(This
->wine_url
) {
1539 WCHAR new_url
[INTERNET_MAX_URL_LENGTH
];
1540 DWORD size
= sizeof(new_url
)/sizeof(WCHAR
);
1544 pathw
= heap_strdupAtoW(path
);
1545 hres
= UrlCombineW(This
->wine_url
, pathw
, new_url
, &size
, 0);
1548 nsIWineURI_SetWineURL(NSWINEURI(This
), new_url
);
1550 WARN("UrlCombine failed: %08x\n", hres
);
1556 return nsIURI_SetPath(This
->uri
, aPath
);
1559 static nsresult NSAPI
nsURI_Equals(nsIWineURI
*iface
, nsIURI
*other
, PRBool
*_retval
)
1561 nsURI
*This
= NSURI_THIS(iface
);
1562 nsIWineURI
*wine_uri
;
1563 LPCWSTR other_url
= NULL
;
1566 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
1569 return nsIURI_Equals(This
->uri
, other
, _retval
);
1571 nsres
= nsIURI_QueryInterface(other
, &IID_nsIWineURI
, (void**)&wine_uri
);
1572 if(NS_FAILED(nsres
)) {
1573 TRACE("Could not get nsIWineURI interface\n");
1578 nsIWineURI_GetWineURL(wine_uri
, &other_url
);
1579 *_retval
= !UrlCompareW(This
->wine_url
, other_url
, TRUE
);
1580 nsIWineURI_Release(wine_uri
);
1585 static nsresult NSAPI
nsURI_SchemeIs(nsIWineURI
*iface
, const char *scheme
, PRBool
*_retval
)
1587 nsURI
*This
= NSURI_THIS(iface
);
1589 TRACE("(%p)->(%s %p)\n", This
, debugstr_a(scheme
), _retval
);
1591 if(This
->use_wine_url
) {
1592 WCHAR buf
[INTERNET_MAX_SCHEME_LENGTH
];
1593 int len
= MultiByteToWideChar(CP_ACP
, 0, scheme
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
))-1;
1595 *_retval
= lstrlenW(This
->wine_url
) > len
1596 && This
->wine_url
[len
] == ':'
1597 && !memcmp(buf
, This
->wine_url
, len
*sizeof(WCHAR
));
1602 return nsIURI_SchemeIs(This
->uri
, scheme
, _retval
);
1604 TRACE("returning error\n");
1605 return NS_ERROR_NOT_IMPLEMENTED
;
1608 static nsresult NSAPI
nsURI_Clone(nsIWineURI
*iface
, nsIURI
**_retval
)
1610 nsURI
*This
= NSURI_THIS(iface
);
1611 nsIURI
*nsuri
= NULL
;
1612 nsIWineURI
*wine_uri
;
1615 TRACE("(%p)->(%p)\n", This
, _retval
);
1618 nsres
= nsIURI_Clone(This
->uri
, &nsuri
);
1619 if(NS_FAILED(nsres
)) {
1620 WARN("Clone failed: %08x\n", nsres
);
1625 nsres
= create_uri(nsuri
, This
->container
, &wine_uri
);
1626 if(NS_FAILED(nsres
)) {
1627 WARN("create_uri failed: %08x\n", nsres
);
1631 *_retval
= (nsIURI
*)wine_uri
;
1632 return nsIWineURI_SetWineURL(wine_uri
, This
->wine_url
);
1635 static nsresult NSAPI
nsURI_Resolve(nsIWineURI
*iface
, const nsACString
*arelativePath
,
1636 nsACString
*_retval
)
1638 nsURI
*This
= NSURI_THIS(iface
);
1640 TRACE("(%p)->(%p %p)\n", This
, arelativePath
, _retval
);
1643 return nsIURI_Resolve(This
->uri
, arelativePath
, _retval
);
1645 FIXME("default action not implemented\n");
1646 return NS_ERROR_NOT_IMPLEMENTED
;
1649 static nsresult NSAPI
nsURI_GetAsciiSpec(nsIWineURI
*iface
, nsACString
*aAsciiSpec
)
1651 nsURI
*This
= NSURI_THIS(iface
);
1653 TRACE("(%p)->(%p)\n", This
, aAsciiSpec
);
1655 if(This
->use_wine_url
)
1656 return nsIURI_GetSpec(NSURI(This
), aAsciiSpec
);
1659 return nsIURI_GetAsciiSpec(This
->uri
, aAsciiSpec
);
1661 TRACE("returning error\n");
1662 return NS_ERROR_NOT_IMPLEMENTED
;
1665 static nsresult NSAPI
nsURI_GetAsciiHost(nsIWineURI
*iface
, nsACString
*aAsciiHost
)
1667 nsURI
*This
= NSURI_THIS(iface
);
1669 TRACE("(%p)->(%p)\n", This
, aAsciiHost
);
1672 return nsIURI_GetAsciiHost(This
->uri
, aAsciiHost
);
1674 FIXME("default action not implemented\n");
1675 return NS_ERROR_NOT_IMPLEMENTED
;
1678 static nsresult NSAPI
nsURI_GetOriginCharset(nsIWineURI
*iface
, nsACString
*aOriginCharset
)
1680 nsURI
*This
= NSURI_THIS(iface
);
1682 TRACE("(%p)->(%p)\n", This
, aOriginCharset
);
1685 return nsIURI_GetOriginCharset(This
->uri
, aOriginCharset
);
1687 FIXME("default action not implemented\n");
1688 return NS_ERROR_NOT_IMPLEMENTED
;
1691 static nsresult NSAPI
nsURI_GetNSContainer(nsIWineURI
*iface
, NSContainer
**aContainer
)
1693 nsURI
*This
= NSURI_THIS(iface
);
1695 TRACE("(%p)->(%p)\n", This
, aContainer
);
1698 nsIWebBrowserChrome_AddRef(NSWBCHROME(This
->container
));
1699 *aContainer
= This
->container
;
1704 static nsresult NSAPI
nsURI_SetNSContainer(nsIWineURI
*iface
, NSContainer
*aContainer
)
1706 nsURI
*This
= NSURI_THIS(iface
);
1708 TRACE("(%p)->(%p)\n", This
, aContainer
);
1710 if(This
->container
) {
1711 if(This
->container
== aContainer
)
1713 TRACE("Changing %p -> %p\n", This
->container
, aContainer
);
1714 nsIWebBrowserChrome_Release(NSWBCHROME(This
->container
));
1718 nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer
));
1719 This
->container
= aContainer
;
1724 static nsresult NSAPI
nsURI_GetIsDocumentURI(nsIWineURI
*iface
, PRBool
*aIsDocumentURI
)
1726 nsURI
*This
= NSURI_THIS(iface
);
1728 TRACE("(%p)->(%p)\n", This
, aIsDocumentURI
);
1730 *aIsDocumentURI
= This
->is_doc_uri
;
1734 static nsresult NSAPI
nsURI_SetIsDocumentURI(nsIWineURI
*iface
, PRBool aIsDocumentURI
)
1736 nsURI
*This
= NSURI_THIS(iface
);
1738 TRACE("(%p)->(%x)\n", This
, aIsDocumentURI
);
1740 This
->is_doc_uri
= aIsDocumentURI
;
1744 static nsresult NSAPI
nsURI_GetWineURL(nsIWineURI
*iface
, LPCWSTR
*aURL
)
1746 nsURI
*This
= NSURI_THIS(iface
);
1748 TRACE("(%p)->(%p)\n", This
, aURL
);
1750 *aURL
= This
->wine_url
;
1754 static nsresult NSAPI
nsURI_SetWineURL(nsIWineURI
*iface
, LPCWSTR aURL
)
1756 nsURI
*This
= NSURI_THIS(iface
);
1758 static const WCHAR wszFtp
[] = {'f','t','p',':'};
1759 static const WCHAR wszHttp
[] = {'h','t','t','p',':'};
1760 static const WCHAR wszHttps
[] = {'h','t','t','p','s',':'};
1762 TRACE("(%p)->(%s)\n", This
, debugstr_w(aURL
));
1764 heap_free(This
->wine_url
);
1767 int len
= strlenW(aURL
)+1;
1768 This
->wine_url
= heap_alloc(len
*sizeof(WCHAR
));
1769 memcpy(This
->wine_url
, aURL
, len
*sizeof(WCHAR
));
1771 /* FIXME: Always use wine url */
1772 This
->use_wine_url
=
1773 strncmpW(aURL
, wszFtp
, sizeof(wszFtp
)/sizeof(WCHAR
))
1774 && strncmpW(aURL
, wszHttp
, sizeof(wszHttp
)/sizeof(WCHAR
))
1775 && strncmpW(aURL
, wszHttps
, sizeof(wszHttps
)/sizeof(WCHAR
));
1777 This
->wine_url
= NULL
;
1778 This
->use_wine_url
= FALSE
;
1786 static const nsIWineURIVtbl nsWineURIVtbl
= {
1787 nsURI_QueryInterface
,
1815 nsURI_GetOriginCharset
,
1816 nsURI_GetNSContainer
,
1817 nsURI_SetNSContainer
,
1818 nsURI_GetIsDocumentURI
,
1819 nsURI_SetIsDocumentURI
,
1824 static nsresult
create_uri(nsIURI
*uri
, NSContainer
*container
, nsIWineURI
**_retval
)
1826 nsURI
*ret
= heap_alloc(sizeof(nsURI
));
1828 ret
->lpWineURIVtbl
= &nsWineURIVtbl
;
1831 ret
->container
= container
;
1832 ret
->wine_url
= NULL
;
1833 ret
->is_doc_uri
= FALSE
;
1834 ret
->use_wine_url
= FALSE
;
1837 nsIWebBrowserChrome_AddRef(NSWBCHROME(container
));
1839 TRACE("retval=%p\n", ret
);
1840 *_retval
= NSWINEURI(ret
);
1845 const nsIProtocolHandlerVtbl
*lpProtocolHandlerVtbl
;
1849 nsIProtocolHandler
*nshandler
;
1850 } nsProtocolHandler
;
1852 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
1854 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
1856 static nsresult NSAPI
nsProtocolHandler_QueryInterface(nsIProtocolHandler
*iface
, nsIIDRef riid
,
1859 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
1863 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1864 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1865 *result
= NSPROTHANDLER(This
);
1866 }else if(IsEqualGUID(&IID_nsIProtocolHandler
, riid
)) {
1867 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This
, result
);
1868 *result
= NSPROTHANDLER(This
);
1869 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler
, riid
)) {
1870 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This
, result
);
1871 return NS_NOINTERFACE
;
1875 nsISupports_AddRef((nsISupports
*)*result
);
1879 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
1880 return NS_NOINTERFACE
;
1883 static nsrefcnt NSAPI
nsProtocolHandler_AddRef(nsIProtocolHandler
*iface
)
1885 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
1886 LONG ref
= InterlockedIncrement(&This
->ref
);
1888 TRACE("(%p) ref=%d\n", This
, ref
);
1893 static nsrefcnt NSAPI
nsProtocolHandler_Release(nsIProtocolHandler
*iface
)
1895 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
1896 LONG ref
= InterlockedDecrement(&This
->ref
);
1898 TRACE("(%p) ref=%d\n", This
, ref
);
1902 nsIProtocolHandler_Release(This
->nshandler
);
1909 static nsresult NSAPI
nsProtocolHandler_GetScheme(nsIProtocolHandler
*iface
, nsACString
*aScheme
)
1911 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
1913 TRACE("(%p)->(%p)\n", This
, aScheme
);
1916 return nsIProtocolHandler_GetScheme(This
->nshandler
, aScheme
);
1917 return NS_ERROR_NOT_IMPLEMENTED
;
1920 static nsresult NSAPI
nsProtocolHandler_GetDefaultPort(nsIProtocolHandler
*iface
,
1921 PRInt32
*aDefaultPort
)
1923 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
1925 TRACE("(%p)->(%p)\n", This
, aDefaultPort
);
1928 return nsIProtocolHandler_GetDefaultPort(This
->nshandler
, aDefaultPort
);
1929 return NS_ERROR_NOT_IMPLEMENTED
;
1932 static nsresult NSAPI
nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler
*iface
,
1933 PRUint32
*aProtocolFlags
)
1935 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
1937 TRACE("(%p)->(%p)\n", This
, aProtocolFlags
);
1940 return nsIProtocolHandler_GetProtocolFlags(This
->nshandler
, aProtocolFlags
);
1941 return NS_ERROR_NOT_IMPLEMENTED
;
1944 static nsresult NSAPI
nsProtocolHandler_NewURI(nsIProtocolHandler
*iface
,
1945 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
1947 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
1949 TRACE("((%p)->%p %s %p %p)\n", This
, aSpec
, debugstr_a(aOriginCharset
), aBaseURI
, _retval
);
1952 return nsIProtocolHandler_NewURI(This
->nshandler
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
1953 return NS_ERROR_NOT_IMPLEMENTED
;
1956 static nsresult NSAPI
nsProtocolHandler_NewChannel(nsIProtocolHandler
*iface
,
1957 nsIURI
*aURI
, nsIChannel
**_retval
)
1959 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
1961 TRACE("(%p)->(%p %p)\n", This
, aURI
, _retval
);
1964 return nsIProtocolHandler_NewChannel(This
->nshandler
, aURI
, _retval
);
1965 return NS_ERROR_NOT_IMPLEMENTED
;
1968 static nsresult NSAPI
nsProtocolHandler_AllowPort(nsIProtocolHandler
*iface
,
1969 PRInt32 port
, const char *scheme
, PRBool
*_retval
)
1971 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
1973 TRACE("(%p)->(%d %s %p)\n", This
, port
, debugstr_a(scheme
), _retval
);
1976 return nsIProtocolHandler_AllowPort(This
->nshandler
, port
, scheme
, _retval
);
1977 return NS_ERROR_NOT_IMPLEMENTED
;
1980 #undef NSPROTHANDLER_THIS
1982 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl
= {
1983 nsProtocolHandler_QueryInterface
,
1984 nsProtocolHandler_AddRef
,
1985 nsProtocolHandler_Release
,
1986 nsProtocolHandler_GetScheme
,
1987 nsProtocolHandler_GetDefaultPort
,
1988 nsProtocolHandler_GetProtocolFlags
,
1989 nsProtocolHandler_NewURI
,
1990 nsProtocolHandler_NewChannel
,
1991 nsProtocolHandler_AllowPort
1994 static nsIProtocolHandler
*create_protocol_handler(nsIProtocolHandler
*nshandler
)
1996 nsProtocolHandler
*ret
= heap_alloc(sizeof(nsProtocolHandler
));
1998 ret
->lpProtocolHandlerVtbl
= &nsProtocolHandlerVtbl
;
2000 ret
->nshandler
= nshandler
;
2002 return NSPROTHANDLER(ret
);
2005 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*,nsIIDRef
,nsQIResult
);
2007 static nsrefcnt NSAPI
nsIOService_AddRef(nsIIOService
*iface
)
2012 static nsrefcnt NSAPI
nsIOService_Release(nsIIOService
*iface
)
2017 static nsresult NSAPI
nsIOService_GetProtocolHandler(nsIIOService
*iface
, const char *aScheme
,
2018 nsIProtocolHandler
**_retval
)
2020 nsIExternalProtocolHandler
*nsexthandler
;
2021 nsIProtocolHandler
*nshandler
;
2024 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
2026 nsres
= nsIIOService_GetProtocolHandler(nsio
, aScheme
, &nshandler
);
2027 if(NS_FAILED(nsres
)) {
2028 WARN("GetProtocolHandler failed: %08x\n", nsres
);
2032 nsres
= nsIProtocolHandler_QueryInterface(nshandler
, &IID_nsIExternalProtocolHandler
,
2033 (void**)&nsexthandler
);
2034 if(NS_FAILED(nsres
)) {
2035 *_retval
= nshandler
;
2039 nsIExternalProtocolHandler_Release(nsexthandler
);
2040 *_retval
= create_protocol_handler(nshandler
);
2041 TRACE("return %p\n", *_retval
);
2045 static nsresult NSAPI
nsIOService_GetProtocolFlags(nsIIOService
*iface
, const char *aScheme
,
2048 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
2049 return nsIIOService_GetProtocolFlags(nsio
, aScheme
, _retval
);
2052 static BOOL
is_gecko_special_uri(const char *spec
)
2054 static const char chromeW
[] = "chrome:";
2055 static const char jarW
[] = "jar:";
2056 static const char resourceW
[] = "resource:";
2057 static const char javascriptW
[] = "javascript:";
2059 return !strncasecmp(spec
, chromeW
, sizeof(chromeW
)-1)
2060 || !strncasecmp(spec
, resourceW
, sizeof(resourceW
)-1)
2061 || !strncasecmp(spec
, jarW
, sizeof(jarW
)-1)
2062 || !strncasecmp(spec
, javascriptW
, sizeof(javascriptW
)-1);
2065 static nsresult NSAPI
nsIOService_NewURI(nsIIOService
*iface
, const nsACString
*aSpec
,
2066 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
2068 const char *spec
= NULL
;
2069 NSContainer
*nscontainer
= NULL
;
2071 LPCWSTR base_wine_url
= NULL
;
2072 nsIWineURI
*base_wine_uri
= NULL
, *wine_uri
;
2073 BOOL is_wine_uri
= FALSE
;
2076 nsACString_GetData(aSpec
, &spec
);
2078 TRACE("(%p(%s) %s %p %p)\n", aSpec
, debugstr_a(spec
), debugstr_a(aOriginCharset
),
2081 if(is_gecko_special_uri(spec
))
2082 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2084 if(!strncmp(spec
, "wine:", 5)) {
2090 nsACString base_uri_str
;
2091 const char *base_uri
= NULL
;
2093 nsACString_Init(&base_uri_str
, NULL
);
2095 nsres
= nsIURI_GetSpec(aBaseURI
, &base_uri_str
);
2096 if(NS_SUCCEEDED(nsres
)) {
2097 nsACString_GetData(&base_uri_str
, &base_uri
);
2098 TRACE("base_uri=%s\n", debugstr_a(base_uri
));
2100 ERR("GetSpec failed: %08x\n", nsres
);
2103 nsACString_Finish(&base_uri_str
);
2106 nsres
= nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, &uri
);
2107 if(NS_FAILED(nsres
))
2108 TRACE("NewURI failed: %08x\n", nsres
);
2111 nsres
= nsIURI_QueryInterface(aBaseURI
, &IID_nsIWineURI
, (void**)&base_wine_uri
);
2112 if(NS_SUCCEEDED(nsres
)) {
2113 nsIWineURI_GetNSContainer(base_wine_uri
, &nscontainer
);
2114 nsIWineURI_GetWineURL(base_wine_uri
, &base_wine_url
);
2116 TRACE("Could not get base nsIWineURI: %08x\n", nsres
);
2120 TRACE("nscontainer = %p\n", nscontainer
);
2122 nsres
= create_uri(uri
, nscontainer
, &wine_uri
);
2123 *_retval
= (nsIURI
*)wine_uri
;
2126 nsIWebBrowserChrome_Release(NSWBCHROME(nscontainer
));
2129 WCHAR url
[INTERNET_MAX_URL_LENGTH
], rel_url
[INTERNET_MAX_URL_LENGTH
];
2133 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, rel_url
, sizeof(rel_url
)/sizeof(WCHAR
));
2135 hres
= CoInternetCombineUrl(base_wine_url
, rel_url
,
2136 URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
2137 url
, sizeof(url
)/sizeof(WCHAR
), &len
, 0);
2139 nsIWineURI_SetWineURL(wine_uri
, url
);
2141 WARN("CoCombineUrl failed: %08x\n", hres
);
2142 }else if(is_wine_uri
) {
2143 WCHAR url
[INTERNET_MAX_URL_LENGTH
];
2145 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, url
, sizeof(url
)/sizeof(WCHAR
));
2146 nsIWineURI_SetWineURL(wine_uri
, url
);
2150 nsIWineURI_Release(base_wine_uri
);
2155 static nsresult NSAPI
nsIOService_NewFileURI(nsIIOService
*iface
, nsIFile
*aFile
,
2158 TRACE("(%p %p)\n", aFile
, _retval
);
2159 return nsIIOService_NewFileURI(nsio
, aFile
, _retval
);
2162 static nsresult NSAPI
nsIOService_NewChannelFromURI(nsIIOService
*iface
, nsIURI
*aURI
,
2163 nsIChannel
**_retval
)
2165 nsIChannel
*channel
= NULL
;
2167 nsIWineURI
*wine_uri
;
2170 TRACE("(%p %p)\n", aURI
, _retval
);
2172 nsres
= nsIIOService_NewChannelFromURI(nsio
, aURI
, &channel
);
2173 if(NS_FAILED(nsres
) && nsres
!= NS_ERROR_UNKNOWN_PROTOCOL
) {
2174 WARN("NewChannelFromURI failed: %08x\n", nsres
);
2179 nsres
= nsIURI_QueryInterface(aURI
, &IID_nsIWineURI
, (void**)&wine_uri
);
2180 if(NS_FAILED(nsres
)) {
2181 WARN("Could not get nsIWineURI: %08x\n", nsres
);
2183 return channel
? NS_OK
: NS_ERROR_UNEXPECTED
;
2186 ret
= heap_alloc_zero(sizeof(nsChannel
));
2188 ret
->lpHttpChannelVtbl
= &nsChannelVtbl
;
2189 ret
->lpUploadChannelVtbl
= &nsUploadChannelVtbl
;
2191 ret
->channel
= channel
;
2192 ret
->uri
= wine_uri
;
2194 nsIURI_AddRef(aURI
);
2195 ret
->original_uri
= aURI
;
2198 nsIChannel_QueryInterface(channel
, &IID_nsIHttpChannel
, (void**)&ret
->http_channel
);
2200 *_retval
= NSCHANNEL(ret
);
2204 static nsresult NSAPI
nsIOService_NewChannel(nsIIOService
*iface
, const nsACString
*aSpec
,
2205 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIChannel
**_retval
)
2207 TRACE("(%p %s %p %p)\n", aSpec
, debugstr_a(aOriginCharset
), aBaseURI
, _retval
);
2208 return nsIIOService_NewChannel(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2211 static nsresult NSAPI
nsIOService_GetOffline(nsIIOService
*iface
, PRBool
*aOffline
)
2213 TRACE("(%p)\n", aOffline
);
2214 return nsIIOService_GetOffline(nsio
, aOffline
);
2217 static nsresult NSAPI
nsIOService_SetOffline(nsIIOService
*iface
, PRBool aOffline
)
2219 TRACE("(%x)\n", aOffline
);
2220 return nsIIOService_SetOffline(nsio
, aOffline
);
2223 static nsresult NSAPI
nsIOService_AllowPort(nsIIOService
*iface
, PRInt32 aPort
,
2224 const char *aScheme
, PRBool
*_retval
)
2226 TRACE("(%d %s %p)\n", aPort
, debugstr_a(aScheme
), _retval
);
2227 return nsIIOService_AllowPort(nsio
, aPort
, debugstr_a(aScheme
), _retval
);
2230 static nsresult NSAPI
nsIOService_ExtractScheme(nsIIOService
*iface
, const nsACString
*urlString
,
2231 nsACString
* _retval
)
2233 TRACE("(%p %p)\n", urlString
, _retval
);
2234 return nsIIOService_ExtractScheme(nsio
, urlString
, _retval
);
2237 static const nsIIOServiceVtbl nsIOServiceVtbl
= {
2238 nsIOService_QueryInterface
,
2240 nsIOService_Release
,
2241 nsIOService_GetProtocolHandler
,
2242 nsIOService_GetProtocolFlags
,
2244 nsIOService_NewFileURI
,
2245 nsIOService_NewChannelFromURI
,
2246 nsIOService_NewChannel
,
2247 nsIOService_GetOffline
,
2248 nsIOService_SetOffline
,
2249 nsIOService_AllowPort
,
2250 nsIOService_ExtractScheme
2253 static nsIIOService nsIOService
= { &nsIOServiceVtbl
};
2255 static nsresult NSAPI
nsNetUtil_QueryInterface(nsINetUtil
*iface
, nsIIDRef riid
,
2258 return nsIIOService_QueryInterface(&nsIOService
, riid
, result
);
2261 static nsrefcnt NSAPI
nsNetUtil_AddRef(nsINetUtil
*iface
)
2266 static nsrefcnt NSAPI
nsNetUtil_Release(nsINetUtil
*iface
)
2271 static nsresult NSAPI
nsNetUtil_ParseContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
2272 nsACString
*aCharset
, PRBool
*aHadCharset
, nsACString
*aContentType
)
2274 TRACE("(%p %p %p %p)\n", aTypeHeader
, aCharset
, aHadCharset
, aContentType
);
2276 return nsINetUtil_ParseContentType(net_util
, aTypeHeader
, aCharset
, aHadCharset
, aContentType
);
2279 static nsresult NSAPI
nsNetUtil_ProtocolHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, PRUint32 aFlags
, PRBool
*_retval
)
2283 return nsINetUtil_ProtocolHasFlags(net_util
, aURI
, aFlags
, _retval
);
2286 static nsresult NSAPI
nsNetUtil_URIChainHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, PRUint32 aFlags
, PRBool
*_retval
)
2288 TRACE("(%p %08x %p)\n", aURI
, aFlags
, _retval
);
2290 if(aFlags
== (1<<11)) {
2295 return nsINetUtil_URIChainHasFlags(net_util
, aURI
, aFlags
, _retval
);
2298 static nsresult NSAPI
nsNetUtil_ToImmutableURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
2300 TRACE("(%p %p)\n", aURI
, _retval
);
2302 return nsINetUtil_ToImmutableURI(net_util
, aURI
, _retval
);
2305 static nsresult NSAPI
nsNetUtil_EscapeString(nsINetUtil
*iface
, const nsACString
*aString
,
2306 PRUint32 aEscapeType
, nsACString
*_retval
)
2308 TRACE("(%p %x %p)\n", aString
, aEscapeType
, _retval
);
2310 return nsINetUtil_EscapeString(net_util
, aString
, aEscapeType
, _retval
);
2313 static nsresult NSAPI
nsNetUtil_EscapeURL(nsINetUtil
*iface
, const nsACString
*aStr
, PRUint32 aFlags
,
2314 nsACString
*_retval
)
2316 TRACE("(%p %08x %p)\n", aStr
, aFlags
, _retval
);
2318 return nsINetUtil_EscapeURL(net_util
, aStr
, aFlags
, _retval
);
2321 static nsresult NSAPI
nsNetUtil_UnescapeString(nsINetUtil
*iface
, const nsACString
*aStr
,
2322 PRUint32 aFlags
, nsACString
*_retval
)
2324 TRACE("(%p %08x %p)\n", aStr
, aFlags
, _retval
);
2326 return nsINetUtil_UnescapeString(net_util
, aStr
, aFlags
, _retval
);
2329 static nsresult NSAPI
nsNetUtil_ExtractCharsetFromContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
2330 nsACString
*aCharset
, PRInt32
*aCharsetStart
, PRInt32
*aCharsetEnd
, PRBool
*_retval
)
2332 TRACE("(%p %p %p %p %p)\n", aTypeHeader
, aCharset
, aCharsetStart
, aCharsetEnd
, _retval
);
2334 return nsINetUtil_ExtractCharsetFromContentType(net_util
, aTypeHeader
, aCharset
, aCharsetStart
, aCharsetEnd
, _retval
);
2337 static const nsINetUtilVtbl nsNetUtilVtbl
= {
2338 nsNetUtil_QueryInterface
,
2341 nsNetUtil_ParseContentType
,
2342 nsNetUtil_ProtocolHasFlags
,
2343 nsNetUtil_URIChainHasFlags
,
2344 nsNetUtil_ToImmutableURI
,
2345 nsNetUtil_EscapeString
,
2346 nsNetUtil_EscapeURL
,
2347 nsNetUtil_UnescapeString
,
2348 nsNetUtil_ExtractCharsetFromContentType
2351 static nsINetUtil nsNetUtil
= { &nsNetUtilVtbl
};
2353 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*iface
, nsIIDRef riid
,
2358 if(IsEqualGUID(&IID_nsISupports
, riid
))
2359 *result
= &nsIOService
;
2360 else if(IsEqualGUID(&IID_nsIIOService
, riid
))
2361 *result
= &nsIOService
;
2362 else if(IsEqualGUID(&IID_nsINetUtil
, riid
))
2363 *result
= &nsNetUtil
;
2366 nsISupports_AddRef((nsISupports
*)*result
);
2370 FIXME("(%s %p)\n", debugstr_guid(riid
), result
);
2371 return NS_NOINTERFACE
;
2374 static nsresult NSAPI
nsIOServiceFactory_QueryInterface(nsIFactory
*iface
, nsIIDRef riid
,
2379 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
2380 TRACE("(IID_nsISupports %p)\n", result
);
2382 }else if(IsEqualGUID(&IID_nsIFactory
, riid
)) {
2383 TRACE("(IID_nsIFactory %p)\n", result
);
2388 nsIFactory_AddRef(iface
);
2392 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
2393 return NS_NOINTERFACE
;
2396 static nsrefcnt NSAPI
nsIOServiceFactory_AddRef(nsIFactory
*iface
)
2401 static nsrefcnt NSAPI
nsIOServiceFactory_Release(nsIFactory
*iface
)
2406 static nsresult NSAPI
nsIOServiceFactory_CreateInstance(nsIFactory
*iface
,
2407 nsISupports
*aOuter
, const nsIID
*iid
, void **result
)
2409 return nsIIOService_QueryInterface(&nsIOService
, iid
, result
);
2412 static nsresult NSAPI
nsIOServiceFactory_LockFactory(nsIFactory
*iface
, PRBool lock
)
2414 WARN("(%x)\n", lock
);
2418 static const nsIFactoryVtbl nsIOServiceFactoryVtbl
= {
2419 nsIOServiceFactory_QueryInterface
,
2420 nsIOServiceFactory_AddRef
,
2421 nsIOServiceFactory_Release
,
2422 nsIOServiceFactory_CreateInstance
,
2423 nsIOServiceFactory_LockFactory
2426 static nsIFactory nsIOServiceFactory
= { &nsIOServiceFactoryVtbl
};
2428 void init_nsio(nsIComponentManager
*component_manager
, nsIComponentRegistrar
*registrar
)
2430 nsIFactory
*old_factory
= NULL
;
2433 nsres
= nsIComponentManager_GetClassObject(component_manager
, &NS_IOSERVICE_CID
,
2434 &IID_nsIFactory
, (void**)&old_factory
);
2435 if(NS_FAILED(nsres
)) {
2436 ERR("Could not get factory: %08x\n", nsres
);
2440 nsres
= nsIFactory_CreateInstance(old_factory
, NULL
, &IID_nsIIOService
, (void**)&nsio
);
2441 if(NS_FAILED(nsres
)) {
2442 ERR("Couldn not create nsIOService instance %08x\n", nsres
);
2443 nsIFactory_Release(old_factory
);
2447 nsres
= nsIIOService_QueryInterface(nsio
, &IID_nsINetUtil
, (void**)&net_util
);
2448 if(NS_FAILED(nsres
)) {
2449 WARN("Could not get nsINetUtil interface: %08x\n", nsres
);
2450 nsIIOService_Release(nsio
);
2454 nsres
= nsIComponentRegistrar_UnregisterFactory(registrar
, &NS_IOSERVICE_CID
, old_factory
);
2455 nsIFactory_Release(old_factory
);
2456 if(NS_FAILED(nsres
))
2457 ERR("UnregisterFactory failed: %08x\n", nsres
);
2459 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_IOSERVICE_CID
,
2460 NS_IOSERVICE_CLASSNAME
, NS_IOSERVICE_CONTRACTID
, &nsIOServiceFactory
);
2461 if(NS_FAILED(nsres
))
2462 ERR("RegisterFactory failed: %08x\n", nsres
);
2465 void release_nsio(void)
2468 nsINetUtil_Release(net_util
);
2473 nsIIOService_Release(nsio
);