Changes of picasa-wine-2.2.2820-5 except to configure
[wine/hacks.git] / dlls / mshtml / nsio.c
blob6ae9b1e8c4929cb4c570e8817f1b7c91e215e9f1
1 /*
2 * Copyright 2006 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 "ole2.h"
29 #include "shlguid.h"
30 #include "wininet.h"
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
35 #include "mshtml_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39 #define LOAD_INITIAL_DOCUMENT_URI 0x80000
41 #define NS_IOSERVICE_CLASSNAME "nsIOService"
42 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
44 static const IID NS_IOSERVICE_CID =
45 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
47 #define NS_COOKIESERVICE_CONTRACTID "@mozilla.org/cookieService;1"
49 static const IID NS_COOKIESERVICE_CID =
50 {0xc375fa80, 0x150f, 0x11d6, {0xa6, 0x18, 0x00, 0x10, 0xa4, 0x01, 0xeb, 0x10}};
52 static nsIIOService *nsio = NULL;
53 static nsICookieService *nscookie = NULL;
55 typedef struct {
56 const nsIHttpChannelVtbl *lpHttpChannelVtbl;
57 const nsIUploadChannelVtbl *lpUploadChannelVtbl;
59 LONG ref;
61 nsIChannel *channel;
62 nsIHttpChannel *http_channel;
63 nsIWineURI *uri;
64 nsIInputStream *post_data_stream;
65 nsILoadGroup *load_group;
66 nsIInterfaceRequestor *notif_callback;
67 nsLoadFlags load_flags;
68 nsIURI *original_uri;
69 } nsChannel;
71 typedef struct {
72 const nsIWineURIVtbl *lpWineURIVtbl;
74 LONG ref;
76 nsIURI *uri;
77 NSContainer *container;
78 } nsURI;
80 #define NSCHANNEL(x) ((nsIChannel*) &(x)->lpHttpChannelVtbl)
81 #define NSHTTPCHANNEL(x) ((nsIHttpChannel*) &(x)->lpHttpChannelVtbl)
82 #define NSUPCHANNEL(x) ((nsIUploadChannel*) &(x)->lpUploadChannelVtbl)
83 #define NSURI(x) ((nsIURI*) &(x)->lpWineURIVtbl)
85 static nsresult create_uri(nsIURI*,NSContainer*,nsIURI**);
87 static BOOL exec_shldocvw_67(HTMLDocument *doc, LPCWSTR url)
89 IOleCommandTarget *cmdtrg = NULL;
90 HRESULT hres;
92 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget,
93 (void**)&cmdtrg);
94 if(SUCCEEDED(hres)) {
95 VARIANT varUrl, varRes;
97 V_VT(&varUrl) = VT_BSTR;
98 V_BSTR(&varUrl) = SysAllocString(url);
99 V_VT(&varRes) = VT_BOOL;
101 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
103 IOleCommandTarget_Release(cmdtrg);
104 SysFreeString(V_BSTR(&varUrl));
106 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
107 TRACE("got VARIANT_FALSE, do not load\n");
108 return FALSE;
112 return TRUE;
115 static BOOL handle_uri(NSContainer *container, nsChannel *channel, LPCWSTR uri)
117 IServiceProvider *service_provider;
118 HTMLDocument *doc = container->doc;
119 DWORD hlnf = 0;
120 HRESULT hres;
122 if(!doc) {
123 NSContainer *container_iter = container;
125 hlnf = HLNF_OPENINNEWWINDOW;
126 while(!container_iter->doc)
127 container_iter = container_iter->parent;
128 doc = container_iter->doc;
131 if(!doc->client) {
132 WARN("doc->client == NULL\n");
133 return FALSE;
136 if(!hlnf && !exec_shldocvw_67(doc, uri))
137 return FALSE;
139 hres = IOleClientSite_QueryInterface(doc->client, &IID_IServiceProvider,
140 (void**)&service_provider);
141 if(SUCCEEDED(hres)) {
142 IHlinkFrame *hlink_frame;
144 hres = IServiceProvider_QueryService(service_provider, &IID_IHlinkFrame,
145 &IID_IHlinkFrame, (void**)&hlink_frame);
146 IServiceProvider_Release(service_provider);
147 if(SUCCEEDED(hres)) {
148 hlink_frame_navigate(doc, hlink_frame, uri, channel->post_data_stream, hlnf);
149 IHlinkFrame_Release(hlink_frame);
151 return FALSE;
155 return TRUE;
158 static void sync_cookie_hack(nsChannel *This)
160 char *cookie = NULL;
161 nsresult nsres;
163 nsres = nsICookieService_GetCookieString(nscookie, (nsIURI*)This->uri, NSCHANNEL(This), &cookie);
164 if(NS_FAILED(nsres)) {
165 ERR("GetCookieString failed: %08lx\n", nsres);
166 return;
169 InternetSetCookieA("http://photos.blogger.com", NULL, cookie);
170 nsfree(cookie);
173 static BOOL before_async_open(nsChannel *This)
175 nsACString uri_str;
176 NSContainer *container;
177 const char *uria;
178 LPWSTR uri;
179 DWORD len;
180 BOOL ret;
182 if(!(This->load_flags & LOAD_INITIAL_DOCUMENT_URI))
183 return TRUE;
185 nsIWineURI_GetNSContainer(This->uri, &container);
186 if(!container) {
187 WARN("container = NULL\n");
188 return TRUE;
191 if(container->load_call) {
192 nsIWebBrowserChrome_Release(NSWBCHROME(container));
193 return TRUE;
196 sync_cookie_hack(This);
198 nsACString_Init(&uri_str, NULL);
199 nsIWineURI_GetSpec(This->uri, &uri_str);
200 nsACString_GetData(&uri_str, &uria, NULL);
201 len = MultiByteToWideChar(CP_ACP, 0, uria, -1, NULL, 0);
202 uri = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
203 MultiByteToWideChar(CP_ACP, 0, uria, -1, uri, len);
204 nsACString_Finish(&uri_str);
206 ret = handle_uri(container, This, uri);
208 nsIWebBrowserChrome_Release(NSWBCHROME(container));
209 HeapFree(GetProcessHeap(), 0, uri);
211 return ret;
214 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
216 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
218 nsChannel *This = NSCHANNEL_THIS(iface);
220 *result = NULL;
222 if(IsEqualGUID(&IID_nsISupports, riid)) {
223 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
224 *result = NSCHANNEL(This);
225 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
226 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
227 *result = NSCHANNEL(This);
228 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
229 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
230 *result = NSCHANNEL(This);
231 }else if(This->http_channel && IsEqualGUID(&IID_nsIHttpChannel, riid)) {
232 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
233 *result = NSHTTPCHANNEL(This);
234 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
235 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
236 *result = NSUPCHANNEL(This);
239 if(*result) {
240 nsIChannel_AddRef(NSCHANNEL(This));
241 return NS_OK;
244 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
246 if(This->channel)
247 return nsIChannel_QueryInterface(This->channel, riid, result);
248 return NS_NOINTERFACE;
251 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
253 nsChannel *This = NSCHANNEL_THIS(iface);
254 nsrefcnt ref = InterlockedIncrement(&This->ref);
256 TRACE("(%p) ref=%ld\n", This, ref);
258 return ref;
261 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
263 nsChannel *This = NSCHANNEL_THIS(iface);
264 LONG ref = InterlockedDecrement(&This->ref);
266 if(!ref) {
267 nsIWineURI_Release(This->uri);
268 if(This->channel)
269 nsIChannel_Release(This->channel);
270 if(This->http_channel)
271 nsIHttpChannel_Release(This->http_channel);
272 if(This->post_data_stream)
273 nsIInputStream_Release(This->post_data_stream);
274 if(This->load_group)
275 nsILoadGroup_Release(This->load_group);
276 if(This->notif_callback)
277 nsIInterfaceRequestor_Release(This->notif_callback);
278 if(This->original_uri)
279 nsIURI_Release(This->original_uri);
280 HeapFree(GetProcessHeap(), 0, This);
283 return ref;
286 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
288 nsChannel *This = NSCHANNEL_THIS(iface);
290 TRACE("(%p)->(%p)\n", This, aName);
292 if(This->channel)
293 return nsIChannel_GetName(This->channel, aName);
295 FIXME("default action not implemented\n");
296 return NS_ERROR_NOT_IMPLEMENTED;
299 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
301 nsChannel *This = NSCHANNEL_THIS(iface);
303 TRACE("(%p)->(%p)\n", This, _retval);
305 if(This->channel)
306 return nsIChannel_IsPending(This->channel, _retval);
308 FIXME("default action not implemented\n");
309 return NS_ERROR_NOT_IMPLEMENTED;
312 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
314 nsChannel *This = NSCHANNEL_THIS(iface);
316 TRACE("(%p)->(%p)\n", This, aStatus);
318 if(This->channel)
319 return nsIChannel_GetStatus(This->channel, aStatus);
321 FIXME("default action not implemented\n");
322 return NS_ERROR_NOT_IMPLEMENTED;
325 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
327 nsChannel *This = NSCHANNEL_THIS(iface);
329 TRACE("(%p)->(%08lx)\n", This, aStatus);
331 if(This->channel)
332 return nsIChannel_Cancel(This->channel, aStatus);
334 FIXME("default action not implemented\n");
335 return NS_ERROR_NOT_IMPLEMENTED;
338 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
340 nsChannel *This = NSCHANNEL_THIS(iface);
342 TRACE("(%p)\n", This);
344 if(This->channel)
345 return nsIChannel_Suspend(This->channel);
347 FIXME("default action not implemented\n");
348 return NS_ERROR_NOT_IMPLEMENTED;
351 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
353 nsChannel *This = NSCHANNEL_THIS(iface);
355 TRACE("(%p)\n", This);
357 if(This->channel)
358 return nsIChannel_Resume(This->channel);
360 FIXME("default action not implemented\n");
361 return NS_ERROR_NOT_IMPLEMENTED;
364 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
366 nsChannel *This = NSCHANNEL_THIS(iface);
368 TRACE("(%p)->(%p)\n", This, aLoadGroup);
370 if(This->load_group)
371 nsILoadGroup_AddRef(This->load_group);
373 *aLoadGroup = This->load_group;
374 return NS_OK;
377 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
379 nsChannel *This = NSCHANNEL_THIS(iface);
381 TRACE("(%p)->(%p)\n", This, aLoadGroup);
383 if(This->load_group)
384 nsILoadGroup_Release(This->load_group);
385 if(aLoadGroup)
386 nsILoadGroup_AddRef(aLoadGroup);
388 This->load_group = aLoadGroup;
390 if(This->channel)
391 return nsIChannel_SetLoadGroup(This->channel, aLoadGroup);
392 return NS_OK;
395 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
397 nsChannel *This = NSCHANNEL_THIS(iface);
399 TRACE("(%p)->(%p)\n", This, aLoadFlags);
401 *aLoadFlags = This->load_flags;
402 return NS_OK;
405 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
407 nsChannel *This = NSCHANNEL_THIS(iface);
409 TRACE("(%p)->(%08lx)\n", This, aLoadFlags);
411 This->load_flags = aLoadFlags;
413 if(This->channel)
414 return nsIChannel_SetLoadFlags(This->channel, aLoadFlags);
415 return NS_OK;
418 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
420 nsChannel *This = NSCHANNEL_THIS(iface);
422 TRACE("(%p)->(%p)\n", This, aOriginalURI);
424 if(This->original_uri)
425 nsIURI_AddRef(This->original_uri);
427 *aOriginalURI = This->original_uri;
428 return NS_OK;
431 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
433 nsChannel *This = NSCHANNEL_THIS(iface);
435 TRACE("(%p)->(%p)\n", This, aOriginalURI);
437 if(This->original_uri)
438 nsIURI_Release(This->original_uri);
440 nsIURI_AddRef(aOriginalURI);
441 This->original_uri = aOriginalURI;
443 if(This->channel)
444 return nsIChannel_SetOriginalURI(This->channel, aOriginalURI);
445 return NS_OK;
448 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
450 nsChannel *This = NSCHANNEL_THIS(iface);
452 TRACE("(%p)->(%p)\n", This, aURI);
454 nsIWineURI_AddRef(This->uri);
455 *aURI = (nsIURI*)This->uri;
457 return NS_OK;
460 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
462 nsChannel *This = NSCHANNEL_THIS(iface);
464 TRACE("(%p)->(%p)\n", This, aOwner);
466 if(This->channel)
467 return nsIChannel_GetOwner(This->channel, aOwner);
469 FIXME("default action not implemented\n");
470 return NS_ERROR_NOT_IMPLEMENTED;
473 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
475 nsChannel *This = NSCHANNEL_THIS(iface);
477 TRACE("(%p)->(%p)\n", This, aOwner);
479 if(This->channel)
480 return nsIChannel_SetOwner(This->channel, aOwner);
482 FIXME("default action not implemented\n");
483 return NS_ERROR_NOT_IMPLEMENTED;
486 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
487 nsIInterfaceRequestor **aNotificationCallbacks)
489 nsChannel *This = NSCHANNEL_THIS(iface);
491 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
493 if(This->notif_callback)
494 nsIInterfaceRequestor_AddRef(This->notif_callback);
495 *aNotificationCallbacks = This->notif_callback;
497 return NS_OK;
500 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
501 nsIInterfaceRequestor *aNotificationCallbacks)
503 nsChannel *This = NSCHANNEL_THIS(iface);
505 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
507 if(This->notif_callback)
508 nsIInterfaceRequestor_Release(This->notif_callback);
509 if(aNotificationCallbacks)
510 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
512 This->notif_callback = aNotificationCallbacks;
514 if(This->channel)
515 return nsIChannel_SetNotificationCallbacks(This->channel, aNotificationCallbacks);
516 return NS_OK;
519 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
521 nsChannel *This = NSCHANNEL_THIS(iface);
522 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
523 return nsIChannel_GetSecurityInfo(This->channel, aSecurityInfo);
526 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
528 nsChannel *This = NSCHANNEL_THIS(iface);
530 TRACE("(%p)->(%p)\n", This, aContentType);
532 if(This->channel)
533 return nsIChannel_GetContentType(This->channel, aContentType);
535 FIXME("default action not implemented\n");
536 return NS_ERROR_NOT_IMPLEMENTED;
539 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
540 const nsACString *aContentType)
542 nsChannel *This = NSCHANNEL_THIS(iface);
544 TRACE("(%p)->(%p)\n", This, aContentType);
546 if(This->channel)
547 return nsIChannel_SetContentType(This->channel, aContentType);
549 FIXME("default action not implemented\n");
550 return NS_ERROR_NOT_IMPLEMENTED;
553 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
554 nsACString *aContentCharset)
556 nsChannel *This = NSCHANNEL_THIS(iface);
558 TRACE("(%p)->(%p)\n", This, aContentCharset);
560 if(This->channel)
561 return nsIChannel_GetContentCharset(This->channel, aContentCharset);
563 FIXME("default action not implemented\n");
564 return NS_ERROR_NOT_IMPLEMENTED;
567 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
568 const nsACString *aContentCharset)
570 nsChannel *This = NSCHANNEL_THIS(iface);
572 TRACE("(%p)->(%p)\n", This, aContentCharset);
574 if(This->channel)
575 return nsIChannel_SetContentCharset(This->channel, aContentCharset);
577 FIXME("default action not implemented\n");
578 return NS_ERROR_NOT_IMPLEMENTED;
581 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
583 nsChannel *This = NSCHANNEL_THIS(iface);
585 TRACE("(%p)->(%p)\n", This, aContentLength);
587 if(This->channel)
588 return nsIChannel_GetContentLength(This->channel, aContentLength);
590 FIXME("default action not implemented\n");
591 return NS_ERROR_NOT_IMPLEMENTED;
594 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
596 nsChannel *This = NSCHANNEL_THIS(iface);
598 TRACE("(%p)->(%ld)\n", This, aContentLength);
600 if(This->channel)
601 return nsIChannel_SetContentLength(This->channel, aContentLength);
603 FIXME("default action not implemented\n");
604 return NS_ERROR_NOT_IMPLEMENTED;
607 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
609 nsChannel *This = NSCHANNEL_THIS(iface);
611 TRACE("(%p)->(%p)\n", This, _retval);
613 if(This->channel)
614 return nsIChannel_Open(This->channel, _retval);
616 FIXME("default action not implemented\n");
617 return NS_ERROR_NOT_IMPLEMENTED;
620 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
621 nsISupports *aContext)
623 nsChannel *This = NSCHANNEL_THIS(iface);
624 nsresult nsres;
626 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
628 if(!before_async_open(This)) {
629 TRACE("canceled\n");
630 return NS_ERROR_UNEXPECTED;
633 if(!This->channel) {
634 FIXME("channel == NULL\n");
635 return NS_ERROR_UNEXPECTED;
638 if(This->post_data_stream) {
639 nsIUploadChannel *upload_channel;
641 nsres = nsIChannel_QueryInterface(This->channel, &IID_nsIUploadChannel,
642 (void**)&upload_channel);
643 if(NS_SUCCEEDED(nsres)) {
644 nsACString empty_string;
645 nsACString_Init(&empty_string, "");
647 nsres = nsIUploadChannel_SetUploadStream(upload_channel, This->post_data_stream,
648 &empty_string, -1);
649 nsIUploadChannel_Release(upload_channel);
650 if(NS_FAILED(nsres))
651 WARN("SetUploadStream failed: %08lx\n", nsres);
653 nsACString_Finish(&empty_string);
657 return nsIChannel_AsyncOpen(This->channel, aListener, aContext);
660 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
662 nsChannel *This = NSCHANNEL_THIS(iface);
664 TRACE("(%p)->(%p)\n", This, aRequestMethod);
666 if(This->http_channel)
667 return nsIHttpChannel_GetRequestMethod(This->http_channel, aRequestMethod);
669 return NS_ERROR_NOT_IMPLEMENTED;
672 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
673 const nsACString *aRequestMethod)
675 nsChannel *This = NSCHANNEL_THIS(iface);
677 TRACE("(%p)->(%p)\n", This, aRequestMethod);
679 if(This->http_channel)
680 return nsIHttpChannel_SetRequestMethod(This->http_channel, aRequestMethod);
682 return NS_ERROR_NOT_IMPLEMENTED;
685 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
687 nsChannel *This = NSCHANNEL_THIS(iface);
689 TRACE("(%p)->(%p)\n", This, aReferrer);
691 if(This->http_channel)
692 return nsIHttpChannel_GetReferrer(This->http_channel, aReferrer);
694 return NS_ERROR_NOT_IMPLEMENTED;
697 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
699 nsChannel *This = NSCHANNEL_THIS(iface);
701 TRACE("(%p)->(%p)\n", This, aReferrer);
703 if(This->http_channel)
704 return nsIHttpChannel_SetReferrer(This->http_channel, aReferrer);
706 return NS_ERROR_NOT_IMPLEMENTED;
709 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
710 const nsACString *aHeader, nsACString *_retval)
712 nsChannel *This = NSCHANNEL_THIS(iface);
714 TRACE("(%p)->(%p %p)\n", This, aHeader, _retval);
716 if(This->http_channel)
717 return nsIHttpChannel_GetRequestHeader(This->http_channel, aHeader, _retval);
719 return NS_ERROR_NOT_IMPLEMENTED;
722 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
723 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
725 nsChannel *This = NSCHANNEL_THIS(iface);
727 TRACE("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
729 if(This->http_channel)
730 return nsIHttpChannel_SetRequestHeader(This->http_channel, aHeader, aValue, aMerge);
732 return NS_ERROR_NOT_IMPLEMENTED;
735 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
736 nsIHttpHeaderVisitor *aVisitor)
738 nsChannel *This = NSCHANNEL_THIS(iface);
740 TRACE("(%p)->(%p)\n", This, aVisitor);
742 if(This->http_channel)
743 return nsIHttpChannel_VisitRequestHeaders(This->http_channel, aVisitor);
745 return NS_ERROR_NOT_IMPLEMENTED;
748 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
750 nsChannel *This = NSCHANNEL_THIS(iface);
752 TRACE("(%p)->(%p)\n", This, aAllowPipelining);
754 if(This->http_channel)
755 return nsIHttpChannel_GetAllowPipelining(This->http_channel, aAllowPipelining);
757 return NS_ERROR_NOT_IMPLEMENTED;
760 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
762 nsChannel *This = NSCHANNEL_THIS(iface);
764 TRACE("(%p)->(%x)\n", This, aAllowPipelining);
766 if(This->http_channel)
767 return nsIHttpChannel_SetAllowPipelining(This->http_channel, aAllowPipelining);
769 return NS_ERROR_NOT_IMPLEMENTED;
772 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
774 nsChannel *This = NSCHANNEL_THIS(iface);
776 TRACE("(%p)->(%p)\n", This, aRedirectionLimit);
778 if(This->http_channel)
779 return nsIHttpChannel_GetRedirectionLimit(This->http_channel, aRedirectionLimit);
781 return NS_ERROR_NOT_IMPLEMENTED;
784 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
786 nsChannel *This = NSCHANNEL_THIS(iface);
788 TRACE("(%p)->(%lu)\n", This, aRedirectionLimit);
790 if(This->http_channel)
791 return nsIHttpChannel_SetRedirectionLimit(This->http_channel, aRedirectionLimit);
793 return NS_ERROR_NOT_IMPLEMENTED;
796 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
798 nsChannel *This = NSCHANNEL_THIS(iface);
800 TRACE("(%p)->(%p)\n", This, aResponseStatus);
802 if(This->http_channel)
803 return nsIHttpChannel_GetResponseStatus(This->http_channel, aResponseStatus);
805 return NS_ERROR_NOT_IMPLEMENTED;
808 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
809 nsACString *aResponseStatusText)
811 nsChannel *This = NSCHANNEL_THIS(iface);
813 TRACE("(%p)->(%p)\n", This, aResponseStatusText);
815 if(This->http_channel)
816 return nsIHttpChannel_GetResponseStatusText(This->http_channel, aResponseStatusText);
818 return NS_ERROR_NOT_IMPLEMENTED;
821 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
822 PRBool *aRequestSucceeded)
824 nsChannel *This = NSCHANNEL_THIS(iface);
826 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
828 if(This->http_channel)
829 return nsIHttpChannel_GetRequestSucceeded(This->http_channel, aRequestSucceeded);
831 return NS_ERROR_NOT_IMPLEMENTED;
834 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
835 const nsACString *header, nsACString *_retval)
837 nsChannel *This = NSCHANNEL_THIS(iface);
839 TRACE("(%p)->(%p %p)\n", This, header, _retval);
841 if(This->http_channel)
842 return nsIHttpChannel_GetResponseHeader(This->http_channel, header, _retval);
844 return NS_ERROR_NOT_IMPLEMENTED;
847 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
848 const nsACString *header, const nsACString *value, PRBool merge)
850 nsChannel *This = NSCHANNEL_THIS(iface);
852 TRACE("(%p)->(%p %p %x)\n", This, header, value, merge);
854 if(This->http_channel)
855 return nsIHttpChannel_SetResponseHeader(This->http_channel, header, value, merge);
857 return NS_ERROR_NOT_IMPLEMENTED;
860 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
861 nsIHttpHeaderVisitor *aVisitor)
863 nsChannel *This = NSCHANNEL_THIS(iface);
865 TRACE("(%p)->(%p)\n", This, aVisitor);
867 if(This->http_channel)
868 return nsIHttpChannel_VisitResponseHeaders(This->http_channel, aVisitor);
870 return NS_ERROR_NOT_IMPLEMENTED;
873 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
875 nsChannel *This = NSCHANNEL_THIS(iface);
877 TRACE("(%p)->(%p)\n", This, _retval);
879 if(This->http_channel)
880 return nsIHttpChannel_IsNoStoreResponse(This->http_channel, _retval);
882 return NS_ERROR_NOT_IMPLEMENTED;
885 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
887 nsChannel *This = NSCHANNEL_THIS(iface);
889 TRACE("(%p)->(%p)\n", This, _retval);
891 if(This->http_channel)
892 return nsIHttpChannel_IsNoCacheResponse(This->http_channel, _retval);
894 return NS_ERROR_NOT_IMPLEMENTED;
897 #undef NSCHANNEL_THIS
899 static const nsIHttpChannelVtbl nsChannelVtbl = {
900 nsChannel_QueryInterface,
901 nsChannel_AddRef,
902 nsChannel_Release,
903 nsChannel_GetName,
904 nsChannel_IsPending,
905 nsChannel_GetStatus,
906 nsChannel_Cancel,
907 nsChannel_Suspend,
908 nsChannel_Resume,
909 nsChannel_GetLoadGroup,
910 nsChannel_SetLoadGroup,
911 nsChannel_GetLoadFlags,
912 nsChannel_SetLoadFlags,
913 nsChannel_GetOriginalURI,
914 nsChannel_SetOriginalURI,
915 nsChannel_GetURI,
916 nsChannel_GetOwner,
917 nsChannel_SetOwner,
918 nsChannel_GetNotificationCallbacks,
919 nsChannel_SetNotificationCallbacks,
920 nsChannel_GetSecurityInfo,
921 nsChannel_GetContentType,
922 nsChannel_SetContentType,
923 nsChannel_GetContentCharset,
924 nsChannel_SetContentCharset,
925 nsChannel_GetContentLength,
926 nsChannel_SetContentLength,
927 nsChannel_Open,
928 nsChannel_AsyncOpen,
929 nsChannel_GetRequestMethod,
930 nsChannel_SetRequestMethod,
931 nsChannel_GetReferrer,
932 nsChannel_SetReferrer,
933 nsChannel_GetRequestHeader,
934 nsChannel_SetRequestHeader,
935 nsChannel_VisitRequestHeaders,
936 nsChannel_GetAllowPipelining,
937 nsChannel_SetAllowPipelining,
938 nsChannel_GetRedirectionLimit,
939 nsChannel_SetRedirectionLimit,
940 nsChannel_GetResponseStatus,
941 nsChannel_GetResponseStatusText,
942 nsChannel_GetRequestSucceeded,
943 nsChannel_GetResponseHeader,
944 nsChannel_SetResponseHeader,
945 nsChannel_VisitResponseHeaders,
946 nsChannel_IsNoStoreResponse,
947 nsChannel_IsNoCacheResponse
950 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
952 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
953 nsQIResult result)
955 nsChannel *This = NSUPCHANNEL_THIS(iface);
956 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
959 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
961 nsChannel *This = NSUPCHANNEL_THIS(iface);
962 return nsIChannel_AddRef(NSCHANNEL(This));
965 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
967 nsChannel *This = NSUPCHANNEL_THIS(iface);
968 return nsIChannel_Release(NSCHANNEL(This));
971 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
972 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
974 nsChannel *This = NSUPCHANNEL_THIS(iface);
975 const char *content_type;
977 TRACE("(%p)->(%p %p %ld)\n", This, aStream, aContentType, aContentLength);
979 if(This->post_data_stream)
980 nsIInputStream_Release(This->post_data_stream);
982 if(aContentType) {
983 nsACString_GetData(aContentType, &content_type, NULL);
984 if(*content_type)
985 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
988 if(aContentLength != -1)
989 FIXME("Unsupported acontentLength = %ld\n", aContentLength);
991 if(aStream)
992 nsIInputStream_AddRef(aStream);
993 This->post_data_stream = aStream;
995 return NS_OK;
998 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
999 nsIInputStream **aUploadStream)
1001 nsChannel *This = NSUPCHANNEL_THIS(iface);
1003 TRACE("(%p)->(%p)\n", This, aUploadStream);
1005 if(This->post_data_stream)
1006 nsIInputStream_AddRef(This->post_data_stream);
1008 *aUploadStream = This->post_data_stream;
1009 return NS_OK;
1012 #undef NSUPCHANNEL_THIS
1014 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1015 nsUploadChannel_QueryInterface,
1016 nsUploadChannel_AddRef,
1017 nsUploadChannel_Release,
1018 nsUploadChannel_SetUploadStream,
1019 nsUploadChannel_GetUploadStream
1022 #define NSURI_THIS(iface) DEFINE_THIS(nsURI, WineURI, iface)
1024 static nsresult NSAPI nsURI_QueryInterface(nsIWineURI *iface, nsIIDRef riid, nsQIResult result)
1026 nsURI *This = NSURI_THIS(iface);
1028 *result = NULL;
1030 if(IsEqualGUID(&IID_nsISupports, riid)) {
1031 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1032 *result = NSURI(This);
1033 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1034 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1035 *result = NSURI(This);
1036 }else if(IsEqualGUID(&IID_nsIWineURI, riid)) {
1037 TRACE("(%p)->(IID_nsIWineURI %p)\n", This, result);
1038 *result = NSURI(This);
1041 if(*result) {
1042 nsIURI_AddRef(NSURI(This));
1043 return NS_OK;
1046 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1047 return nsIURI_QueryInterface(This->uri, riid, result);
1050 static nsrefcnt NSAPI nsURI_AddRef(nsIWineURI *iface)
1052 nsURI *This = NSURI_THIS(iface);
1053 LONG ref = InterlockedIncrement(&This->ref);
1055 TRACE("(%p) ref=%ld\n", This, ref);
1057 return ref;
1060 static nsrefcnt NSAPI nsURI_Release(nsIWineURI *iface)
1062 nsURI *This = NSURI_THIS(iface);
1063 LONG ref = InterlockedDecrement(&This->ref);
1065 TRACE("(%p) ref=%ld\n", This, ref);
1067 if(!ref) {
1068 if(This->container)
1069 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1070 nsIURI_Release(This->uri);
1071 HeapFree(GetProcessHeap(), 0, This);
1074 return ref;
1077 static nsresult NSAPI nsURI_GetSpec(nsIWineURI *iface, nsACString *aSpec)
1079 nsURI *This = NSURI_THIS(iface);
1080 TRACE("(%p)->(%p)\n", This, aSpec);
1081 return nsIURI_GetSpec(This->uri, aSpec);
1084 static nsresult NSAPI nsURI_SetSpec(nsIWineURI *iface, const nsACString *aSpec)
1086 nsURI *This = NSURI_THIS(iface);
1087 TRACE("(%p)->(%p)\n", This, aSpec);
1088 return nsIURI_SetSpec(This->uri, aSpec);
1091 static nsresult NSAPI nsURI_GetPrePath(nsIWineURI *iface, nsACString *aPrePath)
1093 nsURI *This = NSURI_THIS(iface);
1094 TRACE("(%p)->(%p)\n", This, aPrePath);
1095 return nsIURI_GetPrePath(This->uri, aPrePath);
1098 static nsresult NSAPI nsURI_GetScheme(nsIWineURI *iface, nsACString *aScheme)
1100 nsURI *This = NSURI_THIS(iface);
1101 TRACE("(%p)->(%p)\n", This, aScheme);
1102 return nsIURI_GetScheme(This->uri, aScheme);
1105 static nsresult NSAPI nsURI_SetScheme(nsIWineURI *iface, const nsACString *aScheme)
1107 nsURI *This = NSURI_THIS(iface);
1108 TRACE("(%p)->(%p)\n", This, aScheme);
1109 return nsIURI_SetScheme(This->uri, aScheme);
1112 static nsresult NSAPI nsURI_GetUserPass(nsIWineURI *iface, nsACString *aUserPass)
1114 nsURI *This = NSURI_THIS(iface);
1115 TRACE("(%p)->(%p)\n", This, aUserPass);
1116 return nsIURI_GetUserPass(This->uri, aUserPass);
1119 static nsresult NSAPI nsURI_SetUserPass(nsIWineURI *iface, const nsACString *aUserPass)
1121 nsURI *This = NSURI_THIS(iface);
1122 TRACE("(%p)->(%p)\n", This, aUserPass);
1123 return nsIURI_SetUserPass(This->uri, aUserPass);
1126 static nsresult NSAPI nsURI_GetUsername(nsIWineURI *iface, nsACString *aUsername)
1128 nsURI *This = NSURI_THIS(iface);
1129 TRACE("(%p)->(%p)\n", This, aUsername);
1130 return nsIURI_GetUsername(This->uri, aUsername);
1133 static nsresult NSAPI nsURI_SetUsername(nsIWineURI *iface, const nsACString *aUsername)
1135 nsURI *This = NSURI_THIS(iface);
1136 TRACE("(%p)->(%p)\n", This, aUsername);
1137 return nsIURI_SetUsername(This->uri, aUsername);
1140 static nsresult NSAPI nsURI_GetPassword(nsIWineURI *iface, nsACString *aPassword)
1142 nsURI *This = NSURI_THIS(iface);
1143 TRACE("(%p)->(%p)\n", This, aPassword);
1144 return nsIURI_GetPassword(This->uri, aPassword);
1147 static nsresult NSAPI nsURI_SetPassword(nsIWineURI *iface, const nsACString *aPassword)
1149 nsURI *This = NSURI_THIS(iface);
1150 TRACE("(%p)->(%p)\n", This, aPassword);
1151 return nsIURI_SetPassword(This->uri, aPassword);
1154 static nsresult NSAPI nsURI_GetHostPort(nsIWineURI *iface, nsACString *aHostPort)
1156 nsURI *This = NSURI_THIS(iface);
1157 TRACE("(%p)->(%p)\n", This, aHostPort);
1158 return nsIURI_GetHostPort(This->uri, aHostPort);
1161 static nsresult NSAPI nsURI_SetHostPort(nsIWineURI *iface, const nsACString *aHostPort)
1163 nsURI *This = NSURI_THIS(iface);
1164 TRACE("(%p)->(%p)\n", This, aHostPort);
1165 return nsIURI_SetHostPort(This->uri, aHostPort);
1168 static nsresult NSAPI nsURI_GetHost(nsIWineURI *iface, nsACString *aHost)
1170 nsURI *This = NSURI_THIS(iface);
1171 TRACE("(%p)->(%p)\n", This, aHost);
1172 return nsIURI_GetHost(This->uri, aHost);
1175 static nsresult NSAPI nsURI_SetHost(nsIWineURI *iface, const nsACString *aHost)
1177 nsURI *This = NSURI_THIS(iface);
1178 TRACE("(%p)->(%p)\n", This, aHost);
1179 return nsIURI_SetHost(This->uri, aHost);
1182 static nsresult NSAPI nsURI_GetPort(nsIWineURI *iface, PRInt32 *aPort)
1184 nsURI *This = NSURI_THIS(iface);
1185 TRACE("(%p)->(%p)\n", This, aPort);
1186 return nsIURI_GetPort(This->uri, aPort);
1189 static nsresult NSAPI nsURI_SetPort(nsIWineURI *iface, PRInt32 aPort)
1191 nsURI *This = NSURI_THIS(iface);
1192 TRACE("(%p)->(%ld)\n", This, aPort);
1193 return nsIURI_SetPort(This->uri, aPort);
1196 static nsresult NSAPI nsURI_GetPath(nsIWineURI *iface, nsACString *aPath)
1198 nsURI *This = NSURI_THIS(iface);
1199 TRACE("(%p)->(%p)\n", This, aPath);
1200 return nsIURI_GetPath(This->uri, aPath);
1203 static nsresult NSAPI nsURI_SetPath(nsIWineURI *iface, const nsACString *aPath)
1205 nsURI *This = NSURI_THIS(iface);
1206 TRACE("(%p)->(%p)\n", This, aPath);
1207 return nsIURI_SetPath(This->uri, aPath);
1210 static nsresult NSAPI nsURI_Equals(nsIWineURI *iface, nsIURI *other, PRBool *_retval)
1212 nsURI *This = NSURI_THIS(iface);
1213 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1214 return nsIURI_Equals(This->uri, other, _retval);
1217 static nsresult NSAPI nsURI_SchemeIs(nsIWineURI *iface, const char *scheme, PRBool *_retval)
1219 nsURI *This = NSURI_THIS(iface);
1220 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1221 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1224 static nsresult NSAPI nsURI_Clone(nsIWineURI *iface, nsIURI **_retval)
1226 nsURI *This = NSURI_THIS(iface);
1227 nsIURI *uri;
1228 nsresult nsres;
1230 TRACE("(%p)->(%p)\n", This, _retval);
1232 nsres = nsIURI_Clone(This->uri, &uri);
1233 if(NS_FAILED(nsres)) {
1234 WARN("Clone failed: %08lx\n", nsres);
1235 return nsres;
1238 return create_uri(uri, This->container, _retval);
1241 static nsresult NSAPI nsURI_Resolve(nsIWineURI *iface, const nsACString *arelativePath,
1242 nsACString *_retval)
1244 nsURI *This = NSURI_THIS(iface);
1245 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1246 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1249 static nsresult NSAPI nsURI_GetAsciiSpec(nsIWineURI *iface, nsACString *aAsciiSpec)
1251 nsURI *This = NSURI_THIS(iface);
1252 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1253 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1256 static nsresult NSAPI nsURI_GetAsciiHost(nsIWineURI *iface, nsACString *aAsciiHost)
1258 nsURI *This = NSURI_THIS(iface);
1259 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1260 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1263 static nsresult NSAPI nsURI_GetOriginCharset(nsIWineURI *iface, nsACString *aOriginCharset)
1265 nsURI *This = NSURI_THIS(iface);
1266 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1267 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1270 static nsresult NSAPI nsURI_GetNSContainer(nsIWineURI *iface, NSContainer **aContainer)
1272 nsURI *This = NSURI_THIS(iface);
1274 TRACE("(%p)->(%p)\n", This, aContainer);
1276 if(This->container)
1277 nsIWebBrowserChrome_AddRef(NSWBCHROME(This->container));
1278 *aContainer = This->container;
1280 return NS_OK;
1283 static nsresult NSAPI nsURI_SetNSContainer(nsIWineURI *iface, NSContainer *aContainer)
1285 nsURI *This = NSURI_THIS(iface);
1287 TRACE("(%p)->(%p)\n", This, aContainer);
1289 if(This->container) {
1290 WARN("Container already set: %p\n", This->container);
1291 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1294 if(aContainer)
1295 nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer));
1296 This->container = aContainer;
1298 return NS_OK;
1301 #undef NSURI_THIS
1303 static const nsIWineURIVtbl nsWineURIVtbl = {
1304 nsURI_QueryInterface,
1305 nsURI_AddRef,
1306 nsURI_Release,
1307 nsURI_GetSpec,
1308 nsURI_SetSpec,
1309 nsURI_GetPrePath,
1310 nsURI_GetScheme,
1311 nsURI_SetScheme,
1312 nsURI_GetUserPass,
1313 nsURI_SetUserPass,
1314 nsURI_GetUsername,
1315 nsURI_SetUsername,
1316 nsURI_GetPassword,
1317 nsURI_SetPassword,
1318 nsURI_GetHostPort,
1319 nsURI_SetHostPort,
1320 nsURI_GetHost,
1321 nsURI_SetHost,
1322 nsURI_GetPort,
1323 nsURI_SetPort,
1324 nsURI_GetPath,
1325 nsURI_SetPath,
1326 nsURI_Equals,
1327 nsURI_SchemeIs,
1328 nsURI_Clone,
1329 nsURI_Resolve,
1330 nsURI_GetAsciiSpec,
1331 nsURI_GetAsciiHost,
1332 nsURI_GetOriginCharset,
1333 nsURI_GetNSContainer,
1334 nsURI_SetNSContainer,
1337 static nsresult create_uri(nsIURI *uri, NSContainer *container, nsIURI **_retval)
1339 nsURI *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(nsURI));
1341 ret->lpWineURIVtbl = &nsWineURIVtbl;
1342 ret->ref = 1;
1343 ret->uri = uri;
1344 ret->container = container;
1346 if(container)
1347 nsIWebBrowserChrome_AddRef(NSWBCHROME(container));
1349 TRACE("retval=%p\n", ret);
1350 *_retval = NSURI(ret);
1351 return NS_OK;
1354 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
1355 nsQIResult result)
1357 *result = NULL;
1359 if(IsEqualGUID(&IID_nsISupports, riid)) {
1360 TRACE("(IID_nsISupports %p)\n", result);
1361 *result = iface;
1362 }else if(IsEqualGUID(&IID_nsIIOService, riid)) {
1363 TRACE("(IID_nsIIOService %p)\n", result);
1364 *result = iface;
1367 if(*result) {
1368 nsIIOService_AddRef(iface);
1369 return S_OK;
1372 WARN("(%s %p)\n", debugstr_guid(riid), result);
1373 return NS_NOINTERFACE;
1376 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
1378 return 2;
1381 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
1383 return 1;
1386 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
1387 nsIProtocolHandler **_retval)
1389 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1390 return nsIIOService_GetProtocolHandler(nsio, aScheme, _retval);
1393 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
1394 PRUint32 *_retval)
1396 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1397 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
1400 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
1401 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
1403 const char *spec = NULL;
1404 nsIURI *uri;
1405 PRBool is_javascript = FALSE;
1406 nsresult nsres;
1408 nsACString_GetData(aSpec, &spec, NULL);
1410 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
1411 aBaseURI, _retval);
1413 if(aBaseURI) {
1414 nsACString base_uri_str;
1415 const char *base_uri = NULL;
1417 nsACString_Init(&base_uri_str, NULL);
1419 nsres = nsIURI_GetSpec(aBaseURI, &base_uri_str);
1420 if(NS_SUCCEEDED(nsres)) {
1421 nsACString_GetData(&base_uri_str, &base_uri, NULL);
1422 TRACE("uri=%s\n", debugstr_a(base_uri));
1423 }else {
1424 ERR("GetSpec failed: %08lx\n", nsres);
1427 nsACString_Finish(&base_uri_str);
1430 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
1431 if(NS_FAILED(nsres)) {
1432 WARN("NewURI failed: %08lx\n", nsres);
1433 return nsres;
1436 nsIURI_SchemeIs(uri, "javascript", &is_javascript);
1437 if(is_javascript) {
1438 TRACE("returning javascript uri: %p\n", uri);
1439 *_retval = uri;
1440 return NS_OK;
1443 return create_uri(uri, NULL, _retval);
1446 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
1447 nsIURI **_retval)
1449 TRACE("(%p %p)\n", aFile, _retval);
1450 return nsIIOService_NewFileURI(nsio, aFile, _retval);
1453 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
1454 nsIChannel **_retval)
1456 nsIChannel *channel = NULL;
1457 nsChannel *ret;
1458 nsIWineURI *wine_uri;
1459 nsresult nsres;
1461 TRACE("(%p %p)\n", aURI, _retval);
1463 nsres = nsIIOService_NewChannelFromURI(nsio, aURI, &channel);
1464 if(NS_FAILED(nsres) && nsres != NS_ERROR_UNKNOWN_PROTOCOL) {
1465 WARN("NewChannelFromURI failed: %08lx\n", nsres);
1466 *_retval = channel;
1467 return nsres;
1470 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
1471 if(NS_FAILED(nsres)) {
1472 WARN("Could not get nsIWineURI: %08lx\n", nsres);
1473 *_retval = channel;
1474 return channel ? NS_OK : NS_ERROR_UNEXPECTED;
1477 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(nsChannel));
1479 ret->lpHttpChannelVtbl = &nsChannelVtbl;
1480 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
1481 ret->ref = 1;
1482 ret->channel = channel;
1483 ret->http_channel = NULL;
1484 ret->uri = wine_uri;
1485 ret->post_data_stream = NULL;
1486 ret->load_group = NULL;
1487 ret->notif_callback = NULL;
1488 ret->load_flags = 0;
1490 nsIURI_AddRef(aURI);
1491 ret->original_uri = aURI;
1493 if(channel)
1494 nsIChannel_QueryInterface(channel, &IID_nsIHttpChannel, (void**)&ret->http_channel);
1496 *_retval = NSCHANNEL(ret);
1497 return NS_OK;
1500 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
1501 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
1503 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
1504 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
1507 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
1509 TRACE("(%p)\n", aOffline);
1510 return nsIIOService_GetOffline(nsio, aOffline);
1513 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
1515 TRACE("(%x)\n", aOffline);
1516 return nsIIOService_SetOffline(nsio, aOffline);
1519 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
1520 const char *aScheme, PRBool *_retval)
1522 TRACE("(%ld %s %p)\n", aPort, debugstr_a(aScheme), _retval);
1523 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
1526 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
1527 nsACString * _retval)
1529 TRACE("(%p %p)\n", urlString, _retval);
1530 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
1533 static const nsIIOServiceVtbl nsIOServiceVtbl = {
1534 nsIOService_QueryInterface,
1535 nsIOService_AddRef,
1536 nsIOService_Release,
1537 nsIOService_GetProtocolHandler,
1538 nsIOService_GetProtocolFlags,
1539 nsIOService_NewURI,
1540 nsIOService_NewFileURI,
1541 nsIOService_NewChannelFromURI,
1542 nsIOService_NewChannel,
1543 nsIOService_GetOffline,
1544 nsIOService_SetOffline,
1545 nsIOService_AllowPort,
1546 nsIOService_ExtractScheme
1549 static nsIIOService nsIOService = { &nsIOServiceVtbl };
1551 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
1552 nsQIResult result)
1554 *result = NULL;
1556 if(IsEqualGUID(&IID_nsISupports, riid)) {
1557 TRACE("(IID_nsISupoprts %p)\n", result);
1558 *result = iface;
1559 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
1560 TRACE("(IID_nsIFactory %p)\n", result);
1561 *result = iface;
1564 if(*result) {
1565 nsIFactory_AddRef(iface);
1566 return NS_OK;
1569 WARN("(%s %p)\n", debugstr_guid(riid), result);
1570 return NS_NOINTERFACE;
1573 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
1575 return 2;
1578 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
1580 return 1;
1583 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
1584 nsISupports *aOuter, const nsIID *iid, void **result)
1586 return nsIIOService_QueryInterface(&nsIOService, iid, result);
1589 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
1591 WARN("(%x)\n", lock);
1592 return NS_OK;
1595 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
1596 nsIOServiceFactory_QueryInterface,
1597 nsIOServiceFactory_AddRef,
1598 nsIOServiceFactory_Release,
1599 nsIOServiceFactory_CreateInstance,
1600 nsIOServiceFactory_LockFactory
1603 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
1605 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
1607 nsIFactory *old_factory = NULL;
1608 nsresult nsres;
1610 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
1611 &IID_nsIFactory, (void**)&old_factory);
1612 if(NS_FAILED(nsres)) {
1613 ERR("Could not get factory: %08lx\n", nsres);
1614 nsIFactory_Release(old_factory);
1615 return;
1618 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
1619 if(NS_FAILED(nsres)) {
1620 ERR("Couldn not create nsIOService instance %08lx\n", nsres);
1621 nsIFactory_Release(old_factory);
1622 return;
1625 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
1626 nsIFactory_Release(old_factory);
1627 if(NS_FAILED(nsres))
1628 ERR("UnregisterFactory failed: %08lx\n", nsres);
1630 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
1631 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
1632 if(NS_FAILED(nsres))
1633 ERR("RegisterFactory failed: %08lx\n", nsres);
1635 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_COOKIESERVICE_CID,
1636 &IID_nsIFactory, (void**)&old_factory);
1637 if(NS_FAILED(nsres)) {
1638 ERR("Could not get factory: %08lx\n", nsres);
1639 nsIFactory_Release(old_factory);
1640 return;
1643 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsICookieService, (void**)&nscookie);
1644 if(NS_FAILED(nsres)) {
1645 ERR("Couldn not create nsCookieManager instance %08lx\n", nsres);
1646 nsIFactory_Release(old_factory);
1647 return;
1651 nsIURI *get_nsIURI(LPCWSTR url)
1653 nsIURI *ret;
1654 nsACString acstr;
1655 nsresult nsres;
1656 char *urla;
1657 int len;
1659 len = WideCharToMultiByte(CP_ACP, 0, url, -1, NULL, -1, NULL, NULL);
1660 urla = HeapAlloc(GetProcessHeap(), 0, len);
1661 WideCharToMultiByte(CP_ACP, 0, url, -1, urla, -1, NULL, NULL);
1663 nsACString_Init(&acstr, urla);
1665 nsres = nsIIOService_NewURI(nsio, &acstr, NULL, NULL, &ret);
1666 if(NS_FAILED(nsres))
1667 FIXME("NewURI failed: %08lx\n", nsres);
1669 nsACString_Finish(&acstr);
1670 HeapFree(GetProcessHeap(), 0, urla);
1672 return ret;