2 * Copyright 2006-2010 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
37 #include "mshtml_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
41 #define NS_IOSERVICE_CLASSNAME "nsIOService"
42 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
44 static const IID NS_IOSERVICE_CID
=
45 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
46 static const IID IID_nsWineURI
=
47 {0x5088272e, 0x900b, 0x11da, {0xc6,0x87, 0x00,0x0f,0xea,0x57,0xf2,0x1a}};
49 static nsIIOService
*nsio
= NULL
;
50 static nsINetUtil
*net_util
;
52 static const WCHAR about_blankW
[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
54 static const char *request_method_strings
[] = {"GET", "PUT", "POST"};
57 const nsIURLVtbl
*lpIURLVtbl
;
63 NSContainer
*container
;
64 windowref_t
*window_ref
;
65 nsChannelBSC
*channel_bsc
;
71 #define NSURI(x) ((nsIURI*) &(x)->lpIURLVtbl)
72 #define NSURL(x) ((nsIURL*) &(x)->lpIURLVtbl)
74 static nsresult
create_uri(nsIURI
*,HTMLWindow
*,NSContainer
*,nsWineURI
**);
76 static const char *debugstr_nsacstr(const nsACString
*nsstr
)
80 nsACString_GetData(nsstr
, &data
);
81 return debugstr_a(data
);
84 HRESULT
nsuri_to_url(LPCWSTR nsuri
, BOOL ret_empty
, BSTR
*ret
)
86 const WCHAR
*ptr
= nsuri
;
88 static const WCHAR wine_prefixW
[] = {'w','i','n','e',':'};
90 if(!strncmpW(nsuri
, wine_prefixW
, sizeof(wine_prefixW
)/sizeof(WCHAR
)))
91 ptr
+= sizeof(wine_prefixW
)/sizeof(WCHAR
);
93 if(*ptr
|| ret_empty
) {
94 *ret
= SysAllocString(ptr
);
101 TRACE("%s -> %s\n", debugstr_w(nsuri
), debugstr_w(*ret
));
105 static BOOL
exec_shldocvw_67(HTMLDocumentObj
*doc
, LPCWSTR url
)
107 IOleCommandTarget
*cmdtrg
= NULL
;
110 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
111 if(SUCCEEDED(hres
)) {
112 VARIANT varUrl
, varRes
;
114 V_VT(&varUrl
) = VT_BSTR
;
115 V_BSTR(&varUrl
) = SysAllocString(url
);
116 V_VT(&varRes
) = VT_BOOL
;
118 hres
= IOleCommandTarget_Exec(cmdtrg
, &CGID_ShellDocView
, 67, 0, &varUrl
, &varRes
);
120 IOleCommandTarget_Release(cmdtrg
);
121 SysFreeString(V_BSTR(&varUrl
));
123 if(SUCCEEDED(hres
) && !V_BOOL(&varRes
)) {
124 TRACE("got VARIANT_FALSE, do not load\n");
132 static BOOL
before_async_open(nsChannel
*channel
, NSContainer
*container
)
134 HTMLDocumentObj
*doc
= container
->doc
;
140 NSContainer
*container_iter
= container
;
142 hlnf
= HLNF_OPENINNEWWINDOW
;
143 while(!container_iter
->doc
)
144 container_iter
= container_iter
->parent
;
145 doc
= container_iter
->doc
;
151 if(!hlnf
&& !exec_shldocvw_67(doc
, channel
->uri
->wine_url
))
154 hres
= hlink_frame_navigate(&doc
->basedoc
, channel
->uri
->wine_url
, channel
->post_data_stream
, hlnf
, &cancel
);
155 return FAILED(hres
) || cancel
;
158 HRESULT
load_nsuri(HTMLWindow
*window
, nsWineURI
*uri
, nsChannelBSC
*channelbsc
, DWORD flags
)
160 nsIWebNavigation
*web_navigation
;
161 nsIDocShell
*doc_shell
;
162 HTMLDocumentNode
*doc
;
165 nsres
= get_nsinterface((nsISupports
*)window
->nswindow
, &IID_nsIWebNavigation
, (void**)&web_navigation
);
166 if(NS_FAILED(nsres
)) {
167 ERR("Could not get nsIWebNavigation interface: %08x\n", nsres
);
171 nsres
= nsIWebNavigation_QueryInterface(web_navigation
, &IID_nsIDocShell
, (void**)&doc_shell
);
172 nsIWebNavigation_Release(web_navigation
);
173 if(NS_FAILED(nsres
)) {
174 ERR("Could not get nsIDocShell: %08x\n", nsres
);
178 uri
->channel_bsc
= channelbsc
;
180 doc
->skip_mutation_notif
= TRUE
;
181 nsres
= nsIDocShell_LoadURI(doc_shell
, NSURI(uri
), NULL
, flags
, FALSE
);
182 if(doc
== window
->doc
)
183 doc
->skip_mutation_notif
= FALSE
;
184 uri
->channel_bsc
= NULL
;
185 nsIDocShell_Release(doc_shell
);
186 if(NS_FAILED(nsres
)) {
187 WARN("LoadURI failed: %08x\n", nsres
);
194 static BOOL
translate_url(HTMLDocumentObj
*doc
, nsWineURI
*uri
)
196 OLECHAR
*new_url
= NULL
, *url
;
203 url
= heap_strdupW(uri
->wine_url
);
204 hres
= IDocHostUIHandler_TranslateUrl(doc
->hostui
, 0, url
, &new_url
);
205 if(hres
== S_OK
&& new_url
) {
206 if(strcmpW(url
, new_url
)) {
207 FIXME("TranslateUrl returned new URL %s -> %s\n", debugstr_w(url
), debugstr_w(new_url
));
210 CoTaskMemFree(new_url
);
217 nsresult
on_start_uri_open(NSContainer
*nscontainer
, nsIURI
*uri
, PRBool
*_retval
)
224 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
225 if(NS_FAILED(nsres
)) {
226 WARN("Could not get nsWineURI: %08x\n", nsres
);
227 return NS_ERROR_NOT_IMPLEMENTED
;
230 if(!wine_uri
->is_doc_uri
) {
231 wine_uri
->is_doc_uri
= TRUE
;
233 if(!wine_uri
->container
) {
234 nsIWebBrowserChrome_AddRef(NSWBCHROME(nscontainer
));
235 wine_uri
->container
= nscontainer
;
239 *_retval
= translate_url(nscontainer
->doc
, wine_uri
);
242 nsIURI_Release(NSURI(wine_uri
));
246 HRESULT
set_wine_url(nsWineURI
*This
, LPCWSTR url
)
248 static const WCHAR wszFtp
[] = {'f','t','p',':'};
249 static const WCHAR wszHttp
[] = {'h','t','t','p',':'};
250 static const WCHAR wszHttps
[] = {'h','t','t','p','s',':'};
252 TRACE("(%p)->(%s)\n", This
, debugstr_w(url
));
257 new_url
= heap_strdupW(url
);
259 return E_OUTOFMEMORY
;
260 heap_free(This
->wine_url
);
261 This
->wine_url
= new_url
;
264 /* FIXME: Always use wine url */
266 strncmpW(url
, wszFtp
, sizeof(wszFtp
)/sizeof(WCHAR
))
267 && strncmpW(url
, wszHttp
, sizeof(wszHttp
)/sizeof(WCHAR
))
268 && strncmpW(url
, wszHttps
, sizeof(wszHttps
)/sizeof(WCHAR
));
270 This
->use_wine_url
= TRUE
;
273 heap_free(This
->wine_url
);
274 This
->wine_url
= NULL
;
275 This
->use_wine_url
= FALSE
;
281 static void set_uri_nscontainer(nsWineURI
*This
, NSContainer
*nscontainer
)
283 if(This
->container
) {
284 if(This
->container
== nscontainer
)
286 TRACE("Changing %p -> %p\n", This
->container
, nscontainer
);
287 nsIWebBrowserChrome_Release(NSWBCHROME(This
->container
));
291 nsIWebBrowserChrome_AddRef(NSWBCHROME(nscontainer
));
292 This
->container
= nscontainer
;
295 static void set_uri_window(nsWineURI
*This
, HTMLWindow
*window
)
297 if(This
->window_ref
) {
298 if(This
->window_ref
->window
== window
)
300 TRACE("Changing %p -> %p\n", This
->window_ref
->window
, window
);
301 windowref_release(This
->window_ref
);
305 windowref_addref(window
->window_ref
);
306 This
->window_ref
= window
->window_ref
;
309 set_uri_nscontainer(This
, window
->doc_obj
->nscontainer
);
311 This
->window_ref
= NULL
;
315 static inline BOOL
is_http_channel(nsChannel
*This
)
317 return This
->url_scheme
== URL_SCHEME_HTTP
|| This
->url_scheme
== URL_SCHEME_HTTPS
;
320 static http_header_t
*find_http_header(struct list
*headers
, const WCHAR
*name
, int len
)
324 LIST_FOR_EACH_ENTRY(iter
, headers
, http_header_t
, entry
) {
325 if(!strcmpiW(iter
->header
, name
))
332 static nsresult
get_channel_http_header(struct list
*headers
, const nsACString
*header_name_str
,
335 const char *header_namea
;
336 http_header_t
*header
;
340 nsACString_GetData(header_name_str
, &header_namea
);
341 header_name
= heap_strdupAtoW(header_namea
);
343 return NS_ERROR_UNEXPECTED
;
345 header
= find_http_header(headers
, header_name
, strlenW(header_name
));
346 heap_free(header_name
);
348 return NS_ERROR_NOT_AVAILABLE
;
350 data
= heap_strdupWtoA(header
->data
);
352 return NS_ERROR_UNEXPECTED
;
354 nsACString_SetData(_retval
, data
);
359 HRESULT
set_http_header(struct list
*headers
, const WCHAR
*name
, int name_len
,
360 const WCHAR
*value
, int value_len
)
362 http_header_t
*header
;
364 TRACE("%s: %s\n", debugstr_wn(name
, name_len
), debugstr_wn(value
, value_len
));
366 header
= find_http_header(headers
, name
, name_len
);
370 new_data
= heap_strndupW(value
, value_len
);
372 return E_OUTOFMEMORY
;
374 heap_free(header
->data
);
375 header
->data
= new_data
;
377 header
= heap_alloc(sizeof(http_header_t
));
379 return E_OUTOFMEMORY
;
381 header
->header
= heap_strndupW(name
, name_len
);
382 header
->data
= heap_strndupW(value
, value_len
);
383 if(!header
->header
|| !header
->data
) {
384 heap_free(header
->header
);
385 heap_free(header
->data
);
387 return E_OUTOFMEMORY
;
390 list_add_tail(headers
, &header
->entry
);
396 static nsresult
set_channel_http_header(struct list
*headers
, const nsACString
*name_str
,
397 const nsACString
*value_str
)
399 const char *namea
, *valuea
;
403 nsACString_GetData(name_str
, &namea
);
404 name
= heap_strdupAtoW(namea
);
406 return NS_ERROR_UNEXPECTED
;
408 nsACString_GetData(value_str
, &valuea
);
409 value
= heap_strdupAtoW(valuea
);
412 return NS_ERROR_UNEXPECTED
;
415 hres
= set_http_header(headers
, name
, strlenW(name
), value
, strlenW(value
));
419 return SUCCEEDED(hres
) ? NS_OK
: NS_ERROR_UNEXPECTED
;
422 static nsresult
visit_http_headers(struct list
*headers
, nsIHttpHeaderVisitor
*visitor
)
424 nsACString header_str
, value_str
;
425 char *header
, *value
;
429 LIST_FOR_EACH_ENTRY(iter
, headers
, http_header_t
, entry
) {
430 header
= heap_strdupWtoA(iter
->header
);
432 return NS_ERROR_OUT_OF_MEMORY
;
434 value
= heap_strdupWtoA(iter
->data
);
437 return NS_ERROR_OUT_OF_MEMORY
;
440 nsACString_InitDepend(&header_str
, header
);
441 nsACString_InitDepend(&value_str
, value
);
442 nsres
= nsIHttpHeaderVisitor_VisitHeader(visitor
, &header_str
, &value_str
);
443 nsACString_Finish(&header_str
);
444 nsACString_Finish(&value_str
);
454 static void free_http_headers(struct list
*list
)
456 http_header_t
*iter
, *iter_next
;
458 LIST_FOR_EACH_ENTRY_SAFE(iter
, iter_next
, list
, http_header_t
, entry
) {
459 list_remove(&iter
->entry
);
460 heap_free(iter
->header
);
461 heap_free(iter
->data
);
466 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
468 static nsresult NSAPI
nsChannel_QueryInterface(nsIHttpChannel
*iface
, nsIIDRef riid
, void **result
)
470 nsChannel
*This
= NSCHANNEL_THIS(iface
);
472 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
473 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
474 *result
= NSCHANNEL(This
);
475 }else if(IsEqualGUID(&IID_nsIRequest
, riid
)) {
476 TRACE("(%p)->(IID_nsIRequest %p)\n", This
, result
);
477 *result
= NSCHANNEL(This
);
478 }else if(IsEqualGUID(&IID_nsIChannel
, riid
)) {
479 TRACE("(%p)->(IID_nsIChannel %p)\n", This
, result
);
480 *result
= NSCHANNEL(This
);
481 }else if(IsEqualGUID(&IID_nsIHttpChannel
, riid
)) {
482 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This
, result
);
483 *result
= is_http_channel(This
) ? NSHTTPCHANNEL(This
) : NULL
;
484 }else if(IsEqualGUID(&IID_nsIUploadChannel
, riid
)) {
485 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This
, result
);
486 *result
= NSUPCHANNEL(This
);
487 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal
, riid
)) {
488 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This
, result
);
489 *result
= is_http_channel(This
) ? NSHTTPINTERNAL(This
) : NULL
;
491 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
496 nsIChannel_AddRef(NSCHANNEL(This
));
500 return NS_NOINTERFACE
;
503 static nsrefcnt NSAPI
nsChannel_AddRef(nsIHttpChannel
*iface
)
505 nsChannel
*This
= NSCHANNEL_THIS(iface
);
506 nsrefcnt ref
= InterlockedIncrement(&This
->ref
);
508 TRACE("(%p) ref=%d\n", This
, ref
);
513 static nsrefcnt NSAPI
nsChannel_Release(nsIHttpChannel
*iface
)
515 nsChannel
*This
= NSCHANNEL_THIS(iface
);
516 LONG ref
= InterlockedDecrement(&This
->ref
);
519 nsIURI_Release(NSURI(This
->uri
));
521 nsISupports_Release(This
->owner
);
522 if(This
->post_data_stream
)
523 nsIInputStream_Release(This
->post_data_stream
);
525 nsILoadGroup_Release(This
->load_group
);
526 if(This
->notif_callback
)
527 nsIInterfaceRequestor_Release(This
->notif_callback
);
528 if(This
->original_uri
)
529 nsIURI_Release(This
->original_uri
);
531 nsIURI_Release(This
->referrer
);
533 free_http_headers(&This
->response_headers
);
534 free_http_headers(&This
->request_headers
);
536 heap_free(This
->content_type
);
537 heap_free(This
->charset
);
544 static nsresult NSAPI
nsChannel_GetName(nsIHttpChannel
*iface
, nsACString
*aName
)
546 nsChannel
*This
= NSCHANNEL_THIS(iface
);
548 TRACE("(%p)->(%p)\n", This
, aName
);
550 return nsIURI_GetSpec(NSURI(This
->uri
), aName
);
553 static nsresult NSAPI
nsChannel_IsPending(nsIHttpChannel
*iface
, PRBool
*_retval
)
555 nsChannel
*This
= NSCHANNEL_THIS(iface
);
557 FIXME("(%p)->(%p)\n", This
, _retval
);
559 return NS_ERROR_NOT_IMPLEMENTED
;
562 static nsresult NSAPI
nsChannel_GetStatus(nsIHttpChannel
*iface
, nsresult
*aStatus
)
564 nsChannel
*This
= NSCHANNEL_THIS(iface
);
566 WARN("(%p)->(%p) returning NS_OK\n", This
, aStatus
);
568 return *aStatus
= NS_OK
;
571 static nsresult NSAPI
nsChannel_Cancel(nsIHttpChannel
*iface
, nsresult aStatus
)
573 nsChannel
*This
= NSCHANNEL_THIS(iface
);
575 FIXME("(%p)->(%08x)\n", This
, aStatus
);
577 return NS_ERROR_NOT_IMPLEMENTED
;
580 static nsresult NSAPI
nsChannel_Suspend(nsIHttpChannel
*iface
)
582 nsChannel
*This
= NSCHANNEL_THIS(iface
);
584 FIXME("(%p)\n", This
);
586 return NS_ERROR_NOT_IMPLEMENTED
;
589 static nsresult NSAPI
nsChannel_Resume(nsIHttpChannel
*iface
)
591 nsChannel
*This
= NSCHANNEL_THIS(iface
);
593 FIXME("(%p)\n", This
);
595 return NS_ERROR_NOT_IMPLEMENTED
;
598 static nsresult NSAPI
nsChannel_GetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
**aLoadGroup
)
600 nsChannel
*This
= NSCHANNEL_THIS(iface
);
602 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
605 nsILoadGroup_AddRef(This
->load_group
);
607 *aLoadGroup
= This
->load_group
;
611 static nsresult NSAPI
nsChannel_SetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
*aLoadGroup
)
613 nsChannel
*This
= NSCHANNEL_THIS(iface
);
615 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
618 nsILoadGroup_Release(This
->load_group
);
620 nsILoadGroup_AddRef(aLoadGroup
);
621 This
->load_group
= aLoadGroup
;
626 static nsresult NSAPI
nsChannel_GetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags
*aLoadFlags
)
628 nsChannel
*This
= NSCHANNEL_THIS(iface
);
630 TRACE("(%p)->(%p)\n", This
, aLoadFlags
);
632 *aLoadFlags
= This
->load_flags
;
636 static nsresult NSAPI
nsChannel_SetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags aLoadFlags
)
638 nsChannel
*This
= NSCHANNEL_THIS(iface
);
640 TRACE("(%p)->(%08x)\n", This
, aLoadFlags
);
642 This
->load_flags
= aLoadFlags
;
646 static nsresult NSAPI
nsChannel_GetOriginalURI(nsIHttpChannel
*iface
, nsIURI
**aOriginalURI
)
648 nsChannel
*This
= NSCHANNEL_THIS(iface
);
650 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
652 if(This
->original_uri
)
653 nsIURI_AddRef(This
->original_uri
);
655 *aOriginalURI
= This
->original_uri
;
659 static nsresult NSAPI
nsChannel_SetOriginalURI(nsIHttpChannel
*iface
, nsIURI
*aOriginalURI
)
661 nsChannel
*This
= NSCHANNEL_THIS(iface
);
663 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
665 if(This
->original_uri
)
666 nsIURI_Release(This
->original_uri
);
668 nsIURI_AddRef(aOriginalURI
);
669 This
->original_uri
= aOriginalURI
;
673 static nsresult NSAPI
nsChannel_GetURI(nsIHttpChannel
*iface
, nsIURI
**aURI
)
675 nsChannel
*This
= NSCHANNEL_THIS(iface
);
677 TRACE("(%p)->(%p)\n", This
, aURI
);
679 nsIURI_AddRef(NSURI(This
->uri
));
680 *aURI
= (nsIURI
*)This
->uri
;
685 static nsresult NSAPI
nsChannel_GetOwner(nsIHttpChannel
*iface
, nsISupports
**aOwner
)
687 nsChannel
*This
= NSCHANNEL_THIS(iface
);
689 TRACE("(%p)->(%p)\n", This
, aOwner
);
692 nsISupports_AddRef(This
->owner
);
693 *aOwner
= This
->owner
;
698 static nsresult NSAPI
nsChannel_SetOwner(nsIHttpChannel
*iface
, nsISupports
*aOwner
)
700 nsChannel
*This
= NSCHANNEL_THIS(iface
);
702 TRACE("(%p)->(%p)\n", This
, aOwner
);
705 nsISupports_AddRef(aOwner
);
707 nsISupports_Release(This
->owner
);
708 This
->owner
= aOwner
;
713 static nsresult NSAPI
nsChannel_GetNotificationCallbacks(nsIHttpChannel
*iface
,
714 nsIInterfaceRequestor
**aNotificationCallbacks
)
716 nsChannel
*This
= NSCHANNEL_THIS(iface
);
718 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
720 if(This
->notif_callback
)
721 nsIInterfaceRequestor_AddRef(This
->notif_callback
);
722 *aNotificationCallbacks
= This
->notif_callback
;
727 static nsresult NSAPI
nsChannel_SetNotificationCallbacks(nsIHttpChannel
*iface
,
728 nsIInterfaceRequestor
*aNotificationCallbacks
)
730 nsChannel
*This
= NSCHANNEL_THIS(iface
);
732 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
734 if(This
->notif_callback
)
735 nsIInterfaceRequestor_Release(This
->notif_callback
);
736 if(aNotificationCallbacks
)
737 nsIInterfaceRequestor_AddRef(aNotificationCallbacks
);
739 This
->notif_callback
= aNotificationCallbacks
;
744 static nsresult NSAPI
nsChannel_GetSecurityInfo(nsIHttpChannel
*iface
, nsISupports
**aSecurityInfo
)
746 nsChannel
*This
= NSCHANNEL_THIS(iface
);
748 TRACE("(%p)->(%p)\n", This
, aSecurityInfo
);
750 return NS_ERROR_NOT_IMPLEMENTED
;
753 static nsresult NSAPI
nsChannel_GetContentType(nsIHttpChannel
*iface
, nsACString
*aContentType
)
755 nsChannel
*This
= NSCHANNEL_THIS(iface
);
757 TRACE("(%p)->(%p)\n", This
, aContentType
);
759 if(This
->content_type
) {
760 nsACString_SetData(aContentType
, This
->content_type
);
764 WARN("unknown type\n");
765 return NS_ERROR_FAILURE
;
768 static nsresult NSAPI
nsChannel_SetContentType(nsIHttpChannel
*iface
,
769 const nsACString
*aContentType
)
771 nsChannel
*This
= NSCHANNEL_THIS(iface
);
772 const char *content_type
;
774 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentType
));
776 nsACString_GetData(aContentType
, &content_type
);
777 heap_free(This
->content_type
);
778 This
->content_type
= heap_strdupA(content_type
);
783 static nsresult NSAPI
nsChannel_GetContentCharset(nsIHttpChannel
*iface
,
784 nsACString
*aContentCharset
)
786 nsChannel
*This
= NSCHANNEL_THIS(iface
);
788 TRACE("(%p)->(%p)\n", This
, aContentCharset
);
791 nsACString_SetData(aContentCharset
, This
->charset
);
795 nsACString_SetData(aContentCharset
, "");
799 static nsresult NSAPI
nsChannel_SetContentCharset(nsIHttpChannel
*iface
,
800 const nsACString
*aContentCharset
)
802 nsChannel
*This
= NSCHANNEL_THIS(iface
);
804 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentCharset
));
806 return NS_ERROR_NOT_IMPLEMENTED
;
809 static nsresult NSAPI
nsChannel_GetContentLength(nsIHttpChannel
*iface
, PRInt32
*aContentLength
)
811 nsChannel
*This
= NSCHANNEL_THIS(iface
);
813 FIXME("(%p)->(%p)\n", This
, aContentLength
);
815 return NS_ERROR_NOT_IMPLEMENTED
;
818 static nsresult NSAPI
nsChannel_SetContentLength(nsIHttpChannel
*iface
, PRInt32 aContentLength
)
820 nsChannel
*This
= NSCHANNEL_THIS(iface
);
822 FIXME("(%p)->(%d)\n", This
, aContentLength
);
824 return NS_ERROR_NOT_IMPLEMENTED
;
827 static nsresult NSAPI
nsChannel_Open(nsIHttpChannel
*iface
, nsIInputStream
**_retval
)
829 nsChannel
*This
= NSCHANNEL_THIS(iface
);
831 FIXME("(%p)->(%p)\n", This
, _retval
);
833 return NS_ERROR_NOT_IMPLEMENTED
;
836 static HTMLWindow
*get_window_from_load_group(nsChannel
*This
)
845 nsres
= nsILoadGroup_GetDefaultLoadRequest(This
->load_group
, &req
);
846 if(NS_FAILED(nsres
)) {
847 ERR("GetDefaultLoadRequest failed: %08x\n", nsres
);
854 nsres
= nsIRequest_QueryInterface(req
, &IID_nsIChannel
, (void**)&channel
);
855 nsIRequest_Release(req
);
856 if(NS_FAILED(nsres
)) {
857 WARN("Could not get nsIChannel interface: %08x\n", nsres
);
861 nsres
= nsIChannel_GetURI(channel
, &uri
);
862 nsIChannel_Release(channel
);
863 if(NS_FAILED(nsres
)) {
864 ERR("GetURI failed: %08x\n", nsres
);
868 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
870 if(NS_FAILED(nsres
)) {
871 TRACE("Could not get nsWineURI: %08x\n", nsres
);
875 window
= wine_uri
->window_ref
? wine_uri
->window_ref
->window
: NULL
;
877 IHTMLWindow2_AddRef(HTMLWINDOW2(window
));
878 nsIURI_Release(NSURI(wine_uri
));
883 static HTMLWindow
*get_channel_window(nsChannel
*This
)
885 nsIWebProgress
*web_progress
;
886 nsIDOMWindow
*nswindow
;
890 if(This
->load_group
) {
891 nsIRequestObserver
*req_observer
;
893 nsres
= nsILoadGroup_GetGroupObserver(This
->load_group
, &req_observer
);
894 if(NS_FAILED(nsres
) || !req_observer
) {
895 ERR("GetGroupObserver failed: %08x\n", nsres
);
899 nsres
= nsIRequestObserver_QueryInterface(req_observer
, &IID_nsIWebProgress
, (void**)&web_progress
);
900 nsIRequestObserver_Release(req_observer
);
901 if(NS_FAILED(nsres
)) {
902 ERR("Could not get nsIWebProgress iface: %08x\n", nsres
);
905 }else if(This
->notif_callback
) {
906 nsres
= nsIInterfaceRequestor_GetInterface(This
->notif_callback
, &IID_nsIWebProgress
, (void**)&web_progress
);
907 if(NS_FAILED(nsres
)) {
908 ERR("GetInterface(IID_nsIWebProgress failed: %08x\n", nsres
);
912 ERR("no load group nor notif callback\n");
916 nsres
= nsIWebProgress_GetDOMWindow(web_progress
, &nswindow
);
917 nsIWebProgress_Release(web_progress
);
918 if(NS_FAILED(nsres
) || !nswindow
) {
919 ERR("GetDOMWindow failed: %08x\n", nsres
);
923 window
= nswindow_to_window(nswindow
);
924 nsIDOMWindow_Release(nswindow
);
927 IHTMLWindow2_AddRef(HTMLWINDOW2(window
));
929 FIXME("NULL window for %p\n", nswindow
);
935 HTMLDocumentNode
*doc
;
936 nsChannelBSC
*bscallback
;
937 } start_binding_task_t
;
939 static void start_binding_proc(task_t
*_task
)
941 start_binding_task_t
*task
= (start_binding_task_t
*)_task
;
943 start_binding(NULL
, task
->doc
, (BSCallback
*)task
->bscallback
, NULL
);
945 IUnknown_Release((IUnknown
*)task
->bscallback
);
948 static nsresult
async_open(nsChannel
*This
, HTMLWindow
*window
, BOOL is_doc_channel
, nsIStreamListener
*listener
,
949 nsISupports
*context
)
951 nsChannelBSC
*bscallback
;
952 IMoniker
*mon
= NULL
;
955 hres
= CreateURLMoniker(NULL
, This
->uri
->wine_url
, &mon
);
957 WARN("CreateURLMoniker failed: %08x\n", hres
);
958 return NS_ERROR_UNEXPECTED
;
962 set_current_mon(window
, mon
);
964 hres
= create_channelbsc(mon
, NULL
, NULL
, 0, &bscallback
);
965 IMoniker_Release(mon
);
967 return NS_ERROR_UNEXPECTED
;
969 channelbsc_set_channel(bscallback
, This
, listener
, context
);
972 set_window_bscallback(window
, bscallback
);
973 async_start_doc_binding(window
, bscallback
);
974 IUnknown_Release((IUnknown
*)bscallback
);
976 start_binding_task_t
*task
= heap_alloc(sizeof(start_binding_task_t
));
978 task
->doc
= window
->doc
;
979 task
->bscallback
= bscallback
;
980 push_task(&task
->header
, start_binding_proc
, window
->doc
->basedoc
.task_magic
);
986 static nsresult NSAPI
nsChannel_AsyncOpen(nsIHttpChannel
*iface
, nsIStreamListener
*aListener
,
987 nsISupports
*aContext
)
989 nsChannel
*This
= NSCHANNEL_THIS(iface
);
990 HTMLWindow
*window
= NULL
;
992 nsresult nsres
= NS_OK
;
994 TRACE("(%p)->(%p %p) opening %s\n", This
, aListener
, aContext
, debugstr_w(This
->uri
->wine_url
));
996 if(This
->uri
->is_doc_uri
) {
997 window
= get_channel_window(This
);
999 set_uri_window(This
->uri
, window
);
1000 }else if(This
->uri
->container
) {
1003 /* nscontainer->doc should be NULL which means navigation to a new window */
1004 if(This
->uri
->container
->doc
)
1005 FIXME("nscontainer->doc = %p\n", This
->uri
->container
->doc
);
1007 b
= before_async_open(This
, This
->uri
->container
);
1009 FIXME("Navigation not cancelled\n");
1010 return NS_ERROR_UNEXPECTED
;
1015 if(This
->uri
->window_ref
&& This
->uri
->window_ref
->window
) {
1016 window
= This
->uri
->window_ref
->window
;
1017 IHTMLWindow2_AddRef(HTMLWINDOW2(window
));
1019 /* FIXME: Analyze removing get_window_from_load_group call */
1020 if(This
->load_group
)
1021 window
= get_window_from_load_group(This
);
1023 window
= get_channel_window(This
);
1025 set_uri_window(This
->uri
, window
);
1030 ERR("window = NULL\n");
1031 return NS_ERROR_UNEXPECTED
;
1034 if(This
->uri
->is_doc_uri
&& window
== window
->doc_obj
->basedoc
.window
) {
1035 if(This
->uri
->channel_bsc
) {
1036 channelbsc_set_channel(This
->uri
->channel_bsc
, This
, aListener
, aContext
);
1038 if(window
->doc_obj
->mime
) {
1039 heap_free(This
->content_type
);
1040 This
->content_type
= heap_strdupWtoA(window
->doc_obj
->mime
);
1045 open
= !before_async_open(This
, window
->doc_obj
->nscontainer
);
1047 TRACE("canceled\n");
1048 nsres
= NS_ERROR_UNEXPECTED
;
1054 nsres
= async_open(This
, window
, This
->uri
->is_doc_uri
, aListener
, aContext
);
1056 if(NS_SUCCEEDED(nsres
) && This
->load_group
) {
1057 nsres
= nsILoadGroup_AddRequest(This
->load_group
, (nsIRequest
*)NSCHANNEL(This
), aContext
);
1058 if(NS_FAILED(nsres
))
1059 ERR("AddRequest failed: %08x\n", nsres
);
1062 IHTMLWindow2_Release(HTMLWINDOW2(window
));
1066 static nsresult NSAPI
nsChannel_GetRequestMethod(nsIHttpChannel
*iface
, nsACString
*aRequestMethod
)
1068 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1070 TRACE("(%p)->(%p)\n", This
, aRequestMethod
);
1072 nsACString_SetData(aRequestMethod
, request_method_strings
[This
->request_method
]);
1076 static nsresult NSAPI
nsChannel_SetRequestMethod(nsIHttpChannel
*iface
,
1077 const nsACString
*aRequestMethod
)
1079 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1083 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRequestMethod
));
1085 nsACString_GetData(aRequestMethod
, &method
);
1086 for(i
=0; i
< sizeof(request_method_strings
)/sizeof(*request_method_strings
); i
++) {
1087 if(!strcasecmp(method
, request_method_strings
[i
])) {
1088 This
->request_method
= i
;
1093 ERR("Invalid method %s\n", debugstr_a(method
));
1094 return NS_ERROR_UNEXPECTED
;
1097 static nsresult NSAPI
nsChannel_GetReferrer(nsIHttpChannel
*iface
, nsIURI
**aReferrer
)
1099 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1101 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1104 nsIURI_AddRef(This
->referrer
);
1105 *aReferrer
= This
->referrer
;
1109 static nsresult NSAPI
nsChannel_SetReferrer(nsIHttpChannel
*iface
, nsIURI
*aReferrer
)
1111 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1113 TRACE("(%p)->(%p)\n", This
, aReferrer
);
1116 nsIURI_AddRef(aReferrer
);
1118 nsIURI_Release(This
->referrer
);
1119 This
->referrer
= aReferrer
;
1123 static nsresult NSAPI
nsChannel_GetRequestHeader(nsIHttpChannel
*iface
,
1124 const nsACString
*aHeader
, nsACString
*_retval
)
1126 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1128 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aHeader
), _retval
);
1130 return get_channel_http_header(&This
->request_headers
, aHeader
, _retval
);
1133 static nsresult NSAPI
nsChannel_SetRequestHeader(nsIHttpChannel
*iface
,
1134 const nsACString
*aHeader
, const nsACString
*aValue
, PRBool aMerge
)
1136 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1138 TRACE("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(aHeader
), debugstr_nsacstr(aValue
), aMerge
);
1141 FIXME("aMerge not supported\n");
1143 return set_channel_http_header(&This
->request_headers
, aHeader
, aValue
);
1146 static nsresult NSAPI
nsChannel_VisitRequestHeaders(nsIHttpChannel
*iface
,
1147 nsIHttpHeaderVisitor
*aVisitor
)
1149 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1151 FIXME("(%p)->(%p)\n", This
, aVisitor
);
1153 return NS_ERROR_NOT_IMPLEMENTED
;
1156 static nsresult NSAPI
nsChannel_GetAllowPipelining(nsIHttpChannel
*iface
, PRBool
*aAllowPipelining
)
1158 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1160 FIXME("(%p)->(%p)\n", This
, aAllowPipelining
);
1162 return NS_ERROR_NOT_IMPLEMENTED
;
1165 static nsresult NSAPI
nsChannel_SetAllowPipelining(nsIHttpChannel
*iface
, PRBool aAllowPipelining
)
1167 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1169 FIXME("(%p)->(%x)\n", This
, aAllowPipelining
);
1171 return NS_ERROR_NOT_IMPLEMENTED
;
1174 static nsresult NSAPI
nsChannel_GetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32
*aRedirectionLimit
)
1176 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1178 FIXME("(%p)->(%p)\n", This
, aRedirectionLimit
);
1180 return NS_ERROR_NOT_IMPLEMENTED
;
1183 static nsresult NSAPI
nsChannel_SetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32 aRedirectionLimit
)
1185 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1187 FIXME("(%p)->(%u)\n", This
, aRedirectionLimit
);
1189 return NS_ERROR_NOT_IMPLEMENTED
;
1192 static nsresult NSAPI
nsChannel_GetResponseStatus(nsIHttpChannel
*iface
, PRUint32
*aResponseStatus
)
1194 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1196 TRACE("(%p)->(%p)\n", This
, aResponseStatus
);
1198 if(This
->response_status
) {
1199 *aResponseStatus
= This
->response_status
;
1203 WARN("No response status\n");
1204 return NS_ERROR_UNEXPECTED
;
1207 static nsresult NSAPI
nsChannel_GetResponseStatusText(nsIHttpChannel
*iface
,
1208 nsACString
*aResponseStatusText
)
1210 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1212 FIXME("(%p)->(%p)\n", This
, aResponseStatusText
);
1214 return NS_ERROR_NOT_IMPLEMENTED
;
1217 static nsresult NSAPI
nsChannel_GetRequestSucceeded(nsIHttpChannel
*iface
,
1218 PRBool
*aRequestSucceeded
)
1220 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1222 TRACE("(%p)->(%p)\n", This
, aRequestSucceeded
);
1224 if(!This
->response_status
)
1225 return NS_ERROR_NOT_AVAILABLE
;
1227 *aRequestSucceeded
= This
->response_status
/100 == 2;
1232 static nsresult NSAPI
nsChannel_GetResponseHeader(nsIHttpChannel
*iface
,
1233 const nsACString
*header
, nsACString
*_retval
)
1235 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1237 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(header
), _retval
);
1239 return get_channel_http_header(&This
->response_headers
, header
, _retval
);
1242 static nsresult NSAPI
nsChannel_SetResponseHeader(nsIHttpChannel
*iface
,
1243 const nsACString
*header
, const nsACString
*value
, PRBool merge
)
1245 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1247 FIXME("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(header
), debugstr_nsacstr(value
), merge
);
1249 return NS_ERROR_NOT_IMPLEMENTED
;
1252 static nsresult NSAPI
nsChannel_VisitResponseHeaders(nsIHttpChannel
*iface
,
1253 nsIHttpHeaderVisitor
*aVisitor
)
1255 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1257 TRACE("(%p)->(%p)\n", This
, aVisitor
);
1259 return visit_http_headers(&This
->response_headers
, aVisitor
);
1262 static nsresult NSAPI
nsChannel_IsNoStoreResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1264 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1266 FIXME("(%p)->(%p)\n", This
, _retval
);
1268 return NS_ERROR_NOT_IMPLEMENTED
;
1271 static nsresult NSAPI
nsChannel_IsNoCacheResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1273 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1275 FIXME("(%p)->(%p)\n", This
, _retval
);
1277 return NS_ERROR_NOT_IMPLEMENTED
;
1280 #undef NSCHANNEL_THIS
1282 static const nsIHttpChannelVtbl nsChannelVtbl
= {
1283 nsChannel_QueryInterface
,
1287 nsChannel_IsPending
,
1288 nsChannel_GetStatus
,
1292 nsChannel_GetLoadGroup
,
1293 nsChannel_SetLoadGroup
,
1294 nsChannel_GetLoadFlags
,
1295 nsChannel_SetLoadFlags
,
1296 nsChannel_GetOriginalURI
,
1297 nsChannel_SetOriginalURI
,
1301 nsChannel_GetNotificationCallbacks
,
1302 nsChannel_SetNotificationCallbacks
,
1303 nsChannel_GetSecurityInfo
,
1304 nsChannel_GetContentType
,
1305 nsChannel_SetContentType
,
1306 nsChannel_GetContentCharset
,
1307 nsChannel_SetContentCharset
,
1308 nsChannel_GetContentLength
,
1309 nsChannel_SetContentLength
,
1311 nsChannel_AsyncOpen
,
1312 nsChannel_GetRequestMethod
,
1313 nsChannel_SetRequestMethod
,
1314 nsChannel_GetReferrer
,
1315 nsChannel_SetReferrer
,
1316 nsChannel_GetRequestHeader
,
1317 nsChannel_SetRequestHeader
,
1318 nsChannel_VisitRequestHeaders
,
1319 nsChannel_GetAllowPipelining
,
1320 nsChannel_SetAllowPipelining
,
1321 nsChannel_GetRedirectionLimit
,
1322 nsChannel_SetRedirectionLimit
,
1323 nsChannel_GetResponseStatus
,
1324 nsChannel_GetResponseStatusText
,
1325 nsChannel_GetRequestSucceeded
,
1326 nsChannel_GetResponseHeader
,
1327 nsChannel_SetResponseHeader
,
1328 nsChannel_VisitResponseHeaders
,
1329 nsChannel_IsNoStoreResponse
,
1330 nsChannel_IsNoCacheResponse
1333 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1335 static nsresult NSAPI
nsUploadChannel_QueryInterface(nsIUploadChannel
*iface
, nsIIDRef riid
,
1338 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1339 return nsIChannel_QueryInterface(NSCHANNEL(This
), riid
, result
);
1342 static nsrefcnt NSAPI
nsUploadChannel_AddRef(nsIUploadChannel
*iface
)
1344 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1345 return nsIChannel_AddRef(NSCHANNEL(This
));
1348 static nsrefcnt NSAPI
nsUploadChannel_Release(nsIUploadChannel
*iface
)
1350 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1351 return nsIChannel_Release(NSCHANNEL(This
));
1354 static nsresult NSAPI
nsUploadChannel_SetUploadStream(nsIUploadChannel
*iface
,
1355 nsIInputStream
*aStream
, const nsACString
*aContentType
, PRInt32 aContentLength
)
1357 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1358 const char *content_type
;
1360 static const WCHAR content_typeW
[] =
1361 {'C','o','n','t','e','n','t','-','T','y','p','e',0};
1363 TRACE("(%p)->(%p %s %d)\n", This
, aStream
, debugstr_nsacstr(aContentType
), aContentLength
);
1365 This
->parse_stream
= TRUE
;
1367 nsACString_GetData(aContentType
, &content_type
);
1371 ct
= heap_strdupAtoW(content_type
);
1373 return NS_ERROR_UNEXPECTED
;
1375 set_http_header(&This
->request_headers
, content_typeW
,
1376 sizeof(content_typeW
)/sizeof(WCHAR
), ct
, strlenW(ct
));
1378 This
->parse_stream
= FALSE
;
1382 if(This
->post_data_stream
)
1383 nsIInputStream_Release(This
->post_data_stream
);
1385 if(aContentLength
!= -1)
1386 FIXME("Unsupported acontentLength = %d\n", aContentLength
);
1388 if(This
->post_data_stream
)
1389 nsIInputStream_Release(This
->post_data_stream
);
1390 This
->post_data_stream
= aStream
;
1392 nsIInputStream_AddRef(aStream
);
1394 This
->request_method
= METHOD_POST
;
1398 static nsresult NSAPI
nsUploadChannel_GetUploadStream(nsIUploadChannel
*iface
,
1399 nsIInputStream
**aUploadStream
)
1401 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1403 TRACE("(%p)->(%p)\n", This
, aUploadStream
);
1405 if(This
->post_data_stream
)
1406 nsIInputStream_AddRef(This
->post_data_stream
);
1408 *aUploadStream
= This
->post_data_stream
;
1412 #undef NSUPCHANNEL_THIS
1414 static const nsIUploadChannelVtbl nsUploadChannelVtbl
= {
1415 nsUploadChannel_QueryInterface
,
1416 nsUploadChannel_AddRef
,
1417 nsUploadChannel_Release
,
1418 nsUploadChannel_SetUploadStream
,
1419 nsUploadChannel_GetUploadStream
1422 #define NSHTTPINTERNAL_THIS(iface) DEFINE_THIS(nsChannel, IHttpChannelInternal, iface)
1424 static nsresult NSAPI
nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal
*iface
, nsIIDRef riid
,
1427 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1428 return nsIChannel_QueryInterface(NSCHANNEL(This
), riid
, result
);
1431 static nsrefcnt NSAPI
nsHttpChannelInternal_AddRef(nsIHttpChannelInternal
*iface
)
1433 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1434 return nsIChannel_AddRef(NSCHANNEL(This
));
1437 static nsrefcnt NSAPI
nsHttpChannelInternal_Release(nsIHttpChannelInternal
*iface
)
1439 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1440 return nsIChannel_Release(NSCHANNEL(This
));
1443 static nsresult NSAPI
nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
**aDocumentURI
)
1445 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1447 FIXME("(%p)->()\n", This
);
1449 return NS_ERROR_NOT_IMPLEMENTED
;
1452 static nsresult NSAPI
nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
*aDocumentURI
)
1454 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1456 FIXME("(%p)->()\n", This
);
1458 return NS_ERROR_NOT_IMPLEMENTED
;
1461 static nsresult NSAPI
nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal
*iface
, PRUint32
*major
, PRUint32
*minor
)
1463 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1465 FIXME("(%p)->()\n", This
);
1467 return NS_ERROR_NOT_IMPLEMENTED
;
1470 static nsresult NSAPI
nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal
*iface
, PRUint32
*major
, PRUint32
*minor
)
1472 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1474 FIXME("(%p)->()\n", This
);
1476 return NS_ERROR_NOT_IMPLEMENTED
;
1479 static nsresult NSAPI
nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal
*iface
, const char *aCookieHeader
)
1481 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1483 FIXME("(%p)->()\n", This
);
1485 return NS_ERROR_NOT_IMPLEMENTED
;
1488 static nsresult NSAPI
nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal
*iface
, const char *aFallbackKey
)
1490 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1492 FIXME("(%p)->()\n", This
);
1494 return NS_ERROR_NOT_IMPLEMENTED
;
1497 static nsresult NSAPI
nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, PRBool
*aForceThirdPartyCookie
)
1499 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1501 FIXME("(%p)->()\n", This
);
1503 return NS_ERROR_NOT_IMPLEMENTED
;
1506 static nsresult NSAPI
nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, PRBool aForceThirdPartyCookie
)
1508 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1510 FIXME("(%p)->()\n", This
);
1512 return NS_ERROR_NOT_IMPLEMENTED
;
1515 static nsresult NSAPI
nsHttpChannelInternal_GetCanceled(nsIHttpChannelInternal
*iface
, PRBool
*aCanceled
)
1517 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1519 FIXME("(%p)->(%p)\n", This
, aCanceled
);
1521 return NS_ERROR_NOT_IMPLEMENTED
;
1524 #undef NSHTTPINTERNAL_THIS
1526 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl
= {
1527 nsHttpChannelInternal_QueryInterface
,
1528 nsHttpChannelInternal_AddRef
,
1529 nsHttpChannelInternal_Release
,
1530 nsHttpChannelInternal_GetDocumentURI
,
1531 nsHttpChannelInternal_SetDocumentURI
,
1532 nsHttpChannelInternal_GetRequestVersion
,
1533 nsHttpChannelInternal_GetResponseVersion
,
1534 nsHttpChannelInternal_SetCookie
,
1535 nsHttpChannelInternal_SetupFallbackChannel
,
1536 nsHttpChannelInternal_GetForceAllowThirdPartyCookie
,
1537 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
,
1538 nsHttpChannelInternal_GetCanceled
1541 #define NSURI_THIS(iface) DEFINE_THIS(nsWineURI, IURL, iface)
1543 static nsresult NSAPI
nsURI_QueryInterface(nsIURL
*iface
, nsIIDRef riid
, void **result
)
1545 nsWineURI
*This
= NSURI_THIS(iface
);
1549 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1550 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1551 *result
= NSURI(This
);
1552 }else if(IsEqualGUID(&IID_nsIURI
, riid
)) {
1553 TRACE("(%p)->(IID_nsIURI %p)\n", This
, result
);
1554 *result
= NSURI(This
);
1555 }else if(IsEqualGUID(&IID_nsIURL
, riid
)) {
1556 TRACE("(%p)->(IID_nsIURL %p)\n", This
, result
);
1557 *result
= NSURL(This
);
1558 }else if(IsEqualGUID(&IID_nsWineURI
, riid
)) {
1559 TRACE("(%p)->(IID_nsWineURI %p)\n", This
, result
);
1564 nsIURI_AddRef(NSURI(This
));
1568 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1569 return This
->uri
? nsIURI_QueryInterface(This
->uri
, riid
, result
) : NS_NOINTERFACE
;
1572 static nsrefcnt NSAPI
nsURI_AddRef(nsIURL
*iface
)
1574 nsWineURI
*This
= NSURI_THIS(iface
);
1575 LONG ref
= InterlockedIncrement(&This
->ref
);
1577 TRACE("(%p) ref=%d\n", This
, ref
);
1582 static nsrefcnt NSAPI
nsURI_Release(nsIURL
*iface
)
1584 nsWineURI
*This
= NSURI_THIS(iface
);
1585 LONG ref
= InterlockedDecrement(&This
->ref
);
1587 TRACE("(%p) ref=%d\n", This
, ref
);
1590 if(This
->window_ref
)
1591 windowref_release(This
->window_ref
);
1593 nsIWebBrowserChrome_Release(NSWBCHROME(This
->container
));
1595 nsIURL_Release(This
->nsurl
);
1597 nsIURI_Release(This
->uri
);
1598 heap_free(This
->wine_url
);
1605 static nsresult NSAPI
nsURI_GetSpec(nsIURL
*iface
, nsACString
*aSpec
)
1607 nsWineURI
*This
= NSURI_THIS(iface
);
1609 TRACE("(%p)->(%p)\n", This
, aSpec
);
1611 if(This
->use_wine_url
) {
1612 char speca
[INTERNET_MAX_URL_LENGTH
];
1613 WideCharToMultiByte(CP_ACP
, 0, This
->wine_url
, -1, speca
, sizeof(speca
), NULL
, NULL
);
1614 nsACString_SetData(aSpec
, speca
);
1620 return nsIURI_GetSpec(This
->uri
, aSpec
);
1622 TRACE("returning error\n");
1623 return NS_ERROR_NOT_IMPLEMENTED
;
1627 static nsresult NSAPI
nsURI_SetSpec(nsIURL
*iface
, const nsACString
*aSpec
)
1629 nsWineURI
*This
= NSURI_THIS(iface
);
1631 TRACE("(%p)->(%p)\n", This
, debugstr_nsacstr(aSpec
));
1634 return nsIURI_SetSpec(This
->uri
, aSpec
);
1636 FIXME("default action not implemented\n");
1637 return NS_ERROR_NOT_IMPLEMENTED
;
1640 static nsresult NSAPI
nsURI_GetPrePath(nsIURL
*iface
, nsACString
*aPrePath
)
1642 nsWineURI
*This
= NSURI_THIS(iface
);
1644 TRACE("(%p)->(%p)\n", This
, aPrePath
);
1647 return nsIURI_GetPrePath(This
->uri
, aPrePath
);
1649 FIXME("default action not implemented\n");
1650 return NS_ERROR_NOT_IMPLEMENTED
;
1653 static nsresult NSAPI
nsURI_GetScheme(nsIURL
*iface
, nsACString
*aScheme
)
1655 nsWineURI
*This
= NSURI_THIS(iface
);
1657 TRACE("(%p)->(%p)\n", This
, aScheme
);
1659 if(This
->use_wine_url
) {
1660 char scheme
[INTERNET_MAX_SCHEME_LENGTH
+1];
1664 ptr
= strchrW(This
->wine_url
, ':');
1666 nsACString_SetData(aScheme
, "wine");
1670 len
= WideCharToMultiByte(CP_ACP
, 0, This
->wine_url
, ptr
-This
->wine_url
, scheme
,
1671 sizeof(scheme
), NULL
, NULL
);
1672 scheme
[min(len
,sizeof(scheme
)-1)] = 0;
1673 nsACString_SetData(aScheme
, strcmp(scheme
, "about") ? scheme
: "wine");
1678 return nsIURI_GetScheme(This
->uri
, aScheme
);
1680 TRACE("returning error\n");
1681 return NS_ERROR_NOT_IMPLEMENTED
;
1684 static nsresult NSAPI
nsURI_SetScheme(nsIURL
*iface
, const nsACString
*aScheme
)
1686 nsWineURI
*This
= NSURI_THIS(iface
);
1688 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aScheme
));
1691 return nsIURI_SetScheme(This
->uri
, aScheme
);
1693 FIXME("default action not implemented\n");
1694 return NS_ERROR_NOT_IMPLEMENTED
;
1697 static nsresult NSAPI
nsURI_GetUserPass(nsIURL
*iface
, nsACString
*aUserPass
)
1699 nsWineURI
*This
= NSURI_THIS(iface
);
1701 TRACE("(%p)->(%p)\n", This
, aUserPass
);
1704 return nsIURI_GetUserPass(This
->uri
, aUserPass
);
1706 FIXME("default action not implemented\n");
1707 return NS_ERROR_NOT_IMPLEMENTED
;
1710 static nsresult NSAPI
nsURI_SetUserPass(nsIURL
*iface
, const nsACString
*aUserPass
)
1712 nsWineURI
*This
= NSURI_THIS(iface
);
1714 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUserPass
));
1717 return nsIURI_SetUserPass(This
->uri
, aUserPass
);
1719 FIXME("default action not implemented\n");
1720 return NS_ERROR_NOT_IMPLEMENTED
;
1723 static nsresult NSAPI
nsURI_GetUsername(nsIURL
*iface
, nsACString
*aUsername
)
1725 nsWineURI
*This
= NSURI_THIS(iface
);
1727 TRACE("(%p)->(%p)\n", This
, aUsername
);
1730 return nsIURI_GetUsername(This
->uri
, aUsername
);
1732 FIXME("default action not implemented\n");
1733 return NS_ERROR_NOT_IMPLEMENTED
;
1736 static nsresult NSAPI
nsURI_SetUsername(nsIURL
*iface
, const nsACString
*aUsername
)
1738 nsWineURI
*This
= NSURI_THIS(iface
);
1740 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUsername
));
1743 return nsIURI_SetUsername(This
->uri
, aUsername
);
1745 FIXME("default action not implemented\n");
1746 return NS_ERROR_NOT_IMPLEMENTED
;
1749 static nsresult NSAPI
nsURI_GetPassword(nsIURL
*iface
, nsACString
*aPassword
)
1751 nsWineURI
*This
= NSURI_THIS(iface
);
1753 TRACE("(%p)->(%p)\n", This
, aPassword
);
1756 return nsIURI_GetPassword(This
->uri
, aPassword
);
1758 FIXME("default action not implemented\n");
1759 return NS_ERROR_NOT_IMPLEMENTED
;
1762 static nsresult NSAPI
nsURI_SetPassword(nsIURL
*iface
, const nsACString
*aPassword
)
1764 nsWineURI
*This
= NSURI_THIS(iface
);
1766 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPassword
));
1769 return nsIURI_SetPassword(This
->uri
, aPassword
);
1771 FIXME("default action not implemented\n");
1772 return NS_ERROR_NOT_IMPLEMENTED
;
1775 static nsresult NSAPI
nsURI_GetHostPort(nsIURL
*iface
, nsACString
*aHostPort
)
1777 nsWineURI
*This
= NSURI_THIS(iface
);
1779 TRACE("(%p)->(%p)\n", This
, aHostPort
);
1782 return nsIURI_GetHostPort(This
->uri
, aHostPort
);
1784 FIXME("default action not implemented\n");
1785 return NS_ERROR_NOT_IMPLEMENTED
;
1788 static nsresult NSAPI
nsURI_SetHostPort(nsIURL
*iface
, const nsACString
*aHostPort
)
1790 nsWineURI
*This
= NSURI_THIS(iface
);
1792 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aHostPort
));
1795 return nsIURI_SetHostPort(This
->uri
, aHostPort
);
1797 FIXME("default action not implemented\n");
1798 return NS_ERROR_NOT_IMPLEMENTED
;
1801 static nsresult NSAPI
nsURI_GetHost(nsIURL
*iface
, nsACString
*aHost
)
1803 nsWineURI
*This
= NSURI_THIS(iface
);
1805 TRACE("(%p)->(%p)\n", This
, aHost
);
1808 return nsIURI_GetHost(This
->uri
, aHost
);
1810 FIXME("default action not implemented\n");
1811 return NS_ERROR_NOT_IMPLEMENTED
;
1814 static nsresult NSAPI
nsURI_SetHost(nsIURL
*iface
, const nsACString
*aHost
)
1816 nsWineURI
*This
= NSURI_THIS(iface
);
1818 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aHost
));
1821 return nsIURI_SetHost(This
->uri
, aHost
);
1823 FIXME("default action not implemented\n");
1824 return NS_ERROR_NOT_IMPLEMENTED
;
1827 static nsresult NSAPI
nsURI_GetPort(nsIURL
*iface
, PRInt32
*aPort
)
1829 nsWineURI
*This
= NSURI_THIS(iface
);
1831 TRACE("(%p)->(%p)\n", This
, aPort
);
1834 return nsIURI_GetPort(This
->uri
, aPort
);
1836 FIXME("default action not implemented\n");
1837 return NS_ERROR_NOT_IMPLEMENTED
;
1840 static nsresult NSAPI
nsURI_SetPort(nsIURL
*iface
, PRInt32 aPort
)
1842 nsWineURI
*This
= NSURI_THIS(iface
);
1844 TRACE("(%p)->(%d)\n", This
, aPort
);
1847 return nsIURI_SetPort(This
->uri
, aPort
);
1849 FIXME("default action not implemented\n");
1850 return NS_ERROR_NOT_IMPLEMENTED
;
1853 static nsresult NSAPI
nsURI_GetPath(nsIURL
*iface
, nsACString
*aPath
)
1855 nsWineURI
*This
= NSURI_THIS(iface
);
1857 TRACE("(%p)->(%p)\n", This
, aPath
);
1860 return nsIURI_GetPath(This
->uri
, aPath
);
1862 FIXME("default action not implemented\n");
1863 return NS_ERROR_NOT_IMPLEMENTED
;
1866 static nsresult NSAPI
nsURI_SetPath(nsIURL
*iface
, const nsACString
*aPath
)
1868 nsWineURI
*This
= NSURI_THIS(iface
);
1871 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPath
));
1873 nsACString_GetData(aPath
, &path
);
1874 if(This
->wine_url
) {
1875 WCHAR new_url
[INTERNET_MAX_URL_LENGTH
];
1876 DWORD size
= sizeof(new_url
)/sizeof(WCHAR
);
1880 pathw
= heap_strdupAtoW(path
);
1881 hres
= UrlCombineW(This
->wine_url
, pathw
, new_url
, &size
, 0);
1884 set_wine_url(This
, new_url
);
1886 WARN("UrlCombine failed: %08x\n", hres
);
1892 return nsIURI_SetPath(This
->uri
, aPath
);
1895 static nsresult NSAPI
nsURI_Equals(nsIURL
*iface
, nsIURI
*other
, PRBool
*_retval
)
1897 nsWineURI
*This
= NSURI_THIS(iface
);
1898 nsWineURI
*wine_uri
;
1901 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
1904 return nsIURI_Equals(This
->uri
, other
, _retval
);
1906 nsres
= nsIURI_QueryInterface(other
, &IID_nsWineURI
, (void**)&wine_uri
);
1907 if(NS_FAILED(nsres
)) {
1908 TRACE("Could not get nsWineURI interface\n");
1913 *_retval
= wine_uri
->wine_url
&& !UrlCompareW(This
->wine_url
, wine_uri
->wine_url
, TRUE
);
1914 nsIURI_Release(NSURI(wine_uri
));
1919 static nsresult NSAPI
nsURI_SchemeIs(nsIURL
*iface
, const char *scheme
, PRBool
*_retval
)
1921 nsWineURI
*This
= NSURI_THIS(iface
);
1923 TRACE("(%p)->(%s %p)\n", This
, debugstr_a(scheme
), _retval
);
1925 if(This
->use_wine_url
) {
1926 WCHAR buf
[INTERNET_MAX_SCHEME_LENGTH
];
1927 int len
= MultiByteToWideChar(CP_ACP
, 0, scheme
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
))-1;
1929 *_retval
= lstrlenW(This
->wine_url
) > len
1930 && This
->wine_url
[len
] == ':'
1931 && !memcmp(buf
, This
->wine_url
, len
*sizeof(WCHAR
));
1936 return nsIURI_SchemeIs(This
->uri
, scheme
, _retval
);
1938 TRACE("returning error\n");
1939 return NS_ERROR_NOT_IMPLEMENTED
;
1942 static nsresult NSAPI
nsURI_Clone(nsIURL
*iface
, nsIURI
**_retval
)
1944 nsWineURI
*This
= NSURI_THIS(iface
);
1945 nsIURI
*nsuri
= NULL
;
1946 nsWineURI
*wine_uri
;
1949 TRACE("(%p)->(%p)\n", This
, _retval
);
1952 nsres
= nsIURI_Clone(This
->uri
, &nsuri
);
1953 if(NS_FAILED(nsres
)) {
1954 WARN("Clone failed: %08x\n", nsres
);
1959 nsres
= create_uri(nsuri
, This
->window_ref
? This
->window_ref
->window
: NULL
, This
->container
, &wine_uri
);
1960 if(NS_FAILED(nsres
)) {
1961 WARN("create_uri failed: %08x\n", nsres
);
1965 set_wine_url(wine_uri
, This
->wine_url
);
1967 *_retval
= NSURI(wine_uri
);
1971 static nsresult NSAPI
nsURI_Resolve(nsIURL
*iface
, const nsACString
*aRelativePath
,
1972 nsACString
*_retval
)
1974 nsWineURI
*This
= NSURI_THIS(iface
);
1975 WCHAR url
[INTERNET_MAX_URL_LENGTH
];
1982 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aRelativePath
), _retval
);
1985 return nsIURI_Resolve(This
->uri
, aRelativePath
, _retval
);
1987 nsACString_GetData(aRelativePath
, &patha
);
1988 path
= heap_strdupAtoW(patha
);
1990 return NS_ERROR_OUT_OF_MEMORY
;
1992 hres
= CoInternetCombineUrl(This
->wine_url
, path
,
1993 URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
1994 url
, sizeof(url
)/sizeof(WCHAR
), &len
, 0);
1997 ERR("CoIntenetCombineUrl failed: %08x\n", hres
);
1998 return NS_ERROR_FAILURE
;
2001 urla
= heap_strdupWtoA(url
);
2003 return NS_ERROR_OUT_OF_MEMORY
;
2005 TRACE("returning %s\n", debugstr_a(urla
));
2006 nsACString_SetData(_retval
, urla
);
2011 static nsresult NSAPI
nsURI_GetAsciiSpec(nsIURL
*iface
, nsACString
*aAsciiSpec
)
2013 nsWineURI
*This
= NSURI_THIS(iface
);
2015 TRACE("(%p)->(%p)\n", This
, aAsciiSpec
);
2017 if(This
->use_wine_url
)
2018 return nsIURI_GetSpec(NSURI(This
), aAsciiSpec
);
2021 return nsIURI_GetAsciiSpec(This
->uri
, aAsciiSpec
);
2023 TRACE("returning error\n");
2024 return NS_ERROR_NOT_IMPLEMENTED
;
2027 static nsresult NSAPI
nsURI_GetAsciiHost(nsIURL
*iface
, nsACString
*aAsciiHost
)
2029 nsWineURI
*This
= NSURI_THIS(iface
);
2031 TRACE("(%p)->(%p)\n", This
, aAsciiHost
);
2034 return nsIURI_GetAsciiHost(This
->uri
, aAsciiHost
);
2036 FIXME("default action not implemented\n");
2037 return NS_ERROR_NOT_IMPLEMENTED
;
2040 static nsresult NSAPI
nsURI_GetOriginCharset(nsIURL
*iface
, nsACString
*aOriginCharset
)
2042 nsWineURI
*This
= NSURI_THIS(iface
);
2044 TRACE("(%p)->(%p)\n", This
, aOriginCharset
);
2047 return nsIURI_GetOriginCharset(This
->uri
, aOriginCharset
);
2049 FIXME("default action not implemented\n");
2050 return NS_ERROR_NOT_IMPLEMENTED
;
2053 static nsresult NSAPI
nsURL_GetFilePath(nsIURL
*iface
, nsACString
*aFilePath
)
2055 nsWineURI
*This
= NSURI_THIS(iface
);
2057 TRACE("(%p)->(%p)\n", This
, aFilePath
);
2060 return nsIURL_GetFilePath(This
->nsurl
, aFilePath
);
2062 FIXME("default action not implemented\n");
2063 return NS_ERROR_NOT_IMPLEMENTED
;
2066 static nsresult NSAPI
nsURL_SetFilePath(nsIURL
*iface
, const nsACString
*aFilePath
)
2068 nsWineURI
*This
= NSURI_THIS(iface
);
2070 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFilePath
));
2073 return nsIURL_SetFilePath(This
->nsurl
, aFilePath
);
2075 FIXME("default action not implemented\n");
2076 return NS_ERROR_NOT_IMPLEMENTED
;
2079 static nsresult NSAPI
nsURL_GetParam(nsIURL
*iface
, nsACString
*aParam
)
2081 nsWineURI
*This
= NSURI_THIS(iface
);
2083 TRACE("(%p)->(%p)\n", This
, aParam
);
2086 return nsIURL_GetParam(This
->nsurl
, aParam
);
2088 FIXME("default action not implemented\n");
2089 return NS_ERROR_NOT_IMPLEMENTED
;
2092 static nsresult NSAPI
nsURL_SetParam(nsIURL
*iface
, const nsACString
*aParam
)
2094 nsWineURI
*This
= NSURI_THIS(iface
);
2096 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aParam
));
2099 return nsIURL_SetParam(This
->nsurl
, aParam
);
2101 FIXME("default action not implemented\n");
2102 return NS_ERROR_NOT_IMPLEMENTED
;
2105 static nsresult NSAPI
nsURL_GetQuery(nsIURL
*iface
, nsACString
*aQuery
)
2107 nsWineURI
*This
= NSURI_THIS(iface
);
2108 URL_COMPONENTSW url
= {sizeof(URL_COMPONENTSW
)};
2109 WCHAR
*ptr_end
, *ptr
;
2113 TRACE("(%p)->(%p)\n", This
, aQuery
);
2116 return nsIURL_GetQuery(This
->nsurl
, aQuery
);
2118 url
.dwExtraInfoLength
= 1;
2119 if(!InternetCrackUrlW(This
->wine_url
, 0, 0, &url
)) {
2120 WARN("InternetCrackUrlW failed: 0x%08x\n", GetLastError());
2121 nsACString_SetData(aQuery
, "");
2125 ptr_end
= url
.lpszExtraInfo
+url
.dwExtraInfoLength
;
2126 for(ptr
= url
.lpszExtraInfo
; ptr
< ptr_end
; ptr
++) {
2133 ptr
= url
.lpszExtraInfo
;
2134 len
= WideCharToMultiByte(CP_ACP
, 0, ptr
, ptr_end
-ptr
, NULL
, 0, NULL
, NULL
);
2135 query
= heap_alloc(len
+1);
2137 return NS_ERROR_OUT_OF_MEMORY
;
2138 WideCharToMultiByte(CP_ACP
, 0, ptr
, ptr_end
-ptr
, query
, len
, NULL
, NULL
);
2140 nsACString_SetData(aQuery
, query
);
2142 TRACE("ret %s\n", debugstr_a(query
));
2147 static nsresult NSAPI
nsURL_SetQuery(nsIURL
*iface
, const nsACString
*aQuery
)
2149 nsWineURI
*This
= NSURI_THIS(iface
);
2150 const WCHAR
*ptr1
, *ptr2
;
2152 WCHAR
*new_url
, *ptr
;
2155 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aQuery
));
2158 nsIURL_SetQuery(This
->nsurl
, aQuery
);
2163 nsACString_GetData(aQuery
, &query
);
2164 size
= len
= MultiByteToWideChar(CP_ACP
, 0, query
, -1, NULL
, 0);
2165 ptr1
= strchrW(This
->wine_url
, '?');
2167 size
+= ptr1
-This
->wine_url
;
2168 ptr2
= strchrW(ptr1
, '#');
2170 size
+= strlenW(ptr2
);
2172 ptr1
= This
->wine_url
+ strlenW(This
->wine_url
);
2174 size
+= strlenW(This
->wine_url
);
2180 new_url
= heap_alloc(size
*sizeof(WCHAR
));
2181 memcpy(new_url
, This
->wine_url
, (ptr1
-This
->wine_url
)*sizeof(WCHAR
));
2182 ptr
= new_url
+ (ptr1
-This
->wine_url
);
2185 MultiByteToWideChar(CP_ACP
, 0, query
, -1, ptr
, len
);
2193 TRACE("setting %s\n", debugstr_w(new_url
));
2195 heap_free(This
->wine_url
);
2196 This
->wine_url
= new_url
;
2200 static nsresult NSAPI
nsURL_GetRef(nsIURL
*iface
, nsACString
*aRef
)
2202 nsWineURI
*This
= NSURI_THIS(iface
);
2204 TRACE("(%p)->(%p)\n", This
, aRef
);
2207 return nsIURL_GetRef(This
->nsurl
, aRef
);
2209 FIXME("default action not implemented\n");
2210 return NS_ERROR_NOT_IMPLEMENTED
;
2213 static nsresult NSAPI
nsURL_SetRef(nsIURL
*iface
, const nsACString
*aRef
)
2215 nsWineURI
*This
= NSURI_THIS(iface
);
2218 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRef
));
2221 return nsIURL_SetRef(This
->nsurl
, aRef
);
2223 nsACString_GetData(aRef
, &refa
);
2227 FIXME("default action not implemented\n");
2228 return NS_ERROR_NOT_IMPLEMENTED
;
2231 static nsresult NSAPI
nsURL_GetDirectory(nsIURL
*iface
, nsACString
*aDirectory
)
2233 nsWineURI
*This
= NSURI_THIS(iface
);
2235 TRACE("(%p)->(%p)\n", This
, aDirectory
);
2238 return nsIURL_GetDirectory(This
->nsurl
, aDirectory
);
2240 FIXME("default action not implemented\n");
2241 return NS_ERROR_NOT_IMPLEMENTED
;
2244 static nsresult NSAPI
nsURL_SetDirectory(nsIURL
*iface
, const nsACString
*aDirectory
)
2246 nsWineURI
*This
= NSURI_THIS(iface
);
2248 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aDirectory
));
2251 return nsIURL_SetDirectory(This
->nsurl
, aDirectory
);
2253 FIXME("default action not implemented\n");
2254 return NS_ERROR_NOT_IMPLEMENTED
;
2257 static nsresult NSAPI
nsURL_GetFileName(nsIURL
*iface
, nsACString
*aFileName
)
2259 nsWineURI
*This
= NSURI_THIS(iface
);
2261 TRACE("(%p)->(%p)\n", This
, aFileName
);
2264 return nsIURL_GetFileName(This
->nsurl
, aFileName
);
2266 FIXME("default action not implemented\n");
2267 return NS_ERROR_NOT_IMPLEMENTED
;
2270 static nsresult NSAPI
nsURL_SetFileName(nsIURL
*iface
, const nsACString
*aFileName
)
2272 nsWineURI
*This
= NSURI_THIS(iface
);
2274 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileName
));
2277 return nsIURL_SetFileName(This
->nsurl
, aFileName
);
2279 FIXME("default action not implemented\n");
2280 return NS_ERROR_NOT_IMPLEMENTED
;
2283 static nsresult NSAPI
nsURL_GetFileBaseName(nsIURL
*iface
, nsACString
*aFileBaseName
)
2285 nsWineURI
*This
= NSURI_THIS(iface
);
2287 TRACE("(%p)->(%p)\n", This
, aFileBaseName
);
2290 return nsIURL_GetFileBaseName(This
->nsurl
, aFileBaseName
);
2292 FIXME("default action not implemented\n");
2293 return NS_ERROR_NOT_IMPLEMENTED
;
2296 static nsresult NSAPI
nsURL_SetFileBaseName(nsIURL
*iface
, const nsACString
*aFileBaseName
)
2298 nsWineURI
*This
= NSURI_THIS(iface
);
2300 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileBaseName
));
2303 return nsIURL_SetFileBaseName(This
->nsurl
, aFileBaseName
);
2305 FIXME("default action not implemented\n");
2306 return NS_ERROR_NOT_IMPLEMENTED
;
2309 static nsresult NSAPI
nsURL_GetFileExtension(nsIURL
*iface
, nsACString
*aFileExtension
)
2311 nsWineURI
*This
= NSURI_THIS(iface
);
2313 TRACE("(%p)->(%p)\n", This
, aFileExtension
);
2316 return nsIURL_GetFileExtension(This
->nsurl
, aFileExtension
);
2318 FIXME("default action not implemented\n");
2319 return NS_ERROR_NOT_IMPLEMENTED
;
2322 static nsresult NSAPI
nsURL_SetFileExtension(nsIURL
*iface
, const nsACString
*aFileExtension
)
2324 nsWineURI
*This
= NSURI_THIS(iface
);
2326 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileExtension
));
2329 return nsIURL_SetFileExtension(This
->nsurl
, aFileExtension
);
2331 FIXME("default action not implemented\n");
2332 return NS_ERROR_NOT_IMPLEMENTED
;
2335 static nsresult NSAPI
nsURL_GetCommonBaseSpec(nsIURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2337 nsWineURI
*This
= NSURI_THIS(iface
);
2339 TRACE("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2342 return nsIURL_GetCommonBaseSpec(This
->nsurl
, aURIToCompare
, _retval
);
2344 FIXME("default action not implemented\n");
2345 return NS_ERROR_NOT_IMPLEMENTED
;
2348 static nsresult NSAPI
nsURL_GetRelativeSpec(nsIURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2350 nsWineURI
*This
= NSURI_THIS(iface
);
2352 TRACE("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2355 return nsIURL_GetRelativeSpec(This
->nsurl
, aURIToCompare
, _retval
);
2357 FIXME("default action not implemented\n");
2358 return NS_ERROR_NOT_IMPLEMENTED
;
2363 static const nsIURLVtbl nsURLVtbl
= {
2364 nsURI_QueryInterface
,
2392 nsURI_GetOriginCharset
,
2405 nsURL_GetFileBaseName
,
2406 nsURL_SetFileBaseName
,
2407 nsURL_GetFileExtension
,
2408 nsURL_SetFileExtension
,
2409 nsURL_GetCommonBaseSpec
,
2410 nsURL_GetRelativeSpec
2413 static nsresult
create_uri(nsIURI
*uri
, HTMLWindow
*window
, NSContainer
*container
, nsWineURI
**_retval
)
2415 nsWineURI
*ret
= heap_alloc_zero(sizeof(nsWineURI
));
2417 ret
->lpIURLVtbl
= &nsURLVtbl
;
2421 set_uri_nscontainer(ret
, container
);
2422 set_uri_window(ret
, window
);
2425 nsIURI_QueryInterface(uri
, &IID_nsIURL
, (void**)&ret
->nsurl
);
2427 TRACE("retval=%p\n", ret
);
2432 HRESULT
create_doc_uri(HTMLWindow
*window
, WCHAR
*url
, nsWineURI
**ret
)
2437 nsres
= create_uri(NULL
, window
, window
->doc_obj
->nscontainer
, &uri
);
2438 if(NS_FAILED(nsres
))
2441 set_wine_url(uri
, url
);
2442 uri
->is_doc_uri
= TRUE
;
2449 const nsIProtocolHandlerVtbl
*lpProtocolHandlerVtbl
;
2453 nsIProtocolHandler
*nshandler
;
2454 } nsProtocolHandler
;
2456 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
2458 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
2460 static nsresult NSAPI
nsProtocolHandler_QueryInterface(nsIProtocolHandler
*iface
, nsIIDRef riid
,
2463 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2467 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
2468 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
2469 *result
= NSPROTHANDLER(This
);
2470 }else if(IsEqualGUID(&IID_nsIProtocolHandler
, riid
)) {
2471 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This
, result
);
2472 *result
= NSPROTHANDLER(This
);
2473 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler
, riid
)) {
2474 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This
, result
);
2475 return NS_NOINTERFACE
;
2479 nsISupports_AddRef((nsISupports
*)*result
);
2483 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
2484 return NS_NOINTERFACE
;
2487 static nsrefcnt NSAPI
nsProtocolHandler_AddRef(nsIProtocolHandler
*iface
)
2489 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2490 LONG ref
= InterlockedIncrement(&This
->ref
);
2492 TRACE("(%p) ref=%d\n", This
, ref
);
2497 static nsrefcnt NSAPI
nsProtocolHandler_Release(nsIProtocolHandler
*iface
)
2499 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2500 LONG ref
= InterlockedDecrement(&This
->ref
);
2502 TRACE("(%p) ref=%d\n", This
, ref
);
2506 nsIProtocolHandler_Release(This
->nshandler
);
2513 static nsresult NSAPI
nsProtocolHandler_GetScheme(nsIProtocolHandler
*iface
, nsACString
*aScheme
)
2515 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2517 TRACE("(%p)->(%p)\n", This
, aScheme
);
2520 return nsIProtocolHandler_GetScheme(This
->nshandler
, aScheme
);
2521 return NS_ERROR_NOT_IMPLEMENTED
;
2524 static nsresult NSAPI
nsProtocolHandler_GetDefaultPort(nsIProtocolHandler
*iface
,
2525 PRInt32
*aDefaultPort
)
2527 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2529 TRACE("(%p)->(%p)\n", This
, aDefaultPort
);
2532 return nsIProtocolHandler_GetDefaultPort(This
->nshandler
, aDefaultPort
);
2533 return NS_ERROR_NOT_IMPLEMENTED
;
2536 static nsresult NSAPI
nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler
*iface
,
2537 PRUint32
*aProtocolFlags
)
2539 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2541 TRACE("(%p)->(%p)\n", This
, aProtocolFlags
);
2544 return nsIProtocolHandler_GetProtocolFlags(This
->nshandler
, aProtocolFlags
);
2545 return NS_ERROR_NOT_IMPLEMENTED
;
2548 static nsresult NSAPI
nsProtocolHandler_NewURI(nsIProtocolHandler
*iface
,
2549 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
2551 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2553 TRACE("((%p)->%s %s %p %p)\n", This
, debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
2557 return nsIProtocolHandler_NewURI(This
->nshandler
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2558 return NS_ERROR_NOT_IMPLEMENTED
;
2561 static nsresult NSAPI
nsProtocolHandler_NewChannel(nsIProtocolHandler
*iface
,
2562 nsIURI
*aURI
, nsIChannel
**_retval
)
2564 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2566 TRACE("(%p)->(%p %p)\n", This
, aURI
, _retval
);
2569 return nsIProtocolHandler_NewChannel(This
->nshandler
, aURI
, _retval
);
2570 return NS_ERROR_NOT_IMPLEMENTED
;
2573 static nsresult NSAPI
nsProtocolHandler_AllowPort(nsIProtocolHandler
*iface
,
2574 PRInt32 port
, const char *scheme
, PRBool
*_retval
)
2576 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2578 TRACE("(%p)->(%d %s %p)\n", This
, port
, debugstr_a(scheme
), _retval
);
2581 return nsIProtocolHandler_AllowPort(This
->nshandler
, port
, scheme
, _retval
);
2582 return NS_ERROR_NOT_IMPLEMENTED
;
2585 #undef NSPROTHANDLER_THIS
2587 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl
= {
2588 nsProtocolHandler_QueryInterface
,
2589 nsProtocolHandler_AddRef
,
2590 nsProtocolHandler_Release
,
2591 nsProtocolHandler_GetScheme
,
2592 nsProtocolHandler_GetDefaultPort
,
2593 nsProtocolHandler_GetProtocolFlags
,
2594 nsProtocolHandler_NewURI
,
2595 nsProtocolHandler_NewChannel
,
2596 nsProtocolHandler_AllowPort
2599 static nsIProtocolHandler
*create_protocol_handler(nsIProtocolHandler
*nshandler
)
2601 nsProtocolHandler
*ret
= heap_alloc(sizeof(nsProtocolHandler
));
2603 ret
->lpProtocolHandlerVtbl
= &nsProtocolHandlerVtbl
;
2605 ret
->nshandler
= nshandler
;
2607 return NSPROTHANDLER(ret
);
2610 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*,nsIIDRef
,void**);
2612 static nsrefcnt NSAPI
nsIOService_AddRef(nsIIOService
*iface
)
2617 static nsrefcnt NSAPI
nsIOService_Release(nsIIOService
*iface
)
2622 static nsresult NSAPI
nsIOService_GetProtocolHandler(nsIIOService
*iface
, const char *aScheme
,
2623 nsIProtocolHandler
**_retval
)
2625 nsIExternalProtocolHandler
*nsexthandler
;
2626 nsIProtocolHandler
*nshandler
;
2629 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
2631 nsres
= nsIIOService_GetProtocolHandler(nsio
, aScheme
, &nshandler
);
2632 if(NS_FAILED(nsres
)) {
2633 WARN("GetProtocolHandler failed: %08x\n", nsres
);
2637 nsres
= nsIProtocolHandler_QueryInterface(nshandler
, &IID_nsIExternalProtocolHandler
,
2638 (void**)&nsexthandler
);
2639 if(NS_FAILED(nsres
)) {
2640 *_retval
= nshandler
;
2644 nsIExternalProtocolHandler_Release(nsexthandler
);
2645 *_retval
= create_protocol_handler(nshandler
);
2646 TRACE("return %p\n", *_retval
);
2650 static nsresult NSAPI
nsIOService_GetProtocolFlags(nsIIOService
*iface
, const char *aScheme
,
2653 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
2654 return nsIIOService_GetProtocolFlags(nsio
, aScheme
, _retval
);
2657 static BOOL
is_gecko_special_uri(const char *spec
)
2659 static const char *special_schemes
[] = {"chrome:", "jar:", "resource:", "javascript:", "wyciwyg:"};
2662 for(i
=0; i
< sizeof(special_schemes
)/sizeof(*special_schemes
); i
++) {
2663 if(!strncasecmp(spec
, special_schemes
[i
], strlen(special_schemes
[i
])))
2667 if(!strncasecmp(spec
, "file:", 5)) {
2668 const char *ptr
= spec
+5;
2671 return is_gecko_path(ptr
);
2677 static nsresult NSAPI
nsIOService_NewURI(nsIIOService
*iface
, const nsACString
*aSpec
,
2678 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
2680 nsWineURI
*wine_uri
, *base_wine_uri
= NULL
;
2681 const char *spec
= NULL
;
2682 HTMLWindow
*window
= NULL
;
2684 LPCWSTR base_wine_url
= NULL
;
2685 nsACString spec_str
;
2689 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
2692 nsACString_GetData(aSpec
, &spec
);
2693 if(is_gecko_special_uri(spec
))
2694 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2696 if(!strncmp(spec
, "wine:", 5))
2700 PARSEDURLA parsed_url
= {sizeof(PARSEDURLA
)};
2702 nsres
= nsIURI_QueryInterface(aBaseURI
, &IID_nsWineURI
, (void**)&base_wine_uri
);
2703 if(NS_SUCCEEDED(nsres
)) {
2704 base_wine_url
= base_wine_uri
->wine_url
;
2705 if(base_wine_uri
->window_ref
&& base_wine_uri
->window_ref
->window
) {
2706 window
= base_wine_uri
->window_ref
->window
;
2707 IHTMLWindow2_AddRef(HTMLWINDOW2(window
));
2709 TRACE("base url: %s window: %p\n", debugstr_w(base_wine_url
), window
);
2710 }else if(FAILED(ParseURLA(spec
, &parsed_url
))) {
2711 TRACE("not wraping\n");
2712 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2714 WARN("Could not get base nsWineURI: %08x\n", nsres
);
2718 nsACString_InitDepend(&spec_str
, spec
);
2719 nsres
= nsIIOService_NewURI(nsio
, &spec_str
, aOriginCharset
, aBaseURI
, &uri
);
2720 nsACString_Finish(&spec_str
);
2721 if(NS_FAILED(nsres
))
2722 TRACE("NewURI failed: %08x\n", nsres
);
2724 nsres
= create_uri(uri
, window
, NULL
, &wine_uri
);
2725 *_retval
= (nsIURI
*)wine_uri
;
2728 IHTMLWindow2_Release(HTMLWINDOW2(window
));
2731 WCHAR url
[INTERNET_MAX_URL_LENGTH
], rel_url
[INTERNET_MAX_URL_LENGTH
];
2735 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, rel_url
, sizeof(rel_url
)/sizeof(WCHAR
));
2737 hres
= CoInternetCombineUrl(base_wine_url
, rel_url
,
2738 URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
2739 url
, sizeof(url
)/sizeof(WCHAR
), &len
, 0);
2741 set_wine_url(wine_uri
, url
);
2743 WARN("CoCombineUrl failed: %08x\n", hres
);
2745 WCHAR url
[INTERNET_MAX_URL_LENGTH
];
2747 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, url
, sizeof(url
)/sizeof(WCHAR
));
2748 set_wine_url(wine_uri
, url
);
2752 nsIURI_Release(NSURI(base_wine_uri
));
2757 static nsresult NSAPI
nsIOService_NewFileURI(nsIIOService
*iface
, nsIFile
*aFile
,
2760 TRACE("(%p %p)\n", aFile
, _retval
);
2761 return nsIIOService_NewFileURI(nsio
, aFile
, _retval
);
2764 static nsresult NSAPI
nsIOService_NewChannelFromURI(nsIIOService
*iface
, nsIURI
*aURI
,
2765 nsIChannel
**_retval
)
2767 PARSEDURLW parsed_url
= {sizeof(PARSEDURLW
)};
2769 nsWineURI
*wine_uri
;
2772 TRACE("(%p %p)\n", aURI
, _retval
);
2774 nsres
= nsIURI_QueryInterface(aURI
, &IID_nsWineURI
, (void**)&wine_uri
);
2775 if(NS_FAILED(nsres
)) {
2776 TRACE("Could not get nsWineURI: %08x\n", nsres
);
2777 return nsIIOService_NewChannelFromURI(nsio
, aURI
, _retval
);
2780 ret
= heap_alloc_zero(sizeof(nsChannel
));
2782 ret
->lpHttpChannelVtbl
= &nsChannelVtbl
;
2783 ret
->lpUploadChannelVtbl
= &nsUploadChannelVtbl
;
2784 ret
->lpIHttpChannelInternalVtbl
= &nsHttpChannelInternalVtbl
;
2786 ret
->uri
= wine_uri
;
2787 ret
->request_method
= METHOD_GET
;
2788 list_init(&ret
->response_headers
);
2789 list_init(&ret
->request_headers
);
2791 nsIURI_AddRef(aURI
);
2792 ret
->original_uri
= aURI
;
2793 ret
->url_scheme
= wine_uri
->wine_url
&& SUCCEEDED(ParseURLW(wine_uri
->wine_url
, &parsed_url
))
2794 ? parsed_url
.nScheme
: URL_SCHEME_UNKNOWN
;
2796 *_retval
= NSCHANNEL(ret
);
2800 static nsresult NSAPI
nsIOService_NewChannel(nsIIOService
*iface
, const nsACString
*aSpec
,
2801 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIChannel
**_retval
)
2803 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
), aBaseURI
, _retval
);
2804 return nsIIOService_NewChannel(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2807 static nsresult NSAPI
nsIOService_GetOffline(nsIIOService
*iface
, PRBool
*aOffline
)
2809 TRACE("(%p)\n", aOffline
);
2810 return nsIIOService_GetOffline(nsio
, aOffline
);
2813 static nsresult NSAPI
nsIOService_SetOffline(nsIIOService
*iface
, PRBool aOffline
)
2815 TRACE("(%x)\n", aOffline
);
2816 return nsIIOService_SetOffline(nsio
, aOffline
);
2819 static nsresult NSAPI
nsIOService_AllowPort(nsIIOService
*iface
, PRInt32 aPort
,
2820 const char *aScheme
, PRBool
*_retval
)
2822 TRACE("(%d %s %p)\n", aPort
, debugstr_a(aScheme
), _retval
);
2823 return nsIIOService_AllowPort(nsio
, aPort
, debugstr_a(aScheme
), _retval
);
2826 static nsresult NSAPI
nsIOService_ExtractScheme(nsIIOService
*iface
, const nsACString
*urlString
,
2827 nsACString
* _retval
)
2829 TRACE("(%s %p)\n", debugstr_nsacstr(urlString
), _retval
);
2830 return nsIIOService_ExtractScheme(nsio
, urlString
, _retval
);
2833 static const nsIIOServiceVtbl nsIOServiceVtbl
= {
2834 nsIOService_QueryInterface
,
2836 nsIOService_Release
,
2837 nsIOService_GetProtocolHandler
,
2838 nsIOService_GetProtocolFlags
,
2840 nsIOService_NewFileURI
,
2841 nsIOService_NewChannelFromURI
,
2842 nsIOService_NewChannel
,
2843 nsIOService_GetOffline
,
2844 nsIOService_SetOffline
,
2845 nsIOService_AllowPort
,
2846 nsIOService_ExtractScheme
2849 static nsIIOService nsIOService
= { &nsIOServiceVtbl
};
2851 static nsresult NSAPI
nsNetUtil_QueryInterface(nsINetUtil
*iface
, nsIIDRef riid
,
2854 return nsIIOService_QueryInterface(&nsIOService
, riid
, result
);
2857 static nsrefcnt NSAPI
nsNetUtil_AddRef(nsINetUtil
*iface
)
2862 static nsrefcnt NSAPI
nsNetUtil_Release(nsINetUtil
*iface
)
2867 static nsresult NSAPI
nsNetUtil_ParseContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
2868 nsACString
*aCharset
, PRBool
*aHadCharset
, nsACString
*aContentType
)
2870 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aHadCharset
, aContentType
);
2872 return nsINetUtil_ParseContentType(net_util
, aTypeHeader
, aCharset
, aHadCharset
, aContentType
);
2875 static nsresult NSAPI
nsNetUtil_ProtocolHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, PRUint32 aFlags
, PRBool
*_retval
)
2879 return nsINetUtil_ProtocolHasFlags(net_util
, aURI
, aFlags
, _retval
);
2882 static nsresult NSAPI
nsNetUtil_URIChainHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, PRUint32 aFlags
, PRBool
*_retval
)
2884 TRACE("(%p %08x %p)\n", aURI
, aFlags
, _retval
);
2886 if(aFlags
== (1<<11)) {
2891 return nsINetUtil_URIChainHasFlags(net_util
, aURI
, aFlags
, _retval
);
2894 static nsresult NSAPI
nsNetUtil_ToImmutableURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
2896 TRACE("(%p %p)\n", aURI
, _retval
);
2898 return nsINetUtil_ToImmutableURI(net_util
, aURI
, _retval
);
2901 static nsresult NSAPI
nsNetUtil_NewSimpleNestedURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
2903 TRACE("(%p %p)\n", aURI
, _retval
);
2905 return nsINetUtil_NewSimpleNestedURI(net_util
, aURI
, _retval
);
2908 static nsresult NSAPI
nsNetUtil_EscapeString(nsINetUtil
*iface
, const nsACString
*aString
,
2909 PRUint32 aEscapeType
, nsACString
*_retval
)
2911 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString
), aEscapeType
, _retval
);
2913 return nsINetUtil_EscapeString(net_util
, aString
, aEscapeType
, _retval
);
2916 static nsresult NSAPI
nsNetUtil_EscapeURL(nsINetUtil
*iface
, const nsACString
*aStr
, PRUint32 aFlags
,
2917 nsACString
*_retval
)
2919 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
2921 return nsINetUtil_EscapeURL(net_util
, aStr
, aFlags
, _retval
);
2924 static nsresult NSAPI
nsNetUtil_UnescapeString(nsINetUtil
*iface
, const nsACString
*aStr
,
2925 PRUint32 aFlags
, nsACString
*_retval
)
2927 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
2929 return nsINetUtil_UnescapeString(net_util
, aStr
, aFlags
, _retval
);
2932 static nsresult NSAPI
nsNetUtil_ExtractCharsetFromContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
2933 nsACString
*aCharset
, PRInt32
*aCharsetStart
, PRInt32
*aCharsetEnd
, PRBool
*_retval
)
2935 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aCharsetStart
,
2936 aCharsetEnd
, _retval
);
2938 return nsINetUtil_ExtractCharsetFromContentType(net_util
, aTypeHeader
, aCharset
, aCharsetStart
, aCharsetEnd
, _retval
);
2941 static const nsINetUtilVtbl nsNetUtilVtbl
= {
2942 nsNetUtil_QueryInterface
,
2945 nsNetUtil_ParseContentType
,
2946 nsNetUtil_ProtocolHasFlags
,
2947 nsNetUtil_URIChainHasFlags
,
2948 nsNetUtil_ToImmutableURI
,
2949 nsNetUtil_NewSimpleNestedURI
,
2950 nsNetUtil_EscapeString
,
2951 nsNetUtil_EscapeURL
,
2952 nsNetUtil_UnescapeString
,
2953 nsNetUtil_ExtractCharsetFromContentType
2956 static nsINetUtil nsNetUtil
= { &nsNetUtilVtbl
};
2958 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*iface
, nsIIDRef riid
,
2963 if(IsEqualGUID(&IID_nsISupports
, riid
))
2964 *result
= &nsIOService
;
2965 else if(IsEqualGUID(&IID_nsIIOService
, riid
))
2966 *result
= &nsIOService
;
2967 else if(IsEqualGUID(&IID_nsINetUtil
, riid
))
2968 *result
= &nsNetUtil
;
2971 nsISupports_AddRef((nsISupports
*)*result
);
2975 FIXME("(%s %p)\n", debugstr_guid(riid
), result
);
2976 return NS_NOINTERFACE
;
2979 static nsresult NSAPI
nsIOServiceFactory_QueryInterface(nsIFactory
*iface
, nsIIDRef riid
,
2984 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
2985 TRACE("(IID_nsISupports %p)\n", result
);
2987 }else if(IsEqualGUID(&IID_nsIFactory
, riid
)) {
2988 TRACE("(IID_nsIFactory %p)\n", result
);
2993 nsIFactory_AddRef(iface
);
2997 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
2998 return NS_NOINTERFACE
;
3001 static nsrefcnt NSAPI
nsIOServiceFactory_AddRef(nsIFactory
*iface
)
3006 static nsrefcnt NSAPI
nsIOServiceFactory_Release(nsIFactory
*iface
)
3011 static nsresult NSAPI
nsIOServiceFactory_CreateInstance(nsIFactory
*iface
,
3012 nsISupports
*aOuter
, const nsIID
*iid
, void **result
)
3014 return nsIIOService_QueryInterface(&nsIOService
, iid
, result
);
3017 static nsresult NSAPI
nsIOServiceFactory_LockFactory(nsIFactory
*iface
, PRBool lock
)
3019 WARN("(%x)\n", lock
);
3023 static const nsIFactoryVtbl nsIOServiceFactoryVtbl
= {
3024 nsIOServiceFactory_QueryInterface
,
3025 nsIOServiceFactory_AddRef
,
3026 nsIOServiceFactory_Release
,
3027 nsIOServiceFactory_CreateInstance
,
3028 nsIOServiceFactory_LockFactory
3031 static nsIFactory nsIOServiceFactory
= { &nsIOServiceFactoryVtbl
};
3033 void init_nsio(nsIComponentManager
*component_manager
, nsIComponentRegistrar
*registrar
)
3035 nsIFactory
*old_factory
= NULL
;
3038 nsres
= nsIComponentManager_GetClassObject(component_manager
, &NS_IOSERVICE_CID
,
3039 &IID_nsIFactory
, (void**)&old_factory
);
3040 if(NS_FAILED(nsres
)) {
3041 ERR("Could not get factory: %08x\n", nsres
);
3045 nsres
= nsIFactory_CreateInstance(old_factory
, NULL
, &IID_nsIIOService
, (void**)&nsio
);
3046 if(NS_FAILED(nsres
)) {
3047 ERR("Couldn not create nsIOService instance %08x\n", nsres
);
3048 nsIFactory_Release(old_factory
);
3052 nsres
= nsIIOService_QueryInterface(nsio
, &IID_nsINetUtil
, (void**)&net_util
);
3053 if(NS_FAILED(nsres
)) {
3054 WARN("Could not get nsINetUtil interface: %08x\n", nsres
);
3055 nsIIOService_Release(nsio
);
3059 nsres
= nsIComponentRegistrar_UnregisterFactory(registrar
, &NS_IOSERVICE_CID
, old_factory
);
3060 nsIFactory_Release(old_factory
);
3061 if(NS_FAILED(nsres
))
3062 ERR("UnregisterFactory failed: %08x\n", nsres
);
3064 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_IOSERVICE_CID
,
3065 NS_IOSERVICE_CLASSNAME
, NS_IOSERVICE_CONTRACTID
, &nsIOServiceFactory
);
3066 if(NS_FAILED(nsres
))
3067 ERR("RegisterFactory failed: %08x\n", nsres
);
3070 void release_nsio(void)
3073 nsINetUtil_Release(net_util
);
3078 nsIIOService_Release(nsio
);