rpcrt4/tests: Replace || by |.
[wine/multimedia.git] / dlls / mshtml / nsio.c
blob568434d798790a552210046338831b1ae19f8b16
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., 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 "ole2.h"
29 #include "shlguid.h"
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 const IID NS_IOSERVICE_CID =
44 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
46 static nsIIOService *nsio = NULL;
48 typedef struct {
49 const nsIWineURIVtbl *lpWineURIVtbl;
51 LONG ref;
53 nsIURI *uri;
54 NSContainer *container;
55 IMoniker *mon;
56 LPSTR spec;
57 } nsURI;
59 #define NSURI(x) ((nsIURI*) &(x)->lpWineURIVtbl)
61 static nsresult create_uri(nsIURI*,NSContainer*,nsIURI**);
63 static BOOL exec_shldocvw_67(HTMLDocument *doc, LPCWSTR url)
65 IOleCommandTarget *cmdtrg = NULL;
66 HRESULT hres;
68 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget,
69 (void**)&cmdtrg);
70 if(SUCCEEDED(hres)) {
71 VARIANT varUrl, varRes;
73 V_VT(&varUrl) = VT_BSTR;
74 V_BSTR(&varUrl) = SysAllocString(url);
75 V_VT(&varRes) = VT_BOOL;
77 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
79 IOleCommandTarget_Release(cmdtrg);
80 SysFreeString(V_BSTR(&varUrl));
82 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
83 TRACE("got VARIANT_FALSE, do not load\n");
84 return FALSE;
88 return TRUE;
91 static BOOL handle_uri(NSContainer *container, nsChannel *channel, LPCWSTR uri)
93 IServiceProvider *service_provider;
94 HTMLDocument *doc = container->doc;
95 DWORD hlnf = 0;
96 HRESULT hres;
98 if(!doc) {
99 NSContainer *container_iter = container;
101 hlnf = HLNF_OPENINNEWWINDOW;
102 while(!container_iter->doc)
103 container_iter = container_iter->parent;
104 doc = container_iter->doc;
107 if(!hlnf && !exec_shldocvw_67(doc, uri))
108 return FALSE;
110 hres = IOleClientSite_QueryInterface(doc->client, &IID_IServiceProvider,
111 (void**)&service_provider);
112 if(SUCCEEDED(hres)) {
113 IHlinkFrame *hlink_frame;
115 hres = IServiceProvider_QueryService(service_provider, &IID_IHlinkFrame,
116 &IID_IHlinkFrame, (void**)&hlink_frame);
117 IServiceProvider_Release(service_provider);
118 if(SUCCEEDED(hres)) {
119 hlink_frame_navigate(doc, hlink_frame, uri, channel->post_data_stream, hlnf);
120 IHlinkFrame_Release(hlink_frame);
122 return FALSE;
126 return TRUE;
129 static BOOL before_async_open(nsChannel *channel, NSContainer *container)
131 nsACString uri_str;
132 const char *uria;
133 LPWSTR uri;
134 DWORD len;
135 BOOL ret;
137 nsACString_Init(&uri_str, NULL);
138 nsIWineURI_GetSpec(channel->uri, &uri_str);
139 nsACString_GetData(&uri_str, &uria, NULL);
140 len = MultiByteToWideChar(CP_ACP, 0, uria, -1, NULL, 0);
141 uri = mshtml_alloc(len*sizeof(WCHAR));
142 MultiByteToWideChar(CP_ACP, 0, uria, -1, uri, len);
143 nsACString_Finish(&uri_str);
145 ret = handle_uri(container, channel, uri);
147 mshtml_free(uri);
149 return ret;
152 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
154 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
156 nsChannel *This = NSCHANNEL_THIS(iface);
158 *result = NULL;
160 if(IsEqualGUID(&IID_nsISupports, riid)) {
161 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
162 *result = NSCHANNEL(This);
163 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
164 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
165 *result = NSCHANNEL(This);
166 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
167 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
168 *result = NSCHANNEL(This);
169 }else if(This->http_channel && IsEqualGUID(&IID_nsIHttpChannel, riid)) {
170 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
171 *result = NSHTTPCHANNEL(This);
172 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
173 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
174 *result = NSUPCHANNEL(This);
177 if(*result) {
178 nsIChannel_AddRef(NSCHANNEL(This));
179 return NS_OK;
182 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
184 if(This->channel)
185 return nsIChannel_QueryInterface(This->channel, riid, result);
186 return NS_NOINTERFACE;
189 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
191 nsChannel *This = NSCHANNEL_THIS(iface);
192 nsrefcnt ref = InterlockedIncrement(&This->ref);
194 TRACE("(%p) ref=%d\n", This, ref);
196 return ref;
199 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
201 nsChannel *This = NSCHANNEL_THIS(iface);
202 LONG ref = InterlockedDecrement(&This->ref);
204 if(!ref) {
205 nsIWineURI_Release(This->uri);
206 if(This->channel)
207 nsIChannel_Release(This->channel);
208 if(This->http_channel)
209 nsIHttpChannel_Release(This->http_channel);
210 if(This->post_data_stream)
211 nsIInputStream_Release(This->post_data_stream);
212 if(This->load_group)
213 nsILoadGroup_Release(This->load_group);
214 if(This->notif_callback)
215 nsIInterfaceRequestor_Release(This->notif_callback);
216 if(This->original_uri)
217 nsIURI_Release(This->original_uri);
218 mshtml_free(This->content);
219 mshtml_free(This);
222 return ref;
225 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
227 nsChannel *This = NSCHANNEL_THIS(iface);
229 TRACE("(%p)->(%p)\n", This, aName);
231 if(This->channel)
232 return nsIChannel_GetName(This->channel, aName);
234 FIXME("default action not implemented\n");
235 return NS_ERROR_NOT_IMPLEMENTED;
238 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
240 nsChannel *This = NSCHANNEL_THIS(iface);
242 TRACE("(%p)->(%p)\n", This, _retval);
244 if(This->channel)
245 return nsIChannel_IsPending(This->channel, _retval);
247 FIXME("default action not implemented\n");
248 return NS_ERROR_NOT_IMPLEMENTED;
251 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
253 nsChannel *This = NSCHANNEL_THIS(iface);
255 TRACE("(%p)->(%p)\n", This, aStatus);
257 if(This->channel)
258 return nsIChannel_GetStatus(This->channel, aStatus);
260 TRACE("returning NS_OK\n");
261 return *aStatus = NS_OK;
264 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
266 nsChannel *This = NSCHANNEL_THIS(iface);
268 TRACE("(%p)->(%08x)\n", This, aStatus);
270 if(This->channel)
271 return nsIChannel_Cancel(This->channel, aStatus);
273 FIXME("default action not implemented\n");
274 return NS_ERROR_NOT_IMPLEMENTED;
277 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
279 nsChannel *This = NSCHANNEL_THIS(iface);
281 TRACE("(%p)\n", This);
283 if(This->channel)
284 return nsIChannel_Suspend(This->channel);
286 FIXME("default action not implemented\n");
287 return NS_ERROR_NOT_IMPLEMENTED;
290 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
292 nsChannel *This = NSCHANNEL_THIS(iface);
294 TRACE("(%p)\n", This);
296 if(This->channel)
297 return nsIChannel_Resume(This->channel);
299 FIXME("default action not implemented\n");
300 return NS_ERROR_NOT_IMPLEMENTED;
303 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
305 nsChannel *This = NSCHANNEL_THIS(iface);
307 TRACE("(%p)->(%p)\n", This, aLoadGroup);
309 if(This->load_group)
310 nsILoadGroup_AddRef(This->load_group);
312 *aLoadGroup = This->load_group;
313 return NS_OK;
316 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
318 nsChannel *This = NSCHANNEL_THIS(iface);
320 TRACE("(%p)->(%p)\n", This, aLoadGroup);
322 if(This->load_group)
323 nsILoadGroup_Release(This->load_group);
324 if(aLoadGroup)
325 nsILoadGroup_AddRef(aLoadGroup);
327 This->load_group = aLoadGroup;
329 if(This->channel)
330 return nsIChannel_SetLoadGroup(This->channel, aLoadGroup);
331 return NS_OK;
334 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
336 nsChannel *This = NSCHANNEL_THIS(iface);
338 TRACE("(%p)->(%p)\n", This, aLoadFlags);
340 *aLoadFlags = This->load_flags;
341 return NS_OK;
344 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
346 nsChannel *This = NSCHANNEL_THIS(iface);
348 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
350 This->load_flags = aLoadFlags;
352 if(This->channel)
353 return nsIChannel_SetLoadFlags(This->channel, aLoadFlags);
354 return NS_OK;
357 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
359 nsChannel *This = NSCHANNEL_THIS(iface);
361 TRACE("(%p)->(%p)\n", This, aOriginalURI);
363 if(This->original_uri)
364 nsIURI_AddRef(This->original_uri);
366 *aOriginalURI = This->original_uri;
367 return NS_OK;
370 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
372 nsChannel *This = NSCHANNEL_THIS(iface);
374 TRACE("(%p)->(%p)\n", This, aOriginalURI);
376 if(This->original_uri)
377 nsIURI_Release(This->original_uri);
379 nsIURI_AddRef(aOriginalURI);
380 This->original_uri = aOriginalURI;
382 if(This->channel)
383 return nsIChannel_SetOriginalURI(This->channel, aOriginalURI);
384 return NS_OK;
387 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
389 nsChannel *This = NSCHANNEL_THIS(iface);
391 TRACE("(%p)->(%p)\n", This, aURI);
393 nsIWineURI_AddRef(This->uri);
394 *aURI = (nsIURI*)This->uri;
396 return NS_OK;
399 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
401 nsChannel *This = NSCHANNEL_THIS(iface);
403 TRACE("(%p)->(%p)\n", This, aOwner);
405 if(This->channel)
406 return nsIChannel_GetOwner(This->channel, aOwner);
408 FIXME("default action not implemented\n");
409 return NS_ERROR_NOT_IMPLEMENTED;
412 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
414 nsChannel *This = NSCHANNEL_THIS(iface);
416 TRACE("(%p)->(%p)\n", This, aOwner);
418 if(This->channel)
419 return nsIChannel_SetOwner(This->channel, aOwner);
421 FIXME("default action not implemented\n");
422 return NS_ERROR_NOT_IMPLEMENTED;
425 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
426 nsIInterfaceRequestor **aNotificationCallbacks)
428 nsChannel *This = NSCHANNEL_THIS(iface);
430 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
432 if(This->notif_callback)
433 nsIInterfaceRequestor_AddRef(This->notif_callback);
434 *aNotificationCallbacks = This->notif_callback;
436 return NS_OK;
439 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
440 nsIInterfaceRequestor *aNotificationCallbacks)
442 nsChannel *This = NSCHANNEL_THIS(iface);
444 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
446 if(This->notif_callback)
447 nsIInterfaceRequestor_Release(This->notif_callback);
448 if(aNotificationCallbacks)
449 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
451 This->notif_callback = aNotificationCallbacks;
453 if(This->channel)
454 return nsIChannel_SetNotificationCallbacks(This->channel, aNotificationCallbacks);
455 return NS_OK;
458 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
460 nsChannel *This = NSCHANNEL_THIS(iface);
462 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
464 if(This->channel)
465 return nsIChannel_GetSecurityInfo(This->channel, aSecurityInfo);
467 FIXME("default action not implemented\n");
468 return NS_ERROR_NOT_IMPLEMENTED;
471 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
473 nsChannel *This = NSCHANNEL_THIS(iface);
475 TRACE("(%p)->(%p)\n", This, aContentType);
477 if(This->content) {
478 nsACString_Init(aContentType, This->content);
479 return S_OK;
482 if(This->channel)
483 return nsIChannel_GetContentType(This->channel, aContentType);
485 TRACE("returning default text/html\n");
486 nsACString_Init(aContentType, "text/html");
487 return NS_OK;
490 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
491 const nsACString *aContentType)
493 nsChannel *This = NSCHANNEL_THIS(iface);
495 TRACE("(%p)->(%p)\n", This, aContentType);
497 if(This->channel)
498 return nsIChannel_SetContentType(This->channel, aContentType);
500 FIXME("default action not implemented\n");
501 return NS_ERROR_NOT_IMPLEMENTED;
504 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
505 nsACString *aContentCharset)
507 nsChannel *This = NSCHANNEL_THIS(iface);
509 TRACE("(%p)->(%p)\n", This, aContentCharset);
511 if(This->channel)
512 return nsIChannel_GetContentCharset(This->channel, aContentCharset);
514 FIXME("default action not implemented\n");
515 return NS_ERROR_NOT_IMPLEMENTED;
518 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
519 const nsACString *aContentCharset)
521 nsChannel *This = NSCHANNEL_THIS(iface);
523 TRACE("(%p)->(%p)\n", This, aContentCharset);
525 if(This->channel)
526 return nsIChannel_SetContentCharset(This->channel, aContentCharset);
528 FIXME("default action not implemented\n");
529 return NS_ERROR_NOT_IMPLEMENTED;
532 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
534 nsChannel *This = NSCHANNEL_THIS(iface);
536 TRACE("(%p)->(%p)\n", This, aContentLength);
538 if(This->channel)
539 return nsIChannel_GetContentLength(This->channel, aContentLength);
541 FIXME("default action not implemented\n");
542 return NS_ERROR_NOT_IMPLEMENTED;
545 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
547 nsChannel *This = NSCHANNEL_THIS(iface);
549 TRACE("(%p)->(%d)\n", This, aContentLength);
551 if(This->channel)
552 return nsIChannel_SetContentLength(This->channel, aContentLength);
554 FIXME("default action not implemented\n");
555 return NS_ERROR_NOT_IMPLEMENTED;
558 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
560 nsChannel *This = NSCHANNEL_THIS(iface);
562 TRACE("(%p)->(%p)\n", This, _retval);
564 if(This->channel)
565 return nsIChannel_Open(This->channel, _retval);
567 FIXME("default action not implemented\n");
568 return NS_ERROR_NOT_IMPLEMENTED;
571 static BOOL do_load_from_moniker_hack(nsChannel *This)
573 PRBool b = FALSE;
576 * We should always load the page from IMoniker, but Wine is not yet
577 * ready for this. This function is a heuristic, that decides which
578 * way of loading is better (Gecko implementation or IMoniker). The
579 * aim is to always return TRUE.
582 /* Load from moniker if there is no Gecko channel available */
583 if(!This->channel)
584 return TRUE;
586 /* Load about protocol from moniker */
587 nsIWineURI_SchemeIs(This->uri, "about", &b);
588 if(b)
589 return TRUE;
591 return FALSE;
594 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
595 nsISupports *aContext)
597 nsChannel *This = NSCHANNEL_THIS(iface);
598 BSCallback *bscallback;
599 nsIWineURI *wine_uri;
600 IMoniker *mon;
601 nsresult nsres;
603 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
605 if(This->load_flags & LOAD_INITIAL_DOCUMENT_URI) {
606 NSContainer *container;
608 nsIWineURI_GetNSContainer(This->uri, &container);
609 if(!container) {
610 ERR("container = NULL\n");
611 return NS_ERROR_UNEXPECTED;
614 if(container->bscallback) {
615 nsIChannel_AddRef(NSCHANNEL(This));
616 container->bscallback->nschannel = This;
618 nsIStreamListener_AddRef(aListener);
619 container->bscallback->nslistener = aListener;
621 if(aContext) {
622 nsISupports_AddRef(aContext);
623 container->bscallback->nscontext = aContext;
626 nsIWebBrowserChrome_Release(NSWBCHROME(container));
628 if(do_load_from_moniker_hack(This)) {
629 if(This->load_group) {
630 nsres = nsILoadGroup_AddRequest(This->load_group,
631 (nsIRequest*)NSCHANNEL(This), NULL);
633 if(NS_FAILED(nsres))
634 ERR("AddRequest failed:%08x\n", nsres);
637 return WINE_NS_LOAD_FROM_MONIKER;
639 }else {
640 BOOL cont = before_async_open(This, container);
641 nsIWebBrowserChrome_Release(NSWBCHROME(container));
643 if(!cont) {
644 TRACE("canceled\n");
645 return NS_ERROR_UNEXPECTED;
650 if(This->channel) {
651 if(This->post_data_stream) {
652 nsIUploadChannel *upload_channel;
654 nsres = nsIChannel_QueryInterface(This->channel, &IID_nsIUploadChannel,
655 (void**)&upload_channel);
656 if(NS_SUCCEEDED(nsres)) {
657 nsACString empty_string;
658 nsACString_Init(&empty_string, "");
660 nsres = nsIUploadChannel_SetUploadStream(upload_channel, This->post_data_stream,
661 &empty_string, -1);
662 nsIUploadChannel_Release(upload_channel);
663 if(NS_FAILED(nsres))
664 WARN("SetUploadStream failed: %08x\n", nsres);
666 nsACString_Finish(&empty_string);
670 nsres = nsIChannel_AsyncOpen(This->channel, aListener, aContext);
672 if(NS_FAILED(nsres) && (This->load_flags & LOAD_INITIAL_DOCUMENT_URI))
673 return WINE_NS_LOAD_FROM_MONIKER;
674 return nsres;
677 TRACE("channel == NULL\n");
679 if(!This->original_uri) {
680 ERR("original_uri == NULL\n");
681 return NS_ERROR_UNEXPECTED;
684 nsres = nsIURI_QueryInterface(This->original_uri, &IID_nsIWineURI, (void**)&wine_uri);
685 if(NS_FAILED(nsres)) {
686 ERR("Could not get nsIWineURI: %08x\n", nsres);
687 return NS_ERROR_UNEXPECTED;
690 nsIWineURI_GetMoniker(wine_uri, &mon);
691 nsIWineURI_Release(wine_uri);
693 if(!mon) {
694 WARN("mon == NULL\n");
695 return NS_ERROR_UNEXPECTED;
698 bscallback = create_bscallback(mon);
699 IMoniker_Release(mon);
701 nsIChannel_AddRef(NSCHANNEL(This));
702 bscallback->nschannel = This;
704 nsIStreamListener_AddRef(aListener);
705 bscallback->nslistener = aListener;
707 if(aContext) {
708 nsISupports_AddRef(aContext);
709 bscallback->nscontext = aContext;
712 if(This->load_group) {
713 nsres = nsILoadGroup_AddRequest(This->load_group,
714 (nsIRequest*)NSCHANNEL(This), NULL);
716 if(NS_FAILED(nsres))
717 ERR("AddRequest failed:%08x\n", nsres);
720 start_binding(bscallback);
721 IBindStatusCallback_Release(STATUSCLB(bscallback));
723 return NS_OK;
726 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
728 nsChannel *This = NSCHANNEL_THIS(iface);
730 TRACE("(%p)->(%p)\n", This, aRequestMethod);
732 if(This->http_channel)
733 return nsIHttpChannel_GetRequestMethod(This->http_channel, aRequestMethod);
735 return NS_ERROR_NOT_IMPLEMENTED;
738 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
739 const nsACString *aRequestMethod)
741 nsChannel *This = NSCHANNEL_THIS(iface);
743 TRACE("(%p)->(%p)\n", This, aRequestMethod);
745 if(This->http_channel)
746 return nsIHttpChannel_SetRequestMethod(This->http_channel, aRequestMethod);
748 return NS_ERROR_NOT_IMPLEMENTED;
751 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
753 nsChannel *This = NSCHANNEL_THIS(iface);
755 TRACE("(%p)->(%p)\n", This, aReferrer);
757 if(This->http_channel)
758 return nsIHttpChannel_GetReferrer(This->http_channel, aReferrer);
760 return NS_ERROR_NOT_IMPLEMENTED;
763 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
765 nsChannel *This = NSCHANNEL_THIS(iface);
767 TRACE("(%p)->(%p)\n", This, aReferrer);
769 if(This->http_channel)
770 return nsIHttpChannel_SetReferrer(This->http_channel, aReferrer);
772 return NS_ERROR_NOT_IMPLEMENTED;
775 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
776 const nsACString *aHeader, nsACString *_retval)
778 nsChannel *This = NSCHANNEL_THIS(iface);
780 TRACE("(%p)->(%p %p)\n", This, aHeader, _retval);
782 if(This->http_channel)
783 return nsIHttpChannel_GetRequestHeader(This->http_channel, aHeader, _retval);
785 return NS_ERROR_NOT_IMPLEMENTED;
788 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
789 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
791 nsChannel *This = NSCHANNEL_THIS(iface);
793 TRACE("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
795 if(This->http_channel)
796 return nsIHttpChannel_SetRequestHeader(This->http_channel, aHeader, aValue, aMerge);
798 return NS_ERROR_NOT_IMPLEMENTED;
801 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
802 nsIHttpHeaderVisitor *aVisitor)
804 nsChannel *This = NSCHANNEL_THIS(iface);
806 TRACE("(%p)->(%p)\n", This, aVisitor);
808 if(This->http_channel)
809 return nsIHttpChannel_VisitRequestHeaders(This->http_channel, aVisitor);
811 return NS_ERROR_NOT_IMPLEMENTED;
814 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
816 nsChannel *This = NSCHANNEL_THIS(iface);
818 TRACE("(%p)->(%p)\n", This, aAllowPipelining);
820 if(This->http_channel)
821 return nsIHttpChannel_GetAllowPipelining(This->http_channel, aAllowPipelining);
823 return NS_ERROR_NOT_IMPLEMENTED;
826 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
828 nsChannel *This = NSCHANNEL_THIS(iface);
830 TRACE("(%p)->(%x)\n", This, aAllowPipelining);
832 if(This->http_channel)
833 return nsIHttpChannel_SetAllowPipelining(This->http_channel, aAllowPipelining);
835 return NS_ERROR_NOT_IMPLEMENTED;
838 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
840 nsChannel *This = NSCHANNEL_THIS(iface);
842 TRACE("(%p)->(%p)\n", This, aRedirectionLimit);
844 if(This->http_channel)
845 return nsIHttpChannel_GetRedirectionLimit(This->http_channel, aRedirectionLimit);
847 return NS_ERROR_NOT_IMPLEMENTED;
850 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
852 nsChannel *This = NSCHANNEL_THIS(iface);
854 TRACE("(%p)->(%u)\n", This, aRedirectionLimit);
856 if(This->http_channel)
857 return nsIHttpChannel_SetRedirectionLimit(This->http_channel, aRedirectionLimit);
859 return NS_ERROR_NOT_IMPLEMENTED;
862 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
864 nsChannel *This = NSCHANNEL_THIS(iface);
866 TRACE("(%p)->(%p)\n", This, aResponseStatus);
868 if(This->http_channel)
869 return nsIHttpChannel_GetResponseStatus(This->http_channel, aResponseStatus);
871 return NS_ERROR_NOT_IMPLEMENTED;
874 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
875 nsACString *aResponseStatusText)
877 nsChannel *This = NSCHANNEL_THIS(iface);
879 TRACE("(%p)->(%p)\n", This, aResponseStatusText);
881 if(This->http_channel)
882 return nsIHttpChannel_GetResponseStatusText(This->http_channel, aResponseStatusText);
884 return NS_ERROR_NOT_IMPLEMENTED;
887 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
888 PRBool *aRequestSucceeded)
890 nsChannel *This = NSCHANNEL_THIS(iface);
892 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
894 if(This->http_channel)
895 return nsIHttpChannel_GetRequestSucceeded(This->http_channel, aRequestSucceeded);
897 return NS_ERROR_NOT_IMPLEMENTED;
900 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
901 const nsACString *header, nsACString *_retval)
903 nsChannel *This = NSCHANNEL_THIS(iface);
905 TRACE("(%p)->(%p %p)\n", This, header, _retval);
907 if(This->http_channel)
908 return nsIHttpChannel_GetResponseHeader(This->http_channel, header, _retval);
910 return NS_ERROR_NOT_IMPLEMENTED;
913 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
914 const nsACString *header, const nsACString *value, PRBool merge)
916 nsChannel *This = NSCHANNEL_THIS(iface);
918 TRACE("(%p)->(%p %p %x)\n", This, header, value, merge);
920 if(This->http_channel)
921 return nsIHttpChannel_SetResponseHeader(This->http_channel, header, value, merge);
923 return NS_ERROR_NOT_IMPLEMENTED;
926 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
927 nsIHttpHeaderVisitor *aVisitor)
929 nsChannel *This = NSCHANNEL_THIS(iface);
931 TRACE("(%p)->(%p)\n", This, aVisitor);
933 if(This->http_channel)
934 return nsIHttpChannel_VisitResponseHeaders(This->http_channel, aVisitor);
936 return NS_ERROR_NOT_IMPLEMENTED;
939 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
941 nsChannel *This = NSCHANNEL_THIS(iface);
943 TRACE("(%p)->(%p)\n", This, _retval);
945 if(This->http_channel)
946 return nsIHttpChannel_IsNoStoreResponse(This->http_channel, _retval);
948 return NS_ERROR_NOT_IMPLEMENTED;
951 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
953 nsChannel *This = NSCHANNEL_THIS(iface);
955 TRACE("(%p)->(%p)\n", This, _retval);
957 if(This->http_channel)
958 return nsIHttpChannel_IsNoCacheResponse(This->http_channel, _retval);
960 return NS_ERROR_NOT_IMPLEMENTED;
963 #undef NSCHANNEL_THIS
965 static const nsIHttpChannelVtbl nsChannelVtbl = {
966 nsChannel_QueryInterface,
967 nsChannel_AddRef,
968 nsChannel_Release,
969 nsChannel_GetName,
970 nsChannel_IsPending,
971 nsChannel_GetStatus,
972 nsChannel_Cancel,
973 nsChannel_Suspend,
974 nsChannel_Resume,
975 nsChannel_GetLoadGroup,
976 nsChannel_SetLoadGroup,
977 nsChannel_GetLoadFlags,
978 nsChannel_SetLoadFlags,
979 nsChannel_GetOriginalURI,
980 nsChannel_SetOriginalURI,
981 nsChannel_GetURI,
982 nsChannel_GetOwner,
983 nsChannel_SetOwner,
984 nsChannel_GetNotificationCallbacks,
985 nsChannel_SetNotificationCallbacks,
986 nsChannel_GetSecurityInfo,
987 nsChannel_GetContentType,
988 nsChannel_SetContentType,
989 nsChannel_GetContentCharset,
990 nsChannel_SetContentCharset,
991 nsChannel_GetContentLength,
992 nsChannel_SetContentLength,
993 nsChannel_Open,
994 nsChannel_AsyncOpen,
995 nsChannel_GetRequestMethod,
996 nsChannel_SetRequestMethod,
997 nsChannel_GetReferrer,
998 nsChannel_SetReferrer,
999 nsChannel_GetRequestHeader,
1000 nsChannel_SetRequestHeader,
1001 nsChannel_VisitRequestHeaders,
1002 nsChannel_GetAllowPipelining,
1003 nsChannel_SetAllowPipelining,
1004 nsChannel_GetRedirectionLimit,
1005 nsChannel_SetRedirectionLimit,
1006 nsChannel_GetResponseStatus,
1007 nsChannel_GetResponseStatusText,
1008 nsChannel_GetRequestSucceeded,
1009 nsChannel_GetResponseHeader,
1010 nsChannel_SetResponseHeader,
1011 nsChannel_VisitResponseHeaders,
1012 nsChannel_IsNoStoreResponse,
1013 nsChannel_IsNoCacheResponse
1016 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1018 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1019 nsQIResult result)
1021 nsChannel *This = NSUPCHANNEL_THIS(iface);
1022 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1025 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1027 nsChannel *This = NSUPCHANNEL_THIS(iface);
1028 return nsIChannel_AddRef(NSCHANNEL(This));
1031 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1033 nsChannel *This = NSUPCHANNEL_THIS(iface);
1034 return nsIChannel_Release(NSCHANNEL(This));
1037 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1038 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1040 nsChannel *This = NSUPCHANNEL_THIS(iface);
1041 const char *content_type;
1043 TRACE("(%p)->(%p %p %d)\n", This, aStream, aContentType, aContentLength);
1045 if(This->post_data_stream)
1046 nsIInputStream_Release(This->post_data_stream);
1048 if(aContentType) {
1049 nsACString_GetData(aContentType, &content_type, NULL);
1050 if(*content_type)
1051 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
1054 if(aContentLength != -1)
1055 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1057 if(aStream)
1058 nsIInputStream_AddRef(aStream);
1059 This->post_data_stream = aStream;
1061 return NS_OK;
1064 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1065 nsIInputStream **aUploadStream)
1067 nsChannel *This = NSUPCHANNEL_THIS(iface);
1069 TRACE("(%p)->(%p)\n", This, aUploadStream);
1071 if(This->post_data_stream)
1072 nsIInputStream_AddRef(This->post_data_stream);
1074 *aUploadStream = This->post_data_stream;
1075 return NS_OK;
1078 #undef NSUPCHANNEL_THIS
1080 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1081 nsUploadChannel_QueryInterface,
1082 nsUploadChannel_AddRef,
1083 nsUploadChannel_Release,
1084 nsUploadChannel_SetUploadStream,
1085 nsUploadChannel_GetUploadStream
1088 #define NSURI_THIS(iface) DEFINE_THIS(nsURI, WineURI, iface)
1090 static nsresult NSAPI nsURI_QueryInterface(nsIWineURI *iface, nsIIDRef riid, nsQIResult result)
1092 nsURI *This = NSURI_THIS(iface);
1094 *result = NULL;
1096 if(IsEqualGUID(&IID_nsISupports, riid)) {
1097 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1098 *result = NSURI(This);
1099 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1100 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1101 *result = NSURI(This);
1102 }else if(IsEqualGUID(&IID_nsIWineURI, riid)) {
1103 TRACE("(%p)->(IID_nsIWineURI %p)\n", This, result);
1104 *result = NSURI(This);
1107 if(*result) {
1108 nsIURI_AddRef(NSURI(This));
1109 return NS_OK;
1112 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1113 return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1116 static nsrefcnt NSAPI nsURI_AddRef(nsIWineURI *iface)
1118 nsURI *This = NSURI_THIS(iface);
1119 LONG ref = InterlockedIncrement(&This->ref);
1121 TRACE("(%p) ref=%d\n", This, ref);
1123 return ref;
1126 static nsrefcnt NSAPI nsURI_Release(nsIWineURI *iface)
1128 nsURI *This = NSURI_THIS(iface);
1129 LONG ref = InterlockedDecrement(&This->ref);
1131 TRACE("(%p) ref=%d\n", This, ref);
1133 if(!ref) {
1134 if(This->container)
1135 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1136 if(This->uri)
1137 nsIURI_Release(This->uri);
1138 if(This->mon)
1139 IMoniker_Release(This->mon);
1140 mshtml_free(This->spec);
1141 mshtml_free(This);
1144 return ref;
1147 static nsresult NSAPI nsURI_GetSpec(nsIWineURI *iface, nsACString *aSpec)
1149 nsURI *This = NSURI_THIS(iface);
1151 TRACE("(%p)->(%p)\n", This, aSpec);
1153 if(This->uri)
1154 return nsIURI_GetSpec(This->uri, aSpec);
1156 if(This->spec) {
1157 nsACString_Init(aSpec, This->spec);
1158 return NS_OK;
1161 WARN("mon and uri are NULL\n");
1162 return NS_ERROR_NOT_IMPLEMENTED;
1166 static nsresult NSAPI nsURI_SetSpec(nsIWineURI *iface, const nsACString *aSpec)
1168 nsURI *This = NSURI_THIS(iface);
1170 TRACE("(%p)->(%p)\n", This, aSpec);
1172 if(This->uri)
1173 return nsIURI_SetSpec(This->uri, aSpec);
1175 FIXME("default action not implemented\n");
1176 return NS_ERROR_NOT_IMPLEMENTED;
1179 static nsresult NSAPI nsURI_GetPrePath(nsIWineURI *iface, nsACString *aPrePath)
1181 nsURI *This = NSURI_THIS(iface);
1183 TRACE("(%p)->(%p)\n", This, aPrePath);
1185 if(This->uri)
1186 return nsIURI_GetPrePath(This->uri, aPrePath);
1188 FIXME("default action not implemented\n");
1189 return NS_ERROR_NOT_IMPLEMENTED;
1192 static nsresult NSAPI nsURI_GetScheme(nsIWineURI *iface, nsACString *aScheme)
1194 nsURI *This = NSURI_THIS(iface);
1196 TRACE("(%p)->(%p)\n", This, aScheme);
1198 if(This->uri)
1199 return nsIURI_GetScheme(This->uri, aScheme);
1201 FIXME("default action not implemented\n");
1202 return NS_ERROR_NOT_IMPLEMENTED;
1205 static nsresult NSAPI nsURI_SetScheme(nsIWineURI *iface, const nsACString *aScheme)
1207 nsURI *This = NSURI_THIS(iface);
1209 TRACE("(%p)->(%p)\n", This, aScheme);
1211 if(This->uri)
1212 return nsIURI_SetScheme(This->uri, aScheme);
1214 FIXME("default action not implemented\n");
1215 return NS_ERROR_NOT_IMPLEMENTED;
1218 static nsresult NSAPI nsURI_GetUserPass(nsIWineURI *iface, nsACString *aUserPass)
1220 nsURI *This = NSURI_THIS(iface);
1222 TRACE("(%p)->(%p)\n", This, aUserPass);
1224 if(This->uri)
1225 return nsIURI_GetUserPass(This->uri, aUserPass);
1227 FIXME("default action not implemented\n");
1228 return NS_ERROR_NOT_IMPLEMENTED;
1231 static nsresult NSAPI nsURI_SetUserPass(nsIWineURI *iface, const nsACString *aUserPass)
1233 nsURI *This = NSURI_THIS(iface);
1235 TRACE("(%p)->(%p)\n", This, aUserPass);
1237 if(This->uri)
1238 return nsIURI_SetUserPass(This->uri, aUserPass);
1240 FIXME("default action not implemented\n");
1241 return NS_ERROR_NOT_IMPLEMENTED;
1244 static nsresult NSAPI nsURI_GetUsername(nsIWineURI *iface, nsACString *aUsername)
1246 nsURI *This = NSURI_THIS(iface);
1248 TRACE("(%p)->(%p)\n", This, aUsername);
1250 if(This->uri)
1251 return nsIURI_GetUsername(This->uri, aUsername);
1253 FIXME("default action not implemented\n");
1254 return NS_ERROR_NOT_IMPLEMENTED;
1257 static nsresult NSAPI nsURI_SetUsername(nsIWineURI *iface, const nsACString *aUsername)
1259 nsURI *This = NSURI_THIS(iface);
1261 TRACE("(%p)->(%p)\n", This, aUsername);
1263 if(This->uri)
1264 return nsIURI_SetUsername(This->uri, aUsername);
1266 FIXME("default action not implemented\n");
1267 return NS_ERROR_NOT_IMPLEMENTED;
1270 static nsresult NSAPI nsURI_GetPassword(nsIWineURI *iface, nsACString *aPassword)
1272 nsURI *This = NSURI_THIS(iface);
1274 TRACE("(%p)->(%p)\n", This, aPassword);
1276 if(This->uri)
1277 return nsIURI_GetPassword(This->uri, aPassword);
1279 FIXME("default action not implemented\n");
1280 return NS_ERROR_NOT_IMPLEMENTED;
1283 static nsresult NSAPI nsURI_SetPassword(nsIWineURI *iface, const nsACString *aPassword)
1285 nsURI *This = NSURI_THIS(iface);
1287 TRACE("(%p)->(%p)\n", This, aPassword);
1289 if(This->uri)
1290 return nsIURI_SetPassword(This->uri, aPassword);
1292 FIXME("default action not implemented\n");
1293 return NS_ERROR_NOT_IMPLEMENTED;
1296 static nsresult NSAPI nsURI_GetHostPort(nsIWineURI *iface, nsACString *aHostPort)
1298 nsURI *This = NSURI_THIS(iface);
1300 TRACE("(%p)->(%p)\n", This, aHostPort);
1302 if(This->uri)
1303 return nsIURI_GetHostPort(This->uri, aHostPort);
1305 FIXME("default action not implemented\n");
1306 return NS_ERROR_NOT_IMPLEMENTED;
1309 static nsresult NSAPI nsURI_SetHostPort(nsIWineURI *iface, const nsACString *aHostPort)
1311 nsURI *This = NSURI_THIS(iface);
1313 TRACE("(%p)->(%p)\n", This, aHostPort);
1315 if(This->uri)
1316 return nsIURI_SetHostPort(This->uri, aHostPort);
1318 FIXME("default action not implemented\n");
1319 return NS_ERROR_NOT_IMPLEMENTED;
1322 static nsresult NSAPI nsURI_GetHost(nsIWineURI *iface, nsACString *aHost)
1324 nsURI *This = NSURI_THIS(iface);
1326 TRACE("(%p)->(%p)\n", This, aHost);
1328 if(This->uri)
1329 return nsIURI_GetHost(This->uri, aHost);
1331 FIXME("default action not implemented\n");
1332 return NS_ERROR_NOT_IMPLEMENTED;
1335 static nsresult NSAPI nsURI_SetHost(nsIWineURI *iface, const nsACString *aHost)
1337 nsURI *This = NSURI_THIS(iface);
1339 TRACE("(%p)->(%p)\n", This, aHost);
1341 if(This->uri)
1342 return nsIURI_SetHost(This->uri, aHost);
1344 FIXME("default action not implemented\n");
1345 return NS_ERROR_NOT_IMPLEMENTED;
1348 static nsresult NSAPI nsURI_GetPort(nsIWineURI *iface, PRInt32 *aPort)
1350 nsURI *This = NSURI_THIS(iface);
1352 TRACE("(%p)->(%p)\n", This, aPort);
1354 if(This->uri)
1355 return nsIURI_GetPort(This->uri, aPort);
1357 FIXME("default action not implemented\n");
1358 return NS_ERROR_NOT_IMPLEMENTED;
1361 static nsresult NSAPI nsURI_SetPort(nsIWineURI *iface, PRInt32 aPort)
1363 nsURI *This = NSURI_THIS(iface);
1365 TRACE("(%p)->(%d)\n", This, aPort);
1367 if(This->uri)
1368 return nsIURI_SetPort(This->uri, aPort);
1370 FIXME("default action not implemented\n");
1371 return NS_ERROR_NOT_IMPLEMENTED;
1374 static nsresult NSAPI nsURI_GetPath(nsIWineURI *iface, nsACString *aPath)
1376 nsURI *This = NSURI_THIS(iface);
1378 TRACE("(%p)->(%p)\n", This, aPath);
1380 if(This->uri)
1381 return nsIURI_GetPath(This->uri, aPath);
1383 FIXME("default action not implemented\n");
1384 return NS_ERROR_NOT_IMPLEMENTED;
1387 static nsresult NSAPI nsURI_SetPath(nsIWineURI *iface, const nsACString *aPath)
1389 nsURI *This = NSURI_THIS(iface);
1391 TRACE("(%p)->(%p)\n", This, aPath);
1393 if(This->uri)
1394 return nsIURI_SetPath(This->uri, aPath);
1396 FIXME("default action not implemented\n");
1397 return NS_ERROR_NOT_IMPLEMENTED;
1400 static nsresult NSAPI nsURI_Equals(nsIWineURI *iface, nsIURI *other, PRBool *_retval)
1402 nsURI *This = NSURI_THIS(iface);
1404 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1406 if(This->uri)
1407 return nsIURI_Equals(This->uri, other, _retval);
1409 FIXME("default action not implemented\n");
1410 return NS_ERROR_NOT_IMPLEMENTED;
1413 static nsresult NSAPI nsURI_SchemeIs(nsIWineURI *iface, const char *scheme, PRBool *_retval)
1415 nsURI *This = NSURI_THIS(iface);
1417 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1419 if(This->uri)
1420 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1422 FIXME("default action not implemented\n");
1423 return NS_ERROR_NOT_IMPLEMENTED;
1426 static nsresult NSAPI nsURI_Clone(nsIWineURI *iface, nsIURI **_retval)
1428 nsURI *This = NSURI_THIS(iface);
1430 TRACE("(%p)->(%p)\n", This, _retval);
1432 if(This->uri) {
1433 nsIURI *uri;
1434 nsresult nsres;
1436 nsres = nsIURI_Clone(This->uri, &uri);
1437 if(NS_FAILED(nsres)) {
1438 WARN("Clone failed: %08x\n", nsres);
1439 return nsres;
1442 return create_uri(uri, This->container, _retval);
1445 FIXME("default action not implemented\n");
1446 return NS_ERROR_NOT_IMPLEMENTED;
1449 static nsresult NSAPI nsURI_Resolve(nsIWineURI *iface, const nsACString *arelativePath,
1450 nsACString *_retval)
1452 nsURI *This = NSURI_THIS(iface);
1454 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1456 if(This->uri)
1457 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1459 FIXME("default action not implemented\n");
1460 return NS_ERROR_NOT_IMPLEMENTED;
1463 static nsresult NSAPI nsURI_GetAsciiSpec(nsIWineURI *iface, nsACString *aAsciiSpec)
1465 nsURI *This = NSURI_THIS(iface);
1467 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1469 if(This->uri)
1470 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1472 FIXME("default action not implemented\n");
1473 return NS_ERROR_NOT_IMPLEMENTED;
1476 static nsresult NSAPI nsURI_GetAsciiHost(nsIWineURI *iface, nsACString *aAsciiHost)
1478 nsURI *This = NSURI_THIS(iface);
1480 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1482 if(This->uri)
1483 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1485 FIXME("default action not implemented\n");
1486 return NS_ERROR_NOT_IMPLEMENTED;
1489 static nsresult NSAPI nsURI_GetOriginCharset(nsIWineURI *iface, nsACString *aOriginCharset)
1491 nsURI *This = NSURI_THIS(iface);
1493 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1495 if(This->uri)
1496 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1498 FIXME("default action not implemented\n");
1499 return NS_ERROR_NOT_IMPLEMENTED;
1502 static nsresult NSAPI nsURI_GetNSContainer(nsIWineURI *iface, NSContainer **aContainer)
1504 nsURI *This = NSURI_THIS(iface);
1506 TRACE("(%p)->(%p)\n", This, aContainer);
1508 if(This->container)
1509 nsIWebBrowserChrome_AddRef(NSWBCHROME(This->container));
1510 *aContainer = This->container;
1512 return NS_OK;
1515 static nsresult NSAPI nsURI_SetNSContainer(nsIWineURI *iface, NSContainer *aContainer)
1517 nsURI *This = NSURI_THIS(iface);
1519 TRACE("(%p)->(%p)\n", This, aContainer);
1521 if(This->container) {
1522 WARN("Container already set: %p\n", This->container);
1523 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1526 if(aContainer)
1527 nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer));
1528 This->container = aContainer;
1530 return NS_OK;
1533 static nsresult NSAPI nsURI_GetMoniker(nsIWineURI *iface, IMoniker **aMoniker)
1535 nsURI *This = NSURI_THIS(iface);
1537 TRACE("(%p)->(%p)\n", This, aMoniker);
1539 if(This->mon)
1540 IMoniker_AddRef(This->mon);
1541 *aMoniker = This->mon;
1543 return NS_OK;
1546 static nsresult NSAPI nsURI_SetMoniker(nsIWineURI *iface, IMoniker *aMoniker)
1548 nsURI *This = NSURI_THIS(iface);
1550 TRACE("(%p)->(%p)\n", This, aMoniker);
1552 if(This->mon) {
1553 WARN("Moniker already set: %p\n", This->container);
1554 IMoniker_Release(This->mon);
1556 mshtml_free(This->spec);
1557 This->spec = NULL;
1560 if(aMoniker) {
1561 LPWSTR url = NULL;
1562 HRESULT hres;
1564 hres = IMoniker_GetDisplayName(aMoniker, NULL, NULL, &url);
1565 if(SUCCEEDED(hres)) {
1566 DWORD len;
1568 len = WideCharToMultiByte(CP_ACP, 0, url, -1, NULL, 0, NULL, NULL);
1569 This->spec = mshtml_alloc(len*sizeof(WCHAR));
1570 WideCharToMultiByte(CP_ACP, 0, url, -1, This->spec, -1, NULL, NULL);
1571 CoTaskMemFree(url);
1573 TRACE("spec %s\n", debugstr_a(This->spec));
1574 }else {
1575 ERR("GetDisplayName failed: %08x\n", hres);
1578 IMoniker_AddRef(aMoniker);
1580 This->mon = aMoniker;
1582 return NS_OK;
1585 #undef NSURI_THIS
1587 static const nsIWineURIVtbl nsWineURIVtbl = {
1588 nsURI_QueryInterface,
1589 nsURI_AddRef,
1590 nsURI_Release,
1591 nsURI_GetSpec,
1592 nsURI_SetSpec,
1593 nsURI_GetPrePath,
1594 nsURI_GetScheme,
1595 nsURI_SetScheme,
1596 nsURI_GetUserPass,
1597 nsURI_SetUserPass,
1598 nsURI_GetUsername,
1599 nsURI_SetUsername,
1600 nsURI_GetPassword,
1601 nsURI_SetPassword,
1602 nsURI_GetHostPort,
1603 nsURI_SetHostPort,
1604 nsURI_GetHost,
1605 nsURI_SetHost,
1606 nsURI_GetPort,
1607 nsURI_SetPort,
1608 nsURI_GetPath,
1609 nsURI_SetPath,
1610 nsURI_Equals,
1611 nsURI_SchemeIs,
1612 nsURI_Clone,
1613 nsURI_Resolve,
1614 nsURI_GetAsciiSpec,
1615 nsURI_GetAsciiHost,
1616 nsURI_GetOriginCharset,
1617 nsURI_GetNSContainer,
1618 nsURI_SetNSContainer,
1619 nsURI_GetMoniker,
1620 nsURI_SetMoniker
1623 static nsresult create_uri(nsIURI *uri, NSContainer *container, nsIURI **_retval)
1625 nsURI *ret = mshtml_alloc(sizeof(nsURI));
1627 ret->lpWineURIVtbl = &nsWineURIVtbl;
1628 ret->ref = 1;
1629 ret->uri = uri;
1630 ret->container = container;
1631 ret->mon = NULL;
1632 ret->spec = NULL;
1634 if(container)
1635 nsIWebBrowserChrome_AddRef(NSWBCHROME(container));
1637 TRACE("retval=%p\n", ret);
1638 *_retval = NSURI(ret);
1639 return NS_OK;
1642 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
1643 nsQIResult result)
1645 *result = NULL;
1647 if(IsEqualGUID(&IID_nsISupports, riid)) {
1648 TRACE("(IID_nsISupports %p)\n", result);
1649 *result = iface;
1650 }else if(IsEqualGUID(&IID_nsIIOService, riid)) {
1651 TRACE("(IID_nsIIOService %p)\n", result);
1652 *result = iface;
1655 if(*result) {
1656 nsIIOService_AddRef(iface);
1657 return S_OK;
1660 WARN("(%s %p)\n", debugstr_guid(riid), result);
1661 return NS_NOINTERFACE;
1664 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
1666 return 2;
1669 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
1671 return 1;
1674 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
1675 nsIProtocolHandler **_retval)
1677 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1678 return nsIIOService_GetProtocolHandler(nsio, aScheme, _retval);
1681 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
1682 PRUint32 *_retval)
1684 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1685 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
1688 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
1689 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
1691 const char *spec = NULL;
1692 NSContainer *nscontainer = NULL;
1693 nsIURI *uri = NULL;
1694 PRBool is_javascript = FALSE;
1695 IMoniker *base_mon = NULL;
1696 nsresult nsres;
1698 nsACString_GetData(aSpec, &spec, NULL);
1700 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
1701 aBaseURI, _retval);
1703 if(aBaseURI) {
1704 nsACString base_uri_str;
1705 const char *base_uri = NULL;
1707 nsACString_Init(&base_uri_str, NULL);
1709 nsres = nsIURI_GetSpec(aBaseURI, &base_uri_str);
1710 if(NS_SUCCEEDED(nsres)) {
1711 nsACString_GetData(&base_uri_str, &base_uri, NULL);
1712 TRACE("uri=%s\n", debugstr_a(base_uri));
1713 }else {
1714 ERR("GetSpec failed: %08x\n", nsres);
1717 nsACString_Finish(&base_uri_str);
1720 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
1721 if(NS_FAILED(nsres))
1722 TRACE("NewURI failed: %08x\n", nsres);
1724 if(uri) {
1725 nsIURI_SchemeIs(uri, "javascript", &is_javascript);
1726 if(is_javascript) {
1727 TRACE("returning javascript uri: %p\n", uri);
1728 *_retval = uri;
1729 return NS_OK;
1733 if(aBaseURI) {
1734 nsIWineURI *wine_uri;
1736 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsIWineURI, (void**)&wine_uri);
1737 if(NS_SUCCEEDED(nsres)) {
1738 nsIWineURI_GetNSContainer(wine_uri, &nscontainer);
1739 nsIWineURI_GetMoniker(wine_uri, &base_mon);
1740 nsIWineURI_Release(wine_uri);
1741 }else {
1742 ERR("Could not get nsIWineURI: %08x\n", nsres);
1746 nsres = create_uri(uri, nscontainer, _retval);
1748 if(nscontainer)
1749 nsIWebBrowserChrome_Release(NSWBCHROME(nscontainer));
1751 if(base_mon) {
1752 LPWSTR url;
1753 IMoniker *mon;
1754 DWORD len;
1755 HRESULT hres;
1757 len = MultiByteToWideChar(CP_ACP, 0, spec, -1, NULL, 0);
1758 url = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
1759 MultiByteToWideChar(CP_ACP, 0, spec, -1, url, -1);
1761 hres = CreateURLMoniker(base_mon, url, &mon);
1762 HeapFree(GetProcessHeap(), 0, url);
1763 if(SUCCEEDED(hres)) {
1764 nsIWineURI_SetMoniker((nsIWineURI*)*_retval, mon);
1765 IMoniker_Release(mon);
1766 }else {
1767 WARN("CreateURLMoniker failed: %08x\n", hres);
1771 return nsres;
1774 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
1775 nsIURI **_retval)
1777 TRACE("(%p %p)\n", aFile, _retval);
1778 return nsIIOService_NewFileURI(nsio, aFile, _retval);
1781 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
1782 nsIChannel **_retval)
1784 nsIChannel *channel = NULL;
1785 nsChannel *ret;
1786 nsIWineURI *wine_uri;
1787 nsresult nsres;
1789 TRACE("(%p %p)\n", aURI, _retval);
1791 nsres = nsIIOService_NewChannelFromURI(nsio, aURI, &channel);
1792 if(NS_FAILED(nsres) && nsres != NS_ERROR_UNKNOWN_PROTOCOL) {
1793 WARN("NewChannelFromURI failed: %08x\n", nsres);
1794 *_retval = channel;
1795 return nsres;
1798 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
1799 if(NS_FAILED(nsres)) {
1800 WARN("Could not get nsIWineURI: %08x\n", nsres);
1801 *_retval = channel;
1802 return channel ? NS_OK : NS_ERROR_UNEXPECTED;
1805 ret = mshtml_alloc(sizeof(nsChannel));
1807 ret->lpHttpChannelVtbl = &nsChannelVtbl;
1808 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
1809 ret->ref = 1;
1810 ret->channel = channel;
1811 ret->http_channel = NULL;
1812 ret->uri = wine_uri;
1813 ret->post_data_stream = NULL;
1814 ret->load_group = NULL;
1815 ret->notif_callback = NULL;
1816 ret->load_flags = 0;
1817 ret->content = NULL;
1819 nsIURI_AddRef(aURI);
1820 ret->original_uri = aURI;
1822 if(channel)
1823 nsIChannel_QueryInterface(channel, &IID_nsIHttpChannel, (void**)&ret->http_channel);
1825 *_retval = NSCHANNEL(ret);
1826 return NS_OK;
1829 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
1830 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
1832 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
1833 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
1836 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
1838 TRACE("(%p)\n", aOffline);
1839 return nsIIOService_GetOffline(nsio, aOffline);
1842 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
1844 TRACE("(%x)\n", aOffline);
1845 return nsIIOService_SetOffline(nsio, aOffline);
1848 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
1849 const char *aScheme, PRBool *_retval)
1851 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
1852 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
1855 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
1856 nsACString * _retval)
1858 TRACE("(%p %p)\n", urlString, _retval);
1859 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
1862 static const nsIIOServiceVtbl nsIOServiceVtbl = {
1863 nsIOService_QueryInterface,
1864 nsIOService_AddRef,
1865 nsIOService_Release,
1866 nsIOService_GetProtocolHandler,
1867 nsIOService_GetProtocolFlags,
1868 nsIOService_NewURI,
1869 nsIOService_NewFileURI,
1870 nsIOService_NewChannelFromURI,
1871 nsIOService_NewChannel,
1872 nsIOService_GetOffline,
1873 nsIOService_SetOffline,
1874 nsIOService_AllowPort,
1875 nsIOService_ExtractScheme
1878 static nsIIOService nsIOService = { &nsIOServiceVtbl };
1880 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
1881 nsQIResult result)
1883 *result = NULL;
1885 if(IsEqualGUID(&IID_nsISupports, riid)) {
1886 TRACE("(IID_nsISupoprts %p)\n", result);
1887 *result = iface;
1888 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
1889 TRACE("(IID_nsIFactory %p)\n", result);
1890 *result = iface;
1893 if(*result) {
1894 nsIFactory_AddRef(iface);
1895 return NS_OK;
1898 WARN("(%s %p)\n", debugstr_guid(riid), result);
1899 return NS_NOINTERFACE;
1902 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
1904 return 2;
1907 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
1909 return 1;
1912 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
1913 nsISupports *aOuter, const nsIID *iid, void **result)
1915 return nsIIOService_QueryInterface(&nsIOService, iid, result);
1918 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
1920 WARN("(%x)\n", lock);
1921 return NS_OK;
1924 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
1925 nsIOServiceFactory_QueryInterface,
1926 nsIOServiceFactory_AddRef,
1927 nsIOServiceFactory_Release,
1928 nsIOServiceFactory_CreateInstance,
1929 nsIOServiceFactory_LockFactory
1932 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
1934 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
1936 nsIFactory *old_factory = NULL;
1937 nsresult nsres;
1939 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
1940 &IID_nsIFactory, (void**)&old_factory);
1941 if(NS_FAILED(nsres)) {
1942 ERR("Could not get factory: %08x\n", nsres);
1943 nsIFactory_Release(old_factory);
1944 return;
1947 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
1948 if(NS_FAILED(nsres)) {
1949 ERR("Couldn not create nsIOService instance %08x\n", nsres);
1950 nsIFactory_Release(old_factory);
1951 return;
1954 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
1955 nsIFactory_Release(old_factory);
1956 if(NS_FAILED(nsres))
1957 ERR("UnregisterFactory failed: %08x\n", nsres);
1959 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
1960 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
1961 if(NS_FAILED(nsres))
1962 ERR("RegisterFactory failed: %08x\n", nsres);