2 * Copyright 2006 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 #define LOAD_INITIAL_DOCUMENT_URI 0x80000
40 #define NS_IOSERVICE_CLASSNAME "nsIOService"
41 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
43 static IID NS_IOSERVICE_CID =
44 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
46 static nsIIOService *nsio = NULL;
49 const nsIHttpChannelVtbl *lpHttpChannelVtbl;
50 const nsIUploadChannelVtbl *lpUploadChannelVtbl;
55 nsIHttpChannel *http_channel;
57 nsIInputStream *post_data_stream;
58 nsILoadGroup *load_group;
59 nsIInterfaceRequestor *notif_callback;
60 nsLoadFlags load_flags;
65 const nsIWineURIVtbl *lpWineURIVtbl;
70 NSContainer *container;
73 #define NSCHANNEL(x) ((nsIChannel*) &(x)->lpHttpChannelVtbl)
74 #define NSHTTPCHANNEL(x) ((nsIHttpChannel*) &(x)->lpHttpChannelVtbl)
75 #define NSUPCHANNEL(x) ((nsIUploadChannel*) &(x)->lpUploadChannelVtbl)
76 #define NSURI(x) ((nsIURI*) &(x)->lpWineURIVtbl)
78 static BOOL exec_shldocvw_67(NSContainer *container, LPCWSTR url)
80 IOleCommandTarget *cmdtrg = NULL;
83 hres = IOleClientSite_QueryInterface(container->doc->client, &IID_IOleCommandTarget,
86 VARIANT varUrl, varRes;
88 V_VT(&varUrl) = VT_BSTR;
89 V_BSTR(&varUrl) = SysAllocString(url);
90 V_VT(&varRes) = VT_BOOL;
92 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
94 IOleCommandTarget_Release(cmdtrg);
95 SysFreeString(V_BSTR(&varUrl));
97 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
98 TRACE("got VARIANT_FALSE, do not load\n");
106 static BOOL handle_uri(NSContainer *container, nsChannel *channel, LPCWSTR uri)
108 IServiceProvider *service_provider;
111 if(!exec_shldocvw_67(container, uri))
114 hres = IOleClientSite_QueryInterface(container->doc->client, &IID_IServiceProvider,
115 (void**)&service_provider);
116 if(SUCCEEDED(hres)) {
117 IHlinkFrame *hlink_frame;
119 hres = IServiceProvider_QueryService(service_provider, &IID_IHlinkFrame,
120 &IID_IHlinkFrame, (void**)&hlink_frame);
121 if(SUCCEEDED(hres)) {
122 hlink_frame_navigate(container, hlink_frame, uri, channel->post_data_stream);
123 IHlinkFrame_Release(hlink_frame);
128 IServiceProvider_Release(service_provider);
134 static BOOL before_async_open(nsChannel *This)
137 NSContainer *container;
143 if(!(This->load_flags & LOAD_INITIAL_DOCUMENT_URI))
146 nsIWineURI_GetNSContainer(This->uri, &container);
148 WARN("container = NULL\n");
152 if(container->load_call) {
153 nsIWebBrowserChrome_Release(NSWBCHROME(container));
157 uri_str = nsACString_Create();
158 nsIWineURI_GetSpec(This->uri, uri_str);
159 nsACString_GetData(uri_str, &uria, NULL);
160 len = MultiByteToWideChar(CP_ACP, 0, uria, -1, NULL, 0);
161 uri = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
162 MultiByteToWideChar(CP_ACP, 0, uria, -1, uri, len);
163 nsACString_Destroy(uri_str);
165 ret = handle_uri(container, This, uri);
167 nsIWebBrowserChrome_Release(NSWBCHROME(container));
168 HeapFree(GetProcessHeap(), 0, uri);
173 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
175 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
177 nsChannel *This = NSCHANNEL_THIS(iface);
181 if(IsEqualGUID(&IID_nsISupports, riid)) {
182 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
183 *result = NSCHANNEL(This);
184 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
185 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
186 *result = NSCHANNEL(This);
187 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
188 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
189 *result = NSCHANNEL(This);
190 }else if(This->http_channel && IsEqualGUID(&IID_nsIHttpChannel, riid)) {
191 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
192 *result = NSHTTPCHANNEL(This);
193 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
194 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
195 *result = NSUPCHANNEL(This);
199 nsIChannel_AddRef(NSCHANNEL(This));
203 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
206 return nsIChannel_QueryInterface(This->channel, riid, result);
207 return NS_NOINTERFACE;
210 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
212 nsChannel *This = NSCHANNEL_THIS(iface);
213 nsrefcnt ref = InterlockedIncrement(&This->ref);
215 TRACE("(%p) ref=%ld\n", This, ref);
220 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
222 nsChannel *This = NSCHANNEL_THIS(iface);
223 LONG ref = InterlockedDecrement(&This->ref);
226 nsIWineURI_Release(This->uri);
228 nsIChannel_Release(This->channel);
229 if(This->http_channel)
230 nsIHttpChannel_Release(This->http_channel);
231 if(This->post_data_stream)
232 nsIInputStream_Release(This->post_data_stream);
234 nsILoadGroup_Release(This->load_group);
235 if(This->notif_callback)
236 nsIInterfaceRequestor_Release(This->notif_callback);
237 if(This->original_uri)
238 nsIURI_Release(This->original_uri);
239 HeapFree(GetProcessHeap(), 0, This);
245 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
247 nsChannel *This = NSCHANNEL_THIS(iface);
249 TRACE("(%p)->(%p)\n", This, aName);
252 return nsIChannel_GetName(This->channel, aName);
254 FIXME("default action not implemented\n");
255 return NS_ERROR_NOT_IMPLEMENTED;
258 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
260 nsChannel *This = NSCHANNEL_THIS(iface);
262 TRACE("(%p)->(%p)\n", This, _retval);
265 return nsIChannel_IsPending(This->channel, _retval);
267 FIXME("default action not implemented\n");
268 return NS_ERROR_NOT_IMPLEMENTED;
271 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
273 nsChannel *This = NSCHANNEL_THIS(iface);
275 TRACE("(%p)->(%p)\n", This, aStatus);
278 return nsIChannel_GetStatus(This->channel, aStatus);
280 FIXME("default action not implemented\n");
281 return NS_ERROR_NOT_IMPLEMENTED;
284 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
286 nsChannel *This = NSCHANNEL_THIS(iface);
288 TRACE("(%p)->(%08lx)\n", This, aStatus);
291 return nsIChannel_Cancel(This->channel, aStatus);
293 FIXME("default action not implemented\n");
294 return NS_ERROR_NOT_IMPLEMENTED;
297 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
299 nsChannel *This = NSCHANNEL_THIS(iface);
301 TRACE("(%p)\n", This);
304 return nsIChannel_Suspend(This->channel);
306 FIXME("default action not implemented\n");
307 return NS_ERROR_NOT_IMPLEMENTED;
310 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
312 nsChannel *This = NSCHANNEL_THIS(iface);
314 TRACE("(%p)\n", This);
317 return nsIChannel_Resume(This->channel);
319 FIXME("default action not implemented\n");
320 return NS_ERROR_NOT_IMPLEMENTED;
323 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
325 nsChannel *This = NSCHANNEL_THIS(iface);
327 TRACE("(%p)->(%p)\n", This, aLoadGroup);
330 nsILoadGroup_AddRef(This->load_group);
332 *aLoadGroup = This->load_group;
336 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
338 nsChannel *This = NSCHANNEL_THIS(iface);
340 TRACE("(%p)->(%p)\n", This, aLoadGroup);
343 nsILoadGroup_Release(This->load_group);
345 nsILoadGroup_AddRef(aLoadGroup);
347 This->load_group = aLoadGroup;
350 return nsIChannel_SetLoadGroup(This->channel, aLoadGroup);
354 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
356 nsChannel *This = NSCHANNEL_THIS(iface);
358 TRACE("(%p)->(%p)\n", This, aLoadFlags);
360 *aLoadFlags = This->load_flags;
364 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
366 nsChannel *This = NSCHANNEL_THIS(iface);
368 TRACE("(%p)->(%08lx)\n", This, aLoadFlags);
370 This->load_flags = aLoadFlags;
373 return nsIChannel_SetLoadFlags(This->channel, aLoadFlags);
377 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
379 nsChannel *This = NSCHANNEL_THIS(iface);
381 TRACE("(%p)->(%p)\n", This, aOriginalURI);
383 if(This->original_uri)
384 nsIURI_AddRef(This->original_uri);
386 *aOriginalURI = This->original_uri;
390 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
392 nsChannel *This = NSCHANNEL_THIS(iface);
394 TRACE("(%p)->(%p)\n", This, aOriginalURI);
396 if(This->original_uri)
397 nsIURI_Release(This->original_uri);
399 nsIURI_AddRef(aOriginalURI);
400 This->original_uri = aOriginalURI;
403 return nsIChannel_SetOriginalURI(This->channel, aOriginalURI);
407 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
409 nsChannel *This = NSCHANNEL_THIS(iface);
411 TRACE("(%p)->(%p)\n", This, aURI);
413 nsIWineURI_AddRef(This->uri);
414 *aURI = (nsIURI*)This->uri;
419 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
421 nsChannel *This = NSCHANNEL_THIS(iface);
423 TRACE("(%p)->(%p)\n", This, aOwner);
426 return nsIChannel_GetOwner(This->channel, aOwner);
428 FIXME("default action not implemented\n");
429 return NS_ERROR_NOT_IMPLEMENTED;
432 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
434 nsChannel *This = NSCHANNEL_THIS(iface);
436 TRACE("(%p)->(%p)\n", This, aOwner);
439 return nsIChannel_SetOwner(This->channel, aOwner);
441 FIXME("default action not implemented\n");
442 return NS_ERROR_NOT_IMPLEMENTED;
445 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
446 nsIInterfaceRequestor **aNotificationCallbacks)
448 nsChannel *This = NSCHANNEL_THIS(iface);
450 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
452 if(This->notif_callback)
453 nsIInterfaceRequestor_AddRef(This->notif_callback);
454 *aNotificationCallbacks = This->notif_callback;
459 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
460 nsIInterfaceRequestor *aNotificationCallbacks)
462 nsChannel *This = NSCHANNEL_THIS(iface);
464 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
466 if(This->notif_callback)
467 nsIInterfaceRequestor_Release(This->notif_callback);
468 if(aNotificationCallbacks)
469 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
471 This->notif_callback = aNotificationCallbacks;
474 return nsIChannel_SetNotificationCallbacks(This->channel, aNotificationCallbacks);
478 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
480 nsChannel *This = NSCHANNEL_THIS(iface);
481 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
482 return nsIChannel_GetSecurityInfo(This->channel, aSecurityInfo);
485 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
487 nsChannel *This = NSCHANNEL_THIS(iface);
489 TRACE("(%p)->(%p)\n", This, aContentType);
492 return nsIChannel_GetContentType(This->channel, aContentType);
494 FIXME("default action not implemented\n");
495 return NS_ERROR_NOT_IMPLEMENTED;
498 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
499 const nsACString *aContentType)
501 nsChannel *This = NSCHANNEL_THIS(iface);
503 TRACE("(%p)->(%p)\n", This, aContentType);
506 return nsIChannel_SetContentType(This->channel, aContentType);
508 FIXME("default action not implemented\n");
509 return NS_ERROR_NOT_IMPLEMENTED;
512 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
513 nsACString *aContentCharset)
515 nsChannel *This = NSCHANNEL_THIS(iface);
517 TRACE("(%p)->(%p)\n", This, aContentCharset);
520 return nsIChannel_GetContentCharset(This->channel, aContentCharset);
522 FIXME("default action not implemented\n");
523 return NS_ERROR_NOT_IMPLEMENTED;
526 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
527 const nsACString *aContentCharset)
529 nsChannel *This = NSCHANNEL_THIS(iface);
531 TRACE("(%p)->(%p)\n", This, aContentCharset);
534 return nsIChannel_SetContentCharset(This->channel, aContentCharset);
536 FIXME("default action not implemented\n");
537 return NS_ERROR_NOT_IMPLEMENTED;
540 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
542 nsChannel *This = NSCHANNEL_THIS(iface);
544 TRACE("(%p)->(%p)\n", This, aContentLength);
547 return nsIChannel_GetContentLength(This->channel, aContentLength);
549 FIXME("default action not implemented\n");
550 return NS_ERROR_NOT_IMPLEMENTED;
553 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
555 nsChannel *This = NSCHANNEL_THIS(iface);
557 TRACE("(%p)->(%ld)\n", This, aContentLength);
560 return nsIChannel_SetContentLength(This->channel, aContentLength);
562 FIXME("default action not implemented\n");
563 return NS_ERROR_NOT_IMPLEMENTED;
566 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
568 nsChannel *This = NSCHANNEL_THIS(iface);
570 TRACE("(%p)->(%p)\n", This, _retval);
573 return nsIChannel_Open(This->channel, _retval);
575 FIXME("default action not implemented\n");
576 return NS_ERROR_NOT_IMPLEMENTED;
579 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
580 nsISupports *aContext)
582 nsChannel *This = NSCHANNEL_THIS(iface);
585 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
587 if(!before_async_open(This)) {
589 return NS_ERROR_UNEXPECTED;
593 FIXME("channel == NULL\n");
594 return NS_ERROR_UNEXPECTED;
597 if(This->post_data_stream) {
598 nsIUploadChannel *upload_channel;
600 nsres = nsIChannel_QueryInterface(This->channel, &IID_nsIUploadChannel,
601 (void**)&upload_channel);
602 if(NS_SUCCEEDED(nsres)) {
603 nsACString *empty_string = nsACString_Create();
604 nsACString_SetData(empty_string, "");
606 nsres = nsIUploadChannel_SetUploadStream(upload_channel, This->post_data_stream,
609 WARN("SetUploadStream failed: %08lx\n", nsres);
613 return nsIChannel_AsyncOpen(This->channel, aListener, aContext);
616 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
618 nsChannel *This = NSCHANNEL_THIS(iface);
620 TRACE("(%p)->(%p)\n", This, aRequestMethod);
622 if(This->http_channel)
623 return nsIHttpChannel_GetRequestMethod(This->http_channel, aRequestMethod);
625 return NS_ERROR_NOT_IMPLEMENTED;
628 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
629 const nsACString *aRequestMethod)
631 nsChannel *This = NSCHANNEL_THIS(iface);
633 TRACE("(%p)->(%p)\n", This, aRequestMethod);
635 if(This->http_channel)
636 return nsIHttpChannel_SetRequestMethod(This->http_channel, aRequestMethod);
638 return NS_ERROR_NOT_IMPLEMENTED;
641 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
643 nsChannel *This = NSCHANNEL_THIS(iface);
645 TRACE("(%p)->(%p)\n", This, aReferrer);
647 if(This->http_channel)
648 return nsIHttpChannel_GetReferrer(This->http_channel, aReferrer);
650 return NS_ERROR_NOT_IMPLEMENTED;
653 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
655 nsChannel *This = NSCHANNEL_THIS(iface);
657 TRACE("(%p)->(%p)\n", This, aReferrer);
659 if(This->http_channel)
660 return nsIHttpChannel_SetReferrer(This->http_channel, aReferrer);
662 return NS_ERROR_NOT_IMPLEMENTED;
665 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
666 const nsACString *aHeader, nsACString *_retval)
668 nsChannel *This = NSCHANNEL_THIS(iface);
670 TRACE("(%p)->(%p %p)\n", This, aHeader, _retval);
672 if(This->http_channel)
673 return nsIHttpChannel_GetRequestHeader(This->http_channel, aHeader, _retval);
675 return NS_ERROR_NOT_IMPLEMENTED;
678 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
679 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
681 nsChannel *This = NSCHANNEL_THIS(iface);
683 TRACE("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
685 if(This->http_channel)
686 return nsIHttpChannel_SetRequestHeader(This->http_channel, aHeader, aValue, aMerge);
688 return NS_ERROR_NOT_IMPLEMENTED;
691 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
692 nsIHttpHeaderVisitor *aVisitor)
694 nsChannel *This = NSCHANNEL_THIS(iface);
696 TRACE("(%p)->(%p)\n", This, aVisitor);
698 if(This->http_channel)
699 return nsIHttpChannel_VisitRequestHeaders(This->http_channel, aVisitor);
701 return NS_ERROR_NOT_IMPLEMENTED;
704 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
706 nsChannel *This = NSCHANNEL_THIS(iface);
708 TRACE("(%p)->(%p)\n", This, aAllowPipelining);
710 if(This->http_channel)
711 return nsIHttpChannel_GetAllowPipelining(This->http_channel, aAllowPipelining);
713 return NS_ERROR_NOT_IMPLEMENTED;
716 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
718 nsChannel *This = NSCHANNEL_THIS(iface);
720 TRACE("(%p)->(%x)\n", This, aAllowPipelining);
722 if(This->http_channel)
723 return nsIHttpChannel_SetAllowPipelining(This->http_channel, aAllowPipelining);
725 return NS_ERROR_NOT_IMPLEMENTED;
728 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
730 nsChannel *This = NSCHANNEL_THIS(iface);
732 TRACE("(%p)->(%p)\n", This, aRedirectionLimit);
734 if(This->http_channel)
735 return nsIHttpChannel_GetRedirectionLimit(This->http_channel, aRedirectionLimit);
737 return NS_ERROR_NOT_IMPLEMENTED;
740 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
742 nsChannel *This = NSCHANNEL_THIS(iface);
744 TRACE("(%p)->(%lu)\n", This, aRedirectionLimit);
746 if(This->http_channel)
747 return nsIHttpChannel_SetRedirectionLimit(This->http_channel, aRedirectionLimit);
749 return NS_ERROR_NOT_IMPLEMENTED;
752 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
754 nsChannel *This = NSCHANNEL_THIS(iface);
756 TRACE("(%p)->(%p)\n", This, aResponseStatus);
758 if(This->http_channel)
759 return nsIHttpChannel_GetResponseStatus(This->http_channel, aResponseStatus);
761 return NS_ERROR_NOT_IMPLEMENTED;
764 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
765 nsACString *aResponseStatusText)
767 nsChannel *This = NSCHANNEL_THIS(iface);
769 TRACE("(%p)->(%p)\n", This, aResponseStatusText);
771 if(This->http_channel)
772 return nsIHttpChannel_GetResponseStatusText(This->http_channel, aResponseStatusText);
774 return NS_ERROR_NOT_IMPLEMENTED;
777 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
778 PRBool *aRequestSucceeded)
780 nsChannel *This = NSCHANNEL_THIS(iface);
782 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
784 if(This->http_channel)
785 return nsIHttpChannel_GetRequestSucceeded(This->http_channel, aRequestSucceeded);
787 return NS_ERROR_NOT_IMPLEMENTED;
790 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
791 const nsACString *header, nsACString *_retval)
793 nsChannel *This = NSCHANNEL_THIS(iface);
795 TRACE("(%p)->(%p %p)\n", This, header, _retval);
797 if(This->http_channel)
798 return nsIHttpChannel_GetResponseHeader(This->http_channel, header, _retval);
800 return NS_ERROR_NOT_IMPLEMENTED;
803 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
804 const nsACString *header, const nsACString *value, PRBool merge)
806 nsChannel *This = NSCHANNEL_THIS(iface);
808 TRACE("(%p)->(%p %p %x)\n", This, header, value, merge);
810 if(This->http_channel)
811 return nsIHttpChannel_SetResponseHeader(This->http_channel, header, value, merge);
813 return NS_ERROR_NOT_IMPLEMENTED;
816 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
817 nsIHttpHeaderVisitor *aVisitor)
819 nsChannel *This = NSCHANNEL_THIS(iface);
821 TRACE("(%p)->(%p)\n", This, aVisitor);
823 if(This->http_channel)
824 return nsIHttpChannel_VisitResponseHeaders(This->http_channel, aVisitor);
826 return NS_ERROR_NOT_IMPLEMENTED;
829 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
831 nsChannel *This = NSCHANNEL_THIS(iface);
833 TRACE("(%p)->(%p)\n", This, _retval);
835 if(This->http_channel)
836 return nsIHttpChannel_IsNoStoreResponse(This->http_channel, _retval);
838 return NS_ERROR_NOT_IMPLEMENTED;
841 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
843 nsChannel *This = NSCHANNEL_THIS(iface);
845 TRACE("(%p)->(%p)\n", This, _retval);
847 if(This->http_channel)
848 return nsIHttpChannel_IsNoCacheResponse(This->http_channel, _retval);
850 return NS_ERROR_NOT_IMPLEMENTED;
853 #undef NSCHANNEL_THIS
855 static const nsIHttpChannelVtbl nsChannelVtbl = {
856 nsChannel_QueryInterface,
865 nsChannel_GetLoadGroup,
866 nsChannel_SetLoadGroup,
867 nsChannel_GetLoadFlags,
868 nsChannel_SetLoadFlags,
869 nsChannel_GetOriginalURI,
870 nsChannel_SetOriginalURI,
874 nsChannel_GetNotificationCallbacks,
875 nsChannel_SetNotificationCallbacks,
876 nsChannel_GetSecurityInfo,
877 nsChannel_GetContentType,
878 nsChannel_SetContentType,
879 nsChannel_GetContentCharset,
880 nsChannel_SetContentCharset,
881 nsChannel_GetContentLength,
882 nsChannel_SetContentLength,
885 nsChannel_GetRequestMethod,
886 nsChannel_SetRequestMethod,
887 nsChannel_GetReferrer,
888 nsChannel_SetReferrer,
889 nsChannel_GetRequestHeader,
890 nsChannel_SetRequestHeader,
891 nsChannel_VisitRequestHeaders,
892 nsChannel_GetAllowPipelining,
893 nsChannel_SetAllowPipelining,
894 nsChannel_GetRedirectionLimit,
895 nsChannel_SetRedirectionLimit,
896 nsChannel_GetResponseStatus,
897 nsChannel_GetResponseStatusText,
898 nsChannel_GetRequestSucceeded,
899 nsChannel_GetResponseHeader,
900 nsChannel_SetResponseHeader,
901 nsChannel_VisitResponseHeaders,
902 nsChannel_IsNoStoreResponse,
903 nsChannel_IsNoCacheResponse
906 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
908 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
911 nsChannel *This = NSUPCHANNEL_THIS(iface);
912 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
915 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
917 nsChannel *This = NSUPCHANNEL_THIS(iface);
918 return nsIChannel_AddRef(NSCHANNEL(This));
921 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
923 nsChannel *This = NSUPCHANNEL_THIS(iface);
924 return nsIChannel_Release(NSCHANNEL(This));
927 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
928 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
930 nsChannel *This = NSUPCHANNEL_THIS(iface);
931 const char *content_type;
933 TRACE("(%p)->(%p %p %ld)\n", This, aStream, aContentType, aContentLength);
935 if(This->post_data_stream)
936 nsIInputStream_Release(This->post_data_stream);
939 nsACString_GetData(aContentType, &content_type, NULL);
941 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
944 if(aContentLength != -1)
945 FIXME("Unsupported acontentLength = %ld\n", aContentLength);
948 nsIInputStream_AddRef(aStream);
949 This->post_data_stream = aStream;
954 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
955 nsIInputStream **aUploadStream)
957 nsChannel *This = NSUPCHANNEL_THIS(iface);
959 TRACE("(%p)->(%p)\n", This, aUploadStream);
961 if(This->post_data_stream)
962 nsIInputStream_AddRef(This->post_data_stream);
964 *aUploadStream = This->post_data_stream;
968 #undef NSUPCHANNEL_THIS
970 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
971 nsUploadChannel_QueryInterface,
972 nsUploadChannel_AddRef,
973 nsUploadChannel_Release,
974 nsUploadChannel_SetUploadStream,
975 nsUploadChannel_GetUploadStream
978 #define NSURI_THIS(iface) DEFINE_THIS(nsURI, WineURI, iface)
980 static nsresult NSAPI nsURI_QueryInterface(nsIWineURI *iface, nsIIDRef riid, nsQIResult result)
982 nsURI *This = NSURI_THIS(iface);
986 if(IsEqualGUID(&IID_nsISupports, riid)) {
987 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
988 *result = NSURI(This);
989 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
990 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
991 *result = NSURI(This);
992 }else if(IsEqualGUID(&IID_nsIWineURI, riid)) {
993 TRACE("(%p)->(IID_nsIWineURI %p)\n", This, result);
994 *result = NSURI(This);
998 nsIURI_AddRef(NSURI(This));
1002 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1003 return nsIURI_QueryInterface(This->uri, riid, result);
1006 static nsrefcnt NSAPI nsURI_AddRef(nsIWineURI *iface)
1008 nsURI *This = NSURI_THIS(iface);
1009 LONG ref = InterlockedIncrement(&This->ref);
1011 TRACE("(%p) ref=%ld\n", This, ref);
1016 static nsrefcnt NSAPI nsURI_Release(nsIWineURI *iface)
1018 nsURI *This = NSURI_THIS(iface);
1019 LONG ref = InterlockedDecrement(&This->ref);
1021 TRACE("(%p) ref=%ld\n", This, ref);
1025 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1026 nsIURI_Release(This->uri);
1027 HeapFree(GetProcessHeap(), 0, This);
1033 static nsresult NSAPI nsURI_GetSpec(nsIWineURI *iface, nsACString *aSpec)
1035 nsURI *This = NSURI_THIS(iface);
1036 TRACE("(%p)->(%p)\n", This, aSpec);
1037 return nsIURI_GetSpec(This->uri, aSpec);
1040 static nsresult NSAPI nsURI_SetSpec(nsIWineURI *iface, const nsACString *aSpec)
1042 nsURI *This = NSURI_THIS(iface);
1043 TRACE("(%p)->(%p)\n", This, aSpec);
1044 return nsIURI_SetSpec(This->uri, aSpec);
1047 static nsresult NSAPI nsURI_GetPrePath(nsIWineURI *iface, nsACString *aPrePath)
1049 nsURI *This = NSURI_THIS(iface);
1050 TRACE("(%p)->(%p)\n", This, aPrePath);
1051 return nsIURI_GetPrePath(This->uri, aPrePath);
1054 static nsresult NSAPI nsURI_GetScheme(nsIWineURI *iface, nsACString *aScheme)
1056 nsURI *This = NSURI_THIS(iface);
1057 TRACE("(%p)->(%p)\n", This, aScheme);
1058 return nsIURI_GetScheme(This->uri, aScheme);
1061 static nsresult NSAPI nsURI_SetScheme(nsIWineURI *iface, const nsACString *aScheme)
1063 nsURI *This = NSURI_THIS(iface);
1064 TRACE("(%p)->(%p)\n", This, aScheme);
1065 return nsIURI_SetScheme(This->uri, aScheme);
1068 static nsresult NSAPI nsURI_GetUserPass(nsIWineURI *iface, nsACString *aUserPass)
1070 nsURI *This = NSURI_THIS(iface);
1071 TRACE("(%p)->(%p)\n", This, aUserPass);
1072 return nsIURI_GetUserPass(This->uri, aUserPass);
1075 static nsresult NSAPI nsURI_SetUserPass(nsIWineURI *iface, const nsACString *aUserPass)
1077 nsURI *This = NSURI_THIS(iface);
1078 TRACE("(%p)->(%p)\n", This, aUserPass);
1079 return nsIURI_SetUserPass(This->uri, aUserPass);
1082 static nsresult NSAPI nsURI_GetUsername(nsIWineURI *iface, nsACString *aUsername)
1084 nsURI *This = NSURI_THIS(iface);
1085 TRACE("(%p)->(%p)\n", This, aUsername);
1086 return nsIURI_GetUsername(This->uri, aUsername);
1089 static nsresult NSAPI nsURI_SetUsername(nsIWineURI *iface, const nsACString *aUsername)
1091 nsURI *This = NSURI_THIS(iface);
1092 TRACE("(%p)->(%p)\n", This, aUsername);
1093 return nsIURI_SetUsername(This->uri, aUsername);
1096 static nsresult NSAPI nsURI_GetPassword(nsIWineURI *iface, nsACString *aPassword)
1098 nsURI *This = NSURI_THIS(iface);
1099 TRACE("(%p)->(%p)\n", This, aPassword);
1100 return nsIURI_GetPassword(This->uri, aPassword);
1103 static nsresult NSAPI nsURI_SetPassword(nsIWineURI *iface, const nsACString *aPassword)
1105 nsURI *This = NSURI_THIS(iface);
1106 TRACE("(%p)->(%p)\n", This, aPassword);
1107 return nsIURI_SetPassword(This->uri, aPassword);
1110 static nsresult NSAPI nsURI_GetHostPort(nsIWineURI *iface, nsACString *aHostPort)
1112 nsURI *This = NSURI_THIS(iface);
1113 TRACE("(%p)->(%p)\n", This, aHostPort);
1114 return nsIURI_GetHostPort(This->uri, aHostPort);
1117 static nsresult NSAPI nsURI_SetHostPort(nsIWineURI *iface, const nsACString *aHostPort)
1119 nsURI *This = NSURI_THIS(iface);
1120 TRACE("(%p)->(%p)\n", This, aHostPort);
1121 return nsIURI_SetHostPort(This->uri, aHostPort);
1124 static nsresult NSAPI nsURI_GetHost(nsIWineURI *iface, nsACString *aHost)
1126 nsURI *This = NSURI_THIS(iface);
1127 TRACE("(%p)->(%p)\n", This, aHost);
1128 return nsIURI_GetHost(This->uri, aHost);
1131 static nsresult NSAPI nsURI_SetHost(nsIWineURI *iface, const nsACString *aHost)
1133 nsURI *This = NSURI_THIS(iface);
1134 TRACE("(%p)->(%p)\n", This, aHost);
1135 return nsIURI_SetHost(This->uri, aHost);
1138 static nsresult NSAPI nsURI_GetPort(nsIWineURI *iface, PRInt32 *aPort)
1140 nsURI *This = NSURI_THIS(iface);
1141 TRACE("(%p)->(%p)\n", This, aPort);
1142 return nsIURI_GetPort(This->uri, aPort);
1145 static nsresult NSAPI nsURI_SetPort(nsIWineURI *iface, PRInt32 aPort)
1147 nsURI *This = NSURI_THIS(iface);
1148 TRACE("(%p)->(%ld)\n", This, aPort);
1149 return nsIURI_SetPort(This->uri, aPort);
1152 static nsresult NSAPI nsURI_GetPath(nsIWineURI *iface, nsACString *aPath)
1154 nsURI *This = NSURI_THIS(iface);
1155 TRACE("(%p)->(%p)\n", This, aPath);
1156 return nsIURI_GetPath(This->uri, aPath);
1159 static nsresult NSAPI nsURI_SetPath(nsIWineURI *iface, const nsACString *aPath)
1161 nsURI *This = NSURI_THIS(iface);
1162 TRACE("(%p)->(%p)\n", This, aPath);
1163 return nsIURI_SetPath(This->uri, aPath);
1166 static nsresult NSAPI nsURI_Equals(nsIWineURI *iface, nsIURI *other, PRBool *_retval)
1168 nsURI *This = NSURI_THIS(iface);
1169 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1170 return nsIURI_Equals(This->uri, other, _retval);
1173 static nsresult NSAPI nsURI_SchemeIs(nsIWineURI *iface, const char *scheme, PRBool *_retval)
1175 nsURI *This = NSURI_THIS(iface);
1176 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1177 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1180 static nsresult NSAPI nsURI_Clone(nsIWineURI *iface, nsIURI **_retval)
1182 nsURI *This = NSURI_THIS(iface);
1183 TRACE("(%p)->(%p)\n", This, _retval);
1184 return nsIURI_Clone(This->uri, _retval);
1187 static nsresult NSAPI nsURI_Resolve(nsIWineURI *iface, const nsACString *arelativePath,
1188 nsACString *_retval)
1190 nsURI *This = NSURI_THIS(iface);
1191 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1192 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1195 static nsresult NSAPI nsURI_GetAsciiSpec(nsIWineURI *iface, nsACString *aAsciiSpec)
1197 nsURI *This = NSURI_THIS(iface);
1198 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1199 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1202 static nsresult NSAPI nsURI_GetAsciiHost(nsIWineURI *iface, nsACString *aAsciiHost)
1204 nsURI *This = NSURI_THIS(iface);
1205 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1206 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1209 static nsresult NSAPI nsURI_GetOriginCharset(nsIWineURI *iface, nsACString *aOriginCharset)
1211 nsURI *This = NSURI_THIS(iface);
1212 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1213 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1216 static nsresult NSAPI nsURI_GetNSContainer(nsIWineURI *iface, NSContainer **aContainer)
1218 nsURI *This = NSURI_THIS(iface);
1220 TRACE("(%p)->(%p)\n", This, aContainer);
1223 nsIWebBrowserChrome_AddRef(NSWBCHROME(This->container));
1224 *aContainer = This->container;
1229 static nsresult NSAPI nsURI_SetNSContainer(nsIWineURI *iface, NSContainer *aContainer)
1231 nsURI *This = NSURI_THIS(iface);
1233 TRACE("(%p)->(%p)\n", This, aContainer);
1235 if(This->container) {
1236 WARN("Container already set: %p\n", This->container);
1237 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1241 nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer));
1242 This->container = aContainer;
1249 static const nsIWineURIVtbl nsWineURIVtbl = {
1250 nsURI_QueryInterface,
1278 nsURI_GetOriginCharset,
1279 nsURI_GetNSContainer,
1280 nsURI_SetNSContainer,
1283 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
1288 if(IsEqualGUID(&IID_nsISupports, riid)) {
1289 TRACE("(IID_nsISupports %p)\n", result);
1291 }else if(IsEqualGUID(&IID_nsIIOService, riid)) {
1292 TRACE("(IID_nsIIOService %p)\n", result);
1297 nsIIOService_AddRef(iface);
1301 WARN("(%s %p)\n", debugstr_guid(riid), result);
1302 return NS_NOINTERFACE;
1305 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
1310 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
1315 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
1316 nsIProtocolHandler **_retval)
1318 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1319 return nsIIOService_GetProtocolHandler(nsio, aScheme, _retval);
1322 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
1325 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1326 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
1329 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
1330 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
1332 const char *spec = NULL;
1335 PRBool is_javascript = FALSE;
1338 nsACString_GetData(aSpec, &spec, NULL);
1340 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
1344 nsACString *base_uri_str = nsACString_Create();
1345 const char *base_uri = NULL;
1347 nsres = nsIURI_GetSpec(aBaseURI, base_uri_str);
1348 if(NS_SUCCEEDED(nsres)) {
1349 nsACString_GetData(base_uri_str, &base_uri, NULL);
1350 TRACE("uri=%s\n", debugstr_a(base_uri));
1352 ERR("GetSpec failed: %08lx\n", nsres);
1355 nsACString_Destroy(base_uri_str);
1358 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
1359 if(NS_FAILED(nsres)) {
1360 WARN("NewURI failed: %08lx\n", nsres);
1364 nsIURI_SchemeIs(uri, "javascript", &is_javascript);
1366 TRACE("returning javascript uri: %p\n", uri);
1371 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(nsURI));
1373 ret->lpWineURIVtbl = &nsWineURIVtbl;
1376 ret->container = NULL;
1378 TRACE("_retval = %p\n", ret);
1379 *_retval = NSURI(ret);
1383 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
1386 TRACE("(%p %p)\n", aFile, _retval);
1387 return nsIIOService_NewFileURI(nsio, aFile, _retval);
1390 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
1391 nsIChannel **_retval)
1393 nsIChannel *channel = NULL;
1395 nsIWineURI *wine_uri;
1398 TRACE("(%p %p)\n", aURI, _retval);
1400 nsres = nsIIOService_NewChannelFromURI(nsio, aURI, &channel);
1401 if(NS_FAILED(nsres) && nsres != NS_ERROR_UNKNOWN_PROTOCOL) {
1402 WARN("NewChannelFromURI failed: %08lx\n", nsres);
1407 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
1408 if(NS_FAILED(nsres)) {
1409 WARN("Could not get nsIWineURI: %08lx\n", nsres);
1414 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(nsChannel));
1416 ret->lpHttpChannelVtbl = &nsChannelVtbl;
1417 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
1419 ret->channel = channel;
1420 ret->http_channel = NULL;
1421 ret->uri = wine_uri;
1422 ret->post_data_stream = NULL;
1423 ret->load_group = NULL;
1424 ret->notif_callback = NULL;
1425 ret->load_flags = 0;
1427 nsIURI_AddRef(aURI);
1428 ret->original_uri = aURI;
1431 nsIChannel_QueryInterface(channel, &IID_nsIHttpChannel, (void**)&ret->http_channel);
1433 *_retval = NSCHANNEL(ret);
1437 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
1438 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
1440 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
1441 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
1444 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
1446 TRACE("(%p)\n", aOffline);
1447 return nsIIOService_GetOffline(nsio, aOffline);
1450 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
1452 TRACE("(%x)\n", aOffline);
1453 return nsIIOService_SetOffline(nsio, aOffline);
1456 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
1457 const char *aScheme, PRBool *_retval)
1459 TRACE("(%ld %s %p)\n", aPort, debugstr_a(aScheme), _retval);
1460 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
1463 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
1464 nsACString * _retval)
1466 TRACE("(%p %p)\n", urlString, _retval);
1467 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
1470 static const nsIIOServiceVtbl nsIOServiceVtbl = {
1471 nsIOService_QueryInterface,
1473 nsIOService_Release,
1474 nsIOService_GetProtocolHandler,
1475 nsIOService_GetProtocolFlags,
1477 nsIOService_NewFileURI,
1478 nsIOService_NewChannelFromURI,
1479 nsIOService_NewChannel,
1480 nsIOService_GetOffline,
1481 nsIOService_SetOffline,
1482 nsIOService_AllowPort,
1483 nsIOService_ExtractScheme
1486 static nsIIOService nsIOService = { &nsIOServiceVtbl };
1488 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
1493 if(IsEqualGUID(&IID_nsISupports, riid)) {
1494 TRACE("(IID_nsISupoprts %p)\n", result);
1496 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
1497 TRACE("(IID_nsIFactory %p)\n", result);
1502 nsIFactory_AddRef(iface);
1506 WARN("(%s %p)\n", debugstr_guid(riid), result);
1507 return NS_NOINTERFACE;
1510 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
1515 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
1520 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
1521 nsISupports *aOuter, const nsIID *iid, void **result)
1523 return nsIIOService_QueryInterface(&nsIOService, iid, result);
1526 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
1528 WARN("(%x)\n", lock);
1532 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
1533 nsIOServiceFactory_QueryInterface,
1534 nsIOServiceFactory_AddRef,
1535 nsIOServiceFactory_Release,
1536 nsIOServiceFactory_CreateInstance,
1537 nsIOServiceFactory_LockFactory
1540 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
1542 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
1544 nsIFactory *old_factory = NULL;
1547 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
1548 &IID_nsIFactory, (void**)&old_factory);
1549 if(NS_FAILED(nsres)) {
1550 ERR("Could not get factory: %08lx\n", nsres);
1551 nsIFactory_Release(old_factory);
1555 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
1556 if(NS_FAILED(nsres)) {
1557 ERR("Couldn not create nsIOService instance %08lx\n", nsres);
1558 nsIFactory_Release(old_factory);
1562 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
1563 nsIFactory_Release(old_factory);
1564 if(NS_FAILED(nsres))
1565 ERR("UnregisterFactory failed: %08lx\n", nsres);
1567 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
1568 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
1569 if(NS_FAILED(nsres))
1570 ERR("RegisterFactory failed: %08lx\n", nsres);
1573 nsIURI *get_nsIURI(LPCWSTR url)
1581 len = WideCharToMultiByte(CP_ACP, 0, url, -1, NULL, -1, NULL, NULL);
1582 urla = HeapAlloc(GetProcessHeap(), 0, len);
1583 WideCharToMultiByte(CP_ACP, 0, url, -1, urla, -1, NULL, NULL);
1585 acstr = nsACString_Create();
1586 nsACString_SetData(acstr, urla);
1588 nsres = nsIIOService_NewURI(nsio, acstr, NULL, NULL, &ret);
1589 if(NS_FAILED(nsres))
1590 FIXME("NewURI failed: %08lx\n", nsres);
1592 nsACString_Destroy(acstr);
1593 HeapFree(GetProcessHeap(), 0, urla);