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;
61 NSContainer *container;
67 #define NSURI(x) ((nsIURI*) &(x)->lpWineURIVtbl)
68 #define NSWINEURI(x) ((nsIWineURI*) &(x)->lpWineURIVtbl)
70 static nsresult create_uri(nsIURI*,NSContainer*,nsIWineURI**);
72 static const char *debugstr_nsacstr(const nsACString *nsstr)
76 nsACString_GetData(nsstr, &data);
77 return debugstr_a(data);
80 HRESULT nsuri_to_url(LPCWSTR nsuri, BOOL ret_empty, BSTR *ret)
82 const WCHAR *ptr = nsuri;
84 static const WCHAR wine_prefixW[] = {'w','i','n','e',':'};
86 if(!strncmpW(nsuri, wine_prefixW, sizeof(wine_prefixW)/sizeof(WCHAR)))
87 ptr += sizeof(wine_prefixW)/sizeof(WCHAR);
89 if(*ptr || ret_empty) {
90 *ret = SysAllocString(ptr);
97 TRACE("%s -> %s\n", debugstr_w(nsuri), debugstr_w(*ret));
101 static BOOL exec_shldocvw_67(HTMLDocumentObj *doc, LPCWSTR url)
103 IOleCommandTarget *cmdtrg = NULL;
106 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
107 if(SUCCEEDED(hres)) {
108 VARIANT varUrl, varRes;
110 V_VT(&varUrl) = VT_BSTR;
111 V_BSTR(&varUrl) = SysAllocString(url);
112 V_VT(&varRes) = VT_BOOL;
114 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
116 IOleCommandTarget_Release(cmdtrg);
117 SysFreeString(V_BSTR(&varUrl));
119 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
120 TRACE("got VARIANT_FALSE, do not load\n");
128 static BOOL before_async_open(nsChannel *channel, NSContainer *container)
130 HTMLDocumentObj *doc = container->doc;
131 IServiceProvider *service_provider;
136 nsIWineURI_GetWineURL(channel->uri, &uri);
138 ERR("GetWineURL returned NULL\n");
143 NSContainer *container_iter = container;
145 hlnf = HLNF_OPENINNEWWINDOW;
146 while(!container_iter->doc)
147 container_iter = container_iter->parent;
148 doc = container_iter->doc;
154 if(!hlnf && !exec_shldocvw_67(doc, uri))
157 hres = IOleClientSite_QueryInterface(doc->client, &IID_IServiceProvider,
158 (void**)&service_provider);
159 if(SUCCEEDED(hres)) {
160 IHlinkFrame *hlink_frame;
162 hres = IServiceProvider_QueryService(service_provider, &IID_IHlinkFrame,
163 &IID_IHlinkFrame, (void**)&hlink_frame);
164 IServiceProvider_Release(service_provider);
165 if(SUCCEEDED(hres)) {
166 hlink_frame_navigate(&doc->basedoc, hlink_frame, uri, channel->post_data_stream, hlnf);
167 IHlinkFrame_Release(hlink_frame);
176 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
178 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
180 nsChannel *This = NSCHANNEL_THIS(iface);
182 if(IsEqualGUID(&IID_nsISupports, riid)) {
183 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
184 *result = NSCHANNEL(This);
185 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
186 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
187 *result = NSCHANNEL(This);
188 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
189 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
190 *result = NSCHANNEL(This);
191 }else if(IsEqualGUID(&IID_nsIHttpChannel, riid)) {
192 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
193 *result = This->http_channel ? NSHTTPCHANNEL(This) : NULL;
194 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
195 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
196 *result = NSUPCHANNEL(This);
197 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal, riid)) {
198 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This, result);
199 *result = This->http_channel_internal ? NSHTTPINTERNAL(This) : NULL;
201 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
206 nsIChannel_AddRef(NSCHANNEL(This));
210 return NS_NOINTERFACE;
213 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
215 nsChannel *This = NSCHANNEL_THIS(iface);
216 nsrefcnt ref = InterlockedIncrement(&This->ref);
218 TRACE("(%p) ref=%d\n", This, ref);
223 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
225 nsChannel *This = NSCHANNEL_THIS(iface);
226 LONG ref = InterlockedDecrement(&This->ref);
229 nsIWineURI_Release(This->uri);
231 nsIChannel_Release(This->channel);
232 if(This->http_channel)
233 nsIHttpChannel_Release(This->http_channel);
234 if(This->http_channel_internal)
235 nsIHttpChannel_Release(This->http_channel_internal);
237 nsISupports_Release(This->owner);
238 if(This->post_data_stream)
239 nsIInputStream_Release(This->post_data_stream);
241 nsILoadGroup_Release(This->load_group);
242 if(This->notif_callback)
243 nsIInterfaceRequestor_Release(This->notif_callback);
244 if(This->original_uri)
245 nsIURI_Release(This->original_uri);
246 heap_free(This->content_type);
247 heap_free(This->charset);
254 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
256 nsChannel *This = NSCHANNEL_THIS(iface);
258 TRACE("(%p)->(%p)\n", This, aName);
261 return nsIChannel_GetName(This->channel, aName);
263 return NS_ERROR_NOT_IMPLEMENTED;
266 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
268 nsChannel *This = NSCHANNEL_THIS(iface);
270 TRACE("(%p)->(%p)\n", This, _retval);
273 return nsIChannel_IsPending(This->channel, _retval);
275 FIXME("default action not implemented\n");
276 return NS_ERROR_NOT_IMPLEMENTED;
279 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
281 nsChannel *This = NSCHANNEL_THIS(iface);
283 TRACE("(%p)->(%p)\n", This, aStatus);
286 return nsIChannel_GetStatus(This->channel, aStatus);
288 TRACE("returning NS_OK\n");
289 return *aStatus = NS_OK;
292 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
294 nsChannel *This = NSCHANNEL_THIS(iface);
296 TRACE("(%p)->(%08x)\n", This, aStatus);
299 return nsIChannel_Cancel(This->channel, aStatus);
301 FIXME("default action not implemented\n");
302 return NS_ERROR_NOT_IMPLEMENTED;
305 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
307 nsChannel *This = NSCHANNEL_THIS(iface);
309 TRACE("(%p)\n", This);
312 return nsIChannel_Suspend(This->channel);
314 FIXME("default action not implemented\n");
315 return NS_ERROR_NOT_IMPLEMENTED;
318 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
320 nsChannel *This = NSCHANNEL_THIS(iface);
322 TRACE("(%p)\n", This);
325 return nsIChannel_Resume(This->channel);
327 FIXME("default action not implemented\n");
328 return NS_ERROR_NOT_IMPLEMENTED;
331 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
333 nsChannel *This = NSCHANNEL_THIS(iface);
335 TRACE("(%p)->(%p)\n", This, aLoadGroup);
338 nsILoadGroup_AddRef(This->load_group);
340 *aLoadGroup = This->load_group;
344 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
346 nsChannel *This = NSCHANNEL_THIS(iface);
348 TRACE("(%p)->(%p)\n", This, aLoadGroup);
351 nsILoadGroup_Release(This->load_group);
353 nsILoadGroup_AddRef(aLoadGroup);
355 This->load_group = aLoadGroup;
358 return nsIChannel_SetLoadGroup(This->channel, aLoadGroup);
362 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
364 nsChannel *This = NSCHANNEL_THIS(iface);
366 TRACE("(%p)->(%p)\n", This, aLoadFlags);
368 *aLoadFlags = This->load_flags;
372 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
374 nsChannel *This = NSCHANNEL_THIS(iface);
376 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
378 This->load_flags = aLoadFlags;
381 return nsIChannel_SetLoadFlags(This->channel, aLoadFlags);
385 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
387 nsChannel *This = NSCHANNEL_THIS(iface);
389 TRACE("(%p)->(%p)\n", This, aOriginalURI);
391 if(This->original_uri)
392 nsIURI_AddRef(This->original_uri);
394 *aOriginalURI = This->original_uri;
398 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
400 nsChannel *This = NSCHANNEL_THIS(iface);
402 TRACE("(%p)->(%p)\n", This, aOriginalURI);
404 if(This->original_uri)
405 nsIURI_Release(This->original_uri);
407 nsIURI_AddRef(aOriginalURI);
408 This->original_uri = aOriginalURI;
411 return nsIChannel_SetOriginalURI(This->channel, aOriginalURI);
415 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
417 nsChannel *This = NSCHANNEL_THIS(iface);
419 TRACE("(%p)->(%p)\n", This, aURI);
421 nsIWineURI_AddRef(This->uri);
422 *aURI = (nsIURI*)This->uri;
427 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
429 nsChannel *This = NSCHANNEL_THIS(iface);
431 TRACE("(%p)->(%p)\n", This, aOwner);
434 return nsIChannel_GetOwner(This->channel, aOwner);
437 nsISupports_AddRef(This->owner);
438 *aOwner = This->owner;
443 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
445 nsChannel *This = NSCHANNEL_THIS(iface);
447 TRACE("(%p)->(%p)\n", This, aOwner);
450 return nsIChannel_SetOwner(This->channel, aOwner);
453 nsISupports_AddRef(aOwner);
455 nsISupports_Release(This->owner);
456 This->owner = aOwner;
461 static nsresult NSAPI nsChannel_GetNotificationCallbacks(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_AddRef(This->notif_callback);
470 *aNotificationCallbacks = This->notif_callback;
475 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
476 nsIInterfaceRequestor *aNotificationCallbacks)
478 nsChannel *This = NSCHANNEL_THIS(iface);
480 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
482 if(This->notif_callback)
483 nsIInterfaceRequestor_Release(This->notif_callback);
484 if(aNotificationCallbacks)
485 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
487 This->notif_callback = aNotificationCallbacks;
490 return nsIChannel_SetNotificationCallbacks(This->channel, aNotificationCallbacks);
494 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
496 nsChannel *This = NSCHANNEL_THIS(iface);
498 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
501 return nsIChannel_GetSecurityInfo(This->channel, aSecurityInfo);
503 FIXME("default action not implemented\n");
504 return NS_ERROR_NOT_IMPLEMENTED;
507 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
509 nsChannel *This = NSCHANNEL_THIS(iface);
511 TRACE("(%p)->(%p)\n", This, aContentType);
513 if(This->content_type) {
514 nsACString_SetData(aContentType, This->content_type);
519 return nsIChannel_GetContentType(This->channel, aContentType);
521 TRACE("returning default text/html\n");
522 nsACString_SetData(aContentType, "text/html");
526 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
527 const nsACString *aContentType)
529 nsChannel *This = NSCHANNEL_THIS(iface);
530 const char *content_type;
532 TRACE("(%p)->(%p)\n", This, aContentType);
534 nsACString_GetData(aContentType, &content_type);
536 TRACE("content_type %s\n", content_type);
538 heap_free(This->content_type);
539 This->content_type = heap_strdupA(content_type);
542 return nsIChannel_SetContentType(This->channel, aContentType);
547 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
548 nsACString *aContentCharset)
550 nsChannel *This = NSCHANNEL_THIS(iface);
552 TRACE("(%p)->(%p)\n", This, aContentCharset);
555 nsACString_SetData(aContentCharset, This->charset);
560 nsresult nsres = nsIChannel_GetContentCharset(This->channel, aContentCharset);
562 nsACString_GetData(aContentCharset, &ch);
566 nsACString_SetData(aContentCharset, "");
570 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
571 const nsACString *aContentCharset)
573 nsChannel *This = NSCHANNEL_THIS(iface);
575 TRACE("(%p)->(%p)\n", This, aContentCharset);
578 return nsIChannel_SetContentCharset(This->channel, aContentCharset);
580 FIXME("default action not implemented\n");
581 return NS_ERROR_NOT_IMPLEMENTED;
584 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
586 nsChannel *This = NSCHANNEL_THIS(iface);
588 TRACE("(%p)->(%p)\n", This, aContentLength);
591 return nsIChannel_GetContentLength(This->channel, aContentLength);
593 FIXME("default action not implemented\n");
594 return NS_ERROR_NOT_IMPLEMENTED;
597 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
599 nsChannel *This = NSCHANNEL_THIS(iface);
601 TRACE("(%p)->(%d)\n", This, aContentLength);
604 return nsIChannel_SetContentLength(This->channel, aContentLength);
606 FIXME("default action not implemented\n");
607 return NS_ERROR_NOT_IMPLEMENTED;
610 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
612 nsChannel *This = NSCHANNEL_THIS(iface);
614 TRACE("(%p)->(%p)\n", This, _retval);
617 return nsIChannel_Open(This->channel, _retval);
619 FIXME("default action not implemented\n");
620 return NS_ERROR_NOT_IMPLEMENTED;
623 static HRESULT create_mon_for_nschannel(nsChannel *channel, IMoniker **mon)
625 nsIWineURI *wine_uri;
630 if(!channel->original_uri) {
631 ERR("original_uri == NULL\n");
635 nsres = nsIURI_QueryInterface(channel->original_uri, &IID_nsIWineURI, (void**)&wine_uri);
636 if(NS_FAILED(nsres)) {
637 ERR("Could not get nsIWineURI: %08x\n", nsres);
641 nsIWineURI_GetWineURL(wine_uri, &wine_url);
642 nsIWineURI_Release(wine_uri);
644 TRACE("wine_url == NULL\n");
648 hres = CreateURLMoniker(NULL, wine_url, mon);
650 WARN("CreateURLMonikrer failed: %08x\n", hres);
655 static NSContainer *get_nscontainer_from_load_group(nsChannel *This)
657 NSContainer *container;
660 nsIWineURI *wine_uri;
664 nsres = nsILoadGroup_GetDefaultLoadRequest(This->load_group, &req);
665 if(NS_FAILED(nsres)) {
666 ERR("GetDefaultLoadRequest failed: %08x\n", nsres);
673 nsres = nsIRequest_QueryInterface(req, &IID_nsIChannel, (void**)&channel);
674 nsIRequest_Release(req);
675 if(NS_FAILED(nsres)) {
676 WARN("Could not get nsIChannel interface: %08x\n", nsres);
680 nsres = nsIChannel_GetURI(channel, &uri);
681 nsIChannel_Release(channel);
682 if(NS_FAILED(nsres)) {
683 ERR("GetURI failed: %08x\n", nsres);
687 nsres = nsIURI_QueryInterface(uri, &IID_nsIWineURI, (void**)&wine_uri);
689 if(NS_FAILED(nsres)) {
690 TRACE("Could not get nsIWineURI: %08x\n", nsres);
694 nsIWineURI_GetNSContainer(wine_uri, &container);
695 nsIWineURI_Release(wine_uri);
700 static nsresult async_open_doc_uri(nsChannel *This, NSContainer *container,
701 nsIStreamListener *listener, nsISupports *context, BOOL *open)
708 if(container->bscallback) {
709 channelbsc_set_channel(container->bscallback, This, listener, context);
711 if(container->doc && container->doc->mime) {
712 heap_free(This->content_type);
713 This->content_type = heap_strdupWtoA(container->doc->mime);
718 BOOL cont = before_async_open(This, container);
722 return NS_ERROR_UNEXPECTED;
725 if(!container->doc) {
727 ? nsIChannel_AsyncOpen(This->channel, listener, context)
728 : NS_ERROR_UNEXPECTED;
731 hres = create_mon_for_nschannel(This, &mon);
733 return NS_ERROR_UNEXPECTED;
735 set_current_mon(&container->doc->basedoc, mon);
742 static nsresult async_open(nsChannel *This, NSContainer *container, nsIStreamListener *listener,
743 nsISupports *context)
745 nsChannelBSC *bscallback;
746 IMoniker *mon = NULL;
750 hres = create_mon_for_nschannel(This, &mon);
752 return NS_ERROR_UNEXPECTED;
754 bscallback = create_channelbsc(mon);
755 IMoniker_Release(mon);
757 channelbsc_set_channel(bscallback, This, listener, context);
759 task = heap_alloc(sizeof(task_t));
761 task->doc = &container->doc->basedoc;
762 task->task_id = TASK_START_BINDING;
764 task->bscallback = bscallback;
771 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
772 nsISupports *aContext)
774 nsChannel *This = NSCHANNEL_THIS(iface);
775 NSContainer *container;
778 nsresult nsres = NS_OK;
780 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
782 nsIWineURI_GetNSContainer(This->uri, &container);
784 if(!container && This->load_group) {
785 container = get_nscontainer_from_load_group(This);
787 nsIWineURI_SetNSContainer(This->uri, container);
791 TRACE("container = NULL\n");
793 ? nsIChannel_AsyncOpen(This->channel, aListener, aContext)
794 : NS_ERROR_UNEXPECTED;
797 nsIWineURI_GetIsDocumentURI(This->uri, &is_doc_uri);
799 if(is_doc_uri && (This->load_flags & LOAD_INITIAL_DOCUMENT_URI))
800 nsres = async_open_doc_uri(This, container, aListener, aContext, &open);
803 nsres = async_open(This, container, aListener, aContext);
805 nsIWebBrowserChrome_Release(NSWBCHROME(container));
809 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
811 nsChannel *This = NSCHANNEL_THIS(iface);
813 TRACE("(%p)->(%p)\n", This, aRequestMethod);
815 if(This->http_channel)
816 return nsIHttpChannel_GetRequestMethod(This->http_channel, aRequestMethod);
818 return NS_ERROR_NOT_IMPLEMENTED;
821 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
822 const nsACString *aRequestMethod)
824 nsChannel *This = NSCHANNEL_THIS(iface);
826 TRACE("(%p)->(%p)\n", This, aRequestMethod);
828 if(This->http_channel)
829 return nsIHttpChannel_SetRequestMethod(This->http_channel, aRequestMethod);
831 return NS_ERROR_NOT_IMPLEMENTED;
834 static nsresult NSAPI nsChannel_GetReferrer(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_GetReferrer(This->http_channel, aReferrer);
843 return NS_ERROR_NOT_IMPLEMENTED;
846 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
848 nsChannel *This = NSCHANNEL_THIS(iface);
850 TRACE("(%p)->(%p)\n", This, aReferrer);
852 if(This->http_channel)
853 return nsIHttpChannel_SetReferrer(This->http_channel, aReferrer);
855 return NS_ERROR_NOT_IMPLEMENTED;
858 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
859 const nsACString *aHeader, nsACString *_retval)
861 nsChannel *This = NSCHANNEL_THIS(iface);
863 TRACE("(%p)->(%p %p)\n", This, aHeader, _retval);
865 if(This->http_channel)
866 return nsIHttpChannel_GetRequestHeader(This->http_channel, aHeader, _retval);
868 return NS_ERROR_NOT_IMPLEMENTED;
871 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
872 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
874 nsChannel *This = NSCHANNEL_THIS(iface);
876 TRACE("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
878 if(This->http_channel)
879 return nsIHttpChannel_SetRequestHeader(This->http_channel, aHeader, aValue, aMerge);
881 return NS_ERROR_NOT_IMPLEMENTED;
884 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
885 nsIHttpHeaderVisitor *aVisitor)
887 nsChannel *This = NSCHANNEL_THIS(iface);
889 TRACE("(%p)->(%p)\n", This, aVisitor);
891 if(This->http_channel)
892 return nsIHttpChannel_VisitRequestHeaders(This->http_channel, aVisitor);
894 return NS_ERROR_NOT_IMPLEMENTED;
897 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
899 nsChannel *This = NSCHANNEL_THIS(iface);
901 TRACE("(%p)->(%p)\n", This, aAllowPipelining);
903 if(This->http_channel)
904 return nsIHttpChannel_GetAllowPipelining(This->http_channel, aAllowPipelining);
906 return NS_ERROR_NOT_IMPLEMENTED;
909 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
911 nsChannel *This = NSCHANNEL_THIS(iface);
913 TRACE("(%p)->(%x)\n", This, aAllowPipelining);
915 if(This->http_channel)
916 return nsIHttpChannel_SetAllowPipelining(This->http_channel, aAllowPipelining);
918 return NS_ERROR_NOT_IMPLEMENTED;
921 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
923 nsChannel *This = NSCHANNEL_THIS(iface);
925 TRACE("(%p)->(%p)\n", This, aRedirectionLimit);
927 if(This->http_channel)
928 return nsIHttpChannel_GetRedirectionLimit(This->http_channel, aRedirectionLimit);
930 return NS_ERROR_NOT_IMPLEMENTED;
933 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
935 nsChannel *This = NSCHANNEL_THIS(iface);
937 TRACE("(%p)->(%u)\n", This, aRedirectionLimit);
939 if(This->http_channel)
940 return nsIHttpChannel_SetRedirectionLimit(This->http_channel, aRedirectionLimit);
942 return NS_ERROR_NOT_IMPLEMENTED;
945 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
947 nsChannel *This = NSCHANNEL_THIS(iface);
949 TRACE("(%p)->(%p)\n", This, aResponseStatus);
951 if(This->response_status) {
952 *aResponseStatus = This->response_status;
956 if(This->http_channel)
957 return nsIHttpChannel_GetResponseStatus(This->http_channel, aResponseStatus);
959 return NS_ERROR_UNEXPECTED;
962 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
963 nsACString *aResponseStatusText)
965 nsChannel *This = NSCHANNEL_THIS(iface);
967 TRACE("(%p)->(%p)\n", This, aResponseStatusText);
969 if(This->http_channel)
970 return nsIHttpChannel_GetResponseStatusText(This->http_channel, aResponseStatusText);
972 return NS_ERROR_NOT_IMPLEMENTED;
975 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
976 PRBool *aRequestSucceeded)
978 nsChannel *This = NSCHANNEL_THIS(iface);
980 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
982 if(This->http_channel)
983 return nsIHttpChannel_GetRequestSucceeded(This->http_channel, aRequestSucceeded);
985 return NS_ERROR_NOT_IMPLEMENTED;
988 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
989 const nsACString *header, nsACString *_retval)
991 nsChannel *This = NSCHANNEL_THIS(iface);
993 TRACE("(%p)->(%p %p)\n", This, header, _retval);
995 if(This->http_channel)
996 return nsIHttpChannel_GetResponseHeader(This->http_channel, header, _retval);
998 return NS_ERROR_NOT_IMPLEMENTED;
1001 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
1002 const nsACString *header, const nsACString *value, PRBool merge)
1004 nsChannel *This = NSCHANNEL_THIS(iface);
1006 TRACE("(%p)->(%p %p %x)\n", This, header, value, merge);
1008 if(This->http_channel)
1009 return nsIHttpChannel_SetResponseHeader(This->http_channel, header, value, merge);
1011 return NS_ERROR_NOT_IMPLEMENTED;
1014 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1015 nsIHttpHeaderVisitor *aVisitor)
1017 nsChannel *This = NSCHANNEL_THIS(iface);
1019 TRACE("(%p)->(%p)\n", This, aVisitor);
1021 if(This->http_channel)
1022 return nsIHttpChannel_VisitResponseHeaders(This->http_channel, aVisitor);
1024 return NS_ERROR_NOT_IMPLEMENTED;
1027 static nsresult NSAPI nsChannel_IsNoStoreResponse(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_IsNoStoreResponse(This->http_channel, _retval);
1036 return NS_ERROR_NOT_IMPLEMENTED;
1039 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
1041 nsChannel *This = NSCHANNEL_THIS(iface);
1043 TRACE("(%p)->(%p)\n", This, _retval);
1045 if(This->http_channel)
1046 return nsIHttpChannel_IsNoCacheResponse(This->http_channel, _retval);
1048 return NS_ERROR_NOT_IMPLEMENTED;
1051 #undef NSCHANNEL_THIS
1053 static const nsIHttpChannelVtbl nsChannelVtbl = {
1054 nsChannel_QueryInterface,
1058 nsChannel_IsPending,
1059 nsChannel_GetStatus,
1063 nsChannel_GetLoadGroup,
1064 nsChannel_SetLoadGroup,
1065 nsChannel_GetLoadFlags,
1066 nsChannel_SetLoadFlags,
1067 nsChannel_GetOriginalURI,
1068 nsChannel_SetOriginalURI,
1072 nsChannel_GetNotificationCallbacks,
1073 nsChannel_SetNotificationCallbacks,
1074 nsChannel_GetSecurityInfo,
1075 nsChannel_GetContentType,
1076 nsChannel_SetContentType,
1077 nsChannel_GetContentCharset,
1078 nsChannel_SetContentCharset,
1079 nsChannel_GetContentLength,
1080 nsChannel_SetContentLength,
1082 nsChannel_AsyncOpen,
1083 nsChannel_GetRequestMethod,
1084 nsChannel_SetRequestMethod,
1085 nsChannel_GetReferrer,
1086 nsChannel_SetReferrer,
1087 nsChannel_GetRequestHeader,
1088 nsChannel_SetRequestHeader,
1089 nsChannel_VisitRequestHeaders,
1090 nsChannel_GetAllowPipelining,
1091 nsChannel_SetAllowPipelining,
1092 nsChannel_GetRedirectionLimit,
1093 nsChannel_SetRedirectionLimit,
1094 nsChannel_GetResponseStatus,
1095 nsChannel_GetResponseStatusText,
1096 nsChannel_GetRequestSucceeded,
1097 nsChannel_GetResponseHeader,
1098 nsChannel_SetResponseHeader,
1099 nsChannel_VisitResponseHeaders,
1100 nsChannel_IsNoStoreResponse,
1101 nsChannel_IsNoCacheResponse
1104 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1106 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1109 nsChannel *This = NSUPCHANNEL_THIS(iface);
1110 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1113 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1115 nsChannel *This = NSUPCHANNEL_THIS(iface);
1116 return nsIChannel_AddRef(NSCHANNEL(This));
1119 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1121 nsChannel *This = NSUPCHANNEL_THIS(iface);
1122 return nsIChannel_Release(NSCHANNEL(This));
1125 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1126 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1128 nsChannel *This = NSUPCHANNEL_THIS(iface);
1129 const char *content_type;
1132 TRACE("(%p)->(%p %p %d)\n", This, aStream, aContentType, aContentLength);
1134 if(This->post_data_stream)
1135 nsIInputStream_Release(This->post_data_stream);
1138 nsACString_GetData(aContentType, &content_type);
1140 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
1143 if(aContentLength != -1)
1144 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1146 if(This->post_data_stream)
1147 nsIInputStream_Release(This->post_data_stream);
1148 This->post_data_stream = aStream;
1150 nsIInputStream_AddRef(aStream);
1152 if(This->post_data_stream) {
1153 nsIUploadChannel *upload_channel;
1155 nsres = nsIChannel_QueryInterface(This->channel, &IID_nsIUploadChannel,
1156 (void**)&upload_channel);
1157 if(NS_SUCCEEDED(nsres)) {
1158 nsres = nsIUploadChannel_SetUploadStream(upload_channel, aStream, aContentType, aContentLength);
1159 nsIUploadChannel_Release(upload_channel);
1160 if(NS_FAILED(nsres))
1161 WARN("SetUploadStream failed: %08x\n", nsres);
1169 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1170 nsIInputStream **aUploadStream)
1172 nsChannel *This = NSUPCHANNEL_THIS(iface);
1174 TRACE("(%p)->(%p)\n", This, aUploadStream);
1176 if(This->post_data_stream)
1177 nsIInputStream_AddRef(This->post_data_stream);
1179 *aUploadStream = This->post_data_stream;
1183 #undef NSUPCHANNEL_THIS
1185 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1186 nsUploadChannel_QueryInterface,
1187 nsUploadChannel_AddRef,
1188 nsUploadChannel_Release,
1189 nsUploadChannel_SetUploadStream,
1190 nsUploadChannel_GetUploadStream
1193 #define NSHTTPINTERNAL_THIS(iface) DEFINE_THIS(nsChannel, IHttpChannelInternal, iface)
1195 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1198 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1199 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1202 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1204 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1205 return nsIChannel_AddRef(NSCHANNEL(This));
1208 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1210 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1211 return nsIChannel_Release(NSCHANNEL(This));
1214 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1216 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1218 TRACE("(%p)->()\n", This);
1220 if(This->http_channel_internal)
1221 return nsIHttpChannelInternal_GetDocumentURI(This->http_channel_internal, aDocumentURI);
1222 return NS_ERROR_NOT_IMPLEMENTED;
1225 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1227 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1229 TRACE("(%p)->()\n", This);
1231 if(This->http_channel_internal)
1232 return nsIHttpChannelInternal_SetDocumentURI(This->http_channel_internal, aDocumentURI);
1233 return NS_ERROR_NOT_IMPLEMENTED;
1236 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1238 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1240 TRACE("(%p)->()\n", This);
1242 if(This->http_channel_internal)
1243 return nsIHttpChannelInternal_GetRequestVersion(This->http_channel_internal, major, minor);
1244 return NS_ERROR_NOT_IMPLEMENTED;
1247 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1249 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1251 TRACE("(%p)->()\n", This);
1253 if(This->http_channel_internal)
1254 return nsIHttpChannelInternal_GetResponseVersion(This->http_channel_internal, major, minor);
1255 return NS_ERROR_NOT_IMPLEMENTED;
1258 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1260 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1262 TRACE("(%p)->()\n", This);
1264 if(This->http_channel_internal)
1265 return nsIHttpChannelInternal_SetCookie(This->http_channel_internal, aCookieHeader);
1266 return NS_ERROR_NOT_IMPLEMENTED;
1269 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1271 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1273 TRACE("(%p)->()\n", This);
1275 if(This->http_channel_internal)
1276 return nsIHttpChannelInternal_SetupFallbackChannel(This->http_channel_internal, aFallbackKey);
1277 return NS_ERROR_NOT_IMPLEMENTED;
1280 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool *aForceThirdPartyCookie)
1282 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1284 TRACE("(%p)->()\n", This);
1286 if(This->http_channel_internal)
1287 return nsIHttpChannelInternal_GetForceAllowThirdPartyCookie(This->http_channel_internal, aForceThirdPartyCookie);
1288 return NS_ERROR_NOT_IMPLEMENTED;
1291 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool aForceThirdPartyCookie)
1293 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1295 TRACE("(%p)->()\n", This);
1297 if(This->http_channel_internal)
1298 return nsIHttpChannelInternal_SetForceAllowThirdPartyCookie(This->http_channel_internal, aForceThirdPartyCookie);
1299 return NS_ERROR_NOT_IMPLEMENTED;
1302 #undef NSHTTPINTERNAL_THIS
1304 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
1305 nsHttpChannelInternal_QueryInterface,
1306 nsHttpChannelInternal_AddRef,
1307 nsHttpChannelInternal_Release,
1308 nsHttpChannelInternal_GetDocumentURI,
1309 nsHttpChannelInternal_SetDocumentURI,
1310 nsHttpChannelInternal_GetRequestVersion,
1311 nsHttpChannelInternal_GetResponseVersion,
1312 nsHttpChannelInternal_SetCookie,
1313 nsHttpChannelInternal_SetupFallbackChannel,
1314 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
1315 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
1318 #define NSURI_THIS(iface) DEFINE_THIS(nsURI, WineURI, iface)
1320 static nsresult NSAPI nsURI_QueryInterface(nsIWineURI *iface, nsIIDRef riid, nsQIResult result)
1322 nsURI *This = NSURI_THIS(iface);
1326 if(IsEqualGUID(&IID_nsISupports, riid)) {
1327 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1328 *result = NSURI(This);
1329 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1330 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1331 *result = NSURI(This);
1332 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
1333 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
1334 *result = NSURI(This);
1335 }else if(IsEqualGUID(&IID_nsIWineURI, riid)) {
1336 TRACE("(%p)->(IID_nsIWineURI %p)\n", This, result);
1337 *result = NSURI(This);
1341 nsIURI_AddRef(NSURI(This));
1345 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1346 return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1349 static nsrefcnt NSAPI nsURI_AddRef(nsIWineURI *iface)
1351 nsURI *This = NSURI_THIS(iface);
1352 LONG ref = InterlockedIncrement(&This->ref);
1354 TRACE("(%p) ref=%d\n", This, ref);
1359 static nsrefcnt NSAPI nsURI_Release(nsIWineURI *iface)
1361 nsURI *This = NSURI_THIS(iface);
1362 LONG ref = InterlockedDecrement(&This->ref);
1364 TRACE("(%p) ref=%d\n", This, ref);
1368 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1370 nsIURL_Release(This->nsurl);
1372 nsIURI_Release(This->uri);
1373 heap_free(This->wine_url);
1380 static nsresult NSAPI nsURI_GetSpec(nsIWineURI *iface, nsACString *aSpec)
1382 nsURI *This = NSURI_THIS(iface);
1384 TRACE("(%p)->(%p)\n", This, aSpec);
1386 if(This->use_wine_url) {
1387 char speca[INTERNET_MAX_URL_LENGTH] = "wine:";
1388 WideCharToMultiByte(CP_ACP, 0, This->wine_url, -1, speca+5, sizeof(speca)-5, NULL, NULL);
1389 nsACString_SetData(aSpec, speca);
1395 return nsIURI_GetSpec(This->uri, aSpec);
1397 TRACE("returning error\n");
1398 return NS_ERROR_NOT_IMPLEMENTED;
1402 static nsresult NSAPI nsURI_SetSpec(nsIWineURI *iface, const nsACString *aSpec)
1404 nsURI *This = NSURI_THIS(iface);
1406 TRACE("(%p)->(%p)\n", This, aSpec);
1409 return nsIURI_SetSpec(This->uri, aSpec);
1411 FIXME("default action not implemented\n");
1412 return NS_ERROR_NOT_IMPLEMENTED;
1415 static nsresult NSAPI nsURI_GetPrePath(nsIWineURI *iface, nsACString *aPrePath)
1417 nsURI *This = NSURI_THIS(iface);
1419 TRACE("(%p)->(%p)\n", This, aPrePath);
1422 return nsIURI_GetPrePath(This->uri, aPrePath);
1424 FIXME("default action not implemented\n");
1425 return NS_ERROR_NOT_IMPLEMENTED;
1428 static nsresult NSAPI nsURI_GetScheme(nsIWineURI *iface, nsACString *aScheme)
1430 nsURI *This = NSURI_THIS(iface);
1432 TRACE("(%p)->(%p)\n", This, aScheme);
1434 if(This->use_wine_url && strcmpW(This->wine_url, about_blankW)) {
1436 * For Gecko we set scheme to unknown so it won't be handled
1437 * as any special case.
1439 nsACString_SetData(aScheme, "wine");
1444 return nsIURI_GetScheme(This->uri, aScheme);
1446 TRACE("returning error\n");
1447 return NS_ERROR_NOT_IMPLEMENTED;
1450 static nsresult NSAPI nsURI_SetScheme(nsIWineURI *iface, const nsACString *aScheme)
1452 nsURI *This = NSURI_THIS(iface);
1454 TRACE("(%p)->(%p)\n", This, aScheme);
1457 return nsIURI_SetScheme(This->uri, aScheme);
1459 FIXME("default action not implemented\n");
1460 return NS_ERROR_NOT_IMPLEMENTED;
1463 static nsresult NSAPI nsURI_GetUserPass(nsIWineURI *iface, nsACString *aUserPass)
1465 nsURI *This = NSURI_THIS(iface);
1467 TRACE("(%p)->(%p)\n", This, aUserPass);
1470 return nsIURI_GetUserPass(This->uri, aUserPass);
1472 FIXME("default action not implemented\n");
1473 return NS_ERROR_NOT_IMPLEMENTED;
1476 static nsresult NSAPI nsURI_SetUserPass(nsIWineURI *iface, const nsACString *aUserPass)
1478 nsURI *This = NSURI_THIS(iface);
1480 TRACE("(%p)->(%p)\n", This, aUserPass);
1483 return nsIURI_SetUserPass(This->uri, aUserPass);
1485 FIXME("default action not implemented\n");
1486 return NS_ERROR_NOT_IMPLEMENTED;
1489 static nsresult NSAPI nsURI_GetUsername(nsIWineURI *iface, nsACString *aUsername)
1491 nsURI *This = NSURI_THIS(iface);
1493 TRACE("(%p)->(%p)\n", This, aUsername);
1496 return nsIURI_GetUsername(This->uri, aUsername);
1498 FIXME("default action not implemented\n");
1499 return NS_ERROR_NOT_IMPLEMENTED;
1502 static nsresult NSAPI nsURI_SetUsername(nsIWineURI *iface, const nsACString *aUsername)
1504 nsURI *This = NSURI_THIS(iface);
1506 TRACE("(%p)->(%p)\n", This, aUsername);
1509 return nsIURI_SetUsername(This->uri, aUsername);
1511 FIXME("default action not implemented\n");
1512 return NS_ERROR_NOT_IMPLEMENTED;
1515 static nsresult NSAPI nsURI_GetPassword(nsIWineURI *iface, nsACString *aPassword)
1517 nsURI *This = NSURI_THIS(iface);
1519 TRACE("(%p)->(%p)\n", This, aPassword);
1522 return nsIURI_GetPassword(This->uri, aPassword);
1524 FIXME("default action not implemented\n");
1525 return NS_ERROR_NOT_IMPLEMENTED;
1528 static nsresult NSAPI nsURI_SetPassword(nsIWineURI *iface, const nsACString *aPassword)
1530 nsURI *This = NSURI_THIS(iface);
1532 TRACE("(%p)->(%p)\n", This, aPassword);
1535 return nsIURI_SetPassword(This->uri, aPassword);
1537 FIXME("default action not implemented\n");
1538 return NS_ERROR_NOT_IMPLEMENTED;
1541 static nsresult NSAPI nsURI_GetHostPort(nsIWineURI *iface, nsACString *aHostPort)
1543 nsURI *This = NSURI_THIS(iface);
1545 TRACE("(%p)->(%p)\n", This, aHostPort);
1548 return nsIURI_GetHostPort(This->uri, aHostPort);
1550 FIXME("default action not implemented\n");
1551 return NS_ERROR_NOT_IMPLEMENTED;
1554 static nsresult NSAPI nsURI_SetHostPort(nsIWineURI *iface, const nsACString *aHostPort)
1556 nsURI *This = NSURI_THIS(iface);
1558 TRACE("(%p)->(%p)\n", This, aHostPort);
1561 return nsIURI_SetHostPort(This->uri, aHostPort);
1563 FIXME("default action not implemented\n");
1564 return NS_ERROR_NOT_IMPLEMENTED;
1567 static nsresult NSAPI nsURI_GetHost(nsIWineURI *iface, nsACString *aHost)
1569 nsURI *This = NSURI_THIS(iface);
1571 TRACE("(%p)->(%p)\n", This, aHost);
1574 return nsIURI_GetHost(This->uri, aHost);
1576 FIXME("default action not implemented\n");
1577 return NS_ERROR_NOT_IMPLEMENTED;
1580 static nsresult NSAPI nsURI_SetHost(nsIWineURI *iface, const nsACString *aHost)
1582 nsURI *This = NSURI_THIS(iface);
1584 TRACE("(%p)->(%p)\n", This, aHost);
1587 return nsIURI_SetHost(This->uri, aHost);
1589 FIXME("default action not implemented\n");
1590 return NS_ERROR_NOT_IMPLEMENTED;
1593 static nsresult NSAPI nsURI_GetPort(nsIWineURI *iface, PRInt32 *aPort)
1595 nsURI *This = NSURI_THIS(iface);
1597 TRACE("(%p)->(%p)\n", This, aPort);
1600 return nsIURI_GetPort(This->uri, aPort);
1602 FIXME("default action not implemented\n");
1603 return NS_ERROR_NOT_IMPLEMENTED;
1606 static nsresult NSAPI nsURI_SetPort(nsIWineURI *iface, PRInt32 aPort)
1608 nsURI *This = NSURI_THIS(iface);
1610 TRACE("(%p)->(%d)\n", This, aPort);
1613 return nsIURI_SetPort(This->uri, aPort);
1615 FIXME("default action not implemented\n");
1616 return NS_ERROR_NOT_IMPLEMENTED;
1619 static nsresult NSAPI nsURI_GetPath(nsIWineURI *iface, nsACString *aPath)
1621 nsURI *This = NSURI_THIS(iface);
1623 TRACE("(%p)->(%p)\n", This, aPath);
1626 return nsIURI_GetPath(This->uri, aPath);
1628 FIXME("default action not implemented\n");
1629 return NS_ERROR_NOT_IMPLEMENTED;
1632 static nsresult NSAPI nsURI_SetPath(nsIWineURI *iface, const nsACString *aPath)
1634 nsURI *This = NSURI_THIS(iface);
1637 nsACString_GetData(aPath, &path);
1638 TRACE("(%p)->(%p(%s))\n", This, aPath, debugstr_a(path));
1641 if(This->wine_url) {
1642 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
1643 DWORD size = sizeof(new_url)/sizeof(WCHAR);
1647 pathw = heap_strdupAtoW(path);
1648 hres = UrlCombineW(This->wine_url, pathw, new_url, &size, 0);
1651 nsIWineURI_SetWineURL(NSWINEURI(This), new_url);
1653 WARN("UrlCombine failed: %08x\n", hres);
1659 return nsIURI_SetPath(This->uri, aPath);
1662 static nsresult NSAPI nsURI_Equals(nsIWineURI *iface, nsIURI *other, PRBool *_retval)
1664 nsURI *This = NSURI_THIS(iface);
1665 nsIWineURI *wine_uri;
1666 LPCWSTR other_url = NULL;
1669 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1672 return nsIURI_Equals(This->uri, other, _retval);
1674 nsres = nsIURI_QueryInterface(other, &IID_nsIWineURI, (void**)&wine_uri);
1675 if(NS_FAILED(nsres)) {
1676 TRACE("Could not get nsIWineURI interface\n");
1681 nsIWineURI_GetWineURL(wine_uri, &other_url);
1682 *_retval = !UrlCompareW(This->wine_url, other_url, TRUE);
1683 nsIWineURI_Release(wine_uri);
1688 static nsresult NSAPI nsURI_SchemeIs(nsIWineURI *iface, const char *scheme, PRBool *_retval)
1690 nsURI *This = NSURI_THIS(iface);
1692 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1694 if(This->use_wine_url) {
1695 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
1696 int len = MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR))-1;
1698 *_retval = lstrlenW(This->wine_url) > len
1699 && This->wine_url[len] == ':'
1700 && !memcmp(buf, This->wine_url, len*sizeof(WCHAR));
1705 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1707 TRACE("returning error\n");
1708 return NS_ERROR_NOT_IMPLEMENTED;
1711 static nsresult NSAPI nsURI_Clone(nsIWineURI *iface, nsIURI **_retval)
1713 nsURI *This = NSURI_THIS(iface);
1714 nsIURI *nsuri = NULL;
1715 nsIWineURI *wine_uri;
1718 TRACE("(%p)->(%p)\n", This, _retval);
1721 nsres = nsIURI_Clone(This->uri, &nsuri);
1722 if(NS_FAILED(nsres)) {
1723 WARN("Clone failed: %08x\n", nsres);
1728 nsres = create_uri(nsuri, This->container, &wine_uri);
1729 if(NS_FAILED(nsres)) {
1730 WARN("create_uri failed: %08x\n", nsres);
1734 *_retval = (nsIURI*)wine_uri;
1735 return nsIWineURI_SetWineURL(wine_uri, This->wine_url);
1738 static nsresult NSAPI nsURI_Resolve(nsIWineURI *iface, const nsACString *arelativePath,
1739 nsACString *_retval)
1741 nsURI *This = NSURI_THIS(iface);
1743 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1746 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1748 FIXME("default action not implemented\n");
1749 return NS_ERROR_NOT_IMPLEMENTED;
1752 static nsresult NSAPI nsURI_GetAsciiSpec(nsIWineURI *iface, nsACString *aAsciiSpec)
1754 nsURI *This = NSURI_THIS(iface);
1756 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1758 if(This->use_wine_url)
1759 return nsIURI_GetSpec(NSURI(This), aAsciiSpec);
1762 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1764 TRACE("returning error\n");
1765 return NS_ERROR_NOT_IMPLEMENTED;
1768 static nsresult NSAPI nsURI_GetAsciiHost(nsIWineURI *iface, nsACString *aAsciiHost)
1770 nsURI *This = NSURI_THIS(iface);
1772 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1775 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1777 FIXME("default action not implemented\n");
1778 return NS_ERROR_NOT_IMPLEMENTED;
1781 static nsresult NSAPI nsURI_GetOriginCharset(nsIWineURI *iface, nsACString *aOriginCharset)
1783 nsURI *This = NSURI_THIS(iface);
1785 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1788 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1790 FIXME("default action not implemented\n");
1791 return NS_ERROR_NOT_IMPLEMENTED;
1794 static nsresult NSAPI nsURL_GetFilePath(nsIWineURI *iface, nsACString *aFilePath)
1796 nsURI *This = NSURI_THIS(iface);
1798 TRACE("(%p)->(%p)\n", This, aFilePath);
1801 return nsIURL_GetFilePath(This->nsurl, aFilePath);
1803 FIXME("default action not implemented\n");
1804 return NS_ERROR_NOT_IMPLEMENTED;
1807 static nsresult NSAPI nsURL_SetFilePath(nsIWineURI *iface, const nsACString *aFilePath)
1809 nsURI *This = NSURI_THIS(iface);
1811 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
1814 return nsIURL_SetFilePath(This->nsurl, aFilePath);
1816 FIXME("default action not implemented\n");
1817 return NS_ERROR_NOT_IMPLEMENTED;
1820 static nsresult NSAPI nsURL_GetParam(nsIWineURI *iface, nsACString *aParam)
1822 nsURI *This = NSURI_THIS(iface);
1824 TRACE("(%p)->(%p)\n", This, aParam);
1827 return nsIURL_GetParam(This->nsurl, aParam);
1829 FIXME("default action not implemented\n");
1830 return NS_ERROR_NOT_IMPLEMENTED;
1833 static nsresult NSAPI nsURL_SetParam(nsIWineURI *iface, const nsACString *aParam)
1835 nsURI *This = NSURI_THIS(iface);
1837 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aParam));
1840 return nsIURL_SetParam(This->nsurl, aParam);
1842 FIXME("default action not implemented\n");
1843 return NS_ERROR_NOT_IMPLEMENTED;
1846 static nsresult NSAPI nsURL_GetQuery(nsIWineURI *iface, nsACString *aQuery)
1848 nsURI *This = NSURI_THIS(iface);
1850 TRACE("(%p)->(%p)\n", This, aQuery);
1853 return nsIURL_GetQuery(This->nsurl, aQuery);
1855 FIXME("default action not implemented\n");
1856 return NS_ERROR_NOT_IMPLEMENTED;
1859 static nsresult NSAPI nsURL_SetQuery(nsIWineURI *iface, const nsACString *aQuery)
1861 nsURI *This = NSURI_THIS(iface);
1862 const WCHAR *ptr1, *ptr2;
1864 WCHAR *new_url, *ptr;
1867 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
1870 nsIURL_SetQuery(This->nsurl, aQuery);
1875 nsACString_GetData(aQuery, &query);
1876 size = len = MultiByteToWideChar(CP_ACP, 0, query, -1, NULL, 0);
1877 ptr1 = strchrW(This->wine_url, '?');
1879 size += ptr1-This->wine_url;
1880 ptr2 = strchrW(ptr1, '#');
1882 size += strlenW(ptr2);
1884 ptr1 = This->wine_url + strlenW(This->wine_url);
1886 size += strlenW(This->wine_url);
1892 new_url = heap_alloc(size*sizeof(WCHAR));
1893 memcpy(new_url, This->wine_url, (ptr1-This->wine_url)*sizeof(WCHAR));
1894 ptr = new_url + (ptr1-This->wine_url);
1897 MultiByteToWideChar(CP_ACP, 0, query, -1, ptr, len);
1905 TRACE("setting %s\n", debugstr_w(new_url));
1907 heap_free(This->wine_url);
1908 This->wine_url = new_url;
1912 static nsresult NSAPI nsURL_GetRef(nsIWineURI *iface, nsACString *aRef)
1914 nsURI *This = NSURI_THIS(iface);
1916 TRACE("(%p)->(%p)\n", This, aRef);
1919 return nsIURL_GetRef(This->nsurl, aRef);
1921 FIXME("default action not implemented\n");
1922 return NS_ERROR_NOT_IMPLEMENTED;
1925 static nsresult NSAPI nsURL_SetRef(nsIWineURI *iface, const nsACString *aRef)
1927 nsURI *This = NSURI_THIS(iface);
1929 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
1932 return nsIURL_SetRef(This->nsurl, aRef);
1934 FIXME("default action not implemented\n");
1935 return NS_ERROR_NOT_IMPLEMENTED;
1938 static nsresult NSAPI nsURL_GetDirectory(nsIWineURI *iface, nsACString *aDirectory)
1940 nsURI *This = NSURI_THIS(iface);
1942 TRACE("(%p)->(%p)\n", This, aDirectory);
1945 return nsIURL_GetDirectory(This->nsurl, aDirectory);
1947 FIXME("default action not implemented\n");
1948 return NS_ERROR_NOT_IMPLEMENTED;
1951 static nsresult NSAPI nsURL_SetDirectory(nsIWineURI *iface, const nsACString *aDirectory)
1953 nsURI *This = NSURI_THIS(iface);
1955 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
1958 return nsIURL_SetDirectory(This->nsurl, aDirectory);
1960 FIXME("default action not implemented\n");
1961 return NS_ERROR_NOT_IMPLEMENTED;
1964 static nsresult NSAPI nsURL_GetFileName(nsIWineURI *iface, nsACString *aFileName)
1966 nsURI *This = NSURI_THIS(iface);
1968 TRACE("(%p)->(%p)\n", This, aFileName);
1971 return nsIURL_GetFileName(This->nsurl, aFileName);
1973 FIXME("default action not implemented\n");
1974 return NS_ERROR_NOT_IMPLEMENTED;
1977 static nsresult NSAPI nsURL_SetFileName(nsIWineURI *iface, const nsACString *aFileName)
1979 nsURI *This = NSURI_THIS(iface);
1981 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
1984 return nsIURL_SetFileName(This->nsurl, aFileName);
1986 FIXME("default action not implemented\n");
1987 return NS_ERROR_NOT_IMPLEMENTED;
1990 static nsresult NSAPI nsURL_GetFileBaseName(nsIWineURI *iface, nsACString *aFileBaseName)
1992 nsURI *This = NSURI_THIS(iface);
1994 TRACE("(%p)->(%p)\n", This, aFileBaseName);
1997 return nsIURL_GetFileBaseName(This->nsurl, aFileBaseName);
1999 FIXME("default action not implemented\n");
2000 return NS_ERROR_NOT_IMPLEMENTED;
2003 static nsresult NSAPI nsURL_SetFileBaseName(nsIWineURI *iface, const nsACString *aFileBaseName)
2005 nsURI *This = NSURI_THIS(iface);
2007 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
2010 return nsIURL_SetFileBaseName(This->nsurl, aFileBaseName);
2012 FIXME("default action not implemented\n");
2013 return NS_ERROR_NOT_IMPLEMENTED;
2016 static nsresult NSAPI nsURL_GetFileExtension(nsIWineURI *iface, nsACString *aFileExtension)
2018 nsURI *This = NSURI_THIS(iface);
2020 TRACE("(%p)->(%p)\n", This, aFileExtension);
2023 return nsIURL_GetFileExtension(This->nsurl, aFileExtension);
2025 FIXME("default action not implemented\n");
2026 return NS_ERROR_NOT_IMPLEMENTED;
2029 static nsresult NSAPI nsURL_SetFileExtension(nsIWineURI *iface, const nsACString *aFileExtension)
2031 nsURI *This = NSURI_THIS(iface);
2033 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
2036 return nsIURL_SetFileExtension(This->nsurl, aFileExtension);
2038 FIXME("default action not implemented\n");
2039 return NS_ERROR_NOT_IMPLEMENTED;
2042 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIWineURI *iface, nsIURI *aURIToCompare, nsACString *_retval)
2044 nsURI *This = NSURI_THIS(iface);
2046 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2049 return nsIURL_GetCommonBaseSpec(This->nsurl, aURIToCompare, _retval);
2051 FIXME("default action not implemented\n");
2052 return NS_ERROR_NOT_IMPLEMENTED;
2055 static nsresult NSAPI nsURL_GetRelativeSpec(nsIWineURI *iface, nsIURI *aURIToCompare, nsACString *_retval)
2057 nsURI *This = NSURI_THIS(iface);
2059 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
2062 return nsIURL_GetRelativeSpec(This->nsurl, aURIToCompare, _retval);
2064 FIXME("default action not implemented\n");
2065 return NS_ERROR_NOT_IMPLEMENTED;
2068 static nsresult NSAPI nsURI_GetNSContainer(nsIWineURI *iface, NSContainer **aContainer)
2070 nsURI *This = NSURI_THIS(iface);
2072 TRACE("(%p)->(%p)\n", This, aContainer);
2075 nsIWebBrowserChrome_AddRef(NSWBCHROME(This->container));
2076 *aContainer = This->container;
2081 static nsresult NSAPI nsURI_SetNSContainer(nsIWineURI *iface, NSContainer *aContainer)
2083 nsURI *This = NSURI_THIS(iface);
2085 TRACE("(%p)->(%p)\n", This, aContainer);
2087 if(This->container) {
2088 if(This->container == aContainer)
2090 TRACE("Changing %p -> %p\n", This->container, aContainer);
2091 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
2095 nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer));
2096 This->container = aContainer;
2101 static nsresult NSAPI nsURI_GetIsDocumentURI(nsIWineURI *iface, PRBool *aIsDocumentURI)
2103 nsURI *This = NSURI_THIS(iface);
2105 TRACE("(%p)->(%p)\n", This, aIsDocumentURI);
2107 *aIsDocumentURI = This->is_doc_uri;
2111 static nsresult NSAPI nsURI_SetIsDocumentURI(nsIWineURI *iface, PRBool aIsDocumentURI)
2113 nsURI *This = NSURI_THIS(iface);
2115 TRACE("(%p)->(%x)\n", This, aIsDocumentURI);
2117 This->is_doc_uri = aIsDocumentURI;
2121 static nsresult NSAPI nsURI_GetWineURL(nsIWineURI *iface, LPCWSTR *aURL)
2123 nsURI *This = NSURI_THIS(iface);
2125 TRACE("(%p)->(%p)\n", This, aURL);
2127 *aURL = This->wine_url;
2131 static nsresult NSAPI nsURI_SetWineURL(nsIWineURI *iface, LPCWSTR aURL)
2133 nsURI *This = NSURI_THIS(iface);
2135 static const WCHAR wszFtp[] = {'f','t','p',':'};
2136 static const WCHAR wszHttp[] = {'h','t','t','p',':'};
2137 static const WCHAR wszHttps[] = {'h','t','t','p','s',':'};
2139 TRACE("(%p)->(%s)\n", This, debugstr_w(aURL));
2141 heap_free(This->wine_url);
2144 int len = strlenW(aURL)+1;
2145 This->wine_url = heap_alloc(len*sizeof(WCHAR));
2146 memcpy(This->wine_url, aURL, len*sizeof(WCHAR));
2148 /* FIXME: Always use wine url */
2149 This->use_wine_url =
2150 strncmpW(aURL, wszFtp, sizeof(wszFtp)/sizeof(WCHAR))
2151 && strncmpW(aURL, wszHttp, sizeof(wszHttp)/sizeof(WCHAR))
2152 && strncmpW(aURL, wszHttps, sizeof(wszHttps)/sizeof(WCHAR));
2154 This->wine_url = NULL;
2155 This->use_wine_url = FALSE;
2163 static const nsIWineURIVtbl nsWineURIVtbl = {
2164 nsURI_QueryInterface,
2192 nsURI_GetOriginCharset,
2205 nsURL_GetFileBaseName,
2206 nsURL_SetFileBaseName,
2207 nsURL_GetFileExtension,
2208 nsURL_SetFileExtension,
2209 nsURL_GetCommonBaseSpec,
2210 nsURL_GetRelativeSpec,
2211 nsURI_GetNSContainer,
2212 nsURI_SetNSContainer,
2213 nsURI_GetIsDocumentURI,
2214 nsURI_SetIsDocumentURI,
2219 static nsresult create_uri(nsIURI *uri, NSContainer *container, nsIWineURI **_retval)
2221 nsURI *ret = heap_alloc(sizeof(nsURI));
2223 ret->lpWineURIVtbl = &nsWineURIVtbl;
2226 ret->container = container;
2227 ret->wine_url = NULL;
2228 ret->is_doc_uri = FALSE;
2229 ret->use_wine_url = FALSE;
2232 nsIWebBrowserChrome_AddRef(NSWBCHROME(container));
2235 nsIURI_QueryInterface(uri, &IID_nsIURL, (void**)&ret->nsurl);
2239 TRACE("retval=%p\n", ret);
2240 *_retval = NSWINEURI(ret);
2245 const nsIProtocolHandlerVtbl *lpProtocolHandlerVtbl;
2249 nsIProtocolHandler *nshandler;
2250 } nsProtocolHandler;
2252 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
2254 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
2256 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
2259 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2263 if(IsEqualGUID(&IID_nsISupports, riid)) {
2264 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
2265 *result = NSPROTHANDLER(This);
2266 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
2267 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
2268 *result = NSPROTHANDLER(This);
2269 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
2270 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
2271 return NS_NOINTERFACE;
2275 nsISupports_AddRef((nsISupports*)*result);
2279 WARN("(%s %p)\n", debugstr_guid(riid), result);
2280 return NS_NOINTERFACE;
2283 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
2285 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2286 LONG ref = InterlockedIncrement(&This->ref);
2288 TRACE("(%p) ref=%d\n", This, ref);
2293 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
2295 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2296 LONG ref = InterlockedDecrement(&This->ref);
2298 TRACE("(%p) ref=%d\n", This, ref);
2302 nsIProtocolHandler_Release(This->nshandler);
2309 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
2311 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2313 TRACE("(%p)->(%p)\n", This, aScheme);
2316 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
2317 return NS_ERROR_NOT_IMPLEMENTED;
2320 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
2321 PRInt32 *aDefaultPort)
2323 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2325 TRACE("(%p)->(%p)\n", This, aDefaultPort);
2328 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
2329 return NS_ERROR_NOT_IMPLEMENTED;
2332 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
2333 PRUint32 *aProtocolFlags)
2335 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2337 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
2340 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
2341 return NS_ERROR_NOT_IMPLEMENTED;
2344 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
2345 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2347 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2349 TRACE("((%p)->%p %s %p %p)\n", This, aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2352 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
2353 return NS_ERROR_NOT_IMPLEMENTED;
2356 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
2357 nsIURI *aURI, nsIChannel **_retval)
2359 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2361 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
2364 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
2365 return NS_ERROR_NOT_IMPLEMENTED;
2368 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
2369 PRInt32 port, const char *scheme, PRBool *_retval)
2371 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2373 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
2376 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
2377 return NS_ERROR_NOT_IMPLEMENTED;
2380 #undef NSPROTHANDLER_THIS
2382 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
2383 nsProtocolHandler_QueryInterface,
2384 nsProtocolHandler_AddRef,
2385 nsProtocolHandler_Release,
2386 nsProtocolHandler_GetScheme,
2387 nsProtocolHandler_GetDefaultPort,
2388 nsProtocolHandler_GetProtocolFlags,
2389 nsProtocolHandler_NewURI,
2390 nsProtocolHandler_NewChannel,
2391 nsProtocolHandler_AllowPort
2394 static nsIProtocolHandler *create_protocol_handler(nsIProtocolHandler *nshandler)
2396 nsProtocolHandler *ret = heap_alloc(sizeof(nsProtocolHandler));
2398 ret->lpProtocolHandlerVtbl = &nsProtocolHandlerVtbl;
2400 ret->nshandler = nshandler;
2402 return NSPROTHANDLER(ret);
2405 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,nsQIResult);
2407 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
2412 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
2417 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
2418 nsIProtocolHandler **_retval)
2420 nsIExternalProtocolHandler *nsexthandler;
2421 nsIProtocolHandler *nshandler;
2424 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2426 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
2427 if(NS_FAILED(nsres)) {
2428 WARN("GetProtocolHandler failed: %08x\n", nsres);
2432 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
2433 (void**)&nsexthandler);
2434 if(NS_FAILED(nsres)) {
2435 *_retval = nshandler;
2439 nsIExternalProtocolHandler_Release(nsexthandler);
2440 *_retval = create_protocol_handler(nshandler);
2441 TRACE("return %p\n", *_retval);
2445 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
2448 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2449 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
2452 static BOOL is_gecko_special_uri(const char *spec)
2454 static const char *special_schemes[] = {"chrome:", "jar:", "resource:", "javascript:", "wyciwyg:"};
2457 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
2458 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
2465 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
2466 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2468 const char *spec = NULL;
2469 NSContainer *nscontainer = NULL;
2471 LPCWSTR base_wine_url = NULL;
2472 nsIWineURI *base_wine_uri = NULL, *wine_uri;
2473 BOOL is_wine_uri = FALSE;
2476 nsACString_GetData(aSpec, &spec);
2478 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
2481 if(is_gecko_special_uri(spec))
2482 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2484 if(!strncmp(spec, "wine:", 5)) {
2490 nsACString base_uri_str;
2491 const char *base_uri = NULL;
2493 nsACString_Init(&base_uri_str, NULL);
2495 nsres = nsIURI_GetSpec(aBaseURI, &base_uri_str);
2496 if(NS_SUCCEEDED(nsres)) {
2497 nsACString_GetData(&base_uri_str, &base_uri);
2498 TRACE("base_uri=%s\n", debugstr_a(base_uri));
2500 ERR("GetSpec failed: %08x\n", nsres);
2503 nsACString_Finish(&base_uri_str);
2506 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
2507 if(NS_FAILED(nsres))
2508 TRACE("NewURI failed: %08x\n", nsres);
2511 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsIWineURI, (void**)&base_wine_uri);
2512 if(NS_SUCCEEDED(nsres)) {
2513 nsIWineURI_GetNSContainer(base_wine_uri, &nscontainer);
2514 nsIWineURI_GetWineURL(base_wine_uri, &base_wine_url);
2516 TRACE("Could not get base nsIWineURI: %08x\n", nsres);
2520 TRACE("nscontainer = %p\n", nscontainer);
2522 nsres = create_uri(uri, nscontainer, &wine_uri);
2523 *_retval = (nsIURI*)wine_uri;
2526 nsIWebBrowserChrome_Release(NSWBCHROME(nscontainer));
2529 WCHAR url[INTERNET_MAX_URL_LENGTH], rel_url[INTERNET_MAX_URL_LENGTH];
2533 MultiByteToWideChar(CP_ACP, 0, spec, -1, rel_url, sizeof(rel_url)/sizeof(WCHAR));
2535 hres = CoInternetCombineUrl(base_wine_url, rel_url,
2536 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
2537 url, sizeof(url)/sizeof(WCHAR), &len, 0);
2539 nsIWineURI_SetWineURL(wine_uri, url);
2541 WARN("CoCombineUrl failed: %08x\n", hres);
2542 }else if(is_wine_uri) {
2543 WCHAR url[INTERNET_MAX_URL_LENGTH];
2545 MultiByteToWideChar(CP_ACP, 0, spec, -1, url, sizeof(url)/sizeof(WCHAR));
2546 nsIWineURI_SetWineURL(wine_uri, url);
2550 nsIWineURI_Release(base_wine_uri);
2555 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
2558 TRACE("(%p %p)\n", aFile, _retval);
2559 return nsIIOService_NewFileURI(nsio, aFile, _retval);
2562 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
2563 nsIChannel **_retval)
2565 nsIChannel *channel = NULL;
2567 nsIWineURI *wine_uri;
2570 TRACE("(%p %p)\n", aURI, _retval);
2572 nsres = nsIIOService_NewChannelFromURI(nsio, aURI, &channel);
2573 if(NS_FAILED(nsres) && nsres != NS_ERROR_UNKNOWN_PROTOCOL) {
2574 WARN("NewChannelFromURI failed: %08x\n", nsres);
2579 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
2580 if(NS_FAILED(nsres)) {
2581 WARN("Could not get nsIWineURI: %08x\n", nsres);
2583 return channel ? NS_OK : NS_ERROR_UNEXPECTED;
2586 ret = heap_alloc_zero(sizeof(nsChannel));
2588 ret->lpHttpChannelVtbl = &nsChannelVtbl;
2589 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
2590 ret->lpIHttpChannelInternalVtbl = &nsHttpChannelInternalVtbl;
2592 ret->channel = channel;
2593 ret->uri = wine_uri;
2595 nsIURI_AddRef(aURI);
2596 ret->original_uri = aURI;
2599 nsIChannel_QueryInterface(channel, &IID_nsIHttpChannel, (void**)&ret->http_channel);
2600 nsIChannel_QueryInterface(channel, &IID_nsIHttpChannelInternal, (void**)&ret->http_channel_internal);
2603 *_retval = NSCHANNEL(ret);
2607 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
2608 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
2610 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2611 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2614 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
2616 TRACE("(%p)\n", aOffline);
2617 return nsIIOService_GetOffline(nsio, aOffline);
2620 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
2622 TRACE("(%x)\n", aOffline);
2623 return nsIIOService_SetOffline(nsio, aOffline);
2626 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
2627 const char *aScheme, PRBool *_retval)
2629 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
2630 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
2633 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
2634 nsACString * _retval)
2636 TRACE("(%p %p)\n", urlString, _retval);
2637 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
2640 static const nsIIOServiceVtbl nsIOServiceVtbl = {
2641 nsIOService_QueryInterface,
2643 nsIOService_Release,
2644 nsIOService_GetProtocolHandler,
2645 nsIOService_GetProtocolFlags,
2647 nsIOService_NewFileURI,
2648 nsIOService_NewChannelFromURI,
2649 nsIOService_NewChannel,
2650 nsIOService_GetOffline,
2651 nsIOService_SetOffline,
2652 nsIOService_AllowPort,
2653 nsIOService_ExtractScheme
2656 static nsIIOService nsIOService = { &nsIOServiceVtbl };
2658 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
2661 return nsIIOService_QueryInterface(&nsIOService, riid, result);
2664 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
2669 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
2674 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2675 nsACString *aCharset, PRBool *aHadCharset, nsACString *aContentType)
2677 TRACE("(%p %p %p %p)\n", aTypeHeader, aCharset, aHadCharset, aContentType);
2679 return nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
2682 static nsresult NSAPI nsNetUtil_ProtocolHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2686 return nsINetUtil_ProtocolHasFlags(net_util, aURI, aFlags, _retval);
2689 static nsresult NSAPI nsNetUtil_URIChainHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2691 TRACE("(%p %08x %p)\n", aURI, aFlags, _retval);
2693 if(aFlags == (1<<11)) {
2698 return nsINetUtil_URIChainHasFlags(net_util, aURI, aFlags, _retval);
2701 static nsresult NSAPI nsNetUtil_ToImmutableURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
2703 TRACE("(%p %p)\n", aURI, _retval);
2705 return nsINetUtil_ToImmutableURI(net_util, aURI, _retval);
2708 static nsresult NSAPI nsNetUtil_EscapeString(nsINetUtil *iface, const nsACString *aString,
2709 PRUint32 aEscapeType, nsACString *_retval)
2711 TRACE("(%p %x %p)\n", aString, aEscapeType, _retval);
2713 return nsINetUtil_EscapeString(net_util, aString, aEscapeType, _retval);
2716 static nsresult NSAPI nsNetUtil_EscapeURL(nsINetUtil *iface, const nsACString *aStr, PRUint32 aFlags,
2717 nsACString *_retval)
2719 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2721 return nsINetUtil_EscapeURL(net_util, aStr, aFlags, _retval);
2724 static nsresult NSAPI nsNetUtil_UnescapeString(nsINetUtil *iface, const nsACString *aStr,
2725 PRUint32 aFlags, nsACString *_retval)
2727 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2729 return nsINetUtil_UnescapeString(net_util, aStr, aFlags, _retval);
2732 static nsresult NSAPI nsNetUtil_ExtractCharsetFromContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2733 nsACString *aCharset, PRInt32 *aCharsetStart, PRInt32 *aCharsetEnd, PRBool *_retval)
2735 TRACE("(%p %p %p %p %p)\n", aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2737 return nsINetUtil_ExtractCharsetFromContentType(net_util, aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2740 static const nsINetUtilVtbl nsNetUtilVtbl = {
2741 nsNetUtil_QueryInterface,
2744 nsNetUtil_ParseContentType,
2745 nsNetUtil_ProtocolHasFlags,
2746 nsNetUtil_URIChainHasFlags,
2747 nsNetUtil_ToImmutableURI,
2748 nsNetUtil_EscapeString,
2749 nsNetUtil_EscapeURL,
2750 nsNetUtil_UnescapeString,
2751 nsNetUtil_ExtractCharsetFromContentType
2754 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
2756 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
2761 if(IsEqualGUID(&IID_nsISupports, riid))
2762 *result = &nsIOService;
2763 else if(IsEqualGUID(&IID_nsIIOService, riid))
2764 *result = &nsIOService;
2765 else if(IsEqualGUID(&IID_nsINetUtil, riid))
2766 *result = &nsNetUtil;
2769 nsISupports_AddRef((nsISupports*)*result);
2773 FIXME("(%s %p)\n", debugstr_guid(riid), result);
2774 return NS_NOINTERFACE;
2777 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
2782 if(IsEqualGUID(&IID_nsISupports, riid)) {
2783 TRACE("(IID_nsISupports %p)\n", result);
2785 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
2786 TRACE("(IID_nsIFactory %p)\n", result);
2791 nsIFactory_AddRef(iface);
2795 WARN("(%s %p)\n", debugstr_guid(riid), result);
2796 return NS_NOINTERFACE;
2799 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
2804 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
2809 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
2810 nsISupports *aOuter, const nsIID *iid, void **result)
2812 return nsIIOService_QueryInterface(&nsIOService, iid, result);
2815 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
2817 WARN("(%x)\n", lock);
2821 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
2822 nsIOServiceFactory_QueryInterface,
2823 nsIOServiceFactory_AddRef,
2824 nsIOServiceFactory_Release,
2825 nsIOServiceFactory_CreateInstance,
2826 nsIOServiceFactory_LockFactory
2829 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
2831 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
2833 nsIFactory *old_factory = NULL;
2836 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
2837 &IID_nsIFactory, (void**)&old_factory);
2838 if(NS_FAILED(nsres)) {
2839 ERR("Could not get factory: %08x\n", nsres);
2843 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
2844 if(NS_FAILED(nsres)) {
2845 ERR("Couldn not create nsIOService instance %08x\n", nsres);
2846 nsIFactory_Release(old_factory);
2850 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
2851 if(NS_FAILED(nsres)) {
2852 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
2853 nsIIOService_Release(nsio);
2857 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
2858 nsIFactory_Release(old_factory);
2859 if(NS_FAILED(nsres))
2860 ERR("UnregisterFactory failed: %08x\n", nsres);
2862 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
2863 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
2864 if(NS_FAILED(nsres))
2865 ERR("RegisterFactory failed: %08x\n", nsres);
2868 void release_nsio(void)
2871 nsINetUtil_Release(net_util);
2876 nsIIOService_Release(nsio);