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);
170 if(IsEqualGUID(&IID_nsISupports, riid)) {
171 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
172 *result = NSCHANNEL(This);
173 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
174 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
175 *result = NSCHANNEL(This);
176 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
177 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
178 *result = NSCHANNEL(This);
179 }else if(IsEqualGUID(&IID_nsIHttpChannel, riid)) {
180 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
181 *result = This->http_channel ? NSHTTPCHANNEL(This) : NULL;
182 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
183 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
184 *result = NSUPCHANNEL(This);
185 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal, riid)) {
186 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This, result);
187 *result = This->http_channel_internal ? NSHTTPINTERNAL(This) : NULL;
189 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
194 nsIChannel_AddRef(NSCHANNEL(This));
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);
222 if(This->http_channel_internal)
223 nsIHttpChannel_Release(This->http_channel_internal);
225 nsISupports_Release(This->owner);
226 if(This->post_data_stream)
227 nsIInputStream_Release(This->post_data_stream);
229 nsILoadGroup_Release(This->load_group);
230 if(This->notif_callback)
231 nsIInterfaceRequestor_Release(This->notif_callback);
232 if(This->original_uri)
233 nsIURI_Release(This->original_uri);
234 heap_free(This->content_type);
235 heap_free(This->charset);
242 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
244 nsChannel *This = NSCHANNEL_THIS(iface);
246 TRACE("(%p)->(%p)\n", This, aName);
249 return nsIChannel_GetName(This->channel, aName);
251 return NS_ERROR_NOT_IMPLEMENTED;
254 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
256 nsChannel *This = NSCHANNEL_THIS(iface);
258 TRACE("(%p)->(%p)\n", This, _retval);
261 return nsIChannel_IsPending(This->channel, _retval);
263 FIXME("default action not implemented\n");
264 return NS_ERROR_NOT_IMPLEMENTED;
267 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
269 nsChannel *This = NSCHANNEL_THIS(iface);
271 TRACE("(%p)->(%p)\n", This, aStatus);
274 return nsIChannel_GetStatus(This->channel, aStatus);
276 TRACE("returning NS_OK\n");
277 return *aStatus = NS_OK;
280 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
282 nsChannel *This = NSCHANNEL_THIS(iface);
284 TRACE("(%p)->(%08x)\n", This, aStatus);
287 return nsIChannel_Cancel(This->channel, aStatus);
289 FIXME("default action not implemented\n");
290 return NS_ERROR_NOT_IMPLEMENTED;
293 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
295 nsChannel *This = NSCHANNEL_THIS(iface);
297 TRACE("(%p)\n", This);
300 return nsIChannel_Suspend(This->channel);
302 FIXME("default action not implemented\n");
303 return NS_ERROR_NOT_IMPLEMENTED;
306 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
308 nsChannel *This = NSCHANNEL_THIS(iface);
310 TRACE("(%p)\n", This);
313 return nsIChannel_Resume(This->channel);
315 FIXME("default action not implemented\n");
316 return NS_ERROR_NOT_IMPLEMENTED;
319 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
321 nsChannel *This = NSCHANNEL_THIS(iface);
323 TRACE("(%p)->(%p)\n", This, aLoadGroup);
326 nsILoadGroup_AddRef(This->load_group);
328 *aLoadGroup = This->load_group;
332 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
334 nsChannel *This = NSCHANNEL_THIS(iface);
336 TRACE("(%p)->(%p)\n", This, aLoadGroup);
339 nsILoadGroup_Release(This->load_group);
341 nsILoadGroup_AddRef(aLoadGroup);
343 This->load_group = aLoadGroup;
346 return nsIChannel_SetLoadGroup(This->channel, aLoadGroup);
350 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
352 nsChannel *This = NSCHANNEL_THIS(iface);
354 TRACE("(%p)->(%p)\n", This, aLoadFlags);
356 *aLoadFlags = This->load_flags;
360 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
362 nsChannel *This = NSCHANNEL_THIS(iface);
364 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
366 This->load_flags = aLoadFlags;
369 return nsIChannel_SetLoadFlags(This->channel, aLoadFlags);
373 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
375 nsChannel *This = NSCHANNEL_THIS(iface);
377 TRACE("(%p)->(%p)\n", This, aOriginalURI);
379 if(This->original_uri)
380 nsIURI_AddRef(This->original_uri);
382 *aOriginalURI = This->original_uri;
386 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
388 nsChannel *This = NSCHANNEL_THIS(iface);
390 TRACE("(%p)->(%p)\n", This, aOriginalURI);
392 if(This->original_uri)
393 nsIURI_Release(This->original_uri);
395 nsIURI_AddRef(aOriginalURI);
396 This->original_uri = aOriginalURI;
399 return nsIChannel_SetOriginalURI(This->channel, aOriginalURI);
403 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
405 nsChannel *This = NSCHANNEL_THIS(iface);
407 TRACE("(%p)->(%p)\n", This, aURI);
409 nsIWineURI_AddRef(This->uri);
410 *aURI = (nsIURI*)This->uri;
415 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
417 nsChannel *This = NSCHANNEL_THIS(iface);
419 TRACE("(%p)->(%p)\n", This, aOwner);
422 return nsIChannel_GetOwner(This->channel, aOwner);
425 nsISupports_AddRef(This->owner);
426 *aOwner = This->owner;
431 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
433 nsChannel *This = NSCHANNEL_THIS(iface);
435 TRACE("(%p)->(%p)\n", This, aOwner);
438 return nsIChannel_SetOwner(This->channel, aOwner);
441 nsISupports_AddRef(aOwner);
443 nsISupports_Release(This->owner);
444 This->owner = aOwner;
449 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
450 nsIInterfaceRequestor **aNotificationCallbacks)
452 nsChannel *This = NSCHANNEL_THIS(iface);
454 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
456 if(This->notif_callback)
457 nsIInterfaceRequestor_AddRef(This->notif_callback);
458 *aNotificationCallbacks = This->notif_callback;
463 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
464 nsIInterfaceRequestor *aNotificationCallbacks)
466 nsChannel *This = NSCHANNEL_THIS(iface);
468 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
470 if(This->notif_callback)
471 nsIInterfaceRequestor_Release(This->notif_callback);
472 if(aNotificationCallbacks)
473 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
475 This->notif_callback = aNotificationCallbacks;
478 return nsIChannel_SetNotificationCallbacks(This->channel, aNotificationCallbacks);
482 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
484 nsChannel *This = NSCHANNEL_THIS(iface);
486 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
489 return nsIChannel_GetSecurityInfo(This->channel, aSecurityInfo);
491 FIXME("default action not implemented\n");
492 return NS_ERROR_NOT_IMPLEMENTED;
495 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
497 nsChannel *This = NSCHANNEL_THIS(iface);
499 TRACE("(%p)->(%p)\n", This, aContentType);
501 if(This->content_type) {
502 nsACString_SetData(aContentType, This->content_type);
507 return nsIChannel_GetContentType(This->channel, aContentType);
509 TRACE("returning default text/html\n");
510 nsACString_SetData(aContentType, "text/html");
514 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
515 const nsACString *aContentType)
517 nsChannel *This = NSCHANNEL_THIS(iface);
518 const char *content_type;
520 TRACE("(%p)->(%p)\n", This, aContentType);
522 nsACString_GetData(aContentType, &content_type);
524 TRACE("content_type %s\n", content_type);
526 heap_free(This->content_type);
527 This->content_type = heap_strdupA(content_type);
530 return nsIChannel_SetContentType(This->channel, aContentType);
535 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
536 nsACString *aContentCharset)
538 nsChannel *This = NSCHANNEL_THIS(iface);
540 TRACE("(%p)->(%p)\n", This, aContentCharset);
543 nsACString_SetData(aContentCharset, This->charset);
548 nsresult nsres = nsIChannel_GetContentCharset(This->channel, aContentCharset);
550 nsACString_GetData(aContentCharset, &ch);
554 nsACString_SetData(aContentCharset, "");
558 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
559 const nsACString *aContentCharset)
561 nsChannel *This = NSCHANNEL_THIS(iface);
563 TRACE("(%p)->(%p)\n", This, aContentCharset);
566 return nsIChannel_SetContentCharset(This->channel, aContentCharset);
568 FIXME("default action not implemented\n");
569 return NS_ERROR_NOT_IMPLEMENTED;
572 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
574 nsChannel *This = NSCHANNEL_THIS(iface);
576 TRACE("(%p)->(%p)\n", This, aContentLength);
579 return nsIChannel_GetContentLength(This->channel, aContentLength);
581 FIXME("default action not implemented\n");
582 return NS_ERROR_NOT_IMPLEMENTED;
585 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
587 nsChannel *This = NSCHANNEL_THIS(iface);
589 TRACE("(%p)->(%d)\n", This, aContentLength);
592 return nsIChannel_SetContentLength(This->channel, aContentLength);
594 FIXME("default action not implemented\n");
595 return NS_ERROR_NOT_IMPLEMENTED;
598 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
600 nsChannel *This = NSCHANNEL_THIS(iface);
602 TRACE("(%p)->(%p)\n", This, _retval);
605 return nsIChannel_Open(This->channel, _retval);
607 FIXME("default action not implemented\n");
608 return NS_ERROR_NOT_IMPLEMENTED;
611 static HRESULT create_mon_for_nschannel(nsChannel *channel, IMoniker **mon)
613 nsIWineURI *wine_uri;
618 if(!channel->original_uri) {
619 ERR("original_uri == NULL\n");
623 nsres = nsIURI_QueryInterface(channel->original_uri, &IID_nsIWineURI, (void**)&wine_uri);
624 if(NS_FAILED(nsres)) {
625 ERR("Could not get nsIWineURI: %08x\n", nsres);
629 nsIWineURI_GetWineURL(wine_uri, &wine_url);
630 nsIWineURI_Release(wine_uri);
632 TRACE("wine_url == NULL\n");
636 hres = CreateURLMoniker(NULL, wine_url, mon);
638 WARN("CreateURLMonikrer failed: %08x\n", hres);
643 static NSContainer *get_nscontainer_from_load_group(nsChannel *This)
645 NSContainer *container;
648 nsIWineURI *wine_uri;
652 nsres = nsILoadGroup_GetDefaultLoadRequest(This->load_group, &req);
653 if(NS_FAILED(nsres)) {
654 ERR("GetDefaultLoadRequest failed: %08x\n", nsres);
661 nsres = nsIRequest_QueryInterface(req, &IID_nsIChannel, (void**)&channel);
662 nsIRequest_Release(req);
663 if(NS_FAILED(nsres)) {
664 WARN("Could not get nsIChannel interface: %08x\n", nsres);
668 nsres = nsIChannel_GetURI(channel, &uri);
669 nsIChannel_Release(channel);
670 if(NS_FAILED(nsres)) {
671 ERR("GetURI failed: %08x\n", nsres);
675 nsres = nsIURI_QueryInterface(uri, &IID_nsIWineURI, (void**)&wine_uri);
677 if(NS_FAILED(nsres)) {
678 TRACE("Could not get nsIWineURI: %08x\n", nsres);
682 nsIWineURI_GetNSContainer(wine_uri, &container);
683 nsIWineURI_Release(wine_uri);
688 static nsresult async_open_doc_uri(nsChannel *This, NSContainer *container,
689 nsIStreamListener *listener, nsISupports *context, BOOL *open)
696 if(container->bscallback) {
697 channelbsc_set_channel(container->bscallback, This, listener, context);
699 if(container->doc && container->doc->mime) {
700 heap_free(This->content_type);
701 This->content_type = heap_strdupWtoA(container->doc->mime);
706 BOOL cont = before_async_open(This, container);
710 return NS_ERROR_UNEXPECTED;
713 if(!container->doc) {
715 ? nsIChannel_AsyncOpen(This->channel, listener, context)
716 : NS_ERROR_UNEXPECTED;
719 hres = create_mon_for_nschannel(This, &mon);
721 return NS_ERROR_UNEXPECTED;
723 set_current_mon(container->doc, mon);
730 static nsresult async_open(nsChannel *This, NSContainer *container, nsIStreamListener *listener,
731 nsISupports *context)
733 nsChannelBSC *bscallback;
734 IMoniker *mon = NULL;
738 hres = create_mon_for_nschannel(This, &mon);
740 return NS_ERROR_UNEXPECTED;
742 bscallback = create_channelbsc(mon);
743 IMoniker_Release(mon);
745 channelbsc_set_channel(bscallback, This, listener, context);
747 task = heap_alloc(sizeof(task_t));
749 task->doc = container->doc;
750 task->task_id = TASK_START_BINDING;
752 task->bscallback = bscallback;
759 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
760 nsISupports *aContext)
762 nsChannel *This = NSCHANNEL_THIS(iface);
763 NSContainer *container;
766 nsresult nsres = NS_OK;
768 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
770 nsIWineURI_GetNSContainer(This->uri, &container);
772 if(!container && This->load_group) {
773 container = get_nscontainer_from_load_group(This);
775 nsIWineURI_SetNSContainer(This->uri, container);
779 TRACE("container = NULL\n");
781 ? nsIChannel_AsyncOpen(This->channel, aListener, aContext)
782 : NS_ERROR_UNEXPECTED;
785 nsIWineURI_GetIsDocumentURI(This->uri, &is_doc_uri);
787 if(is_doc_uri && (This->load_flags & LOAD_INITIAL_DOCUMENT_URI))
788 nsres = async_open_doc_uri(This, container, aListener, aContext, &open);
791 nsres = async_open(This, container, aListener, aContext);
793 nsIWebBrowserChrome_Release(NSWBCHROME(container));
797 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
799 nsChannel *This = NSCHANNEL_THIS(iface);
801 TRACE("(%p)->(%p)\n", This, aRequestMethod);
803 if(This->http_channel)
804 return nsIHttpChannel_GetRequestMethod(This->http_channel, aRequestMethod);
806 return NS_ERROR_NOT_IMPLEMENTED;
809 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
810 const nsACString *aRequestMethod)
812 nsChannel *This = NSCHANNEL_THIS(iface);
814 TRACE("(%p)->(%p)\n", This, aRequestMethod);
816 if(This->http_channel)
817 return nsIHttpChannel_SetRequestMethod(This->http_channel, aRequestMethod);
819 return NS_ERROR_NOT_IMPLEMENTED;
822 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
824 nsChannel *This = NSCHANNEL_THIS(iface);
826 TRACE("(%p)->(%p)\n", This, aReferrer);
828 if(This->http_channel)
829 return nsIHttpChannel_GetReferrer(This->http_channel, aReferrer);
831 return NS_ERROR_NOT_IMPLEMENTED;
834 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
836 nsChannel *This = NSCHANNEL_THIS(iface);
838 TRACE("(%p)->(%p)\n", This, aReferrer);
840 if(This->http_channel)
841 return nsIHttpChannel_SetReferrer(This->http_channel, aReferrer);
843 return NS_ERROR_NOT_IMPLEMENTED;
846 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
847 const nsACString *aHeader, nsACString *_retval)
849 nsChannel *This = NSCHANNEL_THIS(iface);
851 TRACE("(%p)->(%p %p)\n", This, aHeader, _retval);
853 if(This->http_channel)
854 return nsIHttpChannel_GetRequestHeader(This->http_channel, aHeader, _retval);
856 return NS_ERROR_NOT_IMPLEMENTED;
859 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
860 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
862 nsChannel *This = NSCHANNEL_THIS(iface);
864 TRACE("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
866 if(This->http_channel)
867 return nsIHttpChannel_SetRequestHeader(This->http_channel, aHeader, aValue, aMerge);
869 return NS_ERROR_NOT_IMPLEMENTED;
872 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
873 nsIHttpHeaderVisitor *aVisitor)
875 nsChannel *This = NSCHANNEL_THIS(iface);
877 TRACE("(%p)->(%p)\n", This, aVisitor);
879 if(This->http_channel)
880 return nsIHttpChannel_VisitRequestHeaders(This->http_channel, aVisitor);
882 return NS_ERROR_NOT_IMPLEMENTED;
885 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
887 nsChannel *This = NSCHANNEL_THIS(iface);
889 TRACE("(%p)->(%p)\n", This, aAllowPipelining);
891 if(This->http_channel)
892 return nsIHttpChannel_GetAllowPipelining(This->http_channel, aAllowPipelining);
894 return NS_ERROR_NOT_IMPLEMENTED;
897 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
899 nsChannel *This = NSCHANNEL_THIS(iface);
901 TRACE("(%p)->(%x)\n", This, aAllowPipelining);
903 if(This->http_channel)
904 return nsIHttpChannel_SetAllowPipelining(This->http_channel, aAllowPipelining);
906 return NS_ERROR_NOT_IMPLEMENTED;
909 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
911 nsChannel *This = NSCHANNEL_THIS(iface);
913 TRACE("(%p)->(%p)\n", This, aRedirectionLimit);
915 if(This->http_channel)
916 return nsIHttpChannel_GetRedirectionLimit(This->http_channel, aRedirectionLimit);
918 return NS_ERROR_NOT_IMPLEMENTED;
921 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
923 nsChannel *This = NSCHANNEL_THIS(iface);
925 TRACE("(%p)->(%u)\n", This, aRedirectionLimit);
927 if(This->http_channel)
928 return nsIHttpChannel_SetRedirectionLimit(This->http_channel, aRedirectionLimit);
930 return NS_ERROR_NOT_IMPLEMENTED;
933 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
935 nsChannel *This = NSCHANNEL_THIS(iface);
937 TRACE("(%p)->(%p)\n", This, aResponseStatus);
939 if(This->response_status) {
940 *aResponseStatus = This->response_status;
944 if(This->http_channel)
945 return nsIHttpChannel_GetResponseStatus(This->http_channel, aResponseStatus);
947 return NS_ERROR_UNEXPECTED;
950 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
951 nsACString *aResponseStatusText)
953 nsChannel *This = NSCHANNEL_THIS(iface);
955 TRACE("(%p)->(%p)\n", This, aResponseStatusText);
957 if(This->http_channel)
958 return nsIHttpChannel_GetResponseStatusText(This->http_channel, aResponseStatusText);
960 return NS_ERROR_NOT_IMPLEMENTED;
963 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
964 PRBool *aRequestSucceeded)
966 nsChannel *This = NSCHANNEL_THIS(iface);
968 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
970 if(This->http_channel)
971 return nsIHttpChannel_GetRequestSucceeded(This->http_channel, aRequestSucceeded);
973 return NS_ERROR_NOT_IMPLEMENTED;
976 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
977 const nsACString *header, nsACString *_retval)
979 nsChannel *This = NSCHANNEL_THIS(iface);
981 TRACE("(%p)->(%p %p)\n", This, header, _retval);
983 if(This->http_channel)
984 return nsIHttpChannel_GetResponseHeader(This->http_channel, header, _retval);
986 return NS_ERROR_NOT_IMPLEMENTED;
989 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
990 const nsACString *header, const nsACString *value, PRBool merge)
992 nsChannel *This = NSCHANNEL_THIS(iface);
994 TRACE("(%p)->(%p %p %x)\n", This, header, value, merge);
996 if(This->http_channel)
997 return nsIHttpChannel_SetResponseHeader(This->http_channel, header, value, merge);
999 return NS_ERROR_NOT_IMPLEMENTED;
1002 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1003 nsIHttpHeaderVisitor *aVisitor)
1005 nsChannel *This = NSCHANNEL_THIS(iface);
1007 TRACE("(%p)->(%p)\n", This, aVisitor);
1009 if(This->http_channel)
1010 return nsIHttpChannel_VisitResponseHeaders(This->http_channel, aVisitor);
1012 return NS_ERROR_NOT_IMPLEMENTED;
1015 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
1017 nsChannel *This = NSCHANNEL_THIS(iface);
1019 TRACE("(%p)->(%p)\n", This, _retval);
1021 if(This->http_channel)
1022 return nsIHttpChannel_IsNoStoreResponse(This->http_channel, _retval);
1024 return NS_ERROR_NOT_IMPLEMENTED;
1027 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
1029 nsChannel *This = NSCHANNEL_THIS(iface);
1031 TRACE("(%p)->(%p)\n", This, _retval);
1033 if(This->http_channel)
1034 return nsIHttpChannel_IsNoCacheResponse(This->http_channel, _retval);
1036 return NS_ERROR_NOT_IMPLEMENTED;
1039 #undef NSCHANNEL_THIS
1041 static const nsIHttpChannelVtbl nsChannelVtbl = {
1042 nsChannel_QueryInterface,
1046 nsChannel_IsPending,
1047 nsChannel_GetStatus,
1051 nsChannel_GetLoadGroup,
1052 nsChannel_SetLoadGroup,
1053 nsChannel_GetLoadFlags,
1054 nsChannel_SetLoadFlags,
1055 nsChannel_GetOriginalURI,
1056 nsChannel_SetOriginalURI,
1060 nsChannel_GetNotificationCallbacks,
1061 nsChannel_SetNotificationCallbacks,
1062 nsChannel_GetSecurityInfo,
1063 nsChannel_GetContentType,
1064 nsChannel_SetContentType,
1065 nsChannel_GetContentCharset,
1066 nsChannel_SetContentCharset,
1067 nsChannel_GetContentLength,
1068 nsChannel_SetContentLength,
1070 nsChannel_AsyncOpen,
1071 nsChannel_GetRequestMethod,
1072 nsChannel_SetRequestMethod,
1073 nsChannel_GetReferrer,
1074 nsChannel_SetReferrer,
1075 nsChannel_GetRequestHeader,
1076 nsChannel_SetRequestHeader,
1077 nsChannel_VisitRequestHeaders,
1078 nsChannel_GetAllowPipelining,
1079 nsChannel_SetAllowPipelining,
1080 nsChannel_GetRedirectionLimit,
1081 nsChannel_SetRedirectionLimit,
1082 nsChannel_GetResponseStatus,
1083 nsChannel_GetResponseStatusText,
1084 nsChannel_GetRequestSucceeded,
1085 nsChannel_GetResponseHeader,
1086 nsChannel_SetResponseHeader,
1087 nsChannel_VisitResponseHeaders,
1088 nsChannel_IsNoStoreResponse,
1089 nsChannel_IsNoCacheResponse
1092 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1094 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1097 nsChannel *This = NSUPCHANNEL_THIS(iface);
1098 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1101 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1103 nsChannel *This = NSUPCHANNEL_THIS(iface);
1104 return nsIChannel_AddRef(NSCHANNEL(This));
1107 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1109 nsChannel *This = NSUPCHANNEL_THIS(iface);
1110 return nsIChannel_Release(NSCHANNEL(This));
1113 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1114 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1116 nsChannel *This = NSUPCHANNEL_THIS(iface);
1117 const char *content_type;
1120 TRACE("(%p)->(%p %p %d)\n", This, aStream, aContentType, aContentLength);
1122 if(This->post_data_stream)
1123 nsIInputStream_Release(This->post_data_stream);
1126 nsACString_GetData(aContentType, &content_type);
1128 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
1131 if(aContentLength != -1)
1132 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1134 if(This->post_data_stream)
1135 nsIInputStream_Release(This->post_data_stream);
1136 This->post_data_stream = aStream;
1138 nsIInputStream_AddRef(aStream);
1140 if(This->post_data_stream) {
1141 nsIUploadChannel *upload_channel;
1143 nsres = nsIChannel_QueryInterface(This->channel, &IID_nsIUploadChannel,
1144 (void**)&upload_channel);
1145 if(NS_SUCCEEDED(nsres)) {
1146 nsres = nsIUploadChannel_SetUploadStream(upload_channel, aStream, aContentType, aContentLength);
1147 nsIUploadChannel_Release(upload_channel);
1148 if(NS_FAILED(nsres))
1149 WARN("SetUploadStream failed: %08x\n", nsres);
1157 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1158 nsIInputStream **aUploadStream)
1160 nsChannel *This = NSUPCHANNEL_THIS(iface);
1162 TRACE("(%p)->(%p)\n", This, aUploadStream);
1164 if(This->post_data_stream)
1165 nsIInputStream_AddRef(This->post_data_stream);
1167 *aUploadStream = This->post_data_stream;
1171 #undef NSUPCHANNEL_THIS
1173 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1174 nsUploadChannel_QueryInterface,
1175 nsUploadChannel_AddRef,
1176 nsUploadChannel_Release,
1177 nsUploadChannel_SetUploadStream,
1178 nsUploadChannel_GetUploadStream
1181 #define NSHTTPINTERNAL_THIS(iface) DEFINE_THIS(nsChannel, IHttpChannelInternal, iface)
1183 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1186 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1187 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1190 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1192 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1193 return nsIChannel_AddRef(NSCHANNEL(This));
1196 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1198 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1199 return nsIChannel_Release(NSCHANNEL(This));
1202 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1204 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1206 TRACE("(%p)->()\n", This);
1208 if(This->http_channel_internal)
1209 return nsIHttpChannelInternal_GetDocumentURI(This->http_channel_internal, aDocumentURI);
1210 return NS_ERROR_NOT_IMPLEMENTED;
1213 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1215 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1217 TRACE("(%p)->()\n", This);
1219 if(This->http_channel_internal)
1220 return nsIHttpChannelInternal_SetDocumentURI(This->http_channel_internal, aDocumentURI);
1221 return NS_ERROR_NOT_IMPLEMENTED;
1224 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1226 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1228 TRACE("(%p)->()\n", This);
1230 if(This->http_channel_internal)
1231 return nsIHttpChannelInternal_GetRequestVersion(This->http_channel_internal, major, minor);
1232 return NS_ERROR_NOT_IMPLEMENTED;
1235 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1237 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1239 TRACE("(%p)->()\n", This);
1241 if(This->http_channel_internal)
1242 return nsIHttpChannelInternal_GetResponseVersion(This->http_channel_internal, major, minor);
1243 return NS_ERROR_NOT_IMPLEMENTED;
1246 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1248 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1250 TRACE("(%p)->()\n", This);
1252 if(This->http_channel_internal)
1253 return nsIHttpChannelInternal_SetCookie(This->http_channel_internal, aCookieHeader);
1254 return NS_ERROR_NOT_IMPLEMENTED;
1257 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1259 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1261 TRACE("(%p)->()\n", This);
1263 if(This->http_channel_internal)
1264 return nsIHttpChannelInternal_SetupFallbackChannel(This->http_channel_internal, aFallbackKey);
1265 return NS_ERROR_NOT_IMPLEMENTED;
1268 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool *aForceThirdPartyCookie)
1270 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1272 TRACE("(%p)->()\n", This);
1274 if(This->http_channel_internal)
1275 return nsIHttpChannelInternal_GetForceAllowThirdPartyCookie(This->http_channel_internal, aForceThirdPartyCookie);
1276 return NS_ERROR_NOT_IMPLEMENTED;
1279 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool aForceThirdPartyCookie)
1281 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1283 TRACE("(%p)->()\n", This);
1285 if(This->http_channel_internal)
1286 return nsIHttpChannelInternal_SetForceAllowThirdPartyCookie(This->http_channel_internal, aForceThirdPartyCookie);
1287 return NS_ERROR_NOT_IMPLEMENTED;
1290 #undef NSHTTPINTERNAL_THIS
1292 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
1293 nsHttpChannelInternal_QueryInterface,
1294 nsHttpChannelInternal_AddRef,
1295 nsHttpChannelInternal_Release,
1296 nsHttpChannelInternal_GetDocumentURI,
1297 nsHttpChannelInternal_SetDocumentURI,
1298 nsHttpChannelInternal_GetRequestVersion,
1299 nsHttpChannelInternal_GetResponseVersion,
1300 nsHttpChannelInternal_SetCookie,
1301 nsHttpChannelInternal_SetupFallbackChannel,
1302 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
1303 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
1306 #define NSURI_THIS(iface) DEFINE_THIS(nsURI, WineURI, iface)
1308 static nsresult NSAPI nsURI_QueryInterface(nsIWineURI *iface, nsIIDRef riid, nsQIResult result)
1310 nsURI *This = NSURI_THIS(iface);
1314 if(IsEqualGUID(&IID_nsISupports, riid)) {
1315 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1316 *result = NSURI(This);
1317 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1318 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1319 *result = NSURI(This);
1320 }else if(IsEqualGUID(&IID_nsIWineURI, riid)) {
1321 TRACE("(%p)->(IID_nsIWineURI %p)\n", This, result);
1322 *result = NSURI(This);
1326 nsIURI_AddRef(NSURI(This));
1330 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1331 return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1334 static nsrefcnt NSAPI nsURI_AddRef(nsIWineURI *iface)
1336 nsURI *This = NSURI_THIS(iface);
1337 LONG ref = InterlockedIncrement(&This->ref);
1339 TRACE("(%p) ref=%d\n", This, ref);
1344 static nsrefcnt NSAPI nsURI_Release(nsIWineURI *iface)
1346 nsURI *This = NSURI_THIS(iface);
1347 LONG ref = InterlockedDecrement(&This->ref);
1349 TRACE("(%p) ref=%d\n", This, ref);
1353 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1355 nsIURI_Release(This->uri);
1356 heap_free(This->wine_url);
1363 static nsresult NSAPI nsURI_GetSpec(nsIWineURI *iface, nsACString *aSpec)
1365 nsURI *This = NSURI_THIS(iface);
1367 TRACE("(%p)->(%p)\n", This, aSpec);
1369 if(This->use_wine_url) {
1370 char speca[INTERNET_MAX_URL_LENGTH] = "wine:";
1371 WideCharToMultiByte(CP_ACP, 0, This->wine_url, -1, speca+5, sizeof(speca)-5, NULL, NULL);
1372 nsACString_SetData(aSpec, speca);
1378 return nsIURI_GetSpec(This->uri, aSpec);
1380 TRACE("returning error\n");
1381 return NS_ERROR_NOT_IMPLEMENTED;
1385 static nsresult NSAPI nsURI_SetSpec(nsIWineURI *iface, const nsACString *aSpec)
1387 nsURI *This = NSURI_THIS(iface);
1389 TRACE("(%p)->(%p)\n", This, aSpec);
1392 return nsIURI_SetSpec(This->uri, aSpec);
1394 FIXME("default action not implemented\n");
1395 return NS_ERROR_NOT_IMPLEMENTED;
1398 static nsresult NSAPI nsURI_GetPrePath(nsIWineURI *iface, nsACString *aPrePath)
1400 nsURI *This = NSURI_THIS(iface);
1402 TRACE("(%p)->(%p)\n", This, aPrePath);
1405 return nsIURI_GetPrePath(This->uri, aPrePath);
1407 FIXME("default action not implemented\n");
1408 return NS_ERROR_NOT_IMPLEMENTED;
1411 static nsresult NSAPI nsURI_GetScheme(nsIWineURI *iface, nsACString *aScheme)
1413 nsURI *This = NSURI_THIS(iface);
1415 TRACE("(%p)->(%p)\n", This, aScheme);
1417 if(This->use_wine_url && strcmpW(This->wine_url, about_blankW)) {
1419 * For Gecko we set scheme to unknown so it won't be handled
1420 * as any special case.
1422 nsACString_SetData(aScheme, "wine");
1427 return nsIURI_GetScheme(This->uri, aScheme);
1429 TRACE("returning error\n");
1430 return NS_ERROR_NOT_IMPLEMENTED;
1433 static nsresult NSAPI nsURI_SetScheme(nsIWineURI *iface, const nsACString *aScheme)
1435 nsURI *This = NSURI_THIS(iface);
1437 TRACE("(%p)->(%p)\n", This, aScheme);
1440 return nsIURI_SetScheme(This->uri, aScheme);
1442 FIXME("default action not implemented\n");
1443 return NS_ERROR_NOT_IMPLEMENTED;
1446 static nsresult NSAPI nsURI_GetUserPass(nsIWineURI *iface, nsACString *aUserPass)
1448 nsURI *This = NSURI_THIS(iface);
1450 TRACE("(%p)->(%p)\n", This, aUserPass);
1453 return nsIURI_GetUserPass(This->uri, aUserPass);
1455 FIXME("default action not implemented\n");
1456 return NS_ERROR_NOT_IMPLEMENTED;
1459 static nsresult NSAPI nsURI_SetUserPass(nsIWineURI *iface, const nsACString *aUserPass)
1461 nsURI *This = NSURI_THIS(iface);
1463 TRACE("(%p)->(%p)\n", This, aUserPass);
1466 return nsIURI_SetUserPass(This->uri, aUserPass);
1468 FIXME("default action not implemented\n");
1469 return NS_ERROR_NOT_IMPLEMENTED;
1472 static nsresult NSAPI nsURI_GetUsername(nsIWineURI *iface, nsACString *aUsername)
1474 nsURI *This = NSURI_THIS(iface);
1476 TRACE("(%p)->(%p)\n", This, aUsername);
1479 return nsIURI_GetUsername(This->uri, aUsername);
1481 FIXME("default action not implemented\n");
1482 return NS_ERROR_NOT_IMPLEMENTED;
1485 static nsresult NSAPI nsURI_SetUsername(nsIWineURI *iface, const nsACString *aUsername)
1487 nsURI *This = NSURI_THIS(iface);
1489 TRACE("(%p)->(%p)\n", This, aUsername);
1492 return nsIURI_SetUsername(This->uri, aUsername);
1494 FIXME("default action not implemented\n");
1495 return NS_ERROR_NOT_IMPLEMENTED;
1498 static nsresult NSAPI nsURI_GetPassword(nsIWineURI *iface, nsACString *aPassword)
1500 nsURI *This = NSURI_THIS(iface);
1502 TRACE("(%p)->(%p)\n", This, aPassword);
1505 return nsIURI_GetPassword(This->uri, aPassword);
1507 FIXME("default action not implemented\n");
1508 return NS_ERROR_NOT_IMPLEMENTED;
1511 static nsresult NSAPI nsURI_SetPassword(nsIWineURI *iface, const nsACString *aPassword)
1513 nsURI *This = NSURI_THIS(iface);
1515 TRACE("(%p)->(%p)\n", This, aPassword);
1518 return nsIURI_SetPassword(This->uri, aPassword);
1520 FIXME("default action not implemented\n");
1521 return NS_ERROR_NOT_IMPLEMENTED;
1524 static nsresult NSAPI nsURI_GetHostPort(nsIWineURI *iface, nsACString *aHostPort)
1526 nsURI *This = NSURI_THIS(iface);
1528 TRACE("(%p)->(%p)\n", This, aHostPort);
1531 return nsIURI_GetHostPort(This->uri, aHostPort);
1533 FIXME("default action not implemented\n");
1534 return NS_ERROR_NOT_IMPLEMENTED;
1537 static nsresult NSAPI nsURI_SetHostPort(nsIWineURI *iface, const nsACString *aHostPort)
1539 nsURI *This = NSURI_THIS(iface);
1541 TRACE("(%p)->(%p)\n", This, aHostPort);
1544 return nsIURI_SetHostPort(This->uri, aHostPort);
1546 FIXME("default action not implemented\n");
1547 return NS_ERROR_NOT_IMPLEMENTED;
1550 static nsresult NSAPI nsURI_GetHost(nsIWineURI *iface, nsACString *aHost)
1552 nsURI *This = NSURI_THIS(iface);
1554 TRACE("(%p)->(%p)\n", This, aHost);
1557 return nsIURI_GetHost(This->uri, aHost);
1559 FIXME("default action not implemented\n");
1560 return NS_ERROR_NOT_IMPLEMENTED;
1563 static nsresult NSAPI nsURI_SetHost(nsIWineURI *iface, const nsACString *aHost)
1565 nsURI *This = NSURI_THIS(iface);
1567 TRACE("(%p)->(%p)\n", This, aHost);
1570 return nsIURI_SetHost(This->uri, aHost);
1572 FIXME("default action not implemented\n");
1573 return NS_ERROR_NOT_IMPLEMENTED;
1576 static nsresult NSAPI nsURI_GetPort(nsIWineURI *iface, PRInt32 *aPort)
1578 nsURI *This = NSURI_THIS(iface);
1580 TRACE("(%p)->(%p)\n", This, aPort);
1583 return nsIURI_GetPort(This->uri, aPort);
1585 FIXME("default action not implemented\n");
1586 return NS_ERROR_NOT_IMPLEMENTED;
1589 static nsresult NSAPI nsURI_SetPort(nsIWineURI *iface, PRInt32 aPort)
1591 nsURI *This = NSURI_THIS(iface);
1593 TRACE("(%p)->(%d)\n", This, aPort);
1596 return nsIURI_SetPort(This->uri, aPort);
1598 FIXME("default action not implemented\n");
1599 return NS_ERROR_NOT_IMPLEMENTED;
1602 static nsresult NSAPI nsURI_GetPath(nsIWineURI *iface, nsACString *aPath)
1604 nsURI *This = NSURI_THIS(iface);
1606 TRACE("(%p)->(%p)\n", This, aPath);
1609 return nsIURI_GetPath(This->uri, aPath);
1611 FIXME("default action not implemented\n");
1612 return NS_ERROR_NOT_IMPLEMENTED;
1615 static nsresult NSAPI nsURI_SetPath(nsIWineURI *iface, const nsACString *aPath)
1617 nsURI *This = NSURI_THIS(iface);
1620 nsACString_GetData(aPath, &path);
1621 TRACE("(%p)->(%p(%s))\n", This, aPath, debugstr_a(path));
1624 if(This->wine_url) {
1625 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
1626 DWORD size = sizeof(new_url)/sizeof(WCHAR);
1630 pathw = heap_strdupAtoW(path);
1631 hres = UrlCombineW(This->wine_url, pathw, new_url, &size, 0);
1634 nsIWineURI_SetWineURL(NSWINEURI(This), new_url);
1636 WARN("UrlCombine failed: %08x\n", hres);
1642 return nsIURI_SetPath(This->uri, aPath);
1645 static nsresult NSAPI nsURI_Equals(nsIWineURI *iface, nsIURI *other, PRBool *_retval)
1647 nsURI *This = NSURI_THIS(iface);
1648 nsIWineURI *wine_uri;
1649 LPCWSTR other_url = NULL;
1652 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1655 return nsIURI_Equals(This->uri, other, _retval);
1657 nsres = nsIURI_QueryInterface(other, &IID_nsIWineURI, (void**)&wine_uri);
1658 if(NS_FAILED(nsres)) {
1659 TRACE("Could not get nsIWineURI interface\n");
1664 nsIWineURI_GetWineURL(wine_uri, &other_url);
1665 *_retval = !UrlCompareW(This->wine_url, other_url, TRUE);
1666 nsIWineURI_Release(wine_uri);
1671 static nsresult NSAPI nsURI_SchemeIs(nsIWineURI *iface, const char *scheme, PRBool *_retval)
1673 nsURI *This = NSURI_THIS(iface);
1675 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1677 if(This->use_wine_url) {
1678 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
1679 int len = MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR))-1;
1681 *_retval = lstrlenW(This->wine_url) > len
1682 && This->wine_url[len] == ':'
1683 && !memcmp(buf, This->wine_url, len*sizeof(WCHAR));
1688 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1690 TRACE("returning error\n");
1691 return NS_ERROR_NOT_IMPLEMENTED;
1694 static nsresult NSAPI nsURI_Clone(nsIWineURI *iface, nsIURI **_retval)
1696 nsURI *This = NSURI_THIS(iface);
1697 nsIURI *nsuri = NULL;
1698 nsIWineURI *wine_uri;
1701 TRACE("(%p)->(%p)\n", This, _retval);
1704 nsres = nsIURI_Clone(This->uri, &nsuri);
1705 if(NS_FAILED(nsres)) {
1706 WARN("Clone failed: %08x\n", nsres);
1711 nsres = create_uri(nsuri, This->container, &wine_uri);
1712 if(NS_FAILED(nsres)) {
1713 WARN("create_uri failed: %08x\n", nsres);
1717 *_retval = (nsIURI*)wine_uri;
1718 return nsIWineURI_SetWineURL(wine_uri, This->wine_url);
1721 static nsresult NSAPI nsURI_Resolve(nsIWineURI *iface, const nsACString *arelativePath,
1722 nsACString *_retval)
1724 nsURI *This = NSURI_THIS(iface);
1726 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1729 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1731 FIXME("default action not implemented\n");
1732 return NS_ERROR_NOT_IMPLEMENTED;
1735 static nsresult NSAPI nsURI_GetAsciiSpec(nsIWineURI *iface, nsACString *aAsciiSpec)
1737 nsURI *This = NSURI_THIS(iface);
1739 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1741 if(This->use_wine_url)
1742 return nsIURI_GetSpec(NSURI(This), aAsciiSpec);
1745 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1747 TRACE("returning error\n");
1748 return NS_ERROR_NOT_IMPLEMENTED;
1751 static nsresult NSAPI nsURI_GetAsciiHost(nsIWineURI *iface, nsACString *aAsciiHost)
1753 nsURI *This = NSURI_THIS(iface);
1755 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1758 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1760 FIXME("default action not implemented\n");
1761 return NS_ERROR_NOT_IMPLEMENTED;
1764 static nsresult NSAPI nsURI_GetOriginCharset(nsIWineURI *iface, nsACString *aOriginCharset)
1766 nsURI *This = NSURI_THIS(iface);
1768 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1771 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1773 FIXME("default action not implemented\n");
1774 return NS_ERROR_NOT_IMPLEMENTED;
1777 static nsresult NSAPI nsURI_GetNSContainer(nsIWineURI *iface, NSContainer **aContainer)
1779 nsURI *This = NSURI_THIS(iface);
1781 TRACE("(%p)->(%p)\n", This, aContainer);
1784 nsIWebBrowserChrome_AddRef(NSWBCHROME(This->container));
1785 *aContainer = This->container;
1790 static nsresult NSAPI nsURI_SetNSContainer(nsIWineURI *iface, NSContainer *aContainer)
1792 nsURI *This = NSURI_THIS(iface);
1794 TRACE("(%p)->(%p)\n", This, aContainer);
1796 if(This->container) {
1797 if(This->container == aContainer)
1799 TRACE("Changing %p -> %p\n", This->container, aContainer);
1800 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1804 nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer));
1805 This->container = aContainer;
1810 static nsresult NSAPI nsURI_GetIsDocumentURI(nsIWineURI *iface, PRBool *aIsDocumentURI)
1812 nsURI *This = NSURI_THIS(iface);
1814 TRACE("(%p)->(%p)\n", This, aIsDocumentURI);
1816 *aIsDocumentURI = This->is_doc_uri;
1820 static nsresult NSAPI nsURI_SetIsDocumentURI(nsIWineURI *iface, PRBool aIsDocumentURI)
1822 nsURI *This = NSURI_THIS(iface);
1824 TRACE("(%p)->(%x)\n", This, aIsDocumentURI);
1826 This->is_doc_uri = aIsDocumentURI;
1830 static nsresult NSAPI nsURI_GetWineURL(nsIWineURI *iface, LPCWSTR *aURL)
1832 nsURI *This = NSURI_THIS(iface);
1834 TRACE("(%p)->(%p)\n", This, aURL);
1836 *aURL = This->wine_url;
1840 static nsresult NSAPI nsURI_SetWineURL(nsIWineURI *iface, LPCWSTR aURL)
1842 nsURI *This = NSURI_THIS(iface);
1844 static const WCHAR wszFtp[] = {'f','t','p',':'};
1845 static const WCHAR wszHttp[] = {'h','t','t','p',':'};
1846 static const WCHAR wszHttps[] = {'h','t','t','p','s',':'};
1848 TRACE("(%p)->(%s)\n", This, debugstr_w(aURL));
1850 heap_free(This->wine_url);
1853 int len = strlenW(aURL)+1;
1854 This->wine_url = heap_alloc(len*sizeof(WCHAR));
1855 memcpy(This->wine_url, aURL, len*sizeof(WCHAR));
1857 /* FIXME: Always use wine url */
1858 This->use_wine_url =
1859 strncmpW(aURL, wszFtp, sizeof(wszFtp)/sizeof(WCHAR))
1860 && strncmpW(aURL, wszHttp, sizeof(wszHttp)/sizeof(WCHAR))
1861 && strncmpW(aURL, wszHttps, sizeof(wszHttps)/sizeof(WCHAR));
1863 This->wine_url = NULL;
1864 This->use_wine_url = FALSE;
1872 static const nsIWineURIVtbl nsWineURIVtbl = {
1873 nsURI_QueryInterface,
1901 nsURI_GetOriginCharset,
1902 nsURI_GetNSContainer,
1903 nsURI_SetNSContainer,
1904 nsURI_GetIsDocumentURI,
1905 nsURI_SetIsDocumentURI,
1910 static nsresult create_uri(nsIURI *uri, NSContainer *container, nsIWineURI **_retval)
1912 nsURI *ret = heap_alloc(sizeof(nsURI));
1914 ret->lpWineURIVtbl = &nsWineURIVtbl;
1917 ret->container = container;
1918 ret->wine_url = NULL;
1919 ret->is_doc_uri = FALSE;
1920 ret->use_wine_url = FALSE;
1923 nsIWebBrowserChrome_AddRef(NSWBCHROME(container));
1925 TRACE("retval=%p\n", ret);
1926 *_retval = NSWINEURI(ret);
1931 const nsIProtocolHandlerVtbl *lpProtocolHandlerVtbl;
1935 nsIProtocolHandler *nshandler;
1936 } nsProtocolHandler;
1938 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
1940 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
1942 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
1945 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1949 if(IsEqualGUID(&IID_nsISupports, riid)) {
1950 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1951 *result = NSPROTHANDLER(This);
1952 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
1953 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
1954 *result = NSPROTHANDLER(This);
1955 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
1956 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
1957 return NS_NOINTERFACE;
1961 nsISupports_AddRef((nsISupports*)*result);
1965 WARN("(%s %p)\n", debugstr_guid(riid), result);
1966 return NS_NOINTERFACE;
1969 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
1971 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1972 LONG ref = InterlockedIncrement(&This->ref);
1974 TRACE("(%p) ref=%d\n", This, ref);
1979 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
1981 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1982 LONG ref = InterlockedDecrement(&This->ref);
1984 TRACE("(%p) ref=%d\n", This, ref);
1988 nsIProtocolHandler_Release(This->nshandler);
1995 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
1997 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1999 TRACE("(%p)->(%p)\n", This, aScheme);
2002 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
2003 return NS_ERROR_NOT_IMPLEMENTED;
2006 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
2007 PRInt32 *aDefaultPort)
2009 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2011 TRACE("(%p)->(%p)\n", This, aDefaultPort);
2014 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
2015 return NS_ERROR_NOT_IMPLEMENTED;
2018 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
2019 PRUint32 *aProtocolFlags)
2021 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2023 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
2026 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
2027 return NS_ERROR_NOT_IMPLEMENTED;
2030 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
2031 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2033 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2035 TRACE("((%p)->%p %s %p %p)\n", This, aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2038 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
2039 return NS_ERROR_NOT_IMPLEMENTED;
2042 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
2043 nsIURI *aURI, nsIChannel **_retval)
2045 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2047 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
2050 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
2051 return NS_ERROR_NOT_IMPLEMENTED;
2054 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
2055 PRInt32 port, const char *scheme, PRBool *_retval)
2057 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2059 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
2062 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
2063 return NS_ERROR_NOT_IMPLEMENTED;
2066 #undef NSPROTHANDLER_THIS
2068 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
2069 nsProtocolHandler_QueryInterface,
2070 nsProtocolHandler_AddRef,
2071 nsProtocolHandler_Release,
2072 nsProtocolHandler_GetScheme,
2073 nsProtocolHandler_GetDefaultPort,
2074 nsProtocolHandler_GetProtocolFlags,
2075 nsProtocolHandler_NewURI,
2076 nsProtocolHandler_NewChannel,
2077 nsProtocolHandler_AllowPort
2080 static nsIProtocolHandler *create_protocol_handler(nsIProtocolHandler *nshandler)
2082 nsProtocolHandler *ret = heap_alloc(sizeof(nsProtocolHandler));
2084 ret->lpProtocolHandlerVtbl = &nsProtocolHandlerVtbl;
2086 ret->nshandler = nshandler;
2088 return NSPROTHANDLER(ret);
2091 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,nsQIResult);
2093 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
2098 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
2103 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
2104 nsIProtocolHandler **_retval)
2106 nsIExternalProtocolHandler *nsexthandler;
2107 nsIProtocolHandler *nshandler;
2110 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2112 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
2113 if(NS_FAILED(nsres)) {
2114 WARN("GetProtocolHandler failed: %08x\n", nsres);
2118 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
2119 (void**)&nsexthandler);
2120 if(NS_FAILED(nsres)) {
2121 *_retval = nshandler;
2125 nsIExternalProtocolHandler_Release(nsexthandler);
2126 *_retval = create_protocol_handler(nshandler);
2127 TRACE("return %p\n", *_retval);
2131 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
2134 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2135 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
2138 static BOOL is_gecko_special_uri(const char *spec)
2140 static const char *special_schemes[] = {"chrome:", "jar:", "resource:", "javascript:", "wyciwyg:"};
2143 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
2144 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
2151 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
2152 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2154 const char *spec = NULL;
2155 NSContainer *nscontainer = NULL;
2157 LPCWSTR base_wine_url = NULL;
2158 nsIWineURI *base_wine_uri = NULL, *wine_uri;
2159 BOOL is_wine_uri = FALSE;
2162 nsACString_GetData(aSpec, &spec);
2164 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
2167 if(is_gecko_special_uri(spec))
2168 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2170 if(!strncmp(spec, "wine:", 5)) {
2176 nsACString base_uri_str;
2177 const char *base_uri = NULL;
2179 nsACString_Init(&base_uri_str, NULL);
2181 nsres = nsIURI_GetSpec(aBaseURI, &base_uri_str);
2182 if(NS_SUCCEEDED(nsres)) {
2183 nsACString_GetData(&base_uri_str, &base_uri);
2184 TRACE("base_uri=%s\n", debugstr_a(base_uri));
2186 ERR("GetSpec failed: %08x\n", nsres);
2189 nsACString_Finish(&base_uri_str);
2192 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
2193 if(NS_FAILED(nsres))
2194 TRACE("NewURI failed: %08x\n", nsres);
2197 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsIWineURI, (void**)&base_wine_uri);
2198 if(NS_SUCCEEDED(nsres)) {
2199 nsIWineURI_GetNSContainer(base_wine_uri, &nscontainer);
2200 nsIWineURI_GetWineURL(base_wine_uri, &base_wine_url);
2202 TRACE("Could not get base nsIWineURI: %08x\n", nsres);
2206 TRACE("nscontainer = %p\n", nscontainer);
2208 nsres = create_uri(uri, nscontainer, &wine_uri);
2209 *_retval = (nsIURI*)wine_uri;
2212 nsIWebBrowserChrome_Release(NSWBCHROME(nscontainer));
2215 WCHAR url[INTERNET_MAX_URL_LENGTH], rel_url[INTERNET_MAX_URL_LENGTH];
2219 MultiByteToWideChar(CP_ACP, 0, spec, -1, rel_url, sizeof(rel_url)/sizeof(WCHAR));
2221 hres = CoInternetCombineUrl(base_wine_url, rel_url,
2222 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
2223 url, sizeof(url)/sizeof(WCHAR), &len, 0);
2225 nsIWineURI_SetWineURL(wine_uri, url);
2227 WARN("CoCombineUrl failed: %08x\n", hres);
2228 }else if(is_wine_uri) {
2229 WCHAR url[INTERNET_MAX_URL_LENGTH];
2231 MultiByteToWideChar(CP_ACP, 0, spec, -1, url, sizeof(url)/sizeof(WCHAR));
2232 nsIWineURI_SetWineURL(wine_uri, url);
2236 nsIWineURI_Release(base_wine_uri);
2241 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
2244 TRACE("(%p %p)\n", aFile, _retval);
2245 return nsIIOService_NewFileURI(nsio, aFile, _retval);
2248 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
2249 nsIChannel **_retval)
2251 nsIChannel *channel = NULL;
2253 nsIWineURI *wine_uri;
2256 TRACE("(%p %p)\n", aURI, _retval);
2258 nsres = nsIIOService_NewChannelFromURI(nsio, aURI, &channel);
2259 if(NS_FAILED(nsres) && nsres != NS_ERROR_UNKNOWN_PROTOCOL) {
2260 WARN("NewChannelFromURI failed: %08x\n", nsres);
2265 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
2266 if(NS_FAILED(nsres)) {
2267 WARN("Could not get nsIWineURI: %08x\n", nsres);
2269 return channel ? NS_OK : NS_ERROR_UNEXPECTED;
2272 ret = heap_alloc_zero(sizeof(nsChannel));
2274 ret->lpHttpChannelVtbl = &nsChannelVtbl;
2275 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
2276 ret->lpIHttpChannelInternalVtbl = &nsHttpChannelInternalVtbl;
2278 ret->channel = channel;
2279 ret->uri = wine_uri;
2281 nsIURI_AddRef(aURI);
2282 ret->original_uri = aURI;
2285 nsIChannel_QueryInterface(channel, &IID_nsIHttpChannel, (void**)&ret->http_channel);
2286 nsIChannel_QueryInterface(channel, &IID_nsIHttpChannelInternal, (void**)&ret->http_channel_internal);
2289 *_retval = NSCHANNEL(ret);
2293 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
2294 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
2296 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2297 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2300 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
2302 TRACE("(%p)\n", aOffline);
2303 return nsIIOService_GetOffline(nsio, aOffline);
2306 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
2308 TRACE("(%x)\n", aOffline);
2309 return nsIIOService_SetOffline(nsio, aOffline);
2312 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
2313 const char *aScheme, PRBool *_retval)
2315 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
2316 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
2319 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
2320 nsACString * _retval)
2322 TRACE("(%p %p)\n", urlString, _retval);
2323 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
2326 static const nsIIOServiceVtbl nsIOServiceVtbl = {
2327 nsIOService_QueryInterface,
2329 nsIOService_Release,
2330 nsIOService_GetProtocolHandler,
2331 nsIOService_GetProtocolFlags,
2333 nsIOService_NewFileURI,
2334 nsIOService_NewChannelFromURI,
2335 nsIOService_NewChannel,
2336 nsIOService_GetOffline,
2337 nsIOService_SetOffline,
2338 nsIOService_AllowPort,
2339 nsIOService_ExtractScheme
2342 static nsIIOService nsIOService = { &nsIOServiceVtbl };
2344 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
2347 return nsIIOService_QueryInterface(&nsIOService, riid, result);
2350 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
2355 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
2360 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2361 nsACString *aCharset, PRBool *aHadCharset, nsACString *aContentType)
2363 TRACE("(%p %p %p %p)\n", aTypeHeader, aCharset, aHadCharset, aContentType);
2365 return nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
2368 static nsresult NSAPI nsNetUtil_ProtocolHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2372 return nsINetUtil_ProtocolHasFlags(net_util, aURI, aFlags, _retval);
2375 static nsresult NSAPI nsNetUtil_URIChainHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2377 TRACE("(%p %08x %p)\n", aURI, aFlags, _retval);
2379 if(aFlags == (1<<11)) {
2384 return nsINetUtil_URIChainHasFlags(net_util, aURI, aFlags, _retval);
2387 static nsresult NSAPI nsNetUtil_ToImmutableURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
2389 TRACE("(%p %p)\n", aURI, _retval);
2391 return nsINetUtil_ToImmutableURI(net_util, aURI, _retval);
2394 static nsresult NSAPI nsNetUtil_EscapeString(nsINetUtil *iface, const nsACString *aString,
2395 PRUint32 aEscapeType, nsACString *_retval)
2397 TRACE("(%p %x %p)\n", aString, aEscapeType, _retval);
2399 return nsINetUtil_EscapeString(net_util, aString, aEscapeType, _retval);
2402 static nsresult NSAPI nsNetUtil_EscapeURL(nsINetUtil *iface, const nsACString *aStr, PRUint32 aFlags,
2403 nsACString *_retval)
2405 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2407 return nsINetUtil_EscapeURL(net_util, aStr, aFlags, _retval);
2410 static nsresult NSAPI nsNetUtil_UnescapeString(nsINetUtil *iface, const nsACString *aStr,
2411 PRUint32 aFlags, nsACString *_retval)
2413 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2415 return nsINetUtil_UnescapeString(net_util, aStr, aFlags, _retval);
2418 static nsresult NSAPI nsNetUtil_ExtractCharsetFromContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2419 nsACString *aCharset, PRInt32 *aCharsetStart, PRInt32 *aCharsetEnd, PRBool *_retval)
2421 TRACE("(%p %p %p %p %p)\n", aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2423 return nsINetUtil_ExtractCharsetFromContentType(net_util, aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2426 static const nsINetUtilVtbl nsNetUtilVtbl = {
2427 nsNetUtil_QueryInterface,
2430 nsNetUtil_ParseContentType,
2431 nsNetUtil_ProtocolHasFlags,
2432 nsNetUtil_URIChainHasFlags,
2433 nsNetUtil_ToImmutableURI,
2434 nsNetUtil_EscapeString,
2435 nsNetUtil_EscapeURL,
2436 nsNetUtil_UnescapeString,
2437 nsNetUtil_ExtractCharsetFromContentType
2440 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
2442 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
2447 if(IsEqualGUID(&IID_nsISupports, riid))
2448 *result = &nsIOService;
2449 else if(IsEqualGUID(&IID_nsIIOService, riid))
2450 *result = &nsIOService;
2451 else if(IsEqualGUID(&IID_nsINetUtil, riid))
2452 *result = &nsNetUtil;
2455 nsISupports_AddRef((nsISupports*)*result);
2459 FIXME("(%s %p)\n", debugstr_guid(riid), result);
2460 return NS_NOINTERFACE;
2463 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
2468 if(IsEqualGUID(&IID_nsISupports, riid)) {
2469 TRACE("(IID_nsISupports %p)\n", result);
2471 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
2472 TRACE("(IID_nsIFactory %p)\n", result);
2477 nsIFactory_AddRef(iface);
2481 WARN("(%s %p)\n", debugstr_guid(riid), result);
2482 return NS_NOINTERFACE;
2485 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
2490 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
2495 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
2496 nsISupports *aOuter, const nsIID *iid, void **result)
2498 return nsIIOService_QueryInterface(&nsIOService, iid, result);
2501 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
2503 WARN("(%x)\n", lock);
2507 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
2508 nsIOServiceFactory_QueryInterface,
2509 nsIOServiceFactory_AddRef,
2510 nsIOServiceFactory_Release,
2511 nsIOServiceFactory_CreateInstance,
2512 nsIOServiceFactory_LockFactory
2515 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
2517 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
2519 nsIFactory *old_factory = NULL;
2522 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
2523 &IID_nsIFactory, (void**)&old_factory);
2524 if(NS_FAILED(nsres)) {
2525 ERR("Could not get factory: %08x\n", nsres);
2529 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
2530 if(NS_FAILED(nsres)) {
2531 ERR("Couldn not create nsIOService instance %08x\n", nsres);
2532 nsIFactory_Release(old_factory);
2536 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
2537 if(NS_FAILED(nsres)) {
2538 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
2539 nsIIOService_Release(nsio);
2543 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
2544 nsIFactory_Release(old_factory);
2545 if(NS_FAILED(nsres))
2546 ERR("UnregisterFactory failed: %08x\n", nsres);
2548 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
2549 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
2550 if(NS_FAILED(nsres))
2551 ERR("RegisterFactory failed: %08x\n", nsres);
2554 void release_nsio(void)
2557 nsINetUtil_Release(net_util);
2562 nsIIOService_Release(nsio);