push 88671f85dcf7a7cd89c63d6e9f34ad6b6ad2ae64
[wine/hacks.git] / dlls / mshtml / nsio.c
blob2e62a44bf5b4cb6da2f4c6f057f816b2c6f189cc
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(!doc->client)
120 return TRUE;
122 if(!hlnf && !exec_shldocvw_67(doc, uri))
123 return FALSE;
125 hres = IOleClientSite_QueryInterface(doc->client, &IID_IServiceProvider,
126 (void**)&service_provider);
127 if(SUCCEEDED(hres)) {
128 IHlinkFrame *hlink_frame;
130 hres = IServiceProvider_QueryService(service_provider, &IID_IHlinkFrame,
131 &IID_IHlinkFrame, (void**)&hlink_frame);
132 IServiceProvider_Release(service_provider);
133 if(SUCCEEDED(hres)) {
134 hlink_frame_navigate(doc, hlink_frame, uri, channel->post_data_stream, hlnf);
135 IHlinkFrame_Release(hlink_frame);
137 return FALSE;
141 return TRUE;
144 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
146 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
148 nsChannel *This = NSCHANNEL_THIS(iface);
150 *result = NULL;
152 if(IsEqualGUID(&IID_nsISupports, riid)) {
153 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
154 *result = NSCHANNEL(This);
155 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
156 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
157 *result = NSCHANNEL(This);
158 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
159 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
160 *result = NSCHANNEL(This);
161 }else if(This->http_channel && IsEqualGUID(&IID_nsIHttpChannel, riid)) {
162 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
163 *result = NSHTTPCHANNEL(This);
164 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
165 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
166 *result = NSUPCHANNEL(This);
169 if(*result) {
170 nsIChannel_AddRef(NSCHANNEL(This));
171 return NS_OK;
174 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
176 if(This->channel)
177 return nsIChannel_QueryInterface(This->channel, riid, result);
178 return NS_NOINTERFACE;
181 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
183 nsChannel *This = NSCHANNEL_THIS(iface);
184 nsrefcnt ref = InterlockedIncrement(&This->ref);
186 TRACE("(%p) ref=%d\n", This, ref);
188 return ref;
191 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
193 nsChannel *This = NSCHANNEL_THIS(iface);
194 LONG ref = InterlockedDecrement(&This->ref);
196 if(!ref) {
197 nsIWineURI_Release(This->uri);
198 if(This->channel)
199 nsIChannel_Release(This->channel);
200 if(This->http_channel)
201 nsIHttpChannel_Release(This->http_channel);
202 if(This->post_data_stream)
203 nsIInputStream_Release(This->post_data_stream);
204 if(This->load_group)
205 nsILoadGroup_Release(This->load_group);
206 if(This->notif_callback)
207 nsIInterfaceRequestor_Release(This->notif_callback);
208 if(This->original_uri)
209 nsIURI_Release(This->original_uri);
210 heap_free(This->content);
211 heap_free(This->charset);
212 heap_free(This);
215 return ref;
218 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
220 nsChannel *This = NSCHANNEL_THIS(iface);
222 TRACE("(%p)->(%p)\n", This, aName);
224 if(This->channel)
225 return nsIChannel_GetName(This->channel, aName);
227 return NS_ERROR_NOT_IMPLEMENTED;
230 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
232 nsChannel *This = NSCHANNEL_THIS(iface);
234 TRACE("(%p)->(%p)\n", This, _retval);
236 if(This->channel)
237 return nsIChannel_IsPending(This->channel, _retval);
239 FIXME("default action not implemented\n");
240 return NS_ERROR_NOT_IMPLEMENTED;
243 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
245 nsChannel *This = NSCHANNEL_THIS(iface);
247 TRACE("(%p)->(%p)\n", This, aStatus);
249 if(This->channel)
250 return nsIChannel_GetStatus(This->channel, aStatus);
252 TRACE("returning NS_OK\n");
253 return *aStatus = NS_OK;
256 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
258 nsChannel *This = NSCHANNEL_THIS(iface);
260 TRACE("(%p)->(%08x)\n", This, aStatus);
262 if(This->channel)
263 return nsIChannel_Cancel(This->channel, aStatus);
265 FIXME("default action not implemented\n");
266 return NS_ERROR_NOT_IMPLEMENTED;
269 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
271 nsChannel *This = NSCHANNEL_THIS(iface);
273 TRACE("(%p)\n", This);
275 if(This->channel)
276 return nsIChannel_Suspend(This->channel);
278 FIXME("default action not implemented\n");
279 return NS_ERROR_NOT_IMPLEMENTED;
282 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
284 nsChannel *This = NSCHANNEL_THIS(iface);
286 TRACE("(%p)\n", This);
288 if(This->channel)
289 return nsIChannel_Resume(This->channel);
291 FIXME("default action not implemented\n");
292 return NS_ERROR_NOT_IMPLEMENTED;
295 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
297 nsChannel *This = NSCHANNEL_THIS(iface);
299 TRACE("(%p)->(%p)\n", This, aLoadGroup);
301 if(This->load_group)
302 nsILoadGroup_AddRef(This->load_group);
304 *aLoadGroup = This->load_group;
305 return NS_OK;
308 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
310 nsChannel *This = NSCHANNEL_THIS(iface);
312 TRACE("(%p)->(%p)\n", This, aLoadGroup);
314 if(This->load_group)
315 nsILoadGroup_Release(This->load_group);
316 if(aLoadGroup)
317 nsILoadGroup_AddRef(aLoadGroup);
319 This->load_group = aLoadGroup;
321 if(This->channel)
322 return nsIChannel_SetLoadGroup(This->channel, aLoadGroup);
323 return NS_OK;
326 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
328 nsChannel *This = NSCHANNEL_THIS(iface);
330 TRACE("(%p)->(%p)\n", This, aLoadFlags);
332 *aLoadFlags = This->load_flags;
333 return NS_OK;
336 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
338 nsChannel *This = NSCHANNEL_THIS(iface);
340 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
342 This->load_flags = aLoadFlags;
344 if(This->channel)
345 return nsIChannel_SetLoadFlags(This->channel, aLoadFlags);
346 return NS_OK;
349 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
351 nsChannel *This = NSCHANNEL_THIS(iface);
353 TRACE("(%p)->(%p)\n", This, aOriginalURI);
355 if(This->original_uri)
356 nsIURI_AddRef(This->original_uri);
358 *aOriginalURI = This->original_uri;
359 return NS_OK;
362 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
364 nsChannel *This = NSCHANNEL_THIS(iface);
366 TRACE("(%p)->(%p)\n", This, aOriginalURI);
368 if(This->original_uri)
369 nsIURI_Release(This->original_uri);
371 nsIURI_AddRef(aOriginalURI);
372 This->original_uri = aOriginalURI;
374 if(This->channel)
375 return nsIChannel_SetOriginalURI(This->channel, aOriginalURI);
376 return NS_OK;
379 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
381 nsChannel *This = NSCHANNEL_THIS(iface);
383 TRACE("(%p)->(%p)\n", This, aURI);
385 nsIWineURI_AddRef(This->uri);
386 *aURI = (nsIURI*)This->uri;
388 return NS_OK;
391 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
393 nsChannel *This = NSCHANNEL_THIS(iface);
395 TRACE("(%p)->(%p)\n", This, aOwner);
397 if(This->channel)
398 return nsIChannel_GetOwner(This->channel, aOwner);
400 FIXME("default action not implemented\n");
401 return NS_ERROR_NOT_IMPLEMENTED;
404 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
406 nsChannel *This = NSCHANNEL_THIS(iface);
408 TRACE("(%p)->(%p)\n", This, aOwner);
410 if(This->channel)
411 return nsIChannel_SetOwner(This->channel, aOwner);
413 FIXME("default action not implemented\n");
414 return NS_ERROR_NOT_IMPLEMENTED;
417 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
418 nsIInterfaceRequestor **aNotificationCallbacks)
420 nsChannel *This = NSCHANNEL_THIS(iface);
422 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
424 if(This->notif_callback)
425 nsIInterfaceRequestor_AddRef(This->notif_callback);
426 *aNotificationCallbacks = This->notif_callback;
428 return NS_OK;
431 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
432 nsIInterfaceRequestor *aNotificationCallbacks)
434 nsChannel *This = NSCHANNEL_THIS(iface);
436 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
438 if(This->notif_callback)
439 nsIInterfaceRequestor_Release(This->notif_callback);
440 if(aNotificationCallbacks)
441 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
443 This->notif_callback = aNotificationCallbacks;
445 if(This->channel)
446 return nsIChannel_SetNotificationCallbacks(This->channel, aNotificationCallbacks);
447 return NS_OK;
450 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
452 nsChannel *This = NSCHANNEL_THIS(iface);
454 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
456 if(This->channel)
457 return nsIChannel_GetSecurityInfo(This->channel, aSecurityInfo);
459 FIXME("default action not implemented\n");
460 return NS_ERROR_NOT_IMPLEMENTED;
463 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
465 nsChannel *This = NSCHANNEL_THIS(iface);
467 TRACE("(%p)->(%p)\n", This, aContentType);
469 if(This->content) {
470 nsACString_SetData(aContentType, This->content);
471 return S_OK;
474 if(This->channel)
475 return nsIChannel_GetContentType(This->channel, aContentType);
477 TRACE("returning default text/html\n");
478 nsACString_SetData(aContentType, "text/html");
479 return NS_OK;
482 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
483 const nsACString *aContentType)
485 nsChannel *This = NSCHANNEL_THIS(iface);
487 TRACE("(%p)->(%p)\n", This, aContentType);
489 if(This->channel)
490 return nsIChannel_SetContentType(This->channel, aContentType);
492 FIXME("default action not implemented\n");
493 return NS_ERROR_NOT_IMPLEMENTED;
496 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
497 nsACString *aContentCharset)
499 nsChannel *This = NSCHANNEL_THIS(iface);
501 TRACE("(%p)->(%p)\n", This, aContentCharset);
503 if(This->charset) {
504 nsACString_SetData(aContentCharset, This->charset);
505 return NS_OK;
508 if(This->channel) {
509 nsresult nsres = nsIChannel_GetContentCharset(This->channel, aContentCharset);
510 const char *ch;
511 nsACString_GetData(aContentCharset, &ch);
512 return nsres;
515 nsACString_SetData(aContentCharset, "");
516 return NS_OK;
519 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
520 const nsACString *aContentCharset)
522 nsChannel *This = NSCHANNEL_THIS(iface);
524 TRACE("(%p)->(%p)\n", This, aContentCharset);
526 if(This->channel)
527 return nsIChannel_SetContentCharset(This->channel, aContentCharset);
529 FIXME("default action not implemented\n");
530 return NS_ERROR_NOT_IMPLEMENTED;
533 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
535 nsChannel *This = NSCHANNEL_THIS(iface);
537 TRACE("(%p)->(%p)\n", This, aContentLength);
539 if(This->channel)
540 return nsIChannel_GetContentLength(This->channel, aContentLength);
542 FIXME("default action not implemented\n");
543 return NS_ERROR_NOT_IMPLEMENTED;
546 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
548 nsChannel *This = NSCHANNEL_THIS(iface);
550 TRACE("(%p)->(%d)\n", This, aContentLength);
552 if(This->channel)
553 return nsIChannel_SetContentLength(This->channel, aContentLength);
555 FIXME("default action not implemented\n");
556 return NS_ERROR_NOT_IMPLEMENTED;
559 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
561 nsChannel *This = NSCHANNEL_THIS(iface);
563 TRACE("(%p)->(%p)\n", This, _retval);
565 if(This->channel)
566 return nsIChannel_Open(This->channel, _retval);
568 FIXME("default action not implemented\n");
569 return NS_ERROR_NOT_IMPLEMENTED;
572 static BOOL do_load_from_moniker_hack(nsChannel *This)
574 nsACString scheme_str;
575 nsresult nsres;
576 BOOL ret = TRUE;
579 * We should always load the page from IMoniker, but Wine is not yet
580 * ready for this. This function is a heuristic, that decides which
581 * way of loading is better (Gecko implementation or IMoniker). The
582 * aim is to always return TRUE.
585 /* Load from moniker if there is no Gecko channel available */
586 if(!This->channel)
587 return TRUE;
589 nsACString_Init(&scheme_str, NULL);
590 nsres = nsIWineURI_GetScheme(This->uri, &scheme_str);
592 if(NS_SUCCEEDED(nsres)) {
593 const char *scheme;
595 nsACString_GetData(&scheme_str, &scheme);
596 ret = !strcmp(scheme, "wine");
599 nsACString_Finish(&scheme_str);
600 return ret;
603 static HRESULT create_mon_for_nschannel(nsChannel *channel, IMoniker **mon)
605 nsIWineURI *wine_uri;
606 LPCWSTR wine_url;
607 nsresult nsres;
608 HRESULT hres;
610 if(!channel->original_uri) {
611 ERR("original_uri == NULL\n");
612 return E_FAIL;
615 nsres = nsIURI_QueryInterface(channel->original_uri, &IID_nsIWineURI, (void**)&wine_uri);
616 if(NS_FAILED(nsres)) {
617 ERR("Could not get nsIWineURI: %08x\n", nsres);
618 return E_FAIL;
621 nsIWineURI_GetWineURL(wine_uri, &wine_url);
622 nsIWineURI_Release(wine_uri);
623 if(!wine_url) {
624 TRACE("wine_url == NULL\n");
625 return E_FAIL;
628 hres = CreateURLMoniker(NULL, wine_url, mon);
629 if(FAILED(hres))
630 WARN("CreateURLMonikrer failed: %08x\n", hres);
632 return hres;
635 static nsresult async_open_doc_uri(nsChannel *This, NSContainer *container,
636 nsIStreamListener *listener, nsISupports *context, BOOL *open)
638 IMoniker *mon;
639 HRESULT hres;
641 *open = FALSE;
643 if(container->bscallback) {
644 nsIChannel_AddRef(NSCHANNEL(This));
645 container->bscallback->nschannel = This;
647 nsIStreamListener_AddRef(listener);
648 container->bscallback->nslistener = listener;
650 if(context) {
651 nsISupports_AddRef(context);
652 container->bscallback->nscontext = context;
655 if(container->doc && container->doc->mime) {
656 DWORD len;
658 heap_free(This->content);
660 len = WideCharToMultiByte(CP_ACP, 0, container->doc->mime, -1, NULL, 0, NULL, NULL);
661 This->content = heap_alloc(len);
662 WideCharToMultiByte(CP_ACP, 0, container->doc->mime, -1, This->content, -1, NULL, NULL);
665 if(do_load_from_moniker_hack(This))
666 return WINE_NS_LOAD_FROM_MONIKER;
667 }else {
668 BOOL cont = before_async_open(This, container);
670 if(!cont) {
671 TRACE("canceled\n");
672 return NS_ERROR_UNEXPECTED;
675 if(!container->doc) {
676 return This->channel
677 ? nsIChannel_AsyncOpen(This->channel, listener, context)
678 : NS_ERROR_UNEXPECTED;
681 hres = create_mon_for_nschannel(This, &mon);
682 if(FAILED(hres)) {
683 return NS_ERROR_UNEXPECTED;
685 set_current_mon(container->doc, mon);
688 *open = TRUE;
689 return NS_OK;
692 static nsresult async_open(nsChannel *This, NSContainer *container, nsIStreamListener *listener,
693 nsISupports *context)
695 BSCallback *bscallback;
696 IMoniker *mon = NULL;
697 nsresult nsres;
698 task_t *task;
699 HRESULT hres;
701 if(This->channel) {
702 if(This->post_data_stream) {
703 nsIUploadChannel *upload_channel;
705 nsres = nsIChannel_QueryInterface(This->channel, &IID_nsIUploadChannel,
706 (void**)&upload_channel);
707 if(NS_SUCCEEDED(nsres)) {
708 nsACString empty_string;
709 nsACString_Init(&empty_string, "");
711 nsres = nsIUploadChannel_SetUploadStream(upload_channel, This->post_data_stream,
712 &empty_string, -1);
713 nsIUploadChannel_Release(upload_channel);
714 if(NS_FAILED(nsres))
715 WARN("SetUploadStream failed: %08x\n", nsres);
717 nsACString_Finish(&empty_string);
721 nsres = nsIChannel_AsyncOpen(This->channel, listener, context);
723 if(mon)
724 IMoniker_Release(mon);
726 if(NS_FAILED(nsres) && (This->load_flags & LOAD_INITIAL_DOCUMENT_URI))
727 return WINE_NS_LOAD_FROM_MONIKER;
728 return nsres;
731 TRACE("channel == NULL\n");
733 hres = create_mon_for_nschannel(This, &mon);
734 if(FAILED(hres))
735 return NS_ERROR_UNEXPECTED;
737 bscallback = create_bscallback(mon);
738 IMoniker_Release(mon);
740 nsIChannel_AddRef(NSCHANNEL(This));
741 bscallback->nschannel = This;
743 nsIStreamListener_AddRef(listener);
744 bscallback->nslistener = listener;
746 if(context) {
747 nsISupports_AddRef(context);
748 bscallback->nscontext = context;
751 task = heap_alloc(sizeof(task_t));
753 task->doc = container->doc;
754 task->task_id = TASK_START_BINDING;
755 task->next = NULL;
756 task->bscallback = bscallback;
758 push_task(task);
760 return NS_OK;
763 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
764 nsISupports *aContext)
766 nsChannel *This = NSCHANNEL_THIS(iface);
767 NSContainer *container;
768 PRBool is_doc_uri;
769 BOOL open = TRUE;
770 nsresult nsres = NS_OK;
772 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
774 nsIWineURI_GetNSContainer(This->uri, &container);
775 if(!container) {
776 TRACE("container = NULL\n");
777 return This->channel
778 ? nsIChannel_AsyncOpen(This->channel, aListener, aContext)
779 : NS_ERROR_UNEXPECTED;
782 nsIWineURI_GetIsDocumentURI(This->uri, &is_doc_uri);
784 if(is_doc_uri && (This->load_flags & LOAD_INITIAL_DOCUMENT_URI))
785 nsres = async_open_doc_uri(This, container, aListener, aContext, &open);
787 if(open)
788 nsres = async_open(This, container, aListener, aContext);
790 nsIWebBrowserChrome_Release(NSWBCHROME(container));
791 return nsres;
794 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
796 nsChannel *This = NSCHANNEL_THIS(iface);
798 TRACE("(%p)->(%p)\n", This, aRequestMethod);
800 if(This->http_channel)
801 return nsIHttpChannel_GetRequestMethod(This->http_channel, aRequestMethod);
803 return NS_ERROR_NOT_IMPLEMENTED;
806 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
807 const nsACString *aRequestMethod)
809 nsChannel *This = NSCHANNEL_THIS(iface);
811 TRACE("(%p)->(%p)\n", This, aRequestMethod);
813 if(This->http_channel)
814 return nsIHttpChannel_SetRequestMethod(This->http_channel, aRequestMethod);
816 return NS_ERROR_NOT_IMPLEMENTED;
819 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
821 nsChannel *This = NSCHANNEL_THIS(iface);
823 TRACE("(%p)->(%p)\n", This, aReferrer);
825 if(This->http_channel)
826 return nsIHttpChannel_GetReferrer(This->http_channel, aReferrer);
828 return NS_ERROR_NOT_IMPLEMENTED;
831 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
833 nsChannel *This = NSCHANNEL_THIS(iface);
835 TRACE("(%p)->(%p)\n", This, aReferrer);
837 if(This->http_channel)
838 return nsIHttpChannel_SetReferrer(This->http_channel, aReferrer);
840 return NS_ERROR_NOT_IMPLEMENTED;
843 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
844 const nsACString *aHeader, nsACString *_retval)
846 nsChannel *This = NSCHANNEL_THIS(iface);
848 TRACE("(%p)->(%p %p)\n", This, aHeader, _retval);
850 if(This->http_channel)
851 return nsIHttpChannel_GetRequestHeader(This->http_channel, aHeader, _retval);
853 return NS_ERROR_NOT_IMPLEMENTED;
856 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
857 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
859 nsChannel *This = NSCHANNEL_THIS(iface);
861 TRACE("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
863 if(This->http_channel)
864 return nsIHttpChannel_SetRequestHeader(This->http_channel, aHeader, aValue, aMerge);
866 return NS_ERROR_NOT_IMPLEMENTED;
869 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
870 nsIHttpHeaderVisitor *aVisitor)
872 nsChannel *This = NSCHANNEL_THIS(iface);
874 TRACE("(%p)->(%p)\n", This, aVisitor);
876 if(This->http_channel)
877 return nsIHttpChannel_VisitRequestHeaders(This->http_channel, aVisitor);
879 return NS_ERROR_NOT_IMPLEMENTED;
882 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
884 nsChannel *This = NSCHANNEL_THIS(iface);
886 TRACE("(%p)->(%p)\n", This, aAllowPipelining);
888 if(This->http_channel)
889 return nsIHttpChannel_GetAllowPipelining(This->http_channel, aAllowPipelining);
891 return NS_ERROR_NOT_IMPLEMENTED;
894 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
896 nsChannel *This = NSCHANNEL_THIS(iface);
898 TRACE("(%p)->(%x)\n", This, aAllowPipelining);
900 if(This->http_channel)
901 return nsIHttpChannel_SetAllowPipelining(This->http_channel, aAllowPipelining);
903 return NS_ERROR_NOT_IMPLEMENTED;
906 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
908 nsChannel *This = NSCHANNEL_THIS(iface);
910 TRACE("(%p)->(%p)\n", This, aRedirectionLimit);
912 if(This->http_channel)
913 return nsIHttpChannel_GetRedirectionLimit(This->http_channel, aRedirectionLimit);
915 return NS_ERROR_NOT_IMPLEMENTED;
918 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
920 nsChannel *This = NSCHANNEL_THIS(iface);
922 TRACE("(%p)->(%u)\n", This, aRedirectionLimit);
924 if(This->http_channel)
925 return nsIHttpChannel_SetRedirectionLimit(This->http_channel, aRedirectionLimit);
927 return NS_ERROR_NOT_IMPLEMENTED;
930 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
932 nsChannel *This = NSCHANNEL_THIS(iface);
934 TRACE("(%p)->(%p)\n", This, aResponseStatus);
936 if(This->http_channel)
937 return nsIHttpChannel_GetResponseStatus(This->http_channel, aResponseStatus);
939 return NS_ERROR_NOT_IMPLEMENTED;
942 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
943 nsACString *aResponseStatusText)
945 nsChannel *This = NSCHANNEL_THIS(iface);
947 TRACE("(%p)->(%p)\n", This, aResponseStatusText);
949 if(This->http_channel)
950 return nsIHttpChannel_GetResponseStatusText(This->http_channel, aResponseStatusText);
952 return NS_ERROR_NOT_IMPLEMENTED;
955 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
956 PRBool *aRequestSucceeded)
958 nsChannel *This = NSCHANNEL_THIS(iface);
960 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
962 if(This->http_channel)
963 return nsIHttpChannel_GetRequestSucceeded(This->http_channel, aRequestSucceeded);
965 return NS_ERROR_NOT_IMPLEMENTED;
968 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
969 const nsACString *header, nsACString *_retval)
971 nsChannel *This = NSCHANNEL_THIS(iface);
973 TRACE("(%p)->(%p %p)\n", This, header, _retval);
975 if(This->http_channel)
976 return nsIHttpChannel_GetResponseHeader(This->http_channel, header, _retval);
978 return NS_ERROR_NOT_IMPLEMENTED;
981 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
982 const nsACString *header, const nsACString *value, PRBool merge)
984 nsChannel *This = NSCHANNEL_THIS(iface);
986 TRACE("(%p)->(%p %p %x)\n", This, header, value, merge);
988 if(This->http_channel)
989 return nsIHttpChannel_SetResponseHeader(This->http_channel, header, value, merge);
991 return NS_ERROR_NOT_IMPLEMENTED;
994 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
995 nsIHttpHeaderVisitor *aVisitor)
997 nsChannel *This = NSCHANNEL_THIS(iface);
999 TRACE("(%p)->(%p)\n", This, aVisitor);
1001 if(This->http_channel)
1002 return nsIHttpChannel_VisitResponseHeaders(This->http_channel, aVisitor);
1004 return NS_ERROR_NOT_IMPLEMENTED;
1007 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
1009 nsChannel *This = NSCHANNEL_THIS(iface);
1011 TRACE("(%p)->(%p)\n", This, _retval);
1013 if(This->http_channel)
1014 return nsIHttpChannel_IsNoStoreResponse(This->http_channel, _retval);
1016 return NS_ERROR_NOT_IMPLEMENTED;
1019 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
1021 nsChannel *This = NSCHANNEL_THIS(iface);
1023 TRACE("(%p)->(%p)\n", This, _retval);
1025 if(This->http_channel)
1026 return nsIHttpChannel_IsNoCacheResponse(This->http_channel, _retval);
1028 return NS_ERROR_NOT_IMPLEMENTED;
1031 #undef NSCHANNEL_THIS
1033 static const nsIHttpChannelVtbl nsChannelVtbl = {
1034 nsChannel_QueryInterface,
1035 nsChannel_AddRef,
1036 nsChannel_Release,
1037 nsChannel_GetName,
1038 nsChannel_IsPending,
1039 nsChannel_GetStatus,
1040 nsChannel_Cancel,
1041 nsChannel_Suspend,
1042 nsChannel_Resume,
1043 nsChannel_GetLoadGroup,
1044 nsChannel_SetLoadGroup,
1045 nsChannel_GetLoadFlags,
1046 nsChannel_SetLoadFlags,
1047 nsChannel_GetOriginalURI,
1048 nsChannel_SetOriginalURI,
1049 nsChannel_GetURI,
1050 nsChannel_GetOwner,
1051 nsChannel_SetOwner,
1052 nsChannel_GetNotificationCallbacks,
1053 nsChannel_SetNotificationCallbacks,
1054 nsChannel_GetSecurityInfo,
1055 nsChannel_GetContentType,
1056 nsChannel_SetContentType,
1057 nsChannel_GetContentCharset,
1058 nsChannel_SetContentCharset,
1059 nsChannel_GetContentLength,
1060 nsChannel_SetContentLength,
1061 nsChannel_Open,
1062 nsChannel_AsyncOpen,
1063 nsChannel_GetRequestMethod,
1064 nsChannel_SetRequestMethod,
1065 nsChannel_GetReferrer,
1066 nsChannel_SetReferrer,
1067 nsChannel_GetRequestHeader,
1068 nsChannel_SetRequestHeader,
1069 nsChannel_VisitRequestHeaders,
1070 nsChannel_GetAllowPipelining,
1071 nsChannel_SetAllowPipelining,
1072 nsChannel_GetRedirectionLimit,
1073 nsChannel_SetRedirectionLimit,
1074 nsChannel_GetResponseStatus,
1075 nsChannel_GetResponseStatusText,
1076 nsChannel_GetRequestSucceeded,
1077 nsChannel_GetResponseHeader,
1078 nsChannel_SetResponseHeader,
1079 nsChannel_VisitResponseHeaders,
1080 nsChannel_IsNoStoreResponse,
1081 nsChannel_IsNoCacheResponse
1084 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1086 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1087 nsQIResult result)
1089 nsChannel *This = NSUPCHANNEL_THIS(iface);
1090 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1093 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1095 nsChannel *This = NSUPCHANNEL_THIS(iface);
1096 return nsIChannel_AddRef(NSCHANNEL(This));
1099 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1101 nsChannel *This = NSUPCHANNEL_THIS(iface);
1102 return nsIChannel_Release(NSCHANNEL(This));
1105 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1106 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1108 nsChannel *This = NSUPCHANNEL_THIS(iface);
1109 const char *content_type;
1111 TRACE("(%p)->(%p %p %d)\n", This, aStream, aContentType, aContentLength);
1113 if(This->post_data_stream)
1114 nsIInputStream_Release(This->post_data_stream);
1116 if(aContentType) {
1117 nsACString_GetData(aContentType, &content_type);
1118 if(*content_type)
1119 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
1122 if(aContentLength != -1)
1123 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1125 if(aStream)
1126 nsIInputStream_AddRef(aStream);
1127 This->post_data_stream = aStream;
1129 return NS_OK;
1132 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1133 nsIInputStream **aUploadStream)
1135 nsChannel *This = NSUPCHANNEL_THIS(iface);
1137 TRACE("(%p)->(%p)\n", This, aUploadStream);
1139 if(This->post_data_stream)
1140 nsIInputStream_AddRef(This->post_data_stream);
1142 *aUploadStream = This->post_data_stream;
1143 return NS_OK;
1146 #undef NSUPCHANNEL_THIS
1148 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1149 nsUploadChannel_QueryInterface,
1150 nsUploadChannel_AddRef,
1151 nsUploadChannel_Release,
1152 nsUploadChannel_SetUploadStream,
1153 nsUploadChannel_GetUploadStream
1156 #define NSURI_THIS(iface) DEFINE_THIS(nsURI, WineURI, iface)
1158 static nsresult NSAPI nsURI_QueryInterface(nsIWineURI *iface, nsIIDRef riid, nsQIResult result)
1160 nsURI *This = NSURI_THIS(iface);
1162 *result = NULL;
1164 if(IsEqualGUID(&IID_nsISupports, riid)) {
1165 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1166 *result = NSURI(This);
1167 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1168 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1169 *result = NSURI(This);
1170 }else if(IsEqualGUID(&IID_nsIWineURI, riid)) {
1171 TRACE("(%p)->(IID_nsIWineURI %p)\n", This, result);
1172 *result = NSURI(This);
1175 if(*result) {
1176 nsIURI_AddRef(NSURI(This));
1177 return NS_OK;
1180 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1181 return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1184 static nsrefcnt NSAPI nsURI_AddRef(nsIWineURI *iface)
1186 nsURI *This = NSURI_THIS(iface);
1187 LONG ref = InterlockedIncrement(&This->ref);
1189 TRACE("(%p) ref=%d\n", This, ref);
1191 return ref;
1194 static nsrefcnt NSAPI nsURI_Release(nsIWineURI *iface)
1196 nsURI *This = NSURI_THIS(iface);
1197 LONG ref = InterlockedDecrement(&This->ref);
1199 TRACE("(%p) ref=%d\n", This, ref);
1201 if(!ref) {
1202 if(This->container)
1203 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1204 if(This->uri)
1205 nsIURI_Release(This->uri);
1206 heap_free(This->wine_url);
1207 heap_free(This);
1210 return ref;
1213 static nsresult NSAPI nsURI_GetSpec(nsIWineURI *iface, nsACString *aSpec)
1215 nsURI *This = NSURI_THIS(iface);
1217 TRACE("(%p)->(%p)\n", This, aSpec);
1219 if(This->use_wine_url) {
1220 char speca[INTERNET_MAX_URL_LENGTH] = "wine:";
1221 WideCharToMultiByte(CP_ACP, 0, This->wine_url, -1, speca+5, sizeof(speca)-5, NULL, NULL);
1222 nsACString_SetData(aSpec, speca);
1224 return NS_OK;
1227 if(This->uri)
1228 return nsIURI_GetSpec(This->uri, aSpec);
1230 TRACE("returning error\n");
1231 return NS_ERROR_NOT_IMPLEMENTED;
1235 static nsresult NSAPI nsURI_SetSpec(nsIWineURI *iface, const nsACString *aSpec)
1237 nsURI *This = NSURI_THIS(iface);
1239 TRACE("(%p)->(%p)\n", This, aSpec);
1241 if(This->uri)
1242 return nsIURI_SetSpec(This->uri, aSpec);
1244 FIXME("default action not implemented\n");
1245 return NS_ERROR_NOT_IMPLEMENTED;
1248 static nsresult NSAPI nsURI_GetPrePath(nsIWineURI *iface, nsACString *aPrePath)
1250 nsURI *This = NSURI_THIS(iface);
1252 TRACE("(%p)->(%p)\n", This, aPrePath);
1254 if(This->uri)
1255 return nsIURI_GetPrePath(This->uri, aPrePath);
1257 FIXME("default action not implemented\n");
1258 return NS_ERROR_NOT_IMPLEMENTED;
1261 static nsresult NSAPI nsURI_GetScheme(nsIWineURI *iface, nsACString *aScheme)
1263 nsURI *This = NSURI_THIS(iface);
1265 TRACE("(%p)->(%p)\n", This, aScheme);
1267 if(This->use_wine_url) {
1269 * For Gecko we set scheme to unknown so it won't be handled
1270 * as any special case.
1272 nsACString_SetData(aScheme, "wine");
1273 return NS_OK;
1276 if(This->uri)
1277 return nsIURI_GetScheme(This->uri, aScheme);
1279 TRACE("returning error\n");
1280 return NS_ERROR_NOT_IMPLEMENTED;
1283 static nsresult NSAPI nsURI_SetScheme(nsIWineURI *iface, const nsACString *aScheme)
1285 nsURI *This = NSURI_THIS(iface);
1287 TRACE("(%p)->(%p)\n", This, aScheme);
1289 if(This->uri)
1290 return nsIURI_SetScheme(This->uri, aScheme);
1292 FIXME("default action not implemented\n");
1293 return NS_ERROR_NOT_IMPLEMENTED;
1296 static nsresult NSAPI nsURI_GetUserPass(nsIWineURI *iface, nsACString *aUserPass)
1298 nsURI *This = NSURI_THIS(iface);
1300 TRACE("(%p)->(%p)\n", This, aUserPass);
1302 if(This->uri)
1303 return nsIURI_GetUserPass(This->uri, aUserPass);
1305 FIXME("default action not implemented\n");
1306 return NS_ERROR_NOT_IMPLEMENTED;
1309 static nsresult NSAPI nsURI_SetUserPass(nsIWineURI *iface, const nsACString *aUserPass)
1311 nsURI *This = NSURI_THIS(iface);
1313 TRACE("(%p)->(%p)\n", This, aUserPass);
1315 if(This->uri)
1316 return nsIURI_SetUserPass(This->uri, aUserPass);
1318 FIXME("default action not implemented\n");
1319 return NS_ERROR_NOT_IMPLEMENTED;
1322 static nsresult NSAPI nsURI_GetUsername(nsIWineURI *iface, nsACString *aUsername)
1324 nsURI *This = NSURI_THIS(iface);
1326 TRACE("(%p)->(%p)\n", This, aUsername);
1328 if(This->uri)
1329 return nsIURI_GetUsername(This->uri, aUsername);
1331 FIXME("default action not implemented\n");
1332 return NS_ERROR_NOT_IMPLEMENTED;
1335 static nsresult NSAPI nsURI_SetUsername(nsIWineURI *iface, const nsACString *aUsername)
1337 nsURI *This = NSURI_THIS(iface);
1339 TRACE("(%p)->(%p)\n", This, aUsername);
1341 if(This->uri)
1342 return nsIURI_SetUsername(This->uri, aUsername);
1344 FIXME("default action not implemented\n");
1345 return NS_ERROR_NOT_IMPLEMENTED;
1348 static nsresult NSAPI nsURI_GetPassword(nsIWineURI *iface, nsACString *aPassword)
1350 nsURI *This = NSURI_THIS(iface);
1352 TRACE("(%p)->(%p)\n", This, aPassword);
1354 if(This->uri)
1355 return nsIURI_GetPassword(This->uri, aPassword);
1357 FIXME("default action not implemented\n");
1358 return NS_ERROR_NOT_IMPLEMENTED;
1361 static nsresult NSAPI nsURI_SetPassword(nsIWineURI *iface, const nsACString *aPassword)
1363 nsURI *This = NSURI_THIS(iface);
1365 TRACE("(%p)->(%p)\n", This, aPassword);
1367 if(This->uri)
1368 return nsIURI_SetPassword(This->uri, aPassword);
1370 FIXME("default action not implemented\n");
1371 return NS_ERROR_NOT_IMPLEMENTED;
1374 static nsresult NSAPI nsURI_GetHostPort(nsIWineURI *iface, nsACString *aHostPort)
1376 nsURI *This = NSURI_THIS(iface);
1378 TRACE("(%p)->(%p)\n", This, aHostPort);
1380 if(This->uri)
1381 return nsIURI_GetHostPort(This->uri, aHostPort);
1383 FIXME("default action not implemented\n");
1384 return NS_ERROR_NOT_IMPLEMENTED;
1387 static nsresult NSAPI nsURI_SetHostPort(nsIWineURI *iface, const nsACString *aHostPort)
1389 nsURI *This = NSURI_THIS(iface);
1391 TRACE("(%p)->(%p)\n", This, aHostPort);
1393 if(This->uri)
1394 return nsIURI_SetHostPort(This->uri, aHostPort);
1396 FIXME("default action not implemented\n");
1397 return NS_ERROR_NOT_IMPLEMENTED;
1400 static nsresult NSAPI nsURI_GetHost(nsIWineURI *iface, nsACString *aHost)
1402 nsURI *This = NSURI_THIS(iface);
1404 TRACE("(%p)->(%p)\n", This, aHost);
1406 if(This->uri)
1407 return nsIURI_GetHost(This->uri, aHost);
1409 FIXME("default action not implemented\n");
1410 return NS_ERROR_NOT_IMPLEMENTED;
1413 static nsresult NSAPI nsURI_SetHost(nsIWineURI *iface, const nsACString *aHost)
1415 nsURI *This = NSURI_THIS(iface);
1417 TRACE("(%p)->(%p)\n", This, aHost);
1419 if(This->uri)
1420 return nsIURI_SetHost(This->uri, aHost);
1422 FIXME("default action not implemented\n");
1423 return NS_ERROR_NOT_IMPLEMENTED;
1426 static nsresult NSAPI nsURI_GetPort(nsIWineURI *iface, PRInt32 *aPort)
1428 nsURI *This = NSURI_THIS(iface);
1430 TRACE("(%p)->(%p)\n", This, aPort);
1432 if(This->uri)
1433 return nsIURI_GetPort(This->uri, aPort);
1435 FIXME("default action not implemented\n");
1436 return NS_ERROR_NOT_IMPLEMENTED;
1439 static nsresult NSAPI nsURI_SetPort(nsIWineURI *iface, PRInt32 aPort)
1441 nsURI *This = NSURI_THIS(iface);
1443 TRACE("(%p)->(%d)\n", This, aPort);
1445 if(This->uri)
1446 return nsIURI_SetPort(This->uri, aPort);
1448 FIXME("default action not implemented\n");
1449 return NS_ERROR_NOT_IMPLEMENTED;
1452 static nsresult NSAPI nsURI_GetPath(nsIWineURI *iface, nsACString *aPath)
1454 nsURI *This = NSURI_THIS(iface);
1456 TRACE("(%p)->(%p)\n", This, aPath);
1458 if(This->uri)
1459 return nsIURI_GetPath(This->uri, aPath);
1461 FIXME("default action not implemented\n");
1462 return NS_ERROR_NOT_IMPLEMENTED;
1465 static nsresult NSAPI nsURI_SetPath(nsIWineURI *iface, const nsACString *aPath)
1467 nsURI *This = NSURI_THIS(iface);
1468 const char *path;
1470 nsACString_GetData(aPath, &path);
1471 TRACE("(%p)->(%p(%s))\n", This, aPath, debugstr_a(path));
1474 if(This->wine_url) {
1475 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
1476 DWORD size = sizeof(new_url)/sizeof(WCHAR);
1477 LPWSTR pathw;
1478 HRESULT hres;
1480 pathw = heap_strdupAtoW(path);
1481 hres = UrlCombineW(This->wine_url, pathw, new_url, &size, 0);
1482 heap_free(pathw);
1483 if(SUCCEEDED(hres))
1484 nsIWineURI_SetWineURL(NSWINEURI(This), new_url);
1485 else
1486 WARN("UrlCombine failed: %08x\n", hres);
1489 if(!This->uri)
1490 return NS_OK;
1492 return nsIURI_SetPath(This->uri, aPath);
1495 static nsresult NSAPI nsURI_Equals(nsIWineURI *iface, nsIURI *other, PRBool *_retval)
1497 nsURI *This = NSURI_THIS(iface);
1499 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1501 if(This->uri)
1502 return nsIURI_Equals(This->uri, other, _retval);
1504 FIXME("default action not implemented\n");
1505 return NS_ERROR_NOT_IMPLEMENTED;
1508 static nsresult NSAPI nsURI_SchemeIs(nsIWineURI *iface, const char *scheme, PRBool *_retval)
1510 nsURI *This = NSURI_THIS(iface);
1512 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1514 if(This->use_wine_url) {
1515 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
1516 int len = MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR))-1;
1518 *_retval = strlenW(This->wine_url) > len
1519 && This->wine_url[len] == ':'
1520 && !memcmp(buf, This->wine_url, len*sizeof(WCHAR));
1521 return NS_OK;
1524 if(This->uri)
1525 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1527 TRACE("returning error\n");
1528 return NS_ERROR_NOT_IMPLEMENTED;
1531 static nsresult NSAPI nsURI_Clone(nsIWineURI *iface, nsIURI **_retval)
1533 nsURI *This = NSURI_THIS(iface);
1535 TRACE("(%p)->(%p)\n", This, _retval);
1537 if(This->uri) {
1538 nsIURI *uri;
1539 nsIWineURI *wine_uri;
1540 nsresult nsres;
1542 nsres = nsIURI_Clone(This->uri, &uri);
1543 if(NS_FAILED(nsres)) {
1544 WARN("Clone failed: %08x\n", nsres);
1545 return nsres;
1548 nsres = create_uri(uri, This->container, &wine_uri);
1549 *_retval = (nsIURI*)wine_uri;
1550 if(NS_SUCCEEDED(nsres))
1551 return nsIWineURI_SetWineURL(wine_uri, This->wine_url);
1552 return nsres;
1555 FIXME("default action not implemented\n");
1556 return NS_ERROR_NOT_IMPLEMENTED;
1559 static nsresult NSAPI nsURI_Resolve(nsIWineURI *iface, const nsACString *arelativePath,
1560 nsACString *_retval)
1562 nsURI *This = NSURI_THIS(iface);
1564 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1566 if(This->uri)
1567 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1569 FIXME("default action not implemented\n");
1570 return NS_ERROR_NOT_IMPLEMENTED;
1573 static nsresult NSAPI nsURI_GetAsciiSpec(nsIWineURI *iface, nsACString *aAsciiSpec)
1575 nsURI *This = NSURI_THIS(iface);
1577 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1579 if(This->use_wine_url)
1580 return nsIURI_GetSpec(NSURI(This), aAsciiSpec);
1582 if(This->uri)
1583 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1585 TRACE("returning error\n");
1586 return NS_ERROR_NOT_IMPLEMENTED;
1589 static nsresult NSAPI nsURI_GetAsciiHost(nsIWineURI *iface, nsACString *aAsciiHost)
1591 nsURI *This = NSURI_THIS(iface);
1593 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1595 if(This->uri)
1596 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1598 FIXME("default action not implemented\n");
1599 return NS_ERROR_NOT_IMPLEMENTED;
1602 static nsresult NSAPI nsURI_GetOriginCharset(nsIWineURI *iface, nsACString *aOriginCharset)
1604 nsURI *This = NSURI_THIS(iface);
1606 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1608 if(This->uri)
1609 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1611 FIXME("default action not implemented\n");
1612 return NS_ERROR_NOT_IMPLEMENTED;
1615 static nsresult NSAPI nsURI_GetNSContainer(nsIWineURI *iface, NSContainer **aContainer)
1617 nsURI *This = NSURI_THIS(iface);
1619 TRACE("(%p)->(%p)\n", This, aContainer);
1621 if(This->container)
1622 nsIWebBrowserChrome_AddRef(NSWBCHROME(This->container));
1623 *aContainer = This->container;
1625 return NS_OK;
1628 static nsresult NSAPI nsURI_SetNSContainer(nsIWineURI *iface, NSContainer *aContainer)
1630 nsURI *This = NSURI_THIS(iface);
1632 TRACE("(%p)->(%p)\n", This, aContainer);
1634 if(This->container) {
1635 if(This->container == aContainer)
1636 return NS_OK;
1637 TRACE("Changing %p -> %p\n", This->container, aContainer);
1638 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1641 if(aContainer)
1642 nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer));
1643 This->container = aContainer;
1645 return NS_OK;
1648 static nsresult NSAPI nsURI_GetIsDocumentURI(nsIWineURI *iface, PRBool *aIsDocumentURI)
1650 nsURI *This = NSURI_THIS(iface);
1652 TRACE("(%p)->(%p)\n", This, aIsDocumentURI);
1654 *aIsDocumentURI = This->is_doc_uri;
1655 return NS_OK;
1658 static nsresult NSAPI nsURI_SetIsDocumentURI(nsIWineURI *iface, PRBool aIsDocumentURI)
1660 nsURI *This = NSURI_THIS(iface);
1662 TRACE("(%p)->(%x)\n", This, aIsDocumentURI);
1664 This->is_doc_uri = aIsDocumentURI;
1665 return NS_OK;
1668 static nsresult NSAPI nsURI_GetWineURL(nsIWineURI *iface, LPCWSTR *aURL)
1670 nsURI *This = NSURI_THIS(iface);
1672 TRACE("(%p)->(%p)\n", This, aURL);
1674 *aURL = This->wine_url;
1675 return NS_OK;
1678 static nsresult NSAPI nsURI_SetWineURL(nsIWineURI *iface, LPCWSTR aURL)
1680 nsURI *This = NSURI_THIS(iface);
1682 static const WCHAR wszFtp[] = {'f','t','p',':'};
1683 static const WCHAR wszHttp[] = {'h','t','t','p',':'};
1684 static const WCHAR wszHttps[] = {'h','t','t','p','s',':'};
1686 TRACE("(%p)->(%s)\n", This, debugstr_w(aURL));
1688 heap_free(This->wine_url);
1690 if(aURL) {
1691 int len = strlenW(aURL)+1;
1692 This->wine_url = heap_alloc(len*sizeof(WCHAR));
1693 memcpy(This->wine_url, aURL, len*sizeof(WCHAR));
1695 /* FIXME: Always use wine url */
1696 This->use_wine_url =
1697 strncmpW(aURL, wszFtp, sizeof(wszFtp)/sizeof(WCHAR))
1698 && strncmpW(aURL, wszHttp, sizeof(wszHttp)/sizeof(WCHAR))
1699 && strncmpW(aURL, wszHttps, sizeof(wszHttps)/sizeof(WCHAR));
1700 }else {
1701 This->wine_url = NULL;
1702 This->use_wine_url = FALSE;
1705 return NS_OK;
1708 #undef NSURI_THIS
1710 static const nsIWineURIVtbl nsWineURIVtbl = {
1711 nsURI_QueryInterface,
1712 nsURI_AddRef,
1713 nsURI_Release,
1714 nsURI_GetSpec,
1715 nsURI_SetSpec,
1716 nsURI_GetPrePath,
1717 nsURI_GetScheme,
1718 nsURI_SetScheme,
1719 nsURI_GetUserPass,
1720 nsURI_SetUserPass,
1721 nsURI_GetUsername,
1722 nsURI_SetUsername,
1723 nsURI_GetPassword,
1724 nsURI_SetPassword,
1725 nsURI_GetHostPort,
1726 nsURI_SetHostPort,
1727 nsURI_GetHost,
1728 nsURI_SetHost,
1729 nsURI_GetPort,
1730 nsURI_SetPort,
1731 nsURI_GetPath,
1732 nsURI_SetPath,
1733 nsURI_Equals,
1734 nsURI_SchemeIs,
1735 nsURI_Clone,
1736 nsURI_Resolve,
1737 nsURI_GetAsciiSpec,
1738 nsURI_GetAsciiHost,
1739 nsURI_GetOriginCharset,
1740 nsURI_GetNSContainer,
1741 nsURI_SetNSContainer,
1742 nsURI_GetIsDocumentURI,
1743 nsURI_SetIsDocumentURI,
1744 nsURI_GetWineURL,
1745 nsURI_SetWineURL
1748 static nsresult create_uri(nsIURI *uri, NSContainer *container, nsIWineURI **_retval)
1750 nsURI *ret = heap_alloc(sizeof(nsURI));
1752 ret->lpWineURIVtbl = &nsWineURIVtbl;
1753 ret->ref = 1;
1754 ret->uri = uri;
1755 ret->container = container;
1756 ret->wine_url = NULL;
1757 ret->is_doc_uri = FALSE;
1758 ret->use_wine_url = FALSE;
1760 if(container)
1761 nsIWebBrowserChrome_AddRef(NSWBCHROME(container));
1763 TRACE("retval=%p\n", ret);
1764 *_retval = NSWINEURI(ret);
1765 return NS_OK;
1768 typedef struct {
1769 const nsIProtocolHandlerVtbl *lpProtocolHandlerVtbl;
1771 LONG ref;
1773 nsIProtocolHandler *nshandler;
1774 } nsProtocolHandler;
1776 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
1778 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
1780 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
1781 nsQIResult result)
1783 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1785 *result = NULL;
1787 if(IsEqualGUID(&IID_nsISupports, riid)) {
1788 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1789 *result = NSPROTHANDLER(This);
1790 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
1791 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
1792 *result = NSPROTHANDLER(This);
1793 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
1794 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
1795 return NS_NOINTERFACE;
1798 if(*result) {
1799 nsISupports_AddRef((nsISupports*)*result);
1800 return NS_OK;
1803 WARN("(%s %p)\n", debugstr_guid(riid), result);
1804 return NS_NOINTERFACE;
1807 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
1809 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1810 LONG ref = InterlockedIncrement(&This->ref);
1812 TRACE("(%p) ref=%d\n", This, ref);
1814 return ref;
1817 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
1819 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1820 LONG ref = InterlockedDecrement(&This->ref);
1822 TRACE("(%p) ref=%d\n", This, ref);
1824 if(!ref) {
1825 if(This->nshandler)
1826 nsIProtocolHandler_Release(This->nshandler);
1827 heap_free(This);
1830 return ref;
1833 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
1835 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1837 TRACE("(%p)->(%p)\n", This, aScheme);
1839 if(This->nshandler)
1840 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
1841 return NS_ERROR_NOT_IMPLEMENTED;
1844 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
1845 PRInt32 *aDefaultPort)
1847 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1849 TRACE("(%p)->(%p)\n", This, aDefaultPort);
1851 if(This->nshandler)
1852 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
1853 return NS_ERROR_NOT_IMPLEMENTED;
1856 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
1857 PRUint32 *aProtocolFlags)
1859 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1861 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
1863 if(This->nshandler)
1864 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
1865 return NS_ERROR_NOT_IMPLEMENTED;
1868 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
1869 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
1871 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1873 TRACE("((%p)->%p %s %p %p)\n", This, aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
1875 if(This->nshandler)
1876 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
1877 return NS_ERROR_NOT_IMPLEMENTED;
1880 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
1881 nsIURI *aURI, nsIChannel **_retval)
1883 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1885 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
1887 if(This->nshandler)
1888 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
1889 return NS_ERROR_NOT_IMPLEMENTED;
1892 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
1893 PRInt32 port, const char *scheme, PRBool *_retval)
1895 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
1897 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
1899 if(This->nshandler)
1900 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
1901 return NS_ERROR_NOT_IMPLEMENTED;
1904 #undef NSPROTHANDLER_THIS
1906 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
1907 nsProtocolHandler_QueryInterface,
1908 nsProtocolHandler_AddRef,
1909 nsProtocolHandler_Release,
1910 nsProtocolHandler_GetScheme,
1911 nsProtocolHandler_GetDefaultPort,
1912 nsProtocolHandler_GetProtocolFlags,
1913 nsProtocolHandler_NewURI,
1914 nsProtocolHandler_NewChannel,
1915 nsProtocolHandler_AllowPort
1918 static nsIProtocolHandler *create_protocol_handler(nsIProtocolHandler *nshandler)
1920 nsProtocolHandler *ret = heap_alloc(sizeof(nsProtocolHandler));
1922 ret->lpProtocolHandlerVtbl = &nsProtocolHandlerVtbl;
1923 ret->ref = 1;
1924 ret->nshandler = nshandler;
1926 return NSPROTHANDLER(ret);
1929 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
1930 nsQIResult result)
1932 *result = NULL;
1934 if(IsEqualGUID(&IID_nsISupports, riid)
1935 || IsEqualGUID(&IID_nsIIOService, riid)) {
1936 *result = iface;
1937 nsIIOService_AddRef(iface);
1938 return S_OK;
1941 WARN("(%s %p)\n", debugstr_guid(riid), result);
1942 return NS_NOINTERFACE;
1945 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
1947 return 2;
1950 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
1952 return 1;
1955 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
1956 nsIProtocolHandler **_retval)
1958 nsIExternalProtocolHandler *nsexthandler;
1959 nsIProtocolHandler *nshandler;
1960 nsresult nsres;
1962 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1964 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
1965 if(NS_FAILED(nsres)) {
1966 WARN("GetProtocolHandler failed: %08x\n", nsres);
1967 return nsres;
1970 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
1971 (void**)&nsexthandler);
1972 if(NS_FAILED(nsres)) {
1973 *_retval = nshandler;
1974 return NS_OK;
1977 nsIExternalProtocolHandler_Release(nsexthandler);
1978 *_retval = create_protocol_handler(nshandler);
1979 TRACE("return %p\n", *_retval);
1980 return NS_OK;
1983 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
1984 PRUint32 *_retval)
1986 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1987 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
1990 static BOOL is_gecko_special_uri(const char *spec)
1992 static const char chromeW[] = "chrome:";
1993 static const char jarW[] = "jar:";
1994 static const char resourceW[] = "resource:";
1995 static const char javascriptW[] = "javascript:";
1997 return !strncasecmp(spec, chromeW, sizeof(chromeW)-1)
1998 || !strncasecmp(spec, resourceW, sizeof(resourceW)-1)
1999 || !strncasecmp(spec, jarW, sizeof(jarW)-1)
2000 || !strncasecmp(spec, javascriptW, sizeof(javascriptW)-1);
2003 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
2004 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2006 const char *spec = NULL;
2007 nsACString spec_str;
2008 NSContainer *nscontainer = NULL;
2009 nsIURI *uri = NULL;
2010 LPCWSTR base_wine_url = NULL;
2011 nsIWineURI *base_wine_uri = NULL, *wine_uri;
2012 BOOL is_wine_uri = FALSE;
2013 nsresult nsres;
2015 nsACString_GetData(aSpec, &spec);
2017 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
2018 aBaseURI, _retval);
2020 if(is_gecko_special_uri(spec))
2021 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2023 if(!strncmp(spec, "wine:", 5)) {
2024 spec += 5;
2025 is_wine_uri = TRUE;
2028 if(aBaseURI) {
2029 nsACString base_uri_str;
2030 const char *base_uri = NULL;
2032 nsACString_Init(&base_uri_str, NULL);
2034 nsres = nsIURI_GetSpec(aBaseURI, &base_uri_str);
2035 if(NS_SUCCEEDED(nsres)) {
2036 nsACString_GetData(&base_uri_str, &base_uri);
2037 TRACE("base_uri=%s\n", debugstr_a(base_uri));
2038 }else {
2039 ERR("GetSpec failed: %08x\n", nsres);
2042 nsACString_Finish(&base_uri_str);
2045 nsACString_Init(&spec_str, spec);
2046 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
2047 nsACString_Finish(&spec_str);
2048 if(NS_FAILED(nsres))
2049 TRACE("NewURI failed: %08x\n", nsres);
2051 if(aBaseURI) {
2052 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsIWineURI, (void**)&base_wine_uri);
2053 if(NS_SUCCEEDED(nsres)) {
2054 nsIWineURI_GetNSContainer(base_wine_uri, &nscontainer);
2055 nsIWineURI_GetWineURL(base_wine_uri, &base_wine_url);
2056 }else {
2057 TRACE("Could not get base nsIWineURI: %08x\n", nsres);
2061 nsres = create_uri(uri, nscontainer, &wine_uri);
2062 *_retval = (nsIURI*)wine_uri;
2064 if(nscontainer)
2065 nsIWebBrowserChrome_Release(NSWBCHROME(nscontainer));
2067 if(base_wine_url) {
2068 WCHAR url[INTERNET_MAX_URL_LENGTH], rel_url[INTERNET_MAX_URL_LENGTH];
2069 DWORD len;
2070 HRESULT hres;
2072 MultiByteToWideChar(CP_ACP, 0, spec, -1, rel_url, sizeof(rel_url)/sizeof(WCHAR));
2074 hres = CoInternetCombineUrl(base_wine_url, rel_url,
2075 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
2076 url, sizeof(url)/sizeof(WCHAR), &len, 0);
2077 if(SUCCEEDED(hres))
2078 nsIWineURI_SetWineURL(wine_uri, url);
2079 else
2080 WARN("CoCombineUrl failed: %08x\n", hres);
2081 }else if(is_wine_uri) {
2082 WCHAR url[INTERNET_MAX_URL_LENGTH];
2084 MultiByteToWideChar(CP_ACP, 0, spec, -1, url, sizeof(url)/sizeof(WCHAR));
2085 nsIWineURI_SetWineURL(wine_uri, url);
2088 if(base_wine_uri)
2089 nsIWineURI_Release(base_wine_uri);
2091 return nsres;
2094 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
2095 nsIURI **_retval)
2097 TRACE("(%p %p)\n", aFile, _retval);
2098 return nsIIOService_NewFileURI(nsio, aFile, _retval);
2101 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
2102 nsIChannel **_retval)
2104 nsIChannel *channel = NULL;
2105 nsChannel *ret;
2106 nsIWineURI *wine_uri;
2107 nsresult nsres;
2109 TRACE("(%p %p)\n", aURI, _retval);
2111 nsres = nsIIOService_NewChannelFromURI(nsio, aURI, &channel);
2112 if(NS_FAILED(nsres) && nsres != NS_ERROR_UNKNOWN_PROTOCOL) {
2113 WARN("NewChannelFromURI failed: %08x\n", nsres);
2114 *_retval = channel;
2115 return nsres;
2118 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
2119 if(NS_FAILED(nsres)) {
2120 WARN("Could not get nsIWineURI: %08x\n", nsres);
2121 *_retval = channel;
2122 return channel ? NS_OK : NS_ERROR_UNEXPECTED;
2125 ret = heap_alloc(sizeof(nsChannel));
2127 ret->lpHttpChannelVtbl = &nsChannelVtbl;
2128 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
2129 ret->ref = 1;
2130 ret->channel = channel;
2131 ret->http_channel = NULL;
2132 ret->uri = wine_uri;
2133 ret->post_data_stream = NULL;
2134 ret->load_group = NULL;
2135 ret->notif_callback = NULL;
2136 ret->load_flags = 0;
2137 ret->content = NULL;
2138 ret->charset = NULL;
2140 nsIURI_AddRef(aURI);
2141 ret->original_uri = aURI;
2143 if(channel)
2144 nsIChannel_QueryInterface(channel, &IID_nsIHttpChannel, (void**)&ret->http_channel);
2146 *_retval = NSCHANNEL(ret);
2147 return NS_OK;
2150 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
2151 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
2153 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2154 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2157 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
2159 TRACE("(%p)\n", aOffline);
2160 return nsIIOService_GetOffline(nsio, aOffline);
2163 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
2165 TRACE("(%x)\n", aOffline);
2166 return nsIIOService_SetOffline(nsio, aOffline);
2169 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
2170 const char *aScheme, PRBool *_retval)
2172 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
2173 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
2176 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
2177 nsACString * _retval)
2179 TRACE("(%p %p)\n", urlString, _retval);
2180 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
2183 static const nsIIOServiceVtbl nsIOServiceVtbl = {
2184 nsIOService_QueryInterface,
2185 nsIOService_AddRef,
2186 nsIOService_Release,
2187 nsIOService_GetProtocolHandler,
2188 nsIOService_GetProtocolFlags,
2189 nsIOService_NewURI,
2190 nsIOService_NewFileURI,
2191 nsIOService_NewChannelFromURI,
2192 nsIOService_NewChannel,
2193 nsIOService_GetOffline,
2194 nsIOService_SetOffline,
2195 nsIOService_AllowPort,
2196 nsIOService_ExtractScheme
2199 static nsIIOService nsIOService = { &nsIOServiceVtbl };
2201 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
2202 nsQIResult result)
2204 *result = NULL;
2206 if(IsEqualGUID(&IID_nsISupports, riid)) {
2207 TRACE("(IID_nsISupports %p)\n", result);
2208 *result = iface;
2209 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
2210 TRACE("(IID_nsIFactory %p)\n", result);
2211 *result = iface;
2214 if(*result) {
2215 nsIFactory_AddRef(iface);
2216 return NS_OK;
2219 WARN("(%s %p)\n", debugstr_guid(riid), result);
2220 return NS_NOINTERFACE;
2223 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
2225 return 2;
2228 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
2230 return 1;
2233 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
2234 nsISupports *aOuter, const nsIID *iid, void **result)
2236 return nsIIOService_QueryInterface(&nsIOService, iid, result);
2239 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
2241 WARN("(%x)\n", lock);
2242 return NS_OK;
2245 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
2246 nsIOServiceFactory_QueryInterface,
2247 nsIOServiceFactory_AddRef,
2248 nsIOServiceFactory_Release,
2249 nsIOServiceFactory_CreateInstance,
2250 nsIOServiceFactory_LockFactory
2253 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
2255 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
2257 nsIFactory *old_factory = NULL;
2258 nsresult nsres;
2260 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
2261 &IID_nsIFactory, (void**)&old_factory);
2262 if(NS_FAILED(nsres)) {
2263 ERR("Could not get factory: %08x\n", nsres);
2264 return;
2267 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
2268 if(NS_FAILED(nsres)) {
2269 ERR("Couldn not create nsIOService instance %08x\n", nsres);
2270 nsIFactory_Release(old_factory);
2271 return;
2274 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
2275 nsIFactory_Release(old_factory);
2276 if(NS_FAILED(nsres))
2277 ERR("UnregisterFactory failed: %08x\n", nsres);
2279 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
2280 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
2281 if(NS_FAILED(nsres))
2282 ERR("RegisterFactory failed: %08x\n", nsres);