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
;
51 static const WCHAR about_blankW
[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
54 const nsIWineURIVtbl
*lpWineURIVtbl
;
59 NSContainer
*container
;
65 #define NSURI(x) ((nsIURI*) &(x)->lpWineURIVtbl)
66 #define NSWINEURI(x) ((nsIWineURI*) &(x)->lpWineURIVtbl)
68 static nsresult
create_uri(nsIURI
*,NSContainer
*,nsIWineURI
**);
70 static BOOL
exec_shldocvw_67(HTMLDocument
*doc
, LPCWSTR url
)
72 IOleCommandTarget
*cmdtrg
= NULL
;
75 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
,
78 VARIANT varUrl
, varRes
;
80 V_VT(&varUrl
) = VT_BSTR
;
81 V_BSTR(&varUrl
) = SysAllocString(url
);
82 V_VT(&varRes
) = VT_BOOL
;
84 hres
= IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 67, 0, &varUrl
, &varRes
);
86 IOleCommandTarget_Release(cmdtrg
);
87 SysFreeString(V_BSTR(&varUrl
));
89 if(SUCCEEDED(hres
) && !V_BOOL(&varRes
)) {
90 TRACE("got VARIANT_FALSE, do not load\n");
98 static BOOL
before_async_open(nsChannel
*channel
, NSContainer
*container
)
100 IServiceProvider
*service_provider
;
101 HTMLDocument
*doc
= container
->doc
;
106 nsIWineURI_GetWineURL(channel
->uri
, &uri
);
108 ERR("GetWineURL returned NULL\n");
113 NSContainer
*container_iter
= container
;
115 hlnf
= HLNF_OPENINNEWWINDOW
;
116 while(!container_iter
->doc
)
117 container_iter
= container_iter
->parent
;
118 doc
= container_iter
->doc
;
124 if(!hlnf
&& !exec_shldocvw_67(doc
, uri
))
127 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IServiceProvider
,
128 (void**)&service_provider
);
129 if(SUCCEEDED(hres
)) {
130 IHlinkFrame
*hlink_frame
;
132 hres
= IServiceProvider_QueryService(service_provider
, &IID_IHlinkFrame
,
133 &IID_IHlinkFrame
, (void**)&hlink_frame
);
134 IServiceProvider_Release(service_provider
);
135 if(SUCCEEDED(hres
)) {
136 hlink_frame_navigate(doc
, hlink_frame
, uri
, channel
->post_data_stream
, hlnf
);
137 IHlinkFrame_Release(hlink_frame
);
146 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
148 static nsresult NSAPI
nsChannel_QueryInterface(nsIHttpChannel
*iface
, nsIIDRef riid
, nsQIResult result
)
150 nsChannel
*This
= NSCHANNEL_THIS(iface
);
154 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
155 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
156 *result
= NSCHANNEL(This
);
157 }else if(IsEqualGUID(&IID_nsIRequest
, riid
)) {
158 TRACE("(%p)->(IID_nsIRequest %p)\n", This
, result
);
159 *result
= NSCHANNEL(This
);
160 }else if(IsEqualGUID(&IID_nsIChannel
, riid
)) {
161 TRACE("(%p)->(IID_nsIChannel %p)\n", This
, result
);
162 *result
= NSCHANNEL(This
);
163 }else if(This
->http_channel
&& IsEqualGUID(&IID_nsIHttpChannel
, riid
)) {
164 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This
, result
);
165 *result
= NSHTTPCHANNEL(This
);
166 }else if(IsEqualGUID(&IID_nsIUploadChannel
, riid
)) {
167 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This
, result
);
168 *result
= NSUPCHANNEL(This
);
172 nsIChannel_AddRef(NSCHANNEL(This
));
176 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
179 return nsIChannel_QueryInterface(This
->channel
, riid
, result
);
180 return NS_NOINTERFACE
;
183 static nsrefcnt NSAPI
nsChannel_AddRef(nsIHttpChannel
*iface
)
185 nsChannel
*This
= NSCHANNEL_THIS(iface
);
186 nsrefcnt ref
= InterlockedIncrement(&This
->ref
);
188 TRACE("(%p) ref=%d\n", This
, ref
);
193 static nsrefcnt NSAPI
nsChannel_Release(nsIHttpChannel
*iface
)
195 nsChannel
*This
= NSCHANNEL_THIS(iface
);
196 LONG ref
= InterlockedDecrement(&This
->ref
);
199 nsIWineURI_Release(This
->uri
);
201 nsIChannel_Release(This
->channel
);
202 if(This
->http_channel
)
203 nsIHttpChannel_Release(This
->http_channel
);
204 if(This
->post_data_stream
)
205 nsIInputStream_Release(This
->post_data_stream
);
207 nsILoadGroup_Release(This
->load_group
);
208 if(This
->notif_callback
)
209 nsIInterfaceRequestor_Release(This
->notif_callback
);
210 if(This
->original_uri
)
211 nsIURI_Release(This
->original_uri
);
212 heap_free(This
->content_type
);
213 heap_free(This
->charset
);
220 static nsresult NSAPI
nsChannel_GetName(nsIHttpChannel
*iface
, nsACString
*aName
)
222 nsChannel
*This
= NSCHANNEL_THIS(iface
);
224 TRACE("(%p)->(%p)\n", This
, aName
);
227 return nsIChannel_GetName(This
->channel
, aName
);
229 return NS_ERROR_NOT_IMPLEMENTED
;
232 static nsresult NSAPI
nsChannel_IsPending(nsIHttpChannel
*iface
, PRBool
*_retval
)
234 nsChannel
*This
= NSCHANNEL_THIS(iface
);
236 TRACE("(%p)->(%p)\n", This
, _retval
);
239 return nsIChannel_IsPending(This
->channel
, _retval
);
241 FIXME("default action not implemented\n");
242 return NS_ERROR_NOT_IMPLEMENTED
;
245 static nsresult NSAPI
nsChannel_GetStatus(nsIHttpChannel
*iface
, nsresult
*aStatus
)
247 nsChannel
*This
= NSCHANNEL_THIS(iface
);
249 TRACE("(%p)->(%p)\n", This
, aStatus
);
252 return nsIChannel_GetStatus(This
->channel
, aStatus
);
254 TRACE("returning NS_OK\n");
255 return *aStatus
= NS_OK
;
258 static nsresult NSAPI
nsChannel_Cancel(nsIHttpChannel
*iface
, nsresult aStatus
)
260 nsChannel
*This
= NSCHANNEL_THIS(iface
);
262 TRACE("(%p)->(%08x)\n", This
, aStatus
);
265 return nsIChannel_Cancel(This
->channel
, aStatus
);
267 FIXME("default action not implemented\n");
268 return NS_ERROR_NOT_IMPLEMENTED
;
271 static nsresult NSAPI
nsChannel_Suspend(nsIHttpChannel
*iface
)
273 nsChannel
*This
= NSCHANNEL_THIS(iface
);
275 TRACE("(%p)\n", This
);
278 return nsIChannel_Suspend(This
->channel
);
280 FIXME("default action not implemented\n");
281 return NS_ERROR_NOT_IMPLEMENTED
;
284 static nsresult NSAPI
nsChannel_Resume(nsIHttpChannel
*iface
)
286 nsChannel
*This
= NSCHANNEL_THIS(iface
);
288 TRACE("(%p)\n", This
);
291 return nsIChannel_Resume(This
->channel
);
293 FIXME("default action not implemented\n");
294 return NS_ERROR_NOT_IMPLEMENTED
;
297 static nsresult NSAPI
nsChannel_GetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
**aLoadGroup
)
299 nsChannel
*This
= NSCHANNEL_THIS(iface
);
301 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
304 nsILoadGroup_AddRef(This
->load_group
);
306 *aLoadGroup
= This
->load_group
;
310 static nsresult NSAPI
nsChannel_SetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
*aLoadGroup
)
312 nsChannel
*This
= NSCHANNEL_THIS(iface
);
314 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
317 nsILoadGroup_Release(This
->load_group
);
319 nsILoadGroup_AddRef(aLoadGroup
);
321 This
->load_group
= aLoadGroup
;
324 return nsIChannel_SetLoadGroup(This
->channel
, aLoadGroup
);
328 static nsresult NSAPI
nsChannel_GetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags
*aLoadFlags
)
330 nsChannel
*This
= NSCHANNEL_THIS(iface
);
332 TRACE("(%p)->(%p)\n", This
, aLoadFlags
);
334 *aLoadFlags
= This
->load_flags
;
338 static nsresult NSAPI
nsChannel_SetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags aLoadFlags
)
340 nsChannel
*This
= NSCHANNEL_THIS(iface
);
342 TRACE("(%p)->(%08x)\n", This
, aLoadFlags
);
344 This
->load_flags
= aLoadFlags
;
347 return nsIChannel_SetLoadFlags(This
->channel
, aLoadFlags
);
351 static nsresult NSAPI
nsChannel_GetOriginalURI(nsIHttpChannel
*iface
, nsIURI
**aOriginalURI
)
353 nsChannel
*This
= NSCHANNEL_THIS(iface
);
355 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
357 if(This
->original_uri
)
358 nsIURI_AddRef(This
->original_uri
);
360 *aOriginalURI
= This
->original_uri
;
364 static nsresult NSAPI
nsChannel_SetOriginalURI(nsIHttpChannel
*iface
, nsIURI
*aOriginalURI
)
366 nsChannel
*This
= NSCHANNEL_THIS(iface
);
368 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
370 if(This
->original_uri
)
371 nsIURI_Release(This
->original_uri
);
373 nsIURI_AddRef(aOriginalURI
);
374 This
->original_uri
= aOriginalURI
;
377 return nsIChannel_SetOriginalURI(This
->channel
, aOriginalURI
);
381 static nsresult NSAPI
nsChannel_GetURI(nsIHttpChannel
*iface
, nsIURI
**aURI
)
383 nsChannel
*This
= NSCHANNEL_THIS(iface
);
385 TRACE("(%p)->(%p)\n", This
, aURI
);
387 nsIWineURI_AddRef(This
->uri
);
388 *aURI
= (nsIURI
*)This
->uri
;
393 static nsresult NSAPI
nsChannel_GetOwner(nsIHttpChannel
*iface
, nsISupports
**aOwner
)
395 nsChannel
*This
= NSCHANNEL_THIS(iface
);
397 TRACE("(%p)->(%p)\n", This
, aOwner
);
400 return nsIChannel_GetOwner(This
->channel
, aOwner
);
402 FIXME("default action not implemented\n");
403 return NS_ERROR_NOT_IMPLEMENTED
;
406 static nsresult NSAPI
nsChannel_SetOwner(nsIHttpChannel
*iface
, nsISupports
*aOwner
)
408 nsChannel
*This
= NSCHANNEL_THIS(iface
);
410 TRACE("(%p)->(%p)\n", This
, aOwner
);
413 return nsIChannel_SetOwner(This
->channel
, aOwner
);
415 FIXME("default action not implemented\n");
416 return NS_ERROR_NOT_IMPLEMENTED
;
419 static nsresult NSAPI
nsChannel_GetNotificationCallbacks(nsIHttpChannel
*iface
,
420 nsIInterfaceRequestor
**aNotificationCallbacks
)
422 nsChannel
*This
= NSCHANNEL_THIS(iface
);
424 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
426 if(This
->notif_callback
)
427 nsIInterfaceRequestor_AddRef(This
->notif_callback
);
428 *aNotificationCallbacks
= This
->notif_callback
;
433 static nsresult NSAPI
nsChannel_SetNotificationCallbacks(nsIHttpChannel
*iface
,
434 nsIInterfaceRequestor
*aNotificationCallbacks
)
436 nsChannel
*This
= NSCHANNEL_THIS(iface
);
438 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
440 if(This
->notif_callback
)
441 nsIInterfaceRequestor_Release(This
->notif_callback
);
442 if(aNotificationCallbacks
)
443 nsIInterfaceRequestor_AddRef(aNotificationCallbacks
);
445 This
->notif_callback
= aNotificationCallbacks
;
448 return nsIChannel_SetNotificationCallbacks(This
->channel
, aNotificationCallbacks
);
452 static nsresult NSAPI
nsChannel_GetSecurityInfo(nsIHttpChannel
*iface
, nsISupports
**aSecurityInfo
)
454 nsChannel
*This
= NSCHANNEL_THIS(iface
);
456 TRACE("(%p)->(%p)\n", This
, aSecurityInfo
);
459 return nsIChannel_GetSecurityInfo(This
->channel
, aSecurityInfo
);
461 FIXME("default action not implemented\n");
462 return NS_ERROR_NOT_IMPLEMENTED
;
465 static nsresult NSAPI
nsChannel_GetContentType(nsIHttpChannel
*iface
, nsACString
*aContentType
)
467 nsChannel
*This
= NSCHANNEL_THIS(iface
);
469 TRACE("(%p)->(%p)\n", This
, aContentType
);
471 if(This
->content_type
) {
472 nsACString_SetData(aContentType
, This
->content_type
);
477 return nsIChannel_GetContentType(This
->channel
, aContentType
);
479 TRACE("returning default text/html\n");
480 nsACString_SetData(aContentType
, "text/html");
484 static nsresult NSAPI
nsChannel_SetContentType(nsIHttpChannel
*iface
,
485 const nsACString
*aContentType
)
487 nsChannel
*This
= NSCHANNEL_THIS(iface
);
488 const char *content_type
;
490 TRACE("(%p)->(%p)\n", This
, aContentType
);
492 nsACString_GetData(aContentType
, &content_type
);
494 TRACE("content_type %s\n", content_type
);
496 heap_free(This
->content_type
);
497 This
->content_type
= heap_strdupA(content_type
);
500 return nsIChannel_SetContentType(This
->channel
, aContentType
);
505 static nsresult NSAPI
nsChannel_GetContentCharset(nsIHttpChannel
*iface
,
506 nsACString
*aContentCharset
)
508 nsChannel
*This
= NSCHANNEL_THIS(iface
);
510 TRACE("(%p)->(%p)\n", This
, aContentCharset
);
513 nsACString_SetData(aContentCharset
, This
->charset
);
518 nsresult nsres
= nsIChannel_GetContentCharset(This
->channel
, aContentCharset
);
520 nsACString_GetData(aContentCharset
, &ch
);
524 nsACString_SetData(aContentCharset
, "");
528 static nsresult NSAPI
nsChannel_SetContentCharset(nsIHttpChannel
*iface
,
529 const nsACString
*aContentCharset
)
531 nsChannel
*This
= NSCHANNEL_THIS(iface
);
533 TRACE("(%p)->(%p)\n", This
, aContentCharset
);
536 return nsIChannel_SetContentCharset(This
->channel
, aContentCharset
);
538 FIXME("default action not implemented\n");
539 return NS_ERROR_NOT_IMPLEMENTED
;
542 static nsresult NSAPI
nsChannel_GetContentLength(nsIHttpChannel
*iface
, PRInt32
*aContentLength
)
544 nsChannel
*This
= NSCHANNEL_THIS(iface
);
546 TRACE("(%p)->(%p)\n", This
, aContentLength
);
549 return nsIChannel_GetContentLength(This
->channel
, aContentLength
);
551 FIXME("default action not implemented\n");
552 return NS_ERROR_NOT_IMPLEMENTED
;
555 static nsresult NSAPI
nsChannel_SetContentLength(nsIHttpChannel
*iface
, PRInt32 aContentLength
)
557 nsChannel
*This
= NSCHANNEL_THIS(iface
);
559 TRACE("(%p)->(%d)\n", This
, aContentLength
);
562 return nsIChannel_SetContentLength(This
->channel
, aContentLength
);
564 FIXME("default action not implemented\n");
565 return NS_ERROR_NOT_IMPLEMENTED
;
568 static nsresult NSAPI
nsChannel_Open(nsIHttpChannel
*iface
, nsIInputStream
**_retval
)
570 nsChannel
*This
= NSCHANNEL_THIS(iface
);
572 TRACE("(%p)->(%p)\n", This
, _retval
);
575 return nsIChannel_Open(This
->channel
, _retval
);
577 FIXME("default action not implemented\n");
578 return NS_ERROR_NOT_IMPLEMENTED
;
581 static BOOL
do_load_from_moniker_hack(nsChannel
*This
)
583 nsACString scheme_str
;
588 * We should always load the page from IMoniker, but Wine is not yet
589 * ready for this. This function is a heuristic, that decides which
590 * way of loading is better (Gecko implementation or IMoniker). The
591 * aim is to always return TRUE.
594 /* Load from moniker if there is no Gecko channel available */
598 nsACString_Init(&scheme_str
, NULL
);
599 nsres
= nsIWineURI_GetScheme(This
->uri
, &scheme_str
);
601 if(NS_SUCCEEDED(nsres
)) {
604 nsACString_GetData(&scheme_str
, &scheme
);
605 ret
= !strcmp(scheme
, "wine") || !strcmp(scheme
, "about");
608 nsACString_Finish(&scheme_str
);
612 static HRESULT
create_mon_for_nschannel(nsChannel
*channel
, IMoniker
**mon
)
614 nsIWineURI
*wine_uri
;
619 if(!channel
->original_uri
) {
620 ERR("original_uri == NULL\n");
624 nsres
= nsIURI_QueryInterface(channel
->original_uri
, &IID_nsIWineURI
, (void**)&wine_uri
);
625 if(NS_FAILED(nsres
)) {
626 ERR("Could not get nsIWineURI: %08x\n", nsres
);
630 nsIWineURI_GetWineURL(wine_uri
, &wine_url
);
631 nsIWineURI_Release(wine_uri
);
633 TRACE("wine_url == NULL\n");
637 hres
= CreateURLMoniker(NULL
, wine_url
, mon
);
639 WARN("CreateURLMonikrer failed: %08x\n", hres
);
644 static NSContainer
*get_nscontainer_from_load_group(nsChannel
*This
)
646 NSContainer
*container
;
649 nsIWineURI
*wine_uri
;
653 nsres
= nsILoadGroup_GetDefaultLoadRequest(This
->load_group
, &req
);
654 if(NS_FAILED(nsres
)) {
655 ERR("GetDefaultLoadRequest failed: %08x\n", nsres
);
659 nsres
= nsIRequest_QueryInterface(req
, &IID_nsIChannel
, (void**)&channel
);
660 nsIRequest_Release(req
);
661 if(NS_FAILED(nsres
)) {
662 WARN("Could not get nsIChannel interface: %08x\n", nsres
);
666 nsres
= nsIChannel_GetURI(channel
, &uri
);
667 nsIChannel_Release(channel
);
668 if(NS_FAILED(nsres
)) {
669 ERR("GetURI failed: %08x\n", nsres
);
673 nsres
= nsIURI_QueryInterface(uri
, &IID_nsIWineURI
, (void**)&wine_uri
);
675 if(NS_FAILED(nsres
)) {
676 TRACE("Could not get nsIWineURI: %08x\n", nsres
);
680 nsIWineURI_GetNSContainer(wine_uri
, &container
);
681 nsIWineURI_Release(wine_uri
);
686 static nsresult
async_open_doc_uri(nsChannel
*This
, NSContainer
*container
,
687 nsIStreamListener
*listener
, nsISupports
*context
, BOOL
*open
)
694 if(container
->bscallback
) {
695 channelbsc_set_channel(container
->bscallback
, This
, listener
, context
);
697 if(container
->doc
&& container
->doc
->mime
) {
698 heap_free(This
->content_type
);
699 This
->content_type
= heap_strdupWtoA(container
->doc
->mime
);
702 if(do_load_from_moniker_hack(This
))
703 return WINE_NS_LOAD_FROM_MONIKER
;
705 BOOL cont
= before_async_open(This
, container
);
709 return NS_ERROR_UNEXPECTED
;
712 if(!container
->doc
) {
714 ? nsIChannel_AsyncOpen(This
->channel
, listener
, context
)
715 : NS_ERROR_UNEXPECTED
;
718 hres
= create_mon_for_nschannel(This
, &mon
);
720 return NS_ERROR_UNEXPECTED
;
722 set_current_mon(container
->doc
, mon
);
729 static nsresult
async_open(nsChannel
*This
, NSContainer
*container
, nsIStreamListener
*listener
,
730 nsISupports
*context
)
732 nsChannelBSC
*bscallback
;
733 IMoniker
*mon
= NULL
;
739 if(This
->post_data_stream
) {
740 nsIUploadChannel
*upload_channel
;
742 nsres
= nsIChannel_QueryInterface(This
->channel
, &IID_nsIUploadChannel
,
743 (void**)&upload_channel
);
744 if(NS_SUCCEEDED(nsres
)) {
745 nsACString empty_string
;
746 nsACString_Init(&empty_string
, "");
748 nsres
= nsIUploadChannel_SetUploadStream(upload_channel
, This
->post_data_stream
,
750 nsIUploadChannel_Release(upload_channel
);
752 WARN("SetUploadStream failed: %08x\n", nsres
);
754 nsACString_Finish(&empty_string
);
758 nsres
= nsIChannel_AsyncOpen(This
->channel
, listener
, context
);
761 IMoniker_Release(mon
);
763 if(NS_FAILED(nsres
) && (This
->load_flags
& LOAD_INITIAL_DOCUMENT_URI
))
764 return WINE_NS_LOAD_FROM_MONIKER
;
768 TRACE("channel == NULL\n");
770 hres
= create_mon_for_nschannel(This
, &mon
);
772 return NS_ERROR_UNEXPECTED
;
774 bscallback
= create_channelbsc(mon
);
775 IMoniker_Release(mon
);
777 channelbsc_set_channel(bscallback
, This
, listener
, context
);
779 task
= heap_alloc(sizeof(task_t
));
781 task
->doc
= container
->doc
;
782 task
->task_id
= TASK_START_BINDING
;
784 task
->bscallback
= bscallback
;
791 static nsresult NSAPI
nsChannel_AsyncOpen(nsIHttpChannel
*iface
, nsIStreamListener
*aListener
,
792 nsISupports
*aContext
)
794 nsChannel
*This
= NSCHANNEL_THIS(iface
);
795 NSContainer
*container
;
798 nsresult nsres
= NS_OK
;
800 TRACE("(%p)->(%p %p)\n", This
, aListener
, aContext
);
802 nsIWineURI_GetNSContainer(This
->uri
, &container
);
804 if(!container
&& This
->load_group
) {
805 container
= get_nscontainer_from_load_group(This
);
807 nsIWineURI_SetNSContainer(This
->uri
, container
);
811 TRACE("container = NULL\n");
813 ? nsIChannel_AsyncOpen(This
->channel
, aListener
, aContext
)
814 : NS_ERROR_UNEXPECTED
;
817 nsIWineURI_GetIsDocumentURI(This
->uri
, &is_doc_uri
);
819 if(is_doc_uri
&& (This
->load_flags
& LOAD_INITIAL_DOCUMENT_URI
))
820 nsres
= async_open_doc_uri(This
, container
, aListener
, aContext
, &open
);
823 nsres
= async_open(This
, container
, aListener
, aContext
);
825 nsIWebBrowserChrome_Release(NSWBCHROME(container
));
829 static nsresult NSAPI
nsChannel_GetRequestMethod(nsIHttpChannel
*iface
, nsACString
*aRequestMethod
)
831 nsChannel
*This
= NSCHANNEL_THIS(iface
);
833 TRACE("(%p)->(%p)\n", This
, aRequestMethod
);
835 if(This
->http_channel
)
836 return nsIHttpChannel_GetRequestMethod(This
->http_channel
, aRequestMethod
);
838 return NS_ERROR_NOT_IMPLEMENTED
;
841 static nsresult NSAPI
nsChannel_SetRequestMethod(nsIHttpChannel
*iface
,
842 const nsACString
*aRequestMethod
)
844 nsChannel
*This
= NSCHANNEL_THIS(iface
);
846 TRACE("(%p)->(%p)\n", This
, aRequestMethod
);
848 if(This
->http_channel
)
849 return nsIHttpChannel_SetRequestMethod(This
->http_channel
, aRequestMethod
);
851 return NS_ERROR_NOT_IMPLEMENTED
;
854 static nsresult NSAPI
nsChannel_GetReferrer(nsIHttpChannel
*iface
, nsIURI
**aReferrer
)
856 nsChannel
*This
= NSCHANNEL_THIS(iface
);
858 TRACE("(%p)->(%p)\n", This
, aReferrer
);
860 if(This
->http_channel
)
861 return nsIHttpChannel_GetReferrer(This
->http_channel
, aReferrer
);
863 return NS_ERROR_NOT_IMPLEMENTED
;
866 static nsresult NSAPI
nsChannel_SetReferrer(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_SetReferrer(This
->http_channel
, aReferrer
);
875 return NS_ERROR_NOT_IMPLEMENTED
;
878 static nsresult NSAPI
nsChannel_GetRequestHeader(nsIHttpChannel
*iface
,
879 const nsACString
*aHeader
, nsACString
*_retval
)
881 nsChannel
*This
= NSCHANNEL_THIS(iface
);
883 TRACE("(%p)->(%p %p)\n", This
, aHeader
, _retval
);
885 if(This
->http_channel
)
886 return nsIHttpChannel_GetRequestHeader(This
->http_channel
, aHeader
, _retval
);
888 return NS_ERROR_NOT_IMPLEMENTED
;
891 static nsresult NSAPI
nsChannel_SetRequestHeader(nsIHttpChannel
*iface
,
892 const nsACString
*aHeader
, const nsACString
*aValue
, PRBool aMerge
)
894 nsChannel
*This
= NSCHANNEL_THIS(iface
);
896 TRACE("(%p)->(%p %p %x)\n", This
, aHeader
, aValue
, aMerge
);
898 if(This
->http_channel
)
899 return nsIHttpChannel_SetRequestHeader(This
->http_channel
, aHeader
, aValue
, aMerge
);
901 return NS_ERROR_NOT_IMPLEMENTED
;
904 static nsresult NSAPI
nsChannel_VisitRequestHeaders(nsIHttpChannel
*iface
,
905 nsIHttpHeaderVisitor
*aVisitor
)
907 nsChannel
*This
= NSCHANNEL_THIS(iface
);
909 TRACE("(%p)->(%p)\n", This
, aVisitor
);
911 if(This
->http_channel
)
912 return nsIHttpChannel_VisitRequestHeaders(This
->http_channel
, aVisitor
);
914 return NS_ERROR_NOT_IMPLEMENTED
;
917 static nsresult NSAPI
nsChannel_GetAllowPipelining(nsIHttpChannel
*iface
, PRBool
*aAllowPipelining
)
919 nsChannel
*This
= NSCHANNEL_THIS(iface
);
921 TRACE("(%p)->(%p)\n", This
, aAllowPipelining
);
923 if(This
->http_channel
)
924 return nsIHttpChannel_GetAllowPipelining(This
->http_channel
, aAllowPipelining
);
926 return NS_ERROR_NOT_IMPLEMENTED
;
929 static nsresult NSAPI
nsChannel_SetAllowPipelining(nsIHttpChannel
*iface
, PRBool aAllowPipelining
)
931 nsChannel
*This
= NSCHANNEL_THIS(iface
);
933 TRACE("(%p)->(%x)\n", This
, aAllowPipelining
);
935 if(This
->http_channel
)
936 return nsIHttpChannel_SetAllowPipelining(This
->http_channel
, aAllowPipelining
);
938 return NS_ERROR_NOT_IMPLEMENTED
;
941 static nsresult NSAPI
nsChannel_GetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32
*aRedirectionLimit
)
943 nsChannel
*This
= NSCHANNEL_THIS(iface
);
945 TRACE("(%p)->(%p)\n", This
, aRedirectionLimit
);
947 if(This
->http_channel
)
948 return nsIHttpChannel_GetRedirectionLimit(This
->http_channel
, aRedirectionLimit
);
950 return NS_ERROR_NOT_IMPLEMENTED
;
953 static nsresult NSAPI
nsChannel_SetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32 aRedirectionLimit
)
955 nsChannel
*This
= NSCHANNEL_THIS(iface
);
957 TRACE("(%p)->(%u)\n", This
, aRedirectionLimit
);
959 if(This
->http_channel
)
960 return nsIHttpChannel_SetRedirectionLimit(This
->http_channel
, aRedirectionLimit
);
962 return NS_ERROR_NOT_IMPLEMENTED
;
965 static nsresult NSAPI
nsChannel_GetResponseStatus(nsIHttpChannel
*iface
, PRUint32
*aResponseStatus
)
967 nsChannel
*This
= NSCHANNEL_THIS(iface
);
969 TRACE("(%p)->(%p)\n", This
, aResponseStatus
);
971 if(This
->http_channel
)
972 return nsIHttpChannel_GetResponseStatus(This
->http_channel
, aResponseStatus
);
974 return NS_ERROR_NOT_IMPLEMENTED
;
977 static nsresult NSAPI
nsChannel_GetResponseStatusText(nsIHttpChannel
*iface
,
978 nsACString
*aResponseStatusText
)
980 nsChannel
*This
= NSCHANNEL_THIS(iface
);
982 TRACE("(%p)->(%p)\n", This
, aResponseStatusText
);
984 if(This
->http_channel
)
985 return nsIHttpChannel_GetResponseStatusText(This
->http_channel
, aResponseStatusText
);
987 return NS_ERROR_NOT_IMPLEMENTED
;
990 static nsresult NSAPI
nsChannel_GetRequestSucceeded(nsIHttpChannel
*iface
,
991 PRBool
*aRequestSucceeded
)
993 nsChannel
*This
= NSCHANNEL_THIS(iface
);
995 TRACE("(%p)->(%p)\n", This
, aRequestSucceeded
);
997 if(This
->http_channel
)
998 return nsIHttpChannel_GetRequestSucceeded(This
->http_channel
, aRequestSucceeded
);
1000 return NS_ERROR_NOT_IMPLEMENTED
;
1003 static nsresult NSAPI
nsChannel_GetResponseHeader(nsIHttpChannel
*iface
,
1004 const nsACString
*header
, nsACString
*_retval
)
1006 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1008 TRACE("(%p)->(%p %p)\n", This
, header
, _retval
);
1010 if(This
->http_channel
)
1011 return nsIHttpChannel_GetResponseHeader(This
->http_channel
, header
, _retval
);
1013 return NS_ERROR_NOT_IMPLEMENTED
;
1016 static nsresult NSAPI
nsChannel_SetResponseHeader(nsIHttpChannel
*iface
,
1017 const nsACString
*header
, const nsACString
*value
, PRBool merge
)
1019 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1021 TRACE("(%p)->(%p %p %x)\n", This
, header
, value
, merge
);
1023 if(This
->http_channel
)
1024 return nsIHttpChannel_SetResponseHeader(This
->http_channel
, header
, value
, merge
);
1026 return NS_ERROR_NOT_IMPLEMENTED
;
1029 static nsresult NSAPI
nsChannel_VisitResponseHeaders(nsIHttpChannel
*iface
,
1030 nsIHttpHeaderVisitor
*aVisitor
)
1032 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1034 TRACE("(%p)->(%p)\n", This
, aVisitor
);
1036 if(This
->http_channel
)
1037 return nsIHttpChannel_VisitResponseHeaders(This
->http_channel
, aVisitor
);
1039 return NS_ERROR_NOT_IMPLEMENTED
;
1042 static nsresult NSAPI
nsChannel_IsNoStoreResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1044 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1046 TRACE("(%p)->(%p)\n", This
, _retval
);
1048 if(This
->http_channel
)
1049 return nsIHttpChannel_IsNoStoreResponse(This
->http_channel
, _retval
);
1051 return NS_ERROR_NOT_IMPLEMENTED
;
1054 static nsresult NSAPI
nsChannel_IsNoCacheResponse(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_IsNoCacheResponse(This
->http_channel
, _retval
);
1063 return NS_ERROR_NOT_IMPLEMENTED
;
1066 #undef NSCHANNEL_THIS
1068 static const nsIHttpChannelVtbl nsChannelVtbl
= {
1069 nsChannel_QueryInterface
,
1073 nsChannel_IsPending
,
1074 nsChannel_GetStatus
,
1078 nsChannel_GetLoadGroup
,
1079 nsChannel_SetLoadGroup
,
1080 nsChannel_GetLoadFlags
,
1081 nsChannel_SetLoadFlags
,
1082 nsChannel_GetOriginalURI
,
1083 nsChannel_SetOriginalURI
,
1087 nsChannel_GetNotificationCallbacks
,
1088 nsChannel_SetNotificationCallbacks
,
1089 nsChannel_GetSecurityInfo
,
1090 nsChannel_GetContentType
,
1091 nsChannel_SetContentType
,
1092 nsChannel_GetContentCharset
,
1093 nsChannel_SetContentCharset
,
1094 nsChannel_GetContentLength
,
1095 nsChannel_SetContentLength
,
1097 nsChannel_AsyncOpen
,
1098 nsChannel_GetRequestMethod
,
1099 nsChannel_SetRequestMethod
,
1100 nsChannel_GetReferrer
,
1101 nsChannel_SetReferrer
,
1102 nsChannel_GetRequestHeader
,
1103 nsChannel_SetRequestHeader
,
1104 nsChannel_VisitRequestHeaders
,
1105 nsChannel_GetAllowPipelining
,
1106 nsChannel_SetAllowPipelining
,
1107 nsChannel_GetRedirectionLimit
,
1108 nsChannel_SetRedirectionLimit
,
1109 nsChannel_GetResponseStatus
,
1110 nsChannel_GetResponseStatusText
,
1111 nsChannel_GetRequestSucceeded
,
1112 nsChannel_GetResponseHeader
,
1113 nsChannel_SetResponseHeader
,
1114 nsChannel_VisitResponseHeaders
,
1115 nsChannel_IsNoStoreResponse
,
1116 nsChannel_IsNoCacheResponse
1119 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1121 static nsresult NSAPI
nsUploadChannel_QueryInterface(nsIUploadChannel
*iface
, nsIIDRef riid
,
1124 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1125 return nsIChannel_QueryInterface(NSCHANNEL(This
), riid
, result
);
1128 static nsrefcnt NSAPI
nsUploadChannel_AddRef(nsIUploadChannel
*iface
)
1130 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1131 return nsIChannel_AddRef(NSCHANNEL(This
));
1134 static nsrefcnt NSAPI
nsUploadChannel_Release(nsIUploadChannel
*iface
)
1136 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1137 return nsIChannel_Release(NSCHANNEL(This
));
1140 static nsresult NSAPI
nsUploadChannel_SetUploadStream(nsIUploadChannel
*iface
,
1141 nsIInputStream
*aStream
, const nsACString
*aContentType
, PRInt32 aContentLength
)
1143 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1144 const char *content_type
;
1146 TRACE("(%p)->(%p %p %d)\n", This
, aStream
, aContentType
, aContentLength
);
1148 if(This
->post_data_stream
)
1149 nsIInputStream_Release(This
->post_data_stream
);
1152 nsACString_GetData(aContentType
, &content_type
);
1154 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type
));
1157 if(aContentLength
!= -1)
1158 FIXME("Unsupported acontentLength = %d\n", aContentLength
);
1161 nsIInputStream_AddRef(aStream
);
1162 This
->post_data_stream
= aStream
;
1167 static nsresult NSAPI
nsUploadChannel_GetUploadStream(nsIUploadChannel
*iface
,
1168 nsIInputStream
**aUploadStream
)
1170 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1172 TRACE("(%p)->(%p)\n", This
, aUploadStream
);
1174 if(This
->post_data_stream
)
1175 nsIInputStream_AddRef(This
->post_data_stream
);
1177 *aUploadStream
= This
->post_data_stream
;
1181 #undef NSUPCHANNEL_THIS
1183 static const nsIUploadChannelVtbl nsUploadChannelVtbl
= {
1184 nsUploadChannel_QueryInterface
,
1185 nsUploadChannel_AddRef
,
1186 nsUploadChannel_Release
,
1187 nsUploadChannel_SetUploadStream
,
1188 nsUploadChannel_GetUploadStream
1191 #define NSURI_THIS(iface) DEFINE_THIS(nsURI, WineURI, iface)
1193 static nsresult NSAPI
nsURI_QueryInterface(nsIWineURI
*iface
, nsIIDRef riid
, nsQIResult result
)
1195 nsURI
*This
= NSURI_THIS(iface
);
1199 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1200 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1201 *result
= NSURI(This
);
1202 }else if(IsEqualGUID(&IID_nsIURI
, riid
)) {
1203 TRACE("(%p)->(IID_nsIURI %p)\n", This
, result
);
1204 *result
= NSURI(This
);
1205 }else if(IsEqualGUID(&IID_nsIWineURI
, riid
)) {
1206 TRACE("(%p)->(IID_nsIWineURI %p)\n", This
, result
);
1207 *result
= NSURI(This
);
1211 nsIURI_AddRef(NSURI(This
));
1215 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1216 return This
->uri
? nsIURI_QueryInterface(This
->uri
, riid
, result
) : NS_NOINTERFACE
;
1219 static nsrefcnt NSAPI
nsURI_AddRef(nsIWineURI
*iface
)
1221 nsURI
*This
= NSURI_THIS(iface
);
1222 LONG ref
= InterlockedIncrement(&This
->ref
);
1224 TRACE("(%p) ref=%d\n", This
, ref
);
1229 static nsrefcnt NSAPI
nsURI_Release(nsIWineURI
*iface
)
1231 nsURI
*This
= NSURI_THIS(iface
);
1232 LONG ref
= InterlockedDecrement(&This
->ref
);
1234 TRACE("(%p) ref=%d\n", This
, ref
);
1238 nsIWebBrowserChrome_Release(NSWBCHROME(This
->container
));
1240 nsIURI_Release(This
->uri
);
1241 heap_free(This
->wine_url
);
1248 static nsresult NSAPI
nsURI_GetSpec(nsIWineURI
*iface
, nsACString
*aSpec
)
1250 nsURI
*This
= NSURI_THIS(iface
);
1252 TRACE("(%p)->(%p)\n", This
, aSpec
);
1254 if(This
->use_wine_url
) {
1255 char speca
[INTERNET_MAX_URL_LENGTH
] = "wine:";
1256 WideCharToMultiByte(CP_ACP
, 0, This
->wine_url
, -1, speca
+5, sizeof(speca
)-5, NULL
, NULL
);
1257 nsACString_SetData(aSpec
, speca
);
1263 return nsIURI_GetSpec(This
->uri
, aSpec
);
1265 TRACE("returning error\n");
1266 return NS_ERROR_NOT_IMPLEMENTED
;
1270 static nsresult NSAPI
nsURI_SetSpec(nsIWineURI
*iface
, const nsACString
*aSpec
)
1272 nsURI
*This
= NSURI_THIS(iface
);
1274 TRACE("(%p)->(%p)\n", This
, aSpec
);
1277 return nsIURI_SetSpec(This
->uri
, aSpec
);
1279 FIXME("default action not implemented\n");
1280 return NS_ERROR_NOT_IMPLEMENTED
;
1283 static nsresult NSAPI
nsURI_GetPrePath(nsIWineURI
*iface
, nsACString
*aPrePath
)
1285 nsURI
*This
= NSURI_THIS(iface
);
1287 TRACE("(%p)->(%p)\n", This
, aPrePath
);
1290 return nsIURI_GetPrePath(This
->uri
, aPrePath
);
1292 FIXME("default action not implemented\n");
1293 return NS_ERROR_NOT_IMPLEMENTED
;
1296 static nsresult NSAPI
nsURI_GetScheme(nsIWineURI
*iface
, nsACString
*aScheme
)
1298 nsURI
*This
= NSURI_THIS(iface
);
1300 TRACE("(%p)->(%p)\n", This
, aScheme
);
1302 if(This
->use_wine_url
&& strcmpW(This
->wine_url
, about_blankW
)) {
1304 * For Gecko we set scheme to unknown so it won't be handled
1305 * as any special case.
1307 nsACString_SetData(aScheme
, "wine");
1312 return nsIURI_GetScheme(This
->uri
, aScheme
);
1314 TRACE("returning error\n");
1315 return NS_ERROR_NOT_IMPLEMENTED
;
1318 static nsresult NSAPI
nsURI_SetScheme(nsIWineURI
*iface
, const nsACString
*aScheme
)
1320 nsURI
*This
= NSURI_THIS(iface
);
1322 TRACE("(%p)->(%p)\n", This
, aScheme
);
1325 return nsIURI_SetScheme(This
->uri
, aScheme
);
1327 FIXME("default action not implemented\n");
1328 return NS_ERROR_NOT_IMPLEMENTED
;
1331 static nsresult NSAPI
nsURI_GetUserPass(nsIWineURI
*iface
, nsACString
*aUserPass
)
1333 nsURI
*This
= NSURI_THIS(iface
);
1335 TRACE("(%p)->(%p)\n", This
, aUserPass
);
1338 return nsIURI_GetUserPass(This
->uri
, aUserPass
);
1340 FIXME("default action not implemented\n");
1341 return NS_ERROR_NOT_IMPLEMENTED
;
1344 static nsresult NSAPI
nsURI_SetUserPass(nsIWineURI
*iface
, const nsACString
*aUserPass
)
1346 nsURI
*This
= NSURI_THIS(iface
);
1348 TRACE("(%p)->(%p)\n", This
, aUserPass
);
1351 return nsIURI_SetUserPass(This
->uri
, aUserPass
);
1353 FIXME("default action not implemented\n");
1354 return NS_ERROR_NOT_IMPLEMENTED
;
1357 static nsresult NSAPI
nsURI_GetUsername(nsIWineURI
*iface
, nsACString
*aUsername
)
1359 nsURI
*This
= NSURI_THIS(iface
);
1361 TRACE("(%p)->(%p)\n", This
, aUsername
);
1364 return nsIURI_GetUsername(This
->uri
, aUsername
);
1366 FIXME("default action not implemented\n");
1367 return NS_ERROR_NOT_IMPLEMENTED
;
1370 static nsresult NSAPI
nsURI_SetUsername(nsIWineURI
*iface
, const nsACString
*aUsername
)
1372 nsURI
*This
= NSURI_THIS(iface
);
1374 TRACE("(%p)->(%p)\n", This
, aUsername
);
1377 return nsIURI_SetUsername(This
->uri
, aUsername
);
1379 FIXME("default action not implemented\n");
1380 return NS_ERROR_NOT_IMPLEMENTED
;
1383 static nsresult NSAPI
nsURI_GetPassword(nsIWineURI
*iface
, nsACString
*aPassword
)
1385 nsURI
*This
= NSURI_THIS(iface
);
1387 TRACE("(%p)->(%p)\n", This
, aPassword
);
1390 return nsIURI_GetPassword(This
->uri
, aPassword
);
1392 FIXME("default action not implemented\n");
1393 return NS_ERROR_NOT_IMPLEMENTED
;
1396 static nsresult NSAPI
nsURI_SetPassword(nsIWineURI
*iface
, const nsACString
*aPassword
)
1398 nsURI
*This
= NSURI_THIS(iface
);
1400 TRACE("(%p)->(%p)\n", This
, aPassword
);
1403 return nsIURI_SetPassword(This
->uri
, aPassword
);
1405 FIXME("default action not implemented\n");
1406 return NS_ERROR_NOT_IMPLEMENTED
;
1409 static nsresult NSAPI
nsURI_GetHostPort(nsIWineURI
*iface
, nsACString
*aHostPort
)
1411 nsURI
*This
= NSURI_THIS(iface
);
1413 TRACE("(%p)->(%p)\n", This
, aHostPort
);
1416 return nsIURI_GetHostPort(This
->uri
, aHostPort
);
1418 FIXME("default action not implemented\n");
1419 return NS_ERROR_NOT_IMPLEMENTED
;
1422 static nsresult NSAPI
nsURI_SetHostPort(nsIWineURI
*iface
, const nsACString
*aHostPort
)
1424 nsURI
*This
= NSURI_THIS(iface
);
1426 TRACE("(%p)->(%p)\n", This
, aHostPort
);
1429 return nsIURI_SetHostPort(This
->uri
, aHostPort
);
1431 FIXME("default action not implemented\n");
1432 return NS_ERROR_NOT_IMPLEMENTED
;
1435 static nsresult NSAPI
nsURI_GetHost(nsIWineURI
*iface
, nsACString
*aHost
)
1437 nsURI
*This
= NSURI_THIS(iface
);
1439 TRACE("(%p)->(%p)\n", This
, aHost
);
1442 return nsIURI_GetHost(This
->uri
, aHost
);
1444 FIXME("default action not implemented\n");
1445 return NS_ERROR_NOT_IMPLEMENTED
;
1448 static nsresult NSAPI
nsURI_SetHost(nsIWineURI
*iface
, const nsACString
*aHost
)
1450 nsURI
*This
= NSURI_THIS(iface
);
1452 TRACE("(%p)->(%p)\n", This
, aHost
);
1455 return nsIURI_SetHost(This
->uri
, aHost
);
1457 FIXME("default action not implemented\n");
1458 return NS_ERROR_NOT_IMPLEMENTED
;
1461 static nsresult NSAPI
nsURI_GetPort(nsIWineURI
*iface
, PRInt32
*aPort
)
1463 nsURI
*This
= NSURI_THIS(iface
);
1465 TRACE("(%p)->(%p)\n", This
, aPort
);
1468 return nsIURI_GetPort(This
->uri
, aPort
);
1470 FIXME("default action not implemented\n");
1471 return NS_ERROR_NOT_IMPLEMENTED
;
1474 static nsresult NSAPI
nsURI_SetPort(nsIWineURI
*iface
, PRInt32 aPort
)
1476 nsURI
*This
= NSURI_THIS(iface
);
1478 TRACE("(%p)->(%d)\n", This
, aPort
);
1481 return nsIURI_SetPort(This
->uri
, aPort
);
1483 FIXME("default action not implemented\n");
1484 return NS_ERROR_NOT_IMPLEMENTED
;
1487 static nsresult NSAPI
nsURI_GetPath(nsIWineURI
*iface
, nsACString
*aPath
)
1489 nsURI
*This
= NSURI_THIS(iface
);
1491 TRACE("(%p)->(%p)\n", This
, aPath
);
1494 return nsIURI_GetPath(This
->uri
, aPath
);
1496 FIXME("default action not implemented\n");
1497 return NS_ERROR_NOT_IMPLEMENTED
;
1500 static nsresult NSAPI
nsURI_SetPath(nsIWineURI
*iface
, const nsACString
*aPath
)
1502 nsURI
*This
= NSURI_THIS(iface
);
1505 nsACString_GetData(aPath
, &path
);
1506 TRACE("(%p)->(%p(%s))\n", This
, aPath
, debugstr_a(path
));
1509 if(This
->wine_url
) {
1510 WCHAR new_url
[INTERNET_MAX_URL_LENGTH
];
1511 DWORD size
= sizeof(new_url
)/sizeof(WCHAR
);
1515 pathw
= heap_strdupAtoW(path
);
1516 hres
= UrlCombineW(This
->wine_url
, pathw
, new_url
, &size
, 0);
1519 nsIWineURI_SetWineURL(NSWINEURI(This
), new_url
);
1521 WARN("UrlCombine failed: %08x\n", hres
);
1527 return nsIURI_SetPath(This
->uri
, aPath
);
1530 static nsresult NSAPI
nsURI_Equals(nsIWineURI
*iface
, nsIURI
*other
, PRBool
*_retval
)
1532 nsURI
*This
= NSURI_THIS(iface
);
1533 nsIWineURI
*wine_uri
;
1534 LPCWSTR other_url
= NULL
;
1537 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
1540 return nsIURI_Equals(This
->uri
, other
, _retval
);
1542 nsres
= nsIURI_QueryInterface(other
, &IID_nsIWineURI
, (void**)&wine_uri
);
1543 if(NS_FAILED(nsres
)) {
1544 TRACE("Could not get nsIWineURI interface\n");
1549 nsIWineURI_GetWineURL(wine_uri
, &other_url
);
1550 *_retval
= !UrlCompareW(This
->wine_url
, other_url
, TRUE
);
1551 nsIWineURI_Release(wine_uri
);
1556 static nsresult NSAPI
nsURI_SchemeIs(nsIWineURI
*iface
, const char *scheme
, PRBool
*_retval
)
1558 nsURI
*This
= NSURI_THIS(iface
);
1560 TRACE("(%p)->(%s %p)\n", This
, debugstr_a(scheme
), _retval
);
1562 if(This
->use_wine_url
) {
1563 WCHAR buf
[INTERNET_MAX_SCHEME_LENGTH
];
1564 int len
= MultiByteToWideChar(CP_ACP
, 0, scheme
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
))-1;
1566 *_retval
= strlenW(This
->wine_url
) > len
1567 && This
->wine_url
[len
] == ':'
1568 && !memcmp(buf
, This
->wine_url
, len
*sizeof(WCHAR
));
1573 return nsIURI_SchemeIs(This
->uri
, scheme
, _retval
);
1575 TRACE("returning error\n");
1576 return NS_ERROR_NOT_IMPLEMENTED
;
1579 static nsresult NSAPI
nsURI_Clone(nsIWineURI
*iface
, nsIURI
**_retval
)
1581 nsURI
*This
= NSURI_THIS(iface
);
1582 nsIURI
*nsuri
= NULL
;
1583 nsIWineURI
*wine_uri
;
1586 TRACE("(%p)->(%p)\n", This
, _retval
);
1589 nsres
= nsIURI_Clone(This
->uri
, &nsuri
);
1590 if(NS_FAILED(nsres
)) {
1591 WARN("Clone failed: %08x\n", nsres
);
1596 nsres
= create_uri(nsuri
, This
->container
, &wine_uri
);
1597 if(NS_FAILED(nsres
)) {
1598 WARN("create_uri failed: %08x\n", nsres
);
1602 *_retval
= (nsIURI
*)wine_uri
;
1603 return nsIWineURI_SetWineURL(wine_uri
, This
->wine_url
);
1606 static nsresult NSAPI
nsURI_Resolve(nsIWineURI
*iface
, const nsACString
*arelativePath
,
1607 nsACString
*_retval
)
1609 nsURI
*This
= NSURI_THIS(iface
);
1611 TRACE("(%p)->(%p %p)\n", This
, arelativePath
, _retval
);
1614 return nsIURI_Resolve(This
->uri
, arelativePath
, _retval
);
1616 FIXME("default action not implemented\n");
1617 return NS_ERROR_NOT_IMPLEMENTED
;
1620 static nsresult NSAPI
nsURI_GetAsciiSpec(nsIWineURI
*iface
, nsACString
*aAsciiSpec
)
1622 nsURI
*This
= NSURI_THIS(iface
);
1624 TRACE("(%p)->(%p)\n", This
, aAsciiSpec
);
1626 if(This
->use_wine_url
)
1627 return nsIURI_GetSpec(NSURI(This
), aAsciiSpec
);
1630 return nsIURI_GetAsciiSpec(This
->uri
, aAsciiSpec
);
1632 TRACE("returning error\n");
1633 return NS_ERROR_NOT_IMPLEMENTED
;
1636 static nsresult NSAPI
nsURI_GetAsciiHost(nsIWineURI
*iface
, nsACString
*aAsciiHost
)
1638 nsURI
*This
= NSURI_THIS(iface
);
1640 TRACE("(%p)->(%p)\n", This
, aAsciiHost
);
1643 return nsIURI_GetAsciiHost(This
->uri
, aAsciiHost
);
1645 FIXME("default action not implemented\n");
1646 return NS_ERROR_NOT_IMPLEMENTED
;
1649 static nsresult NSAPI
nsURI_GetOriginCharset(nsIWineURI
*iface
, nsACString
*aOriginCharset
)
1651 nsURI
*This
= NSURI_THIS(iface
);
1653 TRACE("(%p)->(%p)\n", This
, aOriginCharset
);
1656 return nsIURI_GetOriginCharset(This
->uri
, aOriginCharset
);
1658 FIXME("default action not implemented\n");
1659 return NS_ERROR_NOT_IMPLEMENTED
;
1662 static nsresult NSAPI
nsURI_GetNSContainer(nsIWineURI
*iface
, NSContainer
**aContainer
)
1664 nsURI
*This
= NSURI_THIS(iface
);
1666 TRACE("(%p)->(%p)\n", This
, aContainer
);
1669 nsIWebBrowserChrome_AddRef(NSWBCHROME(This
->container
));
1670 *aContainer
= This
->container
;
1675 static nsresult NSAPI
nsURI_SetNSContainer(nsIWineURI
*iface
, NSContainer
*aContainer
)
1677 nsURI
*This
= NSURI_THIS(iface
);
1679 TRACE("(%p)->(%p)\n", This
, aContainer
);
1681 if(This
->container
) {
1682 if(This
->container
== aContainer
)
1684 TRACE("Changing %p -> %p\n", This
->container
, aContainer
);
1685 nsIWebBrowserChrome_Release(NSWBCHROME(This
->container
));
1689 nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer
));
1690 This
->container
= aContainer
;
1695 static nsresult NSAPI
nsURI_GetIsDocumentURI(nsIWineURI
*iface
, PRBool
*aIsDocumentURI
)
1697 nsURI
*This
= NSURI_THIS(iface
);
1699 TRACE("(%p)->(%p)\n", This
, aIsDocumentURI
);
1701 *aIsDocumentURI
= This
->is_doc_uri
;
1705 static nsresult NSAPI
nsURI_SetIsDocumentURI(nsIWineURI
*iface
, PRBool aIsDocumentURI
)
1707 nsURI
*This
= NSURI_THIS(iface
);
1709 TRACE("(%p)->(%x)\n", This
, aIsDocumentURI
);
1711 This
->is_doc_uri
= aIsDocumentURI
;
1715 static nsresult NSAPI
nsURI_GetWineURL(nsIWineURI
*iface
, LPCWSTR
*aURL
)
1717 nsURI
*This
= NSURI_THIS(iface
);
1719 TRACE("(%p)->(%p)\n", This
, aURL
);
1721 *aURL
= This
->wine_url
;
1725 static nsresult NSAPI
nsURI_SetWineURL(nsIWineURI
*iface
, LPCWSTR aURL
)
1727 nsURI
*This
= NSURI_THIS(iface
);
1729 static const WCHAR wszFtp
[] = {'f','t','p',':'};
1730 static const WCHAR wszHttp
[] = {'h','t','t','p',':'};
1731 static const WCHAR wszHttps
[] = {'h','t','t','p','s',':'};
1733 TRACE("(%p)->(%s)\n", This
, debugstr_w(aURL
));
1735 heap_free(This
->wine_url
);
1738 int len
= strlenW(aURL
)+1;
1739 This
->wine_url
= heap_alloc(len
*sizeof(WCHAR
));
1740 memcpy(This
->wine_url
, aURL
, len
*sizeof(WCHAR
));
1742 /* FIXME: Always use wine url */
1743 This
->use_wine_url
=
1744 strncmpW(aURL
, wszFtp
, sizeof(wszFtp
)/sizeof(WCHAR
))
1745 && strncmpW(aURL
, wszHttp
, sizeof(wszHttp
)/sizeof(WCHAR
))
1746 && strncmpW(aURL
, wszHttps
, sizeof(wszHttps
)/sizeof(WCHAR
));
1748 This
->wine_url
= NULL
;
1749 This
->use_wine_url
= FALSE
;
1757 static const nsIWineURIVtbl nsWineURIVtbl
= {
1758 nsURI_QueryInterface
,
1786 nsURI_GetOriginCharset
,
1787 nsURI_GetNSContainer
,
1788 nsURI_SetNSContainer
,
1789 nsURI_GetIsDocumentURI
,
1790 nsURI_SetIsDocumentURI
,
1795 static nsresult
create_uri(nsIURI
*uri
, NSContainer
*container
, nsIWineURI
**_retval
)
1797 nsURI
*ret
= heap_alloc(sizeof(nsURI
));
1799 ret
->lpWineURIVtbl
= &nsWineURIVtbl
;
1802 ret
->container
= container
;
1803 ret
->wine_url
= NULL
;
1804 ret
->is_doc_uri
= FALSE
;
1805 ret
->use_wine_url
= FALSE
;
1808 nsIWebBrowserChrome_AddRef(NSWBCHROME(container
));
1810 TRACE("retval=%p\n", ret
);
1811 *_retval
= NSWINEURI(ret
);
1816 const nsIProtocolHandlerVtbl
*lpProtocolHandlerVtbl
;
1820 nsIProtocolHandler
*nshandler
;
1821 } nsProtocolHandler
;
1823 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
1825 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
1827 static nsresult NSAPI
nsProtocolHandler_QueryInterface(nsIProtocolHandler
*iface
, nsIIDRef riid
,
1830 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
1834 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1835 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1836 *result
= NSPROTHANDLER(This
);
1837 }else if(IsEqualGUID(&IID_nsIProtocolHandler
, riid
)) {
1838 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This
, result
);
1839 *result
= NSPROTHANDLER(This
);
1840 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler
, riid
)) {
1841 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This
, result
);
1842 return NS_NOINTERFACE
;
1846 nsISupports_AddRef((nsISupports
*)*result
);
1850 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
1851 return NS_NOINTERFACE
;
1854 static nsrefcnt NSAPI
nsProtocolHandler_AddRef(nsIProtocolHandler
*iface
)
1856 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
1857 LONG ref
= InterlockedIncrement(&This
->ref
);
1859 TRACE("(%p) ref=%d\n", This
, ref
);
1864 static nsrefcnt NSAPI
nsProtocolHandler_Release(nsIProtocolHandler
*iface
)
1866 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
1867 LONG ref
= InterlockedDecrement(&This
->ref
);
1869 TRACE("(%p) ref=%d\n", This
, ref
);
1873 nsIProtocolHandler_Release(This
->nshandler
);
1880 static nsresult NSAPI
nsProtocolHandler_GetScheme(nsIProtocolHandler
*iface
, nsACString
*aScheme
)
1882 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
1884 TRACE("(%p)->(%p)\n", This
, aScheme
);
1887 return nsIProtocolHandler_GetScheme(This
->nshandler
, aScheme
);
1888 return NS_ERROR_NOT_IMPLEMENTED
;
1891 static nsresult NSAPI
nsProtocolHandler_GetDefaultPort(nsIProtocolHandler
*iface
,
1892 PRInt32
*aDefaultPort
)
1894 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
1896 TRACE("(%p)->(%p)\n", This
, aDefaultPort
);
1899 return nsIProtocolHandler_GetDefaultPort(This
->nshandler
, aDefaultPort
);
1900 return NS_ERROR_NOT_IMPLEMENTED
;
1903 static nsresult NSAPI
nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler
*iface
,
1904 PRUint32
*aProtocolFlags
)
1906 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
1908 TRACE("(%p)->(%p)\n", This
, aProtocolFlags
);
1911 return nsIProtocolHandler_GetProtocolFlags(This
->nshandler
, aProtocolFlags
);
1912 return NS_ERROR_NOT_IMPLEMENTED
;
1915 static nsresult NSAPI
nsProtocolHandler_NewURI(nsIProtocolHandler
*iface
,
1916 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
1918 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
1920 TRACE("((%p)->%p %s %p %p)\n", This
, aSpec
, debugstr_a(aOriginCharset
), aBaseURI
, _retval
);
1923 return nsIProtocolHandler_NewURI(This
->nshandler
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
1924 return NS_ERROR_NOT_IMPLEMENTED
;
1927 static nsresult NSAPI
nsProtocolHandler_NewChannel(nsIProtocolHandler
*iface
,
1928 nsIURI
*aURI
, nsIChannel
**_retval
)
1930 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
1932 TRACE("(%p)->(%p %p)\n", This
, aURI
, _retval
);
1935 return nsIProtocolHandler_NewChannel(This
->nshandler
, aURI
, _retval
);
1936 return NS_ERROR_NOT_IMPLEMENTED
;
1939 static nsresult NSAPI
nsProtocolHandler_AllowPort(nsIProtocolHandler
*iface
,
1940 PRInt32 port
, const char *scheme
, PRBool
*_retval
)
1942 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
1944 TRACE("(%p)->(%d %s %p)\n", This
, port
, debugstr_a(scheme
), _retval
);
1947 return nsIProtocolHandler_AllowPort(This
->nshandler
, port
, scheme
, _retval
);
1948 return NS_ERROR_NOT_IMPLEMENTED
;
1951 #undef NSPROTHANDLER_THIS
1953 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl
= {
1954 nsProtocolHandler_QueryInterface
,
1955 nsProtocolHandler_AddRef
,
1956 nsProtocolHandler_Release
,
1957 nsProtocolHandler_GetScheme
,
1958 nsProtocolHandler_GetDefaultPort
,
1959 nsProtocolHandler_GetProtocolFlags
,
1960 nsProtocolHandler_NewURI
,
1961 nsProtocolHandler_NewChannel
,
1962 nsProtocolHandler_AllowPort
1965 static nsIProtocolHandler
*create_protocol_handler(nsIProtocolHandler
*nshandler
)
1967 nsProtocolHandler
*ret
= heap_alloc(sizeof(nsProtocolHandler
));
1969 ret
->lpProtocolHandlerVtbl
= &nsProtocolHandlerVtbl
;
1971 ret
->nshandler
= nshandler
;
1973 return NSPROTHANDLER(ret
);
1976 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*,nsIIDRef
,nsQIResult
);
1978 static nsrefcnt NSAPI
nsIOService_AddRef(nsIIOService
*iface
)
1983 static nsrefcnt NSAPI
nsIOService_Release(nsIIOService
*iface
)
1988 static nsresult NSAPI
nsIOService_GetProtocolHandler(nsIIOService
*iface
, const char *aScheme
,
1989 nsIProtocolHandler
**_retval
)
1991 nsIExternalProtocolHandler
*nsexthandler
;
1992 nsIProtocolHandler
*nshandler
;
1995 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
1997 nsres
= nsIIOService_GetProtocolHandler(nsio
, aScheme
, &nshandler
);
1998 if(NS_FAILED(nsres
)) {
1999 WARN("GetProtocolHandler failed: %08x\n", nsres
);
2003 nsres
= nsIProtocolHandler_QueryInterface(nshandler
, &IID_nsIExternalProtocolHandler
,
2004 (void**)&nsexthandler
);
2005 if(NS_FAILED(nsres
)) {
2006 *_retval
= nshandler
;
2010 nsIExternalProtocolHandler_Release(nsexthandler
);
2011 *_retval
= create_protocol_handler(nshandler
);
2012 TRACE("return %p\n", *_retval
);
2016 static nsresult NSAPI
nsIOService_GetProtocolFlags(nsIIOService
*iface
, const char *aScheme
,
2019 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
2020 return nsIIOService_GetProtocolFlags(nsio
, aScheme
, _retval
);
2023 static BOOL
is_gecko_special_uri(const char *spec
)
2025 static const char chromeW
[] = "chrome:";
2026 static const char jarW
[] = "jar:";
2027 static const char resourceW
[] = "resource:";
2028 static const char javascriptW
[] = "javascript:";
2030 return !strncasecmp(spec
, chromeW
, sizeof(chromeW
)-1)
2031 || !strncasecmp(spec
, resourceW
, sizeof(resourceW
)-1)
2032 || !strncasecmp(spec
, jarW
, sizeof(jarW
)-1)
2033 || !strncasecmp(spec
, javascriptW
, sizeof(javascriptW
)-1);
2036 static nsresult NSAPI
nsIOService_NewURI(nsIIOService
*iface
, const nsACString
*aSpec
,
2037 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
2039 const char *spec
= NULL
;
2040 nsACString spec_str
;
2041 NSContainer
*nscontainer
= NULL
;
2043 LPCWSTR base_wine_url
= NULL
;
2044 nsIWineURI
*base_wine_uri
= NULL
, *wine_uri
;
2045 BOOL is_wine_uri
= FALSE
;
2048 nsACString_GetData(aSpec
, &spec
);
2050 TRACE("(%p(%s) %s %p %p)\n", aSpec
, debugstr_a(spec
), debugstr_a(aOriginCharset
),
2053 if(is_gecko_special_uri(spec
))
2054 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2056 if(!strncmp(spec
, "wine:", 5)) {
2062 nsACString base_uri_str
;
2063 const char *base_uri
= NULL
;
2065 nsACString_Init(&base_uri_str
, NULL
);
2067 nsres
= nsIURI_GetSpec(aBaseURI
, &base_uri_str
);
2068 if(NS_SUCCEEDED(nsres
)) {
2069 nsACString_GetData(&base_uri_str
, &base_uri
);
2070 TRACE("base_uri=%s\n", debugstr_a(base_uri
));
2072 ERR("GetSpec failed: %08x\n", nsres
);
2075 nsACString_Finish(&base_uri_str
);
2078 nsACString_Init(&spec_str
, spec
);
2079 nsres
= nsIIOService_NewURI(nsio
, &spec_str
, aOriginCharset
, aBaseURI
, &uri
);
2080 nsACString_Finish(&spec_str
);
2081 if(NS_FAILED(nsres
))
2082 TRACE("NewURI failed: %08x\n", nsres
);
2085 nsres
= nsIURI_QueryInterface(aBaseURI
, &IID_nsIWineURI
, (void**)&base_wine_uri
);
2086 if(NS_SUCCEEDED(nsres
)) {
2087 nsIWineURI_GetNSContainer(base_wine_uri
, &nscontainer
);
2088 nsIWineURI_GetWineURL(base_wine_uri
, &base_wine_url
);
2090 TRACE("Could not get base nsIWineURI: %08x\n", nsres
);
2094 TRACE("nscontainer = %p\n", nscontainer
);
2096 nsres
= create_uri(uri
, nscontainer
, &wine_uri
);
2097 *_retval
= (nsIURI
*)wine_uri
;
2100 nsIWebBrowserChrome_Release(NSWBCHROME(nscontainer
));
2103 WCHAR url
[INTERNET_MAX_URL_LENGTH
], rel_url
[INTERNET_MAX_URL_LENGTH
];
2107 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, rel_url
, sizeof(rel_url
)/sizeof(WCHAR
));
2109 hres
= CoInternetCombineUrl(base_wine_url
, rel_url
,
2110 URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
2111 url
, sizeof(url
)/sizeof(WCHAR
), &len
, 0);
2113 nsIWineURI_SetWineURL(wine_uri
, url
);
2115 WARN("CoCombineUrl failed: %08x\n", hres
);
2116 }else if(is_wine_uri
) {
2117 WCHAR url
[INTERNET_MAX_URL_LENGTH
];
2119 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, url
, sizeof(url
)/sizeof(WCHAR
));
2120 nsIWineURI_SetWineURL(wine_uri
, url
);
2124 nsIWineURI_Release(base_wine_uri
);
2129 static nsresult NSAPI
nsIOService_NewFileURI(nsIIOService
*iface
, nsIFile
*aFile
,
2132 TRACE("(%p %p)\n", aFile
, _retval
);
2133 return nsIIOService_NewFileURI(nsio
, aFile
, _retval
);
2136 static nsresult NSAPI
nsIOService_NewChannelFromURI(nsIIOService
*iface
, nsIURI
*aURI
,
2137 nsIChannel
**_retval
)
2139 nsIChannel
*channel
= NULL
;
2141 nsIWineURI
*wine_uri
;
2144 TRACE("(%p %p)\n", aURI
, _retval
);
2146 nsres
= nsIIOService_NewChannelFromURI(nsio
, aURI
, &channel
);
2147 if(NS_FAILED(nsres
) && nsres
!= NS_ERROR_UNKNOWN_PROTOCOL
) {
2148 WARN("NewChannelFromURI failed: %08x\n", nsres
);
2153 nsres
= nsIURI_QueryInterface(aURI
, &IID_nsIWineURI
, (void**)&wine_uri
);
2154 if(NS_FAILED(nsres
)) {
2155 WARN("Could not get nsIWineURI: %08x\n", nsres
);
2157 return channel
? NS_OK
: NS_ERROR_UNEXPECTED
;
2160 ret
= heap_alloc_zero(sizeof(nsChannel
));
2162 ret
->lpHttpChannelVtbl
= &nsChannelVtbl
;
2163 ret
->lpUploadChannelVtbl
= &nsUploadChannelVtbl
;
2165 ret
->channel
= channel
;
2166 ret
->uri
= wine_uri
;
2168 nsIURI_AddRef(aURI
);
2169 ret
->original_uri
= aURI
;
2172 nsIChannel_QueryInterface(channel
, &IID_nsIHttpChannel
, (void**)&ret
->http_channel
);
2174 *_retval
= NSCHANNEL(ret
);
2178 static nsresult NSAPI
nsIOService_NewChannel(nsIIOService
*iface
, const nsACString
*aSpec
,
2179 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIChannel
**_retval
)
2181 TRACE("(%p %s %p %p)\n", aSpec
, debugstr_a(aOriginCharset
), aBaseURI
, _retval
);
2182 return nsIIOService_NewChannel(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2185 static nsresult NSAPI
nsIOService_GetOffline(nsIIOService
*iface
, PRBool
*aOffline
)
2187 TRACE("(%p)\n", aOffline
);
2188 return nsIIOService_GetOffline(nsio
, aOffline
);
2191 static nsresult NSAPI
nsIOService_SetOffline(nsIIOService
*iface
, PRBool aOffline
)
2193 TRACE("(%x)\n", aOffline
);
2194 return nsIIOService_SetOffline(nsio
, aOffline
);
2197 static nsresult NSAPI
nsIOService_AllowPort(nsIIOService
*iface
, PRInt32 aPort
,
2198 const char *aScheme
, PRBool
*_retval
)
2200 TRACE("(%d %s %p)\n", aPort
, debugstr_a(aScheme
), _retval
);
2201 return nsIIOService_AllowPort(nsio
, aPort
, debugstr_a(aScheme
), _retval
);
2204 static nsresult NSAPI
nsIOService_ExtractScheme(nsIIOService
*iface
, const nsACString
*urlString
,
2205 nsACString
* _retval
)
2207 TRACE("(%p %p)\n", urlString
, _retval
);
2208 return nsIIOService_ExtractScheme(nsio
, urlString
, _retval
);
2211 static const nsIIOServiceVtbl nsIOServiceVtbl
= {
2212 nsIOService_QueryInterface
,
2214 nsIOService_Release
,
2215 nsIOService_GetProtocolHandler
,
2216 nsIOService_GetProtocolFlags
,
2218 nsIOService_NewFileURI
,
2219 nsIOService_NewChannelFromURI
,
2220 nsIOService_NewChannel
,
2221 nsIOService_GetOffline
,
2222 nsIOService_SetOffline
,
2223 nsIOService_AllowPort
,
2224 nsIOService_ExtractScheme
2227 static nsIIOService nsIOService
= { &nsIOServiceVtbl
};
2229 static nsresult NSAPI
nsNetUtil_QueryInterface(nsINetUtil
*iface
, nsIIDRef riid
,
2232 return nsIIOService_QueryInterface(&nsIOService
, riid
, result
);
2235 static nsrefcnt NSAPI
nsNetUtil_AddRef(nsINetUtil
*iface
)
2240 static nsrefcnt NSAPI
nsNetUtil_Release(nsINetUtil
*iface
)
2245 static nsresult NSAPI
nsNetUtil_ParseContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
2246 nsACString
*aCharset
, PRBool
*aHadCharset
, nsACString
*aContentType
)
2248 nsINetUtil
*net_util
;
2251 TRACE("(%p %p %p %p)\n", aTypeHeader
, aCharset
, aHadCharset
, aContentType
);
2253 nsres
= nsIIOService_QueryInterface(nsio
, &IID_nsINetUtil
, (void**)&net_util
);
2254 if(NS_FAILED(nsres
)) {
2255 WARN("Could not get nsINetUtil interface: %08x\n", nsres
);
2259 nsres
= nsINetUtil_ParseContentType(net_util
, aTypeHeader
, aCharset
, aHadCharset
, aContentType
);
2261 nsINetUtil_Release(net_util
);
2265 static const nsINetUtilVtbl nsNetUtilVtbl
= {
2266 nsNetUtil_QueryInterface
,
2269 nsNetUtil_ParseContentType
2272 static nsINetUtil nsNetUtil
= { &nsNetUtilVtbl
};
2274 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*iface
, nsIIDRef riid
,
2279 if(IsEqualGUID(&IID_nsISupports
, riid
))
2280 *result
= &nsIOService
;
2281 else if(IsEqualGUID(&IID_nsIIOService
, riid
))
2282 *result
= &nsIOService
;
2283 else if(IsEqualGUID(&IID_nsINetUtil
, riid
))
2284 *result
= &nsNetUtil
;
2287 nsISupports_AddRef((nsISupports
*)*result
);
2291 FIXME("(%s %p)\n", debugstr_guid(riid
), result
);
2292 return NS_NOINTERFACE
;
2295 static nsresult NSAPI
nsIOServiceFactory_QueryInterface(nsIFactory
*iface
, nsIIDRef riid
,
2300 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
2301 TRACE("(IID_nsISupports %p)\n", result
);
2303 }else if(IsEqualGUID(&IID_nsIFactory
, riid
)) {
2304 TRACE("(IID_nsIFactory %p)\n", result
);
2309 nsIFactory_AddRef(iface
);
2313 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
2314 return NS_NOINTERFACE
;
2317 static nsrefcnt NSAPI
nsIOServiceFactory_AddRef(nsIFactory
*iface
)
2322 static nsrefcnt NSAPI
nsIOServiceFactory_Release(nsIFactory
*iface
)
2327 static nsresult NSAPI
nsIOServiceFactory_CreateInstance(nsIFactory
*iface
,
2328 nsISupports
*aOuter
, const nsIID
*iid
, void **result
)
2330 return nsIIOService_QueryInterface(&nsIOService
, iid
, result
);
2333 static nsresult NSAPI
nsIOServiceFactory_LockFactory(nsIFactory
*iface
, PRBool lock
)
2335 WARN("(%x)\n", lock
);
2339 static const nsIFactoryVtbl nsIOServiceFactoryVtbl
= {
2340 nsIOServiceFactory_QueryInterface
,
2341 nsIOServiceFactory_AddRef
,
2342 nsIOServiceFactory_Release
,
2343 nsIOServiceFactory_CreateInstance
,
2344 nsIOServiceFactory_LockFactory
2347 static nsIFactory nsIOServiceFactory
= { &nsIOServiceFactoryVtbl
};
2349 void init_nsio(nsIComponentManager
*component_manager
, nsIComponentRegistrar
*registrar
)
2351 nsIFactory
*old_factory
= NULL
;
2354 nsres
= nsIComponentManager_GetClassObject(component_manager
, &NS_IOSERVICE_CID
,
2355 &IID_nsIFactory
, (void**)&old_factory
);
2356 if(NS_FAILED(nsres
)) {
2357 ERR("Could not get factory: %08x\n", nsres
);
2361 nsres
= nsIFactory_CreateInstance(old_factory
, NULL
, &IID_nsIIOService
, (void**)&nsio
);
2362 if(NS_FAILED(nsres
)) {
2363 ERR("Couldn not create nsIOService instance %08x\n", nsres
);
2364 nsIFactory_Release(old_factory
);
2368 nsres
= nsIComponentRegistrar_UnregisterFactory(registrar
, &NS_IOSERVICE_CID
, old_factory
);
2369 nsIFactory_Release(old_factory
);
2370 if(NS_FAILED(nsres
))
2371 ERR("UnregisterFactory failed: %08x\n", nsres
);
2373 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_IOSERVICE_CID
,
2374 NS_IOSERVICE_CLASSNAME
, NS_IOSERVICE_CONTRACTID
, &nsIOServiceFactory
);
2375 if(NS_FAILED(nsres
))
2376 ERR("RegisterFactory failed: %08x\n", nsres
);