wined3d: Fix a "ordered comparison of pointer with integer zero".
[wine/gsoc_dplay.git] / dlls / mshtml / nsio.c
blob72ad814a1cbbbdf6e7456927a6757118d4b1264a
1 /*
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
19 #include "config.h"
21 #include <stdarg.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "ole2.h"
30 #include "shlguid.h"
31 #include "wininet.h"
32 #include "shlwapi.h"
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 typedef struct {
52 const nsIWineURIVtbl *lpWineURIVtbl;
54 LONG ref;
56 nsIURI *uri;
57 NSContainer *container;
58 LPWSTR wine_url;
59 PRBool is_doc_uri;
60 BOOL use_wine_url;
61 } nsURI;
63 #define NSURI(x) ((nsIURI*) &(x)->lpWineURIVtbl)
64 #define NSWINEURI(x) ((nsIWineURI*) &(x)->lpWineURIVtbl)
66 static nsresult create_uri(nsIURI*,NSContainer*,nsIWineURI**);
68 static BOOL exec_shldocvw_67(HTMLDocument *doc, LPCWSTR url)
70 IOleCommandTarget *cmdtrg = NULL;
71 HRESULT hres;
73 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget,
74 (void**)&cmdtrg);
75 if(SUCCEEDED(hres)) {
76 VARIANT varUrl, varRes;
78 V_VT(&varUrl) = VT_BSTR;
79 V_BSTR(&varUrl) = SysAllocString(url);
80 V_VT(&varRes) = VT_BOOL;
82 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
84 IOleCommandTarget_Release(cmdtrg);
85 SysFreeString(V_BSTR(&varUrl));
87 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
88 TRACE("got VARIANT_FALSE, do not load\n");
89 return FALSE;
93 return TRUE;
96 static BOOL before_async_open(nsChannel *channel, NSContainer *container)
98 IServiceProvider *service_provider;
99 HTMLDocument *doc = container->doc;
100 DWORD hlnf = 0;
101 LPCWSTR uri;
102 HRESULT hres;
104 nsIWineURI_GetWineURL(channel->uri, &uri);
105 if(!uri) {
106 ERR("GetWineURL returned NULL\n");
107 return TRUE;
110 if(!doc) {
111 NSContainer *container_iter = container;
113 hlnf = HLNF_OPENINNEWWINDOW;
114 while(!container_iter->doc)
115 container_iter = container_iter->parent;
116 doc = container_iter->doc;
119 if(!hlnf && !exec_shldocvw_67(doc, uri))
120 return FALSE;
122 hres = IOleClientSite_QueryInterface(doc->client, &IID_IServiceProvider,
123 (void**)&service_provider);
124 if(SUCCEEDED(hres)) {
125 IHlinkFrame *hlink_frame;
127 hres = IServiceProvider_QueryService(service_provider, &IID_IHlinkFrame,
128 &IID_IHlinkFrame, (void**)&hlink_frame);
129 IServiceProvider_Release(service_provider);
130 if(SUCCEEDED(hres)) {
131 hlink_frame_navigate(doc, hlink_frame, uri, channel->post_data_stream, hlnf);
132 IHlinkFrame_Release(hlink_frame);
134 return FALSE;
138 return TRUE;
141 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
143 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
145 nsChannel *This = NSCHANNEL_THIS(iface);
147 *result = NULL;
149 if(IsEqualGUID(&IID_nsISupports, riid)) {
150 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
151 *result = NSCHANNEL(This);
152 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
153 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
154 *result = NSCHANNEL(This);
155 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
156 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
157 *result = NSCHANNEL(This);
158 }else if(This->http_channel && IsEqualGUID(&IID_nsIHttpChannel, riid)) {
159 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
160 *result = NSHTTPCHANNEL(This);
161 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
162 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
163 *result = NSUPCHANNEL(This);
166 if(*result) {
167 nsIChannel_AddRef(NSCHANNEL(This));
168 return NS_OK;
171 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
173 if(This->channel)
174 return nsIChannel_QueryInterface(This->channel, riid, result);
175 return NS_NOINTERFACE;
178 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
180 nsChannel *This = NSCHANNEL_THIS(iface);
181 nsrefcnt ref = InterlockedIncrement(&This->ref);
183 TRACE("(%p) ref=%d\n", This, ref);
185 return ref;
188 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
190 nsChannel *This = NSCHANNEL_THIS(iface);
191 LONG ref = InterlockedDecrement(&This->ref);
193 if(!ref) {
194 nsIWineURI_Release(This->uri);
195 if(This->channel)
196 nsIChannel_Release(This->channel);
197 if(This->http_channel)
198 nsIHttpChannel_Release(This->http_channel);
199 if(This->post_data_stream)
200 nsIInputStream_Release(This->post_data_stream);
201 if(This->load_group)
202 nsILoadGroup_Release(This->load_group);
203 if(This->notif_callback)
204 nsIInterfaceRequestor_Release(This->notif_callback);
205 if(This->original_uri)
206 nsIURI_Release(This->original_uri);
207 heap_free(This->content);
208 heap_free(This->charset);
209 heap_free(This);
212 return ref;
215 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
217 nsChannel *This = NSCHANNEL_THIS(iface);
219 TRACE("(%p)->(%p)\n", This, aName);
221 if(This->channel)
222 return nsIChannel_GetName(This->channel, aName);
224 return NS_ERROR_NOT_IMPLEMENTED;
227 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
229 nsChannel *This = NSCHANNEL_THIS(iface);
231 TRACE("(%p)->(%p)\n", This, _retval);
233 if(This->channel)
234 return nsIChannel_IsPending(This->channel, _retval);
236 FIXME("default action not implemented\n");
237 return NS_ERROR_NOT_IMPLEMENTED;
240 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
242 nsChannel *This = NSCHANNEL_THIS(iface);
244 TRACE("(%p)->(%p)\n", This, aStatus);
246 if(This->channel)
247 return nsIChannel_GetStatus(This->channel, aStatus);
249 TRACE("returning NS_OK\n");
250 return *aStatus = NS_OK;
253 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
255 nsChannel *This = NSCHANNEL_THIS(iface);
257 TRACE("(%p)->(%08x)\n", This, aStatus);
259 if(This->channel)
260 return nsIChannel_Cancel(This->channel, aStatus);
262 FIXME("default action not implemented\n");
263 return NS_ERROR_NOT_IMPLEMENTED;
266 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
268 nsChannel *This = NSCHANNEL_THIS(iface);
270 TRACE("(%p)\n", This);
272 if(This->channel)
273 return nsIChannel_Suspend(This->channel);
275 FIXME("default action not implemented\n");
276 return NS_ERROR_NOT_IMPLEMENTED;
279 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
281 nsChannel *This = NSCHANNEL_THIS(iface);
283 TRACE("(%p)\n", This);
285 if(This->channel)
286 return nsIChannel_Resume(This->channel);
288 FIXME("default action not implemented\n");
289 return NS_ERROR_NOT_IMPLEMENTED;
292 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
294 nsChannel *This = NSCHANNEL_THIS(iface);
296 TRACE("(%p)->(%p)\n", This, aLoadGroup);
298 if(This->load_group)
299 nsILoadGroup_AddRef(This->load_group);
301 *aLoadGroup = This->load_group;
302 return NS_OK;
305 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
307 nsChannel *This = NSCHANNEL_THIS(iface);
309 TRACE("(%p)->(%p)\n", This, aLoadGroup);
311 if(This->load_group)
312 nsILoadGroup_Release(This->load_group);
313 if(aLoadGroup)
314 nsILoadGroup_AddRef(aLoadGroup);
316 This->load_group = aLoadGroup;
318 if(This->channel)
319 return nsIChannel_SetLoadGroup(This->channel, aLoadGroup);
320 return NS_OK;
323 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
325 nsChannel *This = NSCHANNEL_THIS(iface);
327 TRACE("(%p)->(%p)\n", This, aLoadFlags);
329 *aLoadFlags = This->load_flags;
330 return NS_OK;
333 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
335 nsChannel *This = NSCHANNEL_THIS(iface);
337 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
339 This->load_flags = aLoadFlags;
341 if(This->channel)
342 return nsIChannel_SetLoadFlags(This->channel, aLoadFlags);
343 return NS_OK;
346 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
348 nsChannel *This = NSCHANNEL_THIS(iface);
350 TRACE("(%p)->(%p)\n", This, aOriginalURI);
352 if(This->original_uri)
353 nsIURI_AddRef(This->original_uri);
355 *aOriginalURI = This->original_uri;
356 return NS_OK;
359 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
361 nsChannel *This = NSCHANNEL_THIS(iface);
363 TRACE("(%p)->(%p)\n", This, aOriginalURI);
365 if(This->original_uri)
366 nsIURI_Release(This->original_uri);
368 nsIURI_AddRef(aOriginalURI);
369 This->original_uri = aOriginalURI;
371 if(This->channel)
372 return nsIChannel_SetOriginalURI(This->channel, aOriginalURI);
373 return NS_OK;
376 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
378 nsChannel *This = NSCHANNEL_THIS(iface);
380 TRACE("(%p)->(%p)\n", This, aURI);
382 nsIWineURI_AddRef(This->uri);
383 *aURI = (nsIURI*)This->uri;
385 return NS_OK;
388 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
390 nsChannel *This = NSCHANNEL_THIS(iface);
392 TRACE("(%p)->(%p)\n", This, aOwner);
394 if(This->channel)
395 return nsIChannel_GetOwner(This->channel, aOwner);
397 FIXME("default action not implemented\n");
398 return NS_ERROR_NOT_IMPLEMENTED;
401 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
403 nsChannel *This = NSCHANNEL_THIS(iface);
405 TRACE("(%p)->(%p)\n", This, aOwner);
407 if(This->channel)
408 return nsIChannel_SetOwner(This->channel, aOwner);
410 FIXME("default action not implemented\n");
411 return NS_ERROR_NOT_IMPLEMENTED;
414 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
415 nsIInterfaceRequestor **aNotificationCallbacks)
417 nsChannel *This = NSCHANNEL_THIS(iface);
419 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
421 if(This->notif_callback)
422 nsIInterfaceRequestor_AddRef(This->notif_callback);
423 *aNotificationCallbacks = This->notif_callback;
425 return NS_OK;
428 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
429 nsIInterfaceRequestor *aNotificationCallbacks)
431 nsChannel *This = NSCHANNEL_THIS(iface);
433 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
435 if(This->notif_callback)
436 nsIInterfaceRequestor_Release(This->notif_callback);
437 if(aNotificationCallbacks)
438 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
440 This->notif_callback = aNotificationCallbacks;
442 if(This->channel)
443 return nsIChannel_SetNotificationCallbacks(This->channel, aNotificationCallbacks);
444 return NS_OK;
447 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
449 nsChannel *This = NSCHANNEL_THIS(iface);
451 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
453 if(This->channel)
454 return nsIChannel_GetSecurityInfo(This->channel, aSecurityInfo);
456 FIXME("default action not implemented\n");
457 return NS_ERROR_NOT_IMPLEMENTED;
460 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
462 nsChannel *This = NSCHANNEL_THIS(iface);
464 TRACE("(%p)->(%p)\n", This, aContentType);
466 if(This->content) {
467 nsACString_SetData(aContentType, This->content);
468 return S_OK;
471 if(This->channel)
472 return nsIChannel_GetContentType(This->channel, aContentType);
474 TRACE("returning default text/html\n");
475 nsACString_SetData(aContentType, "text/html");
476 return NS_OK;
479 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
480 const nsACString *aContentType)
482 nsChannel *This = NSCHANNEL_THIS(iface);
484 TRACE("(%p)->(%p)\n", This, aContentType);
486 if(This->channel)
487 return nsIChannel_SetContentType(This->channel, aContentType);
489 FIXME("default action not implemented\n");
490 return NS_ERROR_NOT_IMPLEMENTED;
493 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
494 nsACString *aContentCharset)
496 nsChannel *This = NSCHANNEL_THIS(iface);
498 TRACE("(%p)->(%p)\n", This, aContentCharset);
500 if(This->charset) {
501 nsACString_SetData(aContentCharset, This->charset);
502 return NS_OK;
505 if(This->channel) {
506 nsresult nsres = nsIChannel_GetContentCharset(This->channel, aContentCharset);
507 const char *ch;
508 nsACString_GetData(aContentCharset, &ch, NULL);
509 return nsres;
512 nsACString_SetData(aContentCharset, "");
513 return NS_OK;
516 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
517 const nsACString *aContentCharset)
519 nsChannel *This = NSCHANNEL_THIS(iface);
521 TRACE("(%p)->(%p)\n", This, aContentCharset);
523 if(This->channel)
524 return nsIChannel_SetContentCharset(This->channel, aContentCharset);
526 FIXME("default action not implemented\n");
527 return NS_ERROR_NOT_IMPLEMENTED;
530 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
532 nsChannel *This = NSCHANNEL_THIS(iface);
534 TRACE("(%p)->(%p)\n", This, aContentLength);
536 if(This->channel)
537 return nsIChannel_GetContentLength(This->channel, aContentLength);
539 FIXME("default action not implemented\n");
540 return NS_ERROR_NOT_IMPLEMENTED;
543 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
545 nsChannel *This = NSCHANNEL_THIS(iface);
547 TRACE("(%p)->(%d)\n", This, aContentLength);
549 if(This->channel)
550 return nsIChannel_SetContentLength(This->channel, aContentLength);
552 FIXME("default action not implemented\n");
553 return NS_ERROR_NOT_IMPLEMENTED;
556 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
558 nsChannel *This = NSCHANNEL_THIS(iface);
560 TRACE("(%p)->(%p)\n", This, _retval);
562 if(This->channel)
563 return nsIChannel_Open(This->channel, _retval);
565 FIXME("default action not implemented\n");
566 return NS_ERROR_NOT_IMPLEMENTED;
569 static BOOL do_load_from_moniker_hack(nsChannel *This)
571 nsACString scheme_str;
572 nsresult nsres;
573 BOOL ret = TRUE;
576 * We should always load the page from IMoniker, but Wine is not yet
577 * ready for this. This function is a heuristic, that decides which
578 * way of loading is better (Gecko implementation or IMoniker). The
579 * aim is to always return TRUE.
582 /* Load from moniker if there is no Gecko channel available */
583 if(!This->channel)
584 return TRUE;
586 nsACString_Init(&scheme_str, NULL);
587 nsres = nsIWineURI_GetScheme(This->uri, &scheme_str);
589 if(NS_SUCCEEDED(nsres)) {
590 const char *scheme;
592 nsACString_GetData(&scheme_str, &scheme, NULL);
593 ret = !strcmp(scheme, "wine");
596 nsACString_Finish(&scheme_str);
597 return ret;
600 static HRESULT create_mon_for_nschannel(nsChannel *channel, IMoniker **mon)
602 nsIWineURI *wine_uri;
603 LPCWSTR wine_url;
604 nsresult nsres;
605 HRESULT hres;
607 if(!channel->original_uri) {
608 ERR("original_uri == NULL\n");
609 return E_FAIL;
612 nsres = nsIURI_QueryInterface(channel->original_uri, &IID_nsIWineURI, (void**)&wine_uri);
613 if(NS_FAILED(nsres)) {
614 ERR("Could not get nsIWineURI: %08x\n", nsres);
615 return E_FAIL;
618 nsIWineURI_GetWineURL(wine_uri, &wine_url);
619 nsIWineURI_Release(wine_uri);
620 if(!wine_url) {
621 TRACE("wine_url == NULL\n");
622 return E_FAIL;
625 hres = CreateURLMoniker(NULL, wine_url, mon);
626 if(FAILED(hres))
627 WARN("CreateURLMonikrer failed: %08x\n", hres);
629 return hres;
632 static nsresult async_open_doc_uri(nsChannel *This, NSContainer *container,
633 nsIStreamListener *listener, nsISupports *context, BOOL *open)
635 IMoniker *mon;
636 HRESULT hres;
638 *open = FALSE;
640 if(container->bscallback) {
641 nsIChannel_AddRef(NSCHANNEL(This));
642 container->bscallback->nschannel = This;
644 nsIStreamListener_AddRef(listener);
645 container->bscallback->nslistener = listener;
647 if(context) {
648 nsISupports_AddRef(context);
649 container->bscallback->nscontext = context;
652 if(do_load_from_moniker_hack(This))
653 return WINE_NS_LOAD_FROM_MONIKER;
654 }else {
655 BOOL cont = before_async_open(This, container);
657 if(!cont) {
658 TRACE("canceled\n");
659 return NS_ERROR_UNEXPECTED;
662 if(!container->doc) {
663 return This->channel
664 ? nsIChannel_AsyncOpen(This->channel, listener, context)
665 : NS_ERROR_UNEXPECTED;
668 hres = create_mon_for_nschannel(This, &mon);
669 if(FAILED(hres)) {
670 return NS_ERROR_UNEXPECTED;
672 set_current_mon(container->doc, mon);
675 *open = TRUE;
676 return NS_OK;
679 static nsresult async_open(nsChannel *This, NSContainer *container, nsIStreamListener *listener,
680 nsISupports *context)
682 BSCallback *bscallback;
683 IMoniker *mon = NULL;
684 nsresult nsres;
685 task_t *task;
686 HRESULT hres;
688 if(This->channel) {
689 if(This->post_data_stream) {
690 nsIUploadChannel *upload_channel;
692 nsres = nsIChannel_QueryInterface(This->channel, &IID_nsIUploadChannel,
693 (void**)&upload_channel);
694 if(NS_SUCCEEDED(nsres)) {
695 nsACString empty_string;
696 nsACString_Init(&empty_string, "");
698 nsres = nsIUploadChannel_SetUploadStream(upload_channel, This->post_data_stream,
699 &empty_string, -1);
700 nsIUploadChannel_Release(upload_channel);
701 if(NS_FAILED(nsres))
702 WARN("SetUploadStream failed: %08x\n", nsres);
704 nsACString_Finish(&empty_string);
708 nsres = nsIChannel_AsyncOpen(This->channel, listener, context);
710 if(mon)
711 IMoniker_Release(mon);
713 if(NS_FAILED(nsres) && (This->load_flags & LOAD_INITIAL_DOCUMENT_URI))
714 return WINE_NS_LOAD_FROM_MONIKER;
715 return nsres;
718 TRACE("channel == NULL\n");
720 hres = create_mon_for_nschannel(This, &mon);
721 if(FAILED(hres))
722 return NS_ERROR_UNEXPECTED;
724 bscallback = create_bscallback(mon);
725 IMoniker_Release(mon);
727 nsIChannel_AddRef(NSCHANNEL(This));
728 bscallback->nschannel = This;
730 nsIStreamListener_AddRef(listener);
731 bscallback->nslistener = listener;
733 if(context) {
734 nsISupports_AddRef(context);
735 bscallback->nscontext = context;
738 task = heap_alloc(sizeof(task_t));
740 task->doc = container->doc;
741 task->task_id = TASK_START_BINDING;
742 task->next = NULL;
743 task->bscallback = bscallback;
745 push_task(task);
747 return NS_OK;
750 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
751 nsISupports *aContext)
753 nsChannel *This = NSCHANNEL_THIS(iface);
754 NSContainer *container;
755 PRBool is_doc_uri;
756 BOOL open = TRUE;
757 nsresult nsres = NS_OK;
759 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
761 nsIWineURI_GetNSContainer(This->uri, &container);
762 if(!container) {
763 TRACE("container = NULL\n");
764 return This->channel
765 ? nsIChannel_AsyncOpen(This->channel, aListener, aContext)
766 : NS_ERROR_UNEXPECTED;
769 nsIWineURI_GetIsDocumentURI(This->uri, &is_doc_uri);
771 if(is_doc_uri && (This->load_flags & LOAD_INITIAL_DOCUMENT_URI))
772 nsres = async_open_doc_uri(This, container, aListener, aContext, &open);
774 if(open)
775 nsres = async_open(This, container, aListener, aContext);
777 nsIWebBrowserChrome_Release(NSWBCHROME(container));
778 return nsres;
781 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
783 nsChannel *This = NSCHANNEL_THIS(iface);
785 TRACE("(%p)->(%p)\n", This, aRequestMethod);
787 if(This->http_channel)
788 return nsIHttpChannel_GetRequestMethod(This->http_channel, aRequestMethod);
790 return NS_ERROR_NOT_IMPLEMENTED;
793 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
794 const nsACString *aRequestMethod)
796 nsChannel *This = NSCHANNEL_THIS(iface);
798 TRACE("(%p)->(%p)\n", This, aRequestMethod);
800 if(This->http_channel)
801 return nsIHttpChannel_SetRequestMethod(This->http_channel, aRequestMethod);
803 return NS_ERROR_NOT_IMPLEMENTED;
806 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
808 nsChannel *This = NSCHANNEL_THIS(iface);
810 TRACE("(%p)->(%p)\n", This, aReferrer);
812 if(This->http_channel)
813 return nsIHttpChannel_GetReferrer(This->http_channel, aReferrer);
815 return NS_ERROR_NOT_IMPLEMENTED;
818 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
820 nsChannel *This = NSCHANNEL_THIS(iface);
822 TRACE("(%p)->(%p)\n", This, aReferrer);
824 if(This->http_channel)
825 return nsIHttpChannel_SetReferrer(This->http_channel, aReferrer);
827 return NS_ERROR_NOT_IMPLEMENTED;
830 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
831 const nsACString *aHeader, nsACString *_retval)
833 nsChannel *This = NSCHANNEL_THIS(iface);
835 TRACE("(%p)->(%p %p)\n", This, aHeader, _retval);
837 if(This->http_channel)
838 return nsIHttpChannel_GetRequestHeader(This->http_channel, aHeader, _retval);
840 return NS_ERROR_NOT_IMPLEMENTED;
843 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
844 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
846 nsChannel *This = NSCHANNEL_THIS(iface);
848 TRACE("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
850 if(This->http_channel)
851 return nsIHttpChannel_SetRequestHeader(This->http_channel, aHeader, aValue, aMerge);
853 return NS_ERROR_NOT_IMPLEMENTED;
856 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
857 nsIHttpHeaderVisitor *aVisitor)
859 nsChannel *This = NSCHANNEL_THIS(iface);
861 TRACE("(%p)->(%p)\n", This, aVisitor);
863 if(This->http_channel)
864 return nsIHttpChannel_VisitRequestHeaders(This->http_channel, aVisitor);
866 return NS_ERROR_NOT_IMPLEMENTED;
869 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
871 nsChannel *This = NSCHANNEL_THIS(iface);
873 TRACE("(%p)->(%p)\n", This, aAllowPipelining);
875 if(This->http_channel)
876 return nsIHttpChannel_GetAllowPipelining(This->http_channel, aAllowPipelining);
878 return NS_ERROR_NOT_IMPLEMENTED;
881 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
883 nsChannel *This = NSCHANNEL_THIS(iface);
885 TRACE("(%p)->(%x)\n", This, aAllowPipelining);
887 if(This->http_channel)
888 return nsIHttpChannel_SetAllowPipelining(This->http_channel, aAllowPipelining);
890 return NS_ERROR_NOT_IMPLEMENTED;
893 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
895 nsChannel *This = NSCHANNEL_THIS(iface);
897 TRACE("(%p)->(%p)\n", This, aRedirectionLimit);
899 if(This->http_channel)
900 return nsIHttpChannel_GetRedirectionLimit(This->http_channel, aRedirectionLimit);
902 return NS_ERROR_NOT_IMPLEMENTED;
905 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
907 nsChannel *This = NSCHANNEL_THIS(iface);
909 TRACE("(%p)->(%u)\n", This, aRedirectionLimit);
911 if(This->http_channel)
912 return nsIHttpChannel_SetRedirectionLimit(This->http_channel, aRedirectionLimit);
914 return NS_ERROR_NOT_IMPLEMENTED;
917 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
919 nsChannel *This = NSCHANNEL_THIS(iface);
921 TRACE("(%p)->(%p)\n", This, aResponseStatus);
923 if(This->http_channel)
924 return nsIHttpChannel_GetResponseStatus(This->http_channel, aResponseStatus);
926 return NS_ERROR_NOT_IMPLEMENTED;
929 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
930 nsACString *aResponseStatusText)
932 nsChannel *This = NSCHANNEL_THIS(iface);
934 TRACE("(%p)->(%p)\n", This, aResponseStatusText);
936 if(This->http_channel)
937 return nsIHttpChannel_GetResponseStatusText(This->http_channel, aResponseStatusText);
939 return NS_ERROR_NOT_IMPLEMENTED;
942 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
943 PRBool *aRequestSucceeded)
945 nsChannel *This = NSCHANNEL_THIS(iface);
947 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
949 if(This->http_channel)
950 return nsIHttpChannel_GetRequestSucceeded(This->http_channel, aRequestSucceeded);
952 return NS_ERROR_NOT_IMPLEMENTED;
955 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
956 const nsACString *header, nsACString *_retval)
958 nsChannel *This = NSCHANNEL_THIS(iface);
960 TRACE("(%p)->(%p %p)\n", This, header, _retval);
962 if(This->http_channel)
963 return nsIHttpChannel_GetResponseHeader(This->http_channel, header, _retval);
965 return NS_ERROR_NOT_IMPLEMENTED;
968 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
969 const nsACString *header, const nsACString *value, PRBool merge)
971 nsChannel *This = NSCHANNEL_THIS(iface);
973 TRACE("(%p)->(%p %p %x)\n", This, header, value, merge);
975 if(This->http_channel)
976 return nsIHttpChannel_SetResponseHeader(This->http_channel, header, value, merge);
978 return NS_ERROR_NOT_IMPLEMENTED;
981 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
982 nsIHttpHeaderVisitor *aVisitor)
984 nsChannel *This = NSCHANNEL_THIS(iface);
986 TRACE("(%p)->(%p)\n", This, aVisitor);
988 if(This->http_channel)
989 return nsIHttpChannel_VisitResponseHeaders(This->http_channel, aVisitor);
991 return NS_ERROR_NOT_IMPLEMENTED;
994 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
996 nsChannel *This = NSCHANNEL_THIS(iface);
998 TRACE("(%p)->(%p)\n", This, _retval);
1000 if(This->http_channel)
1001 return nsIHttpChannel_IsNoStoreResponse(This->http_channel, _retval);
1003 return NS_ERROR_NOT_IMPLEMENTED;
1006 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
1008 nsChannel *This = NSCHANNEL_THIS(iface);
1010 TRACE("(%p)->(%p)\n", This, _retval);
1012 if(This->http_channel)
1013 return nsIHttpChannel_IsNoCacheResponse(This->http_channel, _retval);
1015 return NS_ERROR_NOT_IMPLEMENTED;
1018 #undef NSCHANNEL_THIS
1020 static const nsIHttpChannelVtbl nsChannelVtbl = {
1021 nsChannel_QueryInterface,
1022 nsChannel_AddRef,
1023 nsChannel_Release,
1024 nsChannel_GetName,
1025 nsChannel_IsPending,
1026 nsChannel_GetStatus,
1027 nsChannel_Cancel,
1028 nsChannel_Suspend,
1029 nsChannel_Resume,
1030 nsChannel_GetLoadGroup,
1031 nsChannel_SetLoadGroup,
1032 nsChannel_GetLoadFlags,
1033 nsChannel_SetLoadFlags,
1034 nsChannel_GetOriginalURI,
1035 nsChannel_SetOriginalURI,
1036 nsChannel_GetURI,
1037 nsChannel_GetOwner,
1038 nsChannel_SetOwner,
1039 nsChannel_GetNotificationCallbacks,
1040 nsChannel_SetNotificationCallbacks,
1041 nsChannel_GetSecurityInfo,
1042 nsChannel_GetContentType,
1043 nsChannel_SetContentType,
1044 nsChannel_GetContentCharset,
1045 nsChannel_SetContentCharset,
1046 nsChannel_GetContentLength,
1047 nsChannel_SetContentLength,
1048 nsChannel_Open,
1049 nsChannel_AsyncOpen,
1050 nsChannel_GetRequestMethod,
1051 nsChannel_SetRequestMethod,
1052 nsChannel_GetReferrer,
1053 nsChannel_SetReferrer,
1054 nsChannel_GetRequestHeader,
1055 nsChannel_SetRequestHeader,
1056 nsChannel_VisitRequestHeaders,
1057 nsChannel_GetAllowPipelining,
1058 nsChannel_SetAllowPipelining,
1059 nsChannel_GetRedirectionLimit,
1060 nsChannel_SetRedirectionLimit,
1061 nsChannel_GetResponseStatus,
1062 nsChannel_GetResponseStatusText,
1063 nsChannel_GetRequestSucceeded,
1064 nsChannel_GetResponseHeader,
1065 nsChannel_SetResponseHeader,
1066 nsChannel_VisitResponseHeaders,
1067 nsChannel_IsNoStoreResponse,
1068 nsChannel_IsNoCacheResponse
1071 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1073 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1074 nsQIResult result)
1076 nsChannel *This = NSUPCHANNEL_THIS(iface);
1077 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1080 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1082 nsChannel *This = NSUPCHANNEL_THIS(iface);
1083 return nsIChannel_AddRef(NSCHANNEL(This));
1086 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1088 nsChannel *This = NSUPCHANNEL_THIS(iface);
1089 return nsIChannel_Release(NSCHANNEL(This));
1092 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1093 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1095 nsChannel *This = NSUPCHANNEL_THIS(iface);
1096 const char *content_type;
1098 TRACE("(%p)->(%p %p %d)\n", This, aStream, aContentType, aContentLength);
1100 if(This->post_data_stream)
1101 nsIInputStream_Release(This->post_data_stream);
1103 if(aContentType) {
1104 nsACString_GetData(aContentType, &content_type, NULL);
1105 if(*content_type)
1106 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
1109 if(aContentLength != -1)
1110 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1112 if(aStream)
1113 nsIInputStream_AddRef(aStream);
1114 This->post_data_stream = aStream;
1116 return NS_OK;
1119 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1120 nsIInputStream **aUploadStream)
1122 nsChannel *This = NSUPCHANNEL_THIS(iface);
1124 TRACE("(%p)->(%p)\n", This, aUploadStream);
1126 if(This->post_data_stream)
1127 nsIInputStream_AddRef(This->post_data_stream);
1129 *aUploadStream = This->post_data_stream;
1130 return NS_OK;
1133 #undef NSUPCHANNEL_THIS
1135 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1136 nsUploadChannel_QueryInterface,
1137 nsUploadChannel_AddRef,
1138 nsUploadChannel_Release,
1139 nsUploadChannel_SetUploadStream,
1140 nsUploadChannel_GetUploadStream
1143 #define NSURI_THIS(iface) DEFINE_THIS(nsURI, WineURI, iface)
1145 static nsresult NSAPI nsURI_QueryInterface(nsIWineURI *iface, nsIIDRef riid, nsQIResult result)
1147 nsURI *This = NSURI_THIS(iface);
1149 *result = NULL;
1151 if(IsEqualGUID(&IID_nsISupports, riid)) {
1152 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1153 *result = NSURI(This);
1154 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1155 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1156 *result = NSURI(This);
1157 }else if(IsEqualGUID(&IID_nsIWineURI, riid)) {
1158 TRACE("(%p)->(IID_nsIWineURI %p)\n", This, result);
1159 *result = NSURI(This);
1162 if(*result) {
1163 nsIURI_AddRef(NSURI(This));
1164 return NS_OK;
1167 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1168 return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1171 static nsrefcnt NSAPI nsURI_AddRef(nsIWineURI *iface)
1173 nsURI *This = NSURI_THIS(iface);
1174 LONG ref = InterlockedIncrement(&This->ref);
1176 TRACE("(%p) ref=%d\n", This, ref);
1178 return ref;
1181 static nsrefcnt NSAPI nsURI_Release(nsIWineURI *iface)
1183 nsURI *This = NSURI_THIS(iface);
1184 LONG ref = InterlockedDecrement(&This->ref);
1186 TRACE("(%p) ref=%d\n", This, ref);
1188 if(!ref) {
1189 if(This->container)
1190 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1191 if(This->uri)
1192 nsIURI_Release(This->uri);
1193 heap_free(This->wine_url);
1194 heap_free(This);
1197 return ref;
1200 static nsresult NSAPI nsURI_GetSpec(nsIWineURI *iface, nsACString *aSpec)
1202 nsURI *This = NSURI_THIS(iface);
1204 TRACE("(%p)->(%p)\n", This, aSpec);
1206 if(This->use_wine_url) {
1207 char speca[INTERNET_MAX_URL_LENGTH] = "wine:";
1208 WideCharToMultiByte(CP_ACP, 0, This->wine_url, -1, speca+5, sizeof(speca)-5, NULL, NULL);
1209 nsACString_SetData(aSpec, speca);
1211 return NS_OK;
1214 if(This->uri)
1215 return nsIURI_GetSpec(This->uri, aSpec);
1217 TRACE("returning error\n");
1218 return NS_ERROR_NOT_IMPLEMENTED;
1222 static nsresult NSAPI nsURI_SetSpec(nsIWineURI *iface, const nsACString *aSpec)
1224 nsURI *This = NSURI_THIS(iface);
1226 TRACE("(%p)->(%p)\n", This, aSpec);
1228 if(This->uri)
1229 return nsIURI_SetSpec(This->uri, aSpec);
1231 FIXME("default action not implemented\n");
1232 return NS_ERROR_NOT_IMPLEMENTED;
1235 static nsresult NSAPI nsURI_GetPrePath(nsIWineURI *iface, nsACString *aPrePath)
1237 nsURI *This = NSURI_THIS(iface);
1239 TRACE("(%p)->(%p)\n", This, aPrePath);
1241 if(This->uri)
1242 return nsIURI_GetPrePath(This->uri, aPrePath);
1244 FIXME("default action not implemented\n");
1245 return NS_ERROR_NOT_IMPLEMENTED;
1248 static nsresult NSAPI nsURI_GetScheme(nsIWineURI *iface, nsACString *aScheme)
1250 nsURI *This = NSURI_THIS(iface);
1252 TRACE("(%p)->(%p)\n", This, aScheme);
1254 if(This->use_wine_url) {
1256 * For Gecko we set scheme to unknown so it won't be handled
1257 * as any special case.
1259 nsACString_SetData(aScheme, "wine");
1260 return NS_OK;
1263 if(This->uri)
1264 return nsIURI_GetScheme(This->uri, aScheme);
1266 TRACE("returning error\n");
1267 return NS_ERROR_NOT_IMPLEMENTED;
1270 static nsresult NSAPI nsURI_SetScheme(nsIWineURI *iface, const nsACString *aScheme)
1272 nsURI *This = NSURI_THIS(iface);
1274 TRACE("(%p)->(%p)\n", This, aScheme);
1276 if(This->uri)
1277 return nsIURI_SetScheme(This->uri, aScheme);
1279 FIXME("default action not implemented\n");
1280 return NS_ERROR_NOT_IMPLEMENTED;
1283 static nsresult NSAPI nsURI_GetUserPass(nsIWineURI *iface, nsACString *aUserPass)
1285 nsURI *This = NSURI_THIS(iface);
1287 TRACE("(%p)->(%p)\n", This, aUserPass);
1289 if(This->uri)
1290 return nsIURI_GetUserPass(This->uri, aUserPass);
1292 FIXME("default action not implemented\n");
1293 return NS_ERROR_NOT_IMPLEMENTED;
1296 static nsresult NSAPI nsURI_SetUserPass(nsIWineURI *iface, const nsACString *aUserPass)
1298 nsURI *This = NSURI_THIS(iface);
1300 TRACE("(%p)->(%p)\n", This, aUserPass);
1302 if(This->uri)
1303 return nsIURI_SetUserPass(This->uri, aUserPass);
1305 FIXME("default action not implemented\n");
1306 return NS_ERROR_NOT_IMPLEMENTED;
1309 static nsresult NSAPI nsURI_GetUsername(nsIWineURI *iface, nsACString *aUsername)
1311 nsURI *This = NSURI_THIS(iface);
1313 TRACE("(%p)->(%p)\n", This, aUsername);
1315 if(This->uri)
1316 return nsIURI_GetUsername(This->uri, aUsername);
1318 FIXME("default action not implemented\n");
1319 return NS_ERROR_NOT_IMPLEMENTED;
1322 static nsresult NSAPI nsURI_SetUsername(nsIWineURI *iface, const nsACString *aUsername)
1324 nsURI *This = NSURI_THIS(iface);
1326 TRACE("(%p)->(%p)\n", This, aUsername);
1328 if(This->uri)
1329 return nsIURI_SetUsername(This->uri, aUsername);
1331 FIXME("default action not implemented\n");
1332 return NS_ERROR_NOT_IMPLEMENTED;
1335 static nsresult NSAPI nsURI_GetPassword(nsIWineURI *iface, nsACString *aPassword)
1337 nsURI *This = NSURI_THIS(iface);
1339 TRACE("(%p)->(%p)\n", This, aPassword);
1341 if(This->uri)
1342 return nsIURI_GetPassword(This->uri, aPassword);
1344 FIXME("default action not implemented\n");
1345 return NS_ERROR_NOT_IMPLEMENTED;
1348 static nsresult NSAPI nsURI_SetPassword(nsIWineURI *iface, const nsACString *aPassword)
1350 nsURI *This = NSURI_THIS(iface);
1352 TRACE("(%p)->(%p)\n", This, aPassword);
1354 if(This->uri)
1355 return nsIURI_SetPassword(This->uri, aPassword);
1357 FIXME("default action not implemented\n");
1358 return NS_ERROR_NOT_IMPLEMENTED;
1361 static nsresult NSAPI nsURI_GetHostPort(nsIWineURI *iface, nsACString *aHostPort)
1363 nsURI *This = NSURI_THIS(iface);
1365 TRACE("(%p)->(%p)\n", This, aHostPort);
1367 if(This->uri)
1368 return nsIURI_GetHostPort(This->uri, aHostPort);
1370 FIXME("default action not implemented\n");
1371 return NS_ERROR_NOT_IMPLEMENTED;
1374 static nsresult NSAPI nsURI_SetHostPort(nsIWineURI *iface, const nsACString *aHostPort)
1376 nsURI *This = NSURI_THIS(iface);
1378 TRACE("(%p)->(%p)\n", This, aHostPort);
1380 if(This->uri)
1381 return nsIURI_SetHostPort(This->uri, aHostPort);
1383 FIXME("default action not implemented\n");
1384 return NS_ERROR_NOT_IMPLEMENTED;
1387 static nsresult NSAPI nsURI_GetHost(nsIWineURI *iface, nsACString *aHost)
1389 nsURI *This = NSURI_THIS(iface);
1391 TRACE("(%p)->(%p)\n", This, aHost);
1393 if(This->uri)
1394 return nsIURI_GetHost(This->uri, aHost);
1396 FIXME("default action not implemented\n");
1397 return NS_ERROR_NOT_IMPLEMENTED;
1400 static nsresult NSAPI nsURI_SetHost(nsIWineURI *iface, const nsACString *aHost)
1402 nsURI *This = NSURI_THIS(iface);
1404 TRACE("(%p)->(%p)\n", This, aHost);
1406 if(This->uri)
1407 return nsIURI_SetHost(This->uri, aHost);
1409 FIXME("default action not implemented\n");
1410 return NS_ERROR_NOT_IMPLEMENTED;
1413 static nsresult NSAPI nsURI_GetPort(nsIWineURI *iface, PRInt32 *aPort)
1415 nsURI *This = NSURI_THIS(iface);
1417 TRACE("(%p)->(%p)\n", This, aPort);
1419 if(This->uri)
1420 return nsIURI_GetPort(This->uri, aPort);
1422 FIXME("default action not implemented\n");
1423 return NS_ERROR_NOT_IMPLEMENTED;
1426 static nsresult NSAPI nsURI_SetPort(nsIWineURI *iface, PRInt32 aPort)
1428 nsURI *This = NSURI_THIS(iface);
1430 TRACE("(%p)->(%d)\n", This, aPort);
1432 if(This->uri)
1433 return nsIURI_SetPort(This->uri, aPort);
1435 FIXME("default action not implemented\n");
1436 return NS_ERROR_NOT_IMPLEMENTED;
1439 static nsresult NSAPI nsURI_GetPath(nsIWineURI *iface, nsACString *aPath)
1441 nsURI *This = NSURI_THIS(iface);
1443 TRACE("(%p)->(%p)\n", This, aPath);
1445 if(This->uri)
1446 return nsIURI_GetPath(This->uri, aPath);
1448 FIXME("default action not implemented\n");
1449 return NS_ERROR_NOT_IMPLEMENTED;
1452 static nsresult NSAPI nsURI_SetPath(nsIWineURI *iface, const nsACString *aPath)
1454 nsURI *This = NSURI_THIS(iface);
1456 TRACE("(%p)->(%p)\n", This, aPath);
1458 if(This->uri)
1459 return nsIURI_SetPath(This->uri, aPath);
1461 FIXME("default action not implemented\n");
1462 return NS_ERROR_NOT_IMPLEMENTED;
1465 static nsresult NSAPI nsURI_Equals(nsIWineURI *iface, nsIURI *other, PRBool *_retval)
1467 nsURI *This = NSURI_THIS(iface);
1469 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1471 if(This->uri)
1472 return nsIURI_Equals(This->uri, other, _retval);
1474 FIXME("default action not implemented\n");
1475 return NS_ERROR_NOT_IMPLEMENTED;
1478 static nsresult NSAPI nsURI_SchemeIs(nsIWineURI *iface, const char *scheme, PRBool *_retval)
1480 nsURI *This = NSURI_THIS(iface);
1482 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1484 if(This->use_wine_url) {
1485 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
1486 int len = MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR))-1;
1488 *_retval = strlenW(This->wine_url) > len
1489 && This->wine_url[len] == ':'
1490 && !memcmp(buf, This->wine_url, len*sizeof(WCHAR));
1491 return NS_OK;
1494 if(This->uri)
1495 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1497 TRACE("returning error\n");
1498 return NS_ERROR_NOT_IMPLEMENTED;
1501 static nsresult NSAPI nsURI_Clone(nsIWineURI *iface, nsIURI **_retval)
1503 nsURI *This = NSURI_THIS(iface);
1505 TRACE("(%p)->(%p)\n", This, _retval);
1507 if(This->uri) {
1508 nsIURI *uri;
1509 nsIWineURI *wine_uri;
1510 nsresult nsres;
1512 nsres = nsIURI_Clone(This->uri, &uri);
1513 if(NS_FAILED(nsres)) {
1514 WARN("Clone failed: %08x\n", nsres);
1515 return nsres;
1518 nsres = create_uri(uri, This->container, &wine_uri);
1519 *_retval = (nsIURI*)wine_uri;
1520 if(NS_SUCCEEDED(nsres))
1521 return nsIWineURI_SetWineURL(wine_uri, This->wine_url);
1522 return nsres;
1525 FIXME("default action not implemented\n");
1526 return NS_ERROR_NOT_IMPLEMENTED;
1529 static nsresult NSAPI nsURI_Resolve(nsIWineURI *iface, const nsACString *arelativePath,
1530 nsACString *_retval)
1532 nsURI *This = NSURI_THIS(iface);
1534 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1536 if(This->uri)
1537 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1539 FIXME("default action not implemented\n");
1540 return NS_ERROR_NOT_IMPLEMENTED;
1543 static nsresult NSAPI nsURI_GetAsciiSpec(nsIWineURI *iface, nsACString *aAsciiSpec)
1545 nsURI *This = NSURI_THIS(iface);
1547 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1549 if(This->use_wine_url)
1550 return nsIURI_GetSpec(NSURI(This), aAsciiSpec);
1552 if(This->uri)
1553 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1555 TRACE("returning error\n");
1556 return NS_ERROR_NOT_IMPLEMENTED;
1559 static nsresult NSAPI nsURI_GetAsciiHost(nsIWineURI *iface, nsACString *aAsciiHost)
1561 nsURI *This = NSURI_THIS(iface);
1563 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1565 if(This->uri)
1566 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1568 FIXME("default action not implemented\n");
1569 return NS_ERROR_NOT_IMPLEMENTED;
1572 static nsresult NSAPI nsURI_GetOriginCharset(nsIWineURI *iface, nsACString *aOriginCharset)
1574 nsURI *This = NSURI_THIS(iface);
1576 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1578 if(This->uri)
1579 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1581 FIXME("default action not implemented\n");
1582 return NS_ERROR_NOT_IMPLEMENTED;
1585 static nsresult NSAPI nsURI_GetNSContainer(nsIWineURI *iface, NSContainer **aContainer)
1587 nsURI *This = NSURI_THIS(iface);
1589 TRACE("(%p)->(%p)\n", This, aContainer);
1591 if(This->container)
1592 nsIWebBrowserChrome_AddRef(NSWBCHROME(This->container));
1593 *aContainer = This->container;
1595 return NS_OK;
1598 static nsresult NSAPI nsURI_SetNSContainer(nsIWineURI *iface, NSContainer *aContainer)
1600 nsURI *This = NSURI_THIS(iface);
1602 TRACE("(%p)->(%p)\n", This, aContainer);
1604 if(This->container) {
1605 if(This->container == aContainer)
1606 return NS_OK;
1607 TRACE("Changing %p -> %p\n", This->container, aContainer);
1608 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1611 if(aContainer)
1612 nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer));
1613 This->container = aContainer;
1615 return NS_OK;
1618 static nsresult NSAPI nsURI_GetIsDocumentURI(nsIWineURI *iface, PRBool *aIsDocumentURI)
1620 nsURI *This = NSURI_THIS(iface);
1622 TRACE("(%p)->(%p)\n", This, aIsDocumentURI);
1624 *aIsDocumentURI = This->is_doc_uri;
1625 return NS_OK;
1628 static nsresult NSAPI nsURI_SetIsDocumentURI(nsIWineURI *iface, PRBool aIsDocumentURI)
1630 nsURI *This = NSURI_THIS(iface);
1632 TRACE("(%p)->(%x)\n", This, aIsDocumentURI);
1634 This->is_doc_uri = aIsDocumentURI;
1635 return NS_OK;
1638 static nsresult NSAPI nsURI_GetWineURL(nsIWineURI *iface, LPCWSTR *aURL)
1640 nsURI *This = NSURI_THIS(iface);
1642 TRACE("(%p)->(%p)\n", This, aURL);
1644 *aURL = This->wine_url;
1645 return NS_OK;
1648 static nsresult NSAPI nsURI_SetWineURL(nsIWineURI *iface, LPCWSTR aURL)
1650 nsURI *This = NSURI_THIS(iface);
1652 static const WCHAR wszFtp[] = {'f','t','p',':'};
1653 static const WCHAR wszHttp[] = {'h','t','t','p',':'};
1654 static const WCHAR wszHttps[] = {'h','t','t','p','s',':'};
1656 TRACE("(%p)->(%s)\n", This, debugstr_w(aURL));
1658 heap_free(This->wine_url);
1660 if(aURL) {
1661 int len = strlenW(aURL)+1;
1662 This->wine_url = heap_alloc(len*sizeof(WCHAR));
1663 memcpy(This->wine_url, aURL, len*sizeof(WCHAR));
1665 /* FIXME: Always use wine url */
1666 This->use_wine_url =
1667 strncmpW(aURL, wszFtp, sizeof(wszFtp)/sizeof(WCHAR))
1668 && strncmpW(aURL, wszHttp, sizeof(wszHttp)/sizeof(WCHAR))
1669 && strncmpW(aURL, wszHttps, sizeof(wszHttps)/sizeof(WCHAR));
1670 }else {
1671 This->wine_url = NULL;
1672 This->use_wine_url = FALSE;
1675 return NS_OK;
1678 #undef NSURI_THIS
1680 static const nsIWineURIVtbl nsWineURIVtbl = {
1681 nsURI_QueryInterface,
1682 nsURI_AddRef,
1683 nsURI_Release,
1684 nsURI_GetSpec,
1685 nsURI_SetSpec,
1686 nsURI_GetPrePath,
1687 nsURI_GetScheme,
1688 nsURI_SetScheme,
1689 nsURI_GetUserPass,
1690 nsURI_SetUserPass,
1691 nsURI_GetUsername,
1692 nsURI_SetUsername,
1693 nsURI_GetPassword,
1694 nsURI_SetPassword,
1695 nsURI_GetHostPort,
1696 nsURI_SetHostPort,
1697 nsURI_GetHost,
1698 nsURI_SetHost,
1699 nsURI_GetPort,
1700 nsURI_SetPort,
1701 nsURI_GetPath,
1702 nsURI_SetPath,
1703 nsURI_Equals,
1704 nsURI_SchemeIs,
1705 nsURI_Clone,
1706 nsURI_Resolve,
1707 nsURI_GetAsciiSpec,
1708 nsURI_GetAsciiHost,
1709 nsURI_GetOriginCharset,
1710 nsURI_GetNSContainer,
1711 nsURI_SetNSContainer,
1712 nsURI_GetIsDocumentURI,
1713 nsURI_SetIsDocumentURI,
1714 nsURI_GetWineURL,
1715 nsURI_SetWineURL
1718 static nsresult create_uri(nsIURI *uri, NSContainer *container, nsIWineURI **_retval)
1720 nsURI *ret = heap_alloc(sizeof(nsURI));
1722 ret->lpWineURIVtbl = &nsWineURIVtbl;
1723 ret->ref = 1;
1724 ret->uri = uri;
1725 ret->container = container;
1726 ret->wine_url = NULL;
1727 ret->is_doc_uri = FALSE;
1728 ret->use_wine_url = FALSE;
1730 if(container)
1731 nsIWebBrowserChrome_AddRef(NSWBCHROME(container));
1733 TRACE("retval=%p\n", ret);
1734 *_retval = NSWINEURI(ret);
1735 return NS_OK;
1738 typedef struct {
1739 const nsIProtocolHandlerVtbl *lpProtocolHandlerVtbl;
1741 LONG ref;
1743 nsIProtocolHandler *nshandler;
1744 } nsProtocolHandler;
1746 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
1748 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
1750 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
1751 nsQIResult result)
1753 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1755 *result = NULL;
1757 if(IsEqualGUID(&IID_nsISupports, riid)) {
1758 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1759 *result = NSPROTHANDLER(This);
1760 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
1761 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
1762 *result = NSPROTHANDLER(This);
1763 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
1764 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
1765 return NS_NOINTERFACE;
1768 if(*result) {
1769 nsISupports_AddRef((nsISupports*)*result);
1770 return NS_OK;
1773 WARN("(%s %p)\n", debugstr_guid(riid), result);
1774 return NS_NOINTERFACE;
1777 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
1779 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1780 LONG ref = InterlockedIncrement(&This->ref);
1782 TRACE("(%p) ref=%d\n", This, ref);
1784 return ref;
1787 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
1789 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1790 LONG ref = InterlockedDecrement(&This->ref);
1792 TRACE("(%p) ref=%d\n", This, ref);
1794 if(!ref) {
1795 if(This->nshandler)
1796 nsIProtocolHandler_Release(This->nshandler);
1797 heap_free(This);
1800 return ref;
1803 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
1805 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1807 TRACE("(%p)->(%p)\n", This, aScheme);
1809 if(This->nshandler)
1810 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
1811 return NS_ERROR_NOT_IMPLEMENTED;
1814 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
1815 PRInt32 *aDefaultPort)
1817 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1819 TRACE("(%p)->(%p)\n", This, aDefaultPort);
1821 if(This->nshandler)
1822 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
1823 return NS_ERROR_NOT_IMPLEMENTED;
1826 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
1827 PRUint32 *aProtocolFlags)
1829 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1831 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
1833 if(This->nshandler)
1834 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
1835 return NS_ERROR_NOT_IMPLEMENTED;
1838 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
1839 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
1841 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1843 TRACE("((%p)->%p %s %p %p)\n", This, aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
1845 if(This->nshandler)
1846 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
1847 return NS_ERROR_NOT_IMPLEMENTED;
1850 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
1851 nsIURI *aURI, nsIChannel **_retval)
1853 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1855 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
1857 if(This->nshandler)
1858 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
1859 return NS_ERROR_NOT_IMPLEMENTED;
1862 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
1863 PRInt32 port, const char *scheme, PRBool *_retval)
1865 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1867 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
1869 if(This->nshandler)
1870 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
1871 return NS_ERROR_NOT_IMPLEMENTED;
1874 #undef NSPROTHANDLER_THIS
1876 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
1877 nsProtocolHandler_QueryInterface,
1878 nsProtocolHandler_AddRef,
1879 nsProtocolHandler_Release,
1880 nsProtocolHandler_GetScheme,
1881 nsProtocolHandler_GetDefaultPort,
1882 nsProtocolHandler_GetProtocolFlags,
1883 nsProtocolHandler_NewURI,
1884 nsProtocolHandler_NewChannel,
1885 nsProtocolHandler_AllowPort
1888 static nsIProtocolHandler *create_protocol_handler(nsIProtocolHandler *nshandler)
1890 nsProtocolHandler *ret = heap_alloc(sizeof(nsProtocolHandler));
1892 ret->lpProtocolHandlerVtbl = &nsProtocolHandlerVtbl;
1893 ret->ref = 1;
1894 ret->nshandler = nshandler;
1896 return NSPROTHANDLER(ret);
1899 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
1900 nsQIResult result)
1902 *result = NULL;
1904 if(IsEqualGUID(&IID_nsISupports, riid)
1905 || IsEqualGUID(&IID_nsIIOService, riid)) {
1906 *result = iface;
1907 nsIIOService_AddRef(iface);
1908 return S_OK;
1911 WARN("(%s %p)\n", debugstr_guid(riid), result);
1912 return NS_NOINTERFACE;
1915 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
1917 return 2;
1920 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
1922 return 1;
1925 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
1926 nsIProtocolHandler **_retval)
1928 nsIExternalProtocolHandler *nsexthandler;
1929 nsIProtocolHandler *nshandler;
1930 nsresult nsres;
1932 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1934 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
1935 if(NS_FAILED(nsres)) {
1936 WARN("GetProtocolHandler failed: %08x\n", nsres);
1937 return nsres;
1940 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
1941 (void**)&nsexthandler);
1942 if(NS_FAILED(nsres)) {
1943 *_retval = nshandler;
1944 return NS_OK;
1947 nsIExternalProtocolHandler_Release(nsexthandler);
1948 *_retval = create_protocol_handler(nshandler);
1949 TRACE("return %p\n", *_retval);
1950 return NS_OK;
1953 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
1954 PRUint32 *_retval)
1956 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1957 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
1960 static BOOL is_gecko_special_uri(const char *spec)
1962 static const char chromeW[] = "chrome:";
1963 static const char jarW[] = "jar:";
1964 static const char resourceW[] = "resource:";
1965 static const char javascriptW[] = "javascript:";
1967 return !strncasecmp(spec, chromeW, sizeof(chromeW)-1)
1968 || !strncasecmp(spec, resourceW, sizeof(resourceW)-1)
1969 || !strncasecmp(spec, jarW, sizeof(jarW)-1)
1970 || !strncasecmp(spec, javascriptW, sizeof(javascriptW)-1);
1973 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
1974 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
1976 const char *spec = NULL;
1977 nsACString spec_str;
1978 NSContainer *nscontainer = NULL;
1979 nsIURI *uri = NULL;
1980 LPCWSTR base_wine_url = NULL;
1981 nsIWineURI *base_wine_uri = NULL, *wine_uri;
1982 BOOL is_wine_uri = FALSE;
1983 nsresult nsres;
1985 nsACString_GetData(aSpec, &spec, NULL);
1987 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
1988 aBaseURI, _retval);
1990 if(is_gecko_special_uri(spec))
1991 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
1993 if(!strncmp(spec, "wine:", 5)) {
1994 spec += 5;
1995 is_wine_uri = TRUE;
1998 if(aBaseURI) {
1999 nsACString base_uri_str;
2000 const char *base_uri = NULL;
2002 nsACString_Init(&base_uri_str, NULL);
2004 nsres = nsIURI_GetSpec(aBaseURI, &base_uri_str);
2005 if(NS_SUCCEEDED(nsres)) {
2006 nsACString_GetData(&base_uri_str, &base_uri, NULL);
2007 TRACE("base_uri=%s\n", debugstr_a(base_uri));
2008 }else {
2009 ERR("GetSpec failed: %08x\n", nsres);
2012 nsACString_Finish(&base_uri_str);
2015 nsACString_Init(&spec_str, spec);
2016 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
2017 nsACString_Finish(&spec_str);
2018 if(NS_FAILED(nsres))
2019 TRACE("NewURI failed: %08x\n", nsres);
2021 if(aBaseURI) {
2022 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsIWineURI, (void**)&base_wine_uri);
2023 if(NS_SUCCEEDED(nsres)) {
2024 nsIWineURI_GetNSContainer(base_wine_uri, &nscontainer);
2025 nsIWineURI_GetWineURL(base_wine_uri, &base_wine_url);
2026 }else {
2027 TRACE("Could not get base nsIWineURI: %08x\n", nsres);
2031 nsres = create_uri(uri, nscontainer, &wine_uri);
2032 *_retval = (nsIURI*)wine_uri;
2034 if(nscontainer)
2035 nsIWebBrowserChrome_Release(NSWBCHROME(nscontainer));
2037 if(base_wine_url) {
2038 WCHAR url[INTERNET_MAX_URL_LENGTH], rel_url[INTERNET_MAX_URL_LENGTH];
2039 DWORD len;
2040 HRESULT hres;
2042 MultiByteToWideChar(CP_ACP, 0, spec, -1, rel_url, sizeof(rel_url)/sizeof(WCHAR));
2044 hres = CoInternetCombineUrl(base_wine_url, rel_url,
2045 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
2046 url, sizeof(url)/sizeof(WCHAR), &len, 0);
2047 if(SUCCEEDED(hres))
2048 nsIWineURI_SetWineURL(wine_uri, url);
2049 else
2050 WARN("CoCombineUrl failed: %08x\n", hres);
2051 }else if(is_wine_uri) {
2052 WCHAR url[INTERNET_MAX_URL_LENGTH];
2054 MultiByteToWideChar(CP_ACP, 0, spec, -1, url, sizeof(url)/sizeof(WCHAR));
2055 nsIWineURI_SetWineURL(wine_uri, url);
2058 if(base_wine_uri)
2059 nsIWineURI_Release(base_wine_uri);
2061 return nsres;
2064 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
2065 nsIURI **_retval)
2067 TRACE("(%p %p)\n", aFile, _retval);
2068 return nsIIOService_NewFileURI(nsio, aFile, _retval);
2071 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
2072 nsIChannel **_retval)
2074 nsIChannel *channel = NULL;
2075 nsChannel *ret;
2076 nsIWineURI *wine_uri;
2077 nsresult nsres;
2079 TRACE("(%p %p)\n", aURI, _retval);
2081 nsres = nsIIOService_NewChannelFromURI(nsio, aURI, &channel);
2082 if(NS_FAILED(nsres) && nsres != NS_ERROR_UNKNOWN_PROTOCOL) {
2083 WARN("NewChannelFromURI failed: %08x\n", nsres);
2084 *_retval = channel;
2085 return nsres;
2088 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
2089 if(NS_FAILED(nsres)) {
2090 WARN("Could not get nsIWineURI: %08x\n", nsres);
2091 *_retval = channel;
2092 return channel ? NS_OK : NS_ERROR_UNEXPECTED;
2095 ret = heap_alloc(sizeof(nsChannel));
2097 ret->lpHttpChannelVtbl = &nsChannelVtbl;
2098 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
2099 ret->ref = 1;
2100 ret->channel = channel;
2101 ret->http_channel = NULL;
2102 ret->uri = wine_uri;
2103 ret->post_data_stream = NULL;
2104 ret->load_group = NULL;
2105 ret->notif_callback = NULL;
2106 ret->load_flags = 0;
2107 ret->content = NULL;
2108 ret->charset = NULL;
2110 nsIURI_AddRef(aURI);
2111 ret->original_uri = aURI;
2113 if(channel)
2114 nsIChannel_QueryInterface(channel, &IID_nsIHttpChannel, (void**)&ret->http_channel);
2116 *_retval = NSCHANNEL(ret);
2117 return NS_OK;
2120 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
2121 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
2123 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2124 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2127 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
2129 TRACE("(%p)\n", aOffline);
2130 return nsIIOService_GetOffline(nsio, aOffline);
2133 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
2135 TRACE("(%x)\n", aOffline);
2136 return nsIIOService_SetOffline(nsio, aOffline);
2139 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
2140 const char *aScheme, PRBool *_retval)
2142 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
2143 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
2146 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
2147 nsACString * _retval)
2149 TRACE("(%p %p)\n", urlString, _retval);
2150 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
2153 static const nsIIOServiceVtbl nsIOServiceVtbl = {
2154 nsIOService_QueryInterface,
2155 nsIOService_AddRef,
2156 nsIOService_Release,
2157 nsIOService_GetProtocolHandler,
2158 nsIOService_GetProtocolFlags,
2159 nsIOService_NewURI,
2160 nsIOService_NewFileURI,
2161 nsIOService_NewChannelFromURI,
2162 nsIOService_NewChannel,
2163 nsIOService_GetOffline,
2164 nsIOService_SetOffline,
2165 nsIOService_AllowPort,
2166 nsIOService_ExtractScheme
2169 static nsIIOService nsIOService = { &nsIOServiceVtbl };
2171 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
2172 nsQIResult result)
2174 *result = NULL;
2176 if(IsEqualGUID(&IID_nsISupports, riid)) {
2177 TRACE("(IID_nsISupoprts %p)\n", result);
2178 *result = iface;
2179 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
2180 TRACE("(IID_nsIFactory %p)\n", result);
2181 *result = iface;
2184 if(*result) {
2185 nsIFactory_AddRef(iface);
2186 return NS_OK;
2189 WARN("(%s %p)\n", debugstr_guid(riid), result);
2190 return NS_NOINTERFACE;
2193 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
2195 return 2;
2198 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
2200 return 1;
2203 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
2204 nsISupports *aOuter, const nsIID *iid, void **result)
2206 return nsIIOService_QueryInterface(&nsIOService, iid, result);
2209 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
2211 WARN("(%x)\n", lock);
2212 return NS_OK;
2215 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
2216 nsIOServiceFactory_QueryInterface,
2217 nsIOServiceFactory_AddRef,
2218 nsIOServiceFactory_Release,
2219 nsIOServiceFactory_CreateInstance,
2220 nsIOServiceFactory_LockFactory
2223 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
2225 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
2227 nsIFactory *old_factory = NULL;
2228 nsresult nsres;
2230 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
2231 &IID_nsIFactory, (void**)&old_factory);
2232 if(NS_FAILED(nsres)) {
2233 ERR("Could not get factory: %08x\n", nsres);
2234 return;
2237 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
2238 if(NS_FAILED(nsres)) {
2239 ERR("Couldn not create nsIOService instance %08x\n", nsres);
2240 nsIFactory_Release(old_factory);
2241 return;
2244 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
2245 nsIFactory_Release(old_factory);
2246 if(NS_FAILED(nsres))
2247 ERR("UnregisterFactory failed: %08x\n", nsres);
2249 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
2250 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
2251 if(NS_FAILED(nsres))
2252 ERR("RegisterFactory failed: %08x\n", nsres);