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
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 #define LOAD_INITIAL_DOCUMENT_URI 0x80000
40 #define NS_IOSERVICE_CLASSNAME "nsIOService"
41 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
43 static IID NS_IOSERVICE_CID =
44 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
46 static nsIIOService *nsio = NULL;
49 const nsIHttpChannelVtbl *lpHttpChannelVtbl;
54 nsIHttpChannel *http_channel;
59 const nsIWineURIVtbl *lpWineURIVtbl;
64 NSContainer *container;
67 #define NSCHANNEL(x) ((nsIChannel*) &(x)->lpHttpChannelVtbl)
68 #define NSHTTPCHANNEL(x) ((nsIHttpChannel*) &(x)->lpHttpChannelVtbl)
69 #define NSURI(x) ((nsIURI*) &(x)->lpWineURIVtbl)
71 static BOOL exec_shldocvw_67(NSContainer *container, LPCWSTR url)
73 IOleCommandTarget *cmdtrg = NULL;
76 hres = IOleClientSite_QueryInterface(container->doc->client, &IID_IOleCommandTarget,
79 VARIANT varUrl, varRes;
81 V_VT(&varUrl) = VT_BSTR;
82 V_BSTR(&varUrl) = SysAllocString(url);
83 V_VT(&varRes) = VT_BOOL;
85 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
87 IOleCommandTarget_Release(cmdtrg);
88 SysFreeString(V_BSTR(&varUrl));
90 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
91 TRACE("got VARIANT_FALSE, do not load\n");
99 static BOOL before_async_open(nsChannel *This)
102 NSContainer *container;
103 PRUint32 load_flags = 0;
109 nsIChannel_GetLoadFlags(This->channel, &load_flags);
110 TRACE("load_flags = %08lx\n", load_flags);
111 if(!(load_flags & LOAD_INITIAL_DOCUMENT_URI))
114 nsIWineURI_GetNSContainer(This->uri, &container);
116 WARN("container = NULL\n");
120 if(container->load_call) {
121 nsIWebBrowserChrome_Release(NSWBCHROME(container));
125 uri_str = nsACString_Create();
126 nsIWineURI_GetSpec(This->uri, uri_str);
127 nsACString_GetData(uri_str, &uria, NULL);
128 len = MultiByteToWideChar(CP_ACP, 0, uria, -1, NULL, 0);
129 uri = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
130 MultiByteToWideChar(CP_ACP, 0, uria, -1, uri, len);
131 nsACString_Destroy(uri_str);
133 ret = exec_shldocvw_67(container, uri);
135 nsIWebBrowserChrome_Release(NSWBCHROME(container));
136 HeapFree(GetProcessHeap(), 0, uri);
141 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
143 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
145 nsChannel *This = NSCHANNEL_THIS(iface);
149 if(IsEqualGUID(&IID_nsISupports, riid)) {
150 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
151 *result = NSCHANNEL(This);
152 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
153 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
154 *result = NSCHANNEL(This);
155 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
156 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
157 *result = NSCHANNEL(This);
158 }else if(This->http_channel && IsEqualGUID(&IID_nsIHttpChannel, riid)) {
159 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
160 *result = NSHTTPCHANNEL(This);
164 nsIChannel_AddRef(NSCHANNEL(This));
168 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
169 return nsIChannel_QueryInterface(This->channel, riid, result);
172 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
174 nsChannel *This = NSCHANNEL_THIS(iface);
175 nsrefcnt ref = InterlockedIncrement(&This->ref);
177 TRACE("(%p) ref=%ld\n", This, ref);
182 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
184 nsChannel *This = NSCHANNEL_THIS(iface);
185 LONG ref = InterlockedDecrement(&This->ref);
188 nsIChannel_Release(This->channel);
189 nsIWineURI_Release(This->uri);
190 if(This->http_channel)
191 nsIHttpChannel_Release(This->http_channel);
192 HeapFree(GetProcessHeap(), 0, This);
198 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
200 nsChannel *This = NSCHANNEL_THIS(iface);
201 TRACE("(%p)->(%p)\n", This, aName);
202 return nsIChannel_GetName(This->channel, aName);
205 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
207 nsChannel *This = NSCHANNEL_THIS(iface);
208 TRACE("(%p)->(%p)\n", This, _retval);
209 return nsIChannel_IsPending(This->channel, _retval);
212 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
214 nsChannel *This = NSCHANNEL_THIS(iface);
215 TRACE("(%p)->(%p)\n", This, aStatus);
216 return nsIChannel_GetStatus(This->channel, aStatus);
219 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
221 nsChannel *This = NSCHANNEL_THIS(iface);
222 TRACE("(%p)->(%08lx)\n", This, aStatus);
223 return nsIChannel_Cancel(This->channel, aStatus);
226 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
228 nsChannel *This = NSCHANNEL_THIS(iface);
229 TRACE("(%p)\n", This);
230 return nsIChannel_Suspend(This->channel);
233 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
235 nsChannel *This = NSCHANNEL_THIS(iface);
236 TRACE("(%p)\n", This);
237 return nsIChannel_Resume(This->channel);
240 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
242 nsChannel *This = NSCHANNEL_THIS(iface);
243 TRACE("(%p)->(%p)\n", This, aLoadGroup);
244 return nsIChannel_GetLoadGroup(This->channel, aLoadGroup);
247 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
249 nsChannel *This = NSCHANNEL_THIS(iface);
250 TRACE("(%p)->(%p)\n", This, aLoadGroup);
251 return nsIChannel_SetLoadGroup(This->channel, aLoadGroup);
254 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
256 nsChannel *This = NSCHANNEL_THIS(iface);
257 TRACE("(%p)->(%p)\n", This, aLoadFlags);
258 return nsIChannel_GetLoadFlags(This->channel, aLoadFlags);
261 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
263 nsChannel *This = NSCHANNEL_THIS(iface);
264 TRACE("(%p)->(%08lx)\n", This, aLoadFlags);
265 return nsIChannel_SetLoadFlags(This->channel, aLoadFlags);
268 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
270 nsChannel *This = NSCHANNEL_THIS(iface);
271 TRACE("(%p)->(%p)\n", This, aOriginalURI);
272 return nsIChannel_GetOriginalURI(This->channel, aOriginalURI);
275 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
277 nsChannel *This = NSCHANNEL_THIS(iface);
278 TRACE("(%p)->(%p)\n", This, aOriginalURI);
279 return nsIChannel_SetOriginalURI(This->channel, aOriginalURI);
282 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
284 nsChannel *This = NSCHANNEL_THIS(iface);
286 TRACE("(%p)->(%p)\n", This, aURI);
288 nsIWineURI_AddRef(This->uri);
289 *aURI = (nsIURI*)This->uri;
294 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
296 nsChannel *This = NSCHANNEL_THIS(iface);
297 TRACE("(%p)->(%p)\n", This, aOwner);
298 return nsIChannel_GetOwner(This->channel, aOwner);
301 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
303 nsChannel *This = NSCHANNEL_THIS(iface);
304 TRACE("(%p)->(%p)\n", This, aOwner);
305 return nsIChannel_SetOwner(This->channel, aOwner);
308 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
309 nsIInterfaceRequestor **aNotificationCallbacks)
311 nsChannel *This = NSCHANNEL_THIS(iface);
312 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
313 return nsIChannel_GetNotificationCallbacks(This->channel, aNotificationCallbacks);
316 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
317 nsIInterfaceRequestor *aNotificationCallbacks)
319 nsChannel *This = NSCHANNEL_THIS(iface);
320 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
321 return nsIChannel_SetNotificationCallbacks(This->channel, aNotificationCallbacks);
324 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
326 nsChannel *This = NSCHANNEL_THIS(iface);
327 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
328 return nsIChannel_GetSecurityInfo(This->channel, aSecurityInfo);
331 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
333 nsChannel *This = NSCHANNEL_THIS(iface);
334 TRACE("(%p)->(%p)\n", This, aContentType);
335 return nsIChannel_GetContentType(This->channel, aContentType);
338 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
339 const nsACString *aContentType)
341 nsChannel *This = NSCHANNEL_THIS(iface);
342 TRACE("(%p)->(%p)\n", This, aContentType);
343 return nsIChannel_SetContentType(This->channel, aContentType);
346 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
347 nsACString *aContentCharset)
349 nsChannel *This = NSCHANNEL_THIS(iface);
350 TRACE("(%p)->(%p)\n", This, aContentCharset);
351 return nsIChannel_GetContentCharset(This->channel, aContentCharset);
354 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
355 const nsACString *aContentCharset)
357 nsChannel *This = NSCHANNEL_THIS(iface);
358 TRACE("(%p)->(%p)\n", This, aContentCharset);
359 return nsIChannel_SetContentCharset(This->channel, aContentCharset);
362 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
364 nsChannel *This = NSCHANNEL_THIS(iface);
365 TRACE("(%p)->(%p)\n", This, aContentLength);
366 return nsIChannel_GetContentLength(This->channel, aContentLength);
369 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
371 nsChannel *This = NSCHANNEL_THIS(iface);
372 TRACE("(%p)->(%ld)\n", This, aContentLength);
373 return nsIChannel_SetContentLength(This->channel, aContentLength);
376 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
378 nsChannel *This = NSCHANNEL_THIS(iface);
379 TRACE("(%p)->(%p)\n", This, _retval);
380 return nsIChannel_Open(This->channel, _retval);
383 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
384 nsISupports *aContext)
386 nsChannel *This = NSCHANNEL_THIS(iface);
388 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
390 if(!before_async_open(This)) {
392 return NS_ERROR_UNEXPECTED;
395 return nsIChannel_AsyncOpen(This->channel, aListener, aContext);
398 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
400 nsChannel *This = NSCHANNEL_THIS(iface);
402 TRACE("(%p)->(%p)\n", This, aRequestMethod);
404 if(This->http_channel)
405 return nsIHttpChannel_GetRequestMethod(This->http_channel, aRequestMethod);
407 return NS_ERROR_NOT_IMPLEMENTED;
410 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
411 const nsACString *aRequestMethod)
413 nsChannel *This = NSCHANNEL_THIS(iface);
415 TRACE("(%p)->(%p)\n", This, aRequestMethod);
417 if(This->http_channel)
418 return nsIHttpChannel_SetRequestMethod(This->http_channel, aRequestMethod);
420 return NS_ERROR_NOT_IMPLEMENTED;
423 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
425 nsChannel *This = NSCHANNEL_THIS(iface);
427 TRACE("(%p)->(%p)\n", This, aReferrer);
429 if(This->http_channel)
430 return nsIHttpChannel_GetReferrer(This->http_channel, aReferrer);
432 return NS_ERROR_NOT_IMPLEMENTED;
435 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
437 nsChannel *This = NSCHANNEL_THIS(iface);
439 TRACE("(%p)->(%p)\n", This, aReferrer);
441 if(This->http_channel)
442 return nsIHttpChannel_SetReferrer(This->http_channel, aReferrer);
444 return NS_ERROR_NOT_IMPLEMENTED;
447 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
448 const nsACString *aHeader, nsACString *_retval)
450 nsChannel *This = NSCHANNEL_THIS(iface);
452 TRACE("(%p)->(%p %p)\n", This, aHeader, _retval);
454 if(This->http_channel)
455 return nsIHttpChannel_GetRequestHeader(This->http_channel, aHeader, _retval);
457 return NS_ERROR_NOT_IMPLEMENTED;
460 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
461 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
463 nsChannel *This = NSCHANNEL_THIS(iface);
465 TRACE("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
467 if(This->http_channel)
468 return nsIHttpChannel_SetRequestHeader(This->http_channel, aHeader, aValue, aMerge);
470 return NS_ERROR_NOT_IMPLEMENTED;
473 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
474 nsIHttpHeaderVisitor *aVisitor)
476 nsChannel *This = NSCHANNEL_THIS(iface);
478 TRACE("(%p)->(%p)\n", This, aVisitor);
480 if(This->http_channel)
481 return nsIHttpChannel_VisitRequestHeaders(This->http_channel, aVisitor);
483 return NS_ERROR_NOT_IMPLEMENTED;
486 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
488 nsChannel *This = NSCHANNEL_THIS(iface);
490 TRACE("(%p)->(%p)\n", This, aAllowPipelining);
492 if(This->http_channel)
493 return nsIHttpChannel_GetAllowPipelining(This->http_channel, aAllowPipelining);
495 return NS_ERROR_NOT_IMPLEMENTED;
498 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
500 nsChannel *This = NSCHANNEL_THIS(iface);
502 TRACE("(%p)->(%x)\n", This, aAllowPipelining);
504 if(This->http_channel)
505 return nsIHttpChannel_SetAllowPipelining(This->http_channel, aAllowPipelining);
507 return NS_ERROR_NOT_IMPLEMENTED;
510 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
512 nsChannel *This = NSCHANNEL_THIS(iface);
514 TRACE("(%p)->(%p)\n", This, aRedirectionLimit);
516 if(This->http_channel)
517 return nsIHttpChannel_GetRedirectionLimit(This->http_channel, aRedirectionLimit);
519 return NS_ERROR_NOT_IMPLEMENTED;
522 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
524 nsChannel *This = NSCHANNEL_THIS(iface);
526 TRACE("(%p)->(%lu)\n", This, aRedirectionLimit);
528 if(This->http_channel)
529 return nsIHttpChannel_SetRedirectionLimit(This->http_channel, aRedirectionLimit);
531 return NS_ERROR_NOT_IMPLEMENTED;
534 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
536 nsChannel *This = NSCHANNEL_THIS(iface);
538 TRACE("(%p)->(%p)\n", This, aResponseStatus);
540 if(This->http_channel)
541 return nsIHttpChannel_GetResponseStatus(This->http_channel, aResponseStatus);
543 return NS_ERROR_NOT_IMPLEMENTED;
546 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
547 nsACString *aResponseStatusText)
549 nsChannel *This = NSCHANNEL_THIS(iface);
551 TRACE("(%p)->(%p)\n", This, aResponseStatusText);
553 if(This->http_channel)
554 return nsIHttpChannel_GetResponseStatusText(This->http_channel, aResponseStatusText);
556 return NS_ERROR_NOT_IMPLEMENTED;
559 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
560 PRBool *aRequestSucceeded)
562 nsChannel *This = NSCHANNEL_THIS(iface);
564 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
566 if(This->http_channel)
567 return nsIHttpChannel_GetRequestSucceeded(This->http_channel, aRequestSucceeded);
569 return NS_ERROR_NOT_IMPLEMENTED;
572 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
573 const nsACString *header, nsACString *_retval)
575 nsChannel *This = NSCHANNEL_THIS(iface);
577 TRACE("(%p)->(%p %p)\n", This, header, _retval);
579 if(This->http_channel)
580 return nsIHttpChannel_GetResponseHeader(This->http_channel, header, _retval);
582 return NS_ERROR_NOT_IMPLEMENTED;
585 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
586 const nsACString *header, const nsACString *value, PRBool merge)
588 nsChannel *This = NSCHANNEL_THIS(iface);
590 TRACE("(%p)->(%p %p %x)\n", This, header, value, merge);
592 if(This->http_channel)
593 return nsIHttpChannel_SetResponseHeader(This->http_channel, header, value, merge);
595 return NS_ERROR_NOT_IMPLEMENTED;
598 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
599 nsIHttpHeaderVisitor *aVisitor)
601 nsChannel *This = NSCHANNEL_THIS(iface);
603 TRACE("(%p)->(%p)\n", This, aVisitor);
605 if(This->http_channel)
606 return nsIHttpChannel_VisitResponseHeaders(This->http_channel, aVisitor);
608 return NS_ERROR_NOT_IMPLEMENTED;
611 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
613 nsChannel *This = NSCHANNEL_THIS(iface);
615 TRACE("(%p)->(%p)\n", This, _retval);
617 if(This->http_channel)
618 return nsIHttpChannel_IsNoStoreResponse(This->http_channel, _retval);
620 return NS_ERROR_NOT_IMPLEMENTED;
623 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
625 nsChannel *This = NSCHANNEL_THIS(iface);
627 TRACE("(%p)->(%p)\n", This, _retval);
629 if(This->http_channel)
630 return nsIHttpChannel_IsNoCacheResponse(This->http_channel, _retval);
632 return NS_ERROR_NOT_IMPLEMENTED;
635 #undef NSCHANNEL_THIS
637 static const nsIHttpChannelVtbl nsChannelVtbl = {
638 nsChannel_QueryInterface,
647 nsChannel_GetLoadGroup,
648 nsChannel_SetLoadGroup,
649 nsChannel_GetLoadFlags,
650 nsChannel_SetLoadFlags,
651 nsChannel_GetOriginalURI,
652 nsChannel_SetOriginalURI,
656 nsChannel_GetNotificationCallbacks,
657 nsChannel_SetNotificationCallbacks,
658 nsChannel_GetSecurityInfo,
659 nsChannel_GetContentType,
660 nsChannel_SetContentType,
661 nsChannel_GetContentCharset,
662 nsChannel_SetContentCharset,
663 nsChannel_GetContentLength,
664 nsChannel_SetContentLength,
667 nsChannel_GetRequestMethod,
668 nsChannel_SetRequestMethod,
669 nsChannel_GetReferrer,
670 nsChannel_SetReferrer,
671 nsChannel_GetRequestHeader,
672 nsChannel_SetRequestHeader,
673 nsChannel_VisitRequestHeaders,
674 nsChannel_GetAllowPipelining,
675 nsChannel_SetAllowPipelining,
676 nsChannel_GetRedirectionLimit,
677 nsChannel_SetRedirectionLimit,
678 nsChannel_GetResponseStatus,
679 nsChannel_GetResponseStatusText,
680 nsChannel_GetRequestSucceeded,
681 nsChannel_GetResponseHeader,
682 nsChannel_SetResponseHeader,
683 nsChannel_VisitResponseHeaders,
684 nsChannel_IsNoStoreResponse,
685 nsChannel_IsNoCacheResponse
688 #define NSURI_THIS(iface) DEFINE_THIS(nsURI, WineURI, iface)
690 static nsresult NSAPI nsURI_QueryInterface(nsIWineURI *iface, nsIIDRef riid, nsQIResult result)
692 nsURI *This = NSURI_THIS(iface);
696 if(IsEqualGUID(&IID_nsISupports, riid)) {
697 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
698 *result = NSURI(This);
699 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
700 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
701 *result = NSURI(This);
702 }else if(IsEqualGUID(&IID_nsIWineURI, riid)) {
703 TRACE("(%p)->(IID_nsIWineURI %p)\n", This, result);
704 *result = NSURI(This);
708 nsIURI_AddRef(NSURI(This));
712 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
713 return nsIURI_QueryInterface(This->uri, riid, result);
716 static nsrefcnt NSAPI nsURI_AddRef(nsIWineURI *iface)
718 nsURI *This = NSURI_THIS(iface);
719 LONG ref = InterlockedIncrement(&This->ref);
721 TRACE("(%p) ref=%ld\n", This, ref);
726 static nsrefcnt NSAPI nsURI_Release(nsIWineURI *iface)
728 nsURI *This = NSURI_THIS(iface);
729 LONG ref = InterlockedDecrement(&This->ref);
731 TRACE("(%p) ref=%ld\n", This, ref);
734 nsIURI_Release(This->uri);
735 HeapFree(GetProcessHeap(), 0, This);
741 static nsresult NSAPI nsURI_GetSpec(nsIWineURI *iface, nsACString *aSpec)
743 nsURI *This = NSURI_THIS(iface);
744 TRACE("(%p)->(%p)\n", This, aSpec);
745 return nsIURI_GetSpec(This->uri, aSpec);
748 static nsresult NSAPI nsURI_SetSpec(nsIWineURI *iface, const nsACString *aSpec)
750 nsURI *This = NSURI_THIS(iface);
751 TRACE("(%p)->(%p)\n", This, aSpec);
752 return nsIURI_SetSpec(This->uri, aSpec);
755 static nsresult NSAPI nsURI_GetPrePath(nsIWineURI *iface, nsACString *aPrePath)
757 nsURI *This = NSURI_THIS(iface);
758 TRACE("(%p)->(%p)\n", This, aPrePath);
759 return nsIURI_GetPrePath(This->uri, aPrePath);
762 static nsresult NSAPI nsURI_GetScheme(nsIWineURI *iface, nsACString *aScheme)
764 nsURI *This = NSURI_THIS(iface);
765 TRACE("(%p)->(%p)\n", This, aScheme);
766 return nsIURI_GetScheme(This->uri, aScheme);
769 static nsresult NSAPI nsURI_SetScheme(nsIWineURI *iface, const nsACString *aScheme)
771 nsURI *This = NSURI_THIS(iface);
772 TRACE("(%p)->(%p)\n", This, aScheme);
773 return nsIURI_SetScheme(This->uri, aScheme);
776 static nsresult NSAPI nsURI_GetUserPass(nsIWineURI *iface, nsACString *aUserPass)
778 nsURI *This = NSURI_THIS(iface);
779 TRACE("(%p)->(%p)\n", This, aUserPass);
780 return nsIURI_GetUserPass(This->uri, aUserPass);
783 static nsresult NSAPI nsURI_SetUserPass(nsIWineURI *iface, const nsACString *aUserPass)
785 nsURI *This = NSURI_THIS(iface);
786 TRACE("(%p)->(%p)\n", This, aUserPass);
787 return nsIURI_SetUserPass(This->uri, aUserPass);
790 static nsresult NSAPI nsURI_GetUsername(nsIWineURI *iface, nsACString *aUsername)
792 nsURI *This = NSURI_THIS(iface);
793 TRACE("(%p)->(%p)\n", This, aUsername);
794 return nsIURI_GetUsername(This->uri, aUsername);
797 static nsresult NSAPI nsURI_SetUsername(nsIWineURI *iface, const nsACString *aUsername)
799 nsURI *This = NSURI_THIS(iface);
800 TRACE("(%p)->(%p)\n", This, aUsername);
801 return nsIURI_SetUsername(This->uri, aUsername);
804 static nsresult NSAPI nsURI_GetPassword(nsIWineURI *iface, nsACString *aPassword)
806 nsURI *This = NSURI_THIS(iface);
807 TRACE("(%p)->(%p)\n", This, aPassword);
808 return nsIURI_GetPassword(This->uri, aPassword);
811 static nsresult NSAPI nsURI_SetPassword(nsIWineURI *iface, const nsACString *aPassword)
813 nsURI *This = NSURI_THIS(iface);
814 TRACE("(%p)->(%p)\n", This, aPassword);
815 return nsIURI_SetPassword(This->uri, aPassword);
818 static nsresult NSAPI nsURI_GetHostPort(nsIWineURI *iface, nsACString *aHostPort)
820 nsURI *This = NSURI_THIS(iface);
821 TRACE("(%p)->(%p)\n", This, aHostPort);
822 return nsIURI_GetHostPort(This->uri, aHostPort);
825 static nsresult NSAPI nsURI_SetHostPort(nsIWineURI *iface, const nsACString *aHostPort)
827 nsURI *This = NSURI_THIS(iface);
828 TRACE("(%p)->(%p)\n", This, aHostPort);
829 return nsIURI_SetHostPort(This->uri, aHostPort);
832 static nsresult NSAPI nsURI_GetHost(nsIWineURI *iface, nsACString *aHost)
834 nsURI *This = NSURI_THIS(iface);
835 TRACE("(%p)->(%p)\n", This, aHost);
836 return nsIURI_GetHost(This->uri, aHost);
839 static nsresult NSAPI nsURI_SetHost(nsIWineURI *iface, const nsACString *aHost)
841 nsURI *This = NSURI_THIS(iface);
842 TRACE("(%p)->(%p)\n", This, aHost);
843 return nsIURI_SetHost(This->uri, aHost);
846 static nsresult NSAPI nsURI_GetPort(nsIWineURI *iface, PRInt32 *aPort)
848 nsURI *This = NSURI_THIS(iface);
849 TRACE("(%p)->(%p)\n", This, aPort);
850 return nsIURI_GetPort(This->uri, aPort);
853 static nsresult NSAPI nsURI_SetPort(nsIWineURI *iface, PRInt32 aPort)
855 nsURI *This = NSURI_THIS(iface);
856 TRACE("(%p)->(%ld)\n", This, aPort);
857 return nsIURI_SetPort(This->uri, aPort);
860 static nsresult NSAPI nsURI_GetPath(nsIWineURI *iface, nsACString *aPath)
862 nsURI *This = NSURI_THIS(iface);
863 TRACE("(%p)->(%p)\n", This, aPath);
864 return nsIURI_GetPath(This->uri, aPath);
867 static nsresult NSAPI nsURI_SetPath(nsIWineURI *iface, const nsACString *aPath)
869 nsURI *This = NSURI_THIS(iface);
870 TRACE("(%p)->(%p)\n", This, aPath);
871 return nsIURI_SetPath(This->uri, aPath);
874 static nsresult NSAPI nsURI_Equals(nsIWineURI *iface, nsIURI *other, PRBool *_retval)
876 nsURI *This = NSURI_THIS(iface);
877 TRACE("(%p)->(%p %p)\n", This, other, _retval);
878 return nsIURI_Equals(This->uri, other, _retval);
881 static nsresult NSAPI nsURI_SchemeIs(nsIWineURI *iface, const char *scheme, PRBool *_retval)
883 nsURI *This = NSURI_THIS(iface);
884 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
885 return nsIURI_SchemeIs(This->uri, scheme, _retval);
888 static nsresult NSAPI nsURI_Clone(nsIWineURI *iface, nsIURI **_retval)
890 nsURI *This = NSURI_THIS(iface);
891 TRACE("(%p)->(%p)\n", This, _retval);
892 return nsIURI_Clone(This->uri, _retval);
895 static nsresult NSAPI nsURI_Resolve(nsIWineURI *iface, const nsACString *arelativePath,
898 nsURI *This = NSURI_THIS(iface);
899 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
900 return nsIURI_Resolve(This->uri, arelativePath, _retval);
903 static nsresult NSAPI nsURI_GetAsciiSpec(nsIWineURI *iface, nsACString *aAsciiSpec)
905 nsURI *This = NSURI_THIS(iface);
906 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
907 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
910 static nsresult NSAPI nsURI_GetAsciiHost(nsIWineURI *iface, nsACString *aAsciiHost)
912 nsURI *This = NSURI_THIS(iface);
913 TRACE("(%p)->(%p)\n", This, aAsciiHost);
914 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
917 static nsresult NSAPI nsURI_GetOriginCharset(nsIWineURI *iface, nsACString *aOriginCharset)
919 nsURI *This = NSURI_THIS(iface);
920 TRACE("(%p)->(%p)\n", This, aOriginCharset);
921 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
924 static nsresult NSAPI nsURI_GetNSContainer(nsIWineURI *iface, NSContainer **aContainer)
926 nsURI *This = NSURI_THIS(iface);
928 TRACE("(%p)->(%p)\n", This, aContainer);
931 nsIWebBrowserChrome_AddRef(NSWBCHROME(This->container));
932 *aContainer = This->container;
937 static nsresult NSAPI nsURI_SetNSContainer(nsIWineURI *iface, NSContainer *aContainer)
939 nsURI *This = NSURI_THIS(iface);
941 TRACE("(%p)->(%p)\n", This, aContainer);
943 if(This->container) {
944 WARN("Container already set: %p\n", This->container);
945 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
949 nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer));
950 This->container = aContainer;
957 static const nsIWineURIVtbl nsWineURIVtbl = {
958 nsURI_QueryInterface,
986 nsURI_GetOriginCharset,
987 nsURI_GetNSContainer,
988 nsURI_SetNSContainer,
991 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
996 if(IsEqualGUID(&IID_nsISupports, riid)) {
997 TRACE("(IID_nsISupports %p)\n", result);
999 }else if(IsEqualGUID(&IID_nsIIOService, riid)) {
1000 TRACE("(IID_nsIIOService %p)\n", result);
1005 nsIIOService_AddRef(iface);
1009 WARN("(%s %p)\n", debugstr_guid(riid), result);
1010 return NS_NOINTERFACE;
1013 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
1018 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
1023 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
1024 nsIProtocolHandler **_retval)
1026 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1027 return nsIIOService_GetProtocolHandler(nsio, aScheme, _retval);
1030 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
1033 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1034 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
1037 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
1038 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
1040 const char *spec = NULL;
1043 PRBool is_javascript = FALSE;
1046 nsACString_GetData(aSpec, &spec, NULL);
1048 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
1052 nsACString *base_uri_str = nsACString_Create();
1053 const char *base_uri = NULL;
1055 nsres = nsIURI_GetSpec(aBaseURI, base_uri_str);
1056 if(NS_SUCCEEDED(nsres)) {
1057 nsACString_GetData(base_uri_str, &base_uri, NULL);
1058 TRACE("uri=%s\n", debugstr_a(base_uri));
1060 ERR("GetSpec failed: %08lx\n", nsres);
1063 nsACString_Destroy(base_uri_str);
1066 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
1067 if(NS_FAILED(nsres)) {
1068 WARN("NewURI failed: %08lx\n", nsres);
1072 nsIURI_SchemeIs(uri, "javascript", &is_javascript);
1074 TRACE("returning javascript uri: %p\n", uri);
1079 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(nsURI));
1081 ret->lpWineURIVtbl = &nsWineURIVtbl;
1084 ret->container = NULL;
1086 TRACE("_retval = %p\n", ret);
1087 *_retval = NSURI(ret);
1091 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
1094 TRACE("(%p %p)\n", aFile, _retval);
1095 return nsIIOService_NewFileURI(nsio, aFile, _retval);
1098 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
1099 nsIChannel **_retval)
1101 nsIChannel *channel = NULL;
1103 nsIWineURI *wine_uri;
1106 TRACE("(%p %p)\n", aURI, _retval);
1108 nsres = nsIIOService_NewChannelFromURI(nsio, aURI, &channel);
1109 if(NS_FAILED(nsres)) {
1110 WARN("NewChannelFromURI failed: %08lx\n", nsres);
1115 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
1116 if(NS_FAILED(nsres)) {
1117 WARN("Could not get nsIWineURI: %08lx\n", nsres);
1122 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(nsChannel));
1124 ret->lpHttpChannelVtbl = &nsChannelVtbl;
1126 ret->channel = channel;
1127 ret->http_channel = NULL;
1128 ret->uri = wine_uri;
1130 nsIChannel_QueryInterface(ret->channel, &IID_nsIHttpChannel, (void**)&ret->http_channel);
1132 *_retval = NSCHANNEL(ret);
1136 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
1137 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
1139 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
1140 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
1143 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
1145 TRACE("(%p)\n", aOffline);
1146 return nsIIOService_GetOffline(nsio, aOffline);
1149 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
1151 TRACE("(%x)\n", aOffline);
1152 return nsIIOService_SetOffline(nsio, aOffline);
1155 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
1156 const char *aScheme, PRBool *_retval)
1158 TRACE("(%ld %s %p)\n", aPort, debugstr_a(aScheme), _retval);
1159 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
1162 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
1163 nsACString * _retval)
1165 TRACE("(%p %p)\n", urlString, _retval);
1166 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
1169 static const nsIIOServiceVtbl nsIOServiceVtbl = {
1170 nsIOService_QueryInterface,
1172 nsIOService_Release,
1173 nsIOService_GetProtocolHandler,
1174 nsIOService_GetProtocolFlags,
1176 nsIOService_NewFileURI,
1177 nsIOService_NewChannelFromURI,
1178 nsIOService_NewChannel,
1179 nsIOService_GetOffline,
1180 nsIOService_SetOffline,
1181 nsIOService_AllowPort,
1182 nsIOService_ExtractScheme
1185 static nsIIOService nsIOService = { &nsIOServiceVtbl };
1187 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
1192 if(IsEqualGUID(&IID_nsISupports, riid)) {
1193 TRACE("(IID_nsISupoprts %p)\n", result);
1195 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
1196 TRACE("(IID_nsIFactory %p)\n", result);
1201 nsIFactory_AddRef(iface);
1205 WARN("(%s %p)\n", debugstr_guid(riid), result);
1206 return NS_NOINTERFACE;
1209 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
1214 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
1219 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
1220 nsISupports *aOuter, const nsIID *iid, void **result)
1222 return nsIIOService_QueryInterface(&nsIOService, iid, result);
1225 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
1227 WARN("(%x)\n", lock);
1231 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
1232 nsIOServiceFactory_QueryInterface,
1233 nsIOServiceFactory_AddRef,
1234 nsIOServiceFactory_Release,
1235 nsIOServiceFactory_CreateInstance,
1236 nsIOServiceFactory_LockFactory
1239 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
1241 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
1243 nsIFactory *old_factory = NULL;
1246 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
1247 &IID_nsIFactory, (void**)&old_factory);
1248 if(NS_FAILED(nsres)) {
1249 ERR("Could not get factory: %08lx\n", nsres);
1250 nsIFactory_Release(old_factory);
1254 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
1255 if(NS_FAILED(nsres)) {
1256 ERR("Couldn not create nsIOService instance %08lx\n", nsres);
1257 nsIFactory_Release(old_factory);
1261 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
1262 nsIFactory_Release(old_factory);
1263 if(NS_FAILED(nsres))
1264 ERR("UnregisterFactory failed: %08lx\n", nsres);
1266 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
1267 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
1268 if(NS_FAILED(nsres))
1269 ERR("RegisterFactory failed: %08lx\n", nsres);
1272 nsIURI *get_nsIURI(LPCWSTR url)
1280 len = WideCharToMultiByte(CP_ACP, 0, url, -1, NULL, -1, NULL, NULL);
1281 urla = HeapAlloc(GetProcessHeap(), 0, len);
1282 WideCharToMultiByte(CP_ACP, 0, url, -1, urla, -1, NULL, NULL);
1284 acstr = nsACString_Create();
1285 nsACString_SetData(acstr, urla);
1287 nsres = nsIIOService_NewURI(nsio, acstr, NULL, NULL, &ret);
1288 if(NS_FAILED(nsres))
1289 FIXME("NewURI failed: %08lx\n", nsres);
1291 nsACString_Destroy(acstr);
1292 HeapFree(GetProcessHeap(), 0, urla);