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;
51 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
54 const nsIWineURIVtbl *lpWineURIVtbl;
59 NSContainer *container;
65 #define NSURI(x) ((nsIURI*) &(x)->lpWineURIVtbl)
66 #define NSWINEURI(x) ((nsIWineURI*) &(x)->lpWineURIVtbl)
68 static nsresult create_uri(nsIURI*,NSContainer*,nsIWineURI**);
70 static BOOL exec_shldocvw_67(HTMLDocument *doc, LPCWSTR url)
72 IOleCommandTarget *cmdtrg = NULL;
75 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget,
78 VARIANT varUrl, varRes;
80 V_VT(&varUrl) = VT_BSTR;
81 V_BSTR(&varUrl) = SysAllocString(url);
82 V_VT(&varRes) = VT_BOOL;
84 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
86 IOleCommandTarget_Release(cmdtrg);
87 SysFreeString(V_BSTR(&varUrl));
89 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
90 TRACE("got VARIANT_FALSE, do not load\n");
98 static BOOL before_async_open(nsChannel *channel, NSContainer *container)
100 IServiceProvider *service_provider;
101 HTMLDocument *doc = container->doc;
106 nsIWineURI_GetWineURL(channel->uri, &uri);
108 ERR("GetWineURL returned NULL\n");
113 NSContainer *container_iter = container;
115 hlnf = HLNF_OPENINNEWWINDOW;
116 while(!container_iter->doc)
117 container_iter = container_iter->parent;
118 doc = container_iter->doc;
124 if(!hlnf && !exec_shldocvw_67(doc, uri))
127 hres = IOleClientSite_QueryInterface(doc->client, &IID_IServiceProvider,
128 (void**)&service_provider);
129 if(SUCCEEDED(hres)) {
130 IHlinkFrame *hlink_frame;
132 hres = IServiceProvider_QueryService(service_provider, &IID_IHlinkFrame,
133 &IID_IHlinkFrame, (void**)&hlink_frame);
134 IServiceProvider_Release(service_provider);
135 if(SUCCEEDED(hres)) {
136 hlink_frame_navigate(doc, hlink_frame, uri, channel->post_data_stream, hlnf);
137 IHlinkFrame_Release(hlink_frame);
146 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
148 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
150 nsChannel *This = NSCHANNEL_THIS(iface);
154 if(IsEqualGUID(&IID_nsISupports, riid)) {
155 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
156 *result = NSCHANNEL(This);
157 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
158 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
159 *result = NSCHANNEL(This);
160 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
161 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
162 *result = NSCHANNEL(This);
163 }else if(This->http_channel && IsEqualGUID(&IID_nsIHttpChannel, riid)) {
164 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
165 *result = NSHTTPCHANNEL(This);
166 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
167 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
168 *result = NSUPCHANNEL(This);
172 nsIChannel_AddRef(NSCHANNEL(This));
176 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
179 return nsIChannel_QueryInterface(This->channel, riid, result);
180 return NS_NOINTERFACE;
183 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
185 nsChannel *This = NSCHANNEL_THIS(iface);
186 nsrefcnt ref = InterlockedIncrement(&This->ref);
188 TRACE("(%p) ref=%d\n", This, ref);
193 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
195 nsChannel *This = NSCHANNEL_THIS(iface);
196 LONG ref = InterlockedDecrement(&This->ref);
199 nsIWineURI_Release(This->uri);
201 nsIChannel_Release(This->channel);
202 if(This->http_channel)
203 nsIHttpChannel_Release(This->http_channel);
204 if(This->post_data_stream)
205 nsIInputStream_Release(This->post_data_stream);
207 nsILoadGroup_Release(This->load_group);
208 if(This->notif_callback)
209 nsIInterfaceRequestor_Release(This->notif_callback);
210 if(This->original_uri)
211 nsIURI_Release(This->original_uri);
212 heap_free(This->content);
213 heap_free(This->charset);
220 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
222 nsChannel *This = NSCHANNEL_THIS(iface);
224 TRACE("(%p)->(%p)\n", This, aName);
227 return nsIChannel_GetName(This->channel, aName);
229 return NS_ERROR_NOT_IMPLEMENTED;
232 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
234 nsChannel *This = NSCHANNEL_THIS(iface);
236 TRACE("(%p)->(%p)\n", This, _retval);
239 return nsIChannel_IsPending(This->channel, _retval);
241 FIXME("default action not implemented\n");
242 return NS_ERROR_NOT_IMPLEMENTED;
245 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
247 nsChannel *This = NSCHANNEL_THIS(iface);
249 TRACE("(%p)->(%p)\n", This, aStatus);
252 return nsIChannel_GetStatus(This->channel, aStatus);
254 TRACE("returning NS_OK\n");
255 return *aStatus = NS_OK;
258 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
260 nsChannel *This = NSCHANNEL_THIS(iface);
262 TRACE("(%p)->(%08x)\n", This, aStatus);
265 return nsIChannel_Cancel(This->channel, aStatus);
267 FIXME("default action not implemented\n");
268 return NS_ERROR_NOT_IMPLEMENTED;
271 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
273 nsChannel *This = NSCHANNEL_THIS(iface);
275 TRACE("(%p)\n", This);
278 return nsIChannel_Suspend(This->channel);
280 FIXME("default action not implemented\n");
281 return NS_ERROR_NOT_IMPLEMENTED;
284 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
286 nsChannel *This = NSCHANNEL_THIS(iface);
288 TRACE("(%p)\n", This);
291 return nsIChannel_Resume(This->channel);
293 FIXME("default action not implemented\n");
294 return NS_ERROR_NOT_IMPLEMENTED;
297 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
299 nsChannel *This = NSCHANNEL_THIS(iface);
301 TRACE("(%p)->(%p)\n", This, aLoadGroup);
304 nsILoadGroup_AddRef(This->load_group);
306 *aLoadGroup = This->load_group;
310 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
312 nsChannel *This = NSCHANNEL_THIS(iface);
314 TRACE("(%p)->(%p)\n", This, aLoadGroup);
317 nsILoadGroup_Release(This->load_group);
319 nsILoadGroup_AddRef(aLoadGroup);
321 This->load_group = aLoadGroup;
324 return nsIChannel_SetLoadGroup(This->channel, aLoadGroup);
328 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
330 nsChannel *This = NSCHANNEL_THIS(iface);
332 TRACE("(%p)->(%p)\n", This, aLoadFlags);
334 *aLoadFlags = This->load_flags;
338 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
340 nsChannel *This = NSCHANNEL_THIS(iface);
342 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
344 This->load_flags = aLoadFlags;
347 return nsIChannel_SetLoadFlags(This->channel, aLoadFlags);
351 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
353 nsChannel *This = NSCHANNEL_THIS(iface);
355 TRACE("(%p)->(%p)\n", This, aOriginalURI);
357 if(This->original_uri)
358 nsIURI_AddRef(This->original_uri);
360 *aOriginalURI = This->original_uri;
364 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
366 nsChannel *This = NSCHANNEL_THIS(iface);
368 TRACE("(%p)->(%p)\n", This, aOriginalURI);
370 if(This->original_uri)
371 nsIURI_Release(This->original_uri);
373 nsIURI_AddRef(aOriginalURI);
374 This->original_uri = aOriginalURI;
377 return nsIChannel_SetOriginalURI(This->channel, aOriginalURI);
381 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
383 nsChannel *This = NSCHANNEL_THIS(iface);
385 TRACE("(%p)->(%p)\n", This, aURI);
387 nsIWineURI_AddRef(This->uri);
388 *aURI = (nsIURI*)This->uri;
393 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
395 nsChannel *This = NSCHANNEL_THIS(iface);
397 TRACE("(%p)->(%p)\n", This, aOwner);
400 return nsIChannel_GetOwner(This->channel, aOwner);
402 FIXME("default action not implemented\n");
403 return NS_ERROR_NOT_IMPLEMENTED;
406 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
408 nsChannel *This = NSCHANNEL_THIS(iface);
410 TRACE("(%p)->(%p)\n", This, aOwner);
413 return nsIChannel_SetOwner(This->channel, aOwner);
415 FIXME("default action not implemented\n");
416 return NS_ERROR_NOT_IMPLEMENTED;
419 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
420 nsIInterfaceRequestor **aNotificationCallbacks)
422 nsChannel *This = NSCHANNEL_THIS(iface);
424 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
426 if(This->notif_callback)
427 nsIInterfaceRequestor_AddRef(This->notif_callback);
428 *aNotificationCallbacks = This->notif_callback;
433 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
434 nsIInterfaceRequestor *aNotificationCallbacks)
436 nsChannel *This = NSCHANNEL_THIS(iface);
438 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
440 if(This->notif_callback)
441 nsIInterfaceRequestor_Release(This->notif_callback);
442 if(aNotificationCallbacks)
443 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
445 This->notif_callback = aNotificationCallbacks;
448 return nsIChannel_SetNotificationCallbacks(This->channel, aNotificationCallbacks);
452 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
454 nsChannel *This = NSCHANNEL_THIS(iface);
456 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
459 return nsIChannel_GetSecurityInfo(This->channel, aSecurityInfo);
461 FIXME("default action not implemented\n");
462 return NS_ERROR_NOT_IMPLEMENTED;
465 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
467 nsChannel *This = NSCHANNEL_THIS(iface);
469 TRACE("(%p)->(%p)\n", This, aContentType);
472 nsACString_SetData(aContentType, This->content);
477 return nsIChannel_GetContentType(This->channel, aContentType);
479 TRACE("returning default text/html\n");
480 nsACString_SetData(aContentType, "text/html");
484 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
485 const nsACString *aContentType)
487 nsChannel *This = NSCHANNEL_THIS(iface);
489 TRACE("(%p)->(%p)\n", This, aContentType);
492 return nsIChannel_SetContentType(This->channel, aContentType);
494 FIXME("default action not implemented\n");
495 return NS_ERROR_NOT_IMPLEMENTED;
498 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
499 nsACString *aContentCharset)
501 nsChannel *This = NSCHANNEL_THIS(iface);
503 TRACE("(%p)->(%p)\n", This, aContentCharset);
506 nsACString_SetData(aContentCharset, This->charset);
511 nsresult nsres = nsIChannel_GetContentCharset(This->channel, aContentCharset);
513 nsACString_GetData(aContentCharset, &ch);
517 nsACString_SetData(aContentCharset, "");
521 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
522 const nsACString *aContentCharset)
524 nsChannel *This = NSCHANNEL_THIS(iface);
526 TRACE("(%p)->(%p)\n", This, aContentCharset);
529 return nsIChannel_SetContentCharset(This->channel, aContentCharset);
531 FIXME("default action not implemented\n");
532 return NS_ERROR_NOT_IMPLEMENTED;
535 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
537 nsChannel *This = NSCHANNEL_THIS(iface);
539 TRACE("(%p)->(%p)\n", This, aContentLength);
542 return nsIChannel_GetContentLength(This->channel, aContentLength);
544 FIXME("default action not implemented\n");
545 return NS_ERROR_NOT_IMPLEMENTED;
548 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
550 nsChannel *This = NSCHANNEL_THIS(iface);
552 TRACE("(%p)->(%d)\n", This, aContentLength);
555 return nsIChannel_SetContentLength(This->channel, aContentLength);
557 FIXME("default action not implemented\n");
558 return NS_ERROR_NOT_IMPLEMENTED;
561 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
563 nsChannel *This = NSCHANNEL_THIS(iface);
565 TRACE("(%p)->(%p)\n", This, _retval);
568 return nsIChannel_Open(This->channel, _retval);
570 FIXME("default action not implemented\n");
571 return NS_ERROR_NOT_IMPLEMENTED;
574 static BOOL do_load_from_moniker_hack(nsChannel *This)
576 nsACString scheme_str;
581 * We should always load the page from IMoniker, but Wine is not yet
582 * ready for this. This function is a heuristic, that decides which
583 * way of loading is better (Gecko implementation or IMoniker). The
584 * aim is to always return TRUE.
587 /* Load from moniker if there is no Gecko channel available */
591 nsACString_Init(&scheme_str, NULL);
592 nsres = nsIWineURI_GetScheme(This->uri, &scheme_str);
594 if(NS_SUCCEEDED(nsres)) {
597 nsACString_GetData(&scheme_str, &scheme);
598 ret = !strcmp(scheme, "wine") || !strcmp(scheme, "about");
601 nsACString_Finish(&scheme_str);
605 static HRESULT create_mon_for_nschannel(nsChannel *channel, IMoniker **mon)
607 nsIWineURI *wine_uri;
612 if(!channel->original_uri) {
613 ERR("original_uri == NULL\n");
617 nsres = nsIURI_QueryInterface(channel->original_uri, &IID_nsIWineURI, (void**)&wine_uri);
618 if(NS_FAILED(nsres)) {
619 ERR("Could not get nsIWineURI: %08x\n", nsres);
623 nsIWineURI_GetWineURL(wine_uri, &wine_url);
624 nsIWineURI_Release(wine_uri);
626 TRACE("wine_url == NULL\n");
630 hres = CreateURLMoniker(NULL, wine_url, mon);
632 WARN("CreateURLMonikrer failed: %08x\n", hres);
637 static NSContainer *get_nscontainer_from_load_group(nsChannel *This)
639 NSContainer *container;
642 nsIWineURI *wine_uri;
646 nsres = nsILoadGroup_GetDefaultLoadRequest(This->load_group, &req);
647 if(NS_FAILED(nsres)) {
648 ERR("GetDefaultLoadRequest failed: %08x\n", nsres);
652 nsres = nsIRequest_QueryInterface(req, &IID_nsIChannel, (void**)&channel);
653 nsIRequest_Release(req);
654 if(NS_FAILED(nsres)) {
655 WARN("Could not get nsIChannel interface: %08x\n", nsres);
659 nsres = nsIChannel_GetURI(channel, &uri);
660 nsIChannel_Release(channel);
661 if(NS_FAILED(nsres)) {
662 ERR("GetURI failed: %08x\n", nsres);
666 nsres = nsIURI_QueryInterface(uri, &IID_nsIWineURI, (void**)&wine_uri);
668 if(NS_FAILED(nsres)) {
669 TRACE("Could not get nsIWineURI: %08x\n", nsres);
673 nsIWineURI_GetNSContainer(wine_uri, &container);
674 nsIWineURI_Release(wine_uri);
679 static nsresult async_open_doc_uri(nsChannel *This, NSContainer *container,
680 nsIStreamListener *listener, nsISupports *context, BOOL *open)
687 if(container->bscallback) {
688 nsIChannel_AddRef(NSCHANNEL(This));
689 container->bscallback->nschannel = This;
691 nsIStreamListener_AddRef(listener);
692 container->bscallback->nslistener = listener;
695 nsISupports_AddRef(context);
696 container->bscallback->nscontext = context;
699 if(container->doc && container->doc->mime) {
702 heap_free(This->content);
704 len = WideCharToMultiByte(CP_ACP, 0, container->doc->mime, -1, NULL, 0, NULL, NULL);
705 This->content = heap_alloc(len);
706 WideCharToMultiByte(CP_ACP, 0, container->doc->mime, -1, This->content, -1, NULL, NULL);
709 if(do_load_from_moniker_hack(This))
710 return WINE_NS_LOAD_FROM_MONIKER;
712 BOOL cont = before_async_open(This, container);
716 return NS_ERROR_UNEXPECTED;
719 if(!container->doc) {
721 ? nsIChannel_AsyncOpen(This->channel, listener, context)
722 : NS_ERROR_UNEXPECTED;
725 hres = create_mon_for_nschannel(This, &mon);
727 return NS_ERROR_UNEXPECTED;
729 set_current_mon(container->doc, mon);
736 static nsresult async_open(nsChannel *This, NSContainer *container, nsIStreamListener *listener,
737 nsISupports *context)
739 BSCallback *bscallback;
740 IMoniker *mon = NULL;
746 if(This->post_data_stream) {
747 nsIUploadChannel *upload_channel;
749 nsres = nsIChannel_QueryInterface(This->channel, &IID_nsIUploadChannel,
750 (void**)&upload_channel);
751 if(NS_SUCCEEDED(nsres)) {
752 nsACString empty_string;
753 nsACString_Init(&empty_string, "");
755 nsres = nsIUploadChannel_SetUploadStream(upload_channel, This->post_data_stream,
757 nsIUploadChannel_Release(upload_channel);
759 WARN("SetUploadStream failed: %08x\n", nsres);
761 nsACString_Finish(&empty_string);
765 nsres = nsIChannel_AsyncOpen(This->channel, listener, context);
768 IMoniker_Release(mon);
770 if(NS_FAILED(nsres) && (This->load_flags & LOAD_INITIAL_DOCUMENT_URI))
771 return WINE_NS_LOAD_FROM_MONIKER;
775 TRACE("channel == NULL\n");
777 hres = create_mon_for_nschannel(This, &mon);
779 return NS_ERROR_UNEXPECTED;
781 bscallback = create_bscallback(mon);
782 IMoniker_Release(mon);
784 nsIChannel_AddRef(NSCHANNEL(This));
785 bscallback->nschannel = This;
787 nsIStreamListener_AddRef(listener);
788 bscallback->nslistener = listener;
791 nsISupports_AddRef(context);
792 bscallback->nscontext = context;
795 task = heap_alloc(sizeof(task_t));
797 task->doc = container->doc;
798 task->task_id = TASK_START_BINDING;
800 task->bscallback = bscallback;
807 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
808 nsISupports *aContext)
810 nsChannel *This = NSCHANNEL_THIS(iface);
811 NSContainer *container;
814 nsresult nsres = NS_OK;
816 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
818 nsIWineURI_GetNSContainer(This->uri, &container);
820 if(!container && This->load_group) {
821 container = get_nscontainer_from_load_group(This);
823 nsIWineURI_SetNSContainer(This->uri, container);
827 TRACE("container = NULL\n");
829 ? nsIChannel_AsyncOpen(This->channel, aListener, aContext)
830 : NS_ERROR_UNEXPECTED;
833 nsIWineURI_GetIsDocumentURI(This->uri, &is_doc_uri);
835 if(is_doc_uri && (This->load_flags & LOAD_INITIAL_DOCUMENT_URI))
836 nsres = async_open_doc_uri(This, container, aListener, aContext, &open);
839 nsres = async_open(This, container, aListener, aContext);
841 nsIWebBrowserChrome_Release(NSWBCHROME(container));
845 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
847 nsChannel *This = NSCHANNEL_THIS(iface);
849 TRACE("(%p)->(%p)\n", This, aRequestMethod);
851 if(This->http_channel)
852 return nsIHttpChannel_GetRequestMethod(This->http_channel, aRequestMethod);
854 return NS_ERROR_NOT_IMPLEMENTED;
857 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
858 const nsACString *aRequestMethod)
860 nsChannel *This = NSCHANNEL_THIS(iface);
862 TRACE("(%p)->(%p)\n", This, aRequestMethod);
864 if(This->http_channel)
865 return nsIHttpChannel_SetRequestMethod(This->http_channel, aRequestMethod);
867 return NS_ERROR_NOT_IMPLEMENTED;
870 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
872 nsChannel *This = NSCHANNEL_THIS(iface);
874 TRACE("(%p)->(%p)\n", This, aReferrer);
876 if(This->http_channel)
877 return nsIHttpChannel_GetReferrer(This->http_channel, aReferrer);
879 return NS_ERROR_NOT_IMPLEMENTED;
882 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
884 nsChannel *This = NSCHANNEL_THIS(iface);
886 TRACE("(%p)->(%p)\n", This, aReferrer);
888 if(This->http_channel)
889 return nsIHttpChannel_SetReferrer(This->http_channel, aReferrer);
891 return NS_ERROR_NOT_IMPLEMENTED;
894 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
895 const nsACString *aHeader, nsACString *_retval)
897 nsChannel *This = NSCHANNEL_THIS(iface);
899 TRACE("(%p)->(%p %p)\n", This, aHeader, _retval);
901 if(This->http_channel)
902 return nsIHttpChannel_GetRequestHeader(This->http_channel, aHeader, _retval);
904 return NS_ERROR_NOT_IMPLEMENTED;
907 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
908 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
910 nsChannel *This = NSCHANNEL_THIS(iface);
912 TRACE("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
914 if(This->http_channel)
915 return nsIHttpChannel_SetRequestHeader(This->http_channel, aHeader, aValue, aMerge);
917 return NS_ERROR_NOT_IMPLEMENTED;
920 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
921 nsIHttpHeaderVisitor *aVisitor)
923 nsChannel *This = NSCHANNEL_THIS(iface);
925 TRACE("(%p)->(%p)\n", This, aVisitor);
927 if(This->http_channel)
928 return nsIHttpChannel_VisitRequestHeaders(This->http_channel, aVisitor);
930 return NS_ERROR_NOT_IMPLEMENTED;
933 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
935 nsChannel *This = NSCHANNEL_THIS(iface);
937 TRACE("(%p)->(%p)\n", This, aAllowPipelining);
939 if(This->http_channel)
940 return nsIHttpChannel_GetAllowPipelining(This->http_channel, aAllowPipelining);
942 return NS_ERROR_NOT_IMPLEMENTED;
945 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
947 nsChannel *This = NSCHANNEL_THIS(iface);
949 TRACE("(%p)->(%x)\n", This, aAllowPipelining);
951 if(This->http_channel)
952 return nsIHttpChannel_SetAllowPipelining(This->http_channel, aAllowPipelining);
954 return NS_ERROR_NOT_IMPLEMENTED;
957 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
959 nsChannel *This = NSCHANNEL_THIS(iface);
961 TRACE("(%p)->(%p)\n", This, aRedirectionLimit);
963 if(This->http_channel)
964 return nsIHttpChannel_GetRedirectionLimit(This->http_channel, aRedirectionLimit);
966 return NS_ERROR_NOT_IMPLEMENTED;
969 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
971 nsChannel *This = NSCHANNEL_THIS(iface);
973 TRACE("(%p)->(%u)\n", This, aRedirectionLimit);
975 if(This->http_channel)
976 return nsIHttpChannel_SetRedirectionLimit(This->http_channel, aRedirectionLimit);
978 return NS_ERROR_NOT_IMPLEMENTED;
981 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
983 nsChannel *This = NSCHANNEL_THIS(iface);
985 TRACE("(%p)->(%p)\n", This, aResponseStatus);
987 if(This->http_channel)
988 return nsIHttpChannel_GetResponseStatus(This->http_channel, aResponseStatus);
990 return NS_ERROR_NOT_IMPLEMENTED;
993 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
994 nsACString *aResponseStatusText)
996 nsChannel *This = NSCHANNEL_THIS(iface);
998 TRACE("(%p)->(%p)\n", This, aResponseStatusText);
1000 if(This->http_channel)
1001 return nsIHttpChannel_GetResponseStatusText(This->http_channel, aResponseStatusText);
1003 return NS_ERROR_NOT_IMPLEMENTED;
1006 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
1007 PRBool *aRequestSucceeded)
1009 nsChannel *This = NSCHANNEL_THIS(iface);
1011 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
1013 if(This->http_channel)
1014 return nsIHttpChannel_GetRequestSucceeded(This->http_channel, aRequestSucceeded);
1016 return NS_ERROR_NOT_IMPLEMENTED;
1019 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
1020 const nsACString *header, nsACString *_retval)
1022 nsChannel *This = NSCHANNEL_THIS(iface);
1024 TRACE("(%p)->(%p %p)\n", This, header, _retval);
1026 if(This->http_channel)
1027 return nsIHttpChannel_GetResponseHeader(This->http_channel, header, _retval);
1029 return NS_ERROR_NOT_IMPLEMENTED;
1032 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
1033 const nsACString *header, const nsACString *value, PRBool merge)
1035 nsChannel *This = NSCHANNEL_THIS(iface);
1037 TRACE("(%p)->(%p %p %x)\n", This, header, value, merge);
1039 if(This->http_channel)
1040 return nsIHttpChannel_SetResponseHeader(This->http_channel, header, value, merge);
1042 return NS_ERROR_NOT_IMPLEMENTED;
1045 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
1046 nsIHttpHeaderVisitor *aVisitor)
1048 nsChannel *This = NSCHANNEL_THIS(iface);
1050 TRACE("(%p)->(%p)\n", This, aVisitor);
1052 if(This->http_channel)
1053 return nsIHttpChannel_VisitResponseHeaders(This->http_channel, aVisitor);
1055 return NS_ERROR_NOT_IMPLEMENTED;
1058 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
1060 nsChannel *This = NSCHANNEL_THIS(iface);
1062 TRACE("(%p)->(%p)\n", This, _retval);
1064 if(This->http_channel)
1065 return nsIHttpChannel_IsNoStoreResponse(This->http_channel, _retval);
1067 return NS_ERROR_NOT_IMPLEMENTED;
1070 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
1072 nsChannel *This = NSCHANNEL_THIS(iface);
1074 TRACE("(%p)->(%p)\n", This, _retval);
1076 if(This->http_channel)
1077 return nsIHttpChannel_IsNoCacheResponse(This->http_channel, _retval);
1079 return NS_ERROR_NOT_IMPLEMENTED;
1082 #undef NSCHANNEL_THIS
1084 static const nsIHttpChannelVtbl nsChannelVtbl = {
1085 nsChannel_QueryInterface,
1089 nsChannel_IsPending,
1090 nsChannel_GetStatus,
1094 nsChannel_GetLoadGroup,
1095 nsChannel_SetLoadGroup,
1096 nsChannel_GetLoadFlags,
1097 nsChannel_SetLoadFlags,
1098 nsChannel_GetOriginalURI,
1099 nsChannel_SetOriginalURI,
1103 nsChannel_GetNotificationCallbacks,
1104 nsChannel_SetNotificationCallbacks,
1105 nsChannel_GetSecurityInfo,
1106 nsChannel_GetContentType,
1107 nsChannel_SetContentType,
1108 nsChannel_GetContentCharset,
1109 nsChannel_SetContentCharset,
1110 nsChannel_GetContentLength,
1111 nsChannel_SetContentLength,
1113 nsChannel_AsyncOpen,
1114 nsChannel_GetRequestMethod,
1115 nsChannel_SetRequestMethod,
1116 nsChannel_GetReferrer,
1117 nsChannel_SetReferrer,
1118 nsChannel_GetRequestHeader,
1119 nsChannel_SetRequestHeader,
1120 nsChannel_VisitRequestHeaders,
1121 nsChannel_GetAllowPipelining,
1122 nsChannel_SetAllowPipelining,
1123 nsChannel_GetRedirectionLimit,
1124 nsChannel_SetRedirectionLimit,
1125 nsChannel_GetResponseStatus,
1126 nsChannel_GetResponseStatusText,
1127 nsChannel_GetRequestSucceeded,
1128 nsChannel_GetResponseHeader,
1129 nsChannel_SetResponseHeader,
1130 nsChannel_VisitResponseHeaders,
1131 nsChannel_IsNoStoreResponse,
1132 nsChannel_IsNoCacheResponse
1135 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1137 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1140 nsChannel *This = NSUPCHANNEL_THIS(iface);
1141 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1144 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1146 nsChannel *This = NSUPCHANNEL_THIS(iface);
1147 return nsIChannel_AddRef(NSCHANNEL(This));
1150 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1152 nsChannel *This = NSUPCHANNEL_THIS(iface);
1153 return nsIChannel_Release(NSCHANNEL(This));
1156 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1157 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1159 nsChannel *This = NSUPCHANNEL_THIS(iface);
1160 const char *content_type;
1162 TRACE("(%p)->(%p %p %d)\n", This, aStream, aContentType, aContentLength);
1164 if(This->post_data_stream)
1165 nsIInputStream_Release(This->post_data_stream);
1168 nsACString_GetData(aContentType, &content_type);
1170 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
1173 if(aContentLength != -1)
1174 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1177 nsIInputStream_AddRef(aStream);
1178 This->post_data_stream = aStream;
1183 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1184 nsIInputStream **aUploadStream)
1186 nsChannel *This = NSUPCHANNEL_THIS(iface);
1188 TRACE("(%p)->(%p)\n", This, aUploadStream);
1190 if(This->post_data_stream)
1191 nsIInputStream_AddRef(This->post_data_stream);
1193 *aUploadStream = This->post_data_stream;
1197 #undef NSUPCHANNEL_THIS
1199 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1200 nsUploadChannel_QueryInterface,
1201 nsUploadChannel_AddRef,
1202 nsUploadChannel_Release,
1203 nsUploadChannel_SetUploadStream,
1204 nsUploadChannel_GetUploadStream
1207 #define NSURI_THIS(iface) DEFINE_THIS(nsURI, WineURI, iface)
1209 static nsresult NSAPI nsURI_QueryInterface(nsIWineURI *iface, nsIIDRef riid, nsQIResult result)
1211 nsURI *This = NSURI_THIS(iface);
1215 if(IsEqualGUID(&IID_nsISupports, riid)) {
1216 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1217 *result = NSURI(This);
1218 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1219 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1220 *result = NSURI(This);
1221 }else if(IsEqualGUID(&IID_nsIWineURI, riid)) {
1222 TRACE("(%p)->(IID_nsIWineURI %p)\n", This, result);
1223 *result = NSURI(This);
1227 nsIURI_AddRef(NSURI(This));
1231 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1232 return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1235 static nsrefcnt NSAPI nsURI_AddRef(nsIWineURI *iface)
1237 nsURI *This = NSURI_THIS(iface);
1238 LONG ref = InterlockedIncrement(&This->ref);
1240 TRACE("(%p) ref=%d\n", This, ref);
1245 static nsrefcnt NSAPI nsURI_Release(nsIWineURI *iface)
1247 nsURI *This = NSURI_THIS(iface);
1248 LONG ref = InterlockedDecrement(&This->ref);
1250 TRACE("(%p) ref=%d\n", This, ref);
1254 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1256 nsIURI_Release(This->uri);
1257 heap_free(This->wine_url);
1264 static nsresult NSAPI nsURI_GetSpec(nsIWineURI *iface, nsACString *aSpec)
1266 nsURI *This = NSURI_THIS(iface);
1268 TRACE("(%p)->(%p)\n", This, aSpec);
1270 if(This->use_wine_url) {
1271 char speca[INTERNET_MAX_URL_LENGTH] = "wine:";
1272 WideCharToMultiByte(CP_ACP, 0, This->wine_url, -1, speca+5, sizeof(speca)-5, NULL, NULL);
1273 nsACString_SetData(aSpec, speca);
1279 return nsIURI_GetSpec(This->uri, aSpec);
1281 TRACE("returning error\n");
1282 return NS_ERROR_NOT_IMPLEMENTED;
1286 static nsresult NSAPI nsURI_SetSpec(nsIWineURI *iface, const nsACString *aSpec)
1288 nsURI *This = NSURI_THIS(iface);
1290 TRACE("(%p)->(%p)\n", This, aSpec);
1293 return nsIURI_SetSpec(This->uri, aSpec);
1295 FIXME("default action not implemented\n");
1296 return NS_ERROR_NOT_IMPLEMENTED;
1299 static nsresult NSAPI nsURI_GetPrePath(nsIWineURI *iface, nsACString *aPrePath)
1301 nsURI *This = NSURI_THIS(iface);
1303 TRACE("(%p)->(%p)\n", This, aPrePath);
1306 return nsIURI_GetPrePath(This->uri, aPrePath);
1308 FIXME("default action not implemented\n");
1309 return NS_ERROR_NOT_IMPLEMENTED;
1312 static nsresult NSAPI nsURI_GetScheme(nsIWineURI *iface, nsACString *aScheme)
1314 nsURI *This = NSURI_THIS(iface);
1316 TRACE("(%p)->(%p)\n", This, aScheme);
1318 if(This->use_wine_url && strcmpW(This->wine_url, about_blankW)) {
1320 * For Gecko we set scheme to unknown so it won't be handled
1321 * as any special case.
1323 nsACString_SetData(aScheme, "wine");
1328 return nsIURI_GetScheme(This->uri, aScheme);
1330 TRACE("returning error\n");
1331 return NS_ERROR_NOT_IMPLEMENTED;
1334 static nsresult NSAPI nsURI_SetScheme(nsIWineURI *iface, const nsACString *aScheme)
1336 nsURI *This = NSURI_THIS(iface);
1338 TRACE("(%p)->(%p)\n", This, aScheme);
1341 return nsIURI_SetScheme(This->uri, aScheme);
1343 FIXME("default action not implemented\n");
1344 return NS_ERROR_NOT_IMPLEMENTED;
1347 static nsresult NSAPI nsURI_GetUserPass(nsIWineURI *iface, nsACString *aUserPass)
1349 nsURI *This = NSURI_THIS(iface);
1351 TRACE("(%p)->(%p)\n", This, aUserPass);
1354 return nsIURI_GetUserPass(This->uri, aUserPass);
1356 FIXME("default action not implemented\n");
1357 return NS_ERROR_NOT_IMPLEMENTED;
1360 static nsresult NSAPI nsURI_SetUserPass(nsIWineURI *iface, const nsACString *aUserPass)
1362 nsURI *This = NSURI_THIS(iface);
1364 TRACE("(%p)->(%p)\n", This, aUserPass);
1367 return nsIURI_SetUserPass(This->uri, aUserPass);
1369 FIXME("default action not implemented\n");
1370 return NS_ERROR_NOT_IMPLEMENTED;
1373 static nsresult NSAPI nsURI_GetUsername(nsIWineURI *iface, nsACString *aUsername)
1375 nsURI *This = NSURI_THIS(iface);
1377 TRACE("(%p)->(%p)\n", This, aUsername);
1380 return nsIURI_GetUsername(This->uri, aUsername);
1382 FIXME("default action not implemented\n");
1383 return NS_ERROR_NOT_IMPLEMENTED;
1386 static nsresult NSAPI nsURI_SetUsername(nsIWineURI *iface, const nsACString *aUsername)
1388 nsURI *This = NSURI_THIS(iface);
1390 TRACE("(%p)->(%p)\n", This, aUsername);
1393 return nsIURI_SetUsername(This->uri, aUsername);
1395 FIXME("default action not implemented\n");
1396 return NS_ERROR_NOT_IMPLEMENTED;
1399 static nsresult NSAPI nsURI_GetPassword(nsIWineURI *iface, nsACString *aPassword)
1401 nsURI *This = NSURI_THIS(iface);
1403 TRACE("(%p)->(%p)\n", This, aPassword);
1406 return nsIURI_GetPassword(This->uri, aPassword);
1408 FIXME("default action not implemented\n");
1409 return NS_ERROR_NOT_IMPLEMENTED;
1412 static nsresult NSAPI nsURI_SetPassword(nsIWineURI *iface, const nsACString *aPassword)
1414 nsURI *This = NSURI_THIS(iface);
1416 TRACE("(%p)->(%p)\n", This, aPassword);
1419 return nsIURI_SetPassword(This->uri, aPassword);
1421 FIXME("default action not implemented\n");
1422 return NS_ERROR_NOT_IMPLEMENTED;
1425 static nsresult NSAPI nsURI_GetHostPort(nsIWineURI *iface, nsACString *aHostPort)
1427 nsURI *This = NSURI_THIS(iface);
1429 TRACE("(%p)->(%p)\n", This, aHostPort);
1432 return nsIURI_GetHostPort(This->uri, aHostPort);
1434 FIXME("default action not implemented\n");
1435 return NS_ERROR_NOT_IMPLEMENTED;
1438 static nsresult NSAPI nsURI_SetHostPort(nsIWineURI *iface, const nsACString *aHostPort)
1440 nsURI *This = NSURI_THIS(iface);
1442 TRACE("(%p)->(%p)\n", This, aHostPort);
1445 return nsIURI_SetHostPort(This->uri, aHostPort);
1447 FIXME("default action not implemented\n");
1448 return NS_ERROR_NOT_IMPLEMENTED;
1451 static nsresult NSAPI nsURI_GetHost(nsIWineURI *iface, nsACString *aHost)
1453 nsURI *This = NSURI_THIS(iface);
1455 TRACE("(%p)->(%p)\n", This, aHost);
1458 return nsIURI_GetHost(This->uri, aHost);
1460 FIXME("default action not implemented\n");
1461 return NS_ERROR_NOT_IMPLEMENTED;
1464 static nsresult NSAPI nsURI_SetHost(nsIWineURI *iface, const nsACString *aHost)
1466 nsURI *This = NSURI_THIS(iface);
1468 TRACE("(%p)->(%p)\n", This, aHost);
1471 return nsIURI_SetHost(This->uri, aHost);
1473 FIXME("default action not implemented\n");
1474 return NS_ERROR_NOT_IMPLEMENTED;
1477 static nsresult NSAPI nsURI_GetPort(nsIWineURI *iface, PRInt32 *aPort)
1479 nsURI *This = NSURI_THIS(iface);
1481 TRACE("(%p)->(%p)\n", This, aPort);
1484 return nsIURI_GetPort(This->uri, aPort);
1486 FIXME("default action not implemented\n");
1487 return NS_ERROR_NOT_IMPLEMENTED;
1490 static nsresult NSAPI nsURI_SetPort(nsIWineURI *iface, PRInt32 aPort)
1492 nsURI *This = NSURI_THIS(iface);
1494 TRACE("(%p)->(%d)\n", This, aPort);
1497 return nsIURI_SetPort(This->uri, aPort);
1499 FIXME("default action not implemented\n");
1500 return NS_ERROR_NOT_IMPLEMENTED;
1503 static nsresult NSAPI nsURI_GetPath(nsIWineURI *iface, nsACString *aPath)
1505 nsURI *This = NSURI_THIS(iface);
1507 TRACE("(%p)->(%p)\n", This, aPath);
1510 return nsIURI_GetPath(This->uri, aPath);
1512 FIXME("default action not implemented\n");
1513 return NS_ERROR_NOT_IMPLEMENTED;
1516 static nsresult NSAPI nsURI_SetPath(nsIWineURI *iface, const nsACString *aPath)
1518 nsURI *This = NSURI_THIS(iface);
1521 nsACString_GetData(aPath, &path);
1522 TRACE("(%p)->(%p(%s))\n", This, aPath, debugstr_a(path));
1525 if(This->wine_url) {
1526 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
1527 DWORD size = sizeof(new_url)/sizeof(WCHAR);
1531 pathw = heap_strdupAtoW(path);
1532 hres = UrlCombineW(This->wine_url, pathw, new_url, &size, 0);
1535 nsIWineURI_SetWineURL(NSWINEURI(This), new_url);
1537 WARN("UrlCombine failed: %08x\n", hres);
1543 return nsIURI_SetPath(This->uri, aPath);
1546 static nsresult NSAPI nsURI_Equals(nsIWineURI *iface, nsIURI *other, PRBool *_retval)
1548 nsURI *This = NSURI_THIS(iface);
1549 nsIWineURI *wine_uri;
1550 LPCWSTR other_url = NULL;
1553 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1556 return nsIURI_Equals(This->uri, other, _retval);
1558 nsres = nsIURI_QueryInterface(other, &IID_nsIWineURI, (void**)&wine_uri);
1559 if(NS_FAILED(nsres)) {
1560 TRACE("Could not get nsIWineURI interface\n");
1565 nsIWineURI_GetWineURL(wine_uri, &other_url);
1566 *_retval = !UrlCompareW(This->wine_url, other_url, TRUE);
1567 nsIWineURI_Release(wine_uri);
1572 static nsresult NSAPI nsURI_SchemeIs(nsIWineURI *iface, const char *scheme, PRBool *_retval)
1574 nsURI *This = NSURI_THIS(iface);
1576 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1578 if(This->use_wine_url) {
1579 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
1580 int len = MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR))-1;
1582 *_retval = strlenW(This->wine_url) > len
1583 && This->wine_url[len] == ':'
1584 && !memcmp(buf, This->wine_url, len*sizeof(WCHAR));
1589 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1591 TRACE("returning error\n");
1592 return NS_ERROR_NOT_IMPLEMENTED;
1595 static nsresult NSAPI nsURI_Clone(nsIWineURI *iface, nsIURI **_retval)
1597 nsURI *This = NSURI_THIS(iface);
1598 nsIURI *nsuri = NULL;
1599 nsIWineURI *wine_uri;
1602 TRACE("(%p)->(%p)\n", This, _retval);
1605 nsres = nsIURI_Clone(This->uri, &nsuri);
1606 if(NS_FAILED(nsres)) {
1607 WARN("Clone failed: %08x\n", nsres);
1612 nsres = create_uri(nsuri, This->container, &wine_uri);
1613 if(NS_FAILED(nsres)) {
1614 WARN("create_uri failed: %08x\n", nsres);
1618 *_retval = (nsIURI*)wine_uri;
1619 return nsIWineURI_SetWineURL(wine_uri, This->wine_url);
1622 static nsresult NSAPI nsURI_Resolve(nsIWineURI *iface, const nsACString *arelativePath,
1623 nsACString *_retval)
1625 nsURI *This = NSURI_THIS(iface);
1627 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1630 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1632 FIXME("default action not implemented\n");
1633 return NS_ERROR_NOT_IMPLEMENTED;
1636 static nsresult NSAPI nsURI_GetAsciiSpec(nsIWineURI *iface, nsACString *aAsciiSpec)
1638 nsURI *This = NSURI_THIS(iface);
1640 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1642 if(This->use_wine_url)
1643 return nsIURI_GetSpec(NSURI(This), aAsciiSpec);
1646 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1648 TRACE("returning error\n");
1649 return NS_ERROR_NOT_IMPLEMENTED;
1652 static nsresult NSAPI nsURI_GetAsciiHost(nsIWineURI *iface, nsACString *aAsciiHost)
1654 nsURI *This = NSURI_THIS(iface);
1656 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1659 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1661 FIXME("default action not implemented\n");
1662 return NS_ERROR_NOT_IMPLEMENTED;
1665 static nsresult NSAPI nsURI_GetOriginCharset(nsIWineURI *iface, nsACString *aOriginCharset)
1667 nsURI *This = NSURI_THIS(iface);
1669 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1672 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1674 FIXME("default action not implemented\n");
1675 return NS_ERROR_NOT_IMPLEMENTED;
1678 static nsresult NSAPI nsURI_GetNSContainer(nsIWineURI *iface, NSContainer **aContainer)
1680 nsURI *This = NSURI_THIS(iface);
1682 TRACE("(%p)->(%p)\n", This, aContainer);
1685 nsIWebBrowserChrome_AddRef(NSWBCHROME(This->container));
1686 *aContainer = This->container;
1691 static nsresult NSAPI nsURI_SetNSContainer(nsIWineURI *iface, NSContainer *aContainer)
1693 nsURI *This = NSURI_THIS(iface);
1695 TRACE("(%p)->(%p)\n", This, aContainer);
1697 if(This->container) {
1698 if(This->container == aContainer)
1700 TRACE("Changing %p -> %p\n", This->container, aContainer);
1701 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1705 nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer));
1706 This->container = aContainer;
1711 static nsresult NSAPI nsURI_GetIsDocumentURI(nsIWineURI *iface, PRBool *aIsDocumentURI)
1713 nsURI *This = NSURI_THIS(iface);
1715 TRACE("(%p)->(%p)\n", This, aIsDocumentURI);
1717 *aIsDocumentURI = This->is_doc_uri;
1721 static nsresult NSAPI nsURI_SetIsDocumentURI(nsIWineURI *iface, PRBool aIsDocumentURI)
1723 nsURI *This = NSURI_THIS(iface);
1725 TRACE("(%p)->(%x)\n", This, aIsDocumentURI);
1727 This->is_doc_uri = aIsDocumentURI;
1731 static nsresult NSAPI nsURI_GetWineURL(nsIWineURI *iface, LPCWSTR *aURL)
1733 nsURI *This = NSURI_THIS(iface);
1735 TRACE("(%p)->(%p)\n", This, aURL);
1737 *aURL = This->wine_url;
1741 static nsresult NSAPI nsURI_SetWineURL(nsIWineURI *iface, LPCWSTR aURL)
1743 nsURI *This = NSURI_THIS(iface);
1745 static const WCHAR wszFtp[] = {'f','t','p',':'};
1746 static const WCHAR wszHttp[] = {'h','t','t','p',':'};
1747 static const WCHAR wszHttps[] = {'h','t','t','p','s',':'};
1749 TRACE("(%p)->(%s)\n", This, debugstr_w(aURL));
1751 heap_free(This->wine_url);
1754 int len = strlenW(aURL)+1;
1755 This->wine_url = heap_alloc(len*sizeof(WCHAR));
1756 memcpy(This->wine_url, aURL, len*sizeof(WCHAR));
1758 /* FIXME: Always use wine url */
1759 This->use_wine_url =
1760 strncmpW(aURL, wszFtp, sizeof(wszFtp)/sizeof(WCHAR))
1761 && strncmpW(aURL, wszHttp, sizeof(wszHttp)/sizeof(WCHAR))
1762 && strncmpW(aURL, wszHttps, sizeof(wszHttps)/sizeof(WCHAR));
1764 This->wine_url = NULL;
1765 This->use_wine_url = FALSE;
1773 static const nsIWineURIVtbl nsWineURIVtbl = {
1774 nsURI_QueryInterface,
1802 nsURI_GetOriginCharset,
1803 nsURI_GetNSContainer,
1804 nsURI_SetNSContainer,
1805 nsURI_GetIsDocumentURI,
1806 nsURI_SetIsDocumentURI,
1811 static nsresult create_uri(nsIURI *uri, NSContainer *container, nsIWineURI **_retval)
1813 nsURI *ret = heap_alloc(sizeof(nsURI));
1815 ret->lpWineURIVtbl = &nsWineURIVtbl;
1818 ret->container = container;
1819 ret->wine_url = NULL;
1820 ret->is_doc_uri = FALSE;
1821 ret->use_wine_url = FALSE;
1824 nsIWebBrowserChrome_AddRef(NSWBCHROME(container));
1826 TRACE("retval=%p\n", ret);
1827 *_retval = NSWINEURI(ret);
1832 const nsIProtocolHandlerVtbl *lpProtocolHandlerVtbl;
1836 nsIProtocolHandler *nshandler;
1837 } nsProtocolHandler;
1839 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
1841 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
1843 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
1846 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1850 if(IsEqualGUID(&IID_nsISupports, riid)) {
1851 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1852 *result = NSPROTHANDLER(This);
1853 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
1854 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
1855 *result = NSPROTHANDLER(This);
1856 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
1857 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
1858 return NS_NOINTERFACE;
1862 nsISupports_AddRef((nsISupports*)*result);
1866 WARN("(%s %p)\n", debugstr_guid(riid), result);
1867 return NS_NOINTERFACE;
1870 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
1872 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1873 LONG ref = InterlockedIncrement(&This->ref);
1875 TRACE("(%p) ref=%d\n", This, ref);
1880 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
1882 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1883 LONG ref = InterlockedDecrement(&This->ref);
1885 TRACE("(%p) ref=%d\n", This, ref);
1889 nsIProtocolHandler_Release(This->nshandler);
1896 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
1898 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1900 TRACE("(%p)->(%p)\n", This, aScheme);
1903 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
1904 return NS_ERROR_NOT_IMPLEMENTED;
1907 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
1908 PRInt32 *aDefaultPort)
1910 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1912 TRACE("(%p)->(%p)\n", This, aDefaultPort);
1915 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
1916 return NS_ERROR_NOT_IMPLEMENTED;
1919 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
1920 PRUint32 *aProtocolFlags)
1922 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1924 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
1927 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
1928 return NS_ERROR_NOT_IMPLEMENTED;
1931 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
1932 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
1934 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1936 TRACE("((%p)->%p %s %p %p)\n", This, aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
1939 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
1940 return NS_ERROR_NOT_IMPLEMENTED;
1943 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
1944 nsIURI *aURI, nsIChannel **_retval)
1946 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1948 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
1951 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
1952 return NS_ERROR_NOT_IMPLEMENTED;
1955 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
1956 PRInt32 port, const char *scheme, PRBool *_retval)
1958 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1960 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
1963 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
1964 return NS_ERROR_NOT_IMPLEMENTED;
1967 #undef NSPROTHANDLER_THIS
1969 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
1970 nsProtocolHandler_QueryInterface,
1971 nsProtocolHandler_AddRef,
1972 nsProtocolHandler_Release,
1973 nsProtocolHandler_GetScheme,
1974 nsProtocolHandler_GetDefaultPort,
1975 nsProtocolHandler_GetProtocolFlags,
1976 nsProtocolHandler_NewURI,
1977 nsProtocolHandler_NewChannel,
1978 nsProtocolHandler_AllowPort
1981 static nsIProtocolHandler *create_protocol_handler(nsIProtocolHandler *nshandler)
1983 nsProtocolHandler *ret = heap_alloc(sizeof(nsProtocolHandler));
1985 ret->lpProtocolHandlerVtbl = &nsProtocolHandlerVtbl;
1987 ret->nshandler = nshandler;
1989 return NSPROTHANDLER(ret);
1992 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,nsQIResult);
1994 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
1999 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
2004 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
2005 nsIProtocolHandler **_retval)
2007 nsIExternalProtocolHandler *nsexthandler;
2008 nsIProtocolHandler *nshandler;
2011 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2013 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
2014 if(NS_FAILED(nsres)) {
2015 WARN("GetProtocolHandler failed: %08x\n", nsres);
2019 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
2020 (void**)&nsexthandler);
2021 if(NS_FAILED(nsres)) {
2022 *_retval = nshandler;
2026 nsIExternalProtocolHandler_Release(nsexthandler);
2027 *_retval = create_protocol_handler(nshandler);
2028 TRACE("return %p\n", *_retval);
2032 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
2035 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2036 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
2039 static BOOL is_gecko_special_uri(const char *spec)
2041 static const char chromeW[] = "chrome:";
2042 static const char jarW[] = "jar:";
2043 static const char resourceW[] = "resource:";
2044 static const char javascriptW[] = "javascript:";
2046 return !strncasecmp(spec, chromeW, sizeof(chromeW)-1)
2047 || !strncasecmp(spec, resourceW, sizeof(resourceW)-1)
2048 || !strncasecmp(spec, jarW, sizeof(jarW)-1)
2049 || !strncasecmp(spec, javascriptW, sizeof(javascriptW)-1);
2052 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
2053 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2055 const char *spec = NULL;
2056 nsACString spec_str;
2057 NSContainer *nscontainer = NULL;
2059 LPCWSTR base_wine_url = NULL;
2060 nsIWineURI *base_wine_uri = NULL, *wine_uri;
2061 BOOL is_wine_uri = FALSE;
2064 nsACString_GetData(aSpec, &spec);
2066 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
2069 if(is_gecko_special_uri(spec))
2070 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2072 if(!strncmp(spec, "wine:", 5)) {
2078 nsACString base_uri_str;
2079 const char *base_uri = NULL;
2081 nsACString_Init(&base_uri_str, NULL);
2083 nsres = nsIURI_GetSpec(aBaseURI, &base_uri_str);
2084 if(NS_SUCCEEDED(nsres)) {
2085 nsACString_GetData(&base_uri_str, &base_uri);
2086 TRACE("base_uri=%s\n", debugstr_a(base_uri));
2088 ERR("GetSpec failed: %08x\n", nsres);
2091 nsACString_Finish(&base_uri_str);
2094 nsACString_Init(&spec_str, spec);
2095 nsres = nsIIOService_NewURI(nsio, &spec_str, aOriginCharset, aBaseURI, &uri);
2096 nsACString_Finish(&spec_str);
2097 if(NS_FAILED(nsres))
2098 TRACE("NewURI failed: %08x\n", nsres);
2101 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsIWineURI, (void**)&base_wine_uri);
2102 if(NS_SUCCEEDED(nsres)) {
2103 nsIWineURI_GetNSContainer(base_wine_uri, &nscontainer);
2104 nsIWineURI_GetWineURL(base_wine_uri, &base_wine_url);
2106 TRACE("Could not get base nsIWineURI: %08x\n", nsres);
2110 TRACE("nscontainer = %p\n", nscontainer);
2112 nsres = create_uri(uri, nscontainer, &wine_uri);
2113 *_retval = (nsIURI*)wine_uri;
2116 nsIWebBrowserChrome_Release(NSWBCHROME(nscontainer));
2119 WCHAR url[INTERNET_MAX_URL_LENGTH], rel_url[INTERNET_MAX_URL_LENGTH];
2123 MultiByteToWideChar(CP_ACP, 0, spec, -1, rel_url, sizeof(rel_url)/sizeof(WCHAR));
2125 hres = CoInternetCombineUrl(base_wine_url, rel_url,
2126 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
2127 url, sizeof(url)/sizeof(WCHAR), &len, 0);
2129 nsIWineURI_SetWineURL(wine_uri, url);
2131 WARN("CoCombineUrl failed: %08x\n", hres);
2132 }else if(is_wine_uri) {
2133 WCHAR url[INTERNET_MAX_URL_LENGTH];
2135 MultiByteToWideChar(CP_ACP, 0, spec, -1, url, sizeof(url)/sizeof(WCHAR));
2136 nsIWineURI_SetWineURL(wine_uri, url);
2140 nsIWineURI_Release(base_wine_uri);
2145 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
2148 TRACE("(%p %p)\n", aFile, _retval);
2149 return nsIIOService_NewFileURI(nsio, aFile, _retval);
2152 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
2153 nsIChannel **_retval)
2155 nsIChannel *channel = NULL;
2157 nsIWineURI *wine_uri;
2160 TRACE("(%p %p)\n", aURI, _retval);
2162 nsres = nsIIOService_NewChannelFromURI(nsio, aURI, &channel);
2163 if(NS_FAILED(nsres) && nsres != NS_ERROR_UNKNOWN_PROTOCOL) {
2164 WARN("NewChannelFromURI failed: %08x\n", nsres);
2169 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
2170 if(NS_FAILED(nsres)) {
2171 WARN("Could not get nsIWineURI: %08x\n", nsres);
2173 return channel ? NS_OK : NS_ERROR_UNEXPECTED;
2176 ret = heap_alloc(sizeof(nsChannel));
2178 ret->lpHttpChannelVtbl = &nsChannelVtbl;
2179 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
2181 ret->channel = channel;
2182 ret->http_channel = NULL;
2183 ret->uri = wine_uri;
2184 ret->post_data_stream = NULL;
2185 ret->load_group = NULL;
2186 ret->notif_callback = NULL;
2187 ret->load_flags = 0;
2188 ret->content = NULL;
2189 ret->charset = NULL;
2191 nsIURI_AddRef(aURI);
2192 ret->original_uri = aURI;
2195 nsIChannel_QueryInterface(channel, &IID_nsIHttpChannel, (void**)&ret->http_channel);
2197 *_retval = NSCHANNEL(ret);
2201 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
2202 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
2204 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2205 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2208 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
2210 TRACE("(%p)\n", aOffline);
2211 return nsIIOService_GetOffline(nsio, aOffline);
2214 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
2216 TRACE("(%x)\n", aOffline);
2217 return nsIIOService_SetOffline(nsio, aOffline);
2220 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
2221 const char *aScheme, PRBool *_retval)
2223 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
2224 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
2227 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
2228 nsACString * _retval)
2230 TRACE("(%p %p)\n", urlString, _retval);
2231 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
2234 static const nsIIOServiceVtbl nsIOServiceVtbl = {
2235 nsIOService_QueryInterface,
2237 nsIOService_Release,
2238 nsIOService_GetProtocolHandler,
2239 nsIOService_GetProtocolFlags,
2241 nsIOService_NewFileURI,
2242 nsIOService_NewChannelFromURI,
2243 nsIOService_NewChannel,
2244 nsIOService_GetOffline,
2245 nsIOService_SetOffline,
2246 nsIOService_AllowPort,
2247 nsIOService_ExtractScheme
2250 static nsIIOService nsIOService = { &nsIOServiceVtbl };
2252 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
2255 return nsIIOService_QueryInterface(&nsIOService, riid, result);
2258 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
2263 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
2268 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2269 nsACString *aCharset, PRBool *aHadCharset, nsACString *aContentType)
2271 nsINetUtil *net_util;
2274 TRACE("(%p %p %p %p)\n", aTypeHeader, aCharset, aHadCharset, aContentType);
2276 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
2277 if(NS_FAILED(nsres)) {
2278 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
2282 nsres = nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
2284 nsINetUtil_Release(net_util);
2288 static const nsINetUtilVtbl nsNetUtilVtbl = {
2289 nsNetUtil_QueryInterface,
2292 nsNetUtil_ParseContentType
2295 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
2297 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
2302 if(IsEqualGUID(&IID_nsISupports, riid))
2303 *result = &nsIOService;
2304 else if(IsEqualGUID(&IID_nsIIOService, riid))
2305 *result = &nsIOService;
2306 else if(IsEqualGUID(&IID_nsINetUtil, riid))
2307 *result = &nsNetUtil;
2310 nsISupports_AddRef((nsISupports*)*result);
2314 FIXME("(%s %p)\n", debugstr_guid(riid), result);
2315 return NS_NOINTERFACE;
2318 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
2323 if(IsEqualGUID(&IID_nsISupports, riid)) {
2324 TRACE("(IID_nsISupports %p)\n", result);
2326 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
2327 TRACE("(IID_nsIFactory %p)\n", result);
2332 nsIFactory_AddRef(iface);
2336 WARN("(%s %p)\n", debugstr_guid(riid), result);
2337 return NS_NOINTERFACE;
2340 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
2345 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
2350 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
2351 nsISupports *aOuter, const nsIID *iid, void **result)
2353 return nsIIOService_QueryInterface(&nsIOService, iid, result);
2356 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
2358 WARN("(%x)\n", lock);
2362 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
2363 nsIOServiceFactory_QueryInterface,
2364 nsIOServiceFactory_AddRef,
2365 nsIOServiceFactory_Release,
2366 nsIOServiceFactory_CreateInstance,
2367 nsIOServiceFactory_LockFactory
2370 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
2372 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
2374 nsIFactory *old_factory = NULL;
2377 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
2378 &IID_nsIFactory, (void**)&old_factory);
2379 if(NS_FAILED(nsres)) {
2380 ERR("Could not get factory: %08x\n", nsres);
2384 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
2385 if(NS_FAILED(nsres)) {
2386 ERR("Couldn not create nsIOService instance %08x\n", nsres);
2387 nsIFactory_Release(old_factory);
2391 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
2392 nsIFactory_Release(old_factory);
2393 if(NS_FAILED(nsres))
2394 ERR("UnregisterFactory failed: %08x\n", nsres);
2396 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
2397 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
2398 if(NS_FAILED(nsres))
2399 ERR("RegisterFactory failed: %08x\n", nsres);