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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 const IID NS_IOSERVICE_CID =
44 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
46 static nsIIOService *nsio = NULL;
49 const nsIWineURIVtbl *lpWineURIVtbl;
54 NSContainer *container;
57 #define NSURI(x) ((nsIURI*) &(x)->lpWineURIVtbl)
59 static nsresult create_uri(nsIURI*,NSContainer*,nsIURI**);
61 static BOOL exec_shldocvw_67(HTMLDocument *doc, LPCWSTR url)
63 IOleCommandTarget *cmdtrg = NULL;
66 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget,
69 VARIANT varUrl, varRes;
71 V_VT(&varUrl) = VT_BSTR;
72 V_BSTR(&varUrl) = SysAllocString(url);
73 V_VT(&varRes) = VT_BOOL;
75 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
77 IOleCommandTarget_Release(cmdtrg);
78 SysFreeString(V_BSTR(&varUrl));
80 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
81 TRACE("got VARIANT_FALSE, do not load\n");
89 static BOOL handle_uri(NSContainer *container, nsChannel *channel, LPCWSTR uri)
91 IServiceProvider *service_provider;
92 HTMLDocument *doc = container->doc;
97 NSContainer *container_iter = container;
99 hlnf = HLNF_OPENINNEWWINDOW;
100 while(!container_iter->doc)
101 container_iter = container_iter->parent;
102 doc = container_iter->doc;
105 if(!hlnf && !exec_shldocvw_67(doc, uri))
108 hres = IOleClientSite_QueryInterface(doc->client, &IID_IServiceProvider,
109 (void**)&service_provider);
110 if(SUCCEEDED(hres)) {
111 IHlinkFrame *hlink_frame;
113 hres = IServiceProvider_QueryService(service_provider, &IID_IHlinkFrame,
114 &IID_IHlinkFrame, (void**)&hlink_frame);
115 IServiceProvider_Release(service_provider);
116 if(SUCCEEDED(hres)) {
117 hlink_frame_navigate(doc, hlink_frame, uri, channel->post_data_stream, hlnf);
118 IHlinkFrame_Release(hlink_frame);
127 static BOOL before_async_open(nsChannel *channel, NSContainer *container)
135 nsACString_Init(&uri_str, NULL);
136 nsIWineURI_GetSpec(channel->uri, &uri_str);
137 nsACString_GetData(&uri_str, &uria, NULL);
138 len = MultiByteToWideChar(CP_ACP, 0, uria, -1, NULL, 0);
139 uri = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
140 MultiByteToWideChar(CP_ACP, 0, uria, -1, uri, len);
141 nsACString_Finish(&uri_str);
143 ret = handle_uri(container, channel, uri);
145 HeapFree(GetProcessHeap(), 0, uri);
150 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
152 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
154 nsChannel *This = NSCHANNEL_THIS(iface);
158 if(IsEqualGUID(&IID_nsISupports, riid)) {
159 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
160 *result = NSCHANNEL(This);
161 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
162 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
163 *result = NSCHANNEL(This);
164 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
165 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
166 *result = NSCHANNEL(This);
167 }else if(This->http_channel && IsEqualGUID(&IID_nsIHttpChannel, riid)) {
168 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
169 *result = NSHTTPCHANNEL(This);
170 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
171 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
172 *result = NSUPCHANNEL(This);
176 nsIChannel_AddRef(NSCHANNEL(This));
180 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
183 return nsIChannel_QueryInterface(This->channel, riid, result);
184 return NS_NOINTERFACE;
187 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
189 nsChannel *This = NSCHANNEL_THIS(iface);
190 nsrefcnt ref = InterlockedIncrement(&This->ref);
192 TRACE("(%p) ref=%ld\n", This, ref);
197 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
199 nsChannel *This = NSCHANNEL_THIS(iface);
200 LONG ref = InterlockedDecrement(&This->ref);
203 nsIWineURI_Release(This->uri);
205 nsIChannel_Release(This->channel);
206 if(This->http_channel)
207 nsIHttpChannel_Release(This->http_channel);
208 if(This->post_data_stream)
209 nsIInputStream_Release(This->post_data_stream);
211 nsILoadGroup_Release(This->load_group);
212 if(This->notif_callback)
213 nsIInterfaceRequestor_Release(This->notif_callback);
214 if(This->original_uri)
215 nsIURI_Release(This->original_uri);
216 HeapFree(GetProcessHeap(), 0, This);
222 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
224 nsChannel *This = NSCHANNEL_THIS(iface);
226 TRACE("(%p)->(%p)\n", This, aName);
229 return nsIChannel_GetName(This->channel, aName);
231 FIXME("default action not implemented\n");
232 return NS_ERROR_NOT_IMPLEMENTED;
235 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
237 nsChannel *This = NSCHANNEL_THIS(iface);
239 TRACE("(%p)->(%p)\n", This, _retval);
242 return nsIChannel_IsPending(This->channel, _retval);
244 FIXME("default action not implemented\n");
245 return NS_ERROR_NOT_IMPLEMENTED;
248 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
250 nsChannel *This = NSCHANNEL_THIS(iface);
252 TRACE("(%p)->(%p)\n", This, aStatus);
255 return nsIChannel_GetStatus(This->channel, aStatus);
257 FIXME("default action not implemented\n");
258 return NS_ERROR_NOT_IMPLEMENTED;
261 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
263 nsChannel *This = NSCHANNEL_THIS(iface);
265 TRACE("(%p)->(%08lx)\n", This, aStatus);
268 return nsIChannel_Cancel(This->channel, aStatus);
270 FIXME("default action not implemented\n");
271 return NS_ERROR_NOT_IMPLEMENTED;
274 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
276 nsChannel *This = NSCHANNEL_THIS(iface);
278 TRACE("(%p)\n", This);
281 return nsIChannel_Suspend(This->channel);
283 FIXME("default action not implemented\n");
284 return NS_ERROR_NOT_IMPLEMENTED;
287 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
289 nsChannel *This = NSCHANNEL_THIS(iface);
291 TRACE("(%p)\n", This);
294 return nsIChannel_Resume(This->channel);
296 FIXME("default action not implemented\n");
297 return NS_ERROR_NOT_IMPLEMENTED;
300 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
302 nsChannel *This = NSCHANNEL_THIS(iface);
304 TRACE("(%p)->(%p)\n", This, aLoadGroup);
307 nsILoadGroup_AddRef(This->load_group);
309 *aLoadGroup = This->load_group;
313 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
315 nsChannel *This = NSCHANNEL_THIS(iface);
317 TRACE("(%p)->(%p)\n", This, aLoadGroup);
320 nsILoadGroup_Release(This->load_group);
322 nsILoadGroup_AddRef(aLoadGroup);
324 This->load_group = aLoadGroup;
327 return nsIChannel_SetLoadGroup(This->channel, aLoadGroup);
331 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
333 nsChannel *This = NSCHANNEL_THIS(iface);
335 TRACE("(%p)->(%p)\n", This, aLoadFlags);
337 *aLoadFlags = This->load_flags;
341 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
343 nsChannel *This = NSCHANNEL_THIS(iface);
345 TRACE("(%p)->(%08lx)\n", This, aLoadFlags);
347 This->load_flags = aLoadFlags;
350 return nsIChannel_SetLoadFlags(This->channel, aLoadFlags);
354 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
356 nsChannel *This = NSCHANNEL_THIS(iface);
358 TRACE("(%p)->(%p)\n", This, aOriginalURI);
360 if(This->original_uri)
361 nsIURI_AddRef(This->original_uri);
363 *aOriginalURI = This->original_uri;
367 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
369 nsChannel *This = NSCHANNEL_THIS(iface);
371 TRACE("(%p)->(%p)\n", This, aOriginalURI);
373 if(This->original_uri)
374 nsIURI_Release(This->original_uri);
376 nsIURI_AddRef(aOriginalURI);
377 This->original_uri = aOriginalURI;
380 return nsIChannel_SetOriginalURI(This->channel, aOriginalURI);
384 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
386 nsChannel *This = NSCHANNEL_THIS(iface);
388 TRACE("(%p)->(%p)\n", This, aURI);
390 nsIWineURI_AddRef(This->uri);
391 *aURI = (nsIURI*)This->uri;
396 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
398 nsChannel *This = NSCHANNEL_THIS(iface);
400 TRACE("(%p)->(%p)\n", This, aOwner);
403 return nsIChannel_GetOwner(This->channel, aOwner);
405 FIXME("default action not implemented\n");
406 return NS_ERROR_NOT_IMPLEMENTED;
409 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
411 nsChannel *This = NSCHANNEL_THIS(iface);
413 TRACE("(%p)->(%p)\n", This, aOwner);
416 return nsIChannel_SetOwner(This->channel, aOwner);
418 FIXME("default action not implemented\n");
419 return NS_ERROR_NOT_IMPLEMENTED;
422 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
423 nsIInterfaceRequestor **aNotificationCallbacks)
425 nsChannel *This = NSCHANNEL_THIS(iface);
427 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
429 if(This->notif_callback)
430 nsIInterfaceRequestor_AddRef(This->notif_callback);
431 *aNotificationCallbacks = This->notif_callback;
436 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
437 nsIInterfaceRequestor *aNotificationCallbacks)
439 nsChannel *This = NSCHANNEL_THIS(iface);
441 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
443 if(This->notif_callback)
444 nsIInterfaceRequestor_Release(This->notif_callback);
445 if(aNotificationCallbacks)
446 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
448 This->notif_callback = aNotificationCallbacks;
451 return nsIChannel_SetNotificationCallbacks(This->channel, aNotificationCallbacks);
455 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
457 nsChannel *This = NSCHANNEL_THIS(iface);
458 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
459 return nsIChannel_GetSecurityInfo(This->channel, aSecurityInfo);
462 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
464 nsChannel *This = NSCHANNEL_THIS(iface);
466 TRACE("(%p)->(%p)\n", This, aContentType);
469 return nsIChannel_GetContentType(This->channel, aContentType);
471 FIXME("default action not implemented\n");
472 return NS_ERROR_NOT_IMPLEMENTED;
475 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
476 const nsACString *aContentType)
478 nsChannel *This = NSCHANNEL_THIS(iface);
480 TRACE("(%p)->(%p)\n", This, aContentType);
483 return nsIChannel_SetContentType(This->channel, aContentType);
485 FIXME("default action not implemented\n");
486 return NS_ERROR_NOT_IMPLEMENTED;
489 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
490 nsACString *aContentCharset)
492 nsChannel *This = NSCHANNEL_THIS(iface);
494 TRACE("(%p)->(%p)\n", This, aContentCharset);
497 return nsIChannel_GetContentCharset(This->channel, aContentCharset);
499 FIXME("default action not implemented\n");
500 return NS_ERROR_NOT_IMPLEMENTED;
503 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
504 const nsACString *aContentCharset)
506 nsChannel *This = NSCHANNEL_THIS(iface);
508 TRACE("(%p)->(%p)\n", This, aContentCharset);
511 return nsIChannel_SetContentCharset(This->channel, aContentCharset);
513 FIXME("default action not implemented\n");
514 return NS_ERROR_NOT_IMPLEMENTED;
517 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
519 nsChannel *This = NSCHANNEL_THIS(iface);
521 TRACE("(%p)->(%p)\n", This, aContentLength);
524 return nsIChannel_GetContentLength(This->channel, aContentLength);
526 FIXME("default action not implemented\n");
527 return NS_ERROR_NOT_IMPLEMENTED;
530 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
532 nsChannel *This = NSCHANNEL_THIS(iface);
534 TRACE("(%p)->(%ld)\n", This, aContentLength);
537 return nsIChannel_SetContentLength(This->channel, aContentLength);
539 FIXME("default action not implemented\n");
540 return NS_ERROR_NOT_IMPLEMENTED;
543 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
545 nsChannel *This = NSCHANNEL_THIS(iface);
547 TRACE("(%p)->(%p)\n", This, _retval);
550 return nsIChannel_Open(This->channel, _retval);
552 FIXME("default action not implemented\n");
553 return NS_ERROR_NOT_IMPLEMENTED;
556 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
557 nsISupports *aContext)
559 nsChannel *This = NSCHANNEL_THIS(iface);
562 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
564 if(This->load_flags & LOAD_INITIAL_DOCUMENT_URI) {
565 NSContainer *container;
567 nsIWineURI_GetNSContainer(This->uri, &container);
569 ERR("container = NULL\n");
570 return NS_ERROR_UNEXPECTED;
573 if(container->bscallback) {
574 nsIChannel_AddRef(NSCHANNEL(This));
575 container->bscallback->nschannel = This;
577 nsIStreamListener_AddRef(aListener);
578 container->bscallback->nslistener = aListener;
581 nsISupports_AddRef(aContext);
582 container->bscallback->nscontext = aContext;
585 nsIWebBrowserChrome_Release(NSWBCHROME(container));
587 BOOL cont = before_async_open(This, container);
588 nsIWebBrowserChrome_Release(NSWBCHROME(container));
592 return NS_ERROR_UNEXPECTED;
598 FIXME("channel == NULL\n");
599 return NS_ERROR_UNEXPECTED;
602 if(This->post_data_stream) {
603 nsIUploadChannel *upload_channel;
605 nsres = nsIChannel_QueryInterface(This->channel, &IID_nsIUploadChannel,
606 (void**)&upload_channel);
607 if(NS_SUCCEEDED(nsres)) {
608 nsACString empty_string;
609 nsACString_Init(&empty_string, "");
611 nsres = nsIUploadChannel_SetUploadStream(upload_channel, This->post_data_stream,
613 nsIUploadChannel_Release(upload_channel);
615 WARN("SetUploadStream failed: %08lx\n", nsres);
617 nsACString_Finish(&empty_string);
621 return nsIChannel_AsyncOpen(This->channel, aListener, aContext);
624 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
626 nsChannel *This = NSCHANNEL_THIS(iface);
628 TRACE("(%p)->(%p)\n", This, aRequestMethod);
630 if(This->http_channel)
631 return nsIHttpChannel_GetRequestMethod(This->http_channel, aRequestMethod);
633 return NS_ERROR_NOT_IMPLEMENTED;
636 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
637 const nsACString *aRequestMethod)
639 nsChannel *This = NSCHANNEL_THIS(iface);
641 TRACE("(%p)->(%p)\n", This, aRequestMethod);
643 if(This->http_channel)
644 return nsIHttpChannel_SetRequestMethod(This->http_channel, aRequestMethod);
646 return NS_ERROR_NOT_IMPLEMENTED;
649 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
651 nsChannel *This = NSCHANNEL_THIS(iface);
653 TRACE("(%p)->(%p)\n", This, aReferrer);
655 if(This->http_channel)
656 return nsIHttpChannel_GetReferrer(This->http_channel, aReferrer);
658 return NS_ERROR_NOT_IMPLEMENTED;
661 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
663 nsChannel *This = NSCHANNEL_THIS(iface);
665 TRACE("(%p)->(%p)\n", This, aReferrer);
667 if(This->http_channel)
668 return nsIHttpChannel_SetReferrer(This->http_channel, aReferrer);
670 return NS_ERROR_NOT_IMPLEMENTED;
673 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
674 const nsACString *aHeader, nsACString *_retval)
676 nsChannel *This = NSCHANNEL_THIS(iface);
678 TRACE("(%p)->(%p %p)\n", This, aHeader, _retval);
680 if(This->http_channel)
681 return nsIHttpChannel_GetRequestHeader(This->http_channel, aHeader, _retval);
683 return NS_ERROR_NOT_IMPLEMENTED;
686 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
687 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
689 nsChannel *This = NSCHANNEL_THIS(iface);
691 TRACE("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
693 if(This->http_channel)
694 return nsIHttpChannel_SetRequestHeader(This->http_channel, aHeader, aValue, aMerge);
696 return NS_ERROR_NOT_IMPLEMENTED;
699 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
700 nsIHttpHeaderVisitor *aVisitor)
702 nsChannel *This = NSCHANNEL_THIS(iface);
704 TRACE("(%p)->(%p)\n", This, aVisitor);
706 if(This->http_channel)
707 return nsIHttpChannel_VisitRequestHeaders(This->http_channel, aVisitor);
709 return NS_ERROR_NOT_IMPLEMENTED;
712 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
714 nsChannel *This = NSCHANNEL_THIS(iface);
716 TRACE("(%p)->(%p)\n", This, aAllowPipelining);
718 if(This->http_channel)
719 return nsIHttpChannel_GetAllowPipelining(This->http_channel, aAllowPipelining);
721 return NS_ERROR_NOT_IMPLEMENTED;
724 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
726 nsChannel *This = NSCHANNEL_THIS(iface);
728 TRACE("(%p)->(%x)\n", This, aAllowPipelining);
730 if(This->http_channel)
731 return nsIHttpChannel_SetAllowPipelining(This->http_channel, aAllowPipelining);
733 return NS_ERROR_NOT_IMPLEMENTED;
736 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
738 nsChannel *This = NSCHANNEL_THIS(iface);
740 TRACE("(%p)->(%p)\n", This, aRedirectionLimit);
742 if(This->http_channel)
743 return nsIHttpChannel_GetRedirectionLimit(This->http_channel, aRedirectionLimit);
745 return NS_ERROR_NOT_IMPLEMENTED;
748 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
750 nsChannel *This = NSCHANNEL_THIS(iface);
752 TRACE("(%p)->(%lu)\n", This, aRedirectionLimit);
754 if(This->http_channel)
755 return nsIHttpChannel_SetRedirectionLimit(This->http_channel, aRedirectionLimit);
757 return NS_ERROR_NOT_IMPLEMENTED;
760 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
762 nsChannel *This = NSCHANNEL_THIS(iface);
764 TRACE("(%p)->(%p)\n", This, aResponseStatus);
766 if(This->http_channel)
767 return nsIHttpChannel_GetResponseStatus(This->http_channel, aResponseStatus);
769 return NS_ERROR_NOT_IMPLEMENTED;
772 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
773 nsACString *aResponseStatusText)
775 nsChannel *This = NSCHANNEL_THIS(iface);
777 TRACE("(%p)->(%p)\n", This, aResponseStatusText);
779 if(This->http_channel)
780 return nsIHttpChannel_GetResponseStatusText(This->http_channel, aResponseStatusText);
782 return NS_ERROR_NOT_IMPLEMENTED;
785 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
786 PRBool *aRequestSucceeded)
788 nsChannel *This = NSCHANNEL_THIS(iface);
790 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
792 if(This->http_channel)
793 return nsIHttpChannel_GetRequestSucceeded(This->http_channel, aRequestSucceeded);
795 return NS_ERROR_NOT_IMPLEMENTED;
798 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
799 const nsACString *header, nsACString *_retval)
801 nsChannel *This = NSCHANNEL_THIS(iface);
803 TRACE("(%p)->(%p %p)\n", This, header, _retval);
805 if(This->http_channel)
806 return nsIHttpChannel_GetResponseHeader(This->http_channel, header, _retval);
808 return NS_ERROR_NOT_IMPLEMENTED;
811 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
812 const nsACString *header, const nsACString *value, PRBool merge)
814 nsChannel *This = NSCHANNEL_THIS(iface);
816 TRACE("(%p)->(%p %p %x)\n", This, header, value, merge);
818 if(This->http_channel)
819 return nsIHttpChannel_SetResponseHeader(This->http_channel, header, value, merge);
821 return NS_ERROR_NOT_IMPLEMENTED;
824 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
825 nsIHttpHeaderVisitor *aVisitor)
827 nsChannel *This = NSCHANNEL_THIS(iface);
829 TRACE("(%p)->(%p)\n", This, aVisitor);
831 if(This->http_channel)
832 return nsIHttpChannel_VisitResponseHeaders(This->http_channel, aVisitor);
834 return NS_ERROR_NOT_IMPLEMENTED;
837 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
839 nsChannel *This = NSCHANNEL_THIS(iface);
841 TRACE("(%p)->(%p)\n", This, _retval);
843 if(This->http_channel)
844 return nsIHttpChannel_IsNoStoreResponse(This->http_channel, _retval);
846 return NS_ERROR_NOT_IMPLEMENTED;
849 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
851 nsChannel *This = NSCHANNEL_THIS(iface);
853 TRACE("(%p)->(%p)\n", This, _retval);
855 if(This->http_channel)
856 return nsIHttpChannel_IsNoCacheResponse(This->http_channel, _retval);
858 return NS_ERROR_NOT_IMPLEMENTED;
861 #undef NSCHANNEL_THIS
863 static const nsIHttpChannelVtbl nsChannelVtbl = {
864 nsChannel_QueryInterface,
873 nsChannel_GetLoadGroup,
874 nsChannel_SetLoadGroup,
875 nsChannel_GetLoadFlags,
876 nsChannel_SetLoadFlags,
877 nsChannel_GetOriginalURI,
878 nsChannel_SetOriginalURI,
882 nsChannel_GetNotificationCallbacks,
883 nsChannel_SetNotificationCallbacks,
884 nsChannel_GetSecurityInfo,
885 nsChannel_GetContentType,
886 nsChannel_SetContentType,
887 nsChannel_GetContentCharset,
888 nsChannel_SetContentCharset,
889 nsChannel_GetContentLength,
890 nsChannel_SetContentLength,
893 nsChannel_GetRequestMethod,
894 nsChannel_SetRequestMethod,
895 nsChannel_GetReferrer,
896 nsChannel_SetReferrer,
897 nsChannel_GetRequestHeader,
898 nsChannel_SetRequestHeader,
899 nsChannel_VisitRequestHeaders,
900 nsChannel_GetAllowPipelining,
901 nsChannel_SetAllowPipelining,
902 nsChannel_GetRedirectionLimit,
903 nsChannel_SetRedirectionLimit,
904 nsChannel_GetResponseStatus,
905 nsChannel_GetResponseStatusText,
906 nsChannel_GetRequestSucceeded,
907 nsChannel_GetResponseHeader,
908 nsChannel_SetResponseHeader,
909 nsChannel_VisitResponseHeaders,
910 nsChannel_IsNoStoreResponse,
911 nsChannel_IsNoCacheResponse
914 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
916 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
919 nsChannel *This = NSUPCHANNEL_THIS(iface);
920 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
923 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
925 nsChannel *This = NSUPCHANNEL_THIS(iface);
926 return nsIChannel_AddRef(NSCHANNEL(This));
929 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
931 nsChannel *This = NSUPCHANNEL_THIS(iface);
932 return nsIChannel_Release(NSCHANNEL(This));
935 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
936 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
938 nsChannel *This = NSUPCHANNEL_THIS(iface);
939 const char *content_type;
941 TRACE("(%p)->(%p %p %ld)\n", This, aStream, aContentType, aContentLength);
943 if(This->post_data_stream)
944 nsIInputStream_Release(This->post_data_stream);
947 nsACString_GetData(aContentType, &content_type, NULL);
949 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
952 if(aContentLength != -1)
953 FIXME("Unsupported acontentLength = %ld\n", aContentLength);
956 nsIInputStream_AddRef(aStream);
957 This->post_data_stream = aStream;
962 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
963 nsIInputStream **aUploadStream)
965 nsChannel *This = NSUPCHANNEL_THIS(iface);
967 TRACE("(%p)->(%p)\n", This, aUploadStream);
969 if(This->post_data_stream)
970 nsIInputStream_AddRef(This->post_data_stream);
972 *aUploadStream = This->post_data_stream;
976 #undef NSUPCHANNEL_THIS
978 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
979 nsUploadChannel_QueryInterface,
980 nsUploadChannel_AddRef,
981 nsUploadChannel_Release,
982 nsUploadChannel_SetUploadStream,
983 nsUploadChannel_GetUploadStream
986 #define NSURI_THIS(iface) DEFINE_THIS(nsURI, WineURI, iface)
988 static nsresult NSAPI nsURI_QueryInterface(nsIWineURI *iface, nsIIDRef riid, nsQIResult result)
990 nsURI *This = NSURI_THIS(iface);
994 if(IsEqualGUID(&IID_nsISupports, riid)) {
995 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
996 *result = NSURI(This);
997 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
998 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
999 *result = NSURI(This);
1000 }else if(IsEqualGUID(&IID_nsIWineURI, riid)) {
1001 TRACE("(%p)->(IID_nsIWineURI %p)\n", This, result);
1002 *result = NSURI(This);
1006 nsIURI_AddRef(NSURI(This));
1010 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1011 return nsIURI_QueryInterface(This->uri, riid, result);
1014 static nsrefcnt NSAPI nsURI_AddRef(nsIWineURI *iface)
1016 nsURI *This = NSURI_THIS(iface);
1017 LONG ref = InterlockedIncrement(&This->ref);
1019 TRACE("(%p) ref=%ld\n", This, ref);
1024 static nsrefcnt NSAPI nsURI_Release(nsIWineURI *iface)
1026 nsURI *This = NSURI_THIS(iface);
1027 LONG ref = InterlockedDecrement(&This->ref);
1029 TRACE("(%p) ref=%ld\n", This, ref);
1033 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1034 nsIURI_Release(This->uri);
1035 HeapFree(GetProcessHeap(), 0, This);
1041 static nsresult NSAPI nsURI_GetSpec(nsIWineURI *iface, nsACString *aSpec)
1043 nsURI *This = NSURI_THIS(iface);
1044 TRACE("(%p)->(%p)\n", This, aSpec);
1045 return nsIURI_GetSpec(This->uri, aSpec);
1048 static nsresult NSAPI nsURI_SetSpec(nsIWineURI *iface, const nsACString *aSpec)
1050 nsURI *This = NSURI_THIS(iface);
1051 TRACE("(%p)->(%p)\n", This, aSpec);
1052 return nsIURI_SetSpec(This->uri, aSpec);
1055 static nsresult NSAPI nsURI_GetPrePath(nsIWineURI *iface, nsACString *aPrePath)
1057 nsURI *This = NSURI_THIS(iface);
1058 TRACE("(%p)->(%p)\n", This, aPrePath);
1059 return nsIURI_GetPrePath(This->uri, aPrePath);
1062 static nsresult NSAPI nsURI_GetScheme(nsIWineURI *iface, nsACString *aScheme)
1064 nsURI *This = NSURI_THIS(iface);
1065 TRACE("(%p)->(%p)\n", This, aScheme);
1066 return nsIURI_GetScheme(This->uri, aScheme);
1069 static nsresult NSAPI nsURI_SetScheme(nsIWineURI *iface, const nsACString *aScheme)
1071 nsURI *This = NSURI_THIS(iface);
1072 TRACE("(%p)->(%p)\n", This, aScheme);
1073 return nsIURI_SetScheme(This->uri, aScheme);
1076 static nsresult NSAPI nsURI_GetUserPass(nsIWineURI *iface, nsACString *aUserPass)
1078 nsURI *This = NSURI_THIS(iface);
1079 TRACE("(%p)->(%p)\n", This, aUserPass);
1080 return nsIURI_GetUserPass(This->uri, aUserPass);
1083 static nsresult NSAPI nsURI_SetUserPass(nsIWineURI *iface, const nsACString *aUserPass)
1085 nsURI *This = NSURI_THIS(iface);
1086 TRACE("(%p)->(%p)\n", This, aUserPass);
1087 return nsIURI_SetUserPass(This->uri, aUserPass);
1090 static nsresult NSAPI nsURI_GetUsername(nsIWineURI *iface, nsACString *aUsername)
1092 nsURI *This = NSURI_THIS(iface);
1093 TRACE("(%p)->(%p)\n", This, aUsername);
1094 return nsIURI_GetUsername(This->uri, aUsername);
1097 static nsresult NSAPI nsURI_SetUsername(nsIWineURI *iface, const nsACString *aUsername)
1099 nsURI *This = NSURI_THIS(iface);
1100 TRACE("(%p)->(%p)\n", This, aUsername);
1101 return nsIURI_SetUsername(This->uri, aUsername);
1104 static nsresult NSAPI nsURI_GetPassword(nsIWineURI *iface, nsACString *aPassword)
1106 nsURI *This = NSURI_THIS(iface);
1107 TRACE("(%p)->(%p)\n", This, aPassword);
1108 return nsIURI_GetPassword(This->uri, aPassword);
1111 static nsresult NSAPI nsURI_SetPassword(nsIWineURI *iface, const nsACString *aPassword)
1113 nsURI *This = NSURI_THIS(iface);
1114 TRACE("(%p)->(%p)\n", This, aPassword);
1115 return nsIURI_SetPassword(This->uri, aPassword);
1118 static nsresult NSAPI nsURI_GetHostPort(nsIWineURI *iface, nsACString *aHostPort)
1120 nsURI *This = NSURI_THIS(iface);
1121 TRACE("(%p)->(%p)\n", This, aHostPort);
1122 return nsIURI_GetHostPort(This->uri, aHostPort);
1125 static nsresult NSAPI nsURI_SetHostPort(nsIWineURI *iface, const nsACString *aHostPort)
1127 nsURI *This = NSURI_THIS(iface);
1128 TRACE("(%p)->(%p)\n", This, aHostPort);
1129 return nsIURI_SetHostPort(This->uri, aHostPort);
1132 static nsresult NSAPI nsURI_GetHost(nsIWineURI *iface, nsACString *aHost)
1134 nsURI *This = NSURI_THIS(iface);
1135 TRACE("(%p)->(%p)\n", This, aHost);
1136 return nsIURI_GetHost(This->uri, aHost);
1139 static nsresult NSAPI nsURI_SetHost(nsIWineURI *iface, const nsACString *aHost)
1141 nsURI *This = NSURI_THIS(iface);
1142 TRACE("(%p)->(%p)\n", This, aHost);
1143 return nsIURI_SetHost(This->uri, aHost);
1146 static nsresult NSAPI nsURI_GetPort(nsIWineURI *iface, PRInt32 *aPort)
1148 nsURI *This = NSURI_THIS(iface);
1149 TRACE("(%p)->(%p)\n", This, aPort);
1150 return nsIURI_GetPort(This->uri, aPort);
1153 static nsresult NSAPI nsURI_SetPort(nsIWineURI *iface, PRInt32 aPort)
1155 nsURI *This = NSURI_THIS(iface);
1156 TRACE("(%p)->(%ld)\n", This, aPort);
1157 return nsIURI_SetPort(This->uri, aPort);
1160 static nsresult NSAPI nsURI_GetPath(nsIWineURI *iface, nsACString *aPath)
1162 nsURI *This = NSURI_THIS(iface);
1163 TRACE("(%p)->(%p)\n", This, aPath);
1164 return nsIURI_GetPath(This->uri, aPath);
1167 static nsresult NSAPI nsURI_SetPath(nsIWineURI *iface, const nsACString *aPath)
1169 nsURI *This = NSURI_THIS(iface);
1170 TRACE("(%p)->(%p)\n", This, aPath);
1171 return nsIURI_SetPath(This->uri, aPath);
1174 static nsresult NSAPI nsURI_Equals(nsIWineURI *iface, nsIURI *other, PRBool *_retval)
1176 nsURI *This = NSURI_THIS(iface);
1177 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1178 return nsIURI_Equals(This->uri, other, _retval);
1181 static nsresult NSAPI nsURI_SchemeIs(nsIWineURI *iface, const char *scheme, PRBool *_retval)
1183 nsURI *This = NSURI_THIS(iface);
1184 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1185 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1188 static nsresult NSAPI nsURI_Clone(nsIWineURI *iface, nsIURI **_retval)
1190 nsURI *This = NSURI_THIS(iface);
1194 TRACE("(%p)->(%p)\n", This, _retval);
1196 nsres = nsIURI_Clone(This->uri, &uri);
1197 if(NS_FAILED(nsres)) {
1198 WARN("Clone failed: %08lx\n", nsres);
1202 return create_uri(uri, This->container, _retval);
1205 static nsresult NSAPI nsURI_Resolve(nsIWineURI *iface, const nsACString *arelativePath,
1206 nsACString *_retval)
1208 nsURI *This = NSURI_THIS(iface);
1209 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1210 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1213 static nsresult NSAPI nsURI_GetAsciiSpec(nsIWineURI *iface, nsACString *aAsciiSpec)
1215 nsURI *This = NSURI_THIS(iface);
1216 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1217 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1220 static nsresult NSAPI nsURI_GetAsciiHost(nsIWineURI *iface, nsACString *aAsciiHost)
1222 nsURI *This = NSURI_THIS(iface);
1223 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1224 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1227 static nsresult NSAPI nsURI_GetOriginCharset(nsIWineURI *iface, nsACString *aOriginCharset)
1229 nsURI *This = NSURI_THIS(iface);
1230 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1231 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1234 static nsresult NSAPI nsURI_GetNSContainer(nsIWineURI *iface, NSContainer **aContainer)
1236 nsURI *This = NSURI_THIS(iface);
1238 TRACE("(%p)->(%p)\n", This, aContainer);
1241 nsIWebBrowserChrome_AddRef(NSWBCHROME(This->container));
1242 *aContainer = This->container;
1247 static nsresult NSAPI nsURI_SetNSContainer(nsIWineURI *iface, NSContainer *aContainer)
1249 nsURI *This = NSURI_THIS(iface);
1251 TRACE("(%p)->(%p)\n", This, aContainer);
1253 if(This->container) {
1254 WARN("Container already set: %p\n", This->container);
1255 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1259 nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer));
1260 This->container = aContainer;
1267 static const nsIWineURIVtbl nsWineURIVtbl = {
1268 nsURI_QueryInterface,
1296 nsURI_GetOriginCharset,
1297 nsURI_GetNSContainer,
1298 nsURI_SetNSContainer,
1301 static nsresult create_uri(nsIURI *uri, NSContainer *container, nsIURI **_retval)
1303 nsURI *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(nsURI));
1305 ret->lpWineURIVtbl = &nsWineURIVtbl;
1308 ret->container = container;
1311 nsIWebBrowserChrome_AddRef(NSWBCHROME(container));
1313 TRACE("retval=%p\n", ret);
1314 *_retval = NSURI(ret);
1318 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
1323 if(IsEqualGUID(&IID_nsISupports, riid)) {
1324 TRACE("(IID_nsISupports %p)\n", result);
1326 }else if(IsEqualGUID(&IID_nsIIOService, riid)) {
1327 TRACE("(IID_nsIIOService %p)\n", result);
1332 nsIIOService_AddRef(iface);
1336 WARN("(%s %p)\n", debugstr_guid(riid), result);
1337 return NS_NOINTERFACE;
1340 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
1345 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
1350 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
1351 nsIProtocolHandler **_retval)
1353 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1354 return nsIIOService_GetProtocolHandler(nsio, aScheme, _retval);
1357 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
1360 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1361 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
1364 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
1365 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
1367 const char *spec = NULL;
1369 PRBool is_javascript = FALSE;
1372 nsACString_GetData(aSpec, &spec, NULL);
1374 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
1378 nsACString base_uri_str;
1379 const char *base_uri = NULL;
1381 nsACString_Init(&base_uri_str, NULL);
1383 nsres = nsIURI_GetSpec(aBaseURI, &base_uri_str);
1384 if(NS_SUCCEEDED(nsres)) {
1385 nsACString_GetData(&base_uri_str, &base_uri, NULL);
1386 TRACE("uri=%s\n", debugstr_a(base_uri));
1388 ERR("GetSpec failed: %08lx\n", nsres);
1391 nsACString_Finish(&base_uri_str);
1394 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
1395 if(NS_FAILED(nsres)) {
1396 WARN("NewURI failed: %08lx\n", nsres);
1400 nsIURI_SchemeIs(uri, "javascript", &is_javascript);
1402 TRACE("returning javascript uri: %p\n", uri);
1407 return create_uri(uri, NULL, _retval);
1410 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
1413 TRACE("(%p %p)\n", aFile, _retval);
1414 return nsIIOService_NewFileURI(nsio, aFile, _retval);
1417 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
1418 nsIChannel **_retval)
1420 nsIChannel *channel = NULL;
1422 nsIWineURI *wine_uri;
1425 TRACE("(%p %p)\n", aURI, _retval);
1427 nsres = nsIIOService_NewChannelFromURI(nsio, aURI, &channel);
1428 if(NS_FAILED(nsres) && nsres != NS_ERROR_UNKNOWN_PROTOCOL) {
1429 WARN("NewChannelFromURI failed: %08lx\n", nsres);
1434 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
1435 if(NS_FAILED(nsres)) {
1436 WARN("Could not get nsIWineURI: %08lx\n", nsres);
1438 return channel ? NS_OK : NS_ERROR_UNEXPECTED;
1441 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(nsChannel));
1443 ret->lpHttpChannelVtbl = &nsChannelVtbl;
1444 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
1446 ret->channel = channel;
1447 ret->http_channel = NULL;
1448 ret->uri = wine_uri;
1449 ret->post_data_stream = NULL;
1450 ret->load_group = NULL;
1451 ret->notif_callback = NULL;
1452 ret->load_flags = 0;
1454 nsIURI_AddRef(aURI);
1455 ret->original_uri = aURI;
1458 nsIChannel_QueryInterface(channel, &IID_nsIHttpChannel, (void**)&ret->http_channel);
1460 *_retval = NSCHANNEL(ret);
1464 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
1465 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
1467 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
1468 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
1471 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
1473 TRACE("(%p)\n", aOffline);
1474 return nsIIOService_GetOffline(nsio, aOffline);
1477 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
1479 TRACE("(%x)\n", aOffline);
1480 return nsIIOService_SetOffline(nsio, aOffline);
1483 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
1484 const char *aScheme, PRBool *_retval)
1486 TRACE("(%ld %s %p)\n", aPort, debugstr_a(aScheme), _retval);
1487 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
1490 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
1491 nsACString * _retval)
1493 TRACE("(%p %p)\n", urlString, _retval);
1494 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
1497 static const nsIIOServiceVtbl nsIOServiceVtbl = {
1498 nsIOService_QueryInterface,
1500 nsIOService_Release,
1501 nsIOService_GetProtocolHandler,
1502 nsIOService_GetProtocolFlags,
1504 nsIOService_NewFileURI,
1505 nsIOService_NewChannelFromURI,
1506 nsIOService_NewChannel,
1507 nsIOService_GetOffline,
1508 nsIOService_SetOffline,
1509 nsIOService_AllowPort,
1510 nsIOService_ExtractScheme
1513 static nsIIOService nsIOService = { &nsIOServiceVtbl };
1515 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
1520 if(IsEqualGUID(&IID_nsISupports, riid)) {
1521 TRACE("(IID_nsISupoprts %p)\n", result);
1523 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
1524 TRACE("(IID_nsIFactory %p)\n", result);
1529 nsIFactory_AddRef(iface);
1533 WARN("(%s %p)\n", debugstr_guid(riid), result);
1534 return NS_NOINTERFACE;
1537 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
1542 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
1547 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
1548 nsISupports *aOuter, const nsIID *iid, void **result)
1550 return nsIIOService_QueryInterface(&nsIOService, iid, result);
1553 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
1555 WARN("(%x)\n", lock);
1559 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
1560 nsIOServiceFactory_QueryInterface,
1561 nsIOServiceFactory_AddRef,
1562 nsIOServiceFactory_Release,
1563 nsIOServiceFactory_CreateInstance,
1564 nsIOServiceFactory_LockFactory
1567 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
1569 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
1571 nsIFactory *old_factory = NULL;
1574 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
1575 &IID_nsIFactory, (void**)&old_factory);
1576 if(NS_FAILED(nsres)) {
1577 ERR("Could not get factory: %08lx\n", nsres);
1578 nsIFactory_Release(old_factory);
1582 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
1583 if(NS_FAILED(nsres)) {
1584 ERR("Couldn not create nsIOService instance %08lx\n", nsres);
1585 nsIFactory_Release(old_factory);
1589 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
1590 nsIFactory_Release(old_factory);
1591 if(NS_FAILED(nsres))
1592 ERR("UnregisterFactory failed: %08lx\n", nsres);
1594 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
1595 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
1596 if(NS_FAILED(nsres))
1597 ERR("RegisterFactory failed: %08lx\n", nsres);
1600 nsIURI *get_nsIURI(LPCWSTR url)
1608 len = WideCharToMultiByte(CP_ACP, 0, url, -1, NULL, -1, NULL, NULL);
1609 urla = HeapAlloc(GetProcessHeap(), 0, len);
1610 WideCharToMultiByte(CP_ACP, 0, url, -1, urla, -1, NULL, NULL);
1612 nsACString_Init(&acstr, urla);
1614 nsres = nsIIOService_NewURI(nsio, &acstr, NULL, NULL, &ret);
1615 if(NS_FAILED(nsres))
1616 FIXME("NewURI failed: %08lx\n", nsres);
1618 nsACString_Finish(&acstr);
1619 HeapFree(GetProcessHeap(), 0, urla);