shell32/tests: Fixed potential overflow.
[wine/gsoc_dplay.git] / dlls / mshtml / nsio.c
blob6bf8649b95d6eb4581f36ed5fd0c45326f363303
1 /*
2 * Copyright 2006-2007 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "config.h"
21 #include <stdarg.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "ole2.h"
30 #include "shlguid.h"
31 #include "wininet.h"
32 #include "shlwapi.h"
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
37 #include "mshtml_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
41 #define LOAD_INITIAL_DOCUMENT_URI 0x80000
43 #define NS_IOSERVICE_CLASSNAME "nsIOService"
44 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
46 static const IID NS_IOSERVICE_CID =
47 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
49 static nsIIOService *nsio = NULL;
51 typedef struct {
52 const nsIWineURIVtbl *lpWineURIVtbl;
54 LONG ref;
56 nsIURI *uri;
57 NSContainer *container;
58 LPWSTR wine_url;
59 PRBool is_doc_uri;
60 BOOL use_wine_url;
61 } nsURI;
63 #define NSURI(x) ((nsIURI*) &(x)->lpWineURIVtbl)
64 #define NSWINEURI(x) ((nsIWineURI*) &(x)->lpWineURIVtbl)
66 static nsresult create_uri(nsIURI*,NSContainer*,nsIWineURI**);
68 static BOOL exec_shldocvw_67(HTMLDocument *doc, LPCWSTR url)
70 IOleCommandTarget *cmdtrg = NULL;
71 HRESULT hres;
73 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget,
74 (void**)&cmdtrg);
75 if(SUCCEEDED(hres)) {
76 VARIANT varUrl, varRes;
78 V_VT(&varUrl) = VT_BSTR;
79 V_BSTR(&varUrl) = SysAllocString(url);
80 V_VT(&varRes) = VT_BOOL;
82 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
84 IOleCommandTarget_Release(cmdtrg);
85 SysFreeString(V_BSTR(&varUrl));
87 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
88 TRACE("got VARIANT_FALSE, do not load\n");
89 return FALSE;
93 return TRUE;
96 static BOOL handle_uri(NSContainer *container, nsChannel *channel, LPCWSTR uri)
98 IServiceProvider *service_provider;
99 HTMLDocument *doc = container->doc;
100 DWORD hlnf = 0;
101 HRESULT hres;
103 if(!doc) {
104 NSContainer *container_iter = container;
106 hlnf = HLNF_OPENINNEWWINDOW;
107 while(!container_iter->doc)
108 container_iter = container_iter->parent;
109 doc = container_iter->doc;
112 if(!hlnf && !exec_shldocvw_67(doc, uri))
113 return FALSE;
115 hres = IOleClientSite_QueryInterface(doc->client, &IID_IServiceProvider,
116 (void**)&service_provider);
117 if(SUCCEEDED(hres)) {
118 IHlinkFrame *hlink_frame;
120 hres = IServiceProvider_QueryService(service_provider, &IID_IHlinkFrame,
121 &IID_IHlinkFrame, (void**)&hlink_frame);
122 IServiceProvider_Release(service_provider);
123 if(SUCCEEDED(hres)) {
124 hlink_frame_navigate(doc, hlink_frame, uri, channel->post_data_stream, hlnf);
125 IHlinkFrame_Release(hlink_frame);
127 return FALSE;
131 return TRUE;
134 static BOOL before_async_open(nsChannel *channel, NSContainer *container)
136 nsACString uri_str;
137 const char *uria;
138 LPWSTR uri;
139 DWORD len;
140 BOOL ret;
142 nsACString_Init(&uri_str, NULL);
143 nsIWineURI_GetSpec(channel->uri, &uri_str);
144 nsACString_GetData(&uri_str, &uria, NULL);
145 len = MultiByteToWideChar(CP_ACP, 0, uria, -1, NULL, 0);
146 uri = mshtml_alloc(len*sizeof(WCHAR));
147 MultiByteToWideChar(CP_ACP, 0, uria, -1, uri, len);
148 nsACString_Finish(&uri_str);
150 ret = handle_uri(container, channel, uri);
152 mshtml_free(uri);
154 return ret;
157 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
159 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
161 nsChannel *This = NSCHANNEL_THIS(iface);
163 *result = NULL;
165 if(IsEqualGUID(&IID_nsISupports, riid)) {
166 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
167 *result = NSCHANNEL(This);
168 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
169 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
170 *result = NSCHANNEL(This);
171 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
172 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
173 *result = NSCHANNEL(This);
174 }else if(This->http_channel && IsEqualGUID(&IID_nsIHttpChannel, riid)) {
175 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
176 *result = NSHTTPCHANNEL(This);
177 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
178 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
179 *result = NSUPCHANNEL(This);
182 if(*result) {
183 nsIChannel_AddRef(NSCHANNEL(This));
184 return NS_OK;
187 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
189 if(This->channel)
190 return nsIChannel_QueryInterface(This->channel, riid, result);
191 return NS_NOINTERFACE;
194 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
196 nsChannel *This = NSCHANNEL_THIS(iface);
197 nsrefcnt ref = InterlockedIncrement(&This->ref);
199 TRACE("(%p) ref=%d\n", This, ref);
201 return ref;
204 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
206 nsChannel *This = NSCHANNEL_THIS(iface);
207 LONG ref = InterlockedDecrement(&This->ref);
209 if(!ref) {
210 nsIWineURI_Release(This->uri);
211 if(This->channel)
212 nsIChannel_Release(This->channel);
213 if(This->http_channel)
214 nsIHttpChannel_Release(This->http_channel);
215 if(This->post_data_stream)
216 nsIInputStream_Release(This->post_data_stream);
217 if(This->load_group)
218 nsILoadGroup_Release(This->load_group);
219 if(This->notif_callback)
220 nsIInterfaceRequestor_Release(This->notif_callback);
221 if(This->original_uri)
222 nsIURI_Release(This->original_uri);
223 mshtml_free(This->content);
224 mshtml_free(This);
227 return ref;
230 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
232 nsChannel *This = NSCHANNEL_THIS(iface);
234 TRACE("(%p)->(%p)\n", This, aName);
236 if(This->channel)
237 return nsIChannel_GetName(This->channel, aName);
239 FIXME("default action not implemented\n");
240 return NS_ERROR_NOT_IMPLEMENTED;
243 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
245 nsChannel *This = NSCHANNEL_THIS(iface);
247 TRACE("(%p)->(%p)\n", This, _retval);
249 if(This->channel)
250 return nsIChannel_IsPending(This->channel, _retval);
252 FIXME("default action not implemented\n");
253 return NS_ERROR_NOT_IMPLEMENTED;
256 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
258 nsChannel *This = NSCHANNEL_THIS(iface);
260 TRACE("(%p)->(%p)\n", This, aStatus);
262 if(This->channel)
263 return nsIChannel_GetStatus(This->channel, aStatus);
265 TRACE("returning NS_OK\n");
266 return *aStatus = NS_OK;
269 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
271 nsChannel *This = NSCHANNEL_THIS(iface);
273 TRACE("(%p)->(%08x)\n", This, aStatus);
275 if(This->channel)
276 return nsIChannel_Cancel(This->channel, aStatus);
278 FIXME("default action not implemented\n");
279 return NS_ERROR_NOT_IMPLEMENTED;
282 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
284 nsChannel *This = NSCHANNEL_THIS(iface);
286 TRACE("(%p)\n", This);
288 if(This->channel)
289 return nsIChannel_Suspend(This->channel);
291 FIXME("default action not implemented\n");
292 return NS_ERROR_NOT_IMPLEMENTED;
295 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
297 nsChannel *This = NSCHANNEL_THIS(iface);
299 TRACE("(%p)\n", This);
301 if(This->channel)
302 return nsIChannel_Resume(This->channel);
304 FIXME("default action not implemented\n");
305 return NS_ERROR_NOT_IMPLEMENTED;
308 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
310 nsChannel *This = NSCHANNEL_THIS(iface);
312 TRACE("(%p)->(%p)\n", This, aLoadGroup);
314 if(This->load_group)
315 nsILoadGroup_AddRef(This->load_group);
317 *aLoadGroup = This->load_group;
318 return NS_OK;
321 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
323 nsChannel *This = NSCHANNEL_THIS(iface);
325 TRACE("(%p)->(%p)\n", This, aLoadGroup);
327 if(This->load_group)
328 nsILoadGroup_Release(This->load_group);
329 if(aLoadGroup)
330 nsILoadGroup_AddRef(aLoadGroup);
332 This->load_group = aLoadGroup;
334 if(This->channel)
335 return nsIChannel_SetLoadGroup(This->channel, aLoadGroup);
336 return NS_OK;
339 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
341 nsChannel *This = NSCHANNEL_THIS(iface);
343 TRACE("(%p)->(%p)\n", This, aLoadFlags);
345 *aLoadFlags = This->load_flags;
346 return NS_OK;
349 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
351 nsChannel *This = NSCHANNEL_THIS(iface);
353 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
355 This->load_flags = aLoadFlags;
357 if(This->channel)
358 return nsIChannel_SetLoadFlags(This->channel, aLoadFlags);
359 return NS_OK;
362 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
364 nsChannel *This = NSCHANNEL_THIS(iface);
366 TRACE("(%p)->(%p)\n", This, aOriginalURI);
368 if(This->original_uri)
369 nsIURI_AddRef(This->original_uri);
371 *aOriginalURI = This->original_uri;
372 return NS_OK;
375 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
377 nsChannel *This = NSCHANNEL_THIS(iface);
379 TRACE("(%p)->(%p)\n", This, aOriginalURI);
381 if(This->original_uri)
382 nsIURI_Release(This->original_uri);
384 nsIURI_AddRef(aOriginalURI);
385 This->original_uri = aOriginalURI;
387 if(This->channel)
388 return nsIChannel_SetOriginalURI(This->channel, aOriginalURI);
389 return NS_OK;
392 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
394 nsChannel *This = NSCHANNEL_THIS(iface);
396 TRACE("(%p)->(%p)\n", This, aURI);
398 nsIWineURI_AddRef(This->uri);
399 *aURI = (nsIURI*)This->uri;
401 return NS_OK;
404 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
406 nsChannel *This = NSCHANNEL_THIS(iface);
408 TRACE("(%p)->(%p)\n", This, aOwner);
410 if(This->channel)
411 return nsIChannel_GetOwner(This->channel, aOwner);
413 FIXME("default action not implemented\n");
414 return NS_ERROR_NOT_IMPLEMENTED;
417 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
419 nsChannel *This = NSCHANNEL_THIS(iface);
421 TRACE("(%p)->(%p)\n", This, aOwner);
423 if(This->channel)
424 return nsIChannel_SetOwner(This->channel, aOwner);
426 FIXME("default action not implemented\n");
427 return NS_ERROR_NOT_IMPLEMENTED;
430 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
431 nsIInterfaceRequestor **aNotificationCallbacks)
433 nsChannel *This = NSCHANNEL_THIS(iface);
435 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
437 if(This->notif_callback)
438 nsIInterfaceRequestor_AddRef(This->notif_callback);
439 *aNotificationCallbacks = This->notif_callback;
441 return NS_OK;
444 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
445 nsIInterfaceRequestor *aNotificationCallbacks)
447 nsChannel *This = NSCHANNEL_THIS(iface);
449 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
451 if(This->notif_callback)
452 nsIInterfaceRequestor_Release(This->notif_callback);
453 if(aNotificationCallbacks)
454 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
456 This->notif_callback = aNotificationCallbacks;
458 if(This->channel)
459 return nsIChannel_SetNotificationCallbacks(This->channel, aNotificationCallbacks);
460 return NS_OK;
463 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
465 nsChannel *This = NSCHANNEL_THIS(iface);
467 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
469 if(This->channel)
470 return nsIChannel_GetSecurityInfo(This->channel, aSecurityInfo);
472 FIXME("default action not implemented\n");
473 return NS_ERROR_NOT_IMPLEMENTED;
476 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
478 nsChannel *This = NSCHANNEL_THIS(iface);
480 TRACE("(%p)->(%p)\n", This, aContentType);
482 if(This->content) {
483 nsACString_SetData(aContentType, This->content);
484 return S_OK;
487 if(This->channel)
488 return nsIChannel_GetContentType(This->channel, aContentType);
490 TRACE("returning default text/html\n");
491 nsACString_SetData(aContentType, "text/html");
492 return NS_OK;
495 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
496 const nsACString *aContentType)
498 nsChannel *This = NSCHANNEL_THIS(iface);
500 TRACE("(%p)->(%p)\n", This, aContentType);
502 if(This->channel)
503 return nsIChannel_SetContentType(This->channel, aContentType);
505 FIXME("default action not implemented\n");
506 return NS_ERROR_NOT_IMPLEMENTED;
509 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
510 nsACString *aContentCharset)
512 nsChannel *This = NSCHANNEL_THIS(iface);
514 TRACE("(%p)->(%p)\n", This, aContentCharset);
516 if(This->channel)
517 return nsIChannel_GetContentCharset(This->channel, aContentCharset);
519 FIXME("default action not implemented\n");
520 return NS_ERROR_NOT_IMPLEMENTED;
523 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
524 const nsACString *aContentCharset)
526 nsChannel *This = NSCHANNEL_THIS(iface);
528 TRACE("(%p)->(%p)\n", This, aContentCharset);
530 if(This->channel)
531 return nsIChannel_SetContentCharset(This->channel, aContentCharset);
533 FIXME("default action not implemented\n");
534 return NS_ERROR_NOT_IMPLEMENTED;
537 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
539 nsChannel *This = NSCHANNEL_THIS(iface);
541 TRACE("(%p)->(%p)\n", This, aContentLength);
543 if(This->channel)
544 return nsIChannel_GetContentLength(This->channel, aContentLength);
546 FIXME("default action not implemented\n");
547 return NS_ERROR_NOT_IMPLEMENTED;
550 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
552 nsChannel *This = NSCHANNEL_THIS(iface);
554 TRACE("(%p)->(%d)\n", This, aContentLength);
556 if(This->channel)
557 return nsIChannel_SetContentLength(This->channel, aContentLength);
559 FIXME("default action not implemented\n");
560 return NS_ERROR_NOT_IMPLEMENTED;
563 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
565 nsChannel *This = NSCHANNEL_THIS(iface);
567 TRACE("(%p)->(%p)\n", This, _retval);
569 if(This->channel)
570 return nsIChannel_Open(This->channel, _retval);
572 FIXME("default action not implemented\n");
573 return NS_ERROR_NOT_IMPLEMENTED;
576 static BOOL do_load_from_moniker_hack(nsChannel *This)
578 PRBool b = FALSE;
581 * We should always load the page from IMoniker, but Wine is not yet
582 * ready for this. This function is a heuristic, that decides which
583 * way of loading is better (Gecko implementation or IMoniker). The
584 * aim is to always return TRUE.
587 /* Load from moniker if there is no Gecko channel available */
588 if(!This->channel)
589 return TRUE;
591 /* Load about protocol from moniker */
592 nsIWineURI_SchemeIs(This->uri, "about", &b);
593 if(b)
594 return TRUE;
596 return FALSE;
599 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
600 nsISupports *aContext)
602 nsChannel *This = NSCHANNEL_THIS(iface);
603 BSCallback *bscallback;
604 nsIWineURI *wine_uri;
605 IMoniker *mon;
606 PRBool is_doc_uri;
607 LPCWSTR wine_url;
608 nsresult nsres;
609 task_t *task;
610 HRESULT hres;
612 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
614 nsIWineURI_GetIsDocumentURI(This->uri, &is_doc_uri);
616 if(is_doc_uri && (This->load_flags & LOAD_INITIAL_DOCUMENT_URI)) {
617 NSContainer *container;
619 nsIWineURI_GetNSContainer(This->uri, &container);
620 if(!container) {
621 TRACE("container = NULL\n");
622 return nsIChannel_AsyncOpen(This->channel, aListener, aContext);
625 if(container->bscallback) {
626 nsIChannel_AddRef(NSCHANNEL(This));
627 container->bscallback->nschannel = This;
629 nsIStreamListener_AddRef(aListener);
630 container->bscallback->nslistener = aListener;
632 if(aContext) {
633 nsISupports_AddRef(aContext);
634 container->bscallback->nscontext = aContext;
637 nsIWebBrowserChrome_Release(NSWBCHROME(container));
639 if(do_load_from_moniker_hack(This))
640 return WINE_NS_LOAD_FROM_MONIKER;
641 }else if(container->doc) {
642 BOOL cont = before_async_open(This, container);
643 nsIWebBrowserChrome_Release(NSWBCHROME(container));
645 if(!cont) {
646 TRACE("canceled\n");
647 return NS_ERROR_UNEXPECTED;
649 }else {
650 nsIWebBrowserChrome_Release(NSWBCHROME(container));
651 return This->channel
652 ? nsIChannel_AsyncOpen(This->channel, aListener, aContext)
653 : NS_ERROR_UNEXPECTED;
657 if(This->channel) {
658 if(This->post_data_stream) {
659 nsIUploadChannel *upload_channel;
661 nsres = nsIChannel_QueryInterface(This->channel, &IID_nsIUploadChannel,
662 (void**)&upload_channel);
663 if(NS_SUCCEEDED(nsres)) {
664 nsACString empty_string;
665 nsACString_Init(&empty_string, "");
667 nsres = nsIUploadChannel_SetUploadStream(upload_channel, This->post_data_stream,
668 &empty_string, -1);
669 nsIUploadChannel_Release(upload_channel);
670 if(NS_FAILED(nsres))
671 WARN("SetUploadStream failed: %08x\n", nsres);
673 nsACString_Finish(&empty_string);
677 nsres = nsIChannel_AsyncOpen(This->channel, aListener, aContext);
679 if(NS_FAILED(nsres) && (This->load_flags & LOAD_INITIAL_DOCUMENT_URI))
680 return WINE_NS_LOAD_FROM_MONIKER;
681 return nsres;
684 TRACE("channel == NULL\n");
686 if(!This->original_uri) {
687 ERR("original_uri == NULL\n");
688 return NS_ERROR_UNEXPECTED;
691 nsres = nsIURI_QueryInterface(This->original_uri, &IID_nsIWineURI, (void**)&wine_uri);
692 if(NS_FAILED(nsres)) {
693 ERR("Could not get nsIWineURI: %08x\n", nsres);
694 return NS_ERROR_UNEXPECTED;
697 nsIWineURI_GetWineURL(wine_uri, &wine_url);
698 if(!wine_url) {
699 TRACE("wine_url == NULL\n");
700 return NS_ERROR_UNEXPECTED;
703 hres = CreateURLMoniker(NULL, wine_url, &mon);
704 if(FAILED(hres)) {
705 WARN("CreateURLMonikrer failed: %08x\n", hres);
706 return NS_ERROR_UNEXPECTED;
709 bscallback = create_bscallback(mon);
710 IMoniker_Release(mon);
712 nsIChannel_AddRef(NSCHANNEL(This));
713 bscallback->nschannel = This;
715 nsIStreamListener_AddRef(aListener);
716 bscallback->nslistener = aListener;
718 if(aContext) {
719 nsISupports_AddRef(aContext);
720 bscallback->nscontext = aContext;
723 task = mshtml_alloc(sizeof(task_t));
725 task->doc = bscallback->doc;
726 task->task_id = TASK_START_BINDING;
727 task->next = NULL;
728 task->bscallback = bscallback;
730 push_task(task);
732 return NS_OK;
735 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
737 nsChannel *This = NSCHANNEL_THIS(iface);
739 TRACE("(%p)->(%p)\n", This, aRequestMethod);
741 if(This->http_channel)
742 return nsIHttpChannel_GetRequestMethod(This->http_channel, aRequestMethod);
744 return NS_ERROR_NOT_IMPLEMENTED;
747 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
748 const nsACString *aRequestMethod)
750 nsChannel *This = NSCHANNEL_THIS(iface);
752 TRACE("(%p)->(%p)\n", This, aRequestMethod);
754 if(This->http_channel)
755 return nsIHttpChannel_SetRequestMethod(This->http_channel, aRequestMethod);
757 return NS_ERROR_NOT_IMPLEMENTED;
760 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
762 nsChannel *This = NSCHANNEL_THIS(iface);
764 TRACE("(%p)->(%p)\n", This, aReferrer);
766 if(This->http_channel)
767 return nsIHttpChannel_GetReferrer(This->http_channel, aReferrer);
769 return NS_ERROR_NOT_IMPLEMENTED;
772 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
774 nsChannel *This = NSCHANNEL_THIS(iface);
776 TRACE("(%p)->(%p)\n", This, aReferrer);
778 if(This->http_channel)
779 return nsIHttpChannel_SetReferrer(This->http_channel, aReferrer);
781 return NS_ERROR_NOT_IMPLEMENTED;
784 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
785 const nsACString *aHeader, nsACString *_retval)
787 nsChannel *This = NSCHANNEL_THIS(iface);
789 TRACE("(%p)->(%p %p)\n", This, aHeader, _retval);
791 if(This->http_channel)
792 return nsIHttpChannel_GetRequestHeader(This->http_channel, aHeader, _retval);
794 return NS_ERROR_NOT_IMPLEMENTED;
797 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
798 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
800 nsChannel *This = NSCHANNEL_THIS(iface);
802 TRACE("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
804 if(This->http_channel)
805 return nsIHttpChannel_SetRequestHeader(This->http_channel, aHeader, aValue, aMerge);
807 return NS_ERROR_NOT_IMPLEMENTED;
810 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
811 nsIHttpHeaderVisitor *aVisitor)
813 nsChannel *This = NSCHANNEL_THIS(iface);
815 TRACE("(%p)->(%p)\n", This, aVisitor);
817 if(This->http_channel)
818 return nsIHttpChannel_VisitRequestHeaders(This->http_channel, aVisitor);
820 return NS_ERROR_NOT_IMPLEMENTED;
823 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
825 nsChannel *This = NSCHANNEL_THIS(iface);
827 TRACE("(%p)->(%p)\n", This, aAllowPipelining);
829 if(This->http_channel)
830 return nsIHttpChannel_GetAllowPipelining(This->http_channel, aAllowPipelining);
832 return NS_ERROR_NOT_IMPLEMENTED;
835 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
837 nsChannel *This = NSCHANNEL_THIS(iface);
839 TRACE("(%p)->(%x)\n", This, aAllowPipelining);
841 if(This->http_channel)
842 return nsIHttpChannel_SetAllowPipelining(This->http_channel, aAllowPipelining);
844 return NS_ERROR_NOT_IMPLEMENTED;
847 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
849 nsChannel *This = NSCHANNEL_THIS(iface);
851 TRACE("(%p)->(%p)\n", This, aRedirectionLimit);
853 if(This->http_channel)
854 return nsIHttpChannel_GetRedirectionLimit(This->http_channel, aRedirectionLimit);
856 return NS_ERROR_NOT_IMPLEMENTED;
859 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
861 nsChannel *This = NSCHANNEL_THIS(iface);
863 TRACE("(%p)->(%u)\n", This, aRedirectionLimit);
865 if(This->http_channel)
866 return nsIHttpChannel_SetRedirectionLimit(This->http_channel, aRedirectionLimit);
868 return NS_ERROR_NOT_IMPLEMENTED;
871 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
873 nsChannel *This = NSCHANNEL_THIS(iface);
875 TRACE("(%p)->(%p)\n", This, aResponseStatus);
877 if(This->http_channel)
878 return nsIHttpChannel_GetResponseStatus(This->http_channel, aResponseStatus);
880 return NS_ERROR_NOT_IMPLEMENTED;
883 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
884 nsACString *aResponseStatusText)
886 nsChannel *This = NSCHANNEL_THIS(iface);
888 TRACE("(%p)->(%p)\n", This, aResponseStatusText);
890 if(This->http_channel)
891 return nsIHttpChannel_GetResponseStatusText(This->http_channel, aResponseStatusText);
893 return NS_ERROR_NOT_IMPLEMENTED;
896 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
897 PRBool *aRequestSucceeded)
899 nsChannel *This = NSCHANNEL_THIS(iface);
901 TRACE("(%p)->(%p)\n", This, aRequestSucceeded);
903 if(This->http_channel)
904 return nsIHttpChannel_GetRequestSucceeded(This->http_channel, aRequestSucceeded);
906 return NS_ERROR_NOT_IMPLEMENTED;
909 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
910 const nsACString *header, nsACString *_retval)
912 nsChannel *This = NSCHANNEL_THIS(iface);
914 TRACE("(%p)->(%p %p)\n", This, header, _retval);
916 if(This->http_channel)
917 return nsIHttpChannel_GetResponseHeader(This->http_channel, header, _retval);
919 return NS_ERROR_NOT_IMPLEMENTED;
922 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
923 const nsACString *header, const nsACString *value, PRBool merge)
925 nsChannel *This = NSCHANNEL_THIS(iface);
927 TRACE("(%p)->(%p %p %x)\n", This, header, value, merge);
929 if(This->http_channel)
930 return nsIHttpChannel_SetResponseHeader(This->http_channel, header, value, merge);
932 return NS_ERROR_NOT_IMPLEMENTED;
935 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
936 nsIHttpHeaderVisitor *aVisitor)
938 nsChannel *This = NSCHANNEL_THIS(iface);
940 TRACE("(%p)->(%p)\n", This, aVisitor);
942 if(This->http_channel)
943 return nsIHttpChannel_VisitResponseHeaders(This->http_channel, aVisitor);
945 return NS_ERROR_NOT_IMPLEMENTED;
948 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
950 nsChannel *This = NSCHANNEL_THIS(iface);
952 TRACE("(%p)->(%p)\n", This, _retval);
954 if(This->http_channel)
955 return nsIHttpChannel_IsNoStoreResponse(This->http_channel, _retval);
957 return NS_ERROR_NOT_IMPLEMENTED;
960 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
962 nsChannel *This = NSCHANNEL_THIS(iface);
964 TRACE("(%p)->(%p)\n", This, _retval);
966 if(This->http_channel)
967 return nsIHttpChannel_IsNoCacheResponse(This->http_channel, _retval);
969 return NS_ERROR_NOT_IMPLEMENTED;
972 #undef NSCHANNEL_THIS
974 static const nsIHttpChannelVtbl nsChannelVtbl = {
975 nsChannel_QueryInterface,
976 nsChannel_AddRef,
977 nsChannel_Release,
978 nsChannel_GetName,
979 nsChannel_IsPending,
980 nsChannel_GetStatus,
981 nsChannel_Cancel,
982 nsChannel_Suspend,
983 nsChannel_Resume,
984 nsChannel_GetLoadGroup,
985 nsChannel_SetLoadGroup,
986 nsChannel_GetLoadFlags,
987 nsChannel_SetLoadFlags,
988 nsChannel_GetOriginalURI,
989 nsChannel_SetOriginalURI,
990 nsChannel_GetURI,
991 nsChannel_GetOwner,
992 nsChannel_SetOwner,
993 nsChannel_GetNotificationCallbacks,
994 nsChannel_SetNotificationCallbacks,
995 nsChannel_GetSecurityInfo,
996 nsChannel_GetContentType,
997 nsChannel_SetContentType,
998 nsChannel_GetContentCharset,
999 nsChannel_SetContentCharset,
1000 nsChannel_GetContentLength,
1001 nsChannel_SetContentLength,
1002 nsChannel_Open,
1003 nsChannel_AsyncOpen,
1004 nsChannel_GetRequestMethod,
1005 nsChannel_SetRequestMethod,
1006 nsChannel_GetReferrer,
1007 nsChannel_SetReferrer,
1008 nsChannel_GetRequestHeader,
1009 nsChannel_SetRequestHeader,
1010 nsChannel_VisitRequestHeaders,
1011 nsChannel_GetAllowPipelining,
1012 nsChannel_SetAllowPipelining,
1013 nsChannel_GetRedirectionLimit,
1014 nsChannel_SetRedirectionLimit,
1015 nsChannel_GetResponseStatus,
1016 nsChannel_GetResponseStatusText,
1017 nsChannel_GetRequestSucceeded,
1018 nsChannel_GetResponseHeader,
1019 nsChannel_SetResponseHeader,
1020 nsChannel_VisitResponseHeaders,
1021 nsChannel_IsNoStoreResponse,
1022 nsChannel_IsNoCacheResponse
1025 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1027 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1028 nsQIResult result)
1030 nsChannel *This = NSUPCHANNEL_THIS(iface);
1031 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1034 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1036 nsChannel *This = NSUPCHANNEL_THIS(iface);
1037 return nsIChannel_AddRef(NSCHANNEL(This));
1040 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1042 nsChannel *This = NSUPCHANNEL_THIS(iface);
1043 return nsIChannel_Release(NSCHANNEL(This));
1046 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1047 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1049 nsChannel *This = NSUPCHANNEL_THIS(iface);
1050 const char *content_type;
1052 TRACE("(%p)->(%p %p %d)\n", This, aStream, aContentType, aContentLength);
1054 if(This->post_data_stream)
1055 nsIInputStream_Release(This->post_data_stream);
1057 if(aContentType) {
1058 nsACString_GetData(aContentType, &content_type, NULL);
1059 if(*content_type)
1060 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
1063 if(aContentLength != -1)
1064 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1066 if(aStream)
1067 nsIInputStream_AddRef(aStream);
1068 This->post_data_stream = aStream;
1070 return NS_OK;
1073 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1074 nsIInputStream **aUploadStream)
1076 nsChannel *This = NSUPCHANNEL_THIS(iface);
1078 TRACE("(%p)->(%p)\n", This, aUploadStream);
1080 if(This->post_data_stream)
1081 nsIInputStream_AddRef(This->post_data_stream);
1083 *aUploadStream = This->post_data_stream;
1084 return NS_OK;
1087 #undef NSUPCHANNEL_THIS
1089 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1090 nsUploadChannel_QueryInterface,
1091 nsUploadChannel_AddRef,
1092 nsUploadChannel_Release,
1093 nsUploadChannel_SetUploadStream,
1094 nsUploadChannel_GetUploadStream
1097 #define NSURI_THIS(iface) DEFINE_THIS(nsURI, WineURI, iface)
1099 static nsresult NSAPI nsURI_QueryInterface(nsIWineURI *iface, nsIIDRef riid, nsQIResult result)
1101 nsURI *This = NSURI_THIS(iface);
1103 *result = NULL;
1105 if(IsEqualGUID(&IID_nsISupports, riid)) {
1106 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1107 *result = NSURI(This);
1108 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1109 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1110 *result = NSURI(This);
1111 }else if(IsEqualGUID(&IID_nsIWineURI, riid)) {
1112 TRACE("(%p)->(IID_nsIWineURI %p)\n", This, result);
1113 *result = NSURI(This);
1116 if(*result) {
1117 nsIURI_AddRef(NSURI(This));
1118 return NS_OK;
1121 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1122 return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1125 static nsrefcnt NSAPI nsURI_AddRef(nsIWineURI *iface)
1127 nsURI *This = NSURI_THIS(iface);
1128 LONG ref = InterlockedIncrement(&This->ref);
1130 TRACE("(%p) ref=%d\n", This, ref);
1132 return ref;
1135 static nsrefcnt NSAPI nsURI_Release(nsIWineURI *iface)
1137 nsURI *This = NSURI_THIS(iface);
1138 LONG ref = InterlockedDecrement(&This->ref);
1140 TRACE("(%p) ref=%d\n", This, ref);
1142 if(!ref) {
1143 if(This->container)
1144 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1145 if(This->uri)
1146 nsIURI_Release(This->uri);
1147 mshtml_free(This->wine_url);
1148 mshtml_free(This);
1151 return ref;
1154 static nsresult NSAPI nsURI_GetSpec(nsIWineURI *iface, nsACString *aSpec)
1156 nsURI *This = NSURI_THIS(iface);
1158 TRACE("(%p)->(%p)\n", This, aSpec);
1160 if(This->use_wine_url) {
1161 char speca[INTERNET_MAX_URL_LENGTH];
1162 WideCharToMultiByte(CP_ACP, 0, This->wine_url, -1, speca, sizeof(speca), NULL, NULL);
1163 nsACString_SetData(aSpec, speca);
1165 return NS_OK;
1168 if(This->uri)
1169 return nsIURI_GetSpec(This->uri, aSpec);
1171 TRACE("returning error\n");
1172 return NS_ERROR_NOT_IMPLEMENTED;
1176 static nsresult NSAPI nsURI_SetSpec(nsIWineURI *iface, const nsACString *aSpec)
1178 nsURI *This = NSURI_THIS(iface);
1180 TRACE("(%p)->(%p)\n", This, aSpec);
1182 if(This->uri)
1183 return nsIURI_SetSpec(This->uri, aSpec);
1185 FIXME("default action not implemented\n");
1186 return NS_ERROR_NOT_IMPLEMENTED;
1189 static nsresult NSAPI nsURI_GetPrePath(nsIWineURI *iface, nsACString *aPrePath)
1191 nsURI *This = NSURI_THIS(iface);
1193 TRACE("(%p)->(%p)\n", This, aPrePath);
1195 if(This->uri)
1196 return nsIURI_GetPrePath(This->uri, aPrePath);
1198 FIXME("default action not implemented\n");
1199 return NS_ERROR_NOT_IMPLEMENTED;
1202 static nsresult NSAPI nsURI_GetScheme(nsIWineURI *iface, nsACString *aScheme)
1204 nsURI *This = NSURI_THIS(iface);
1206 TRACE("(%p)->(%p)\n", This, aScheme);
1208 if(This->use_wine_url) {
1210 * For Gecko we set scheme to unknown so it won't be handled
1211 * as any special case.
1213 nsACString_SetData(aScheme, "wine");
1214 return NS_OK;
1217 if(This->uri)
1218 return nsIURI_GetScheme(This->uri, aScheme);
1220 TRACE("returning error\n");
1221 return NS_ERROR_NOT_IMPLEMENTED;
1224 static nsresult NSAPI nsURI_SetScheme(nsIWineURI *iface, const nsACString *aScheme)
1226 nsURI *This = NSURI_THIS(iface);
1228 TRACE("(%p)->(%p)\n", This, aScheme);
1230 if(This->uri)
1231 return nsIURI_SetScheme(This->uri, aScheme);
1233 FIXME("default action not implemented\n");
1234 return NS_ERROR_NOT_IMPLEMENTED;
1237 static nsresult NSAPI nsURI_GetUserPass(nsIWineURI *iface, nsACString *aUserPass)
1239 nsURI *This = NSURI_THIS(iface);
1241 TRACE("(%p)->(%p)\n", This, aUserPass);
1243 if(This->uri)
1244 return nsIURI_GetUserPass(This->uri, aUserPass);
1246 FIXME("default action not implemented\n");
1247 return NS_ERROR_NOT_IMPLEMENTED;
1250 static nsresult NSAPI nsURI_SetUserPass(nsIWineURI *iface, const nsACString *aUserPass)
1252 nsURI *This = NSURI_THIS(iface);
1254 TRACE("(%p)->(%p)\n", This, aUserPass);
1256 if(This->uri)
1257 return nsIURI_SetUserPass(This->uri, aUserPass);
1259 FIXME("default action not implemented\n");
1260 return NS_ERROR_NOT_IMPLEMENTED;
1263 static nsresult NSAPI nsURI_GetUsername(nsIWineURI *iface, nsACString *aUsername)
1265 nsURI *This = NSURI_THIS(iface);
1267 TRACE("(%p)->(%p)\n", This, aUsername);
1269 if(This->uri)
1270 return nsIURI_GetUsername(This->uri, aUsername);
1272 FIXME("default action not implemented\n");
1273 return NS_ERROR_NOT_IMPLEMENTED;
1276 static nsresult NSAPI nsURI_SetUsername(nsIWineURI *iface, const nsACString *aUsername)
1278 nsURI *This = NSURI_THIS(iface);
1280 TRACE("(%p)->(%p)\n", This, aUsername);
1282 if(This->uri)
1283 return nsIURI_SetUsername(This->uri, aUsername);
1285 FIXME("default action not implemented\n");
1286 return NS_ERROR_NOT_IMPLEMENTED;
1289 static nsresult NSAPI nsURI_GetPassword(nsIWineURI *iface, nsACString *aPassword)
1291 nsURI *This = NSURI_THIS(iface);
1293 TRACE("(%p)->(%p)\n", This, aPassword);
1295 if(This->uri)
1296 return nsIURI_GetPassword(This->uri, aPassword);
1298 FIXME("default action not implemented\n");
1299 return NS_ERROR_NOT_IMPLEMENTED;
1302 static nsresult NSAPI nsURI_SetPassword(nsIWineURI *iface, const nsACString *aPassword)
1304 nsURI *This = NSURI_THIS(iface);
1306 TRACE("(%p)->(%p)\n", This, aPassword);
1308 if(This->uri)
1309 return nsIURI_SetPassword(This->uri, aPassword);
1311 FIXME("default action not implemented\n");
1312 return NS_ERROR_NOT_IMPLEMENTED;
1315 static nsresult NSAPI nsURI_GetHostPort(nsIWineURI *iface, nsACString *aHostPort)
1317 nsURI *This = NSURI_THIS(iface);
1319 TRACE("(%p)->(%p)\n", This, aHostPort);
1321 if(This->uri)
1322 return nsIURI_GetHostPort(This->uri, aHostPort);
1324 FIXME("default action not implemented\n");
1325 return NS_ERROR_NOT_IMPLEMENTED;
1328 static nsresult NSAPI nsURI_SetHostPort(nsIWineURI *iface, const nsACString *aHostPort)
1330 nsURI *This = NSURI_THIS(iface);
1332 TRACE("(%p)->(%p)\n", This, aHostPort);
1334 if(This->uri)
1335 return nsIURI_SetHostPort(This->uri, aHostPort);
1337 FIXME("default action not implemented\n");
1338 return NS_ERROR_NOT_IMPLEMENTED;
1341 static nsresult NSAPI nsURI_GetHost(nsIWineURI *iface, nsACString *aHost)
1343 nsURI *This = NSURI_THIS(iface);
1345 TRACE("(%p)->(%p)\n", This, aHost);
1347 if(This->uri)
1348 return nsIURI_GetHost(This->uri, aHost);
1350 FIXME("default action not implemented\n");
1351 return NS_ERROR_NOT_IMPLEMENTED;
1354 static nsresult NSAPI nsURI_SetHost(nsIWineURI *iface, const nsACString *aHost)
1356 nsURI *This = NSURI_THIS(iface);
1358 TRACE("(%p)->(%p)\n", This, aHost);
1360 if(This->uri)
1361 return nsIURI_SetHost(This->uri, aHost);
1363 FIXME("default action not implemented\n");
1364 return NS_ERROR_NOT_IMPLEMENTED;
1367 static nsresult NSAPI nsURI_GetPort(nsIWineURI *iface, PRInt32 *aPort)
1369 nsURI *This = NSURI_THIS(iface);
1371 TRACE("(%p)->(%p)\n", This, aPort);
1373 if(This->uri)
1374 return nsIURI_GetPort(This->uri, aPort);
1376 FIXME("default action not implemented\n");
1377 return NS_ERROR_NOT_IMPLEMENTED;
1380 static nsresult NSAPI nsURI_SetPort(nsIWineURI *iface, PRInt32 aPort)
1382 nsURI *This = NSURI_THIS(iface);
1384 TRACE("(%p)->(%d)\n", This, aPort);
1386 if(This->uri)
1387 return nsIURI_SetPort(This->uri, aPort);
1389 FIXME("default action not implemented\n");
1390 return NS_ERROR_NOT_IMPLEMENTED;
1393 static nsresult NSAPI nsURI_GetPath(nsIWineURI *iface, nsACString *aPath)
1395 nsURI *This = NSURI_THIS(iface);
1397 TRACE("(%p)->(%p)\n", This, aPath);
1399 if(This->uri)
1400 return nsIURI_GetPath(This->uri, aPath);
1402 FIXME("default action not implemented\n");
1403 return NS_ERROR_NOT_IMPLEMENTED;
1406 static nsresult NSAPI nsURI_SetPath(nsIWineURI *iface, const nsACString *aPath)
1408 nsURI *This = NSURI_THIS(iface);
1410 TRACE("(%p)->(%p)\n", This, aPath);
1412 if(This->uri)
1413 return nsIURI_SetPath(This->uri, aPath);
1415 FIXME("default action not implemented\n");
1416 return NS_ERROR_NOT_IMPLEMENTED;
1419 static nsresult NSAPI nsURI_Equals(nsIWineURI *iface, nsIURI *other, PRBool *_retval)
1421 nsURI *This = NSURI_THIS(iface);
1423 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1425 if(This->uri)
1426 return nsIURI_Equals(This->uri, other, _retval);
1428 FIXME("default action not implemented\n");
1429 return NS_ERROR_NOT_IMPLEMENTED;
1432 static nsresult NSAPI nsURI_SchemeIs(nsIWineURI *iface, const char *scheme, PRBool *_retval)
1434 nsURI *This = NSURI_THIS(iface);
1436 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1438 if(This->use_wine_url) {
1439 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
1440 int len = MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR))-1;
1442 *_retval = strlenW(This->wine_url) > len
1443 && This->wine_url[len] == ':'
1444 && !memcmp(buf, This->wine_url, len*sizeof(WCHAR));
1445 return NS_OK;
1448 if(This->uri)
1449 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1451 TRACE("returning error\n");
1452 return NS_ERROR_NOT_IMPLEMENTED;
1455 static nsresult NSAPI nsURI_Clone(nsIWineURI *iface, nsIURI **_retval)
1457 nsURI *This = NSURI_THIS(iface);
1459 TRACE("(%p)->(%p)\n", This, _retval);
1461 if(This->uri) {
1462 nsIURI *uri;
1463 nsIWineURI *wine_uri;
1464 nsresult nsres;
1466 nsres = nsIURI_Clone(This->uri, &uri);
1467 if(NS_FAILED(nsres)) {
1468 WARN("Clone failed: %08x\n", nsres);
1469 return nsres;
1472 nsres = create_uri(uri, This->container, &wine_uri);
1473 *_retval = (nsIURI*)wine_uri;
1474 if(NS_SUCCEEDED(nsres))
1475 return nsIWineURI_SetWineURL(wine_uri, This->wine_url);
1476 return nsres;
1479 FIXME("default action not implemented\n");
1480 return NS_ERROR_NOT_IMPLEMENTED;
1483 static nsresult NSAPI nsURI_Resolve(nsIWineURI *iface, const nsACString *arelativePath,
1484 nsACString *_retval)
1486 nsURI *This = NSURI_THIS(iface);
1488 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1490 if(This->uri)
1491 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1493 FIXME("default action not implemented\n");
1494 return NS_ERROR_NOT_IMPLEMENTED;
1497 static nsresult NSAPI nsURI_GetAsciiSpec(nsIWineURI *iface, nsACString *aAsciiSpec)
1499 nsURI *This = NSURI_THIS(iface);
1501 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1503 if(This->wine_url)
1504 return nsIURI_GetSpec(NSURI(This), aAsciiSpec);
1506 if(This->uri)
1507 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1509 TRACE("returning error\n");
1510 return NS_ERROR_NOT_IMPLEMENTED;
1513 static nsresult NSAPI nsURI_GetAsciiHost(nsIWineURI *iface, nsACString *aAsciiHost)
1515 nsURI *This = NSURI_THIS(iface);
1517 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1519 if(This->uri)
1520 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1522 FIXME("default action not implemented\n");
1523 return NS_ERROR_NOT_IMPLEMENTED;
1526 static nsresult NSAPI nsURI_GetOriginCharset(nsIWineURI *iface, nsACString *aOriginCharset)
1528 nsURI *This = NSURI_THIS(iface);
1530 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1532 if(This->uri)
1533 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1535 FIXME("default action not implemented\n");
1536 return NS_ERROR_NOT_IMPLEMENTED;
1539 static nsresult NSAPI nsURI_GetNSContainer(nsIWineURI *iface, NSContainer **aContainer)
1541 nsURI *This = NSURI_THIS(iface);
1543 TRACE("(%p)->(%p)\n", This, aContainer);
1545 if(This->container)
1546 nsIWebBrowserChrome_AddRef(NSWBCHROME(This->container));
1547 *aContainer = This->container;
1549 return NS_OK;
1552 static nsresult NSAPI nsURI_SetNSContainer(nsIWineURI *iface, NSContainer *aContainer)
1554 nsURI *This = NSURI_THIS(iface);
1556 TRACE("(%p)->(%p)\n", This, aContainer);
1558 if(This->container) {
1559 if(This->container == aContainer)
1560 return NS_OK;
1561 WARN("Container already set: %p\n", This->container);
1562 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1565 if(aContainer)
1566 nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer));
1567 This->container = aContainer;
1569 return NS_OK;
1572 static nsresult NSAPI nsURI_GetIsDocumentURI(nsIWineURI *iface, PRBool *aIsDocumentURI)
1574 nsURI *This = NSURI_THIS(iface);
1576 TRACE("(%p)->(%p)\n", This, aIsDocumentURI);
1578 *aIsDocumentURI = This->is_doc_uri;
1579 return NS_OK;
1582 static nsresult NSAPI nsURI_SetIsDocumentURI(nsIWineURI *iface, PRBool aIsDocumentURI)
1584 nsURI *This = NSURI_THIS(iface);
1586 TRACE("(%p)->(%x)\n", This, aIsDocumentURI);
1588 This->is_doc_uri = aIsDocumentURI;
1589 return NS_OK;
1592 static nsresult NSAPI nsURI_GetWineURL(nsIWineURI *iface, LPCWSTR *aURL)
1594 nsURI *This = NSURI_THIS(iface);
1596 TRACE("(%p)->(%p)\n", This, aURL);
1598 *aURL = This->wine_url;
1599 return NS_OK;
1602 static nsresult NSAPI nsURI_SetWineURL(nsIWineURI *iface, LPCWSTR aURL)
1604 nsURI *This = NSURI_THIS(iface);
1606 static const WCHAR wszFtp[] = {'f','t','p',':'};
1607 static const WCHAR wszHttp[] = {'h','t','t','p',':'};
1608 static const WCHAR wszHttps[] = {'h','t','t','p','s',':'};
1610 TRACE("(%p)->(%s)\n", This, debugstr_w(aURL));
1612 mshtml_free(This->wine_url);
1614 if(aURL) {
1615 int len = strlenW(aURL)+1;
1616 This->wine_url = mshtml_alloc(len*sizeof(WCHAR));
1617 memcpy(This->wine_url, aURL, len*sizeof(WCHAR));
1619 /* FIXME: Always use wine url */
1620 This->use_wine_url =
1621 strncmpW(aURL, wszFtp, sizeof(wszFtp)/sizeof(WCHAR))
1622 && strncmpW(aURL, wszHttp, sizeof(wszHttp)/sizeof(WCHAR))
1623 && strncmpW(aURL, wszHttps, sizeof(wszHttps)/sizeof(WCHAR));
1624 }else {
1625 This->wine_url = NULL;
1626 This->use_wine_url = FALSE;
1629 return NS_OK;
1632 #undef NSURI_THIS
1634 static const nsIWineURIVtbl nsWineURIVtbl = {
1635 nsURI_QueryInterface,
1636 nsURI_AddRef,
1637 nsURI_Release,
1638 nsURI_GetSpec,
1639 nsURI_SetSpec,
1640 nsURI_GetPrePath,
1641 nsURI_GetScheme,
1642 nsURI_SetScheme,
1643 nsURI_GetUserPass,
1644 nsURI_SetUserPass,
1645 nsURI_GetUsername,
1646 nsURI_SetUsername,
1647 nsURI_GetPassword,
1648 nsURI_SetPassword,
1649 nsURI_GetHostPort,
1650 nsURI_SetHostPort,
1651 nsURI_GetHost,
1652 nsURI_SetHost,
1653 nsURI_GetPort,
1654 nsURI_SetPort,
1655 nsURI_GetPath,
1656 nsURI_SetPath,
1657 nsURI_Equals,
1658 nsURI_SchemeIs,
1659 nsURI_Clone,
1660 nsURI_Resolve,
1661 nsURI_GetAsciiSpec,
1662 nsURI_GetAsciiHost,
1663 nsURI_GetOriginCharset,
1664 nsURI_GetNSContainer,
1665 nsURI_SetNSContainer,
1666 nsURI_GetIsDocumentURI,
1667 nsURI_SetIsDocumentURI,
1668 nsURI_GetWineURL,
1669 nsURI_SetWineURL
1672 static nsresult create_uri(nsIURI *uri, NSContainer *container, nsIWineURI **_retval)
1674 nsURI *ret = mshtml_alloc(sizeof(nsURI));
1676 ret->lpWineURIVtbl = &nsWineURIVtbl;
1677 ret->ref = 1;
1678 ret->uri = uri;
1679 ret->container = container;
1680 ret->wine_url = NULL;
1681 ret->is_doc_uri = FALSE;
1682 ret->use_wine_url = FALSE;
1684 if(container)
1685 nsIWebBrowserChrome_AddRef(NSWBCHROME(container));
1687 TRACE("retval=%p\n", ret);
1688 *_retval = NSWINEURI(ret);
1689 return NS_OK;
1692 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
1693 nsQIResult result)
1695 *result = NULL;
1697 if(IsEqualGUID(&IID_nsISupports, riid)) {
1698 TRACE("(IID_nsISupports %p)\n", result);
1699 *result = iface;
1700 }else if(IsEqualGUID(&IID_nsIIOService, riid)) {
1701 TRACE("(IID_nsIIOService %p)\n", result);
1702 *result = iface;
1705 if(*result) {
1706 nsIIOService_AddRef(iface);
1707 return S_OK;
1710 WARN("(%s %p)\n", debugstr_guid(riid), result);
1711 return NS_NOINTERFACE;
1714 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
1716 return 2;
1719 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
1721 return 1;
1724 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
1725 nsIProtocolHandler **_retval)
1727 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1728 return nsIIOService_GetProtocolHandler(nsio, aScheme, _retval);
1731 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
1732 PRUint32 *_retval)
1734 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
1735 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
1738 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
1739 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
1741 const char *spec = NULL;
1742 NSContainer *nscontainer = NULL;
1743 nsIURI *uri = NULL;
1744 PRBool is_javascript = FALSE;
1745 LPCWSTR base_wine_url = NULL;
1746 nsIWineURI *base_wine_uri = NULL, *wine_uri;
1747 nsresult nsres;
1749 nsACString_GetData(aSpec, &spec, NULL);
1751 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
1752 aBaseURI, _retval);
1754 if(aBaseURI) {
1755 nsACString base_uri_str;
1756 const char *base_uri = NULL;
1758 static const char szChrome[] = "chrome:";
1759 static const char szResource[] = "resource:";
1761 nsACString_Init(&base_uri_str, NULL);
1763 nsres = nsIURI_GetSpec(aBaseURI, &base_uri_str);
1764 if(NS_SUCCEEDED(nsres)) {
1765 nsACString_GetData(&base_uri_str, &base_uri, NULL);
1766 TRACE("base_uri=%s\n", debugstr_a(base_uri));
1767 }else {
1768 ERR("GetSpec failed: %08x\n", nsres);
1771 nsACString_Finish(&base_uri_str);
1773 if(!strncmp(spec, szChrome, sizeof(szChrome)-1)
1774 || !strncmp(spec, szResource, sizeof(szResource)-1))
1775 aBaseURI = NULL;
1778 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
1779 if(NS_FAILED(nsres))
1780 TRACE("NewURI failed: %08x\n", nsres);
1782 if(uri) {
1783 nsIURI_SchemeIs(uri, "javascript", &is_javascript);
1784 if(is_javascript) {
1785 TRACE("returning javascript uri: %p\n", uri);
1786 *_retval = uri;
1787 return NS_OK;
1791 if(aBaseURI) {
1792 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsIWineURI, (void**)&base_wine_uri);
1793 if(NS_SUCCEEDED(nsres)) {
1794 nsIWineURI_GetNSContainer(base_wine_uri, &nscontainer);
1795 nsIWineURI_GetWineURL(base_wine_uri, &base_wine_url);
1796 }else {
1797 ERR("Could not get nsIWineURI: %08x\n", nsres);
1801 nsres = create_uri(uri, nscontainer, &wine_uri);
1802 *_retval = (nsIURI*)wine_uri;
1804 if(nscontainer)
1805 nsIWebBrowserChrome_Release(NSWBCHROME(nscontainer));
1807 if(base_wine_url) {
1808 WCHAR url[INTERNET_MAX_URL_LENGTH], rel_url[INTERNET_MAX_URL_LENGTH];
1809 LPCSTR speca;
1810 DWORD len;
1811 HRESULT hres;
1813 nsACString_GetData(aSpec, &speca, NULL);
1814 MultiByteToWideChar(CP_ACP, 0, speca, -1, rel_url, sizeof(rel_url)/sizeof(WCHAR));
1816 hres = CoInternetCombineUrl(base_wine_url, rel_url,
1817 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
1818 url, sizeof(url)/sizeof(WCHAR), &len, 0);
1819 if(SUCCEEDED(hres))
1820 nsIWineURI_SetWineURL(wine_uri, url);
1821 else
1822 WARN("CoCombineUrl failed: %08x\n", hres);
1825 if(base_wine_uri)
1826 nsIWineURI_Release(base_wine_uri);
1828 return nsres;
1831 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
1832 nsIURI **_retval)
1834 TRACE("(%p %p)\n", aFile, _retval);
1835 return nsIIOService_NewFileURI(nsio, aFile, _retval);
1838 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
1839 nsIChannel **_retval)
1841 nsIChannel *channel = NULL;
1842 nsChannel *ret;
1843 nsIWineURI *wine_uri;
1844 nsresult nsres;
1846 TRACE("(%p %p)\n", aURI, _retval);
1848 nsres = nsIIOService_NewChannelFromURI(nsio, aURI, &channel);
1849 if(NS_FAILED(nsres) && nsres != NS_ERROR_UNKNOWN_PROTOCOL) {
1850 WARN("NewChannelFromURI failed: %08x\n", nsres);
1851 *_retval = channel;
1852 return nsres;
1855 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
1856 if(NS_FAILED(nsres)) {
1857 WARN("Could not get nsIWineURI: %08x\n", nsres);
1858 *_retval = channel;
1859 return channel ? NS_OK : NS_ERROR_UNEXPECTED;
1862 ret = mshtml_alloc(sizeof(nsChannel));
1864 ret->lpHttpChannelVtbl = &nsChannelVtbl;
1865 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
1866 ret->ref = 1;
1867 ret->channel = channel;
1868 ret->http_channel = NULL;
1869 ret->uri = wine_uri;
1870 ret->post_data_stream = NULL;
1871 ret->load_group = NULL;
1872 ret->notif_callback = NULL;
1873 ret->load_flags = 0;
1874 ret->content = NULL;
1876 nsIURI_AddRef(aURI);
1877 ret->original_uri = aURI;
1879 if(channel)
1880 nsIChannel_QueryInterface(channel, &IID_nsIHttpChannel, (void**)&ret->http_channel);
1882 *_retval = NSCHANNEL(ret);
1883 return NS_OK;
1886 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
1887 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
1889 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
1890 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
1893 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
1895 TRACE("(%p)\n", aOffline);
1896 return nsIIOService_GetOffline(nsio, aOffline);
1899 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
1901 TRACE("(%x)\n", aOffline);
1902 return nsIIOService_SetOffline(nsio, aOffline);
1905 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
1906 const char *aScheme, PRBool *_retval)
1908 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
1909 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
1912 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
1913 nsACString * _retval)
1915 TRACE("(%p %p)\n", urlString, _retval);
1916 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
1919 static const nsIIOServiceVtbl nsIOServiceVtbl = {
1920 nsIOService_QueryInterface,
1921 nsIOService_AddRef,
1922 nsIOService_Release,
1923 nsIOService_GetProtocolHandler,
1924 nsIOService_GetProtocolFlags,
1925 nsIOService_NewURI,
1926 nsIOService_NewFileURI,
1927 nsIOService_NewChannelFromURI,
1928 nsIOService_NewChannel,
1929 nsIOService_GetOffline,
1930 nsIOService_SetOffline,
1931 nsIOService_AllowPort,
1932 nsIOService_ExtractScheme
1935 static nsIIOService nsIOService = { &nsIOServiceVtbl };
1937 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
1938 nsQIResult result)
1940 *result = NULL;
1942 if(IsEqualGUID(&IID_nsISupports, riid)) {
1943 TRACE("(IID_nsISupoprts %p)\n", result);
1944 *result = iface;
1945 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
1946 TRACE("(IID_nsIFactory %p)\n", result);
1947 *result = iface;
1950 if(*result) {
1951 nsIFactory_AddRef(iface);
1952 return NS_OK;
1955 WARN("(%s %p)\n", debugstr_guid(riid), result);
1956 return NS_NOINTERFACE;
1959 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
1961 return 2;
1964 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
1966 return 1;
1969 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
1970 nsISupports *aOuter, const nsIID *iid, void **result)
1972 return nsIIOService_QueryInterface(&nsIOService, iid, result);
1975 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
1977 WARN("(%x)\n", lock);
1978 return NS_OK;
1981 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
1982 nsIOServiceFactory_QueryInterface,
1983 nsIOServiceFactory_AddRef,
1984 nsIOServiceFactory_Release,
1985 nsIOServiceFactory_CreateInstance,
1986 nsIOServiceFactory_LockFactory
1989 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
1991 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
1993 nsIFactory *old_factory = NULL;
1994 nsresult nsres;
1996 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
1997 &IID_nsIFactory, (void**)&old_factory);
1998 if(NS_FAILED(nsres)) {
1999 ERR("Could not get factory: %08x\n", nsres);
2000 nsIFactory_Release(old_factory);
2001 return;
2004 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
2005 if(NS_FAILED(nsres)) {
2006 ERR("Couldn not create nsIOService instance %08x\n", nsres);
2007 nsIFactory_Release(old_factory);
2008 return;
2011 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
2012 nsIFactory_Release(old_factory);
2013 if(NS_FAILED(nsres))
2014 ERR("UnregisterFactory failed: %08x\n", nsres);
2016 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
2017 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
2018 if(NS_FAILED(nsres))
2019 ERR("RegisterFactory failed: %08x\n", nsres);