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;
52 const nsIWineURIVtbl *lpWineURIVtbl;
57 NSContainer *container;
63 #define NSURI(x) ((nsIURI*) &(x)->lpWineURIVtbl)
64 #define NSWINEURI(x) ((nsIWineURI*) &(x)->lpWineURIVtbl)
66 static nsresult create_uri(nsIURI*,NSContainer*,nsIWineURI**);
68 static BOOL exec_shldocvw_67(HTMLDocument *doc, LPCWSTR url)
70 IOleCommandTarget *cmdtrg = NULL;
73 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget,
76 VARIANT varUrl, varRes;
78 V_VT(&varUrl) = VT_BSTR;
79 V_BSTR(&varUrl) = SysAllocString(url);
80 V_VT(&varRes) = VT_BOOL;
82 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
84 IOleCommandTarget_Release(cmdtrg);
85 SysFreeString(V_BSTR(&varUrl));
87 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
88 TRACE("got VARIANT_FALSE, do not load\n");
96 static BOOL before_async_open(nsChannel *channel, NSContainer *container)
98 IServiceProvider *service_provider;
99 HTMLDocument *doc = container->doc;
104 nsIWineURI_GetWineURL(channel->uri, &uri);
106 ERR("GetWineURL returned NULL\n");
111 NSContainer *container_iter = container;
113 hlnf = HLNF_OPENINNEWWINDOW;
114 while(!container_iter->doc)
115 container_iter = container_iter->parent;
116 doc = container_iter->doc;
119 if(!hlnf && !exec_shldocvw_67(doc, uri))
122 hres = IOleClientSite_QueryInterface(doc->client, &IID_IServiceProvider,
123 (void**)&service_provider);
124 if(SUCCEEDED(hres)) {
125 IHlinkFrame *hlink_frame;
127 hres = IServiceProvider_QueryService(service_provider, &IID_IHlinkFrame,
128 &IID_IHlinkFrame, (void**)&hlink_frame);
129 IServiceProvider_Release(service_provider);
130 if(SUCCEEDED(hres)) {
131 hlink_frame_navigate(doc, hlink_frame, uri, channel->post_data_stream, hlnf);
132 IHlinkFrame_Release(hlink_frame);
141 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
143 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
145 nsChannel *This = NSCHANNEL_THIS(iface);
149 if(IsEqualGUID(&IID_nsISupports, riid)) {
150 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
151 *result = NSCHANNEL(This);
152 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
153 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
154 *result = NSCHANNEL(This);
155 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
156 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
157 *result = NSCHANNEL(This);
158 }else if(This->http_channel && IsEqualGUID(&IID_nsIHttpChannel, riid)) {
159 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
160 *result = NSHTTPCHANNEL(This);
161 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
162 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
163 *result = NSUPCHANNEL(This);
167 nsIChannel_AddRef(NSCHANNEL(This));
171 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
174 return nsIChannel_QueryInterface(This->channel, riid, result);
175 return NS_NOINTERFACE;
178 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
180 nsChannel *This = NSCHANNEL_THIS(iface);
181 nsrefcnt ref = InterlockedIncrement(&This->ref);
183 TRACE("(%p) ref=%d\n", This, ref);
188 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
190 nsChannel *This = NSCHANNEL_THIS(iface);
191 LONG ref = InterlockedDecrement(&This->ref);
194 nsIWineURI_Release(This->uri);
196 nsIChannel_Release(This->channel);
197 if(This->http_channel)
198 nsIHttpChannel_Release(This->http_channel);
199 if(This->post_data_stream)
200 nsIInputStream_Release(This->post_data_stream);
202 nsILoadGroup_Release(This->load_group);
203 if(This->notif_callback)
204 nsIInterfaceRequestor_Release(This->notif_callback);
205 if(This->original_uri)
206 nsIURI_Release(This->original_uri);
207 mshtml_free(This->content);
208 mshtml_free(This->charset);
215 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
217 nsChannel *This = NSCHANNEL_THIS(iface);
219 TRACE("(%p)->(%p)\n", This, aName);
222 return nsIChannel_GetName(This->channel, aName);
224 return NS_ERROR_NOT_IMPLEMENTED;
227 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
229 nsChannel *This = NSCHANNEL_THIS(iface);
231 TRACE("(%p)->(%p)\n", This, _retval);
234 return nsIChannel_IsPending(This->channel, _retval);
236 FIXME("default action not implemented\n");
237 return NS_ERROR_NOT_IMPLEMENTED;
240 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
242 nsChannel *This = NSCHANNEL_THIS(iface);
244 TRACE("(%p)->(%p)\n", This, aStatus);
247 return nsIChannel_GetStatus(This->channel, aStatus);
249 TRACE("returning NS_OK\n");
250 return *aStatus = NS_OK;
253 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
255 nsChannel *This = NSCHANNEL_THIS(iface);
257 TRACE("(%p)->(%08x)\n", This, aStatus);
260 return nsIChannel_Cancel(This->channel, aStatus);
262 FIXME("default action not implemented\n");
263 return NS_ERROR_NOT_IMPLEMENTED;
266 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
268 nsChannel *This = NSCHANNEL_THIS(iface);
270 TRACE("(%p)\n", This);
273 return nsIChannel_Suspend(This->channel);
275 FIXME("default action not implemented\n");
276 return NS_ERROR_NOT_IMPLEMENTED;
279 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
281 nsChannel *This = NSCHANNEL_THIS(iface);
283 TRACE("(%p)\n", This);
286 return nsIChannel_Resume(This->channel);
288 FIXME("default action not implemented\n");
289 return NS_ERROR_NOT_IMPLEMENTED;
292 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
294 nsChannel *This = NSCHANNEL_THIS(iface);
296 TRACE("(%p)->(%p)\n", This, aLoadGroup);
299 nsILoadGroup_AddRef(This->load_group);
301 *aLoadGroup = This->load_group;
305 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
307 nsChannel *This = NSCHANNEL_THIS(iface);
309 TRACE("(%p)->(%p)\n", This, aLoadGroup);
312 nsILoadGroup_Release(This->load_group);
314 nsILoadGroup_AddRef(aLoadGroup);
316 This->load_group = aLoadGroup;
319 return nsIChannel_SetLoadGroup(This->channel, aLoadGroup);
323 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
325 nsChannel *This = NSCHANNEL_THIS(iface);
327 TRACE("(%p)->(%p)\n", This, aLoadFlags);
329 *aLoadFlags = This->load_flags;
333 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
335 nsChannel *This = NSCHANNEL_THIS(iface);
337 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
339 This->load_flags = aLoadFlags;
342 return nsIChannel_SetLoadFlags(This->channel, aLoadFlags);
346 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
348 nsChannel *This = NSCHANNEL_THIS(iface);
350 TRACE("(%p)->(%p)\n", This, aOriginalURI);
352 if(This->original_uri)
353 nsIURI_AddRef(This->original_uri);
355 *aOriginalURI = This->original_uri;
359 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
361 nsChannel *This = NSCHANNEL_THIS(iface);
363 TRACE("(%p)->(%p)\n", This, aOriginalURI);
365 if(This->original_uri)
366 nsIURI_Release(This->original_uri);
368 nsIURI_AddRef(aOriginalURI);
369 This->original_uri = aOriginalURI;
372 return nsIChannel_SetOriginalURI(This->channel, aOriginalURI);
376 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
378 nsChannel *This = NSCHANNEL_THIS(iface);
380 TRACE("(%p)->(%p)\n", This, aURI);
382 nsIWineURI_AddRef(This->uri);
383 *aURI = (nsIURI*)This->uri;
388 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
390 nsChannel *This = NSCHANNEL_THIS(iface);
392 TRACE("(%p)->(%p)\n", This, aOwner);
395 return nsIChannel_GetOwner(This->channel, aOwner);
397 FIXME("default action not implemented\n");
398 return NS_ERROR_NOT_IMPLEMENTED;
401 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
403 nsChannel *This = NSCHANNEL_THIS(iface);
405 TRACE("(%p)->(%p)\n", This, aOwner);
408 return nsIChannel_SetOwner(This->channel, aOwner);
410 FIXME("default action not implemented\n");
411 return NS_ERROR_NOT_IMPLEMENTED;
414 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
415 nsIInterfaceRequestor **aNotificationCallbacks)
417 nsChannel *This = NSCHANNEL_THIS(iface);
419 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
421 if(This->notif_callback)
422 nsIInterfaceRequestor_AddRef(This->notif_callback);
423 *aNotificationCallbacks = This->notif_callback;
428 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
429 nsIInterfaceRequestor *aNotificationCallbacks)
431 nsChannel *This = NSCHANNEL_THIS(iface);
433 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
435 if(This->notif_callback)
436 nsIInterfaceRequestor_Release(This->notif_callback);
437 if(aNotificationCallbacks)
438 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
440 This->notif_callback = aNotificationCallbacks;
443 return nsIChannel_SetNotificationCallbacks(This->channel, aNotificationCallbacks);
447 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
449 nsChannel *This = NSCHANNEL_THIS(iface);
451 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
454 return nsIChannel_GetSecurityInfo(This->channel, aSecurityInfo);
456 FIXME("default action not implemented\n");
457 return NS_ERROR_NOT_IMPLEMENTED;
460 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
462 nsChannel *This = NSCHANNEL_THIS(iface);
464 TRACE("(%p)->(%p)\n", This, aContentType);
467 nsACString_SetData(aContentType, This->content);
472 return nsIChannel_GetContentType(This->channel, aContentType);
474 TRACE("returning default text/html\n");
475 nsACString_SetData(aContentType, "text/html");
479 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
480 const nsACString *aContentType)
482 nsChannel *This = NSCHANNEL_THIS(iface);
484 TRACE("(%p)->(%p)\n", This, aContentType);
487 return nsIChannel_SetContentType(This->channel, aContentType);
489 FIXME("default action not implemented\n");
490 return NS_ERROR_NOT_IMPLEMENTED;
493 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
494 nsACString *aContentCharset)
496 nsChannel *This = NSCHANNEL_THIS(iface);
498 TRACE("(%p)->(%p)\n", This, aContentCharset);
501 nsACString_SetData(aContentCharset, This->charset);
506 nsresult nsres = nsIChannel_GetContentCharset(This->channel, aContentCharset);
508 nsACString_GetData(aContentCharset, &ch, NULL);
512 nsACString_SetData(aContentCharset, "");
516 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
517 const nsACString *aContentCharset)
519 nsChannel *This = NSCHANNEL_THIS(iface);
521 TRACE("(%p)->(%p)\n", This, aContentCharset);
524 return nsIChannel_SetContentCharset(This->channel, aContentCharset);
526 FIXME("default action not implemented\n");
527 return NS_ERROR_NOT_IMPLEMENTED;
530 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
532 nsChannel *This = NSCHANNEL_THIS(iface);
534 TRACE("(%p)->(%p)\n", This, aContentLength);
537 return nsIChannel_GetContentLength(This->channel, aContentLength);
539 FIXME("default action not implemented\n");
540 return NS_ERROR_NOT_IMPLEMENTED;
543 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
545 nsChannel *This = NSCHANNEL_THIS(iface);
547 TRACE("(%p)->(%d)\n", This, aContentLength);
550 return nsIChannel_SetContentLength(This->channel, aContentLength);
552 FIXME("default action not implemented\n");
553 return NS_ERROR_NOT_IMPLEMENTED;
556 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
558 nsChannel *This = NSCHANNEL_THIS(iface);
560 TRACE("(%p)->(%p)\n", This, _retval);
563 return nsIChannel_Open(This->channel, _retval);
565 FIXME("default action not implemented\n");
566 return NS_ERROR_NOT_IMPLEMENTED;
569 static BOOL do_load_from_moniker_hack(nsChannel *This)
571 nsACString scheme_str;
576 * We should always load the page from IMoniker, but Wine is not yet
577 * ready for this. This function is a heuristic, that decides which
578 * way of loading is better (Gecko implementation or IMoniker). The
579 * aim is to always return TRUE.
582 /* Load from moniker if there is no Gecko channel available */
586 nsACString_Init(&scheme_str, NULL);
587 nsres = nsIWineURI_GetScheme(This->uri, &scheme_str);
589 if(NS_SUCCEEDED(nsres)) {
592 nsACString_GetData(&scheme_str, &scheme, NULL);
593 ret = !strcmp(scheme, "wine");
596 nsACString_Finish(&scheme_str);
600 static HRESULT create_mon_for_nschannel(nsChannel *channel, IMoniker **mon)
602 nsIWineURI *wine_uri;
607 if(!channel->original_uri) {
608 ERR("original_uri == NULL\n");
612 nsres = nsIURI_QueryInterface(channel->original_uri, &IID_nsIWineURI, (void**)&wine_uri);
613 if(NS_FAILED(nsres)) {
614 ERR("Could not get nsIWineURI: %08x\n", nsres);
618 nsIWineURI_GetWineURL(wine_uri, &wine_url);
619 nsIWineURI_Release(wine_uri);
621 TRACE("wine_url == NULL\n");
625 hres = CreateURLMoniker(NULL, wine_url, mon);
627 WARN("CreateURLMonikrer failed: %08x\n", hres);
632 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
633 nsISupports *aContext)
635 nsChannel *This = NSCHANNEL_THIS(iface);
636 BSCallback *bscallback;
637 IMoniker *mon = NULL;
643 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
645 nsIWineURI_GetIsDocumentURI(This->uri, &is_doc_uri);
647 if(is_doc_uri && (This->load_flags & LOAD_INITIAL_DOCUMENT_URI)) {
648 NSContainer *container;
650 nsIWineURI_GetNSContainer(This->uri, &container);
652 TRACE("container = NULL\n");
653 return nsIChannel_AsyncOpen(This->channel, aListener, aContext);
656 if(container->bscallback) {
657 nsIChannel_AddRef(NSCHANNEL(This));
658 container->bscallback->nschannel = This;
660 nsIStreamListener_AddRef(aListener);
661 container->bscallback->nslistener = aListener;
664 nsISupports_AddRef(aContext);
665 container->bscallback->nscontext = aContext;
668 nsIWebBrowserChrome_Release(NSWBCHROME(container));
670 if(do_load_from_moniker_hack(This))
671 return WINE_NS_LOAD_FROM_MONIKER;
673 BOOL cont = before_async_open(This, container);
674 nsIWebBrowserChrome_Release(NSWBCHROME(container));
678 return NS_ERROR_UNEXPECTED;
683 ? nsIChannel_AsyncOpen(This->channel, aListener, aContext)
684 : NS_ERROR_UNEXPECTED;
686 hres = create_mon_for_nschannel(This, &mon);
688 return NS_ERROR_UNEXPECTED;
689 set_current_mon(container->doc, mon);
694 if(This->post_data_stream) {
695 nsIUploadChannel *upload_channel;
697 nsres = nsIChannel_QueryInterface(This->channel, &IID_nsIUploadChannel,
698 (void**)&upload_channel);
699 if(NS_SUCCEEDED(nsres)) {
700 nsACString empty_string;
701 nsACString_Init(&empty_string, "");
703 nsres = nsIUploadChannel_SetUploadStream(upload_channel, This->post_data_stream,
705 nsIUploadChannel_Release(upload_channel);
707 WARN("SetUploadStream failed: %08x\n", nsres);
709 nsACString_Finish(&empty_string);
713 nsres = nsIChannel_AsyncOpen(This->channel, aListener, aContext);
716 IMoniker_Release(mon);
718 if(NS_FAILED(nsres) && (This->load_flags & LOAD_INITIAL_DOCUMENT_URI))
719 return WINE_NS_LOAD_FROM_MONIKER;
723 TRACE("channel == NULL\n");
725 hres = create_mon_for_nschannel(This, &mon);
727 return NS_ERROR_UNEXPECTED;
729 bscallback = create_bscallback(mon);
730 IMoniker_Release(mon);
732 nsIChannel_AddRef(NSCHANNEL(This));
733 bscallback->nschannel = This;
735 nsIStreamListener_AddRef(aListener);
736 bscallback->nslistener = aListener;
739 nsISupports_AddRef(aContext);
740 bscallback->nscontext = aContext;
743 task = mshtml_alloc(sizeof(task_t));
745 task->doc = bscallback->doc;
746 task->task_id = TASK_START_BINDING;
748 task->bscallback = bscallback;
755 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
757 nsChannel *This = NSCHANNEL_THIS(iface);
759 TRACE("(%p)->(%p)\n", This, aRequestMethod);
761 if(This->http_channel)
762 return nsIHttpChannel_GetRequestMethod(This->http_channel, aRequestMethod);
764 return NS_ERROR_NOT_IMPLEMENTED;
767 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
768 const nsACString *aRequestMethod)
770 nsChannel *This = NSCHANNEL_THIS(iface);
772 TRACE("(%p)->(%p)\n", This, aRequestMethod);
774 if(This->http_channel)
775 return nsIHttpChannel_SetRequestMethod(This->http_channel, aRequestMethod);
777 return NS_ERROR_NOT_IMPLEMENTED;
780 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
782 nsChannel *This = NSCHANNEL_THIS(iface);
784 TRACE("(%p)->(%p)\n", This, aReferrer);
786 if(This->http_channel)
787 return nsIHttpChannel_GetReferrer(This->http_channel, aReferrer);
789 return NS_ERROR_NOT_IMPLEMENTED;
792 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
794 nsChannel *This = NSCHANNEL_THIS(iface);
796 TRACE("(%p)->(%p)\n", This, aReferrer);
798 if(This->http_channel)
799 return nsIHttpChannel_SetReferrer(This->http_channel, aReferrer);
801 return NS_ERROR_NOT_IMPLEMENTED;
804 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
805 const nsACString *aHeader, nsACString *_retval)
807 nsChannel *This = NSCHANNEL_THIS(iface);
809 TRACE("(%p)->(%p %p)\n", This, aHeader, _retval);
811 if(This->http_channel)
812 return nsIHttpChannel_GetRequestHeader(This->http_channel, aHeader, _retval);
814 return NS_ERROR_NOT_IMPLEMENTED;
817 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
818 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
820 nsChannel *This = NSCHANNEL_THIS(iface);
822 TRACE("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
824 if(This->http_channel)
825 return nsIHttpChannel_SetRequestHeader(This->http_channel, aHeader, aValue, aMerge);
827 return NS_ERROR_NOT_IMPLEMENTED;
830 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
831 nsIHttpHeaderVisitor *aVisitor)
833 nsChannel *This = NSCHANNEL_THIS(iface);
835 TRACE("(%p)->(%p)\n", This, aVisitor);
837 if(This->http_channel)
838 return nsIHttpChannel_VisitRequestHeaders(This->http_channel, aVisitor);
840 return NS_ERROR_NOT_IMPLEMENTED;
843 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
845 nsChannel *This = NSCHANNEL_THIS(iface);
847 TRACE("(%p)->(%p)\n", This, aAllowPipelining);
849 if(This->http_channel)
850 return nsIHttpChannel_GetAllowPipelining(This->http_channel, aAllowPipelining);
852 return NS_ERROR_NOT_IMPLEMENTED;
855 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
857 nsChannel *This = NSCHANNEL_THIS(iface);
859 TRACE("(%p)->(%x)\n", This, aAllowPipelining);
861 if(This->http_channel)
862 return nsIHttpChannel_SetAllowPipelining(This->http_channel, aAllowPipelining);
864 return NS_ERROR_NOT_IMPLEMENTED;
867 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
869 nsChannel *This = NSCHANNEL_THIS(iface);
871 TRACE("(%p)->(%p)\n", This, aRedirectionLimit);
873 if(This->http_channel)
874 return nsIHttpChannel_GetRedirectionLimit(This->http_channel, aRedirectionLimit);
876 return NS_ERROR_NOT_IMPLEMENTED;
879 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
881 nsChannel *This = NSCHANNEL_THIS(iface);
883 TRACE("(%p)->(%u)\n", This, aRedirectionLimit);
885 if(This->http_channel)
886 return nsIHttpChannel_SetRedirectionLimit(This->http_channel, aRedirectionLimit);
888 return NS_ERROR_NOT_IMPLEMENTED;
891 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
893 nsChannel *This = NSCHANNEL_THIS(iface);
895 TRACE("(%p)->(%p)\n", This, aResponseStatus);
897 if(This->http_channel)
898 return nsIHttpChannel_GetResponseStatus(This->http_channel, aResponseStatus);
900 return NS_ERROR_NOT_IMPLEMENTED;
903 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
904 nsACString *aResponseStatusText)
906 nsChannel *This = NSCHANNEL_THIS(iface);
908 TRACE("(%p)->(%p)\n", This, aResponseStatusText);
910 if(This->http_channel)
911 return nsIHttpChannel_GetResponseStatusText(This->http_channel, aResponseStatusText);
913 return NS_ERROR_NOT_IMPLEMENTED;
916 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
917 PRBool *aRequestSucceeded)
919 nsChannel *This = NSCHANNEL_THIS(iface);
921 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
923 if(This->http_channel)
924 return nsIHttpChannel_GetRequestSucceeded(This->http_channel, aRequestSucceeded);
926 return NS_ERROR_NOT_IMPLEMENTED;
929 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
930 const nsACString *header, nsACString *_retval)
932 nsChannel *This = NSCHANNEL_THIS(iface);
934 TRACE("(%p)->(%p %p)\n", This, header, _retval);
936 if(This->http_channel)
937 return nsIHttpChannel_GetResponseHeader(This->http_channel, header, _retval);
939 return NS_ERROR_NOT_IMPLEMENTED;
942 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
943 const nsACString *header, const nsACString *value, PRBool merge)
945 nsChannel *This = NSCHANNEL_THIS(iface);
947 TRACE("(%p)->(%p %p %x)\n", This, header, value, merge);
949 if(This->http_channel)
950 return nsIHttpChannel_SetResponseHeader(This->http_channel, header, value, merge);
952 return NS_ERROR_NOT_IMPLEMENTED;
955 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
956 nsIHttpHeaderVisitor *aVisitor)
958 nsChannel *This = NSCHANNEL_THIS(iface);
960 TRACE("(%p)->(%p)\n", This, aVisitor);
962 if(This->http_channel)
963 return nsIHttpChannel_VisitResponseHeaders(This->http_channel, aVisitor);
965 return NS_ERROR_NOT_IMPLEMENTED;
968 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
970 nsChannel *This = NSCHANNEL_THIS(iface);
972 TRACE("(%p)->(%p)\n", This, _retval);
974 if(This->http_channel)
975 return nsIHttpChannel_IsNoStoreResponse(This->http_channel, _retval);
977 return NS_ERROR_NOT_IMPLEMENTED;
980 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
982 nsChannel *This = NSCHANNEL_THIS(iface);
984 TRACE("(%p)->(%p)\n", This, _retval);
986 if(This->http_channel)
987 return nsIHttpChannel_IsNoCacheResponse(This->http_channel, _retval);
989 return NS_ERROR_NOT_IMPLEMENTED;
992 #undef NSCHANNEL_THIS
994 static const nsIHttpChannelVtbl nsChannelVtbl = {
995 nsChannel_QueryInterface,
1000 nsChannel_GetStatus,
1004 nsChannel_GetLoadGroup,
1005 nsChannel_SetLoadGroup,
1006 nsChannel_GetLoadFlags,
1007 nsChannel_SetLoadFlags,
1008 nsChannel_GetOriginalURI,
1009 nsChannel_SetOriginalURI,
1013 nsChannel_GetNotificationCallbacks,
1014 nsChannel_SetNotificationCallbacks,
1015 nsChannel_GetSecurityInfo,
1016 nsChannel_GetContentType,
1017 nsChannel_SetContentType,
1018 nsChannel_GetContentCharset,
1019 nsChannel_SetContentCharset,
1020 nsChannel_GetContentLength,
1021 nsChannel_SetContentLength,
1023 nsChannel_AsyncOpen,
1024 nsChannel_GetRequestMethod,
1025 nsChannel_SetRequestMethod,
1026 nsChannel_GetReferrer,
1027 nsChannel_SetReferrer,
1028 nsChannel_GetRequestHeader,
1029 nsChannel_SetRequestHeader,
1030 nsChannel_VisitRequestHeaders,
1031 nsChannel_GetAllowPipelining,
1032 nsChannel_SetAllowPipelining,
1033 nsChannel_GetRedirectionLimit,
1034 nsChannel_SetRedirectionLimit,
1035 nsChannel_GetResponseStatus,
1036 nsChannel_GetResponseStatusText,
1037 nsChannel_GetRequestSucceeded,
1038 nsChannel_GetResponseHeader,
1039 nsChannel_SetResponseHeader,
1040 nsChannel_VisitResponseHeaders,
1041 nsChannel_IsNoStoreResponse,
1042 nsChannel_IsNoCacheResponse
1045 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1047 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1050 nsChannel *This = NSUPCHANNEL_THIS(iface);
1051 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1054 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1056 nsChannel *This = NSUPCHANNEL_THIS(iface);
1057 return nsIChannel_AddRef(NSCHANNEL(This));
1060 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1062 nsChannel *This = NSUPCHANNEL_THIS(iface);
1063 return nsIChannel_Release(NSCHANNEL(This));
1066 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1067 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1069 nsChannel *This = NSUPCHANNEL_THIS(iface);
1070 const char *content_type;
1072 TRACE("(%p)->(%p %p %d)\n", This, aStream, aContentType, aContentLength);
1074 if(This->post_data_stream)
1075 nsIInputStream_Release(This->post_data_stream);
1078 nsACString_GetData(aContentType, &content_type, NULL);
1080 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
1083 if(aContentLength != -1)
1084 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1087 nsIInputStream_AddRef(aStream);
1088 This->post_data_stream = aStream;
1093 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1094 nsIInputStream **aUploadStream)
1096 nsChannel *This = NSUPCHANNEL_THIS(iface);
1098 TRACE("(%p)->(%p)\n", This, aUploadStream);
1100 if(This->post_data_stream)
1101 nsIInputStream_AddRef(This->post_data_stream);
1103 *aUploadStream = This->post_data_stream;
1107 #undef NSUPCHANNEL_THIS
1109 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1110 nsUploadChannel_QueryInterface,
1111 nsUploadChannel_AddRef,
1112 nsUploadChannel_Release,
1113 nsUploadChannel_SetUploadStream,
1114 nsUploadChannel_GetUploadStream
1117 #define NSURI_THIS(iface) DEFINE_THIS(nsURI, WineURI, iface)
1119 static nsresult NSAPI nsURI_QueryInterface(nsIWineURI *iface, nsIIDRef riid, nsQIResult result)
1121 nsURI *This = NSURI_THIS(iface);
1125 if(IsEqualGUID(&IID_nsISupports, riid)) {
1126 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1127 *result = NSURI(This);
1128 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1129 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1130 *result = NSURI(This);
1131 }else if(IsEqualGUID(&IID_nsIWineURI, riid)) {
1132 TRACE("(%p)->(IID_nsIWineURI %p)\n", This, result);
1133 *result = NSURI(This);
1137 nsIURI_AddRef(NSURI(This));
1141 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1142 return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1145 static nsrefcnt NSAPI nsURI_AddRef(nsIWineURI *iface)
1147 nsURI *This = NSURI_THIS(iface);
1148 LONG ref = InterlockedIncrement(&This->ref);
1150 TRACE("(%p) ref=%d\n", This, ref);
1155 static nsrefcnt NSAPI nsURI_Release(nsIWineURI *iface)
1157 nsURI *This = NSURI_THIS(iface);
1158 LONG ref = InterlockedDecrement(&This->ref);
1160 TRACE("(%p) ref=%d\n", This, ref);
1164 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1166 nsIURI_Release(This->uri);
1167 mshtml_free(This->wine_url);
1174 static nsresult NSAPI nsURI_GetSpec(nsIWineURI *iface, nsACString *aSpec)
1176 nsURI *This = NSURI_THIS(iface);
1178 TRACE("(%p)->(%p)\n", This, aSpec);
1180 if(This->use_wine_url) {
1181 char speca[INTERNET_MAX_URL_LENGTH] = "wine:";
1182 WideCharToMultiByte(CP_ACP, 0, This->wine_url, -1, speca+5, sizeof(speca)-5, NULL, NULL);
1183 nsACString_SetData(aSpec, speca);
1189 return nsIURI_GetSpec(This->uri, aSpec);
1191 TRACE("returning error\n");
1192 return NS_ERROR_NOT_IMPLEMENTED;
1196 static nsresult NSAPI nsURI_SetSpec(nsIWineURI *iface, const nsACString *aSpec)
1198 nsURI *This = NSURI_THIS(iface);
1200 TRACE("(%p)->(%p)\n", This, aSpec);
1203 return nsIURI_SetSpec(This->uri, aSpec);
1205 FIXME("default action not implemented\n");
1206 return NS_ERROR_NOT_IMPLEMENTED;
1209 static nsresult NSAPI nsURI_GetPrePath(nsIWineURI *iface, nsACString *aPrePath)
1211 nsURI *This = NSURI_THIS(iface);
1213 TRACE("(%p)->(%p)\n", This, aPrePath);
1216 return nsIURI_GetPrePath(This->uri, aPrePath);
1218 FIXME("default action not implemented\n");
1219 return NS_ERROR_NOT_IMPLEMENTED;
1222 static nsresult NSAPI nsURI_GetScheme(nsIWineURI *iface, nsACString *aScheme)
1224 nsURI *This = NSURI_THIS(iface);
1226 TRACE("(%p)->(%p)\n", This, aScheme);
1228 if(This->use_wine_url) {
1230 * For Gecko we set scheme to unknown so it won't be handled
1231 * as any special case.
1233 nsACString_SetData(aScheme, "wine");
1238 return nsIURI_GetScheme(This->uri, aScheme);
1240 TRACE("returning error\n");
1241 return NS_ERROR_NOT_IMPLEMENTED;
1244 static nsresult NSAPI nsURI_SetScheme(nsIWineURI *iface, const nsACString *aScheme)
1246 nsURI *This = NSURI_THIS(iface);
1248 TRACE("(%p)->(%p)\n", This, aScheme);
1251 return nsIURI_SetScheme(This->uri, aScheme);
1253 FIXME("default action not implemented\n");
1254 return NS_ERROR_NOT_IMPLEMENTED;
1257 static nsresult NSAPI nsURI_GetUserPass(nsIWineURI *iface, nsACString *aUserPass)
1259 nsURI *This = NSURI_THIS(iface);
1261 TRACE("(%p)->(%p)\n", This, aUserPass);
1264 return nsIURI_GetUserPass(This->uri, aUserPass);
1266 FIXME("default action not implemented\n");
1267 return NS_ERROR_NOT_IMPLEMENTED;
1270 static nsresult NSAPI nsURI_SetUserPass(nsIWineURI *iface, const nsACString *aUserPass)
1272 nsURI *This = NSURI_THIS(iface);
1274 TRACE("(%p)->(%p)\n", This, aUserPass);
1277 return nsIURI_SetUserPass(This->uri, aUserPass);
1279 FIXME("default action not implemented\n");
1280 return NS_ERROR_NOT_IMPLEMENTED;
1283 static nsresult NSAPI nsURI_GetUsername(nsIWineURI *iface, nsACString *aUsername)
1285 nsURI *This = NSURI_THIS(iface);
1287 TRACE("(%p)->(%p)\n", This, aUsername);
1290 return nsIURI_GetUsername(This->uri, aUsername);
1292 FIXME("default action not implemented\n");
1293 return NS_ERROR_NOT_IMPLEMENTED;
1296 static nsresult NSAPI nsURI_SetUsername(nsIWineURI *iface, const nsACString *aUsername)
1298 nsURI *This = NSURI_THIS(iface);
1300 TRACE("(%p)->(%p)\n", This, aUsername);
1303 return nsIURI_SetUsername(This->uri, aUsername);
1305 FIXME("default action not implemented\n");
1306 return NS_ERROR_NOT_IMPLEMENTED;
1309 static nsresult NSAPI nsURI_GetPassword(nsIWineURI *iface, nsACString *aPassword)
1311 nsURI *This = NSURI_THIS(iface);
1313 TRACE("(%p)->(%p)\n", This, aPassword);
1316 return nsIURI_GetPassword(This->uri, aPassword);
1318 FIXME("default action not implemented\n");
1319 return NS_ERROR_NOT_IMPLEMENTED;
1322 static nsresult NSAPI nsURI_SetPassword(nsIWineURI *iface, const nsACString *aPassword)
1324 nsURI *This = NSURI_THIS(iface);
1326 TRACE("(%p)->(%p)\n", This, aPassword);
1329 return nsIURI_SetPassword(This->uri, aPassword);
1331 FIXME("default action not implemented\n");
1332 return NS_ERROR_NOT_IMPLEMENTED;
1335 static nsresult NSAPI nsURI_GetHostPort(nsIWineURI *iface, nsACString *aHostPort)
1337 nsURI *This = NSURI_THIS(iface);
1339 TRACE("(%p)->(%p)\n", This, aHostPort);
1342 return nsIURI_GetHostPort(This->uri, aHostPort);
1344 FIXME("default action not implemented\n");
1345 return NS_ERROR_NOT_IMPLEMENTED;
1348 static nsresult NSAPI nsURI_SetHostPort(nsIWineURI *iface, const nsACString *aHostPort)
1350 nsURI *This = NSURI_THIS(iface);
1352 TRACE("(%p)->(%p)\n", This, aHostPort);
1355 return nsIURI_SetHostPort(This->uri, aHostPort);
1357 FIXME("default action not implemented\n");
1358 return NS_ERROR_NOT_IMPLEMENTED;
1361 static nsresult NSAPI nsURI_GetHost(nsIWineURI *iface, nsACString *aHost)
1363 nsURI *This = NSURI_THIS(iface);
1365 TRACE("(%p)->(%p)\n", This, aHost);
1368 return nsIURI_GetHost(This->uri, aHost);
1370 FIXME("default action not implemented\n");
1371 return NS_ERROR_NOT_IMPLEMENTED;
1374 static nsresult NSAPI nsURI_SetHost(nsIWineURI *iface, const nsACString *aHost)
1376 nsURI *This = NSURI_THIS(iface);
1378 TRACE("(%p)->(%p)\n", This, aHost);
1381 return nsIURI_SetHost(This->uri, aHost);
1383 FIXME("default action not implemented\n");
1384 return NS_ERROR_NOT_IMPLEMENTED;
1387 static nsresult NSAPI nsURI_GetPort(nsIWineURI *iface, PRInt32 *aPort)
1389 nsURI *This = NSURI_THIS(iface);
1391 TRACE("(%p)->(%p)\n", This, aPort);
1394 return nsIURI_GetPort(This->uri, aPort);
1396 FIXME("default action not implemented\n");
1397 return NS_ERROR_NOT_IMPLEMENTED;
1400 static nsresult NSAPI nsURI_SetPort(nsIWineURI *iface, PRInt32 aPort)
1402 nsURI *This = NSURI_THIS(iface);
1404 TRACE("(%p)->(%d)\n", This, aPort);
1407 return nsIURI_SetPort(This->uri, aPort);
1409 FIXME("default action not implemented\n");
1410 return NS_ERROR_NOT_IMPLEMENTED;
1413 static nsresult NSAPI nsURI_GetPath(nsIWineURI *iface, nsACString *aPath)
1415 nsURI *This = NSURI_THIS(iface);
1417 TRACE("(%p)->(%p)\n", This, aPath);
1420 return nsIURI_GetPath(This->uri, aPath);
1422 FIXME("default action not implemented\n");
1423 return NS_ERROR_NOT_IMPLEMENTED;
1426 static nsresult NSAPI nsURI_SetPath(nsIWineURI *iface, const nsACString *aPath)
1428 nsURI *This = NSURI_THIS(iface);
1430 TRACE("(%p)->(%p)\n", This, aPath);
1433 return nsIURI_SetPath(This->uri, aPath);
1435 FIXME("default action not implemented\n");
1436 return NS_ERROR_NOT_IMPLEMENTED;
1439 static nsresult NSAPI nsURI_Equals(nsIWineURI *iface, nsIURI *other, PRBool *_retval)
1441 nsURI *This = NSURI_THIS(iface);
1443 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1446 return nsIURI_Equals(This->uri, other, _retval);
1448 FIXME("default action not implemented\n");
1449 return NS_ERROR_NOT_IMPLEMENTED;
1452 static nsresult NSAPI nsURI_SchemeIs(nsIWineURI *iface, const char *scheme, PRBool *_retval)
1454 nsURI *This = NSURI_THIS(iface);
1456 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1458 if(This->use_wine_url) {
1459 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
1460 int len = MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR))-1;
1462 *_retval = strlenW(This->wine_url) > len
1463 && This->wine_url[len] == ':'
1464 && !memcmp(buf, This->wine_url, len*sizeof(WCHAR));
1469 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1471 TRACE("returning error\n");
1472 return NS_ERROR_NOT_IMPLEMENTED;
1475 static nsresult NSAPI nsURI_Clone(nsIWineURI *iface, nsIURI **_retval)
1477 nsURI *This = NSURI_THIS(iface);
1479 TRACE("(%p)->(%p)\n", This, _retval);
1483 nsIWineURI *wine_uri;
1486 nsres = nsIURI_Clone(This->uri, &uri);
1487 if(NS_FAILED(nsres)) {
1488 WARN("Clone failed: %08x\n", nsres);
1492 nsres = create_uri(uri, This->container, &wine_uri);
1493 *_retval = (nsIURI*)wine_uri;
1494 if(NS_SUCCEEDED(nsres))
1495 return nsIWineURI_SetWineURL(wine_uri, This->wine_url);
1499 FIXME("default action not implemented\n");
1500 return NS_ERROR_NOT_IMPLEMENTED;
1503 static nsresult NSAPI nsURI_Resolve(nsIWineURI *iface, const nsACString *arelativePath,
1504 nsACString *_retval)
1506 nsURI *This = NSURI_THIS(iface);
1508 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1511 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1513 FIXME("default action not implemented\n");
1514 return NS_ERROR_NOT_IMPLEMENTED;
1517 static nsresult NSAPI nsURI_GetAsciiSpec(nsIWineURI *iface, nsACString *aAsciiSpec)
1519 nsURI *This = NSURI_THIS(iface);
1521 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1523 if(This->use_wine_url)
1524 return nsIURI_GetSpec(NSURI(This), aAsciiSpec);
1527 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1529 TRACE("returning error\n");
1530 return NS_ERROR_NOT_IMPLEMENTED;
1533 static nsresult NSAPI nsURI_GetAsciiHost(nsIWineURI *iface, nsACString *aAsciiHost)
1535 nsURI *This = NSURI_THIS(iface);
1537 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1540 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1542 FIXME("default action not implemented\n");
1543 return NS_ERROR_NOT_IMPLEMENTED;
1546 static nsresult NSAPI nsURI_GetOriginCharset(nsIWineURI *iface, nsACString *aOriginCharset)
1548 nsURI *This = NSURI_THIS(iface);
1550 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1553 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1555 FIXME("default action not implemented\n");
1556 return NS_ERROR_NOT_IMPLEMENTED;
1559 static nsresult NSAPI nsURI_GetNSContainer(nsIWineURI *iface, NSContainer **aContainer)
1561 nsURI *This = NSURI_THIS(iface);
1563 TRACE("(%p)->(%p)\n", This, aContainer);
1566 nsIWebBrowserChrome_AddRef(NSWBCHROME(This->container));
1567 *aContainer = This->container;
1572 static nsresult NSAPI nsURI_SetNSContainer(nsIWineURI *iface, NSContainer *aContainer)
1574 nsURI *This = NSURI_THIS(iface);
1576 TRACE("(%p)->(%p)\n", This, aContainer);
1578 if(This->container) {
1579 if(This->container == aContainer)
1581 TRACE("Changing %p -> %p\n", This->container, aContainer);
1582 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1586 nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer));
1587 This->container = aContainer;
1592 static nsresult NSAPI nsURI_GetIsDocumentURI(nsIWineURI *iface, PRBool *aIsDocumentURI)
1594 nsURI *This = NSURI_THIS(iface);
1596 TRACE("(%p)->(%p)\n", This, aIsDocumentURI);
1598 *aIsDocumentURI = This->is_doc_uri;
1602 static nsresult NSAPI nsURI_SetIsDocumentURI(nsIWineURI *iface, PRBool aIsDocumentURI)
1604 nsURI *This = NSURI_THIS(iface);
1606 TRACE("(%p)->(%x)\n", This, aIsDocumentURI);
1608 This->is_doc_uri = aIsDocumentURI;
1612 static nsresult NSAPI nsURI_GetWineURL(nsIWineURI *iface, LPCWSTR *aURL)
1614 nsURI *This = NSURI_THIS(iface);
1616 TRACE("(%p)->(%p)\n", This, aURL);
1618 *aURL = This->wine_url;
1622 static nsresult NSAPI nsURI_SetWineURL(nsIWineURI *iface, LPCWSTR aURL)
1624 nsURI *This = NSURI_THIS(iface);
1626 static const WCHAR wszFtp[] = {'f','t','p',':'};
1627 static const WCHAR wszHttp[] = {'h','t','t','p',':'};
1628 static const WCHAR wszHttps[] = {'h','t','t','p','s',':'};
1630 TRACE("(%p)->(%s)\n", This, debugstr_w(aURL));
1632 mshtml_free(This->wine_url);
1635 int len = strlenW(aURL)+1;
1636 This->wine_url = mshtml_alloc(len*sizeof(WCHAR));
1637 memcpy(This->wine_url, aURL, len*sizeof(WCHAR));
1639 /* FIXME: Always use wine url */
1640 This->use_wine_url =
1641 strncmpW(aURL, wszFtp, sizeof(wszFtp)/sizeof(WCHAR))
1642 && strncmpW(aURL, wszHttp, sizeof(wszHttp)/sizeof(WCHAR))
1643 && strncmpW(aURL, wszHttps, sizeof(wszHttps)/sizeof(WCHAR));
1645 This->wine_url = NULL;
1646 This->use_wine_url = FALSE;
1654 static const nsIWineURIVtbl nsWineURIVtbl = {
1655 nsURI_QueryInterface,
1683 nsURI_GetOriginCharset,
1684 nsURI_GetNSContainer,
1685 nsURI_SetNSContainer,
1686 nsURI_GetIsDocumentURI,
1687 nsURI_SetIsDocumentURI,
1692 static nsresult create_uri(nsIURI *uri, NSContainer *container, nsIWineURI **_retval)
1694 nsURI *ret = mshtml_alloc(sizeof(nsURI));
1696 ret->lpWineURIVtbl = &nsWineURIVtbl;
1699 ret->container = container;
1700 ret->wine_url = NULL;
1701 ret->is_doc_uri = FALSE;
1702 ret->use_wine_url = FALSE;
1705 nsIWebBrowserChrome_AddRef(NSWBCHROME(container));
1707 TRACE("retval=%p\n", ret);
1708 *_retval = NSWINEURI(ret);
1713 const nsIProtocolHandlerVtbl *lpProtocolHandlerVtbl;
1717 nsIProtocolHandler *nshandler;
1718 } nsProtocolHandler;
1720 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
1722 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
1724 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
1727 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1731 if(IsEqualGUID(&IID_nsISupports, riid)) {
1732 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1733 *result = NSPROTHANDLER(This);
1734 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
1735 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
1736 *result = NSPROTHANDLER(This);
1737 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
1738 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
1739 return NS_NOINTERFACE;
1743 nsISupports_AddRef((nsISupports*)*result);
1747 WARN("(%s %p)\n", debugstr_guid(riid), result);
1748 return NS_NOINTERFACE;
1751 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
1753 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1754 LONG ref = InterlockedIncrement(&This->ref);
1756 TRACE("(%p) ref=%d\n", This, ref);
1761 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
1763 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1764 LONG ref = InterlockedDecrement(&This->ref);
1766 TRACE("(%p) ref=%d\n", This, ref);
1770 nsIProtocolHandler_Release(This->nshandler);
1777 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
1779 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1781 TRACE("(%p)->(%p)\n", This, aScheme);
1784 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
1785 return NS_ERROR_NOT_IMPLEMENTED;
1788 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
1789 PRInt32 *aDefaultPort)
1791 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1793 TRACE("(%p)->(%p)\n", This, aDefaultPort);
1796 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
1797 return NS_ERROR_NOT_IMPLEMENTED;
1800 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
1801 PRUint32 *aProtocolFlags)
1803 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1805 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
1808 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
1809 return NS_ERROR_NOT_IMPLEMENTED;
1812 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
1813 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
1815 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1817 TRACE("((%p)->%p %s %p %p)\n", This, aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
1820 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
1821 return NS_ERROR_NOT_IMPLEMENTED;
1824 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
1825 nsIURI *aURI, nsIChannel **_retval)
1827 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1829 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
1832 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
1833 return NS_ERROR_NOT_IMPLEMENTED;
1836 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
1837 PRInt32 port, const char *scheme, PRBool *_retval)
1839 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1841 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
1844 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
1845 return NS_ERROR_NOT_IMPLEMENTED;
1848 #undef NSPROTHANDLER_THIS
1850 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
1851 nsProtocolHandler_QueryInterface,
1852 nsProtocolHandler_AddRef,
1853 nsProtocolHandler_Release,
1854 nsProtocolHandler_GetScheme,
1855 nsProtocolHandler_GetDefaultPort,
1856 nsProtocolHandler_GetProtocolFlags,
1857 nsProtocolHandler_NewURI,
1858 nsProtocolHandler_NewChannel,
1859 nsProtocolHandler_AllowPort
1862 static nsIProtocolHandler *create_protocol_handler(nsIProtocolHandler *nshandler)
1864 nsProtocolHandler *ret = mshtml_alloc(sizeof(nsProtocolHandler));
1866 ret->lpProtocolHandlerVtbl = &nsProtocolHandlerVtbl;
1868 ret->nshandler = nshandler;
1870 return NSPROTHANDLER(ret);
1873 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
1878 if(IsEqualGUID(&IID_nsISupports, riid)
1879 || IsEqualGUID(&IID_nsIIOService, riid)) {
1881 nsIIOService_AddRef(iface);
1885 WARN("(%s %p)\n", debugstr_guid(riid), result);
1886 return NS_NOINTERFACE;
1889 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
1894 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
1899 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
1900 nsIProtocolHandler **_retval)
1902 nsIExternalProtocolHandler *nsexthandler;
1903 nsIProtocolHandler *nshandler;
1906 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1908 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
1909 if(NS_FAILED(nsres)) {
1910 WARN("GetProtocolHandler failed: %08x\n", nsres);
1914 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
1915 (void**)&nsexthandler);
1916 if(NS_FAILED(nsres)) {
1917 *_retval = nshandler;
1921 nsIExternalProtocolHandler_Release(nsexthandler);
1922 *_retval = create_protocol_handler(nshandler);
1923 TRACE("return %p\n", *_retval);
1927 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
1930 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1931 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
1934 static BOOL is_gecko_special_uri(const char *spec)
1936 static const char chromeW[] = "chrome:";
1937 static const char jarW[] = "jar:";
1938 static const char resourceW[] = "resource:";
1939 static const char javascriptW[] = "javascript:";
1941 return !strncasecmp(spec, chromeW, sizeof(chromeW)-1)
1942 || !strncasecmp(spec, resourceW, sizeof(resourceW)-1)
1943 || !strncasecmp(spec, jarW, sizeof(jarW)-1)
1944 || !strncasecmp(spec, javascriptW, sizeof(javascriptW)-1);
1947 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
1948 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
1950 const char *spec = NULL;
1951 nsACString spec_str;
1952 NSContainer *nscontainer = NULL;
1954 LPCWSTR base_wine_url = NULL;
1955 nsIWineURI *base_wine_uri = NULL, *wine_uri;
1956 BOOL is_wine_uri = FALSE;
1959 nsACString_GetData(aSpec, &spec, NULL);
1961 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
1964 if(is_gecko_special_uri(spec))
1965 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
1967 if(!strncmp(spec, "wine:", 5)) {
1973 nsACString base_uri_str;
1974 const char *base_uri = NULL;
1976 nsACString_Init(&base_uri_str, NULL);
1978 nsres = nsIURI_GetSpec(aBaseURI, &base_uri_str);
1979 if(NS_SUCCEEDED(nsres)) {
1980 nsACString_GetData(&base_uri_str, &base_uri, NULL);
1981 TRACE("base_uri=%s\n", debugstr_a(base_uri));
1983 ERR("GetSpec failed: %08x\n", nsres);
1986 nsACString_Finish(&base_uri_str);
1989 nsACString_Init(&spec_str, spec);
1990 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
1991 nsACString_Finish(&spec_str);
1992 if(NS_FAILED(nsres))
1993 TRACE("NewURI failed: %08x\n", nsres);
1996 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsIWineURI, (void**)&base_wine_uri);
1997 if(NS_SUCCEEDED(nsres)) {
1998 nsIWineURI_GetNSContainer(base_wine_uri, &nscontainer);
1999 nsIWineURI_GetWineURL(base_wine_uri, &base_wine_url);
2001 TRACE("Could not get base nsIWineURI: %08x\n", nsres);
2005 nsres = create_uri(uri, nscontainer, &wine_uri);
2006 *_retval = (nsIURI*)wine_uri;
2009 nsIWebBrowserChrome_Release(NSWBCHROME(nscontainer));
2012 WCHAR url[INTERNET_MAX_URL_LENGTH], rel_url[INTERNET_MAX_URL_LENGTH];
2016 MultiByteToWideChar(CP_ACP, 0, spec, -1, rel_url, sizeof(rel_url)/sizeof(WCHAR));
2018 hres = CoInternetCombineUrl(base_wine_url, rel_url,
2019 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
2020 url, sizeof(url)/sizeof(WCHAR), &len, 0);
2022 nsIWineURI_SetWineURL(wine_uri, url);
2024 WARN("CoCombineUrl failed: %08x\n", hres);
2025 }else if(is_wine_uri) {
2026 WCHAR url[INTERNET_MAX_URL_LENGTH];
2028 MultiByteToWideChar(CP_ACP, 0, spec, -1, url, sizeof(url)/sizeof(WCHAR));
2029 nsIWineURI_SetWineURL(wine_uri, url);
2033 nsIWineURI_Release(base_wine_uri);
2038 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
2041 TRACE("(%p %p)\n", aFile, _retval);
2042 return nsIIOService_NewFileURI(nsio, aFile, _retval);
2045 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
2046 nsIChannel **_retval)
2048 nsIChannel *channel = NULL;
2050 nsIWineURI *wine_uri;
2053 TRACE("(%p %p)\n", aURI, _retval);
2055 nsres = nsIIOService_NewChannelFromURI(nsio, aURI, &channel);
2056 if(NS_FAILED(nsres) && nsres != NS_ERROR_UNKNOWN_PROTOCOL) {
2057 WARN("NewChannelFromURI failed: %08x\n", nsres);
2062 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
2063 if(NS_FAILED(nsres)) {
2064 WARN("Could not get nsIWineURI: %08x\n", nsres);
2066 return channel ? NS_OK : NS_ERROR_UNEXPECTED;
2069 ret = mshtml_alloc(sizeof(nsChannel));
2071 ret->lpHttpChannelVtbl = &nsChannelVtbl;
2072 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
2074 ret->channel = channel;
2075 ret->http_channel = NULL;
2076 ret->uri = wine_uri;
2077 ret->post_data_stream = NULL;
2078 ret->load_group = NULL;
2079 ret->notif_callback = NULL;
2080 ret->load_flags = 0;
2081 ret->content = NULL;
2082 ret->charset = NULL;
2084 nsIURI_AddRef(aURI);
2085 ret->original_uri = aURI;
2088 nsIChannel_QueryInterface(channel, &IID_nsIHttpChannel, (void**)&ret->http_channel);
2090 *_retval = NSCHANNEL(ret);
2094 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
2095 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
2097 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2098 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2101 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
2103 TRACE("(%p)\n", aOffline);
2104 return nsIIOService_GetOffline(nsio, aOffline);
2107 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
2109 TRACE("(%x)\n", aOffline);
2110 return nsIIOService_SetOffline(nsio, aOffline);
2113 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
2114 const char *aScheme, PRBool *_retval)
2116 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
2117 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
2120 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
2121 nsACString * _retval)
2123 TRACE("(%p %p)\n", urlString, _retval);
2124 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
2127 static const nsIIOServiceVtbl nsIOServiceVtbl = {
2128 nsIOService_QueryInterface,
2130 nsIOService_Release,
2131 nsIOService_GetProtocolHandler,
2132 nsIOService_GetProtocolFlags,
2134 nsIOService_NewFileURI,
2135 nsIOService_NewChannelFromURI,
2136 nsIOService_NewChannel,
2137 nsIOService_GetOffline,
2138 nsIOService_SetOffline,
2139 nsIOService_AllowPort,
2140 nsIOService_ExtractScheme
2143 static nsIIOService nsIOService = { &nsIOServiceVtbl };
2145 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
2150 if(IsEqualGUID(&IID_nsISupports, riid)) {
2151 TRACE("(IID_nsISupoprts %p)\n", result);
2153 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
2154 TRACE("(IID_nsIFactory %p)\n", result);
2159 nsIFactory_AddRef(iface);
2163 WARN("(%s %p)\n", debugstr_guid(riid), result);
2164 return NS_NOINTERFACE;
2167 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
2172 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
2177 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
2178 nsISupports *aOuter, const nsIID *iid, void **result)
2180 return nsIIOService_QueryInterface(&nsIOService, iid, result);
2183 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
2185 WARN("(%x)\n", lock);
2189 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
2190 nsIOServiceFactory_QueryInterface,
2191 nsIOServiceFactory_AddRef,
2192 nsIOServiceFactory_Release,
2193 nsIOServiceFactory_CreateInstance,
2194 nsIOServiceFactory_LockFactory
2197 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
2199 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
2201 nsIFactory *old_factory = NULL;
2204 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
2205 &IID_nsIFactory, (void**)&old_factory);
2206 if(NS_FAILED(nsres)) {
2207 ERR("Could not get factory: %08x\n", nsres);
2211 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
2212 if(NS_FAILED(nsres)) {
2213 ERR("Couldn not create nsIOService instance %08x\n", nsres);
2214 nsIFactory_Release(old_factory);
2218 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
2219 nsIFactory_Release(old_factory);
2220 if(NS_FAILED(nsres))
2221 ERR("UnregisterFactory failed: %08x\n", nsres);
2223 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
2224 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
2225 if(NS_FAILED(nsres))
2226 ERR("RegisterFactory failed: %08x\n", nsres);