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
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
37 #include "mshtml_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
41 #define NS_IOSERVICE_CLASSNAME "nsIOService"
42 #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
44 static const IID NS_IOSERVICE_CID =
45 {0x9ac9e770, 0x18bc, 0x11d3, {0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40}};
47 static nsIIOService *nsio = NULL;
48 static nsINetUtil *net_util;
50 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
53 const nsIWineURIVtbl *lpWineURIVtbl;
59 NSContainer *container;
60 windowref_t *window_ref;
61 nsChannelBSC *channel_bsc;
67 #define NSURI(x) ((nsIURI*) &(x)->lpWineURIVtbl)
68 #define NSWINEURI(x) ((nsIWineURI*) &(x)->lpWineURIVtbl)
70 static nsresult create_uri(nsIURI*,HTMLWindow*,NSContainer*,nsIWineURI**);
72 static const char *debugstr_nsacstr(const nsACString *nsstr)
76 nsACString_GetData(nsstr, &data);
77 return debugstr_a(data);
80 HRESULT nsuri_to_url(LPCWSTR nsuri, BOOL ret_empty, BSTR *ret)
82 const WCHAR *ptr = nsuri;
84 static const WCHAR wine_prefixW[] = {'w','i','n','e',':'};
86 if(!strncmpW(nsuri, wine_prefixW, sizeof(wine_prefixW)/sizeof(WCHAR)))
87 ptr += sizeof(wine_prefixW)/sizeof(WCHAR);
89 if(*ptr || ret_empty) {
90 *ret = SysAllocString(ptr);
97 TRACE("%s -> %s\n", debugstr_w(nsuri), debugstr_w(*ret));
101 static BOOL exec_shldocvw_67(HTMLDocumentObj *doc, LPCWSTR url)
103 IOleCommandTarget *cmdtrg = NULL;
106 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
107 if(SUCCEEDED(hres)) {
108 VARIANT varUrl, varRes;
110 V_VT(&varUrl) = VT_BSTR;
111 V_BSTR(&varUrl) = SysAllocString(url);
112 V_VT(&varRes) = VT_BOOL;
114 hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
116 IOleCommandTarget_Release(cmdtrg);
117 SysFreeString(V_BSTR(&varUrl));
119 if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
120 TRACE("got VARIANT_FALSE, do not load\n");
128 static BOOL before_async_open(nsChannel *channel, NSContainer *container)
130 HTMLDocumentObj *doc = container->doc;
135 nsIWineURI_GetWineURL(channel->uri, &uri);
137 ERR("GetWineURL returned NULL\n");
142 NSContainer *container_iter = container;
144 hlnf = HLNF_OPENINNEWWINDOW;
145 while(!container_iter->doc)
146 container_iter = container_iter->parent;
147 doc = container_iter->doc;
153 if(!hlnf && !exec_shldocvw_67(doc, uri))
156 hres = hlink_frame_navigate(&doc->basedoc, uri, channel->post_data_stream, hlnf);
160 static inline BOOL is_http_channel(nsChannel *This)
162 return This->url_scheme == URL_SCHEME_HTTP || This->url_scheme == URL_SCHEME_HTTP;
165 #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
167 static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
169 nsChannel *This = NSCHANNEL_THIS(iface);
171 if(IsEqualGUID(&IID_nsISupports, riid)) {
172 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
173 *result = NSCHANNEL(This);
174 }else if(IsEqualGUID(&IID_nsIRequest, riid)) {
175 TRACE("(%p)->(IID_nsIRequest %p)\n", This, result);
176 *result = NSCHANNEL(This);
177 }else if(IsEqualGUID(&IID_nsIChannel, riid)) {
178 TRACE("(%p)->(IID_nsIChannel %p)\n", This, result);
179 *result = NSCHANNEL(This);
180 }else if(IsEqualGUID(&IID_nsIHttpChannel, riid)) {
181 TRACE("(%p)->(IID_nsIHttpChannel %p)\n", This, result);
182 *result = is_http_channel(This) ? NSHTTPCHANNEL(This) : NULL;
183 }else if(IsEqualGUID(&IID_nsIUploadChannel, riid)) {
184 TRACE("(%p)->(IID_nsIUploadChannel %p)\n", This, result);
185 *result = NSUPCHANNEL(This);
186 }else if(IsEqualGUID(&IID_nsIHttpChannelInternal, riid)) {
187 TRACE("(%p)->(IID_nsIHttpChannelInternal %p)\n", This, result);
188 *result = is_http_channel(This) ? NSHTTPINTERNAL(This) : NULL;
190 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
195 nsIChannel_AddRef(NSCHANNEL(This));
199 return NS_NOINTERFACE;
202 static nsrefcnt NSAPI nsChannel_AddRef(nsIHttpChannel *iface)
204 nsChannel *This = NSCHANNEL_THIS(iface);
205 nsrefcnt ref = InterlockedIncrement(&This->ref);
207 TRACE("(%p) ref=%d\n", This, ref);
212 static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
214 nsChannel *This = NSCHANNEL_THIS(iface);
215 LONG ref = InterlockedDecrement(&This->ref);
218 nsIWineURI_Release(This->uri);
220 nsISupports_Release(This->owner);
221 if(This->post_data_stream)
222 nsIInputStream_Release(This->post_data_stream);
224 nsILoadGroup_Release(This->load_group);
225 if(This->notif_callback)
226 nsIInterfaceRequestor_Release(This->notif_callback);
227 if(This->original_uri)
228 nsIURI_Release(This->original_uri);
229 heap_free(This->content_type);
230 heap_free(This->charset);
237 static nsresult NSAPI nsChannel_GetName(nsIHttpChannel *iface, nsACString *aName)
239 nsChannel *This = NSCHANNEL_THIS(iface);
241 FIXME("(%p)->(%p)\n", This, aName);
243 return NS_ERROR_NOT_IMPLEMENTED;
246 static nsresult NSAPI nsChannel_IsPending(nsIHttpChannel *iface, PRBool *_retval)
248 nsChannel *This = NSCHANNEL_THIS(iface);
250 FIXME("(%p)->(%p)\n", This, _retval);
252 return NS_ERROR_NOT_IMPLEMENTED;
255 static nsresult NSAPI nsChannel_GetStatus(nsIHttpChannel *iface, nsresult *aStatus)
257 nsChannel *This = NSCHANNEL_THIS(iface);
259 WARN("(%p)->(%p) returning NS_OK\n", This, aStatus);
261 return *aStatus = NS_OK;
264 static nsresult NSAPI nsChannel_Cancel(nsIHttpChannel *iface, nsresult aStatus)
266 nsChannel *This = NSCHANNEL_THIS(iface);
268 FIXME("(%p)->(%08x)\n", This, aStatus);
270 return NS_ERROR_NOT_IMPLEMENTED;
273 static nsresult NSAPI nsChannel_Suspend(nsIHttpChannel *iface)
275 nsChannel *This = NSCHANNEL_THIS(iface);
277 FIXME("(%p)\n", This);
279 return NS_ERROR_NOT_IMPLEMENTED;
282 static nsresult NSAPI nsChannel_Resume(nsIHttpChannel *iface)
284 nsChannel *This = NSCHANNEL_THIS(iface);
286 FIXME("(%p)\n", This);
288 return NS_ERROR_NOT_IMPLEMENTED;
291 static nsresult NSAPI nsChannel_GetLoadGroup(nsIHttpChannel *iface, nsILoadGroup **aLoadGroup)
293 nsChannel *This = NSCHANNEL_THIS(iface);
295 TRACE("(%p)->(%p)\n", This, aLoadGroup);
298 nsILoadGroup_AddRef(This->load_group);
300 *aLoadGroup = This->load_group;
304 static nsresult NSAPI nsChannel_SetLoadGroup(nsIHttpChannel *iface, nsILoadGroup *aLoadGroup)
306 nsChannel *This = NSCHANNEL_THIS(iface);
308 TRACE("(%p)->(%p)\n", This, aLoadGroup);
311 nsILoadGroup_Release(This->load_group);
313 nsILoadGroup_AddRef(aLoadGroup);
314 This->load_group = aLoadGroup;
319 static nsresult NSAPI nsChannel_GetLoadFlags(nsIHttpChannel *iface, nsLoadFlags *aLoadFlags)
321 nsChannel *This = NSCHANNEL_THIS(iface);
323 TRACE("(%p)->(%p)\n", This, aLoadFlags);
325 *aLoadFlags = This->load_flags;
329 static nsresult NSAPI nsChannel_SetLoadFlags(nsIHttpChannel *iface, nsLoadFlags aLoadFlags)
331 nsChannel *This = NSCHANNEL_THIS(iface);
333 TRACE("(%p)->(%08x)\n", This, aLoadFlags);
335 This->load_flags = aLoadFlags;
339 static nsresult NSAPI nsChannel_GetOriginalURI(nsIHttpChannel *iface, nsIURI **aOriginalURI)
341 nsChannel *This = NSCHANNEL_THIS(iface);
343 TRACE("(%p)->(%p)\n", This, aOriginalURI);
345 if(This->original_uri)
346 nsIURI_AddRef(This->original_uri);
348 *aOriginalURI = This->original_uri;
352 static nsresult NSAPI nsChannel_SetOriginalURI(nsIHttpChannel *iface, nsIURI *aOriginalURI)
354 nsChannel *This = NSCHANNEL_THIS(iface);
356 TRACE("(%p)->(%p)\n", This, aOriginalURI);
358 if(This->original_uri)
359 nsIURI_Release(This->original_uri);
361 nsIURI_AddRef(aOriginalURI);
362 This->original_uri = aOriginalURI;
366 static nsresult NSAPI nsChannel_GetURI(nsIHttpChannel *iface, nsIURI **aURI)
368 nsChannel *This = NSCHANNEL_THIS(iface);
370 TRACE("(%p)->(%p)\n", This, aURI);
372 nsIWineURI_AddRef(This->uri);
373 *aURI = (nsIURI*)This->uri;
378 static nsresult NSAPI nsChannel_GetOwner(nsIHttpChannel *iface, nsISupports **aOwner)
380 nsChannel *This = NSCHANNEL_THIS(iface);
382 TRACE("(%p)->(%p)\n", This, aOwner);
385 nsISupports_AddRef(This->owner);
386 *aOwner = This->owner;
391 static nsresult NSAPI nsChannel_SetOwner(nsIHttpChannel *iface, nsISupports *aOwner)
393 nsChannel *This = NSCHANNEL_THIS(iface);
395 TRACE("(%p)->(%p)\n", This, aOwner);
398 nsISupports_AddRef(aOwner);
400 nsISupports_Release(This->owner);
401 This->owner = aOwner;
406 static nsresult NSAPI nsChannel_GetNotificationCallbacks(nsIHttpChannel *iface,
407 nsIInterfaceRequestor **aNotificationCallbacks)
409 nsChannel *This = NSCHANNEL_THIS(iface);
411 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
413 if(This->notif_callback)
414 nsIInterfaceRequestor_AddRef(This->notif_callback);
415 *aNotificationCallbacks = This->notif_callback;
420 static nsresult NSAPI nsChannel_SetNotificationCallbacks(nsIHttpChannel *iface,
421 nsIInterfaceRequestor *aNotificationCallbacks)
423 nsChannel *This = NSCHANNEL_THIS(iface);
425 TRACE("(%p)->(%p)\n", This, aNotificationCallbacks);
427 if(This->notif_callback)
428 nsIInterfaceRequestor_Release(This->notif_callback);
429 if(aNotificationCallbacks)
430 nsIInterfaceRequestor_AddRef(aNotificationCallbacks);
432 This->notif_callback = aNotificationCallbacks;
437 static nsresult NSAPI nsChannel_GetSecurityInfo(nsIHttpChannel *iface, nsISupports **aSecurityInfo)
439 nsChannel *This = NSCHANNEL_THIS(iface);
441 TRACE("(%p)->(%p)\n", This, aSecurityInfo);
443 return NS_ERROR_NOT_IMPLEMENTED;
446 static nsresult NSAPI nsChannel_GetContentType(nsIHttpChannel *iface, nsACString *aContentType)
448 nsChannel *This = NSCHANNEL_THIS(iface);
450 TRACE("(%p)->(%p)\n", This, aContentType);
452 if(This->content_type) {
453 nsACString_SetData(aContentType, This->content_type);
457 WARN("unknown type\n");
458 return NS_ERROR_FAILURE;
461 static nsresult NSAPI nsChannel_SetContentType(nsIHttpChannel *iface,
462 const nsACString *aContentType)
464 nsChannel *This = NSCHANNEL_THIS(iface);
465 const char *content_type;
467 TRACE("(%p)->(%p)\n", This, aContentType);
469 nsACString_GetData(aContentType, &content_type);
471 TRACE("content_type %s\n", content_type);
473 heap_free(This->content_type);
474 This->content_type = heap_strdupA(content_type);
479 static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
480 nsACString *aContentCharset)
482 nsChannel *This = NSCHANNEL_THIS(iface);
484 TRACE("(%p)->(%p)\n", This, aContentCharset);
487 nsACString_SetData(aContentCharset, This->charset);
491 nsACString_SetData(aContentCharset, "");
495 static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
496 const nsACString *aContentCharset)
498 nsChannel *This = NSCHANNEL_THIS(iface);
500 FIXME("(%p)->(%p)\n", This, aContentCharset);
502 return NS_ERROR_NOT_IMPLEMENTED;
505 static nsresult NSAPI nsChannel_GetContentLength(nsIHttpChannel *iface, PRInt32 *aContentLength)
507 nsChannel *This = NSCHANNEL_THIS(iface);
509 FIXME("(%p)->(%p)\n", This, aContentLength);
511 return NS_ERROR_NOT_IMPLEMENTED;
514 static nsresult NSAPI nsChannel_SetContentLength(nsIHttpChannel *iface, PRInt32 aContentLength)
516 nsChannel *This = NSCHANNEL_THIS(iface);
518 FIXME("(%p)->(%d)\n", This, aContentLength);
520 return NS_ERROR_NOT_IMPLEMENTED;
523 static nsresult NSAPI nsChannel_Open(nsIHttpChannel *iface, nsIInputStream **_retval)
525 nsChannel *This = NSCHANNEL_THIS(iface);
527 FIXME("(%p)->(%p)\n", This, _retval);
529 return NS_ERROR_NOT_IMPLEMENTED;
532 static HRESULT create_mon_for_nschannel(nsChannel *channel, IMoniker **mon)
534 nsIWineURI *wine_uri;
539 if(!channel->original_uri) {
540 ERR("original_uri == NULL\n");
544 nsres = nsIURI_QueryInterface(channel->original_uri, &IID_nsIWineURI, (void**)&wine_uri);
545 if(NS_FAILED(nsres)) {
546 ERR("Could not get nsIWineURI: %08x\n", nsres);
550 nsIWineURI_GetWineURL(wine_uri, &wine_url);
551 nsIWineURI_Release(wine_uri);
553 TRACE("wine_url == NULL\n");
557 hres = CreateURLMoniker(NULL, wine_url, mon);
559 WARN("CreateURLMoniker failed: %08x\n", hres);
564 static HTMLWindow *get_window_from_load_group(nsChannel *This)
569 nsIWineURI *wine_uri;
573 nsres = nsILoadGroup_GetDefaultLoadRequest(This->load_group, &req);
574 if(NS_FAILED(nsres)) {
575 ERR("GetDefaultLoadRequest failed: %08x\n", nsres);
582 nsres = nsIRequest_QueryInterface(req, &IID_nsIChannel, (void**)&channel);
583 nsIRequest_Release(req);
584 if(NS_FAILED(nsres)) {
585 WARN("Could not get nsIChannel interface: %08x\n", nsres);
589 nsres = nsIChannel_GetURI(channel, &uri);
590 nsIChannel_Release(channel);
591 if(NS_FAILED(nsres)) {
592 ERR("GetURI failed: %08x\n", nsres);
596 nsres = nsIURI_QueryInterface(uri, &IID_nsIWineURI, (void**)&wine_uri);
598 if(NS_FAILED(nsres)) {
599 TRACE("Could not get nsIWineURI: %08x\n", nsres);
603 nsIWineURI_GetWindow(wine_uri, &window);
604 nsIWineURI_Release(wine_uri);
609 static HTMLWindow *get_channel_window(nsChannel *This)
611 nsIRequestObserver *req_observer;
612 nsIWebProgress *web_progress;
613 nsIDOMWindow *nswindow;
617 if(!This->load_group) {
618 ERR("NULL load_group\n");
622 nsres = nsILoadGroup_GetGroupObserver(This->load_group, &req_observer);
623 if(NS_FAILED(nsres) || !req_observer) {
624 ERR("GetGroupObserver failed: %08x\n", nsres);
628 nsres = nsIRequestObserver_QueryInterface(req_observer, &IID_nsIWebProgress, (void**)&web_progress);
629 nsIRequestObserver_Release(req_observer);
630 if(NS_FAILED(nsres)) {
631 ERR("Could not get nsIWebProgress iface: %08x\n", nsres);
635 nsres = nsIWebProgress_GetDOMWindow(web_progress, &nswindow);
636 nsIWebProgress_Release(web_progress);
637 if(NS_FAILED(nsres) || !nswindow) {
638 ERR("GetDOMWindow failed: %08x\n", nsres);
642 window = nswindow_to_window(nswindow);
643 nsIDOMWindow_Release(nswindow);
646 IHTMLWindow2_AddRef(HTMLWINDOW2(window));
648 FIXME("NULL window for %p\n", nswindow);
654 HTMLDocumentNode *doc;
655 nsChannelBSC *bscallback;
656 } start_binding_task_t;
658 static void start_binding_proc(task_t *_task)
660 start_binding_task_t *task = (start_binding_task_t*)_task;
662 start_binding(NULL, task->doc, (BSCallback*)task->bscallback, NULL);
668 nsChannelBSC *bscallback;
669 } start_doc_binding_task_t;
671 static void start_doc_binding_proc(task_t *_task)
673 start_doc_binding_task_t *task = (start_doc_binding_task_t*)_task;
675 start_binding(task->window, NULL, (BSCallback*)task->bscallback, NULL);
676 IUnknown_Release((IUnknown*)task->bscallback);
679 static nsresult async_open(nsChannel *This, HTMLWindow *window, BOOL is_doc_channel, nsIStreamListener *listener,
680 nsISupports *context)
682 nsChannelBSC *bscallback;
683 IMoniker *mon = NULL;
686 hres = create_mon_for_nschannel(This, &mon);
688 return NS_ERROR_UNEXPECTED;
691 set_current_mon(window, mon);
693 bscallback = create_channelbsc(mon);
694 IMoniker_Release(mon);
696 channelbsc_set_channel(bscallback, This, listener, context);
699 start_doc_binding_task_t *task;
701 set_window_bscallback(window, bscallback);
703 task = heap_alloc(sizeof(start_doc_binding_task_t));
704 task->window = window;
705 task->bscallback = bscallback;
706 push_task(&task->header, start_doc_binding_proc, window->task_magic);
708 start_binding_task_t *task = heap_alloc(sizeof(start_binding_task_t));
710 task->doc = window->doc;
711 task->bscallback = bscallback;
712 push_task(&task->header, start_binding_proc, window->doc->basedoc.task_magic);
718 static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListener *aListener,
719 nsISupports *aContext)
721 nsChannel *This = NSCHANNEL_THIS(iface);
722 HTMLWindow *window = NULL;
725 nsresult nsres = NS_OK;
727 TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
729 if(TRACE_ON(mshtml)) {
732 nsIWineURI_GetWineURL(This->uri, &url);
733 TRACE("opening %s\n", debugstr_w(url));
736 nsIWineURI_GetIsDocumentURI(This->uri, &is_doc_uri);
738 window = get_channel_window(This);
740 nsIWineURI_SetWindow(This->uri, window);
742 NSContainer *nscontainer;
744 nsIWineURI_GetNSContainer(This->uri, &nscontainer);
748 /* nscontainer->doc should be NULL which means navigation to a new window */
750 FIXME("nscontainer->doc = %p\n", nscontainer->doc);
752 b = before_async_open(This, nscontainer);
753 nsIWebBrowserChrome_Release(NSWBCHROME(nscontainer));
755 FIXME("Navigation not cancelled\n");
756 return NS_ERROR_UNEXPECTED;
762 nsIWineURI_GetWindow(This->uri, &window);
764 if(!window && This->load_group) {
765 window = get_window_from_load_group(This);
767 nsIWineURI_SetWindow(This->uri, window);
772 ERR("window = NULL\n");
773 return NS_ERROR_UNEXPECTED;
776 if(is_doc_uri && window == window->doc_obj->basedoc.window) {
777 nsChannelBSC *channel_bsc;
779 nsIWineURI_GetChannelBSC(This->uri, &channel_bsc);
781 channelbsc_set_channel(channel_bsc, This, aListener, aContext);
782 IUnknown_Release((IUnknown*)channel_bsc);
784 if(window->doc_obj->mime) {
785 heap_free(This->content_type);
786 This->content_type = heap_strdupWtoA(window->doc_obj->mime);
791 open = before_async_open(This, window->doc_obj->nscontainer);
794 nsres = NS_ERROR_UNEXPECTED;
800 nsres = async_open(This, window, is_doc_uri, aListener, aContext);
802 IHTMLWindow2_Release(HTMLWINDOW2(window));
806 static nsresult NSAPI nsChannel_GetRequestMethod(nsIHttpChannel *iface, nsACString *aRequestMethod)
808 nsChannel *This = NSCHANNEL_THIS(iface);
810 FIXME("(%p)->(%p)\n", This, aRequestMethod);
812 return NS_ERROR_NOT_IMPLEMENTED;
815 static nsresult NSAPI nsChannel_SetRequestMethod(nsIHttpChannel *iface,
816 const nsACString *aRequestMethod)
818 nsChannel *This = NSCHANNEL_THIS(iface);
820 FIXME("(%p)->(%p)\n", This, aRequestMethod);
822 return NS_ERROR_NOT_IMPLEMENTED;
825 static nsresult NSAPI nsChannel_GetReferrer(nsIHttpChannel *iface, nsIURI **aReferrer)
827 nsChannel *This = NSCHANNEL_THIS(iface);
829 FIXME("(%p)->(%p)\n", This, aReferrer);
831 return NS_ERROR_NOT_IMPLEMENTED;
834 static nsresult NSAPI nsChannel_SetReferrer(nsIHttpChannel *iface, nsIURI *aReferrer)
836 nsChannel *This = NSCHANNEL_THIS(iface);
838 FIXME("(%p)->(%p)\n", This, aReferrer);
843 static nsresult NSAPI nsChannel_GetRequestHeader(nsIHttpChannel *iface,
844 const nsACString *aHeader, nsACString *_retval)
846 nsChannel *This = NSCHANNEL_THIS(iface);
848 FIXME("(%p)->(%p %p)\n", This, aHeader, _retval);
850 return NS_ERROR_NOT_IMPLEMENTED;
853 static nsresult NSAPI nsChannel_SetRequestHeader(nsIHttpChannel *iface,
854 const nsACString *aHeader, const nsACString *aValue, PRBool aMerge)
856 nsChannel *This = NSCHANNEL_THIS(iface);
858 FIXME("(%p)->(%p %p %x)\n", This, aHeader, aValue, aMerge);
863 static nsresult NSAPI nsChannel_VisitRequestHeaders(nsIHttpChannel *iface,
864 nsIHttpHeaderVisitor *aVisitor)
866 nsChannel *This = NSCHANNEL_THIS(iface);
868 FIXME("(%p)->(%p)\n", This, aVisitor);
870 return NS_ERROR_NOT_IMPLEMENTED;
873 static nsresult NSAPI nsChannel_GetAllowPipelining(nsIHttpChannel *iface, PRBool *aAllowPipelining)
875 nsChannel *This = NSCHANNEL_THIS(iface);
877 FIXME("(%p)->(%p)\n", This, aAllowPipelining);
879 return NS_ERROR_NOT_IMPLEMENTED;
882 static nsresult NSAPI nsChannel_SetAllowPipelining(nsIHttpChannel *iface, PRBool aAllowPipelining)
884 nsChannel *This = NSCHANNEL_THIS(iface);
886 FIXME("(%p)->(%x)\n", This, aAllowPipelining);
888 return NS_ERROR_NOT_IMPLEMENTED;
891 static nsresult NSAPI nsChannel_GetRedirectionLimit(nsIHttpChannel *iface, PRUint32 *aRedirectionLimit)
893 nsChannel *This = NSCHANNEL_THIS(iface);
895 FIXME("(%p)->(%p)\n", This, aRedirectionLimit);
897 return NS_ERROR_NOT_IMPLEMENTED;
900 static nsresult NSAPI nsChannel_SetRedirectionLimit(nsIHttpChannel *iface, PRUint32 aRedirectionLimit)
902 nsChannel *This = NSCHANNEL_THIS(iface);
904 FIXME("(%p)->(%u)\n", This, aRedirectionLimit);
906 return NS_ERROR_NOT_IMPLEMENTED;
909 static nsresult NSAPI nsChannel_GetResponseStatus(nsIHttpChannel *iface, PRUint32 *aResponseStatus)
911 nsChannel *This = NSCHANNEL_THIS(iface);
913 TRACE("(%p)->(%p)\n", This, aResponseStatus);
915 if(This->response_status) {
916 *aResponseStatus = This->response_status;
920 WARN("No response status\n");
921 return NS_ERROR_UNEXPECTED;
924 static nsresult NSAPI nsChannel_GetResponseStatusText(nsIHttpChannel *iface,
925 nsACString *aResponseStatusText)
927 nsChannel *This = NSCHANNEL_THIS(iface);
929 FIXME("(%p)->(%p)\n", This, aResponseStatusText);
931 return NS_ERROR_NOT_IMPLEMENTED;
934 static nsresult NSAPI nsChannel_GetRequestSucceeded(nsIHttpChannel *iface,
935 PRBool *aRequestSucceeded)
937 nsChannel *This = NSCHANNEL_THIS(iface);
939 FIXME("(%p)->(%p)\n", This, aRequestSucceeded);
941 return NS_ERROR_NOT_IMPLEMENTED;
944 static nsresult NSAPI nsChannel_GetResponseHeader(nsIHttpChannel *iface,
945 const nsACString *header, nsACString *_retval)
947 nsChannel *This = NSCHANNEL_THIS(iface);
949 FIXME("(%p)->(%p %p)\n", This, header, _retval);
951 return NS_ERROR_NOT_IMPLEMENTED;
954 static nsresult NSAPI nsChannel_SetResponseHeader(nsIHttpChannel *iface,
955 const nsACString *header, const nsACString *value, PRBool merge)
957 nsChannel *This = NSCHANNEL_THIS(iface);
959 FIXME("(%p)->(%p %p %x)\n", This, header, value, merge);
961 return NS_ERROR_NOT_IMPLEMENTED;
964 static nsresult NSAPI nsChannel_VisitResponseHeaders(nsIHttpChannel *iface,
965 nsIHttpHeaderVisitor *aVisitor)
967 nsChannel *This = NSCHANNEL_THIS(iface);
969 FIXME("(%p)->(%p)\n", This, aVisitor);
971 return NS_ERROR_NOT_IMPLEMENTED;
974 static nsresult NSAPI nsChannel_IsNoStoreResponse(nsIHttpChannel *iface, PRBool *_retval)
976 nsChannel *This = NSCHANNEL_THIS(iface);
978 FIXME("(%p)->(%p)\n", This, _retval);
980 return NS_ERROR_NOT_IMPLEMENTED;
983 static nsresult NSAPI nsChannel_IsNoCacheResponse(nsIHttpChannel *iface, PRBool *_retval)
985 nsChannel *This = NSCHANNEL_THIS(iface);
987 FIXME("(%p)->(%p)\n", This, _retval);
989 return NS_ERROR_NOT_IMPLEMENTED;
992 #undef NSCHANNEL_THIS
994 static const nsIHttpChannelVtbl nsChannelVtbl = {
995 nsChannel_QueryInterface,
1000 nsChannel_GetStatus,
1004 nsChannel_GetLoadGroup,
1005 nsChannel_SetLoadGroup,
1006 nsChannel_GetLoadFlags,
1007 nsChannel_SetLoadFlags,
1008 nsChannel_GetOriginalURI,
1009 nsChannel_SetOriginalURI,
1013 nsChannel_GetNotificationCallbacks,
1014 nsChannel_SetNotificationCallbacks,
1015 nsChannel_GetSecurityInfo,
1016 nsChannel_GetContentType,
1017 nsChannel_SetContentType,
1018 nsChannel_GetContentCharset,
1019 nsChannel_SetContentCharset,
1020 nsChannel_GetContentLength,
1021 nsChannel_SetContentLength,
1023 nsChannel_AsyncOpen,
1024 nsChannel_GetRequestMethod,
1025 nsChannel_SetRequestMethod,
1026 nsChannel_GetReferrer,
1027 nsChannel_SetReferrer,
1028 nsChannel_GetRequestHeader,
1029 nsChannel_SetRequestHeader,
1030 nsChannel_VisitRequestHeaders,
1031 nsChannel_GetAllowPipelining,
1032 nsChannel_SetAllowPipelining,
1033 nsChannel_GetRedirectionLimit,
1034 nsChannel_SetRedirectionLimit,
1035 nsChannel_GetResponseStatus,
1036 nsChannel_GetResponseStatusText,
1037 nsChannel_GetRequestSucceeded,
1038 nsChannel_GetResponseHeader,
1039 nsChannel_SetResponseHeader,
1040 nsChannel_VisitResponseHeaders,
1041 nsChannel_IsNoStoreResponse,
1042 nsChannel_IsNoCacheResponse
1045 #define NSUPCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, UploadChannel, iface)
1047 static nsresult NSAPI nsUploadChannel_QueryInterface(nsIUploadChannel *iface, nsIIDRef riid,
1050 nsChannel *This = NSUPCHANNEL_THIS(iface);
1051 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1054 static nsrefcnt NSAPI nsUploadChannel_AddRef(nsIUploadChannel *iface)
1056 nsChannel *This = NSUPCHANNEL_THIS(iface);
1057 return nsIChannel_AddRef(NSCHANNEL(This));
1060 static nsrefcnt NSAPI nsUploadChannel_Release(nsIUploadChannel *iface)
1062 nsChannel *This = NSUPCHANNEL_THIS(iface);
1063 return nsIChannel_Release(NSCHANNEL(This));
1066 static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
1067 nsIInputStream *aStream, const nsACString *aContentType, PRInt32 aContentLength)
1069 nsChannel *This = NSUPCHANNEL_THIS(iface);
1070 const char *content_type;
1072 TRACE("(%p)->(%p %p %d)\n", This, aStream, aContentType, aContentLength);
1074 if(This->post_data_stream)
1075 nsIInputStream_Release(This->post_data_stream);
1078 nsACString_GetData(aContentType, &content_type);
1080 FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
1083 if(aContentLength != -1)
1084 FIXME("Unsupported acontentLength = %d\n", aContentLength);
1086 if(This->post_data_stream)
1087 nsIInputStream_Release(This->post_data_stream);
1088 This->post_data_stream = aStream;
1090 nsIInputStream_AddRef(aStream);
1095 static nsresult NSAPI nsUploadChannel_GetUploadStream(nsIUploadChannel *iface,
1096 nsIInputStream **aUploadStream)
1098 nsChannel *This = NSUPCHANNEL_THIS(iface);
1100 TRACE("(%p)->(%p)\n", This, aUploadStream);
1102 if(This->post_data_stream)
1103 nsIInputStream_AddRef(This->post_data_stream);
1105 *aUploadStream = This->post_data_stream;
1109 #undef NSUPCHANNEL_THIS
1111 static const nsIUploadChannelVtbl nsUploadChannelVtbl = {
1112 nsUploadChannel_QueryInterface,
1113 nsUploadChannel_AddRef,
1114 nsUploadChannel_Release,
1115 nsUploadChannel_SetUploadStream,
1116 nsUploadChannel_GetUploadStream
1119 #define NSHTTPINTERNAL_THIS(iface) DEFINE_THIS(nsChannel, IHttpChannelInternal, iface)
1121 static nsresult NSAPI nsHttpChannelInternal_QueryInterface(nsIHttpChannelInternal *iface, nsIIDRef riid,
1124 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1125 return nsIChannel_QueryInterface(NSCHANNEL(This), riid, result);
1128 static nsrefcnt NSAPI nsHttpChannelInternal_AddRef(nsIHttpChannelInternal *iface)
1130 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1131 return nsIChannel_AddRef(NSCHANNEL(This));
1134 static nsrefcnt NSAPI nsHttpChannelInternal_Release(nsIHttpChannelInternal *iface)
1136 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1137 return nsIChannel_Release(NSCHANNEL(This));
1140 static nsresult NSAPI nsHttpChannelInternal_GetDocumentURI(nsIHttpChannelInternal *iface, nsIURI **aDocumentURI)
1142 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1144 FIXME("(%p)->()\n", This);
1146 return NS_ERROR_NOT_IMPLEMENTED;
1149 static nsresult NSAPI nsHttpChannelInternal_SetDocumentURI(nsIHttpChannelInternal *iface, nsIURI *aDocumentURI)
1151 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1153 FIXME("(%p)->()\n", This);
1155 return NS_ERROR_NOT_IMPLEMENTED;
1158 static nsresult NSAPI nsHttpChannelInternal_GetRequestVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1160 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1162 FIXME("(%p)->()\n", This);
1164 return NS_ERROR_NOT_IMPLEMENTED;
1167 static nsresult NSAPI nsHttpChannelInternal_GetResponseVersion(nsIHttpChannelInternal *iface, PRUint32 *major, PRUint32 *minor)
1169 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1171 FIXME("(%p)->()\n", This);
1173 return NS_ERROR_NOT_IMPLEMENTED;
1176 static nsresult NSAPI nsHttpChannelInternal_SetCookie(nsIHttpChannelInternal *iface, const char *aCookieHeader)
1178 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1180 FIXME("(%p)->()\n", This);
1182 return NS_ERROR_NOT_IMPLEMENTED;
1185 static nsresult NSAPI nsHttpChannelInternal_SetupFallbackChannel(nsIHttpChannelInternal *iface, const char *aFallbackKey)
1187 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1189 FIXME("(%p)->()\n", This);
1191 return NS_ERROR_NOT_IMPLEMENTED;
1194 static nsresult NSAPI nsHttpChannelInternal_GetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool *aForceThirdPartyCookie)
1196 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1198 FIXME("(%p)->()\n", This);
1200 return NS_ERROR_NOT_IMPLEMENTED;
1203 static nsresult NSAPI nsHttpChannelInternal_SetForceAllowThirdPartyCookie(nsIHttpChannelInternal *iface, PRBool aForceThirdPartyCookie)
1205 nsChannel *This = NSHTTPINTERNAL_THIS(iface);
1207 FIXME("(%p)->()\n", This);
1209 return NS_ERROR_NOT_IMPLEMENTED;
1212 #undef NSHTTPINTERNAL_THIS
1214 static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
1215 nsHttpChannelInternal_QueryInterface,
1216 nsHttpChannelInternal_AddRef,
1217 nsHttpChannelInternal_Release,
1218 nsHttpChannelInternal_GetDocumentURI,
1219 nsHttpChannelInternal_SetDocumentURI,
1220 nsHttpChannelInternal_GetRequestVersion,
1221 nsHttpChannelInternal_GetResponseVersion,
1222 nsHttpChannelInternal_SetCookie,
1223 nsHttpChannelInternal_SetupFallbackChannel,
1224 nsHttpChannelInternal_GetForceAllowThirdPartyCookie,
1225 nsHttpChannelInternal_SetForceAllowThirdPartyCookie
1228 #define NSURI_THIS(iface) DEFINE_THIS(nsURI, WineURI, iface)
1230 static nsresult NSAPI nsURI_QueryInterface(nsIWineURI *iface, nsIIDRef riid, nsQIResult result)
1232 nsURI *This = NSURI_THIS(iface);
1236 if(IsEqualGUID(&IID_nsISupports, riid)) {
1237 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
1238 *result = NSURI(This);
1239 }else if(IsEqualGUID(&IID_nsIURI, riid)) {
1240 TRACE("(%p)->(IID_nsIURI %p)\n", This, result);
1241 *result = NSURI(This);
1242 }else if(IsEqualGUID(&IID_nsIURL, riid)) {
1243 TRACE("(%p)->(IID_nsIURL %p)\n", This, result);
1244 *result = NSURI(This);
1245 }else if(IsEqualGUID(&IID_nsIWineURI, riid)) {
1246 TRACE("(%p)->(IID_nsIWineURI %p)\n", This, result);
1247 *result = NSURI(This);
1251 nsIURI_AddRef(NSURI(This));
1255 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
1256 return This->uri ? nsIURI_QueryInterface(This->uri, riid, result) : NS_NOINTERFACE;
1259 static nsrefcnt NSAPI nsURI_AddRef(nsIWineURI *iface)
1261 nsURI *This = NSURI_THIS(iface);
1262 LONG ref = InterlockedIncrement(&This->ref);
1264 TRACE("(%p) ref=%d\n", This, ref);
1269 static nsrefcnt NSAPI nsURI_Release(nsIWineURI *iface)
1271 nsURI *This = NSURI_THIS(iface);
1272 LONG ref = InterlockedDecrement(&This->ref);
1274 TRACE("(%p) ref=%d\n", This, ref);
1277 if(This->window_ref)
1278 windowref_release(This->window_ref);
1280 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
1282 nsIURL_Release(This->nsurl);
1284 nsIURI_Release(This->uri);
1285 heap_free(This->wine_url);
1292 static nsresult NSAPI nsURI_GetSpec(nsIWineURI *iface, nsACString *aSpec)
1294 nsURI *This = NSURI_THIS(iface);
1296 TRACE("(%p)->(%p)\n", This, aSpec);
1298 if(This->use_wine_url) {
1299 char speca[INTERNET_MAX_URL_LENGTH] = "wine:";
1300 WideCharToMultiByte(CP_ACP, 0, This->wine_url, -1, speca+5, sizeof(speca)-5, NULL, NULL);
1301 nsACString_SetData(aSpec, speca);
1307 return nsIURI_GetSpec(This->uri, aSpec);
1309 TRACE("returning error\n");
1310 return NS_ERROR_NOT_IMPLEMENTED;
1314 static nsresult NSAPI nsURI_SetSpec(nsIWineURI *iface, const nsACString *aSpec)
1316 nsURI *This = NSURI_THIS(iface);
1318 TRACE("(%p)->(%p)\n", This, aSpec);
1321 return nsIURI_SetSpec(This->uri, aSpec);
1323 FIXME("default action not implemented\n");
1324 return NS_ERROR_NOT_IMPLEMENTED;
1327 static nsresult NSAPI nsURI_GetPrePath(nsIWineURI *iface, nsACString *aPrePath)
1329 nsURI *This = NSURI_THIS(iface);
1331 TRACE("(%p)->(%p)\n", This, aPrePath);
1334 return nsIURI_GetPrePath(This->uri, aPrePath);
1336 FIXME("default action not implemented\n");
1337 return NS_ERROR_NOT_IMPLEMENTED;
1340 static nsresult NSAPI nsURI_GetScheme(nsIWineURI *iface, nsACString *aScheme)
1342 nsURI *This = NSURI_THIS(iface);
1344 TRACE("(%p)->(%p)\n", This, aScheme);
1346 if(This->use_wine_url) {
1348 * For Gecko we set scheme to unknown so it won't be handled
1349 * as any special case.
1351 nsACString_SetData(aScheme, "wine");
1356 return nsIURI_GetScheme(This->uri, aScheme);
1358 TRACE("returning error\n");
1359 return NS_ERROR_NOT_IMPLEMENTED;
1362 static nsresult NSAPI nsURI_SetScheme(nsIWineURI *iface, const nsACString *aScheme)
1364 nsURI *This = NSURI_THIS(iface);
1366 TRACE("(%p)->(%p)\n", This, aScheme);
1369 return nsIURI_SetScheme(This->uri, aScheme);
1371 FIXME("default action not implemented\n");
1372 return NS_ERROR_NOT_IMPLEMENTED;
1375 static nsresult NSAPI nsURI_GetUserPass(nsIWineURI *iface, nsACString *aUserPass)
1377 nsURI *This = NSURI_THIS(iface);
1379 TRACE("(%p)->(%p)\n", This, aUserPass);
1382 return nsIURI_GetUserPass(This->uri, aUserPass);
1384 FIXME("default action not implemented\n");
1385 return NS_ERROR_NOT_IMPLEMENTED;
1388 static nsresult NSAPI nsURI_SetUserPass(nsIWineURI *iface, const nsACString *aUserPass)
1390 nsURI *This = NSURI_THIS(iface);
1392 TRACE("(%p)->(%p)\n", This, aUserPass);
1395 return nsIURI_SetUserPass(This->uri, aUserPass);
1397 FIXME("default action not implemented\n");
1398 return NS_ERROR_NOT_IMPLEMENTED;
1401 static nsresult NSAPI nsURI_GetUsername(nsIWineURI *iface, nsACString *aUsername)
1403 nsURI *This = NSURI_THIS(iface);
1405 TRACE("(%p)->(%p)\n", This, aUsername);
1408 return nsIURI_GetUsername(This->uri, aUsername);
1410 FIXME("default action not implemented\n");
1411 return NS_ERROR_NOT_IMPLEMENTED;
1414 static nsresult NSAPI nsURI_SetUsername(nsIWineURI *iface, const nsACString *aUsername)
1416 nsURI *This = NSURI_THIS(iface);
1418 TRACE("(%p)->(%p)\n", This, aUsername);
1421 return nsIURI_SetUsername(This->uri, aUsername);
1423 FIXME("default action not implemented\n");
1424 return NS_ERROR_NOT_IMPLEMENTED;
1427 static nsresult NSAPI nsURI_GetPassword(nsIWineURI *iface, nsACString *aPassword)
1429 nsURI *This = NSURI_THIS(iface);
1431 TRACE("(%p)->(%p)\n", This, aPassword);
1434 return nsIURI_GetPassword(This->uri, aPassword);
1436 FIXME("default action not implemented\n");
1437 return NS_ERROR_NOT_IMPLEMENTED;
1440 static nsresult NSAPI nsURI_SetPassword(nsIWineURI *iface, const nsACString *aPassword)
1442 nsURI *This = NSURI_THIS(iface);
1444 TRACE("(%p)->(%p)\n", This, aPassword);
1447 return nsIURI_SetPassword(This->uri, aPassword);
1449 FIXME("default action not implemented\n");
1450 return NS_ERROR_NOT_IMPLEMENTED;
1453 static nsresult NSAPI nsURI_GetHostPort(nsIWineURI *iface, nsACString *aHostPort)
1455 nsURI *This = NSURI_THIS(iface);
1457 TRACE("(%p)->(%p)\n", This, aHostPort);
1460 return nsIURI_GetHostPort(This->uri, aHostPort);
1462 FIXME("default action not implemented\n");
1463 return NS_ERROR_NOT_IMPLEMENTED;
1466 static nsresult NSAPI nsURI_SetHostPort(nsIWineURI *iface, const nsACString *aHostPort)
1468 nsURI *This = NSURI_THIS(iface);
1470 TRACE("(%p)->(%p)\n", This, aHostPort);
1473 return nsIURI_SetHostPort(This->uri, aHostPort);
1475 FIXME("default action not implemented\n");
1476 return NS_ERROR_NOT_IMPLEMENTED;
1479 static nsresult NSAPI nsURI_GetHost(nsIWineURI *iface, nsACString *aHost)
1481 nsURI *This = NSURI_THIS(iface);
1483 TRACE("(%p)->(%p)\n", This, aHost);
1486 return nsIURI_GetHost(This->uri, aHost);
1488 FIXME("default action not implemented\n");
1489 return NS_ERROR_NOT_IMPLEMENTED;
1492 static nsresult NSAPI nsURI_SetHost(nsIWineURI *iface, const nsACString *aHost)
1494 nsURI *This = NSURI_THIS(iface);
1496 TRACE("(%p)->(%p)\n", This, aHost);
1499 return nsIURI_SetHost(This->uri, aHost);
1501 FIXME("default action not implemented\n");
1502 return NS_ERROR_NOT_IMPLEMENTED;
1505 static nsresult NSAPI nsURI_GetPort(nsIWineURI *iface, PRInt32 *aPort)
1507 nsURI *This = NSURI_THIS(iface);
1509 TRACE("(%p)->(%p)\n", This, aPort);
1512 return nsIURI_GetPort(This->uri, aPort);
1514 FIXME("default action not implemented\n");
1515 return NS_ERROR_NOT_IMPLEMENTED;
1518 static nsresult NSAPI nsURI_SetPort(nsIWineURI *iface, PRInt32 aPort)
1520 nsURI *This = NSURI_THIS(iface);
1522 TRACE("(%p)->(%d)\n", This, aPort);
1525 return nsIURI_SetPort(This->uri, aPort);
1527 FIXME("default action not implemented\n");
1528 return NS_ERROR_NOT_IMPLEMENTED;
1531 static nsresult NSAPI nsURI_GetPath(nsIWineURI *iface, nsACString *aPath)
1533 nsURI *This = NSURI_THIS(iface);
1535 TRACE("(%p)->(%p)\n", This, aPath);
1538 return nsIURI_GetPath(This->uri, aPath);
1540 FIXME("default action not implemented\n");
1541 return NS_ERROR_NOT_IMPLEMENTED;
1544 static nsresult NSAPI nsURI_SetPath(nsIWineURI *iface, const nsACString *aPath)
1546 nsURI *This = NSURI_THIS(iface);
1549 nsACString_GetData(aPath, &path);
1550 TRACE("(%p)->(%p(%s))\n", This, aPath, debugstr_a(path));
1553 if(This->wine_url) {
1554 WCHAR new_url[INTERNET_MAX_URL_LENGTH];
1555 DWORD size = sizeof(new_url)/sizeof(WCHAR);
1559 pathw = heap_strdupAtoW(path);
1560 hres = UrlCombineW(This->wine_url, pathw, new_url, &size, 0);
1563 nsIWineURI_SetWineURL(NSWINEURI(This), new_url);
1565 WARN("UrlCombine failed: %08x\n", hres);
1571 return nsIURI_SetPath(This->uri, aPath);
1574 static nsresult NSAPI nsURI_Equals(nsIWineURI *iface, nsIURI *other, PRBool *_retval)
1576 nsURI *This = NSURI_THIS(iface);
1577 nsIWineURI *wine_uri;
1578 LPCWSTR other_url = NULL;
1581 TRACE("(%p)->(%p %p)\n", This, other, _retval);
1584 return nsIURI_Equals(This->uri, other, _retval);
1586 nsres = nsIURI_QueryInterface(other, &IID_nsIWineURI, (void**)&wine_uri);
1587 if(NS_FAILED(nsres)) {
1588 TRACE("Could not get nsIWineURI interface\n");
1593 nsIWineURI_GetWineURL(wine_uri, &other_url);
1594 *_retval = other_url && !UrlCompareW(This->wine_url, other_url, TRUE);
1595 nsIWineURI_Release(wine_uri);
1600 static nsresult NSAPI nsURI_SchemeIs(nsIWineURI *iface, const char *scheme, PRBool *_retval)
1602 nsURI *This = NSURI_THIS(iface);
1604 TRACE("(%p)->(%s %p)\n", This, debugstr_a(scheme), _retval);
1606 if(This->use_wine_url) {
1607 WCHAR buf[INTERNET_MAX_SCHEME_LENGTH];
1608 int len = MultiByteToWideChar(CP_ACP, 0, scheme, -1, buf, sizeof(buf)/sizeof(WCHAR))-1;
1610 *_retval = lstrlenW(This->wine_url) > len
1611 && This->wine_url[len] == ':'
1612 && !memcmp(buf, This->wine_url, len*sizeof(WCHAR));
1617 return nsIURI_SchemeIs(This->uri, scheme, _retval);
1619 TRACE("returning error\n");
1620 return NS_ERROR_NOT_IMPLEMENTED;
1623 static nsresult NSAPI nsURI_Clone(nsIWineURI *iface, nsIURI **_retval)
1625 nsURI *This = NSURI_THIS(iface);
1626 nsIURI *nsuri = NULL;
1627 nsIWineURI *wine_uri;
1630 TRACE("(%p)->(%p)\n", This, _retval);
1633 nsres = nsIURI_Clone(This->uri, &nsuri);
1634 if(NS_FAILED(nsres)) {
1635 WARN("Clone failed: %08x\n", nsres);
1640 nsres = create_uri(nsuri, This->window_ref ? This->window_ref->window : NULL, This->container, &wine_uri);
1641 if(NS_FAILED(nsres)) {
1642 WARN("create_uri failed: %08x\n", nsres);
1646 *_retval = (nsIURI*)wine_uri;
1647 return nsIWineURI_SetWineURL(wine_uri, This->wine_url);
1650 static nsresult NSAPI nsURI_Resolve(nsIWineURI *iface, const nsACString *arelativePath,
1651 nsACString *_retval)
1653 nsURI *This = NSURI_THIS(iface);
1655 TRACE("(%p)->(%p %p)\n", This, arelativePath, _retval);
1658 return nsIURI_Resolve(This->uri, arelativePath, _retval);
1660 FIXME("default action not implemented\n");
1661 return NS_ERROR_NOT_IMPLEMENTED;
1664 static nsresult NSAPI nsURI_GetAsciiSpec(nsIWineURI *iface, nsACString *aAsciiSpec)
1666 nsURI *This = NSURI_THIS(iface);
1668 TRACE("(%p)->(%p)\n", This, aAsciiSpec);
1670 if(This->use_wine_url)
1671 return nsIURI_GetSpec(NSURI(This), aAsciiSpec);
1674 return nsIURI_GetAsciiSpec(This->uri, aAsciiSpec);
1676 TRACE("returning error\n");
1677 return NS_ERROR_NOT_IMPLEMENTED;
1680 static nsresult NSAPI nsURI_GetAsciiHost(nsIWineURI *iface, nsACString *aAsciiHost)
1682 nsURI *This = NSURI_THIS(iface);
1684 TRACE("(%p)->(%p)\n", This, aAsciiHost);
1687 return nsIURI_GetAsciiHost(This->uri, aAsciiHost);
1689 FIXME("default action not implemented\n");
1690 return NS_ERROR_NOT_IMPLEMENTED;
1693 static nsresult NSAPI nsURI_GetOriginCharset(nsIWineURI *iface, nsACString *aOriginCharset)
1695 nsURI *This = NSURI_THIS(iface);
1697 TRACE("(%p)->(%p)\n", This, aOriginCharset);
1700 return nsIURI_GetOriginCharset(This->uri, aOriginCharset);
1702 FIXME("default action not implemented\n");
1703 return NS_ERROR_NOT_IMPLEMENTED;
1706 static nsresult NSAPI nsURL_GetFilePath(nsIWineURI *iface, nsACString *aFilePath)
1708 nsURI *This = NSURI_THIS(iface);
1710 TRACE("(%p)->(%p)\n", This, aFilePath);
1713 return nsIURL_GetFilePath(This->nsurl, aFilePath);
1715 FIXME("default action not implemented\n");
1716 return NS_ERROR_NOT_IMPLEMENTED;
1719 static nsresult NSAPI nsURL_SetFilePath(nsIWineURI *iface, const nsACString *aFilePath)
1721 nsURI *This = NSURI_THIS(iface);
1723 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFilePath));
1726 return nsIURL_SetFilePath(This->nsurl, aFilePath);
1728 FIXME("default action not implemented\n");
1729 return NS_ERROR_NOT_IMPLEMENTED;
1732 static nsresult NSAPI nsURL_GetParam(nsIWineURI *iface, nsACString *aParam)
1734 nsURI *This = NSURI_THIS(iface);
1736 TRACE("(%p)->(%p)\n", This, aParam);
1739 return nsIURL_GetParam(This->nsurl, aParam);
1741 FIXME("default action not implemented\n");
1742 return NS_ERROR_NOT_IMPLEMENTED;
1745 static nsresult NSAPI nsURL_SetParam(nsIWineURI *iface, const nsACString *aParam)
1747 nsURI *This = NSURI_THIS(iface);
1749 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aParam));
1752 return nsIURL_SetParam(This->nsurl, aParam);
1754 FIXME("default action not implemented\n");
1755 return NS_ERROR_NOT_IMPLEMENTED;
1758 static nsresult NSAPI nsURL_GetQuery(nsIWineURI *iface, nsACString *aQuery)
1760 nsURI *This = NSURI_THIS(iface);
1762 TRACE("(%p)->(%p)\n", This, aQuery);
1765 return nsIURL_GetQuery(This->nsurl, aQuery);
1767 FIXME("default action not implemented\n");
1768 return NS_ERROR_NOT_IMPLEMENTED;
1771 static nsresult NSAPI nsURL_SetQuery(nsIWineURI *iface, const nsACString *aQuery)
1773 nsURI *This = NSURI_THIS(iface);
1774 const WCHAR *ptr1, *ptr2;
1776 WCHAR *new_url, *ptr;
1779 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
1782 nsIURL_SetQuery(This->nsurl, aQuery);
1787 nsACString_GetData(aQuery, &query);
1788 size = len = MultiByteToWideChar(CP_ACP, 0, query, -1, NULL, 0);
1789 ptr1 = strchrW(This->wine_url, '?');
1791 size += ptr1-This->wine_url;
1792 ptr2 = strchrW(ptr1, '#');
1794 size += strlenW(ptr2);
1796 ptr1 = This->wine_url + strlenW(This->wine_url);
1798 size += strlenW(This->wine_url);
1804 new_url = heap_alloc(size*sizeof(WCHAR));
1805 memcpy(new_url, This->wine_url, (ptr1-This->wine_url)*sizeof(WCHAR));
1806 ptr = new_url + (ptr1-This->wine_url);
1809 MultiByteToWideChar(CP_ACP, 0, query, -1, ptr, len);
1817 TRACE("setting %s\n", debugstr_w(new_url));
1819 heap_free(This->wine_url);
1820 This->wine_url = new_url;
1824 static nsresult NSAPI nsURL_GetRef(nsIWineURI *iface, nsACString *aRef)
1826 nsURI *This = NSURI_THIS(iface);
1828 TRACE("(%p)->(%p)\n", This, aRef);
1831 return nsIURL_GetRef(This->nsurl, aRef);
1833 FIXME("default action not implemented\n");
1834 return NS_ERROR_NOT_IMPLEMENTED;
1837 static nsresult NSAPI nsURL_SetRef(nsIWineURI *iface, const nsACString *aRef)
1839 nsURI *This = NSURI_THIS(iface);
1842 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aRef));
1845 return nsIURL_SetRef(This->nsurl, aRef);
1847 nsACString_GetData(aRef, &refa);
1851 FIXME("default action not implemented\n");
1852 return NS_ERROR_NOT_IMPLEMENTED;
1855 static nsresult NSAPI nsURL_GetDirectory(nsIWineURI *iface, nsACString *aDirectory)
1857 nsURI *This = NSURI_THIS(iface);
1859 TRACE("(%p)->(%p)\n", This, aDirectory);
1862 return nsIURL_GetDirectory(This->nsurl, aDirectory);
1864 FIXME("default action not implemented\n");
1865 return NS_ERROR_NOT_IMPLEMENTED;
1868 static nsresult NSAPI nsURL_SetDirectory(nsIWineURI *iface, const nsACString *aDirectory)
1870 nsURI *This = NSURI_THIS(iface);
1872 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aDirectory));
1875 return nsIURL_SetDirectory(This->nsurl, aDirectory);
1877 FIXME("default action not implemented\n");
1878 return NS_ERROR_NOT_IMPLEMENTED;
1881 static nsresult NSAPI nsURL_GetFileName(nsIWineURI *iface, nsACString *aFileName)
1883 nsURI *This = NSURI_THIS(iface);
1885 TRACE("(%p)->(%p)\n", This, aFileName);
1888 return nsIURL_GetFileName(This->nsurl, aFileName);
1890 FIXME("default action not implemented\n");
1891 return NS_ERROR_NOT_IMPLEMENTED;
1894 static nsresult NSAPI nsURL_SetFileName(nsIWineURI *iface, const nsACString *aFileName)
1896 nsURI *This = NSURI_THIS(iface);
1898 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileName));
1901 return nsIURL_SetFileName(This->nsurl, aFileName);
1903 FIXME("default action not implemented\n");
1904 return NS_ERROR_NOT_IMPLEMENTED;
1907 static nsresult NSAPI nsURL_GetFileBaseName(nsIWineURI *iface, nsACString *aFileBaseName)
1909 nsURI *This = NSURI_THIS(iface);
1911 TRACE("(%p)->(%p)\n", This, aFileBaseName);
1914 return nsIURL_GetFileBaseName(This->nsurl, aFileBaseName);
1916 FIXME("default action not implemented\n");
1917 return NS_ERROR_NOT_IMPLEMENTED;
1920 static nsresult NSAPI nsURL_SetFileBaseName(nsIWineURI *iface, const nsACString *aFileBaseName)
1922 nsURI *This = NSURI_THIS(iface);
1924 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileBaseName));
1927 return nsIURL_SetFileBaseName(This->nsurl, aFileBaseName);
1929 FIXME("default action not implemented\n");
1930 return NS_ERROR_NOT_IMPLEMENTED;
1933 static nsresult NSAPI nsURL_GetFileExtension(nsIWineURI *iface, nsACString *aFileExtension)
1935 nsURI *This = NSURI_THIS(iface);
1937 TRACE("(%p)->(%p)\n", This, aFileExtension);
1940 return nsIURL_GetFileExtension(This->nsurl, aFileExtension);
1942 FIXME("default action not implemented\n");
1943 return NS_ERROR_NOT_IMPLEMENTED;
1946 static nsresult NSAPI nsURL_SetFileExtension(nsIWineURI *iface, const nsACString *aFileExtension)
1948 nsURI *This = NSURI_THIS(iface);
1950 TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aFileExtension));
1953 return nsIURL_SetFileExtension(This->nsurl, aFileExtension);
1955 FIXME("default action not implemented\n");
1956 return NS_ERROR_NOT_IMPLEMENTED;
1959 static nsresult NSAPI nsURL_GetCommonBaseSpec(nsIWineURI *iface, nsIURI *aURIToCompare, nsACString *_retval)
1961 nsURI *This = NSURI_THIS(iface);
1963 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
1966 return nsIURL_GetCommonBaseSpec(This->nsurl, aURIToCompare, _retval);
1968 FIXME("default action not implemented\n");
1969 return NS_ERROR_NOT_IMPLEMENTED;
1972 static nsresult NSAPI nsURL_GetRelativeSpec(nsIWineURI *iface, nsIURI *aURIToCompare, nsACString *_retval)
1974 nsURI *This = NSURI_THIS(iface);
1976 TRACE("(%p)->(%p %p)\n", This, aURIToCompare, _retval);
1979 return nsIURL_GetRelativeSpec(This->nsurl, aURIToCompare, _retval);
1981 FIXME("default action not implemented\n");
1982 return NS_ERROR_NOT_IMPLEMENTED;
1985 static nsresult NSAPI nsURI_GetNSContainer(nsIWineURI *iface, NSContainer **aContainer)
1987 nsURI *This = NSURI_THIS(iface);
1989 TRACE("(%p)->(%p)\n", This, aContainer);
1992 nsIWebBrowserChrome_AddRef(NSWBCHROME(This->container));
1993 *aContainer = This->container;
1998 static nsresult NSAPI nsURI_SetNSContainer(nsIWineURI *iface, NSContainer *aContainer)
2000 nsURI *This = NSURI_THIS(iface);
2002 TRACE("(%p)->(%p)\n", This, aContainer);
2004 if(This->container) {
2005 if(This->container == aContainer)
2007 TRACE("Changing %p -> %p\n", This->container, aContainer);
2008 nsIWebBrowserChrome_Release(NSWBCHROME(This->container));
2012 nsIWebBrowserChrome_AddRef(NSWBCHROME(aContainer));
2013 This->container = aContainer;
2018 static nsresult NSAPI nsURI_GetWindow(nsIWineURI *iface, HTMLWindow **aHTMLWindow)
2020 nsURI *This = NSURI_THIS(iface);
2022 TRACE("(%p)->(%p)\n", This, aHTMLWindow);
2024 if(This->window_ref && This->window_ref->window) {
2025 IHTMLWindow2_AddRef(HTMLWINDOW2(This->window_ref->window));
2026 *aHTMLWindow = This->window_ref->window;
2028 *aHTMLWindow = NULL;
2034 static nsresult NSAPI nsURI_SetWindow(nsIWineURI *iface, HTMLWindow *aHTMLWindow)
2036 nsURI *This = NSURI_THIS(iface);
2038 TRACE("(%p)->(%p)\n", This, aHTMLWindow);
2040 if(This->window_ref) {
2041 if(This->window_ref->window == aHTMLWindow)
2043 TRACE("Changing %p -> %p\n", This->window_ref->window, aHTMLWindow);
2044 windowref_release(This->window_ref);
2048 windowref_addref(aHTMLWindow->window_ref);
2049 This->window_ref = aHTMLWindow->window_ref;
2051 if(aHTMLWindow->doc_obj)
2052 nsIWineURI_SetNSContainer(NSWINEURI(This), aHTMLWindow->doc_obj->nscontainer);
2054 This->window_ref = NULL;
2060 static nsresult NSAPI nsURI_GetChannelBSC(nsIWineURI *iface, nsChannelBSC **aChannelBSC)
2062 nsURI *This = NSURI_THIS(iface);
2064 TRACE("(%p)->(%p)\n", This, aChannelBSC);
2066 if(This->channel_bsc)
2067 IUnknown_AddRef((IUnknown*)This->channel_bsc);
2068 *aChannelBSC = This->channel_bsc;
2072 static nsresult NSAPI nsURI_SetChannelBSC(nsIWineURI *iface, nsChannelBSC *aChannelBSC)
2074 nsURI *This = NSURI_THIS(iface);
2076 TRACE("(%p)->(%p)\n", This, aChannelBSC);
2078 if(This->channel_bsc)
2079 IUnknown_Release((IUnknown*)This->channel_bsc);
2081 IUnknown_AddRef((IUnknown*)aChannelBSC);
2082 This->channel_bsc = aChannelBSC;
2086 static nsresult NSAPI nsURI_GetIsDocumentURI(nsIWineURI *iface, PRBool *aIsDocumentURI)
2088 nsURI *This = NSURI_THIS(iface);
2090 TRACE("(%p)->(%p)\n", This, aIsDocumentURI);
2092 *aIsDocumentURI = This->is_doc_uri;
2096 static nsresult NSAPI nsURI_SetIsDocumentURI(nsIWineURI *iface, PRBool aIsDocumentURI)
2098 nsURI *This = NSURI_THIS(iface);
2100 TRACE("(%p)->(%x)\n", This, aIsDocumentURI);
2102 This->is_doc_uri = aIsDocumentURI;
2106 static nsresult NSAPI nsURI_GetWineURL(nsIWineURI *iface, LPCWSTR *aURL)
2108 nsURI *This = NSURI_THIS(iface);
2110 TRACE("(%p)->(%p)\n", This, aURL);
2112 *aURL = This->wine_url;
2116 static nsresult NSAPI nsURI_SetWineURL(nsIWineURI *iface, LPCWSTR aURL)
2118 nsURI *This = NSURI_THIS(iface);
2120 static const WCHAR wszFtp[] = {'f','t','p',':'};
2121 static const WCHAR wszHttp[] = {'h','t','t','p',':'};
2122 static const WCHAR wszHttps[] = {'h','t','t','p','s',':'};
2124 TRACE("(%p)->(%s)\n", This, debugstr_w(aURL));
2126 heap_free(This->wine_url);
2129 int len = strlenW(aURL)+1;
2130 This->wine_url = heap_alloc(len*sizeof(WCHAR));
2131 memcpy(This->wine_url, aURL, len*sizeof(WCHAR));
2134 /* FIXME: Always use wine url */
2135 This->use_wine_url =
2136 strncmpW(aURL, wszFtp, sizeof(wszFtp)/sizeof(WCHAR))
2137 && strncmpW(aURL, wszHttp, sizeof(wszHttp)/sizeof(WCHAR))
2138 && strncmpW(aURL, wszHttps, sizeof(wszHttps)/sizeof(WCHAR));
2140 This->use_wine_url = TRUE;
2143 This->wine_url = NULL;
2144 This->use_wine_url = FALSE;
2152 static const nsIWineURIVtbl nsWineURIVtbl = {
2153 nsURI_QueryInterface,
2181 nsURI_GetOriginCharset,
2194 nsURL_GetFileBaseName,
2195 nsURL_SetFileBaseName,
2196 nsURL_GetFileExtension,
2197 nsURL_SetFileExtension,
2198 nsURL_GetCommonBaseSpec,
2199 nsURL_GetRelativeSpec,
2200 nsURI_GetNSContainer,
2201 nsURI_SetNSContainer,
2204 nsURI_GetChannelBSC,
2205 nsURI_SetChannelBSC,
2206 nsURI_GetIsDocumentURI,
2207 nsURI_SetIsDocumentURI,
2212 static nsresult create_uri(nsIURI *uri, HTMLWindow *window, NSContainer *container, nsIWineURI **_retval)
2214 nsURI *ret = heap_alloc_zero(sizeof(nsURI));
2216 ret->lpWineURIVtbl = &nsWineURIVtbl;
2220 nsIWineURI_SetNSContainer(NSWINEURI(ret), container);
2221 nsIWineURI_SetWindow(NSWINEURI(ret), window);
2224 nsIURI_QueryInterface(uri, &IID_nsIURL, (void**)&ret->nsurl);
2228 TRACE("retval=%p\n", ret);
2229 *_retval = NSWINEURI(ret);
2233 HRESULT create_doc_uri(HTMLWindow *window, WCHAR *url, nsIWineURI **ret)
2238 nsres = create_uri(NULL, window, window->doc_obj->nscontainer, &uri);
2239 if(NS_FAILED(nsres))
2242 nsIWineURI_SetWineURL(uri, url);
2243 nsIWineURI_SetIsDocumentURI(uri, TRUE);
2250 const nsIProtocolHandlerVtbl *lpProtocolHandlerVtbl;
2254 nsIProtocolHandler *nshandler;
2255 } nsProtocolHandler;
2257 #define NSPROTHANDLER(x) ((nsIProtocolHandler*) &(x)->lpProtocolHandlerVtbl)
2259 #define NSPROTHANDLER_THIS(iface) DEFINE_THIS(nsProtocolHandler, ProtocolHandler, iface)
2261 static nsresult NSAPI nsProtocolHandler_QueryInterface(nsIProtocolHandler *iface, nsIIDRef riid,
2264 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2268 if(IsEqualGUID(&IID_nsISupports, riid)) {
2269 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
2270 *result = NSPROTHANDLER(This);
2271 }else if(IsEqualGUID(&IID_nsIProtocolHandler, riid)) {
2272 TRACE("(%p)->(IID_nsIProtocolHandler %p)\n", This, result);
2273 *result = NSPROTHANDLER(This);
2274 }else if(IsEqualGUID(&IID_nsIExternalProtocolHandler, riid)) {
2275 TRACE("(%p)->(IID_nsIExternalProtocolHandler %p), returning NULL\n", This, result);
2276 return NS_NOINTERFACE;
2280 nsISupports_AddRef((nsISupports*)*result);
2284 WARN("(%s %p)\n", debugstr_guid(riid), result);
2285 return NS_NOINTERFACE;
2288 static nsrefcnt NSAPI nsProtocolHandler_AddRef(nsIProtocolHandler *iface)
2290 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2291 LONG ref = InterlockedIncrement(&This->ref);
2293 TRACE("(%p) ref=%d\n", This, ref);
2298 static nsrefcnt NSAPI nsProtocolHandler_Release(nsIProtocolHandler *iface)
2300 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2301 LONG ref = InterlockedDecrement(&This->ref);
2303 TRACE("(%p) ref=%d\n", This, ref);
2307 nsIProtocolHandler_Release(This->nshandler);
2314 static nsresult NSAPI nsProtocolHandler_GetScheme(nsIProtocolHandler *iface, nsACString *aScheme)
2316 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2318 TRACE("(%p)->(%p)\n", This, aScheme);
2321 return nsIProtocolHandler_GetScheme(This->nshandler, aScheme);
2322 return NS_ERROR_NOT_IMPLEMENTED;
2325 static nsresult NSAPI nsProtocolHandler_GetDefaultPort(nsIProtocolHandler *iface,
2326 PRInt32 *aDefaultPort)
2328 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2330 TRACE("(%p)->(%p)\n", This, aDefaultPort);
2333 return nsIProtocolHandler_GetDefaultPort(This->nshandler, aDefaultPort);
2334 return NS_ERROR_NOT_IMPLEMENTED;
2337 static nsresult NSAPI nsProtocolHandler_GetProtocolFlags(nsIProtocolHandler *iface,
2338 PRUint32 *aProtocolFlags)
2340 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2342 TRACE("(%p)->(%p)\n", This, aProtocolFlags);
2345 return nsIProtocolHandler_GetProtocolFlags(This->nshandler, aProtocolFlags);
2346 return NS_ERROR_NOT_IMPLEMENTED;
2349 static nsresult NSAPI nsProtocolHandler_NewURI(nsIProtocolHandler *iface,
2350 const nsACString *aSpec, const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2352 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2354 TRACE("((%p)->%p %s %p %p)\n", This, aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2357 return nsIProtocolHandler_NewURI(This->nshandler, aSpec, aOriginCharset, aBaseURI, _retval);
2358 return NS_ERROR_NOT_IMPLEMENTED;
2361 static nsresult NSAPI nsProtocolHandler_NewChannel(nsIProtocolHandler *iface,
2362 nsIURI *aURI, nsIChannel **_retval)
2364 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2366 TRACE("(%p)->(%p %p)\n", This, aURI, _retval);
2369 return nsIProtocolHandler_NewChannel(This->nshandler, aURI, _retval);
2370 return NS_ERROR_NOT_IMPLEMENTED;
2373 static nsresult NSAPI nsProtocolHandler_AllowPort(nsIProtocolHandler *iface,
2374 PRInt32 port, const char *scheme, PRBool *_retval)
2376 nsProtocolHandler *This = NSPROTHANDLER_THIS(iface);
2378 TRACE("(%p)->(%d %s %p)\n", This, port, debugstr_a(scheme), _retval);
2381 return nsIProtocolHandler_AllowPort(This->nshandler, port, scheme, _retval);
2382 return NS_ERROR_NOT_IMPLEMENTED;
2385 #undef NSPROTHANDLER_THIS
2387 static const nsIProtocolHandlerVtbl nsProtocolHandlerVtbl = {
2388 nsProtocolHandler_QueryInterface,
2389 nsProtocolHandler_AddRef,
2390 nsProtocolHandler_Release,
2391 nsProtocolHandler_GetScheme,
2392 nsProtocolHandler_GetDefaultPort,
2393 nsProtocolHandler_GetProtocolFlags,
2394 nsProtocolHandler_NewURI,
2395 nsProtocolHandler_NewChannel,
2396 nsProtocolHandler_AllowPort
2399 static nsIProtocolHandler *create_protocol_handler(nsIProtocolHandler *nshandler)
2401 nsProtocolHandler *ret = heap_alloc(sizeof(nsProtocolHandler));
2403 ret->lpProtocolHandlerVtbl = &nsProtocolHandlerVtbl;
2405 ret->nshandler = nshandler;
2407 return NSPROTHANDLER(ret);
2410 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService*,nsIIDRef,nsQIResult);
2412 static nsrefcnt NSAPI nsIOService_AddRef(nsIIOService *iface)
2417 static nsrefcnt NSAPI nsIOService_Release(nsIIOService *iface)
2422 static nsresult NSAPI nsIOService_GetProtocolHandler(nsIIOService *iface, const char *aScheme,
2423 nsIProtocolHandler **_retval)
2425 nsIExternalProtocolHandler *nsexthandler;
2426 nsIProtocolHandler *nshandler;
2429 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2431 nsres = nsIIOService_GetProtocolHandler(nsio, aScheme, &nshandler);
2432 if(NS_FAILED(nsres)) {
2433 WARN("GetProtocolHandler failed: %08x\n", nsres);
2437 nsres = nsIProtocolHandler_QueryInterface(nshandler, &IID_nsIExternalProtocolHandler,
2438 (void**)&nsexthandler);
2439 if(NS_FAILED(nsres)) {
2440 *_retval = nshandler;
2444 nsIExternalProtocolHandler_Release(nsexthandler);
2445 *_retval = create_protocol_handler(nshandler);
2446 TRACE("return %p\n", *_retval);
2450 static nsresult NSAPI nsIOService_GetProtocolFlags(nsIIOService *iface, const char *aScheme,
2453 TRACE("(%s %p)\n", debugstr_a(aScheme), _retval);
2454 return nsIIOService_GetProtocolFlags(nsio, aScheme, _retval);
2457 static BOOL is_gecko_special_uri(const char *spec)
2459 static const char *special_schemes[] = {"chrome:", "jar:", "resource:", "javascript:", "wyciwyg:"};
2462 for(i=0; i < sizeof(special_schemes)/sizeof(*special_schemes); i++) {
2463 if(!strncasecmp(spec, special_schemes[i], strlen(special_schemes[i])))
2470 static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *aSpec,
2471 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval)
2473 const char *spec = NULL;
2474 HTMLWindow *window = NULL;
2476 LPCWSTR base_wine_url = NULL;
2477 nsIWineURI *base_wine_uri = NULL, *wine_uri;
2478 BOOL is_wine_uri = FALSE;
2481 nsACString_GetData(aSpec, &spec);
2483 TRACE("(%p(%s) %s %p %p)\n", aSpec, debugstr_a(spec), debugstr_a(aOriginCharset),
2486 if(is_gecko_special_uri(spec))
2487 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2489 if(!strncmp(spec, "wine:", 5)) {
2495 PARSEDURLA parsed_url = {sizeof(PARSEDURLA)};
2497 nsres = nsIURI_QueryInterface(aBaseURI, &IID_nsIWineURI, (void**)&base_wine_uri);
2498 if(NS_SUCCEEDED(nsres)) {
2499 nsIWineURI_GetWineURL(base_wine_uri, &base_wine_url);
2500 nsIWineURI_GetWindow(base_wine_uri, &window);
2501 TRACE("base url: %s window: %p\n", debugstr_w(base_wine_url), window);
2502 }else if(FAILED(ParseURLA(spec, &parsed_url))) {
2503 TRACE("not wraping\n");
2504 return nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2506 WARN("Could not get base nsIWineURI: %08x\n", nsres);
2510 nsres = nsIIOService_NewURI(nsio, aSpec, aOriginCharset, aBaseURI, &uri);
2511 if(NS_FAILED(nsres))
2512 TRACE("NewURI failed: %08x\n", nsres);
2514 nsres = create_uri(uri, window, NULL, &wine_uri);
2515 *_retval = (nsIURI*)wine_uri;
2518 IHTMLWindow2_Release(HTMLWINDOW2(window));
2521 WCHAR url[INTERNET_MAX_URL_LENGTH], rel_url[INTERNET_MAX_URL_LENGTH];
2525 MultiByteToWideChar(CP_ACP, 0, spec, -1, rel_url, sizeof(rel_url)/sizeof(WCHAR));
2527 hres = CoInternetCombineUrl(base_wine_url, rel_url,
2528 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
2529 url, sizeof(url)/sizeof(WCHAR), &len, 0);
2531 nsIWineURI_SetWineURL(wine_uri, url);
2533 WARN("CoCombineUrl failed: %08x\n", hres);
2534 }else if(is_wine_uri) {
2535 WCHAR url[INTERNET_MAX_URL_LENGTH];
2537 MultiByteToWideChar(CP_ACP, 0, spec, -1, url, sizeof(url)/sizeof(WCHAR));
2538 nsIWineURI_SetWineURL(wine_uri, url);
2542 nsIWineURI_Release(base_wine_uri);
2547 static nsresult NSAPI nsIOService_NewFileURI(nsIIOService *iface, nsIFile *aFile,
2550 TRACE("(%p %p)\n", aFile, _retval);
2551 return nsIIOService_NewFileURI(nsio, aFile, _retval);
2554 static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI *aURI,
2555 nsIChannel **_retval)
2557 PARSEDURLW parsed_url = {sizeof(PARSEDURLW)};
2559 nsIWineURI *wine_uri;
2563 TRACE("(%p %p)\n", aURI, _retval);
2565 nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
2566 if(NS_FAILED(nsres)) {
2567 TRACE("Could not get nsIWineURI: %08x\n", nsres);
2568 return nsIIOService_NewChannelFromURI(nsio, aURI, _retval);
2571 ret = heap_alloc_zero(sizeof(nsChannel));
2573 ret->lpHttpChannelVtbl = &nsChannelVtbl;
2574 ret->lpUploadChannelVtbl = &nsUploadChannelVtbl;
2575 ret->lpIHttpChannelInternalVtbl = &nsHttpChannelInternalVtbl;
2577 ret->uri = wine_uri;
2579 nsIURI_AddRef(aURI);
2580 ret->original_uri = aURI;
2582 nsIWineURI_GetWineURL(wine_uri, &url);
2583 ret->url_scheme = url && SUCCEEDED(ParseURLW(url, &parsed_url)) ? parsed_url.nScheme : URL_SCHEME_UNKNOWN;
2585 *_retval = NSCHANNEL(ret);
2589 static nsresult NSAPI nsIOService_NewChannel(nsIIOService *iface, const nsACString *aSpec,
2590 const char *aOriginCharset, nsIURI *aBaseURI, nsIChannel **_retval)
2592 TRACE("(%p %s %p %p)\n", aSpec, debugstr_a(aOriginCharset), aBaseURI, _retval);
2593 return nsIIOService_NewChannel(nsio, aSpec, aOriginCharset, aBaseURI, _retval);
2596 static nsresult NSAPI nsIOService_GetOffline(nsIIOService *iface, PRBool *aOffline)
2598 TRACE("(%p)\n", aOffline);
2599 return nsIIOService_GetOffline(nsio, aOffline);
2602 static nsresult NSAPI nsIOService_SetOffline(nsIIOService *iface, PRBool aOffline)
2604 TRACE("(%x)\n", aOffline);
2605 return nsIIOService_SetOffline(nsio, aOffline);
2608 static nsresult NSAPI nsIOService_AllowPort(nsIIOService *iface, PRInt32 aPort,
2609 const char *aScheme, PRBool *_retval)
2611 TRACE("(%d %s %p)\n", aPort, debugstr_a(aScheme), _retval);
2612 return nsIIOService_AllowPort(nsio, aPort, debugstr_a(aScheme), _retval);
2615 static nsresult NSAPI nsIOService_ExtractScheme(nsIIOService *iface, const nsACString *urlString,
2616 nsACString * _retval)
2618 TRACE("(%p %p)\n", urlString, _retval);
2619 return nsIIOService_ExtractScheme(nsio, urlString, _retval);
2622 static const nsIIOServiceVtbl nsIOServiceVtbl = {
2623 nsIOService_QueryInterface,
2625 nsIOService_Release,
2626 nsIOService_GetProtocolHandler,
2627 nsIOService_GetProtocolFlags,
2629 nsIOService_NewFileURI,
2630 nsIOService_NewChannelFromURI,
2631 nsIOService_NewChannel,
2632 nsIOService_GetOffline,
2633 nsIOService_SetOffline,
2634 nsIOService_AllowPort,
2635 nsIOService_ExtractScheme
2638 static nsIIOService nsIOService = { &nsIOServiceVtbl };
2640 static nsresult NSAPI nsNetUtil_QueryInterface(nsINetUtil *iface, nsIIDRef riid,
2643 return nsIIOService_QueryInterface(&nsIOService, riid, result);
2646 static nsrefcnt NSAPI nsNetUtil_AddRef(nsINetUtil *iface)
2651 static nsrefcnt NSAPI nsNetUtil_Release(nsINetUtil *iface)
2656 static nsresult NSAPI nsNetUtil_ParseContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2657 nsACString *aCharset, PRBool *aHadCharset, nsACString *aContentType)
2659 TRACE("(%p %p %p %p)\n", aTypeHeader, aCharset, aHadCharset, aContentType);
2661 return nsINetUtil_ParseContentType(net_util, aTypeHeader, aCharset, aHadCharset, aContentType);
2664 static nsresult NSAPI nsNetUtil_ProtocolHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2668 return nsINetUtil_ProtocolHasFlags(net_util, aURI, aFlags, _retval);
2671 static nsresult NSAPI nsNetUtil_URIChainHasFlags(nsINetUtil *iface, nsIURI *aURI, PRUint32 aFlags, PRBool *_retval)
2673 TRACE("(%p %08x %p)\n", aURI, aFlags, _retval);
2675 if(aFlags == (1<<11)) {
2680 return nsINetUtil_URIChainHasFlags(net_util, aURI, aFlags, _retval);
2683 static nsresult NSAPI nsNetUtil_ToImmutableURI(nsINetUtil *iface, nsIURI *aURI, nsIURI **_retval)
2685 TRACE("(%p %p)\n", aURI, _retval);
2687 return nsINetUtil_ToImmutableURI(net_util, aURI, _retval);
2690 static nsresult NSAPI nsNetUtil_EscapeString(nsINetUtil *iface, const nsACString *aString,
2691 PRUint32 aEscapeType, nsACString *_retval)
2693 TRACE("(%p %x %p)\n", aString, aEscapeType, _retval);
2695 return nsINetUtil_EscapeString(net_util, aString, aEscapeType, _retval);
2698 static nsresult NSAPI nsNetUtil_EscapeURL(nsINetUtil *iface, const nsACString *aStr, PRUint32 aFlags,
2699 nsACString *_retval)
2701 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2703 return nsINetUtil_EscapeURL(net_util, aStr, aFlags, _retval);
2706 static nsresult NSAPI nsNetUtil_UnescapeString(nsINetUtil *iface, const nsACString *aStr,
2707 PRUint32 aFlags, nsACString *_retval)
2709 TRACE("(%p %08x %p)\n", aStr, aFlags, _retval);
2711 return nsINetUtil_UnescapeString(net_util, aStr, aFlags, _retval);
2714 static nsresult NSAPI nsNetUtil_ExtractCharsetFromContentType(nsINetUtil *iface, const nsACString *aTypeHeader,
2715 nsACString *aCharset, PRInt32 *aCharsetStart, PRInt32 *aCharsetEnd, PRBool *_retval)
2717 TRACE("(%p %p %p %p %p)\n", aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2719 return nsINetUtil_ExtractCharsetFromContentType(net_util, aTypeHeader, aCharset, aCharsetStart, aCharsetEnd, _retval);
2722 static const nsINetUtilVtbl nsNetUtilVtbl = {
2723 nsNetUtil_QueryInterface,
2726 nsNetUtil_ParseContentType,
2727 nsNetUtil_ProtocolHasFlags,
2728 nsNetUtil_URIChainHasFlags,
2729 nsNetUtil_ToImmutableURI,
2730 nsNetUtil_EscapeString,
2731 nsNetUtil_EscapeURL,
2732 nsNetUtil_UnescapeString,
2733 nsNetUtil_ExtractCharsetFromContentType
2736 static nsINetUtil nsNetUtil = { &nsNetUtilVtbl };
2738 static nsresult NSAPI nsIOService_QueryInterface(nsIIOService *iface, nsIIDRef riid,
2743 if(IsEqualGUID(&IID_nsISupports, riid))
2744 *result = &nsIOService;
2745 else if(IsEqualGUID(&IID_nsIIOService, riid))
2746 *result = &nsIOService;
2747 else if(IsEqualGUID(&IID_nsINetUtil, riid))
2748 *result = &nsNetUtil;
2751 nsISupports_AddRef((nsISupports*)*result);
2755 FIXME("(%s %p)\n", debugstr_guid(riid), result);
2756 return NS_NOINTERFACE;
2759 static nsresult NSAPI nsIOServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
2764 if(IsEqualGUID(&IID_nsISupports, riid)) {
2765 TRACE("(IID_nsISupports %p)\n", result);
2767 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
2768 TRACE("(IID_nsIFactory %p)\n", result);
2773 nsIFactory_AddRef(iface);
2777 WARN("(%s %p)\n", debugstr_guid(riid), result);
2778 return NS_NOINTERFACE;
2781 static nsrefcnt NSAPI nsIOServiceFactory_AddRef(nsIFactory *iface)
2786 static nsrefcnt NSAPI nsIOServiceFactory_Release(nsIFactory *iface)
2791 static nsresult NSAPI nsIOServiceFactory_CreateInstance(nsIFactory *iface,
2792 nsISupports *aOuter, const nsIID *iid, void **result)
2794 return nsIIOService_QueryInterface(&nsIOService, iid, result);
2797 static nsresult NSAPI nsIOServiceFactory_LockFactory(nsIFactory *iface, PRBool lock)
2799 WARN("(%x)\n", lock);
2803 static const nsIFactoryVtbl nsIOServiceFactoryVtbl = {
2804 nsIOServiceFactory_QueryInterface,
2805 nsIOServiceFactory_AddRef,
2806 nsIOServiceFactory_Release,
2807 nsIOServiceFactory_CreateInstance,
2808 nsIOServiceFactory_LockFactory
2811 static nsIFactory nsIOServiceFactory = { &nsIOServiceFactoryVtbl };
2813 void init_nsio(nsIComponentManager *component_manager, nsIComponentRegistrar *registrar)
2815 nsIFactory *old_factory = NULL;
2818 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_IOSERVICE_CID,
2819 &IID_nsIFactory, (void**)&old_factory);
2820 if(NS_FAILED(nsres)) {
2821 ERR("Could not get factory: %08x\n", nsres);
2825 nsres = nsIFactory_CreateInstance(old_factory, NULL, &IID_nsIIOService, (void**)&nsio);
2826 if(NS_FAILED(nsres)) {
2827 ERR("Couldn not create nsIOService instance %08x\n", nsres);
2828 nsIFactory_Release(old_factory);
2832 nsres = nsIIOService_QueryInterface(nsio, &IID_nsINetUtil, (void**)&net_util);
2833 if(NS_FAILED(nsres)) {
2834 WARN("Could not get nsINetUtil interface: %08x\n", nsres);
2835 nsIIOService_Release(nsio);
2839 nsres = nsIComponentRegistrar_UnregisterFactory(registrar, &NS_IOSERVICE_CID, old_factory);
2840 nsIFactory_Release(old_factory);
2841 if(NS_FAILED(nsres))
2842 ERR("UnregisterFactory failed: %08x\n", nsres);
2844 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_IOSERVICE_CID,
2845 NS_IOSERVICE_CLASSNAME, NS_IOSERVICE_CONTRACTID, &nsIOServiceFactory);
2846 if(NS_FAILED(nsres))
2847 ERR("RegisterFactory failed: %08x\n", nsres);
2850 void release_nsio(void)
2853 nsINetUtil_Release(net_util);
2858 nsIIOService_Release(nsio);