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 static void free_http_headers(struct list
*list
)
355 http_header_t
*iter
, *iter_next
;
357 LIST_FOR_EACH_ENTRY_SAFE(iter
, iter_next
, list
, http_header_t
, entry
) {
358 list_remove(&iter
->entry
);
359 heap_free(iter
->header
);
360 heap_free(iter
->data
);
365 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
367 static nsresult NSAPI
nsChannel_QueryInterface(nsIHttpChannel
*iface
, nsIIDRef riid
, void **result
)
369 nsChannel
*This
= NSCHANNEL_THIS(iface
);
371 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
372 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
373 *result
= NSCHANNEL(This
);
374 }else if(IsEqualGUID(&IID_nsIRequest
, riid
)) {
375 TRACE("(%p)->(IID_nsIRequest %p)\n", This
, result
);
376 *result
= NSCHANNEL(This
);
377 }else if(IsEqualGUID(&IID_nsIChannel
, riid
)) {
378 TRACE("(%p)->(IID_nsIChannel %p)\n", This
, result
);
379 *result
= NSCHANNEL(This
);
380 }else if(IsEqualGUID(&IID_nsIHttpChannel
, riid
)) {
381 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This
, result
);
382 *result
= is_http_channel(This
) ? NSHTTPCHANNEL(This
) : NULL
;
383 }else if(IsEqualGUID(&IID_nsIUploadChannel
, riid
)) {
384 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This
, result
);
385 *result
= NSUPCHANNEL(This
);
386 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal
, riid
)) {
387 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This
, result
);
388 *result
= is_http_channel(This
) ? NSHTTPINTERNAL(This
) : NULL
;
390 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
395 nsIChannel_AddRef(NSCHANNEL(This
));
399 return NS_NOINTERFACE
;
402 static nsrefcnt NSAPI
nsChannel_AddRef(nsIHttpChannel
*iface
)
404 nsChannel
*This
= NSCHANNEL_THIS(iface
);
405 nsrefcnt ref
= InterlockedIncrement(&This
->ref
);
407 TRACE("(%p) ref=%d\n", This
, ref
);
412 static nsrefcnt NSAPI
nsChannel_Release(nsIHttpChannel
*iface
)
414 nsChannel
*This
= NSCHANNEL_THIS(iface
);
415 LONG ref
= InterlockedDecrement(&This
->ref
);
418 nsIURI_Release(NSURI(This
->uri
));
420 nsISupports_Release(This
->owner
);
421 if(This
->post_data_stream
)
422 nsIInputStream_Release(This
->post_data_stream
);
424 nsILoadGroup_Release(This
->load_group
);
425 if(This
->notif_callback
)
426 nsIInterfaceRequestor_Release(This
->notif_callback
);
427 if(This
->original_uri
)
428 nsIURI_Release(This
->original_uri
);
430 free_http_headers(&This
->response_headers
);
432 heap_free(This
->content_type
);
433 heap_free(This
->charset
);
440 static nsresult NSAPI
nsChannel_GetName(nsIHttpChannel
*iface
, nsACString
*aName
)
442 nsChannel
*This
= NSCHANNEL_THIS(iface
);
444 FIXME("(%p)->(%p)\n", This
, aName
);
446 return NS_ERROR_NOT_IMPLEMENTED
;
449 static nsresult NSAPI
nsChannel_IsPending(nsIHttpChannel
*iface
, PRBool
*_retval
)
451 nsChannel
*This
= NSCHANNEL_THIS(iface
);
453 FIXME("(%p)->(%p)\n", This
, _retval
);
455 return NS_ERROR_NOT_IMPLEMENTED
;
458 static nsresult NSAPI
nsChannel_GetStatus(nsIHttpChannel
*iface
, nsresult
*aStatus
)
460 nsChannel
*This
= NSCHANNEL_THIS(iface
);
462 WARN("(%p)->(%p) returning NS_OK\n", This
, aStatus
);
464 return *aStatus
= NS_OK
;
467 static nsresult NSAPI
nsChannel_Cancel(nsIHttpChannel
*iface
, nsresult aStatus
)
469 nsChannel
*This
= NSCHANNEL_THIS(iface
);
471 FIXME("(%p)->(%08x)\n", This
, aStatus
);
473 return NS_ERROR_NOT_IMPLEMENTED
;
476 static nsresult NSAPI
nsChannel_Suspend(nsIHttpChannel
*iface
)
478 nsChannel
*This
= NSCHANNEL_THIS(iface
);
480 FIXME("(%p)\n", This
);
482 return NS_ERROR_NOT_IMPLEMENTED
;
485 static nsresult NSAPI
nsChannel_Resume(nsIHttpChannel
*iface
)
487 nsChannel
*This
= NSCHANNEL_THIS(iface
);
489 FIXME("(%p)\n", This
);
491 return NS_ERROR_NOT_IMPLEMENTED
;
494 static nsresult NSAPI
nsChannel_GetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
**aLoadGroup
)
496 nsChannel
*This
= NSCHANNEL_THIS(iface
);
498 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
501 nsILoadGroup_AddRef(This
->load_group
);
503 *aLoadGroup
= This
->load_group
;
507 static nsresult NSAPI
nsChannel_SetLoadGroup(nsIHttpChannel
*iface
, nsILoadGroup
*aLoadGroup
)
509 nsChannel
*This
= NSCHANNEL_THIS(iface
);
511 TRACE("(%p)->(%p)\n", This
, aLoadGroup
);
514 nsILoadGroup_Release(This
->load_group
);
516 nsILoadGroup_AddRef(aLoadGroup
);
517 This
->load_group
= aLoadGroup
;
522 static nsresult NSAPI
nsChannel_GetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags
*aLoadFlags
)
524 nsChannel
*This
= NSCHANNEL_THIS(iface
);
526 TRACE("(%p)->(%p)\n", This
, aLoadFlags
);
528 *aLoadFlags
= This
->load_flags
;
532 static nsresult NSAPI
nsChannel_SetLoadFlags(nsIHttpChannel
*iface
, nsLoadFlags aLoadFlags
)
534 nsChannel
*This
= NSCHANNEL_THIS(iface
);
536 TRACE("(%p)->(%08x)\n", This
, aLoadFlags
);
538 This
->load_flags
= aLoadFlags
;
542 static nsresult NSAPI
nsChannel_GetOriginalURI(nsIHttpChannel
*iface
, nsIURI
**aOriginalURI
)
544 nsChannel
*This
= NSCHANNEL_THIS(iface
);
546 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
548 if(This
->original_uri
)
549 nsIURI_AddRef(This
->original_uri
);
551 *aOriginalURI
= This
->original_uri
;
555 static nsresult NSAPI
nsChannel_SetOriginalURI(nsIHttpChannel
*iface
, nsIURI
*aOriginalURI
)
557 nsChannel
*This
= NSCHANNEL_THIS(iface
);
559 TRACE("(%p)->(%p)\n", This
, aOriginalURI
);
561 if(This
->original_uri
)
562 nsIURI_Release(This
->original_uri
);
564 nsIURI_AddRef(aOriginalURI
);
565 This
->original_uri
= aOriginalURI
;
569 static nsresult NSAPI
nsChannel_GetURI(nsIHttpChannel
*iface
, nsIURI
**aURI
)
571 nsChannel
*This
= NSCHANNEL_THIS(iface
);
573 TRACE("(%p)->(%p)\n", This
, aURI
);
575 nsIURI_AddRef(NSURI(This
->uri
));
576 *aURI
= (nsIURI
*)This
->uri
;
581 static nsresult NSAPI
nsChannel_GetOwner(nsIHttpChannel
*iface
, nsISupports
**aOwner
)
583 nsChannel
*This
= NSCHANNEL_THIS(iface
);
585 TRACE("(%p)->(%p)\n", This
, aOwner
);
588 nsISupports_AddRef(This
->owner
);
589 *aOwner
= This
->owner
;
594 static nsresult NSAPI
nsChannel_SetOwner(nsIHttpChannel
*iface
, nsISupports
*aOwner
)
596 nsChannel
*This
= NSCHANNEL_THIS(iface
);
598 TRACE("(%p)->(%p)\n", This
, aOwner
);
601 nsISupports_AddRef(aOwner
);
603 nsISupports_Release(This
->owner
);
604 This
->owner
= aOwner
;
609 static nsresult NSAPI
nsChannel_GetNotificationCallbacks(nsIHttpChannel
*iface
,
610 nsIInterfaceRequestor
**aNotificationCallbacks
)
612 nsChannel
*This
= NSCHANNEL_THIS(iface
);
614 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
616 if(This
->notif_callback
)
617 nsIInterfaceRequestor_AddRef(This
->notif_callback
);
618 *aNotificationCallbacks
= This
->notif_callback
;
623 static nsresult NSAPI
nsChannel_SetNotificationCallbacks(nsIHttpChannel
*iface
,
624 nsIInterfaceRequestor
*aNotificationCallbacks
)
626 nsChannel
*This
= NSCHANNEL_THIS(iface
);
628 TRACE("(%p)->(%p)\n", This
, aNotificationCallbacks
);
630 if(This
->notif_callback
)
631 nsIInterfaceRequestor_Release(This
->notif_callback
);
632 if(aNotificationCallbacks
)
633 nsIInterfaceRequestor_AddRef(aNotificationCallbacks
);
635 This
->notif_callback
= aNotificationCallbacks
;
640 static nsresult NSAPI
nsChannel_GetSecurityInfo(nsIHttpChannel
*iface
, nsISupports
**aSecurityInfo
)
642 nsChannel
*This
= NSCHANNEL_THIS(iface
);
644 TRACE("(%p)->(%p)\n", This
, aSecurityInfo
);
646 return NS_ERROR_NOT_IMPLEMENTED
;
649 static nsresult NSAPI
nsChannel_GetContentType(nsIHttpChannel
*iface
, nsACString
*aContentType
)
651 nsChannel
*This
= NSCHANNEL_THIS(iface
);
653 TRACE("(%p)->(%p)\n", This
, aContentType
);
655 if(This
->content_type
) {
656 nsACString_SetData(aContentType
, This
->content_type
);
660 WARN("unknown type\n");
661 return NS_ERROR_FAILURE
;
664 static nsresult NSAPI
nsChannel_SetContentType(nsIHttpChannel
*iface
,
665 const nsACString
*aContentType
)
667 nsChannel
*This
= NSCHANNEL_THIS(iface
);
668 const char *content_type
;
670 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentType
));
672 nsACString_GetData(aContentType
, &content_type
);
673 heap_free(This
->content_type
);
674 This
->content_type
= heap_strdupA(content_type
);
679 static nsresult NSAPI
nsChannel_GetContentCharset(nsIHttpChannel
*iface
,
680 nsACString
*aContentCharset
)
682 nsChannel
*This
= NSCHANNEL_THIS(iface
);
684 TRACE("(%p)->(%p)\n", This
, aContentCharset
);
687 nsACString_SetData(aContentCharset
, This
->charset
);
691 nsACString_SetData(aContentCharset
, "");
695 static nsresult NSAPI
nsChannel_SetContentCharset(nsIHttpChannel
*iface
,
696 const nsACString
*aContentCharset
)
698 nsChannel
*This
= NSCHANNEL_THIS(iface
);
700 FIXME("(%p)->(%s)\n", This
, debugstr_nsacstr(aContentCharset
));
702 return NS_ERROR_NOT_IMPLEMENTED
;
705 static nsresult NSAPI
nsChannel_GetContentLength(nsIHttpChannel
*iface
, PRInt32
*aContentLength
)
707 nsChannel
*This
= NSCHANNEL_THIS(iface
);
709 FIXME("(%p)->(%p)\n", This
, aContentLength
);
711 return NS_ERROR_NOT_IMPLEMENTED
;
714 static nsresult NSAPI
nsChannel_SetContentLength(nsIHttpChannel
*iface
, PRInt32 aContentLength
)
716 nsChannel
*This
= NSCHANNEL_THIS(iface
);
718 FIXME("(%p)->(%d)\n", This
, aContentLength
);
720 return NS_ERROR_NOT_IMPLEMENTED
;
723 static nsresult NSAPI
nsChannel_Open(nsIHttpChannel
*iface
, nsIInputStream
**_retval
)
725 nsChannel
*This
= NSCHANNEL_THIS(iface
);
727 FIXME("(%p)->(%p)\n", This
, _retval
);
729 return NS_ERROR_NOT_IMPLEMENTED
;
732 static HRESULT
create_mon_for_nschannel(nsChannel
*channel
, IMoniker
**mon
)
738 if(!channel
->original_uri
) {
739 ERR("original_uri == NULL\n");
743 nsres
= nsIURI_QueryInterface(channel
->original_uri
, &IID_nsWineURI
, (void**)&wine_uri
);
744 if(NS_FAILED(nsres
)) {
745 ERR("Could not get nsWineURI: %08x\n", nsres
);
749 if(wine_uri
->wine_url
) {
750 hres
= CreateURLMoniker(NULL
, wine_uri
->wine_url
, mon
);
752 WARN("CreateURLMoniker failed: %08x\n", hres
);
754 TRACE("wine_url == NULL\n");
758 nsIURI_Release(NSURI(wine_uri
));
763 static HTMLWindow
*get_window_from_load_group(nsChannel
*This
)
772 nsres
= nsILoadGroup_GetDefaultLoadRequest(This
->load_group
, &req
);
773 if(NS_FAILED(nsres
)) {
774 ERR("GetDefaultLoadRequest failed: %08x\n", nsres
);
781 nsres
= nsIRequest_QueryInterface(req
, &IID_nsIChannel
, (void**)&channel
);
782 nsIRequest_Release(req
);
783 if(NS_FAILED(nsres
)) {
784 WARN("Could not get nsIChannel interface: %08x\n", nsres
);
788 nsres
= nsIChannel_GetURI(channel
, &uri
);
789 nsIChannel_Release(channel
);
790 if(NS_FAILED(nsres
)) {
791 ERR("GetURI failed: %08x\n", nsres
);
795 nsres
= nsIURI_QueryInterface(uri
, &IID_nsWineURI
, (void**)&wine_uri
);
797 if(NS_FAILED(nsres
)) {
798 TRACE("Could not get nsWineURI: %08x\n", nsres
);
802 window
= wine_uri
->window_ref
? wine_uri
->window_ref
->window
: NULL
;
804 IHTMLWindow2_AddRef(HTMLWINDOW2(window
));
805 nsIURI_Release(NSURI(wine_uri
));
810 static HTMLWindow
*get_channel_window(nsChannel
*This
)
812 nsIRequestObserver
*req_observer
;
813 nsIWebProgress
*web_progress
;
814 nsIDOMWindow
*nswindow
;
818 if(!This
->load_group
) {
819 ERR("NULL load_group\n");
823 nsres
= nsILoadGroup_GetGroupObserver(This
->load_group
, &req_observer
);
824 if(NS_FAILED(nsres
) || !req_observer
) {
825 ERR("GetGroupObserver failed: %08x\n", nsres
);
829 nsres
= nsIRequestObserver_QueryInterface(req_observer
, &IID_nsIWebProgress
, (void**)&web_progress
);
830 nsIRequestObserver_Release(req_observer
);
831 if(NS_FAILED(nsres
)) {
832 ERR("Could not get nsIWebProgress iface: %08x\n", nsres
);
836 nsres
= nsIWebProgress_GetDOMWindow(web_progress
, &nswindow
);
837 nsIWebProgress_Release(web_progress
);
838 if(NS_FAILED(nsres
) || !nswindow
) {
839 ERR("GetDOMWindow failed: %08x\n", nsres
);
843 window
= nswindow_to_window(nswindow
);
844 nsIDOMWindow_Release(nswindow
);
847 IHTMLWindow2_AddRef(HTMLWINDOW2(window
));
849 FIXME("NULL window for %p\n", nswindow
);
855 HTMLDocumentNode
*doc
;
856 nsChannelBSC
*bscallback
;
857 } start_binding_task_t
;
859 static void start_binding_proc(task_t
*_task
)
861 start_binding_task_t
*task
= (start_binding_task_t
*)_task
;
863 start_binding(NULL
, task
->doc
, (BSCallback
*)task
->bscallback
, NULL
);
865 IUnknown_Release((IUnknown
*)task
->bscallback
);
868 static nsresult
async_open(nsChannel
*This
, HTMLWindow
*window
, BOOL is_doc_channel
, nsIStreamListener
*listener
,
869 nsISupports
*context
)
871 nsChannelBSC
*bscallback
;
872 IMoniker
*mon
= NULL
;
875 hres
= create_mon_for_nschannel(This
, &mon
);
877 return NS_ERROR_UNEXPECTED
;
880 set_current_mon(window
, mon
);
882 hres
= create_channelbsc(mon
, NULL
, NULL
, 0, &bscallback
);
883 IMoniker_Release(mon
);
885 return NS_ERROR_UNEXPECTED
;
887 channelbsc_set_channel(bscallback
, This
, listener
, context
);
890 set_window_bscallback(window
, bscallback
);
891 async_start_doc_binding(window
, bscallback
);
892 IUnknown_Release((IUnknown
*)bscallback
);
894 start_binding_task_t
*task
= heap_alloc(sizeof(start_binding_task_t
));
896 task
->doc
= window
->doc
;
897 task
->bscallback
= bscallback
;
898 push_task(&task
->header
, start_binding_proc
, window
->doc
->basedoc
.task_magic
);
904 static nsresult NSAPI
nsChannel_AsyncOpen(nsIHttpChannel
*iface
, nsIStreamListener
*aListener
,
905 nsISupports
*aContext
)
907 nsChannel
*This
= NSCHANNEL_THIS(iface
);
908 HTMLWindow
*window
= NULL
;
910 nsresult nsres
= NS_OK
;
912 TRACE("(%p)->(%p %p) opening %s\n", This
, aListener
, aContext
, debugstr_w(This
->uri
->wine_url
));
914 if(This
->uri
->is_doc_uri
) {
915 window
= get_channel_window(This
);
917 set_uri_window(This
->uri
, window
);
918 }else if(This
->uri
->container
) {
921 /* nscontainer->doc should be NULL which means navigation to a new window */
922 if(This
->uri
->container
->doc
)
923 FIXME("nscontainer->doc = %p\n", This
->uri
->container
->doc
);
925 b
= before_async_open(This
, This
->uri
->container
);
927 FIXME("Navigation not cancelled\n");
928 return NS_ERROR_UNEXPECTED
;
933 if(This
->uri
->window_ref
&& This
->uri
->window_ref
->window
) {
934 window
= This
->uri
->window_ref
->window
;
935 IHTMLWindow2_AddRef(HTMLWINDOW2(window
));
936 }else if(This
->load_group
) {
937 window
= get_window_from_load_group(This
);
939 set_uri_window(This
->uri
, window
);
944 ERR("window = NULL\n");
945 return NS_ERROR_UNEXPECTED
;
948 if(This
->uri
->is_doc_uri
&& window
== window
->doc_obj
->basedoc
.window
) {
949 if(This
->uri
->channel_bsc
) {
950 channelbsc_set_channel(This
->uri
->channel_bsc
, This
, aListener
, aContext
);
952 if(window
->doc_obj
->mime
) {
953 heap_free(This
->content_type
);
954 This
->content_type
= heap_strdupWtoA(window
->doc_obj
->mime
);
959 open
= !before_async_open(This
, window
->doc_obj
->nscontainer
);
962 nsres
= NS_ERROR_UNEXPECTED
;
968 nsres
= async_open(This
, window
, This
->uri
->is_doc_uri
, aListener
, aContext
);
970 IHTMLWindow2_Release(HTMLWINDOW2(window
));
974 static nsresult NSAPI
nsChannel_GetRequestMethod(nsIHttpChannel
*iface
, nsACString
*aRequestMethod
)
976 nsChannel
*This
= NSCHANNEL_THIS(iface
);
978 FIXME("(%p)->(%p)\n", This
, aRequestMethod
);
980 return NS_ERROR_NOT_IMPLEMENTED
;
983 static nsresult NSAPI
nsChannel_SetRequestMethod(nsIHttpChannel
*iface
,
984 const nsACString
*aRequestMethod
)
986 nsChannel
*This
= NSCHANNEL_THIS(iface
);
988 TRACE("(%p)->(%s): Returning NS_OK\n", This
, debugstr_nsacstr(aRequestMethod
));
993 static nsresult NSAPI
nsChannel_GetReferrer(nsIHttpChannel
*iface
, nsIURI
**aReferrer
)
995 nsChannel
*This
= NSCHANNEL_THIS(iface
);
997 FIXME("(%p)->(%p)\n", This
, aReferrer
);
999 return NS_ERROR_NOT_IMPLEMENTED
;
1002 static nsresult NSAPI
nsChannel_SetReferrer(nsIHttpChannel
*iface
, nsIURI
*aReferrer
)
1004 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1006 FIXME("(%p)->(%p)\n", This
, aReferrer
);
1011 static nsresult NSAPI
nsChannel_GetRequestHeader(nsIHttpChannel
*iface
,
1012 const nsACString
*aHeader
, nsACString
*_retval
)
1014 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1016 FIXME("(%p)->(%s %p)\n", This
, debugstr_nsacstr(aHeader
), _retval
);
1018 return NS_ERROR_NOT_IMPLEMENTED
;
1021 static nsresult NSAPI
nsChannel_SetRequestHeader(nsIHttpChannel
*iface
,
1022 const nsACString
*aHeader
, const nsACString
*aValue
, PRBool aMerge
)
1024 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1026 FIXME("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(aHeader
), debugstr_nsacstr(aValue
), aMerge
);
1031 static nsresult NSAPI
nsChannel_VisitRequestHeaders(nsIHttpChannel
*iface
,
1032 nsIHttpHeaderVisitor
*aVisitor
)
1034 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1036 FIXME("(%p)->(%p)\n", This
, aVisitor
);
1038 return NS_ERROR_NOT_IMPLEMENTED
;
1041 static nsresult NSAPI
nsChannel_GetAllowPipelining(nsIHttpChannel
*iface
, PRBool
*aAllowPipelining
)
1043 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1045 FIXME("(%p)->(%p)\n", This
, aAllowPipelining
);
1047 return NS_ERROR_NOT_IMPLEMENTED
;
1050 static nsresult NSAPI
nsChannel_SetAllowPipelining(nsIHttpChannel
*iface
, PRBool aAllowPipelining
)
1052 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1054 FIXME("(%p)->(%x)\n", This
, aAllowPipelining
);
1056 return NS_ERROR_NOT_IMPLEMENTED
;
1059 static nsresult NSAPI
nsChannel_GetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32
*aRedirectionLimit
)
1061 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1063 FIXME("(%p)->(%p)\n", This
, aRedirectionLimit
);
1065 return NS_ERROR_NOT_IMPLEMENTED
;
1068 static nsresult NSAPI
nsChannel_SetRedirectionLimit(nsIHttpChannel
*iface
, PRUint32 aRedirectionLimit
)
1070 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1072 FIXME("(%p)->(%u)\n", This
, aRedirectionLimit
);
1074 return NS_ERROR_NOT_IMPLEMENTED
;
1077 static nsresult NSAPI
nsChannel_GetResponseStatus(nsIHttpChannel
*iface
, PRUint32
*aResponseStatus
)
1079 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1081 TRACE("(%p)->(%p)\n", This
, aResponseStatus
);
1083 if(This
->response_status
) {
1084 *aResponseStatus
= This
->response_status
;
1088 WARN("No response status\n");
1089 return NS_ERROR_UNEXPECTED
;
1092 static nsresult NSAPI
nsChannel_GetResponseStatusText(nsIHttpChannel
*iface
,
1093 nsACString
*aResponseStatusText
)
1095 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1097 FIXME("(%p)->(%p)\n", This
, aResponseStatusText
);
1099 return NS_ERROR_NOT_IMPLEMENTED
;
1102 static nsresult NSAPI
nsChannel_GetRequestSucceeded(nsIHttpChannel
*iface
,
1103 PRBool
*aRequestSucceeded
)
1105 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1107 TRACE("(%p)->(%p)\n", This
, aRequestSucceeded
);
1109 if(!This
->response_status
)
1110 return NS_ERROR_NOT_AVAILABLE
;
1112 *aRequestSucceeded
= This
->response_status
/100 == 2;
1117 static nsresult NSAPI
nsChannel_GetResponseHeader(nsIHttpChannel
*iface
,
1118 const nsACString
*header
, nsACString
*_retval
)
1120 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1122 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(header
), _retval
);
1124 return get_channel_http_header(&This
->response_headers
, header
, _retval
);
1127 static nsresult NSAPI
nsChannel_SetResponseHeader(nsIHttpChannel
*iface
,
1128 const nsACString
*header
, const nsACString
*value
, PRBool merge
)
1130 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1132 FIXME("(%p)->(%s %s %x)\n", This
, debugstr_nsacstr(header
), debugstr_nsacstr(value
), merge
);
1134 return NS_ERROR_NOT_IMPLEMENTED
;
1137 static nsresult NSAPI
nsChannel_VisitResponseHeaders(nsIHttpChannel
*iface
,
1138 nsIHttpHeaderVisitor
*aVisitor
)
1140 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1142 FIXME("(%p)->(%p)\n", This
, aVisitor
);
1144 return NS_ERROR_NOT_IMPLEMENTED
;
1147 static nsresult NSAPI
nsChannel_IsNoStoreResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1149 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1151 FIXME("(%p)->(%p)\n", This
, _retval
);
1153 return NS_ERROR_NOT_IMPLEMENTED
;
1156 static nsresult NSAPI
nsChannel_IsNoCacheResponse(nsIHttpChannel
*iface
, PRBool
*_retval
)
1158 nsChannel
*This
= NSCHANNEL_THIS(iface
);
1160 FIXME("(%p)->(%p)\n", This
, _retval
);
1162 return NS_ERROR_NOT_IMPLEMENTED
;
1165 #undef NSCHANNEL_THIS
1167 static const nsIHttpChannelVtbl nsChannelVtbl
= {
1168 nsChannel_QueryInterface
,
1172 nsChannel_IsPending
,
1173 nsChannel_GetStatus
,
1177 nsChannel_GetLoadGroup
,
1178 nsChannel_SetLoadGroup
,
1179 nsChannel_GetLoadFlags
,
1180 nsChannel_SetLoadFlags
,
1181 nsChannel_GetOriginalURI
,
1182 nsChannel_SetOriginalURI
,
1186 nsChannel_GetNotificationCallbacks
,
1187 nsChannel_SetNotificationCallbacks
,
1188 nsChannel_GetSecurityInfo
,
1189 nsChannel_GetContentType
,
1190 nsChannel_SetContentType
,
1191 nsChannel_GetContentCharset
,
1192 nsChannel_SetContentCharset
,
1193 nsChannel_GetContentLength
,
1194 nsChannel_SetContentLength
,
1196 nsChannel_AsyncOpen
,
1197 nsChannel_GetRequestMethod
,
1198 nsChannel_SetRequestMethod
,
1199 nsChannel_GetReferrer
,
1200 nsChannel_SetReferrer
,
1201 nsChannel_GetRequestHeader
,
1202 nsChannel_SetRequestHeader
,
1203 nsChannel_VisitRequestHeaders
,
1204 nsChannel_GetAllowPipelining
,
1205 nsChannel_SetAllowPipelining
,
1206 nsChannel_GetRedirectionLimit
,
1207 nsChannel_SetRedirectionLimit
,
1208 nsChannel_GetResponseStatus
,
1209 nsChannel_GetResponseStatusText
,
1210 nsChannel_GetRequestSucceeded
,
1211 nsChannel_GetResponseHeader
,
1212 nsChannel_SetResponseHeader
,
1213 nsChannel_VisitResponseHeaders
,
1214 nsChannel_IsNoStoreResponse
,
1215 nsChannel_IsNoCacheResponse
1218 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1220 static nsresult NSAPI
nsUploadChannel_QueryInterface(nsIUploadChannel
*iface
, nsIIDRef riid
,
1223 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1224 return nsIChannel_QueryInterface(NSCHANNEL(This
), riid
, result
);
1227 static nsrefcnt NSAPI
nsUploadChannel_AddRef(nsIUploadChannel
*iface
)
1229 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1230 return nsIChannel_AddRef(NSCHANNEL(This
));
1233 static nsrefcnt NSAPI
nsUploadChannel_Release(nsIUploadChannel
*iface
)
1235 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1236 return nsIChannel_Release(NSCHANNEL(This
));
1239 static nsresult NSAPI
nsUploadChannel_SetUploadStream(nsIUploadChannel
*iface
,
1240 nsIInputStream
*aStream
, const nsACString
*aContentType
, PRInt32 aContentLength
)
1242 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1243 const char *content_type
;
1245 TRACE("(%p)->(%p %s %d)\n", This
, aStream
, debugstr_nsacstr(aContentType
), aContentLength
);
1247 if(This
->post_data_stream
)
1248 nsIInputStream_Release(This
->post_data_stream
);
1251 nsACString_GetData(aContentType
, &content_type
);
1253 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type
));
1256 if(aContentLength
!= -1)
1257 FIXME("Unsupported acontentLength = %d\n", aContentLength
);
1259 if(This
->post_data_stream
)
1260 nsIInputStream_Release(This
->post_data_stream
);
1261 This
->post_data_stream
= aStream
;
1263 nsIInputStream_AddRef(aStream
);
1268 static nsresult NSAPI
nsUploadChannel_GetUploadStream(nsIUploadChannel
*iface
,
1269 nsIInputStream
**aUploadStream
)
1271 nsChannel
*This
= NSUPCHANNEL_THIS(iface
);
1273 TRACE("(%p)->(%p)\n", This
, aUploadStream
);
1275 if(This
->post_data_stream
)
1276 nsIInputStream_AddRef(This
->post_data_stream
);
1278 *aUploadStream
= This
->post_data_stream
;
1282 #undef NSUPCHANNEL_THIS
1284 static const nsIUploadChannelVtbl nsUploadChannelVtbl
= {
1285 nsUploadChannel_QueryInterface
,
1286 nsUploadChannel_AddRef
,
1287 nsUploadChannel_Release
,
1288 nsUploadChannel_SetUploadStream
,
1289 nsUploadChannel_GetUploadStream
1292 #define NSHTTPINTERNAL_THIS(iface) DEFINE_THIS(nsChannel, IHttpChannelInternal, iface)
1294 static nsresult NSAPI
nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal
*iface
, nsIIDRef riid
,
1297 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1298 return nsIChannel_QueryInterface(NSCHANNEL(This
), riid
, result
);
1301 static nsrefcnt NSAPI
nsHttpChannelInternal_AddRef(nsIHttpChannelInternal
*iface
)
1303 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1304 return nsIChannel_AddRef(NSCHANNEL(This
));
1307 static nsrefcnt NSAPI
nsHttpChannelInternal_Release(nsIHttpChannelInternal
*iface
)
1309 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1310 return nsIChannel_Release(NSCHANNEL(This
));
1313 static nsresult NSAPI
nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
**aDocumentURI
)
1315 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1317 FIXME("(%p)->()\n", This
);
1319 return NS_ERROR_NOT_IMPLEMENTED
;
1322 static nsresult NSAPI
nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal
*iface
, nsIURI
*aDocumentURI
)
1324 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1326 FIXME("(%p)->()\n", This
);
1328 return NS_ERROR_NOT_IMPLEMENTED
;
1331 static nsresult NSAPI
nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal
*iface
, PRUint32
*major
, PRUint32
*minor
)
1333 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1335 FIXME("(%p)->()\n", This
);
1337 return NS_ERROR_NOT_IMPLEMENTED
;
1340 static nsresult NSAPI
nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal
*iface
, PRUint32
*major
, PRUint32
*minor
)
1342 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1344 FIXME("(%p)->()\n", This
);
1346 return NS_ERROR_NOT_IMPLEMENTED
;
1349 static nsresult NSAPI
nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal
*iface
, const char *aCookieHeader
)
1351 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1353 FIXME("(%p)->()\n", This
);
1355 return NS_ERROR_NOT_IMPLEMENTED
;
1358 static nsresult NSAPI
nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal
*iface
, const char *aFallbackKey
)
1360 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1362 FIXME("(%p)->()\n", This
);
1364 return NS_ERROR_NOT_IMPLEMENTED
;
1367 static nsresult NSAPI
nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, PRBool
*aForceThirdPartyCookie
)
1369 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1371 FIXME("(%p)->()\n", This
);
1373 return NS_ERROR_NOT_IMPLEMENTED
;
1376 static nsresult NSAPI
nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal
*iface
, PRBool aForceThirdPartyCookie
)
1378 nsChannel
*This
= NSHTTPINTERNAL_THIS(iface
);
1380 FIXME("(%p)->()\n", This
);
1382 return NS_ERROR_NOT_IMPLEMENTED
;
1385 #undef NSHTTPINTERNAL_THIS
1387 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl
= {
1388 nsHttpChannelInternal_QueryInterface
,
1389 nsHttpChannelInternal_AddRef
,
1390 nsHttpChannelInternal_Release
,
1391 nsHttpChannelInternal_GetDocumentURI
,
1392 nsHttpChannelInternal_SetDocumentURI
,
1393 nsHttpChannelInternal_GetRequestVersion
,
1394 nsHttpChannelInternal_GetResponseVersion
,
1395 nsHttpChannelInternal_SetCookie
,
1396 nsHttpChannelInternal_SetupFallbackChannel
,
1397 nsHttpChannelInternal_GetForceAllowThirdPartyCookie
,
1398 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
1401 #define NSURI_THIS(iface) DEFINE_THIS(nsWineURI, IURL, iface)
1403 static nsresult NSAPI
nsURI_QueryInterface(nsIURL
*iface
, nsIIDRef riid
, void **result
)
1405 nsWineURI
*This
= NSURI_THIS(iface
);
1409 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
1410 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
1411 *result
= NSURI(This
);
1412 }else if(IsEqualGUID(&IID_nsIURI
, riid
)) {
1413 TRACE("(%p)->(IID_nsIURI %p)\n", This
, result
);
1414 *result
= NSURI(This
);
1415 }else if(IsEqualGUID(&IID_nsIURL
, riid
)) {
1416 TRACE("(%p)->(IID_nsIURL %p)\n", This
, result
);
1417 *result
= NSURL(This
);
1418 }else if(IsEqualGUID(&IID_nsWineURI
, riid
)) {
1419 TRACE("(%p)->(IID_nsWineURI %p)\n", This
, result
);
1424 nsIURI_AddRef(NSURI(This
));
1428 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
1429 return This
->uri
? nsIURI_QueryInterface(This
->uri
, riid
, result
) : NS_NOINTERFACE
;
1432 static nsrefcnt NSAPI
nsURI_AddRef(nsIURL
*iface
)
1434 nsWineURI
*This
= NSURI_THIS(iface
);
1435 LONG ref
= InterlockedIncrement(&This
->ref
);
1437 TRACE("(%p) ref=%d\n", This
, ref
);
1442 static nsrefcnt NSAPI
nsURI_Release(nsIURL
*iface
)
1444 nsWineURI
*This
= NSURI_THIS(iface
);
1445 LONG ref
= InterlockedDecrement(&This
->ref
);
1447 TRACE("(%p) ref=%d\n", This
, ref
);
1450 if(This
->window_ref
)
1451 windowref_release(This
->window_ref
);
1453 nsIWebBrowserChrome_Release(NSWBCHROME(This
->container
));
1455 nsIURL_Release(This
->nsurl
);
1457 nsIURI_Release(This
->uri
);
1458 heap_free(This
->wine_url
);
1465 static nsresult NSAPI
nsURI_GetSpec(nsIURL
*iface
, nsACString
*aSpec
)
1467 nsWineURI
*This
= NSURI_THIS(iface
);
1469 TRACE("(%p)->(%p)\n", This
, aSpec
);
1471 if(This
->use_wine_url
) {
1472 char speca
[INTERNET_MAX_URL_LENGTH
] = "wine:";
1473 WideCharToMultiByte(CP_ACP
, 0, This
->wine_url
, -1, speca
+5, sizeof(speca
)-5, NULL
, NULL
);
1474 nsACString_SetData(aSpec
, speca
);
1480 return nsIURI_GetSpec(This
->uri
, aSpec
);
1482 TRACE("returning error\n");
1483 return NS_ERROR_NOT_IMPLEMENTED
;
1487 static nsresult NSAPI
nsURI_SetSpec(nsIURL
*iface
, const nsACString
*aSpec
)
1489 nsWineURI
*This
= NSURI_THIS(iface
);
1491 TRACE("(%p)->(%p)\n", This
, debugstr_nsacstr(aSpec
));
1494 return nsIURI_SetSpec(This
->uri
, aSpec
);
1496 FIXME("default action not implemented\n");
1497 return NS_ERROR_NOT_IMPLEMENTED
;
1500 static nsresult NSAPI
nsURI_GetPrePath(nsIURL
*iface
, nsACString
*aPrePath
)
1502 nsWineURI
*This
= NSURI_THIS(iface
);
1504 TRACE("(%p)->(%p)\n", This
, aPrePath
);
1507 return nsIURI_GetPrePath(This
->uri
, aPrePath
);
1509 FIXME("default action not implemented\n");
1510 return NS_ERROR_NOT_IMPLEMENTED
;
1513 static nsresult NSAPI
nsURI_GetScheme(nsIURL
*iface
, nsACString
*aScheme
)
1515 nsWineURI
*This
= NSURI_THIS(iface
);
1517 TRACE("(%p)->(%p)\n", This
, aScheme
);
1519 if(This
->use_wine_url
) {
1521 * For Gecko we set scheme to unknown so it won't be handled
1522 * as any special case.
1524 nsACString_SetData(aScheme
, "wine");
1529 return nsIURI_GetScheme(This
->uri
, aScheme
);
1531 TRACE("returning error\n");
1532 return NS_ERROR_NOT_IMPLEMENTED
;
1535 static nsresult NSAPI
nsURI_SetScheme(nsIURL
*iface
, const nsACString
*aScheme
)
1537 nsWineURI
*This
= NSURI_THIS(iface
);
1539 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aScheme
));
1542 return nsIURI_SetScheme(This
->uri
, aScheme
);
1544 FIXME("default action not implemented\n");
1545 return NS_ERROR_NOT_IMPLEMENTED
;
1548 static nsresult NSAPI
nsURI_GetUserPass(nsIURL
*iface
, nsACString
*aUserPass
)
1550 nsWineURI
*This
= NSURI_THIS(iface
);
1552 TRACE("(%p)->(%p)\n", This
, aUserPass
);
1555 return nsIURI_GetUserPass(This
->uri
, aUserPass
);
1557 FIXME("default action not implemented\n");
1558 return NS_ERROR_NOT_IMPLEMENTED
;
1561 static nsresult NSAPI
nsURI_SetUserPass(nsIURL
*iface
, const nsACString
*aUserPass
)
1563 nsWineURI
*This
= NSURI_THIS(iface
);
1565 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUserPass
));
1568 return nsIURI_SetUserPass(This
->uri
, aUserPass
);
1570 FIXME("default action not implemented\n");
1571 return NS_ERROR_NOT_IMPLEMENTED
;
1574 static nsresult NSAPI
nsURI_GetUsername(nsIURL
*iface
, nsACString
*aUsername
)
1576 nsWineURI
*This
= NSURI_THIS(iface
);
1578 TRACE("(%p)->(%p)\n", This
, aUsername
);
1581 return nsIURI_GetUsername(This
->uri
, aUsername
);
1583 FIXME("default action not implemented\n");
1584 return NS_ERROR_NOT_IMPLEMENTED
;
1587 static nsresult NSAPI
nsURI_SetUsername(nsIURL
*iface
, const nsACString
*aUsername
)
1589 nsWineURI
*This
= NSURI_THIS(iface
);
1591 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aUsername
));
1594 return nsIURI_SetUsername(This
->uri
, aUsername
);
1596 FIXME("default action not implemented\n");
1597 return NS_ERROR_NOT_IMPLEMENTED
;
1600 static nsresult NSAPI
nsURI_GetPassword(nsIURL
*iface
, nsACString
*aPassword
)
1602 nsWineURI
*This
= NSURI_THIS(iface
);
1604 TRACE("(%p)->(%p)\n", This
, aPassword
);
1607 return nsIURI_GetPassword(This
->uri
, aPassword
);
1609 FIXME("default action not implemented\n");
1610 return NS_ERROR_NOT_IMPLEMENTED
;
1613 static nsresult NSAPI
nsURI_SetPassword(nsIURL
*iface
, const nsACString
*aPassword
)
1615 nsWineURI
*This
= NSURI_THIS(iface
);
1617 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPassword
));
1620 return nsIURI_SetPassword(This
->uri
, aPassword
);
1622 FIXME("default action not implemented\n");
1623 return NS_ERROR_NOT_IMPLEMENTED
;
1626 static nsresult NSAPI
nsURI_GetHostPort(nsIURL
*iface
, nsACString
*aHostPort
)
1628 nsWineURI
*This
= NSURI_THIS(iface
);
1630 TRACE("(%p)->(%p)\n", This
, aHostPort
);
1633 return nsIURI_GetHostPort(This
->uri
, aHostPort
);
1635 FIXME("default action not implemented\n");
1636 return NS_ERROR_NOT_IMPLEMENTED
;
1639 static nsresult NSAPI
nsURI_SetHostPort(nsIURL
*iface
, const nsACString
*aHostPort
)
1641 nsWineURI
*This
= NSURI_THIS(iface
);
1643 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aHostPort
));
1646 return nsIURI_SetHostPort(This
->uri
, aHostPort
);
1648 FIXME("default action not implemented\n");
1649 return NS_ERROR_NOT_IMPLEMENTED
;
1652 static nsresult NSAPI
nsURI_GetHost(nsIURL
*iface
, nsACString
*aHost
)
1654 nsWineURI
*This
= NSURI_THIS(iface
);
1656 TRACE("(%p)->(%p)\n", This
, aHost
);
1659 return nsIURI_GetHost(This
->uri
, aHost
);
1661 FIXME("default action not implemented\n");
1662 return NS_ERROR_NOT_IMPLEMENTED
;
1665 static nsresult NSAPI
nsURI_SetHost(nsIURL
*iface
, const nsACString
*aHost
)
1667 nsWineURI
*This
= NSURI_THIS(iface
);
1669 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aHost
));
1672 return nsIURI_SetHost(This
->uri
, aHost
);
1674 FIXME("default action not implemented\n");
1675 return NS_ERROR_NOT_IMPLEMENTED
;
1678 static nsresult NSAPI
nsURI_GetPort(nsIURL
*iface
, PRInt32
*aPort
)
1680 nsWineURI
*This
= NSURI_THIS(iface
);
1682 TRACE("(%p)->(%p)\n", This
, aPort
);
1685 return nsIURI_GetPort(This
->uri
, aPort
);
1687 FIXME("default action not implemented\n");
1688 return NS_ERROR_NOT_IMPLEMENTED
;
1691 static nsresult NSAPI
nsURI_SetPort(nsIURL
*iface
, PRInt32 aPort
)
1693 nsWineURI
*This
= NSURI_THIS(iface
);
1695 TRACE("(%p)->(%d)\n", This
, aPort
);
1698 return nsIURI_SetPort(This
->uri
, aPort
);
1700 FIXME("default action not implemented\n");
1701 return NS_ERROR_NOT_IMPLEMENTED
;
1704 static nsresult NSAPI
nsURI_GetPath(nsIURL
*iface
, nsACString
*aPath
)
1706 nsWineURI
*This
= NSURI_THIS(iface
);
1708 TRACE("(%p)->(%p)\n", This
, aPath
);
1711 return nsIURI_GetPath(This
->uri
, aPath
);
1713 FIXME("default action not implemented\n");
1714 return NS_ERROR_NOT_IMPLEMENTED
;
1717 static nsresult NSAPI
nsURI_SetPath(nsIURL
*iface
, const nsACString
*aPath
)
1719 nsWineURI
*This
= NSURI_THIS(iface
);
1722 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aPath
));
1724 nsACString_GetData(aPath
, &path
);
1725 if(This
->wine_url
) {
1726 WCHAR new_url
[INTERNET_MAX_URL_LENGTH
];
1727 DWORD size
= sizeof(new_url
)/sizeof(WCHAR
);
1731 pathw
= heap_strdupAtoW(path
);
1732 hres
= UrlCombineW(This
->wine_url
, pathw
, new_url
, &size
, 0);
1735 set_wine_url(This
, new_url
);
1737 WARN("UrlCombine failed: %08x\n", hres
);
1743 return nsIURI_SetPath(This
->uri
, aPath
);
1746 static nsresult NSAPI
nsURI_Equals(nsIURL
*iface
, nsIURI
*other
, PRBool
*_retval
)
1748 nsWineURI
*This
= NSURI_THIS(iface
);
1749 nsWineURI
*wine_uri
;
1752 TRACE("(%p)->(%p %p)\n", This
, other
, _retval
);
1755 return nsIURI_Equals(This
->uri
, other
, _retval
);
1757 nsres
= nsIURI_QueryInterface(other
, &IID_nsWineURI
, (void**)&wine_uri
);
1758 if(NS_FAILED(nsres
)) {
1759 TRACE("Could not get nsWineURI interface\n");
1764 *_retval
= wine_uri
->wine_url
&& !UrlCompareW(This
->wine_url
, wine_uri
->wine_url
, TRUE
);
1765 nsIURI_Release(NSURI(wine_uri
));
1770 static nsresult NSAPI
nsURI_SchemeIs(nsIURL
*iface
, const char *scheme
, PRBool
*_retval
)
1772 nsWineURI
*This
= NSURI_THIS(iface
);
1774 TRACE("(%p)->(%s %p)\n", This
, debugstr_a(scheme
), _retval
);
1776 if(This
->use_wine_url
) {
1777 WCHAR buf
[INTERNET_MAX_SCHEME_LENGTH
];
1778 int len
= MultiByteToWideChar(CP_ACP
, 0, scheme
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
))-1;
1780 *_retval
= lstrlenW(This
->wine_url
) > len
1781 && This
->wine_url
[len
] == ':'
1782 && !memcmp(buf
, This
->wine_url
, len
*sizeof(WCHAR
));
1787 return nsIURI_SchemeIs(This
->uri
, scheme
, _retval
);
1789 TRACE("returning error\n");
1790 return NS_ERROR_NOT_IMPLEMENTED
;
1793 static nsresult NSAPI
nsURI_Clone(nsIURL
*iface
, nsIURI
**_retval
)
1795 nsWineURI
*This
= NSURI_THIS(iface
);
1796 nsIURI
*nsuri
= NULL
;
1797 nsWineURI
*wine_uri
;
1800 TRACE("(%p)->(%p)\n", This
, _retval
);
1803 nsres
= nsIURI_Clone(This
->uri
, &nsuri
);
1804 if(NS_FAILED(nsres
)) {
1805 WARN("Clone failed: %08x\n", nsres
);
1810 nsres
= create_uri(nsuri
, This
->window_ref
? This
->window_ref
->window
: NULL
, This
->container
, &wine_uri
);
1811 if(NS_FAILED(nsres
)) {
1812 WARN("create_uri failed: %08x\n", nsres
);
1816 set_wine_url(wine_uri
, This
->wine_url
);
1818 *_retval
= NSURI(wine_uri
);
1822 static nsresult NSAPI
nsURI_Resolve(nsIURL
*iface
, const nsACString
*arelativePath
,
1823 nsACString
*_retval
)
1825 nsWineURI
*This
= NSURI_THIS(iface
);
1827 TRACE("(%p)->(%s %p)\n", This
, debugstr_nsacstr(arelativePath
), _retval
);
1830 return nsIURI_Resolve(This
->uri
, arelativePath
, _retval
);
1832 FIXME("default action not implemented\n");
1833 return NS_ERROR_NOT_IMPLEMENTED
;
1836 static nsresult NSAPI
nsURI_GetAsciiSpec(nsIURL
*iface
, nsACString
*aAsciiSpec
)
1838 nsWineURI
*This
= NSURI_THIS(iface
);
1840 TRACE("(%p)->(%p)\n", This
, aAsciiSpec
);
1842 if(This
->use_wine_url
)
1843 return nsIURI_GetSpec(NSURI(This
), aAsciiSpec
);
1846 return nsIURI_GetAsciiSpec(This
->uri
, aAsciiSpec
);
1848 TRACE("returning error\n");
1849 return NS_ERROR_NOT_IMPLEMENTED
;
1852 static nsresult NSAPI
nsURI_GetAsciiHost(nsIURL
*iface
, nsACString
*aAsciiHost
)
1854 nsWineURI
*This
= NSURI_THIS(iface
);
1856 TRACE("(%p)->(%p)\n", This
, aAsciiHost
);
1859 return nsIURI_GetAsciiHost(This
->uri
, aAsciiHost
);
1861 FIXME("default action not implemented\n");
1862 return NS_ERROR_NOT_IMPLEMENTED
;
1865 static nsresult NSAPI
nsURI_GetOriginCharset(nsIURL
*iface
, nsACString
*aOriginCharset
)
1867 nsWineURI
*This
= NSURI_THIS(iface
);
1869 TRACE("(%p)->(%p)\n", This
, aOriginCharset
);
1872 return nsIURI_GetOriginCharset(This
->uri
, aOriginCharset
);
1874 FIXME("default action not implemented\n");
1875 return NS_ERROR_NOT_IMPLEMENTED
;
1878 static nsresult NSAPI
nsURL_GetFilePath(nsIURL
*iface
, nsACString
*aFilePath
)
1880 nsWineURI
*This
= NSURI_THIS(iface
);
1882 TRACE("(%p)->(%p)\n", This
, aFilePath
);
1885 return nsIURL_GetFilePath(This
->nsurl
, aFilePath
);
1887 FIXME("default action not implemented\n");
1888 return NS_ERROR_NOT_IMPLEMENTED
;
1891 static nsresult NSAPI
nsURL_SetFilePath(nsIURL
*iface
, const nsACString
*aFilePath
)
1893 nsWineURI
*This
= NSURI_THIS(iface
);
1895 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFilePath
));
1898 return nsIURL_SetFilePath(This
->nsurl
, aFilePath
);
1900 FIXME("default action not implemented\n");
1901 return NS_ERROR_NOT_IMPLEMENTED
;
1904 static nsresult NSAPI
nsURL_GetParam(nsIURL
*iface
, nsACString
*aParam
)
1906 nsWineURI
*This
= NSURI_THIS(iface
);
1908 TRACE("(%p)->(%p)\n", This
, aParam
);
1911 return nsIURL_GetParam(This
->nsurl
, aParam
);
1913 FIXME("default action not implemented\n");
1914 return NS_ERROR_NOT_IMPLEMENTED
;
1917 static nsresult NSAPI
nsURL_SetParam(nsIURL
*iface
, const nsACString
*aParam
)
1919 nsWineURI
*This
= NSURI_THIS(iface
);
1921 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aParam
));
1924 return nsIURL_SetParam(This
->nsurl
, aParam
);
1926 FIXME("default action not implemented\n");
1927 return NS_ERROR_NOT_IMPLEMENTED
;
1930 static nsresult NSAPI
nsURL_GetQuery(nsIURL
*iface
, nsACString
*aQuery
)
1932 nsWineURI
*This
= NSURI_THIS(iface
);
1934 TRACE("(%p)->(%p)\n", This
, aQuery
);
1937 return nsIURL_GetQuery(This
->nsurl
, aQuery
);
1939 FIXME("default action not implemented\n");
1940 return NS_ERROR_NOT_IMPLEMENTED
;
1943 static nsresult NSAPI
nsURL_SetQuery(nsIURL
*iface
, const nsACString
*aQuery
)
1945 nsWineURI
*This
= NSURI_THIS(iface
);
1946 const WCHAR
*ptr1
, *ptr2
;
1948 WCHAR
*new_url
, *ptr
;
1951 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aQuery
));
1954 nsIURL_SetQuery(This
->nsurl
, aQuery
);
1959 nsACString_GetData(aQuery
, &query
);
1960 size
= len
= MultiByteToWideChar(CP_ACP
, 0, query
, -1, NULL
, 0);
1961 ptr1
= strchrW(This
->wine_url
, '?');
1963 size
+= ptr1
-This
->wine_url
;
1964 ptr2
= strchrW(ptr1
, '#');
1966 size
+= strlenW(ptr2
);
1968 ptr1
= This
->wine_url
+ strlenW(This
->wine_url
);
1970 size
+= strlenW(This
->wine_url
);
1976 new_url
= heap_alloc(size
*sizeof(WCHAR
));
1977 memcpy(new_url
, This
->wine_url
, (ptr1
-This
->wine_url
)*sizeof(WCHAR
));
1978 ptr
= new_url
+ (ptr1
-This
->wine_url
);
1981 MultiByteToWideChar(CP_ACP
, 0, query
, -1, ptr
, len
);
1989 TRACE("setting %s\n", debugstr_w(new_url
));
1991 heap_free(This
->wine_url
);
1992 This
->wine_url
= new_url
;
1996 static nsresult NSAPI
nsURL_GetRef(nsIURL
*iface
, nsACString
*aRef
)
1998 nsWineURI
*This
= NSURI_THIS(iface
);
2000 TRACE("(%p)->(%p)\n", This
, aRef
);
2003 return nsIURL_GetRef(This
->nsurl
, aRef
);
2005 FIXME("default action not implemented\n");
2006 return NS_ERROR_NOT_IMPLEMENTED
;
2009 static nsresult NSAPI
nsURL_SetRef(nsIURL
*iface
, const nsACString
*aRef
)
2011 nsWineURI
*This
= NSURI_THIS(iface
);
2014 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aRef
));
2017 return nsIURL_SetRef(This
->nsurl
, aRef
);
2019 nsACString_GetData(aRef
, &refa
);
2023 FIXME("default action not implemented\n");
2024 return NS_ERROR_NOT_IMPLEMENTED
;
2027 static nsresult NSAPI
nsURL_GetDirectory(nsIURL
*iface
, nsACString
*aDirectory
)
2029 nsWineURI
*This
= NSURI_THIS(iface
);
2031 TRACE("(%p)->(%p)\n", This
, aDirectory
);
2034 return nsIURL_GetDirectory(This
->nsurl
, aDirectory
);
2036 FIXME("default action not implemented\n");
2037 return NS_ERROR_NOT_IMPLEMENTED
;
2040 static nsresult NSAPI
nsURL_SetDirectory(nsIURL
*iface
, const nsACString
*aDirectory
)
2042 nsWineURI
*This
= NSURI_THIS(iface
);
2044 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aDirectory
));
2047 return nsIURL_SetDirectory(This
->nsurl
, aDirectory
);
2049 FIXME("default action not implemented\n");
2050 return NS_ERROR_NOT_IMPLEMENTED
;
2053 static nsresult NSAPI
nsURL_GetFileName(nsIURL
*iface
, nsACString
*aFileName
)
2055 nsWineURI
*This
= NSURI_THIS(iface
);
2057 TRACE("(%p)->(%p)\n", This
, aFileName
);
2060 return nsIURL_GetFileName(This
->nsurl
, aFileName
);
2062 FIXME("default action not implemented\n");
2063 return NS_ERROR_NOT_IMPLEMENTED
;
2066 static nsresult NSAPI
nsURL_SetFileName(nsIURL
*iface
, const nsACString
*aFileName
)
2068 nsWineURI
*This
= NSURI_THIS(iface
);
2070 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileName
));
2073 return nsIURL_SetFileName(This
->nsurl
, aFileName
);
2075 FIXME("default action not implemented\n");
2076 return NS_ERROR_NOT_IMPLEMENTED
;
2079 static nsresult NSAPI
nsURL_GetFileBaseName(nsIURL
*iface
, nsACString
*aFileBaseName
)
2081 nsWineURI
*This
= NSURI_THIS(iface
);
2083 TRACE("(%p)->(%p)\n", This
, aFileBaseName
);
2086 return nsIURL_GetFileBaseName(This
->nsurl
, aFileBaseName
);
2088 FIXME("default action not implemented\n");
2089 return NS_ERROR_NOT_IMPLEMENTED
;
2092 static nsresult NSAPI
nsURL_SetFileBaseName(nsIURL
*iface
, const nsACString
*aFileBaseName
)
2094 nsWineURI
*This
= NSURI_THIS(iface
);
2096 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileBaseName
));
2099 return nsIURL_SetFileBaseName(This
->nsurl
, aFileBaseName
);
2101 FIXME("default action not implemented\n");
2102 return NS_ERROR_NOT_IMPLEMENTED
;
2105 static nsresult NSAPI
nsURL_GetFileExtension(nsIURL
*iface
, nsACString
*aFileExtension
)
2107 nsWineURI
*This
= NSURI_THIS(iface
);
2109 TRACE("(%p)->(%p)\n", This
, aFileExtension
);
2112 return nsIURL_GetFileExtension(This
->nsurl
, aFileExtension
);
2114 FIXME("default action not implemented\n");
2115 return NS_ERROR_NOT_IMPLEMENTED
;
2118 static nsresult NSAPI
nsURL_SetFileExtension(nsIURL
*iface
, const nsACString
*aFileExtension
)
2120 nsWineURI
*This
= NSURI_THIS(iface
);
2122 TRACE("(%p)->(%s)\n", This
, debugstr_nsacstr(aFileExtension
));
2125 return nsIURL_SetFileExtension(This
->nsurl
, aFileExtension
);
2127 FIXME("default action not implemented\n");
2128 return NS_ERROR_NOT_IMPLEMENTED
;
2131 static nsresult NSAPI
nsURL_GetCommonBaseSpec(nsIURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2133 nsWineURI
*This
= NSURI_THIS(iface
);
2135 TRACE("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2138 return nsIURL_GetCommonBaseSpec(This
->nsurl
, aURIToCompare
, _retval
);
2140 FIXME("default action not implemented\n");
2141 return NS_ERROR_NOT_IMPLEMENTED
;
2144 static nsresult NSAPI
nsURL_GetRelativeSpec(nsIURL
*iface
, nsIURI
*aURIToCompare
, nsACString
*_retval
)
2146 nsWineURI
*This
= NSURI_THIS(iface
);
2148 TRACE("(%p)->(%p %p)\n", This
, aURIToCompare
, _retval
);
2151 return nsIURL_GetRelativeSpec(This
->nsurl
, aURIToCompare
, _retval
);
2153 FIXME("default action not implemented\n");
2154 return NS_ERROR_NOT_IMPLEMENTED
;
2159 static const nsIURLVtbl nsURLVtbl
= {
2160 nsURI_QueryInterface
,
2188 nsURI_GetOriginCharset
,
2201 nsURL_GetFileBaseName
,
2202 nsURL_SetFileBaseName
,
2203 nsURL_GetFileExtension
,
2204 nsURL_SetFileExtension
,
2205 nsURL_GetCommonBaseSpec
,
2206 nsURL_GetRelativeSpec
2209 static nsresult
create_uri(nsIURI
*uri
, HTMLWindow
*window
, NSContainer
*container
, nsWineURI
**_retval
)
2211 nsWineURI
*ret
= heap_alloc_zero(sizeof(nsWineURI
));
2213 ret
->lpIURLVtbl
= &nsURLVtbl
;
2217 set_uri_nscontainer(ret
, container
);
2218 set_uri_window(ret
, window
);
2221 nsIURI_QueryInterface(uri
, &IID_nsIURL
, (void**)&ret
->nsurl
);
2223 TRACE("retval=%p\n", ret
);
2228 HRESULT
create_doc_uri(HTMLWindow
*window
, WCHAR
*url
, nsWineURI
**ret
)
2233 nsres
= create_uri(NULL
, window
, window
->doc_obj
->nscontainer
, &uri
);
2234 if(NS_FAILED(nsres
))
2237 set_wine_url(uri
, url
);
2238 uri
->is_doc_uri
= TRUE
;
2245 const nsIProtocolHandlerVtbl
*lpProtocolHandlerVtbl
;
2249 nsIProtocolHandler
*nshandler
;
2250 } nsProtocolHandler
;
2252 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
2254 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
2256 static nsresult NSAPI
nsProtocolHandler_QueryInterface(nsIProtocolHandler
*iface
, nsIIDRef riid
,
2259 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2263 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
2264 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
2265 *result
= NSPROTHANDLER(This
);
2266 }else if(IsEqualGUID(&IID_nsIProtocolHandler
, riid
)) {
2267 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This
, result
);
2268 *result
= NSPROTHANDLER(This
);
2269 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler
, riid
)) {
2270 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This
, result
);
2271 return NS_NOINTERFACE
;
2275 nsISupports_AddRef((nsISupports
*)*result
);
2279 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
2280 return NS_NOINTERFACE
;
2283 static nsrefcnt NSAPI
nsProtocolHandler_AddRef(nsIProtocolHandler
*iface
)
2285 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2286 LONG ref
= InterlockedIncrement(&This
->ref
);
2288 TRACE("(%p) ref=%d\n", This
, ref
);
2293 static nsrefcnt NSAPI
nsProtocolHandler_Release(nsIProtocolHandler
*iface
)
2295 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2296 LONG ref
= InterlockedDecrement(&This
->ref
);
2298 TRACE("(%p) ref=%d\n", This
, ref
);
2302 nsIProtocolHandler_Release(This
->nshandler
);
2309 static nsresult NSAPI
nsProtocolHandler_GetScheme(nsIProtocolHandler
*iface
, nsACString
*aScheme
)
2311 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2313 TRACE("(%p)->(%p)\n", This
, aScheme
);
2316 return nsIProtocolHandler_GetScheme(This
->nshandler
, aScheme
);
2317 return NS_ERROR_NOT_IMPLEMENTED
;
2320 static nsresult NSAPI
nsProtocolHandler_GetDefaultPort(nsIProtocolHandler
*iface
,
2321 PRInt32
*aDefaultPort
)
2323 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2325 TRACE("(%p)->(%p)\n", This
, aDefaultPort
);
2328 return nsIProtocolHandler_GetDefaultPort(This
->nshandler
, aDefaultPort
);
2329 return NS_ERROR_NOT_IMPLEMENTED
;
2332 static nsresult NSAPI
nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler
*iface
,
2333 PRUint32
*aProtocolFlags
)
2335 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2337 TRACE("(%p)->(%p)\n", This
, aProtocolFlags
);
2340 return nsIProtocolHandler_GetProtocolFlags(This
->nshandler
, aProtocolFlags
);
2341 return NS_ERROR_NOT_IMPLEMENTED
;
2344 static nsresult NSAPI
nsProtocolHandler_NewURI(nsIProtocolHandler
*iface
,
2345 const nsACString
*aSpec
, const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
2347 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2349 TRACE("((%p)->%s %s %p %p)\n", This
, debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
2353 return nsIProtocolHandler_NewURI(This
->nshandler
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2354 return NS_ERROR_NOT_IMPLEMENTED
;
2357 static nsresult NSAPI
nsProtocolHandler_NewChannel(nsIProtocolHandler
*iface
,
2358 nsIURI
*aURI
, nsIChannel
**_retval
)
2360 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2362 TRACE("(%p)->(%p %p)\n", This
, aURI
, _retval
);
2365 return nsIProtocolHandler_NewChannel(This
->nshandler
, aURI
, _retval
);
2366 return NS_ERROR_NOT_IMPLEMENTED
;
2369 static nsresult NSAPI
nsProtocolHandler_AllowPort(nsIProtocolHandler
*iface
,
2370 PRInt32 port
, const char *scheme
, PRBool
*_retval
)
2372 nsProtocolHandler
*This
= NSPROTHANDLER_THIS(iface
);
2374 TRACE("(%p)->(%d %s %p)\n", This
, port
, debugstr_a(scheme
), _retval
);
2377 return nsIProtocolHandler_AllowPort(This
->nshandler
, port
, scheme
, _retval
);
2378 return NS_ERROR_NOT_IMPLEMENTED
;
2381 #undef NSPROTHANDLER_THIS
2383 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl
= {
2384 nsProtocolHandler_QueryInterface
,
2385 nsProtocolHandler_AddRef
,
2386 nsProtocolHandler_Release
,
2387 nsProtocolHandler_GetScheme
,
2388 nsProtocolHandler_GetDefaultPort
,
2389 nsProtocolHandler_GetProtocolFlags
,
2390 nsProtocolHandler_NewURI
,
2391 nsProtocolHandler_NewChannel
,
2392 nsProtocolHandler_AllowPort
2395 static nsIProtocolHandler
*create_protocol_handler(nsIProtocolHandler
*nshandler
)
2397 nsProtocolHandler
*ret
= heap_alloc(sizeof(nsProtocolHandler
));
2399 ret
->lpProtocolHandlerVtbl
= &nsProtocolHandlerVtbl
;
2401 ret
->nshandler
= nshandler
;
2403 return NSPROTHANDLER(ret
);
2406 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*,nsIIDRef
,void**);
2408 static nsrefcnt NSAPI
nsIOService_AddRef(nsIIOService
*iface
)
2413 static nsrefcnt NSAPI
nsIOService_Release(nsIIOService
*iface
)
2418 static nsresult NSAPI
nsIOService_GetProtocolHandler(nsIIOService
*iface
, const char *aScheme
,
2419 nsIProtocolHandler
**_retval
)
2421 nsIExternalProtocolHandler
*nsexthandler
;
2422 nsIProtocolHandler
*nshandler
;
2425 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
2427 nsres
= nsIIOService_GetProtocolHandler(nsio
, aScheme
, &nshandler
);
2428 if(NS_FAILED(nsres
)) {
2429 WARN("GetProtocolHandler failed: %08x\n", nsres
);
2433 nsres
= nsIProtocolHandler_QueryInterface(nshandler
, &IID_nsIExternalProtocolHandler
,
2434 (void**)&nsexthandler
);
2435 if(NS_FAILED(nsres
)) {
2436 *_retval
= nshandler
;
2440 nsIExternalProtocolHandler_Release(nsexthandler
);
2441 *_retval
= create_protocol_handler(nshandler
);
2442 TRACE("return %p\n", *_retval
);
2446 static nsresult NSAPI
nsIOService_GetProtocolFlags(nsIIOService
*iface
, const char *aScheme
,
2449 TRACE("(%s %p)\n", debugstr_a(aScheme
), _retval
);
2450 return nsIIOService_GetProtocolFlags(nsio
, aScheme
, _retval
);
2453 static BOOL
is_gecko_special_uri(const char *spec
)
2455 static const char *special_schemes
[] = {"chrome:", "jar:", "resource:", "javascript:", "wyciwyg:"};
2458 for(i
=0; i
< sizeof(special_schemes
)/sizeof(*special_schemes
); i
++) {
2459 if(!strncasecmp(spec
, special_schemes
[i
], strlen(special_schemes
[i
])))
2466 static nsresult NSAPI
nsIOService_NewURI(nsIIOService
*iface
, const nsACString
*aSpec
,
2467 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval
)
2469 nsWineURI
*wine_uri
, *base_wine_uri
= NULL
;
2470 const char *spec
= NULL
;
2471 HTMLWindow
*window
= NULL
;
2473 LPCWSTR base_wine_url
= NULL
;
2474 nsACString spec_str
;
2478 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
),
2481 nsACString_GetData(aSpec
, &spec
);
2482 if(is_gecko_special_uri(spec
))
2483 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2485 if(!strncmp(spec
, "wine:", 5))
2489 PARSEDURLA parsed_url
= {sizeof(PARSEDURLA
)};
2491 nsres
= nsIURI_QueryInterface(aBaseURI
, &IID_nsWineURI
, (void**)&base_wine_uri
);
2492 if(NS_SUCCEEDED(nsres
)) {
2493 base_wine_url
= base_wine_uri
->wine_url
;
2494 if(base_wine_uri
->window_ref
&& base_wine_uri
->window_ref
->window
) {
2495 window
= base_wine_uri
->window_ref
->window
;
2496 IHTMLWindow2_AddRef(HTMLWINDOW2(window
));
2498 TRACE("base url: %s window: %p\n", debugstr_w(base_wine_url
), window
);
2499 }else if(FAILED(ParseURLA(spec
, &parsed_url
))) {
2500 TRACE("not wraping\n");
2501 return nsIIOService_NewURI(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2503 WARN("Could not get base nsWineURI: %08x\n", nsres
);
2507 nsACString_InitDepend(&spec_str
, spec
);
2508 nsres
= nsIIOService_NewURI(nsio
, &spec_str
, aOriginCharset
, aBaseURI
, &uri
);
2509 nsACString_Finish(&spec_str
);
2510 if(NS_FAILED(nsres
))
2511 TRACE("NewURI failed: %08x\n", nsres
);
2513 nsres
= create_uri(uri
, window
, NULL
, &wine_uri
);
2514 *_retval
= (nsIURI
*)wine_uri
;
2517 IHTMLWindow2_Release(HTMLWINDOW2(window
));
2520 WCHAR url
[INTERNET_MAX_URL_LENGTH
], rel_url
[INTERNET_MAX_URL_LENGTH
];
2524 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, rel_url
, sizeof(rel_url
)/sizeof(WCHAR
));
2526 hres
= CoInternetCombineUrl(base_wine_url
, rel_url
,
2527 URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
2528 url
, sizeof(url
)/sizeof(WCHAR
), &len
, 0);
2530 set_wine_url(wine_uri
, url
);
2532 WARN("CoCombineUrl failed: %08x\n", hres
);
2534 WCHAR url
[INTERNET_MAX_URL_LENGTH
];
2536 MultiByteToWideChar(CP_ACP
, 0, spec
, -1, url
, sizeof(url
)/sizeof(WCHAR
));
2537 set_wine_url(wine_uri
, url
);
2541 nsIURI_Release(NSURI(base_wine_uri
));
2546 static nsresult NSAPI
nsIOService_NewFileURI(nsIIOService
*iface
, nsIFile
*aFile
,
2549 TRACE("(%p %p)\n", aFile
, _retval
);
2550 return nsIIOService_NewFileURI(nsio
, aFile
, _retval
);
2553 static nsresult NSAPI
nsIOService_NewChannelFromURI(nsIIOService
*iface
, nsIURI
*aURI
,
2554 nsIChannel
**_retval
)
2556 PARSEDURLW parsed_url
= {sizeof(PARSEDURLW
)};
2558 nsWineURI
*wine_uri
;
2561 TRACE("(%p %p)\n", aURI
, _retval
);
2563 nsres
= nsIURI_QueryInterface(aURI
, &IID_nsWineURI
, (void**)&wine_uri
);
2564 if(NS_FAILED(nsres
)) {
2565 TRACE("Could not get nsWineURI: %08x\n", nsres
);
2566 return nsIIOService_NewChannelFromURI(nsio
, aURI
, _retval
);
2569 ret
= heap_alloc_zero(sizeof(nsChannel
));
2571 ret
->lpHttpChannelVtbl
= &nsChannelVtbl
;
2572 ret
->lpUploadChannelVtbl
= &nsUploadChannelVtbl
;
2573 ret
->lpIHttpChannelInternalVtbl
= &nsHttpChannelInternalVtbl
;
2575 ret
->uri
= wine_uri
;
2576 list_init(&ret
->response_headers
);
2578 nsIURI_AddRef(aURI
);
2579 ret
->original_uri
= aURI
;
2580 ret
->url_scheme
= wine_uri
->wine_url
&& SUCCEEDED(ParseURLW(wine_uri
->wine_url
, &parsed_url
))
2581 ? parsed_url
.nScheme
: URL_SCHEME_UNKNOWN
;
2583 *_retval
= NSCHANNEL(ret
);
2587 static nsresult NSAPI
nsIOService_NewChannel(nsIIOService
*iface
, const nsACString
*aSpec
,
2588 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIChannel
**_retval
)
2590 TRACE("(%s %s %p %p)\n", debugstr_nsacstr(aSpec
), debugstr_a(aOriginCharset
), aBaseURI
, _retval
);
2591 return nsIIOService_NewChannel(nsio
, aSpec
, aOriginCharset
, aBaseURI
, _retval
);
2594 static nsresult NSAPI
nsIOService_GetOffline(nsIIOService
*iface
, PRBool
*aOffline
)
2596 TRACE("(%p)\n", aOffline
);
2597 return nsIIOService_GetOffline(nsio
, aOffline
);
2600 static nsresult NSAPI
nsIOService_SetOffline(nsIIOService
*iface
, PRBool aOffline
)
2602 TRACE("(%x)\n", aOffline
);
2603 return nsIIOService_SetOffline(nsio
, aOffline
);
2606 static nsresult NSAPI
nsIOService_AllowPort(nsIIOService
*iface
, PRInt32 aPort
,
2607 const char *aScheme
, PRBool
*_retval
)
2609 TRACE("(%d %s %p)\n", aPort
, debugstr_a(aScheme
), _retval
);
2610 return nsIIOService_AllowPort(nsio
, aPort
, debugstr_a(aScheme
), _retval
);
2613 static nsresult NSAPI
nsIOService_ExtractScheme(nsIIOService
*iface
, const nsACString
*urlString
,
2614 nsACString
* _retval
)
2616 TRACE("(%s %p)\n", debugstr_nsacstr(urlString
), _retval
);
2617 return nsIIOService_ExtractScheme(nsio
, urlString
, _retval
);
2620 static const nsIIOServiceVtbl nsIOServiceVtbl
= {
2621 nsIOService_QueryInterface
,
2623 nsIOService_Release
,
2624 nsIOService_GetProtocolHandler
,
2625 nsIOService_GetProtocolFlags
,
2627 nsIOService_NewFileURI
,
2628 nsIOService_NewChannelFromURI
,
2629 nsIOService_NewChannel
,
2630 nsIOService_GetOffline
,
2631 nsIOService_SetOffline
,
2632 nsIOService_AllowPort
,
2633 nsIOService_ExtractScheme
2636 static nsIIOService nsIOService
= { &nsIOServiceVtbl
};
2638 static nsresult NSAPI
nsNetUtil_QueryInterface(nsINetUtil
*iface
, nsIIDRef riid
,
2641 return nsIIOService_QueryInterface(&nsIOService
, riid
, result
);
2644 static nsrefcnt NSAPI
nsNetUtil_AddRef(nsINetUtil
*iface
)
2649 static nsrefcnt NSAPI
nsNetUtil_Release(nsINetUtil
*iface
)
2654 static nsresult NSAPI
nsNetUtil_ParseContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
2655 nsACString
*aCharset
, PRBool
*aHadCharset
, nsACString
*aContentType
)
2657 TRACE("(%s %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aHadCharset
, aContentType
);
2659 return nsINetUtil_ParseContentType(net_util
, aTypeHeader
, aCharset
, aHadCharset
, aContentType
);
2662 static nsresult NSAPI
nsNetUtil_ProtocolHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, PRUint32 aFlags
, PRBool
*_retval
)
2666 return nsINetUtil_ProtocolHasFlags(net_util
, aURI
, aFlags
, _retval
);
2669 static nsresult NSAPI
nsNetUtil_URIChainHasFlags(nsINetUtil
*iface
, nsIURI
*aURI
, PRUint32 aFlags
, PRBool
*_retval
)
2671 TRACE("(%p %08x %p)\n", aURI
, aFlags
, _retval
);
2673 if(aFlags
== (1<<11)) {
2678 return nsINetUtil_URIChainHasFlags(net_util
, aURI
, aFlags
, _retval
);
2681 static nsresult NSAPI
nsNetUtil_ToImmutableURI(nsINetUtil
*iface
, nsIURI
*aURI
, nsIURI
**_retval
)
2683 TRACE("(%p %p)\n", aURI
, _retval
);
2685 return nsINetUtil_ToImmutableURI(net_util
, aURI
, _retval
);
2688 static nsresult NSAPI
nsNetUtil_EscapeString(nsINetUtil
*iface
, const nsACString
*aString
,
2689 PRUint32 aEscapeType
, nsACString
*_retval
)
2691 TRACE("(%s %x %p)\n", debugstr_nsacstr(aString
), aEscapeType
, _retval
);
2693 return nsINetUtil_EscapeString(net_util
, aString
, aEscapeType
, _retval
);
2696 static nsresult NSAPI
nsNetUtil_EscapeURL(nsINetUtil
*iface
, const nsACString
*aStr
, PRUint32 aFlags
,
2697 nsACString
*_retval
)
2699 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
2701 return nsINetUtil_EscapeURL(net_util
, aStr
, aFlags
, _retval
);
2704 static nsresult NSAPI
nsNetUtil_UnescapeString(nsINetUtil
*iface
, const nsACString
*aStr
,
2705 PRUint32 aFlags
, nsACString
*_retval
)
2707 TRACE("(%s %08x %p)\n", debugstr_nsacstr(aStr
), aFlags
, _retval
);
2709 return nsINetUtil_UnescapeString(net_util
, aStr
, aFlags
, _retval
);
2712 static nsresult NSAPI
nsNetUtil_ExtractCharsetFromContentType(nsINetUtil
*iface
, const nsACString
*aTypeHeader
,
2713 nsACString
*aCharset
, PRInt32
*aCharsetStart
, PRInt32
*aCharsetEnd
, PRBool
*_retval
)
2715 TRACE("(%s %p %p %p %p)\n", debugstr_nsacstr(aTypeHeader
), aCharset
, aCharsetStart
,
2716 aCharsetEnd
, _retval
);
2718 return nsINetUtil_ExtractCharsetFromContentType(net_util
, aTypeHeader
, aCharset
, aCharsetStart
, aCharsetEnd
, _retval
);
2721 static const nsINetUtilVtbl nsNetUtilVtbl
= {
2722 nsNetUtil_QueryInterface
,
2725 nsNetUtil_ParseContentType
,
2726 nsNetUtil_ProtocolHasFlags
,
2727 nsNetUtil_URIChainHasFlags
,
2728 nsNetUtil_ToImmutableURI
,
2729 nsNetUtil_EscapeString
,
2730 nsNetUtil_EscapeURL
,
2731 nsNetUtil_UnescapeString
,
2732 nsNetUtil_ExtractCharsetFromContentType
2735 static nsINetUtil nsNetUtil
= { &nsNetUtilVtbl
};
2737 static nsresult NSAPI
nsIOService_QueryInterface(nsIIOService
*iface
, nsIIDRef riid
,
2742 if(IsEqualGUID(&IID_nsISupports
, riid
))
2743 *result
= &nsIOService
;
2744 else if(IsEqualGUID(&IID_nsIIOService
, riid
))
2745 *result
= &nsIOService
;
2746 else if(IsEqualGUID(&IID_nsINetUtil
, riid
))
2747 *result
= &nsNetUtil
;
2750 nsISupports_AddRef((nsISupports
*)*result
);
2754 FIXME("(%s %p)\n", debugstr_guid(riid
), result
);
2755 return NS_NOINTERFACE
;
2758 static nsresult NSAPI
nsIOServiceFactory_QueryInterface(nsIFactory
*iface
, nsIIDRef riid
,
2763 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
2764 TRACE("(IID_nsISupports %p)\n", result
);
2766 }else if(IsEqualGUID(&IID_nsIFactory
, riid
)) {
2767 TRACE("(IID_nsIFactory %p)\n", result
);
2772 nsIFactory_AddRef(iface
);
2776 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
2777 return NS_NOINTERFACE
;
2780 static nsrefcnt NSAPI
nsIOServiceFactory_AddRef(nsIFactory
*iface
)
2785 static nsrefcnt NSAPI
nsIOServiceFactory_Release(nsIFactory
*iface
)
2790 static nsresult NSAPI
nsIOServiceFactory_CreateInstance(nsIFactory
*iface
,
2791 nsISupports
*aOuter
, const nsIID
*iid
, void **result
)
2793 return nsIIOService_QueryInterface(&nsIOService
, iid
, result
);
2796 static nsresult NSAPI
nsIOServiceFactory_LockFactory(nsIFactory
*iface
, PRBool lock
)
2798 WARN("(%x)\n", lock
);
2802 static const nsIFactoryVtbl nsIOServiceFactoryVtbl
= {
2803 nsIOServiceFactory_QueryInterface
,
2804 nsIOServiceFactory_AddRef
,
2805 nsIOServiceFactory_Release
,
2806 nsIOServiceFactory_CreateInstance
,
2807 nsIOServiceFactory_LockFactory
2810 static nsIFactory nsIOServiceFactory
= { &nsIOServiceFactoryVtbl
};
2812 void init_nsio(nsIComponentManager
*component_manager
, nsIComponentRegistrar
*registrar
)
2814 nsIFactory
*old_factory
= NULL
;
2817 nsres
= nsIComponentManager_GetClassObject(component_manager
, &NS_IOSERVICE_CID
,
2818 &IID_nsIFactory
, (void**)&old_factory
);
2819 if(NS_FAILED(nsres
)) {
2820 ERR("Could not get factory: %08x\n", nsres
);
2824 nsres
= nsIFactory_CreateInstance(old_factory
, NULL
, &IID_nsIIOService
, (void**)&nsio
);
2825 if(NS_FAILED(nsres
)) {
2826 ERR("Couldn not create nsIOService instance %08x\n", nsres
);
2827 nsIFactory_Release(old_factory
);
2831 nsres
= nsIIOService_QueryInterface(nsio
, &IID_nsINetUtil
, (void**)&net_util
);
2832 if(NS_FAILED(nsres
)) {
2833 WARN("Could not get nsINetUtil interface: %08x\n", nsres
);
2834 nsIIOService_Release(nsio
);
2838 nsres
= nsIComponentRegistrar_UnregisterFactory(registrar
, &NS_IOSERVICE_CID
, old_factory
);
2839 nsIFactory_Release(old_factory
);
2840 if(NS_FAILED(nsres
))
2841 ERR("UnregisterFactory failed: %08x\n", nsres
);
2843 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_IOSERVICE_CID
,
2844 NS_IOSERVICE_CLASSNAME
, NS_IOSERVICE_CONTRACTID
, &nsIOServiceFactory
);
2845 if(NS_FAILED(nsres
))
2846 ERR("RegisterFactory failed: %08x\n", nsres
);
2849 void release_nsio(void)
2852 nsINetUtil_Release(net_util
);
2857 nsIIOService_Release(nsio
);