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 NS_IOSERVICE_CLASSNAME "nsIOService"
42 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
44 static const IID NS_IOSERVICE_CID
=
45 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
46 static const IID IID_nsWineURI
=
47 {0x5088272e, 0x900b, 0x11da, {0xc6,0x87, 0x00,0x0f,0xea,0x57,0xf2,0x1a}};
49 static nsIIOService
*nsio
= NULL
;
50 static nsINetUtil
*net_util
;
52 static const WCHAR about_blankW
[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
55 const nsIURLVtbl
*lpIURLVtbl
;
61 NSContainer
*container
;
62 windowref_t
*window_ref
;
63 nsChannelBSC
*channel_bsc
;
69 #define NSURI(x) ((nsIURI*) &(x)->lpIURLVtbl)
70 #define NSURL(x) ((nsIURL*) &(x)->lpIURLVtbl)
72 static nsresult
create_uri(nsIURI
*,HTMLWindow
*,NSContainer
*,nsWineURI
**);
74 static const char *debugstr_nsacstr(const nsACString
*nsstr
)
78 nsACString_GetData(nsstr
, &data
);
79 return debugstr_a(data
);
82 HRESULT
nsuri_to_url(LPCWSTR nsuri
, BOOL ret_empty
, BSTR
*ret
)
84 const WCHAR
*ptr
= nsuri
;
86 static const WCHAR wine_prefixW
[] = {'w','i','n','e',':'};
88 if(!strncmpW(nsuri
, wine_prefixW
, sizeof(wine_prefixW
)/sizeof(WCHAR
)))
89 ptr
+= sizeof(wine_prefixW
)/sizeof(WCHAR
);
91 if(*ptr
|| ret_empty
) {
92 *ret
= SysAllocString(ptr
);
99 TRACE("%s -> %s\n", debugstr_w(nsuri
), debugstr_w(*ret
));
103 static BOOL
exec_shldocvw_67(HTMLDocumentObj
*doc
, LPCWSTR url
)
105 IOleCommandTarget
*cmdtrg
= NULL
;
108 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
109 if(SUCCEEDED(hres
)) {
110 VARIANT varUrl
, varRes
;
112 V_VT(&varUrl
) = VT_BSTR
;
113 V_BSTR(&varUrl
) = SysAllocString(url
);
114 V_VT(&varRes
) = VT_BOOL
;
116 hres
= IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 67, 0, &varUrl
, &varRes
);
118 IOleCommandTarget_Release(cmdtrg
);
119 SysFreeString(V_BSTR(&varUrl
));
121 if(SUCCEEDED(hres
) && !V_BOOL(&varRes
)) {
122 TRACE("got VARIANT_FALSE, do not load\n");
130 static BOOL
before_async_open(nsChannel
*channel
, NSContainer
*container
)
132 HTMLDocumentObj
*doc
= container
->doc
;
138 NSContainer
*container_iter
= container
;
140 hlnf
= HLNF_OPENINNEWWINDOW
;
141 while(!container_iter
->doc
)
142 container_iter
= container_iter
->parent
;
143 doc
= container_iter
->doc
;
149 if(!hlnf
&& !exec_shldocvw_67(doc
, channel
->uri
->wine_url
))
152 hres
= hlink_frame_navigate(&doc
->basedoc
, channel
->uri
->wine_url
, channel
->post_data_stream
, hlnf
, &cancel
);
153 return FAILED(hres
) || cancel
;
156 HRESULT
load_nsuri(HTMLWindow
*window
, nsWineURI
*uri
, nsChannelBSC
*channelbsc
, DWORD flags
)
158 nsIWebNavigation
*web_navigation
;
159 nsIDocShell
*doc_shell
;
162 nsres
= get_nsinterface((nsISupports
*)window
->nswindow
, &IID_nsIWebNavigation
, (void**)&web_navigation
);
163 if(NS_FAILED(nsres
)) {
164 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
168 nsres
= nsIWebNavigation_QueryInterface(web_navigation
, &IID_nsIDocShell
, (void**)&doc_shell
);
169 nsIWebNavigation_Release(web_navigation
);
170 if(NS_FAILED(nsres
)) {
171 ERR("Could not get nsIDocShell: %08x\n", nsres
);
176 uri
->channel_bsc
= channelbsc
;
177 nsres
= nsIDocShell_LoadURI(doc_shell
, NSURI(uri
), NULL
, flags
, FALSE
);
178 uri
->channel_bsc
= NULL
;
179 nsIDocShell_Release(doc_shell
);
180 if(NS_FAILED(nsres
)) {
181 WARN("LoadURI failed: %08x\n", nsres
);
188 static BOOL
translate_url(HTMLDocumentObj
*doc
, nsWineURI
*uri
)
190 OLECHAR
*new_url
= NULL
, *url
;
197 url
= heap_strdupW(uri
->wine_url
);
198 hres
= IDocHostUIHandler_TranslateUrl(doc
->hostui
, 0, url
, &new_url
);
199 if(hres
== S_OK
&& new_url
) {
200 if(strcmpW(url
, new_url
)) {
201 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url
), debugstr_w(new_url
));
204 CoTaskMemFree(new_url
);
211 nsresult
on_start_uri_open(NSContainer
*nscontainer
, nsIURI
*uri
, PRBool
*_retval
)
218 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
219 if(NS_FAILED(nsres
)) {
220 WARN("Could not get nsWineURI: %08x\n", nsres
);
221 return NS_ERROR_NOT_IMPLEMENTED
;
224 if(!wine_uri
->is_doc_uri
) {
225 wine_uri
->is_doc_uri
= TRUE
;
227 if(!wine_uri
->container
) {
228 nsIWebBrowserChrome_AddRef(NSWBCHROME(nscontainer
));
229 wine_uri
->container
= nscontainer
;
233 *_retval
= translate_url(nscontainer
->doc
, wine_uri
);
236 nsIURI_Release(NSURI(wine_uri
));
240 HRESULT
set_wine_url(nsWineURI
*This
, LPCWSTR url
)
242 static const WCHAR wszFtp
[] = {'f','t','p',':'};
243 static const WCHAR wszHttp
[] = {'h','t','t','p',':'};
244 static const WCHAR wszHttps
[] = {'h','t','t','p','s',':'};
246 TRACE("(%p)->(%s)\n", This
, debugstr_w(url
));
251 new_url
= heap_strdupW(url
);
253 return E_OUTOFMEMORY
;
254 heap_free(This
->wine_url
);
255 This
->wine_url
= new_url
;
258 /* FIXME: Always use wine url */
260 strncmpW(url
, wszFtp
, sizeof(wszFtp
)/sizeof(WCHAR
))
261 && strncmpW(url
, wszHttp
, sizeof(wszHttp
)/sizeof(WCHAR
))
262 && strncmpW(url
, wszHttps
, sizeof(wszHttps
)/sizeof(WCHAR
));
264 This
->use_wine_url
= TRUE
;
267 heap_free(This
->wine_url
);
268 This
->wine_url
= NULL
;
269 This
->use_wine_url
= FALSE
;
275 static void set_uri_nscontainer(nsWineURI
*This
, NSContainer
*nscontainer
)
277 if(This
->container
) {
278 if(This
->container
== nscontainer
)
280 TRACE("Changing %p -> %p\n", This
->container
, nscontainer
);
281 nsIWebBrowserChrome_Release(NSWBCHROME(This
->container
));
285 nsIWebBrowserChrome_AddRef(NSWBCHROME(nscontainer
));
286 This
->container
= nscontainer
;
289 static void set_uri_window(nsWineURI
*This
, HTMLWindow
*window
)
291 if(This
->window_ref
) {
292 if(This
->window_ref
->window
== window
)
294 TRACE("Changing %p -> %p\n", This
->window_ref
->window
, window
);
295 windowref_release(This
->window_ref
);
299 windowref_addref(window
->window_ref
);
300 This
->window_ref
= window
->window_ref
;
303 set_uri_nscontainer(This
, window
->doc_obj
->nscontainer
);
305 This
->window_ref
= NULL
;
309 static inline BOOL
is_http_channel(nsChannel
*This
)
311 return This
->url_scheme
== URL_SCHEME_HTTP
|| This
->url_scheme
== URL_SCHEME_HTTPS
;
314 static http_header_t
*find_http_header(struct list
*headers
, const WCHAR
*name
, int len
)
318 LIST_FOR_EACH_ENTRY(iter
, headers
, http_header_t
, entry
) {
319 if(!strcmpiW(iter
->header
, name
))
326 static nsresult
get_channel_http_header(struct list
*headers
, const nsACString
*header_name_str
,
329 const char *header_namea
;
330 http_header_t
*header
;
334 nsACString_GetData(header_name_str
, &header_namea
);
335 header_name
= heap_strdupAtoW(header_namea
);
337 return NS_ERROR_UNEXPECTED
;
339 header
= find_http_header(headers
, header_name
, strlenW(header_name
));
340 heap_free(header_name
);
342 return NS_ERROR_NOT_AVAILABLE
;
344 data
= heap_strdupWtoA(header
->data
);
346 return NS_ERROR_UNEXPECTED
;
348 nsACString_SetData(_retval
, data
);
353 HRESULT
set_http_header(struct list
*headers
, const WCHAR
*name
, int name_len
,
354 const WCHAR
*value
, int value_len
)
356 http_header_t
*header
;
358 TRACE("%s: %s\n", debugstr_wn(name
, name_len
), debugstr_wn(value
, value_len
));
360 header
= find_http_header(headers
, name
, name_len
);
364 new_data
= heap_strndupW(value
, value_len
);
366 return E_OUTOFMEMORY
;
368 heap_free(header
->data
);
369 header
->data
= new_data
;
371 header
= heap_alloc(sizeof(http_header_t
));
373 return E_OUTOFMEMORY
;
375 header
->header
= heap_strndupW(name
, name_len
);
376 header
->data
= heap_strndupW(value
, value_len
);
377 if(!header
->header
|| !header
->data
) {
378 heap_free(header
->header
);
379 heap_free(header
->data
);
381 return E_OUTOFMEMORY
;
384 list_add_tail(headers
, &header
->entry
);
390 static void free_http_headers(struct list
*list
)
392 http_header_t
*iter
, *iter_next
;
394 LIST_FOR_EACH_ENTRY_SAFE(iter
, iter_next
, list
, http_header_t
, entry
) {
395 list_remove(&iter
->entry
);
396 heap_free(iter
->header
);
397 heap_free(iter
->data
);
402 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
404 static nsresult NSAPI
nsChannel_QueryInterface(nsIHttpChannel
*iface
, nsIIDRef riid
, void **result
)
406 nsChannel
*This
= NSCHANNEL_THIS(iface
);
408 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
409 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
410 *result
= NSCHANNEL(This
);
411 }else if(IsEqualGUID(&IID_nsIRequest
, riid
)) {
412 TRACE("(%p)->(IID_nsIRequest %p)\n", This
, result
);
413 *result
= NSCHANNEL(This
);
414 }else if(IsEqualGUID(&IID_nsIChannel
, riid
)) {
415 TRACE("(%p)->(IID_nsIChannel %p)\n", This
, result
);
416 *result
= NSCHANNEL(This
);
417 }else if(IsEqualGUID(&IID_nsIHttpChannel
, riid
)) {
418 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This
, result
);
419 *result
= is_http_channel(This
) ? NSHTTPCHANNEL(This
) : NULL
;
420 }else if(IsEqualGUID(&IID_nsIUploadChannel
, riid
)) {
421 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This
, result
);
422 *result
= NSUPCHANNEL(This
);
423 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal
, riid
)) {
424 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This
, result
);
425 *result
= is_http_channel(This
) ? NSHTTPINTERNAL(This
) : NULL
;
427 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
432 nsIChannel_AddRef(NSCHANNEL(This
));
436 return NS_NOINTERFACE
;
439 static nsrefcnt NSAPI
nsChannel_AddRef(nsIHttpChannel
*iface
)
441 nsChannel
*This
= NSCHANNEL_THIS(iface
);
442 nsrefcnt ref
= InterlockedIncrement(&This
->ref
);
444 TRACE("(%p) ref=%d\n", This
, ref
);
449 static nsrefcnt NSAPI
nsChannel_Release(nsIHttpChannel
*iface
)
451 nsChannel
*This
= NSCHANNEL_THIS(iface
);
452 LONG ref
= InterlockedDecrement(&This
->ref
);
455 nsIURI_Release(NSURI(This
->uri
));
457 nsISupports_Release(This
->owner
);
458 if(This
->post_data_stream
)
459 nsIInputStream_Release(This
->post_data_stream
);
461 nsILoadGroup_Release(This
->load_group
);
462 if(This
->notif_callback
)
463 nsIInterfaceRequestor_Release(This
->notif_callback
);
464 if(This
->original_uri
)
465 nsIURI_Release(This
->original_uri
);
467 free_http_headers(&This
->response_headers
);
468 free_http_headers(&This
->request_headers
);
470 heap_free(This
->content_type
);
471 heap_free(This
->charset
);
478 static nsresult NSAPI
nsChannel_GetName(nsIHttpChannel
*iface
, nsACString
*aName
)
480 nsChannel
*This
= NSCHANNEL_THIS(iface
);
482 FIXME("(%p)->(%p)\n", This
, aName
);
484 return NS_ERROR_NOT_IMPLEMENTED
;
487 static nsresult NSAPI
nsChannel_IsPending(nsIHttpChannel
*iface
, PRBool
*_retval
)
489 nsChannel
*This
= NSCHANNEL_THIS(iface
);
491 FIXME("(%p)->(%p)\n", This
, _retval
);
493 return NS_ERROR_NOT_IMPLEMENTED
;
496 static nsresult NSAPI
nsChannel_GetStatus(nsIHttpChannel
*iface
, nsresult
*aStatus
)
498 nsChannel
*This
= NSCHANNEL_THIS(iface
);
500 WARN("(%p)->(%p) returning NS_OK\n", This
, aStatus
);
502 return *aStatus
= NS_OK
;
505 static nsresult NSAPI
nsChannel_Cancel(nsIHttpChannel
*iface
, nsresult aStatus
)
507 nsChannel
*This
= NSCHANNEL_THIS(iface
);
509 FIXME("(%p)->(%08x)\n", This
, aStatus
);
511 return NS_ERROR_NOT_IMPLEMENTED
;
514 static nsresult NSAPI
nsChannel_Suspend(nsIHttpChannel
*iface
)
516 nsChannel
*This
= NSCHANNEL_THIS(iface
);
518 FIXME("(%p)\n", This
);
520 return NS_ERROR_NOT_IMPLEMENTED
;
523 static nsresult NSAPI
nsChannel_Resume(nsIHttpChannel
*iface
)
525 nsChannel
*This
= NSCHANNEL_THIS(iface
);
527 FIXME("(%p)\n", This
);
529 return NS_ERROR_NOT_IMPLEMENTED
;
532 static nsresult NSAPI
nsChannel_GetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
**aLoadGroup
)
534 nsChannel
*This
= NSCHANNEL_THIS(iface
);
536 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
539 nsILoadGroup_AddRef(This
->load_group
);
541 *aLoadGroup
= This
->load_group
;
545 static nsresult NSAPI
nsChannel_SetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
*aLoadGroup
)
547 nsChannel
*This
= NSCHANNEL_THIS(iface
);
549 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
552 nsILoadGroup_Release(This
->load_group
);
554 nsILoadGroup_AddRef(aLoadGroup
);
555 This
->load_group
= aLoadGroup
;
560 static nsresult NSAPI
nsChannel_GetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags
*aLoadFlags
)
562 nsChannel
*This
= NSCHANNEL_THIS(iface
);
564 TRACE("(%p)->(%p)\n", This
, aLoadFlags
);
566 *aLoadFlags
= This
->load_flags
;
570 static nsresult NSAPI
nsChannel_SetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags aLoadFlags
)
572 nsChannel
*This
= NSCHANNEL_THIS(iface
);
574 TRACE("(%p)->(%08x)\n", This
, aLoadFlags
);
576 This
->load_flags
= aLoadFlags
;
580 static nsresult NSAPI
nsChannel_GetOriginalURI(nsIHttpChannel
*iface
, nsIURI
**aOriginalURI
)
582 nsChannel
*This
= NSCHANNEL_THIS(iface
);
584 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
586 if(This
->original_uri
)
587 nsIURI_AddRef(This
->original_uri
);
589 *aOriginalURI
= This
->original_uri
;
593 static nsresult NSAPI
nsChannel_SetOriginalURI(nsIHttpChannel
*iface
, nsIURI
*aOriginalURI
)
595 nsChannel
*This
= NSCHANNEL_THIS(iface
);
597 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
599 if(This
->original_uri
)
600 nsIURI_Release(This
->original_uri
);
602 nsIURI_AddRef(aOriginalURI
);
603 This
->original_uri
= aOriginalURI
;
607 static nsresult NSAPI
nsChannel_GetURI(nsIHttpChannel
*iface
, nsIURI
**aURI
)
609 nsChannel
*This
= NSCHANNEL_THIS(iface
);
611 TRACE("(%p)->(%p)\n", This
, aURI
);
613 nsIURI_AddRef(NSURI(This
->uri
));
614 *aURI
= (nsIURI
*)This
->uri
;
619 static nsresult NSAPI
nsChannel_GetOwner(nsIHttpChannel
*iface
, nsISupports
**aOwner
)
621 nsChannel
*This
= NSCHANNEL_THIS(iface
);
623 TRACE("(%p)->(%p)\n", This
, aOwner
);
626 nsISupports_AddRef(This
->owner
);
627 *aOwner
= This
->owner
;
632 static nsresult NSAPI
nsChannel_SetOwner(nsIHttpChannel
*iface
, nsISupports
*aOwner
)
634 nsChannel
*This
= NSCHANNEL_THIS(iface
);
636 TRACE("(%p)->(%p)\n", This
, aOwner
);
639 nsISupports_AddRef(aOwner
);
641 nsISupports_Release(This
->owner
);
642 This
->owner
= aOwner
;
647 static nsresult NSAPI
nsChannel_GetNotificationCallbacks(nsIHttpChannel
*iface
,
648 nsIInterfaceRequestor
**aNotificationCallbacks
)
650 nsChannel
*This
= NSCHANNEL_THIS(iface
);
652 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
654 if(This
->notif_callback
)
655 nsIInterfaceRequestor_AddRef(This
->notif_callback
);
656 *aNotificationCallbacks
= This
->notif_callback
;
661 static nsresult NSAPI
nsChannel_SetNotificationCallbacks(nsIHttpChannel
*iface
,
662 nsIInterfaceRequestor
*aNotificationCallbacks
)
664 nsChannel
*This
= NSCHANNEL_THIS(iface
);
666 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
668 if(This
->notif_callback
)
669 nsIInterfaceRequestor_Release(This
->notif_callback
);
670 if(aNotificationCallbacks
)
671 nsIInterfaceRequestor_AddRef(aNotificationCallbacks
);
673 This
->notif_callback
= aNotificationCallbacks
;
678 static nsresult NSAPI
nsChannel_GetSecurityInfo(nsIHttpChannel
*iface
, nsISupports
**aSecurityInfo
)
680 nsChannel
*This
= NSCHANNEL_THIS(iface
);
682 TRACE("(%p)->(%p)\n", This
, aSecurityInfo
);
684 return NS_ERROR_NOT_IMPLEMENTED
;
687 static nsresult NSAPI
nsChannel_GetContentType(nsIHttpChannel
*iface
, nsACString
*aContentType
)
689 nsChannel
*This
= NSCHANNEL_THIS(iface
);
691 TRACE("(%p)->(%p)\n", This
, aContentType
);
693 if(This
->content_type
) {
694 nsACString_SetData(aContentType
, This
->content_type
);
698 WARN("unknown type\n");
699 return NS_ERROR_FAILURE
;
702 static nsresult NSAPI
nsChannel_SetContentType(nsIHttpChannel
*iface
,
703 const nsACString
*aContentType
)
705 nsChannel
*This
= NSCHANNEL_THIS(iface
);
706 const char *content_type
;
708 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentType
));
710 nsACString_GetData(aContentType
, &content_type
);
711 heap_free(This
->content_type
);
712 This
->content_type
= heap_strdupA(content_type
);
717 static nsresult NSAPI
nsChannel_GetContentCharset(nsIHttpChannel
*iface
,
718 nsACString
*aContentCharset
)
720 nsChannel
*This
= NSCHANNEL_THIS(iface
);
722 TRACE("(%p)->(%p)\n", This
, aContentCharset
);
725 nsACString_SetData(aContentCharset
, This
->charset
);
729 nsACString_SetData(aContentCharset
, "");
733 static nsresult NSAPI
nsChannel_SetContentCharset(nsIHttpChannel
*iface
,
734 const nsACString
*aContentCharset
)
736 nsChannel
*This
= NSCHANNEL_THIS(iface
);
738 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentCharset
));
740 return NS_ERROR_NOT_IMPLEMENTED
;
743 static nsresult NSAPI
nsChannel_GetContentLength(nsIHttpChannel
*iface
, PRInt32
*aContentLength
)
745 nsChannel
*This
= NSCHANNEL_THIS(iface
);
747 FIXME("(%p)->(%p)\n", This
, aContentLength
);
749 return NS_ERROR_NOT_IMPLEMENTED
;
752 static nsresult NSAPI
nsChannel_SetContentLength(nsIHttpChannel
*iface
, PRInt32 aContentLength
)
754 nsChannel
*This
= NSCHANNEL_THIS(iface
);
756 FIXME("(%p)->(%d)\n", This
, aContentLength
);
758 return NS_ERROR_NOT_IMPLEMENTED
;
761 static nsresult NSAPI
nsChannel_Open(nsIHttpChannel
*iface
, nsIInputStream
**_retval
)
763 nsChannel
*This
= NSCHANNEL_THIS(iface
);
765 FIXME("(%p)->(%p)\n", This
, _retval
);
767 return NS_ERROR_NOT_IMPLEMENTED
;
770 static HRESULT
create_mon_for_nschannel(nsChannel
*channel
, IMoniker
**mon
)
776 if(!channel
->original_uri
) {
777 ERR("original_uri == NULL\n");
781 nsres
= nsIURI_QueryInterface(channel
->original_uri
, &IID_nsWineURI
, (void**)&wine_uri
);
782 if(NS_FAILED(nsres
)) {
783 ERR("Could not get nsWineURI: %08x\n", nsres
);
787 if(wine_uri
->wine_url
) {
788 hres
= CreateURLMoniker(NULL
, wine_uri
->wine_url
, mon
);
790 WARN("CreateURLMoniker failed: %08x\n", hres
);
792 TRACE("wine_url == NULL\n");
796 nsIURI_Release(NSURI(wine_uri
));
801 static HTMLWindow
*get_window_from_load_group(nsChannel
*This
)
810 nsres
= nsILoadGroup_GetDefaultLoadRequest(This
->load_group
, &req
);
811 if(NS_FAILED(nsres
)) {
812 ERR("GetDefaultLoadRequest failed: %08x\n", nsres
);
819 nsres
= nsIRequest_QueryInterface(req
, &IID_nsIChannel
, (void**)&channel
);
820 nsIRequest_Release(req
);
821 if(NS_FAILED(nsres
)) {
822 WARN("Could not get nsIChannel interface: %08x\n", nsres
);
826 nsres
= nsIChannel_GetURI(channel
, &uri
);
827 nsIChannel_Release(channel
);
828 if(NS_FAILED(nsres
)) {
829 ERR("GetURI failed: %08x\n", nsres
);
833 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
835 if(NS_FAILED(nsres
)) {
836 TRACE("Could not get nsWineURI: %08x\n", nsres
);
840 window
= wine_uri
->window_ref
? wine_uri
->window_ref
->window
: NULL
;
842 IHTMLWindow2_AddRef(HTMLWINDOW2(window
));
843 nsIURI_Release(NSURI(wine_uri
));
848 static HTMLWindow
*get_channel_window(nsChannel
*This
)
850 nsIRequestObserver
*req_observer
;
851 nsIWebProgress
*web_progress
;
852 nsIDOMWindow
*nswindow
;
856 if(!This
->load_group
) {
857 ERR("NULL load_group\n");
861 nsres
= nsILoadGroup_GetGroupObserver(This
->load_group
, &req_observer
);
862 if(NS_FAILED(nsres
) || !req_observer
) {
863 ERR("GetGroupObserver failed: %08x\n", nsres
);
867 nsres
= nsIRequestObserver_QueryInterface(req_observer
, &IID_nsIWebProgress
, (void**)&web_progress
);
868 nsIRequestObserver_Release(req_observer
);
869 if(NS_FAILED(nsres
)) {
870 ERR("Could not get nsIWebProgress iface: %08x\n", nsres
);
874 nsres
= nsIWebProgress_GetDOMWindow(web_progress
, &nswindow
);
875 nsIWebProgress_Release(web_progress
);
876 if(NS_FAILED(nsres
) || !nswindow
) {
877 ERR("GetDOMWindow failed: %08x\n", nsres
);
881 window
= nswindow_to_window(nswindow
);
882 nsIDOMWindow_Release(nswindow
);
885 IHTMLWindow2_AddRef(HTMLWINDOW2(window
));
887 FIXME("NULL window for %p\n", nswindow
);
893 HTMLDocumentNode
*doc
;
894 nsChannelBSC
*bscallback
;
895 } start_binding_task_t
;
897 static void start_binding_proc(task_t
*_task
)
899 start_binding_task_t
*task
= (start_binding_task_t
*)_task
;
901 start_binding(NULL
, task
->doc
, (BSCallback
*)task
->bscallback
, NULL
);
903 IUnknown_Release((IUnknown
*)task
->bscallback
);
906 static nsresult
async_open(nsChannel
*This
, HTMLWindow
*window
, BOOL is_doc_channel
, nsIStreamListener
*listener
,
907 nsISupports
*context
)
909 nsChannelBSC
*bscallback
;
910 IMoniker
*mon
= NULL
;
913 hres
= create_mon_for_nschannel(This
, &mon
);
915 return NS_ERROR_UNEXPECTED
;
918 set_current_mon(window
, mon
);
920 hres
= create_channelbsc(mon
, NULL
, NULL
, 0, &bscallback
);
921 IMoniker_Release(mon
);
923 return NS_ERROR_UNEXPECTED
;
925 channelbsc_set_channel(bscallback
, This
, listener
, context
);
928 set_window_bscallback(window
, bscallback
);
929 async_start_doc_binding(window
, bscallback
);
930 IUnknown_Release((IUnknown
*)bscallback
);
932 start_binding_task_t
*task
= heap_alloc(sizeof(start_binding_task_t
));
934 task
->doc
= window
->doc
;
935 task
->bscallback
= bscallback
;
936 push_task(&task
->header
, start_binding_proc
, window
->doc
->basedoc
.task_magic
);
942 static nsresult NSAPI
nsChannel_AsyncOpen(nsIHttpChannel
*iface
, nsIStreamListener
*aListener
,
943 nsISupports
*aContext
)
945 nsChannel
*This
= NSCHANNEL_THIS(iface
);
946 HTMLWindow
*window
= NULL
;
948 nsresult nsres
= NS_OK
;
950 TRACE("(%p)->(%p %p) opening %s\n", This
, aListener
, aContext
, debugstr_w(This
->uri
->wine_url
));
952 if(This
->uri
->is_doc_uri
) {
953 window
= get_channel_window(This
);
955 set_uri_window(This
->uri
, window
);
956 }else if(This
->uri
->container
) {
959 /* nscontainer->doc should be NULL which means navigation to a new window */
960 if(This
->uri
->container
->doc
)
961 FIXME("nscontainer->doc = %p\n", This
->uri
->container
->doc
);
963 b
= before_async_open(This
, This
->uri
->container
);
965 FIXME("Navigation not cancelled\n");
966 return NS_ERROR_UNEXPECTED
;
971 if(This
->uri
->window_ref
&& This
->uri
->window_ref
->window
) {
972 window
= This
->uri
->window_ref
->window
;
973 IHTMLWindow2_AddRef(HTMLWINDOW2(window
));
974 }else if(This
->load_group
) {
975 window
= get_window_from_load_group(This
);
977 set_uri_window(This
->uri
, window
);
982 ERR("window = NULL\n");
983 return NS_ERROR_UNEXPECTED
;
986 if(This
->uri
->is_doc_uri
&& window
== window
->doc_obj
->basedoc
.window
) {
987 if(This
->uri
->channel_bsc
) {
988 channelbsc_set_channel(This
->uri
->channel_bsc
, This
, aListener
, aContext
);
990 if(window
->doc_obj
->mime
) {
991 heap_free(This
->content_type
);
992 This
->content_type
= heap_strdupWtoA(window
->doc_obj
->mime
);
997 open
= !before_async_open(This
, window
->doc_obj
->nscontainer
);
1000 nsres
= NS_ERROR_UNEXPECTED
;
1006 nsres
= async_open(This
, window
, This
->uri
->is_doc_uri
, aListener
, aContext
);
1008 IHTMLWindow2_Release(HTMLWINDOW2(window
));
1012 static nsresult NSAPI
nsChannel_GetRequestMethod(nsIHttpChannel
*iface
, nsACString
*aRequestMethod
)
1014 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1016 FIXME("(%p)->(%p)\n", This
, aRequestMethod
);
1018 return NS_ERROR_NOT_IMPLEMENTED
;
1021 static nsresult NSAPI
nsChannel_SetRequestMethod(nsIHttpChannel
*iface
,
1022 const nsACString
*aRequestMethod
)
1024 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1026 TRACE("(%p)->(%s): Returning NS_OK\n", This
, debugstr_nsacstr(aRequestMethod
));
1031 static nsresult NSAPI
nsChannel_GetReferrer(nsIHttpChannel
*iface
, nsIURI
**aReferrer
)
1033 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1035 FIXME("(%p)->(%p)\n", This
, aReferrer
);
1037 return NS_ERROR_NOT_IMPLEMENTED
;
1040 static nsresult NSAPI
nsChannel_SetReferrer(nsIHttpChannel
*iface
, nsIURI
*aReferrer
)
1042 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1044 FIXME("(%p)->(%p)\n", This
, aReferrer
);
1049 static nsresult NSAPI
nsChannel_GetRequestHeader(nsIHttpChannel
*iface
,
1050 const nsACString
*aHeader
, nsACString
*_retval
)
1052 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1054 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aHeader
), _retval
);
1056 return get_channel_http_header(&This
->request_headers
, aHeader
, _retval
);
1059 static nsresult NSAPI
nsChannel_SetRequestHeader(nsIHttpChannel
*iface
,
1060 const nsACString
*aHeader
, const nsACString
*aValue
, PRBool aMerge
)
1062 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1064 FIXME("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(aHeader
), debugstr_nsacstr(aValue
), aMerge
);
1069 static nsresult NSAPI
nsChannel_VisitRequestHeaders(nsIHttpChannel
*iface
,
1070 nsIHttpHeaderVisitor
*aVisitor
)
1072 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1074 FIXME("(%p)->(%p)\n", This
, aVisitor
);
1076 return NS_ERROR_NOT_IMPLEMENTED
;
1079 static nsresult NSAPI
nsChannel_GetAllowPipelining(nsIHttpChannel
*iface
, PRBool
*aAllowPipelining
)
1081 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1083 FIXME("(%p)->(%p)\n", This
, aAllowPipelining
);
1085 return NS_ERROR_NOT_IMPLEMENTED
;
1088 static nsresult NSAPI
nsChannel_SetAllowPipelining(nsIHttpChannel
*iface
, PRBool aAllowPipelining
)
1090 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1092 FIXME("(%p)->(%x)\n", This
, aAllowPipelining
);
1094 return NS_ERROR_NOT_IMPLEMENTED
;
1097 static nsresult NSAPI
nsChannel_GetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32
*aRedirectionLimit
)
1099 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1101 FIXME("(%p)->(%p)\n", This
, aRedirectionLimit
);
1103 return NS_ERROR_NOT_IMPLEMENTED
;
1106 static nsresult NSAPI
nsChannel_SetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32 aRedirectionLimit
)
1108 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1110 FIXME("(%p)->(%u)\n", This
, aRedirectionLimit
);
1112 return NS_ERROR_NOT_IMPLEMENTED
;
1115 static nsresult NSAPI
nsChannel_GetResponseStatus(nsIHttpChannel
*iface
, PRUint32
*aResponseStatus
)
1117 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1119 TRACE("(%p)->(%p)\n", This
, aResponseStatus
);
1121 if(This
->response_status
) {
1122 *aResponseStatus
= This
->response_status
;
1126 WARN("No response status\n");
1127 return NS_ERROR_UNEXPECTED
;
1130 static nsresult NSAPI
nsChannel_GetResponseStatusText(nsIHttpChannel
*iface
,
1131 nsACString
*aResponseStatusText
)
1133 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1135 FIXME("(%p)->(%p)\n", This
, aResponseStatusText
);
1137 return NS_ERROR_NOT_IMPLEMENTED
;
1140 static nsresult NSAPI
nsChannel_GetRequestSucceeded(nsIHttpChannel
*iface
,
1141 PRBool
*aRequestSucceeded
)
1143 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1145 TRACE("(%p)->(%p)\n", This
, aRequestSucceeded
);
1147 if(!This
->response_status
)
1148 return NS_ERROR_NOT_AVAILABLE
;
1150 *aRequestSucceeded
= This
->response_status
/100 == 2;
1155 static nsresult NSAPI
nsChannel_GetResponseHeader(nsIHttpChannel
*iface
,
1156 const nsACString
*header
, nsACString
*_retval
)
1158 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1160 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(header
), _retval
);
1162 return get_channel_http_header(&This
->response_headers
, header
, _retval
);
1165 static nsresult NSAPI
nsChannel_SetResponseHeader(nsIHttpChannel
*iface
,
1166 const nsACString
*header
, const nsACString
*value
, PRBool merge
)
1168 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1170 FIXME("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(header
), debugstr_nsacstr(value
), merge
);
1172 return NS_ERROR_NOT_IMPLEMENTED
;
1175 static nsresult NSAPI
nsChannel_VisitResponseHeaders(nsIHttpChannel
*iface
,
1176 nsIHttpHeaderVisitor
*aVisitor
)
1178 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1180 FIXME("(%p)->(%p)\n", This
, aVisitor
);
1182 return NS_ERROR_NOT_IMPLEMENTED
;
1185 static nsresult NSAPI
nsChannel_IsNoStoreResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1187 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1189 FIXME("(%p)->(%p)\n", This
, _retval
);
1191 return NS_ERROR_NOT_IMPLEMENTED
;
1194 static nsresult NSAPI
nsChannel_IsNoCacheResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1196 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1198 FIXME("(%p)->(%p)\n", This
, _retval
);
1200 return NS_ERROR_NOT_IMPLEMENTED
;
1203 #undef NSCHANNEL_THIS
1205 static const nsIHttpChannelVtbl nsChannelVtbl
= {
1206 nsChannel_QueryInterface
,
1210 nsChannel_IsPending
,
1211 nsChannel_GetStatus
,
1215 nsChannel_GetLoadGroup
,
1216 nsChannel_SetLoadGroup
,
1217 nsChannel_GetLoadFlags
,
1218 nsChannel_SetLoadFlags
,
1219 nsChannel_GetOriginalURI
,
1220 nsChannel_SetOriginalURI
,
1224 nsChannel_GetNotificationCallbacks
,
1225 nsChannel_SetNotificationCallbacks
,
1226 nsChannel_GetSecurityInfo
,
1227 nsChannel_GetContentType
,
1228 nsChannel_SetContentType
,
1229 nsChannel_GetContentCharset
,
1230 nsChannel_SetContentCharset
,
1231 nsChannel_GetContentLength
,
1232 nsChannel_SetContentLength
,
1234 nsChannel_AsyncOpen
,
1235 nsChannel_GetRequestMethod
,
1236 nsChannel_SetRequestMethod
,
1237 nsChannel_GetReferrer
,
1238 nsChannel_SetReferrer
,
1239 nsChannel_GetRequestHeader
,
1240 nsChannel_SetRequestHeader
,
1241 nsChannel_VisitRequestHeaders
,
1242 nsChannel_GetAllowPipelining
,
1243 nsChannel_SetAllowPipelining
,
1244 nsChannel_GetRedirectionLimit
,
1245 nsChannel_SetRedirectionLimit
,
1246 nsChannel_GetResponseStatus
,
1247 nsChannel_GetResponseStatusText
,
1248 nsChannel_GetRequestSucceeded
,
1249 nsChannel_GetResponseHeader
,
1250 nsChannel_SetResponseHeader
,
1251 nsChannel_VisitResponseHeaders
,
1252 nsChannel_IsNoStoreResponse
,
1253 nsChannel_IsNoCacheResponse
1256 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1258 static nsresult NSAPI
nsUploadChannel_QueryInterface(nsIUploadChannel
*iface
, nsIIDRef riid
,
1261 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1262 return nsIChannel_QueryInterface(NSCHANNEL(This
), riid
, result
);
1265 static nsrefcnt NSAPI
nsUploadChannel_AddRef(nsIUploadChannel
*iface
)
1267 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1268 return nsIChannel_AddRef(NSCHANNEL(This
));
1271 static nsrefcnt NSAPI
nsUploadChannel_Release(nsIUploadChannel
*iface
)
1273 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1274 return nsIChannel_Release(NSCHANNEL(This
));
1277 static nsresult NSAPI
nsUploadChannel_SetUploadStream(nsIUploadChannel
*iface
,
1278 nsIInputStream
*aStream
, const nsACString
*aContentType
, PRInt32 aContentLength
)
1280 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1281 const char *content_type
;
1283 TRACE("(%p)->(%p %s %d)\n", This
, aStream
, debugstr_nsacstr(aContentType
), aContentLength
);
1285 if(This
->post_data_stream
)
1286 nsIInputStream_Release(This
->post_data_stream
);
1289 nsACString_GetData(aContentType
, &content_type
);
1291 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type
));
1294 if(aContentLength
!= -1)
1295 FIXME("Unsupported acontentLength = %d\n", aContentLength
);
1297 if(This
->post_data_stream
)
1298 nsIInputStream_Release(This
->post_data_stream
);
1299 This
->post_data_stream
= aStream
;
1301 nsIInputStream_AddRef(aStream
);
1306 static nsresult NSAPI
nsUploadChannel_GetUploadStream(nsIUploadChannel
*iface
,
1307 nsIInputStream
**aUploadStream
)
1309 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1311 TRACE("(%p)->(%p)\n", This
, aUploadStream
);
1313 if(This
->post_data_stream
)
1314 nsIInputStream_AddRef(This
->post_data_stream
);
1316 *aUploadStream
= This
->post_data_stream
;
1320 #undef NSUPCHANNEL_THIS
1322 static const nsIUploadChannelVtbl nsUploadChannelVtbl
= {
1323 nsUploadChannel_QueryInterface
,
1324 nsUploadChannel_AddRef
,
1325 nsUploadChannel_Release
,
1326 nsUploadChannel_SetUploadStream
,
1327 nsUploadChannel_GetUploadStream
1330 #define NSHTTPINTERNAL_THIS(iface) DEFINE_THIS(nsChannel, IHttpChannelInternal, iface)
1332 static nsresult NSAPI
nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal
*iface
, nsIIDRef riid
,
1335 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1336 return nsIChannel_QueryInterface(NSCHANNEL(This
), riid
, result
);
1339 static nsrefcnt NSAPI
nsHttpChannelInternal_AddRef(nsIHttpChannelInternal
*iface
)
1341 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1342 return nsIChannel_AddRef(NSCHANNEL(This
));
1345 static nsrefcnt NSAPI
nsHttpChannelInternal_Release(nsIHttpChannelInternal
*iface
)
1347 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1348 return nsIChannel_Release(NSCHANNEL(This
));
1351 static nsresult NSAPI
nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
**aDocumentURI
)
1353 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1355 FIXME("(%p)->()\n", This
);
1357 return NS_ERROR_NOT_IMPLEMENTED
;
1360 static nsresult NSAPI
nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
*aDocumentURI
)
1362 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1364 FIXME("(%p)->()\n", This
);
1366 return NS_ERROR_NOT_IMPLEMENTED
;
1369 static nsresult NSAPI
nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal
*iface
, PRUint32
*major
, PRUint32
*minor
)
1371 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1373 FIXME("(%p)->()\n", This
);
1375 return NS_ERROR_NOT_IMPLEMENTED
;
1378 static nsresult NSAPI
nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal
*iface
, PRUint32
*major
, PRUint32
*minor
)
1380 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1382 FIXME("(%p)->()\n", This
);
1384 return NS_ERROR_NOT_IMPLEMENTED
;
1387 static nsresult NSAPI
nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal
*iface
, const char *aCookieHeader
)
1389 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1391 FIXME("(%p)->()\n", This
);
1393 return NS_ERROR_NOT_IMPLEMENTED
;
1396 static nsresult NSAPI
nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal
*iface
, const char *aFallbackKey
)
1398 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1400 FIXME("(%p)->()\n", This
);
1402 return NS_ERROR_NOT_IMPLEMENTED
;
1405 static nsresult NSAPI
nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, PRBool
*aForceThirdPartyCookie
)
1407 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1409 FIXME("(%p)->()\n", This
);
1411 return NS_ERROR_NOT_IMPLEMENTED
;
1414 static nsresult NSAPI
nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, PRBool aForceThirdPartyCookie
)
1416 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1418 FIXME("(%p)->()\n", This
);
1420 return NS_ERROR_NOT_IMPLEMENTED
;
1423 #undef NSHTTPINTERNAL_THIS
1425 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl
= {
1426 nsHttpChannelInternal_QueryInterface
,
1427 nsHttpChannelInternal_AddRef
,
1428 nsHttpChannelInternal_Release
,
1429 nsHttpChannelInternal_GetDocumentURI
,
1430 nsHttpChannelInternal_SetDocumentURI
,
1431 nsHttpChannelInternal_GetRequestVersion
,
1432 nsHttpChannelInternal_GetResponseVersion
,
1433 nsHttpChannelInternal_SetCookie
,
1434 nsHttpChannelInternal_SetupFallbackChannel
,
1435 nsHttpChannelInternal_GetForceAllowThirdPartyCookie
,
1436 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
1439 #define NSURI_THIS(iface) DEFINE_THIS(nsWineURI, IURL, iface)
1441 static nsresult NSAPI
nsURI_QueryInterface(nsIURL
*iface
, nsIIDRef riid
, void **result
)
1443 nsWineURI
*This
= NSURI_THIS(iface
);
1447 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1448 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1449 *result
= NSURI(This
);
1450 }else if(IsEqualGUID(&IID_nsIURI
, riid
)) {
1451 TRACE("(%p)->(IID_nsIURI %p)\n", This
, result
);
1452 *result
= NSURI(This
);
1453 }else if(IsEqualGUID(&IID_nsIURL
, riid
)) {
1454 TRACE("(%p)->(IID_nsIURL %p)\n", This
, result
);
1455 *result
= NSURL(This
);
1456 }else if(IsEqualGUID(&IID_nsWineURI
, riid
)) {
1457 TRACE("(%p)->(IID_nsWineURI %p)\n", This
, result
);
1462 nsIURI_AddRef(NSURI(This
));
1466 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1467 return This
->uri
? nsIURI_QueryInterface(This
->uri
, riid
, result
) : NS_NOINTERFACE
;
1470 static nsrefcnt NSAPI
nsURI_AddRef(nsIURL
*iface
)
1472 nsWineURI
*This
= NSURI_THIS(iface
);
1473 LONG ref
= InterlockedIncrement(&This
->ref
);
1475 TRACE("(%p) ref=%d\n", This
, ref
);
1480 static nsrefcnt NSAPI
nsURI_Release(nsIURL
*iface
)
1482 nsWineURI
*This
= NSURI_THIS(iface
);
1483 LONG ref
= InterlockedDecrement(&This
->ref
);
1485 TRACE("(%p) ref=%d\n", This
, ref
);
1488 if(This
->window_ref
)
1489 windowref_release(This
->window_ref
);
1491 nsIWebBrowserChrome_Release(NSWBCHROME(This
->container
));
1493 nsIURL_Release(This
->nsurl
);
1495 nsIURI_Release(This
->uri
);
1496 heap_free(This
->wine_url
);
1503 static nsresult NSAPI
nsURI_GetSpec(nsIURL
*iface
, nsACString
*aSpec
)
1505 nsWineURI
*This
= NSURI_THIS(iface
);
1507 TRACE("(%p)->(%p)\n", This
, aSpec
);
1509 if(This
->use_wine_url
) {
1510 char speca
[INTERNET_MAX_URL_LENGTH
] = "wine:";
1511 WideCharToMultiByte(CP_ACP
, 0, This
->wine_url
, -1, speca
+5, sizeof(speca
)-5, NULL
, NULL
);
1512 nsACString_SetData(aSpec
, speca
);
1518 return nsIURI_GetSpec(This
->uri
, aSpec
);
1520 TRACE("returning error\n");
1521 return NS_ERROR_NOT_IMPLEMENTED
;
1525 static nsresult NSAPI
nsURI_SetSpec(nsIURL
*iface
, const nsACString
*aSpec
)
1527 nsWineURI
*This
= NSURI_THIS(iface
);
1529 TRACE("(%p)->(%p)\n", This
, debugstr_nsacstr(aSpec
));
1532 return nsIURI_SetSpec(This
->uri
, aSpec
);
1534 FIXME("default action not implemented\n");
1535 return NS_ERROR_NOT_IMPLEMENTED
;
1538 static nsresult NSAPI
nsURI_GetPrePath(nsIURL
*iface
, nsACString
*aPrePath
)
1540 nsWineURI
*This
= NSURI_THIS(iface
);
1542 TRACE("(%p)->(%p)\n", This
, aPrePath
);
1545 return nsIURI_GetPrePath(This
->uri
, aPrePath
);
1547 FIXME("default action not implemented\n");
1548 return NS_ERROR_NOT_IMPLEMENTED
;
1551 static nsresult NSAPI
nsURI_GetScheme(nsIURL
*iface
, nsACString
*aScheme
)
1553 nsWineURI
*This
= NSURI_THIS(iface
);
1555 TRACE("(%p)->(%p)\n", This
, aScheme
);
1557 if(This
->use_wine_url
) {
1559 * For Gecko we set scheme to unknown so it won't be handled
1560 * as any special case.
1562 nsACString_SetData(aScheme
, "wine");
1567 return nsIURI_GetScheme(This
->uri
, aScheme
);
1569 TRACE("returning error\n");
1570 return NS_ERROR_NOT_IMPLEMENTED
;
1573 static nsresult NSAPI
nsURI_SetScheme(nsIURL
*iface
, const nsACString
*aScheme
)
1575 nsWineURI
*This
= NSURI_THIS(iface
);
1577 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aScheme
));
1580 return nsIURI_SetScheme(This
->uri
, aScheme
);
1582 FIXME("default action not implemented\n");
1583 return NS_ERROR_NOT_IMPLEMENTED
;
1586 static nsresult NSAPI
nsURI_GetUserPass(nsIURL
*iface
, nsACString
*aUserPass
)
1588 nsWineURI
*This
= NSURI_THIS(iface
);
1590 TRACE("(%p)->(%p)\n", This
, aUserPass
);
1593 return nsIURI_GetUserPass(This
->uri
, aUserPass
);
1595 FIXME("default action not implemented\n");
1596 return NS_ERROR_NOT_IMPLEMENTED
;
1599 static nsresult NSAPI
nsURI_SetUserPass(nsIURL
*iface
, const nsACString
*aUserPass
)
1601 nsWineURI
*This
= NSURI_THIS(iface
);
1603 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUserPass
));
1606 return nsIURI_SetUserPass(This
->uri
, aUserPass
);
1608 FIXME("default action not implemented\n");
1609 return NS_ERROR_NOT_IMPLEMENTED
;
1612 static nsresult NSAPI
nsURI_GetUsername(nsIURL
*iface
, nsACString
*aUsername
)
1614 nsWineURI
*This
= NSURI_THIS(iface
);
1616 TRACE("(%p)->(%p)\n", This
, aUsername
);
1619 return nsIURI_GetUsername(This
->uri
, aUsername
);
1621 FIXME("default action not implemented\n");
1622 return NS_ERROR_NOT_IMPLEMENTED
;
1625 static nsresult NSAPI
nsURI_SetUsername(nsIURL
*iface
, const nsACString
*aUsername
)
1627 nsWineURI
*This
= NSURI_THIS(iface
);
1629 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUsername
));
1632 return nsIURI_SetUsername(This
->uri
, aUsername
);
1634 FIXME("default action not implemented\n");
1635 return NS_ERROR_NOT_IMPLEMENTED
;
1638 static nsresult NSAPI
nsURI_GetPassword(nsIURL
*iface
, nsACString
*aPassword
)
1640 nsWineURI
*This
= NSURI_THIS(iface
);
1642 TRACE("(%p)->(%p)\n", This
, aPassword
);
1645 return nsIURI_GetPassword(This
->uri
, aPassword
);
1647 FIXME("default action not implemented\n");
1648 return NS_ERROR_NOT_IMPLEMENTED
;
1651 static nsresult NSAPI
nsURI_SetPassword(nsIURL
*iface
, const nsACString
*aPassword
)
1653 nsWineURI
*This
= NSURI_THIS(iface
);
1655 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPassword
));
1658 return nsIURI_SetPassword(This
->uri
, aPassword
);
1660 FIXME("default action not implemented\n");
1661 return NS_ERROR_NOT_IMPLEMENTED
;
1664 static nsresult NSAPI
nsURI_GetHostPort(nsIURL
*iface
, nsACString
*aHostPort
)
1666 nsWineURI
*This
= NSURI_THIS(iface
);
1668 TRACE("(%p)->(%p)\n", This
, aHostPort
);
1671 return nsIURI_GetHostPort(This
->uri
, aHostPort
);
1673 FIXME("default action not implemented\n");
1674 return NS_ERROR_NOT_IMPLEMENTED
;
1677 static nsresult NSAPI
nsURI_SetHostPort(nsIURL
*iface
, const nsACString
*aHostPort
)
1679 nsWineURI
*This
= NSURI_THIS(iface
);
1681 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aHostPort
));
1684 return nsIURI_SetHostPort(This
->uri
, aHostPort
);
1686 FIXME("default action not implemented\n");
1687 return NS_ERROR_NOT_IMPLEMENTED
;
1690 static nsresult NSAPI
nsURI_GetHost(nsIURL
*iface
, nsACString
*aHost
)
1692 nsWineURI
*This
= NSURI_THIS(iface
);
1694 TRACE("(%p)->(%p)\n", This
, aHost
);
1697 return nsIURI_GetHost(This
->uri
, aHost
);
1699 FIXME("default action not implemented\n");
1700 return NS_ERROR_NOT_IMPLEMENTED
;
1703 static nsresult NSAPI
nsURI_SetHost(nsIURL
*iface
, const nsACString
*aHost
)
1705 nsWineURI
*This
= NSURI_THIS(iface
);
1707 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aHost
));
1710 return nsIURI_SetHost(This
->uri
, aHost
);
1712 FIXME("default action not implemented\n");
1713 return NS_ERROR_NOT_IMPLEMENTED
;
1716 static nsresult NSAPI
nsURI_GetPort(nsIURL
*iface
, PRInt32
*aPort
)
1718 nsWineURI
*This
= NSURI_THIS(iface
);
1720 TRACE("(%p)->(%p)\n", This
, aPort
);
1723 return nsIURI_GetPort(This
->uri
, aPort
);
1725 FIXME("default action not implemented\n");
1726 return NS_ERROR_NOT_IMPLEMENTED
;
1729 static nsresult NSAPI
nsURI_SetPort(nsIURL
*iface
, PRInt32 aPort
)
1731 nsWineURI
*This
= NSURI_THIS(iface
);
1733 TRACE("(%p)->(%d)\n", This
, aPort
);
1736 return nsIURI_SetPort(This
->uri
, aPort
);
1738 FIXME("default action not implemented\n");
1739 return NS_ERROR_NOT_IMPLEMENTED
;
1742 static nsresult NSAPI
nsURI_GetPath(nsIURL
*iface
, nsACString
*aPath
)
1744 nsWineURI
*This
= NSURI_THIS(iface
);
1746 TRACE("(%p)->(%p)\n", This
, aPath
);
1749 return nsIURI_GetPath(This
->uri
, aPath
);
1751 FIXME("default action not implemented\n");
1752 return NS_ERROR_NOT_IMPLEMENTED
;
1755 static nsresult NSAPI
nsURI_SetPath(nsIURL
*iface
, const nsACString
*aPath
)
1757 nsWineURI
*This
= NSURI_THIS(iface
);
1760 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPath
));
1762 nsACString_GetData(aPath
, &path
);
1763 if(This
->wine_url
) {
1764 WCHAR new_url
[INTERNET_MAX_URL_LENGTH
];
1765 DWORD size
= sizeof(new_url
)/sizeof(WCHAR
);
1769 pathw
= heap_strdupAtoW(path
);
1770 hres
= UrlCombineW(This
->wine_url
, pathw
, new_url
, &size
, 0);
1773 set_wine_url(This
, new_url
);
1775 WARN("UrlCombine failed: %08x\n", hres
);
1781 return nsIURI_SetPath(This
->uri
, aPath
);
1784 static nsresult NSAPI
nsURI_Equals(nsIURL
*iface
, nsIURI
*other
, PRBool
*_retval
)
1786 nsWineURI
*This
= NSURI_THIS(iface
);
1787 nsWineURI
*wine_uri
;
1790 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
1793 return nsIURI_Equals(This
->uri
, other
, _retval
);
1795 nsres
= nsIURI_QueryInterface(other
, &IID_nsWineURI
, (void**)&wine_uri
);
1796 if(NS_FAILED(nsres
)) {
1797 TRACE("Could not get nsWineURI interface\n");
1802 *_retval
= wine_uri
->wine_url
&& !UrlCompareW(This
->wine_url
, wine_uri
->wine_url
, TRUE
);
1803 nsIURI_Release(NSURI(wine_uri
));
1808 static nsresult NSAPI
nsURI_SchemeIs(nsIURL
*iface
, const char *scheme
, PRBool
*_retval
)
1810 nsWineURI
*This
= NSURI_THIS(iface
);
1812 TRACE("(%p)->(%s %p)\n", This
, debugstr_a(scheme
), _retval
);
1814 if(This
->use_wine_url
) {
1815 WCHAR buf
[INTERNET_MAX_SCHEME_LENGTH
];
1816 int len
= MultiByteToWideChar(CP_ACP
, 0, scheme
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
))-1;
1818 *_retval
= lstrlenW(This
->wine_url
) > len
1819 && This
->wine_url
[len
] == ':'
1820 && !memcmp(buf
, This
->wine_url
, len
*sizeof(WCHAR
));
1825 return nsIURI_SchemeIs(This
->uri
, scheme
, _retval
);
1827 TRACE("returning error\n");
1828 return NS_ERROR_NOT_IMPLEMENTED
;
1831 static nsresult NSAPI
nsURI_Clone(nsIURL
*iface
, nsIURI
**_retval
)
1833 nsWineURI
*This
= NSURI_THIS(iface
);
1834 nsIURI
*nsuri
= NULL
;
1835 nsWineURI
*wine_uri
;
1838 TRACE("(%p)->(%p)\n", This
, _retval
);
1841 nsres
= nsIURI_Clone(This
->uri
, &nsuri
);
1842 if(NS_FAILED(nsres
)) {
1843 WARN("Clone failed: %08x\n", nsres
);
1848 nsres
= create_uri(nsuri
, This
->window_ref
? This
->window_ref
->window
: NULL
, This
->container
, &wine_uri
);
1849 if(NS_FAILED(nsres
)) {
1850 WARN("create_uri failed: %08x\n", nsres
);
1854 set_wine_url(wine_uri
, This
->wine_url
);
1856 *_retval
= NSURI(wine_uri
);
1860 static nsresult NSAPI
nsURI_Resolve(nsIURL
*iface
, const nsACString
*arelativePath
,
1861 nsACString
*_retval
)
1863 nsWineURI
*This
= NSURI_THIS(iface
);
1865 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(arelativePath
), _retval
);
1868 return nsIURI_Resolve(This
->uri
, arelativePath
, _retval
);
1870 FIXME("default action not implemented\n");
1871 return NS_ERROR_NOT_IMPLEMENTED
;
1874 static nsresult NSAPI
nsURI_GetAsciiSpec(nsIURL
*iface
, nsACString
*aAsciiSpec
)
1876 nsWineURI
*This
= NSURI_THIS(iface
);
1878 TRACE("(%p)->(%p)\n", This
, aAsciiSpec
);
1880 if(This
->use_wine_url
)
1881 return nsIURI_GetSpec(NSURI(This
), aAsciiSpec
);
1884 return nsIURI_GetAsciiSpec(This
->uri
, aAsciiSpec
);
1886 TRACE("returning error\n");
1887 return NS_ERROR_NOT_IMPLEMENTED
;
1890 static nsresult NSAPI
nsURI_GetAsciiHost(nsIURL
*iface
, nsACString
*aAsciiHost
)
1892 nsWineURI
*This
= NSURI_THIS(iface
);
1894 TRACE("(%p)->(%p)\n", This
, aAsciiHost
);
1897 return nsIURI_GetAsciiHost(This
->uri
, aAsciiHost
);
1899 FIXME("default action not implemented\n");
1900 return NS_ERROR_NOT_IMPLEMENTED
;
1903 static nsresult NSAPI
nsURI_GetOriginCharset(nsIURL
*iface
, nsACString
*aOriginCharset
)
1905 nsWineURI
*This
= NSURI_THIS(iface
);
1907 TRACE("(%p)->(%p)\n", This
, aOriginCharset
);
1910 return nsIURI_GetOriginCharset(This
->uri
, aOriginCharset
);
1912 FIXME("default action not implemented\n");
1913 return NS_ERROR_NOT_IMPLEMENTED
;
1916 static nsresult NSAPI
nsURL_GetFilePath(nsIURL
*iface
, nsACString
*aFilePath
)
1918 nsWineURI
*This
= NSURI_THIS(iface
);
1920 TRACE("(%p)->(%p)\n", This
, aFilePath
);
1923 return nsIURL_GetFilePath(This
->nsurl
, aFilePath
);
1925 FIXME("default action not implemented\n");
1926 return NS_ERROR_NOT_IMPLEMENTED
;
1929 static nsresult NSAPI
nsURL_SetFilePath(nsIURL
*iface
, const nsACString
*aFilePath
)
1931 nsWineURI
*This
= NSURI_THIS(iface
);
1933 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFilePath
));
1936 return nsIURL_SetFilePath(This
->nsurl
, aFilePath
);
1938 FIXME("default action not implemented\n");
1939 return NS_ERROR_NOT_IMPLEMENTED
;
1942 static nsresult NSAPI
nsURL_GetParam(nsIURL
*iface
, nsACString
*aParam
)
1944 nsWineURI
*This
= NSURI_THIS(iface
);
1946 TRACE("(%p)->(%p)\n", This
, aParam
);
1949 return nsIURL_GetParam(This
->nsurl
, aParam
);
1951 FIXME("default action not implemented\n");
1952 return NS_ERROR_NOT_IMPLEMENTED
;
1955 static nsresult NSAPI
nsURL_SetParam(nsIURL
*iface
, const nsACString
*aParam
)
1957 nsWineURI
*This
= NSURI_THIS(iface
);
1959 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aParam
));
1962 return nsIURL_SetParam(This
->nsurl
, aParam
);
1964 FIXME("default action not implemented\n");
1965 return NS_ERROR_NOT_IMPLEMENTED
;
1968 static nsresult NSAPI
nsURL_GetQuery(nsIURL
*iface
, nsACString
*aQuery
)
1970 nsWineURI
*This
= NSURI_THIS(iface
);
1972 TRACE("(%p)->(%p)\n", This
, aQuery
);
1975 return nsIURL_GetQuery(This
->nsurl
, aQuery
);
1977 FIXME("default action not implemented\n");
1978 return NS_ERROR_NOT_IMPLEMENTED
;
1981 static nsresult NSAPI
nsURL_SetQuery(nsIURL
*iface
, const nsACString
*aQuery
)
1983 nsWineURI
*This
= NSURI_THIS(iface
);
1984 const WCHAR
*ptr1
, *ptr2
;
1986 WCHAR
*new_url
, *ptr
;
1989 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aQuery
));
1992 nsIURL_SetQuery(This
->nsurl
, aQuery
);
1997 nsACString_GetData(aQuery
, &query
);
1998 size
= len
= MultiByteToWideChar(CP_ACP
, 0, query
, -1, NULL
, 0);
1999 ptr1
= strchrW(This
->wine_url
, '?');
2001 size
+= ptr1
-This
->wine_url
;
2002 ptr2
= strchrW(ptr1
, '#');
2004 size
+= strlenW(ptr2
);
2006 ptr1
= This
->wine_url
+ strlenW(This
->wine_url
);
2008 size
+= strlenW(This
->wine_url
);
2014 new_url
= heap_alloc(size
*sizeof(WCHAR
));
2015 memcpy(new_url
, This
->wine_url
, (ptr1
-This
->wine_url
)*sizeof(WCHAR
));
2016 ptr
= new_url
+ (ptr1
-This
->wine_url
);
2019 MultiByteToWideChar(CP_ACP
, 0, query
, -1, ptr
, len
);
2027 TRACE("setting %s\n", debugstr_w(new_url
));
2029 heap_free(This
->wine_url
);
2030 This
->wine_url
= new_url
;
2034 static nsresult NSAPI
nsURL_GetRef(nsIURL
*iface
, nsACString
*aRef
)
2036 nsWineURI
*This
= NSURI_THIS(iface
);
2038 TRACE("(%p)->(%p)\n", This
, aRef
);
2041 return nsIURL_GetRef(This
->nsurl
, aRef
);
2043 FIXME("default action not implemented\n");
2044 return NS_ERROR_NOT_IMPLEMENTED
;
2047 static nsresult NSAPI
nsURL_SetRef(nsIURL
*iface
, const nsACString
*aRef
)
2049 nsWineURI
*This
= NSURI_THIS(iface
);
2052 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRef
));
2055 return nsIURL_SetRef(This
->nsurl
, aRef
);
2057 nsACString_GetData(aRef
, &refa
);
2061 FIXME("default action not implemented\n");
2062 return NS_ERROR_NOT_IMPLEMENTED
;
2065 static nsresult NSAPI
nsURL_GetDirectory(nsIURL
*iface
, nsACString
*aDirectory
)
2067 nsWineURI
*This
= NSURI_THIS(iface
);
2069 TRACE("(%p)->(%p)\n", This
, aDirectory
);
2072 return nsIURL_GetDirectory(This
->nsurl
, aDirectory
);
2074 FIXME("default action not implemented\n");
2075 return NS_ERROR_NOT_IMPLEMENTED
;
2078 static nsresult NSAPI
nsURL_SetDirectory(nsIURL
*iface
, const nsACString
*aDirectory
)
2080 nsWineURI
*This
= NSURI_THIS(iface
);
2082 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aDirectory
));
2085 return nsIURL_SetDirectory(This
->nsurl
, aDirectory
);
2087 FIXME("default action not implemented\n");
2088 return NS_ERROR_NOT_IMPLEMENTED
;
2091 static nsresult NSAPI
nsURL_GetFileName(nsIURL
*iface
, nsACString
*aFileName
)
2093 nsWineURI
*This
= NSURI_THIS(iface
);
2095 TRACE("(%p)->(%p)\n", This
, aFileName
);
2098 return nsIURL_GetFileName(This
->nsurl
, aFileName
);
2100 FIXME("default action not implemented\n");
2101 return NS_ERROR_NOT_IMPLEMENTED
;
2104 static nsresult NSAPI
nsURL_SetFileName(nsIURL
*iface
, const nsACString
*aFileName
)
2106 nsWineURI
*This
= NSURI_THIS(iface
);
2108 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileName
));
2111 return nsIURL_SetFileName(This
->nsurl
, aFileName
);
2113 FIXME("default action not implemented\n");
2114 return NS_ERROR_NOT_IMPLEMENTED
;
2117 static nsresult NSAPI
nsURL_GetFileBaseName(nsIURL
*iface
, nsACString
*aFileBaseName
)
2119 nsWineURI
*This
= NSURI_THIS(iface
);
2121 TRACE("(%p)->(%p)\n", This
, aFileBaseName
);
2124 return nsIURL_GetFileBaseName(This
->nsurl
, aFileBaseName
);
2126 FIXME("default action not implemented\n");
2127 return NS_ERROR_NOT_IMPLEMENTED
;
2130 static nsresult NSAPI
nsURL_SetFileBaseName(nsIURL
*iface
, const nsACString
*aFileBaseName
)
2132 nsWineURI
*This
= NSURI_THIS(iface
);
2134 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileBaseName
));
2137 return nsIURL_SetFileBaseName(This
->nsurl
, aFileBaseName
);
2139 FIXME("default action not implemented\n");
2140 return NS_ERROR_NOT_IMPLEMENTED
;
2143 static nsresult NSAPI
nsURL_GetFileExtension(nsIURL
*iface
, nsACString
*aFileExtension
)
2145 nsWineURI
*This
= NSURI_THIS(iface
);
2147 TRACE("(%p)->(%p)\n", This
, aFileExtension
);
2150 return nsIURL_GetFileExtension(This
->nsurl
, aFileExtension
);
2152 FIXME("default action not implemented\n");
2153 return NS_ERROR_NOT_IMPLEMENTED
;
2156 static nsresult NSAPI
nsURL_SetFileExtension(nsIURL
*iface
, const nsACString
*aFileExtension
)
2158 nsWineURI
*This
= NSURI_THIS(iface
);
2160 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileExtension
));
2163 return nsIURL_SetFileExtension(This
->nsurl
, aFileExtension
);
2165 FIXME("default action not implemented\n");
2166 return NS_ERROR_NOT_IMPLEMENTED
;
2169 static nsresult NSAPI
nsURL_GetCommonBaseSpec(nsIURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2171 nsWineURI
*This
= NSURI_THIS(iface
);
2173 TRACE("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2176 return nsIURL_GetCommonBaseSpec(This
->nsurl
, aURIToCompare
, _retval
);
2178 FIXME("default action not implemented\n");
2179 return NS_ERROR_NOT_IMPLEMENTED
;
2182 static nsresult NSAPI
nsURL_GetRelativeSpec(nsIURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2184 nsWineURI
*This
= NSURI_THIS(iface
);
2186 TRACE("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2189 return nsIURL_GetRelativeSpec(This
->nsurl
, aURIToCompare
, _retval
);
2191 FIXME("default action not implemented\n");
2192 return NS_ERROR_NOT_IMPLEMENTED
;
2197 static const nsIURLVtbl nsURLVtbl
= {
2198 nsURI_QueryInterface
,
2226 nsURI_GetOriginCharset
,
2239 nsURL_GetFileBaseName
,
2240 nsURL_SetFileBaseName
,
2241 nsURL_GetFileExtension
,
2242 nsURL_SetFileExtension
,
2243 nsURL_GetCommonBaseSpec
,
2244 nsURL_GetRelativeSpec
2247 static nsresult
create_uri(nsIURI
*uri
, HTMLWindow
*window
, NSContainer
*container
, nsWineURI
**_retval
)
2249 nsWineURI
*ret
= heap_alloc_zero(sizeof(nsWineURI
));
2251 ret
->lpIURLVtbl
= &nsURLVtbl
;
2255 set_uri_nscontainer(ret
, container
);
2256 set_uri_window(ret
, window
);
2259 nsIURI_QueryInterface(uri
, &IID_nsIURL
, (void**)&ret
->nsurl
);
2261 TRACE("retval=%p\n", ret
);
2266 HRESULT
create_doc_uri(HTMLWindow
*window
, WCHAR
*url
, nsWineURI
**ret
)
2271 nsres
= create_uri(NULL
, window
, window
->doc_obj
->nscontainer
, &uri
);
2272 if(NS_FAILED(nsres
))
2275 set_wine_url(uri
, url
);
2276 uri
->is_doc_uri
= TRUE
;
2283 const nsIProtocolHandlerVtbl
*lpProtocolHandlerVtbl
;
2287 nsIProtocolHandler
*nshandler
;
2288 } nsProtocolHandler
;
2290 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
2292 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
2294 static nsresult NSAPI
nsProtocolHandler_QueryInterface(nsIProtocolHandler
*iface
, nsIIDRef riid
,
2297 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2301 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
2302 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
2303 *result
= NSPROTHANDLER(This
);
2304 }else if(IsEqualGUID(&IID_nsIProtocolHandler
, riid
)) {
2305 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This
, result
);
2306 *result
= NSPROTHANDLER(This
);
2307 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler
, riid
)) {
2308 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This
, result
);
2309 return NS_NOINTERFACE
;
2313 nsISupports_AddRef((nsISupports
*)*result
);
2317 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
2318 return NS_NOINTERFACE
;
2321 static nsrefcnt NSAPI
nsProtocolHandler_AddRef(nsIProtocolHandler
*iface
)
2323 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2324 LONG ref
= InterlockedIncrement(&This
->ref
);
2326 TRACE("(%p) ref=%d\n", This
, ref
);
2331 static nsrefcnt NSAPI
nsProtocolHandler_Release(nsIProtocolHandler
*iface
)
2333 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2334 LONG ref
= InterlockedDecrement(&This
->ref
);
2336 TRACE("(%p) ref=%d\n", This
, ref
);
2340 nsIProtocolHandler_Release(This
->nshandler
);
2347 static nsresult NSAPI
nsProtocolHandler_GetScheme(nsIProtocolHandler
*iface
, nsACString
*aScheme
)
2349 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2351 TRACE("(%p)->(%p)\n", This
, aScheme
);
2354 return nsIProtocolHandler_GetScheme(This
->nshandler
, aScheme
);
2355 return NS_ERROR_NOT_IMPLEMENTED
;
2358 static nsresult NSAPI
nsProtocolHandler_GetDefaultPort(nsIProtocolHandler
*iface
,
2359 PRInt32
*aDefaultPort
)
2361 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2363 TRACE("(%p)->(%p)\n", This
, aDefaultPort
);
2366 return nsIProtocolHandler_GetDefaultPort(This
->nshandler
, aDefaultPort
);
2367 return NS_ERROR_NOT_IMPLEMENTED
;
2370 static nsresult NSAPI
nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler
*iface
,
2371 PRUint32
*aProtocolFlags
)
2373 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2375 TRACE("(%p)->(%p)\n", This
, aProtocolFlags
);
2378 return nsIProtocolHandler_GetProtocolFlags(This
->nshandler
, aProtocolFlags
);
2379 return NS_ERROR_NOT_IMPLEMENTED
;
2382 static nsresult NSAPI
nsProtocolHandler_NewURI(nsIProtocolHandler
*iface
,
2383 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
2385 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2387 TRACE("((%p)->%s %s %p %p)\n", This
, debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
2391 return nsIProtocolHandler_NewURI(This
->nshandler
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2392 return NS_ERROR_NOT_IMPLEMENTED
;
2395 static nsresult NSAPI
nsProtocolHandler_NewChannel(nsIProtocolHandler
*iface
,
2396 nsIURI
*aURI
, nsIChannel
**_retval
)
2398 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2400 TRACE("(%p)->(%p %p)\n", This
, aURI
, _retval
);
2403 return nsIProtocolHandler_NewChannel(This
->nshandler
, aURI
, _retval
);
2404 return NS_ERROR_NOT_IMPLEMENTED
;
2407 static nsresult NSAPI
nsProtocolHandler_AllowPort(nsIProtocolHandler
*iface
,
2408 PRInt32 port
, const char *scheme
, PRBool
*_retval
)
2410 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2412 TRACE("(%p)->(%d %s %p)\n", This
, port
, debugstr_a(scheme
), _retval
);
2415 return nsIProtocolHandler_AllowPort(This
->nshandler
, port
, scheme
, _retval
);
2416 return NS_ERROR_NOT_IMPLEMENTED
;
2419 #undef NSPROTHANDLER_THIS
2421 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl
= {
2422 nsProtocolHandler_QueryInterface
,
2423 nsProtocolHandler_AddRef
,
2424 nsProtocolHandler_Release
,
2425 nsProtocolHandler_GetScheme
,
2426 nsProtocolHandler_GetDefaultPort
,
2427 nsProtocolHandler_GetProtocolFlags
,
2428 nsProtocolHandler_NewURI
,
2429 nsProtocolHandler_NewChannel
,
2430 nsProtocolHandler_AllowPort
2433 static nsIProtocolHandler
*create_protocol_handler(nsIProtocolHandler
*nshandler
)
2435 nsProtocolHandler
*ret
= heap_alloc(sizeof(nsProtocolHandler
));
2437 ret
->lpProtocolHandlerVtbl
= &nsProtocolHandlerVtbl
;
2439 ret
->nshandler
= nshandler
;
2441 return NSPROTHANDLER(ret
);
2444 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*,nsIIDRef
,void**);
2446 static nsrefcnt NSAPI
nsIOService_AddRef(nsIIOService
*iface
)
2451 static nsrefcnt NSAPI
nsIOService_Release(nsIIOService
*iface
)
2456 static nsresult NSAPI
nsIOService_GetProtocolHandler(nsIIOService
*iface
, const char *aScheme
,
2457 nsIProtocolHandler
**_retval
)
2459 nsIExternalProtocolHandler
*nsexthandler
;
2460 nsIProtocolHandler
*nshandler
;
2463 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
2465 nsres
= nsIIOService_GetProtocolHandler(nsio
, aScheme
, &nshandler
);
2466 if(NS_FAILED(nsres
)) {
2467 WARN("GetProtocolHandler failed: %08x\n", nsres
);
2471 nsres
= nsIProtocolHandler_QueryInterface(nshandler
, &IID_nsIExternalProtocolHandler
,
2472 (void**)&nsexthandler
);
2473 if(NS_FAILED(nsres
)) {
2474 *_retval
= nshandler
;
2478 nsIExternalProtocolHandler_Release(nsexthandler
);
2479 *_retval
= create_protocol_handler(nshandler
);
2480 TRACE("return %p\n", *_retval
);
2484 static nsresult NSAPI
nsIOService_GetProtocolFlags(nsIIOService
*iface
, const char *aScheme
,
2487 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
2488 return nsIIOService_GetProtocolFlags(nsio
, aScheme
, _retval
);
2491 static BOOL
is_gecko_special_uri(const char *spec
)
2493 static const char *special_schemes
[] = {"chrome:", "jar:", "resource:", "javascript:", "wyciwyg:"};
2496 for(i
=0; i
< sizeof(special_schemes
)/sizeof(*special_schemes
); i
++) {
2497 if(!strncasecmp(spec
, special_schemes
[i
], strlen(special_schemes
[i
])))
2504 static nsresult NSAPI
nsIOService_NewURI(nsIIOService
*iface
, const nsACString
*aSpec
,
2505 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
2507 nsWineURI
*wine_uri
, *base_wine_uri
= NULL
;
2508 const char *spec
= NULL
;
2509 HTMLWindow
*window
= NULL
;
2511 LPCWSTR base_wine_url
= NULL
;
2512 nsACString spec_str
;
2516 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
2519 nsACString_GetData(aSpec
, &spec
);
2520 if(is_gecko_special_uri(spec
))
2521 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2523 if(!strncmp(spec
, "wine:", 5))
2527 PARSEDURLA parsed_url
= {sizeof(PARSEDURLA
)};
2529 nsres
= nsIURI_QueryInterface(aBaseURI
, &IID_nsWineURI
, (void**)&base_wine_uri
);
2530 if(NS_SUCCEEDED(nsres
)) {
2531 base_wine_url
= base_wine_uri
->wine_url
;
2532 if(base_wine_uri
->window_ref
&& base_wine_uri
->window_ref
->window
) {
2533 window
= base_wine_uri
->window_ref
->window
;
2534 IHTMLWindow2_AddRef(HTMLWINDOW2(window
));
2536 TRACE("base url: %s window: %p\n", debugstr_w(base_wine_url
), window
);
2537 }else if(FAILED(ParseURLA(spec
, &parsed_url
))) {
2538 TRACE("not wraping\n");
2539 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2541 WARN("Could not get base nsWineURI: %08x\n", nsres
);
2545 nsACString_InitDepend(&spec_str
, spec
);
2546 nsres
= nsIIOService_NewURI(nsio
, &spec_str
, aOriginCharset
, aBaseURI
, &uri
);
2547 nsACString_Finish(&spec_str
);
2548 if(NS_FAILED(nsres
))
2549 TRACE("NewURI failed: %08x\n", nsres
);
2551 nsres
= create_uri(uri
, window
, NULL
, &wine_uri
);
2552 *_retval
= (nsIURI
*)wine_uri
;
2555 IHTMLWindow2_Release(HTMLWINDOW2(window
));
2558 WCHAR url
[INTERNET_MAX_URL_LENGTH
], rel_url
[INTERNET_MAX_URL_LENGTH
];
2562 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, rel_url
, sizeof(rel_url
)/sizeof(WCHAR
));
2564 hres
= CoInternetCombineUrl(base_wine_url
, rel_url
,
2565 URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
2566 url
, sizeof(url
)/sizeof(WCHAR
), &len
, 0);
2568 set_wine_url(wine_uri
, url
);
2570 WARN("CoCombineUrl failed: %08x\n", hres
);
2572 WCHAR url
[INTERNET_MAX_URL_LENGTH
];
2574 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, url
, sizeof(url
)/sizeof(WCHAR
));
2575 set_wine_url(wine_uri
, url
);
2579 nsIURI_Release(NSURI(base_wine_uri
));
2584 static nsresult NSAPI
nsIOService_NewFileURI(nsIIOService
*iface
, nsIFile
*aFile
,
2587 TRACE("(%p %p)\n", aFile
, _retval
);
2588 return nsIIOService_NewFileURI(nsio
, aFile
, _retval
);
2591 static nsresult NSAPI
nsIOService_NewChannelFromURI(nsIIOService
*iface
, nsIURI
*aURI
,
2592 nsIChannel
**_retval
)
2594 PARSEDURLW parsed_url
= {sizeof(PARSEDURLW
)};
2596 nsWineURI
*wine_uri
;
2599 TRACE("(%p %p)\n", aURI
, _retval
);
2601 nsres
= nsIURI_QueryInterface(aURI
, &IID_nsWineURI
, (void**)&wine_uri
);
2602 if(NS_FAILED(nsres
)) {
2603 TRACE("Could not get nsWineURI: %08x\n", nsres
);
2604 return nsIIOService_NewChannelFromURI(nsio
, aURI
, _retval
);
2607 ret
= heap_alloc_zero(sizeof(nsChannel
));
2609 ret
->lpHttpChannelVtbl
= &nsChannelVtbl
;
2610 ret
->lpUploadChannelVtbl
= &nsUploadChannelVtbl
;
2611 ret
->lpIHttpChannelInternalVtbl
= &nsHttpChannelInternalVtbl
;
2613 ret
->uri
= wine_uri
;
2614 list_init(&ret
->response_headers
);
2615 list_init(&ret
->request_headers
);
2617 nsIURI_AddRef(aURI
);
2618 ret
->original_uri
= aURI
;
2619 ret
->url_scheme
= wine_uri
->wine_url
&& SUCCEEDED(ParseURLW(wine_uri
->wine_url
, &parsed_url
))
2620 ? parsed_url
.nScheme
: URL_SCHEME_UNKNOWN
;
2622 *_retval
= NSCHANNEL(ret
);
2626 static nsresult NSAPI
nsIOService_NewChannel(nsIIOService
*iface
, const nsACString
*aSpec
,
2627 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIChannel
**_retval
)
2629 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
), aBaseURI
, _retval
);
2630 return nsIIOService_NewChannel(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2633 static nsresult NSAPI
nsIOService_GetOffline(nsIIOService
*iface
, PRBool
*aOffline
)
2635 TRACE("(%p)\n", aOffline
);
2636 return nsIIOService_GetOffline(nsio
, aOffline
);
2639 static nsresult NSAPI
nsIOService_SetOffline(nsIIOService
*iface
, PRBool aOffline
)
2641 TRACE("(%x)\n", aOffline
);
2642 return nsIIOService_SetOffline(nsio
, aOffline
);
2645 static nsresult NSAPI
nsIOService_AllowPort(nsIIOService
*iface
, PRInt32 aPort
,
2646 const char *aScheme
, PRBool
*_retval
)
2648 TRACE("(%d %s %p)\n", aPort
, debugstr_a(aScheme
), _retval
);
2649 return nsIIOService_AllowPort(nsio
, aPort
, debugstr_a(aScheme
), _retval
);
2652 static nsresult NSAPI
nsIOService_ExtractScheme(nsIIOService
*iface
, const nsACString
*urlString
,
2653 nsACString
* _retval
)
2655 TRACE("(%s %p)\n", debugstr_nsacstr(urlString
), _retval
);
2656 return nsIIOService_ExtractScheme(nsio
, urlString
, _retval
);
2659 static const nsIIOServiceVtbl nsIOServiceVtbl
= {
2660 nsIOService_QueryInterface
,
2662 nsIOService_Release
,
2663 nsIOService_GetProtocolHandler
,
2664 nsIOService_GetProtocolFlags
,
2666 nsIOService_NewFileURI
,
2667 nsIOService_NewChannelFromURI
,
2668 nsIOService_NewChannel
,
2669 nsIOService_GetOffline
,
2670 nsIOService_SetOffline
,
2671 nsIOService_AllowPort
,
2672 nsIOService_ExtractScheme
2675 static nsIIOService nsIOService
= { &nsIOServiceVtbl
};
2677 static nsresult NSAPI
nsNetUtil_QueryInterface(nsINetUtil
*iface
, nsIIDRef riid
,
2680 return nsIIOService_QueryInterface(&nsIOService
, riid
, result
);
2683 static nsrefcnt NSAPI
nsNetUtil_AddRef(nsINetUtil
*iface
)
2688 static nsrefcnt NSAPI
nsNetUtil_Release(nsINetUtil
*iface
)
2693 static nsresult NSAPI
nsNetUtil_ParseContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
2694 nsACString
*aCharset
, PRBool
*aHadCharset
, nsACString
*aContentType
)
2696 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aHadCharset
, aContentType
);
2698 return nsINetUtil_ParseContentType(net_util
, aTypeHeader
, aCharset
, aHadCharset
, aContentType
);
2701 static nsresult NSAPI
nsNetUtil_ProtocolHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, PRUint32 aFlags
, PRBool
*_retval
)
2705 return nsINetUtil_ProtocolHasFlags(net_util
, aURI
, aFlags
, _retval
);
2708 static nsresult NSAPI
nsNetUtil_URIChainHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, PRUint32 aFlags
, PRBool
*_retval
)
2710 TRACE("(%p %08x %p)\n", aURI
, aFlags
, _retval
);
2712 if(aFlags
== (1<<11)) {
2717 return nsINetUtil_URIChainHasFlags(net_util
, aURI
, aFlags
, _retval
);
2720 static nsresult NSAPI
nsNetUtil_ToImmutableURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
2722 TRACE("(%p %p)\n", aURI
, _retval
);
2724 return nsINetUtil_ToImmutableURI(net_util
, aURI
, _retval
);
2727 static nsresult NSAPI
nsNetUtil_EscapeString(nsINetUtil
*iface
, const nsACString
*aString
,
2728 PRUint32 aEscapeType
, nsACString
*_retval
)
2730 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString
), aEscapeType
, _retval
);
2732 return nsINetUtil_EscapeString(net_util
, aString
, aEscapeType
, _retval
);
2735 static nsresult NSAPI
nsNetUtil_EscapeURL(nsINetUtil
*iface
, const nsACString
*aStr
, PRUint32 aFlags
,
2736 nsACString
*_retval
)
2738 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
2740 return nsINetUtil_EscapeURL(net_util
, aStr
, aFlags
, _retval
);
2743 static nsresult NSAPI
nsNetUtil_UnescapeString(nsINetUtil
*iface
, const nsACString
*aStr
,
2744 PRUint32 aFlags
, nsACString
*_retval
)
2746 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
2748 return nsINetUtil_UnescapeString(net_util
, aStr
, aFlags
, _retval
);
2751 static nsresult NSAPI
nsNetUtil_ExtractCharsetFromContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
2752 nsACString
*aCharset
, PRInt32
*aCharsetStart
, PRInt32
*aCharsetEnd
, PRBool
*_retval
)
2754 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aCharsetStart
,
2755 aCharsetEnd
, _retval
);
2757 return nsINetUtil_ExtractCharsetFromContentType(net_util
, aTypeHeader
, aCharset
, aCharsetStart
, aCharsetEnd
, _retval
);
2760 static const nsINetUtilVtbl nsNetUtilVtbl
= {
2761 nsNetUtil_QueryInterface
,
2764 nsNetUtil_ParseContentType
,
2765 nsNetUtil_ProtocolHasFlags
,
2766 nsNetUtil_URIChainHasFlags
,
2767 nsNetUtil_ToImmutableURI
,
2768 nsNetUtil_EscapeString
,
2769 nsNetUtil_EscapeURL
,
2770 nsNetUtil_UnescapeString
,
2771 nsNetUtil_ExtractCharsetFromContentType
2774 static nsINetUtil nsNetUtil
= { &nsNetUtilVtbl
};
2776 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*iface
, nsIIDRef riid
,
2781 if(IsEqualGUID(&IID_nsISupports
, riid
))
2782 *result
= &nsIOService
;
2783 else if(IsEqualGUID(&IID_nsIIOService
, riid
))
2784 *result
= &nsIOService
;
2785 else if(IsEqualGUID(&IID_nsINetUtil
, riid
))
2786 *result
= &nsNetUtil
;
2789 nsISupports_AddRef((nsISupports
*)*result
);
2793 FIXME("(%s %p)\n", debugstr_guid(riid
), result
);
2794 return NS_NOINTERFACE
;
2797 static nsresult NSAPI
nsIOServiceFactory_QueryInterface(nsIFactory
*iface
, nsIIDRef riid
,
2802 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
2803 TRACE("(IID_nsISupports %p)\n", result
);
2805 }else if(IsEqualGUID(&IID_nsIFactory
, riid
)) {
2806 TRACE("(IID_nsIFactory %p)\n", result
);
2811 nsIFactory_AddRef(iface
);
2815 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
2816 return NS_NOINTERFACE
;
2819 static nsrefcnt NSAPI
nsIOServiceFactory_AddRef(nsIFactory
*iface
)
2824 static nsrefcnt NSAPI
nsIOServiceFactory_Release(nsIFactory
*iface
)
2829 static nsresult NSAPI
nsIOServiceFactory_CreateInstance(nsIFactory
*iface
,
2830 nsISupports
*aOuter
, const nsIID
*iid
, void **result
)
2832 return nsIIOService_QueryInterface(&nsIOService
, iid
, result
);
2835 static nsresult NSAPI
nsIOServiceFactory_LockFactory(nsIFactory
*iface
, PRBool lock
)
2837 WARN("(%x)\n", lock
);
2841 static const nsIFactoryVtbl nsIOServiceFactoryVtbl
= {
2842 nsIOServiceFactory_QueryInterface
,
2843 nsIOServiceFactory_AddRef
,
2844 nsIOServiceFactory_Release
,
2845 nsIOServiceFactory_CreateInstance
,
2846 nsIOServiceFactory_LockFactory
2849 static nsIFactory nsIOServiceFactory
= { &nsIOServiceFactoryVtbl
};
2851 void init_nsio(nsIComponentManager
*component_manager
, nsIComponentRegistrar
*registrar
)
2853 nsIFactory
*old_factory
= NULL
;
2856 nsres
= nsIComponentManager_GetClassObject(component_manager
, &NS_IOSERVICE_CID
,
2857 &IID_nsIFactory
, (void**)&old_factory
);
2858 if(NS_FAILED(nsres
)) {
2859 ERR("Could not get factory: %08x\n", nsres
);
2863 nsres
= nsIFactory_CreateInstance(old_factory
, NULL
, &IID_nsIIOService
, (void**)&nsio
);
2864 if(NS_FAILED(nsres
)) {
2865 ERR("Couldn not create nsIOService instance %08x\n", nsres
);
2866 nsIFactory_Release(old_factory
);
2870 nsres
= nsIIOService_QueryInterface(nsio
, &IID_nsINetUtil
, (void**)&net_util
);
2871 if(NS_FAILED(nsres
)) {
2872 WARN("Could not get nsINetUtil interface: %08x\n", nsres
);
2873 nsIIOService_Release(nsio
);
2877 nsres
= nsIComponentRegistrar_UnregisterFactory(registrar
, &NS_IOSERVICE_CID
, old_factory
);
2878 nsIFactory_Release(old_factory
);
2879 if(NS_FAILED(nsres
))
2880 ERR("UnregisterFactory failed: %08x\n", nsres
);
2882 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_IOSERVICE_CID
,
2883 NS_IOSERVICE_CLASSNAME
, NS_IOSERVICE_CONTRACTID
, &nsIOServiceFactory
);
2884 if(NS_FAILED(nsres
))
2885 ERR("RegisterFactory failed: %08x\n", nsres
);
2888 void release_nsio(void)
2891 nsINetUtil_Release(net_util
);
2896 nsIIOService_Release(nsio
);