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 handle_uri(NSContainer *container, nsChannel *channel, LPCWSTR uri)
98 IServiceProvider *service_provider;
99 HTMLDocument *doc = container->doc;
104 NSContainer *container_iter = container;
106 hlnf = HLNF_OPENINNEWWINDOW;
107 while(!container_iter->doc)
108 container_iter = container_iter->parent;
109 doc = container_iter->doc;
112 if(!hlnf && !exec_shldocvw_67(doc, uri))
115 hres = IOleClientSite_QueryInterface(doc->client, &IID_IServiceProvider,
116 (void**)&service_provider);
117 if(SUCCEEDED(hres)) {
118 IHlinkFrame *hlink_frame;
120 hres = IServiceProvider_QueryService(service_provider, &IID_IHlinkFrame,
121 &IID_IHlinkFrame, (void**)&hlink_frame);
122 IServiceProvider_Release(service_provider);
123 if(SUCCEEDED(hres)) {
124 hlink_frame_navigate(doc, hlink_frame, uri, channel->post_data_stream, hlnf);
125 IHlinkFrame_Release(hlink_frame);
134 static BOOL before_async_open(nsChannel *channel, NSContainer *container)
142 nsACString_Init(&uri_str, NULL);
143 nsIWineURI_GetSpec(channel->uri, &uri_str);
144 nsACString_GetData(&uri_str, &uria, NULL);
145 len = MultiByteToWideChar(CP_ACP, 0, uria, -1, NULL, 0);
146 uri = mshtml_alloc(len*sizeof(WCHAR));
147 MultiByteToWideChar(CP_ACP, 0, uria, -1, uri, len);
148 nsACString_Finish(&uri_str);
150 ret = handle_uri(container, channel, uri);
157 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
159 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
161 nsChannel *This = NSCHANNEL_THIS(iface);
165 if(IsEqualGUID(&IID_nsISupports, riid)) {
166 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
167 *result = NSCHANNEL(This);
168 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
169 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
170 *result = NSCHANNEL(This);
171 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
172 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
173 *result = NSCHANNEL(This);
174 }else if(This->http_channel && IsEqualGUID(&IID_nsIHttpChannel, riid)) {
175 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
176 *result = NSHTTPCHANNEL(This);
177 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
178 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
179 *result = NSUPCHANNEL(This);
183 nsIChannel_AddRef(NSCHANNEL(This));
187 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
190 return nsIChannel_QueryInterface(This->channel, riid, result);
191 return NS_NOINTERFACE;
194 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
196 nsChannel *This = NSCHANNEL_THIS(iface);
197 nsrefcnt ref = InterlockedIncrement(&This->ref);
199 TRACE("(%p) ref=%d\n", This, ref);
204 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
206 nsChannel *This = NSCHANNEL_THIS(iface);
207 LONG ref = InterlockedDecrement(&This->ref);
210 nsIWineURI_Release(This->uri);
212 nsIChannel_Release(This->channel);
213 if(This->http_channel)
214 nsIHttpChannel_Release(This->http_channel);
215 if(This->post_data_stream)
216 nsIInputStream_Release(This->post_data_stream);
218 nsILoadGroup_Release(This->load_group);
219 if(This->notif_callback)
220 nsIInterfaceRequestor_Release(This->notif_callback);
221 if(This->original_uri)
222 nsIURI_Release(This->original_uri);
223 mshtml_free(This->content);
230 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
232 nsChannel *This = NSCHANNEL_THIS(iface);
234 TRACE("(%p)->(%p)\n", This, aName);
237 return nsIChannel_GetName(This->channel, aName);
239 return NS_ERROR_NOT_IMPLEMENTED;
242 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
244 nsChannel *This = NSCHANNEL_THIS(iface);
246 TRACE("(%p)->(%p)\n", This, _retval);
249 return nsIChannel_IsPending(This->channel, _retval);
251 FIXME("default action not implemented\n");
252 return NS_ERROR_NOT_IMPLEMENTED;
255 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
257 nsChannel *This = NSCHANNEL_THIS(iface);
259 TRACE("(%p)->(%p)\n", This, aStatus);
262 return nsIChannel_GetStatus(This->channel, aStatus);
264 TRACE("returning NS_OK\n");
265 return *aStatus = NS_OK;
268 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
270 nsChannel *This = NSCHANNEL_THIS(iface);
272 TRACE("(%p)->(%08x)\n", This, aStatus);
275 return nsIChannel_Cancel(This->channel, aStatus);
277 FIXME("default action not implemented\n");
278 return NS_ERROR_NOT_IMPLEMENTED;
281 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
283 nsChannel *This = NSCHANNEL_THIS(iface);
285 TRACE("(%p)\n", This);
288 return nsIChannel_Suspend(This->channel);
290 FIXME("default action not implemented\n");
291 return NS_ERROR_NOT_IMPLEMENTED;
294 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
296 nsChannel *This = NSCHANNEL_THIS(iface);
298 TRACE("(%p)\n", This);
301 return nsIChannel_Resume(This->channel);
303 FIXME("default action not implemented\n");
304 return NS_ERROR_NOT_IMPLEMENTED;
307 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
309 nsChannel *This = NSCHANNEL_THIS(iface);
311 TRACE("(%p)->(%p)\n", This, aLoadGroup);
314 nsILoadGroup_AddRef(This->load_group);
316 *aLoadGroup = This->load_group;
320 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
322 nsChannel *This = NSCHANNEL_THIS(iface);
324 TRACE("(%p)->(%p)\n", This, aLoadGroup);
327 nsILoadGroup_Release(This->load_group);
329 nsILoadGroup_AddRef(aLoadGroup);
331 This->load_group = aLoadGroup;
334 return nsIChannel_SetLoadGroup(This->channel, aLoadGroup);
338 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
340 nsChannel *This = NSCHANNEL_THIS(iface);
342 TRACE("(%p)->(%p)\n", This, aLoadFlags);
344 *aLoadFlags = This->load_flags;
348 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
350 nsChannel *This = NSCHANNEL_THIS(iface);
352 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
354 This->load_flags = aLoadFlags;
357 return nsIChannel_SetLoadFlags(This->channel, aLoadFlags);
361 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
363 nsChannel *This = NSCHANNEL_THIS(iface);
365 TRACE("(%p)->(%p)\n", This, aOriginalURI);
367 if(This->original_uri)
368 nsIURI_AddRef(This->original_uri);
370 *aOriginalURI = This->original_uri;
374 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
376 nsChannel *This = NSCHANNEL_THIS(iface);
378 TRACE("(%p)->(%p)\n", This, aOriginalURI);
380 if(This->original_uri)
381 nsIURI_Release(This->original_uri);
383 nsIURI_AddRef(aOriginalURI);
384 This->original_uri = aOriginalURI;
387 return nsIChannel_SetOriginalURI(This->channel, aOriginalURI);
391 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
393 nsChannel *This = NSCHANNEL_THIS(iface);
395 TRACE("(%p)->(%p)\n", This, aURI);
397 nsIWineURI_AddRef(This->uri);
398 *aURI = (nsIURI*)This->uri;
403 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
405 nsChannel *This = NSCHANNEL_THIS(iface);
407 TRACE("(%p)->(%p)\n", This, aOwner);
410 return nsIChannel_GetOwner(This->channel, aOwner);
412 FIXME("default action not implemented\n");
413 return NS_ERROR_NOT_IMPLEMENTED;
416 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
418 nsChannel *This = NSCHANNEL_THIS(iface);
420 TRACE("(%p)->(%p)\n", This, aOwner);
423 return nsIChannel_SetOwner(This->channel, aOwner);
425 FIXME("default action not implemented\n");
426 return NS_ERROR_NOT_IMPLEMENTED;
429 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
430 nsIInterfaceRequestor **aNotificationCallbacks)
432 nsChannel *This = NSCHANNEL_THIS(iface);
434 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
436 if(This->notif_callback)
437 nsIInterfaceRequestor_AddRef(This->notif_callback);
438 *aNotificationCallbacks = This->notif_callback;
443 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
444 nsIInterfaceRequestor *aNotificationCallbacks)
446 nsChannel *This = NSCHANNEL_THIS(iface);
448 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
450 if(This->notif_callback)
451 nsIInterfaceRequestor_Release(This->notif_callback);
452 if(aNotificationCallbacks)
453 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
455 This->notif_callback = aNotificationCallbacks;
458 return nsIChannel_SetNotificationCallbacks(This->channel, aNotificationCallbacks);
462 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
464 nsChannel *This = NSCHANNEL_THIS(iface);
466 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
469 return nsIChannel_GetSecurityInfo(This->channel, aSecurityInfo);
471 FIXME("default action not implemented\n");
472 return NS_ERROR_NOT_IMPLEMENTED;
475 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
477 nsChannel *This = NSCHANNEL_THIS(iface);
479 TRACE("(%p)->(%p)\n", This, aContentType);
482 nsACString_SetData(aContentType, This->content);
487 return nsIChannel_GetContentType(This->channel, aContentType);
489 TRACE("returning default text/html\n");
490 nsACString_SetData(aContentType, "text/html");
494 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
495 const nsACString *aContentType)
497 nsChannel *This = NSCHANNEL_THIS(iface);
499 TRACE("(%p)->(%p)\n", This, aContentType);
502 return nsIChannel_SetContentType(This->channel, aContentType);
504 FIXME("default action not implemented\n");
505 return NS_ERROR_NOT_IMPLEMENTED;
508 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
509 nsACString *aContentCharset)
511 nsChannel *This = NSCHANNEL_THIS(iface);
513 TRACE("(%p)->(%p)\n", This, aContentCharset);
516 return nsIChannel_GetContentCharset(This->channel, aContentCharset);
518 FIXME("default action not implemented\n");
519 return NS_ERROR_NOT_IMPLEMENTED;
522 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
523 const nsACString *aContentCharset)
525 nsChannel *This = NSCHANNEL_THIS(iface);
527 TRACE("(%p)->(%p)\n", This, aContentCharset);
530 return nsIChannel_SetContentCharset(This->channel, aContentCharset);
532 FIXME("default action not implemented\n");
533 return NS_ERROR_NOT_IMPLEMENTED;
536 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
538 nsChannel *This = NSCHANNEL_THIS(iface);
540 TRACE("(%p)->(%p)\n", This, aContentLength);
543 return nsIChannel_GetContentLength(This->channel, aContentLength);
545 FIXME("default action not implemented\n");
546 return NS_ERROR_NOT_IMPLEMENTED;
549 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
551 nsChannel *This = NSCHANNEL_THIS(iface);
553 TRACE("(%p)->(%d)\n", This, aContentLength);
556 return nsIChannel_SetContentLength(This->channel, aContentLength);
558 FIXME("default action not implemented\n");
559 return NS_ERROR_NOT_IMPLEMENTED;
562 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
564 nsChannel *This = NSCHANNEL_THIS(iface);
566 TRACE("(%p)->(%p)\n", This, _retval);
569 return nsIChannel_Open(This->channel, _retval);
571 FIXME("default action not implemented\n");
572 return NS_ERROR_NOT_IMPLEMENTED;
575 static BOOL do_load_from_moniker_hack(nsChannel *This)
580 * We should always load the page from IMoniker, but Wine is not yet
581 * ready for this. This function is a heuristic, that decides which
582 * way of loading is better (Gecko implementation or IMoniker). The
583 * aim is to always return TRUE.
586 /* Load from moniker if there is no Gecko channel available */
590 /* Load about protocol from moniker */
591 nsIWineURI_SchemeIs(This->uri, "about", &b);
598 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
599 nsISupports *aContext)
601 nsChannel *This = NSCHANNEL_THIS(iface);
602 BSCallback *bscallback;
603 nsIWineURI *wine_uri;
611 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
613 nsIWineURI_GetIsDocumentURI(This->uri, &is_doc_uri);
615 if(is_doc_uri && (This->load_flags & LOAD_INITIAL_DOCUMENT_URI)) {
616 NSContainer *container;
618 nsIWineURI_GetNSContainer(This->uri, &container);
620 TRACE("container = NULL\n");
621 return nsIChannel_AsyncOpen(This->channel, aListener, aContext);
624 if(container->bscallback) {
625 nsIChannel_AddRef(NSCHANNEL(This));
626 container->bscallback->nschannel = This;
628 nsIStreamListener_AddRef(aListener);
629 container->bscallback->nslistener = aListener;
632 nsISupports_AddRef(aContext);
633 container->bscallback->nscontext = aContext;
636 nsIWebBrowserChrome_Release(NSWBCHROME(container));
638 if(do_load_from_moniker_hack(This))
639 return WINE_NS_LOAD_FROM_MONIKER;
640 }else if(container->doc) {
641 BOOL cont = before_async_open(This, container);
642 nsIWebBrowserChrome_Release(NSWBCHROME(container));
646 return NS_ERROR_UNEXPECTED;
649 nsIWebBrowserChrome_Release(NSWBCHROME(container));
651 ? nsIChannel_AsyncOpen(This->channel, aListener, aContext)
652 : NS_ERROR_UNEXPECTED;
657 if(This->post_data_stream) {
658 nsIUploadChannel *upload_channel;
660 nsres = nsIChannel_QueryInterface(This->channel, &IID_nsIUploadChannel,
661 (void**)&upload_channel);
662 if(NS_SUCCEEDED(nsres)) {
663 nsACString empty_string;
664 nsACString_Init(&empty_string, "");
666 nsres = nsIUploadChannel_SetUploadStream(upload_channel, This->post_data_stream,
668 nsIUploadChannel_Release(upload_channel);
670 WARN("SetUploadStream failed: %08x\n", nsres);
672 nsACString_Finish(&empty_string);
676 nsres = nsIChannel_AsyncOpen(This->channel, aListener, aContext);
678 if(NS_FAILED(nsres) && (This->load_flags & LOAD_INITIAL_DOCUMENT_URI))
679 return WINE_NS_LOAD_FROM_MONIKER;
683 TRACE("channel == NULL\n");
685 if(!This->original_uri) {
686 ERR("original_uri == NULL\n");
687 return NS_ERROR_UNEXPECTED;
690 nsres = nsIURI_QueryInterface(This->original_uri, &IID_nsIWineURI, (void**)&wine_uri);
691 if(NS_FAILED(nsres)) {
692 ERR("Could not get nsIWineURI: %08x\n", nsres);
693 return NS_ERROR_UNEXPECTED;
696 nsIWineURI_GetWineURL(wine_uri, &wine_url);
698 TRACE("wine_url == NULL\n");
699 return NS_ERROR_UNEXPECTED;
702 hres = CreateURLMoniker(NULL, wine_url, &mon);
704 WARN("CreateURLMonikrer failed: %08x\n", hres);
705 return NS_ERROR_UNEXPECTED;
708 bscallback = create_bscallback(mon);
709 IMoniker_Release(mon);
711 nsIChannel_AddRef(NSCHANNEL(This));
712 bscallback->nschannel = This;
714 nsIStreamListener_AddRef(aListener);
715 bscallback->nslistener = aListener;
718 nsISupports_AddRef(aContext);
719 bscallback->nscontext = aContext;
722 task = mshtml_alloc(sizeof(task_t));
724 task->doc = bscallback->doc;
725 task->task_id = TASK_START_BINDING;
727 task->bscallback = bscallback;
734 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
736 nsChannel *This = NSCHANNEL_THIS(iface);
738 TRACE("(%p)->(%p)\n", This, aRequestMethod);
740 if(This->http_channel)
741 return nsIHttpChannel_GetRequestMethod(This->http_channel, aRequestMethod);
743 return NS_ERROR_NOT_IMPLEMENTED;
746 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
747 const nsACString *aRequestMethod)
749 nsChannel *This = NSCHANNEL_THIS(iface);
751 TRACE("(%p)->(%p)\n", This, aRequestMethod);
753 if(This->http_channel)
754 return nsIHttpChannel_SetRequestMethod(This->http_channel, aRequestMethod);
756 return NS_ERROR_NOT_IMPLEMENTED;
759 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
761 nsChannel *This = NSCHANNEL_THIS(iface);
763 TRACE("(%p)->(%p)\n", This, aReferrer);
765 if(This->http_channel)
766 return nsIHttpChannel_GetReferrer(This->http_channel, aReferrer);
768 return NS_ERROR_NOT_IMPLEMENTED;
771 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
773 nsChannel *This = NSCHANNEL_THIS(iface);
775 TRACE("(%p)->(%p)\n", This, aReferrer);
777 if(This->http_channel)
778 return nsIHttpChannel_SetReferrer(This->http_channel, aReferrer);
780 return NS_ERROR_NOT_IMPLEMENTED;
783 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
784 const nsACString *aHeader, nsACString *_retval)
786 nsChannel *This = NSCHANNEL_THIS(iface);
788 TRACE("(%p)->(%p %p)\n", This, aHeader, _retval);
790 if(This->http_channel)
791 return nsIHttpChannel_GetRequestHeader(This->http_channel, aHeader, _retval);
793 return NS_ERROR_NOT_IMPLEMENTED;
796 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
797 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
799 nsChannel *This = NSCHANNEL_THIS(iface);
801 TRACE("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
803 if(This->http_channel)
804 return nsIHttpChannel_SetRequestHeader(This->http_channel, aHeader, aValue, aMerge);
806 return NS_ERROR_NOT_IMPLEMENTED;
809 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
810 nsIHttpHeaderVisitor *aVisitor)
812 nsChannel *This = NSCHANNEL_THIS(iface);
814 TRACE("(%p)->(%p)\n", This, aVisitor);
816 if(This->http_channel)
817 return nsIHttpChannel_VisitRequestHeaders(This->http_channel, aVisitor);
819 return NS_ERROR_NOT_IMPLEMENTED;
822 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
824 nsChannel *This = NSCHANNEL_THIS(iface);
826 TRACE("(%p)->(%p)\n", This, aAllowPipelining);
828 if(This->http_channel)
829 return nsIHttpChannel_GetAllowPipelining(This->http_channel, aAllowPipelining);
831 return NS_ERROR_NOT_IMPLEMENTED;
834 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
836 nsChannel *This = NSCHANNEL_THIS(iface);
838 TRACE("(%p)->(%x)\n", This, aAllowPipelining);
840 if(This->http_channel)
841 return nsIHttpChannel_SetAllowPipelining(This->http_channel, aAllowPipelining);
843 return NS_ERROR_NOT_IMPLEMENTED;
846 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
848 nsChannel *This = NSCHANNEL_THIS(iface);
850 TRACE("(%p)->(%p)\n", This, aRedirectionLimit);
852 if(This->http_channel)
853 return nsIHttpChannel_GetRedirectionLimit(This->http_channel, aRedirectionLimit);
855 return NS_ERROR_NOT_IMPLEMENTED;
858 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
860 nsChannel *This = NSCHANNEL_THIS(iface);
862 TRACE("(%p)->(%u)\n", This, aRedirectionLimit);
864 if(This->http_channel)
865 return nsIHttpChannel_SetRedirectionLimit(This->http_channel, aRedirectionLimit);
867 return NS_ERROR_NOT_IMPLEMENTED;
870 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
872 nsChannel *This = NSCHANNEL_THIS(iface);
874 TRACE("(%p)->(%p)\n", This, aResponseStatus);
876 if(This->http_channel)
877 return nsIHttpChannel_GetResponseStatus(This->http_channel, aResponseStatus);
879 return NS_ERROR_NOT_IMPLEMENTED;
882 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
883 nsACString *aResponseStatusText)
885 nsChannel *This = NSCHANNEL_THIS(iface);
887 TRACE("(%p)->(%p)\n", This, aResponseStatusText);
889 if(This->http_channel)
890 return nsIHttpChannel_GetResponseStatusText(This->http_channel, aResponseStatusText);
892 return NS_ERROR_NOT_IMPLEMENTED;
895 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
896 PRBool *aRequestSucceeded)
898 nsChannel *This = NSCHANNEL_THIS(iface);
900 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
902 if(This->http_channel)
903 return nsIHttpChannel_GetRequestSucceeded(This->http_channel, aRequestSucceeded);
905 return NS_ERROR_NOT_IMPLEMENTED;
908 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
909 const nsACString *header, nsACString *_retval)
911 nsChannel *This = NSCHANNEL_THIS(iface);
913 TRACE("(%p)->(%p %p)\n", This, header, _retval);
915 if(This->http_channel)
916 return nsIHttpChannel_GetResponseHeader(This->http_channel, header, _retval);
918 return NS_ERROR_NOT_IMPLEMENTED;
921 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
922 const nsACString *header, const nsACString *value, PRBool merge)
924 nsChannel *This = NSCHANNEL_THIS(iface);
926 TRACE("(%p)->(%p %p %x)\n", This, header, value, merge);
928 if(This->http_channel)
929 return nsIHttpChannel_SetResponseHeader(This->http_channel, header, value, merge);
931 return NS_ERROR_NOT_IMPLEMENTED;
934 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
935 nsIHttpHeaderVisitor *aVisitor)
937 nsChannel *This = NSCHANNEL_THIS(iface);
939 TRACE("(%p)->(%p)\n", This, aVisitor);
941 if(This->http_channel)
942 return nsIHttpChannel_VisitResponseHeaders(This->http_channel, aVisitor);
944 return NS_ERROR_NOT_IMPLEMENTED;
947 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
949 nsChannel *This = NSCHANNEL_THIS(iface);
951 TRACE("(%p)->(%p)\n", This, _retval);
953 if(This->http_channel)
954 return nsIHttpChannel_IsNoStoreResponse(This->http_channel, _retval);
956 return NS_ERROR_NOT_IMPLEMENTED;
959 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
961 nsChannel *This = NSCHANNEL_THIS(iface);
963 TRACE("(%p)->(%p)\n", This, _retval);
965 if(This->http_channel)
966 return nsIHttpChannel_IsNoCacheResponse(This->http_channel, _retval);
968 return NS_ERROR_NOT_IMPLEMENTED;
971 #undef NSCHANNEL_THIS
973 static const nsIHttpChannelVtbl nsChannelVtbl = {
974 nsChannel_QueryInterface,
983 nsChannel_GetLoadGroup,
984 nsChannel_SetLoadGroup,
985 nsChannel_GetLoadFlags,
986 nsChannel_SetLoadFlags,
987 nsChannel_GetOriginalURI,
988 nsChannel_SetOriginalURI,
992 nsChannel_GetNotificationCallbacks,
993 nsChannel_SetNotificationCallbacks,
994 nsChannel_GetSecurityInfo,
995 nsChannel_GetContentType,
996 nsChannel_SetContentType,
997 nsChannel_GetContentCharset,
998 nsChannel_SetContentCharset,
999 nsChannel_GetContentLength,
1000 nsChannel_SetContentLength,
1002 nsChannel_AsyncOpen,
1003 nsChannel_GetRequestMethod,
1004 nsChannel_SetRequestMethod,
1005 nsChannel_GetReferrer,
1006 nsChannel_SetReferrer,
1007 nsChannel_GetRequestHeader,
1008 nsChannel_SetRequestHeader,
1009 nsChannel_VisitRequestHeaders,
1010 nsChannel_GetAllowPipelining,
1011 nsChannel_SetAllowPipelining,
1012 nsChannel_GetRedirectionLimit,
1013 nsChannel_SetRedirectionLimit,
1014 nsChannel_GetResponseStatus,
1015 nsChannel_GetResponseStatusText,
1016 nsChannel_GetRequestSucceeded,
1017 nsChannel_GetResponseHeader,
1018 nsChannel_SetResponseHeader,
1019 nsChannel_VisitResponseHeaders,
1020 nsChannel_IsNoStoreResponse,
1021 nsChannel_IsNoCacheResponse
1024 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1026 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1029 nsChannel *This = NSUPCHANNEL_THIS(iface);
1030 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1033 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1035 nsChannel *This = NSUPCHANNEL_THIS(iface);
1036 return nsIChannel_AddRef(NSCHANNEL(This));
1039 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1041 nsChannel *This = NSUPCHANNEL_THIS(iface);
1042 return nsIChannel_Release(NSCHANNEL(This));
1045 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1046 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1048 nsChannel *This = NSUPCHANNEL_THIS(iface);
1049 const char *content_type;
1051 TRACE("(%p)->(%p %p %d)\n", This, aStream, aContentType, aContentLength);
1053 if(This->post_data_stream)
1054 nsIInputStream_Release(This->post_data_stream);
1057 nsACString_GetData(aContentType, &content_type, NULL);
1059 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
1062 if(aContentLength != -1)
1063 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1066 nsIInputStream_AddRef(aStream);
1067 This->post_data_stream = aStream;
1072 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1073 nsIInputStream **aUploadStream)
1075 nsChannel *This = NSUPCHANNEL_THIS(iface);
1077 TRACE("(%p)->(%p)\n", This, aUploadStream);
1079 if(This->post_data_stream)
1080 nsIInputStream_AddRef(This->post_data_stream);
1082 *aUploadStream = This->post_data_stream;
1086 #undef NSUPCHANNEL_THIS
1088 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1089 nsUploadChannel_QueryInterface,
1090 nsUploadChannel_AddRef,
1091 nsUploadChannel_Release,
1092 nsUploadChannel_SetUploadStream,
1093 nsUploadChannel_GetUploadStream
1096 #define NSURI_THIS(iface) DEFINE_THIS(nsURI, WineURI, iface)
1098 static nsresult NSAPI nsURI_QueryInterface(nsIWineURI *iface, nsIIDRef riid, nsQIResult result)
1100 nsURI *This = NSURI_THIS(iface);
1104 if(IsEqualGUID(&IID_nsISupports, riid)) {
1105 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1106 *result = NSURI(This);
1107 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1108 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1109 *result = NSURI(This);
1110 }else if(IsEqualGUID(&IID_nsIWineURI, riid)) {
1111 TRACE("(%p)->(IID_nsIWineURI %p)\n", This, result);
1112 *result = NSURI(This);
1116 nsIURI_AddRef(NSURI(This));
1120 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1121 return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1124 static nsrefcnt NSAPI nsURI_AddRef(nsIWineURI *iface)
1126 nsURI *This = NSURI_THIS(iface);
1127 LONG ref = InterlockedIncrement(&This->ref);
1129 TRACE("(%p) ref=%d\n", This, ref);
1134 static nsrefcnt NSAPI nsURI_Release(nsIWineURI *iface)
1136 nsURI *This = NSURI_THIS(iface);
1137 LONG ref = InterlockedDecrement(&This->ref);
1139 TRACE("(%p) ref=%d\n", This, ref);
1143 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1145 nsIURI_Release(This->uri);
1146 mshtml_free(This->wine_url);
1153 static nsresult NSAPI nsURI_GetSpec(nsIWineURI *iface, nsACString *aSpec)
1155 nsURI *This = NSURI_THIS(iface);
1157 TRACE("(%p)->(%p)\n", This, aSpec);
1159 if(This->use_wine_url) {
1160 char speca[INTERNET_MAX_URL_LENGTH];
1161 WideCharToMultiByte(CP_ACP, 0, This->wine_url, -1, speca, sizeof(speca), NULL, NULL);
1162 nsACString_SetData(aSpec, speca);
1168 return nsIURI_GetSpec(This->uri, aSpec);
1170 TRACE("returning error\n");
1171 return NS_ERROR_NOT_IMPLEMENTED;
1175 static nsresult NSAPI nsURI_SetSpec(nsIWineURI *iface, const nsACString *aSpec)
1177 nsURI *This = NSURI_THIS(iface);
1179 TRACE("(%p)->(%p)\n", This, aSpec);
1182 return nsIURI_SetSpec(This->uri, aSpec);
1184 FIXME("default action not implemented\n");
1185 return NS_ERROR_NOT_IMPLEMENTED;
1188 static nsresult NSAPI nsURI_GetPrePath(nsIWineURI *iface, nsACString *aPrePath)
1190 nsURI *This = NSURI_THIS(iface);
1192 TRACE("(%p)->(%p)\n", This, aPrePath);
1195 return nsIURI_GetPrePath(This->uri, aPrePath);
1197 FIXME("default action not implemented\n");
1198 return NS_ERROR_NOT_IMPLEMENTED;
1201 static nsresult NSAPI nsURI_GetScheme(nsIWineURI *iface, nsACString *aScheme)
1203 nsURI *This = NSURI_THIS(iface);
1205 TRACE("(%p)->(%p)\n", This, aScheme);
1207 if(This->use_wine_url) {
1209 * For Gecko we set scheme to unknown so it won't be handled
1210 * as any special case.
1212 nsACString_SetData(aScheme, "wine");
1217 return nsIURI_GetScheme(This->uri, aScheme);
1219 TRACE("returning error\n");
1220 return NS_ERROR_NOT_IMPLEMENTED;
1223 static nsresult NSAPI nsURI_SetScheme(nsIWineURI *iface, const nsACString *aScheme)
1225 nsURI *This = NSURI_THIS(iface);
1227 TRACE("(%p)->(%p)\n", This, aScheme);
1230 return nsIURI_SetScheme(This->uri, aScheme);
1232 FIXME("default action not implemented\n");
1233 return NS_ERROR_NOT_IMPLEMENTED;
1236 static nsresult NSAPI nsURI_GetUserPass(nsIWineURI *iface, nsACString *aUserPass)
1238 nsURI *This = NSURI_THIS(iface);
1240 TRACE("(%p)->(%p)\n", This, aUserPass);
1243 return nsIURI_GetUserPass(This->uri, aUserPass);
1245 FIXME("default action not implemented\n");
1246 return NS_ERROR_NOT_IMPLEMENTED;
1249 static nsresult NSAPI nsURI_SetUserPass(nsIWineURI *iface, const nsACString *aUserPass)
1251 nsURI *This = NSURI_THIS(iface);
1253 TRACE("(%p)->(%p)\n", This, aUserPass);
1256 return nsIURI_SetUserPass(This->uri, aUserPass);
1258 FIXME("default action not implemented\n");
1259 return NS_ERROR_NOT_IMPLEMENTED;
1262 static nsresult NSAPI nsURI_GetUsername(nsIWineURI *iface, nsACString *aUsername)
1264 nsURI *This = NSURI_THIS(iface);
1266 TRACE("(%p)->(%p)\n", This, aUsername);
1269 return nsIURI_GetUsername(This->uri, aUsername);
1271 FIXME("default action not implemented\n");
1272 return NS_ERROR_NOT_IMPLEMENTED;
1275 static nsresult NSAPI nsURI_SetUsername(nsIWineURI *iface, const nsACString *aUsername)
1277 nsURI *This = NSURI_THIS(iface);
1279 TRACE("(%p)->(%p)\n", This, aUsername);
1282 return nsIURI_SetUsername(This->uri, aUsername);
1284 FIXME("default action not implemented\n");
1285 return NS_ERROR_NOT_IMPLEMENTED;
1288 static nsresult NSAPI nsURI_GetPassword(nsIWineURI *iface, nsACString *aPassword)
1290 nsURI *This = NSURI_THIS(iface);
1292 TRACE("(%p)->(%p)\n", This, aPassword);
1295 return nsIURI_GetPassword(This->uri, aPassword);
1297 FIXME("default action not implemented\n");
1298 return NS_ERROR_NOT_IMPLEMENTED;
1301 static nsresult NSAPI nsURI_SetPassword(nsIWineURI *iface, const nsACString *aPassword)
1303 nsURI *This = NSURI_THIS(iface);
1305 TRACE("(%p)->(%p)\n", This, aPassword);
1308 return nsIURI_SetPassword(This->uri, aPassword);
1310 FIXME("default action not implemented\n");
1311 return NS_ERROR_NOT_IMPLEMENTED;
1314 static nsresult NSAPI nsURI_GetHostPort(nsIWineURI *iface, nsACString *aHostPort)
1316 nsURI *This = NSURI_THIS(iface);
1318 TRACE("(%p)->(%p)\n", This, aHostPort);
1321 return nsIURI_GetHostPort(This->uri, aHostPort);
1323 FIXME("default action not implemented\n");
1324 return NS_ERROR_NOT_IMPLEMENTED;
1327 static nsresult NSAPI nsURI_SetHostPort(nsIWineURI *iface, const nsACString *aHostPort)
1329 nsURI *This = NSURI_THIS(iface);
1331 TRACE("(%p)->(%p)\n", This, aHostPort);
1334 return nsIURI_SetHostPort(This->uri, aHostPort);
1336 FIXME("default action not implemented\n");
1337 return NS_ERROR_NOT_IMPLEMENTED;
1340 static nsresult NSAPI nsURI_GetHost(nsIWineURI *iface, nsACString *aHost)
1342 nsURI *This = NSURI_THIS(iface);
1344 TRACE("(%p)->(%p)\n", This, aHost);
1347 return nsIURI_GetHost(This->uri, aHost);
1349 FIXME("default action not implemented\n");
1350 return NS_ERROR_NOT_IMPLEMENTED;
1353 static nsresult NSAPI nsURI_SetHost(nsIWineURI *iface, const nsACString *aHost)
1355 nsURI *This = NSURI_THIS(iface);
1357 TRACE("(%p)->(%p)\n", This, aHost);
1360 return nsIURI_SetHost(This->uri, aHost);
1362 FIXME("default action not implemented\n");
1363 return NS_ERROR_NOT_IMPLEMENTED;
1366 static nsresult NSAPI nsURI_GetPort(nsIWineURI *iface, PRInt32 *aPort)
1368 nsURI *This = NSURI_THIS(iface);
1370 TRACE("(%p)->(%p)\n", This, aPort);
1373 return nsIURI_GetPort(This->uri, aPort);
1375 FIXME("default action not implemented\n");
1376 return NS_ERROR_NOT_IMPLEMENTED;
1379 static nsresult NSAPI nsURI_SetPort(nsIWineURI *iface, PRInt32 aPort)
1381 nsURI *This = NSURI_THIS(iface);
1383 TRACE("(%p)->(%d)\n", This, aPort);
1386 return nsIURI_SetPort(This->uri, aPort);
1388 FIXME("default action not implemented\n");
1389 return NS_ERROR_NOT_IMPLEMENTED;
1392 static nsresult NSAPI nsURI_GetPath(nsIWineURI *iface, nsACString *aPath)
1394 nsURI *This = NSURI_THIS(iface);
1396 TRACE("(%p)->(%p)\n", This, aPath);
1399 return nsIURI_GetPath(This->uri, aPath);
1401 FIXME("default action not implemented\n");
1402 return NS_ERROR_NOT_IMPLEMENTED;
1405 static nsresult NSAPI nsURI_SetPath(nsIWineURI *iface, const nsACString *aPath)
1407 nsURI *This = NSURI_THIS(iface);
1409 TRACE("(%p)->(%p)\n", This, aPath);
1412 return nsIURI_SetPath(This->uri, aPath);
1414 FIXME("default action not implemented\n");
1415 return NS_ERROR_NOT_IMPLEMENTED;
1418 static nsresult NSAPI nsURI_Equals(nsIWineURI *iface, nsIURI *other, PRBool *_retval)
1420 nsURI *This = NSURI_THIS(iface);
1422 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1425 return nsIURI_Equals(This->uri, other, _retval);
1427 FIXME("default action not implemented\n");
1428 return NS_ERROR_NOT_IMPLEMENTED;
1431 static nsresult NSAPI nsURI_SchemeIs(nsIWineURI *iface, const char *scheme, PRBool *_retval)
1433 nsURI *This = NSURI_THIS(iface);
1435 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1437 if(This->use_wine_url) {
1438 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
1439 int len = MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR))-1;
1441 *_retval = strlenW(This->wine_url) > len
1442 && This->wine_url[len] == ':'
1443 && !memcmp(buf, This->wine_url, len*sizeof(WCHAR));
1448 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1450 TRACE("returning error\n");
1451 return NS_ERROR_NOT_IMPLEMENTED;
1454 static nsresult NSAPI nsURI_Clone(nsIWineURI *iface, nsIURI **_retval)
1456 nsURI *This = NSURI_THIS(iface);
1458 TRACE("(%p)->(%p)\n", This, _retval);
1462 nsIWineURI *wine_uri;
1465 nsres = nsIURI_Clone(This->uri, &uri);
1466 if(NS_FAILED(nsres)) {
1467 WARN("Clone failed: %08x\n", nsres);
1471 nsres = create_uri(uri, This->container, &wine_uri);
1472 *_retval = (nsIURI*)wine_uri;
1473 if(NS_SUCCEEDED(nsres))
1474 return nsIWineURI_SetWineURL(wine_uri, This->wine_url);
1478 FIXME("default action not implemented\n");
1479 return NS_ERROR_NOT_IMPLEMENTED;
1482 static nsresult NSAPI nsURI_Resolve(nsIWineURI *iface, const nsACString *arelativePath,
1483 nsACString *_retval)
1485 nsURI *This = NSURI_THIS(iface);
1487 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1490 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1492 FIXME("default action not implemented\n");
1493 return NS_ERROR_NOT_IMPLEMENTED;
1496 static nsresult NSAPI nsURI_GetAsciiSpec(nsIWineURI *iface, nsACString *aAsciiSpec)
1498 nsURI *This = NSURI_THIS(iface);
1500 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1503 return nsIURI_GetSpec(NSURI(This), aAsciiSpec);
1506 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1508 TRACE("returning error\n");
1509 return NS_ERROR_NOT_IMPLEMENTED;
1512 static nsresult NSAPI nsURI_GetAsciiHost(nsIWineURI *iface, nsACString *aAsciiHost)
1514 nsURI *This = NSURI_THIS(iface);
1516 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1519 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1521 FIXME("default action not implemented\n");
1522 return NS_ERROR_NOT_IMPLEMENTED;
1525 static nsresult NSAPI nsURI_GetOriginCharset(nsIWineURI *iface, nsACString *aOriginCharset)
1527 nsURI *This = NSURI_THIS(iface);
1529 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1532 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1534 FIXME("default action not implemented\n");
1535 return NS_ERROR_NOT_IMPLEMENTED;
1538 static nsresult NSAPI nsURI_GetNSContainer(nsIWineURI *iface, NSContainer **aContainer)
1540 nsURI *This = NSURI_THIS(iface);
1542 TRACE("(%p)->(%p)\n", This, aContainer);
1545 nsIWebBrowserChrome_AddRef(NSWBCHROME(This->container));
1546 *aContainer = This->container;
1551 static nsresult NSAPI nsURI_SetNSContainer(nsIWineURI *iface, NSContainer *aContainer)
1553 nsURI *This = NSURI_THIS(iface);
1555 TRACE("(%p)->(%p)\n", This, aContainer);
1557 if(This->container) {
1558 if(This->container == aContainer)
1560 WARN("Container already set: %p\n", This->container);
1561 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1565 nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer));
1566 This->container = aContainer;
1571 static nsresult NSAPI nsURI_GetIsDocumentURI(nsIWineURI *iface, PRBool *aIsDocumentURI)
1573 nsURI *This = NSURI_THIS(iface);
1575 TRACE("(%p)->(%p)\n", This, aIsDocumentURI);
1577 *aIsDocumentURI = This->is_doc_uri;
1581 static nsresult NSAPI nsURI_SetIsDocumentURI(nsIWineURI *iface, PRBool aIsDocumentURI)
1583 nsURI *This = NSURI_THIS(iface);
1585 TRACE("(%p)->(%x)\n", This, aIsDocumentURI);
1587 This->is_doc_uri = aIsDocumentURI;
1591 static nsresult NSAPI nsURI_GetWineURL(nsIWineURI *iface, LPCWSTR *aURL)
1593 nsURI *This = NSURI_THIS(iface);
1595 TRACE("(%p)->(%p)\n", This, aURL);
1597 *aURL = This->wine_url;
1601 static nsresult NSAPI nsURI_SetWineURL(nsIWineURI *iface, LPCWSTR aURL)
1603 nsURI *This = NSURI_THIS(iface);
1605 static const WCHAR wszFtp[] = {'f','t','p',':'};
1606 static const WCHAR wszHttp[] = {'h','t','t','p',':'};
1607 static const WCHAR wszHttps[] = {'h','t','t','p','s',':'};
1609 TRACE("(%p)->(%s)\n", This, debugstr_w(aURL));
1611 mshtml_free(This->wine_url);
1614 int len = strlenW(aURL)+1;
1615 This->wine_url = mshtml_alloc(len*sizeof(WCHAR));
1616 memcpy(This->wine_url, aURL, len*sizeof(WCHAR));
1618 /* FIXME: Always use wine url */
1619 This->use_wine_url =
1620 strncmpW(aURL, wszFtp, sizeof(wszFtp)/sizeof(WCHAR))
1621 && strncmpW(aURL, wszHttp, sizeof(wszHttp)/sizeof(WCHAR))
1622 && strncmpW(aURL, wszHttps, sizeof(wszHttps)/sizeof(WCHAR));
1624 This->wine_url = NULL;
1625 This->use_wine_url = FALSE;
1633 static const nsIWineURIVtbl nsWineURIVtbl = {
1634 nsURI_QueryInterface,
1662 nsURI_GetOriginCharset,
1663 nsURI_GetNSContainer,
1664 nsURI_SetNSContainer,
1665 nsURI_GetIsDocumentURI,
1666 nsURI_SetIsDocumentURI,
1671 static nsresult create_uri(nsIURI *uri, NSContainer *container, nsIWineURI **_retval)
1673 nsURI *ret = mshtml_alloc(sizeof(nsURI));
1675 ret->lpWineURIVtbl = &nsWineURIVtbl;
1678 ret->container = container;
1679 ret->wine_url = NULL;
1680 ret->is_doc_uri = FALSE;
1681 ret->use_wine_url = FALSE;
1684 nsIWebBrowserChrome_AddRef(NSWBCHROME(container));
1686 TRACE("retval=%p\n", ret);
1687 *_retval = NSWINEURI(ret);
1691 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
1696 if(IsEqualGUID(&IID_nsISupports, riid)) {
1697 TRACE("(IID_nsISupports %p)\n", result);
1699 }else if(IsEqualGUID(&IID_nsIIOService, riid)) {
1700 TRACE("(IID_nsIIOService %p)\n", result);
1705 nsIIOService_AddRef(iface);
1709 WARN("(%s %p)\n", debugstr_guid(riid), result);
1710 return NS_NOINTERFACE;
1713 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
1718 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
1723 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
1724 nsIProtocolHandler **_retval)
1726 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1727 return nsIIOService_GetProtocolHandler(nsio, aScheme, _retval);
1730 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
1733 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1734 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
1737 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
1738 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
1740 const char *spec = NULL;
1741 NSContainer *nscontainer = NULL;
1743 PRBool is_javascript = FALSE;
1744 LPCWSTR base_wine_url = NULL;
1745 nsIWineURI *base_wine_uri = NULL, *wine_uri;
1748 nsACString_GetData(aSpec, &spec, NULL);
1750 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
1754 nsACString base_uri_str;
1755 const char *base_uri = NULL;
1757 static const char szChrome[] = "chrome:";
1758 static const char szResource[] = "resource:";
1760 nsACString_Init(&base_uri_str, NULL);
1762 nsres = nsIURI_GetSpec(aBaseURI, &base_uri_str);
1763 if(NS_SUCCEEDED(nsres)) {
1764 nsACString_GetData(&base_uri_str, &base_uri, NULL);
1765 TRACE("base_uri=%s\n", debugstr_a(base_uri));
1767 ERR("GetSpec failed: %08x\n", nsres);
1770 nsACString_Finish(&base_uri_str);
1772 if(!strncmp(spec, szChrome, sizeof(szChrome)-1)
1773 || !strncmp(spec, szResource, sizeof(szResource)-1))
1777 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
1778 if(NS_FAILED(nsres))
1779 TRACE("NewURI failed: %08x\n", nsres);
1782 nsIURI_SchemeIs(uri, "javascript", &is_javascript);
1784 TRACE("returning javascript uri: %p\n", uri);
1791 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsIWineURI, (void**)&base_wine_uri);
1792 if(NS_SUCCEEDED(nsres)) {
1793 nsIWineURI_GetNSContainer(base_wine_uri, &nscontainer);
1794 nsIWineURI_GetWineURL(base_wine_uri, &base_wine_url);
1796 ERR("Could not get nsIWineURI: %08x\n", nsres);
1800 nsres = create_uri(uri, nscontainer, &wine_uri);
1801 *_retval = (nsIURI*)wine_uri;
1804 nsIWebBrowserChrome_Release(NSWBCHROME(nscontainer));
1807 WCHAR url[INTERNET_MAX_URL_LENGTH], rel_url[INTERNET_MAX_URL_LENGTH];
1812 nsACString_GetData(aSpec, &speca, NULL);
1813 MultiByteToWideChar(CP_ACP, 0, speca, -1, rel_url, sizeof(rel_url)/sizeof(WCHAR));
1815 hres = CoInternetCombineUrl(base_wine_url, rel_url,
1816 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
1817 url, sizeof(url)/sizeof(WCHAR), &len, 0);
1819 nsIWineURI_SetWineURL(wine_uri, url);
1821 WARN("CoCombineUrl failed: %08x\n", hres);
1825 nsIWineURI_Release(base_wine_uri);
1830 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
1833 TRACE("(%p %p)\n", aFile, _retval);
1834 return nsIIOService_NewFileURI(nsio, aFile, _retval);
1837 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
1838 nsIChannel **_retval)
1840 nsIChannel *channel = NULL;
1842 nsIWineURI *wine_uri;
1845 TRACE("(%p %p)\n", aURI, _retval);
1847 nsres = nsIIOService_NewChannelFromURI(nsio, aURI, &channel);
1848 if(NS_FAILED(nsres) && nsres != NS_ERROR_UNKNOWN_PROTOCOL) {
1849 WARN("NewChannelFromURI failed: %08x\n", nsres);
1854 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
1855 if(NS_FAILED(nsres)) {
1856 WARN("Could not get nsIWineURI: %08x\n", nsres);
1858 return channel ? NS_OK : NS_ERROR_UNEXPECTED;
1861 ret = mshtml_alloc(sizeof(nsChannel));
1863 ret->lpHttpChannelVtbl = &nsChannelVtbl;
1864 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
1866 ret->channel = channel;
1867 ret->http_channel = NULL;
1868 ret->uri = wine_uri;
1869 ret->post_data_stream = NULL;
1870 ret->load_group = NULL;
1871 ret->notif_callback = NULL;
1872 ret->load_flags = 0;
1873 ret->content = NULL;
1875 nsIURI_AddRef(aURI);
1876 ret->original_uri = aURI;
1879 nsIChannel_QueryInterface(channel, &IID_nsIHttpChannel, (void**)&ret->http_channel);
1881 *_retval = NSCHANNEL(ret);
1885 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
1886 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
1888 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
1889 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
1892 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
1894 TRACE("(%p)\n", aOffline);
1895 return nsIIOService_GetOffline(nsio, aOffline);
1898 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
1900 TRACE("(%x)\n", aOffline);
1901 return nsIIOService_SetOffline(nsio, aOffline);
1904 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
1905 const char *aScheme, PRBool *_retval)
1907 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
1908 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
1911 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
1912 nsACString * _retval)
1914 TRACE("(%p %p)\n", urlString, _retval);
1915 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
1918 static const nsIIOServiceVtbl nsIOServiceVtbl = {
1919 nsIOService_QueryInterface,
1921 nsIOService_Release,
1922 nsIOService_GetProtocolHandler,
1923 nsIOService_GetProtocolFlags,
1925 nsIOService_NewFileURI,
1926 nsIOService_NewChannelFromURI,
1927 nsIOService_NewChannel,
1928 nsIOService_GetOffline,
1929 nsIOService_SetOffline,
1930 nsIOService_AllowPort,
1931 nsIOService_ExtractScheme
1934 static nsIIOService nsIOService = { &nsIOServiceVtbl };
1936 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
1941 if(IsEqualGUID(&IID_nsISupports, riid)) {
1942 TRACE("(IID_nsISupoprts %p)\n", result);
1944 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
1945 TRACE("(IID_nsIFactory %p)\n", result);
1950 nsIFactory_AddRef(iface);
1954 WARN("(%s %p)\n", debugstr_guid(riid), result);
1955 return NS_NOINTERFACE;
1958 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
1963 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
1968 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
1969 nsISupports *aOuter, const nsIID *iid, void **result)
1971 return nsIIOService_QueryInterface(&nsIOService, iid, result);
1974 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
1976 WARN("(%x)\n", lock);
1980 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
1981 nsIOServiceFactory_QueryInterface,
1982 nsIOServiceFactory_AddRef,
1983 nsIOServiceFactory_Release,
1984 nsIOServiceFactory_CreateInstance,
1985 nsIOServiceFactory_LockFactory
1988 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
1990 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
1992 nsIFactory *old_factory = NULL;
1995 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
1996 &IID_nsIFactory, (void**)&old_factory);
1997 if(NS_FAILED(nsres)) {
1998 ERR("Could not get factory: %08x\n", nsres);
1999 nsIFactory_Release(old_factory);
2003 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
2004 if(NS_FAILED(nsres)) {
2005 ERR("Couldn not create nsIOService instance %08x\n", nsres);
2006 nsIFactory_Release(old_factory);
2010 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
2011 nsIFactory_Release(old_factory);
2012 if(NS_FAILED(nsres))
2013 ERR("UnregisterFactory failed: %08x\n", nsres);
2015 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
2016 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
2017 if(NS_FAILED(nsres))
2018 ERR("RegisterFactory failed: %08x\n", nsres);