2 * Copyright 2006-2007 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
37 #include "mshtml_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
41 #define LOAD_INITIAL_DOCUMENT_URI 0x80000
43 #define NS_IOSERVICE_CLASSNAME "nsIOService"
44 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
46 static const IID NS_IOSERVICE_CID =
47 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
49 static nsIIOService *nsio = NULL;
50 static nsINetUtil *net_util;
52 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
55 const nsIWineURIVtbl *lpWineURIVtbl;
60 NSContainer *container;
66 #define NSURI(x) ((nsIURI*) &(x)->lpWineURIVtbl)
67 #define NSWINEURI(x) ((nsIWineURI*) &(x)->lpWineURIVtbl)
69 static nsresult create_uri(nsIURI*,NSContainer*,nsIWineURI**);
71 HRESULT nsuri_to_url(LPCWSTR nsuri, BSTR *ret)
73 const WCHAR *ptr = nsuri;
75 static const WCHAR wine_prefixW[] = {'w','i','n','e',':'};
77 if(!strncmpW(nsuri, wine_prefixW, sizeof(wine_prefixW)/sizeof(WCHAR)))
78 ptr += sizeof(wine_prefixW)/sizeof(WCHAR);
80 *ret = SysAllocString(ptr);
84 TRACE("%s -> %s\n", debugstr_w(nsuri), debugstr_w(*ret));
88 static BOOL exec_shldocvw_67(HTMLDocument *doc, LPCWSTR url)
90 IOleCommandTarget *cmdtrg = NULL;
93 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget,
96 VARIANT varUrl, varRes;
98 V_VT(&varUrl) = VT_BSTR;
99 V_BSTR(&varUrl) = SysAllocString(url);
100 V_VT(&varRes) = VT_BOOL;
102 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
104 IOleCommandTarget_Release(cmdtrg);
105 SysFreeString(V_BSTR(&varUrl));
107 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
108 TRACE("got VARIANT_FALSE, do not load\n");
116 static BOOL before_async_open(nsChannel *channel, NSContainer *container)
118 IServiceProvider *service_provider;
119 HTMLDocument *doc = container->doc;
124 nsIWineURI_GetWineURL(channel->uri, &uri);
126 ERR("GetWineURL returned NULL\n");
131 NSContainer *container_iter = container;
133 hlnf = HLNF_OPENINNEWWINDOW;
134 while(!container_iter->doc)
135 container_iter = container_iter->parent;
136 doc = container_iter->doc;
142 if(!hlnf && !exec_shldocvw_67(doc, uri))
145 hres = IOleClientSite_QueryInterface(doc->client, &IID_IServiceProvider,
146 (void**)&service_provider);
147 if(SUCCEEDED(hres)) {
148 IHlinkFrame *hlink_frame;
150 hres = IServiceProvider_QueryService(service_provider, &IID_IHlinkFrame,
151 &IID_IHlinkFrame, (void**)&hlink_frame);
152 IServiceProvider_Release(service_provider);
153 if(SUCCEEDED(hres)) {
154 hlink_frame_navigate(doc, hlink_frame, uri, channel->post_data_stream, hlnf);
155 IHlinkFrame_Release(hlink_frame);
164 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
166 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
168 nsChannel *This = NSCHANNEL_THIS(iface);
172 if(IsEqualGUID(&IID_nsISupports, riid)) {
173 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
174 *result = NSCHANNEL(This);
175 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
176 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
177 *result = NSCHANNEL(This);
178 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
179 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
180 *result = NSCHANNEL(This);
181 }else if(This->http_channel && IsEqualGUID(&IID_nsIHttpChannel, riid)) {
182 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
183 *result = NSHTTPCHANNEL(This);
184 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
185 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
186 *result = NSUPCHANNEL(This);
190 nsIChannel_AddRef(NSCHANNEL(This));
194 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
197 return nsIChannel_QueryInterface(This->channel, riid, result);
198 return NS_NOINTERFACE;
201 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
203 nsChannel *This = NSCHANNEL_THIS(iface);
204 nsrefcnt ref = InterlockedIncrement(&This->ref);
206 TRACE("(%p) ref=%d\n", This, ref);
211 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
213 nsChannel *This = NSCHANNEL_THIS(iface);
214 LONG ref = InterlockedDecrement(&This->ref);
217 nsIWineURI_Release(This->uri);
219 nsIChannel_Release(This->channel);
220 if(This->http_channel)
221 nsIHttpChannel_Release(This->http_channel);
223 nsISupports_Release(This->owner);
224 if(This->post_data_stream)
225 nsIInputStream_Release(This->post_data_stream);
227 nsILoadGroup_Release(This->load_group);
228 if(This->notif_callback)
229 nsIInterfaceRequestor_Release(This->notif_callback);
230 if(This->original_uri)
231 nsIURI_Release(This->original_uri);
232 heap_free(This->content_type);
233 heap_free(This->charset);
240 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
242 nsChannel *This = NSCHANNEL_THIS(iface);
244 TRACE("(%p)->(%p)\n", This, aName);
247 return nsIChannel_GetName(This->channel, aName);
249 return NS_ERROR_NOT_IMPLEMENTED;
252 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
254 nsChannel *This = NSCHANNEL_THIS(iface);
256 TRACE("(%p)->(%p)\n", This, _retval);
259 return nsIChannel_IsPending(This->channel, _retval);
261 FIXME("default action not implemented\n");
262 return NS_ERROR_NOT_IMPLEMENTED;
265 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
267 nsChannel *This = NSCHANNEL_THIS(iface);
269 TRACE("(%p)->(%p)\n", This, aStatus);
272 return nsIChannel_GetStatus(This->channel, aStatus);
274 TRACE("returning NS_OK\n");
275 return *aStatus = NS_OK;
278 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
280 nsChannel *This = NSCHANNEL_THIS(iface);
282 TRACE("(%p)->(%08x)\n", This, aStatus);
285 return nsIChannel_Cancel(This->channel, aStatus);
287 FIXME("default action not implemented\n");
288 return NS_ERROR_NOT_IMPLEMENTED;
291 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
293 nsChannel *This = NSCHANNEL_THIS(iface);
295 TRACE("(%p)\n", This);
298 return nsIChannel_Suspend(This->channel);
300 FIXME("default action not implemented\n");
301 return NS_ERROR_NOT_IMPLEMENTED;
304 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
306 nsChannel *This = NSCHANNEL_THIS(iface);
308 TRACE("(%p)\n", This);
311 return nsIChannel_Resume(This->channel);
313 FIXME("default action not implemented\n");
314 return NS_ERROR_NOT_IMPLEMENTED;
317 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
319 nsChannel *This = NSCHANNEL_THIS(iface);
321 TRACE("(%p)->(%p)\n", This, aLoadGroup);
324 nsILoadGroup_AddRef(This->load_group);
326 *aLoadGroup = This->load_group;
330 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
332 nsChannel *This = NSCHANNEL_THIS(iface);
334 TRACE("(%p)->(%p)\n", This, aLoadGroup);
337 nsILoadGroup_Release(This->load_group);
339 nsILoadGroup_AddRef(aLoadGroup);
341 This->load_group = aLoadGroup;
344 return nsIChannel_SetLoadGroup(This->channel, aLoadGroup);
348 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
350 nsChannel *This = NSCHANNEL_THIS(iface);
352 TRACE("(%p)->(%p)\n", This, aLoadFlags);
354 *aLoadFlags = This->load_flags;
358 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
360 nsChannel *This = NSCHANNEL_THIS(iface);
362 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
364 This->load_flags = aLoadFlags;
367 return nsIChannel_SetLoadFlags(This->channel, aLoadFlags);
371 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
373 nsChannel *This = NSCHANNEL_THIS(iface);
375 TRACE("(%p)->(%p)\n", This, aOriginalURI);
377 if(This->original_uri)
378 nsIURI_AddRef(This->original_uri);
380 *aOriginalURI = This->original_uri;
384 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
386 nsChannel *This = NSCHANNEL_THIS(iface);
388 TRACE("(%p)->(%p)\n", This, aOriginalURI);
390 if(This->original_uri)
391 nsIURI_Release(This->original_uri);
393 nsIURI_AddRef(aOriginalURI);
394 This->original_uri = aOriginalURI;
397 return nsIChannel_SetOriginalURI(This->channel, aOriginalURI);
401 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
403 nsChannel *This = NSCHANNEL_THIS(iface);
405 TRACE("(%p)->(%p)\n", This, aURI);
407 nsIWineURI_AddRef(This->uri);
408 *aURI = (nsIURI*)This->uri;
413 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
415 nsChannel *This = NSCHANNEL_THIS(iface);
417 TRACE("(%p)->(%p)\n", This, aOwner);
420 return nsIChannel_GetOwner(This->channel, aOwner);
423 nsISupports_AddRef(This->owner);
424 *aOwner = This->owner;
429 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
431 nsChannel *This = NSCHANNEL_THIS(iface);
433 TRACE("(%p)->(%p)\n", This, aOwner);
436 return nsIChannel_SetOwner(This->channel, aOwner);
439 nsISupports_AddRef(aOwner);
441 nsISupports_Release(This->owner);
442 This->owner = aOwner;
447 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
448 nsIInterfaceRequestor **aNotificationCallbacks)
450 nsChannel *This = NSCHANNEL_THIS(iface);
452 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
454 if(This->notif_callback)
455 nsIInterfaceRequestor_AddRef(This->notif_callback);
456 *aNotificationCallbacks = This->notif_callback;
461 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
462 nsIInterfaceRequestor *aNotificationCallbacks)
464 nsChannel *This = NSCHANNEL_THIS(iface);
466 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
468 if(This->notif_callback)
469 nsIInterfaceRequestor_Release(This->notif_callback);
470 if(aNotificationCallbacks)
471 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
473 This->notif_callback = aNotificationCallbacks;
476 return nsIChannel_SetNotificationCallbacks(This->channel, aNotificationCallbacks);
480 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
482 nsChannel *This = NSCHANNEL_THIS(iface);
484 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
487 return nsIChannel_GetSecurityInfo(This->channel, aSecurityInfo);
489 FIXME("default action not implemented\n");
490 return NS_ERROR_NOT_IMPLEMENTED;
493 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
495 nsChannel *This = NSCHANNEL_THIS(iface);
497 TRACE("(%p)->(%p)\n", This, aContentType);
499 if(This->content_type) {
500 nsACString_SetData(aContentType, This->content_type);
505 return nsIChannel_GetContentType(This->channel, aContentType);
507 TRACE("returning default text/html\n");
508 nsACString_SetData(aContentType, "text/html");
512 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
513 const nsACString *aContentType)
515 nsChannel *This = NSCHANNEL_THIS(iface);
516 const char *content_type;
518 TRACE("(%p)->(%p)\n", This, aContentType);
520 nsACString_GetData(aContentType, &content_type);
522 TRACE("content_type %s\n", content_type);
524 heap_free(This->content_type);
525 This->content_type = heap_strdupA(content_type);
528 return nsIChannel_SetContentType(This->channel, aContentType);
533 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
534 nsACString *aContentCharset)
536 nsChannel *This = NSCHANNEL_THIS(iface);
538 TRACE("(%p)->(%p)\n", This, aContentCharset);
541 nsACString_SetData(aContentCharset, This->charset);
546 nsresult nsres = nsIChannel_GetContentCharset(This->channel, aContentCharset);
548 nsACString_GetData(aContentCharset, &ch);
552 nsACString_SetData(aContentCharset, "");
556 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
557 const nsACString *aContentCharset)
559 nsChannel *This = NSCHANNEL_THIS(iface);
561 TRACE("(%p)->(%p)\n", This, aContentCharset);
564 return nsIChannel_SetContentCharset(This->channel, aContentCharset);
566 FIXME("default action not implemented\n");
567 return NS_ERROR_NOT_IMPLEMENTED;
570 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
572 nsChannel *This = NSCHANNEL_THIS(iface);
574 TRACE("(%p)->(%p)\n", This, aContentLength);
577 return nsIChannel_GetContentLength(This->channel, aContentLength);
579 FIXME("default action not implemented\n");
580 return NS_ERROR_NOT_IMPLEMENTED;
583 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
585 nsChannel *This = NSCHANNEL_THIS(iface);
587 TRACE("(%p)->(%d)\n", This, aContentLength);
590 return nsIChannel_SetContentLength(This->channel, aContentLength);
592 FIXME("default action not implemented\n");
593 return NS_ERROR_NOT_IMPLEMENTED;
596 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
598 nsChannel *This = NSCHANNEL_THIS(iface);
600 TRACE("(%p)->(%p)\n", This, _retval);
603 return nsIChannel_Open(This->channel, _retval);
605 FIXME("default action not implemented\n");
606 return NS_ERROR_NOT_IMPLEMENTED;
609 static BOOL do_load_from_moniker_hack(nsChannel *This)
611 nsACString scheme_str;
616 * We should always load the page from IMoniker, but Wine is not yet
617 * ready for this. This function is a heuristic, that decides which
618 * way of loading is better (Gecko implementation or IMoniker). The
619 * aim is to always return TRUE.
622 /* Load from moniker if there is no Gecko channel available */
626 nsACString_Init(&scheme_str, NULL);
627 nsres = nsIWineURI_GetScheme(This->uri, &scheme_str);
629 if(NS_SUCCEEDED(nsres)) {
632 nsACString_GetData(&scheme_str, &scheme);
633 ret = !strcmp(scheme, "wine") || !strcmp(scheme, "about");
636 nsACString_Finish(&scheme_str);
640 static HRESULT create_mon_for_nschannel(nsChannel *channel, IMoniker **mon)
642 nsIWineURI *wine_uri;
647 if(!channel->original_uri) {
648 ERR("original_uri == NULL\n");
652 nsres = nsIURI_QueryInterface(channel->original_uri, &IID_nsIWineURI, (void**)&wine_uri);
653 if(NS_FAILED(nsres)) {
654 ERR("Could not get nsIWineURI: %08x\n", nsres);
658 nsIWineURI_GetWineURL(wine_uri, &wine_url);
659 nsIWineURI_Release(wine_uri);
661 TRACE("wine_url == NULL\n");
665 hres = CreateURLMoniker(NULL, wine_url, mon);
667 WARN("CreateURLMonikrer failed: %08x\n", hres);
672 static NSContainer *get_nscontainer_from_load_group(nsChannel *This)
674 NSContainer *container;
677 nsIWineURI *wine_uri;
681 nsres = nsILoadGroup_GetDefaultLoadRequest(This->load_group, &req);
682 if(NS_FAILED(nsres)) {
683 ERR("GetDefaultLoadRequest failed: %08x\n", nsres);
690 nsres = nsIRequest_QueryInterface(req, &IID_nsIChannel, (void**)&channel);
691 nsIRequest_Release(req);
692 if(NS_FAILED(nsres)) {
693 WARN("Could not get nsIChannel interface: %08x\n", nsres);
697 nsres = nsIChannel_GetURI(channel, &uri);
698 nsIChannel_Release(channel);
699 if(NS_FAILED(nsres)) {
700 ERR("GetURI failed: %08x\n", nsres);
704 nsres = nsIURI_QueryInterface(uri, &IID_nsIWineURI, (void**)&wine_uri);
706 if(NS_FAILED(nsres)) {
707 TRACE("Could not get nsIWineURI: %08x\n", nsres);
711 nsIWineURI_GetNSContainer(wine_uri, &container);
712 nsIWineURI_Release(wine_uri);
717 static nsresult async_open_doc_uri(nsChannel *This, NSContainer *container,
718 nsIStreamListener *listener, nsISupports *context, BOOL *open)
725 if(container->bscallback) {
726 channelbsc_set_channel(container->bscallback, This, listener, context);
728 if(container->doc && container->doc->mime) {
729 heap_free(This->content_type);
730 This->content_type = heap_strdupWtoA(container->doc->mime);
733 if(do_load_from_moniker_hack(This))
734 return WINE_NS_LOAD_FROM_MONIKER;
736 BOOL cont = before_async_open(This, container);
740 return NS_ERROR_UNEXPECTED;
743 if(!container->doc) {
745 ? nsIChannel_AsyncOpen(This->channel, listener, context)
746 : NS_ERROR_UNEXPECTED;
749 hres = create_mon_for_nschannel(This, &mon);
751 return NS_ERROR_UNEXPECTED;
753 set_current_mon(container->doc, mon);
760 static nsresult async_open(nsChannel *This, NSContainer *container, nsIStreamListener *listener,
761 nsISupports *context)
763 nsChannelBSC *bscallback;
764 IMoniker *mon = NULL;
770 nsres = nsIChannel_AsyncOpen(This->channel, listener, context);
773 IMoniker_Release(mon);
775 if(NS_FAILED(nsres) && (This->load_flags & LOAD_INITIAL_DOCUMENT_URI))
776 return WINE_NS_LOAD_FROM_MONIKER;
780 TRACE("channel == NULL\n");
782 hres = create_mon_for_nschannel(This, &mon);
784 return NS_ERROR_UNEXPECTED;
786 bscallback = create_channelbsc(mon);
787 IMoniker_Release(mon);
789 channelbsc_set_channel(bscallback, This, listener, context);
791 task = heap_alloc(sizeof(task_t));
793 task->doc = container->doc;
794 task->task_id = TASK_START_BINDING;
796 task->bscallback = bscallback;
803 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
804 nsISupports *aContext)
806 nsChannel *This = NSCHANNEL_THIS(iface);
807 NSContainer *container;
810 nsresult nsres = NS_OK;
812 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
814 nsIWineURI_GetNSContainer(This->uri, &container);
816 if(!container && This->load_group) {
817 container = get_nscontainer_from_load_group(This);
819 nsIWineURI_SetNSContainer(This->uri, container);
823 TRACE("container = NULL\n");
825 ? nsIChannel_AsyncOpen(This->channel, aListener, aContext)
826 : NS_ERROR_UNEXPECTED;
829 nsIWineURI_GetIsDocumentURI(This->uri, &is_doc_uri);
831 if(is_doc_uri && (This->load_flags & LOAD_INITIAL_DOCUMENT_URI))
832 nsres = async_open_doc_uri(This, container, aListener, aContext, &open);
835 nsres = async_open(This, container, aListener, aContext);
837 nsIWebBrowserChrome_Release(NSWBCHROME(container));
841 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
843 nsChannel *This = NSCHANNEL_THIS(iface);
845 TRACE("(%p)->(%p)\n", This, aRequestMethod);
847 if(This->http_channel)
848 return nsIHttpChannel_GetRequestMethod(This->http_channel, aRequestMethod);
850 return NS_ERROR_NOT_IMPLEMENTED;
853 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
854 const nsACString *aRequestMethod)
856 nsChannel *This = NSCHANNEL_THIS(iface);
858 TRACE("(%p)->(%p)\n", This, aRequestMethod);
860 if(This->http_channel)
861 return nsIHttpChannel_SetRequestMethod(This->http_channel, aRequestMethod);
863 return NS_ERROR_NOT_IMPLEMENTED;
866 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
868 nsChannel *This = NSCHANNEL_THIS(iface);
870 TRACE("(%p)->(%p)\n", This, aReferrer);
872 if(This->http_channel)
873 return nsIHttpChannel_GetReferrer(This->http_channel, aReferrer);
875 return NS_ERROR_NOT_IMPLEMENTED;
878 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
880 nsChannel *This = NSCHANNEL_THIS(iface);
882 TRACE("(%p)->(%p)\n", This, aReferrer);
884 if(This->http_channel)
885 return nsIHttpChannel_SetReferrer(This->http_channel, aReferrer);
887 return NS_ERROR_NOT_IMPLEMENTED;
890 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
891 const nsACString *aHeader, nsACString *_retval)
893 nsChannel *This = NSCHANNEL_THIS(iface);
895 TRACE("(%p)->(%p %p)\n", This, aHeader, _retval);
897 if(This->http_channel)
898 return nsIHttpChannel_GetRequestHeader(This->http_channel, aHeader, _retval);
900 return NS_ERROR_NOT_IMPLEMENTED;
903 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
904 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
906 nsChannel *This = NSCHANNEL_THIS(iface);
908 TRACE("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
910 if(This->http_channel)
911 return nsIHttpChannel_SetRequestHeader(This->http_channel, aHeader, aValue, aMerge);
913 return NS_ERROR_NOT_IMPLEMENTED;
916 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
917 nsIHttpHeaderVisitor *aVisitor)
919 nsChannel *This = NSCHANNEL_THIS(iface);
921 TRACE("(%p)->(%p)\n", This, aVisitor);
923 if(This->http_channel)
924 return nsIHttpChannel_VisitRequestHeaders(This->http_channel, aVisitor);
926 return NS_ERROR_NOT_IMPLEMENTED;
929 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
931 nsChannel *This = NSCHANNEL_THIS(iface);
933 TRACE("(%p)->(%p)\n", This, aAllowPipelining);
935 if(This->http_channel)
936 return nsIHttpChannel_GetAllowPipelining(This->http_channel, aAllowPipelining);
938 return NS_ERROR_NOT_IMPLEMENTED;
941 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
943 nsChannel *This = NSCHANNEL_THIS(iface);
945 TRACE("(%p)->(%x)\n", This, aAllowPipelining);
947 if(This->http_channel)
948 return nsIHttpChannel_SetAllowPipelining(This->http_channel, aAllowPipelining);
950 return NS_ERROR_NOT_IMPLEMENTED;
953 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
955 nsChannel *This = NSCHANNEL_THIS(iface);
957 TRACE("(%p)->(%p)\n", This, aRedirectionLimit);
959 if(This->http_channel)
960 return nsIHttpChannel_GetRedirectionLimit(This->http_channel, aRedirectionLimit);
962 return NS_ERROR_NOT_IMPLEMENTED;
965 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
967 nsChannel *This = NSCHANNEL_THIS(iface);
969 TRACE("(%p)->(%u)\n", This, aRedirectionLimit);
971 if(This->http_channel)
972 return nsIHttpChannel_SetRedirectionLimit(This->http_channel, aRedirectionLimit);
974 return NS_ERROR_NOT_IMPLEMENTED;
977 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
979 nsChannel *This = NSCHANNEL_THIS(iface);
981 TRACE("(%p)->(%p)\n", This, aResponseStatus);
983 if(This->response_status) {
984 *aResponseStatus = This->response_status;
988 if(This->http_channel)
989 return nsIHttpChannel_GetResponseStatus(This->http_channel, aResponseStatus);
991 return NS_ERROR_UNEXPECTED;
994 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
995 nsACString *aResponseStatusText)
997 nsChannel *This = NSCHANNEL_THIS(iface);
999 TRACE("(%p)->(%p)\n", This, aResponseStatusText);
1001 if(This->http_channel)
1002 return nsIHttpChannel_GetResponseStatusText(This->http_channel, aResponseStatusText);
1004 return NS_ERROR_NOT_IMPLEMENTED;
1007 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
1008 PRBool *aRequestSucceeded)
1010 nsChannel *This = NSCHANNEL_THIS(iface);
1012 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
1014 if(This->http_channel)
1015 return nsIHttpChannel_GetRequestSucceeded(This->http_channel, aRequestSucceeded);
1017 return NS_ERROR_NOT_IMPLEMENTED;
1020 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
1021 const nsACString *header, nsACString *_retval)
1023 nsChannel *This = NSCHANNEL_THIS(iface);
1025 TRACE("(%p)->(%p %p)\n", This, header, _retval);
1027 if(This->http_channel)
1028 return nsIHttpChannel_GetResponseHeader(This->http_channel, header, _retval);
1030 return NS_ERROR_NOT_IMPLEMENTED;
1033 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
1034 const nsACString *header, const nsACString *value, PRBool merge)
1036 nsChannel *This = NSCHANNEL_THIS(iface);
1038 TRACE("(%p)->(%p %p %x)\n", This, header, value, merge);
1040 if(This->http_channel)
1041 return nsIHttpChannel_SetResponseHeader(This->http_channel, header, value, merge);
1043 return NS_ERROR_NOT_IMPLEMENTED;
1046 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1047 nsIHttpHeaderVisitor *aVisitor)
1049 nsChannel *This = NSCHANNEL_THIS(iface);
1051 TRACE("(%p)->(%p)\n", This, aVisitor);
1053 if(This->http_channel)
1054 return nsIHttpChannel_VisitResponseHeaders(This->http_channel, aVisitor);
1056 return NS_ERROR_NOT_IMPLEMENTED;
1059 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
1061 nsChannel *This = NSCHANNEL_THIS(iface);
1063 TRACE("(%p)->(%p)\n", This, _retval);
1065 if(This->http_channel)
1066 return nsIHttpChannel_IsNoStoreResponse(This->http_channel, _retval);
1068 return NS_ERROR_NOT_IMPLEMENTED;
1071 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
1073 nsChannel *This = NSCHANNEL_THIS(iface);
1075 TRACE("(%p)->(%p)\n", This, _retval);
1077 if(This->http_channel)
1078 return nsIHttpChannel_IsNoCacheResponse(This->http_channel, _retval);
1080 return NS_ERROR_NOT_IMPLEMENTED;
1083 #undef NSCHANNEL_THIS
1085 static const nsIHttpChannelVtbl nsChannelVtbl = {
1086 nsChannel_QueryInterface,
1090 nsChannel_IsPending,
1091 nsChannel_GetStatus,
1095 nsChannel_GetLoadGroup,
1096 nsChannel_SetLoadGroup,
1097 nsChannel_GetLoadFlags,
1098 nsChannel_SetLoadFlags,
1099 nsChannel_GetOriginalURI,
1100 nsChannel_SetOriginalURI,
1104 nsChannel_GetNotificationCallbacks,
1105 nsChannel_SetNotificationCallbacks,
1106 nsChannel_GetSecurityInfo,
1107 nsChannel_GetContentType,
1108 nsChannel_SetContentType,
1109 nsChannel_GetContentCharset,
1110 nsChannel_SetContentCharset,
1111 nsChannel_GetContentLength,
1112 nsChannel_SetContentLength,
1114 nsChannel_AsyncOpen,
1115 nsChannel_GetRequestMethod,
1116 nsChannel_SetRequestMethod,
1117 nsChannel_GetReferrer,
1118 nsChannel_SetReferrer,
1119 nsChannel_GetRequestHeader,
1120 nsChannel_SetRequestHeader,
1121 nsChannel_VisitRequestHeaders,
1122 nsChannel_GetAllowPipelining,
1123 nsChannel_SetAllowPipelining,
1124 nsChannel_GetRedirectionLimit,
1125 nsChannel_SetRedirectionLimit,
1126 nsChannel_GetResponseStatus,
1127 nsChannel_GetResponseStatusText,
1128 nsChannel_GetRequestSucceeded,
1129 nsChannel_GetResponseHeader,
1130 nsChannel_SetResponseHeader,
1131 nsChannel_VisitResponseHeaders,
1132 nsChannel_IsNoStoreResponse,
1133 nsChannel_IsNoCacheResponse
1136 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1138 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1141 nsChannel *This = NSUPCHANNEL_THIS(iface);
1142 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1145 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1147 nsChannel *This = NSUPCHANNEL_THIS(iface);
1148 return nsIChannel_AddRef(NSCHANNEL(This));
1151 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1153 nsChannel *This = NSUPCHANNEL_THIS(iface);
1154 return nsIChannel_Release(NSCHANNEL(This));
1157 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1158 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1160 nsChannel *This = NSUPCHANNEL_THIS(iface);
1161 const char *content_type;
1164 TRACE("(%p)->(%p %p %d)\n", This, aStream, aContentType, aContentLength);
1166 if(This->post_data_stream)
1167 nsIInputStream_Release(This->post_data_stream);
1170 nsACString_GetData(aContentType, &content_type);
1172 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
1175 if(aContentLength != -1)
1176 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1178 if(This->post_data_stream)
1179 nsIInputStream_Release(This->post_data_stream);
1180 This->post_data_stream = aStream;
1182 nsIInputStream_AddRef(aStream);
1184 if(This->post_data_stream) {
1185 nsIUploadChannel *upload_channel;
1187 nsres = nsIChannel_QueryInterface(This->channel, &IID_nsIUploadChannel,
1188 (void**)&upload_channel);
1189 if(NS_SUCCEEDED(nsres)) {
1190 nsres = nsIUploadChannel_SetUploadStream(upload_channel, aStream, aContentType, aContentLength);
1191 nsIUploadChannel_Release(upload_channel);
1192 if(NS_FAILED(nsres))
1193 WARN("SetUploadStream failed: %08x\n", nsres);
1201 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1202 nsIInputStream **aUploadStream)
1204 nsChannel *This = NSUPCHANNEL_THIS(iface);
1206 TRACE("(%p)->(%p)\n", This, aUploadStream);
1208 if(This->post_data_stream)
1209 nsIInputStream_AddRef(This->post_data_stream);
1211 *aUploadStream = This->post_data_stream;
1215 #undef NSUPCHANNEL_THIS
1217 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1218 nsUploadChannel_QueryInterface,
1219 nsUploadChannel_AddRef,
1220 nsUploadChannel_Release,
1221 nsUploadChannel_SetUploadStream,
1222 nsUploadChannel_GetUploadStream
1225 #define NSURI_THIS(iface) DEFINE_THIS(nsURI, WineURI, iface)
1227 static nsresult NSAPI nsURI_QueryInterface(nsIWineURI *iface, nsIIDRef riid, nsQIResult result)
1229 nsURI *This = NSURI_THIS(iface);
1233 if(IsEqualGUID(&IID_nsISupports, riid)) {
1234 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1235 *result = NSURI(This);
1236 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1237 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1238 *result = NSURI(This);
1239 }else if(IsEqualGUID(&IID_nsIWineURI, riid)) {
1240 TRACE("(%p)->(IID_nsIWineURI %p)\n", This, result);
1241 *result = NSURI(This);
1245 nsIURI_AddRef(NSURI(This));
1249 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1250 return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1253 static nsrefcnt NSAPI nsURI_AddRef(nsIWineURI *iface)
1255 nsURI *This = NSURI_THIS(iface);
1256 LONG ref = InterlockedIncrement(&This->ref);
1258 TRACE("(%p) ref=%d\n", This, ref);
1263 static nsrefcnt NSAPI nsURI_Release(nsIWineURI *iface)
1265 nsURI *This = NSURI_THIS(iface);
1266 LONG ref = InterlockedDecrement(&This->ref);
1268 TRACE("(%p) ref=%d\n", This, ref);
1272 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1274 nsIURI_Release(This->uri);
1275 heap_free(This->wine_url);
1282 static nsresult NSAPI nsURI_GetSpec(nsIWineURI *iface, nsACString *aSpec)
1284 nsURI *This = NSURI_THIS(iface);
1286 TRACE("(%p)->(%p)\n", This, aSpec);
1288 if(This->use_wine_url) {
1289 char speca[INTERNET_MAX_URL_LENGTH] = "wine:";
1290 WideCharToMultiByte(CP_ACP, 0, This->wine_url, -1, speca+5, sizeof(speca)-5, NULL, NULL);
1291 nsACString_SetData(aSpec, speca);
1297 return nsIURI_GetSpec(This->uri, aSpec);
1299 TRACE("returning error\n");
1300 return NS_ERROR_NOT_IMPLEMENTED;
1304 static nsresult NSAPI nsURI_SetSpec(nsIWineURI *iface, const nsACString *aSpec)
1306 nsURI *This = NSURI_THIS(iface);
1308 TRACE("(%p)->(%p)\n", This, aSpec);
1311 return nsIURI_SetSpec(This->uri, aSpec);
1313 FIXME("default action not implemented\n");
1314 return NS_ERROR_NOT_IMPLEMENTED;
1317 static nsresult NSAPI nsURI_GetPrePath(nsIWineURI *iface, nsACString *aPrePath)
1319 nsURI *This = NSURI_THIS(iface);
1321 TRACE("(%p)->(%p)\n", This, aPrePath);
1324 return nsIURI_GetPrePath(This->uri, aPrePath);
1326 FIXME("default action not implemented\n");
1327 return NS_ERROR_NOT_IMPLEMENTED;
1330 static nsresult NSAPI nsURI_GetScheme(nsIWineURI *iface, nsACString *aScheme)
1332 nsURI *This = NSURI_THIS(iface);
1334 TRACE("(%p)->(%p)\n", This, aScheme);
1336 if(This->use_wine_url && strcmpW(This->wine_url, about_blankW)) {
1338 * For Gecko we set scheme to unknown so it won't be handled
1339 * as any special case.
1341 nsACString_SetData(aScheme, "wine");
1346 return nsIURI_GetScheme(This->uri, aScheme);
1348 TRACE("returning error\n");
1349 return NS_ERROR_NOT_IMPLEMENTED;
1352 static nsresult NSAPI nsURI_SetScheme(nsIWineURI *iface, const nsACString *aScheme)
1354 nsURI *This = NSURI_THIS(iface);
1356 TRACE("(%p)->(%p)\n", This, aScheme);
1359 return nsIURI_SetScheme(This->uri, aScheme);
1361 FIXME("default action not implemented\n");
1362 return NS_ERROR_NOT_IMPLEMENTED;
1365 static nsresult NSAPI nsURI_GetUserPass(nsIWineURI *iface, nsACString *aUserPass)
1367 nsURI *This = NSURI_THIS(iface);
1369 TRACE("(%p)->(%p)\n", This, aUserPass);
1372 return nsIURI_GetUserPass(This->uri, aUserPass);
1374 FIXME("default action not implemented\n");
1375 return NS_ERROR_NOT_IMPLEMENTED;
1378 static nsresult NSAPI nsURI_SetUserPass(nsIWineURI *iface, const nsACString *aUserPass)
1380 nsURI *This = NSURI_THIS(iface);
1382 TRACE("(%p)->(%p)\n", This, aUserPass);
1385 return nsIURI_SetUserPass(This->uri, aUserPass);
1387 FIXME("default action not implemented\n");
1388 return NS_ERROR_NOT_IMPLEMENTED;
1391 static nsresult NSAPI nsURI_GetUsername(nsIWineURI *iface, nsACString *aUsername)
1393 nsURI *This = NSURI_THIS(iface);
1395 TRACE("(%p)->(%p)\n", This, aUsername);
1398 return nsIURI_GetUsername(This->uri, aUsername);
1400 FIXME("default action not implemented\n");
1401 return NS_ERROR_NOT_IMPLEMENTED;
1404 static nsresult NSAPI nsURI_SetUsername(nsIWineURI *iface, const nsACString *aUsername)
1406 nsURI *This = NSURI_THIS(iface);
1408 TRACE("(%p)->(%p)\n", This, aUsername);
1411 return nsIURI_SetUsername(This->uri, aUsername);
1413 FIXME("default action not implemented\n");
1414 return NS_ERROR_NOT_IMPLEMENTED;
1417 static nsresult NSAPI nsURI_GetPassword(nsIWineURI *iface, nsACString *aPassword)
1419 nsURI *This = NSURI_THIS(iface);
1421 TRACE("(%p)->(%p)\n", This, aPassword);
1424 return nsIURI_GetPassword(This->uri, aPassword);
1426 FIXME("default action not implemented\n");
1427 return NS_ERROR_NOT_IMPLEMENTED;
1430 static nsresult NSAPI nsURI_SetPassword(nsIWineURI *iface, const nsACString *aPassword)
1432 nsURI *This = NSURI_THIS(iface);
1434 TRACE("(%p)->(%p)\n", This, aPassword);
1437 return nsIURI_SetPassword(This->uri, aPassword);
1439 FIXME("default action not implemented\n");
1440 return NS_ERROR_NOT_IMPLEMENTED;
1443 static nsresult NSAPI nsURI_GetHostPort(nsIWineURI *iface, nsACString *aHostPort)
1445 nsURI *This = NSURI_THIS(iface);
1447 TRACE("(%p)->(%p)\n", This, aHostPort);
1450 return nsIURI_GetHostPort(This->uri, aHostPort);
1452 FIXME("default action not implemented\n");
1453 return NS_ERROR_NOT_IMPLEMENTED;
1456 static nsresult NSAPI nsURI_SetHostPort(nsIWineURI *iface, const nsACString *aHostPort)
1458 nsURI *This = NSURI_THIS(iface);
1460 TRACE("(%p)->(%p)\n", This, aHostPort);
1463 return nsIURI_SetHostPort(This->uri, aHostPort);
1465 FIXME("default action not implemented\n");
1466 return NS_ERROR_NOT_IMPLEMENTED;
1469 static nsresult NSAPI nsURI_GetHost(nsIWineURI *iface, nsACString *aHost)
1471 nsURI *This = NSURI_THIS(iface);
1473 TRACE("(%p)->(%p)\n", This, aHost);
1476 return nsIURI_GetHost(This->uri, aHost);
1478 FIXME("default action not implemented\n");
1479 return NS_ERROR_NOT_IMPLEMENTED;
1482 static nsresult NSAPI nsURI_SetHost(nsIWineURI *iface, const nsACString *aHost)
1484 nsURI *This = NSURI_THIS(iface);
1486 TRACE("(%p)->(%p)\n", This, aHost);
1489 return nsIURI_SetHost(This->uri, aHost);
1491 FIXME("default action not implemented\n");
1492 return NS_ERROR_NOT_IMPLEMENTED;
1495 static nsresult NSAPI nsURI_GetPort(nsIWineURI *iface, PRInt32 *aPort)
1497 nsURI *This = NSURI_THIS(iface);
1499 TRACE("(%p)->(%p)\n", This, aPort);
1502 return nsIURI_GetPort(This->uri, aPort);
1504 FIXME("default action not implemented\n");
1505 return NS_ERROR_NOT_IMPLEMENTED;
1508 static nsresult NSAPI nsURI_SetPort(nsIWineURI *iface, PRInt32 aPort)
1510 nsURI *This = NSURI_THIS(iface);
1512 TRACE("(%p)->(%d)\n", This, aPort);
1515 return nsIURI_SetPort(This->uri, aPort);
1517 FIXME("default action not implemented\n");
1518 return NS_ERROR_NOT_IMPLEMENTED;
1521 static nsresult NSAPI nsURI_GetPath(nsIWineURI *iface, nsACString *aPath)
1523 nsURI *This = NSURI_THIS(iface);
1525 TRACE("(%p)->(%p)\n", This, aPath);
1528 return nsIURI_GetPath(This->uri, aPath);
1530 FIXME("default action not implemented\n");
1531 return NS_ERROR_NOT_IMPLEMENTED;
1534 static nsresult NSAPI nsURI_SetPath(nsIWineURI *iface, const nsACString *aPath)
1536 nsURI *This = NSURI_THIS(iface);
1539 nsACString_GetData(aPath, &path);
1540 TRACE("(%p)->(%p(%s))\n", This, aPath, debugstr_a(path));
1543 if(This->wine_url) {
1544 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
1545 DWORD size = sizeof(new_url)/sizeof(WCHAR);
1549 pathw = heap_strdupAtoW(path);
1550 hres = UrlCombineW(This->wine_url, pathw, new_url, &size, 0);
1553 nsIWineURI_SetWineURL(NSWINEURI(This), new_url);
1555 WARN("UrlCombine failed: %08x\n", hres);
1561 return nsIURI_SetPath(This->uri, aPath);
1564 static nsresult NSAPI nsURI_Equals(nsIWineURI *iface, nsIURI *other, PRBool *_retval)
1566 nsURI *This = NSURI_THIS(iface);
1567 nsIWineURI *wine_uri;
1568 LPCWSTR other_url = NULL;
1571 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1574 return nsIURI_Equals(This->uri, other, _retval);
1576 nsres = nsIURI_QueryInterface(other, &IID_nsIWineURI, (void**)&wine_uri);
1577 if(NS_FAILED(nsres)) {
1578 TRACE("Could not get nsIWineURI interface\n");
1583 nsIWineURI_GetWineURL(wine_uri, &other_url);
1584 *_retval = !UrlCompareW(This->wine_url, other_url, TRUE);
1585 nsIWineURI_Release(wine_uri);
1590 static nsresult NSAPI nsURI_SchemeIs(nsIWineURI *iface, const char *scheme, PRBool *_retval)
1592 nsURI *This = NSURI_THIS(iface);
1594 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1596 if(This->use_wine_url) {
1597 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
1598 int len = MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR))-1;
1600 *_retval = lstrlenW(This->wine_url) > len
1601 && This->wine_url[len] == ':'
1602 && !memcmp(buf, This->wine_url, len*sizeof(WCHAR));
1607 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1609 TRACE("returning error\n");
1610 return NS_ERROR_NOT_IMPLEMENTED;
1613 static nsresult NSAPI nsURI_Clone(nsIWineURI *iface, nsIURI **_retval)
1615 nsURI *This = NSURI_THIS(iface);
1616 nsIURI *nsuri = NULL;
1617 nsIWineURI *wine_uri;
1620 TRACE("(%p)->(%p)\n", This, _retval);
1623 nsres = nsIURI_Clone(This->uri, &nsuri);
1624 if(NS_FAILED(nsres)) {
1625 WARN("Clone failed: %08x\n", nsres);
1630 nsres = create_uri(nsuri, This->container, &wine_uri);
1631 if(NS_FAILED(nsres)) {
1632 WARN("create_uri failed: %08x\n", nsres);
1636 *_retval = (nsIURI*)wine_uri;
1637 return nsIWineURI_SetWineURL(wine_uri, This->wine_url);
1640 static nsresult NSAPI nsURI_Resolve(nsIWineURI *iface, const nsACString *arelativePath,
1641 nsACString *_retval)
1643 nsURI *This = NSURI_THIS(iface);
1645 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1648 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1650 FIXME("default action not implemented\n");
1651 return NS_ERROR_NOT_IMPLEMENTED;
1654 static nsresult NSAPI nsURI_GetAsciiSpec(nsIWineURI *iface, nsACString *aAsciiSpec)
1656 nsURI *This = NSURI_THIS(iface);
1658 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1660 if(This->use_wine_url)
1661 return nsIURI_GetSpec(NSURI(This), aAsciiSpec);
1664 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1666 TRACE("returning error\n");
1667 return NS_ERROR_NOT_IMPLEMENTED;
1670 static nsresult NSAPI nsURI_GetAsciiHost(nsIWineURI *iface, nsACString *aAsciiHost)
1672 nsURI *This = NSURI_THIS(iface);
1674 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1677 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1679 FIXME("default action not implemented\n");
1680 return NS_ERROR_NOT_IMPLEMENTED;
1683 static nsresult NSAPI nsURI_GetOriginCharset(nsIWineURI *iface, nsACString *aOriginCharset)
1685 nsURI *This = NSURI_THIS(iface);
1687 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1690 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1692 FIXME("default action not implemented\n");
1693 return NS_ERROR_NOT_IMPLEMENTED;
1696 static nsresult NSAPI nsURI_GetNSContainer(nsIWineURI *iface, NSContainer **aContainer)
1698 nsURI *This = NSURI_THIS(iface);
1700 TRACE("(%p)->(%p)\n", This, aContainer);
1703 nsIWebBrowserChrome_AddRef(NSWBCHROME(This->container));
1704 *aContainer = This->container;
1709 static nsresult NSAPI nsURI_SetNSContainer(nsIWineURI *iface, NSContainer *aContainer)
1711 nsURI *This = NSURI_THIS(iface);
1713 TRACE("(%p)->(%p)\n", This, aContainer);
1715 if(This->container) {
1716 if(This->container == aContainer)
1718 TRACE("Changing %p -> %p\n", This->container, aContainer);
1719 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1723 nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer));
1724 This->container = aContainer;
1729 static nsresult NSAPI nsURI_GetIsDocumentURI(nsIWineURI *iface, PRBool *aIsDocumentURI)
1731 nsURI *This = NSURI_THIS(iface);
1733 TRACE("(%p)->(%p)\n", This, aIsDocumentURI);
1735 *aIsDocumentURI = This->is_doc_uri;
1739 static nsresult NSAPI nsURI_SetIsDocumentURI(nsIWineURI *iface, PRBool aIsDocumentURI)
1741 nsURI *This = NSURI_THIS(iface);
1743 TRACE("(%p)->(%x)\n", This, aIsDocumentURI);
1745 This->is_doc_uri = aIsDocumentURI;
1749 static nsresult NSAPI nsURI_GetWineURL(nsIWineURI *iface, LPCWSTR *aURL)
1751 nsURI *This = NSURI_THIS(iface);
1753 TRACE("(%p)->(%p)\n", This, aURL);
1755 *aURL = This->wine_url;
1759 static nsresult NSAPI nsURI_SetWineURL(nsIWineURI *iface, LPCWSTR aURL)
1761 nsURI *This = NSURI_THIS(iface);
1763 static const WCHAR wszFtp[] = {'f','t','p',':'};
1764 static const WCHAR wszHttp[] = {'h','t','t','p',':'};
1765 static const WCHAR wszHttps[] = {'h','t','t','p','s',':'};
1767 TRACE("(%p)->(%s)\n", This, debugstr_w(aURL));
1769 heap_free(This->wine_url);
1772 int len = strlenW(aURL)+1;
1773 This->wine_url = heap_alloc(len*sizeof(WCHAR));
1774 memcpy(This->wine_url, aURL, len*sizeof(WCHAR));
1776 /* FIXME: Always use wine url */
1777 This->use_wine_url =
1778 strncmpW(aURL, wszFtp, sizeof(wszFtp)/sizeof(WCHAR))
1779 && strncmpW(aURL, wszHttp, sizeof(wszHttp)/sizeof(WCHAR))
1780 && strncmpW(aURL, wszHttps, sizeof(wszHttps)/sizeof(WCHAR));
1782 This->wine_url = NULL;
1783 This->use_wine_url = FALSE;
1791 static const nsIWineURIVtbl nsWineURIVtbl = {
1792 nsURI_QueryInterface,
1820 nsURI_GetOriginCharset,
1821 nsURI_GetNSContainer,
1822 nsURI_SetNSContainer,
1823 nsURI_GetIsDocumentURI,
1824 nsURI_SetIsDocumentURI,
1829 static nsresult create_uri(nsIURI *uri, NSContainer *container, nsIWineURI **_retval)
1831 nsURI *ret = heap_alloc(sizeof(nsURI));
1833 ret->lpWineURIVtbl = &nsWineURIVtbl;
1836 ret->container = container;
1837 ret->wine_url = NULL;
1838 ret->is_doc_uri = FALSE;
1839 ret->use_wine_url = FALSE;
1842 nsIWebBrowserChrome_AddRef(NSWBCHROME(container));
1844 TRACE("retval=%p\n", ret);
1845 *_retval = NSWINEURI(ret);
1850 const nsIProtocolHandlerVtbl *lpProtocolHandlerVtbl;
1854 nsIProtocolHandler *nshandler;
1855 } nsProtocolHandler;
1857 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
1859 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
1861 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
1864 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1868 if(IsEqualGUID(&IID_nsISupports, riid)) {
1869 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1870 *result = NSPROTHANDLER(This);
1871 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
1872 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
1873 *result = NSPROTHANDLER(This);
1874 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
1875 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
1876 return NS_NOINTERFACE;
1880 nsISupports_AddRef((nsISupports*)*result);
1884 WARN("(%s %p)\n", debugstr_guid(riid), result);
1885 return NS_NOINTERFACE;
1888 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
1890 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1891 LONG ref = InterlockedIncrement(&This->ref);
1893 TRACE("(%p) ref=%d\n", This, ref);
1898 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
1900 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1901 LONG ref = InterlockedDecrement(&This->ref);
1903 TRACE("(%p) ref=%d\n", This, ref);
1907 nsIProtocolHandler_Release(This->nshandler);
1914 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
1916 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1918 TRACE("(%p)->(%p)\n", This, aScheme);
1921 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
1922 return NS_ERROR_NOT_IMPLEMENTED;
1925 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
1926 PRInt32 *aDefaultPort)
1928 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1930 TRACE("(%p)->(%p)\n", This, aDefaultPort);
1933 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
1934 return NS_ERROR_NOT_IMPLEMENTED;
1937 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
1938 PRUint32 *aProtocolFlags)
1940 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1942 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
1945 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
1946 return NS_ERROR_NOT_IMPLEMENTED;
1949 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
1950 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
1952 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1954 TRACE("((%p)->%p %s %p %p)\n", This, aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
1957 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
1958 return NS_ERROR_NOT_IMPLEMENTED;
1961 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
1962 nsIURI *aURI, nsIChannel **_retval)
1964 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1966 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
1969 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
1970 return NS_ERROR_NOT_IMPLEMENTED;
1973 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
1974 PRInt32 port, const char *scheme, PRBool *_retval)
1976 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1978 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
1981 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
1982 return NS_ERROR_NOT_IMPLEMENTED;
1985 #undef NSPROTHANDLER_THIS
1987 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
1988 nsProtocolHandler_QueryInterface,
1989 nsProtocolHandler_AddRef,
1990 nsProtocolHandler_Release,
1991 nsProtocolHandler_GetScheme,
1992 nsProtocolHandler_GetDefaultPort,
1993 nsProtocolHandler_GetProtocolFlags,
1994 nsProtocolHandler_NewURI,
1995 nsProtocolHandler_NewChannel,
1996 nsProtocolHandler_AllowPort
1999 static nsIProtocolHandler *create_protocol_handler(nsIProtocolHandler *nshandler)
2001 nsProtocolHandler *ret = heap_alloc(sizeof(nsProtocolHandler));
2003 ret->lpProtocolHandlerVtbl = &nsProtocolHandlerVtbl;
2005 ret->nshandler = nshandler;
2007 return NSPROTHANDLER(ret);
2010 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,nsQIResult);
2012 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
2017 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
2022 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
2023 nsIProtocolHandler **_retval)
2025 nsIExternalProtocolHandler *nsexthandler;
2026 nsIProtocolHandler *nshandler;
2029 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2031 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
2032 if(NS_FAILED(nsres)) {
2033 WARN("GetProtocolHandler failed: %08x\n", nsres);
2037 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
2038 (void**)&nsexthandler);
2039 if(NS_FAILED(nsres)) {
2040 *_retval = nshandler;
2044 nsIExternalProtocolHandler_Release(nsexthandler);
2045 *_retval = create_protocol_handler(nshandler);
2046 TRACE("return %p\n", *_retval);
2050 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
2053 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2054 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
2057 static BOOL is_gecko_special_uri(const char *spec)
2059 static const char chromeW[] = "chrome:";
2060 static const char jarW[] = "jar:";
2061 static const char resourceW[] = "resource:";
2062 static const char javascriptW[] = "javascript:";
2064 return !strncasecmp(spec, chromeW, sizeof(chromeW)-1)
2065 || !strncasecmp(spec, resourceW, sizeof(resourceW)-1)
2066 || !strncasecmp(spec, jarW, sizeof(jarW)-1)
2067 || !strncasecmp(spec, javascriptW, sizeof(javascriptW)-1);
2070 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
2071 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2073 const char *spec = NULL;
2074 NSContainer *nscontainer = NULL;
2076 LPCWSTR base_wine_url = NULL;
2077 nsIWineURI *base_wine_uri = NULL, *wine_uri;
2078 BOOL is_wine_uri = FALSE;
2081 nsACString_GetData(aSpec, &spec);
2083 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
2086 if(is_gecko_special_uri(spec))
2087 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2089 if(!strncmp(spec, "wine:", 5)) {
2095 nsACString base_uri_str;
2096 const char *base_uri = NULL;
2098 nsACString_Init(&base_uri_str, NULL);
2100 nsres = nsIURI_GetSpec(aBaseURI, &base_uri_str);
2101 if(NS_SUCCEEDED(nsres)) {
2102 nsACString_GetData(&base_uri_str, &base_uri);
2103 TRACE("base_uri=%s\n", debugstr_a(base_uri));
2105 ERR("GetSpec failed: %08x\n", nsres);
2108 nsACString_Finish(&base_uri_str);
2111 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
2112 if(NS_FAILED(nsres))
2113 TRACE("NewURI failed: %08x\n", nsres);
2116 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsIWineURI, (void**)&base_wine_uri);
2117 if(NS_SUCCEEDED(nsres)) {
2118 nsIWineURI_GetNSContainer(base_wine_uri, &nscontainer);
2119 nsIWineURI_GetWineURL(base_wine_uri, &base_wine_url);
2121 TRACE("Could not get base nsIWineURI: %08x\n", nsres);
2125 TRACE("nscontainer = %p\n", nscontainer);
2127 nsres = create_uri(uri, nscontainer, &wine_uri);
2128 *_retval = (nsIURI*)wine_uri;
2131 nsIWebBrowserChrome_Release(NSWBCHROME(nscontainer));
2134 WCHAR url[INTERNET_MAX_URL_LENGTH], rel_url[INTERNET_MAX_URL_LENGTH];
2138 MultiByteToWideChar(CP_ACP, 0, spec, -1, rel_url, sizeof(rel_url)/sizeof(WCHAR));
2140 hres = CoInternetCombineUrl(base_wine_url, rel_url,
2141 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
2142 url, sizeof(url)/sizeof(WCHAR), &len, 0);
2144 nsIWineURI_SetWineURL(wine_uri, url);
2146 WARN("CoCombineUrl failed: %08x\n", hres);
2147 }else if(is_wine_uri) {
2148 WCHAR url[INTERNET_MAX_URL_LENGTH];
2150 MultiByteToWideChar(CP_ACP, 0, spec, -1, url, sizeof(url)/sizeof(WCHAR));
2151 nsIWineURI_SetWineURL(wine_uri, url);
2155 nsIWineURI_Release(base_wine_uri);
2160 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
2163 TRACE("(%p %p)\n", aFile, _retval);
2164 return nsIIOService_NewFileURI(nsio, aFile, _retval);
2167 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
2168 nsIChannel **_retval)
2170 nsIChannel *channel = NULL;
2172 nsIWineURI *wine_uri;
2175 TRACE("(%p %p)\n", aURI, _retval);
2177 nsres = nsIIOService_NewChannelFromURI(nsio, aURI, &channel);
2178 if(NS_FAILED(nsres) && nsres != NS_ERROR_UNKNOWN_PROTOCOL) {
2179 WARN("NewChannelFromURI failed: %08x\n", nsres);
2184 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
2185 if(NS_FAILED(nsres)) {
2186 WARN("Could not get nsIWineURI: %08x\n", nsres);
2188 return channel ? NS_OK : NS_ERROR_UNEXPECTED;
2191 ret = heap_alloc_zero(sizeof(nsChannel));
2193 ret->lpHttpChannelVtbl = &nsChannelVtbl;
2194 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
2196 ret->channel = channel;
2197 ret->uri = wine_uri;
2199 nsIURI_AddRef(aURI);
2200 ret->original_uri = aURI;
2203 nsIChannel_QueryInterface(channel, &IID_nsIHttpChannel, (void**)&ret->http_channel);
2205 *_retval = NSCHANNEL(ret);
2209 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
2210 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
2212 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2213 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2216 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
2218 TRACE("(%p)\n", aOffline);
2219 return nsIIOService_GetOffline(nsio, aOffline);
2222 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
2224 TRACE("(%x)\n", aOffline);
2225 return nsIIOService_SetOffline(nsio, aOffline);
2228 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
2229 const char *aScheme, PRBool *_retval)
2231 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
2232 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
2235 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
2236 nsACString * _retval)
2238 TRACE("(%p %p)\n", urlString, _retval);
2239 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
2242 static const nsIIOServiceVtbl nsIOServiceVtbl = {
2243 nsIOService_QueryInterface,
2245 nsIOService_Release,
2246 nsIOService_GetProtocolHandler,
2247 nsIOService_GetProtocolFlags,
2249 nsIOService_NewFileURI,
2250 nsIOService_NewChannelFromURI,
2251 nsIOService_NewChannel,
2252 nsIOService_GetOffline,
2253 nsIOService_SetOffline,
2254 nsIOService_AllowPort,
2255 nsIOService_ExtractScheme
2258 static nsIIOService nsIOService = { &nsIOServiceVtbl };
2260 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
2263 return nsIIOService_QueryInterface(&nsIOService, riid, result);
2266 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
2271 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
2276 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2277 nsACString *aCharset, PRBool *aHadCharset, nsACString *aContentType)
2279 TRACE("(%p %p %p %p)\n", aTypeHeader, aCharset, aHadCharset, aContentType);
2281 return nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
2284 static nsresult NSAPI nsNetUtil_ProtocolHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2288 return nsINetUtil_ProtocolHasFlags(net_util, aURI, aFlags, _retval);
2291 static nsresult NSAPI nsNetUtil_URIChainHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2293 TRACE("(%p %08x %p)\n", aURI, aFlags, _retval);
2295 if(aFlags == (1<<11)) {
2300 return nsINetUtil_URIChainHasFlags(net_util, aURI, aFlags, _retval);
2303 static nsresult NSAPI nsNetUtil_ToImmutableURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
2305 TRACE("(%p %p)\n", aURI, _retval);
2307 return nsINetUtil_ToImmutableURI(net_util, aURI, _retval);
2310 static nsresult NSAPI nsNetUtil_EscapeString(nsINetUtil *iface, const nsACString *aString,
2311 PRUint32 aEscapeType, nsACString *_retval)
2313 TRACE("(%p %x %p)\n", aString, aEscapeType, _retval);
2315 return nsINetUtil_EscapeString(net_util, aString, aEscapeType, _retval);
2318 static nsresult NSAPI nsNetUtil_EscapeURL(nsINetUtil *iface, const nsACString *aStr, PRUint32 aFlags,
2319 nsACString *_retval)
2321 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2323 return nsINetUtil_EscapeURL(net_util, aStr, aFlags, _retval);
2326 static nsresult NSAPI nsNetUtil_UnescapeString(nsINetUtil *iface, const nsACString *aStr,
2327 PRUint32 aFlags, nsACString *_retval)
2329 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2331 return nsINetUtil_UnescapeString(net_util, aStr, aFlags, _retval);
2334 static nsresult NSAPI nsNetUtil_ExtractCharsetFromContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2335 nsACString *aCharset, PRInt32 *aCharsetStart, PRInt32 *aCharsetEnd, PRBool *_retval)
2337 TRACE("(%p %p %p %p %p)\n", aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2339 return nsINetUtil_ExtractCharsetFromContentType(net_util, aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2342 static const nsINetUtilVtbl nsNetUtilVtbl = {
2343 nsNetUtil_QueryInterface,
2346 nsNetUtil_ParseContentType,
2347 nsNetUtil_ProtocolHasFlags,
2348 nsNetUtil_URIChainHasFlags,
2349 nsNetUtil_ToImmutableURI,
2350 nsNetUtil_EscapeString,
2351 nsNetUtil_EscapeURL,
2352 nsNetUtil_UnescapeString,
2353 nsNetUtil_ExtractCharsetFromContentType
2356 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
2358 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
2363 if(IsEqualGUID(&IID_nsISupports, riid))
2364 *result = &nsIOService;
2365 else if(IsEqualGUID(&IID_nsIIOService, riid))
2366 *result = &nsIOService;
2367 else if(IsEqualGUID(&IID_nsINetUtil, riid))
2368 *result = &nsNetUtil;
2371 nsISupports_AddRef((nsISupports*)*result);
2375 FIXME("(%s %p)\n", debugstr_guid(riid), result);
2376 return NS_NOINTERFACE;
2379 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
2384 if(IsEqualGUID(&IID_nsISupports, riid)) {
2385 TRACE("(IID_nsISupports %p)\n", result);
2387 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
2388 TRACE("(IID_nsIFactory %p)\n", result);
2393 nsIFactory_AddRef(iface);
2397 WARN("(%s %p)\n", debugstr_guid(riid), result);
2398 return NS_NOINTERFACE;
2401 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
2406 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
2411 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
2412 nsISupports *aOuter, const nsIID *iid, void **result)
2414 return nsIIOService_QueryInterface(&nsIOService, iid, result);
2417 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
2419 WARN("(%x)\n", lock);
2423 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
2424 nsIOServiceFactory_QueryInterface,
2425 nsIOServiceFactory_AddRef,
2426 nsIOServiceFactory_Release,
2427 nsIOServiceFactory_CreateInstance,
2428 nsIOServiceFactory_LockFactory
2431 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
2433 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
2435 nsIFactory *old_factory = NULL;
2438 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
2439 &IID_nsIFactory, (void**)&old_factory);
2440 if(NS_FAILED(nsres)) {
2441 ERR("Could not get factory: %08x\n", nsres);
2445 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
2446 if(NS_FAILED(nsres)) {
2447 ERR("Couldn not create nsIOService instance %08x\n", nsres);
2448 nsIFactory_Release(old_factory);
2452 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
2453 if(NS_FAILED(nsres)) {
2454 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
2455 nsIIOService_Release(nsio);
2459 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
2460 nsIFactory_Release(old_factory);
2461 if(NS_FAILED(nsres))
2462 ERR("UnregisterFactory failed: %08x\n", nsres);
2464 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
2465 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
2466 if(NS_FAILED(nsres))
2467 ERR("RegisterFactory failed: %08x\n", nsres);
2470 void release_nsio(void)
2473 nsINetUtil_Release(net_util);
2478 nsIIOService_Release(nsio);